fsl_ifc_nand.c 30 KB

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