pm-imx6.c 19 KB

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