pm-imx6.c 19 KB

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