Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2014 Freescale Semiconductor, Inc. |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 8 | #include <asm/global_data.h> |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 9 | #include <asm/immap_85xx.h> |
| 10 | #include "sleep.h" |
Zhao Qiang | cfd7671 | 2015-03-25 17:02:59 +0800 | [diff] [blame] | 11 | #ifdef CONFIG_U_QE |
Qianyu Gong | ae6a758 | 2016-02-18 13:01:59 +0800 | [diff] [blame] | 12 | #include <fsl_qe.h> |
Zhao Qiang | cfd7671 | 2015-03-25 17:02:59 +0800 | [diff] [blame] | 13 | #endif |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 14 | |
| 15 | DECLARE_GLOBAL_DATA_PTR; |
| 16 | |
| 17 | void __weak board_mem_sleep_setup(void) |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | void __weak board_sleep_prepare(void) |
| 22 | { |
| 23 | } |
| 24 | |
| 25 | bool is_warm_boot(void) |
| 26 | { |
| 27 | struct ccsr_gur __iomem *gur = (void *)CONFIG_SYS_MPC85xx_GUTS_ADDR; |
| 28 | |
| 29 | if (in_be32(&gur->scrtsr[0]) & DCFG_CCSR_CRSTSR_WDRFR) |
| 30 | return 1; |
| 31 | |
| 32 | return 0; |
| 33 | } |
| 34 | |
| 35 | void 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 | */ |
| 45 | static void dp_ddr_restore(void) |
| 46 | { |
Tang Yuantian | 0b161c6 | 2015-04-20 11:16:56 +0800 | [diff] [blame] | 47 | u64 *src, *dst; |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 48 | int i; |
| 49 | struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_MPC85xx_SCFG; |
| 50 | |
| 51 | /* get the address of ddr date from SPARECR3 */ |
Tang Yuantian | 0b161c6 | 2015-04-20 11:16:56 +0800 | [diff] [blame] | 52 | src = (u64 *)(in_be32(&scfg->sparecr[2]) + DDR_BUFF_LEN - 8); |
| 53 | dst = (u64 *)(CONFIG_SYS_SDRAM_BASE + DDR_BUFF_LEN - 8); |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 54 | |
| 55 | for (i = 0; i < DDR_BUFF_LEN / 8; i++) |
Tang Yuantian | 0b161c6 | 2015-04-20 11:16:56 +0800 | [diff] [blame] | 56 | *dst-- = *src--; |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 57 | |
| 58 | flush_dcache(); |
| 59 | } |
| 60 | |
| 61 | static 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 Qiang | cfd7671 | 2015-03-25 17:02:59 +0800 | [diff] [blame] | 72 | |
| 73 | #ifdef CONFIG_U_QE |
| 74 | u_qe_resume(); |
| 75 | #endif |
| 76 | |
Tang Yuantian | 064f126 | 2014-11-21 11:17:15 +0800 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | int fsl_dp_resume(void) |
| 80 | { |
| 81 | u32 start_addr; |
| 82 | void (*kernel_resume)(void); |
| 83 | struct ccsr_scfg __iomem *scfg = (void *)CONFIG_SYS_MPC85xx_SCFG; |
| 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_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 | } |