blob: a498c65f040d35ff1172d9f109fe03fef754ccaf [file] [log] [blame]
Tang Yuantian064f1262014-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>
Jan Kiszkaac31b5a2015-04-21 07:18:24 +02009#ifndef CONFIG_ARMV7_NONSEC
Tang Yuantian064f1262014-11-21 11:17:15 +080010#error " Deep sleep needs non-secure mode support. "
11#else
12#include <asm/secure.h>
13#endif
14#include <asm/armv7.h>
Tang Yuantian064f1262014-11-21 11:17:15 +080015
16#if defined(CONFIG_LS102XA)
17#include <asm/arch/immap_ls102xa.h>
18#endif
19
20#include "sleep.h"
Zhao Qiange75fc442015-04-07 15:09:54 +080021#ifdef CONFIG_U_QE
22#include "../../../drivers/qe/qe.h"
23#endif
Tang Yuantian064f1262014-11-21 11:17:15 +080024
25DECLARE_GLOBAL_DATA_PTR;
26
27void __weak board_mem_sleep_setup(void)
28{
29}
30
31void __weak board_sleep_prepare(void)
32{
33}
34
35bool is_warm_boot(void)
36{
37 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
38
39 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
40 return 1;
41
42 return 0;
43}
44
45void fsl_dp_disable_console(void)
46{
47 gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
48}
49
50/*
51 * When wakeup from deep sleep, the first 128 bytes space
52 * will be used to do DDR training which corrupts the data
53 * in there. This function will restore them.
54 */
55static void dp_ddr_restore(void)
56{
57 u64 *src, *dst;
58 int i;
59 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
60
61 /* get the address of ddr date from SPARECR3 */
62 src = (u64 *)in_le32(&scfg->sparecr[2]);
63 dst = (u64 *)CONFIG_SYS_SDRAM_BASE;
64
65 for (i = 0; i < DDR_BUFF_LEN / 8; i++)
66 *dst++ = *src++;
Tang Yuantian064f1262014-11-21 11:17:15 +080067}
68
69static void dp_resume_prepare(void)
70{
71 dp_ddr_restore();
72 board_sleep_prepare();
73 armv7_init_nonsec();
Zhao Qiange75fc442015-04-07 15:09:54 +080074#ifdef CONFIG_U_QE
75 u_qe_resume();
76#endif
Tang Yuantian064f1262014-11-21 11:17:15 +080077}
78
79int fsl_dp_resume(void)
80{
81 u32 start_addr;
82 void (*kernel_resume)(void);
83 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
84
85 if (!is_warm_boot())
86 return 0;
87
88 dp_resume_prepare();
89
90 /* Get the entry address and jump to kernel */
91 start_addr = in_le32(&scfg->sparecr[1]);
92 debug("Entry address is 0x%08x\n", start_addr);
93 kernel_resume = (void (*)(void))start_addr;
94 secure_ram_addr(_do_nonsec_entry)(kernel_resume, 0, 0, 0);
95
96 return 0;
97}