blob: 733940860f55dc7d75ca1e6e2f1a5ad7f89abf5b [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/io.h>
Jan Kiszkaac31b5a2015-04-21 07:18:24 +020010#ifndef CONFIG_ARMV7_NONSEC
Tang Yuantian064f1262014-11-21 11:17:15 +080011#error " Deep sleep needs non-secure mode support. "
12#else
13#include <asm/secure.h>
14#endif
15#include <asm/armv7.h>
Tang Yuantian064f1262014-11-21 11:17:15 +080016
York Sunc4f047c2017-03-27 11:41:03 -070017#if defined(CONFIG_ARCH_LS1021A)
Tang Yuantian064f1262014-11-21 11:17:15 +080018#include <asm/arch/immap_ls102xa.h>
19#endif
20
21#include "sleep.h"
Zhao Qiange75fc442015-04-07 15:09:54 +080022#ifdef CONFIG_U_QE
Qianyu Gongae6a7582016-02-18 13:01:59 +080023#include <fsl_qe.h>
Zhao Qiange75fc442015-04-07 15:09:54 +080024#endif
Tang Yuantian064f1262014-11-21 11:17:15 +080025
26DECLARE_GLOBAL_DATA_PTR;
27
28void __weak board_mem_sleep_setup(void)
29{
30}
31
32void __weak board_sleep_prepare(void)
33{
34}
35
36bool is_warm_boot(void)
37{
38 struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_FSL_GUTS_ADDR;
39
40 if (in_be32(&gur->crstsr) & DCFG_CCSR_CRSTSR_WDRFR)
41 return 1;
42
43 return 0;
44}
45
46void fsl_dp_disable_console(void)
47{
48 gd->flags |= GD_FLG_SILENT | GD_FLG_DISABLE_CONSOLE;
49}
50
51/*
52 * When wakeup from deep sleep, the first 128 bytes space
53 * will be used to do DDR training which corrupts the data
54 * in there. This function will restore them.
55 */
56static void dp_ddr_restore(void)
57{
58 u64 *src, *dst;
59 int i;
60 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
61
62 /* get the address of ddr date from SPARECR3 */
63 src = (u64 *)in_le32(&scfg->sparecr[2]);
64 dst = (u64 *)CONFIG_SYS_SDRAM_BASE;
65
66 for (i = 0; i < DDR_BUFF_LEN / 8; i++)
67 *dst++ = *src++;
Tang Yuantian064f1262014-11-21 11:17:15 +080068}
69
York Sunc4f047c2017-03-27 11:41:03 -070070#if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A)
Hongbo Zhang539e4f12016-08-19 17:20:33 +080071void ls1_psci_resume_fixup(void)
72{
73 u32 tmp;
74 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
75
76#ifdef QIXIS_BASE
77 void *qixis_base = (void *)QIXIS_BASE;
78
79 /* Pull on PCIe RST# */
80 out_8(qixis_base + QIXIS_RST_FORCE_3, 0);
81
82 /* disable deep sleep signals in FPGA */
83 tmp = in_8(qixis_base + QIXIS_PWR_CTL2);
84 tmp &= ~QIXIS_PWR_CTL2_PCTL;
85 out_8(qixis_base + QIXIS_PWR_CTL2, tmp);
86#endif
87
88 /* Disable wakeup interrupt during deep sleep */
89 out_be32(&scfg->pmcintecr, 0);
90 /* Clear PMC interrupt status */
91 out_be32(&scfg->pmcintsr, 0xffffffff);
92
93 /* Disable Warm Device Reset */
94 tmp = in_be32(&scfg->dpslpcr);
95 tmp &= ~SCFG_DPSLPCR_WDRR_EN;
96 out_be32(&scfg->dpslpcr, tmp);
97}
98#endif
99
Tang Yuantian064f1262014-11-21 11:17:15 +0800100static void dp_resume_prepare(void)
101{
102 dp_ddr_restore();
103 board_sleep_prepare();
104 armv7_init_nonsec();
Zhao Qiange75fc442015-04-07 15:09:54 +0800105#ifdef CONFIG_U_QE
106 u_qe_resume();
107#endif
York Sunc4f047c2017-03-27 11:41:03 -0700108#if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A)
Hongbo Zhang539e4f12016-08-19 17:20:33 +0800109 ls1_psci_resume_fixup();
110#endif
Tang Yuantian064f1262014-11-21 11:17:15 +0800111}
112
113int fsl_dp_resume(void)
114{
115 u32 start_addr;
116 void (*kernel_resume)(void);
117 struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_FSL_SCFG_ADDR;
118
119 if (!is_warm_boot())
120 return 0;
121
122 dp_resume_prepare();
123
124 /* Get the entry address and jump to kernel */
Hongbo Zhang539e4f12016-08-19 17:20:33 +0800125 start_addr = in_le32(&scfg->sparecr[3]);
Tang Yuantian064f1262014-11-21 11:17:15 +0800126 debug("Entry address is 0x%08x\n", start_addr);
127 kernel_resume = (void (*)(void))start_addr;
128 secure_ram_addr(_do_nonsec_entry)(kernel_resume, 0, 0, 0);
129
130 return 0;
131}