fsl_ifc_nand.c 29 KB

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