mxc_nand.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  1. /*
  2. * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  3. * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version 2
  8. * of the License, or (at your option) any later version.
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
  17. * MA 02110-1301, USA.
  18. */
  19. #include <linux/delay.h>
  20. #include <linux/slab.h>
  21. #include <linux/init.h>
  22. #include <linux/module.h>
  23. #include <linux/mtd/mtd.h>
  24. #include <linux/mtd/nand.h>
  25. #include <linux/mtd/partitions.h>
  26. #include <linux/interrupt.h>
  27. #include <linux/device.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/clk.h>
  30. #include <linux/err.h>
  31. #include <linux/io.h>
  32. #include <linux/irq.h>
  33. #include <linux/completion.h>
  34. #include <linux/of.h>
  35. #include <linux/of_device.h>
  36. #include <linux/of_mtd.h>
  37. #include <asm/mach/flash.h>
  38. #include <linux/platform_data/mtd-mxc_nand.h>
  39. #define DRIVER_NAME "mxc_nand"
  40. /* Addresses for NFC registers */
  41. #define NFC_V1_V2_BUF_SIZE (host->regs + 0x00)
  42. #define NFC_V1_V2_BUF_ADDR (host->regs + 0x04)
  43. #define NFC_V1_V2_FLASH_ADDR (host->regs + 0x06)
  44. #define NFC_V1_V2_FLASH_CMD (host->regs + 0x08)
  45. #define NFC_V1_V2_CONFIG (host->regs + 0x0a)
  46. #define NFC_V1_V2_ECC_STATUS_RESULT (host->regs + 0x0c)
  47. #define NFC_V1_V2_RSLTMAIN_AREA (host->regs + 0x0e)
  48. #define NFC_V1_V2_RSLTSPARE_AREA (host->regs + 0x10)
  49. #define NFC_V1_V2_WRPROT (host->regs + 0x12)
  50. #define NFC_V1_UNLOCKSTART_BLKADDR (host->regs + 0x14)
  51. #define NFC_V1_UNLOCKEND_BLKADDR (host->regs + 0x16)
  52. #define NFC_V21_UNLOCKSTART_BLKADDR0 (host->regs + 0x20)
  53. #define NFC_V21_UNLOCKSTART_BLKADDR1 (host->regs + 0x24)
  54. #define NFC_V21_UNLOCKSTART_BLKADDR2 (host->regs + 0x28)
  55. #define NFC_V21_UNLOCKSTART_BLKADDR3 (host->regs + 0x2c)
  56. #define NFC_V21_UNLOCKEND_BLKADDR0 (host->regs + 0x22)
  57. #define NFC_V21_UNLOCKEND_BLKADDR1 (host->regs + 0x26)
  58. #define NFC_V21_UNLOCKEND_BLKADDR2 (host->regs + 0x2a)
  59. #define NFC_V21_UNLOCKEND_BLKADDR3 (host->regs + 0x2e)
  60. #define NFC_V1_V2_NF_WRPRST (host->regs + 0x18)
  61. #define NFC_V1_V2_CONFIG1 (host->regs + 0x1a)
  62. #define NFC_V1_V2_CONFIG2 (host->regs + 0x1c)
  63. #define NFC_V2_CONFIG1_ECC_MODE_4 (1 << 0)
  64. #define NFC_V1_V2_CONFIG1_SP_EN (1 << 2)
  65. #define NFC_V1_V2_CONFIG1_ECC_EN (1 << 3)
  66. #define NFC_V1_V2_CONFIG1_INT_MSK (1 << 4)
  67. #define NFC_V1_V2_CONFIG1_BIG (1 << 5)
  68. #define NFC_V1_V2_CONFIG1_RST (1 << 6)
  69. #define NFC_V1_V2_CONFIG1_CE (1 << 7)
  70. #define NFC_V2_CONFIG1_ONE_CYCLE (1 << 8)
  71. #define NFC_V2_CONFIG1_PPB(x) (((x) & 0x3) << 9)
  72. #define NFC_V2_CONFIG1_FP_INT (1 << 11)
  73. #define NFC_V1_V2_CONFIG2_INT (1 << 15)
  74. /*
  75. * Operation modes for the NFC. Valid for v1, v2 and v3
  76. * type controllers.
  77. */
  78. #define NFC_CMD (1 << 0)
  79. #define NFC_ADDR (1 << 1)
  80. #define NFC_INPUT (1 << 2)
  81. #define NFC_OUTPUT (1 << 3)
  82. #define NFC_ID (1 << 4)
  83. #define NFC_STATUS (1 << 5)
  84. #define NFC_V3_FLASH_CMD (host->regs_axi + 0x00)
  85. #define NFC_V3_FLASH_ADDR0 (host->regs_axi + 0x04)
  86. #define NFC_V3_CONFIG1 (host->regs_axi + 0x34)
  87. #define NFC_V3_CONFIG1_SP_EN (1 << 0)
  88. #define NFC_V3_CONFIG1_RBA(x) (((x) & 0x7 ) << 4)
  89. #define NFC_V3_ECC_STATUS_RESULT (host->regs_axi + 0x38)
  90. #define NFC_V3_LAUNCH (host->regs_axi + 0x40)
  91. #define NFC_V3_WRPROT (host->regs_ip + 0x0)
  92. #define NFC_V3_WRPROT_LOCK_TIGHT (1 << 0)
  93. #define NFC_V3_WRPROT_LOCK (1 << 1)
  94. #define NFC_V3_WRPROT_UNLOCK (1 << 2)
  95. #define NFC_V3_WRPROT_BLS_UNLOCK (2 << 6)
  96. #define NFC_V3_WRPROT_UNLOCK_BLK_ADD0 (host->regs_ip + 0x04)
  97. #define NFC_V3_CONFIG2 (host->regs_ip + 0x24)
  98. #define NFC_V3_CONFIG2_PS_512 (0 << 0)
  99. #define NFC_V3_CONFIG2_PS_2048 (1 << 0)
  100. #define NFC_V3_CONFIG2_PS_4096 (2 << 0)
  101. #define NFC_V3_CONFIG2_ONE_CYCLE (1 << 2)
  102. #define NFC_V3_CONFIG2_ECC_EN (1 << 3)
  103. #define NFC_V3_CONFIG2_2CMD_PHASES (1 << 4)
  104. #define NFC_V3_CONFIG2_NUM_ADDR_PHASE0 (1 << 5)
  105. #define NFC_V3_CONFIG2_ECC_MODE_8 (1 << 6)
  106. #define NFC_V3_CONFIG2_PPB(x, shift) (((x) & 0x3) << shift)
  107. #define NFC_V3_CONFIG2_NUM_ADDR_PHASE1(x) (((x) & 0x3) << 12)
  108. #define NFC_V3_CONFIG2_INT_MSK (1 << 15)
  109. #define NFC_V3_CONFIG2_ST_CMD(x) (((x) & 0xff) << 24)
  110. #define NFC_V3_CONFIG2_SPAS(x) (((x) & 0xff) << 16)
  111. #define NFC_V3_CONFIG3 (host->regs_ip + 0x28)
  112. #define NFC_V3_CONFIG3_ADD_OP(x) (((x) & 0x3) << 0)
  113. #define NFC_V3_CONFIG3_FW8 (1 << 3)
  114. #define NFC_V3_CONFIG3_SBB(x) (((x) & 0x7) << 8)
  115. #define NFC_V3_CONFIG3_NUM_OF_DEVICES(x) (((x) & 0x7) << 12)
  116. #define NFC_V3_CONFIG3_RBB_MODE (1 << 15)
  117. #define NFC_V3_CONFIG3_NO_SDMA (1 << 20)
  118. #define NFC_V3_IPC (host->regs_ip + 0x2C)
  119. #define NFC_V3_IPC_CREQ (1 << 0)
  120. #define NFC_V3_IPC_INT (1 << 31)
  121. #define NFC_V3_DELAY_LINE (host->regs_ip + 0x34)
  122. struct mxc_nand_host;
  123. struct mxc_nand_devtype_data {
  124. void (*preset)(struct mtd_info *);
  125. void (*send_cmd)(struct mxc_nand_host *, uint16_t, int);
  126. void (*send_addr)(struct mxc_nand_host *, uint16_t, int);
  127. void (*send_page)(struct mtd_info *, unsigned int);
  128. void (*send_read_id)(struct mxc_nand_host *);
  129. uint16_t (*get_dev_status)(struct mxc_nand_host *);
  130. int (*check_int)(struct mxc_nand_host *);
  131. void (*irq_control)(struct mxc_nand_host *, int);
  132. u32 (*get_ecc_status)(struct mxc_nand_host *);
  133. struct nand_ecclayout *ecclayout_512, *ecclayout_2k, *ecclayout_4k;
  134. void (*select_chip)(struct mtd_info *mtd, int chip);
  135. int (*correct_data)(struct mtd_info *mtd, u_char *dat,
  136. u_char *read_ecc, u_char *calc_ecc);
  137. /*
  138. * On i.MX21 the CONFIG2:INT bit cannot be read if interrupts are masked
  139. * (CONFIG1:INT_MSK is set). To handle this the driver uses
  140. * enable_irq/disable_irq_nosync instead of CONFIG1:INT_MSK
  141. */
  142. int irqpending_quirk;
  143. int needs_ip;
  144. size_t regs_offset;
  145. size_t spare0_offset;
  146. size_t axi_offset;
  147. int spare_len;
  148. int eccbytes;
  149. int eccsize;
  150. int ppb_shift;
  151. };
  152. struct mxc_nand_host {
  153. struct nand_chip nand;
  154. struct device *dev;
  155. void __iomem *spare0;
  156. void __iomem *main_area0;
  157. void __iomem *base;
  158. void __iomem *regs;
  159. void __iomem *regs_axi;
  160. void __iomem *regs_ip;
  161. int status_request;
  162. struct clk *clk;
  163. int clk_act;
  164. int irq;
  165. int eccsize;
  166. int used_oobsize;
  167. int active_cs;
  168. struct completion op_completion;
  169. uint8_t *data_buf;
  170. unsigned int buf_start;
  171. const struct mxc_nand_devtype_data *devtype_data;
  172. struct mxc_nand_platform_data pdata;
  173. };
  174. /* OOB placement block for use with hardware ecc generation */
  175. static struct nand_ecclayout nandv1_hw_eccoob_smallpage = {
  176. .eccbytes = 5,
  177. .eccpos = {6, 7, 8, 9, 10},
  178. .oobfree = {{0, 5}, {12, 4}, }
  179. };
  180. static struct nand_ecclayout nandv1_hw_eccoob_largepage = {
  181. .eccbytes = 20,
  182. .eccpos = {6, 7, 8, 9, 10, 22, 23, 24, 25, 26,
  183. 38, 39, 40, 41, 42, 54, 55, 56, 57, 58},
  184. .oobfree = {{2, 4}, {11, 10}, {27, 10}, {43, 10}, {59, 5}, }
  185. };
  186. /* OOB description for 512 byte pages with 16 byte OOB */
  187. static struct nand_ecclayout nandv2_hw_eccoob_smallpage = {
  188. .eccbytes = 1 * 9,
  189. .eccpos = {
  190. 7, 8, 9, 10, 11, 12, 13, 14, 15
  191. },
  192. .oobfree = {
  193. {.offset = 0, .length = 5}
  194. }
  195. };
  196. /* OOB description for 2048 byte pages with 64 byte OOB */
  197. static struct nand_ecclayout nandv2_hw_eccoob_largepage = {
  198. .eccbytes = 4 * 9,
  199. .eccpos = {
  200. 7, 8, 9, 10, 11, 12, 13, 14, 15,
  201. 23, 24, 25, 26, 27, 28, 29, 30, 31,
  202. 39, 40, 41, 42, 43, 44, 45, 46, 47,
  203. 55, 56, 57, 58, 59, 60, 61, 62, 63
  204. },
  205. .oobfree = {
  206. {.offset = 2, .length = 4},
  207. {.offset = 16, .length = 7},
  208. {.offset = 32, .length = 7},
  209. {.offset = 48, .length = 7}
  210. }
  211. };
  212. /* OOB description for 4096 byte pages with 128 byte OOB */
  213. static struct nand_ecclayout nandv2_hw_eccoob_4k = {
  214. .eccbytes = 8 * 9,
  215. .eccpos = {
  216. 7, 8, 9, 10, 11, 12, 13, 14, 15,
  217. 23, 24, 25, 26, 27, 28, 29, 30, 31,
  218. 39, 40, 41, 42, 43, 44, 45, 46, 47,
  219. 55, 56, 57, 58, 59, 60, 61, 62, 63,
  220. 71, 72, 73, 74, 75, 76, 77, 78, 79,
  221. 87, 88, 89, 90, 91, 92, 93, 94, 95,
  222. 103, 104, 105, 106, 107, 108, 109, 110, 111,
  223. 119, 120, 121, 122, 123, 124, 125, 126, 127,
  224. },
  225. .oobfree = {
  226. {.offset = 2, .length = 4},
  227. {.offset = 16, .length = 7},
  228. {.offset = 32, .length = 7},
  229. {.offset = 48, .length = 7},
  230. {.offset = 64, .length = 7},
  231. {.offset = 80, .length = 7},
  232. {.offset = 96, .length = 7},
  233. {.offset = 112, .length = 7},
  234. }
  235. };
  236. static const char * const part_probes[] = {
  237. "cmdlinepart", "RedBoot", "ofpart", NULL };
  238. static void memcpy32_fromio(void *trg, const void __iomem *src, size_t size)
  239. {
  240. int i;
  241. u32 *t = trg;
  242. const __iomem u32 *s = src;
  243. for (i = 0; i < (size >> 2); i++)
  244. *t++ = __raw_readl(s++);
  245. }
  246. static void memcpy16_fromio(void *trg, const void __iomem *src, size_t size)
  247. {
  248. int i;
  249. u16 *t = trg;
  250. const __iomem u16 *s = src;
  251. /* We assume that src (IO) is always 32bit aligned */
  252. if (PTR_ALIGN(trg, 4) == trg && IS_ALIGNED(size, 4)) {
  253. memcpy32_fromio(trg, src, size);
  254. return;
  255. }
  256. for (i = 0; i < (size >> 1); i++)
  257. *t++ = __raw_readw(s++);
  258. }
  259. static inline void memcpy32_toio(void __iomem *trg, const void *src, int size)
  260. {
  261. /* __iowrite32_copy use 32bit size values so divide by 4 */
  262. __iowrite32_copy(trg, src, size / 4);
  263. }
  264. static void memcpy16_toio(void __iomem *trg, const void *src, int size)
  265. {
  266. int i;
  267. __iomem u16 *t = trg;
  268. const u16 *s = src;
  269. /* We assume that trg (IO) is always 32bit aligned */
  270. if (PTR_ALIGN(src, 4) == src && IS_ALIGNED(size, 4)) {
  271. memcpy32_toio(trg, src, size);
  272. return;
  273. }
  274. for (i = 0; i < (size >> 1); i++)
  275. __raw_writew(*s++, t++);
  276. }
  277. static int check_int_v3(struct mxc_nand_host *host)
  278. {
  279. uint32_t tmp;
  280. tmp = readl(NFC_V3_IPC);
  281. if (!(tmp & NFC_V3_IPC_INT))
  282. return 0;
  283. tmp &= ~NFC_V3_IPC_INT;
  284. writel(tmp, NFC_V3_IPC);
  285. return 1;
  286. }
  287. static int check_int_v1_v2(struct mxc_nand_host *host)
  288. {
  289. uint32_t tmp;
  290. tmp = readw(NFC_V1_V2_CONFIG2);
  291. if (!(tmp & NFC_V1_V2_CONFIG2_INT))
  292. return 0;
  293. if (!host->devtype_data->irqpending_quirk)
  294. writew(tmp & ~NFC_V1_V2_CONFIG2_INT, NFC_V1_V2_CONFIG2);
  295. return 1;
  296. }
  297. static void irq_control_v1_v2(struct mxc_nand_host *host, int activate)
  298. {
  299. uint16_t tmp;
  300. tmp = readw(NFC_V1_V2_CONFIG1);
  301. if (activate)
  302. tmp &= ~NFC_V1_V2_CONFIG1_INT_MSK;
  303. else
  304. tmp |= NFC_V1_V2_CONFIG1_INT_MSK;
  305. writew(tmp, NFC_V1_V2_CONFIG1);
  306. }
  307. static void irq_control_v3(struct mxc_nand_host *host, int activate)
  308. {
  309. uint32_t tmp;
  310. tmp = readl(NFC_V3_CONFIG2);
  311. if (activate)
  312. tmp &= ~NFC_V3_CONFIG2_INT_MSK;
  313. else
  314. tmp |= NFC_V3_CONFIG2_INT_MSK;
  315. writel(tmp, NFC_V3_CONFIG2);
  316. }
  317. static void irq_control(struct mxc_nand_host *host, int activate)
  318. {
  319. if (host->devtype_data->irqpending_quirk) {
  320. if (activate)
  321. enable_irq(host->irq);
  322. else
  323. disable_irq_nosync(host->irq);
  324. } else {
  325. host->devtype_data->irq_control(host, activate);
  326. }
  327. }
  328. static u32 get_ecc_status_v1(struct mxc_nand_host *host)
  329. {
  330. return readw(NFC_V1_V2_ECC_STATUS_RESULT);
  331. }
  332. static u32 get_ecc_status_v2(struct mxc_nand_host *host)
  333. {
  334. return readl(NFC_V1_V2_ECC_STATUS_RESULT);
  335. }
  336. static u32 get_ecc_status_v3(struct mxc_nand_host *host)
  337. {
  338. return readl(NFC_V3_ECC_STATUS_RESULT);
  339. }
  340. static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
  341. {
  342. struct mxc_nand_host *host = dev_id;
  343. if (!host->devtype_data->check_int(host))
  344. return IRQ_NONE;
  345. irq_control(host, 0);
  346. complete(&host->op_completion);
  347. return IRQ_HANDLED;
  348. }
  349. /* This function polls the NANDFC to wait for the basic operation to
  350. * complete by checking the INT bit of config2 register.
  351. */
  352. static int wait_op_done(struct mxc_nand_host *host, int useirq)
  353. {
  354. int ret = 0;
  355. /*
  356. * If operation is already complete, don't bother to setup an irq or a
  357. * loop.
  358. */
  359. if (host->devtype_data->check_int(host))
  360. return 0;
  361. if (useirq) {
  362. unsigned long timeout;
  363. reinit_completion(&host->op_completion);
  364. irq_control(host, 1);
  365. timeout = wait_for_completion_timeout(&host->op_completion, HZ);
  366. if (!timeout && !host->devtype_data->check_int(host)) {
  367. dev_dbg(host->dev, "timeout waiting for irq\n");
  368. ret = -ETIMEDOUT;
  369. }
  370. } else {
  371. int max_retries = 8000;
  372. int done;
  373. do {
  374. udelay(1);
  375. done = host->devtype_data->check_int(host);
  376. if (done)
  377. break;
  378. } while (--max_retries);
  379. if (!done) {
  380. dev_dbg(host->dev, "timeout polling for completion\n");
  381. ret = -ETIMEDOUT;
  382. }
  383. }
  384. WARN_ONCE(ret < 0, "timeout! useirq=%d\n", useirq);
  385. return ret;
  386. }
  387. static void send_cmd_v3(struct mxc_nand_host *host, uint16_t cmd, int useirq)
  388. {
  389. /* fill command */
  390. writel(cmd, NFC_V3_FLASH_CMD);
  391. /* send out command */
  392. writel(NFC_CMD, NFC_V3_LAUNCH);
  393. /* Wait for operation to complete */
  394. wait_op_done(host, useirq);
  395. }
  396. /* This function issues the specified command to the NAND device and
  397. * waits for completion. */
  398. static void send_cmd_v1_v2(struct mxc_nand_host *host, uint16_t cmd, int useirq)
  399. {
  400. pr_debug("send_cmd(host, 0x%x, %d)\n", cmd, useirq);
  401. writew(cmd, NFC_V1_V2_FLASH_CMD);
  402. writew(NFC_CMD, NFC_V1_V2_CONFIG2);
  403. if (host->devtype_data->irqpending_quirk && (cmd == NAND_CMD_RESET)) {
  404. int max_retries = 100;
  405. /* Reset completion is indicated by NFC_CONFIG2 */
  406. /* being set to 0 */
  407. while (max_retries-- > 0) {
  408. if (readw(NFC_V1_V2_CONFIG2) == 0) {
  409. break;
  410. }
  411. udelay(1);
  412. }
  413. if (max_retries < 0)
  414. pr_debug("%s: RESET failed\n", __func__);
  415. } else {
  416. /* Wait for operation to complete */
  417. wait_op_done(host, useirq);
  418. }
  419. }
  420. static void send_addr_v3(struct mxc_nand_host *host, uint16_t addr, int islast)
  421. {
  422. /* fill address */
  423. writel(addr, NFC_V3_FLASH_ADDR0);
  424. /* send out address */
  425. writel(NFC_ADDR, NFC_V3_LAUNCH);
  426. wait_op_done(host, 0);
  427. }
  428. /* This function sends an address (or partial address) to the
  429. * NAND device. The address is used to select the source/destination for
  430. * a NAND command. */
  431. static void send_addr_v1_v2(struct mxc_nand_host *host, uint16_t addr, int islast)
  432. {
  433. pr_debug("send_addr(host, 0x%x %d)\n", addr, islast);
  434. writew(addr, NFC_V1_V2_FLASH_ADDR);
  435. writew(NFC_ADDR, NFC_V1_V2_CONFIG2);
  436. /* Wait for operation to complete */
  437. wait_op_done(host, islast);
  438. }
  439. static void send_page_v3(struct mtd_info *mtd, unsigned int ops)
  440. {
  441. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  442. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  443. uint32_t tmp;
  444. tmp = readl(NFC_V3_CONFIG1);
  445. tmp &= ~(7 << 4);
  446. writel(tmp, NFC_V3_CONFIG1);
  447. /* transfer data from NFC ram to nand */
  448. writel(ops, NFC_V3_LAUNCH);
  449. wait_op_done(host, false);
  450. }
  451. static void send_page_v2(struct mtd_info *mtd, unsigned int ops)
  452. {
  453. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  454. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  455. /* NANDFC buffer 0 is used for page read/write */
  456. writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
  457. writew(ops, NFC_V1_V2_CONFIG2);
  458. /* Wait for operation to complete */
  459. wait_op_done(host, true);
  460. }
  461. static void send_page_v1(struct mtd_info *mtd, unsigned int ops)
  462. {
  463. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  464. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  465. int bufs, i;
  466. if (mtd->writesize > 512)
  467. bufs = 4;
  468. else
  469. bufs = 1;
  470. for (i = 0; i < bufs; i++) {
  471. /* NANDFC buffer 0 is used for page read/write */
  472. writew((host->active_cs << 4) | i, NFC_V1_V2_BUF_ADDR);
  473. writew(ops, NFC_V1_V2_CONFIG2);
  474. /* Wait for operation to complete */
  475. wait_op_done(host, true);
  476. }
  477. }
  478. static void send_read_id_v3(struct mxc_nand_host *host)
  479. {
  480. /* Read ID into main buffer */
  481. writel(NFC_ID, NFC_V3_LAUNCH);
  482. wait_op_done(host, true);
  483. memcpy32_fromio(host->data_buf, host->main_area0, 16);
  484. }
  485. /* Request the NANDFC to perform a read of the NAND device ID. */
  486. static void send_read_id_v1_v2(struct mxc_nand_host *host)
  487. {
  488. /* NANDFC buffer 0 is used for device ID output */
  489. writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
  490. writew(NFC_ID, NFC_V1_V2_CONFIG2);
  491. /* Wait for operation to complete */
  492. wait_op_done(host, true);
  493. memcpy32_fromio(host->data_buf, host->main_area0, 16);
  494. }
  495. static uint16_t get_dev_status_v3(struct mxc_nand_host *host)
  496. {
  497. writew(NFC_STATUS, NFC_V3_LAUNCH);
  498. wait_op_done(host, true);
  499. return readl(NFC_V3_CONFIG1) >> 16;
  500. }
  501. /* This function requests the NANDFC to perform a read of the
  502. * NAND device status and returns the current status. */
  503. static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
  504. {
  505. void __iomem *main_buf = host->main_area0;
  506. uint32_t store;
  507. uint16_t ret;
  508. writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
  509. /*
  510. * The device status is stored in main_area0. To
  511. * prevent corruption of the buffer save the value
  512. * and restore it afterwards.
  513. */
  514. store = readl(main_buf);
  515. writew(NFC_STATUS, NFC_V1_V2_CONFIG2);
  516. wait_op_done(host, true);
  517. ret = readw(main_buf);
  518. writel(store, main_buf);
  519. return ret;
  520. }
  521. /* This functions is used by upper layer to checks if device is ready */
  522. static int mxc_nand_dev_ready(struct mtd_info *mtd)
  523. {
  524. /*
  525. * NFC handles R/B internally. Therefore, this function
  526. * always returns status as ready.
  527. */
  528. return 1;
  529. }
  530. static void mxc_nand_enable_hwecc(struct mtd_info *mtd, int mode)
  531. {
  532. /*
  533. * If HW ECC is enabled, we turn it on during init. There is
  534. * no need to enable again here.
  535. */
  536. }
  537. static int mxc_nand_correct_data_v1(struct mtd_info *mtd, u_char *dat,
  538. u_char *read_ecc, u_char *calc_ecc)
  539. {
  540. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  541. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  542. /*
  543. * 1-Bit errors are automatically corrected in HW. No need for
  544. * additional correction. 2-Bit errors cannot be corrected by
  545. * HW ECC, so we need to return failure
  546. */
  547. uint16_t ecc_status = get_ecc_status_v1(host);
  548. if (((ecc_status & 0x3) == 2) || ((ecc_status >> 2) == 2)) {
  549. pr_debug("MXC_NAND: HWECC uncorrectable 2-bit ECC error\n");
  550. return -EBADMSG;
  551. }
  552. return 0;
  553. }
  554. static int mxc_nand_correct_data_v2_v3(struct mtd_info *mtd, u_char *dat,
  555. u_char *read_ecc, u_char *calc_ecc)
  556. {
  557. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  558. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  559. u32 ecc_stat, err;
  560. int no_subpages = 1;
  561. int ret = 0;
  562. u8 ecc_bit_mask, err_limit;
  563. ecc_bit_mask = (host->eccsize == 4) ? 0x7 : 0xf;
  564. err_limit = (host->eccsize == 4) ? 0x4 : 0x8;
  565. no_subpages = mtd->writesize >> 9;
  566. ecc_stat = host->devtype_data->get_ecc_status(host);
  567. do {
  568. err = ecc_stat & ecc_bit_mask;
  569. if (err > err_limit) {
  570. printk(KERN_WARNING "UnCorrectable RS-ECC Error\n");
  571. return -EBADMSG;
  572. } else {
  573. ret += err;
  574. }
  575. ecc_stat >>= 4;
  576. } while (--no_subpages);
  577. pr_debug("%d Symbol Correctable RS-ECC Error\n", ret);
  578. return ret;
  579. }
  580. static int mxc_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
  581. u_char *ecc_code)
  582. {
  583. return 0;
  584. }
  585. static u_char mxc_nand_read_byte(struct mtd_info *mtd)
  586. {
  587. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  588. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  589. uint8_t ret;
  590. /* Check for status request */
  591. if (host->status_request)
  592. return host->devtype_data->get_dev_status(host) & 0xFF;
  593. if (nand_chip->options & NAND_BUSWIDTH_16) {
  594. /* only take the lower byte of each word */
  595. ret = *(uint16_t *)(host->data_buf + host->buf_start);
  596. host->buf_start += 2;
  597. } else {
  598. ret = *(uint8_t *)(host->data_buf + host->buf_start);
  599. host->buf_start++;
  600. }
  601. pr_debug("%s: ret=0x%hhx (start=%u)\n", __func__, ret, host->buf_start);
  602. return ret;
  603. }
  604. static uint16_t mxc_nand_read_word(struct mtd_info *mtd)
  605. {
  606. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  607. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  608. uint16_t ret;
  609. ret = *(uint16_t *)(host->data_buf + host->buf_start);
  610. host->buf_start += 2;
  611. return ret;
  612. }
  613. /* Write data of length len to buffer buf. The data to be
  614. * written on NAND Flash is first copied to RAMbuffer. After the Data Input
  615. * Operation by the NFC, the data is written to NAND Flash */
  616. static void mxc_nand_write_buf(struct mtd_info *mtd,
  617. const u_char *buf, int len)
  618. {
  619. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  620. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  621. u16 col = host->buf_start;
  622. int n = mtd->oobsize + mtd->writesize - col;
  623. n = min(n, len);
  624. memcpy(host->data_buf + col, buf, n);
  625. host->buf_start += n;
  626. }
  627. /* Read the data buffer from the NAND Flash. To read the data from NAND
  628. * Flash first the data output cycle is initiated by the NFC, which copies
  629. * the data to RAMbuffer. This data of length len is then copied to buffer buf.
  630. */
  631. static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len)
  632. {
  633. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  634. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  635. u16 col = host->buf_start;
  636. int n = mtd->oobsize + mtd->writesize - col;
  637. n = min(n, len);
  638. memcpy(buf, host->data_buf + col, n);
  639. host->buf_start += n;
  640. }
  641. /* This function is used by upper layer for select and
  642. * deselect of the NAND chip */
  643. static void mxc_nand_select_chip_v1_v3(struct mtd_info *mtd, int chip)
  644. {
  645. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  646. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  647. if (chip == -1) {
  648. /* Disable the NFC clock */
  649. if (host->clk_act) {
  650. clk_disable_unprepare(host->clk);
  651. host->clk_act = 0;
  652. }
  653. return;
  654. }
  655. if (!host->clk_act) {
  656. /* Enable the NFC clock */
  657. clk_prepare_enable(host->clk);
  658. host->clk_act = 1;
  659. }
  660. }
  661. static void mxc_nand_select_chip_v2(struct mtd_info *mtd, int chip)
  662. {
  663. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  664. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  665. if (chip == -1) {
  666. /* Disable the NFC clock */
  667. if (host->clk_act) {
  668. clk_disable_unprepare(host->clk);
  669. host->clk_act = 0;
  670. }
  671. return;
  672. }
  673. if (!host->clk_act) {
  674. /* Enable the NFC clock */
  675. clk_prepare_enable(host->clk);
  676. host->clk_act = 1;
  677. }
  678. host->active_cs = chip;
  679. writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
  680. }
  681. /*
  682. * The controller splits a page into data chunks of 512 bytes + partial oob.
  683. * There are writesize / 512 such chunks, the size of the partial oob parts is
  684. * oobsize / #chunks rounded down to a multiple of 2. The last oob chunk then
  685. * contains additionally the byte lost by rounding (if any).
  686. * This function handles the needed shuffling between host->data_buf (which
  687. * holds a page in natural order, i.e. writesize bytes data + oobsize bytes
  688. * spare) and the NFC buffer.
  689. */
  690. static void copy_spare(struct mtd_info *mtd, bool bfrom)
  691. {
  692. struct nand_chip *this = mtd_to_nand(mtd);
  693. struct mxc_nand_host *host = nand_get_controller_data(this);
  694. u16 i, oob_chunk_size;
  695. u16 num_chunks = mtd->writesize / 512;
  696. u8 *d = host->data_buf + mtd->writesize;
  697. u8 __iomem *s = host->spare0;
  698. u16 sparebuf_size = host->devtype_data->spare_len;
  699. /* size of oob chunk for all but possibly the last one */
  700. oob_chunk_size = (host->used_oobsize / num_chunks) & ~1;
  701. if (bfrom) {
  702. for (i = 0; i < num_chunks - 1; i++)
  703. memcpy16_fromio(d + i * oob_chunk_size,
  704. s + i * sparebuf_size,
  705. oob_chunk_size);
  706. /* the last chunk */
  707. memcpy16_fromio(d + i * oob_chunk_size,
  708. s + i * sparebuf_size,
  709. host->used_oobsize - i * oob_chunk_size);
  710. } else {
  711. for (i = 0; i < num_chunks - 1; i++)
  712. memcpy16_toio(&s[i * sparebuf_size],
  713. &d[i * oob_chunk_size],
  714. oob_chunk_size);
  715. /* the last chunk */
  716. memcpy16_toio(&s[i * sparebuf_size],
  717. &d[i * oob_chunk_size],
  718. host->used_oobsize - i * oob_chunk_size);
  719. }
  720. }
  721. /*
  722. * MXC NANDFC can only perform full page+spare or spare-only read/write. When
  723. * the upper layers perform a read/write buf operation, the saved column address
  724. * is used to index into the full page. So usually this function is called with
  725. * column == 0 (unless no column cycle is needed indicated by column == -1)
  726. */
  727. static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
  728. {
  729. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  730. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  731. /* Write out column address, if necessary */
  732. if (column != -1) {
  733. host->devtype_data->send_addr(host, column & 0xff,
  734. page_addr == -1);
  735. if (mtd->writesize > 512)
  736. /* another col addr cycle for 2k page */
  737. host->devtype_data->send_addr(host,
  738. (column >> 8) & 0xff,
  739. false);
  740. }
  741. /* Write out page address, if necessary */
  742. if (page_addr != -1) {
  743. /* paddr_0 - p_addr_7 */
  744. host->devtype_data->send_addr(host, (page_addr & 0xff), false);
  745. if (mtd->writesize > 512) {
  746. if (mtd->size >= 0x10000000) {
  747. /* paddr_8 - paddr_15 */
  748. host->devtype_data->send_addr(host,
  749. (page_addr >> 8) & 0xff,
  750. false);
  751. host->devtype_data->send_addr(host,
  752. (page_addr >> 16) & 0xff,
  753. true);
  754. } else
  755. /* paddr_8 - paddr_15 */
  756. host->devtype_data->send_addr(host,
  757. (page_addr >> 8) & 0xff, true);
  758. } else {
  759. /* One more address cycle for higher density devices */
  760. if (mtd->size >= 0x4000000) {
  761. /* paddr_8 - paddr_15 */
  762. host->devtype_data->send_addr(host,
  763. (page_addr >> 8) & 0xff,
  764. false);
  765. host->devtype_data->send_addr(host,
  766. (page_addr >> 16) & 0xff,
  767. true);
  768. } else
  769. /* paddr_8 - paddr_15 */
  770. host->devtype_data->send_addr(host,
  771. (page_addr >> 8) & 0xff, true);
  772. }
  773. }
  774. }
  775. /*
  776. * v2 and v3 type controllers can do 4bit or 8bit ecc depending
  777. * on how much oob the nand chip has. For 8bit ecc we need at least
  778. * 26 bytes of oob data per 512 byte block.
  779. */
  780. static int get_eccsize(struct mtd_info *mtd)
  781. {
  782. int oobbytes_per_512 = 0;
  783. oobbytes_per_512 = mtd->oobsize * 512 / mtd->writesize;
  784. if (oobbytes_per_512 < 26)
  785. return 4;
  786. else
  787. return 8;
  788. }
  789. static void ecc_8bit_layout_4k(struct nand_ecclayout *layout)
  790. {
  791. int i, j;
  792. layout->eccbytes = 8*18;
  793. for (i = 0; i < 8; i++)
  794. for (j = 0; j < 18; j++)
  795. layout->eccpos[i*18 + j] = i*26 + j + 7;
  796. layout->oobfree[0].offset = 2;
  797. layout->oobfree[0].length = 4;
  798. for (i = 1; i < 8; i++) {
  799. layout->oobfree[i].offset = i*26;
  800. layout->oobfree[i].length = 7;
  801. }
  802. }
  803. static void preset_v1(struct mtd_info *mtd)
  804. {
  805. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  806. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  807. uint16_t config1 = 0;
  808. if (nand_chip->ecc.mode == NAND_ECC_HW && mtd->writesize)
  809. config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
  810. if (!host->devtype_data->irqpending_quirk)
  811. config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
  812. host->eccsize = 1;
  813. writew(config1, NFC_V1_V2_CONFIG1);
  814. /* preset operation */
  815. /* Unlock the internal RAM Buffer */
  816. writew(0x2, NFC_V1_V2_CONFIG);
  817. /* Blocks to be unlocked */
  818. writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
  819. writew(0xffff, NFC_V1_UNLOCKEND_BLKADDR);
  820. /* Unlock Block Command for given address range */
  821. writew(0x4, NFC_V1_V2_WRPROT);
  822. }
  823. static void preset_v2(struct mtd_info *mtd)
  824. {
  825. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  826. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  827. uint16_t config1 = 0;
  828. config1 |= NFC_V2_CONFIG1_FP_INT;
  829. if (!host->devtype_data->irqpending_quirk)
  830. config1 |= NFC_V1_V2_CONFIG1_INT_MSK;
  831. if (mtd->writesize) {
  832. uint16_t pages_per_block = mtd->erasesize / mtd->writesize;
  833. if (nand_chip->ecc.mode == NAND_ECC_HW)
  834. config1 |= NFC_V1_V2_CONFIG1_ECC_EN;
  835. host->eccsize = get_eccsize(mtd);
  836. if (host->eccsize == 4)
  837. config1 |= NFC_V2_CONFIG1_ECC_MODE_4;
  838. config1 |= NFC_V2_CONFIG1_PPB(ffs(pages_per_block) - 6);
  839. } else {
  840. host->eccsize = 1;
  841. }
  842. writew(config1, NFC_V1_V2_CONFIG1);
  843. /* preset operation */
  844. /* Unlock the internal RAM Buffer */
  845. writew(0x2, NFC_V1_V2_CONFIG);
  846. /* Blocks to be unlocked */
  847. writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR0);
  848. writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR1);
  849. writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR2);
  850. writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR3);
  851. writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR0);
  852. writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR1);
  853. writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR2);
  854. writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
  855. /* Unlock Block Command for given address range */
  856. writew(0x4, NFC_V1_V2_WRPROT);
  857. }
  858. static void preset_v3(struct mtd_info *mtd)
  859. {
  860. struct nand_chip *chip = mtd_to_nand(mtd);
  861. struct mxc_nand_host *host = nand_get_controller_data(chip);
  862. uint32_t config2, config3;
  863. int i, addr_phases;
  864. writel(NFC_V3_CONFIG1_RBA(0), NFC_V3_CONFIG1);
  865. writel(NFC_V3_IPC_CREQ, NFC_V3_IPC);
  866. /* Unlock the internal RAM Buffer */
  867. writel(NFC_V3_WRPROT_BLS_UNLOCK | NFC_V3_WRPROT_UNLOCK,
  868. NFC_V3_WRPROT);
  869. /* Blocks to be unlocked */
  870. for (i = 0; i < NAND_MAX_CHIPS; i++)
  871. writel(0xffff << 16, NFC_V3_WRPROT_UNLOCK_BLK_ADD0 + (i << 2));
  872. writel(0, NFC_V3_IPC);
  873. config2 = NFC_V3_CONFIG2_ONE_CYCLE |
  874. NFC_V3_CONFIG2_2CMD_PHASES |
  875. NFC_V3_CONFIG2_SPAS(mtd->oobsize >> 1) |
  876. NFC_V3_CONFIG2_ST_CMD(0x70) |
  877. NFC_V3_CONFIG2_INT_MSK |
  878. NFC_V3_CONFIG2_NUM_ADDR_PHASE0;
  879. addr_phases = fls(chip->pagemask) >> 3;
  880. if (mtd->writesize == 2048) {
  881. config2 |= NFC_V3_CONFIG2_PS_2048;
  882. config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
  883. } else if (mtd->writesize == 4096) {
  884. config2 |= NFC_V3_CONFIG2_PS_4096;
  885. config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases);
  886. } else {
  887. config2 |= NFC_V3_CONFIG2_PS_512;
  888. config2 |= NFC_V3_CONFIG2_NUM_ADDR_PHASE1(addr_phases - 1);
  889. }
  890. if (mtd->writesize) {
  891. if (chip->ecc.mode == NAND_ECC_HW)
  892. config2 |= NFC_V3_CONFIG2_ECC_EN;
  893. config2 |= NFC_V3_CONFIG2_PPB(
  894. ffs(mtd->erasesize / mtd->writesize) - 6,
  895. host->devtype_data->ppb_shift);
  896. host->eccsize = get_eccsize(mtd);
  897. if (host->eccsize == 8)
  898. config2 |= NFC_V3_CONFIG2_ECC_MODE_8;
  899. }
  900. writel(config2, NFC_V3_CONFIG2);
  901. config3 = NFC_V3_CONFIG3_NUM_OF_DEVICES(0) |
  902. NFC_V3_CONFIG3_NO_SDMA |
  903. NFC_V3_CONFIG3_RBB_MODE |
  904. NFC_V3_CONFIG3_SBB(6) | /* Reset default */
  905. NFC_V3_CONFIG3_ADD_OP(0);
  906. if (!(chip->options & NAND_BUSWIDTH_16))
  907. config3 |= NFC_V3_CONFIG3_FW8;
  908. writel(config3, NFC_V3_CONFIG3);
  909. writel(0, NFC_V3_DELAY_LINE);
  910. }
  911. /* Used by the upper layer to write command to NAND Flash for
  912. * different operations to be carried out on NAND Flash */
  913. static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
  914. int column, int page_addr)
  915. {
  916. struct nand_chip *nand_chip = mtd_to_nand(mtd);
  917. struct mxc_nand_host *host = nand_get_controller_data(nand_chip);
  918. pr_debug("mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n",
  919. command, column, page_addr);
  920. /* Reset command state information */
  921. host->status_request = false;
  922. /* Command pre-processing step */
  923. switch (command) {
  924. case NAND_CMD_RESET:
  925. host->devtype_data->preset(mtd);
  926. host->devtype_data->send_cmd(host, command, false);
  927. break;
  928. case NAND_CMD_STATUS:
  929. host->buf_start = 0;
  930. host->status_request = true;
  931. host->devtype_data->send_cmd(host, command, true);
  932. WARN_ONCE(column != -1 || page_addr != -1,
  933. "Unexpected column/row value (cmd=%u, col=%d, row=%d)\n",
  934. command, column, page_addr);
  935. mxc_do_addr_cycle(mtd, column, page_addr);
  936. break;
  937. case NAND_CMD_READ0:
  938. case NAND_CMD_READOOB:
  939. if (command == NAND_CMD_READ0)
  940. host->buf_start = column;
  941. else
  942. host->buf_start = column + mtd->writesize;
  943. command = NAND_CMD_READ0; /* only READ0 is valid */
  944. host->devtype_data->send_cmd(host, command, false);
  945. WARN_ONCE(column < 0,
  946. "Unexpected column/row value (cmd=%u, col=%d, row=%d)\n",
  947. command, column, page_addr);
  948. mxc_do_addr_cycle(mtd, 0, page_addr);
  949. if (mtd->writesize > 512)
  950. host->devtype_data->send_cmd(host,
  951. NAND_CMD_READSTART, true);
  952. host->devtype_data->send_page(mtd, NFC_OUTPUT);
  953. memcpy32_fromio(host->data_buf, host->main_area0,
  954. mtd->writesize);
  955. copy_spare(mtd, true);
  956. break;
  957. case NAND_CMD_SEQIN:
  958. if (column >= mtd->writesize)
  959. /* call ourself to read a page */
  960. mxc_nand_command(mtd, NAND_CMD_READ0, 0, page_addr);
  961. host->buf_start = column;
  962. host->devtype_data->send_cmd(host, command, false);
  963. WARN_ONCE(column < -1,
  964. "Unexpected column/row value (cmd=%u, col=%d, row=%d)\n",
  965. command, column, page_addr);
  966. mxc_do_addr_cycle(mtd, 0, page_addr);
  967. break;
  968. case NAND_CMD_PAGEPROG:
  969. memcpy32_toio(host->main_area0, host->data_buf, mtd->writesize);
  970. copy_spare(mtd, false);
  971. host->devtype_data->send_page(mtd, NFC_INPUT);
  972. host->devtype_data->send_cmd(host, command, true);
  973. WARN_ONCE(column != -1 || page_addr != -1,
  974. "Unexpected column/row value (cmd=%u, col=%d, row=%d)\n",
  975. command, column, page_addr);
  976. mxc_do_addr_cycle(mtd, column, page_addr);
  977. break;
  978. case NAND_CMD_READID:
  979. host->devtype_data->send_cmd(host, command, true);
  980. mxc_do_addr_cycle(mtd, column, page_addr);
  981. host->devtype_data->send_read_id(host);
  982. host->buf_start = 0;
  983. break;
  984. case NAND_CMD_ERASE1:
  985. case NAND_CMD_ERASE2:
  986. host->devtype_data->send_cmd(host, command, false);
  987. WARN_ONCE(column != -1,
  988. "Unexpected column value (cmd=%u, col=%d)\n",
  989. command, column);
  990. mxc_do_addr_cycle(mtd, column, page_addr);
  991. break;
  992. case NAND_CMD_PARAM:
  993. host->devtype_data->send_cmd(host, command, false);
  994. mxc_do_addr_cycle(mtd, column, page_addr);
  995. host->devtype_data->send_page(mtd, NFC_OUTPUT);
  996. memcpy32_fromio(host->data_buf, host->main_area0, 512);
  997. host->buf_start = 0;
  998. break;
  999. default:
  1000. WARN_ONCE(1, "Unimplemented command (cmd=%u)\n",
  1001. command);
  1002. break;
  1003. }
  1004. }
  1005. /*
  1006. * The generic flash bbt decriptors overlap with our ecc
  1007. * hardware, so define some i.MX specific ones.
  1008. */
  1009. static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' };
  1010. static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' };
  1011. static struct nand_bbt_descr bbt_main_descr = {
  1012. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1013. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1014. .offs = 0,
  1015. .len = 4,
  1016. .veroffs = 4,
  1017. .maxblocks = 4,
  1018. .pattern = bbt_pattern,
  1019. };
  1020. static struct nand_bbt_descr bbt_mirror_descr = {
  1021. .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
  1022. | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP,
  1023. .offs = 0,
  1024. .len = 4,
  1025. .veroffs = 4,
  1026. .maxblocks = 4,
  1027. .pattern = mirror_pattern,
  1028. };
  1029. /* v1 + irqpending_quirk: i.MX21 */
  1030. static const struct mxc_nand_devtype_data imx21_nand_devtype_data = {
  1031. .preset = preset_v1,
  1032. .send_cmd = send_cmd_v1_v2,
  1033. .send_addr = send_addr_v1_v2,
  1034. .send_page = send_page_v1,
  1035. .send_read_id = send_read_id_v1_v2,
  1036. .get_dev_status = get_dev_status_v1_v2,
  1037. .check_int = check_int_v1_v2,
  1038. .irq_control = irq_control_v1_v2,
  1039. .get_ecc_status = get_ecc_status_v1,
  1040. .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
  1041. .ecclayout_2k = &nandv1_hw_eccoob_largepage,
  1042. .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
  1043. .select_chip = mxc_nand_select_chip_v1_v3,
  1044. .correct_data = mxc_nand_correct_data_v1,
  1045. .irqpending_quirk = 1,
  1046. .needs_ip = 0,
  1047. .regs_offset = 0xe00,
  1048. .spare0_offset = 0x800,
  1049. .spare_len = 16,
  1050. .eccbytes = 3,
  1051. .eccsize = 1,
  1052. };
  1053. /* v1 + !irqpending_quirk: i.MX27, i.MX31 */
  1054. static const struct mxc_nand_devtype_data imx27_nand_devtype_data = {
  1055. .preset = preset_v1,
  1056. .send_cmd = send_cmd_v1_v2,
  1057. .send_addr = send_addr_v1_v2,
  1058. .send_page = send_page_v1,
  1059. .send_read_id = send_read_id_v1_v2,
  1060. .get_dev_status = get_dev_status_v1_v2,
  1061. .check_int = check_int_v1_v2,
  1062. .irq_control = irq_control_v1_v2,
  1063. .get_ecc_status = get_ecc_status_v1,
  1064. .ecclayout_512 = &nandv1_hw_eccoob_smallpage,
  1065. .ecclayout_2k = &nandv1_hw_eccoob_largepage,
  1066. .ecclayout_4k = &nandv1_hw_eccoob_smallpage, /* XXX: needs fix */
  1067. .select_chip = mxc_nand_select_chip_v1_v3,
  1068. .correct_data = mxc_nand_correct_data_v1,
  1069. .irqpending_quirk = 0,
  1070. .needs_ip = 0,
  1071. .regs_offset = 0xe00,
  1072. .spare0_offset = 0x800,
  1073. .axi_offset = 0,
  1074. .spare_len = 16,
  1075. .eccbytes = 3,
  1076. .eccsize = 1,
  1077. };
  1078. /* v21: i.MX25, i.MX35 */
  1079. static const struct mxc_nand_devtype_data imx25_nand_devtype_data = {
  1080. .preset = preset_v2,
  1081. .send_cmd = send_cmd_v1_v2,
  1082. .send_addr = send_addr_v1_v2,
  1083. .send_page = send_page_v2,
  1084. .send_read_id = send_read_id_v1_v2,
  1085. .get_dev_status = get_dev_status_v1_v2,
  1086. .check_int = check_int_v1_v2,
  1087. .irq_control = irq_control_v1_v2,
  1088. .get_ecc_status = get_ecc_status_v2,
  1089. .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
  1090. .ecclayout_2k = &nandv2_hw_eccoob_largepage,
  1091. .ecclayout_4k = &nandv2_hw_eccoob_4k,
  1092. .select_chip = mxc_nand_select_chip_v2,
  1093. .correct_data = mxc_nand_correct_data_v2_v3,
  1094. .irqpending_quirk = 0,
  1095. .needs_ip = 0,
  1096. .regs_offset = 0x1e00,
  1097. .spare0_offset = 0x1000,
  1098. .axi_offset = 0,
  1099. .spare_len = 64,
  1100. .eccbytes = 9,
  1101. .eccsize = 0,
  1102. };
  1103. /* v3.2a: i.MX51 */
  1104. static const struct mxc_nand_devtype_data imx51_nand_devtype_data = {
  1105. .preset = preset_v3,
  1106. .send_cmd = send_cmd_v3,
  1107. .send_addr = send_addr_v3,
  1108. .send_page = send_page_v3,
  1109. .send_read_id = send_read_id_v3,
  1110. .get_dev_status = get_dev_status_v3,
  1111. .check_int = check_int_v3,
  1112. .irq_control = irq_control_v3,
  1113. .get_ecc_status = get_ecc_status_v3,
  1114. .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
  1115. .ecclayout_2k = &nandv2_hw_eccoob_largepage,
  1116. .ecclayout_4k = &nandv2_hw_eccoob_smallpage, /* XXX: needs fix */
  1117. .select_chip = mxc_nand_select_chip_v1_v3,
  1118. .correct_data = mxc_nand_correct_data_v2_v3,
  1119. .irqpending_quirk = 0,
  1120. .needs_ip = 1,
  1121. .regs_offset = 0,
  1122. .spare0_offset = 0x1000,
  1123. .axi_offset = 0x1e00,
  1124. .spare_len = 64,
  1125. .eccbytes = 0,
  1126. .eccsize = 0,
  1127. .ppb_shift = 7,
  1128. };
  1129. /* v3.2b: i.MX53 */
  1130. static const struct mxc_nand_devtype_data imx53_nand_devtype_data = {
  1131. .preset = preset_v3,
  1132. .send_cmd = send_cmd_v3,
  1133. .send_addr = send_addr_v3,
  1134. .send_page = send_page_v3,
  1135. .send_read_id = send_read_id_v3,
  1136. .get_dev_status = get_dev_status_v3,
  1137. .check_int = check_int_v3,
  1138. .irq_control = irq_control_v3,
  1139. .get_ecc_status = get_ecc_status_v3,
  1140. .ecclayout_512 = &nandv2_hw_eccoob_smallpage,
  1141. .ecclayout_2k = &nandv2_hw_eccoob_largepage,
  1142. .ecclayout_4k = &nandv2_hw_eccoob_smallpage, /* XXX: needs fix */
  1143. .select_chip = mxc_nand_select_chip_v1_v3,
  1144. .correct_data = mxc_nand_correct_data_v2_v3,
  1145. .irqpending_quirk = 0,
  1146. .needs_ip = 1,
  1147. .regs_offset = 0,
  1148. .spare0_offset = 0x1000,
  1149. .axi_offset = 0x1e00,
  1150. .spare_len = 64,
  1151. .eccbytes = 0,
  1152. .eccsize = 0,
  1153. .ppb_shift = 8,
  1154. };
  1155. static inline int is_imx21_nfc(struct mxc_nand_host *host)
  1156. {
  1157. return host->devtype_data == &imx21_nand_devtype_data;
  1158. }
  1159. static inline int is_imx27_nfc(struct mxc_nand_host *host)
  1160. {
  1161. return host->devtype_data == &imx27_nand_devtype_data;
  1162. }
  1163. static inline int is_imx25_nfc(struct mxc_nand_host *host)
  1164. {
  1165. return host->devtype_data == &imx25_nand_devtype_data;
  1166. }
  1167. static inline int is_imx51_nfc(struct mxc_nand_host *host)
  1168. {
  1169. return host->devtype_data == &imx51_nand_devtype_data;
  1170. }
  1171. static inline int is_imx53_nfc(struct mxc_nand_host *host)
  1172. {
  1173. return host->devtype_data == &imx53_nand_devtype_data;
  1174. }
  1175. static const struct platform_device_id mxcnd_devtype[] = {
  1176. {
  1177. .name = "imx21-nand",
  1178. .driver_data = (kernel_ulong_t) &imx21_nand_devtype_data,
  1179. }, {
  1180. .name = "imx27-nand",
  1181. .driver_data = (kernel_ulong_t) &imx27_nand_devtype_data,
  1182. }, {
  1183. .name = "imx25-nand",
  1184. .driver_data = (kernel_ulong_t) &imx25_nand_devtype_data,
  1185. }, {
  1186. .name = "imx51-nand",
  1187. .driver_data = (kernel_ulong_t) &imx51_nand_devtype_data,
  1188. }, {
  1189. .name = "imx53-nand",
  1190. .driver_data = (kernel_ulong_t) &imx53_nand_devtype_data,
  1191. }, {
  1192. /* sentinel */
  1193. }
  1194. };
  1195. MODULE_DEVICE_TABLE(platform, mxcnd_devtype);
  1196. #ifdef CONFIG_OF_MTD
  1197. static const struct of_device_id mxcnd_dt_ids[] = {
  1198. {
  1199. .compatible = "fsl,imx21-nand",
  1200. .data = &imx21_nand_devtype_data,
  1201. }, {
  1202. .compatible = "fsl,imx27-nand",
  1203. .data = &imx27_nand_devtype_data,
  1204. }, {
  1205. .compatible = "fsl,imx25-nand",
  1206. .data = &imx25_nand_devtype_data,
  1207. }, {
  1208. .compatible = "fsl,imx51-nand",
  1209. .data = &imx51_nand_devtype_data,
  1210. }, {
  1211. .compatible = "fsl,imx53-nand",
  1212. .data = &imx53_nand_devtype_data,
  1213. },
  1214. { /* sentinel */ }
  1215. };
  1216. MODULE_DEVICE_TABLE(of, mxcnd_dt_ids);
  1217. static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
  1218. {
  1219. struct device_node *np = host->dev->of_node;
  1220. struct mxc_nand_platform_data *pdata = &host->pdata;
  1221. const struct of_device_id *of_id =
  1222. of_match_device(mxcnd_dt_ids, host->dev);
  1223. int buswidth;
  1224. if (!np)
  1225. return 1;
  1226. if (of_get_nand_ecc_mode(np) >= 0)
  1227. pdata->hw_ecc = 1;
  1228. pdata->flash_bbt = of_get_nand_on_flash_bbt(np);
  1229. buswidth = of_get_nand_bus_width(np);
  1230. if (buswidth < 0)
  1231. return buswidth;
  1232. pdata->width = buswidth / 8;
  1233. host->devtype_data = of_id->data;
  1234. return 0;
  1235. }
  1236. #else
  1237. static int __init mxcnd_probe_dt(struct mxc_nand_host *host)
  1238. {
  1239. return 1;
  1240. }
  1241. #endif
  1242. static int mxcnd_probe(struct platform_device *pdev)
  1243. {
  1244. struct nand_chip *this;
  1245. struct mtd_info *mtd;
  1246. struct mxc_nand_host *host;
  1247. struct resource *res;
  1248. int err = 0;
  1249. /* Allocate memory for MTD device structure and private data */
  1250. host = devm_kzalloc(&pdev->dev, sizeof(struct mxc_nand_host),
  1251. GFP_KERNEL);
  1252. if (!host)
  1253. return -ENOMEM;
  1254. /* allocate a temporary buffer for the nand_scan_ident() */
  1255. host->data_buf = devm_kzalloc(&pdev->dev, PAGE_SIZE, GFP_KERNEL);
  1256. if (!host->data_buf)
  1257. return -ENOMEM;
  1258. host->dev = &pdev->dev;
  1259. /* structures must be linked */
  1260. this = &host->nand;
  1261. mtd = nand_to_mtd(this);
  1262. mtd->dev.parent = &pdev->dev;
  1263. mtd->name = DRIVER_NAME;
  1264. /* 50 us command delay time */
  1265. this->chip_delay = 5;
  1266. nand_set_controller_data(this, host);
  1267. nand_set_flash_node(this, pdev->dev.of_node),
  1268. this->dev_ready = mxc_nand_dev_ready;
  1269. this->cmdfunc = mxc_nand_command;
  1270. this->read_byte = mxc_nand_read_byte;
  1271. this->read_word = mxc_nand_read_word;
  1272. this->write_buf = mxc_nand_write_buf;
  1273. this->read_buf = mxc_nand_read_buf;
  1274. host->clk = devm_clk_get(&pdev->dev, NULL);
  1275. if (IS_ERR(host->clk))
  1276. return PTR_ERR(host->clk);
  1277. err = mxcnd_probe_dt(host);
  1278. if (err > 0) {
  1279. struct mxc_nand_platform_data *pdata =
  1280. dev_get_platdata(&pdev->dev);
  1281. if (pdata) {
  1282. host->pdata = *pdata;
  1283. host->devtype_data = (struct mxc_nand_devtype_data *)
  1284. pdev->id_entry->driver_data;
  1285. } else {
  1286. err = -ENODEV;
  1287. }
  1288. }
  1289. if (err < 0)
  1290. return err;
  1291. if (host->devtype_data->needs_ip) {
  1292. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1293. host->regs_ip = devm_ioremap_resource(&pdev->dev, res);
  1294. if (IS_ERR(host->regs_ip))
  1295. return PTR_ERR(host->regs_ip);
  1296. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  1297. } else {
  1298. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  1299. }
  1300. host->base = devm_ioremap_resource(&pdev->dev, res);
  1301. if (IS_ERR(host->base))
  1302. return PTR_ERR(host->base);
  1303. host->main_area0 = host->base;
  1304. if (host->devtype_data->regs_offset)
  1305. host->regs = host->base + host->devtype_data->regs_offset;
  1306. host->spare0 = host->base + host->devtype_data->spare0_offset;
  1307. if (host->devtype_data->axi_offset)
  1308. host->regs_axi = host->base + host->devtype_data->axi_offset;
  1309. this->ecc.bytes = host->devtype_data->eccbytes;
  1310. host->eccsize = host->devtype_data->eccsize;
  1311. this->select_chip = host->devtype_data->select_chip;
  1312. this->ecc.size = 512;
  1313. this->ecc.layout = host->devtype_data->ecclayout_512;
  1314. if (host->pdata.hw_ecc) {
  1315. this->ecc.calculate = mxc_nand_calculate_ecc;
  1316. this->ecc.hwctl = mxc_nand_enable_hwecc;
  1317. this->ecc.correct = host->devtype_data->correct_data;
  1318. this->ecc.mode = NAND_ECC_HW;
  1319. } else {
  1320. this->ecc.mode = NAND_ECC_SOFT;
  1321. }
  1322. /* NAND bus width determines access functions used by upper layer */
  1323. if (host->pdata.width == 2)
  1324. this->options |= NAND_BUSWIDTH_16;
  1325. if (host->pdata.flash_bbt) {
  1326. this->bbt_td = &bbt_main_descr;
  1327. this->bbt_md = &bbt_mirror_descr;
  1328. /* update flash based bbt */
  1329. this->bbt_options |= NAND_BBT_USE_FLASH;
  1330. }
  1331. init_completion(&host->op_completion);
  1332. host->irq = platform_get_irq(pdev, 0);
  1333. if (host->irq < 0)
  1334. return host->irq;
  1335. /*
  1336. * Use host->devtype_data->irq_control() here instead of irq_control()
  1337. * because we must not disable_irq_nosync without having requested the
  1338. * irq.
  1339. */
  1340. host->devtype_data->irq_control(host, 0);
  1341. err = devm_request_irq(&pdev->dev, host->irq, mxc_nfc_irq,
  1342. 0, DRIVER_NAME, host);
  1343. if (err)
  1344. return err;
  1345. err = clk_prepare_enable(host->clk);
  1346. if (err)
  1347. return err;
  1348. host->clk_act = 1;
  1349. /*
  1350. * Now that we "own" the interrupt make sure the interrupt mask bit is
  1351. * cleared on i.MX21. Otherwise we can't read the interrupt status bit
  1352. * on this machine.
  1353. */
  1354. if (host->devtype_data->irqpending_quirk) {
  1355. disable_irq_nosync(host->irq);
  1356. host->devtype_data->irq_control(host, 1);
  1357. }
  1358. /* first scan to find the device and get the page size */
  1359. if (nand_scan_ident(mtd, is_imx25_nfc(host) ? 4 : 1, NULL)) {
  1360. err = -ENXIO;
  1361. goto escan;
  1362. }
  1363. /* allocate the right size buffer now */
  1364. devm_kfree(&pdev->dev, (void *)host->data_buf);
  1365. host->data_buf = devm_kzalloc(&pdev->dev, mtd->writesize + mtd->oobsize,
  1366. GFP_KERNEL);
  1367. if (!host->data_buf) {
  1368. err = -ENOMEM;
  1369. goto escan;
  1370. }
  1371. /* Call preset again, with correct writesize this time */
  1372. host->devtype_data->preset(mtd);
  1373. if (mtd->writesize == 2048)
  1374. this->ecc.layout = host->devtype_data->ecclayout_2k;
  1375. else if (mtd->writesize == 4096) {
  1376. this->ecc.layout = host->devtype_data->ecclayout_4k;
  1377. if (get_eccsize(mtd) == 8)
  1378. ecc_8bit_layout_4k(this->ecc.layout);
  1379. }
  1380. /*
  1381. * Experimentation shows that i.MX NFC can only handle up to 218 oob
  1382. * bytes. Limit used_oobsize to 218 so as to not confuse copy_spare()
  1383. * into copying invalid data to/from the spare IO buffer, as this
  1384. * might cause ECC data corruption when doing sub-page write to a
  1385. * partially written page.
  1386. */
  1387. host->used_oobsize = min(mtd->oobsize, 218U);
  1388. if (this->ecc.mode == NAND_ECC_HW) {
  1389. if (is_imx21_nfc(host) || is_imx27_nfc(host))
  1390. this->ecc.strength = 1;
  1391. else
  1392. this->ecc.strength = (host->eccsize == 4) ? 4 : 8;
  1393. }
  1394. /* second phase scan */
  1395. if (nand_scan_tail(mtd)) {
  1396. err = -ENXIO;
  1397. goto escan;
  1398. }
  1399. /* Register the partitions */
  1400. mtd_device_parse_register(mtd, part_probes,
  1401. NULL,
  1402. host->pdata.parts,
  1403. host->pdata.nr_parts);
  1404. platform_set_drvdata(pdev, host);
  1405. return 0;
  1406. escan:
  1407. if (host->clk_act)
  1408. clk_disable_unprepare(host->clk);
  1409. return err;
  1410. }
  1411. static int mxcnd_remove(struct platform_device *pdev)
  1412. {
  1413. struct mxc_nand_host *host = platform_get_drvdata(pdev);
  1414. nand_release(nand_to_mtd(&host->nand));
  1415. if (host->clk_act)
  1416. clk_disable_unprepare(host->clk);
  1417. return 0;
  1418. }
  1419. static struct platform_driver mxcnd_driver = {
  1420. .driver = {
  1421. .name = DRIVER_NAME,
  1422. .of_match_table = of_match_ptr(mxcnd_dt_ids),
  1423. },
  1424. .id_table = mxcnd_devtype,
  1425. .probe = mxcnd_probe,
  1426. .remove = mxcnd_remove,
  1427. };
  1428. module_platform_driver(mxcnd_driver);
  1429. MODULE_AUTHOR("Freescale Semiconductor, Inc.");
  1430. MODULE_DESCRIPTION("MXC NAND MTD driver");
  1431. MODULE_LICENSE("GPL");