diff options
author | David Woodhouse <David.Woodhouse@intel.com> | 2008-12-10 10:49:12 -0500 |
---|---|---|
committer | David Woodhouse <David.Woodhouse@intel.com> | 2008-12-10 10:49:12 -0500 |
commit | c4956ed6fab26347ab1a712727da84b2501ab2dd (patch) | |
tree | 6ac59589a722faaa70a1865ff8050c5274ba0216 | |
parent | c80a7b265fedef584a1bb8baf92a5b289a66e039 (diff) | |
parent | 6af7a8eb1eb2b5a0967fccf61e750b085d60ad48 (diff) |
Merge branch 'misc/mtd/sharpsl-nand' of git://git.kernel.org/pub/scm/linux/kernel/git/lumag/tosa-2.6
-rw-r--r-- | arch/arm/mach-pxa/corgi.c | 54 | ||||
-rw-r--r-- | arch/arm/mach-pxa/poodle.c | 51 | ||||
-rw-r--r-- | arch/arm/mach-pxa/spitz.c | 77 | ||||
-rw-r--r-- | drivers/mtd/nand/sharpsl.c | 247 | ||||
-rw-r--r-- | include/linux/mtd/sharpsl.h | 20 |
5 files changed, 324 insertions, 125 deletions
diff --git a/arch/arm/mach-pxa/corgi.c b/arch/arm/mach-pxa/corgi.c index 65558d6aa220..b65be8e7792a 100644 --- a/arch/arm/mach-pxa/corgi.c +++ b/arch/arm/mach-pxa/corgi.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/spi/spi.h> | 26 | #include <linux/spi/spi.h> |
27 | #include <linux/spi/ads7846.h> | 27 | #include <linux/spi/ads7846.h> |
28 | #include <linux/spi/corgi_lcd.h> | 28 | #include <linux/spi/corgi_lcd.h> |
29 | #include <linux/mtd/sharpsl.h> | ||
29 | #include <video/w100fb.h> | 30 | #include <video/w100fb.h> |
30 | 31 | ||
31 | #include <asm/setup.h> | 32 | #include <asm/setup.h> |
@@ -541,11 +542,61 @@ err_free_1: | |||
541 | static inline void corgi_init_spi(void) {} | 542 | static inline void corgi_init_spi(void) {} |
542 | #endif | 543 | #endif |
543 | 544 | ||
545 | static struct mtd_partition sharpsl_nand_partitions[] = { | ||
546 | { | ||
547 | .name = "System Area", | ||
548 | .offset = 0, | ||
549 | .size = 7 * 1024 * 1024, | ||
550 | }, | ||
551 | { | ||
552 | .name = "Root Filesystem", | ||
553 | .offset = 7 * 1024 * 1024, | ||
554 | .size = 25 * 1024 * 1024, | ||
555 | }, | ||
556 | { | ||
557 | .name = "Home Filesystem", | ||
558 | .offset = MTDPART_OFS_APPEND, | ||
559 | .size = MTDPART_SIZ_FULL, | ||
560 | }, | ||
561 | }; | ||
562 | |||
563 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | ||
564 | |||
565 | static struct nand_bbt_descr sharpsl_bbt = { | ||
566 | .options = 0, | ||
567 | .offs = 4, | ||
568 | .len = 2, | ||
569 | .pattern = scan_ff_pattern | ||
570 | }; | ||
571 | |||
572 | static struct sharpsl_nand_platform_data sharpsl_nand_platform_data = { | ||
573 | .badblock_pattern = &sharpsl_bbt, | ||
574 | .partitions = sharpsl_nand_partitions, | ||
575 | .nr_partitions = ARRAY_SIZE(sharpsl_nand_partitions), | ||
576 | }; | ||
577 | |||
578 | static struct resource sharpsl_nand_resources[] = { | ||
579 | { | ||
580 | .start = 0x0C000000, | ||
581 | .end = 0x0C000FFF, | ||
582 | .flags = IORESOURCE_MEM, | ||
583 | }, | ||
584 | }; | ||
585 | |||
586 | static struct platform_device sharpsl_nand_device = { | ||
587 | .name = "sharpsl-nand", | ||
588 | .id = -1, | ||
589 | .resource = sharpsl_nand_resources, | ||
590 | .num_resources = ARRAY_SIZE(sharpsl_nand_resources), | ||
591 | .dev.platform_data = &sharpsl_nand_platform_data, | ||
592 | }; | ||
593 | |||
544 | static struct platform_device *devices[] __initdata = { | 594 | static struct platform_device *devices[] __initdata = { |
545 | &corgiscoop_device, | 595 | &corgiscoop_device, |
546 | &corgifb_device, | 596 | &corgifb_device, |
547 | &corgikbd_device, | 597 | &corgikbd_device, |
548 | &corgiled_device, | 598 | &corgiled_device, |
599 | &sharpsl_nand_device, | ||
549 | }; | 600 | }; |
550 | 601 | ||
551 | static void corgi_poweroff(void) | 602 | static void corgi_poweroff(void) |
@@ -585,6 +636,9 @@ static void __init corgi_init(void) | |||
585 | 636 | ||
586 | platform_scoop_config = &corgi_pcmcia_config; | 637 | platform_scoop_config = &corgi_pcmcia_config; |
587 | 638 | ||
639 | if (machine_is_husky()) | ||
640 | sharpsl_nand_partitions[1].size = 53 * 1024 * 1024; | ||
641 | |||
588 | platform_add_devices(devices, ARRAY_SIZE(devices)); | 642 | platform_add_devices(devices, ARRAY_SIZE(devices)); |
589 | } | 643 | } |
590 | 644 | ||
diff --git a/arch/arm/mach-pxa/poodle.c b/arch/arm/mach-pxa/poodle.c index 2e3bd8b1523b..a45afdf25202 100644 --- a/arch/arm/mach-pxa/poodle.c +++ b/arch/arm/mach-pxa/poodle.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/gpio.h> | 23 | #include <linux/gpio.h> |
24 | #include <linux/spi/spi.h> | 24 | #include <linux/spi/spi.h> |
25 | #include <linux/spi/ads7846.h> | 25 | #include <linux/spi/ads7846.h> |
26 | #include <linux/mtd/sharpsl.h> | ||
26 | 27 | ||
27 | #include <mach/hardware.h> | 28 | #include <mach/hardware.h> |
28 | #include <asm/mach-types.h> | 29 | #include <asm/mach-types.h> |
@@ -413,9 +414,59 @@ static struct pxafb_mach_info poodle_fb_info = { | |||
413 | .lcd_conn = LCD_COLOR_TFT_16BPP, | 414 | .lcd_conn = LCD_COLOR_TFT_16BPP, |
414 | }; | 415 | }; |
415 | 416 | ||
417 | static struct mtd_partition sharpsl_nand_partitions[] = { | ||
418 | { | ||
419 | .name = "System Area", | ||
420 | .offset = 0, | ||
421 | .size = 7 * 1024 * 1024, | ||
422 | }, | ||
423 | { | ||
424 | .name = "Root Filesystem", | ||
425 | .offset = 7 * 1024 * 1024, | ||
426 | .size = 22 * 1024 * 1024, | ||
427 | }, | ||
428 | { | ||
429 | .name = "Home Filesystem", | ||
430 | .offset = MTDPART_OFS_APPEND, | ||
431 | .size = MTDPART_SIZ_FULL, | ||
432 | }, | ||
433 | }; | ||
434 | |||
435 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | ||
436 | |||
437 | static struct nand_bbt_descr sharpsl_bbt = { | ||
438 | .options = 0, | ||
439 | .offs = 4, | ||
440 | .len = 2, | ||
441 | .pattern = scan_ff_pattern | ||
442 | }; | ||
443 | |||
444 | static struct sharpsl_nand_platform_data sharpsl_nand_platform_data = { | ||
445 | .badblock_pattern = &sharpsl_bbt, | ||
446 | .partitions = sharpsl_nand_partitions, | ||
447 | .nr_partitions = ARRAY_SIZE(sharpsl_nand_partitions), | ||
448 | }; | ||
449 | |||
450 | static struct resource sharpsl_nand_resources[] = { | ||
451 | { | ||
452 | .start = 0x0C000000, | ||
453 | .end = 0x0C000FFF, | ||
454 | .flags = IORESOURCE_MEM, | ||
455 | }, | ||
456 | }; | ||
457 | |||
458 | static struct platform_device sharpsl_nand_device = { | ||
459 | .name = "sharpsl-nand", | ||
460 | .id = -1, | ||
461 | .resource = sharpsl_nand_resources, | ||
462 | .num_resources = ARRAY_SIZE(sharpsl_nand_resources), | ||
463 | .dev.platform_data = &sharpsl_nand_platform_data, | ||
464 | }; | ||
465 | |||
416 | static struct platform_device *devices[] __initdata = { | 466 | static struct platform_device *devices[] __initdata = { |
417 | &poodle_locomo_device, | 467 | &poodle_locomo_device, |
418 | &poodle_scoop_device, | 468 | &poodle_scoop_device, |
469 | &sharpsl_nand_device, | ||
419 | }; | 470 | }; |
420 | 471 | ||
421 | static void poodle_poweroff(void) | 472 | static void poodle_poweroff(void) |
diff --git a/arch/arm/mach-pxa/spitz.c b/arch/arm/mach-pxa/spitz.c index 3be76ee2bdbf..7672b09c31b9 100644 --- a/arch/arm/mach-pxa/spitz.c +++ b/arch/arm/mach-pxa/spitz.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/spi/spi.h> | 30 | #include <linux/spi/spi.h> |
31 | #include <linux/spi/ads7846.h> | 31 | #include <linux/spi/ads7846.h> |
32 | #include <linux/spi/corgi_lcd.h> | 32 | #include <linux/spi/corgi_lcd.h> |
33 | #include <linux/mtd/sharpsl.h> | ||
33 | 34 | ||
34 | #include <asm/setup.h> | 35 | #include <asm/setup.h> |
35 | #include <asm/memory.h> | 36 | #include <asm/memory.h> |
@@ -608,11 +609,60 @@ static struct pxafb_mach_info spitz_pxafb_info = { | |||
608 | .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING, | 609 | .lcd_conn = LCD_COLOR_TFT_16BPP | LCD_ALTERNATE_MAPPING, |
609 | }; | 610 | }; |
610 | 611 | ||
612 | static struct mtd_partition sharpsl_nand_partitions[] = { | ||
613 | { | ||
614 | .name = "System Area", | ||
615 | .offset = 0, | ||
616 | .size = 7 * 1024 * 1024, | ||
617 | }, | ||
618 | { | ||
619 | .name = "Root Filesystem", | ||
620 | .offset = 7 * 1024 * 1024, | ||
621 | }, | ||
622 | { | ||
623 | .name = "Home Filesystem", | ||
624 | .offset = MTDPART_OFS_APPEND, | ||
625 | .size = MTDPART_SIZ_FULL, | ||
626 | }, | ||
627 | }; | ||
628 | |||
629 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | ||
630 | |||
631 | static struct nand_bbt_descr sharpsl_bbt = { | ||
632 | .options = 0, | ||
633 | .offs = 4, | ||
634 | .len = 2, | ||
635 | .pattern = scan_ff_pattern | ||
636 | }; | ||
637 | |||
638 | static struct sharpsl_nand_platform_data sharpsl_nand_platform_data = { | ||
639 | .badblock_pattern = &sharpsl_bbt, | ||
640 | .partitions = sharpsl_nand_partitions, | ||
641 | .nr_partitions = ARRAY_SIZE(sharpsl_nand_partitions), | ||
642 | }; | ||
643 | |||
644 | static struct resource sharpsl_nand_resources[] = { | ||
645 | { | ||
646 | .start = 0x0C000000, | ||
647 | .end = 0x0C000FFF, | ||
648 | .flags = IORESOURCE_MEM, | ||
649 | }, | ||
650 | }; | ||
651 | |||
652 | static struct platform_device sharpsl_nand_device = { | ||
653 | .name = "sharpsl-nand", | ||
654 | .id = -1, | ||
655 | .resource = sharpsl_nand_resources, | ||
656 | .num_resources = ARRAY_SIZE(sharpsl_nand_resources), | ||
657 | .dev.platform_data = &sharpsl_nand_platform_data, | ||
658 | }; | ||
659 | |||
611 | 660 | ||
612 | static struct platform_device *devices[] __initdata = { | 661 | static struct platform_device *devices[] __initdata = { |
613 | &spitzscoop_device, | 662 | &spitzscoop_device, |
614 | &spitzkbd_device, | 663 | &spitzkbd_device, |
615 | &spitzled_device, | 664 | &spitzled_device, |
665 | &sharpsl_nand_device, | ||
616 | }; | 666 | }; |
617 | 667 | ||
618 | static void spitz_poweroff(void) | 668 | static void spitz_poweroff(void) |
@@ -635,6 +685,14 @@ static void __init common_init(void) | |||
635 | pm_power_off = spitz_poweroff; | 685 | pm_power_off = spitz_poweroff; |
636 | arm_pm_restart = spitz_restart; | 686 | arm_pm_restart = spitz_restart; |
637 | 687 | ||
688 | if (machine_is_spitz()) { | ||
689 | sharpsl_nand_partitions[1].size = 5 * 1024 * 1024; | ||
690 | } else if (machine_is_akita()) { | ||
691 | sharpsl_nand_partitions[1].size = 58 * 1024 * 1024; | ||
692 | } else if (machine_is_borzoi()) { | ||
693 | sharpsl_nand_partitions[1].size = 32 * 1024 * 1024; | ||
694 | } | ||
695 | |||
638 | PMCR = 0x00; | 696 | PMCR = 0x00; |
639 | 697 | ||
640 | /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */ | 698 | /* Stop 3.6MHz and drive HIGH to PCMCIA and CS */ |
@@ -679,10 +737,29 @@ static struct i2c_board_info akita_i2c_board_info[] = { | |||
679 | }, | 737 | }, |
680 | }; | 738 | }; |
681 | 739 | ||
740 | static struct nand_bbt_descr sharpsl_akita_bbt = { | ||
741 | .options = 0, | ||
742 | .offs = 4, | ||
743 | .len = 1, | ||
744 | .pattern = scan_ff_pattern | ||
745 | }; | ||
746 | |||
747 | static struct nand_ecclayout akita_oobinfo = { | ||
748 | .eccbytes = 24, | ||
749 | .eccpos = { | ||
750 | 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, | ||
751 | 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, | ||
752 | 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, | ||
753 | .oobfree = {{0x08, 0x09}} | ||
754 | }; | ||
755 | |||
682 | static void __init akita_init(void) | 756 | static void __init akita_init(void) |
683 | { | 757 | { |
684 | spitz_ficp_platform_data.transceiver_mode = akita_irda_transceiver_mode; | 758 | spitz_ficp_platform_data.transceiver_mode = akita_irda_transceiver_mode; |
685 | 759 | ||
760 | sharpsl_nand_platform_data.badblock_pattern = &sharpsl_akita_bbt; | ||
761 | sharpsl_nand_platform_data.ecc_layout = &akita_oobinfo; | ||
762 | |||
686 | /* We just pretend the second element of the array doesn't exist */ | 763 | /* We just pretend the second element of the array doesn't exist */ |
687 | spitz_pcmcia_config.num_devs = 1; | 764 | spitz_pcmcia_config.num_devs = 1; |
688 | platform_scoop_config = &spitz_pcmcia_config; | 765 | platform_scoop_config = &spitz_pcmcia_config; |
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c index 30a518e211bd..54ec7542a7b7 100644 --- a/drivers/mtd/nand/sharpsl.c +++ b/drivers/mtd/nand/sharpsl.c | |||
@@ -2,6 +2,7 @@ | |||
2 | * drivers/mtd/nand/sharpsl.c | 2 | * drivers/mtd/nand/sharpsl.c |
3 | * | 3 | * |
4 | * Copyright (C) 2004 Richard Purdie | 4 | * Copyright (C) 2004 Richard Purdie |
5 | * Copyright (C) 2008 Dmitry Baryshkov | ||
5 | * | 6 | * |
6 | * Based on Sharp's NAND driver sharp_sl.c | 7 | * Based on Sharp's NAND driver sharp_sl.c |
7 | * | 8 | * |
@@ -19,22 +20,31 @@ | |||
19 | #include <linux/mtd/nand.h> | 20 | #include <linux/mtd/nand.h> |
20 | #include <linux/mtd/nand_ecc.h> | 21 | #include <linux/mtd/nand_ecc.h> |
21 | #include <linux/mtd/partitions.h> | 22 | #include <linux/mtd/partitions.h> |
23 | #include <linux/mtd/sharpsl.h> | ||
22 | #include <linux/interrupt.h> | 24 | #include <linux/interrupt.h> |
25 | #include <linux/platform_device.h> | ||
26 | |||
23 | #include <asm/io.h> | 27 | #include <asm/io.h> |
24 | #include <mach/hardware.h> | 28 | #include <mach/hardware.h> |
25 | #include <asm/mach-types.h> | 29 | #include <asm/mach-types.h> |
26 | 30 | ||
27 | static void __iomem *sharpsl_io_base; | 31 | struct sharpsl_nand { |
28 | static int sharpsl_phys_base = 0x0C000000; | 32 | struct mtd_info mtd; |
33 | struct nand_chip chip; | ||
34 | |||
35 | void __iomem *io; | ||
36 | }; | ||
37 | |||
38 | #define mtd_to_sharpsl(_mtd) container_of(_mtd, struct sharpsl_nand, mtd) | ||
29 | 39 | ||
30 | /* register offset */ | 40 | /* register offset */ |
31 | #define ECCLPLB sharpsl_io_base+0x00 /* line parity 7 - 0 bit */ | 41 | #define ECCLPLB 0x00 /* line parity 7 - 0 bit */ |
32 | #define ECCLPUB sharpsl_io_base+0x04 /* line parity 15 - 8 bit */ | 42 | #define ECCLPUB 0x04 /* line parity 15 - 8 bit */ |
33 | #define ECCCP sharpsl_io_base+0x08 /* column parity 5 - 0 bit */ | 43 | #define ECCCP 0x08 /* column parity 5 - 0 bit */ |
34 | #define ECCCNTR sharpsl_io_base+0x0C /* ECC byte counter */ | 44 | #define ECCCNTR 0x0C /* ECC byte counter */ |
35 | #define ECCCLRR sharpsl_io_base+0x10 /* cleare ECC */ | 45 | #define ECCCLRR 0x10 /* cleare ECC */ |
36 | #define FLASHIO sharpsl_io_base+0x14 /* Flash I/O */ | 46 | #define FLASHIO 0x14 /* Flash I/O */ |
37 | #define FLASHCTL sharpsl_io_base+0x18 /* Flash Control */ | 47 | #define FLASHCTL 0x18 /* Flash Control */ |
38 | 48 | ||
39 | /* Flash control bit */ | 49 | /* Flash control bit */ |
40 | #define FLRYBY (1 << 5) | 50 | #define FLRYBY (1 << 5) |
@@ -45,35 +55,6 @@ static int sharpsl_phys_base = 0x0C000000; | |||
45 | #define FLCE0 (1 << 0) | 55 | #define FLCE0 (1 << 0) |
46 | 56 | ||
47 | /* | 57 | /* |
48 | * MTD structure for SharpSL | ||
49 | */ | ||
50 | static struct mtd_info *sharpsl_mtd = NULL; | ||
51 | |||
52 | /* | ||
53 | * Define partitions for flash device | ||
54 | */ | ||
55 | #define DEFAULT_NUM_PARTITIONS 3 | ||
56 | |||
57 | static int nr_partitions; | ||
58 | static struct mtd_partition sharpsl_nand_default_partition_info[] = { | ||
59 | { | ||
60 | .name = "System Area", | ||
61 | .offset = 0, | ||
62 | .size = 7 * 1024 * 1024, | ||
63 | }, | ||
64 | { | ||
65 | .name = "Root Filesystem", | ||
66 | .offset = 7 * 1024 * 1024, | ||
67 | .size = 30 * 1024 * 1024, | ||
68 | }, | ||
69 | { | ||
70 | .name = "Home Filesystem", | ||
71 | .offset = MTDPART_OFS_APPEND, | ||
72 | .size = MTDPART_SIZ_FULL, | ||
73 | }, | ||
74 | }; | ||
75 | |||
76 | /* | ||
77 | * hardware specific access to control-lines | 58 | * hardware specific access to control-lines |
78 | * ctrl: | 59 | * ctrl: |
79 | * NAND_CNE: bit 0 -> ! bit 0 & 4 | 60 | * NAND_CNE: bit 0 -> ! bit 0 & 4 |
@@ -84,6 +65,7 @@ static struct mtd_partition sharpsl_nand_default_partition_info[] = { | |||
84 | static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, | 65 | static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, |
85 | unsigned int ctrl) | 66 | unsigned int ctrl) |
86 | { | 67 | { |
68 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); | ||
87 | struct nand_chip *chip = mtd->priv; | 69 | struct nand_chip *chip = mtd->priv; |
88 | 70 | ||
89 | if (ctrl & NAND_CTRL_CHANGE) { | 71 | if (ctrl & NAND_CTRL_CHANGE) { |
@@ -93,103 +75,97 @@ static void sharpsl_nand_hwcontrol(struct mtd_info *mtd, int cmd, | |||
93 | 75 | ||
94 | bits ^= 0x11; | 76 | bits ^= 0x11; |
95 | 77 | ||
96 | writeb((readb(FLASHCTL) & ~0x17) | bits, FLASHCTL); | 78 | writeb((readb(sharpsl->io + FLASHCTL) & ~0x17) | bits, sharpsl->io + FLASHCTL); |
97 | } | 79 | } |
98 | 80 | ||
99 | if (cmd != NAND_CMD_NONE) | 81 | if (cmd != NAND_CMD_NONE) |
100 | writeb(cmd, chip->IO_ADDR_W); | 82 | writeb(cmd, chip->IO_ADDR_W); |
101 | } | 83 | } |
102 | 84 | ||
103 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | ||
104 | |||
105 | static struct nand_bbt_descr sharpsl_bbt = { | ||
106 | .options = 0, | ||
107 | .offs = 4, | ||
108 | .len = 2, | ||
109 | .pattern = scan_ff_pattern | ||
110 | }; | ||
111 | |||
112 | static struct nand_bbt_descr sharpsl_akita_bbt = { | ||
113 | .options = 0, | ||
114 | .offs = 4, | ||
115 | .len = 1, | ||
116 | .pattern = scan_ff_pattern | ||
117 | }; | ||
118 | |||
119 | static struct nand_ecclayout akita_oobinfo = { | ||
120 | .eccbytes = 24, | ||
121 | .eccpos = { | ||
122 | 0x5, 0x1, 0x2, 0x3, 0x6, 0x7, 0x15, 0x11, | ||
123 | 0x12, 0x13, 0x16, 0x17, 0x25, 0x21, 0x22, 0x23, | ||
124 | 0x26, 0x27, 0x35, 0x31, 0x32, 0x33, 0x36, 0x37}, | ||
125 | .oobfree = {{0x08, 0x09}} | ||
126 | }; | ||
127 | |||
128 | static int sharpsl_nand_dev_ready(struct mtd_info *mtd) | 85 | static int sharpsl_nand_dev_ready(struct mtd_info *mtd) |
129 | { | 86 | { |
130 | return !((readb(FLASHCTL) & FLRYBY) == 0); | 87 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
88 | return !((readb(sharpsl->io + FLASHCTL) & FLRYBY) == 0); | ||
131 | } | 89 | } |
132 | 90 | ||
133 | static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode) | 91 | static void sharpsl_nand_enable_hwecc(struct mtd_info *mtd, int mode) |
134 | { | 92 | { |
135 | writeb(0, ECCCLRR); | 93 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
94 | writeb(0, sharpsl->io + ECCCLRR); | ||
136 | } | 95 | } |
137 | 96 | ||
138 | static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code) | 97 | static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat, u_char * ecc_code) |
139 | { | 98 | { |
140 | ecc_code[0] = ~readb(ECCLPUB); | 99 | struct sharpsl_nand *sharpsl = mtd_to_sharpsl(mtd); |
141 | ecc_code[1] = ~readb(ECCLPLB); | 100 | ecc_code[0] = ~readb(sharpsl->io + ECCLPUB); |
142 | ecc_code[2] = (~readb(ECCCP) << 2) | 0x03; | 101 | ecc_code[1] = ~readb(sharpsl->io + ECCLPLB); |
143 | return readb(ECCCNTR) != 0; | 102 | ecc_code[2] = (~readb(sharpsl->io + ECCCP) << 2) | 0x03; |
103 | return readb(sharpsl->io + ECCCNTR) != 0; | ||
144 | } | 104 | } |
145 | 105 | ||
146 | #ifdef CONFIG_MTD_PARTITIONS | 106 | #ifdef CONFIG_MTD_PARTITIONS |
147 | const char *part_probes[] = { "cmdlinepart", NULL }; | 107 | static const char *part_probes[] = { "cmdlinepart", NULL }; |
148 | #endif | 108 | #endif |
149 | 109 | ||
150 | /* | 110 | /* |
151 | * Main initialization routine | 111 | * Main initialization routine |
152 | */ | 112 | */ |
153 | static int __init sharpsl_nand_init(void) | 113 | static int __devinit sharpsl_nand_probe(struct platform_device *pdev) |
154 | { | 114 | { |
155 | struct nand_chip *this; | 115 | struct nand_chip *this; |
116 | #ifdef CONFIG_MTD_PARTITIONS | ||
156 | struct mtd_partition *sharpsl_partition_info; | 117 | struct mtd_partition *sharpsl_partition_info; |
118 | int nr_partitions; | ||
119 | #endif | ||
120 | struct resource *r; | ||
157 | int err = 0; | 121 | int err = 0; |
122 | struct sharpsl_nand *sharpsl; | ||
123 | struct sharpsl_nand_platform_data *data = pdev->dev.platform_data; | ||
124 | |||
125 | if (!data) { | ||
126 | dev_err(&pdev->dev, "no platform data!\n"); | ||
127 | return -EINVAL; | ||
128 | } | ||
158 | 129 | ||
159 | /* Allocate memory for MTD device structure and private data */ | 130 | /* Allocate memory for MTD device structure and private data */ |
160 | sharpsl_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); | 131 | sharpsl = kzalloc(sizeof(struct sharpsl_nand), GFP_KERNEL); |
161 | if (!sharpsl_mtd) { | 132 | if (!sharpsl) { |
162 | printk("Unable to allocate SharpSL NAND MTD device structure.\n"); | 133 | printk("Unable to allocate SharpSL NAND MTD device structure.\n"); |
163 | return -ENOMEM; | 134 | return -ENOMEM; |
164 | } | 135 | } |
165 | 136 | ||
137 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
138 | if (!r) { | ||
139 | dev_err(&pdev->dev, "no io memory resource defined!\n"); | ||
140 | err = -ENODEV; | ||
141 | goto err_get_res; | ||
142 | } | ||
143 | |||
166 | /* map physical address */ | 144 | /* map physical address */ |
167 | sharpsl_io_base = ioremap(sharpsl_phys_base, 0x1000); | 145 | sharpsl->io = ioremap(r->start, resource_size(r)); |
168 | if (!sharpsl_io_base) { | 146 | if (!sharpsl->io) { |
169 | printk("ioremap to access Sharp SL NAND chip failed\n"); | 147 | printk("ioremap to access Sharp SL NAND chip failed\n"); |
170 | kfree(sharpsl_mtd); | 148 | err = -EIO; |
171 | return -EIO; | 149 | goto err_ioremap; |
172 | } | 150 | } |
173 | 151 | ||
174 | /* Get pointer to private data */ | 152 | /* Get pointer to private data */ |
175 | this = (struct nand_chip *)(&sharpsl_mtd[1]); | 153 | this = (struct nand_chip *)(&sharpsl->chip); |
176 | |||
177 | /* Initialize structures */ | ||
178 | memset(sharpsl_mtd, 0, sizeof(struct mtd_info)); | ||
179 | memset(this, 0, sizeof(struct nand_chip)); | ||
180 | 154 | ||
181 | /* Link the private data with the MTD structure */ | 155 | /* Link the private data with the MTD structure */ |
182 | sharpsl_mtd->priv = this; | 156 | sharpsl->mtd.priv = this; |
183 | sharpsl_mtd->owner = THIS_MODULE; | 157 | sharpsl->mtd.owner = THIS_MODULE; |
158 | |||
159 | platform_set_drvdata(pdev, sharpsl); | ||
184 | 160 | ||
185 | /* | 161 | /* |
186 | * PXA initialize | 162 | * PXA initialize |
187 | */ | 163 | */ |
188 | writeb(readb(FLASHCTL) | FLWP, FLASHCTL); | 164 | writeb(readb(sharpsl->io + FLASHCTL) | FLWP, sharpsl->io + FLASHCTL); |
189 | 165 | ||
190 | /* Set address of NAND IO lines */ | 166 | /* Set address of NAND IO lines */ |
191 | this->IO_ADDR_R = FLASHIO; | 167 | this->IO_ADDR_R = sharpsl->io + FLASHIO; |
192 | this->IO_ADDR_W = FLASHIO; | 168 | this->IO_ADDR_W = sharpsl->io + FLASHIO; |
193 | /* Set address of hardware control function */ | 169 | /* Set address of hardware control function */ |
194 | this->cmd_ctrl = sharpsl_nand_hwcontrol; | 170 | this->cmd_ctrl = sharpsl_nand_hwcontrol; |
195 | this->dev_ready = sharpsl_nand_dev_ready; | 171 | this->dev_ready = sharpsl_nand_dev_ready; |
@@ -199,68 +175,89 @@ static int __init sharpsl_nand_init(void) | |||
199 | this->ecc.mode = NAND_ECC_HW; | 175 | this->ecc.mode = NAND_ECC_HW; |
200 | this->ecc.size = 256; | 176 | this->ecc.size = 256; |
201 | this->ecc.bytes = 3; | 177 | this->ecc.bytes = 3; |
202 | this->badblock_pattern = &sharpsl_bbt; | 178 | this->badblock_pattern = data->badblock_pattern; |
203 | if (machine_is_akita() || machine_is_borzoi()) { | 179 | this->ecc.layout = data->ecc_layout; |
204 | this->badblock_pattern = &sharpsl_akita_bbt; | ||
205 | this->ecc.layout = &akita_oobinfo; | ||
206 | } | ||
207 | this->ecc.hwctl = sharpsl_nand_enable_hwecc; | 180 | this->ecc.hwctl = sharpsl_nand_enable_hwecc; |
208 | this->ecc.calculate = sharpsl_nand_calculate_ecc; | 181 | this->ecc.calculate = sharpsl_nand_calculate_ecc; |
209 | this->ecc.correct = nand_correct_data; | 182 | this->ecc.correct = nand_correct_data; |
210 | 183 | ||
211 | /* Scan to find existence of the device */ | 184 | /* Scan to find existence of the device */ |
212 | err = nand_scan(sharpsl_mtd, 1); | 185 | err = nand_scan(&sharpsl->mtd, 1); |
213 | if (err) { | 186 | if (err) |
214 | iounmap(sharpsl_io_base); | 187 | goto err_scan; |
215 | kfree(sharpsl_mtd); | ||
216 | return err; | ||
217 | } | ||
218 | 188 | ||
219 | /* Register the partitions */ | 189 | /* Register the partitions */ |
220 | sharpsl_mtd->name = "sharpsl-nand"; | 190 | sharpsl->mtd.name = "sharpsl-nand"; |
221 | nr_partitions = parse_mtd_partitions(sharpsl_mtd, part_probes, &sharpsl_partition_info, 0); | 191 | #ifdef CONFIG_MTD_PARTITIONS |
222 | 192 | nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0); | |
223 | if (nr_partitions <= 0) { | 193 | if (nr_partitions <= 0) { |
224 | nr_partitions = DEFAULT_NUM_PARTITIONS; | 194 | nr_partitions = data->nr_partitions; |
225 | sharpsl_partition_info = sharpsl_nand_default_partition_info; | 195 | sharpsl_partition_info = data->partitions; |
226 | if (machine_is_poodle()) { | ||
227 | sharpsl_partition_info[1].size = 22 * 1024 * 1024; | ||
228 | } else if (machine_is_corgi() || machine_is_shepherd()) { | ||
229 | sharpsl_partition_info[1].size = 25 * 1024 * 1024; | ||
230 | } else if (machine_is_husky()) { | ||
231 | sharpsl_partition_info[1].size = 53 * 1024 * 1024; | ||
232 | } else if (machine_is_spitz()) { | ||
233 | sharpsl_partition_info[1].size = 5 * 1024 * 1024; | ||
234 | } else if (machine_is_akita()) { | ||
235 | sharpsl_partition_info[1].size = 58 * 1024 * 1024; | ||
236 | } else if (machine_is_borzoi()) { | ||
237 | sharpsl_partition_info[1].size = 32 * 1024 * 1024; | ||
238 | } | ||
239 | } | 196 | } |
240 | 197 | ||
241 | add_mtd_partitions(sharpsl_mtd, sharpsl_partition_info, nr_partitions); | 198 | if (nr_partitions > 0) |
199 | err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); | ||
200 | else | ||
201 | #endif | ||
202 | err = add_mtd_device(&sharpsl->mtd); | ||
203 | if (err) | ||
204 | goto err_add; | ||
242 | 205 | ||
243 | /* Return happy */ | 206 | /* Return happy */ |
244 | return 0; | 207 | return 0; |
245 | } | ||
246 | 208 | ||
247 | module_init(sharpsl_nand_init); | 209 | err_add: |
210 | nand_release(&sharpsl->mtd); | ||
211 | |||
212 | err_scan: | ||
213 | platform_set_drvdata(pdev, NULL); | ||
214 | iounmap(sharpsl->io); | ||
215 | err_ioremap: | ||
216 | err_get_res: | ||
217 | kfree(sharpsl); | ||
218 | return err; | ||
219 | } | ||
248 | 220 | ||
249 | /* | 221 | /* |
250 | * Clean up routine | 222 | * Clean up routine |
251 | */ | 223 | */ |
252 | static void __exit sharpsl_nand_cleanup(void) | 224 | static int __devexit sharpsl_nand_remove(struct platform_device *pdev) |
253 | { | 225 | { |
226 | struct sharpsl_nand *sharpsl = platform_get_drvdata(pdev); | ||
227 | |||
254 | /* Release resources, unregister device */ | 228 | /* Release resources, unregister device */ |
255 | nand_release(sharpsl_mtd); | 229 | nand_release(&sharpsl->mtd); |
256 | 230 | ||
257 | iounmap(sharpsl_io_base); | 231 | platform_set_drvdata(pdev, NULL); |
232 | |||
233 | iounmap(sharpsl->io); | ||
258 | 234 | ||
259 | /* Free the MTD device structure */ | 235 | /* Free the MTD device structure */ |
260 | kfree(sharpsl_mtd); | 236 | kfree(sharpsl); |
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static struct platform_driver sharpsl_nand_driver = { | ||
242 | .driver = { | ||
243 | .name = "sharpsl-nand", | ||
244 | .owner = THIS_MODULE, | ||
245 | }, | ||
246 | .probe = sharpsl_nand_probe, | ||
247 | .remove = __devexit_p(sharpsl_nand_remove), | ||
248 | }; | ||
249 | |||
250 | static int __init sharpsl_nand_init(void) | ||
251 | { | ||
252 | return platform_driver_register(&sharpsl_nand_driver); | ||
261 | } | 253 | } |
254 | module_init(sharpsl_nand_init); | ||
262 | 255 | ||
263 | module_exit(sharpsl_nand_cleanup); | 256 | static void __exit sharpsl_nand_exit(void) |
257 | { | ||
258 | platform_driver_unregister(&sharpsl_nand_driver); | ||
259 | } | ||
260 | module_exit(sharpsl_nand_exit); | ||
264 | 261 | ||
265 | MODULE_LICENSE("GPL"); | 262 | MODULE_LICENSE("GPL"); |
266 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); | 263 | MODULE_AUTHOR("Richard Purdie <rpurdie@rpsys.net>"); |
diff --git a/include/linux/mtd/sharpsl.h b/include/linux/mtd/sharpsl.h new file mode 100644 index 000000000000..25f4d2a845c1 --- /dev/null +++ b/include/linux/mtd/sharpsl.h | |||
@@ -0,0 +1,20 @@ | |||
1 | /* | ||
2 | * SharpSL NAND support | ||
3 | * | ||
4 | * Copyright (C) 2008 Dmitry Baryshkov | ||
5 | * | ||
6 | * 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 | #include <linux/mtd/nand.h> | ||
12 | #include <linux/mtd/nand_ecc.h> | ||
13 | #include <linux/mtd/partitions.h> | ||
14 | |||
15 | struct sharpsl_nand_platform_data { | ||
16 | struct nand_bbt_descr *badblock_pattern; | ||
17 | struct nand_ecclayout *ecc_layout; | ||
18 | struct mtd_partition *partitions; | ||
19 | unsigned int nr_partitions; | ||
20 | }; | ||