fsl_ifc_nand.c 30 KB

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