pm-imx6.c 16 KB

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