fsl_ifc_nand.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095
  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. for (i = sector / 4; i <= sector_end / 4; i++)
  218. eccstat[i] = ifc_in32(&ifc->ifc_nand.nand_eccstat[i]);
  219. for (i = sector; i <= sector_end; i++) {
  220. errors = check_read_ecc(mtd, ctrl, eccstat, i);
  221. if (errors == 15) {
  222. /*
  223. * Uncorrectable error.
  224. * OK only if the whole page is blank.
  225. *
  226. * We disable ECCER reporting due to...
  227. * erratum IFC-A002770 -- so report it now if we
  228. * see an uncorrectable error in ECCSTAT.
  229. */
  230. if (!is_blank(mtd, bufnum))
  231. ctrl->nand_stat |=
  232. IFC_NAND_EVTER_STAT_ECCER;
  233. break;
  234. }
  235. mtd->ecc_stats.corrected += errors;
  236. nctrl->max_bitflips = max_t(unsigned int,
  237. nctrl->max_bitflips,
  238. errors);
  239. }
  240. nctrl->eccread = 0;
  241. }
  242. }
  243. static void fsl_ifc_do_read(struct nand_chip *chip,
  244. int oob,
  245. struct mtd_info *mtd)
  246. {
  247. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  248. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  249. struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
  250. /* Program FIR/IFC_NAND_FCR0 for Small/Large page */
  251. if (mtd->writesize > 512) {
  252. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  253. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  254. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  255. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP3_SHIFT) |
  256. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP4_SHIFT),
  257. &ifc->ifc_nand.nand_fir0);
  258. ifc_out32(0x0, &ifc->ifc_nand.nand_fir1);
  259. ifc_out32((NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT) |
  260. (NAND_CMD_READSTART << IFC_NAND_FCR0_CMD1_SHIFT),
  261. &ifc->ifc_nand.nand_fcr0);
  262. } else {
  263. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  264. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  265. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  266. (IFC_FIR_OP_RBCD << IFC_NAND_FIR0_OP3_SHIFT),
  267. &ifc->ifc_nand.nand_fir0);
  268. ifc_out32(0x0, &ifc->ifc_nand.nand_fir1);
  269. if (oob)
  270. ifc_out32(NAND_CMD_READOOB <<
  271. IFC_NAND_FCR0_CMD0_SHIFT,
  272. &ifc->ifc_nand.nand_fcr0);
  273. else
  274. ifc_out32(NAND_CMD_READ0 <<
  275. IFC_NAND_FCR0_CMD0_SHIFT,
  276. &ifc->ifc_nand.nand_fcr0);
  277. }
  278. }
  279. /* cmdfunc send commands to the IFC NAND Machine */
  280. static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
  281. int column, int page_addr) {
  282. struct nand_chip *chip = mtd_to_nand(mtd);
  283. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  284. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  285. struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
  286. /* clear the read buffer */
  287. ifc_nand_ctrl->read_bytes = 0;
  288. if (command != NAND_CMD_PAGEPROG)
  289. ifc_nand_ctrl->index = 0;
  290. switch (command) {
  291. /* READ0 read the entire buffer to use hardware ECC. */
  292. case NAND_CMD_READ0:
  293. ifc_out32(0, &ifc->ifc_nand.nand_fbcr);
  294. set_addr(mtd, 0, page_addr, 0);
  295. ifc_nand_ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  296. ifc_nand_ctrl->index += column;
  297. if (chip->ecc.mode == NAND_ECC_HW)
  298. ifc_nand_ctrl->eccread = 1;
  299. fsl_ifc_do_read(chip, 0, mtd);
  300. fsl_ifc_run_command(mtd);
  301. return;
  302. /* READOOB reads only the OOB because no ECC is performed. */
  303. case NAND_CMD_READOOB:
  304. ifc_out32(mtd->oobsize - column, &ifc->ifc_nand.nand_fbcr);
  305. set_addr(mtd, column, page_addr, 1);
  306. ifc_nand_ctrl->read_bytes = mtd->writesize + mtd->oobsize;
  307. fsl_ifc_do_read(chip, 1, mtd);
  308. fsl_ifc_run_command(mtd);
  309. return;
  310. case NAND_CMD_READID:
  311. case NAND_CMD_PARAM: {
  312. int timing = IFC_FIR_OP_RB;
  313. if (command == NAND_CMD_PARAM)
  314. timing = IFC_FIR_OP_RBCD;
  315. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  316. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  317. (timing << IFC_NAND_FIR0_OP2_SHIFT),
  318. &ifc->ifc_nand.nand_fir0);
  319. ifc_out32(command << IFC_NAND_FCR0_CMD0_SHIFT,
  320. &ifc->ifc_nand.nand_fcr0);
  321. ifc_out32(column, &ifc->ifc_nand.row3);
  322. /*
  323. * although currently it's 8 bytes for READID, we always read
  324. * the maximum 256 bytes(for PARAM)
  325. */
  326. ifc_out32(256, &ifc->ifc_nand.nand_fbcr);
  327. ifc_nand_ctrl->read_bytes = 256;
  328. set_addr(mtd, 0, 0, 0);
  329. fsl_ifc_run_command(mtd);
  330. return;
  331. }
  332. /* ERASE1 stores the block and page address */
  333. case NAND_CMD_ERASE1:
  334. set_addr(mtd, 0, page_addr, 0);
  335. return;
  336. /* ERASE2 uses the block and page address from ERASE1 */
  337. case NAND_CMD_ERASE2:
  338. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  339. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  340. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR0_OP2_SHIFT),
  341. &ifc->ifc_nand.nand_fir0);
  342. ifc_out32((NAND_CMD_ERASE1 << IFC_NAND_FCR0_CMD0_SHIFT) |
  343. (NAND_CMD_ERASE2 << IFC_NAND_FCR0_CMD1_SHIFT),
  344. &ifc->ifc_nand.nand_fcr0);
  345. ifc_out32(0, &ifc->ifc_nand.nand_fbcr);
  346. ifc_nand_ctrl->read_bytes = 0;
  347. fsl_ifc_run_command(mtd);
  348. return;
  349. /* SEQIN sets up the addr buffer and all registers except the length */
  350. case NAND_CMD_SEQIN: {
  351. u32 nand_fcr0;
  352. ifc_nand_ctrl->column = column;
  353. ifc_nand_ctrl->oob = 0;
  354. if (mtd->writesize > 512) {
  355. nand_fcr0 =
  356. (NAND_CMD_SEQIN << IFC_NAND_FCR0_CMD0_SHIFT) |
  357. (NAND_CMD_STATUS << IFC_NAND_FCR0_CMD1_SHIFT) |
  358. (NAND_CMD_PAGEPROG << IFC_NAND_FCR0_CMD2_SHIFT);
  359. ifc_out32(
  360. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  361. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP1_SHIFT) |
  362. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  363. (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP3_SHIFT) |
  364. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP4_SHIFT),
  365. &ifc->ifc_nand.nand_fir0);
  366. ifc_out32(
  367. (IFC_FIR_OP_CW1 << IFC_NAND_FIR1_OP5_SHIFT) |
  368. (IFC_FIR_OP_RDSTAT << IFC_NAND_FIR1_OP6_SHIFT) |
  369. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP7_SHIFT),
  370. &ifc->ifc_nand.nand_fir1);
  371. } else {
  372. nand_fcr0 = ((NAND_CMD_PAGEPROG <<
  373. IFC_NAND_FCR0_CMD1_SHIFT) |
  374. (NAND_CMD_SEQIN <<
  375. IFC_NAND_FCR0_CMD2_SHIFT) |
  376. (NAND_CMD_STATUS <<
  377. IFC_NAND_FCR0_CMD3_SHIFT));
  378. ifc_out32(
  379. (IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  380. (IFC_FIR_OP_CMD2 << IFC_NAND_FIR0_OP1_SHIFT) |
  381. (IFC_FIR_OP_CA0 << IFC_NAND_FIR0_OP2_SHIFT) |
  382. (IFC_FIR_OP_RA0 << IFC_NAND_FIR0_OP3_SHIFT) |
  383. (IFC_FIR_OP_WBCD << IFC_NAND_FIR0_OP4_SHIFT),
  384. &ifc->ifc_nand.nand_fir0);
  385. ifc_out32(
  386. (IFC_FIR_OP_CMD1 << IFC_NAND_FIR1_OP5_SHIFT) |
  387. (IFC_FIR_OP_CW3 << IFC_NAND_FIR1_OP6_SHIFT) |
  388. (IFC_FIR_OP_RDSTAT << IFC_NAND_FIR1_OP7_SHIFT) |
  389. (IFC_FIR_OP_NOP << IFC_NAND_FIR1_OP8_SHIFT),
  390. &ifc->ifc_nand.nand_fir1);
  391. if (column >= mtd->writesize)
  392. nand_fcr0 |=
  393. NAND_CMD_READOOB << IFC_NAND_FCR0_CMD0_SHIFT;
  394. else
  395. nand_fcr0 |=
  396. NAND_CMD_READ0 << IFC_NAND_FCR0_CMD0_SHIFT;
  397. }
  398. if (column >= mtd->writesize) {
  399. /* OOB area --> READOOB */
  400. column -= mtd->writesize;
  401. ifc_nand_ctrl->oob = 1;
  402. }
  403. ifc_out32(nand_fcr0, &ifc->ifc_nand.nand_fcr0);
  404. set_addr(mtd, column, page_addr, ifc_nand_ctrl->oob);
  405. return;
  406. }
  407. /* PAGEPROG reuses all of the setup from SEQIN and adds the length */
  408. case NAND_CMD_PAGEPROG: {
  409. if (ifc_nand_ctrl->oob) {
  410. ifc_out32(ifc_nand_ctrl->index -
  411. ifc_nand_ctrl->column,
  412. &ifc->ifc_nand.nand_fbcr);
  413. } else {
  414. ifc_out32(0, &ifc->ifc_nand.nand_fbcr);
  415. }
  416. fsl_ifc_run_command(mtd);
  417. return;
  418. }
  419. case NAND_CMD_STATUS: {
  420. void __iomem *addr;
  421. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  422. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP1_SHIFT),
  423. &ifc->ifc_nand.nand_fir0);
  424. ifc_out32(NAND_CMD_STATUS << IFC_NAND_FCR0_CMD0_SHIFT,
  425. &ifc->ifc_nand.nand_fcr0);
  426. ifc_out32(1, &ifc->ifc_nand.nand_fbcr);
  427. set_addr(mtd, 0, 0, 0);
  428. ifc_nand_ctrl->read_bytes = 1;
  429. fsl_ifc_run_command(mtd);
  430. /*
  431. * The chip always seems to report that it is
  432. * write-protected, even when it is not.
  433. */
  434. addr = ifc_nand_ctrl->addr;
  435. if (chip->options & NAND_BUSWIDTH_16)
  436. ifc_out16(ifc_in16(addr) | (NAND_STATUS_WP), addr);
  437. else
  438. ifc_out8(ifc_in8(addr) | (NAND_STATUS_WP), addr);
  439. return;
  440. }
  441. case NAND_CMD_RESET:
  442. ifc_out32(IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT,
  443. &ifc->ifc_nand.nand_fir0);
  444. ifc_out32(NAND_CMD_RESET << IFC_NAND_FCR0_CMD0_SHIFT,
  445. &ifc->ifc_nand.nand_fcr0);
  446. fsl_ifc_run_command(mtd);
  447. return;
  448. default:
  449. dev_err(priv->dev, "%s: error, unsupported command 0x%x.\n",
  450. __func__, command);
  451. }
  452. }
  453. static void fsl_ifc_select_chip(struct mtd_info *mtd, int chip)
  454. {
  455. /* The hardware does not seem to support multiple
  456. * chips per bank.
  457. */
  458. }
  459. /*
  460. * Write buf to the IFC NAND Controller Data Buffer
  461. */
  462. static void fsl_ifc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  463. {
  464. struct nand_chip *chip = mtd_to_nand(mtd);
  465. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  466. unsigned int bufsize = mtd->writesize + mtd->oobsize;
  467. if (len <= 0) {
  468. dev_err(priv->dev, "%s: len %d bytes", __func__, len);
  469. return;
  470. }
  471. if ((unsigned int)len > bufsize - ifc_nand_ctrl->index) {
  472. dev_err(priv->dev,
  473. "%s: beyond end of buffer (%d requested, %u available)\n",
  474. __func__, len, bufsize - ifc_nand_ctrl->index);
  475. len = bufsize - ifc_nand_ctrl->index;
  476. }
  477. memcpy_toio(ifc_nand_ctrl->addr + ifc_nand_ctrl->index, buf, len);
  478. ifc_nand_ctrl->index += len;
  479. }
  480. /*
  481. * Read a byte from either the IFC hardware buffer
  482. * read function for 8-bit buswidth
  483. */
  484. static uint8_t fsl_ifc_read_byte(struct mtd_info *mtd)
  485. {
  486. struct nand_chip *chip = mtd_to_nand(mtd);
  487. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  488. unsigned int offset;
  489. /*
  490. * If there are still bytes in the IFC buffer, then use the
  491. * next byte.
  492. */
  493. if (ifc_nand_ctrl->index < ifc_nand_ctrl->read_bytes) {
  494. offset = ifc_nand_ctrl->index++;
  495. return ifc_in8(ifc_nand_ctrl->addr + offset);
  496. }
  497. dev_err(priv->dev, "%s: beyond end of buffer\n", __func__);
  498. return ERR_BYTE;
  499. }
  500. /*
  501. * Read two bytes from the IFC hardware buffer
  502. * read function for 16-bit buswith
  503. */
  504. static uint8_t fsl_ifc_read_byte16(struct mtd_info *mtd)
  505. {
  506. struct nand_chip *chip = mtd_to_nand(mtd);
  507. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  508. uint16_t data;
  509. /*
  510. * If there are still bytes in the IFC buffer, then use the
  511. * next byte.
  512. */
  513. if (ifc_nand_ctrl->index < ifc_nand_ctrl->read_bytes) {
  514. data = ifc_in16(ifc_nand_ctrl->addr + ifc_nand_ctrl->index);
  515. ifc_nand_ctrl->index += 2;
  516. return (uint8_t) data;
  517. }
  518. dev_err(priv->dev, "%s: beyond end of buffer\n", __func__);
  519. return ERR_BYTE;
  520. }
  521. /*
  522. * Read from the IFC Controller Data Buffer
  523. */
  524. static void fsl_ifc_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  525. {
  526. struct nand_chip *chip = mtd_to_nand(mtd);
  527. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  528. int avail;
  529. if (len < 0) {
  530. dev_err(priv->dev, "%s: len %d bytes", __func__, len);
  531. return;
  532. }
  533. avail = min((unsigned int)len,
  534. ifc_nand_ctrl->read_bytes - ifc_nand_ctrl->index);
  535. memcpy_fromio(buf, ifc_nand_ctrl->addr + ifc_nand_ctrl->index, avail);
  536. ifc_nand_ctrl->index += avail;
  537. if (len > avail)
  538. dev_err(priv->dev,
  539. "%s: beyond end of buffer (%d requested, %d available)\n",
  540. __func__, len, avail);
  541. }
  542. /*
  543. * This function is called after Program and Erase Operations to
  544. * check for success or failure.
  545. */
  546. static int fsl_ifc_wait(struct mtd_info *mtd, struct nand_chip *chip)
  547. {
  548. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  549. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  550. struct fsl_ifc_runtime __iomem *ifc = ctrl->rregs;
  551. u32 nand_fsr;
  552. /* Use READ_STATUS command, but wait for the device to be ready */
  553. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  554. (IFC_FIR_OP_RDSTAT << IFC_NAND_FIR0_OP1_SHIFT),
  555. &ifc->ifc_nand.nand_fir0);
  556. ifc_out32(NAND_CMD_STATUS << IFC_NAND_FCR0_CMD0_SHIFT,
  557. &ifc->ifc_nand.nand_fcr0);
  558. ifc_out32(1, &ifc->ifc_nand.nand_fbcr);
  559. set_addr(mtd, 0, 0, 0);
  560. ifc_nand_ctrl->read_bytes = 1;
  561. fsl_ifc_run_command(mtd);
  562. nand_fsr = ifc_in32(&ifc->ifc_nand.nand_fsr);
  563. /*
  564. * The chip always seems to report that it is
  565. * write-protected, even when it is not.
  566. */
  567. return nand_fsr | NAND_STATUS_WP;
  568. }
  569. static int fsl_ifc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
  570. uint8_t *buf, int oob_required, int page)
  571. {
  572. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  573. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  574. struct fsl_ifc_nand_ctrl *nctrl = ifc_nand_ctrl;
  575. fsl_ifc_read_buf(mtd, buf, mtd->writesize);
  576. if (oob_required)
  577. fsl_ifc_read_buf(mtd, chip->oob_poi, mtd->oobsize);
  578. if (ctrl->nand_stat & IFC_NAND_EVTER_STAT_ECCER)
  579. dev_err(priv->dev, "NAND Flash ECC Uncorrectable Error\n");
  580. if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC)
  581. mtd->ecc_stats.failed++;
  582. return nctrl->max_bitflips;
  583. }
  584. /* ECC will be calculated automatically, and errors will be detected in
  585. * waitfunc.
  586. */
  587. static int fsl_ifc_write_page(struct mtd_info *mtd, struct nand_chip *chip,
  588. const uint8_t *buf, int oob_required, int page)
  589. {
  590. fsl_ifc_write_buf(mtd, buf, mtd->writesize);
  591. fsl_ifc_write_buf(mtd, chip->oob_poi, mtd->oobsize);
  592. return 0;
  593. }
  594. static int fsl_ifc_chip_init_tail(struct mtd_info *mtd)
  595. {
  596. struct nand_chip *chip = mtd_to_nand(mtd);
  597. struct fsl_ifc_mtd *priv = nand_get_controller_data(chip);
  598. dev_dbg(priv->dev, "%s: nand->numchips = %d\n", __func__,
  599. chip->numchips);
  600. dev_dbg(priv->dev, "%s: nand->chipsize = %lld\n", __func__,
  601. chip->chipsize);
  602. dev_dbg(priv->dev, "%s: nand->pagemask = %8x\n", __func__,
  603. chip->pagemask);
  604. dev_dbg(priv->dev, "%s: nand->chip_delay = %d\n", __func__,
  605. chip->chip_delay);
  606. dev_dbg(priv->dev, "%s: nand->badblockpos = %d\n", __func__,
  607. chip->badblockpos);
  608. dev_dbg(priv->dev, "%s: nand->chip_shift = %d\n", __func__,
  609. chip->chip_shift);
  610. dev_dbg(priv->dev, "%s: nand->page_shift = %d\n", __func__,
  611. chip->page_shift);
  612. dev_dbg(priv->dev, "%s: nand->phys_erase_shift = %d\n", __func__,
  613. chip->phys_erase_shift);
  614. dev_dbg(priv->dev, "%s: nand->ecc.mode = %d\n", __func__,
  615. chip->ecc.mode);
  616. dev_dbg(priv->dev, "%s: nand->ecc.steps = %d\n", __func__,
  617. chip->ecc.steps);
  618. dev_dbg(priv->dev, "%s: nand->ecc.bytes = %d\n", __func__,
  619. chip->ecc.bytes);
  620. dev_dbg(priv->dev, "%s: nand->ecc.total = %d\n", __func__,
  621. chip->ecc.total);
  622. dev_dbg(priv->dev, "%s: mtd->ooblayout = %p\n", __func__,
  623. mtd->ooblayout);
  624. dev_dbg(priv->dev, "%s: mtd->flags = %08x\n", __func__, mtd->flags);
  625. dev_dbg(priv->dev, "%s: mtd->size = %lld\n", __func__, mtd->size);
  626. dev_dbg(priv->dev, "%s: mtd->erasesize = %d\n", __func__,
  627. mtd->erasesize);
  628. dev_dbg(priv->dev, "%s: mtd->writesize = %d\n", __func__,
  629. mtd->writesize);
  630. dev_dbg(priv->dev, "%s: mtd->oobsize = %d\n", __func__,
  631. mtd->oobsize);
  632. return 0;
  633. }
  634. static void fsl_ifc_sram_init(struct fsl_ifc_mtd *priv)
  635. {
  636. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  637. struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs;
  638. struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
  639. uint32_t csor = 0, csor_8k = 0, csor_ext = 0;
  640. uint32_t cs = priv->bank;
  641. /* Save CSOR and CSOR_ext */
  642. csor = ifc_in32(&ifc_global->csor_cs[cs].csor);
  643. csor_ext = ifc_in32(&ifc_global->csor_cs[cs].csor_ext);
  644. /* chage PageSize 8K and SpareSize 1K*/
  645. csor_8k = (csor & ~(CSOR_NAND_PGS_MASK)) | 0x0018C000;
  646. ifc_out32(csor_8k, &ifc_global->csor_cs[cs].csor);
  647. ifc_out32(0x0000400, &ifc_global->csor_cs[cs].csor_ext);
  648. /* READID */
  649. ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
  650. (IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
  651. (IFC_FIR_OP_RB << IFC_NAND_FIR0_OP2_SHIFT),
  652. &ifc_runtime->ifc_nand.nand_fir0);
  653. ifc_out32(NAND_CMD_READID << IFC_NAND_FCR0_CMD0_SHIFT,
  654. &ifc_runtime->ifc_nand.nand_fcr0);
  655. ifc_out32(0x0, &ifc_runtime->ifc_nand.row3);
  656. ifc_out32(0x0, &ifc_runtime->ifc_nand.nand_fbcr);
  657. /* Program ROW0/COL0 */
  658. ifc_out32(0x0, &ifc_runtime->ifc_nand.row0);
  659. ifc_out32(0x0, &ifc_runtime->ifc_nand.col0);
  660. /* set the chip select for NAND Transaction */
  661. ifc_out32(cs << IFC_NAND_CSEL_SHIFT,
  662. &ifc_runtime->ifc_nand.nand_csel);
  663. /* start read seq */
  664. ifc_out32(IFC_NAND_SEQ_STRT_FIR_STRT,
  665. &ifc_runtime->ifc_nand.nandseq_strt);
  666. /* wait for command complete flag or timeout */
  667. wait_event_timeout(ctrl->nand_wait, ctrl->nand_stat,
  668. msecs_to_jiffies(IFC_TIMEOUT_MSECS));
  669. if (ctrl->nand_stat != IFC_NAND_EVTER_STAT_OPC)
  670. printk(KERN_ERR "fsl-ifc: Failed to Initialise SRAM\n");
  671. /* Restore CSOR and CSOR_ext */
  672. ifc_out32(csor, &ifc_global->csor_cs[cs].csor);
  673. ifc_out32(csor_ext, &ifc_global->csor_cs[cs].csor_ext);
  674. }
  675. static int fsl_ifc_chip_init(struct fsl_ifc_mtd *priv)
  676. {
  677. struct fsl_ifc_ctrl *ctrl = priv->ctrl;
  678. struct fsl_ifc_global __iomem *ifc_global = ctrl->gregs;
  679. struct fsl_ifc_runtime __iomem *ifc_runtime = ctrl->rregs;
  680. struct nand_chip *chip = &priv->chip;
  681. struct mtd_info *mtd = nand_to_mtd(&priv->chip);
  682. u32 csor;
  683. /* Fill in fsl_ifc_mtd structure */
  684. mtd->dev.parent = priv->dev;
  685. nand_set_flash_node(chip, priv->dev->of_node);
  686. /* fill in nand_chip structure */
  687. /* set up function call table */
  688. if ((ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr))
  689. & CSPR_PORT_SIZE_16)
  690. chip->read_byte = fsl_ifc_read_byte16;
  691. else
  692. chip->read_byte = fsl_ifc_read_byte;
  693. chip->write_buf = fsl_ifc_write_buf;
  694. chip->read_buf = fsl_ifc_read_buf;
  695. chip->select_chip = fsl_ifc_select_chip;
  696. chip->cmdfunc = fsl_ifc_cmdfunc;
  697. chip->waitfunc = fsl_ifc_wait;
  698. chip->bbt_td = &bbt_main_descr;
  699. chip->bbt_md = &bbt_mirror_descr;
  700. ifc_out32(0x0, &ifc_runtime->ifc_nand.ncfgr);
  701. /* set up nand options */
  702. chip->bbt_options = NAND_BBT_USE_FLASH;
  703. chip->options = NAND_NO_SUBPAGE_WRITE;
  704. if (ifc_in32(&ifc_global->cspr_cs[priv->bank].cspr)
  705. & CSPR_PORT_SIZE_16) {
  706. chip->read_byte = fsl_ifc_read_byte16;
  707. chip->options |= NAND_BUSWIDTH_16;
  708. } else {
  709. chip->read_byte = fsl_ifc_read_byte;
  710. }
  711. chip->controller = &ifc_nand_ctrl->controller;
  712. nand_set_controller_data(chip, priv);
  713. chip->ecc.read_page = fsl_ifc_read_page;
  714. chip->ecc.write_page = fsl_ifc_write_page;
  715. csor = ifc_in32(&ifc_global->csor_cs[priv->bank].csor);
  716. switch (csor & CSOR_NAND_PGS_MASK) {
  717. case CSOR_NAND_PGS_512:
  718. if (!(chip->options & NAND_BUSWIDTH_16)) {
  719. /* Avoid conflict with bad block marker */
  720. bbt_main_descr.offs = 0;
  721. bbt_mirror_descr.offs = 0;
  722. }
  723. priv->bufnum_mask = 15;
  724. break;
  725. case CSOR_NAND_PGS_2K:
  726. priv->bufnum_mask = 3;
  727. break;
  728. case CSOR_NAND_PGS_4K:
  729. priv->bufnum_mask = 1;
  730. break;
  731. case CSOR_NAND_PGS_8K:
  732. priv->bufnum_mask = 0;
  733. break;
  734. default:
  735. dev_err(priv->dev, "bad csor %#x: bad page size\n", csor);
  736. return -ENODEV;
  737. }
  738. /* Must also set CSOR_NAND_ECC_ENC_EN if DEC_EN set */
  739. if (csor & CSOR_NAND_ECC_DEC_EN) {
  740. chip->ecc.mode = NAND_ECC_HW;
  741. mtd_set_ooblayout(mtd, &fsl_ifc_ooblayout_ops);
  742. /* Hardware generates ECC per 512 Bytes */
  743. chip->ecc.size = 512;
  744. if ((csor & CSOR_NAND_ECC_MODE_MASK) == CSOR_NAND_ECC_MODE_4) {
  745. chip->ecc.bytes = 8;
  746. chip->ecc.strength = 4;
  747. } else {
  748. chip->ecc.bytes = 16;
  749. chip->ecc.strength = 8;
  750. }
  751. } else {
  752. chip->ecc.mode = NAND_ECC_SOFT;
  753. chip->ecc.algo = NAND_ECC_HAMMING;
  754. }
  755. if (ctrl->version == FSL_IFC_VERSION_1_1_0)
  756. fsl_ifc_sram_init(priv);
  757. return 0;
  758. }
  759. static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
  760. {
  761. struct mtd_info *mtd = nand_to_mtd(&priv->chip);
  762. nand_release(mtd);
  763. kfree(mtd->name);
  764. if (priv->vbase)
  765. iounmap(priv->vbase);
  766. ifc_nand_ctrl->chips[priv->bank] = NULL;
  767. return 0;
  768. }
  769. static int match_bank(struct fsl_ifc_global __iomem *ifc_global, int bank,
  770. phys_addr_t addr)
  771. {
  772. u32 cspr = ifc_in32(&ifc_global->cspr_cs[bank].cspr);
  773. if (!(cspr & CSPR_V))
  774. return 0;
  775. if ((cspr & CSPR_MSEL) != CSPR_MSEL_NAND)
  776. return 0;
  777. return (cspr & CSPR_BA) == convert_ifc_address(addr);
  778. }
  779. static DEFINE_MUTEX(fsl_ifc_nand_mutex);
  780. static int fsl_ifc_nand_probe(struct platform_device *dev)
  781. {
  782. struct fsl_ifc_runtime __iomem *ifc;
  783. struct fsl_ifc_mtd *priv;
  784. struct resource res;
  785. static const char *part_probe_types[]
  786. = { "cmdlinepart", "RedBoot", "ofpart", NULL };
  787. int ret;
  788. int bank;
  789. struct device_node *node = dev->dev.of_node;
  790. struct mtd_info *mtd;
  791. if (!fsl_ifc_ctrl_dev || !fsl_ifc_ctrl_dev->rregs)
  792. return -ENODEV;
  793. ifc = fsl_ifc_ctrl_dev->rregs;
  794. /* get, allocate and map the memory resource */
  795. ret = of_address_to_resource(node, 0, &res);
  796. if (ret) {
  797. dev_err(&dev->dev, "%s: failed to get resource\n", __func__);
  798. return ret;
  799. }
  800. /* find which chip select it is connected to */
  801. for (bank = 0; bank < fsl_ifc_ctrl_dev->banks; bank++) {
  802. if (match_bank(fsl_ifc_ctrl_dev->gregs, bank, res.start))
  803. break;
  804. }
  805. if (bank >= fsl_ifc_ctrl_dev->banks) {
  806. dev_err(&dev->dev, "%s: address did not match any chip selects\n",
  807. __func__);
  808. return -ENODEV;
  809. }
  810. priv = devm_kzalloc(&dev->dev, sizeof(*priv), GFP_KERNEL);
  811. if (!priv)
  812. return -ENOMEM;
  813. mutex_lock(&fsl_ifc_nand_mutex);
  814. if (!fsl_ifc_ctrl_dev->nand) {
  815. ifc_nand_ctrl = kzalloc(sizeof(*ifc_nand_ctrl), GFP_KERNEL);
  816. if (!ifc_nand_ctrl) {
  817. mutex_unlock(&fsl_ifc_nand_mutex);
  818. return -ENOMEM;
  819. }
  820. ifc_nand_ctrl->read_bytes = 0;
  821. ifc_nand_ctrl->index = 0;
  822. ifc_nand_ctrl->addr = NULL;
  823. fsl_ifc_ctrl_dev->nand = ifc_nand_ctrl;
  824. nand_hw_control_init(&ifc_nand_ctrl->controller);
  825. } else {
  826. ifc_nand_ctrl = fsl_ifc_ctrl_dev->nand;
  827. }
  828. mutex_unlock(&fsl_ifc_nand_mutex);
  829. ifc_nand_ctrl->chips[bank] = priv;
  830. priv->bank = bank;
  831. priv->ctrl = fsl_ifc_ctrl_dev;
  832. priv->dev = &dev->dev;
  833. priv->vbase = ioremap(res.start, resource_size(&res));
  834. if (!priv->vbase) {
  835. dev_err(priv->dev, "%s: failed to map chip region\n", __func__);
  836. ret = -ENOMEM;
  837. goto err;
  838. }
  839. dev_set_drvdata(priv->dev, priv);
  840. ifc_out32(IFC_NAND_EVTER_EN_OPC_EN |
  841. IFC_NAND_EVTER_EN_FTOER_EN |
  842. IFC_NAND_EVTER_EN_WPER_EN,
  843. &ifc->ifc_nand.nand_evter_en);
  844. /* enable NAND Machine Interrupts */
  845. ifc_out32(IFC_NAND_EVTER_INTR_OPCIR_EN |
  846. IFC_NAND_EVTER_INTR_FTOERIR_EN |
  847. IFC_NAND_EVTER_INTR_WPERIR_EN,
  848. &ifc->ifc_nand.nand_evter_intr_en);
  849. mtd = nand_to_mtd(&priv->chip);
  850. mtd->name = kasprintf(GFP_KERNEL, "%llx.flash", (u64)res.start);
  851. if (!mtd->name) {
  852. ret = -ENOMEM;
  853. goto err;
  854. }
  855. ret = fsl_ifc_chip_init(priv);
  856. if (ret)
  857. goto err;
  858. ret = nand_scan_ident(mtd, 1, NULL);
  859. if (ret)
  860. goto err;
  861. ret = fsl_ifc_chip_init_tail(mtd);
  862. if (ret)
  863. goto err;
  864. ret = nand_scan_tail(mtd);
  865. if (ret)
  866. goto err;
  867. /* First look for RedBoot table or partitions on the command
  868. * line, these take precedence over device tree information */
  869. mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
  870. dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
  871. (unsigned long long)res.start, priv->bank);
  872. return 0;
  873. err:
  874. fsl_ifc_chip_remove(priv);
  875. return ret;
  876. }
  877. static int fsl_ifc_nand_remove(struct platform_device *dev)
  878. {
  879. struct fsl_ifc_mtd *priv = dev_get_drvdata(&dev->dev);
  880. fsl_ifc_chip_remove(priv);
  881. mutex_lock(&fsl_ifc_nand_mutex);
  882. ifc_nand_ctrl->counter--;
  883. if (!ifc_nand_ctrl->counter) {
  884. fsl_ifc_ctrl_dev->nand = NULL;
  885. kfree(ifc_nand_ctrl);
  886. }
  887. mutex_unlock(&fsl_ifc_nand_mutex);
  888. return 0;
  889. }
  890. static const struct of_device_id fsl_ifc_nand_match[] = {
  891. {
  892. .compatible = "fsl,ifc-nand",
  893. },
  894. {}
  895. };
  896. MODULE_DEVICE_TABLE(of, fsl_ifc_nand_match);
  897. static struct platform_driver fsl_ifc_nand_driver = {
  898. .driver = {
  899. .name = "fsl,ifc-nand",
  900. .of_match_table = fsl_ifc_nand_match,
  901. },
  902. .probe = fsl_ifc_nand_probe,
  903. .remove = fsl_ifc_nand_remove,
  904. };
  905. module_platform_driver(fsl_ifc_nand_driver);
  906. MODULE_LICENSE("GPL");
  907. MODULE_AUTHOR("Freescale");
  908. MODULE_DESCRIPTION("Freescale Integrated Flash Controller MTD NAND driver");