Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 1 | /* |
Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 2 | * Copyright 2011-2013 Freescale Semiconductor, Inc. |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 3 | * Copyright 2011 Linaro Ltd. |
| 4 | * |
| 5 | * The code contained herein is licensed under the GNU General Public |
| 6 | * License. You may obtain a copy of the GNU General Public License |
| 7 | * Version 2 or later at the following locations: |
| 8 | * |
| 9 | * http://www.opensource.org/licenses/gpl-license.html |
| 10 | * http://www.gnu.org/copyleft/gpl.html |
| 11 | */ |
| 12 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 13 | #include <linux/delay.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 14 | #include <linux/init.h> |
| 15 | #include <linux/io.h> |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 16 | #include <linux/irq.h> |
| 17 | #include <linux/mfd/syscon.h> |
| 18 | #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 19 | #include <linux/of.h> |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 20 | #include <linux/of_address.h> |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 21 | #include <linux/regmap.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 22 | #include <linux/suspend.h> |
| 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/proc-fns.h> |
| 25 | #include <asm/suspend.h> |
| 26 | #include <asm/hardware/cache-l2x0.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 27 | |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 28 | #include "common.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 29 | #include "hardware.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 30 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 31 | #define CCR 0x0 |
| 32 | #define BM_CCR_WB_COUNT (0x7 << 16) |
| 33 | #define BM_CCR_RBC_BYPASS_COUNT (0x3f << 21) |
| 34 | #define BM_CCR_RBC_EN (0x1 << 27) |
| 35 | |
| 36 | #define CLPCR 0x54 |
| 37 | #define BP_CLPCR_LPM 0 |
| 38 | #define BM_CLPCR_LPM (0x3 << 0) |
| 39 | #define BM_CLPCR_BYPASS_PMIC_READY (0x1 << 2) |
| 40 | #define BM_CLPCR_ARM_CLK_DIS_ON_LPM (0x1 << 5) |
| 41 | #define BM_CLPCR_SBYOS (0x1 << 6) |
| 42 | #define BM_CLPCR_DIS_REF_OSC (0x1 << 7) |
| 43 | #define BM_CLPCR_VSTBY (0x1 << 8) |
| 44 | #define BP_CLPCR_STBY_COUNT 9 |
| 45 | #define BM_CLPCR_STBY_COUNT (0x3 << 9) |
| 46 | #define BM_CLPCR_COSC_PWRDOWN (0x1 << 11) |
| 47 | #define BM_CLPCR_WB_PER_AT_LPM (0x1 << 16) |
| 48 | #define BM_CLPCR_WB_CORE_AT_LPM (0x1 << 17) |
| 49 | #define BM_CLPCR_BYP_MMDC_CH0_LPM_HS (0x1 << 19) |
| 50 | #define BM_CLPCR_BYP_MMDC_CH1_LPM_HS (0x1 << 21) |
| 51 | #define BM_CLPCR_MASK_CORE0_WFI (0x1 << 22) |
| 52 | #define BM_CLPCR_MASK_CORE1_WFI (0x1 << 23) |
| 53 | #define BM_CLPCR_MASK_CORE2_WFI (0x1 << 24) |
| 54 | #define BM_CLPCR_MASK_CORE3_WFI (0x1 << 25) |
| 55 | #define BM_CLPCR_MASK_SCU_IDLE (0x1 << 26) |
| 56 | #define BM_CLPCR_MASK_L2CC_IDLE (0x1 << 27) |
| 57 | |
| 58 | #define CGPR 0x64 |
| 59 | #define BM_CGPR_CHICKEN_BIT (0x1 << 17) |
| 60 | |
| 61 | static void __iomem *ccm_base; |
| 62 | |
| 63 | void imx6q_set_chicken_bit(void) |
| 64 | { |
| 65 | u32 val = readl_relaxed(ccm_base + CGPR); |
| 66 | |
| 67 | val |= BM_CGPR_CHICKEN_BIT; |
| 68 | writel_relaxed(val, ccm_base + CGPR); |
| 69 | } |
| 70 | |
| 71 | static void imx6q_enable_rbc(bool enable) |
| 72 | { |
| 73 | u32 val; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 74 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 75 | /* |
| 76 | * need to mask all interrupts in GPC before |
| 77 | * operating RBC configurations |
| 78 | */ |
| 79 | imx_gpc_mask_all(); |
| 80 | |
| 81 | /* configure RBC enable bit */ |
| 82 | val = readl_relaxed(ccm_base + CCR); |
| 83 | val &= ~BM_CCR_RBC_EN; |
| 84 | val |= enable ? BM_CCR_RBC_EN : 0; |
| 85 | writel_relaxed(val, ccm_base + CCR); |
| 86 | |
| 87 | /* configure RBC count */ |
| 88 | val = readl_relaxed(ccm_base + CCR); |
| 89 | val &= ~BM_CCR_RBC_BYPASS_COUNT; |
| 90 | val |= enable ? BM_CCR_RBC_BYPASS_COUNT : 0; |
| 91 | writel(val, ccm_base + CCR); |
| 92 | |
| 93 | /* |
| 94 | * need to delay at least 2 cycles of CKIL(32K) |
| 95 | * due to hardware design requirement, which is |
| 96 | * ~61us, here we use 65us for safe |
| 97 | */ |
| 98 | udelay(65); |
| 99 | |
| 100 | /* restore GPC interrupt mask settings */ |
| 101 | imx_gpc_restore_all(); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 102 | } |
| 103 | |
| 104 | static void imx6q_enable_wb(bool enable) |
| 105 | { |
| 106 | u32 val; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 107 | |
| 108 | /* configure well bias enable bit */ |
| 109 | val = readl_relaxed(ccm_base + CLPCR); |
| 110 | val &= ~BM_CLPCR_WB_PER_AT_LPM; |
| 111 | val |= enable ? BM_CLPCR_WB_PER_AT_LPM : 0; |
| 112 | writel_relaxed(val, ccm_base + CLPCR); |
| 113 | |
| 114 | /* configure well bias count */ |
| 115 | val = readl_relaxed(ccm_base + CCR); |
| 116 | val &= ~BM_CCR_WB_COUNT; |
| 117 | val |= enable ? BM_CCR_WB_COUNT : 0; |
| 118 | writel_relaxed(val, ccm_base + CCR); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode) |
| 122 | { |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 123 | struct irq_desc *iomuxc_irq_desc; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 124 | u32 val = readl_relaxed(ccm_base + CLPCR); |
| 125 | |
| 126 | val &= ~BM_CLPCR_LPM; |
| 127 | switch (mode) { |
| 128 | case WAIT_CLOCKED: |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 129 | break; |
| 130 | case WAIT_UNCLOCKED: |
| 131 | val |= 0x1 << BP_CLPCR_LPM; |
| 132 | val |= BM_CLPCR_ARM_CLK_DIS_ON_LPM; |
| 133 | break; |
| 134 | case STOP_POWER_ON: |
| 135 | val |= 0x2 << BP_CLPCR_LPM; |
| 136 | break; |
| 137 | case WAIT_UNCLOCKED_POWER_OFF: |
| 138 | val |= 0x1 << BP_CLPCR_LPM; |
| 139 | val &= ~BM_CLPCR_VSTBY; |
| 140 | val &= ~BM_CLPCR_SBYOS; |
| 141 | break; |
| 142 | case STOP_POWER_OFF: |
| 143 | val |= 0x2 << BP_CLPCR_LPM; |
| 144 | val |= 0x3 << BP_CLPCR_STBY_COUNT; |
| 145 | val |= BM_CLPCR_VSTBY; |
| 146 | val |= BM_CLPCR_SBYOS; |
Shawn Guo | 9ba64fe | 2013-10-17 10:07:09 +0800 | [diff] [blame] | 147 | if (cpu_is_imx6sl()) { |
| 148 | val |= BM_CLPCR_BYPASS_PMIC_READY; |
| 149 | val |= BM_CLPCR_BYP_MMDC_CH0_LPM_HS; |
| 150 | } else { |
| 151 | val |= BM_CLPCR_BYP_MMDC_CH1_LPM_HS; |
| 152 | } |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 153 | break; |
| 154 | default: |
| 155 | return -EINVAL; |
| 156 | } |
| 157 | |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 158 | /* |
Anson Huang | 48c9584 | 2013-12-24 17:19:21 -0500 | [diff] [blame] | 159 | * ERR007265: CCM: When improper low-power sequence is used, |
| 160 | * the SoC enters low power mode before the ARM core executes WFI. |
| 161 | * |
| 162 | * Software workaround: |
| 163 | * 1) Software should trigger IRQ #32 (IOMUX) to be always pending |
| 164 | * by setting IOMUX_GPR1_GINT. |
| 165 | * 2) Software should then unmask IRQ #32 in GPC before setting CCM |
| 166 | * Low-Power mode. |
| 167 | * 3) Software should mask IRQ #32 right after CCM Low-Power mode |
| 168 | * is set (set bits 0-1 of CCM_CLPCR). |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 169 | */ |
| 170 | iomuxc_irq_desc = irq_to_desc(32); |
| 171 | imx_gpc_irq_unmask(&iomuxc_irq_desc->irq_data); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 172 | writel_relaxed(val, ccm_base + CLPCR); |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 173 | imx_gpc_irq_mask(&iomuxc_irq_desc->irq_data); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 174 | |
| 175 | return 0; |
| 176 | } |
| 177 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 178 | static int imx6q_suspend_finish(unsigned long val) |
| 179 | { |
| 180 | cpu_do_idle(); |
| 181 | return 0; |
| 182 | } |
| 183 | |
| 184 | static int imx6q_pm_enter(suspend_state_t state) |
| 185 | { |
| 186 | switch (state) { |
| 187 | case PM_SUSPEND_MEM: |
| 188 | imx6q_set_lpm(STOP_POWER_OFF); |
Shawn Guo | 1d674a7 | 2013-10-09 20:31:28 +0800 | [diff] [blame] | 189 | imx6q_enable_wb(true); |
| 190 | imx6q_enable_rbc(true); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 191 | imx_gpc_pre_suspend(); |
Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 192 | imx_anatop_pre_suspend(); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 193 | imx_set_cpu_jump(0, v7_cpu_resume); |
| 194 | /* Zzz ... */ |
| 195 | cpu_suspend(0, imx6q_suspend_finish); |
Shawn Guo | 9ba64fe | 2013-10-17 10:07:09 +0800 | [diff] [blame] | 196 | if (cpu_is_imx6q() || cpu_is_imx6dl()) |
| 197 | imx_smp_prepare(); |
Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 198 | imx_anatop_post_resume(); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 199 | imx_gpc_post_resume(); |
Shawn Guo | 1d674a7 | 2013-10-09 20:31:28 +0800 | [diff] [blame] | 200 | imx6q_enable_rbc(false); |
| 201 | imx6q_enable_wb(false); |
Shawn Guo | 83ae2098 | 2013-01-14 21:11:10 +0800 | [diff] [blame] | 202 | imx6q_set_lpm(WAIT_CLOCKED); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 203 | break; |
| 204 | default: |
| 205 | return -EINVAL; |
| 206 | } |
| 207 | |
| 208 | return 0; |
| 209 | } |
| 210 | |
| 211 | static const struct platform_suspend_ops imx6q_pm_ops = { |
| 212 | .enter = imx6q_pm_enter, |
| 213 | .valid = suspend_valid_only_mem, |
| 214 | }; |
| 215 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 216 | void __init imx6q_pm_set_ccm_base(void __iomem *base) |
| 217 | { |
| 218 | ccm_base = base; |
| 219 | } |
| 220 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 221 | void __init imx6q_pm_init(void) |
| 222 | { |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 223 | struct regmap *gpr; |
| 224 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 225 | WARN_ON(!ccm_base); |
| 226 | |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 227 | /* |
Anson Huang | 48c9584 | 2013-12-24 17:19:21 -0500 | [diff] [blame] | 228 | * This is for SW workaround step #1 of ERR007265, see comments |
| 229 | * in imx6q_set_lpm for details of this errata. |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 230 | * Force IOMUXC irq pending, so that the interrupt to GPC can be |
| 231 | * used to deassert dsm_request signal when the signal gets |
| 232 | * asserted unexpectedly. |
| 233 | */ |
| 234 | gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr"); |
| 235 | if (!IS_ERR(gpr)) |
| 236 | regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT, |
| 237 | IMX6Q_GPR1_GINT); |
| 238 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 239 | /* Set initial power mode */ |
| 240 | imx6q_set_lpm(WAIT_CLOCKED); |
| 241 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 242 | suspend_set_ops(&imx6q_pm_ops); |
| 243 | } |