blob: 6cece6e7ee6b34aca91a931d5ec3d8440bb0576b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * drivers/mtd/nand/au1550nd.c
3 *
4 * Copyright (C) 2004 Embedded Edge, LLC
5 *
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 */
11
12#include <linux/slab.h>
Manuel Laussb7f720d2011-05-08 10:42:20 +020013#include <linux/gpio.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/module.h>
Sergei Shtylyov35af68b2006-05-16 20:52:06 +040015#include <linux/interrupt.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/mtd/mtd.h>
17#include <linux/mtd/nand.h>
18#include <linux/mtd/partitions.h>
Manuel Laussb67a1a02011-12-08 10:42:10 +000019#include <linux/platform_device.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/io.h>
Manuel Laussb67a1a02011-12-08 10:42:10 +000021#include <asm/mach-au1x00/au1000.h>
22#include <asm/mach-au1x00/au1550nd.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023
Linus Torvalds1da177e2005-04-16 15:20:36 -070024
Manuel Laussb67a1a02011-12-08 10:42:10 +000025struct au1550nd_ctx {
26 struct mtd_info info;
27 struct nand_chip chip;
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Manuel Laussb67a1a02011-12-08 10:42:10 +000029 int cs;
30 void __iomem *base;
31 void (*write_byte)(struct mtd_info *, u_char);
Linus Torvalds1da177e2005-04-16 15:20:36 -070032};
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34/**
35 * au_read_byte - read one byte from the chip
36 * @mtd: MTD device structure
37 *
Brian Norris7854d3f2011-06-23 14:12:08 -070038 * read function for 8bit buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 */
40static u_char au_read_byte(struct mtd_info *mtd)
41{
42 struct nand_chip *this = mtd->priv;
43 u_char ret = readb(this->IO_ADDR_R);
44 au_sync();
45 return ret;
46}
47
48/**
49 * au_write_byte - write one byte to the chip
50 * @mtd: MTD device structure
51 * @byte: pointer to data byte to write
52 *
Brian Norris7854d3f2011-06-23 14:12:08 -070053 * write function for 8it buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -070054 */
55static void au_write_byte(struct mtd_info *mtd, u_char byte)
56{
57 struct nand_chip *this = mtd->priv;
58 writeb(byte, this->IO_ADDR_W);
59 au_sync();
60}
61
62/**
Brian Norris7854d3f2011-06-23 14:12:08 -070063 * au_read_byte16 - read one byte endianness aware from the chip
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 * @mtd: MTD device structure
65 *
Brian Norris7854d3f2011-06-23 14:12:08 -070066 * read function for 16bit buswidth with endianness conversion
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 */
68static u_char au_read_byte16(struct mtd_info *mtd)
69{
70 struct nand_chip *this = mtd->priv;
71 u_char ret = (u_char) cpu_to_le16(readw(this->IO_ADDR_R));
72 au_sync();
73 return ret;
74}
75
76/**
Brian Norris7854d3f2011-06-23 14:12:08 -070077 * au_write_byte16 - write one byte endianness aware to the chip
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 * @mtd: MTD device structure
79 * @byte: pointer to data byte to write
80 *
Brian Norris7854d3f2011-06-23 14:12:08 -070081 * write function for 16bit buswidth with endianness conversion
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83static void au_write_byte16(struct mtd_info *mtd, u_char byte)
84{
85 struct nand_chip *this = mtd->priv;
86 writew(le16_to_cpu((u16) byte), this->IO_ADDR_W);
87 au_sync();
88}
89
90/**
91 * au_read_word - read one word from the chip
92 * @mtd: MTD device structure
93 *
Brian Norris7854d3f2011-06-23 14:12:08 -070094 * read function for 16bit buswidth without endianness conversion
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 */
96static u16 au_read_word(struct mtd_info *mtd)
97{
98 struct nand_chip *this = mtd->priv;
99 u16 ret = readw(this->IO_ADDR_R);
100 au_sync();
101 return ret;
102}
103
104/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 * au_write_buf - write buffer to chip
106 * @mtd: MTD device structure
107 * @buf: data buffer
108 * @len: number of bytes to write
109 *
Brian Norris7854d3f2011-06-23 14:12:08 -0700110 * write function for 8bit buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 */
112static void au_write_buf(struct mtd_info *mtd, const u_char *buf, int len)
113{
114 int i;
115 struct nand_chip *this = mtd->priv;
116
David Woodhousee0c7d762006-05-13 18:07:53 +0100117 for (i = 0; i < len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 writeb(buf[i], this->IO_ADDR_W);
119 au_sync();
120 }
121}
122
123/**
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000124 * au_read_buf - read chip data into buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * @mtd: MTD device structure
126 * @buf: buffer to store date
127 * @len: number of bytes to read
128 *
Brian Norris7854d3f2011-06-23 14:12:08 -0700129 * read function for 8bit buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 */
131static void au_read_buf(struct mtd_info *mtd, u_char *buf, int len)
132{
133 int i;
134 struct nand_chip *this = mtd->priv;
135
David Woodhousee0c7d762006-05-13 18:07:53 +0100136 for (i = 0; i < len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 buf[i] = readb(this->IO_ADDR_R);
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000138 au_sync();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 }
140}
141
142/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 * au_write_buf16 - write buffer to chip
144 * @mtd: MTD device structure
145 * @buf: data buffer
146 * @len: number of bytes to write
147 *
Brian Norris7854d3f2011-06-23 14:12:08 -0700148 * write function for 16bit buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 */
150static void au_write_buf16(struct mtd_info *mtd, const u_char *buf, int len)
151{
152 int i;
153 struct nand_chip *this = mtd->priv;
154 u16 *p = (u16 *) buf;
155 len >>= 1;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000156
David Woodhousee0c7d762006-05-13 18:07:53 +0100157 for (i = 0; i < len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 writew(p[i], this->IO_ADDR_W);
159 au_sync();
160 }
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162}
163
164/**
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000165 * au_read_buf16 - read chip data into buffer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 * @mtd: MTD device structure
167 * @buf: buffer to store date
168 * @len: number of bytes to read
169 *
Brian Norris7854d3f2011-06-23 14:12:08 -0700170 * read function for 16bit buswidth
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 */
172static void au_read_buf16(struct mtd_info *mtd, u_char *buf, int len)
173{
174 int i;
175 struct nand_chip *this = mtd->priv;
176 u16 *p = (u16 *) buf;
177 len >>= 1;
178
David Woodhousee0c7d762006-05-13 18:07:53 +0100179 for (i = 0; i < len; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 p[i] = readw(this->IO_ADDR_R);
181 au_sync();
182 }
183}
184
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200185/* Select the chip by setting nCE to low */
186#define NAND_CTL_SETNCE 1
187/* Deselect the chip by setting nCE to high */
188#define NAND_CTL_CLRNCE 2
189/* Select the command latch by setting CLE to high */
190#define NAND_CTL_SETCLE 3
191/* Deselect the command latch by setting CLE to low */
192#define NAND_CTL_CLRCLE 4
193/* Select the address latch by setting ALE to high */
194#define NAND_CTL_SETALE 5
195/* Deselect the address latch by setting ALE to low */
196#define NAND_CTL_CLRALE 6
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
198static void au1550_hwcontrol(struct mtd_info *mtd, int cmd)
199{
Manuel Laussb67a1a02011-12-08 10:42:10 +0000200 struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
201 struct nand_chip *this = mtd->priv;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
David Woodhousee0c7d762006-05-13 18:07:53 +0100203 switch (cmd) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
David Woodhousee0c7d762006-05-13 18:07:53 +0100205 case NAND_CTL_SETCLE:
Manuel Laussb67a1a02011-12-08 10:42:10 +0000206 this->IO_ADDR_W = ctx->base + MEM_STNAND_CMD;
David Woodhousee0c7d762006-05-13 18:07:53 +0100207 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
David Woodhousee0c7d762006-05-13 18:07:53 +0100209 case NAND_CTL_CLRCLE:
Manuel Laussb67a1a02011-12-08 10:42:10 +0000210 this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA;
David Woodhousee0c7d762006-05-13 18:07:53 +0100211 break;
212
213 case NAND_CTL_SETALE:
Manuel Laussb67a1a02011-12-08 10:42:10 +0000214 this->IO_ADDR_W = ctx->base + MEM_STNAND_ADDR;
David Woodhousee0c7d762006-05-13 18:07:53 +0100215 break;
216
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000217 case NAND_CTL_CLRALE:
Manuel Laussb67a1a02011-12-08 10:42:10 +0000218 this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA;
David Woodhousee0c7d762006-05-13 18:07:53 +0100219 /* FIXME: Nobody knows why this is necessary,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 * but it works only that way */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000221 udelay(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 break;
223
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000224 case NAND_CTL_SETNCE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225 /* assert (force assert) chip enable */
Manuel Lauss9cf12162014-07-23 16:36:25 +0200226 alchemy_wrsmem((1 << (4 + ctx->cs)), AU1000_MEM_STNDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000229 case NAND_CTL_CLRNCE:
David Woodhousee0c7d762006-05-13 18:07:53 +0100230 /* deassert chip enable */
Manuel Lauss9cf12162014-07-23 16:36:25 +0200231 alchemy_wrsmem(0, AU1000_MEM_STNDCTL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232 break;
233 }
234
235 this->IO_ADDR_R = this->IO_ADDR_W;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 /* Drain the writebuffer */
238 au_sync();
239}
240
241int au1550_device_ready(struct mtd_info *mtd)
242{
Manuel Lauss9cf12162014-07-23 16:36:25 +0200243 return (alchemy_rdsmem(AU1000_MEM_STSTAT) & 0x1) ? 1 : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400246/**
247 * au1550_select_chip - control -CE line
248 * Forbid driving -CE manually permitting the NAND controller to do this.
249 * Keeping -CE asserted during the whole sector reads interferes with the
250 * NOR flash and PCMCIA drivers as it causes contention on the static bus.
251 * We only have to hold -CE low for the NAND read commands since the flash
252 * chip needs it to be asserted during chip not ready time but the NAND
253 * controller keeps it released.
254 *
255 * @mtd: MTD device structure
256 * @chip: chipnumber to select, -1 for deselect
257 */
258static void au1550_select_chip(struct mtd_info *mtd, int chip)
259{
260}
261
262/**
263 * au1550_command - Send command to NAND device
264 * @mtd: MTD device structure
265 * @command: the command to be sent
266 * @column: the column address for this command, -1 if none
267 * @page_addr: the page address for this command, -1 if none
268 */
269static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr)
270{
Manuel Laussb67a1a02011-12-08 10:42:10 +0000271 struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info);
272 struct nand_chip *this = mtd->priv;
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400273 int ce_override = 0, i;
Manuel Laussb67a1a02011-12-08 10:42:10 +0000274 unsigned long flags = 0;
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400275
276 /* Begin command latch cycle */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200277 au1550_hwcontrol(mtd, NAND_CTL_SETCLE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400278 /*
279 * Write out the command to the device.
280 */
281 if (command == NAND_CMD_SEQIN) {
282 int readcmd;
283
Joern Engel28318772006-05-22 23:18:05 +0200284 if (column >= mtd->writesize) {
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400285 /* OOB area */
Joern Engel28318772006-05-22 23:18:05 +0200286 column -= mtd->writesize;
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400287 readcmd = NAND_CMD_READOOB;
288 } else if (column < 256) {
289 /* First 256 bytes --> READ0 */
290 readcmd = NAND_CMD_READ0;
291 } else {
292 column -= 256;
293 readcmd = NAND_CMD_READ1;
294 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000295 ctx->write_byte(mtd, readcmd);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400296 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000297 ctx->write_byte(mtd, command);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400298
299 /* Set ALE and clear CLE to start address cycle */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200300 au1550_hwcontrol(mtd, NAND_CTL_CLRCLE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400301
302 if (column != -1 || page_addr != -1) {
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200303 au1550_hwcontrol(mtd, NAND_CTL_SETALE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400304
305 /* Serially input address */
306 if (column != -1) {
307 /* Adjust columns for 16 bit buswidth */
Brian Norris3dad2342014-01-29 14:08:12 -0800308 if (this->options & NAND_BUSWIDTH_16 &&
309 !nand_opcode_8bits(command))
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400310 column >>= 1;
Manuel Laussb67a1a02011-12-08 10:42:10 +0000311 ctx->write_byte(mtd, column);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400312 }
313 if (page_addr != -1) {
Manuel Laussb67a1a02011-12-08 10:42:10 +0000314 ctx->write_byte(mtd, (u8)(page_addr & 0xff));
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400315
316 if (command == NAND_CMD_READ0 ||
317 command == NAND_CMD_READ1 ||
318 command == NAND_CMD_READOOB) {
319 /*
320 * NAND controller will release -CE after
321 * the last address byte is written, so we'll
322 * have to forcibly assert it. No interrupts
323 * are allowed while we do this as we don't
324 * want the NOR flash or PCMCIA drivers to
325 * steal our precious bytes of data...
326 */
327 ce_override = 1;
328 local_irq_save(flags);
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200329 au1550_hwcontrol(mtd, NAND_CTL_SETNCE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400330 }
331
Manuel Laussb67a1a02011-12-08 10:42:10 +0000332 ctx->write_byte(mtd, (u8)(page_addr >> 8));
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400333
334 /* One more address cycle for devices > 32MiB */
335 if (this->chipsize > (32 << 20))
Manuel Laussb67a1a02011-12-08 10:42:10 +0000336 ctx->write_byte(mtd,
337 ((page_addr >> 16) & 0x0f));
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400338 }
339 /* Latch in address */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200340 au1550_hwcontrol(mtd, NAND_CTL_CLRALE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400341 }
342
343 /*
344 * Program and erase have their own busy handlers.
345 * Status and sequential in need no delay.
346 */
347 switch (command) {
348
349 case NAND_CMD_PAGEPROG:
350 case NAND_CMD_ERASE1:
351 case NAND_CMD_ERASE2:
352 case NAND_CMD_SEQIN:
353 case NAND_CMD_STATUS:
354 return;
355
356 case NAND_CMD_RESET:
357 break;
358
359 case NAND_CMD_READ0:
360 case NAND_CMD_READ1:
361 case NAND_CMD_READOOB:
362 /* Check if we're really driving -CE low (just in case) */
363 if (unlikely(!ce_override))
364 break;
365
366 /* Apply a short delay always to ensure that we do wait tWB. */
367 ndelay(100);
368 /* Wait for a chip to become ready... */
369 for (i = this->chip_delay; !this->dev_ready(mtd) && i > 0; --i)
370 udelay(1);
371
372 /* Release -CE and re-enable interrupts. */
Thomas Gleixner7abd3ef2006-05-23 23:25:53 +0200373 au1550_hwcontrol(mtd, NAND_CTL_CLRNCE);
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400374 local_irq_restore(flags);
375 return;
376 }
377 /* Apply this short delay always to ensure that we do wait tWB. */
378 ndelay(100);
379
380 while(!this->dev_ready(mtd));
381}
382
Bill Pemberton06f25512012-11-19 13:23:07 -0500383static int find_nand_cs(unsigned long nand_base)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
Manuel Laussb67a1a02011-12-08 10:42:10 +0000385 void __iomem *base =
386 (void __iomem *)KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR);
387 unsigned long addr, staddr, start, mask, end;
388 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Manuel Laussb67a1a02011-12-08 10:42:10 +0000390 for (i = 0; i < 4; i++) {
391 addr = 0x1000 + (i * 0x10); /* CSx */
392 staddr = __raw_readl(base + addr + 0x08); /* STADDRx */
393 /* figure out the decoded range of this CS */
394 start = (staddr << 4) & 0xfffc0000;
395 mask = (staddr << 18) & 0xfffc0000;
396 end = (start | (start - 1)) & ~(start ^ mask);
397 if ((nand_base >= start) && (nand_base < end))
398 return i;
399 }
400
401 return -ENODEV;
402}
403
Bill Pemberton06f25512012-11-19 13:23:07 -0500404static int au1550nd_probe(struct platform_device *pdev)
Manuel Laussb67a1a02011-12-08 10:42:10 +0000405{
406 struct au1550nd_platdata *pd;
407 struct au1550nd_ctx *ctx;
408 struct nand_chip *this;
409 struct resource *r;
410 int ret, cs;
411
Jingoo Han453810b2013-07-30 17:18:33 +0900412 pd = dev_get_platdata(&pdev->dev);
Manuel Laussb67a1a02011-12-08 10:42:10 +0000413 if (!pd) {
414 dev_err(&pdev->dev, "missing platform data\n");
415 return -ENODEV;
416 }
417
418 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
Jingoo Hance3737f2013-12-26 12:02:30 +0900419 if (!ctx)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421
Manuel Laussb67a1a02011-12-08 10:42:10 +0000422 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
423 if (!r) {
424 dev_err(&pdev->dev, "no NAND memory resource\n");
425 ret = -ENODEV;
426 goto out1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000428 if (request_mem_region(r->start, resource_size(r), "au1550-nand")) {
429 dev_err(&pdev->dev, "cannot claim NAND memory area\n");
430 ret = -ENOMEM;
431 goto out1;
Pete Popovef6f0d12005-09-23 02:44:58 +0100432 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000433
434 ctx->base = ioremap_nocache(r->start, 0x1000);
435 if (!ctx->base) {
436 dev_err(&pdev->dev, "cannot remap NAND memory area\n");
437 ret = -ENODEV;
438 goto out2;
Pete Popovef6f0d12005-09-23 02:44:58 +0100439 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000440
441 this = &ctx->chip;
442 ctx->info.priv = this;
443 ctx->info.owner = THIS_MODULE;
444
445 /* figure out which CS# r->start belongs to */
446 cs = find_nand_cs(r->start);
447 if (cs < 0) {
448 dev_err(&pdev->dev, "cannot detect NAND chipselect\n");
449 ret = -ENODEV;
450 goto out3;
Pete Popovef6f0d12005-09-23 02:44:58 +0100451 }
Manuel Laussb67a1a02011-12-08 10:42:10 +0000452 ctx->cs = cs;
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000453
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 this->dev_ready = au1550_device_ready;
Sergei Shtylyov35af68b2006-05-16 20:52:06 +0400455 this->select_chip = au1550_select_chip;
456 this->cmdfunc = au1550_command;
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 /* 30 us command delay time */
Thomas Gleixner61b03bd2005-11-07 11:15:49 +0000459 this->chip_delay = 30;
Thomas Gleixner6dfc6d22006-05-23 12:00:46 +0200460 this->ecc.mode = NAND_ECC_SOFT;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461
Manuel Laussb67a1a02011-12-08 10:42:10 +0000462 if (pd->devwidth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 this->options |= NAND_BUSWIDTH_16;
464
Manuel Laussb67a1a02011-12-08 10:42:10 +0000465 this->read_byte = (pd->devwidth) ? au_read_byte16 : au_read_byte;
466 ctx->write_byte = (pd->devwidth) ? au_write_byte16 : au_write_byte;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 this->read_word = au_read_word;
Manuel Laussb67a1a02011-12-08 10:42:10 +0000468 this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf;
469 this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470
Manuel Laussb67a1a02011-12-08 10:42:10 +0000471 ret = nand_scan(&ctx->info, 1);
472 if (ret) {
473 dev_err(&pdev->dev, "NAND scan failed with %d\n", ret);
474 goto out3;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
476
Manuel Laussb67a1a02011-12-08 10:42:10 +0000477 mtd_device_register(&ctx->info, pd->parts, pd->num_parts);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Wei Yongjuna1d79942013-11-11 14:18:29 +0800479 platform_set_drvdata(pdev, ctx);
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 return 0;
482
Manuel Laussb67a1a02011-12-08 10:42:10 +0000483out3:
484 iounmap(ctx->base);
485out2:
486 release_mem_region(r->start, resource_size(r));
487out1:
488 kfree(ctx);
489 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490}
491
Bill Pemberton810b7e02012-11-19 13:26:04 -0500492static int au1550nd_remove(struct platform_device *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493{
Manuel Laussb67a1a02011-12-08 10:42:10 +0000494 struct au1550nd_ctx *ctx = platform_get_drvdata(pdev);
495 struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496
Manuel Laussb67a1a02011-12-08 10:42:10 +0000497 nand_release(&ctx->info);
498 iounmap(ctx->base);
499 release_mem_region(r->start, 0x1000);
500 kfree(ctx);
501 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502}
David Woodhousee0c7d762006-05-13 18:07:53 +0100503
Manuel Laussb67a1a02011-12-08 10:42:10 +0000504static struct platform_driver au1550nd_driver = {
505 .driver = {
506 .name = "au1550-nand",
507 .owner = THIS_MODULE,
508 },
509 .probe = au1550nd_probe,
Bill Pemberton5153b882012-11-19 13:21:24 -0500510 .remove = au1550nd_remove,
Manuel Laussb67a1a02011-12-08 10:42:10 +0000511};
512
513module_platform_driver(au1550nd_driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514
515MODULE_LICENSE("GPL");
516MODULE_AUTHOR("Embedded Edge, LLC");
517MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on Pb1550 board");