4044-drivers-memory-Add-deep-sleep-support-for-IFC.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. From bb35d670afd2f3501de36c158e9842817ce013b8 Mon Sep 17 00:00:00 2001
  2. From: Raghav Dogra <raghav@freescale.com>
  3. Date: Fri, 15 Jan 2016 17:10:09 +0530
  4. Subject: [PATCH 44/70] drivers/memory: Add deep sleep support for IFC
  5. Add support of suspend, resume function to support deep sleep.
  6. Also make sure of SRAM initialization during resume.
  7. Signed-off-by: Raghav Dogra <raghav@freescale.com>
  8. ---
  9. drivers/memory/fsl_ifc.c | 163 ++++++++++++++++++++++++++++++++++++++++++++++
  10. include/linux/fsl_ifc.h | 6 ++
  11. 2 files changed, 169 insertions(+)
  12. --- a/drivers/memory/fsl_ifc.c
  13. +++ b/drivers/memory/fsl_ifc.c
  14. @@ -24,6 +24,7 @@
  15. #include <linux/compiler.h>
  16. #include <linux/sched.h>
  17. #include <linux/spinlock.h>
  18. +#include <linux/delay.h>
  19. #include <linux/types.h>
  20. #include <linux/slab.h>
  21. #include <linux/io.h>
  22. @@ -35,6 +36,8 @@
  23. struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;
  24. EXPORT_SYMBOL(fsl_ifc_ctrl_dev);
  25. +#define FSL_IFC_V1_3_0 0x01030000
  26. +#define IFC_TIMEOUT_MSECS 100000 /* 100ms */
  27. /*
  28. * convert_ifc_address - convert the base address
  29. @@ -309,6 +312,161 @@ err:
  30. return ret;
  31. }
  32. +#ifdef CONFIG_PM_SLEEP
  33. +/* save ifc registers */
  34. +static int fsl_ifc_suspend(struct device *dev)
  35. +{
  36. + struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(dev);
  37. + struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
  38. + __be32 nand_evter_intr_en, cm_evter_intr_en, nor_evter_intr_en,
  39. + gpcm_evter_intr_en;
  40. +
  41. + ctrl->saved_regs = kzalloc(sizeof(struct fsl_ifc_regs), GFP_KERNEL);
  42. + if (!ctrl->saved_regs)
  43. + return -ENOMEM;
  44. +
  45. + cm_evter_intr_en = ifc_in32(&ifc->cm_evter_intr_en);
  46. + nand_evter_intr_en = ifc_in32(&ifc->ifc_nand.nand_evter_intr_en);
  47. + nor_evter_intr_en = ifc_in32(&ifc->ifc_nor.nor_evter_intr_en);
  48. + gpcm_evter_intr_en = ifc_in32(&ifc->ifc_gpcm.gpcm_evter_intr_en);
  49. +
  50. +/* IFC interrupts disabled */
  51. +
  52. + ifc_out32(0x0, &ifc->cm_evter_intr_en);
  53. + ifc_out32(0x0, &ifc->ifc_nand.nand_evter_intr_en);
  54. + ifc_out32(0x0, &ifc->ifc_nor.nor_evter_intr_en);
  55. + ifc_out32(0x0, &ifc->ifc_gpcm.gpcm_evter_intr_en);
  56. +
  57. + memcpy_fromio(ctrl->saved_regs, ifc, sizeof(struct fsl_ifc_regs));
  58. +
  59. +/* save the interrupt values */
  60. + ctrl->saved_regs->cm_evter_intr_en = cm_evter_intr_en;
  61. + ctrl->saved_regs->ifc_nand.nand_evter_intr_en = nand_evter_intr_en;
  62. + ctrl->saved_regs->ifc_nor.nor_evter_intr_en = nor_evter_intr_en;
  63. + ctrl->saved_regs->ifc_gpcm.gpcm_evter_intr_en = gpcm_evter_intr_en;
  64. +
  65. + return 0;
  66. +}
  67. +
  68. +/* restore ifc registers */
  69. +static int fsl_ifc_resume(struct device *dev)
  70. +{
  71. + struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(dev);
  72. + struct fsl_ifc_regs __iomem *ifc = ctrl->regs;
  73. + struct fsl_ifc_regs *savd_regs = ctrl->saved_regs;
  74. + uint32_t ver = 0, ncfgr, status, ifc_bank, i;
  75. +
  76. +/*
  77. + * IFC interrupts disabled
  78. + */
  79. + ifc_out32(0x0, &ifc->cm_evter_intr_en);
  80. + ifc_out32(0x0, &ifc->ifc_nand.nand_evter_intr_en);
  81. + ifc_out32(0x0, &ifc->ifc_nor.nor_evter_intr_en);
  82. + ifc_out32(0x0, &ifc->ifc_gpcm.gpcm_evter_intr_en);
  83. +
  84. +
  85. + if (ctrl->saved_regs) {
  86. + for (ifc_bank = 0; ifc_bank < FSL_IFC_BANK_COUNT; ifc_bank++) {
  87. + ifc_out32(savd_regs->cspr_cs[ifc_bank].cspr_ext,
  88. + &ifc->cspr_cs[ifc_bank].cspr_ext);
  89. + ifc_out32(savd_regs->cspr_cs[ifc_bank].cspr,
  90. + &ifc->cspr_cs[ifc_bank].cspr);
  91. + ifc_out32(savd_regs->amask_cs[ifc_bank].amask,
  92. + &ifc->amask_cs[ifc_bank].amask);
  93. + ifc_out32(savd_regs->csor_cs[ifc_bank].csor_ext,
  94. + &ifc->csor_cs[ifc_bank].csor_ext);
  95. + ifc_out32(savd_regs->csor_cs[ifc_bank].csor,
  96. + &ifc->csor_cs[ifc_bank].csor);
  97. + for (i = 0; i < 4; i++) {
  98. + ifc_out32(savd_regs->ftim_cs[ifc_bank].ftim[i],
  99. + &ifc->ftim_cs[ifc_bank].ftim[i]);
  100. + }
  101. + }
  102. + ifc_out32(savd_regs->ifc_gcr, &ifc->ifc_gcr);
  103. + ifc_out32(savd_regs->cm_evter_en, &ifc->cm_evter_en);
  104. +
  105. +/*
  106. +* IFC controller NAND machine registers
  107. +*/
  108. + ifc_out32(savd_regs->ifc_nand.ncfgr, &ifc->ifc_nand.ncfgr);
  109. + ifc_out32(savd_regs->ifc_nand.nand_fcr0,
  110. + &ifc->ifc_nand.nand_fcr0);
  111. + ifc_out32(savd_regs->ifc_nand.nand_fcr1,
  112. + &ifc->ifc_nand.nand_fcr1);
  113. + ifc_out32(savd_regs->ifc_nand.row0, &ifc->ifc_nand.row0);
  114. + ifc_out32(savd_regs->ifc_nand.row1, &ifc->ifc_nand.row1);
  115. + ifc_out32(savd_regs->ifc_nand.col0, &ifc->ifc_nand.col0);
  116. + ifc_out32(savd_regs->ifc_nand.col1, &ifc->ifc_nand.col1);
  117. + ifc_out32(savd_regs->ifc_nand.row2, &ifc->ifc_nand.row2);
  118. + ifc_out32(savd_regs->ifc_nand.col2, &ifc->ifc_nand.col2);
  119. + ifc_out32(savd_regs->ifc_nand.row3, &ifc->ifc_nand.row3);
  120. + ifc_out32(savd_regs->ifc_nand.col3, &ifc->ifc_nand.col3);
  121. + ifc_out32(savd_regs->ifc_nand.nand_fbcr,
  122. + &ifc->ifc_nand.nand_fbcr);
  123. + ifc_out32(savd_regs->ifc_nand.nand_fir0,
  124. + &ifc->ifc_nand.nand_fir0);
  125. + ifc_out32(savd_regs->ifc_nand.nand_fir1,
  126. + &ifc->ifc_nand.nand_fir1);
  127. + ifc_out32(savd_regs->ifc_nand.nand_fir2,
  128. + &ifc->ifc_nand.nand_fir2);
  129. + ifc_out32(savd_regs->ifc_nand.nand_csel,
  130. + &ifc->ifc_nand.nand_csel);
  131. + ifc_out32(savd_regs->ifc_nand.nandseq_strt,
  132. + &ifc->ifc_nand.nandseq_strt);
  133. + ifc_out32(savd_regs->ifc_nand.nand_evter_en,
  134. + &ifc->ifc_nand.nand_evter_en);
  135. + ifc_out32(savd_regs->ifc_nand.nanndcr, &ifc->ifc_nand.nanndcr);
  136. +
  137. +/*
  138. +* IFC controller NOR machine registers
  139. +*/
  140. + ifc_out32(savd_regs->ifc_nor.nor_evter_en,
  141. + &ifc->ifc_nor.nor_evter_en);
  142. + ifc_out32(savd_regs->ifc_nor.norcr, &ifc->ifc_nor.norcr);
  143. +
  144. +/*
  145. + * IFC controller GPCM Machine registers
  146. + */
  147. + ifc_out32(savd_regs->ifc_gpcm.gpcm_evter_en,
  148. + &ifc->ifc_gpcm.gpcm_evter_en);
  149. +
  150. +
  151. +
  152. +/*
  153. + * IFC interrupts enabled
  154. + */
  155. + ifc_out32(ctrl->saved_regs->cm_evter_intr_en, &ifc->cm_evter_intr_en);
  156. + ifc_out32(ctrl->saved_regs->ifc_nand.nand_evter_intr_en,
  157. + &ifc->ifc_nand.nand_evter_intr_en);
  158. + ifc_out32(ctrl->saved_regs->ifc_nor.nor_evter_intr_en,
  159. + &ifc->ifc_nor.nor_evter_intr_en);
  160. + ifc_out32(ctrl->saved_regs->ifc_gpcm.gpcm_evter_intr_en,
  161. + &ifc->ifc_gpcm.gpcm_evter_intr_en);
  162. +
  163. + kfree(ctrl->saved_regs);
  164. + ctrl->saved_regs = NULL;
  165. + }
  166. +
  167. + ver = ifc_in32(&ctrl->regs->ifc_rev);
  168. + ncfgr = ifc_in32(&ifc->ifc_nand.ncfgr);
  169. + if (ver >= FSL_IFC_V1_3_0) {
  170. +
  171. + ifc_out32(ncfgr | IFC_NAND_SRAM_INIT_EN,
  172. + &ifc->ifc_nand.ncfgr);
  173. + /* wait for SRAM_INIT bit to be clear or timeout */
  174. + status = spin_event_timeout(
  175. + !(ifc_in32(&ifc->ifc_nand.ncfgr)
  176. + & IFC_NAND_SRAM_INIT_EN),
  177. + IFC_TIMEOUT_MSECS, 0);
  178. +
  179. + if (!status)
  180. + dev_err(ctrl->dev, "Timeout waiting for IFC SRAM INIT");
  181. + }
  182. +
  183. + return 0;
  184. +}
  185. +#endif /* CONFIG_PM_SLEEP */
  186. +
  187. static const struct of_device_id fsl_ifc_match[] = {
  188. {
  189. .compatible = "fsl,ifc",
  190. @@ -316,10 +474,15 @@ static const struct of_device_id fsl_ifc
  191. {},
  192. };
  193. +static const struct dev_pm_ops ifc_pm_ops = {
  194. + SET_SYSTEM_SLEEP_PM_OPS(fsl_ifc_suspend, fsl_ifc_resume)
  195. +};
  196. +
  197. static struct platform_driver fsl_ifc_ctrl_driver = {
  198. .driver = {
  199. .name = "fsl-ifc",
  200. .of_match_table = fsl_ifc_match,
  201. + .pm = &ifc_pm_ops,
  202. },
  203. .probe = fsl_ifc_ctrl_probe,
  204. .remove = fsl_ifc_ctrl_remove,
  205. --- a/include/linux/fsl_ifc.h
  206. +++ b/include/linux/fsl_ifc.h
  207. @@ -270,6 +270,8 @@
  208. */
  209. /* Auto Boot Mode */
  210. #define IFC_NAND_NCFGR_BOOT 0x80000000
  211. +/* SRAM INIT EN */
  212. +#define IFC_NAND_SRAM_INIT_EN 0x20000000
  213. /* Addressing Mode-ROW0+n/COL0 */
  214. #define IFC_NAND_NCFGR_ADDR_MODE_RC0 0x00000000
  215. /* Addressing Mode-ROW0+n/COL0+n */
  216. @@ -842,6 +844,10 @@ struct fsl_ifc_ctrl {
  217. u32 nand_stat;
  218. wait_queue_head_t nand_wait;
  219. bool little_endian;
  220. +#ifdef CONFIG_PM_SLEEP
  221. + /*save regs when system goes to deep sleep*/
  222. + struct fsl_ifc_regs *saved_regs;
  223. +#endif
  224. };
  225. extern struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;