blob: 8edf8788edc1dcc69b774f77acd54dff758d4f4b [file] [log] [blame]
Tang Yuantiana7787b72014-11-21 11:17:15 +08001/*
2 * Copyright 2014 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#if !defined(CONFIG_ARMV7_NONSEC) || !defined(CONFIG_ARMV7_VIRT)
10#error " Deep sleep needs non-secure mode support. "
11#else
12#include <asm/secure.h>
13#endif
14#include <asm/armv7.h>
15#include <asm/cache.h>
16
17#if defined(CONFIG_LS102XA)
18#include <asm/arch/immap_ls102xa.h>
19#endif
20
21#include "sleep.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25void __weak board_mem_sleep_setup(void)
26{
27}
28
29void __weak board_sleep_prepare(void)
30{
31}
32
33bool is_warm_boot(void)
34{
35 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
36
37 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
38 return 1;
39
40 return 0;
41}
42
43void fsl_dp_disable_console(void)
44{
45 gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
46}
47
48/*
49 * When wakeup from deep sleep, the first 128 bytes space
50 * will be used to do DDR training which corrupts the data
51 * in there. This function will restore them.
52 */
53static void dp_ddr_restore(void)
54{
55 u64 *src, *dst;
56 int i;
57 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
58
59 /* get the address of ddr date from SPARECR3 */
60 src = (u64 *)in_le32(&scfg->sparecr[2]);
61 dst = (u64 *)CONFIG_SYS_SDRAM_BASE;
62
63 for (i = 0; i < DDR_BUFF_LEN / 8; i++)
64 *dst++ = *src++;
65
66 flush_dcache_all();
67}
68
69static void dp_resume_prepare(void)
70{
71 dp_ddr_restore();
72 board_sleep_prepare();
73 armv7_init_nonsec();
74 cleanup_before_linux();
75}
76
77int fsl_dp_resume(void)
78{
79 u32 start_addr;
80 void (*kernel_resume)(void);
81 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
82
83 if (!is_warm_boot())
84 return 0;
85
86 dp_resume_prepare();
87
88 /* Get the entry address and jump to kernel */
89 start_addr = in_le32(&scfg->sparecr[1]);
90 debug("Entry address is 0x%08x\n", start_addr);
91 kernel_resume = (void (*)(void))start_addr;
92 secure_ram_addr(_do_nonsec_entry)(kernel_resume, 0, 0, 0);
93
94 return 0;
95}