fsl_ifc_nand.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /* Integrated Flash Controller NAND Machine Driver
  3. *
  4. * Copyright (c) 2012 Freescale Semiconductor, Inc
  5. *
  6. * Authors: Dipen Dudhat <Dipen.Dudhat@freescale.com>
  7. */
  8. #include <common.h>
  9. #include <malloc.h>
  10. #include <nand.h>
  11. #include <linux/mtd/mtd.h>
  12. #include <linux/mtd/rawnand.h>
  13. #include <linux/mtd/nand_ecc.h>
  14. #include <asm/io.h>
  15. #include <linux/errno.h>
  16. #include <fsl_ifc.h>
  17. #ifndef CONFIG_SYS_FSL_IFC_BANK_COUNT
  18. #define CONFIG_SYS_FSL_IFC_BANK_COUNT 4
  19. #endif
  20. #define MAX_BANKS CONFIG_SYS_FSL_IFC_BANK_COUNT
  21. #define ERR_BYTE 0xFF /* Value returned for read bytes
  22. when read failed */
  23. struct fsl_ifc_ctrl;
  24. /* mtd information per set */
  25. struct fsl_ifc_mtd {
  26. struct nand_chip chip;
  27. struct fsl_ifc_ctrl *ctrl;
  28. struct device *dev;
  29. int bank; /* Chip select bank number */
  30. unsigned int bufnum_mask; /* bufnum = page & bufnum_mask */
  31. u8 __iomem *vbase; /* Chip select base virtual address */
  32. };
  33. /* overview of the fsl ifc controller */
  34. struct fsl_ifc_ctrl {
  35. struct nand_hw_control controller;
  36. struct fsl_ifc_mtd *chips[MAX_BANKS];
  37. /* device info */
  38. struct fsl_ifc regs;
  39. void __iomem *addr; /* Address of assigned IFC buffer */
  40. unsigned int page; /* Last page written to / read from */
  41. unsigned int read_bytes; /* Number of bytes read during command */
  42. unsigned int column; /* Saved column from SEQIN */
  43. unsigned int index; /* Pointer to next byte to 'read' */
  44. unsigned int status; /* status read from NEESR after last op */
  45. unsigned int oob; /* Non zero if operating on OOB data */
  46. unsigned int eccread; /* Non zero for a full-page ECC read */
  47. };
  48. static struct fsl_ifc_ctrl *ifc_ctrl;
  49. /* 512-byte page with 4-bit ECC, 8-bit */
  50. static struct nand_ecclayout oob_512_8bit_ecc4 = {
  51. .eccbytes = 8,
  52. .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
  53. .oobfree = { {0, 5}, {6, 2} },
  54. };
  55. /* 512-byte page with 4-bit ECC, 16-bit */
  56. static struct nand_ecclayout oob_512_16bit_ecc4 = {
  57. .eccbytes = 8,
  58. .eccpos = {8, 9, 10, 11, 12, 13, 14, 15},
  59. .oobfree = { {2, 6}, },
  60. };
  61. /* 2048-byte page size with 4-bit ECC */
  62. static struct nand_ecclayout oob_2048_ecc4 = {
  63. .eccbytes = 32,
  64. .eccpos = {
  65. 8, 9, 10, 11, 12, 13, 14, 15,
  66. 16, 17, 18, 19, 20, 21, 22, 23,
  67. 24, 25, 26, 27, 28, 29, 30, 31,
  68. 32, 33, 34, 35, 36, 37, 38, 39,
  69. },
  70. .oobfree = { {2, 6}, {40, 24} },
  71. };
  72. /* 4096-byte page size with 4-bit ECC */
  73. static struct nand_ecclayout oob_4096_ecc4 = {
  74. .eccbytes = 64,
  75. .eccpos = {
  76. 8, 9, 10, 11, 12, 13, 14, 15,
  77. 16, 17, 18, 19, 20, 21, 22, 23,
  78. 24, 25, 26, 27, 28, 29, 30, 31,
  79. 32, 33, 34, 35, 36, 37, 38, 39,
  80. 40, 41, 42, 43, 44, 45, 46, 47,
  81. 48, 49, 50, 51, 52, 53, 54, 55,
  82. 56, 57, 58, 59, 60, 61, 62, 63,
  83. 64, 65, 66, 67, 68, 69, 70, 71,
  84. },
  85. .oobfree = { {2, 6}, {72, 56} },
  86. };
  87. /* 4096-byte page size with 8-bit ECC -- requires 218-byte OOB */
  88. static struct nand_ecclayout oob_4096_ecc8 = {
  89. .eccbytes = 128,
  90. .eccpos = {
  91. 8, 9, 10, 11, 12, 13, 14, 15,
  92. 16, 17, 18, 19, 20, 21, 22, 23,
  93. 24, 25, 26, 27, 28, 29, 30, 31,
  94. 32, 33, 34, 35, 36, 37, 38, 39,
  95. 40, 41, 42, 43, 44, 45, 46, 47,
  96. 48, 49, 50, 51, 52, 53, 54, 55,
  97. 56, 57, 58, 59, 60, 61, 62, 63,
  98. 64, 65, 66, 67, 68, 69, 70, 71,
  99. 72, 73, 74, 75, 76, 77, 78, 79,
  100. 80, 81, 82, 83, 84, 85, 86, 87,
  101. 88, 89, 90, 91, 92, 93, 94, 95,
  102. 96, 97, 98, 99, 100, 101, 102, 103,
  103. 104, 105, 106, 107, 108, 109, 110, 111,
  104. 112, 113, 114, 115, 116, 117, 118, 119,
  105. 120, 121, 122, 123, 124, 125, 126, 127,
  106. 128, 129, 130, 131, 132, 133, 134, 135,
  107. },
  108. .oobfree = { {2, 6}, {136, 82} },
  109. };
  110. /* 8192-byte page size with 4-bit ECC */
  111. static struct nand_ecclayout oob_8192_ecc4 = {
  112. .eccbytes = 128,
  113. .eccpos = {
  114. 8, 9, 10, 11, 12, 13, 14, 15,
  115. 16, 17, 18, 19, 20, 21, 22, 23,
  116. 24, 25, 26, 27, 28, 29, 30, 31,
  117. 32, 33, 34, 35, 36, 37, 38, 39,
  118. 40, 41, 42, 43, 44, 45, 46, 47,
  119. 48, 49, 50, 51, 52, 53, 54, 55,
  120. 56, 57, 58, 59, 60, 61, 62, 63,
  121. 64, 65, 66, 67, 68, 69, 70, 71,
  122. 72, 73, 74, 75, 76, 77, 78, 79,
  123. 80, 81, 82, 83, 84, 85, 86, 87,
  124. 88, 89, 90, 91, 92, 93, 94, 95,
  125. 96, 97, 98, 99, 100, 101, 102, 103,
  126. 104, 105, 106, 107, 108, 109, 110, 111,
  127. 112, 113, 114, 115, 116, 117, 118, 119,
  128. 120, 121, 122, 123, 124, 125, 126, 127,
  129. 128, 129, 130, 131, 132, 133, 134, 135,
  130. },
  131. .oobfree = { {2, 6}, {136, 208} },
  132. };
  133. /* 8192-byte page size with 8-bit ECC -- requires 218-byte OOB */
  134. static struct nand_ecclayout oob_8192_ecc8 = {
  135. .eccbytes = 256,
  136. .eccpos = {
  137. 8, 9, 10, 11, 12, 13, 14, 15,
  138. 16, 17, 18, 19, 20, 21, 22, 23,
  139. 24, 25, 26, 27, 28, 29, 30, 31,
  140. 32, 33, 34, 35, 36, 37, 38, 39,
  141. 40, 41, 42, 43, 44, 45, 46, 47,
  142. 48, 49, 50, 51, 52, 53, 54, 55,
  143. 56, 57, 58, 59, 60, 61, 62, 63,
  144. 64, 65, 66, 67, 68, 69, 70, 71,
  145. 72, 73, 74, 75, 76, 77, 78, 79,
  146. 80, 81, 82, 83, 84, 85, 86, 87,
  147. 88, 89, 90, 91, 92, 93, 94, 95,
  148. 96, 97, 98, 99, 100, 101, 102, 103,
  149. 104, 105, 106, 107, 108, 109, 110, 111,
  150. 112, 113, 114, 115, 116, 117, 118, 119,
  151. 120, 121, 122, 123, 124, 125, 126, 127,
  152. 128, 129, 130, 131, 132, 133, 134, 135,
  153. 136, 137, 138, 139, 140, 141, 142, 143,
  154. 144, 145, 146, 147, 148, 149, 150, 151,
  155. 152, 153, 154, 155, 156, 157, 158, 159,
  156. 160, 161, 162, 163, 164, 165, 166, 167,
  157. 168, 169, 170, 171, 172, 173, 174, 175,
  158. 176, 177, 178, 179, 180, 181, 182, 183,
  159. 184, 185, 186, 187, 188, 189, 190, 191,
  160. 192, 193, 194, 195, 196, 197, 198, 199,
  161. 200, 201, 202, 203, 204, 205, 206, 207,
  162. 208, 209, 210, 211, 212, 213, 214, 215,
  163. 216, 217, 218, 219, 220, 221, 222, 223,
  164. 224, 225, 226, 227, 228, 229, 230, 231,
  165. 232, 233, 234, 235, 236, 237, 238, 239,
  166. 240, 241, 242, 243, 244, 245, 246, 247,
  167. 248, 249, 250, 251, 252, 253, 254, 255,
  168. 256, 257, 258, 259, 260, 261, 262, 263,
  169. },
  170. .oobfree = { {2, 6}, {264, 80} },
  171. };
  172. /*
  173. * Generic flash bbt descriptors
  174. */
  175. static u8 bbt_pattern[] = {'B', 'b', 't', '0' };
  176. static u8 mirror_pattern[] = {'1', 't', 'b', 'B' };
  177. static struct nand_bbt_descr bbt_main_descr = {
  178. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  179. NAND_BBT_2BIT | NAND_BBT_VERSION,
  180. .offs = 2, /* 0 on 8-bit small page */
  181. .len = 4,
  182. .veroffs = 6,
  183. .maxblocks = 4,
  184. .pattern = bbt_pattern,
  185. };
  186. static struct nand_bbt_descr bbt_mirror_descr = {
  187. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
  188. NAND_BBT_2BIT | NAND_BBT_VERSION,
  189. .offs = 2, /* 0 on 8-bit small page */
  190. .len = 4,
  191. .veroffs = 6,
  192. .maxblocks = 4,
  193. .pattern = mirror_pattern,
  194. };
  195. /*
  196. * Set up the IFC hardware block and page address fields, and the ifc nand
  197. * structure addr field to point to the correct IFC buffer in memory
  198. */
  199. static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob)
  200. {
  201. struct nand_chip *chip = mtd_to_nand(mtd);
  202. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  203. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  204. struct fsl_ifc_runtime *ifc = ctrl->regs.rregs;
  205. int buf_num;
  206. ctrl->page = page_addr;
  207. /* Program ROW0/COL0 */
  208. ifc_out32(&ifc->ifc_nand.row0, page_addr);
  209. ifc_out32(&ifc->ifc_nand.col0, (oob ? IFC_NAND_COL_MS : 0) | column);
  210. buf_num = page_addr & priv->bufnum_mask;
  211. ctrl->addr = priv->vbase + buf_num * (mtd->writesize * 2);
  212. ctrl->index = column;
  213. /* for OOB data point to the second half of the buffer */
  214. if (oob)
  215. ctrl->index += mtd->writesize;
  216. }
  217. static int is_blank(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
  218. unsigned int bufnum)
  219. {
  220. struct nand_chip *chip = mtd_to_nand(mtd);
  221. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  222. u8 __iomem *addr = priv->vbase + bufnum * (mtd->writesize * 2);
  223. u32 __iomem *main = (u32 *)addr;
  224. u8 __iomem *oob = addr + mtd->writesize;
  225. int i;
  226. for (i = 0; i < mtd->writesize / 4; i++) {
  227. if (__raw_readl(&main[i]) != 0xffffffff)
  228. return 0;
  229. }
  230. for (i = 0; i < chip->ecc.layout->eccbytes; i++) {
  231. int pos = chip->ecc.layout->eccpos[i];
  232. if (__raw_readb(&oob[pos]) != 0xff)
  233. return 0;
  234. }
  235. return 1;
  236. }
  237. /* returns nonzero if entire page is blank */
  238. static int check_read_ecc(struct mtd_info *mtd, struct fsl_ifc_ctrl *ctrl,
  239. u32 eccstat, unsigned int bufnum)
  240. {
  241. return (eccstat >> ((3 - bufnum % 4) * 8)) & 15;
  242. }
  243. /*
  244. * execute IFC NAND command and wait for it to complete
  245. */
  246. static int fsl_ifc_run_command(struct mtd_info *mtd)
  247. {
  248. struct nand_chip *chip = mtd_to_nand(mtd);
  249. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  250. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  251. struct fsl_ifc_runtime *ifc = ctrl->regs.rregs;
  252. u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
  253. u32 time_start;
  254. u32 eccstat;
  255. int i;
  256. /* set the chip select for NAND Transaction */
  257. ifc_out32(&ifc->ifc_nand.nand_csel, priv->bank << IFC_NAND_CSEL_SHIFT);
  258. /* start read/write seq */
  259. ifc_out32(&ifc->ifc_nand.nandseq_strt,
  260. IFC_NAND_SEQ_STRT_FIR_STRT);
  261. /* wait for NAND Machine complete flag or timeout */
  262. time_start = get_timer(0);
  263. while (get_timer(time_start) < timeo) {
  264. ctrl->status = ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  265. if (ctrl->status & IFC_NAND_EVTER_STAT_OPC)
  266. break;
  267. }
  268. ifc_out32(&ifc->ifc_nand.nand_evter_stat, ctrl->status);
  269. if (ctrl->status & IFC_NAND_EVTER_STAT_FTOER)
  270. printf("%s: Flash Time Out Error\n", __func__);
  271. if (ctrl->status & IFC_NAND_EVTER_STAT_WPER)
  272. printf("%s: Write Protect Error\n", __func__);
  273. if (ctrl->eccread) {
  274. int errors;
  275. int bufnum = ctrl->page & priv->bufnum_mask;
  276. int sector_start = bufnum * chip->ecc.steps;
  277. int sector_end = sector_start + chip->ecc.steps - 1;
  278. u32 *eccstat_regs;
  279. eccstat_regs = ifc->ifc_nand.nand_eccstat;
  280. eccstat = ifc_in32(&eccstat_regs[sector_start / 4]);
  281. for (i = sector_start; i <= sector_end; i++) {
  282. if ((i != sector_start) && !(i % 4))
  283. eccstat = ifc_in32(&eccstat_regs[i / 4]);
  284. errors = check_read_ecc(mtd, ctrl, eccstat, i);
  285. if (errors == 15) {
  286. /*
  287. * Uncorrectable error.
  288. * OK only if the whole page is blank.
  289. *
  290. * We disable ECCER reporting due to erratum
  291. * IFC-A002770 -- so report it now if we
  292. * see an uncorrectable error in ECCSTAT.
  293. */
  294. if (!is_blank(mtd, ctrl, bufnum))
  295. ctrl->status |=
  296. IFC_NAND_EVTER_STAT_ECCER;
  297. break;
  298. }
  299. mtd->ecc_stats.corrected += errors;
  300. }
  301. ctrl->eccread = 0;
  302. }
  303. /* returns 0 on success otherwise non-zero) */
  304. return ctrl->status == IFC_NAND_EVTER_STAT_OPC ? 0 : -EIO;
  305. }
  306. static void fsl_ifc_do_read(struct nand_chip *chip,
  307. int oob,
  308. struct mtd_info *mtd)
  309. {
  310. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  311. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  312. struct fsl_ifc_runtime *ifc = ctrl->regs.rregs;
  313. /* Program FIR/IFC_NAND_FCR0 for Small/Large page */
  314. if (mtd->writesize > 512) {
  315. ifc_out32(&ifc->ifc_nand.nand_fir0,
  316. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  317. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  318. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  319. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP3_SHIFT) |
  320. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP4_SHIFT));
  321. ifc_out32(&ifc->ifc_nand.nand_fir1, 0x0);
  322. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  323. (NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT) |
  324. (NAND_CMD_READSTART << IFC_NAND_FCR0_CMD1_SHIFT));
  325. } else {
  326. ifc_out32(&ifc->ifc_nand.nand_fir0,
  327. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  328. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  329. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  330. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP3_SHIFT));
  331. if (oob)
  332. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  333. NAND_CMD_READOOB << IFC_NAND_FCR0_CMD0_SHIFT);
  334. else
  335. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  336. NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT);
  337. }
  338. }
  339. /* cmdfunc send commands to the IFC NAND Machine */
  340. static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
  341. int column, int page_addr)
  342. {
  343. struct nand_chip *chip = mtd_to_nand(mtd);
  344. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  345. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  346. struct fsl_ifc_runtime *ifc = ctrl->regs.rregs;
  347. /* clear the read buffer */
  348. ctrl->read_bytes = 0;
  349. if (command != NAND_CMD_PAGEPROG)
  350. ctrl->index = 0;
  351. switch (command) {
  352. /* READ0 read the entire buffer to use hardware ECC. */
  353. case NAND_CMD_READ0: {
  354. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  355. set_addr(mtd, 0, page_addr, 0);
  356. ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  357. ctrl->index += column;
  358. if (chip->ecc.mode == NAND_ECC_HW)
  359. ctrl->eccread = 1;
  360. fsl_ifc_do_read(chip, 0, mtd);
  361. fsl_ifc_run_command(mtd);
  362. return;
  363. }
  364. /* READOOB reads only the OOB because no ECC is performed. */
  365. case NAND_CMD_READOOB:
  366. ifc_out32(&ifc->ifc_nand.nand_fbcr, mtd->oobsize - column);
  367. set_addr(mtd, column, page_addr, 1);
  368. ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  369. fsl_ifc_do_read(chip, 1, mtd);
  370. fsl_ifc_run_command(mtd);
  371. return;
  372. /* READID must read all possible bytes while CEB is active */
  373. case NAND_CMD_READID:
  374. case NAND_CMD_PARAM: {
  375. int timing = IFC_FIR_OP_RB;
  376. if (command == NAND_CMD_PARAM)
  377. timing = IFC_FIR_OP_RBCD;
  378. ifc_out32(&ifc->ifc_nand.nand_fir0,
  379. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  380. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  381. (timing << IFC_NAND_FIR0_OP2_SHIFT));
  382. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  383. command << IFC_NAND_FCR0_CMD0_SHIFT);
  384. ifc_out32(&ifc->ifc_nand.row3, column);
  385. /*
  386. * although currently it's 8 bytes for READID, we always read
  387. * the maximum 256 bytes(for PARAM)
  388. */
  389. ifc_out32(&ifc->ifc_nand.nand_fbcr, 256);
  390. ctrl->read_bytes = 256;
  391. set_addr(mtd, 0, 0, 0);
  392. fsl_ifc_run_command(mtd);
  393. return;
  394. }
  395. /* ERASE1 stores the block and page address */
  396. case NAND_CMD_ERASE1:
  397. set_addr(mtd, 0, page_addr, 0);
  398. return;
  399. /* ERASE2 uses the block and page address from ERASE1 */
  400. case NAND_CMD_ERASE2:
  401. ifc_out32(&ifc->ifc_nand.nand_fir0,
  402. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  403. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  404. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP2_SHIFT));
  405. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  406. (NAND_CMD_ERASE1 << IFC_NAND_FCR0_CMD0_SHIFT) |
  407. (NAND_CMD_ERASE2 << IFC_NAND_FCR0_CMD1_SHIFT));
  408. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  409. ctrl->read_bytes = 0;
  410. fsl_ifc_run_command(mtd);
  411. return;
  412. /* SEQIN sets up the addr buffer and all registers except the length */
  413. case NAND_CMD_SEQIN: {
  414. u32 nand_fcr0;
  415. ctrl->column = column;
  416. ctrl->oob = 0;
  417. if (mtd->writesize > 512) {
  418. nand_fcr0 =
  419. (NAND_CMD_SEQIN << IFC_NAND_FCR0_CMD0_SHIFT) |
  420. (NAND_CMD_STATUS << IFC_NAND_FCR0_CMD1_SHIFT) |
  421. (NAND_CMD_PAGEPROG << IFC_NAND_FCR0_CMD2_SHIFT);
  422. ifc_out32(&ifc->ifc_nand.nand_fir0,
  423. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  424. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  425. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  426. (IFC_FIR_OP_WBCD <<
  427. IFC_NAND_FIR0_OP3_SHIFT) |
  428. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP4_SHIFT));
  429. ifc_out32(&ifc->ifc_nand.nand_fir1,
  430. (IFC_FIR_OP_CW1 << IFC_NAND_FIR1_OP5_SHIFT) |
  431. (IFC_FIR_OP_RDSTAT <<
  432. IFC_NAND_FIR1_OP6_SHIFT) |
  433. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP7_SHIFT));
  434. } else {
  435. nand_fcr0 = ((NAND_CMD_PAGEPROG <<
  436. IFC_NAND_FCR0_CMD1_SHIFT) |
  437. (NAND_CMD_SEQIN <<
  438. IFC_NAND_FCR0_CMD2_SHIFT) |
  439. (NAND_CMD_STATUS <<
  440. IFC_NAND_FCR0_CMD3_SHIFT));
  441. ifc_out32(&ifc->ifc_nand.nand_fir0,
  442. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  443. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP1_SHIFT) |
  444. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  445. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP3_SHIFT) |
  446. (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP4_SHIFT));
  447. ifc_out32(&ifc->ifc_nand.nand_fir1,
  448. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR1_OP5_SHIFT) |
  449. (IFC_FIR_OP_CW3 << IFC_NAND_FIR1_OP6_SHIFT) |
  450. (IFC_FIR_OP_RDSTAT <<
  451. IFC_NAND_FIR1_OP7_SHIFT) |
  452. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP8_SHIFT));
  453. if (column >= mtd->writesize)
  454. nand_fcr0 |=
  455. NAND_CMD_READOOB << IFC_NAND_FCR0_CMD0_SHIFT;
  456. else
  457. nand_fcr0 |=
  458. NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT;
  459. }
  460. if (column >= mtd->writesize) {
  461. /* OOB area --> READOOB */
  462. column -= mtd->writesize;
  463. ctrl->oob = 1;
  464. }
  465. ifc_out32(&ifc->ifc_nand.nand_fcr0, nand_fcr0);
  466. set_addr(mtd, column, page_addr, ctrl->oob);
  467. return;
  468. }
  469. /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
  470. case NAND_CMD_PAGEPROG:
  471. if (ctrl->oob)
  472. ifc_out32(&ifc->ifc_nand.nand_fbcr,
  473. ctrl->index - ctrl->column);
  474. else
  475. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0);
  476. fsl_ifc_run_command(mtd);
  477. return;
  478. case NAND_CMD_STATUS:
  479. ifc_out32(&ifc->ifc_nand.nand_fir0,
  480. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  481. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP1_SHIFT));
  482. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  483. NAND_CMD_STATUS << IFC_NAND_FCR0_CMD0_SHIFT);
  484. ifc_out32(&ifc->ifc_nand.nand_fbcr, 1);
  485. set_addr(mtd, 0, 0, 0);
  486. ctrl->read_bytes = 1;
  487. fsl_ifc_run_command(mtd);
  488. /*
  489. * The chip always seems to report that it is
  490. * write-protected, even when it is not.
  491. */
  492. if (chip->options & NAND_BUSWIDTH_16)
  493. ifc_out16(ctrl->addr,
  494. ifc_in16(ctrl->addr) | NAND_STATUS_WP);
  495. else
  496. out_8(ctrl->addr, in_8(ctrl->addr) | NAND_STATUS_WP);
  497. return;
  498. case NAND_CMD_RESET:
  499. ifc_out32(&ifc->ifc_nand.nand_fir0,
  500. IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT);
  501. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  502. NAND_CMD_RESET << IFC_NAND_FCR0_CMD0_SHIFT);
  503. fsl_ifc_run_command(mtd);
  504. return;
  505. default:
  506. printf("%s: error, unsupported command 0x%x.\n",
  507. __func__, command);
  508. }
  509. }
  510. /*
  511. * Write buf to the IFC NAND Controller Data Buffer
  512. */
  513. static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  514. {
  515. struct nand_chip *chip = mtd_to_nand(mtd);
  516. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  517. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  518. unsigned int bufsize = mtd->writesize + mtd->oobsize;
  519. if (len <= 0) {
  520. printf("%s of %d bytes", __func__, len);
  521. ctrl->status = 0;
  522. return;
  523. }
  524. if ((unsigned int)len > bufsize - ctrl->index) {
  525. printf("%s beyond end of buffer "
  526. "(%d requested, %u available)\n",
  527. __func__, len, bufsize - ctrl->index);
  528. len = bufsize - ctrl->index;
  529. }
  530. memcpy_toio(ctrl->addr + ctrl->index, buf, len);
  531. ctrl->index += len;
  532. }
  533. /*
  534. * read a byte from either the IFC hardware buffer if it has any data left
  535. * otherwise issue a command to read a single byte.
  536. */
  537. static u8 fsl_ifc_read_byte(struct mtd_info *mtd)
  538. {
  539. struct nand_chip *chip = mtd_to_nand(mtd);
  540. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  541. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  542. unsigned int offset;
  543. /*
  544. * If there are still bytes in the IFC buffer, then use the
  545. * next byte.
  546. */
  547. if (ctrl->index < ctrl->read_bytes) {
  548. offset = ctrl->index++;
  549. return in_8(ctrl->addr + offset);
  550. }
  551. printf("%s beyond end of buffer\n", __func__);
  552. return ERR_BYTE;
  553. }
  554. /*
  555. * Read two bytes from the IFC hardware buffer
  556. * read function for 16-bit buswith
  557. */
  558. static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd)
  559. {
  560. struct nand_chip *chip = mtd_to_nand(mtd);
  561. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  562. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  563. uint16_t data;
  564. /*
  565. * If there are still bytes in the IFC buffer, then use the
  566. * next byte.
  567. */
  568. if (ctrl->index < ctrl->read_bytes) {
  569. data = ifc_in16(ctrl->addr + ctrl->index);
  570. ctrl->index += 2;
  571. return (uint8_t)data;
  572. }
  573. printf("%s beyond end of buffer\n", __func__);
  574. return ERR_BYTE;
  575. }
  576. /*
  577. * Read from the IFC Controller Data Buffer
  578. */
  579. static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  580. {
  581. struct nand_chip *chip = mtd_to_nand(mtd);
  582. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  583. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  584. int avail;
  585. if (len < 0)
  586. return;
  587. avail = min((unsigned int)len, ctrl->read_bytes - ctrl->index);
  588. memcpy_fromio(buf, ctrl->addr + ctrl->index, avail);
  589. ctrl->index += avail;
  590. if (len > avail)
  591. printf("%s beyond end of buffer "
  592. "(%d requested, %d available)\n",
  593. __func__, len, avail);
  594. }
  595. /* This function is called after Program and Erase Operations to
  596. * check for success or failure.
  597. */
  598. static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
  599. {
  600. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  601. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  602. struct fsl_ifc_runtime *ifc = ctrl->regs.rregs;
  603. u32 nand_fsr;
  604. int status;
  605. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  606. return NAND_STATUS_FAIL;
  607. /* Use READ_STATUS command, but wait for the device to be ready */
  608. ifc_out32(&ifc->ifc_nand.nand_fir0,
  609. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  610. (IFC_FIR_OP_RDSTAT << IFC_NAND_FIR0_OP1_SHIFT));
  611. ifc_out32(&ifc->ifc_nand.nand_fcr0, NAND_CMD_STATUS <<
  612. IFC_NAND_FCR0_CMD0_SHIFT);
  613. ifc_out32(&ifc->ifc_nand.nand_fbcr, 1);
  614. set_addr(mtd, 0, 0, 0);
  615. ctrl->read_bytes = 1;
  616. fsl_ifc_run_command(mtd);
  617. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  618. return NAND_STATUS_FAIL;
  619. nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr);
  620. status = nand_fsr >> 24;
  621. /* Chip sometimes reporting write protect even when it's not */
  622. return status | NAND_STATUS_WP;
  623. }
  624. static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
  625. uint8_t *buf, int oob_required, int page)
  626. {
  627. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  628. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  629. fsl_ifc_read_buf(mtd, buf, mtd->writesize);
  630. fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
  631. if (ctrl->status != IFC_NAND_EVTER_STAT_OPC)
  632. mtd->ecc_stats.failed++;
  633. return 0;
  634. }
  635. /* ECC will be calculated automatically, and errors will be detected in
  636. * waitfunc.
  637. */
  638. static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
  639. const uint8_t *buf, int oob_required, int page)
  640. {
  641. fsl_ifc_write_buf(mtd, buf, mtd->writesize);
  642. fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
  643. return 0;
  644. }
  645. static void fsl_ifc_ctrl_init(void)
  646. {
  647. uint32_t ver = 0;
  648. ifc_ctrl = kzalloc(sizeof(*ifc_ctrl), GFP_KERNEL);
  649. if (!ifc_ctrl)
  650. return;
  651. ifc_ctrl->regs.gregs = IFC_FCM_BASE_ADDR;
  652. ver = ifc_in32(&ifc_ctrl->regs.gregs->ifc_rev);
  653. if (ver >= FSL_IFC_V2_0_0)
  654. ifc_ctrl->regs.rregs =
  655. (void *)CONFIG_SYS_IFC_ADDR + IFC_RREGS_64KOFFSET;
  656. else
  657. ifc_ctrl->regs.rregs =
  658. (void *)CONFIG_SYS_IFC_ADDR + IFC_RREGS_4KOFFSET;
  659. /* clear event registers */
  660. ifc_out32(&ifc_ctrl->regs.rregs->ifc_nand.nand_evter_stat, ~0U);
  661. ifc_out32(&ifc_ctrl->regs.rregs->ifc_nand.pgrdcmpl_evt_stat, ~0U);
  662. /* Enable error and event for any detected errors */
  663. ifc_out32(&ifc_ctrl->regs.rregs->ifc_nand.nand_evter_en,
  664. IFC_NAND_EVTER_EN_OPC_EN |
  665. IFC_NAND_EVTER_EN_PGRDCMPL_EN |
  666. IFC_NAND_EVTER_EN_FTOER_EN |
  667. IFC_NAND_EVTER_EN_WPER_EN);
  668. ifc_out32(&ifc_ctrl->regs.rregs->ifc_nand.ncfgr, 0x0);
  669. }
  670. static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip)
  671. {
  672. }
  673. static int fsl_ifc_sram_init(struct fsl_ifc_mtd *priv, uint32_t ver)
  674. {
  675. struct fsl_ifc_runtime *ifc = ifc_ctrl->regs.rregs;
  676. uint32_t cs = 0, csor = 0, csor_8k = 0, csor_ext = 0;
  677. uint32_t ncfgr = 0;
  678. u32 timeo = (CONFIG_SYS_HZ * 10) / 1000;
  679. u32 time_start;
  680. if (ver > FSL_IFC_V1_1_0) {
  681. ncfgr = ifc_in32(&ifc->ifc_nand.ncfgr);
  682. ifc_out32(&ifc->ifc_nand.ncfgr, ncfgr | IFC_NAND_SRAM_INIT_EN);
  683. /* wait for SRAM_INIT bit to be clear or timeout */
  684. time_start = get_timer(0);
  685. while (get_timer(time_start) < timeo) {
  686. ifc_ctrl->status =
  687. ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  688. if (!(ifc_ctrl->status & IFC_NAND_SRAM_INIT_EN))
  689. return 0;
  690. }
  691. printf("fsl-ifc: Failed to Initialise SRAM\n");
  692. return 1;
  693. }
  694. cs = priv->bank;
  695. /* Save CSOR and CSOR_ext */
  696. csor = ifc_in32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor);
  697. csor_ext = ifc_in32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor_ext);
  698. /* chage PageSize 8K and SpareSize 1K*/
  699. csor_8k = (csor & ~(CSOR_NAND_PGS_MASK)) | 0x0018C000;
  700. ifc_out32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor, csor_8k);
  701. ifc_out32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor_ext, 0x0000400);
  702. /* READID */
  703. ifc_out32(&ifc->ifc_nand.nand_fir0,
  704. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  705. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  706. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT));
  707. ifc_out32(&ifc->ifc_nand.nand_fcr0,
  708. NAND_CMD_READID << IFC_NAND_FCR0_CMD0_SHIFT);
  709. ifc_out32(&ifc->ifc_nand.row3, 0x0);
  710. ifc_out32(&ifc->ifc_nand.nand_fbcr, 0x0);
  711. /* Program ROW0/COL0 */
  712. ifc_out32(&ifc->ifc_nand.row0, 0x0);
  713. ifc_out32(&ifc->ifc_nand.col0, 0x0);
  714. /* set the chip select for NAND Transaction */
  715. ifc_out32(&ifc->ifc_nand.nand_csel, priv->bank << IFC_NAND_CSEL_SHIFT);
  716. /* start read seq */
  717. ifc_out32(&ifc->ifc_nand.nandseq_strt, IFC_NAND_SEQ_STRT_FIR_STRT);
  718. time_start = get_timer(0);
  719. while (get_timer(time_start) < timeo) {
  720. ifc_ctrl->status = ifc_in32(&ifc->ifc_nand.nand_evter_stat);
  721. if (ifc_ctrl->status & IFC_NAND_EVTER_STAT_OPC)
  722. break;
  723. }
  724. if (ifc_ctrl->status != IFC_NAND_EVTER_STAT_OPC) {
  725. printf("fsl-ifc: Failed to Initialise SRAM\n");
  726. return 1;
  727. }
  728. ifc_out32(&ifc->ifc_nand.nand_evter_stat, ifc_ctrl->status);
  729. /* Restore CSOR and CSOR_ext */
  730. ifc_out32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor, csor);
  731. ifc_out32(&ifc_ctrl->regs.gregs->csor_cs[cs].csor_ext, csor_ext);
  732. return 0;
  733. }
  734. static int fsl_ifc_chip_init(int devnum, u8 *addr)
  735. {
  736. struct mtd_info *mtd;
  737. struct nand_chip *nand;
  738. struct fsl_ifc_mtd *priv;
  739. struct nand_ecclayout *layout;
  740. struct fsl_ifc_fcm *gregs = NULL;
  741. uint32_t cspr = 0, csor = 0, ver = 0;
  742. int ret = 0;
  743. if (!ifc_ctrl) {
  744. fsl_ifc_ctrl_init();
  745. if (!ifc_ctrl)
  746. return -1;
  747. }
  748. priv = kzalloc(sizeof(*priv), GFP_KERNEL);
  749. if (!priv)
  750. return -ENOMEM;
  751. priv->ctrl = ifc_ctrl;
  752. priv->vbase = addr;
  753. gregs = ifc_ctrl->regs.gregs;
  754. /* Find which chip select it is connected to.
  755. */
  756. for (priv->bank = 0; priv->bank < MAX_BANKS; priv->bank++) {
  757. phys_addr_t phys_addr = virt_to_phys(addr);
  758. cspr = ifc_in32(&gregs->cspr_cs[priv->bank].cspr);
  759. csor = ifc_in32(&gregs->csor_cs[priv->bank].csor);
  760. if ((cspr & CSPR_V) && (cspr & CSPR_MSEL) == CSPR_MSEL_NAND &&
  761. (cspr & CSPR_BA) == CSPR_PHYS_ADDR(phys_addr))
  762. break;
  763. }
  764. if (priv->bank >= MAX_BANKS) {
  765. printf("%s: address did not match any "
  766. "chip selects\n", __func__);
  767. kfree(priv);
  768. return -ENODEV;
  769. }
  770. nand = &priv->chip;
  771. mtd = nand_to_mtd(nand);
  772. ifc_ctrl->chips[priv->bank] = priv;
  773. /* fill in nand_chip structure */
  774. /* set up function call table */
  775. nand->write_buf = fsl_ifc_write_buf;
  776. nand->read_buf = fsl_ifc_read_buf;
  777. nand->select_chip = fsl_ifc_select_chip;
  778. nand->cmdfunc = fsl_ifc_cmdfunc;
  779. nand->waitfunc = fsl_ifc_wait;
  780. /* set up nand options */
  781. nand->bbt_td = &bbt_main_descr;
  782. nand->bbt_md = &bbt_mirror_descr;
  783. /* set up nand options */
  784. nand->options = NAND_NO_SUBPAGE_WRITE;
  785. nand->bbt_options = NAND_BBT_USE_FLASH;
  786. if (cspr & CSPR_PORT_SIZE_16) {
  787. nand->read_byte = fsl_ifc_read_byte16;
  788. nand->options |= NAND_BUSWIDTH_16;
  789. } else {
  790. nand->read_byte = fsl_ifc_read_byte;
  791. }
  792. nand->controller = &ifc_ctrl->controller;
  793. nand_set_controller_data(nand, priv);
  794. nand->ecc.read_page = fsl_ifc_read_page;
  795. nand->ecc.write_page = fsl_ifc_write_page;
  796. /* Hardware generates ECC per 512 Bytes */
  797. nand->ecc.size = 512;
  798. nand->ecc.bytes = 8;
  799. switch (csor & CSOR_NAND_PGS_MASK) {
  800. case CSOR_NAND_PGS_512:
  801. if (nand->options & NAND_BUSWIDTH_16) {
  802. layout = &oob_512_16bit_ecc4;
  803. } else {
  804. layout = &oob_512_8bit_ecc4;
  805. /* Avoid conflict with bad block marker */
  806. bbt_main_descr.offs = 0;
  807. bbt_mirror_descr.offs = 0;
  808. }
  809. nand->ecc.strength = 4;
  810. priv->bufnum_mask = 15;
  811. break;
  812. case CSOR_NAND_PGS_2K:
  813. layout = &oob_2048_ecc4;
  814. nand->ecc.strength = 4;
  815. priv->bufnum_mask = 3;
  816. break;
  817. case CSOR_NAND_PGS_4K:
  818. if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
  819. CSOR_NAND_ECC_MODE_4) {
  820. layout = &oob_4096_ecc4;
  821. nand->ecc.strength = 4;
  822. } else {
  823. layout = &oob_4096_ecc8;
  824. nand->ecc.strength = 8;
  825. nand->ecc.bytes = 16;
  826. }
  827. priv->bufnum_mask = 1;
  828. break;
  829. case CSOR_NAND_PGS_8K:
  830. if ((csor & CSOR_NAND_ECC_MODE_MASK) ==
  831. CSOR_NAND_ECC_MODE_4) {
  832. layout = &oob_8192_ecc4;
  833. nand->ecc.strength = 4;
  834. } else {
  835. layout = &oob_8192_ecc8;
  836. nand->ecc.strength = 8;
  837. nand->ecc.bytes = 16;
  838. }
  839. priv->bufnum_mask = 0;
  840. break;
  841. default:
  842. printf("ifc nand: bad csor %#x: bad page size\n", csor);
  843. return -ENODEV;
  844. }
  845. /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
  846. if (csor & CSOR_NAND_ECC_DEC_EN) {
  847. nand->ecc.mode = NAND_ECC_HW;
  848. nand->ecc.layout = layout;
  849. } else {
  850. nand->ecc.mode = NAND_ECC_SOFT;
  851. }
  852. ver = ifc_in32(&gregs->ifc_rev);
  853. if (ver >= FSL_IFC_V1_1_0)
  854. ret = fsl_ifc_sram_init(priv, ver);
  855. if (ret)
  856. return ret;
  857. if (ver >= FSL_IFC_V2_0_0)
  858. priv->bufnum_mask = (priv->bufnum_mask * 2) + 1;
  859. ret = nand_scan_ident(mtd, 1, NULL);
  860. if (ret)
  861. return ret;
  862. ret = nand_scan_tail(mtd);
  863. if (ret)
  864. return ret;
  865. ret = nand_register(devnum, mtd);
  866. if (ret)
  867. return ret;
  868. return 0;
  869. }
  870. #ifndef CONFIG_SYS_NAND_BASE_LIST
  871. #define CONFIG_SYS_NAND_BASE_LIST { CONFIG_SYS_NAND_BASE }
  872. #endif
  873. static unsigned long base_address[CONFIG_SYS_MAX_NAND_DEVICE] =
  874. CONFIG_SYS_NAND_BASE_LIST;
  875. void board_nand_init(void)
  876. {
  877. int i;
  878. for (i = 0; i < CONFIG_SYS_MAX_NAND_DEVICE; i++)
  879. fsl_ifc_chip_init(i, (u8 *)base_address[i]);
  880. }