813-ifc-nor-nand-support-layerscape.patch 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. From 780865643e5dbf41fe950924a68f7ee4fea8af3e Mon Sep 17 00:00:00 2001
  2. From: Biwen Li <[email protected]>
  3. Date: Tue, 30 Oct 2018 18:26:39 +0800
  4. Subject: [PATCH 30/40] ifc-nor-nand: support layerscape
  5. This is an integrated patch of ifc-nor-nand for
  6. layerscape
  7. Signed-off-by: Prabhakar Kushwaha <[email protected]>
  8. Signed-off-by: Raghav Dogra <[email protected]>
  9. Signed-off-by: Biwen Li <[email protected]>
  10. ---
  11. drivers/memory/fsl_ifc.c | 263 +++++++++++++++++++++++++++++
  12. drivers/mtd/maps/physmap_of_core.c | 4 +
  13. include/linux/fsl_ifc.h | 7 +
  14. 3 files changed, 274 insertions(+)
  15. --- a/drivers/memory/fsl_ifc.c
  16. +++ b/drivers/memory/fsl_ifc.c
  17. @@ -24,6 +24,7 @@
  18. #include <linux/compiler.h>
  19. #include <linux/sched.h>
  20. #include <linux/spinlock.h>
  21. +#include <linux/delay.h>
  22. #include <linux/types.h>
  23. #include <linux/slab.h>
  24. #include <linux/io.h>
  25. @@ -37,6 +38,8 @@
  26. struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;
  27. EXPORT_SYMBOL(fsl_ifc_ctrl_dev);
  28. +#define FSL_IFC_V1_3_0 0x01030000
  29. +#define IFC_TIMEOUT_MSECS 1000 /* 1000ms */
  30. /*
  31. * convert_ifc_address - convert the base address
  32. @@ -311,6 +314,261 @@ err:
  33. return ret;
  34. }
  35. +#ifdef CONFIG_PM_SLEEP
  36. +/* save ifc registers */
  37. +static int fsl_ifc_suspend(struct device *dev)
  38. +{
  39. + struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(dev);
  40. + struct fsl_ifc_global __iomem *fcm = ctrl->gregs;
  41. + struct fsl_ifc_runtime __iomem *runtime = ctrl->rregs;
  42. + __be32 nand_evter_intr_en, cm_evter_intr_en, nor_evter_intr_en,
  43. + gpcm_evter_intr_en;
  44. + uint32_t ifc_bank, i;
  45. +
  46. + ctrl->saved_gregs = kzalloc(sizeof(struct fsl_ifc_global), GFP_KERNEL);
  47. + if (!ctrl->saved_gregs)
  48. + return -ENOMEM;
  49. + ctrl->saved_rregs = kzalloc(sizeof(struct fsl_ifc_runtime), GFP_KERNEL);
  50. + if (!ctrl->saved_rregs)
  51. + return -ENOMEM;
  52. +
  53. + cm_evter_intr_en = ifc_in32(&fcm->cm_evter_intr_en);
  54. + nand_evter_intr_en = ifc_in32(&runtime->ifc_nand.nand_evter_intr_en);
  55. + nor_evter_intr_en = ifc_in32(&runtime->ifc_nor.nor_evter_intr_en);
  56. + gpcm_evter_intr_en = ifc_in32(&runtime->ifc_gpcm.gpcm_evter_intr_en);
  57. +
  58. +/* IFC interrupts disabled */
  59. +
  60. + ifc_out32(0x0, &fcm->cm_evter_intr_en);
  61. + ifc_out32(0x0, &runtime->ifc_nand.nand_evter_intr_en);
  62. + ifc_out32(0x0, &runtime->ifc_nor.nor_evter_intr_en);
  63. + ifc_out32(0x0, &runtime->ifc_gpcm.gpcm_evter_intr_en);
  64. +
  65. + if (ctrl->saved_gregs) {
  66. + for (ifc_bank = 0; ifc_bank < FSL_IFC_BANK_COUNT; ifc_bank++) {
  67. + ctrl->saved_gregs->cspr_cs[ifc_bank].cspr_ext =
  68. + ifc_in32(&fcm->cspr_cs[ifc_bank].cspr_ext);
  69. + ctrl->saved_gregs->cspr_cs[ifc_bank].cspr =
  70. + ifc_in32(&fcm->cspr_cs[ifc_bank].cspr);
  71. + ctrl->saved_gregs->amask_cs[ifc_bank].amask =
  72. + ifc_in32(&fcm->amask_cs[ifc_bank].amask);
  73. + ctrl->saved_gregs->csor_cs[ifc_bank].csor_ext =
  74. + ifc_in32(&fcm->csor_cs[ifc_bank].csor_ext);
  75. + ctrl->saved_gregs->csor_cs[ifc_bank].csor =
  76. + ifc_in32(&fcm->csor_cs[ifc_bank].csor);
  77. + for (i = 0; i < 4; i++) {
  78. + ctrl->saved_gregs->ftim_cs[ifc_bank].ftim[i] =
  79. + ifc_in32(
  80. + &fcm->ftim_cs[ifc_bank].ftim[i]);
  81. + }
  82. + }
  83. +
  84. + ctrl->saved_gregs->rb_map = ifc_in32(&fcm->rb_map);
  85. + ctrl->saved_gregs->wb_map = ifc_in32(&fcm->wb_map);
  86. + ctrl->saved_gregs->ifc_gcr = ifc_in32(&fcm->ifc_gcr);
  87. + ctrl->saved_gregs->ddr_ccr_low = ifc_in32(&fcm->ddr_ccr_low);
  88. + ctrl->saved_gregs->cm_evter_en = ifc_in32(&fcm->cm_evter_en);
  89. + }
  90. +
  91. + if (ctrl->saved_rregs) {
  92. + /* IFC controller NAND machine registers */
  93. + ctrl->saved_rregs->ifc_nand.ncfgr =
  94. + ifc_in32(&runtime->ifc_nand.ncfgr);
  95. + ctrl->saved_rregs->ifc_nand.nand_fcr0 =
  96. + ifc_in32(&runtime->ifc_nand.nand_fcr0);
  97. + ctrl->saved_rregs->ifc_nand.nand_fcr1 =
  98. + ifc_in32(&runtime->ifc_nand.nand_fcr1);
  99. + ctrl->saved_rregs->ifc_nand.row0 =
  100. + ifc_in32(&runtime->ifc_nand.row0);
  101. + ctrl->saved_rregs->ifc_nand.row1 =
  102. + ifc_in32(&runtime->ifc_nand.row1);
  103. + ctrl->saved_rregs->ifc_nand.col0 =
  104. + ifc_in32(&runtime->ifc_nand.col0);
  105. + ctrl->saved_rregs->ifc_nand.col1 =
  106. + ifc_in32(&runtime->ifc_nand.col1);
  107. + ctrl->saved_rregs->ifc_nand.row2 =
  108. + ifc_in32(&runtime->ifc_nand.row2);
  109. + ctrl->saved_rregs->ifc_nand.col2 =
  110. + ifc_in32(&runtime->ifc_nand.col2);
  111. + ctrl->saved_rregs->ifc_nand.row3 =
  112. + ifc_in32(&runtime->ifc_nand.row3);
  113. + ctrl->saved_rregs->ifc_nand.col3 =
  114. + ifc_in32(&runtime->ifc_nand.col3);
  115. +
  116. + ctrl->saved_rregs->ifc_nand.nand_fbcr =
  117. + ifc_in32(&runtime->ifc_nand.nand_fbcr);
  118. + ctrl->saved_rregs->ifc_nand.nand_fir0 =
  119. + ifc_in32(&runtime->ifc_nand.nand_fir0);
  120. + ctrl->saved_rregs->ifc_nand.nand_fir1 =
  121. + ifc_in32(&runtime->ifc_nand.nand_fir1);
  122. + ctrl->saved_rregs->ifc_nand.nand_fir2 =
  123. + ifc_in32(&runtime->ifc_nand.nand_fir2);
  124. + ctrl->saved_rregs->ifc_nand.nand_csel =
  125. + ifc_in32(&runtime->ifc_nand.nand_csel);
  126. + ctrl->saved_rregs->ifc_nand.nandseq_strt =
  127. + ifc_in32(
  128. + &runtime->ifc_nand.nandseq_strt);
  129. + ctrl->saved_rregs->ifc_nand.nand_evter_en =
  130. + ifc_in32(
  131. + &runtime->ifc_nand.nand_evter_en);
  132. + ctrl->saved_rregs->ifc_nand.nanndcr =
  133. + ifc_in32(&runtime->ifc_nand.nanndcr);
  134. + ctrl->saved_rregs->ifc_nand.nand_dll_lowcfg0 =
  135. + ifc_in32(
  136. + &runtime->ifc_nand.nand_dll_lowcfg0);
  137. + ctrl->saved_rregs->ifc_nand.nand_dll_lowcfg1 =
  138. + ifc_in32(
  139. + &runtime->ifc_nand.nand_dll_lowcfg1);
  140. +
  141. + /* IFC controller NOR machine registers */
  142. + ctrl->saved_rregs->ifc_nor.nor_evter_en =
  143. + ifc_in32(
  144. + &runtime->ifc_nor.nor_evter_en);
  145. + ctrl->saved_rregs->ifc_nor.norcr =
  146. + ifc_in32(&runtime->ifc_nor.norcr);
  147. +
  148. + /* IFC controller GPCM Machine registers */
  149. + ctrl->saved_rregs->ifc_gpcm.gpcm_evter_en =
  150. + ifc_in32(
  151. + &runtime->ifc_gpcm.gpcm_evter_en);
  152. + }
  153. +
  154. +/* save the interrupt values */
  155. + ctrl->saved_gregs->cm_evter_intr_en = cm_evter_intr_en;
  156. + ctrl->saved_rregs->ifc_nand.nand_evter_intr_en = nand_evter_intr_en;
  157. + ctrl->saved_rregs->ifc_nor.nor_evter_intr_en = nor_evter_intr_en;
  158. + ctrl->saved_rregs->ifc_gpcm.gpcm_evter_intr_en = gpcm_evter_intr_en;
  159. +
  160. + return 0;
  161. +}
  162. +
  163. +/* restore ifc registers */
  164. +static int fsl_ifc_resume(struct device *dev)
  165. +{
  166. + struct fsl_ifc_ctrl *ctrl = dev_get_drvdata(dev);
  167. + struct fsl_ifc_global __iomem *fcm = ctrl->gregs;
  168. + struct fsl_ifc_runtime __iomem *runtime = ctrl->rregs;
  169. + struct fsl_ifc_global *savd_gregs = ctrl->saved_gregs;
  170. + struct fsl_ifc_runtime *savd_rregs = ctrl->saved_rregs;
  171. + uint32_t ver = 0, ncfgr, timeout, ifc_bank, i;
  172. +
  173. +/*
  174. + * IFC interrupts disabled
  175. + */
  176. + ifc_out32(0x0, &fcm->cm_evter_intr_en);
  177. + ifc_out32(0x0, &runtime->ifc_nand.nand_evter_intr_en);
  178. + ifc_out32(0x0, &runtime->ifc_nor.nor_evter_intr_en);
  179. + ifc_out32(0x0, &runtime->ifc_gpcm.gpcm_evter_intr_en);
  180. +
  181. +
  182. + if (ctrl->saved_gregs) {
  183. + for (ifc_bank = 0; ifc_bank < FSL_IFC_BANK_COUNT; ifc_bank++) {
  184. + ifc_out32(savd_gregs->cspr_cs[ifc_bank].cspr_ext,
  185. + &fcm->cspr_cs[ifc_bank].cspr_ext);
  186. + ifc_out32(savd_gregs->cspr_cs[ifc_bank].cspr,
  187. + &fcm->cspr_cs[ifc_bank].cspr);
  188. + ifc_out32(savd_gregs->amask_cs[ifc_bank].amask,
  189. + &fcm->amask_cs[ifc_bank].amask);
  190. + ifc_out32(savd_gregs->csor_cs[ifc_bank].csor_ext,
  191. + &fcm->csor_cs[ifc_bank].csor_ext);
  192. + ifc_out32(savd_gregs->csor_cs[ifc_bank].csor,
  193. + &fcm->csor_cs[ifc_bank].csor);
  194. + for (i = 0; i < 4; i++) {
  195. + ifc_out32(savd_gregs->ftim_cs[ifc_bank].ftim[i],
  196. + &fcm->ftim_cs[ifc_bank].ftim[i]);
  197. + }
  198. + }
  199. + ifc_out32(savd_gregs->rb_map, &fcm->rb_map);
  200. + ifc_out32(savd_gregs->wb_map, &fcm->wb_map);
  201. + ifc_out32(savd_gregs->ifc_gcr, &fcm->ifc_gcr);
  202. + ifc_out32(savd_gregs->ddr_ccr_low, &fcm->ddr_ccr_low);
  203. + ifc_out32(savd_gregs->cm_evter_en, &fcm->cm_evter_en);
  204. + }
  205. +
  206. + if (ctrl->saved_rregs) {
  207. + /* IFC controller NAND machine registers */
  208. + ifc_out32(savd_rregs->ifc_nand.ncfgr,
  209. + &runtime->ifc_nand.ncfgr);
  210. + ifc_out32(savd_rregs->ifc_nand.nand_fcr0,
  211. + &runtime->ifc_nand.nand_fcr0);
  212. + ifc_out32(savd_rregs->ifc_nand.nand_fcr1,
  213. + &runtime->ifc_nand.nand_fcr1);
  214. + ifc_out32(savd_rregs->ifc_nand.row0, &runtime->ifc_nand.row0);
  215. + ifc_out32(savd_rregs->ifc_nand.row1, &runtime->ifc_nand.row1);
  216. + ifc_out32(savd_rregs->ifc_nand.col0, &runtime->ifc_nand.col0);
  217. + ifc_out32(savd_rregs->ifc_nand.col1, &runtime->ifc_nand.col1);
  218. + ifc_out32(savd_rregs->ifc_nand.row2, &runtime->ifc_nand.row2);
  219. + ifc_out32(savd_rregs->ifc_nand.col2, &runtime->ifc_nand.col2);
  220. + ifc_out32(savd_rregs->ifc_nand.row3, &runtime->ifc_nand.row3);
  221. + ifc_out32(savd_rregs->ifc_nand.col3, &runtime->ifc_nand.col3);
  222. + ifc_out32(savd_rregs->ifc_nand.nand_fbcr,
  223. + &runtime->ifc_nand.nand_fbcr);
  224. + ifc_out32(savd_rregs->ifc_nand.nand_fir0,
  225. + &runtime->ifc_nand.nand_fir0);
  226. + ifc_out32(savd_rregs->ifc_nand.nand_fir1,
  227. + &runtime->ifc_nand.nand_fir1);
  228. + ifc_out32(savd_rregs->ifc_nand.nand_fir2,
  229. + &runtime->ifc_nand.nand_fir2);
  230. + ifc_out32(savd_rregs->ifc_nand.nand_csel,
  231. + &runtime->ifc_nand.nand_csel);
  232. + ifc_out32(savd_rregs->ifc_nand.nandseq_strt,
  233. + &runtime->ifc_nand.nandseq_strt);
  234. + ifc_out32(savd_rregs->ifc_nand.nand_evter_en,
  235. + &runtime->ifc_nand.nand_evter_en);
  236. + ifc_out32(savd_rregs->ifc_nand.nanndcr,
  237. + &runtime->ifc_nand.nanndcr);
  238. + ifc_out32(savd_rregs->ifc_nand.nand_dll_lowcfg0,
  239. + &runtime->ifc_nand.nand_dll_lowcfg0);
  240. + ifc_out32(savd_rregs->ifc_nand.nand_dll_lowcfg1,
  241. + &runtime->ifc_nand.nand_dll_lowcfg1);
  242. +
  243. + /* IFC controller NOR machine registers */
  244. + ifc_out32(savd_rregs->ifc_nor.nor_evter_en,
  245. + &runtime->ifc_nor.nor_evter_en);
  246. + ifc_out32(savd_rregs->ifc_nor.norcr, &runtime->ifc_nor.norcr);
  247. +
  248. + /* IFC controller GPCM Machine registers */
  249. + ifc_out32(savd_rregs->ifc_gpcm.gpcm_evter_en,
  250. + &runtime->ifc_gpcm.gpcm_evter_en);
  251. +
  252. + /* IFC interrupts enabled */
  253. + ifc_out32(ctrl->saved_gregs->cm_evter_intr_en,
  254. + &fcm->cm_evter_intr_en);
  255. + ifc_out32(ctrl->saved_rregs->ifc_nand.nand_evter_intr_en,
  256. + &runtime->ifc_nand.nand_evter_intr_en);
  257. + ifc_out32(ctrl->saved_rregs->ifc_nor.nor_evter_intr_en,
  258. + &runtime->ifc_nor.nor_evter_intr_en);
  259. + ifc_out32(ctrl->saved_rregs->ifc_gpcm.gpcm_evter_intr_en,
  260. + &runtime->ifc_gpcm.gpcm_evter_intr_en);
  261. +
  262. + kfree(ctrl->saved_gregs);
  263. + kfree(ctrl->saved_rregs);
  264. + ctrl->saved_gregs = NULL;
  265. + ctrl->saved_rregs = NULL;
  266. + }
  267. +
  268. + ver = ifc_in32(&fcm->ifc_rev);
  269. + ncfgr = ifc_in32(&runtime->ifc_nand.ncfgr);
  270. + if (ver >= FSL_IFC_V1_3_0) {
  271. +
  272. + ifc_out32(ncfgr | IFC_NAND_SRAM_INIT_EN,
  273. + &runtime->ifc_nand.ncfgr);
  274. + /* wait for SRAM_INIT bit to be clear or timeout */
  275. + timeout = 10;
  276. + while ((ifc_in32(&runtime->ifc_nand.ncfgr) &
  277. + IFC_NAND_SRAM_INIT_EN) && timeout) {
  278. + mdelay(IFC_TIMEOUT_MSECS);
  279. + timeout--;
  280. + }
  281. +
  282. + if (!timeout)
  283. + dev_err(ctrl->dev, "Timeout waiting for IFC SRAM INIT");
  284. + }
  285. +
  286. + return 0;
  287. +}
  288. +#endif /* CONFIG_PM_SLEEP */
  289. +
  290. static const struct of_device_id fsl_ifc_match[] = {
  291. {
  292. .compatible = "fsl,ifc",
  293. @@ -318,10 +576,15 @@ static const struct of_device_id fsl_ifc
  294. {},
  295. };
  296. +static const struct dev_pm_ops ifc_pm_ops = {
  297. + SET_SYSTEM_SLEEP_PM_OPS(fsl_ifc_suspend, fsl_ifc_resume)
  298. +};
  299. +
  300. static struct platform_driver fsl_ifc_ctrl_driver = {
  301. .driver = {
  302. .name = "fsl-ifc",
  303. .of_match_table = fsl_ifc_match,
  304. + .pm = &ifc_pm_ops,
  305. },
  306. .probe = fsl_ifc_ctrl_probe,
  307. .remove = fsl_ifc_ctrl_remove,
  308. --- a/drivers/mtd/maps/physmap_of_core.c
  309. +++ b/drivers/mtd/maps/physmap_of_core.c
  310. @@ -20,6 +20,7 @@
  311. #include <linux/mtd/map.h>
  312. #include <linux/mtd/partitions.h>
  313. #include <linux/mtd/concat.h>
  314. +#include <linux/mtd/cfi_endian.h>
  315. #include <linux/of.h>
  316. #include <linux/of_address.h>
  317. #include <linux/of_platform.h>
  318. @@ -205,6 +206,9 @@ static int of_flash_probe(struct platfor
  319. info->list[i].map.bankwidth = be32_to_cpup(width);
  320. info->list[i].map.device_node = dp;
  321. + if (of_property_read_bool(dp->parent, "big-endian"))
  322. + info->list[i].map.swap = CFI_BIG_ENDIAN;
  323. +
  324. err = of_flash_probe_gemini(dev, dp, &info->list[i].map);
  325. if (err)
  326. goto err_out;
  327. --- a/include/linux/fsl_ifc.h
  328. +++ b/include/linux/fsl_ifc.h
  329. @@ -274,6 +274,8 @@
  330. */
  331. /* Auto Boot Mode */
  332. #define IFC_NAND_NCFGR_BOOT 0x80000000
  333. +/* SRAM INIT EN */
  334. +#define IFC_NAND_SRAM_INIT_EN 0x20000000
  335. /* Addressing Mode-ROW0+n/COL0 */
  336. #define IFC_NAND_NCFGR_ADDR_MODE_RC0 0x00000000
  337. /* Addressing Mode-ROW0+n/COL0+n */
  338. @@ -857,6 +859,11 @@ struct fsl_ifc_ctrl {
  339. u32 nand_stat;
  340. wait_queue_head_t nand_wait;
  341. bool little_endian;
  342. +#ifdef CONFIG_PM_SLEEP
  343. + /*save regs when system goes to deep sleep*/
  344. + struct fsl_ifc_global *saved_gregs;
  345. + struct fsl_ifc_runtime *saved_rregs;
  346. +#endif
  347. };
  348. extern struct fsl_ifc_ctrl *fsl_ifc_ctrl_dev;