Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 1 | /* |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 2 | * Copyright 2011-2014 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> |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 17 | #include <linux/genalloc.h> |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 18 | #include <linux/mfd/syscon.h> |
| 19 | #include <linux/mfd/syscon/imx6q-iomuxc-gpr.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 20 | #include <linux/of.h> |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 21 | #include <linux/of_address.h> |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 22 | #include <linux/of_platform.h> |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 23 | #include <linux/regmap.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 24 | #include <linux/suspend.h> |
| 25 | #include <asm/cacheflush.h> |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 26 | #include <asm/fncpy.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 27 | #include <asm/proc-fns.h> |
| 28 | #include <asm/suspend.h> |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 29 | #include <asm/tlb.h> |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 30 | |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 31 | #include "common.h" |
Shawn Guo | 50f2de6 | 2012-09-14 14:14:45 +0800 | [diff] [blame] | 32 | #include "hardware.h" |
Shawn Guo | e337247 | 2012-09-13 21:01:00 +0800 | [diff] [blame] | 33 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 34 | #define CCR 0x0 |
| 35 | #define BM_CCR_WB_COUNT (0x7 << 16) |
| 36 | #define BM_CCR_RBC_BYPASS_COUNT (0x3f << 21) |
| 37 | #define BM_CCR_RBC_EN (0x1 << 27) |
| 38 | |
| 39 | #define CLPCR 0x54 |
| 40 | #define BP_CLPCR_LPM 0 |
| 41 | #define BM_CLPCR_LPM (0x3 << 0) |
| 42 | #define BM_CLPCR_BYPASS_PMIC_READY (0x1 << 2) |
| 43 | #define BM_CLPCR_ARM_CLK_DIS_ON_LPM (0x1 << 5) |
| 44 | #define BM_CLPCR_SBYOS (0x1 << 6) |
| 45 | #define BM_CLPCR_DIS_REF_OSC (0x1 << 7) |
| 46 | #define BM_CLPCR_VSTBY (0x1 << 8) |
| 47 | #define BP_CLPCR_STBY_COUNT 9 |
| 48 | #define BM_CLPCR_STBY_COUNT (0x3 << 9) |
| 49 | #define BM_CLPCR_COSC_PWRDOWN (0x1 << 11) |
| 50 | #define BM_CLPCR_WB_PER_AT_LPM (0x1 << 16) |
| 51 | #define BM_CLPCR_WB_CORE_AT_LPM (0x1 << 17) |
| 52 | #define BM_CLPCR_BYP_MMDC_CH0_LPM_HS (0x1 << 19) |
| 53 | #define BM_CLPCR_BYP_MMDC_CH1_LPM_HS (0x1 << 21) |
| 54 | #define BM_CLPCR_MASK_CORE0_WFI (0x1 << 22) |
| 55 | #define BM_CLPCR_MASK_CORE1_WFI (0x1 << 23) |
| 56 | #define BM_CLPCR_MASK_CORE2_WFI (0x1 << 24) |
| 57 | #define BM_CLPCR_MASK_CORE3_WFI (0x1 << 25) |
| 58 | #define BM_CLPCR_MASK_SCU_IDLE (0x1 << 26) |
| 59 | #define BM_CLPCR_MASK_L2CC_IDLE (0x1 << 27) |
| 60 | |
| 61 | #define CGPR 0x64 |
Fabio Estevam | fa6be65 | 2014-01-07 08:00:40 -0200 | [diff] [blame] | 62 | #define BM_CGPR_INT_MEM_CLK_LPM (0x1 << 17) |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 63 | |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 64 | #define MX6Q_SUSPEND_OCRAM_SIZE 0x1000 |
| 65 | #define MX6_MAX_MMDC_IO_NUM 33 |
| 66 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 67 | static void __iomem *ccm_base; |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 68 | static void __iomem *suspend_ocram_base; |
| 69 | static void (*imx6_suspend_in_ocram_fn)(void __iomem *ocram_vbase); |
| 70 | |
| 71 | /* |
| 72 | * suspend ocram space layout: |
| 73 | * ======================== high address ====================== |
| 74 | * . |
| 75 | * . |
| 76 | * . |
| 77 | * ^ |
| 78 | * ^ |
| 79 | * ^ |
| 80 | * imx6_suspend code |
| 81 | * PM_INFO structure(imx6_cpu_pm_info) |
| 82 | * ======================== low address ======================= |
| 83 | */ |
| 84 | |
| 85 | struct imx6_pm_base { |
| 86 | phys_addr_t pbase; |
| 87 | void __iomem *vbase; |
| 88 | }; |
| 89 | |
| 90 | struct imx6_pm_socdata { |
| 91 | u32 cpu_type; |
| 92 | const char *mmdc_compat; |
| 93 | const char *src_compat; |
| 94 | const char *iomuxc_compat; |
| 95 | const char *gpc_compat; |
| 96 | const u32 mmdc_io_num; |
| 97 | const u32 *mmdc_io_offset; |
| 98 | }; |
| 99 | |
| 100 | static const u32 imx6q_mmdc_io_offset[] __initconst = { |
| 101 | 0x5ac, 0x5b4, 0x528, 0x520, /* DQM0 ~ DQM3 */ |
| 102 | 0x514, 0x510, 0x5bc, 0x5c4, /* DQM4 ~ DQM7 */ |
| 103 | 0x56c, 0x578, 0x588, 0x594, /* CAS, RAS, SDCLK_0, SDCLK_1 */ |
| 104 | 0x5a8, 0x5b0, 0x524, 0x51c, /* SDQS0 ~ SDQS3 */ |
| 105 | 0x518, 0x50c, 0x5b8, 0x5c0, /* SDQS4 ~ SDQS7 */ |
| 106 | 0x784, 0x788, 0x794, 0x79c, /* GPR_B0DS ~ GPR_B3DS */ |
| 107 | 0x7a0, 0x7a4, 0x7a8, 0x748, /* GPR_B4DS ~ GPR_B7DS */ |
| 108 | 0x59c, 0x5a0, 0x750, 0x774, /* SODT0, SODT1, MODE_CTL, MODE */ |
| 109 | 0x74c, /* GPR_ADDS */ |
| 110 | }; |
| 111 | |
Anson Huang | da9e926 | 2014-01-17 11:39:06 +0800 | [diff] [blame^] | 112 | static const u32 imx6dl_mmdc_io_offset[] __initconst = { |
| 113 | 0x470, 0x474, 0x478, 0x47c, /* DQM0 ~ DQM3 */ |
| 114 | 0x480, 0x484, 0x488, 0x48c, /* DQM4 ~ DQM7 */ |
| 115 | 0x464, 0x490, 0x4ac, 0x4b0, /* CAS, RAS, SDCLK_0, SDCLK_1 */ |
| 116 | 0x4bc, 0x4c0, 0x4c4, 0x4c8, /* DRAM_SDQS0 ~ DRAM_SDQS3 */ |
| 117 | 0x4cc, 0x4d0, 0x4d4, 0x4d8, /* DRAM_SDQS4 ~ DRAM_SDQS7 */ |
| 118 | 0x764, 0x770, 0x778, 0x77c, /* GPR_B0DS ~ GPR_B3DS */ |
| 119 | 0x780, 0x784, 0x78c, 0x748, /* GPR_B4DS ~ GPR_B7DS */ |
| 120 | 0x4b4, 0x4b8, 0x750, 0x760, /* SODT0, SODT1, MODE_CTL, MODE */ |
| 121 | 0x74c, /* GPR_ADDS */ |
| 122 | }; |
| 123 | |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 124 | static const struct imx6_pm_socdata imx6q_pm_data __initconst = { |
| 125 | .cpu_type = MXC_CPU_IMX6Q, |
| 126 | .mmdc_compat = "fsl,imx6q-mmdc", |
| 127 | .src_compat = "fsl,imx6q-src", |
| 128 | .iomuxc_compat = "fsl,imx6q-iomuxc", |
| 129 | .gpc_compat = "fsl,imx6q-gpc", |
| 130 | .mmdc_io_num = ARRAY_SIZE(imx6q_mmdc_io_offset), |
| 131 | .mmdc_io_offset = imx6q_mmdc_io_offset, |
| 132 | }; |
| 133 | |
Anson Huang | da9e926 | 2014-01-17 11:39:06 +0800 | [diff] [blame^] | 134 | static const struct imx6_pm_socdata imx6dl_pm_data __initconst = { |
| 135 | .cpu_type = MXC_CPU_IMX6DL, |
| 136 | .mmdc_compat = "fsl,imx6q-mmdc", |
| 137 | .src_compat = "fsl,imx6q-src", |
| 138 | .iomuxc_compat = "fsl,imx6dl-iomuxc", |
| 139 | .gpc_compat = "fsl,imx6q-gpc", |
| 140 | .mmdc_io_num = ARRAY_SIZE(imx6dl_mmdc_io_offset), |
| 141 | .mmdc_io_offset = imx6dl_mmdc_io_offset, |
| 142 | }; |
| 143 | |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 144 | /* |
| 145 | * This structure is for passing necessary data for low level ocram |
| 146 | * suspend code(arch/arm/mach-imx/suspend-imx6.S), if this struct |
| 147 | * definition is changed, the offset definition in |
| 148 | * arch/arm/mach-imx/suspend-imx6.S must be also changed accordingly, |
| 149 | * otherwise, the suspend to ocram function will be broken! |
| 150 | */ |
| 151 | struct imx6_cpu_pm_info { |
| 152 | phys_addr_t pbase; /* The physical address of pm_info. */ |
| 153 | phys_addr_t resume_addr; /* The physical resume address for asm code */ |
| 154 | u32 cpu_type; |
| 155 | u32 pm_info_size; /* Size of pm_info. */ |
| 156 | struct imx6_pm_base mmdc_base; |
| 157 | struct imx6_pm_base src_base; |
| 158 | struct imx6_pm_base iomuxc_base; |
| 159 | struct imx6_pm_base ccm_base; |
| 160 | struct imx6_pm_base gpc_base; |
| 161 | struct imx6_pm_base l2_base; |
| 162 | u32 mmdc_io_num; /* Number of MMDC IOs which need saved/restored. */ |
| 163 | u32 mmdc_io_val[MX6_MAX_MMDC_IO_NUM][2]; /* To save offset and value */ |
| 164 | } __aligned(8); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 165 | |
Fabio Estevam | fa6be65 | 2014-01-07 08:00:40 -0200 | [diff] [blame] | 166 | void imx6q_set_int_mem_clk_lpm(void) |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 167 | { |
| 168 | u32 val = readl_relaxed(ccm_base + CGPR); |
| 169 | |
Fabio Estevam | fa6be65 | 2014-01-07 08:00:40 -0200 | [diff] [blame] | 170 | val |= BM_CGPR_INT_MEM_CLK_LPM; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 171 | writel_relaxed(val, ccm_base + CGPR); |
| 172 | } |
| 173 | |
| 174 | static void imx6q_enable_rbc(bool enable) |
| 175 | { |
| 176 | u32 val; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 177 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 178 | /* |
| 179 | * need to mask all interrupts in GPC before |
| 180 | * operating RBC configurations |
| 181 | */ |
| 182 | imx_gpc_mask_all(); |
| 183 | |
| 184 | /* configure RBC enable bit */ |
| 185 | val = readl_relaxed(ccm_base + CCR); |
| 186 | val &= ~BM_CCR_RBC_EN; |
| 187 | val |= enable ? BM_CCR_RBC_EN : 0; |
| 188 | writel_relaxed(val, ccm_base + CCR); |
| 189 | |
| 190 | /* configure RBC count */ |
| 191 | val = readl_relaxed(ccm_base + CCR); |
| 192 | val &= ~BM_CCR_RBC_BYPASS_COUNT; |
| 193 | val |= enable ? BM_CCR_RBC_BYPASS_COUNT : 0; |
| 194 | writel(val, ccm_base + CCR); |
| 195 | |
| 196 | /* |
| 197 | * need to delay at least 2 cycles of CKIL(32K) |
| 198 | * due to hardware design requirement, which is |
| 199 | * ~61us, here we use 65us for safe |
| 200 | */ |
| 201 | udelay(65); |
| 202 | |
| 203 | /* restore GPC interrupt mask settings */ |
| 204 | imx_gpc_restore_all(); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void imx6q_enable_wb(bool enable) |
| 208 | { |
| 209 | u32 val; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 210 | |
| 211 | /* configure well bias enable bit */ |
| 212 | val = readl_relaxed(ccm_base + CLPCR); |
| 213 | val &= ~BM_CLPCR_WB_PER_AT_LPM; |
| 214 | val |= enable ? BM_CLPCR_WB_PER_AT_LPM : 0; |
| 215 | writel_relaxed(val, ccm_base + CLPCR); |
| 216 | |
| 217 | /* configure well bias count */ |
| 218 | val = readl_relaxed(ccm_base + CCR); |
| 219 | val &= ~BM_CCR_WB_COUNT; |
| 220 | val |= enable ? BM_CCR_WB_COUNT : 0; |
| 221 | writel_relaxed(val, ccm_base + CCR); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 222 | } |
| 223 | |
| 224 | int imx6q_set_lpm(enum mxc_cpu_pwr_mode mode) |
| 225 | { |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 226 | struct irq_desc *iomuxc_irq_desc; |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 227 | u32 val = readl_relaxed(ccm_base + CLPCR); |
| 228 | |
| 229 | val &= ~BM_CLPCR_LPM; |
| 230 | switch (mode) { |
| 231 | case WAIT_CLOCKED: |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 232 | break; |
| 233 | case WAIT_UNCLOCKED: |
| 234 | val |= 0x1 << BP_CLPCR_LPM; |
| 235 | val |= BM_CLPCR_ARM_CLK_DIS_ON_LPM; |
| 236 | break; |
| 237 | case STOP_POWER_ON: |
| 238 | val |= 0x2 << BP_CLPCR_LPM; |
| 239 | break; |
| 240 | case WAIT_UNCLOCKED_POWER_OFF: |
| 241 | val |= 0x1 << BP_CLPCR_LPM; |
| 242 | val &= ~BM_CLPCR_VSTBY; |
| 243 | val &= ~BM_CLPCR_SBYOS; |
| 244 | break; |
| 245 | case STOP_POWER_OFF: |
| 246 | val |= 0x2 << BP_CLPCR_LPM; |
| 247 | val |= 0x3 << BP_CLPCR_STBY_COUNT; |
| 248 | val |= BM_CLPCR_VSTBY; |
| 249 | val |= BM_CLPCR_SBYOS; |
Shawn Guo | 9ba64fe | 2013-10-17 10:07:09 +0800 | [diff] [blame] | 250 | if (cpu_is_imx6sl()) { |
| 251 | val |= BM_CLPCR_BYPASS_PMIC_READY; |
| 252 | val |= BM_CLPCR_BYP_MMDC_CH0_LPM_HS; |
| 253 | } else { |
| 254 | val |= BM_CLPCR_BYP_MMDC_CH1_LPM_HS; |
| 255 | } |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 256 | break; |
| 257 | default: |
| 258 | return -EINVAL; |
| 259 | } |
| 260 | |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 261 | /* |
Anson Huang | 48c9584 | 2013-12-24 17:19:21 -0500 | [diff] [blame] | 262 | * ERR007265: CCM: When improper low-power sequence is used, |
| 263 | * the SoC enters low power mode before the ARM core executes WFI. |
| 264 | * |
| 265 | * Software workaround: |
| 266 | * 1) Software should trigger IRQ #32 (IOMUX) to be always pending |
| 267 | * by setting IOMUX_GPR1_GINT. |
| 268 | * 2) Software should then unmask IRQ #32 in GPC before setting CCM |
| 269 | * Low-Power mode. |
| 270 | * 3) Software should mask IRQ #32 right after CCM Low-Power mode |
| 271 | * is set (set bits 0-1 of CCM_CLPCR). |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 272 | */ |
| 273 | iomuxc_irq_desc = irq_to_desc(32); |
| 274 | imx_gpc_irq_unmask(&iomuxc_irq_desc->irq_data); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 275 | writel_relaxed(val, ccm_base + CLPCR); |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 276 | imx_gpc_irq_mask(&iomuxc_irq_desc->irq_data); |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 277 | |
| 278 | return 0; |
| 279 | } |
| 280 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 281 | static int imx6q_suspend_finish(unsigned long val) |
| 282 | { |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 283 | if (!imx6_suspend_in_ocram_fn) { |
| 284 | cpu_do_idle(); |
| 285 | } else { |
| 286 | /* |
| 287 | * call low level suspend function in ocram, |
| 288 | * as we need to float DDR IO. |
| 289 | */ |
| 290 | local_flush_tlb_all(); |
| 291 | imx6_suspend_in_ocram_fn(suspend_ocram_base); |
| 292 | } |
| 293 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
| 297 | static int imx6q_pm_enter(suspend_state_t state) |
| 298 | { |
| 299 | switch (state) { |
| 300 | case PM_SUSPEND_MEM: |
| 301 | imx6q_set_lpm(STOP_POWER_OFF); |
Shawn Guo | 1d674a7 | 2013-10-09 20:31:28 +0800 | [diff] [blame] | 302 | imx6q_enable_wb(true); |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 303 | /* |
| 304 | * For suspend into ocram, asm code already take care of |
| 305 | * RBC setting, so we do NOT need to do that here. |
| 306 | */ |
| 307 | if (!imx6_suspend_in_ocram_fn) |
| 308 | imx6q_enable_rbc(true); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 309 | imx_gpc_pre_suspend(); |
Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 310 | imx_anatop_pre_suspend(); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 311 | imx_set_cpu_jump(0, v7_cpu_resume); |
| 312 | /* Zzz ... */ |
| 313 | cpu_suspend(0, imx6q_suspend_finish); |
Shawn Guo | 9ba64fe | 2013-10-17 10:07:09 +0800 | [diff] [blame] | 314 | if (cpu_is_imx6q() || cpu_is_imx6dl()) |
| 315 | imx_smp_prepare(); |
Anson Huang | e95dddb | 2013-03-20 19:39:42 -0400 | [diff] [blame] | 316 | imx_anatop_post_resume(); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 317 | imx_gpc_post_resume(); |
Shawn Guo | 1d674a7 | 2013-10-09 20:31:28 +0800 | [diff] [blame] | 318 | imx6q_enable_rbc(false); |
| 319 | imx6q_enable_wb(false); |
Shawn Guo | 83ae2098 | 2013-01-14 21:11:10 +0800 | [diff] [blame] | 320 | imx6q_set_lpm(WAIT_CLOCKED); |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 321 | break; |
| 322 | default: |
| 323 | return -EINVAL; |
| 324 | } |
| 325 | |
| 326 | return 0; |
| 327 | } |
| 328 | |
| 329 | static const struct platform_suspend_ops imx6q_pm_ops = { |
| 330 | .enter = imx6q_pm_enter, |
| 331 | .valid = suspend_valid_only_mem, |
| 332 | }; |
| 333 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 334 | void __init imx6q_pm_set_ccm_base(void __iomem *base) |
| 335 | { |
| 336 | ccm_base = base; |
| 337 | } |
| 338 | |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 339 | static int __init imx6_pm_get_base(struct imx6_pm_base *base, |
| 340 | const char *compat) |
| 341 | { |
| 342 | struct device_node *node; |
| 343 | struct resource res; |
| 344 | int ret = 0; |
| 345 | |
| 346 | node = of_find_compatible_node(NULL, NULL, compat); |
| 347 | if (!node) { |
| 348 | ret = -ENODEV; |
| 349 | goto out; |
| 350 | } |
| 351 | |
| 352 | ret = of_address_to_resource(node, 0, &res); |
| 353 | if (ret) |
| 354 | goto put_node; |
| 355 | |
| 356 | base->pbase = res.start; |
| 357 | base->vbase = ioremap(res.start, resource_size(&res)); |
| 358 | if (!base->vbase) |
| 359 | ret = -ENOMEM; |
| 360 | |
| 361 | put_node: |
| 362 | of_node_put(node); |
| 363 | out: |
| 364 | return ret; |
| 365 | } |
| 366 | |
| 367 | static int __init imx6q_ocram_suspend_init(const struct imx6_pm_socdata |
| 368 | *socdata) |
| 369 | { |
| 370 | phys_addr_t ocram_pbase; |
| 371 | struct device_node *node; |
| 372 | struct platform_device *pdev; |
| 373 | struct imx6_cpu_pm_info *pm_info; |
| 374 | struct gen_pool *ocram_pool; |
| 375 | unsigned long ocram_base; |
| 376 | int i, ret = 0; |
| 377 | const u32 *mmdc_offset_array; |
| 378 | |
| 379 | if (!socdata) { |
| 380 | pr_warn("%s: invalid argument!\n", __func__); |
| 381 | return -EINVAL; |
| 382 | } |
| 383 | |
| 384 | node = of_find_compatible_node(NULL, NULL, "mmio-sram"); |
| 385 | if (!node) { |
| 386 | pr_warn("%s: failed to find ocram node!\n", __func__); |
| 387 | return -ENODEV; |
| 388 | } |
| 389 | |
| 390 | pdev = of_find_device_by_node(node); |
| 391 | if (!pdev) { |
| 392 | pr_warn("%s: failed to find ocram device!\n", __func__); |
| 393 | ret = -ENODEV; |
| 394 | goto put_node; |
| 395 | } |
| 396 | |
| 397 | ocram_pool = dev_get_gen_pool(&pdev->dev); |
| 398 | if (!ocram_pool) { |
| 399 | pr_warn("%s: ocram pool unavailable!\n", __func__); |
| 400 | ret = -ENODEV; |
| 401 | goto put_node; |
| 402 | } |
| 403 | |
| 404 | ocram_base = gen_pool_alloc(ocram_pool, MX6Q_SUSPEND_OCRAM_SIZE); |
| 405 | if (!ocram_base) { |
| 406 | pr_warn("%s: unable to alloc ocram!\n", __func__); |
| 407 | ret = -ENOMEM; |
| 408 | goto put_node; |
| 409 | } |
| 410 | |
| 411 | ocram_pbase = gen_pool_virt_to_phys(ocram_pool, ocram_base); |
| 412 | |
| 413 | suspend_ocram_base = __arm_ioremap_exec(ocram_pbase, |
| 414 | MX6Q_SUSPEND_OCRAM_SIZE, false); |
| 415 | |
| 416 | pm_info = suspend_ocram_base; |
| 417 | pm_info->pbase = ocram_pbase; |
| 418 | pm_info->resume_addr = virt_to_phys(v7_cpu_resume); |
| 419 | pm_info->pm_info_size = sizeof(*pm_info); |
| 420 | |
| 421 | /* |
| 422 | * ccm physical address is not used by asm code currently, |
| 423 | * so get ccm virtual address directly, as we already have |
| 424 | * it from ccm driver. |
| 425 | */ |
| 426 | pm_info->ccm_base.vbase = ccm_base; |
| 427 | |
| 428 | ret = imx6_pm_get_base(&pm_info->mmdc_base, socdata->mmdc_compat); |
| 429 | if (ret) { |
| 430 | pr_warn("%s: failed to get mmdc base %d!\n", __func__, ret); |
| 431 | goto put_node; |
| 432 | } |
| 433 | |
| 434 | ret = imx6_pm_get_base(&pm_info->src_base, socdata->src_compat); |
| 435 | if (ret) { |
| 436 | pr_warn("%s: failed to get src base %d!\n", __func__, ret); |
| 437 | goto src_map_failed; |
| 438 | } |
| 439 | |
| 440 | ret = imx6_pm_get_base(&pm_info->iomuxc_base, socdata->iomuxc_compat); |
| 441 | if (ret) { |
| 442 | pr_warn("%s: failed to get iomuxc base %d!\n", __func__, ret); |
| 443 | goto iomuxc_map_failed; |
| 444 | } |
| 445 | |
| 446 | ret = imx6_pm_get_base(&pm_info->gpc_base, socdata->gpc_compat); |
| 447 | if (ret) { |
| 448 | pr_warn("%s: failed to get gpc base %d!\n", __func__, ret); |
| 449 | goto gpc_map_failed; |
| 450 | } |
| 451 | |
| 452 | ret = imx6_pm_get_base(&pm_info->l2_base, "arm,pl310-cache"); |
| 453 | if (ret) { |
| 454 | pr_warn("%s: failed to get pl310-cache base %d!\n", |
| 455 | __func__, ret); |
| 456 | goto pl310_cache_map_failed; |
| 457 | } |
| 458 | |
| 459 | pm_info->cpu_type = socdata->cpu_type; |
| 460 | pm_info->mmdc_io_num = socdata->mmdc_io_num; |
| 461 | mmdc_offset_array = socdata->mmdc_io_offset; |
| 462 | |
| 463 | for (i = 0; i < pm_info->mmdc_io_num; i++) { |
| 464 | pm_info->mmdc_io_val[i][0] = |
| 465 | mmdc_offset_array[i]; |
| 466 | pm_info->mmdc_io_val[i][1] = |
| 467 | readl_relaxed(pm_info->iomuxc_base.vbase + |
| 468 | mmdc_offset_array[i]); |
| 469 | } |
| 470 | |
| 471 | imx6_suspend_in_ocram_fn = fncpy( |
| 472 | suspend_ocram_base + sizeof(*pm_info), |
| 473 | &imx6_suspend, |
| 474 | MX6Q_SUSPEND_OCRAM_SIZE - sizeof(*pm_info)); |
| 475 | |
| 476 | goto put_node; |
| 477 | |
| 478 | pl310_cache_map_failed: |
| 479 | iounmap(&pm_info->gpc_base.vbase); |
| 480 | gpc_map_failed: |
| 481 | iounmap(&pm_info->iomuxc_base.vbase); |
| 482 | iomuxc_map_failed: |
| 483 | iounmap(&pm_info->src_base.vbase); |
| 484 | src_map_failed: |
| 485 | iounmap(&pm_info->mmdc_base.vbase); |
| 486 | put_node: |
| 487 | of_node_put(node); |
| 488 | |
| 489 | return ret; |
| 490 | } |
| 491 | |
| 492 | static void __init imx6_pm_common_init(const struct imx6_pm_socdata |
| 493 | *socdata) |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 494 | { |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 495 | struct regmap *gpr; |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 496 | int ret; |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 497 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 498 | WARN_ON(!ccm_base); |
| 499 | |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 500 | ret = imx6q_ocram_suspend_init(socdata); |
| 501 | if (ret) |
| 502 | pr_warn("%s: failed to initialize ocram suspend %d!\n", |
| 503 | __func__, ret); |
| 504 | |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 505 | /* |
Anson Huang | 48c9584 | 2013-12-24 17:19:21 -0500 | [diff] [blame] | 506 | * This is for SW workaround step #1 of ERR007265, see comments |
| 507 | * in imx6q_set_lpm for details of this errata. |
Shawn Guo | d48866f | 2013-10-16 19:52:00 +0800 | [diff] [blame] | 508 | * Force IOMUXC irq pending, so that the interrupt to GPC can be |
| 509 | * used to deassert dsm_request signal when the signal gets |
| 510 | * asserted unexpectedly. |
| 511 | */ |
| 512 | gpr = syscon_regmap_lookup_by_compatible("fsl,imx6q-iomuxc-gpr"); |
| 513 | if (!IS_ERR(gpr)) |
| 514 | regmap_update_bits(gpr, IOMUXC_GPR1, IMX6Q_GPR1_GINT, |
| 515 | IMX6Q_GPR1_GINT); |
| 516 | |
Shawn Guo | 9e8147b | 2013-09-25 23:09:36 +0800 | [diff] [blame] | 517 | |
Shawn Guo | a1f1c7e | 2011-09-06 15:08:40 +0800 | [diff] [blame] | 518 | suspend_set_ops(&imx6q_pm_ops); |
| 519 | } |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 520 | |
| 521 | void __init imx6q_pm_init(void) |
| 522 | { |
| 523 | imx6_pm_common_init(&imx6q_pm_data); |
| 524 | } |
| 525 | |
| 526 | void __init imx6dl_pm_init(void) |
| 527 | { |
Anson Huang | da9e926 | 2014-01-17 11:39:06 +0800 | [diff] [blame^] | 528 | imx6_pm_common_init(&imx6dl_pm_data); |
Anson Huang | df59574 | 2014-01-17 11:39:05 +0800 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | void __init imx6sl_pm_init(void) |
| 532 | { |
| 533 | imx6_pm_common_init(NULL); |
| 534 | } |