blob: 228f07502f7a1bf0e837755eef47e35890388bed [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
Simon Glass0f2af882020-05-10 11:40:05 -06006#include <log.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06007#include <asm/global_data.h>
Tang Yuantian064f1262014-11-21 11:17:15 +08008#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
York Sunc4f047c2017-03-27 11:41:03 -070016#if defined(CONFIG_ARCH_LS1021A)
Tang Yuantian064f1262014-11-21 11:17:15 +080017#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
Qianyu Gongae6a7582016-02-18 13:01:59 +080022#include <fsl_qe.h>
Zhao Qiange75fc442015-04-07 15:09:54 +080023#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{
Tom Rini376b88a2022-10-28 20:27:13 -040037 struct ccsr_gur __iomem *gur = (void *)CFG_SYS_FSL_GUTS_ADDR;
Tang Yuantian064f1262014-11-21 11:17:15 +080038
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;
Tom Rini376b88a2022-10-28 20:27:13 -040059 struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_FSL_SCFG_ADDR;
Tang Yuantian064f1262014-11-21 11:17:15 +080060
61 /* get the address of ddr date from SPARECR3 */
62 src = (u64 *)in_le32(&scfg->sparecr[2]);
Tom Rinibb4dd962022-11-16 13:10:37 -050063 dst = (u64 *)CFG_SYS_SDRAM_BASE;
Tang Yuantian064f1262014-11-21 11:17:15 +080064
65 for (i = 0; i < DDR_BUFF_LEN / 8; i++)
66 *dst++ = *src++;
Tang Yuantian064f1262014-11-21 11:17:15 +080067}
68
York Sunc4f047c2017-03-27 11:41:03 -070069#if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A)
Hongbo Zhang539e4f12016-08-19 17:20:33 +080070void ls1_psci_resume_fixup(void)
71{
72 u32 tmp;
Tom Rini376b88a2022-10-28 20:27:13 -040073 struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_FSL_SCFG_ADDR;
Hongbo Zhang539e4f12016-08-19 17:20:33 +080074
75#ifdef QIXIS_BASE
76 void *qixis_base = (void *)QIXIS_BASE;
77
78 /* Pull on PCIe RST# */
79 out_8(qixis_base + QIXIS_RST_FORCE_3, 0);
80
81 /* disable deep sleep signals in FPGA */
82 tmp = in_8(qixis_base + QIXIS_PWR_CTL2);
83 tmp &= ~QIXIS_PWR_CTL2_PCTL;
84 out_8(qixis_base + QIXIS_PWR_CTL2, tmp);
85#endif
86
87 /* Disable wakeup interrupt during deep sleep */
88 out_be32(&scfg->pmcintecr, 0);
89 /* Clear PMC interrupt status */
90 out_be32(&scfg->pmcintsr, 0xffffffff);
91
92 /* Disable Warm Device Reset */
93 tmp = in_be32(&scfg->dpslpcr);
94 tmp &= ~SCFG_DPSLPCR_WDRR_EN;
95 out_be32(&scfg->dpslpcr, tmp);
96}
97#endif
98
Tang Yuantian064f1262014-11-21 11:17:15 +080099static void dp_resume_prepare(void)
100{
101 dp_ddr_restore();
102 board_sleep_prepare();
103 armv7_init_nonsec();
Zhao Qiange75fc442015-04-07 15:09:54 +0800104#ifdef CONFIG_U_QE
105 u_qe_resume();
106#endif
York Sunc4f047c2017-03-27 11:41:03 -0700107#if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A)
Hongbo Zhang539e4f12016-08-19 17:20:33 +0800108 ls1_psci_resume_fixup();
109#endif
Tang Yuantian064f1262014-11-21 11:17:15 +0800110}
111
112int fsl_dp_resume(void)
113{
114 u32 start_addr;
115 void (*kernel_resume)(void);
Tom Rini376b88a2022-10-28 20:27:13 -0400116 struct ccsr_scfg __iomem *scfg = (void *)CFG_SYS_FSL_SCFG_ADDR;
Tang Yuantian064f1262014-11-21 11:17:15 +0800117
118 if (!is_warm_boot())
119 return 0;
120
121 dp_resume_prepare();
122
123 /* Get the entry address and jump to kernel */
Hongbo Zhang539e4f12016-08-19 17:20:33 +0800124 start_addr = in_le32(&scfg->sparecr[3]);
Tang Yuantian064f1262014-11-21 11:17:15 +0800125 debug("Entry address is 0x%08x\n", start_addr);
126 kernel_resume = (void (*)(void))start_addr;
127 secure_ram_addr(_do_nonsec_entry)(kernel_resume, 0, 0, 0);
128
129 return 0;
130}