fsl_ifc_nand.c 30 KB

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