blob: d3323b9ec1e5a6328d682f1d044e58cf7b9f4350 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Tang Yuantian064f1262014-11-21 11:17:15 +08002/*
3 * Copyright 2014 Freescale Semiconductor, Inc.
Tang Yuantian064f1262014-11-21 11:17:15 +08004 */
5
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Tang Yuantian064f1262014-11-21 11:17:15 +08009#include <asm/immap_85xx.h>
10#include "sleep.h"
Zhao Qiangcfd76712015-03-25 17:02:59 +080011#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080012#include <fsl_qe.h>
Zhao Qiangcfd76712015-03-25 17:02:59 +080013#endif
Tang Yuantian064f1262014-11-21 11:17:15 +080014
15DECLARE_GLOBAL_DATA_PTR;
16
17void __weak board_mem_sleep_setup(void)
18{
19}
20
21void __weak board_sleep_prepare(void)
22{
23}
24
25bool is_warm_boot(void)
26{
Tom Rinid5c3bf22022-10-28 20:27:12 -040027 struct ccsr_gur __iomem *gur = (void *)CFG_SYS_MPC85xx_GUTS_ADDR;
Tang Yuantian064f1262014-11-21 11:17:15 +080028
29 if (in_be32(&gur->scrtsr[0]) & DCFG_CCSR_CRSTSR_WDRFR)
30 return 1;
31
32 return 0;
33}
34
35void fsl_dp_disable_console(void)
36{
37 gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
38}
39
40/*
41 * When wakeup from deep sleep, the first 128 bytes space
42 * will be used to do DDR training which corrupts the data
43 * in there. This function will restore them.
44 */
45static void dp_ddr_restore(void)
46{
Tang Yuantian0b161c62015-04-20 11:16:56 +080047 u64 *src, *dst;
Tang Yuantian064f1262014-11-21 11:17:15 +080048 int i;
Tom Rinid5c3bf22022-10-28 20:27:12 -040049 struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_MPC85xx_SCFG;
Tang Yuantian064f1262014-11-21 11:17:15 +080050
51 /* get the address of ddr date from SPARECR3 */
Tang Yuantian0b161c62015-04-20 11:16:56 +080052 src = (u64 *)(in_be32(&scfg->sparecr[2]) + DDR_BUFF_LEN - 8);
Tom Rinibb4dd962022-11-16 13:10:37 -050053 dst = (u64 *)(CFG_SYS_SDRAM_BASE + DDR_BUFF_LEN - 8);
Tang Yuantian064f1262014-11-21 11:17:15 +080054
55 for (i = 0; i < DDR_BUFF_LEN / 8; i++)
Tang Yuantian0b161c62015-04-20 11:16:56 +080056 *dst-- = *src--;
Tang Yuantian064f1262014-11-21 11:17:15 +080057
58 flush_dcache();
59}
60
61static void dp_resume_prepare(void)
62{
63 dp_ddr_restore();
64
65 board_sleep_prepare();
66
67 l2cache_init();
68#if defined(CONFIG_RAMBOOT_PBL)
69 disable_cpc_sram();
70#endif
71 enable_cpc();
Zhao Qiangcfd76712015-03-25 17:02:59 +080072
73#ifdef CONFIG_U_QE
74 u_qe_resume();
75#endif
76
Tang Yuantian064f1262014-11-21 11:17:15 +080077}
78
79int fsl_dp_resume(void)
80{
81 u32 start_addr;
82 void (*kernel_resume)(void);
Tom Rinid5c3bf22022-10-28 20:27:12 -040083 struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_MPC85xx_SCFG;
Tang Yuantian064f1262014-11-21 11:17:15 +080084
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_be32(&scfg->sparecr[1]);
92 debug("Entry address is 0x%08x\n", start_addr);
93 kernel_resume = (void (*)(void))start_addr;
94 kernel_resume();
95
96 return 0;
97}