2 * Copyright © 2003 Rick Bronson
4 * Derived from drivers/mtd/nand/autcpu12.c
5 * Copyright © 2001 Thomas Gleixner (gleixner@autronix.de)
7 * Derived from drivers/mtd/spia.c
8 * Copyright © 2000 Steven J. Hill (sjhill@cotw.com)
11 * Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
12 * Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright © 2007
14 * Derived from Das U-Boot source code
15 * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
16 * © Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
18 * Add Programmable Multibit ECC support for various AT91 SoC
19 * © Copyright 2012 ATMEL, Hong Xu
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License version 2 as
23 * published by the Free Software Foundation.
27 #include <linux/dma-mapping.h>
28 #include <linux/slab.h>
29 #include <linux/module.h>
30 #include <linux/moduleparam.h>
31 #include <linux/platform_device.h>
33 #include <linux/of_device.h>
34 #include <linux/of_gpio.h>
35 #include <linux/of_mtd.h>
36 #include <linux/mtd/mtd.h>
37 #include <linux/mtd/nand.h>
38 #include <linux/mtd/partitions.h>
40 #include <linux/dmaengine.h>
41 #include <linux/gpio.h>
43 #include <linux/platform_data/atmel.h>
47 static int use_dma = 1;
48 module_param(use_dma, int, 0);
50 static int on_flash_bbt = 0;
51 module_param(on_flash_bbt, int, 0);
53 /* Register access macros */
54 #define ecc_readl(add, reg) \
55 __raw_readl(add + ATMEL_ECC_##reg)
56 #define ecc_writel(add, reg, value) \
57 __raw_writel((value), add + ATMEL_ECC_##reg)
59 #include "atmel_nand_ecc.h" /* Hardware ECC registers */
61 /* oob layout for large page size
62 * bad block info is on bytes 0 and 1
63 * the bytes have to be consecutives to avoid
64 * several NAND_CMD_RNDOUT during read
66 static struct nand_ecclayout atmel_oobinfo_large = {
68 .eccpos = {60, 61, 62, 63},
74 /* oob layout for small page size
75 * bad block info is on bytes 4 and 5
76 * the bytes have to be consecutives to avoid
77 * several NAND_CMD_RNDOUT during read
79 static struct nand_ecclayout atmel_oobinfo_small = {
81 .eccpos = {0, 1, 2, 3},
87 struct atmel_nand_host {
88 struct nand_chip nand_chip;
90 void __iomem *io_base;
92 struct atmel_nand_data board;
96 struct completion comp;
97 struct dma_chan *dma_chan;
101 u16 pmecc_sector_size;
102 u32 pmecc_lookup_table_offset;
104 int pmecc_bytes_per_sector;
105 int pmecc_sector_number;
106 int pmecc_degree; /* Degree of remainders */
107 int pmecc_cw_len; /* Length of codeword */
109 void __iomem *pmerrloc_base;
110 void __iomem *pmecc_rom_base;
112 /* lookup table for alpha_to and index_of */
113 void __iomem *pmecc_alpha_to;
114 void __iomem *pmecc_index_of;
116 /* data for pmecc computation */
117 int16_t *pmecc_partial_syn;
119 int16_t *pmecc_smu; /* Sigma table */
120 int16_t *pmecc_lmu; /* polynomal order */
126 static struct nand_ecclayout atmel_pmecc_oobinfo;
128 static int cpu_has_dma(void)
130 return cpu_is_at91sam9rl() || cpu_is_at91sam9g45();
136 static void atmel_nand_enable(struct atmel_nand_host *host)
138 if (gpio_is_valid(host->board.enable_pin))
139 gpio_set_value(host->board.enable_pin, 0);
145 static void atmel_nand_disable(struct atmel_nand_host *host)
147 if (gpio_is_valid(host->board.enable_pin))
148 gpio_set_value(host->board.enable_pin, 1);
152 * Hardware specific access to control-lines
154 static void atmel_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
156 struct nand_chip *nand_chip = mtd->priv;
157 struct atmel_nand_host *host = nand_chip->priv;
159 if (ctrl & NAND_CTRL_CHANGE) {
161 atmel_nand_enable(host);
163 atmel_nand_disable(host);
165 if (cmd == NAND_CMD_NONE)
169 writeb(cmd, host->io_base + (1 << host->board.cle));
171 writeb(cmd, host->io_base + (1 << host->board.ale));
175 * Read the Device Ready pin.
177 static int atmel_nand_device_ready(struct mtd_info *mtd)
179 struct nand_chip *nand_chip = mtd->priv;
180 struct atmel_nand_host *host = nand_chip->priv;
182 return gpio_get_value(host->board.rdy_pin) ^
183 !!host->board.rdy_pin_active_low;
187 * Minimal-overhead PIO for data access.
189 static void atmel_read_buf8(struct mtd_info *mtd, u8 *buf, int len)
191 struct nand_chip *nand_chip = mtd->priv;
193 __raw_readsb(nand_chip->IO_ADDR_R, buf, len);
196 static void atmel_read_buf16(struct mtd_info *mtd, u8 *buf, int len)
198 struct nand_chip *nand_chip = mtd->priv;
200 __raw_readsw(nand_chip->IO_ADDR_R, buf, len / 2);
203 static void atmel_write_buf8(struct mtd_info *mtd, const u8 *buf, int len)
205 struct nand_chip *nand_chip = mtd->priv;
207 __raw_writesb(nand_chip->IO_ADDR_W, buf, len);
210 static void atmel_write_buf16(struct mtd_info *mtd, const u8 *buf, int len)
212 struct nand_chip *nand_chip = mtd->priv;
214 __raw_writesw(nand_chip->IO_ADDR_W, buf, len / 2);
217 static void dma_complete_func(void *completion)
219 complete(completion);
222 static int atmel_nand_dma_op(struct mtd_info *mtd, void *buf, int len,
225 struct dma_device *dma_dev;
226 enum dma_ctrl_flags flags;
227 dma_addr_t dma_src_addr, dma_dst_addr, phys_addr;
228 struct dma_async_tx_descriptor *tx = NULL;
230 struct nand_chip *chip = mtd->priv;
231 struct atmel_nand_host *host = chip->priv;
234 enum dma_data_direction dir = is_read ? DMA_FROM_DEVICE : DMA_TO_DEVICE;
236 if (buf >= high_memory)
239 dma_dev = host->dma_chan->device;
241 flags = DMA_CTRL_ACK | DMA_PREP_INTERRUPT | DMA_COMPL_SKIP_SRC_UNMAP |
242 DMA_COMPL_SKIP_DEST_UNMAP;
244 phys_addr = dma_map_single(dma_dev->dev, p, len, dir);
245 if (dma_mapping_error(dma_dev->dev, phys_addr)) {
246 dev_err(host->dev, "Failed to dma_map_single\n");
251 dma_src_addr = host->io_phys;
252 dma_dst_addr = phys_addr;
254 dma_src_addr = phys_addr;
255 dma_dst_addr = host->io_phys;
258 tx = dma_dev->device_prep_dma_memcpy(host->dma_chan, dma_dst_addr,
259 dma_src_addr, len, flags);
261 dev_err(host->dev, "Failed to prepare DMA memcpy\n");
265 init_completion(&host->comp);
266 tx->callback = dma_complete_func;
267 tx->callback_param = &host->comp;
269 cookie = tx->tx_submit(tx);
270 if (dma_submit_error(cookie)) {
271 dev_err(host->dev, "Failed to do DMA tx_submit\n");
275 dma_async_issue_pending(host->dma_chan);
276 wait_for_completion(&host->comp);
281 dma_unmap_single(dma_dev->dev, phys_addr, len, dir);
284 dev_warn(host->dev, "Fall back to CPU I/O\n");
288 static void atmel_read_buf(struct mtd_info *mtd, u8 *buf, int len)
290 struct nand_chip *chip = mtd->priv;
291 struct atmel_nand_host *host = chip->priv;
293 if (use_dma && len > mtd->oobsize)
294 /* only use DMA for bigger than oob size: better performances */
295 if (atmel_nand_dma_op(mtd, buf, len, 1) == 0)
298 if (host->board.bus_width_16)
299 atmel_read_buf16(mtd, buf, len);
301 atmel_read_buf8(mtd, buf, len);
304 static void atmel_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
306 struct nand_chip *chip = mtd->priv;
307 struct atmel_nand_host *host = chip->priv;
309 if (use_dma && len > mtd->oobsize)
310 /* only use DMA for bigger than oob size: better performances */
311 if (atmel_nand_dma_op(mtd, (void *)buf, len, 0) == 0)
314 if (host->board.bus_width_16)
315 atmel_write_buf16(mtd, buf, len);
317 atmel_write_buf8(mtd, buf, len);
321 * Return number of ecc bytes per sector according to sector size and
322 * correction capability
324 * Following table shows what at91 PMECC supported:
325 * Correction Capability Sector_512_bytes Sector_1024_bytes
326 * ===================== ================ =================
327 * 2-bits 4-bytes 4-bytes
328 * 4-bits 7-bytes 7-bytes
329 * 8-bits 13-bytes 14-bytes
330 * 12-bits 20-bytes 21-bytes
331 * 24-bits 39-bytes 42-bytes
333 static int __devinit pmecc_get_ecc_bytes(int cap, int sector_size)
335 int m = 12 + sector_size / 512;
336 return (m * cap + 7) / 8;
339 static void __devinit pmecc_config_ecc_layout(struct nand_ecclayout *layout,
340 int oobsize, int ecc_len)
344 layout->eccbytes = ecc_len;
346 /* ECC will occupy the last ecc_len bytes continuously */
347 for (i = 0; i < ecc_len; i++)
348 layout->eccpos[i] = oobsize - ecc_len + i;
350 layout->oobfree[0].offset = 2;
351 layout->oobfree[0].length =
352 oobsize - ecc_len - layout->oobfree[0].offset;
355 static void __devinit __iomem *pmecc_get_alpha_to(struct atmel_nand_host *host)
359 table_size = host->pmecc_sector_size == 512 ?
360 PMECC_LOOKUP_TABLE_SIZE_512 : PMECC_LOOKUP_TABLE_SIZE_1024;
362 return host->pmecc_rom_base + host->pmecc_lookup_table_offset +
363 table_size * sizeof(int16_t);
366 static void pmecc_data_free(struct atmel_nand_host *host)
368 kfree(host->pmecc_partial_syn);
369 kfree(host->pmecc_si);
370 kfree(host->pmecc_lmu);
371 kfree(host->pmecc_smu);
372 kfree(host->pmecc_mu);
373 kfree(host->pmecc_dmu);
374 kfree(host->pmecc_delta);
377 static int __devinit pmecc_data_alloc(struct atmel_nand_host *host)
379 const int cap = host->pmecc_corr_cap;
381 host->pmecc_partial_syn = kzalloc((2 * cap + 1) * sizeof(int16_t),
383 host->pmecc_si = kzalloc((2 * cap + 1) * sizeof(int16_t), GFP_KERNEL);
384 host->pmecc_lmu = kzalloc((cap + 1) * sizeof(int16_t), GFP_KERNEL);
385 host->pmecc_smu = kzalloc((cap + 2) * (2 * cap + 1) * sizeof(int16_t),
387 host->pmecc_mu = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL);
388 host->pmecc_dmu = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL);
389 host->pmecc_delta = kzalloc((cap + 1) * sizeof(int), GFP_KERNEL);
391 if (host->pmecc_partial_syn &&
401 pmecc_data_free(host);
405 static void pmecc_gen_syndrome(struct mtd_info *mtd, int sector)
407 struct nand_chip *nand_chip = mtd->priv;
408 struct atmel_nand_host *host = nand_chip->priv;
412 /* Fill odd syndromes */
413 for (i = 0; i < host->pmecc_corr_cap; i++) {
414 value = pmecc_readl_rem_relaxed(host->ecc, sector, i / 2);
418 host->pmecc_partial_syn[(2 * i) + 1] = (int16_t)value;
422 static void pmecc_substitute(struct mtd_info *mtd)
424 struct nand_chip *nand_chip = mtd->priv;
425 struct atmel_nand_host *host = nand_chip->priv;
426 int16_t __iomem *alpha_to = host->pmecc_alpha_to;
427 int16_t __iomem *index_of = host->pmecc_index_of;
428 int16_t *partial_syn = host->pmecc_partial_syn;
429 const int cap = host->pmecc_corr_cap;
433 /* si[] is a table that holds the current syndrome value,
434 * an element of that table belongs to the field
438 memset(&si[1], 0, sizeof(int16_t) * (2 * cap - 1));
440 /* Computation 2t syndromes based on S(x) */
442 for (i = 1; i < 2 * cap; i += 2) {
443 for (j = 0; j < host->pmecc_degree; j++) {
444 if (partial_syn[i] & ((unsigned short)0x1 << j))
445 si[i] = readw_relaxed(alpha_to + i * j) ^ si[i];
448 /* Even syndrome = (Odd syndrome) ** 2 */
449 for (i = 2, j = 1; j <= cap; i = ++j << 1) {
455 tmp = readw_relaxed(index_of + si[j]);
456 tmp = (tmp * 2) % host->pmecc_cw_len;
457 si[i] = readw_relaxed(alpha_to + tmp);
464 static void pmecc_get_sigma(struct mtd_info *mtd)
466 struct nand_chip *nand_chip = mtd->priv;
467 struct atmel_nand_host *host = nand_chip->priv;
469 int16_t *lmu = host->pmecc_lmu;
470 int16_t *si = host->pmecc_si;
471 int *mu = host->pmecc_mu;
472 int *dmu = host->pmecc_dmu; /* Discrepancy */
473 int *delta = host->pmecc_delta; /* Delta order */
474 int cw_len = host->pmecc_cw_len;
475 const int16_t cap = host->pmecc_corr_cap;
476 const int num = 2 * cap + 1;
477 int16_t __iomem *index_of = host->pmecc_index_of;
478 int16_t __iomem *alpha_to = host->pmecc_alpha_to;
480 uint32_t dmu_0_count, tmp;
481 int16_t *smu = host->pmecc_smu;
483 /* index of largest delta */
495 memset(smu, 0, sizeof(int16_t) * num);
498 /* discrepancy set to 1 */
500 /* polynom order set to 0 */
502 delta[0] = (mu[0] * 2 - lmu[0]) >> 1;
508 /* Sigma(x) set to 1 */
509 memset(&smu[num], 0, sizeof(int16_t) * num);
512 /* discrepancy set to S1 */
515 /* polynom order set to 0 */
518 delta[1] = (mu[1] * 2 - lmu[1]) >> 1;
520 /* Init the Sigma(x) last row */
521 memset(&smu[(cap + 1) * num], 0, sizeof(int16_t) * num);
523 for (i = 1; i <= cap; i++) {
525 /* Begin Computing Sigma (Mu+1) and L(mu) */
526 /* check if discrepancy is set to 0 */
530 tmp = ((cap - (lmu[i] >> 1) - 1) / 2);
531 if ((cap - (lmu[i] >> 1) - 1) & 0x1)
536 if (dmu_0_count == tmp) {
537 for (j = 0; j <= (lmu[i] >> 1) + 1; j++)
538 smu[(cap + 1) * num + j] =
541 lmu[cap + 1] = lmu[i];
546 for (j = 0; j <= lmu[i] >> 1; j++)
547 smu[(i + 1) * num + j] = smu[i * num + j];
549 /* copy previous polynom order to the next */
554 /* find largest delta with dmu != 0 */
555 for (j = 0; j < i; j++) {
556 if ((dmu[j]) && (delta[j] > largest)) {
562 /* compute difference */
563 diff = (mu[i] - mu[ro]);
565 /* Compute degree of the new smu polynomial */
566 if ((lmu[i] >> 1) > ((lmu[ro] >> 1) + diff))
569 lmu[i + 1] = ((lmu[ro] >> 1) + diff) * 2;
571 /* Init smu[i+1] with 0 */
572 for (k = 0; k < num; k++)
573 smu[(i + 1) * num + k] = 0;
575 /* Compute smu[i+1] */
576 for (k = 0; k <= lmu[ro] >> 1; k++) {
579 if (!(smu[ro * num + k] && dmu[i]))
581 a = readw_relaxed(index_of + dmu[i]);
582 b = readw_relaxed(index_of + dmu[ro]);
583 c = readw_relaxed(index_of + smu[ro * num + k]);
584 tmp = a + (cw_len - b) + c;
585 a = readw_relaxed(alpha_to + tmp % cw_len);
586 smu[(i + 1) * num + (k + diff)] = a;
589 for (k = 0; k <= lmu[i] >> 1; k++)
590 smu[(i + 1) * num + k] ^= smu[i * num + k];
593 /* End Computing Sigma (Mu+1) and L(mu) */
594 /* In either case compute delta */
595 delta[i + 1] = (mu[i + 1] * 2 - lmu[i + 1]) >> 1;
597 /* Do not compute discrepancy for the last iteration */
601 for (k = 0; k <= (lmu[i + 1] >> 1); k++) {
604 dmu[i + 1] = si[tmp + 3];
605 } else if (smu[(i + 1) * num + k] && si[tmp + 3 - k]) {
607 a = readw_relaxed(index_of +
608 smu[(i + 1) * num + k]);
609 b = si[2 * (i - 1) + 3 - k];
610 c = readw_relaxed(index_of + b);
613 dmu[i + 1] = readw_relaxed(alpha_to + tmp) ^
622 static int pmecc_err_location(struct mtd_info *mtd)
624 struct nand_chip *nand_chip = mtd->priv;
625 struct atmel_nand_host *host = nand_chip->priv;
626 unsigned long end_time;
627 const int cap = host->pmecc_corr_cap;
628 const int num = 2 * cap + 1;
629 int sector_size = host->pmecc_sector_size;
630 int err_nbr = 0; /* number of error */
631 int roots_nbr; /* number of roots */
634 int16_t *smu = host->pmecc_smu;
636 pmerrloc_writel(host->pmerrloc_base, ELDIS, PMERRLOC_DISABLE);
638 for (i = 0; i <= host->pmecc_lmu[cap + 1] >> 1; i++) {
639 pmerrloc_writel_sigma_relaxed(host->pmerrloc_base, i,
640 smu[(cap + 1) * num + i]);
644 val = (err_nbr - 1) << 16;
645 if (sector_size == 1024)
648 pmerrloc_writel(host->pmerrloc_base, ELCFG, val);
649 pmerrloc_writel(host->pmerrloc_base, ELEN,
650 sector_size * 8 + host->pmecc_degree * cap);
652 end_time = jiffies + msecs_to_jiffies(PMECC_MAX_TIMEOUT_MS);
653 while (!(pmerrloc_readl_relaxed(host->pmerrloc_base, ELISR)
654 & PMERRLOC_CALC_DONE)) {
655 if (unlikely(time_after(jiffies, end_time))) {
656 dev_err(host->dev, "PMECC: Timeout to calculate error location.\n");
662 roots_nbr = (pmerrloc_readl_relaxed(host->pmerrloc_base, ELISR)
663 & PMERRLOC_ERR_NUM_MASK) >> 8;
664 /* Number of roots == degree of smu hence <= cap */
665 if (roots_nbr == host->pmecc_lmu[cap + 1] >> 1)
668 /* Number of roots does not match the degree of smu
669 * unable to correct error */
673 static void pmecc_correct_data(struct mtd_info *mtd, uint8_t *buf, uint8_t *ecc,
674 int sector_num, int extra_bytes, int err_nbr)
676 struct nand_chip *nand_chip = mtd->priv;
677 struct atmel_nand_host *host = nand_chip->priv;
679 int byte_pos, bit_pos, sector_size, pos;
683 sector_size = host->pmecc_sector_size;
686 tmp = pmerrloc_readl_el_relaxed(host->pmerrloc_base, i) - 1;
690 if (byte_pos >= (sector_size + extra_bytes))
691 BUG(); /* should never happen */
693 if (byte_pos < sector_size) {
694 err_byte = *(buf + byte_pos);
695 *(buf + byte_pos) ^= (1 << bit_pos);
697 pos = sector_num * host->pmecc_sector_size + byte_pos;
698 dev_info(host->dev, "Bit flip in data area, byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
699 pos, bit_pos, err_byte, *(buf + byte_pos));
701 /* Bit flip in OOB area */
702 tmp = sector_num * host->pmecc_bytes_per_sector
703 + (byte_pos - sector_size);
705 ecc[tmp] ^= (1 << bit_pos);
707 pos = tmp + nand_chip->ecc.layout->eccpos[0];
708 dev_info(host->dev, "Bit flip in OOB, oob_byte_pos: %d, bit_pos: %d, 0x%02x -> 0x%02x\n",
709 pos, bit_pos, err_byte, ecc[tmp]);
719 static int pmecc_correction(struct mtd_info *mtd, u32 pmecc_stat, uint8_t *buf,
722 struct nand_chip *nand_chip = mtd->priv;
723 struct atmel_nand_host *host = nand_chip->priv;
724 int i, err_nbr, eccbytes;
727 eccbytes = nand_chip->ecc.bytes;
728 for (i = 0; i < eccbytes; i++)
731 /* Erased page, return OK */
735 for (i = 0; i < host->pmecc_sector_number; i++) {
737 if (pmecc_stat & 0x1) {
738 buf_pos = buf + i * host->pmecc_sector_size;
740 pmecc_gen_syndrome(mtd, i);
741 pmecc_substitute(mtd);
742 pmecc_get_sigma(mtd);
744 err_nbr = pmecc_err_location(mtd);
746 dev_err(host->dev, "PMECC: Too many errors\n");
747 mtd->ecc_stats.failed++;
750 pmecc_correct_data(mtd, buf_pos, ecc, i,
751 host->pmecc_bytes_per_sector, err_nbr);
752 mtd->ecc_stats.corrected += err_nbr;
761 static int atmel_nand_pmecc_read_page(struct mtd_info *mtd,
762 struct nand_chip *chip, uint8_t *buf, int oob_required, int page)
764 struct atmel_nand_host *host = chip->priv;
765 int eccsize = chip->ecc.size;
766 uint8_t *oob = chip->oob_poi;
767 uint32_t *eccpos = chip->ecc.layout->eccpos;
769 unsigned long end_time;
771 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST);
772 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
773 pmecc_writel(host->ecc, CFG, (pmecc_readl_relaxed(host->ecc, CFG)
774 & ~PMECC_CFG_WRITE_OP) | PMECC_CFG_AUTO_ENABLE);
776 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE);
777 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DATA);
779 chip->read_buf(mtd, buf, eccsize);
780 chip->read_buf(mtd, oob, mtd->oobsize);
782 end_time = jiffies + msecs_to_jiffies(PMECC_MAX_TIMEOUT_MS);
783 while ((pmecc_readl_relaxed(host->ecc, SR) & PMECC_SR_BUSY)) {
784 if (unlikely(time_after(jiffies, end_time))) {
785 dev_err(host->dev, "PMECC: Timeout to get error status.\n");
791 stat = pmecc_readl_relaxed(host->ecc, ISR);
793 if (pmecc_correction(mtd, stat, buf, &oob[eccpos[0]]) != 0)
799 static int atmel_nand_pmecc_write_page(struct mtd_info *mtd,
800 struct nand_chip *chip, const uint8_t *buf, int oob_required)
802 struct atmel_nand_host *host = chip->priv;
803 uint32_t *eccpos = chip->ecc.layout->eccpos;
805 unsigned long end_time;
807 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST);
808 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
810 pmecc_writel(host->ecc, CFG, (pmecc_readl_relaxed(host->ecc, CFG) |
811 PMECC_CFG_WRITE_OP) & ~PMECC_CFG_AUTO_ENABLE);
813 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE);
814 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DATA);
816 chip->write_buf(mtd, (u8 *)buf, mtd->writesize);
818 end_time = jiffies + msecs_to_jiffies(PMECC_MAX_TIMEOUT_MS);
819 while ((pmecc_readl_relaxed(host->ecc, SR) & PMECC_SR_BUSY)) {
820 if (unlikely(time_after(jiffies, end_time))) {
821 dev_err(host->dev, "PMECC: Timeout to get ECC value.\n");
827 for (i = 0; i < host->pmecc_sector_number; i++) {
828 for (j = 0; j < host->pmecc_bytes_per_sector; j++) {
831 pos = i * host->pmecc_bytes_per_sector + j;
832 chip->oob_poi[eccpos[pos]] =
833 pmecc_readb_ecc_relaxed(host->ecc, i, j);
836 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
841 static void atmel_pmecc_core_init(struct mtd_info *mtd)
843 struct nand_chip *nand_chip = mtd->priv;
844 struct atmel_nand_host *host = nand_chip->priv;
846 struct nand_ecclayout *ecc_layout;
848 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_RST);
849 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
851 switch (host->pmecc_corr_cap) {
853 val = PMECC_CFG_BCH_ERR2;
856 val = PMECC_CFG_BCH_ERR4;
859 val = PMECC_CFG_BCH_ERR8;
862 val = PMECC_CFG_BCH_ERR12;
865 val = PMECC_CFG_BCH_ERR24;
869 if (host->pmecc_sector_size == 512)
870 val |= PMECC_CFG_SECTOR512;
871 else if (host->pmecc_sector_size == 1024)
872 val |= PMECC_CFG_SECTOR1024;
874 switch (host->pmecc_sector_number) {
876 val |= PMECC_CFG_PAGE_1SECTOR;
879 val |= PMECC_CFG_PAGE_2SECTORS;
882 val |= PMECC_CFG_PAGE_4SECTORS;
885 val |= PMECC_CFG_PAGE_8SECTORS;
889 val |= (PMECC_CFG_READ_OP | PMECC_CFG_SPARE_DISABLE
890 | PMECC_CFG_AUTO_DISABLE);
891 pmecc_writel(host->ecc, CFG, val);
893 ecc_layout = nand_chip->ecc.layout;
894 pmecc_writel(host->ecc, SAREA, mtd->oobsize - 1);
895 pmecc_writel(host->ecc, SADDR, ecc_layout->eccpos[0]);
896 pmecc_writel(host->ecc, EADDR,
897 ecc_layout->eccpos[ecc_layout->eccbytes - 1]);
898 /* See datasheet about PMECC Clock Control Register */
899 pmecc_writel(host->ecc, CLK, 2);
900 pmecc_writel(host->ecc, IDR, 0xff);
901 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_ENABLE);
904 static int __init atmel_pmecc_nand_init_params(struct platform_device *pdev,
905 struct atmel_nand_host *host)
907 struct mtd_info *mtd = &host->mtd;
908 struct nand_chip *nand_chip = &host->nand_chip;
909 struct resource *regs, *regs_pmerr, *regs_rom;
910 int cap, sector_size, err_no;
912 cap = host->pmecc_corr_cap;
913 sector_size = host->pmecc_sector_size;
914 dev_info(host->dev, "Initialize PMECC params, cap: %d, sector: %d\n",
917 regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
920 "Can't get I/O resource regs for PMECC controller, rolling back on software ECC\n");
921 nand_chip->ecc.mode = NAND_ECC_SOFT;
925 host->ecc = ioremap(regs->start, resource_size(regs));
926 if (host->ecc == NULL) {
927 dev_err(host->dev, "ioremap failed\n");
929 goto err_pmecc_ioremap;
932 regs_pmerr = platform_get_resource(pdev, IORESOURCE_MEM, 2);
933 regs_rom = platform_get_resource(pdev, IORESOURCE_MEM, 3);
934 if (regs_pmerr && regs_rom) {
935 host->pmerrloc_base = ioremap(regs_pmerr->start,
936 resource_size(regs_pmerr));
937 host->pmecc_rom_base = ioremap(regs_rom->start,
938 resource_size(regs_rom));
941 if (!host->pmerrloc_base || !host->pmecc_rom_base) {
943 "Can not get I/O resource for PMECC ERRLOC controller or ROM!\n");
945 goto err_pmloc_ioremap;
948 /* ECC is calculated for the whole page (1 step) */
949 nand_chip->ecc.size = mtd->writesize;
951 /* set ECC page size and oob layout */
952 switch (mtd->writesize) {
954 host->pmecc_degree = PMECC_GF_DIMENSION_13;
955 host->pmecc_cw_len = (1 << host->pmecc_degree) - 1;
956 host->pmecc_sector_number = mtd->writesize / sector_size;
957 host->pmecc_bytes_per_sector = pmecc_get_ecc_bytes(
959 host->pmecc_alpha_to = pmecc_get_alpha_to(host);
960 host->pmecc_index_of = host->pmecc_rom_base +
961 host->pmecc_lookup_table_offset;
963 nand_chip->ecc.steps = 1;
964 nand_chip->ecc.strength = cap;
965 nand_chip->ecc.bytes = host->pmecc_bytes_per_sector *
966 host->pmecc_sector_number;
967 if (nand_chip->ecc.bytes > mtd->oobsize - 2) {
968 dev_err(host->dev, "No room for ECC bytes\n");
970 goto err_no_ecc_room;
972 pmecc_config_ecc_layout(&atmel_pmecc_oobinfo,
974 nand_chip->ecc.bytes);
975 nand_chip->ecc.layout = &atmel_pmecc_oobinfo;
982 "Unsupported page size for PMECC, use Software ECC\n");
984 /* page size not handled by HW ECC */
985 /* switching back to soft ECC */
986 nand_chip->ecc.mode = NAND_ECC_SOFT;
990 /* Allocate data for PMECC computation */
991 err_no = pmecc_data_alloc(host);
994 "Cannot allocate memory for PMECC computation!\n");
995 goto err_pmecc_data_alloc;
998 nand_chip->ecc.read_page = atmel_nand_pmecc_read_page;
999 nand_chip->ecc.write_page = atmel_nand_pmecc_write_page;
1001 atmel_pmecc_core_init(mtd);
1005 err_pmecc_data_alloc:
1009 if (host->pmerrloc_base)
1010 iounmap(host->pmerrloc_base);
1011 if (host->pmecc_rom_base)
1012 iounmap(host->pmecc_rom_base);
1020 * function called after a write
1022 * mtd: MTD block structure
1023 * dat: raw data (unused)
1024 * ecc_code: buffer for ECC
1026 static int atmel_nand_calculate(struct mtd_info *mtd,
1027 const u_char *dat, unsigned char *ecc_code)
1029 struct nand_chip *nand_chip = mtd->priv;
1030 struct atmel_nand_host *host = nand_chip->priv;
1031 unsigned int ecc_value;
1033 /* get the first 2 ECC bytes */
1034 ecc_value = ecc_readl(host->ecc, PR);
1036 ecc_code[0] = ecc_value & 0xFF;
1037 ecc_code[1] = (ecc_value >> 8) & 0xFF;
1039 /* get the last 2 ECC bytes */
1040 ecc_value = ecc_readl(host->ecc, NPR) & ATMEL_ECC_NPARITY;
1042 ecc_code[2] = ecc_value & 0xFF;
1043 ecc_code[3] = (ecc_value >> 8) & 0xFF;
1049 * HW ECC read page function
1051 * mtd: mtd info structure
1052 * chip: nand chip info structure
1053 * buf: buffer to store read data
1054 * oob_required: caller expects OOB data read to chip->oob_poi
1056 static int atmel_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1057 uint8_t *buf, int oob_required, int page)
1059 int eccsize = chip->ecc.size;
1060 int eccbytes = chip->ecc.bytes;
1061 uint32_t *eccpos = chip->ecc.layout->eccpos;
1063 uint8_t *oob = chip->oob_poi;
1066 unsigned int max_bitflips = 0;
1069 * Errata: ALE is incorrectly wired up to the ECC controller
1070 * on the AP7000, so it will include the address cycles in the
1073 * Workaround: Reset the parity registers before reading the
1076 if (cpu_is_at32ap7000()) {
1077 struct atmel_nand_host *host = chip->priv;
1078 ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
1082 chip->read_buf(mtd, p, eccsize);
1084 /* move to ECC position if needed */
1085 if (eccpos[0] != 0) {
1086 /* This only works on large pages
1087 * because the ECC controller waits for
1088 * NAND_CMD_RNDOUTSTART after the
1090 * anyway, for small pages, the eccpos[0] == 0
1092 chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
1093 mtd->writesize + eccpos[0], -1);
1096 /* the ECC controller needs to read the ECC just after the data */
1097 ecc_pos = oob + eccpos[0];
1098 chip->read_buf(mtd, ecc_pos, eccbytes);
1100 /* check if there's an error */
1101 stat = chip->ecc.correct(mtd, p, oob, NULL);
1104 mtd->ecc_stats.failed++;
1106 mtd->ecc_stats.corrected += stat;
1107 max_bitflips = max_t(unsigned int, max_bitflips, stat);
1110 /* get back to oob start (end of page) */
1111 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
1114 chip->read_buf(mtd, oob, mtd->oobsize);
1116 return max_bitflips;
1122 * function called after a read
1124 * mtd: MTD block structure
1125 * dat: raw data read from the chip
1126 * read_ecc: ECC from the chip (unused)
1129 * Detect and correct a 1 bit error for a page
1131 static int atmel_nand_correct(struct mtd_info *mtd, u_char *dat,
1132 u_char *read_ecc, u_char *isnull)
1134 struct nand_chip *nand_chip = mtd->priv;
1135 struct atmel_nand_host *host = nand_chip->priv;
1136 unsigned int ecc_status;
1137 unsigned int ecc_word, ecc_bit;
1139 /* get the status from the Status Register */
1140 ecc_status = ecc_readl(host->ecc, SR);
1142 /* if there's no error */
1143 if (likely(!(ecc_status & ATMEL_ECC_RECERR)))
1146 /* get error bit offset (4 bits) */
1147 ecc_bit = ecc_readl(host->ecc, PR) & ATMEL_ECC_BITADDR;
1148 /* get word address (12 bits) */
1149 ecc_word = ecc_readl(host->ecc, PR) & ATMEL_ECC_WORDADDR;
1152 /* if there are multiple errors */
1153 if (ecc_status & ATMEL_ECC_MULERR) {
1154 /* check if it is a freshly erased block
1155 * (filled with 0xff) */
1156 if ((ecc_bit == ATMEL_ECC_BITADDR)
1157 && (ecc_word == (ATMEL_ECC_WORDADDR >> 4))) {
1158 /* the block has just been erased, return OK */
1161 /* it doesn't seems to be a freshly
1163 * We can't correct so many errors */
1164 dev_dbg(host->dev, "atmel_nand : multiple errors detected."
1165 " Unable to correct.\n");
1169 /* if there's a single bit error : we can correct it */
1170 if (ecc_status & ATMEL_ECC_ECCERR) {
1171 /* there's nothing much to do here.
1172 * the bit error is on the ECC itself.
1174 dev_dbg(host->dev, "atmel_nand : one bit error on ECC code."
1175 " Nothing to correct\n");
1179 dev_dbg(host->dev, "atmel_nand : one bit error on data."
1180 " (word offset in the page :"
1181 " 0x%x bit offset : 0x%x)\n",
1183 /* correct the error */
1184 if (nand_chip->options & NAND_BUSWIDTH_16) {
1186 ((unsigned short *) dat)[ecc_word] ^= (1 << ecc_bit);
1189 dat[ecc_word] ^= (1 << ecc_bit);
1191 dev_dbg(host->dev, "atmel_nand : error corrected\n");
1196 * Enable HW ECC : unused on most chips
1198 static void atmel_nand_hwctl(struct mtd_info *mtd, int mode)
1200 if (cpu_is_at32ap7000()) {
1201 struct nand_chip *nand_chip = mtd->priv;
1202 struct atmel_nand_host *host = nand_chip->priv;
1203 ecc_writel(host->ecc, CR, ATMEL_ECC_RST);
1207 #if defined(CONFIG_OF)
1208 static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
1209 struct device_node *np)
1211 u32 val, table_offset;
1214 struct atmel_nand_data *board = &host->board;
1215 enum of_gpio_flags flags;
1217 if (of_property_read_u32(np, "atmel,nand-addr-offset", &val) == 0) {
1219 dev_err(host->dev, "invalid addr-offset %u\n", val);
1225 if (of_property_read_u32(np, "atmel,nand-cmd-offset", &val) == 0) {
1227 dev_err(host->dev, "invalid cmd-offset %u\n", val);
1233 ecc_mode = of_get_nand_ecc_mode(np);
1235 board->ecc_mode = ecc_mode < 0 ? NAND_ECC_SOFT : ecc_mode;
1237 board->on_flash_bbt = of_get_nand_on_flash_bbt(np);
1239 if (of_get_nand_bus_width(np) == 16)
1240 board->bus_width_16 = 1;
1242 board->rdy_pin = of_get_gpio_flags(np, 0, &flags);
1243 board->rdy_pin_active_low = (flags == OF_GPIO_ACTIVE_LOW);
1245 board->enable_pin = of_get_gpio(np, 1);
1246 board->det_pin = of_get_gpio(np, 2);
1248 host->has_pmecc = of_property_read_bool(np, "atmel,has-pmecc");
1250 if (!(board->ecc_mode == NAND_ECC_HW) || !host->has_pmecc)
1251 return 0; /* Not using PMECC */
1253 /* use PMECC, get correction capability, sector size and lookup
1256 if (of_property_read_u32(np, "atmel,pmecc-cap", &val) != 0) {
1257 dev_err(host->dev, "Cannot decide PMECC Capability\n");
1259 } else if ((val != 2) && (val != 4) && (val != 8) && (val != 12) &&
1262 "Unsupported PMECC correction capability: %d; should be 2, 4, 8, 12 or 24\n",
1266 host->pmecc_corr_cap = (u8)val;
1268 if (of_property_read_u32(np, "atmel,pmecc-sector-size", &val) != 0) {
1269 dev_err(host->dev, "Cannot decide PMECC Sector Size\n");
1271 } else if ((val != 512) && (val != 1024)) {
1273 "Unsupported PMECC sector size: %d; should be 512 or 1024 bytes\n",
1277 host->pmecc_sector_size = (u16)val;
1279 if (of_property_read_u32_array(np, "atmel,pmecc-lookup-table-offset",
1281 dev_err(host->dev, "Cannot get PMECC lookup table offset\n");
1284 table_offset = host->pmecc_sector_size == 512 ? offset[0] : offset[1];
1286 if (!table_offset) {
1287 dev_err(host->dev, "Invalid PMECC lookup table offset\n");
1290 host->pmecc_lookup_table_offset = table_offset;
1295 static int __devinit atmel_of_init_port(struct atmel_nand_host *host,
1296 struct device_node *np)
1302 static int __init atmel_hw_nand_init_params(struct platform_device *pdev,
1303 struct atmel_nand_host *host)
1305 struct mtd_info *mtd = &host->mtd;
1306 struct nand_chip *nand_chip = &host->nand_chip;
1307 struct resource *regs;
1309 regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
1312 "Can't get I/O resource regs, use software ECC\n");
1313 nand_chip->ecc.mode = NAND_ECC_SOFT;
1317 host->ecc = ioremap(regs->start, resource_size(regs));
1318 if (host->ecc == NULL) {
1319 dev_err(host->dev, "ioremap failed\n");
1323 /* ECC is calculated for the whole page (1 step) */
1324 nand_chip->ecc.size = mtd->writesize;
1326 /* set ECC page size and oob layout */
1327 switch (mtd->writesize) {
1329 nand_chip->ecc.layout = &atmel_oobinfo_small;
1330 ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_528);
1333 nand_chip->ecc.layout = &atmel_oobinfo_large;
1334 ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_1056);
1337 nand_chip->ecc.layout = &atmel_oobinfo_large;
1338 ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_2112);
1341 nand_chip->ecc.layout = &atmel_oobinfo_large;
1342 ecc_writel(host->ecc, MR, ATMEL_ECC_PAGESIZE_4224);
1345 /* page size not handled by HW ECC */
1346 /* switching back to soft ECC */
1347 nand_chip->ecc.mode = NAND_ECC_SOFT;
1351 /* set up for HW ECC */
1352 nand_chip->ecc.calculate = atmel_nand_calculate;
1353 nand_chip->ecc.correct = atmel_nand_correct;
1354 nand_chip->ecc.hwctl = atmel_nand_hwctl;
1355 nand_chip->ecc.read_page = atmel_nand_read_page;
1356 nand_chip->ecc.bytes = 4;
1357 nand_chip->ecc.strength = 1;
1363 * Probe for the NAND device.
1365 static int __init atmel_nand_probe(struct platform_device *pdev)
1367 struct atmel_nand_host *host;
1368 struct mtd_info *mtd;
1369 struct nand_chip *nand_chip;
1370 struct resource *mem;
1371 struct mtd_part_parser_data ppdata = {};
1374 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1376 printk(KERN_ERR "atmel_nand: can't get I/O resource mem\n");
1380 /* Allocate memory for the device structure (and zero it) */
1381 host = kzalloc(sizeof(struct atmel_nand_host), GFP_KERNEL);
1383 printk(KERN_ERR "atmel_nand: failed to allocate device structure.\n");
1387 host->io_phys = (dma_addr_t)mem->start;
1389 host->io_base = ioremap(mem->start, resource_size(mem));
1390 if (host->io_base == NULL) {
1391 printk(KERN_ERR "atmel_nand: ioremap failed\n");
1393 goto err_nand_ioremap;
1397 nand_chip = &host->nand_chip;
1398 host->dev = &pdev->dev;
1399 if (pdev->dev.of_node) {
1400 res = atmel_of_init_port(host, pdev->dev.of_node);
1402 goto err_ecc_ioremap;
1404 memcpy(&host->board, pdev->dev.platform_data,
1405 sizeof(struct atmel_nand_data));
1408 nand_chip->priv = host; /* link the private data structures */
1409 mtd->priv = nand_chip;
1410 mtd->owner = THIS_MODULE;
1412 /* Set address of NAND IO lines */
1413 nand_chip->IO_ADDR_R = host->io_base;
1414 nand_chip->IO_ADDR_W = host->io_base;
1415 nand_chip->cmd_ctrl = atmel_nand_cmd_ctrl;
1417 if (gpio_is_valid(host->board.rdy_pin)) {
1418 res = gpio_request(host->board.rdy_pin, "nand_rdy");
1421 "can't request rdy gpio %d\n",
1422 host->board.rdy_pin);
1423 goto err_ecc_ioremap;
1426 res = gpio_direction_input(host->board.rdy_pin);
1429 "can't request input direction rdy gpio %d\n",
1430 host->board.rdy_pin);
1431 goto err_ecc_ioremap;
1434 nand_chip->dev_ready = atmel_nand_device_ready;
1437 if (gpio_is_valid(host->board.enable_pin)) {
1438 res = gpio_request(host->board.enable_pin, "nand_enable");
1441 "can't request enable gpio %d\n",
1442 host->board.enable_pin);
1443 goto err_ecc_ioremap;
1446 res = gpio_direction_output(host->board.enable_pin, 1);
1449 "can't request output direction enable gpio %d\n",
1450 host->board.enable_pin);
1451 goto err_ecc_ioremap;
1455 nand_chip->ecc.mode = host->board.ecc_mode;
1456 nand_chip->chip_delay = 20; /* 20us command delay time */
1458 if (host->board.bus_width_16) /* 16-bit bus width */
1459 nand_chip->options |= NAND_BUSWIDTH_16;
1461 nand_chip->read_buf = atmel_read_buf;
1462 nand_chip->write_buf = atmel_write_buf;
1464 platform_set_drvdata(pdev, host);
1465 atmel_nand_enable(host);
1467 if (gpio_is_valid(host->board.det_pin)) {
1468 res = gpio_request(host->board.det_pin, "nand_det");
1471 "can't request det gpio %d\n",
1472 host->board.det_pin);
1476 res = gpio_direction_input(host->board.det_pin);
1479 "can't request input direction det gpio %d\n",
1480 host->board.det_pin);
1484 if (gpio_get_value(host->board.det_pin)) {
1485 printk(KERN_INFO "No SmartMedia card inserted.\n");
1491 if (host->board.on_flash_bbt || on_flash_bbt) {
1492 printk(KERN_INFO "atmel_nand: Use On Flash BBT\n");
1493 nand_chip->bbt_options |= NAND_BBT_USE_FLASH;
1500 dma_cap_mask_t mask;
1503 dma_cap_set(DMA_MEMCPY, mask);
1504 host->dma_chan = dma_request_channel(mask, NULL, NULL);
1505 if (!host->dma_chan) {
1506 dev_err(host->dev, "Failed to request DMA channel\n");
1511 dev_info(host->dev, "Using %s for DMA transfers.\n",
1512 dma_chan_name(host->dma_chan));
1514 dev_info(host->dev, "No DMA support for NAND access.\n");
1516 /* first scan to find the device and get the page size */
1517 if (nand_scan_ident(mtd, 1, NULL)) {
1519 goto err_scan_ident;
1522 if (nand_chip->ecc.mode == NAND_ECC_HW) {
1523 if (host->has_pmecc)
1524 res = atmel_pmecc_nand_init_params(pdev, host);
1526 res = atmel_hw_nand_init_params(pdev, host);
1532 /* second phase scan */
1533 if (nand_scan_tail(mtd)) {
1538 mtd->name = "atmel_nand";
1539 ppdata.of_node = pdev->dev.of_node;
1540 res = mtd_device_parse_register(mtd, NULL, &ppdata,
1541 host->board.parts, host->board.num_parts);
1546 if (host->has_pmecc && host->nand_chip.ecc.mode == NAND_ECC_HW) {
1547 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
1548 pmecc_data_free(host);
1552 if (host->pmerrloc_base)
1553 iounmap(host->pmerrloc_base);
1554 if (host->pmecc_rom_base)
1555 iounmap(host->pmecc_rom_base);
1559 atmel_nand_disable(host);
1560 platform_set_drvdata(pdev, NULL);
1562 dma_release_channel(host->dma_chan);
1564 iounmap(host->io_base);
1571 * Remove a NAND device.
1573 static int __exit atmel_nand_remove(struct platform_device *pdev)
1575 struct atmel_nand_host *host = platform_get_drvdata(pdev);
1576 struct mtd_info *mtd = &host->mtd;
1580 atmel_nand_disable(host);
1582 if (host->has_pmecc && host->nand_chip.ecc.mode == NAND_ECC_HW) {
1583 pmecc_writel(host->ecc, CTRL, PMECC_CTRL_DISABLE);
1584 pmerrloc_writel(host->pmerrloc_base, ELDIS,
1586 pmecc_data_free(host);
1589 if (gpio_is_valid(host->board.det_pin))
1590 gpio_free(host->board.det_pin);
1592 if (gpio_is_valid(host->board.enable_pin))
1593 gpio_free(host->board.enable_pin);
1595 if (gpio_is_valid(host->board.rdy_pin))
1596 gpio_free(host->board.rdy_pin);
1600 if (host->pmecc_rom_base)
1601 iounmap(host->pmecc_rom_base);
1602 if (host->pmerrloc_base)
1603 iounmap(host->pmerrloc_base);
1606 dma_release_channel(host->dma_chan);
1608 iounmap(host->io_base);
1614 #if defined(CONFIG_OF)
1615 static const struct of_device_id atmel_nand_dt_ids[] = {
1616 { .compatible = "atmel,at91rm9200-nand" },
1620 MODULE_DEVICE_TABLE(of, atmel_nand_dt_ids);
1623 static struct platform_driver atmel_nand_driver = {
1624 .remove = __exit_p(atmel_nand_remove),
1626 .name = "atmel_nand",
1627 .owner = THIS_MODULE,
1628 .of_match_table = of_match_ptr(atmel_nand_dt_ids),
1632 static int __init atmel_nand_init(void)
1634 return platform_driver_probe(&atmel_nand_driver, atmel_nand_probe);
1638 static void __exit atmel_nand_exit(void)
1640 platform_driver_unregister(&atmel_nand_driver);
1644 module_init(atmel_nand_init);
1645 module_exit(atmel_nand_exit);
1647 MODULE_LICENSE("GPL");
1648 MODULE_AUTHOR("Rick Bronson");
1649 MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91 / AVR32");
1650 MODULE_ALIAS("platform:atmel_nand");