diff options
author | Manuel Lauss <manuel.lauss@googlemail.com> | 2011-12-08 05:42:10 -0500 |
---|---|---|
committer | Ralf Baechle <ralf@linux-mips.org> | 2011-12-08 05:42:10 -0500 |
commit | b67a1a02d463b5b298cc718ca971738fe20f0ab9 (patch) | |
tree | 3523ca7826a356e1bf1a8ac878056a4fbeb73434 | |
parent | 1c043f16a01c144305e952025e883b55706f2450 (diff) |
MTD: nand: make au1550nd.c a platform_driver
Transform the au1550nd.c driver into a platform_driver and hook it
up in the PB1550 board (gen_nand works fine on the DB1550, but since
I don't have a PB1550 to test this driver stays for now).
Signed-off-by: Manuel Lauss <manuel.lauss@googlemail.com>
Cc: linux-mtd@lists.infradead.org
To: linux-mips@linux-mips.org
Patchwork: https://patchwork.linux-mips.org/patch/2875/
Patchwork: https://patchwork.linux-mips.org/patch/3160/
Acked-by: Artem Bityutskiy <dedekind1@gmail.com>
Signed-off-by: Ralf Baechle <ralf@linux-mips.org>
-rw-r--r-- | arch/mips/alchemy/devboards/pb1550.c | 66 | ||||
-rw-r--r-- | arch/mips/include/asm/mach-au1x00/au1550nd.h | 16 | ||||
-rw-r--r-- | drivers/mtd/nand/au1550nd.c | 298 |
3 files changed, 205 insertions, 175 deletions
diff --git a/arch/mips/alchemy/devboards/pb1550.c b/arch/mips/alchemy/devboards/pb1550.c index e4a00a56a20..b37e7de8d92 100644 --- a/arch/mips/alchemy/devboards/pb1550.c +++ b/arch/mips/alchemy/devboards/pb1550.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
25 | #include <asm/mach-au1x00/au1000.h> | 25 | #include <asm/mach-au1x00/au1000.h> |
26 | #include <asm/mach-au1x00/au1xxx_dbdma.h> | 26 | #include <asm/mach-au1x00/au1xxx_dbdma.h> |
27 | #include <asm/mach-au1x00/au1550nd.h> | ||
27 | #include <asm/mach-au1x00/gpio.h> | 28 | #include <asm/mach-au1x00/gpio.h> |
28 | #include <asm/mach-db1x00/bcsr.h> | 29 | #include <asm/mach-db1x00/bcsr.h> |
29 | #include "platform.h" | 30 | #include "platform.h" |
@@ -131,6 +132,67 @@ static struct platform_device pb1550_i2c_dev = { | |||
131 | .resource = au1550_psc2_res, | 132 | .resource = au1550_psc2_res, |
132 | }; | 133 | }; |
133 | 134 | ||
135 | static struct mtd_partition pb1550_nand_parts[] = { | ||
136 | [0] = { | ||
137 | .name = "NAND FS 0", | ||
138 | .offset = 0, | ||
139 | .size = 8 * 1024 * 1024, | ||
140 | }, | ||
141 | [1] = { | ||
142 | .name = "NAND FS 1", | ||
143 | .offset = MTDPART_OFS_APPEND, | ||
144 | .size = MTDPART_SIZ_FULL, | ||
145 | }, | ||
146 | }; | ||
147 | |||
148 | static struct au1550nd_platdata pb1550_nand_pd = { | ||
149 | .parts = pb1550_nand_parts, | ||
150 | .num_parts = ARRAY_SIZE(pb1550_nand_parts), | ||
151 | .devwidth = 0, /* x8 NAND default, needs fixing up */ | ||
152 | }; | ||
153 | |||
154 | static struct resource pb1550_nand_res[] = { | ||
155 | [0] = { | ||
156 | .start = 0x20000000, | ||
157 | .end = 0x20000fff, | ||
158 | .flags = IORESOURCE_MEM, | ||
159 | }, | ||
160 | }; | ||
161 | |||
162 | static struct platform_device pb1550_nand_dev = { | ||
163 | .name = "au1550-nand", | ||
164 | .id = -1, | ||
165 | .resource = pb1550_nand_res, | ||
166 | .num_resources = ARRAY_SIZE(pb1550_nand_res), | ||
167 | .dev = { | ||
168 | .platform_data = &pb1550_nand_pd, | ||
169 | }, | ||
170 | }; | ||
171 | |||
172 | static void __init pb1550_nand_setup(void) | ||
173 | { | ||
174 | int boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | | ||
175 | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); | ||
176 | |||
177 | switch (boot_swapboot) { | ||
178 | case 0: | ||
179 | case 2: | ||
180 | case 8: | ||
181 | case 0xC: | ||
182 | case 0xD: | ||
183 | /* x16 NAND Flash */ | ||
184 | pb1550_nand_pd.devwidth = 1; | ||
185 | /* fallthrough */ | ||
186 | case 1: | ||
187 | case 9: | ||
188 | case 3: | ||
189 | case 0xE: | ||
190 | case 0xF: | ||
191 | /* x8 NAND, already set up */ | ||
192 | platform_device_register(&pb1550_nand_dev); | ||
193 | } | ||
194 | } | ||
195 | |||
134 | static int __init pb1550_dev_init(void) | 196 | static int __init pb1550_dev_init(void) |
135 | { | 197 | { |
136 | int swapped; | 198 | int swapped; |
@@ -168,6 +230,10 @@ static int __init pb1550_dev_init(void) | |||
168 | AU1000_PCMCIA_IO_PHYS_ADDR + 0x008010000 - 1, | 230 | AU1000_PCMCIA_IO_PHYS_ADDR + 0x008010000 - 1, |
169 | AU1550_GPIO201_205_INT, AU1550_GPIO1_INT, 0, 0, 1); | 231 | AU1550_GPIO201_205_INT, AU1550_GPIO1_INT, 0, 0, 1); |
170 | 232 | ||
233 | /* NAND setup */ | ||
234 | gpio_direction_input(206); /* GPIO206 high */ | ||
235 | pb1550_nand_setup(); | ||
236 | |||
171 | swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_PB1550_SWAPBOOT; | 237 | swapped = bcsr_read(BCSR_STATUS) & BCSR_STATUS_PB1550_SWAPBOOT; |
172 | db1x_register_norflash(128 * 1024 * 1024, 4, swapped); | 238 | db1x_register_norflash(128 * 1024 * 1024, 4, swapped); |
173 | platform_device_register(&pb1550_pci_host); | 239 | platform_device_register(&pb1550_pci_host); |
diff --git a/arch/mips/include/asm/mach-au1x00/au1550nd.h b/arch/mips/include/asm/mach-au1x00/au1550nd.h new file mode 100644 index 00000000000..ad4c0a03afe --- /dev/null +++ b/arch/mips/include/asm/mach-au1x00/au1550nd.h | |||
@@ -0,0 +1,16 @@ | |||
1 | /* | ||
2 | * platform data for the Au1550 NAND driver | ||
3 | */ | ||
4 | |||
5 | #ifndef _AU1550ND_H_ | ||
6 | #define _AU1550ND_H_ | ||
7 | |||
8 | #include <linux/mtd/partitions.h> | ||
9 | |||
10 | struct au1550nd_platdata { | ||
11 | struct mtd_partition *parts; | ||
12 | int num_parts; | ||
13 | int devwidth; /* 0 = 8bit device, 1 = 16bit device */ | ||
14 | }; | ||
15 | |||
16 | #endif | ||
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c index 7dd3700f230..73abbc3e093 100644 --- a/drivers/mtd/nand/au1550nd.c +++ b/drivers/mtd/nand/au1550nd.c | |||
@@ -17,35 +17,19 @@ | |||
17 | #include <linux/mtd/mtd.h> | 17 | #include <linux/mtd/mtd.h> |
18 | #include <linux/mtd/nand.h> | 18 | #include <linux/mtd/nand.h> |
19 | #include <linux/mtd/partitions.h> | 19 | #include <linux/mtd/partitions.h> |
20 | #include <linux/platform_device.h> | ||
20 | #include <asm/io.h> | 21 | #include <asm/io.h> |
22 | #include <asm/mach-au1x00/au1000.h> | ||
23 | #include <asm/mach-au1x00/au1550nd.h> | ||
21 | 24 | ||
22 | #ifdef CONFIG_MIPS_PB1550 | ||
23 | #include <asm/mach-pb1x00/pb1550.h> | ||
24 | #elif defined(CONFIG_MIPS_DB1550) | ||
25 | #include <asm/mach-db1x00/db1x00.h> | ||
26 | #endif | ||
27 | #include <asm/mach-db1x00/bcsr.h> | ||
28 | 25 | ||
29 | /* | 26 | struct au1550nd_ctx { |
30 | * MTD structure for NAND controller | 27 | struct mtd_info info; |
31 | */ | 28 | struct nand_chip chip; |
32 | static struct mtd_info *au1550_mtd = NULL; | ||
33 | static void __iomem *p_nand; | ||
34 | static int nand_width = 1; /* default x8 */ | ||
35 | static void (*au1550_write_byte)(struct mtd_info *, u_char); | ||
36 | 29 | ||
37 | /* | 30 | int cs; |
38 | * Define partitions for flash device | 31 | void __iomem *base; |
39 | */ | 32 | void (*write_byte)(struct mtd_info *, u_char); |
40 | static const struct mtd_partition partition_info[] = { | ||
41 | { | ||
42 | .name = "NAND FS 0", | ||
43 | .offset = 0, | ||
44 | .size = 8 * 1024 * 1024}, | ||
45 | { | ||
46 | .name = "NAND FS 1", | ||
47 | .offset = MTDPART_OFS_APPEND, | ||
48 | .size = MTDPART_SIZ_FULL} | ||
49 | }; | 33 | }; |
50 | 34 | ||
51 | /** | 35 | /** |
@@ -259,24 +243,25 @@ static int au_verify_buf16(struct mtd_info *mtd, const u_char *buf, int len) | |||
259 | 243 | ||
260 | static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) | 244 | static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) |
261 | { | 245 | { |
262 | register struct nand_chip *this = mtd->priv; | 246 | struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info); |
247 | struct nand_chip *this = mtd->priv; | ||
263 | 248 | ||
264 | switch (cmd) { | 249 | switch (cmd) { |
265 | 250 | ||
266 | case NAND_CTL_SETCLE: | 251 | case NAND_CTL_SETCLE: |
267 | this->IO_ADDR_W = p_nand + MEM_STNAND_CMD; | 252 | this->IO_ADDR_W = ctx->base + MEM_STNAND_CMD; |
268 | break; | 253 | break; |
269 | 254 | ||
270 | case NAND_CTL_CLRCLE: | 255 | case NAND_CTL_CLRCLE: |
271 | this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; | 256 | this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA; |
272 | break; | 257 | break; |
273 | 258 | ||
274 | case NAND_CTL_SETALE: | 259 | case NAND_CTL_SETALE: |
275 | this->IO_ADDR_W = p_nand + MEM_STNAND_ADDR; | 260 | this->IO_ADDR_W = ctx->base + MEM_STNAND_ADDR; |
276 | break; | 261 | break; |
277 | 262 | ||
278 | case NAND_CTL_CLRALE: | 263 | case NAND_CTL_CLRALE: |
279 | this->IO_ADDR_W = p_nand + MEM_STNAND_DATA; | 264 | this->IO_ADDR_W = ctx->base + MEM_STNAND_DATA; |
280 | /* FIXME: Nobody knows why this is necessary, | 265 | /* FIXME: Nobody knows why this is necessary, |
281 | * but it works only that way */ | 266 | * but it works only that way */ |
282 | udelay(1); | 267 | udelay(1); |
@@ -284,7 +269,7 @@ static void au1550_hwcontrol(struct mtd_info *mtd, int cmd) | |||
284 | 269 | ||
285 | case NAND_CTL_SETNCE: | 270 | case NAND_CTL_SETNCE: |
286 | /* assert (force assert) chip enable */ | 271 | /* assert (force assert) chip enable */ |
287 | au_writel((1 << (4 + NAND_CS)), MEM_STNDCTL); | 272 | au_writel((1 << (4 + ctx->cs)), MEM_STNDCTL); |
288 | break; | 273 | break; |
289 | 274 | ||
290 | case NAND_CTL_CLRNCE: | 275 | case NAND_CTL_CLRNCE: |
@@ -331,9 +316,10 @@ static void au1550_select_chip(struct mtd_info *mtd, int chip) | |||
331 | */ | 316 | */ |
332 | static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) | 317 | static void au1550_command(struct mtd_info *mtd, unsigned command, int column, int page_addr) |
333 | { | 318 | { |
334 | register struct nand_chip *this = mtd->priv; | 319 | struct au1550nd_ctx *ctx = container_of(mtd, struct au1550nd_ctx, info); |
320 | struct nand_chip *this = mtd->priv; | ||
335 | int ce_override = 0, i; | 321 | int ce_override = 0, i; |
336 | ulong flags; | 322 | unsigned long flags = 0; |
337 | 323 | ||
338 | /* Begin command latch cycle */ | 324 | /* Begin command latch cycle */ |
339 | au1550_hwcontrol(mtd, NAND_CTL_SETCLE); | 325 | au1550_hwcontrol(mtd, NAND_CTL_SETCLE); |
@@ -354,9 +340,9 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i | |||
354 | column -= 256; | 340 | column -= 256; |
355 | readcmd = NAND_CMD_READ1; | 341 | readcmd = NAND_CMD_READ1; |
356 | } | 342 | } |
357 | au1550_write_byte(mtd, readcmd); | 343 | ctx->write_byte(mtd, readcmd); |
358 | } | 344 | } |
359 | au1550_write_byte(mtd, command); | 345 | ctx->write_byte(mtd, command); |
360 | 346 | ||
361 | /* Set ALE and clear CLE to start address cycle */ | 347 | /* Set ALE and clear CLE to start address cycle */ |
362 | au1550_hwcontrol(mtd, NAND_CTL_CLRCLE); | 348 | au1550_hwcontrol(mtd, NAND_CTL_CLRCLE); |
@@ -369,10 +355,10 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i | |||
369 | /* Adjust columns for 16 bit buswidth */ | 355 | /* Adjust columns for 16 bit buswidth */ |
370 | if (this->options & NAND_BUSWIDTH_16) | 356 | if (this->options & NAND_BUSWIDTH_16) |
371 | column >>= 1; | 357 | column >>= 1; |
372 | au1550_write_byte(mtd, column); | 358 | ctx->write_byte(mtd, column); |
373 | } | 359 | } |
374 | if (page_addr != -1) { | 360 | if (page_addr != -1) { |
375 | au1550_write_byte(mtd, (u8)(page_addr & 0xff)); | 361 | ctx->write_byte(mtd, (u8)(page_addr & 0xff)); |
376 | 362 | ||
377 | if (command == NAND_CMD_READ0 || | 363 | if (command == NAND_CMD_READ0 || |
378 | command == NAND_CMD_READ1 || | 364 | command == NAND_CMD_READ1 || |
@@ -390,11 +376,12 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i | |||
390 | au1550_hwcontrol(mtd, NAND_CTL_SETNCE); | 376 | au1550_hwcontrol(mtd, NAND_CTL_SETNCE); |
391 | } | 377 | } |
392 | 378 | ||
393 | au1550_write_byte(mtd, (u8)(page_addr >> 8)); | 379 | ctx->write_byte(mtd, (u8)(page_addr >> 8)); |
394 | 380 | ||
395 | /* One more address cycle for devices > 32MiB */ | 381 | /* One more address cycle for devices > 32MiB */ |
396 | if (this->chipsize > (32 << 20)) | 382 | if (this->chipsize > (32 << 20)) |
397 | au1550_write_byte(mtd, (u8)((page_addr >> 16) & 0x0f)); | 383 | ctx->write_byte(mtd, |
384 | ((page_addr >> 16) & 0x0f)); | ||
398 | } | 385 | } |
399 | /* Latch in address */ | 386 | /* Latch in address */ |
400 | au1550_hwcontrol(mtd, NAND_CTL_CLRALE); | 387 | au1550_hwcontrol(mtd, NAND_CTL_CLRALE); |
@@ -440,121 +427,79 @@ static void au1550_command(struct mtd_info *mtd, unsigned command, int column, i | |||
440 | while(!this->dev_ready(mtd)); | 427 | while(!this->dev_ready(mtd)); |
441 | } | 428 | } |
442 | 429 | ||
443 | 430 | static int __devinit find_nand_cs(unsigned long nand_base) | |
444 | /* | ||
445 | * Main initialization routine | ||
446 | */ | ||
447 | static int __init au1xxx_nand_init(void) | ||
448 | { | 431 | { |
449 | struct nand_chip *this; | 432 | void __iomem *base = |
450 | u16 boot_swapboot = 0; /* default value */ | 433 | (void __iomem *)KSEG1ADDR(AU1000_STATIC_MEM_PHYS_ADDR); |
451 | int retval; | 434 | unsigned long addr, staddr, start, mask, end; |
452 | u32 mem_staddr; | 435 | int i; |
453 | u32 nand_phys; | ||
454 | |||
455 | /* Allocate memory for MTD device structure and private data */ | ||
456 | au1550_mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); | ||
457 | if (!au1550_mtd) { | ||
458 | printk("Unable to allocate NAND MTD dev structure.\n"); | ||
459 | return -ENOMEM; | ||
460 | } | ||
461 | |||
462 | /* Get pointer to private data */ | ||
463 | this = (struct nand_chip *)(&au1550_mtd[1]); | ||
464 | |||
465 | /* Link the private data with the MTD structure */ | ||
466 | au1550_mtd->priv = this; | ||
467 | au1550_mtd->owner = THIS_MODULE; | ||
468 | |||
469 | 436 | ||
470 | /* MEM_STNDCTL: disable ints, disable nand boot */ | 437 | for (i = 0; i < 4; i++) { |
471 | au_writel(0, MEM_STNDCTL); | 438 | addr = 0x1000 + (i * 0x10); /* CSx */ |
439 | staddr = __raw_readl(base + addr + 0x08); /* STADDRx */ | ||
440 | /* figure out the decoded range of this CS */ | ||
441 | start = (staddr << 4) & 0xfffc0000; | ||
442 | mask = (staddr << 18) & 0xfffc0000; | ||
443 | end = (start | (start - 1)) & ~(start ^ mask); | ||
444 | if ((nand_base >= start) && (nand_base < end)) | ||
445 | return i; | ||
446 | } | ||
472 | 447 | ||
473 | #ifdef CONFIG_MIPS_PB1550 | 448 | return -ENODEV; |
474 | /* set gpio206 high */ | 449 | } |
475 | gpio_direction_input(206); | ||
476 | 450 | ||
477 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); | 451 | static int __devinit au1550nd_probe(struct platform_device *pdev) |
452 | { | ||
453 | struct au1550nd_platdata *pd; | ||
454 | struct au1550nd_ctx *ctx; | ||
455 | struct nand_chip *this; | ||
456 | struct resource *r; | ||
457 | int ret, cs; | ||
478 | 458 | ||
479 | switch (boot_swapboot) { | 459 | pd = pdev->dev.platform_data; |
480 | case 0: | 460 | if (!pd) { |
481 | case 2: | 461 | dev_err(&pdev->dev, "missing platform data\n"); |
482 | case 8: | 462 | return -ENODEV; |
483 | case 0xC: | ||
484 | case 0xD: | ||
485 | /* x16 NAND Flash */ | ||
486 | nand_width = 0; | ||
487 | break; | ||
488 | case 1: | ||
489 | case 9: | ||
490 | case 3: | ||
491 | case 0xE: | ||
492 | case 0xF: | ||
493 | /* x8 NAND Flash */ | ||
494 | nand_width = 1; | ||
495 | break; | ||
496 | default: | ||
497 | printk("Pb1550 NAND: bad boot:swap\n"); | ||
498 | retval = -EINVAL; | ||
499 | goto outmem; | ||
500 | } | 463 | } |
501 | #endif | 464 | |
502 | 465 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | |
503 | /* Configure chip-select; normally done by boot code, e.g. YAMON */ | 466 | if (!ctx) { |
504 | #ifdef NAND_STCFG | 467 | dev_err(&pdev->dev, "no memory for NAND context\n"); |
505 | if (NAND_CS == 0) { | 468 | return -ENOMEM; |
506 | au_writel(NAND_STCFG, MEM_STCFG0); | ||
507 | au_writel(NAND_STTIME, MEM_STTIME0); | ||
508 | au_writel(NAND_STADDR, MEM_STADDR0); | ||
509 | } | ||
510 | if (NAND_CS == 1) { | ||
511 | au_writel(NAND_STCFG, MEM_STCFG1); | ||
512 | au_writel(NAND_STTIME, MEM_STTIME1); | ||
513 | au_writel(NAND_STADDR, MEM_STADDR1); | ||
514 | } | 469 | } |
515 | if (NAND_CS == 2) { | 470 | |
516 | au_writel(NAND_STCFG, MEM_STCFG2); | 471 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
517 | au_writel(NAND_STTIME, MEM_STTIME2); | 472 | if (!r) { |
518 | au_writel(NAND_STADDR, MEM_STADDR2); | 473 | dev_err(&pdev->dev, "no NAND memory resource\n"); |
474 | ret = -ENODEV; | ||
475 | goto out1; | ||
519 | } | 476 | } |
520 | if (NAND_CS == 3) { | 477 | if (request_mem_region(r->start, resource_size(r), "au1550-nand")) { |
521 | au_writel(NAND_STCFG, MEM_STCFG3); | 478 | dev_err(&pdev->dev, "cannot claim NAND memory area\n"); |
522 | au_writel(NAND_STTIME, MEM_STTIME3); | 479 | ret = -ENOMEM; |
523 | au_writel(NAND_STADDR, MEM_STADDR3); | 480 | goto out1; |
524 | } | 481 | } |
525 | #endif | 482 | |
526 | 483 | ctx->base = ioremap_nocache(r->start, 0x1000); | |
527 | /* Locate NAND chip-select in order to determine NAND phys address */ | 484 | if (!ctx->base) { |
528 | mem_staddr = 0x00000000; | 485 | dev_err(&pdev->dev, "cannot remap NAND memory area\n"); |
529 | if (((au_readl(MEM_STCFG0) & 0x7) == 0x5) && (NAND_CS == 0)) | 486 | ret = -ENODEV; |
530 | mem_staddr = au_readl(MEM_STADDR0); | 487 | goto out2; |
531 | else if (((au_readl(MEM_STCFG1) & 0x7) == 0x5) && (NAND_CS == 1)) | ||
532 | mem_staddr = au_readl(MEM_STADDR1); | ||
533 | else if (((au_readl(MEM_STCFG2) & 0x7) == 0x5) && (NAND_CS == 2)) | ||
534 | mem_staddr = au_readl(MEM_STADDR2); | ||
535 | else if (((au_readl(MEM_STCFG3) & 0x7) == 0x5) && (NAND_CS == 3)) | ||
536 | mem_staddr = au_readl(MEM_STADDR3); | ||
537 | |||
538 | if (mem_staddr == 0x00000000) { | ||
539 | printk("Au1xxx NAND: ERROR WITH NAND CHIP-SELECT\n"); | ||
540 | kfree(au1550_mtd); | ||
541 | return 1; | ||
542 | } | 488 | } |
543 | nand_phys = (mem_staddr << 4) & 0xFFFC0000; | ||
544 | 489 | ||
545 | p_nand = ioremap(nand_phys, 0x1000); | 490 | this = &ctx->chip; |
491 | ctx->info.priv = this; | ||
492 | ctx->info.owner = THIS_MODULE; | ||
546 | 493 | ||
547 | /* make controller and MTD agree */ | 494 | /* figure out which CS# r->start belongs to */ |
548 | if (NAND_CS == 0) | 495 | cs = find_nand_cs(r->start); |
549 | nand_width = au_readl(MEM_STCFG0) & (1 << 22); | 496 | if (cs < 0) { |
550 | if (NAND_CS == 1) | 497 | dev_err(&pdev->dev, "cannot detect NAND chipselect\n"); |
551 | nand_width = au_readl(MEM_STCFG1) & (1 << 22); | 498 | ret = -ENODEV; |
552 | if (NAND_CS == 2) | 499 | goto out3; |
553 | nand_width = au_readl(MEM_STCFG2) & (1 << 22); | 500 | } |
554 | if (NAND_CS == 3) | 501 | ctx->cs = cs; |
555 | nand_width = au_readl(MEM_STCFG3) & (1 << 22); | ||
556 | 502 | ||
557 | /* Set address of hardware control function */ | ||
558 | this->dev_ready = au1550_device_ready; | 503 | this->dev_ready = au1550_device_ready; |
559 | this->select_chip = au1550_select_chip; | 504 | this->select_chip = au1550_select_chip; |
560 | this->cmdfunc = au1550_command; | 505 | this->cmdfunc = au1550_command; |
@@ -565,54 +510,57 @@ static int __init au1xxx_nand_init(void) | |||
565 | 510 | ||
566 | this->options = NAND_NO_AUTOINCR; | 511 | this->options = NAND_NO_AUTOINCR; |
567 | 512 | ||
568 | if (!nand_width) | 513 | if (pd->devwidth) |
569 | this->options |= NAND_BUSWIDTH_16; | 514 | this->options |= NAND_BUSWIDTH_16; |
570 | 515 | ||
571 | this->read_byte = (!nand_width) ? au_read_byte16 : au_read_byte; | 516 | this->read_byte = (pd->devwidth) ? au_read_byte16 : au_read_byte; |
572 | au1550_write_byte = (!nand_width) ? au_write_byte16 : au_write_byte; | 517 | ctx->write_byte = (pd->devwidth) ? au_write_byte16 : au_write_byte; |
573 | this->read_word = au_read_word; | 518 | this->read_word = au_read_word; |
574 | this->write_buf = (!nand_width) ? au_write_buf16 : au_write_buf; | 519 | this->write_buf = (pd->devwidth) ? au_write_buf16 : au_write_buf; |
575 | this->read_buf = (!nand_width) ? au_read_buf16 : au_read_buf; | 520 | this->read_buf = (pd->devwidth) ? au_read_buf16 : au_read_buf; |
576 | this->verify_buf = (!nand_width) ? au_verify_buf16 : au_verify_buf; | 521 | this->verify_buf = (pd->devwidth) ? au_verify_buf16 : au_verify_buf; |
577 | 522 | ||
578 | /* Scan to find existence of the device */ | 523 | ret = nand_scan(&ctx->info, 1); |
579 | if (nand_scan(au1550_mtd, 1)) { | 524 | if (ret) { |
580 | retval = -ENXIO; | 525 | dev_err(&pdev->dev, "NAND scan failed with %d\n", ret); |
581 | goto outio; | 526 | goto out3; |
582 | } | 527 | } |
583 | 528 | ||
584 | /* Register the partitions */ | 529 | mtd_device_register(&ctx->info, pd->parts, pd->num_parts); |
585 | mtd_device_register(au1550_mtd, partition_info, | ||
586 | ARRAY_SIZE(partition_info)); | ||
587 | 530 | ||
588 | return 0; | 531 | return 0; |
589 | 532 | ||
590 | outio: | 533 | out3: |
591 | iounmap(p_nand); | 534 | iounmap(ctx->base); |
592 | 535 | out2: | |
593 | outmem: | 536 | release_mem_region(r->start, resource_size(r)); |
594 | kfree(au1550_mtd); | 537 | out1: |
595 | return retval; | 538 | kfree(ctx); |
539 | return ret; | ||
596 | } | 540 | } |
597 | 541 | ||
598 | module_init(au1xxx_nand_init); | 542 | static int __devexit au1550nd_remove(struct platform_device *pdev) |
599 | |||
600 | /* | ||
601 | * Clean up routine | ||
602 | */ | ||
603 | static void __exit au1550_cleanup(void) | ||
604 | { | 543 | { |
605 | /* Release resources, unregister device */ | 544 | struct au1550nd_ctx *ctx = platform_get_drvdata(pdev); |
606 | nand_release(au1550_mtd); | 545 | struct resource *r = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
607 | 546 | ||
608 | /* Free the MTD device structure */ | 547 | nand_release(&ctx->info); |
609 | kfree(au1550_mtd); | 548 | iounmap(ctx->base); |
610 | 549 | release_mem_region(r->start, 0x1000); | |
611 | /* Unmap */ | 550 | kfree(ctx); |
612 | iounmap(p_nand); | 551 | return 0; |
613 | } | 552 | } |
614 | 553 | ||
615 | module_exit(au1550_cleanup); | 554 | static struct platform_driver au1550nd_driver = { |
555 | .driver = { | ||
556 | .name = "au1550-nand", | ||
557 | .owner = THIS_MODULE, | ||
558 | }, | ||
559 | .probe = au1550nd_probe, | ||
560 | .remove = __devexit_p(au1550nd_remove), | ||
561 | }; | ||
562 | |||
563 | module_platform_driver(au1550nd_driver); | ||
616 | 564 | ||
617 | MODULE_LICENSE("GPL"); | 565 | MODULE_LICENSE("GPL"); |
618 | MODULE_AUTHOR("Embedded Edge, LLC"); | 566 | MODULE_AUTHOR("Embedded Edge, LLC"); |