blob: cff969d05d4a1824cb18fda1808f89a9f9700000 [file] [log] [blame]
David Woodhousec9ac5972006-11-30 08:17:38 +00001/*
David Woodhousefbad5692006-10-22 15:09:33 +01002 * Driver for One Laptop Per Child ‘CAFÉ’ controller, aka Marvell 88ALP01
David Woodhouse5467fb02006-10-06 15:36:29 +01003 *
4 * Copyright © 2006 Red Hat, Inc.
5 * Copyright © 2006 David Woodhouse <dwmw2@infradead.org>
6 */
7
David Woodhouse8dd851d2006-10-20 02:11:40 +01008#define DEBUG
David Woodhouse5467fb02006-10-06 15:36:29 +01009
10#include <linux/device.h>
11#undef DEBUG
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/nand.h>
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +020014#include <linux/rslib.h>
David Woodhouse5467fb02006-10-06 15:36:29 +010015#include <linux/pci.h>
16#include <linux/delay.h>
17#include <linux/interrupt.h>
Al Viroa1274302007-01-30 13:23:30 +000018#include <linux/dma-mapping.h>
David Woodhouse5467fb02006-10-06 15:36:29 +010019#include <asm/io.h>
20
21#define CAFE_NAND_CTRL1 0x00
22#define CAFE_NAND_CTRL2 0x04
23#define CAFE_NAND_CTRL3 0x08
24#define CAFE_NAND_STATUS 0x0c
25#define CAFE_NAND_IRQ 0x10
26#define CAFE_NAND_IRQ_MASK 0x14
27#define CAFE_NAND_DATA_LEN 0x18
28#define CAFE_NAND_ADDR1 0x1c
29#define CAFE_NAND_ADDR2 0x20
30#define CAFE_NAND_TIMING1 0x24
31#define CAFE_NAND_TIMING2 0x28
32#define CAFE_NAND_TIMING3 0x2c
33#define CAFE_NAND_NONMEM 0x30
David Woodhouse04459d72006-10-22 02:18:48 +010034#define CAFE_NAND_ECC_RESULT 0x3C
David Woodhousefbad5692006-10-22 15:09:33 +010035#define CAFE_NAND_DMA_CTRL 0x40
36#define CAFE_NAND_DMA_ADDR0 0x44
37#define CAFE_NAND_DMA_ADDR1 0x48
David Woodhouse04459d72006-10-22 02:18:48 +010038#define CAFE_NAND_ECC_SYN01 0x50
39#define CAFE_NAND_ECC_SYN23 0x54
40#define CAFE_NAND_ECC_SYN45 0x58
41#define CAFE_NAND_ECC_SYN67 0x5c
David Woodhouse5467fb02006-10-06 15:36:29 +010042#define CAFE_NAND_READ_DATA 0x1000
43#define CAFE_NAND_WRITE_DATA 0x2000
44
David Woodhouse195a2532006-10-31 12:30:11 +080045#define CAFE_GLOBAL_CTRL 0x3004
46#define CAFE_GLOBAL_IRQ 0x3008
47#define CAFE_GLOBAL_IRQ_MASK 0x300c
48#define CAFE_NAND_RESET 0x3034
49
David Woodhouse048c37b2007-05-02 12:26:37 +010050/* Missing from the datasheet: bit 19 of CTRL1 sets CE0 vs. CE1 */
51#define CTRL1_CHIPSELECT (1<<19)
52
David Woodhouse5467fb02006-10-06 15:36:29 +010053struct cafe_priv {
54 struct nand_chip nand;
55 struct pci_dev *pdev;
56 void __iomem *mmio;
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +020057 struct rs_control *rs;
David Woodhouse5467fb02006-10-06 15:36:29 +010058 uint32_t ctl1;
59 uint32_t ctl2;
60 int datalen;
61 int nr_data;
62 int data_pos;
63 int page_addr;
64 dma_addr_t dmaaddr;
65 unsigned char *dmabuf;
David Woodhouse5467fb02006-10-06 15:36:29 +010066};
67
David Woodhouseb478c772006-10-27 14:50:04 +030068static int usedma = 1;
David Woodhouse5467fb02006-10-06 15:36:29 +010069module_param(usedma, int, 0644);
70
David Woodhouse8dd851d2006-10-20 02:11:40 +010071static int skipbbt = 0;
72module_param(skipbbt, int, 0644);
73
74static int debug = 0;
75module_param(debug, int, 0644);
76
David Woodhousebe8444b2006-10-31 12:36:04 +080077static int regdebug = 0;
78module_param(regdebug, int, 0644);
79
David Woodhouseb478c772006-10-27 14:50:04 +030080static int checkecc = 1;
David Woodhouse470b0a92006-10-23 14:29:04 +010081module_param(checkecc, int, 0644);
82
David Woodhouse527a4f42007-01-23 15:35:27 +080083static int numtimings;
84static int timing[3];
85module_param_array(timing, int, &numtimings, 0644);
David Woodhouseb478c772006-10-27 14:50:04 +030086
David Woodhouse04459d72006-10-22 02:18:48 +010087/* Hrm. Why isn't this already conditional on something in the struct device? */
David Woodhouse8dd851d2006-10-20 02:11:40 +010088#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
89
David Woodhouse195a2532006-10-31 12:30:11 +080090/* Make it easier to switch to PIO if we need to */
91#define cafe_readl(cafe, addr) readl((cafe)->mmio + CAFE_##addr)
92#define cafe_writel(cafe, datum, addr) writel(datum, (cafe)->mmio + CAFE_##addr)
David Woodhouse8dd851d2006-10-20 02:11:40 +010093
David Woodhouse5467fb02006-10-06 15:36:29 +010094static int cafe_device_ready(struct mtd_info *mtd)
95{
96 struct cafe_priv *cafe = mtd->priv;
David Woodhouse195a2532006-10-31 12:30:11 +080097 int result = !!(cafe_readl(cafe, NAND_STATUS) | 0x40000000);
98 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
David Woodhousefbad5692006-10-22 15:09:33 +010099
David Woodhouse195a2532006-10-31 12:30:11 +0800100 cafe_writel(cafe, irqs, NAND_IRQ);
David Woodhousefbad5692006-10-22 15:09:33 +0100101
David Woodhouse8dd851d2006-10-20 02:11:40 +0100102 cafe_dev_dbg(&cafe->pdev->dev, "NAND device is%s ready, IRQ %x (%x) (%x,%x)\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800103 result?"":" not", irqs, cafe_readl(cafe, NAND_IRQ),
104 cafe_readl(cafe, GLOBAL_IRQ), cafe_readl(cafe, GLOBAL_IRQ_MASK));
David Woodhousefbad5692006-10-22 15:09:33 +0100105
David Woodhouse5467fb02006-10-06 15:36:29 +0100106 return result;
107}
108
109
110static void cafe_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
111{
112 struct cafe_priv *cafe = mtd->priv;
113
114 if (usedma)
115 memcpy(cafe->dmabuf + cafe->datalen, buf, len);
116 else
117 memcpy_toio(cafe->mmio + CAFE_NAND_WRITE_DATA + cafe->datalen, buf, len);
David Woodhousefbad5692006-10-22 15:09:33 +0100118
David Woodhouse5467fb02006-10-06 15:36:29 +0100119 cafe->datalen += len;
120
David Woodhouse8dd851d2006-10-20 02:11:40 +0100121 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes to write buffer. datalen 0x%x\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100122 len, cafe->datalen);
123}
124
125static void cafe_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
126{
127 struct cafe_priv *cafe = mtd->priv;
128
129 if (usedma)
130 memcpy(buf, cafe->dmabuf + cafe->datalen, len);
131 else
132 memcpy_fromio(buf, cafe->mmio + CAFE_NAND_READ_DATA + cafe->datalen, len);
133
David Woodhouse8dd851d2006-10-20 02:11:40 +0100134 cafe_dev_dbg(&cafe->pdev->dev, "Copy 0x%x bytes from position 0x%x in read buffer.\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100135 len, cafe->datalen);
136 cafe->datalen += len;
137}
138
139static uint8_t cafe_read_byte(struct mtd_info *mtd)
140{
141 struct cafe_priv *cafe = mtd->priv;
142 uint8_t d;
143
144 cafe_read_buf(mtd, &d, 1);
David Woodhouse8dd851d2006-10-20 02:11:40 +0100145 cafe_dev_dbg(&cafe->pdev->dev, "Read %02x\n", d);
David Woodhouse5467fb02006-10-06 15:36:29 +0100146
147 return d;
148}
149
150static void cafe_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
151 int column, int page_addr)
152{
153 struct cafe_priv *cafe = mtd->priv;
154 int adrbytes = 0;
155 uint32_t ctl1;
156 uint32_t doneint = 0x80000000;
David Woodhouse5467fb02006-10-06 15:36:29 +0100157
David Woodhouse8dd851d2006-10-20 02:11:40 +0100158 cafe_dev_dbg(&cafe->pdev->dev, "cmdfunc %02x, 0x%x, 0x%x\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100159 command, column, page_addr);
160
161 if (command == NAND_CMD_ERASE2 || command == NAND_CMD_PAGEPROG) {
162 /* Second half of a command we already calculated */
David Woodhouse195a2532006-10-31 12:30:11 +0800163 cafe_writel(cafe, cafe->ctl2 | 0x100 | command, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100164 ctl1 = cafe->ctl1;
David Woodhousecad40652006-11-01 08:19:20 +0800165 cafe->ctl2 &= ~(1<<30);
David Woodhouse8dd851d2006-10-20 02:11:40 +0100166 cafe_dev_dbg(&cafe->pdev->dev, "Continue command, ctl1 %08x, #data %d\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100167 cafe->ctl1, cafe->nr_data);
168 goto do_command;
169 }
170 /* Reset ECC engine */
David Woodhouse195a2532006-10-31 12:30:11 +0800171 cafe_writel(cafe, 0, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100172
173 /* Emulate NAND_CMD_READOOB on large-page chips */
174 if (mtd->writesize > 512 &&
175 command == NAND_CMD_READOOB) {
176 column += mtd->writesize;
177 command = NAND_CMD_READ0;
178 }
179
180 /* FIXME: Do we need to send read command before sending data
181 for small-page chips, to position the buffer correctly? */
182
183 if (column != -1) {
David Woodhouse195a2532006-10-31 12:30:11 +0800184 cafe_writel(cafe, column, NAND_ADDR1);
David Woodhouse5467fb02006-10-06 15:36:29 +0100185 adrbytes = 2;
186 if (page_addr != -1)
187 goto write_adr2;
188 } else if (page_addr != -1) {
David Woodhouse195a2532006-10-31 12:30:11 +0800189 cafe_writel(cafe, page_addr & 0xffff, NAND_ADDR1);
David Woodhouse5467fb02006-10-06 15:36:29 +0100190 page_addr >>= 16;
191 write_adr2:
David Woodhouse195a2532006-10-31 12:30:11 +0800192 cafe_writel(cafe, page_addr, NAND_ADDR2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100193 adrbytes += 2;
194 if (mtd->size > mtd->writesize << 16)
195 adrbytes++;
196 }
197
198 cafe->data_pos = cafe->datalen = 0;
199
David Woodhouse048c37b2007-05-02 12:26:37 +0100200 /* Set command valid bit, mask in the chip select bit */
201 ctl1 = 0x80000000 | command | (cafe->ctl1 & CTRL1_CHIPSELECT);
David Woodhouse5467fb02006-10-06 15:36:29 +0100202
203 /* Set RD or WR bits as appropriate */
204 if (command == NAND_CMD_READID || command == NAND_CMD_STATUS) {
205 ctl1 |= (1<<26); /* rd */
206 /* Always 5 bytes, for now */
David Woodhouse8dd851d2006-10-20 02:11:40 +0100207 cafe->datalen = 4;
David Woodhouse5467fb02006-10-06 15:36:29 +0100208 /* And one address cycle -- even for STATUS, since the controller doesn't work without */
209 adrbytes = 1;
210 } else if (command == NAND_CMD_READ0 || command == NAND_CMD_READ1 ||
211 command == NAND_CMD_READOOB || command == NAND_CMD_RNDOUT) {
212 ctl1 |= 1<<26; /* rd */
213 /* For now, assume just read to end of page */
214 cafe->datalen = mtd->writesize + mtd->oobsize - column;
215 } else if (command == NAND_CMD_SEQIN)
216 ctl1 |= 1<<25; /* wr */
217
218 /* Set number of address bytes */
219 if (adrbytes)
220 ctl1 |= ((adrbytes-1)|8) << 27;
221
222 if (command == NAND_CMD_SEQIN || command == NAND_CMD_ERASE1) {
David Woodhousec9ac5972006-11-30 08:17:38 +0000223 /* Ignore the first command of a pair; the hardware
David Woodhouse5467fb02006-10-06 15:36:29 +0100224 deals with them both at once, later */
225 cafe->ctl1 = ctl1;
David Woodhouse8dd851d2006-10-20 02:11:40 +0100226 cafe_dev_dbg(&cafe->pdev->dev, "Setup for delayed command, ctl1 %08x, dlen %x\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100227 cafe->ctl1, cafe->datalen);
228 return;
229 }
230 /* RNDOUT and READ0 commands need a following byte */
231 if (command == NAND_CMD_RNDOUT)
David Woodhouse195a2532006-10-31 12:30:11 +0800232 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_RNDOUTSTART, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100233 else if (command == NAND_CMD_READ0 && mtd->writesize > 512)
David Woodhouse195a2532006-10-31 12:30:11 +0800234 cafe_writel(cafe, cafe->ctl2 | 0x100 | NAND_CMD_READSTART, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100235
236 do_command:
David Woodhousec9ac5972006-11-30 08:17:38 +0000237 cafe_dev_dbg(&cafe->pdev->dev, "dlen %x, ctl1 %x, ctl2 %x\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800238 cafe->datalen, ctl1, cafe_readl(cafe, NAND_CTRL2));
David Woodhousefbad5692006-10-22 15:09:33 +0100239
David Woodhouse5467fb02006-10-06 15:36:29 +0100240 /* NB: The datasheet lies -- we really should be subtracting 1 here */
David Woodhouse195a2532006-10-31 12:30:11 +0800241 cafe_writel(cafe, cafe->datalen, NAND_DATA_LEN);
242 cafe_writel(cafe, 0x90000000, NAND_IRQ);
David Woodhouse5467fb02006-10-06 15:36:29 +0100243 if (usedma && (ctl1 & (3<<25))) {
244 uint32_t dmactl = 0xc0000000 + cafe->datalen;
245 /* If WR or RD bits set, set up DMA */
246 if (ctl1 & (1<<26)) {
247 /* It's a read */
248 dmactl |= (1<<29);
249 /* ... so it's done when the DMA is done, not just
250 the command. */
251 doneint = 0x10000000;
252 }
David Woodhouse195a2532006-10-31 12:30:11 +0800253 cafe_writel(cafe, dmactl, NAND_DMA_CTRL);
David Woodhouse5467fb02006-10-06 15:36:29 +0100254 }
David Woodhouse5467fb02006-10-06 15:36:29 +0100255 cafe->datalen = 0;
256
David Woodhousebe8444b2006-10-31 12:36:04 +0800257 if (unlikely(regdebug)) {
258 int i;
259 printk("About to write command %08x to register 0\n", ctl1);
260 for (i=4; i< 0x5c; i+=4)
261 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
David Woodhousefbad5692006-10-22 15:09:33 +0100262 }
David Woodhousebe8444b2006-10-31 12:36:04 +0800263
David Woodhouse195a2532006-10-31 12:30:11 +0800264 cafe_writel(cafe, ctl1, NAND_CTRL1);
David Woodhouse5467fb02006-10-06 15:36:29 +0100265 /* Apply this short delay always to ensure that we do wait tWB in
266 * any case on any machine. */
267 ndelay(100);
268
269 if (1) {
Andrew Morton2a7295b22007-02-17 16:02:11 -0800270 int c;
David Woodhouse5467fb02006-10-06 15:36:29 +0100271 uint32_t irqs;
272
Andrew Morton2a7295b22007-02-17 16:02:11 -0800273 for (c = 500000; c != 0; c--) {
David Woodhouse195a2532006-10-31 12:30:11 +0800274 irqs = cafe_readl(cafe, NAND_IRQ);
David Woodhouse5467fb02006-10-06 15:36:29 +0100275 if (irqs & doneint)
276 break;
277 udelay(1);
David Woodhouse8dd851d2006-10-20 02:11:40 +0100278 if (!(c % 100000))
279 cafe_dev_dbg(&cafe->pdev->dev, "Wait for ready, IRQ %x\n", irqs);
David Woodhouse5467fb02006-10-06 15:36:29 +0100280 cpu_relax();
281 }
David Woodhouse195a2532006-10-31 12:30:11 +0800282 cafe_writel(cafe, doneint, NAND_IRQ);
David Woodhousea0207272006-10-28 17:08:38 +0300283 cafe_dev_dbg(&cafe->pdev->dev, "Command %x completed after %d usec, irqs %x (%x)\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800284 command, 500000-c, irqs, cafe_readl(cafe, NAND_IRQ));
David Woodhouse5467fb02006-10-06 15:36:29 +0100285 }
286
David Woodhousecad40652006-11-01 08:19:20 +0800287 WARN_ON(cafe->ctl2 & (1<<30));
David Woodhouse5467fb02006-10-06 15:36:29 +0100288
289 switch (command) {
290
291 case NAND_CMD_CACHEDPROG:
292 case NAND_CMD_PAGEPROG:
293 case NAND_CMD_ERASE1:
294 case NAND_CMD_ERASE2:
295 case NAND_CMD_SEQIN:
296 case NAND_CMD_RNDIN:
297 case NAND_CMD_STATUS:
298 case NAND_CMD_DEPLETE1:
299 case NAND_CMD_RNDOUT:
300 case NAND_CMD_STATUS_ERROR:
301 case NAND_CMD_STATUS_ERROR0:
302 case NAND_CMD_STATUS_ERROR1:
303 case NAND_CMD_STATUS_ERROR2:
304 case NAND_CMD_STATUS_ERROR3:
David Woodhouse195a2532006-10-31 12:30:11 +0800305 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100306 return;
307 }
308 nand_wait_ready(mtd);
David Woodhouse195a2532006-10-31 12:30:11 +0800309 cafe_writel(cafe, cafe->ctl2, NAND_CTRL2);
David Woodhouse5467fb02006-10-06 15:36:29 +0100310}
311
312static void cafe_select_chip(struct mtd_info *mtd, int chipnr)
313{
David Woodhouse048c37b2007-05-02 12:26:37 +0100314 struct cafe_priv *cafe = mtd->priv;
315
316 cafe_dev_dbg(&cafe->pdev->dev, "select_chip %d\n", chipnr);
317
318 /* Mask the appropriate bit into the stored value of ctl1
319 which will be used by cafe_nand_cmdfunc() */
320 if (chipnr)
321 cafe->ctl1 |= CTRL1_CHIPSELECT;
322 else
323 cafe->ctl1 &= ~CTRL1_CHIPSELECT;
David Woodhouse5467fb02006-10-06 15:36:29 +0100324}
David Woodhousefbad5692006-10-22 15:09:33 +0100325
David Woodhouse28bdd4a2006-11-29 00:04:59 +0000326static int cafe_nand_interrupt(int irq, void *id)
David Woodhouse5467fb02006-10-06 15:36:29 +0100327{
328 struct mtd_info *mtd = id;
329 struct cafe_priv *cafe = mtd->priv;
David Woodhouse195a2532006-10-31 12:30:11 +0800330 uint32_t irqs = cafe_readl(cafe, NAND_IRQ);
331 cafe_writel(cafe, irqs & ~0x90000000, NAND_IRQ);
David Woodhouse5467fb02006-10-06 15:36:29 +0100332 if (!irqs)
333 return IRQ_NONE;
334
David Woodhouse195a2532006-10-31 12:30:11 +0800335 cafe_dev_dbg(&cafe->pdev->dev, "irq, bits %x (%x)\n", irqs, cafe_readl(cafe, NAND_IRQ));
David Woodhouse5467fb02006-10-06 15:36:29 +0100336 return IRQ_HANDLED;
337}
338
339static void cafe_nand_bug(struct mtd_info *mtd)
340{
341 BUG();
342}
343
344static int cafe_nand_write_oob(struct mtd_info *mtd,
345 struct nand_chip *chip, int page)
346{
347 int status = 0;
348
David Woodhouse5467fb02006-10-06 15:36:29 +0100349 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page);
350 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
351 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
352 status = chip->waitfunc(mtd, chip);
353
354 return status & NAND_STATUS_FAIL ? -EIO : 0;
355}
356
357/* Don't use -- use nand_read_oob_std for now */
358static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
359 int page, int sndcmd)
360{
361 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
362 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
363 return 1;
364}
365/**
366 * cafe_nand_read_page_syndrome - {REPLACABLE] hardware ecc syndrom based page read
367 * @mtd: mtd info structure
368 * @chip: nand chip info structure
369 * @buf: buffer to store read data
370 *
371 * The hw generator calculates the error syndrome automatically. Therefor
372 * we need a special oob layout and handling.
373 */
374static int cafe_nand_read_page(struct mtd_info *mtd, struct nand_chip *chip,
375 uint8_t *buf)
376{
377 struct cafe_priv *cafe = mtd->priv;
378
David Woodhousefbad5692006-10-22 15:09:33 +0100379 cafe_dev_dbg(&cafe->pdev->dev, "ECC result %08x SYN1,2 %08x\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800380 cafe_readl(cafe, NAND_ECC_RESULT),
381 cafe_readl(cafe, NAND_ECC_SYN01));
David Woodhouse5467fb02006-10-06 15:36:29 +0100382
383 chip->read_buf(mtd, buf, mtd->writesize);
384 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
385
David Woodhouse195a2532006-10-31 12:30:11 +0800386 if (checkecc && cafe_readl(cafe, NAND_ECC_RESULT) & (1<<18)) {
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200387 unsigned short syn[8], pat[4];
388 int pos[4];
389 u8 *oob = chip->oob_poi;
390 int i, n;
David Woodhouse04459d72006-10-22 02:18:48 +0100391
392 for (i=0; i<8; i+=2) {
David Woodhouse195a2532006-10-31 12:30:11 +0800393 uint32_t tmp = cafe_readl(cafe, NAND_ECC_SYN01 + (i*2));
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200394 syn[i] = cafe->rs->index_of[tmp & 0xfff];
395 syn[i+1] = cafe->rs->index_of[(tmp >> 16) & 0xfff];
David Woodhousec9ac5972006-11-30 08:17:38 +0000396 }
David Woodhouse04459d72006-10-22 02:18:48 +0100397
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200398 n = decode_rs16(cafe->rs, NULL, NULL, 1367, syn, 0, pos, 0,
399 pat);
400
401 for (i = 0; i < n; i++) {
402 int p = pos[i];
403
404 /* The 12-bit symbols are mapped to bytes here */
405
406 if (p > 1374) {
407 /* out of range */
408 n = -1374;
409 } else if (p == 0) {
410 /* high four bits do not correspond to data */
411 if (pat[i] > 0xff)
412 n = -2048;
413 else
414 buf[0] ^= pat[i];
415 } else if (p == 1365) {
416 buf[2047] ^= pat[i] >> 4;
417 oob[0] ^= pat[i] << 4;
418 } else if (p > 1365) {
419 if ((p & 1) == 1) {
420 oob[3*p/2 - 2048] ^= pat[i] >> 4;
421 oob[3*p/2 - 2047] ^= pat[i] << 4;
422 } else {
423 oob[3*p/2 - 2049] ^= pat[i] >> 8;
424 oob[3*p/2 - 2048] ^= pat[i];
425 }
426 } else if ((p & 1) == 1) {
427 buf[3*p/2] ^= pat[i] >> 4;
428 buf[3*p/2 + 1] ^= pat[i] << 4;
429 } else {
430 buf[3*p/2 - 1] ^= pat[i] >> 8;
431 buf[3*p/2] ^= pat[i];
432 }
433 }
434
435 if (n < 0) {
David Woodhousebe8444b2006-10-31 12:36:04 +0800436 dev_dbg(&cafe->pdev->dev, "Failed to correct ECC at %08x\n",
437 cafe_readl(cafe, NAND_ADDR2) * 2048);
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200438 for (i = 0; i < 0x5c; i += 4)
David Woodhousebe8444b2006-10-31 12:36:04 +0800439 printk("Register %x: %08x\n", i, readl(cafe->mmio + i));
David Woodhouse04459d72006-10-22 02:18:48 +0100440 mtd->ecc_stats.failed++;
441 } else {
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200442 dev_dbg(&cafe->pdev->dev, "Corrected %d symbol errors\n", n);
443 mtd->ecc_stats.corrected += n;
David Woodhouse04459d72006-10-22 02:18:48 +0100444 }
445 }
446
David Woodhouse5467fb02006-10-06 15:36:29 +0100447 return 0;
448}
449
David Woodhouse8dd851d2006-10-20 02:11:40 +0100450static struct nand_ecclayout cafe_oobinfo_2048 = {
451 .eccbytes = 14,
452 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
453 .oobfree = {{14, 50}}
454};
455
David Woodhousec9ac5972006-11-30 08:17:38 +0000456/* Ick. The BBT code really ought to be able to work this bit out
David Woodhousefbad5692006-10-22 15:09:33 +0100457 for itself from the above, at least for the 2KiB case */
458static uint8_t cafe_bbt_pattern_2048[] = { 'B', 'b', 't', '0' };
459static uint8_t cafe_mirror_pattern_2048[] = { '1', 't', 'b', 'B' };
460
461static uint8_t cafe_bbt_pattern_512[] = { 0xBB };
462static uint8_t cafe_mirror_pattern_512[] = { 0xBC };
463
David Woodhouse8dd851d2006-10-20 02:11:40 +0100464
465static struct nand_bbt_descr cafe_bbt_main_descr_2048 = {
466 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
David Woodhouse048c37b2007-05-02 12:26:37 +0100467 | NAND_BBT_2BIT | NAND_BBT_VERSION,
David Woodhouse8dd851d2006-10-20 02:11:40 +0100468 .offs = 14,
469 .len = 4,
470 .veroffs = 18,
471 .maxblocks = 4,
David Woodhousefbad5692006-10-22 15:09:33 +0100472 .pattern = cafe_bbt_pattern_2048
David Woodhouse8dd851d2006-10-20 02:11:40 +0100473};
474
475static struct nand_bbt_descr cafe_bbt_mirror_descr_2048 = {
476 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
David Woodhouse048c37b2007-05-02 12:26:37 +0100477 | NAND_BBT_2BIT | NAND_BBT_VERSION,
David Woodhouse8dd851d2006-10-20 02:11:40 +0100478 .offs = 14,
479 .len = 4,
480 .veroffs = 18,
481 .maxblocks = 4,
David Woodhousefbad5692006-10-22 15:09:33 +0100482 .pattern = cafe_mirror_pattern_2048
David Woodhouse8dd851d2006-10-20 02:11:40 +0100483};
484
485static struct nand_ecclayout cafe_oobinfo_512 = {
486 .eccbytes = 14,
487 .eccpos = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13},
488 .oobfree = {{14, 2}}
489};
490
David Woodhousefbad5692006-10-22 15:09:33 +0100491static struct nand_bbt_descr cafe_bbt_main_descr_512 = {
492 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
David Woodhouse048c37b2007-05-02 12:26:37 +0100493 | NAND_BBT_2BIT | NAND_BBT_VERSION,
David Woodhousefbad5692006-10-22 15:09:33 +0100494 .offs = 14,
495 .len = 1,
496 .veroffs = 15,
497 .maxblocks = 4,
498 .pattern = cafe_bbt_pattern_512
499};
500
501static struct nand_bbt_descr cafe_bbt_mirror_descr_512 = {
502 .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE
David Woodhouse048c37b2007-05-02 12:26:37 +0100503 | NAND_BBT_2BIT | NAND_BBT_VERSION,
David Woodhousefbad5692006-10-22 15:09:33 +0100504 .offs = 14,
505 .len = 1,
506 .veroffs = 15,
507 .maxblocks = 4,
508 .pattern = cafe_mirror_pattern_512
509};
510
511
David Woodhouse5467fb02006-10-06 15:36:29 +0100512static void cafe_nand_write_page_lowlevel(struct mtd_info *mtd,
513 struct nand_chip *chip, const uint8_t *buf)
514{
515 struct cafe_priv *cafe = mtd->priv;
516
David Woodhouse5467fb02006-10-06 15:36:29 +0100517 chip->write_buf(mtd, buf, mtd->writesize);
David Woodhouse8dd851d2006-10-20 02:11:40 +0100518 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
David Woodhouse5467fb02006-10-06 15:36:29 +0100519
520 /* Set up ECC autogeneration */
David Woodhousecad40652006-11-01 08:19:20 +0800521 cafe->ctl2 |= (1<<30);
David Woodhouse5467fb02006-10-06 15:36:29 +0100522}
523
524static int cafe_nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,
525 const uint8_t *buf, int page, int cached, int raw)
526{
527 int status;
528
David Woodhouse5467fb02006-10-06 15:36:29 +0100529 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
530
531 if (unlikely(raw))
532 chip->ecc.write_page_raw(mtd, chip, buf);
533 else
534 chip->ecc.write_page(mtd, chip, buf);
535
536 /*
537 * Cached progamming disabled for now, Not sure if its worth the
538 * trouble. The speed gain is not very impressive. (2.3->2.6Mib/s)
539 */
540 cached = 0;
541
542 if (!cached || !(chip->options & NAND_CACHEPRG)) {
543
544 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
545 status = chip->waitfunc(mtd, chip);
546 /*
547 * See if operation failed and additional status checks are
548 * available
549 */
550 if ((status & NAND_STATUS_FAIL) && (chip->errstat))
551 status = chip->errstat(mtd, chip, FL_WRITING, status,
552 page);
553
554 if (status & NAND_STATUS_FAIL)
555 return -EIO;
556 } else {
557 chip->cmdfunc(mtd, NAND_CMD_CACHEDPROG, -1, -1);
558 status = chip->waitfunc(mtd, chip);
559 }
560
561#ifdef CONFIG_MTD_NAND_VERIFY_WRITE
562 /* Send command to read back the data */
563 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
564
565 if (chip->verify_buf(mtd, buf, mtd->writesize))
566 return -EIO;
567#endif
568 return 0;
569}
570
David Woodhouse8dd851d2006-10-20 02:11:40 +0100571static int cafe_nand_block_bad(struct mtd_info *mtd, loff_t ofs, int getchip)
572{
573 return 0;
574}
David Woodhouse5467fb02006-10-06 15:36:29 +0100575
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200576/* F_2[X]/(X**6+X+1) */
577static unsigned short __devinit gf64_mul(u8 a, u8 b)
578{
579 u8 c;
580 unsigned int i;
581
582 c = 0;
583 for (i = 0; i < 6; i++) {
584 if (a & 1)
585 c ^= b;
586 a >>= 1;
587 b <<= 1;
588 if ((b & 0x40) != 0)
589 b ^= 0x43;
590 }
591
592 return c;
593}
594
595/* F_64[X]/(X**2+X+A**-1) with A the generator of F_64[X] */
596static u16 __devinit gf4096_mul(u16 a, u16 b)
597{
598 u8 ah, al, bh, bl, ch, cl;
599
600 ah = a >> 6;
601 al = a & 0x3f;
602 bh = b >> 6;
603 bl = b & 0x3f;
604
605 ch = gf64_mul(ah ^ al, bh ^ bl) ^ gf64_mul(al, bl);
606 cl = gf64_mul(gf64_mul(ah, bh), 0x21) ^ gf64_mul(al, bl);
607
608 return (ch << 6) ^ cl;
609}
610
611static int __devinit cafe_mul(int x)
612{
613 if (x == 0)
614 return 1;
615 return gf4096_mul(x, 0xe01);
616}
617
David Woodhouse5467fb02006-10-06 15:36:29 +0100618static int __devinit cafe_nand_probe(struct pci_dev *pdev,
619 const struct pci_device_id *ent)
620{
621 struct mtd_info *mtd;
622 struct cafe_priv *cafe;
623 uint32_t ctrl;
624 int err = 0;
625
626 err = pci_enable_device(pdev);
627 if (err)
628 return err;
629
630 pci_set_master(pdev);
631
632 mtd = kzalloc(sizeof(*mtd) + sizeof(struct cafe_priv), GFP_KERNEL);
633 if (!mtd) {
634 dev_warn(&pdev->dev, "failed to alloc mtd_info\n");
635 return -ENOMEM;
636 }
637 cafe = (void *)(&mtd[1]);
638
639 mtd->priv = cafe;
640 mtd->owner = THIS_MODULE;
641
642 cafe->pdev = pdev;
643 cafe->mmio = pci_iomap(pdev, 0, 0);
644 if (!cafe->mmio) {
645 dev_warn(&pdev->dev, "failed to iomap\n");
646 err = -ENOMEM;
647 goto out_free_mtd;
648 }
649 cafe->dmabuf = dma_alloc_coherent(&cafe->pdev->dev, 2112 + sizeof(struct nand_buffers),
650 &cafe->dmaaddr, GFP_KERNEL);
651 if (!cafe->dmabuf) {
652 err = -ENOMEM;
653 goto out_ior;
654 }
655 cafe->nand.buffers = (void *)cafe->dmabuf + 2112;
656
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200657 cafe->rs = init_rs_non_canonical(12, &cafe_mul, 0, 1, 8);
658 if (!cafe->rs) {
659 err = -ENOMEM;
660 goto out_ior;
661 }
662
David Woodhouse5467fb02006-10-06 15:36:29 +0100663 cafe->nand.cmdfunc = cafe_nand_cmdfunc;
664 cafe->nand.dev_ready = cafe_device_ready;
665 cafe->nand.read_byte = cafe_read_byte;
666 cafe->nand.read_buf = cafe_read_buf;
667 cafe->nand.write_buf = cafe_write_buf;
668 cafe->nand.select_chip = cafe_select_chip;
669
670 cafe->nand.chip_delay = 0;
671
672 /* Enable the following for a flash based bad block table */
673 cafe->nand.options = NAND_USE_FLASH_BBT | NAND_NO_AUTOINCR | NAND_OWN_BUFFERS;
David Woodhouse8dd851d2006-10-20 02:11:40 +0100674
675 if (skipbbt) {
676 cafe->nand.options |= NAND_SKIP_BBTSCAN;
677 cafe->nand.block_bad = cafe_nand_block_bad;
678 }
David Woodhousec9ac5972006-11-30 08:17:38 +0000679
David Woodhouse527a4f42007-01-23 15:35:27 +0800680 if (numtimings && numtimings != 3) {
681 dev_warn(&cafe->pdev->dev, "%d timing register values ignored; precisely three are required\n", numtimings);
682 }
683
684 if (numtimings == 3) {
David Woodhouse527a4f42007-01-23 15:35:27 +0800685 cafe_dev_dbg(&cafe->pdev->dev, "Using provided timings (%08x %08x %08x)\n",
David Woodhouse8e5368a2007-03-23 10:40:04 +0000686 timing[0], timing[1], timing[2]);
David Woodhouse527a4f42007-01-23 15:35:27 +0800687 } else {
David Woodhouse8e5368a2007-03-23 10:40:04 +0000688 timing[0] = cafe_readl(cafe, NAND_TIMING1);
689 timing[1] = cafe_readl(cafe, NAND_TIMING2);
690 timing[2] = cafe_readl(cafe, NAND_TIMING3);
David Woodhouse527a4f42007-01-23 15:35:27 +0800691
David Woodhouse8e5368a2007-03-23 10:40:04 +0000692 if (timing[0] | timing[1] | timing[2]) {
693 cafe_dev_dbg(&cafe->pdev->dev, "Timing registers already set (%08x %08x %08x)\n",
694 timing[0], timing[1], timing[2]);
David Woodhouse527a4f42007-01-23 15:35:27 +0800695 } else {
696 dev_warn(&cafe->pdev->dev, "Timing registers unset; using most conservative defaults\n");
David Woodhouse8e5368a2007-03-23 10:40:04 +0000697 timing[0] = timing[1] = timing[2] = 0xffffffff;
David Woodhouse527a4f42007-01-23 15:35:27 +0800698 }
699 }
700
David Woodhousedcc41bc2006-10-27 09:55:34 +0300701 /* Start off by resetting the NAND controller completely */
David Woodhouse195a2532006-10-31 12:30:11 +0800702 cafe_writel(cafe, 1, NAND_RESET);
703 cafe_writel(cafe, 0, NAND_RESET);
704
David Woodhouse8e5368a2007-03-23 10:40:04 +0000705 cafe_writel(cafe, timing[0], NAND_TIMING1);
706 cafe_writel(cafe, timing[1], NAND_TIMING2);
707 cafe_writel(cafe, timing[2], NAND_TIMING3);
David Woodhousedcc41bc2006-10-27 09:55:34 +0300708
David Woodhouse195a2532006-10-31 12:30:11 +0800709 cafe_writel(cafe, 0xffffffff, NAND_IRQ_MASK);
Thomas Gleixner2db63462007-02-14 00:33:20 -0800710 err = request_irq(pdev->irq, &cafe_nand_interrupt, IRQF_SHARED,
711 "CAFE NAND", mtd);
David Woodhouse5467fb02006-10-06 15:36:29 +0100712 if (err) {
713 dev_warn(&pdev->dev, "Could not register IRQ %d\n", pdev->irq);
David Woodhouse5467fb02006-10-06 15:36:29 +0100714 goto out_free_dma;
715 }
David Woodhousef7c37d72007-01-23 15:44:10 +0800716
David Woodhouse5467fb02006-10-06 15:36:29 +0100717 /* Disable master reset, enable NAND clock */
David Woodhouse195a2532006-10-31 12:30:11 +0800718 ctrl = cafe_readl(cafe, GLOBAL_CTRL);
David Woodhouse5467fb02006-10-06 15:36:29 +0100719 ctrl &= 0xffffeff0;
720 ctrl |= 0x00007000;
David Woodhouse195a2532006-10-31 12:30:11 +0800721 cafe_writel(cafe, ctrl | 0x05, GLOBAL_CTRL);
722 cafe_writel(cafe, ctrl | 0x0a, GLOBAL_CTRL);
723 cafe_writel(cafe, 0, NAND_DMA_CTRL);
David Woodhouse5467fb02006-10-06 15:36:29 +0100724
David Woodhouse195a2532006-10-31 12:30:11 +0800725 cafe_writel(cafe, 0x7006, GLOBAL_CTRL);
726 cafe_writel(cafe, 0x700a, GLOBAL_CTRL);
David Woodhouse5467fb02006-10-06 15:36:29 +0100727
728 /* Set up DMA address */
David Woodhouse195a2532006-10-31 12:30:11 +0800729 cafe_writel(cafe, cafe->dmaaddr & 0xffffffff, NAND_DMA_ADDR0);
David Woodhouse5467fb02006-10-06 15:36:29 +0100730 if (sizeof(cafe->dmaaddr) > 4)
David Woodhousefbad5692006-10-22 15:09:33 +0100731 /* Shift in two parts to shut the compiler up */
David Woodhouse195a2532006-10-31 12:30:11 +0800732 cafe_writel(cafe, (cafe->dmaaddr >> 16) >> 16, NAND_DMA_ADDR1);
David Woodhouse5467fb02006-10-06 15:36:29 +0100733 else
David Woodhouse195a2532006-10-31 12:30:11 +0800734 cafe_writel(cafe, 0, NAND_DMA_ADDR1);
David Woodhousefbad5692006-10-22 15:09:33 +0100735
David Woodhouse8dd851d2006-10-20 02:11:40 +0100736 cafe_dev_dbg(&cafe->pdev->dev, "Set DMA address to %x (virt %p)\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800737 cafe_readl(cafe, NAND_DMA_ADDR0), cafe->dmabuf);
David Woodhouse5467fb02006-10-06 15:36:29 +0100738
739 /* Enable NAND IRQ in global IRQ mask register */
David Woodhouse195a2532006-10-31 12:30:11 +0800740 cafe_writel(cafe, 0x80000007, GLOBAL_IRQ_MASK);
David Woodhouse8dd851d2006-10-20 02:11:40 +0100741 cafe_dev_dbg(&cafe->pdev->dev, "Control %x, IRQ mask %x\n",
David Woodhouse195a2532006-10-31 12:30:11 +0800742 cafe_readl(cafe, GLOBAL_CTRL), cafe_readl(cafe, GLOBAL_IRQ_MASK));
David Woodhousef7c37d72007-01-23 15:44:10 +0800743
744 /* Scan to find existence of the device */
David Woodhouse048c37b2007-05-02 12:26:37 +0100745 if (nand_scan_ident(mtd, 2)) {
David Woodhouse5467fb02006-10-06 15:36:29 +0100746 err = -ENXIO;
747 goto out_irq;
748 }
749
750 cafe->ctl2 = 1<<27; /* Reed-Solomon ECC */
751 if (mtd->writesize == 2048)
752 cafe->ctl2 |= 1<<29; /* 2KiB page size */
753
754 /* Set up ECC according to the type of chip we found */
David Woodhousefbad5692006-10-22 15:09:33 +0100755 if (mtd->writesize == 2048) {
David Woodhouse8dd851d2006-10-20 02:11:40 +0100756 cafe->nand.ecc.layout = &cafe_oobinfo_2048;
757 cafe->nand.bbt_td = &cafe_bbt_main_descr_2048;
758 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_2048;
David Woodhousefbad5692006-10-22 15:09:33 +0100759 } else if (mtd->writesize == 512) {
760 cafe->nand.ecc.layout = &cafe_oobinfo_512;
761 cafe->nand.bbt_td = &cafe_bbt_main_descr_512;
762 cafe->nand.bbt_md = &cafe_bbt_mirror_descr_512;
David Woodhouse5467fb02006-10-06 15:36:29 +0100763 } else {
David Woodhousefbad5692006-10-22 15:09:33 +0100764 printk(KERN_WARNING "Unexpected NAND flash writesize %d. Aborting\n",
David Woodhouse5467fb02006-10-06 15:36:29 +0100765 mtd->writesize);
David Woodhousefbad5692006-10-22 15:09:33 +0100766 goto out_irq;
David Woodhouse5467fb02006-10-06 15:36:29 +0100767 }
David Woodhousefbad5692006-10-22 15:09:33 +0100768 cafe->nand.ecc.mode = NAND_ECC_HW_SYNDROME;
769 cafe->nand.ecc.size = mtd->writesize;
770 cafe->nand.ecc.bytes = 14;
771 cafe->nand.ecc.hwctl = (void *)cafe_nand_bug;
772 cafe->nand.ecc.calculate = (void *)cafe_nand_bug;
773 cafe->nand.ecc.correct = (void *)cafe_nand_bug;
774 cafe->nand.write_page = cafe_nand_write_page;
775 cafe->nand.ecc.write_page = cafe_nand_write_page_lowlevel;
776 cafe->nand.ecc.write_oob = cafe_nand_write_oob;
777 cafe->nand.ecc.read_page = cafe_nand_read_page;
778 cafe->nand.ecc.read_oob = cafe_nand_read_oob;
David Woodhouse5467fb02006-10-06 15:36:29 +0100779
780 err = nand_scan_tail(mtd);
781 if (err)
782 goto out_irq;
783
David Woodhouse5467fb02006-10-06 15:36:29 +0100784 pci_set_drvdata(pdev, mtd);
785 add_mtd_device(mtd);
786 goto out;
787
788 out_irq:
789 /* Disable NAND IRQ in global IRQ mask register */
David Woodhouse195a2532006-10-31 12:30:11 +0800790 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
David Woodhouse5467fb02006-10-06 15:36:29 +0100791 free_irq(pdev->irq, mtd);
792 out_free_dma:
793 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
794 out_ior:
795 pci_iounmap(pdev, cafe->mmio);
796 out_free_mtd:
797 kfree(mtd);
798 out:
799 return err;
800}
801
802static void __devexit cafe_nand_remove(struct pci_dev *pdev)
803{
804 struct mtd_info *mtd = pci_get_drvdata(pdev);
805 struct cafe_priv *cafe = mtd->priv;
806
807 del_mtd_device(mtd);
808 /* Disable NAND IRQ in global IRQ mask register */
David Woodhouse195a2532006-10-31 12:30:11 +0800809 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
David Woodhouse5467fb02006-10-06 15:36:29 +0100810 free_irq(pdev->irq, mtd);
811 nand_release(mtd);
Segher Boessenkool8c61b7a2007-05-02 12:18:49 +0200812 free_rs(cafe->rs);
David Woodhouse5467fb02006-10-06 15:36:29 +0100813 pci_iounmap(pdev, cafe->mmio);
814 dma_free_coherent(&cafe->pdev->dev, 2112, cafe->dmabuf, cafe->dmaaddr);
815 kfree(mtd);
816}
817
818static struct pci_device_id cafe_nand_tbl[] = {
819 { 0x11ab, 0x4100, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_MEMORY_FLASH << 8, 0xFFFF0 }
820};
821
822MODULE_DEVICE_TABLE(pci, cafe_nand_tbl);
823
824static struct pci_driver cafe_nand_pci_driver = {
825 .name = "CAFÉ NAND",
826 .id_table = cafe_nand_tbl,
827 .probe = cafe_nand_probe,
828 .remove = __devexit_p(cafe_nand_remove),
829#ifdef CONFIG_PMx
830 .suspend = cafe_nand_suspend,
831 .resume = cafe_nand_resume,
832#endif
833};
834
835static int cafe_nand_init(void)
836{
837 return pci_register_driver(&cafe_nand_pci_driver);
838}
839
840static void cafe_nand_exit(void)
841{
842 pci_unregister_driver(&cafe_nand_pci_driver);
843}
844module_init(cafe_nand_init);
845module_exit(cafe_nand_exit);
846
847MODULE_LICENSE("GPL");
848MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
David Woodhousef7c37d72007-01-23 15:44:10 +0800849MODULE_DESCRIPTION("NAND flash driver for OLPC CAFÉ chip");