Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2011-2012 Samsung Electronics Co., Ltd. |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 3 | * http://www.samsung.com |
| 4 | * |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 5 | * EXYNOS - Power Management support |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 6 | * |
| 7 | * Based on arch/arm/mach-s3c2410/pm.c |
| 8 | * Copyright (c) 2006 Simtec Electronics |
| 9 | * Ben Dooks <ben@simtec.co.uk> |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or modify |
| 12 | * it under the terms of the GNU General Public License version 2 as |
| 13 | * published by the Free Software Foundation. |
| 14 | */ |
| 15 | |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/suspend.h> |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 18 | #include <linux/syscore_ops.h> |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 19 | #include <linux/io.h> |
Jaecheol Lee | 56c03d9 | 2011-07-18 19:25:13 +0900 | [diff] [blame] | 20 | #include <linux/err.h> |
| 21 | #include <linux/clk.h> |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 22 | |
| 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/hardware/cache-l2x0.h> |
Shawn Guo | 63b870f | 2011-11-17 01:19:11 +0900 | [diff] [blame] | 25 | #include <asm/smp_scu.h> |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 26 | |
| 27 | #include <plat/cpu.h> |
| 28 | #include <plat/pm.h> |
Jaecheol Lee | 56c03d9 | 2011-07-18 19:25:13 +0900 | [diff] [blame] | 29 | #include <plat/pll.h> |
MyungJoo Ham | b93cb91 | 2011-07-21 11:25:23 +0900 | [diff] [blame] | 30 | #include <plat/regs-srom.h> |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 31 | |
Kukjin Kim | 9c9239a | 2013-12-19 04:19:59 +0900 | [diff] [blame] | 32 | #include <mach/map.h> |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 33 | #include <mach/pm-core.h> |
Kukjin Kim | ccd458c | 2012-12-31 10:06:48 -0800 | [diff] [blame] | 34 | |
| 35 | #include "common.h" |
Kukjin Kim | 65c9a85 | 2013-12-19 04:06:56 +0900 | [diff] [blame] | 36 | #include "regs-pmu.h" |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 37 | |
Abhilash Kesavan | 86ffb0e | 2012-11-20 18:20:45 +0900 | [diff] [blame] | 38 | static struct sleep_save exynos5_sys_save[] = { |
| 39 | SAVE_ITEM(EXYNOS5_SYS_I2C_CFG), |
| 40 | }; |
| 41 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 42 | static struct sleep_save exynos_core_save[] = { |
MyungJoo Ham | b93cb91 | 2011-07-21 11:25:23 +0900 | [diff] [blame] | 43 | /* SROM side */ |
| 44 | SAVE_ITEM(S5P_SROM_BW), |
| 45 | SAVE_ITEM(S5P_SROM_BC0), |
| 46 | SAVE_ITEM(S5P_SROM_BC1), |
| 47 | SAVE_ITEM(S5P_SROM_BC2), |
| 48 | SAVE_ITEM(S5P_SROM_BC3), |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 49 | }; |
| 50 | |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 51 | |
Jaecheol Lee | f4ba4b0 | 2011-07-18 19:25:03 +0900 | [diff] [blame] | 52 | /* For Cortex-A9 Diagnostic and Power control register */ |
| 53 | static unsigned int save_arm_register[2]; |
| 54 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 55 | static int exynos_cpu_suspend(unsigned long arg) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 56 | { |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 57 | #ifdef CONFIG_CACHE_L2X0 |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 58 | outer_flush_all(); |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 59 | #endif |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 60 | |
Abhilash Kesavan | 573e5bb | 2012-11-22 14:46:40 +0900 | [diff] [blame] | 61 | if (soc_is_exynos5250()) |
| 62 | flush_cache_all(); |
| 63 | |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 64 | /* issue the standby signal into the pm unit. */ |
| 65 | cpu_do_idle(); |
| 66 | |
Abhilash Kesavan | d3fcacf | 2013-01-25 10:40:19 -0800 | [diff] [blame] | 67 | pr_info("Failed to suspend the system\n"); |
| 68 | return 1; /* Aborting suspend */ |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 69 | } |
| 70 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 71 | static void exynos_pm_prepare(void) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 72 | { |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 73 | unsigned int tmp; |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 74 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 75 | s3c_pm_do_save(exynos_core_save, ARRAY_SIZE(exynos_core_save)); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 76 | |
Tomasz Figa | e11d919 | 2014-02-14 08:16:01 +0900 | [diff] [blame] | 77 | if (soc_is_exynos5250()) { |
Abhilash Kesavan | 86ffb0e | 2012-11-20 18:20:45 +0900 | [diff] [blame] | 78 | s3c_pm_do_save(exynos5_sys_save, ARRAY_SIZE(exynos5_sys_save)); |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 79 | /* Disable USE_RETENTION of JPEG_MEM_OPTION */ |
| 80 | tmp = __raw_readl(EXYNOS5_JPEG_MEM_OPTION); |
| 81 | tmp &= ~EXYNOS5_OPTION_USE_RETENTION; |
| 82 | __raw_writel(tmp, EXYNOS5_JPEG_MEM_OPTION); |
| 83 | } |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 84 | |
| 85 | /* Set value of power down register for sleep mode */ |
| 86 | |
Jongpill Lee | 7d44d2b | 2012-02-17 09:51:31 +0900 | [diff] [blame] | 87 | exynos_sys_powerdown_conf(SYS_SLEEP); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 88 | __raw_writel(S5P_CHECK_SLEEP, S5P_INFORM1); |
| 89 | |
| 90 | /* ensure at least INFORM0 has the resume address */ |
| 91 | |
| 92 | __raw_writel(virt_to_phys(s3c_cpu_resume), S5P_INFORM0); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 93 | } |
| 94 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 95 | static int exynos_pm_suspend(void) |
Jaecheol Lee | 12974e9 | 2011-07-18 19:21:41 +0900 | [diff] [blame] | 96 | { |
| 97 | unsigned long tmp; |
| 98 | |
| 99 | /* Setting Central Sequence Register for power down mode */ |
| 100 | |
| 101 | tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION); |
| 102 | tmp &= ~S5P_CENTRAL_LOWPWR_CFG; |
| 103 | __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION); |
| 104 | |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 105 | /* Setting SEQ_OPTION register */ |
| 106 | |
| 107 | tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0); |
| 108 | __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION); |
| 109 | |
| 110 | if (!soc_is_exynos5250()) { |
| 111 | /* Save Power control register */ |
| 112 | asm ("mrc p15, 0, %0, c15, c0, 0" |
| 113 | : "=r" (tmp) : : "cc"); |
| 114 | save_arm_register[0] = tmp; |
| 115 | |
| 116 | /* Save Diagnostic register */ |
| 117 | asm ("mrc p15, 0, %0, c15, c0, 1" |
| 118 | : "=r" (tmp) : : "cc"); |
| 119 | save_arm_register[1] = tmp; |
Jongpill Lee | 00a351f | 2011-09-27 07:26:04 +0900 | [diff] [blame] | 120 | } |
| 121 | |
Jaecheol Lee | 12974e9 | 2011-07-18 19:21:41 +0900 | [diff] [blame] | 122 | return 0; |
| 123 | } |
| 124 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 125 | static void exynos_pm_resume(void) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 126 | { |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 127 | unsigned long tmp; |
| 128 | |
| 129 | /* |
| 130 | * If PMU failed while entering sleep mode, WFI will be |
| 131 | * ignored by PMU and then exiting cpu_do_idle(). |
| 132 | * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically |
| 133 | * in this situation. |
| 134 | */ |
| 135 | tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION); |
| 136 | if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) { |
| 137 | tmp |= S5P_CENTRAL_LOWPWR_CFG; |
| 138 | __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION); |
Abhilash Kesavan | d3fcacf | 2013-01-25 10:40:19 -0800 | [diff] [blame] | 139 | /* clear the wakeup state register */ |
| 140 | __raw_writel(0x0, S5P_WAKEUP_STAT); |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 141 | /* No need to perform below restore code */ |
| 142 | goto early_wakeup; |
| 143 | } |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 144 | if (!soc_is_exynos5250()) { |
| 145 | /* Restore Power control register */ |
| 146 | tmp = save_arm_register[0]; |
| 147 | asm volatile ("mcr p15, 0, %0, c15, c0, 0" |
| 148 | : : "r" (tmp) |
| 149 | : "cc"); |
Jaecheol Lee | f4ba4b0 | 2011-07-18 19:25:03 +0900 | [diff] [blame] | 150 | |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 151 | /* Restore Diagnostic register */ |
| 152 | tmp = save_arm_register[1]; |
| 153 | asm volatile ("mcr p15, 0, %0, c15, c0, 1" |
| 154 | : : "r" (tmp) |
| 155 | : "cc"); |
| 156 | } |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 157 | |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 158 | /* For release retention */ |
| 159 | |
| 160 | __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION); |
| 161 | __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION); |
| 162 | __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION); |
| 163 | __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION); |
| 164 | __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION); |
| 165 | __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION); |
| 166 | __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION); |
| 167 | |
Abhilash Kesavan | 86ffb0e | 2012-11-20 18:20:45 +0900 | [diff] [blame] | 168 | if (soc_is_exynos5250()) |
| 169 | s3c_pm_do_restore(exynos5_sys_save, |
| 170 | ARRAY_SIZE(exynos5_sys_save)); |
| 171 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 172 | s3c_pm_do_restore_core(exynos_core_save, ARRAY_SIZE(exynos_core_save)); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 173 | |
Tomasz Figa | e11d919 | 2014-02-14 08:16:01 +0900 | [diff] [blame] | 174 | if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250()) |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 175 | scu_enable(S5P_VA_SCU); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 176 | |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 177 | early_wakeup: |
Inderpal Singh | ebee854 | 2012-11-22 14:46:27 +0900 | [diff] [blame] | 178 | |
| 179 | /* Clear SLEEP mode set in INFORM1 */ |
| 180 | __raw_writel(0x0, S5P_INFORM1); |
| 181 | |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 182 | return; |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 183 | } |
| 184 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 185 | static struct syscore_ops exynos_pm_syscore_ops = { |
| 186 | .suspend = exynos_pm_suspend, |
| 187 | .resume = exynos_pm_resume, |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 188 | }; |
| 189 | |
Tomasz Figa | 559ba23 | 2014-03-18 07:28:22 +0900 | [diff] [blame^] | 190 | void __init exynos_pm_init(void) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 191 | { |
Tomasz Figa | 559ba23 | 2014-03-18 07:28:22 +0900 | [diff] [blame^] | 192 | u32 tmp; |
| 193 | |
| 194 | pm_cpu_prep = exynos_pm_prepare; |
| 195 | pm_cpu_sleep = exynos_cpu_suspend; |
| 196 | |
| 197 | s3c_pm_init(); |
| 198 | |
| 199 | /* All wakeup disable */ |
| 200 | tmp = __raw_readl(S5P_WAKEUP_MASK); |
| 201 | tmp |= ((0xFF << 8) | (0x1F << 1)); |
| 202 | __raw_writel(tmp, S5P_WAKEUP_MASK); |
Kukjin Kim | e085cad | 2013-06-26 22:29:44 +0900 | [diff] [blame] | 203 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 204 | register_syscore_ops(&exynos_pm_syscore_ops); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 205 | } |