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_add(struct device *dev, struct subsys_interface *sif) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 96 | { |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 97 | pm_cpu_prep = exynos_pm_prepare; |
| 98 | pm_cpu_sleep = exynos_cpu_suspend; |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 99 | |
| 100 | return 0; |
| 101 | } |
| 102 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 103 | static struct subsys_interface exynos_pm_interface = { |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 104 | .name = "exynos_pm", |
Thomas Abraham | 9ee6af9 | 2012-05-15 15:47:40 +0900 | [diff] [blame] | 105 | .subsys = &exynos_subsys, |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 106 | .add_dev = exynos_pm_add, |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 107 | }; |
| 108 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 109 | static __init int exynos_pm_drvinit(void) |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 110 | { |
| 111 | unsigned int tmp; |
| 112 | |
Kukjin Kim | e085cad | 2013-06-26 22:29:44 +0900 | [diff] [blame] | 113 | if (soc_is_exynos5440()) |
| 114 | return 0; |
| 115 | |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 116 | s3c_pm_init(); |
| 117 | |
| 118 | /* All wakeup disable */ |
| 119 | |
| 120 | tmp = __raw_readl(S5P_WAKEUP_MASK); |
| 121 | tmp |= ((0xFF << 8) | (0x1F << 1)); |
| 122 | __raw_writel(tmp, S5P_WAKEUP_MASK); |
| 123 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 124 | return subsys_interface_register(&exynos_pm_interface); |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 125 | } |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 126 | arch_initcall(exynos_pm_drvinit); |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 127 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 128 | static int exynos_pm_suspend(void) |
Jaecheol Lee | 12974e9 | 2011-07-18 19:21:41 +0900 | [diff] [blame] | 129 | { |
| 130 | unsigned long tmp; |
| 131 | |
| 132 | /* Setting Central Sequence Register for power down mode */ |
| 133 | |
| 134 | tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION); |
| 135 | tmp &= ~S5P_CENTRAL_LOWPWR_CFG; |
| 136 | __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION); |
| 137 | |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 138 | /* Setting SEQ_OPTION register */ |
| 139 | |
| 140 | tmp = (S5P_USE_STANDBY_WFI0 | S5P_USE_STANDBY_WFE0); |
| 141 | __raw_writel(tmp, S5P_CENTRAL_SEQ_OPTION); |
| 142 | |
| 143 | if (!soc_is_exynos5250()) { |
| 144 | /* Save Power control register */ |
| 145 | asm ("mrc p15, 0, %0, c15, c0, 0" |
| 146 | : "=r" (tmp) : : "cc"); |
| 147 | save_arm_register[0] = tmp; |
| 148 | |
| 149 | /* Save Diagnostic register */ |
| 150 | asm ("mrc p15, 0, %0, c15, c0, 1" |
| 151 | : "=r" (tmp) : : "cc"); |
| 152 | save_arm_register[1] = tmp; |
Jongpill Lee | 00a351f | 2011-09-27 07:26:04 +0900 | [diff] [blame] | 153 | } |
| 154 | |
Jaecheol Lee | 12974e9 | 2011-07-18 19:21:41 +0900 | [diff] [blame] | 155 | return 0; |
| 156 | } |
| 157 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 158 | static void exynos_pm_resume(void) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 159 | { |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 160 | unsigned long tmp; |
| 161 | |
| 162 | /* |
| 163 | * If PMU failed while entering sleep mode, WFI will be |
| 164 | * ignored by PMU and then exiting cpu_do_idle(). |
| 165 | * S5P_CENTRAL_LOWPWR_CFG bit will not be set automatically |
| 166 | * in this situation. |
| 167 | */ |
| 168 | tmp = __raw_readl(S5P_CENTRAL_SEQ_CONFIGURATION); |
| 169 | if (!(tmp & S5P_CENTRAL_LOWPWR_CFG)) { |
| 170 | tmp |= S5P_CENTRAL_LOWPWR_CFG; |
| 171 | __raw_writel(tmp, S5P_CENTRAL_SEQ_CONFIGURATION); |
Abhilash Kesavan | d3fcacf | 2013-01-25 10:40:19 -0800 | [diff] [blame] | 172 | /* clear the wakeup state register */ |
| 173 | __raw_writel(0x0, S5P_WAKEUP_STAT); |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 174 | /* No need to perform below restore code */ |
| 175 | goto early_wakeup; |
| 176 | } |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 177 | if (!soc_is_exynos5250()) { |
| 178 | /* Restore Power control register */ |
| 179 | tmp = save_arm_register[0]; |
| 180 | asm volatile ("mcr p15, 0, %0, c15, c0, 0" |
| 181 | : : "r" (tmp) |
| 182 | : "cc"); |
Jaecheol Lee | f4ba4b0 | 2011-07-18 19:25:03 +0900 | [diff] [blame] | 183 | |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 184 | /* Restore Diagnostic register */ |
| 185 | tmp = save_arm_register[1]; |
| 186 | asm volatile ("mcr p15, 0, %0, c15, c0, 1" |
| 187 | : : "r" (tmp) |
| 188 | : "cc"); |
| 189 | } |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 190 | |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 191 | /* For release retention */ |
| 192 | |
| 193 | __raw_writel((1 << 28), S5P_PAD_RET_MAUDIO_OPTION); |
| 194 | __raw_writel((1 << 28), S5P_PAD_RET_GPIO_OPTION); |
| 195 | __raw_writel((1 << 28), S5P_PAD_RET_UART_OPTION); |
| 196 | __raw_writel((1 << 28), S5P_PAD_RET_MMCA_OPTION); |
| 197 | __raw_writel((1 << 28), S5P_PAD_RET_MMCB_OPTION); |
| 198 | __raw_writel((1 << 28), S5P_PAD_RET_EBIA_OPTION); |
| 199 | __raw_writel((1 << 28), S5P_PAD_RET_EBIB_OPTION); |
| 200 | |
Abhilash Kesavan | 86ffb0e | 2012-11-20 18:20:45 +0900 | [diff] [blame] | 201 | if (soc_is_exynos5250()) |
| 202 | s3c_pm_do_restore(exynos5_sys_save, |
| 203 | ARRAY_SIZE(exynos5_sys_save)); |
| 204 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 205 | 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] | 206 | |
Tomasz Figa | e11d919 | 2014-02-14 08:16:01 +0900 | [diff] [blame^] | 207 | if (IS_ENABLED(CONFIG_SMP) && !soc_is_exynos5250()) |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 208 | scu_enable(S5P_VA_SCU); |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 209 | |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 210 | early_wakeup: |
Inderpal Singh | ebee854 | 2012-11-22 14:46:27 +0900 | [diff] [blame] | 211 | |
| 212 | /* Clear SLEEP mode set in INFORM1 */ |
| 213 | __raw_writel(0x0, S5P_INFORM1); |
| 214 | |
Jaecheol Lee | e240ab1c | 2011-07-18 19:21:34 +0900 | [diff] [blame] | 215 | return; |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 216 | } |
| 217 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 218 | static struct syscore_ops exynos_pm_syscore_ops = { |
| 219 | .suspend = exynos_pm_suspend, |
| 220 | .resume = exynos_pm_resume, |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 221 | }; |
| 222 | |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 223 | static __init int exynos_pm_syscore_init(void) |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 224 | { |
Kukjin Kim | e085cad | 2013-06-26 22:29:44 +0900 | [diff] [blame] | 225 | if (soc_is_exynos5440()) |
| 226 | return 0; |
| 227 | |
Jongpill Lee | c934710 | 2012-02-17 09:49:54 +0900 | [diff] [blame] | 228 | register_syscore_ops(&exynos_pm_syscore_ops); |
Rafael J. Wysocki | bb072c3 | 2011-04-22 22:03:21 +0200 | [diff] [blame] | 229 | return 0; |
Jaecheol Lee | 1663895 | 2011-03-10 13:33:59 +0900 | [diff] [blame] | 230 | } |
Jongpill Lee | 60e49ca | 2012-02-17 12:23:51 +0900 | [diff] [blame] | 231 | arch_initcall(exynos_pm_syscore_init); |