atmel_nand.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. /*
  2. * Copyright (C) 2003 Rick Bronson
  3. *
  4. * Derived from drivers/mtd/nand/autcpu12.c
  5. * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de)
  6. *
  7. * Derived from drivers/mtd/spia.c
  8. * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
  9. *
  10. *
  11. * Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
  12. * Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright (C) 2007
  13. *
  14. * Derived from Das U-Boot source code
  15. * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
  16. * (C) Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
  17. *
  18. *
  19. * This program is free software; you can redistribute it and/or modify
  20. * it under the terms of the GNU General Public License version 2 as
  21. * published by the Free Software Foundation.
  22. *
  23. */
  24. #include <linux/dma-mapping.h>
  25. #include <linux/slab.h>
  26. #include <linux/module.h>
  27. #include <linux/moduleparam.h>
  28. #include <linux/platform_device.h>
  29. #include <linux/mtd/mtd.h>
  30. #include <linux/mtd/nand.h>
  31. #include <linux/mtd/partitions.h>
  32. #include <linux/dmaengine.h>
  33. #include <linux/gpio.h>
  34. #include <linux/io.h>
  35. #include <linux/platform_data/atmel.h>
  36. #include <mach/cpu.h>
  37. static int use_dma = 1;
  38. module_param(use_dma, int, 0);
  39. static int on_flash_bbt = 0;
  40. module_param(on_flash_bbt, int, 0);
  41. /* Register access macros */
  42. #define ecc_readl(add, reg) \
  43. __raw_readl(add + ATMEL_ECC_##reg)
  44. #define ecc_writel(add, reg, value) \
  45. __raw_writel((value), add + ATMEL_ECC_##reg)
  46. #include "atmel_nand_ecc.h" /* Hardware ECC registers */
  47. /* oob layout for large page size
  48. * bad block info is on bytes 0 and 1
  49. * the bytes have to be consecutives to avoid
  50. * several NAND_CMD_RNDOUT during read
  51. */
  52. static struct nand_ecclayout atmel_oobinfo_large = {
  53. .eccbytes = 4,
  54. .eccpos = {60, 61, 62, 63},
  55. .oobfree = {
  56. {2, 58}
  57. },
  58. };
  59. /* oob layout for small page size
  60. * bad block info is on bytes 4 and 5
  61. * the bytes have to be consecutives to avoid
  62. * several NAND_CMD_RNDOUT during read
  63. */
  64. static struct nand_ecclayout atmel_oobinfo_small = {
  65. .eccbytes = 4,
  66. .eccpos = {0, 1, 2, 3},
  67. .oobfree = {
  68. {6, 10}
  69. },
  70. };
  71. struct atmel_nand_host {
  72. struct nand_chip nand_chip;
  73. struct mtd_info mtd;
  74. void __iomem *io_base;
  75. dma_addr_t io_phys;
  76. struct atmel_nand_data *board;
  77. struct device *dev;
  78. void __iomem *ecc;
  79. struct completion comp;
  80. struct dma_chan *dma_chan;
  81. };
  82. static int cpu_has_dma(void)
  83. {
  84. return cpu_is_at91sam9rl() || cpu_is_at91sam9g45();
  85. }
  86. /*
  87. * Enable NAND.
  88. */
  89. static void atmel_nand_enable(struct atmel_nand_host *host)
  90. {
  91. if (gpio_is_valid(host->board->enable_pin))
  92. gpio_set_value(host->board->enable_pin, 0);
  93. }
  94. /*
  95. * Disable NAND.
  96. */
  97. static void atmel_nand_disable(struct atmel_nand_host *host)
  98. {
  99. if (gpio_is_valid(host->board->enable_pin))
  100. gpio_set_value(host->board->enable_pin, 1);
  101. }
  102. /*
  103. * Hardware specific access to control-lines
  104. */
  105. static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
  106. {
  107. struct nand_chip *nand_chip = mtd->priv;
  108. struct atmel_nand_host *host = nand_chip->priv;
  109. if (ctrl & NAND_CTRL_CHANGE) {
  110. if (ctrl & NAND_NCE)
  111. atmel_nand_enable(host);
  112. else
  113. atmel_nand_disable(host);
  114. }
  115. if (cmd == NAND_CMD_NONE)
  116. return;
  117. if (ctrl & NAND_CLE)
  118. writeb(cmd, host->io_base + (1 << host->board->cle));
  119. else
  120. writeb(cmd, host->io_base + (1 << host->board->ale));
  121. }
  122. /*
  123. * Read the Device Ready pin.
  124. */
  125. static int atmel_nand_device_ready(struct mtd_info *mtd)
  126. {
  127. struct nand_chip *nand_chip = mtd->priv;
  128. struct atmel_nand_host *host = nand_chip->priv;
  129. return gpio_get_value(host->board->rdy_pin) ^
  130. !!host->board->rdy_pin_active_low;
  131. }
  132. /*
  133. * Minimal-overhead PIO for data access.
  134. */
  135. static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
  136. {
  137. struct nand_chip *nand_chip = mtd->priv;
  138. __raw_readsb(nand_chip->IO_ADDR_R, buf, len);
  139. }
  140. static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
  141. {
  142. struct nand_chip *nand_chip = mtd->priv;
  143. __raw_readsw(nand_chip->IO_ADDR_R, buf, len / 2);
  144. }
  145. static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len)
  146. {
  147. struct nand_chip *nand_chip = mtd->priv;
  148. __raw_writesb(nand_chip->IO_ADDR_W, buf, len);
  149. }
  150. static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
  151. {
  152. struct nand_chip *nand_chip = mtd->priv;
  153. __raw_writesw(nand_chip->IO_ADDR_W, buf, len / 2);
  154. }
  155. static void dma_complete_func(void *completion)
  156. {
  157. complete(completion);
  158. }
  159. static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len,
  160. int is_read)
  161. {
  162. struct dma_device *dma_dev;
  163. enum dma_ctrl_flags flags;
  164. dma_addr_t dma_src_addr, dma_dst_addr, phys_addr;
  165. struct dma_async_tx_descriptor *tx = NULL;
  166. dma_cookie_t cookie;
  167. struct nand_chip *chip = mtd->priv;
  168. struct atmel_nand_host *host = chip->priv;
  169. void *p = buf;
  170. int err = -EIO;
  171. enum dma_data_direction dir = is_read ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
  172. if (buf >= high_memory)
  173. goto err_buf;
  174. dma_dev = host->dma_chan->device;
  175. flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP |
  176. DMA_COMPL_SKIP_DEST_UNMAP;
  177. phys_addr = dma_map_single(dma_dev->dev, p, len, dir);
  178. if (dma_mapping_error(dma_dev->dev, phys_addr)) {
  179. dev_err(host->dev, "Failed to dma_map_single\n");
  180. goto err_buf;
  181. }
  182. if (is_read) {
  183. dma_src_addr = host->io_phys;
  184. dma_dst_addr = phys_addr;
  185. } else {
  186. dma_src_addr = phys_addr;
  187. dma_dst_addr = host->io_phys;
  188. }
  189. tx = dma_dev->device_prep_dma_memcpy(host->dma_chan, dma_dst_addr,
  190. dma_src_addr, len, flags);
  191. if (!tx) {
  192. dev_err(host->dev, "Failed to prepare DMA memcpy\n");
  193. goto err_dma;
  194. }
  195. init_completion(&host->comp);
  196. tx->callback = dma_complete_func;
  197. tx->callback_param = &host->comp;
  198. cookie = tx->tx_submit(tx);
  199. if (dma_submit_error(cookie)) {
  200. dev_err(host->dev, "Failed to do DMA tx_submit\n");
  201. goto err_dma;
  202. }
  203. dma_async_issue_pending(host->dma_chan);
  204. wait_for_completion(&host->comp);
  205. err = 0;
  206. err_dma:
  207. dma_unmap_single(dma_dev->dev, phys_addr, len, dir);
  208. err_buf:
  209. if (err != 0)
  210. dev_warn(host->dev, "Fall back to CPU I/O\n");
  211. return err;
  212. }
  213. static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
  214. {
  215. struct nand_chip *chip = mtd->priv;
  216. struct atmel_nand_host *host = chip->priv;
  217. if (use_dma && len > mtd->oobsize)
  218. /* only use DMA for bigger than oob size: better performances */
  219. if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
  220. return;
  221. if (host->board->bus_width_16)
  222. atmel_read_buf16(mtd, buf, len);
  223. else
  224. atmel_read_buf8(mtd, buf, len);
  225. }
  226. static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
  227. {
  228. struct nand_chip *chip = mtd->priv;
  229. struct atmel_nand_host *host = chip->priv;
  230. if (use_dma && len > mtd->oobsize)
  231. /* only use DMA for bigger than oob size: better performances */
  232. if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
  233. return;
  234. if (host->board->bus_width_16)
  235. atmel_write_buf16(mtd, buf, len);
  236. else
  237. atmel_write_buf8(mtd, buf, len);
  238. }
  239. /*
  240. * Calculate HW ECC
  241. *
  242. * function called after a write
  243. *
  244. * mtd: MTD block structure
  245. * dat: raw data (unused)
  246. * ecc_code: buffer for ECC
  247. */
  248. static int atmel_nand_calculate(struct mtd_info *mtd,
  249. const u_char *dat, unsigned char *ecc_code)
  250. {
  251. struct nand_chip *nand_chip = mtd->priv;
  252. struct atmel_nand_host *host = nand_chip->priv;
  253. unsigned int ecc_value;
  254. /* get the first 2 ECC bytes */
  255. ecc_value = ecc_readl(host->ecc, PR);
  256. ecc_code[0] = ecc_value & 0xFF;
  257. ecc_code[1] = (ecc_value >> 8) & 0xFF;
  258. /* get the last 2 ECC bytes */
  259. ecc_value = ecc_readl(host->ecc, NPR) & ATMEL_ECC_NPARITY;
  260. ecc_code[2] = ecc_value & 0xFF;
  261. ecc_code[3] = (ecc_value >> 8) & 0xFF;
  262. return 0;
  263. }
  264. /*
  265. * HW ECC read page function
  266. *
  267. * mtd: mtd info structure
  268. * chip: nand chip info structure
  269. * buf: buffer to store read data
  270. */
  271. static int atmel_nand_read_page(struct mtd_info *mtd,
  272. struct nand_chip *chip, uint8_t *buf, int page)
  273. {
  274. int eccsize = chip->ecc.size;
  275. int eccbytes = chip->ecc.bytes;
  276. uint32_t *eccpos = chip->ecc.layout->eccpos;
  277. uint8_t *p = buf;
  278. uint8_t *oob = chip->oob_poi;
  279. uint8_t *ecc_pos;
  280. int stat;
  281. /*
  282. * Errata: ALE is incorrectly wired up to the ECC controller
  283. * on the AP7000, so it will include the address cycles in the
  284. * ECC calculation.
  285. *
  286. * Workaround: Reset the parity registers before reading the
  287. * actual data.
  288. */
  289. if (cpu_is_at32ap7000()) {
  290. struct atmel_nand_host *host = chip->priv;
  291. ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
  292. }
  293. /* read the page */
  294. chip->read_buf(mtd, p, eccsize);
  295. /* move to ECC position if needed */
  296. if (eccpos[0] != 0) {
  297. /* This only works on large pages
  298. * because the ECC controller waits for
  299. * NAND_CMD_RNDOUTSTART after the
  300. * NAND_CMD_RNDOUT.
  301. * anyway, for small pages, the eccpos[0] == 0
  302. */
  303. chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
  304. mtd->writesize + eccpos[0], -1);
  305. }
  306. /* the ECC controller needs to read the ECC just after the data */
  307. ecc_pos = oob + eccpos[0];
  308. chip->read_buf(mtd, ecc_pos, eccbytes);
  309. /* check if there's an error */
  310. stat = chip->ecc.correct(mtd, p, oob, NULL);
  311. if (stat < 0)
  312. mtd->ecc_stats.failed++;
  313. else
  314. mtd->ecc_stats.corrected += stat;
  315. /* get back to oob start (end of page) */
  316. chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
  317. /* read the oob */
  318. chip->read_buf(mtd, oob, mtd->oobsize);
  319. return 0;
  320. }
  321. /*
  322. * HW ECC Correction
  323. *
  324. * function called after a read
  325. *
  326. * mtd: MTD block structure
  327. * dat: raw data read from the chip
  328. * read_ecc: ECC from the chip (unused)
  329. * isnull: unused
  330. *
  331. * Detect and correct a 1 bit error for a page
  332. */
  333. static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
  334. u_char *read_ecc, u_char *isnull)
  335. {
  336. struct nand_chip *nand_chip = mtd->priv;
  337. struct atmel_nand_host *host = nand_chip->priv;
  338. unsigned int ecc_status;
  339. unsigned int ecc_word, ecc_bit;
  340. /* get the status from the Status Register */
  341. ecc_status = ecc_readl(host->ecc, SR);
  342. /* if there's no error */
  343. if (likely(!(ecc_status & ATMEL_ECC_RECERR)))
  344. return 0;
  345. /* get error bit offset (4 bits) */
  346. ecc_bit = ecc_readl(host->ecc, PR) & ATMEL_ECC_BITADDR;
  347. /* get word address (12 bits) */
  348. ecc_word = ecc_readl(host->ecc, PR) & ATMEL_ECC_WORDADDR;
  349. ecc_word >>= 4;
  350. /* if there are multiple errors */
  351. if (ecc_status & ATMEL_ECC_MULERR) {
  352. /* check if it is a freshly erased block
  353. * (filled with 0xff) */
  354. if ((ecc_bit == ATMEL_ECC_BITADDR)
  355. && (ecc_word == (ATMEL_ECC_WORDADDR >> 4))) {
  356. /* the block has just been erased, return OK */
  357. return 0;
  358. }
  359. /* it doesn't seems to be a freshly
  360. * erased block.
  361. * We can't correct so many errors */
  362. dev_dbg(host->dev, "atmel_nand : multiple errors detected."
  363. " Unable to correct.\n");
  364. return -EIO;
  365. }
  366. /* if there's a single bit error : we can correct it */
  367. if (ecc_status & ATMEL_ECC_ECCERR) {
  368. /* there's nothing much to do here.
  369. * the bit error is on the ECC itself.
  370. */
  371. dev_dbg(host->dev, "atmel_nand : one bit error on ECC code."
  372. " Nothing to correct\n");
  373. return 0;
  374. }
  375. dev_dbg(host->dev, "atmel_nand : one bit error on data."
  376. " (word offset in the page :"
  377. " 0x%x bit offset : 0x%x)\n",
  378. ecc_word, ecc_bit);
  379. /* correct the error */
  380. if (nand_chip->options & NAND_BUSWIDTH_16) {
  381. /* 16 bits words */
  382. ((unsigned short *) dat)[ecc_word] ^= (1 << ecc_bit);
  383. } else {
  384. /* 8 bits words */
  385. dat[ecc_word] ^= (1 << ecc_bit);
  386. }
  387. dev_dbg(host->dev, "atmel_nand : error corrected\n");
  388. return 1;
  389. }
  390. /*
  391. * Enable HW ECC : unused on most chips
  392. */
  393. static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
  394. {
  395. if (cpu_is_at32ap7000()) {
  396. struct nand_chip *nand_chip = mtd->priv;
  397. struct atmel_nand_host *host = nand_chip->priv;
  398. ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
  399. }
  400. }
  401. /*
  402. * Probe for the NAND device.
  403. */
  404. static int __init atmel_nand_probe(struct platform_device *pdev)
  405. {
  406. struct atmel_nand_host *host;
  407. struct mtd_info *mtd;
  408. struct nand_chip *nand_chip;
  409. struct resource *regs;
  410. struct resource *mem;
  411. int res;
  412. mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  413. if (!mem) {
  414. printk(KERN_ERR "atmel_nand: can't get I/O resource mem\n");
  415. return -ENXIO;
  416. }
  417. /* Allocate memory for the device structure (and zero it) */
  418. host = kzalloc(sizeof(struct atmel_nand_host), GFP_KERNEL);
  419. if (!host) {
  420. printk(KERN_ERR "atmel_nand: failed to allocate device structure.\n");
  421. return -ENOMEM;
  422. }
  423. host->io_phys = (dma_addr_t)mem->start;
  424. host->io_base = ioremap(mem->start, resource_size(mem));
  425. if (host->io_base == NULL) {
  426. printk(KERN_ERR "atmel_nand: ioremap failed\n");
  427. res = -EIO;
  428. goto err_nand_ioremap;
  429. }
  430. mtd = &host->mtd;
  431. nand_chip = &host->nand_chip;
  432. host->board = pdev->dev.platform_data;
  433. host->dev = &pdev->dev;
  434. nand_chip->priv = host; /* link the private data structures */
  435. mtd->priv = nand_chip;
  436. mtd->owner = THIS_MODULE;
  437. /* Set address of NAND IO lines */
  438. nand_chip->IO_ADDR_R = host->io_base;
  439. nand_chip->IO_ADDR_W = host->io_base;
  440. nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
  441. if (gpio_is_valid(host->board->rdy_pin))
  442. nand_chip->dev_ready = atmel_nand_device_ready;
  443. nand_chip->ecc.mode = host->board->ecc_mode;
  444. regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  445. if (!regs && nand_chip->ecc.mode == NAND_ECC_HW) {
  446. printk(KERN_ERR "atmel_nand: can't get I/O resource "
  447. "regs\nFalling back on software ECC\n");
  448. nand_chip->ecc.mode = NAND_ECC_SOFT;
  449. }
  450. if (nand_chip->ecc.mode == NAND_ECC_HW) {
  451. host->ecc = ioremap(regs->start, resource_size(regs));
  452. if (host->ecc == NULL) {
  453. printk(KERN_ERR "atmel_nand: ioremap failed\n");
  454. res = -EIO;
  455. goto err_ecc_ioremap;
  456. }
  457. nand_chip->ecc.calculate = atmel_nand_calculate;
  458. nand_chip->ecc.correct = atmel_nand_correct;
  459. nand_chip->ecc.hwctl = atmel_nand_hwctl;
  460. nand_chip->ecc.read_page = atmel_nand_read_page;
  461. nand_chip->ecc.bytes = 4;
  462. }
  463. nand_chip->chip_delay = 20; /* 20us command delay time */
  464. if (host->board->bus_width_16) /* 16-bit bus width */
  465. nand_chip->options |= NAND_BUSWIDTH_16;
  466. nand_chip->read_buf = atmel_read_buf;
  467. nand_chip->write_buf = atmel_write_buf;
  468. platform_set_drvdata(pdev, host);
  469. atmel_nand_enable(host);
  470. if (gpio_is_valid(host->board->det_pin)) {
  471. if (gpio_get_value(host->board->det_pin)) {
  472. printk(KERN_INFO "No SmartMedia card inserted.\n");
  473. res = -ENXIO;
  474. goto err_no_card;
  475. }
  476. }
  477. if (host->board->on_flash_bbt || on_flash_bbt) {
  478. printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
  479. nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
  480. }
  481. if (!cpu_has_dma())
  482. use_dma = 0;
  483. if (use_dma) {
  484. dma_cap_mask_t mask;
  485. dma_cap_zero(mask);
  486. dma_cap_set(DMA_MEMCPY, mask);
  487. host->dma_chan = dma_request_channel(mask, NULL, NULL);
  488. if (!host->dma_chan) {
  489. dev_err(host->dev, "Failed to request DMA channel\n");
  490. use_dma = 0;
  491. }
  492. }
  493. if (use_dma)
  494. dev_info(host->dev, "Using %s for DMA transfers.\n",
  495. dma_chan_name(host->dma_chan));
  496. else
  497. dev_info(host->dev, "No DMA support for NAND access.\n");
  498. /* first scan to find the device and get the page size */
  499. if (nand_scan_ident(mtd, 1, NULL)) {
  500. res = -ENXIO;
  501. goto err_scan_ident;
  502. }
  503. if (nand_chip->ecc.mode == NAND_ECC_HW) {
  504. /* ECC is calculated for the whole page (1 step) */
  505. nand_chip->ecc.size = mtd->writesize;
  506. /* set ECC page size and oob layout */
  507. switch (mtd->writesize) {
  508. case 512:
  509. nand_chip->ecc.layout = &atmel_oobinfo_small;
  510. ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_528);
  511. break;
  512. case 1024:
  513. nand_chip->ecc.layout = &atmel_oobinfo_large;
  514. ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_1056);
  515. break;
  516. case 2048:
  517. nand_chip->ecc.layout = &atmel_oobinfo_large;
  518. ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_2112);
  519. break;
  520. case 4096:
  521. nand_chip->ecc.layout = &atmel_oobinfo_large;
  522. ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_4224);
  523. break;
  524. default:
  525. /* page size not handled by HW ECC */
  526. /* switching back to soft ECC */
  527. nand_chip->ecc.mode = NAND_ECC_SOFT;
  528. nand_chip->ecc.calculate = NULL;
  529. nand_chip->ecc.correct = NULL;
  530. nand_chip->ecc.hwctl = NULL;
  531. nand_chip->ecc.read_page = NULL;
  532. nand_chip->ecc.postpad = 0;
  533. nand_chip->ecc.prepad = 0;
  534. nand_chip->ecc.bytes = 0;
  535. break;
  536. }
  537. }
  538. /* second phase scan */
  539. if (nand_scan_tail(mtd)) {
  540. res = -ENXIO;
  541. goto err_scan_tail;
  542. }
  543. mtd->name = "atmel_nand";
  544. res = mtd_device_parse_register(mtd, NULL, 0,
  545. host->board->parts, host->board->num_parts);
  546. if (!res)
  547. return res;
  548. err_scan_tail:
  549. err_scan_ident:
  550. err_no_card:
  551. atmel_nand_disable(host);
  552. platform_set_drvdata(pdev, NULL);
  553. if (host->dma_chan)
  554. dma_release_channel(host->dma_chan);
  555. if (host->ecc)
  556. iounmap(host->ecc);
  557. err_ecc_ioremap:
  558. iounmap(host->io_base);
  559. err_nand_ioremap:
  560. kfree(host);
  561. return res;
  562. }
  563. /*
  564. * Remove a NAND device.
  565. */
  566. static int __exit atmel_nand_remove(struct platform_device *pdev)
  567. {
  568. struct atmel_nand_host *host = platform_get_drvdata(pdev);
  569. struct mtd_info *mtd = &host->mtd;
  570. nand_release(mtd);
  571. atmel_nand_disable(host);
  572. if (host->ecc)
  573. iounmap(host->ecc);
  574. if (host->dma_chan)
  575. dma_release_channel(host->dma_chan);
  576. iounmap(host->io_base);
  577. kfree(host);
  578. return 0;
  579. }
  580. static struct platform_driver atmel_nand_driver = {
  581. .remove = __exit_p(atmel_nand_remove),
  582. .driver = {
  583. .name = "atmel_nand",
  584. .owner = THIS_MODULE,
  585. },
  586. };
  587. static int __init atmel_nand_init(void)
  588. {
  589. return platform_driver_probe(&atmel_nand_driver, atmel_nand_probe);
  590. }
  591. static void __exit atmel_nand_exit(void)
  592. {
  593. platform_driver_unregister(&atmel_nand_driver);
  594. }
  595. module_init(atmel_nand_init);
  596. module_exit(atmel_nand_exit);
  597. MODULE_LICENSE("GPL");
  598. MODULE_AUTHOR("Rick Bronson");
  599. MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91 / AVR32");
  600. MODULE_ALIAS("platform:atmel_nand");