Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 9 | #include <asm/io.h> |
Jan Kiszka | 104d6fb | 2015-04-21 07:18:24 +0200 | [diff] [blame] | 10 | #ifndef CONFIG_ARMV7_NONSEC |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 11 | #error " Deep sleep needs non-secure mode support. " |
| 12 | #else |
| 13 | #include <asm/secure.h> |
| 14 | #endif |
| 15 | #include <asm/armv7.h> |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 16 | |
York Sun | 73fb583 | 2017-03-27 11:41:03 -0700 | [diff] [blame] | 17 | #if defined(CONFIG_ARCH_LS1021A) |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 18 | #include <asm/arch/immap_ls102xa.h> |
| 19 | #endif |
| 20 | |
| 21 | #include "sleep.h" |
Zhao Qiang | 1fb5ff9 | 2015-04-07 15:09:54 +0800 | [diff] [blame] | 22 | #ifdef CONFIG_U_QE |
Qianyu Gong | 2459afb | 2016-02-18 13:01:59 +0800 | [diff] [blame] | 23 | #include <fsl_qe.h> |
Zhao Qiang | 1fb5ff9 | 2015-04-07 15:09:54 +0800 | [diff] [blame] | 24 | #endif |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
| 28 | void __weak board_mem_sleep_setup(void) |
| 29 | { |
| 30 | } |
| 31 | |
| 32 | void __weak board_sleep_prepare(void) |
| 33 | { |
| 34 | } |
| 35 | |
| 36 | bool 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 | |
| 46 | void 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 | */ |
| 56 | static 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 Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 68 | } |
| 69 | |
York Sun | 73fb583 | 2017-03-27 11:41:03 -0700 | [diff] [blame] | 70 | #if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A) |
Hongbo Zhang | 214ffae | 2016-08-19 17:20:33 +0800 | [diff] [blame] | 71 | void 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 Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 100 | static void dp_resume_prepare(void) |
| 101 | { |
| 102 | dp_ddr_restore(); |
| 103 | board_sleep_prepare(); |
| 104 | armv7_init_nonsec(); |
Zhao Qiang | 1fb5ff9 | 2015-04-07 15:09:54 +0800 | [diff] [blame] | 105 | #ifdef CONFIG_U_QE |
| 106 | u_qe_resume(); |
| 107 | #endif |
York Sun | 73fb583 | 2017-03-27 11:41:03 -0700 | [diff] [blame] | 108 | #if defined(CONFIG_ARMV7_PSCI) && defined(CONFIG_ARCH_LS1021A) |
Hongbo Zhang | 214ffae | 2016-08-19 17:20:33 +0800 | [diff] [blame] | 109 | ls1_psci_resume_fixup(); |
| 110 | #endif |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | int 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 Zhang | 214ffae | 2016-08-19 17:20:33 +0800 | [diff] [blame] | 125 | start_addr = in_le32(&scfg->sparecr[3]); |
Tang Yuantian | a7787b7 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 126 | 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 | } |