aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/mtd/Kconfig6
-rw-r--r--drivers/mtd/Makefile1
-rw-r--r--drivers/mtd/ar7part.c151
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c19
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c30
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c15
-rw-r--r--drivers/mtd/chips/cfi_probe.c7
-rw-r--r--drivers/mtd/chips/cfi_util.c2
-rw-r--r--drivers/mtd/chips/jedec_probe.c73
-rw-r--r--drivers/mtd/cmdlinepart.c15
-rw-r--r--drivers/mtd/devices/Kconfig7
-rw-r--r--drivers/mtd/devices/block2mtd.c10
-rw-r--r--drivers/mtd/devices/lart.c16
-rw-r--r--drivers/mtd/devices/m25p80.c40
-rw-r--r--drivers/mtd/devices/mtdram.c1
-rw-r--r--drivers/mtd/devices/phram.c2
-rw-r--r--drivers/mtd/ftl.c6
-rw-r--r--drivers/mtd/inftlmount.c5
-rw-r--r--drivers/mtd/maps/Kconfig3
-rw-r--r--drivers/mtd/maps/bast-flash.c5
-rw-r--r--drivers/mtd/maps/ck804xrom.c89
-rw-r--r--drivers/mtd/maps/integrator-flash.c2
-rw-r--r--drivers/mtd/maps/ixp2000.c3
-rw-r--r--drivers/mtd/maps/ixp4xx.c2
-rw-r--r--drivers/mtd/maps/omap_nor.c12
-rw-r--r--drivers/mtd/maps/pcmciamtd.c2
-rw-r--r--drivers/mtd/maps/physmap.c8
-rw-r--r--drivers/mtd/maps/plat-ram.c50
-rw-r--r--drivers/mtd/maps/pmcmsp-flash.c2
-rw-r--r--drivers/mtd/maps/sa1100-flash.c2
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c2
-rw-r--r--drivers/mtd/maps/tqm8xxl.c6
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/nand/Kconfig56
-rw-r--r--drivers/mtd/nand/Makefile2
-rw-r--r--drivers/mtd/nand/at91_nand.c370
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c17
-rw-r--r--drivers/mtd/nand/cs553x_nand.c2
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c39
-rw-r--r--drivers/mtd/nand/fsl_upm.c291
-rw-r--r--drivers/mtd/nand/nand_base.c21
-rw-r--r--drivers/mtd/nand/ndfc.c2
-rw-r--r--drivers/mtd/nand/orion_nand.c1
-rw-r--r--drivers/mtd/nand/plat_nand.c2
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c1249
-rw-r--r--drivers/mtd/nand/rtc_from4.c50
-rw-r--r--drivers/mtd/nand/s3c2410.c73
-rw-r--r--drivers/mtd/nftlmount.c5
-rw-r--r--drivers/mtd/ofpart.c2
-rw-r--r--drivers/mtd/onenand/onenand_base.c51
-rw-r--r--drivers/mtd/onenand/onenand_bbt.c3
-rw-r--r--drivers/mtd/rfd_ftl.c2
-rw-r--r--drivers/mtd/ubi/Kconfig9
-rw-r--r--drivers/mtd/ubi/build.c40
-rw-r--r--drivers/mtd/ubi/debug.h4
-rw-r--r--drivers/mtd/ubi/gluebi.c5
-rw-r--r--drivers/mtd/ubi/io.c4
-rw-r--r--drivers/mtd/ubi/scan.c41
-rw-r--r--drivers/mtd/ubi/scan.h2
-rw-r--r--drivers/mtd/ubi/ubi-media.h372
-rw-r--r--drivers/mtd/ubi/ubi.h7
61 files changed, 3028 insertions, 290 deletions
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index e8503341e3b1..eed06d068fd1 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -158,6 +158,12 @@ config MTD_OF_PARTS
158 the partition map from the children of the flash node, 158 the partition map from the children of the flash node,
159 as described in Documentation/powerpc/booting-without-of.txt. 159 as described in Documentation/powerpc/booting-without-of.txt.
160 160
161config MTD_AR7_PARTS
162 tristate "TI AR7 partitioning support"
163 depends on MTD_PARTITIONS
164 ---help---
165 TI AR7 partitioning support
166
161comment "User Modules And Translation Layers" 167comment "User Modules And Translation Layers"
162 168
163config MTD_CHAR 169config MTD_CHAR
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 538e33d11d46..4b77335715f0 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
11obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o 11obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
12obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o 12obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o
13obj-$(CONFIG_MTD_AFS_PARTS) += afs.o 13obj-$(CONFIG_MTD_AFS_PARTS) += afs.o
14obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o
14obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o 15obj-$(CONFIG_MTD_OF_PARTS) += ofpart.o
15 16
16# 'Users' - code which presents functionality to userspace. 17# 'Users' - code which presents functionality to userspace.
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
new file mode 100644
index 000000000000..ecf170b55c32
--- /dev/null
+++ b/drivers/mtd/ar7part.c
@@ -0,0 +1,151 @@
1/*
2 * Copyright © 2007 Eugene Konev <ejka@openwrt.org>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 *
18 * TI AR7 flash partition table.
19 * Based on ar7 map by Felix Fietkau <nbd@openwrt.org>
20 *
21 */
22
23#include <linux/kernel.h>
24#include <linux/slab.h>
25
26#include <linux/mtd/mtd.h>
27#include <linux/mtd/partitions.h>
28#include <linux/bootmem.h>
29#include <linux/magic.h>
30
31#define AR7_PARTS 4
32#define ROOT_OFFSET 0xe0000
33
34#define LOADER_MAGIC1 le32_to_cpu(0xfeedfa42)
35#define LOADER_MAGIC2 le32_to_cpu(0xfeed1281)
36
37#ifndef SQUASHFS_MAGIC
38#define SQUASHFS_MAGIC 0x73717368
39#endif
40
41struct ar7_bin_rec {
42 unsigned int checksum;
43 unsigned int length;
44 unsigned int address;
45};
46
47static struct mtd_partition ar7_parts[AR7_PARTS];
48
49static int create_mtd_partitions(struct mtd_info *master,
50 struct mtd_partition **pparts,
51 unsigned long origin)
52{
53 struct ar7_bin_rec header;
54 unsigned int offset;
55 size_t len;
56 unsigned int pre_size = master->erasesize, post_size = 0;
57 unsigned int root_offset = ROOT_OFFSET;
58
59 int retries = 10;
60
61 ar7_parts[0].name = "loader";
62 ar7_parts[0].offset = 0;
63 ar7_parts[0].size = master->erasesize;
64 ar7_parts[0].mask_flags = MTD_WRITEABLE;
65
66 ar7_parts[1].name = "config";
67 ar7_parts[1].offset = 0;
68 ar7_parts[1].size = master->erasesize;
69 ar7_parts[1].mask_flags = 0;
70
71 do { /* Try 10 blocks starting from master->erasesize */
72 offset = pre_size;
73 master->read(master, offset,
74 sizeof(header), &len, (uint8_t *)&header);
75 if (!strncmp((char *)&header, "TIENV0.8", 8))
76 ar7_parts[1].offset = pre_size;
77 if (header.checksum == LOADER_MAGIC1)
78 break;
79 if (header.checksum == LOADER_MAGIC2)
80 break;
81 pre_size += master->erasesize;
82 } while (retries--);
83
84 pre_size = offset;
85
86 if (!ar7_parts[1].offset) {
87 ar7_parts[1].offset = master->size - master->erasesize;
88 post_size = master->erasesize;
89 }
90
91 switch (header.checksum) {
92 case LOADER_MAGIC1:
93 while (header.length) {
94 offset += sizeof(header) + header.length;
95 master->read(master, offset, sizeof(header),
96 &len, (uint8_t *)&header);
97 }
98 root_offset = offset + sizeof(header) + 4;
99 break;
100 case LOADER_MAGIC2:
101 while (header.length) {
102 offset += sizeof(header) + header.length;
103 master->read(master, offset, sizeof(header),
104 &len, (uint8_t *)&header);
105 }
106 root_offset = offset + sizeof(header) + 4 + 0xff;
107 root_offset &= ~(uint32_t)0xff;
108 break;
109 default:
110 printk(KERN_WARNING "Unknown magic: %08x\n", header.checksum);
111 break;
112 }
113
114 master->read(master, root_offset,
115 sizeof(header), &len, (u8 *)&header);
116 if (header.checksum != SQUASHFS_MAGIC) {
117 root_offset += master->erasesize - 1;
118 root_offset &= ~(master->erasesize - 1);
119 }
120
121 ar7_parts[2].name = "linux";
122 ar7_parts[2].offset = pre_size;
123 ar7_parts[2].size = master->size - pre_size - post_size;
124 ar7_parts[2].mask_flags = 0;
125
126 ar7_parts[3].name = "rootfs";
127 ar7_parts[3].offset = root_offset;
128 ar7_parts[3].size = master->size - root_offset - post_size;
129 ar7_parts[3].mask_flags = 0;
130
131 *pparts = ar7_parts;
132 return AR7_PARTS;
133}
134
135static struct mtd_part_parser ar7_parser = {
136 .owner = THIS_MODULE,
137 .parse_fn = create_mtd_partitions,
138 .name = "ar7part",
139};
140
141static int __init ar7_parser_init(void)
142{
143 return register_mtd_parser(&ar7_parser);
144}
145
146module_init(ar7_parser_init);
147
148MODULE_LICENSE("GPL");
149MODULE_AUTHOR( "Felix Fietkau <nbd@openwrt.org>, "
150 "Eugene Konev <ejka@openwrt.org>");
151MODULE_DESCRIPTION("MTD partitioning for TI AR7");
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 0080452531d6..e812df607a5c 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -384,7 +384,7 @@ read_pri_intelext(struct map_info *map, __u16 adr)
384 if (extp_size > 4096) { 384 if (extp_size > 4096) {
385 printk(KERN_ERR 385 printk(KERN_ERR
386 "%s: cfi_pri_intelext is too fat\n", 386 "%s: cfi_pri_intelext is too fat\n",
387 __FUNCTION__); 387 __func__);
388 return NULL; 388 return NULL;
389 } 389 }
390 goto again; 390 goto again;
@@ -619,6 +619,9 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
619 sizeof(struct cfi_intelext_blockinfo); 619 sizeof(struct cfi_intelext_blockinfo);
620 } 620 }
621 621
622 if (!numparts)
623 numparts = 1;
624
622 /* Programming Region info */ 625 /* Programming Region info */
623 if (extp->MinorVersion >= '4') { 626 if (extp->MinorVersion >= '4') {
624 struct cfi_intelext_programming_regioninfo *prinfo; 627 struct cfi_intelext_programming_regioninfo *prinfo;
@@ -641,7 +644,7 @@ static int cfi_intelext_partition_fixup(struct mtd_info *mtd,
641 if ((1 << partshift) < mtd->erasesize) { 644 if ((1 << partshift) < mtd->erasesize) {
642 printk( KERN_ERR 645 printk( KERN_ERR
643 "%s: bad number of hw partitions (%d)\n", 646 "%s: bad number of hw partitions (%d)\n",
644 __FUNCTION__, numparts); 647 __func__, numparts);
645 return -EINVAL; 648 return -EINVAL;
646 } 649 }
647 650
@@ -1071,10 +1074,10 @@ static int __xipram xip_wait_for_operation(
1071 chip->state = newstate; 1074 chip->state = newstate;
1072 map_write(map, CMD(0xff), adr); 1075 map_write(map, CMD(0xff), adr);
1073 (void) map_read(map, adr); 1076 (void) map_read(map, adr);
1074 asm volatile (".rep 8; nop; .endr"); 1077 xip_iprefetch();
1075 local_irq_enable(); 1078 local_irq_enable();
1076 spin_unlock(chip->mutex); 1079 spin_unlock(chip->mutex);
1077 asm volatile (".rep 8; nop; .endr"); 1080 xip_iprefetch();
1078 cond_resched(); 1081 cond_resched();
1079 1082
1080 /* 1083 /*
@@ -2013,7 +2016,7 @@ static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
2013 2016
2014#ifdef DEBUG_LOCK_BITS 2017#ifdef DEBUG_LOCK_BITS
2015 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n", 2018 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
2016 __FUNCTION__, ofs, len); 2019 __func__, ofs, len);
2017 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2020 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2018 ofs, len, NULL); 2021 ofs, len, NULL);
2019#endif 2022#endif
@@ -2023,7 +2026,7 @@ static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len)
2023 2026
2024#ifdef DEBUG_LOCK_BITS 2027#ifdef DEBUG_LOCK_BITS
2025 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2028 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
2026 __FUNCTION__, ret); 2029 __func__, ret);
2027 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2030 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2028 ofs, len, NULL); 2031 ofs, len, NULL);
2029#endif 2032#endif
@@ -2037,7 +2040,7 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2037 2040
2038#ifdef DEBUG_LOCK_BITS 2041#ifdef DEBUG_LOCK_BITS
2039 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n", 2042 printk(KERN_DEBUG "%s: lock status before, ofs=0x%08llx, len=0x%08X\n",
2040 __FUNCTION__, ofs, len); 2043 __func__, ofs, len);
2041 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2044 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2042 ofs, len, NULL); 2045 ofs, len, NULL);
2043#endif 2046#endif
@@ -2047,7 +2050,7 @@ static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2047 2050
2048#ifdef DEBUG_LOCK_BITS 2051#ifdef DEBUG_LOCK_BITS
2049 printk(KERN_DEBUG "%s: lock status after, ret=%d\n", 2052 printk(KERN_DEBUG "%s: lock status after, ret=%d\n",
2050 __FUNCTION__, ret); 2053 __func__, ret);
2051 cfi_varsize_frob(mtd, do_printlockstatus_oneblock, 2054 cfi_varsize_frob(mtd, do_printlockstatus_oneblock,
2052 ofs, len, NULL); 2055 ofs, len, NULL);
2053#endif 2056#endif
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 458d477614d6..f7fcc6389533 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -220,6 +220,28 @@ static void fixup_use_atmel_lock(struct mtd_info *mtd, void *param)
220 mtd->flags |= MTD_POWERUP_LOCK; 220 mtd->flags |= MTD_POWERUP_LOCK;
221} 221}
222 222
223static void fixup_s29gl064n_sectors(struct mtd_info *mtd, void *param)
224{
225 struct map_info *map = mtd->priv;
226 struct cfi_private *cfi = map->fldrv_priv;
227
228 if ((cfi->cfiq->EraseRegionInfo[0] & 0xffff) == 0x003f) {
229 cfi->cfiq->EraseRegionInfo[0] |= 0x0040;
230 pr_warning("%s: Bad S29GL064N CFI data, adjust from 64 to 128 sectors\n", mtd->name);
231 }
232}
233
234static void fixup_s29gl032n_sectors(struct mtd_info *mtd, void *param)
235{
236 struct map_info *map = mtd->priv;
237 struct cfi_private *cfi = map->fldrv_priv;
238
239 if ((cfi->cfiq->EraseRegionInfo[1] & 0xffff) == 0x007e) {
240 cfi->cfiq->EraseRegionInfo[1] &= ~0x0040;
241 pr_warning("%s: Bad S29GL032N CFI data, adjust from 127 to 63 sectors\n", mtd->name);
242 }
243}
244
223static struct cfi_fixup cfi_fixup_table[] = { 245static struct cfi_fixup cfi_fixup_table[] = {
224 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, 246 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
225#ifdef AMD_BOOTLOC_BUG 247#ifdef AMD_BOOTLOC_BUG
@@ -231,6 +253,10 @@ static struct cfi_fixup cfi_fixup_table[] = {
231 { CFI_MFR_AMD, 0x0056, fixup_use_secsi, NULL, }, 253 { CFI_MFR_AMD, 0x0056, fixup_use_secsi, NULL, },
232 { CFI_MFR_AMD, 0x005C, fixup_use_secsi, NULL, }, 254 { CFI_MFR_AMD, 0x005C, fixup_use_secsi, NULL, },
233 { CFI_MFR_AMD, 0x005F, fixup_use_secsi, NULL, }, 255 { CFI_MFR_AMD, 0x005F, fixup_use_secsi, NULL, },
256 { CFI_MFR_AMD, 0x0c01, fixup_s29gl064n_sectors, NULL, },
257 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors, NULL, },
258 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors, NULL, },
259 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors, NULL, },
234#if !FORCE_WORD_WRITE 260#if !FORCE_WORD_WRITE
235 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, }, 261 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
236#endif 262#endif
@@ -723,10 +749,10 @@ static void __xipram xip_udelay(struct map_info *map, struct flchip *chip,
723 chip->erase_suspended = 1; 749 chip->erase_suspended = 1;
724 map_write(map, CMD(0xf0), adr); 750 map_write(map, CMD(0xf0), adr);
725 (void) map_read(map, adr); 751 (void) map_read(map, adr);
726 asm volatile (".rep 8; nop; .endr"); 752 xip_iprefetch();
727 local_irq_enable(); 753 local_irq_enable();
728 spin_unlock(chip->mutex); 754 spin_unlock(chip->mutex);
729 asm volatile (".rep 8; nop; .endr"); 755 xip_iprefetch();
730 cond_resched(); 756 cond_resched();
731 757
732 /* 758 /*
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index 492e2ab27420..1b720cc571f3 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -445,7 +445,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
445 retry: 445 retry:
446 446
447#ifdef DEBUG_CFI_FEATURES 447#ifdef DEBUG_CFI_FEATURES
448 printk("%s: chip->state[%d]\n", __FUNCTION__, chip->state); 448 printk("%s: chip->state[%d]\n", __func__, chip->state);
449#endif 449#endif
450 spin_lock_bh(chip->mutex); 450 spin_lock_bh(chip->mutex);
451 451
@@ -463,7 +463,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
463 map_write(map, CMD(0x70), cmd_adr); 463 map_write(map, CMD(0x70), cmd_adr);
464 chip->state = FL_STATUS; 464 chip->state = FL_STATUS;
465#ifdef DEBUG_CFI_FEATURES 465#ifdef DEBUG_CFI_FEATURES
466 printk("%s: 1 status[%x]\n", __FUNCTION__, map_read(map, cmd_adr)); 466 printk("%s: 1 status[%x]\n", __func__, map_read(map, cmd_adr));
467#endif 467#endif
468 468
469 case FL_STATUS: 469 case FL_STATUS:
@@ -591,7 +591,7 @@ static inline int do_write_buffer(struct map_info *map, struct flchip *chip,
591 /* check for errors: 'lock bit', 'VPP', 'dead cell'/'unerased cell' or 'incorrect cmd' -- saw */ 591 /* check for errors: 'lock bit', 'VPP', 'dead cell'/'unerased cell' or 'incorrect cmd' -- saw */
592 if (map_word_bitsset(map, status, CMD(0x3a))) { 592 if (map_word_bitsset(map, status, CMD(0x3a))) {
593#ifdef DEBUG_CFI_FEATURES 593#ifdef DEBUG_CFI_FEATURES
594 printk("%s: 2 status[%lx]\n", __FUNCTION__, status.x[0]); 594 printk("%s: 2 status[%lx]\n", __func__, status.x[0]);
595#endif 595#endif
596 /* clear status */ 596 /* clear status */
597 map_write(map, CMD(0x50), cmd_adr); 597 map_write(map, CMD(0x50), cmd_adr);
@@ -625,9 +625,9 @@ static int cfi_staa_write_buffers (struct mtd_info *mtd, loff_t to,
625 ofs = to - (chipnum << cfi->chipshift); 625 ofs = to - (chipnum << cfi->chipshift);
626 626
627#ifdef DEBUG_CFI_FEATURES 627#ifdef DEBUG_CFI_FEATURES
628 printk("%s: map_bankwidth(map)[%x]\n", __FUNCTION__, map_bankwidth(map)); 628 printk("%s: map_bankwidth(map)[%x]\n", __func__, map_bankwidth(map));
629 printk("%s: chipnum[%x] wbufsize[%x]\n", __FUNCTION__, chipnum, wbufsize); 629 printk("%s: chipnum[%x] wbufsize[%x]\n", __func__, chipnum, wbufsize);
630 printk("%s: ofs[%x] len[%x]\n", __FUNCTION__, ofs, len); 630 printk("%s: ofs[%x] len[%x]\n", __func__, ofs, len);
631#endif 631#endif
632 632
633 /* Write buffer is worth it only if more than one word to write... */ 633 /* Write buffer is worth it only if more than one word to write... */
@@ -893,7 +893,8 @@ retry:
893 return ret; 893 return ret;
894} 894}
895 895
896int cfi_staa_erase_varsize(struct mtd_info *mtd, struct erase_info *instr) 896static int cfi_staa_erase_varsize(struct mtd_info *mtd,
897 struct erase_info *instr)
897{ struct map_info *map = mtd->priv; 898{ struct map_info *map = mtd->priv;
898 struct cfi_private *cfi = map->fldrv_priv; 899 struct cfi_private *cfi = map->fldrv_priv;
899 unsigned long adr, len; 900 unsigned long adr, len;
diff --git a/drivers/mtd/chips/cfi_probe.c b/drivers/mtd/chips/cfi_probe.c
index f651b6ef1c5d..a4463a91ce31 100644
--- a/drivers/mtd/chips/cfi_probe.c
+++ b/drivers/mtd/chips/cfi_probe.c
@@ -39,7 +39,7 @@ struct mtd_info *cfi_probe(struct map_info *map);
39#define xip_allowed(base, map) \ 39#define xip_allowed(base, map) \
40do { \ 40do { \
41 (void) map_read(map, base); \ 41 (void) map_read(map, base); \
42 asm volatile (".rep 8; nop; .endr"); \ 42 xip_iprefetch(); \
43 local_irq_enable(); \ 43 local_irq_enable(); \
44} while (0) 44} while (0)
45 45
@@ -232,6 +232,11 @@ static int __xipram cfi_chip_setup(struct map_info *map,
232 cfi->mfr = cfi_read_query16(map, base); 232 cfi->mfr = cfi_read_query16(map, base);
233 cfi->id = cfi_read_query16(map, base + ofs_factor); 233 cfi->id = cfi_read_query16(map, base + ofs_factor);
234 234
235 /* Get AMD/Spansion extended JEDEC ID */
236 if (cfi->mfr == CFI_MFR_AMD && (cfi->id & 0xff) == 0x7e)
237 cfi->id = cfi_read_query(map, base + 0xe * ofs_factor) << 8 |
238 cfi_read_query(map, base + 0xf * ofs_factor);
239
235 /* Put it back into Read Mode */ 240 /* Put it back into Read Mode */
236 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); 241 cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL);
237 /* ... even if it's an Intel chip */ 242 /* ... even if it's an Intel chip */
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
index 2e51496c248e..72e0022a47bf 100644
--- a/drivers/mtd/chips/cfi_util.c
+++ b/drivers/mtd/chips/cfi_util.c
@@ -65,7 +65,7 @@ __xipram cfi_read_pri(struct map_info *map, __u16 adr, __u16 size, const char* n
65 65
66#ifdef CONFIG_MTD_XIP 66#ifdef CONFIG_MTD_XIP
67 (void) map_read(map, base); 67 (void) map_read(map, base);
68 asm volatile (".rep 8; nop; .endr"); 68 xip_iprefetch();
69 local_irq_enable(); 69 local_irq_enable();
70#endif 70#endif
71 71
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 4be51a86a85c..aa07575eb288 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -132,6 +132,8 @@
132#define M29F800AB 0x0058 132#define M29F800AB 0x0058
133#define M29W800DT 0x00D7 133#define M29W800DT 0x00D7
134#define M29W800DB 0x005B 134#define M29W800DB 0x005B
135#define M29W400DT 0x00EE
136#define M29W400DB 0x00EF
135#define M29W160DT 0x22C4 137#define M29W160DT 0x22C4
136#define M29W160DB 0x2249 138#define M29W160DB 0x2249
137#define M29W040B 0x00E3 139#define M29W040B 0x00E3
@@ -160,6 +162,7 @@
160#define SST49LF030A 0x001C 162#define SST49LF030A 0x001C
161#define SST49LF040A 0x0051 163#define SST49LF040A 0x0051
162#define SST49LF080A 0x005B 164#define SST49LF080A 0x005B
165#define SST36VF3203 0x7354
163 166
164/* Toshiba */ 167/* Toshiba */
165#define TC58FVT160 0x00C2 168#define TC58FVT160 0x00C2
@@ -1113,7 +1116,7 @@ static const struct amd_flash_info jedec_table[] = {
1113 .regions = { 1116 .regions = {
1114 ERASEINFO(0x10000,8), 1117 ERASEINFO(0x10000,8),
1115 } 1118 }
1116 }, { 1119 }, {
1117 .mfr_id = MANUFACTURER_MACRONIX, 1120 .mfr_id = MANUFACTURER_MACRONIX,
1118 .dev_id = MX29F016, 1121 .dev_id = MX29F016,
1119 .name = "Macronix MX29F016", 1122 .name = "Macronix MX29F016",
@@ -1125,7 +1128,7 @@ static const struct amd_flash_info jedec_table[] = {
1125 .regions = { 1128 .regions = {
1126 ERASEINFO(0x10000,32), 1129 ERASEINFO(0x10000,32),
1127 } 1130 }
1128 }, { 1131 }, {
1129 .mfr_id = MANUFACTURER_MACRONIX, 1132 .mfr_id = MANUFACTURER_MACRONIX,
1130 .dev_id = MX29F004T, 1133 .dev_id = MX29F004T,
1131 .name = "Macronix MX29F004T", 1134 .name = "Macronix MX29F004T",
@@ -1140,7 +1143,7 @@ static const struct amd_flash_info jedec_table[] = {
1140 ERASEINFO(0x02000,2), 1143 ERASEINFO(0x02000,2),
1141 ERASEINFO(0x04000,1), 1144 ERASEINFO(0x04000,1),
1142 } 1145 }
1143 }, { 1146 }, {
1144 .mfr_id = MANUFACTURER_MACRONIX, 1147 .mfr_id = MANUFACTURER_MACRONIX,
1145 .dev_id = MX29F004B, 1148 .dev_id = MX29F004B,
1146 .name = "Macronix MX29F004B", 1149 .name = "Macronix MX29F004B",
@@ -1218,7 +1221,7 @@ static const struct amd_flash_info jedec_table[] = {
1218 .regions = { 1221 .regions = {
1219 ERASEINFO(0x40000,16), 1222 ERASEINFO(0x40000,16),
1220 } 1223 }
1221 }, { 1224 }, {
1222 .mfr_id = MANUFACTURER_SST, 1225 .mfr_id = MANUFACTURER_SST,
1223 .dev_id = SST39LF512, 1226 .dev_id = SST39LF512,
1224 .name = "SST 39LF512", 1227 .name = "SST 39LF512",
@@ -1230,7 +1233,7 @@ static const struct amd_flash_info jedec_table[] = {
1230 .regions = { 1233 .regions = {
1231 ERASEINFO(0x01000,16), 1234 ERASEINFO(0x01000,16),
1232 } 1235 }
1233 }, { 1236 }, {
1234 .mfr_id = MANUFACTURER_SST, 1237 .mfr_id = MANUFACTURER_SST,
1235 .dev_id = SST39LF010, 1238 .dev_id = SST39LF010,
1236 .name = "SST 39LF010", 1239 .name = "SST 39LF010",
@@ -1242,7 +1245,7 @@ static const struct amd_flash_info jedec_table[] = {
1242 .regions = { 1245 .regions = {
1243 ERASEINFO(0x01000,32), 1246 ERASEINFO(0x01000,32),
1244 } 1247 }
1245 }, { 1248 }, {
1246 .mfr_id = MANUFACTURER_SST, 1249 .mfr_id = MANUFACTURER_SST,
1247 .dev_id = SST29EE020, 1250 .dev_id = SST29EE020,
1248 .name = "SST 29EE020", 1251 .name = "SST 29EE020",
@@ -1276,7 +1279,7 @@ static const struct amd_flash_info jedec_table[] = {
1276 .regions = { 1279 .regions = {
1277 ERASEINFO(0x01000,64), 1280 ERASEINFO(0x01000,64),
1278 } 1281 }
1279 }, { 1282 }, {
1280 .mfr_id = MANUFACTURER_SST, 1283 .mfr_id = MANUFACTURER_SST,
1281 .dev_id = SST39LF040, 1284 .dev_id = SST39LF040,
1282 .name = "SST 39LF040", 1285 .name = "SST 39LF040",
@@ -1288,7 +1291,7 @@ static const struct amd_flash_info jedec_table[] = {
1288 .regions = { 1291 .regions = {
1289 ERASEINFO(0x01000,128), 1292 ERASEINFO(0x01000,128),
1290 } 1293 }
1291 }, { 1294 }, {
1292 .mfr_id = MANUFACTURER_SST, 1295 .mfr_id = MANUFACTURER_SST,
1293 .dev_id = SST39SF010A, 1296 .dev_id = SST39SF010A,
1294 .name = "SST 39SF010A", 1297 .name = "SST 39SF010A",
@@ -1300,7 +1303,7 @@ static const struct amd_flash_info jedec_table[] = {
1300 .regions = { 1303 .regions = {
1301 ERASEINFO(0x01000,32), 1304 ERASEINFO(0x01000,32),
1302 } 1305 }
1303 }, { 1306 }, {
1304 .mfr_id = MANUFACTURER_SST, 1307 .mfr_id = MANUFACTURER_SST,
1305 .dev_id = SST39SF020A, 1308 .dev_id = SST39SF020A,
1306 .name = "SST 39SF020A", 1309 .name = "SST 39SF020A",
@@ -1412,6 +1415,18 @@ static const struct amd_flash_info jedec_table[] = {
1412 ERASEINFO(0x1000,256) 1415 ERASEINFO(0x1000,256)
1413 } 1416 }
1414 }, { 1417 }, {
1418 .mfr_id = MANUFACTURER_SST,
1419 .dev_id = SST36VF3203,
1420 .name = "SST 36VF3203",
1421 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1422 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1423 .dev_size = SIZE_4MiB,
1424 .cmd_set = P_ID_AMD_STD,
1425 .nr_regions = 1,
1426 .regions = {
1427 ERASEINFO(0x10000,64),
1428 }
1429 }, {
1415 .mfr_id = MANUFACTURER_ST, 1430 .mfr_id = MANUFACTURER_ST,
1416 .dev_id = M29F800AB, 1431 .dev_id = M29F800AB,
1417 .name = "ST M29F800AB", 1432 .name = "ST M29F800AB",
@@ -1426,7 +1441,7 @@ static const struct amd_flash_info jedec_table[] = {
1426 ERASEINFO(0x08000,1), 1441 ERASEINFO(0x08000,1),
1427 ERASEINFO(0x10000,15), 1442 ERASEINFO(0x10000,15),
1428 } 1443 }
1429 }, { 1444 }, {
1430 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ 1445 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */
1431 .dev_id = M29W800DT, 1446 .dev_id = M29W800DT,
1432 .name = "ST M29W800DT", 1447 .name = "ST M29W800DT",
@@ -1456,6 +1471,36 @@ static const struct amd_flash_info jedec_table[] = {
1456 ERASEINFO(0x08000,1), 1471 ERASEINFO(0x08000,1),
1457 ERASEINFO(0x10000,15) 1472 ERASEINFO(0x10000,15)
1458 } 1473 }
1474 }, {
1475 .mfr_id = MANUFACTURER_ST,
1476 .dev_id = M29W400DT,
1477 .name = "ST M29W400DT",
1478 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1479 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1480 .dev_size = SIZE_512KiB,
1481 .cmd_set = P_ID_AMD_STD,
1482 .nr_regions = 4,
1483 .regions = {
1484 ERASEINFO(0x04000,7),
1485 ERASEINFO(0x02000,1),
1486 ERASEINFO(0x08000,2),
1487 ERASEINFO(0x10000,1)
1488 }
1489 }, {
1490 .mfr_id = MANUFACTURER_ST,
1491 .dev_id = M29W400DB,
1492 .name = "ST M29W400DB",
1493 .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8,
1494 .uaddr = MTD_UADDR_0x0AAA_0x0555,
1495 .dev_size = SIZE_512KiB,
1496 .cmd_set = P_ID_AMD_STD,
1497 .nr_regions = 4,
1498 .regions = {
1499 ERASEINFO(0x04000,1),
1500 ERASEINFO(0x02000,2),
1501 ERASEINFO(0x08000,1),
1502 ERASEINFO(0x10000,7)
1503 }
1459 }, { 1504 }, {
1460 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ 1505 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */
1461 .dev_id = M29W160DT, 1506 .dev_id = M29W160DT,
@@ -1486,7 +1531,7 @@ static const struct amd_flash_info jedec_table[] = {
1486 ERASEINFO(0x08000,1), 1531 ERASEINFO(0x08000,1),
1487 ERASEINFO(0x10000,31) 1532 ERASEINFO(0x10000,31)
1488 } 1533 }
1489 }, { 1534 }, {
1490 .mfr_id = MANUFACTURER_ST, 1535 .mfr_id = MANUFACTURER_ST,
1491 .dev_id = M29W040B, 1536 .dev_id = M29W040B,
1492 .name = "ST M29W040B", 1537 .name = "ST M29W040B",
@@ -1498,7 +1543,7 @@ static const struct amd_flash_info jedec_table[] = {
1498 .regions = { 1543 .regions = {
1499 ERASEINFO(0x10000,8), 1544 ERASEINFO(0x10000,8),
1500 } 1545 }
1501 }, { 1546 }, {
1502 .mfr_id = MANUFACTURER_ST, 1547 .mfr_id = MANUFACTURER_ST,
1503 .dev_id = M50FW040, 1548 .dev_id = M50FW040,
1504 .name = "ST M50FW040", 1549 .name = "ST M50FW040",
@@ -1510,7 +1555,7 @@ static const struct amd_flash_info jedec_table[] = {
1510 .regions = { 1555 .regions = {
1511 ERASEINFO(0x10000,8), 1556 ERASEINFO(0x10000,8),
1512 } 1557 }
1513 }, { 1558 }, {
1514 .mfr_id = MANUFACTURER_ST, 1559 .mfr_id = MANUFACTURER_ST,
1515 .dev_id = M50FW080, 1560 .dev_id = M50FW080,
1516 .name = "ST M50FW080", 1561 .name = "ST M50FW080",
@@ -1522,7 +1567,7 @@ static const struct amd_flash_info jedec_table[] = {
1522 .regions = { 1567 .regions = {
1523 ERASEINFO(0x10000,16), 1568 ERASEINFO(0x10000,16),
1524 } 1569 }
1525 }, { 1570 }, {
1526 .mfr_id = MANUFACTURER_ST, 1571 .mfr_id = MANUFACTURER_ST,
1527 .dev_id = M50FW016, 1572 .dev_id = M50FW016,
1528 .name = "ST M50FW016", 1573 .name = "ST M50FW016",
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index b44292abd9f7..e472a0e9de9d 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -119,7 +119,8 @@ static struct mtd_partition * newpart(char *s,
119 char *p; 119 char *p;
120 120
121 name = ++s; 121 name = ++s;
122 if ((p = strchr(name, delim)) == 0) 122 p = strchr(name, delim);
123 if (!p)
123 { 124 {
124 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim); 125 printk(KERN_ERR ERRP "no closing %c found in partition name\n", delim);
125 return NULL; 126 return NULL;
@@ -159,9 +160,10 @@ static struct mtd_partition * newpart(char *s,
159 return NULL; 160 return NULL;
160 } 161 }
161 /* more partitions follow, parse them */ 162 /* more partitions follow, parse them */
162 if ((parts = newpart(s + 1, &s, num_parts, 163 parts = newpart(s + 1, &s, num_parts, this_part + 1,
163 this_part + 1, &extra_mem, extra_mem_size)) == 0) 164 &extra_mem, extra_mem_size);
164 return NULL; 165 if (!parts)
166 return NULL;
165 } 167 }
166 else 168 else
167 { /* this is the last partition: allocate space for all */ 169 { /* this is the last partition: allocate space for all */
@@ -308,9 +310,6 @@ static int parse_cmdline_partitions(struct mtd_info *master,
308 struct cmdline_mtd_partition *part; 310 struct cmdline_mtd_partition *part;
309 char *mtd_id = master->name; 311 char *mtd_id = master->name;
310 312
311 if(!cmdline)
312 return -EINVAL;
313
314 /* parse command line */ 313 /* parse command line */
315 if (!cmdline_parsed) 314 if (!cmdline_parsed)
316 mtdpart_setup_real(cmdline); 315 mtdpart_setup_real(cmdline);
@@ -341,7 +340,7 @@ static int parse_cmdline_partitions(struct mtd_info *master,
341 return part->num_parts; 340 return part->num_parts;
342 } 341 }
343 } 342 }
344 return -EINVAL; 343 return 0;
345} 344}
346 345
347 346
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig
index 811d56fd890f..35ed1103dbb2 100644
--- a/drivers/mtd/devices/Kconfig
+++ b/drivers/mtd/devices/Kconfig
@@ -77,6 +77,13 @@ config MTD_M25P80
77 if you want to specify device partitioning or to use a device which 77 if you want to specify device partitioning or to use a device which
78 doesn't support the JEDEC ID instruction. 78 doesn't support the JEDEC ID instruction.
79 79
80config M25PXX_USE_FAST_READ
81 bool "Use FAST_READ OPCode allowing SPI CLK <= 50MHz"
82 depends on MTD_M25P80
83 default y
84 help
85 This option enables FAST_READ access supported by ST M25Pxx.
86
80config MTD_SLRAM 87config MTD_SLRAM
81 tristate "Uncached system RAM" 88 tristate "Uncached system RAM"
82 help 89 help
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index ad1880c67518..519d942e7940 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -305,7 +305,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
305 } 305 }
306 list_add(&dev->list, &blkmtd_device_list); 306 list_add(&dev->list, &blkmtd_device_list);
307 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index, 307 INFO("mtd%d: [%s] erase_size = %dKiB [%d]", dev->mtd.index,
308 dev->mtd.name + strlen("blkmtd: "), 308 dev->mtd.name + strlen("block2mtd: "),
309 dev->mtd.erasesize >> 10, dev->mtd.erasesize); 309 dev->mtd.erasesize >> 10, dev->mtd.erasesize);
310 return dev; 310 return dev;
311 311
@@ -366,9 +366,9 @@ static inline void kill_final_newline(char *str)
366} 366}
367 367
368 368
369#define parse_err(fmt, args...) do { \ 369#define parse_err(fmt, args...) do { \
370 ERROR("block2mtd: " fmt "\n", ## args); \ 370 ERROR(fmt, ## args); \
371 return 0; \ 371 return 0; \
372} while (0) 372} while (0)
373 373
374#ifndef MODULE 374#ifndef MODULE
@@ -473,7 +473,7 @@ static void __devexit block2mtd_exit(void)
473 block2mtd_sync(&dev->mtd); 473 block2mtd_sync(&dev->mtd);
474 del_mtd_device(&dev->mtd); 474 del_mtd_device(&dev->mtd);
475 INFO("mtd%d: [%s] removed", dev->mtd.index, 475 INFO("mtd%d: [%s] removed", dev->mtd.index,
476 dev->mtd.name + strlen("blkmtd: ")); 476 dev->mtd.name + strlen("block2mtd: "));
477 list_del(&dev->list); 477 list_del(&dev->list);
478 block2mtd_free_device(dev); 478 block2mtd_free_device(dev);
479 } 479 }
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 99fd210feaec..1d324e5c412d 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -275,7 +275,7 @@ static __u8 read8 (__u32 offset)
275{ 275{
276 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset); 276 volatile __u8 *data = (__u8 *) (FLASH_OFFSET + offset);
277#ifdef LART_DEBUG 277#ifdef LART_DEBUG
278 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n",__FUNCTION__,offset,*data); 278 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.2x\n", __func__, offset, *data);
279#endif 279#endif
280 return (*data); 280 return (*data);
281} 281}
@@ -284,7 +284,7 @@ static __u32 read32 (__u32 offset)
284{ 284{
285 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 285 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
286#ifdef LART_DEBUG 286#ifdef LART_DEBUG
287 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n",__FUNCTION__,offset,*data); 287 printk (KERN_DEBUG "%s(): 0x%.8x -> 0x%.8x\n", __func__, offset, *data);
288#endif 288#endif
289 return (*data); 289 return (*data);
290} 290}
@@ -294,7 +294,7 @@ static void write32 (__u32 x,__u32 offset)
294 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset); 294 volatile __u32 *data = (__u32 *) (FLASH_OFFSET + offset);
295 *data = x; 295 *data = x;
296#ifdef LART_DEBUG 296#ifdef LART_DEBUG
297 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n",__FUNCTION__,offset,*data); 297 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, *data);
298#endif 298#endif
299} 299}
300 300
@@ -337,7 +337,7 @@ static inline int erase_block (__u32 offset)
337 __u32 status; 337 __u32 status;
338 338
339#ifdef LART_DEBUG 339#ifdef LART_DEBUG
340 printk (KERN_DEBUG "%s(): 0x%.8x\n",__FUNCTION__,offset); 340 printk (KERN_DEBUG "%s(): 0x%.8x\n", __func__, offset);
341#endif 341#endif
342 342
343 /* erase and confirm */ 343 /* erase and confirm */
@@ -371,7 +371,7 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
371 int i,first; 371 int i,first;
372 372
373#ifdef LART_DEBUG 373#ifdef LART_DEBUG
374 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n",__FUNCTION__,instr->addr,instr->len); 374 printk (KERN_DEBUG "%s(addr = 0x%.8x, len = %d)\n", __func__, instr->addr, instr->len);
375#endif 375#endif
376 376
377 /* sanity checks */ 377 /* sanity checks */
@@ -442,7 +442,7 @@ static int flash_erase (struct mtd_info *mtd,struct erase_info *instr)
442static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf) 442static int flash_read (struct mtd_info *mtd,loff_t from,size_t len,size_t *retlen,u_char *buf)
443{ 443{
444#ifdef LART_DEBUG 444#ifdef LART_DEBUG
445 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n",__FUNCTION__,(__u32) from,len); 445 printk (KERN_DEBUG "%s(from = 0x%.8x, len = %d)\n", __func__, (__u32)from, len);
446#endif 446#endif
447 447
448 /* sanity checks */ 448 /* sanity checks */
@@ -488,7 +488,7 @@ static inline int write_dword (__u32 offset,__u32 x)
488 __u32 status; 488 __u32 status;
489 489
490#ifdef LART_DEBUG 490#ifdef LART_DEBUG
491 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n",__FUNCTION__,offset,x); 491 printk (KERN_DEBUG "%s(): 0x%.8x <- 0x%.8x\n", __func__, offset, x);
492#endif 492#endif
493 493
494 /* setup writing */ 494 /* setup writing */
@@ -524,7 +524,7 @@ static int flash_write (struct mtd_info *mtd,loff_t to,size_t len,size_t *retlen
524 int i,n; 524 int i,n;
525 525
526#ifdef LART_DEBUG 526#ifdef LART_DEBUG
527 printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n",__FUNCTION__,(__u32) to,len); 527 printk (KERN_DEBUG "%s(to = 0x%.8x, len = %d)\n", __func__, (__u32)to, len);
528#endif 528#endif
529 529
530 *retlen = 0; 530 *retlen = 0;
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 98df5bcc02f3..25efd331ef28 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -33,7 +33,7 @@
33/* Flash opcodes. */ 33/* Flash opcodes. */
34#define OPCODE_WREN 0x06 /* Write enable */ 34#define OPCODE_WREN 0x06 /* Write enable */
35#define OPCODE_RDSR 0x05 /* Read status register */ 35#define OPCODE_RDSR 0x05 /* Read status register */
36#define OPCODE_READ 0x03 /* Read data bytes (low frequency) */ 36#define OPCODE_NORM_READ 0x03 /* Read data bytes (low frequency) */
37#define OPCODE_FAST_READ 0x0b /* Read data bytes (high frequency) */ 37#define OPCODE_FAST_READ 0x0b /* Read data bytes (high frequency) */
38#define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */ 38#define OPCODE_PP 0x02 /* Page program (up to 256 bytes) */
39#define OPCODE_BE_4K 0x20 /* Erase 4KiB block */ 39#define OPCODE_BE_4K 0x20 /* Erase 4KiB block */
@@ -52,7 +52,15 @@
52 52
53/* Define max times to check status register before we give up. */ 53/* Define max times to check status register before we give up. */
54#define MAX_READY_WAIT_COUNT 100000 54#define MAX_READY_WAIT_COUNT 100000
55#define CMD_SIZE 4
55 56
57#ifdef CONFIG_M25PXX_USE_FAST_READ
58#define OPCODE_READ OPCODE_FAST_READ
59#define FAST_READ_DUMMY_BYTE 1
60#else
61#define OPCODE_READ OPCODE_NORM_READ
62#define FAST_READ_DUMMY_BYTE 0
63#endif
56 64
57#ifdef CONFIG_MTD_PARTITIONS 65#ifdef CONFIG_MTD_PARTITIONS
58#define mtd_has_partitions() (1) 66#define mtd_has_partitions() (1)
@@ -68,7 +76,7 @@ struct m25p {
68 struct mtd_info mtd; 76 struct mtd_info mtd;
69 unsigned partitioned:1; 77 unsigned partitioned:1;
70 u8 erase_opcode; 78 u8 erase_opcode;
71 u8 command[4]; 79 u8 command[CMD_SIZE + FAST_READ_DUMMY_BYTE];
72}; 80};
73 81
74static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) 82static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd)
@@ -151,7 +159,7 @@ static int wait_till_ready(struct m25p *flash)
151static int erase_sector(struct m25p *flash, u32 offset) 159static int erase_sector(struct m25p *flash, u32 offset)
152{ 160{
153 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n", 161 DEBUG(MTD_DEBUG_LEVEL3, "%s: %s %dKiB at 0x%08x\n",
154 flash->spi->dev.bus_id, __FUNCTION__, 162 flash->spi->dev.bus_id, __func__,
155 flash->mtd.erasesize / 1024, offset); 163 flash->mtd.erasesize / 1024, offset);
156 164
157 /* Wait until finished previous write command. */ 165 /* Wait until finished previous write command. */
@@ -167,7 +175,7 @@ static int erase_sector(struct m25p *flash, u32 offset)
167 flash->command[2] = offset >> 8; 175 flash->command[2] = offset >> 8;
168 flash->command[3] = offset; 176 flash->command[3] = offset;
169 177
170 spi_write(flash->spi, flash->command, sizeof(flash->command)); 178 spi_write(flash->spi, flash->command, CMD_SIZE);
171 179
172 return 0; 180 return 0;
173} 181}
@@ -188,7 +196,7 @@ static int m25p80_erase(struct mtd_info *mtd, struct erase_info *instr)
188 u32 addr,len; 196 u32 addr,len;
189 197
190 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n", 198 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %d\n",
191 flash->spi->dev.bus_id, __FUNCTION__, "at", 199 flash->spi->dev.bus_id, __func__, "at",
192 (u32)instr->addr, instr->len); 200 (u32)instr->addr, instr->len);
193 201
194 /* sanity checks */ 202 /* sanity checks */
@@ -240,7 +248,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
240 struct spi_message m; 248 struct spi_message m;
241 249
242 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 250 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n",
243 flash->spi->dev.bus_id, __FUNCTION__, "from", 251 flash->spi->dev.bus_id, __func__, "from",
244 (u32)from, len); 252 (u32)from, len);
245 253
246 /* sanity checks */ 254 /* sanity checks */
@@ -253,8 +261,12 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
253 spi_message_init(&m); 261 spi_message_init(&m);
254 memset(t, 0, (sizeof t)); 262 memset(t, 0, (sizeof t));
255 263
264 /* NOTE:
265 * OPCODE_FAST_READ (if available) is faster.
266 * Should add 1 byte DUMMY_BYTE.
267 */
256 t[0].tx_buf = flash->command; 268 t[0].tx_buf = flash->command;
257 t[0].len = sizeof(flash->command); 269 t[0].len = CMD_SIZE + FAST_READ_DUMMY_BYTE;
258 spi_message_add_tail(&t[0], &m); 270 spi_message_add_tail(&t[0], &m);
259 271
260 t[1].rx_buf = buf; 272 t[1].rx_buf = buf;
@@ -287,7 +299,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len,
287 299
288 spi_sync(flash->spi, &m); 300 spi_sync(flash->spi, &m);
289 301
290 *retlen = m.actual_length - sizeof(flash->command); 302 *retlen = m.actual_length - CMD_SIZE - FAST_READ_DUMMY_BYTE;
291 303
292 mutex_unlock(&flash->lock); 304 mutex_unlock(&flash->lock);
293 305
@@ -308,7 +320,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
308 struct spi_message m; 320 struct spi_message m;
309 321
310 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n", 322 DEBUG(MTD_DEBUG_LEVEL2, "%s: %s %s 0x%08x, len %zd\n",
311 flash->spi->dev.bus_id, __FUNCTION__, "to", 323 flash->spi->dev.bus_id, __func__, "to",
312 (u32)to, len); 324 (u32)to, len);
313 325
314 if (retlen) 326 if (retlen)
@@ -325,7 +337,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
325 memset(t, 0, (sizeof t)); 337 memset(t, 0, (sizeof t));
326 338
327 t[0].tx_buf = flash->command; 339 t[0].tx_buf = flash->command;
328 t[0].len = sizeof(flash->command); 340 t[0].len = CMD_SIZE;
329 spi_message_add_tail(&t[0], &m); 341 spi_message_add_tail(&t[0], &m);
330 342
331 t[1].tx_buf = buf; 343 t[1].tx_buf = buf;
@@ -354,7 +366,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
354 366
355 spi_sync(flash->spi, &m); 367 spi_sync(flash->spi, &m);
356 368
357 *retlen = m.actual_length - sizeof(flash->command); 369 *retlen = m.actual_length - CMD_SIZE;
358 } else { 370 } else {
359 u32 i; 371 u32 i;
360 372
@@ -364,7 +376,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
364 t[1].len = page_size; 376 t[1].len = page_size;
365 spi_sync(flash->spi, &m); 377 spi_sync(flash->spi, &m);
366 378
367 *retlen = m.actual_length - sizeof(flash->command); 379 *retlen = m.actual_length - CMD_SIZE;
368 380
369 /* write everything in PAGESIZE chunks */ 381 /* write everything in PAGESIZE chunks */
370 for (i = page_size; i < len; i += page_size) { 382 for (i = page_size; i < len; i += page_size) {
@@ -387,8 +399,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len,
387 spi_sync(flash->spi, &m); 399 spi_sync(flash->spi, &m);
388 400
389 if (retlen) 401 if (retlen)
390 *retlen += m.actual_length 402 *retlen += m.actual_length - CMD_SIZE;
391 - sizeof(flash->command);
392 } 403 }
393 } 404 }
394 405
@@ -435,6 +446,7 @@ static struct flash_info __devinitdata m25p_data [] = {
435 { "at25fs040", 0x1f6604, 64 * 1024, 8, SECT_4K, }, 446 { "at25fs040", 0x1f6604, 64 * 1024, 8, SECT_4K, },
436 447
437 { "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, }, 448 { "at25df041a", 0x1f4401, 64 * 1024, 8, SECT_4K, },
449 { "at25df641", 0x1f4800, 64 * 1024, 128, SECT_4K, },
438 450
439 { "at26f004", 0x1f0400, 64 * 1024, 8, SECT_4K, }, 451 { "at26f004", 0x1f0400, 64 * 1024, 8, SECT_4K, },
440 { "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, }, 452 { "at26df081a", 0x1f4501, 64 * 1024, 16, SECT_4K, },
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index e427c82d5f4c..bf485ff49457 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/mtd/mtdram.h>
20 21
21static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; 22static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE;
22static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; 23static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE;
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 180298b92a7a..5f960182da95 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -282,7 +282,7 @@ static int phram_setup(const char *val, struct kernel_param *kp)
282} 282}
283 283
284module_param_call(phram, phram_setup, NULL, NULL, 000); 284module_param_call(phram, phram_setup, NULL, NULL, 000);
285MODULE_PARM_DESC(phram,"Memory region to map. \"map=<name>,<start>,<length>\""); 285MODULE_PARM_DESC(phram, "Memory region to map. \"phram=<name>,<start>,<length>\"");
286 286
287 287
288static int __init init_phram(void) 288static int __init init_phram(void)
diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c
index c815d0f38577..4a79b187b568 100644
--- a/drivers/mtd/ftl.c
+++ b/drivers/mtd/ftl.c
@@ -136,8 +136,6 @@ typedef struct partition_t {
136#endif 136#endif
137} partition_t; 137} partition_t;
138 138
139void ftl_freepart(partition_t *part);
140
141/* Partition state flags */ 139/* Partition state flags */
142#define FTL_FORMATTED 0x01 140#define FTL_FORMATTED 0x01
143 141
@@ -1014,7 +1012,7 @@ static int ftl_writesect(struct mtd_blktrans_dev *dev,
1014 1012
1015/*====================================================================*/ 1013/*====================================================================*/
1016 1014
1017void ftl_freepart(partition_t *part) 1015static void ftl_freepart(partition_t *part)
1018{ 1016{
1019 vfree(part->VirtualBlockMap); 1017 vfree(part->VirtualBlockMap);
1020 part->VirtualBlockMap = NULL; 1018 part->VirtualBlockMap = NULL;
@@ -1069,7 +1067,7 @@ static void ftl_remove_dev(struct mtd_blktrans_dev *dev)
1069 kfree(dev); 1067 kfree(dev);
1070} 1068}
1071 1069
1072struct mtd_blktrans_ops ftl_tr = { 1070static struct mtd_blktrans_ops ftl_tr = {
1073 .name = "ftl", 1071 .name = "ftl",
1074 .major = FTL_MAJOR, 1072 .major = FTL_MAJOR,
1075 .part_bits = PART_BITS, 1073 .part_bits = PART_BITS,
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index b8917beeb650..c551d2f0779c 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -41,11 +41,6 @@
41 41
42char inftlmountrev[]="$Revision: 1.18 $"; 42char inftlmountrev[]="$Revision: 1.18 $";
43 43
44extern int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
45 size_t *retlen, uint8_t *buf);
46extern int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
47 size_t *retlen, uint8_t *buf);
48
49/* 44/*
50 * find_boot_record: Find the INFTL Media Header and its Spare copy which 45 * find_boot_record: Find the INFTL Media Header and its Spare copy which
51 * contains the various device information of the INFTL partition and 46 * contains the various device information of the INFTL partition and
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 12c253664eb2..1bd69aa9e22a 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -21,6 +21,9 @@ config MTD_PHYSMAP
21 particular board as well as the bus width, either statically 21 particular board as well as the bus width, either statically
22 with config options or at run-time. 22 with config options or at run-time.
23 23
24 To compile this driver as a module, choose M here: the
25 module will be called physmap.
26
24config MTD_PHYSMAP_START 27config MTD_PHYSMAP_START
25 hex "Physical start address of flash mapping" 28 hex "Physical start address of flash mapping"
26 depends on MTD_PHYSMAP 29 depends on MTD_PHYSMAP
diff --git a/drivers/mtd/maps/bast-flash.c b/drivers/mtd/maps/bast-flash.c
index fc3b2672d1e2..1f492062f8ca 100644
--- a/drivers/mtd/maps/bast-flash.c
+++ b/drivers/mtd/maps/bast-flash.c
@@ -137,7 +137,7 @@ static int bast_flash_probe(struct platform_device *pdev)
137 if (info->map.size > AREA_MAXSIZE) 137 if (info->map.size > AREA_MAXSIZE)
138 info->map.size = AREA_MAXSIZE; 138 info->map.size = AREA_MAXSIZE;
139 139
140 pr_debug("%s: area %08lx, size %ld\n", __FUNCTION__, 140 pr_debug("%s: area %08lx, size %ld\n", __func__,
141 info->map.phys, info->map.size); 141 info->map.phys, info->map.size);
142 142
143 info->area = request_mem_region(res->start, info->map.size, 143 info->area = request_mem_region(res->start, info->map.size,
@@ -149,7 +149,7 @@ static int bast_flash_probe(struct platform_device *pdev)
149 } 149 }
150 150
151 info->map.virt = ioremap(res->start, info->map.size); 151 info->map.virt = ioremap(res->start, info->map.size);
152 pr_debug("%s: virt at %08x\n", __FUNCTION__, (int)info->map.virt); 152 pr_debug("%s: virt at %08x\n", __func__, (int)info->map.virt);
153 153
154 if (info->map.virt == 0) { 154 if (info->map.virt == 0) {
155 printk(KERN_ERR PFX "failed to ioremap() region\n"); 155 printk(KERN_ERR PFX "failed to ioremap() region\n");
@@ -223,3 +223,4 @@ module_exit(bast_flash_exit);
223MODULE_LICENSE("GPL"); 223MODULE_LICENSE("GPL");
224MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 224MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
225MODULE_DESCRIPTION("BAST MTD Map driver"); 225MODULE_DESCRIPTION("BAST MTD Map driver");
226MODULE_ALIAS("platform:bast-nor");
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 688ef495888a..59d8fb49270a 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -28,6 +28,9 @@
28 28
29#define ROM_PROBE_STEP_SIZE (64*1024) 29#define ROM_PROBE_STEP_SIZE (64*1024)
30 30
31#define DEV_CK804 1
32#define DEV_MCP55 2
33
31struct ck804xrom_window { 34struct ck804xrom_window {
32 void __iomem *virt; 35 void __iomem *virt;
33 unsigned long phys; 36 unsigned long phys;
@@ -45,8 +48,9 @@ struct ck804xrom_map_info {
45 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN]; 48 char map_name[sizeof(MOD_NAME) + 2 + ADDRESS_NAME_LEN];
46}; 49};
47 50
48 51/*
49/* The 2 bits controlling the window size are often set to allow reading 52 * The following applies to ck804 only:
53 * The 2 bits controlling the window size are often set to allow reading
50 * the BIOS, but too small to allow writing, since the lock registers are 54 * the BIOS, but too small to allow writing, since the lock registers are
51 * 4MiB lower in the address space than the data. 55 * 4MiB lower in the address space than the data.
52 * 56 *
@@ -58,10 +62,17 @@ struct ck804xrom_map_info {
58 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a 62 * If only the 7 Bit is set, it is a 4MiB window. Otherwise, a
59 * 64KiB window. 63 * 64KiB window.
60 * 64 *
65 * The following applies to mcp55 only:
66 * The 15 bits controlling the window size are distributed as follows:
67 * byte @0x88: bit 0..7
68 * byte @0x8c: bit 8..15
69 * word @0x90: bit 16..30
70 * If all bits are enabled, we have a 16? MiB window
71 * Please set win_size_bits to 0x7fffffff if you actually want to do something
61 */ 72 */
62static uint win_size_bits = 0; 73static uint win_size_bits = 0;
63module_param(win_size_bits, uint, 0); 74module_param(win_size_bits, uint, 0);
64MODULE_PARM_DESC(win_size_bits, "ROM window size bits override for 0x88 byte, normally set by BIOS."); 75MODULE_PARM_DESC(win_size_bits, "ROM window size bits override, normally set by BIOS.");
65 76
66static struct ck804xrom_window ck804xrom_window = { 77static struct ck804xrom_window ck804xrom_window = {
67 .maps = LIST_HEAD_INIT(ck804xrom_window.maps), 78 .maps = LIST_HEAD_INIT(ck804xrom_window.maps),
@@ -102,10 +113,11 @@ static void ck804xrom_cleanup(struct ck804xrom_window *window)
102 113
103 114
104static int __devinit ck804xrom_init_one (struct pci_dev *pdev, 115static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
105 const struct pci_device_id *ent) 116 const struct pci_device_id *ent)
106{ 117{
107 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 118 static char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
108 u8 byte; 119 u8 byte;
120 u16 word;
109 struct ck804xrom_window *window = &ck804xrom_window; 121 struct ck804xrom_window *window = &ck804xrom_window;
110 struct ck804xrom_map_info *map = NULL; 122 struct ck804xrom_map_info *map = NULL;
111 unsigned long map_top; 123 unsigned long map_top;
@@ -113,26 +125,42 @@ static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
113 /* Remember the pci dev I find the window in */ 125 /* Remember the pci dev I find the window in */
114 window->pdev = pci_dev_get(pdev); 126 window->pdev = pci_dev_get(pdev);
115 127
116 /* Enable the selected rom window. This is often incorrectly 128 switch (ent->driver_data) {
117 * set up by the BIOS, and the 4MiB offset for the lock registers 129 case DEV_CK804:
118 * requires the full 5MiB of window space. 130 /* Enable the selected rom window. This is often incorrectly
119 * 131 * set up by the BIOS, and the 4MiB offset for the lock registers
120 * This 'write, then read' approach leaves the bits for 132 * requires the full 5MiB of window space.
121 * other uses of the hardware info. 133 *
122 */ 134 * This 'write, then read' approach leaves the bits for
123 pci_read_config_byte(pdev, 0x88, &byte); 135 * other uses of the hardware info.
124 pci_write_config_byte(pdev, 0x88, byte | win_size_bits ); 136 */
125 137 pci_read_config_byte(pdev, 0x88, &byte);
126 138 pci_write_config_byte(pdev, 0x88, byte | win_size_bits );
127 /* Assume the rom window is properly setup, and find it's size */ 139
128 pci_read_config_byte(pdev, 0x88, &byte); 140 /* Assume the rom window is properly setup, and find it's size */
129 141 pci_read_config_byte(pdev, 0x88, &byte);
130 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6))) 142
131 window->phys = 0xffb00000; /* 5MiB */ 143 if ((byte & ((1<<7)|(1<<6))) == ((1<<7)|(1<<6)))
132 else if ((byte & (1<<7)) == (1<<7)) 144 window->phys = 0xffb00000; /* 5MiB */
133 window->phys = 0xffc00000; /* 4MiB */ 145 else if ((byte & (1<<7)) == (1<<7))
134 else 146 window->phys = 0xffc00000; /* 4MiB */
135 window->phys = 0xffff0000; /* 64KiB */ 147 else
148 window->phys = 0xffff0000; /* 64KiB */
149 break;
150
151 case DEV_MCP55:
152 pci_read_config_byte(pdev, 0x88, &byte);
153 pci_write_config_byte(pdev, 0x88, byte | (win_size_bits & 0xff));
154
155 pci_read_config_byte(pdev, 0x8c, &byte);
156 pci_write_config_byte(pdev, 0x8c, byte | ((win_size_bits & 0xff00) >> 8));
157
158 pci_read_config_word(pdev, 0x90, &word);
159 pci_write_config_word(pdev, 0x90, word | ((win_size_bits & 0x7fff0000) >> 16));
160
161 window->phys = 0xff000000; /* 16MiB, hardcoded for now */
162 break;
163 }
136 164
137 window->size = 0xffffffffUL - window->phys + 1UL; 165 window->size = 0xffffffffUL - window->phys + 1UL;
138 166
@@ -303,8 +331,15 @@ static void __devexit ck804xrom_remove_one (struct pci_dev *pdev)
303} 331}
304 332
305static struct pci_device_id ck804xrom_pci_tbl[] = { 333static struct pci_device_id ck804xrom_pci_tbl[] = {
306 { PCI_VENDOR_ID_NVIDIA, 0x0051, 334 { PCI_VENDOR_ID_NVIDIA, 0x0051, PCI_ANY_ID, PCI_ANY_ID, DEV_CK804 },
307 PCI_ANY_ID, PCI_ANY_ID, }, /* nvidia ck804 */ 335 { PCI_VENDOR_ID_NVIDIA, 0x0360, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
336 { PCI_VENDOR_ID_NVIDIA, 0x0361, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
337 { PCI_VENDOR_ID_NVIDIA, 0x0362, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
338 { PCI_VENDOR_ID_NVIDIA, 0x0363, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
339 { PCI_VENDOR_ID_NVIDIA, 0x0364, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
340 { PCI_VENDOR_ID_NVIDIA, 0x0365, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
341 { PCI_VENDOR_ID_NVIDIA, 0x0366, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
342 { PCI_VENDOR_ID_NVIDIA, 0x0367, PCI_ANY_ID, PCI_ANY_ID, DEV_MCP55 },
308 { 0, } 343 { 0, }
309}; 344};
310 345
@@ -332,7 +367,7 @@ static int __init init_ck804xrom(void)
332 break; 367 break;
333 } 368 }
334 if (pdev) { 369 if (pdev) {
335 retVal = ck804xrom_init_one(pdev, &ck804xrom_pci_tbl[0]); 370 retVal = ck804xrom_init_one(pdev, id);
336 pci_dev_put(pdev); 371 pci_dev_put(pdev);
337 return retVal; 372 return retVal;
338 } 373 }
diff --git a/drivers/mtd/maps/integrator-flash.c b/drivers/mtd/maps/integrator-flash.c
index 6946d802e6f6..325c8880c437 100644
--- a/drivers/mtd/maps/integrator-flash.c
+++ b/drivers/mtd/maps/integrator-flash.c
@@ -190,6 +190,7 @@ static struct platform_driver armflash_driver = {
190 .remove = armflash_remove, 190 .remove = armflash_remove,
191 .driver = { 191 .driver = {
192 .name = "armflash", 192 .name = "armflash",
193 .owner = THIS_MODULE,
193 }, 194 },
194}; 195};
195 196
@@ -209,3 +210,4 @@ module_exit(armflash_exit);
209MODULE_AUTHOR("ARM Ltd"); 210MODULE_AUTHOR("ARM Ltd");
210MODULE_DESCRIPTION("ARM Integrator CFI map driver"); 211MODULE_DESCRIPTION("ARM Integrator CFI map driver");
211MODULE_LICENSE("GPL"); 212MODULE_LICENSE("GPL");
213MODULE_ALIAS("platform:armflash");
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index c26488a1793a..c8396b8574c4 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -253,6 +253,7 @@ static struct platform_driver ixp2000_flash_driver = {
253 .remove = ixp2000_flash_remove, 253 .remove = ixp2000_flash_remove,
254 .driver = { 254 .driver = {
255 .name = "IXP2000-Flash", 255 .name = "IXP2000-Flash",
256 .owner = THIS_MODULE,
256 }, 257 },
257}; 258};
258 259
@@ -270,4 +271,4 @@ module_init(ixp2000_flash_init);
270module_exit(ixp2000_flash_exit); 271module_exit(ixp2000_flash_exit);
271MODULE_LICENSE("GPL"); 272MODULE_LICENSE("GPL");
272MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>"); 273MODULE_AUTHOR("Deepak Saxena <dsaxena@plexity.net>");
273 274MODULE_ALIAS("platform:IXP2000-Flash");
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 7a828e3e6446..01f19a4714b5 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -275,6 +275,7 @@ static struct platform_driver ixp4xx_flash_driver = {
275 .remove = ixp4xx_flash_remove, 275 .remove = ixp4xx_flash_remove,
276 .driver = { 276 .driver = {
277 .name = "IXP4XX-Flash", 277 .name = "IXP4XX-Flash",
278 .owner = THIS_MODULE,
278 }, 279 },
279}; 280};
280 281
@@ -295,3 +296,4 @@ module_exit(ixp4xx_flash_exit);
295MODULE_LICENSE("GPL"); 296MODULE_LICENSE("GPL");
296MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems"); 297MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems");
297MODULE_AUTHOR("Deepak Saxena"); 298MODULE_AUTHOR("Deepak Saxena");
299MODULE_ALIAS("platform:IXP4XX-Flash");
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index e8d9ae535673..240b0e2d095d 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -70,7 +70,7 @@ static void omap_set_vpp(struct map_info *map, int enable)
70 } 70 }
71} 71}
72 72
73static int __devinit omapflash_probe(struct platform_device *pdev) 73static int __init omapflash_probe(struct platform_device *pdev)
74{ 74{
75 int err; 75 int err;
76 struct omapflash_info *info; 76 struct omapflash_info *info;
@@ -130,7 +130,7 @@ out_free_info:
130 return err; 130 return err;
131} 131}
132 132
133static int __devexit omapflash_remove(struct platform_device *pdev) 133static int __exit omapflash_remove(struct platform_device *pdev)
134{ 134{
135 struct omapflash_info *info = platform_get_drvdata(pdev); 135 struct omapflash_info *info = platform_get_drvdata(pdev);
136 136
@@ -152,16 +152,16 @@ static int __devexit omapflash_remove(struct platform_device *pdev)
152} 152}
153 153
154static struct platform_driver omapflash_driver = { 154static struct platform_driver omapflash_driver = {
155 .probe = omapflash_probe, 155 .remove = __exit_p(omapflash_remove),
156 .remove = __devexit_p(omapflash_remove),
157 .driver = { 156 .driver = {
158 .name = "omapflash", 157 .name = "omapflash",
158 .owner = THIS_MODULE,
159 }, 159 },
160}; 160};
161 161
162static int __init omapflash_init(void) 162static int __init omapflash_init(void)
163{ 163{
164 return platform_driver_register(&omapflash_driver); 164 return platform_driver_probe(&omapflash_driver, omapflash_probe);
165} 165}
166 166
167static void __exit omapflash_exit(void) 167static void __exit omapflash_exit(void)
@@ -174,4 +174,4 @@ module_exit(omapflash_exit);
174 174
175MODULE_LICENSE("GPL"); 175MODULE_LICENSE("GPL");
176MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards"); 176MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
177 177MODULE_ALIAS("platform:omapflash");
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index eaeb56a4070a..1912d968718b 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -33,7 +33,7 @@ MODULE_PARM_DESC(debug, "Set Debug Level 0=quiet, 5=noisy");
33#undef DEBUG 33#undef DEBUG
34#define DEBUG(n, format, arg...) \ 34#define DEBUG(n, format, arg...) \
35 if (n <= debug) { \ 35 if (n <= debug) { \
36 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \ 36 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
37 } 37 }
38 38
39#else 39#else
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index bc4649a17b9d..183255fcfdcb 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -242,6 +242,7 @@ static struct platform_driver physmap_flash_driver = {
242 .shutdown = physmap_flash_shutdown, 242 .shutdown = physmap_flash_shutdown,
243 .driver = { 243 .driver = {
244 .name = "physmap-flash", 244 .name = "physmap-flash",
245 .owner = THIS_MODULE,
245 }, 246 },
246}; 247};
247 248
@@ -319,3 +320,10 @@ module_exit(physmap_exit);
319MODULE_LICENSE("GPL"); 320MODULE_LICENSE("GPL");
320MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 321MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
321MODULE_DESCRIPTION("Generic configurable MTD map driver"); 322MODULE_DESCRIPTION("Generic configurable MTD map driver");
323
324/* legacy platform drivers can't hotplug or coldplg */
325#ifndef PHYSMAP_COMPAT
326/* work with hotplug and coldplug */
327MODULE_ALIAS("platform:physmap-flash");
328#endif
329
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 894c0b271289..f0b10ca05029 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -47,6 +47,7 @@ struct platram_info {
47 struct mtd_info *mtd; 47 struct mtd_info *mtd;
48 struct map_info map; 48 struct map_info map;
49 struct mtd_partition *partitions; 49 struct mtd_partition *partitions;
50 bool free_partitions;
50 struct resource *area; 51 struct resource *area;
51 struct platdata_mtd_ram *pdata; 52 struct platdata_mtd_ram *pdata;
52}; 53};
@@ -98,7 +99,8 @@ static int platram_remove(struct platform_device *pdev)
98#ifdef CONFIG_MTD_PARTITIONS 99#ifdef CONFIG_MTD_PARTITIONS
99 if (info->partitions) { 100 if (info->partitions) {
100 del_mtd_partitions(info->mtd); 101 del_mtd_partitions(info->mtd);
101 kfree(info->partitions); 102 if (info->free_partitions)
103 kfree(info->partitions);
102 } 104 }
103#endif 105#endif
104 del_mtd_device(info->mtd); 106 del_mtd_device(info->mtd);
@@ -176,7 +178,8 @@ static int platram_probe(struct platform_device *pdev)
176 178
177 info->map.phys = res->start; 179 info->map.phys = res->start;
178 info->map.size = (res->end - res->start) + 1; 180 info->map.size = (res->end - res->start) + 1;
179 info->map.name = pdata->mapname != NULL ? pdata->mapname : (char *)pdev->name; 181 info->map.name = pdata->mapname != NULL ?
182 (char *)pdata->mapname : (char *)pdev->name;
180 info->map.bankwidth = pdata->bankwidth; 183 info->map.bankwidth = pdata->bankwidth;
181 184
182 /* register our usage of the memory area */ 185 /* register our usage of the memory area */
@@ -203,9 +206,19 @@ static int platram_probe(struct platform_device *pdev)
203 206
204 dev_dbg(&pdev->dev, "initialised map, probing for mtd\n"); 207 dev_dbg(&pdev->dev, "initialised map, probing for mtd\n");
205 208
206 /* probe for the right mtd map driver */ 209 /* probe for the right mtd map driver
210 * supplied by the platform_data struct */
211
212 if (pdata->map_probes != 0) {
213 const char **map_probes = pdata->map_probes;
214
215 for ( ; !info->mtd && *map_probes; map_probes++)
216 info->mtd = do_map_probe(*map_probes , &info->map);
217 }
218 /* fallback to map_ram */
219 else
220 info->mtd = do_map_probe("map_ram", &info->map);
207 221
208 info->mtd = do_map_probe("map_ram" , &info->map);
209 if (info->mtd == NULL) { 222 if (info->mtd == NULL) {
210 dev_err(&pdev->dev, "failed to probe for map_ram\n"); 223 dev_err(&pdev->dev, "failed to probe for map_ram\n");
211 err = -ENOMEM; 224 err = -ENOMEM;
@@ -220,19 +233,21 @@ static int platram_probe(struct platform_device *pdev)
220 * to add this device whole */ 233 * to add this device whole */
221 234
222#ifdef CONFIG_MTD_PARTITIONS 235#ifdef CONFIG_MTD_PARTITIONS
223 if (pdata->nr_partitions > 0) { 236 if (!pdata->nr_partitions) {
224 const char **probes = { NULL }; 237 /* try to probe using the supplied probe type */
225 238 if (pdata->probes) {
226 if (pdata->probes) 239 err = parse_mtd_partitions(info->mtd, pdata->probes,
227 probes = (const char **)pdata->probes;
228
229 err = parse_mtd_partitions(info->mtd, probes,
230 &info->partitions, 0); 240 &info->partitions, 0);
231 if (err > 0) { 241 info->free_partitions = 1;
232 err = add_mtd_partitions(info->mtd, info->partitions, 242 if (err > 0)
233 err); 243 err = add_mtd_partitions(info->mtd,
244 info->partitions, err);
234 } 245 }
235 } 246 }
247 /* use the static mapping */
248 else
249 err = add_mtd_partitions(info->mtd, pdata->partitions,
250 pdata->nr_partitions);
236#endif /* CONFIG_MTD_PARTITIONS */ 251#endif /* CONFIG_MTD_PARTITIONS */
237 252
238 if (add_mtd_device(info->mtd)) { 253 if (add_mtd_device(info->mtd)) {
@@ -240,7 +255,9 @@ static int platram_probe(struct platform_device *pdev)
240 err = -ENOMEM; 255 err = -ENOMEM;
241 } 256 }
242 257
243 dev_info(&pdev->dev, "registered mtd device\n"); 258 if (!err)
259 dev_info(&pdev->dev, "registered mtd device\n");
260
244 return err; 261 return err;
245 262
246 exit_free: 263 exit_free:
@@ -251,6 +268,9 @@ static int platram_probe(struct platform_device *pdev)
251 268
252/* device driver info */ 269/* device driver info */
253 270
271/* work with hotplug and coldplug */
272MODULE_ALIAS("platform:mtd-ram");
273
254static struct platform_driver platram_driver = { 274static struct platform_driver platram_driver = {
255 .probe = platram_probe, 275 .probe = platram_probe,
256 .remove = platram_remove, 276 .remove = platram_remove,
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 02bde8c982ec..f43ba2815cbb 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -46,7 +46,7 @@ static struct mtd_partition **msp_parts;
46static struct map_info *msp_maps; 46static struct map_info *msp_maps;
47static int fcnt; 47static int fcnt;
48 48
49#define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n",__FUNCTION__,__LINE__) 49#define DEBUG_MARKER printk(KERN_NOTICE "%s[%d]\n", __func__, __LINE__)
50 50
51int __init init_msp_flash(void) 51int __init init_msp_flash(void)
52{ 52{
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index f904e6bd02e0..c7d5a52a2d55 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -456,6 +456,7 @@ static struct platform_driver sa1100_mtd_driver = {
456 .shutdown = sa1100_mtd_shutdown, 456 .shutdown = sa1100_mtd_shutdown,
457 .driver = { 457 .driver = {
458 .name = "flash", 458 .name = "flash",
459 .owner = THIS_MODULE,
459 }, 460 },
460}; 461};
461 462
@@ -475,3 +476,4 @@ module_exit(sa1100_mtd_exit);
475MODULE_AUTHOR("Nicolas Pitre"); 476MODULE_AUTHOR("Nicolas Pitre");
476MODULE_DESCRIPTION("SA1100 CFI map driver"); 477MODULE_DESCRIPTION("SA1100 CFI map driver");
477MODULE_LICENSE("GPL"); 478MODULE_LICENSE("GPL");
479MODULE_ALIAS("platform:flash");
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
index 12fe53c0d2fc..917dc778f24e 100644
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ b/drivers/mtd/maps/sharpsl-flash.c
@@ -92,7 +92,7 @@ int __init init_sharpsl(void)
92 parts = sharpsl_partitions; 92 parts = sharpsl_partitions;
93 nb_parts = ARRAY_SIZE(sharpsl_partitions); 93 nb_parts = ARRAY_SIZE(sharpsl_partitions);
94 94
95 printk(KERN_NOTICE "Using %s partision definition\n", part_type); 95 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
96 add_mtd_partitions(mymtd, parts, nb_parts); 96 add_mtd_partitions(mymtd, parts, nb_parts);
97 97
98 return 0; 98 return 0;
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 37e4ded9b600..521734057314 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -124,7 +124,7 @@ int __init init_tqm_mtd(void)
124 //request maximum flash size address space 124 //request maximum flash size address space
125 start_scan_addr = ioremap(flash_addr, flash_size); 125 start_scan_addr = ioremap(flash_addr, flash_size);
126 if (!start_scan_addr) { 126 if (!start_scan_addr) {
127 printk(KERN_WARNING "%s:Failed to ioremap address:0x%x\n", __FUNCTION__, flash_addr); 127 printk(KERN_WARNING "%s:Failed to ioremap address:0x%x\n", __func__, flash_addr);
128 return -EIO; 128 return -EIO;
129 } 129 }
130 130
@@ -132,7 +132,7 @@ int __init init_tqm_mtd(void)
132 if(mtd_size >= flash_size) 132 if(mtd_size >= flash_size)
133 break; 133 break;
134 134
135 printk(KERN_INFO "%s: chip probing count %d\n", __FUNCTION__, idx); 135 printk(KERN_INFO "%s: chip probing count %d\n", __func__, idx);
136 136
137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL); 137 map_banks[idx] = kzalloc(sizeof(struct map_info), GFP_KERNEL);
138 if(map_banks[idx] == NULL) { 138 if(map_banks[idx] == NULL) {
@@ -178,7 +178,7 @@ int __init init_tqm_mtd(void)
178 mtd_size += mtd_banks[idx]->size; 178 mtd_size += mtd_banks[idx]->size;
179 num_banks++; 179 num_banks++;
180 180
181 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __FUNCTION__, num_banks, 181 printk(KERN_INFO "%s: bank%d, name:%s, size:%dbytes \n", __func__, num_banks,
182 mtd_banks[idx]->name, mtd_banks[idx]->size); 182 mtd_banks[idx]->name, mtd_banks[idx]->size);
183 } 183 }
184 } 184 }
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index d3cf05012b46..5a680e1e61f1 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -35,7 +35,7 @@
35 35
36#define OOPS_PAGE_SIZE 4096 36#define OOPS_PAGE_SIZE 4096
37 37
38struct mtdoops_context { 38static struct mtdoops_context {
39 int mtd_index; 39 int mtd_index;
40 struct work_struct work_erase; 40 struct work_struct work_erase;
41 struct work_struct work_write; 41 struct work_struct work_write;
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 959fb86cda01..5076faf9ca66 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -278,6 +278,54 @@ config MTD_NAND_AT91
278 help 278 help
279 Enables support for NAND Flash / Smart Media Card interface 279 Enables support for NAND Flash / Smart Media Card interface
280 on Atmel AT91 processors. 280 on Atmel AT91 processors.
281choice
282 prompt "ECC management for NAND Flash / SmartMedia on AT91"
283 depends on MTD_NAND_AT91
284
285config MTD_NAND_AT91_ECC_HW
286 bool "Hardware ECC"
287 depends on ARCH_AT91SAM9263 || ARCH_AT91SAM9260
288 help
289 Uses hardware ECC provided by the at91sam9260/at91sam9263 chip
290 instead of software ECC.
291 The hardware ECC controller is capable of single bit error
292 correction and 2-bit random detection per page.
293
294 NB : hardware and software ECC schemes are incompatible.
295 If you switch from one to another, you'll have to erase your
296 mtd partition.
297
298 If unsure, say Y
299
300config MTD_NAND_AT91_ECC_SOFT
301 bool "Software ECC"
302 help
303 Uses software ECC.
304
305 NB : hardware and software ECC schemes are incompatible.
306 If you switch from one to another, you'll have to erase your
307 mtd partition.
308
309config MTD_NAND_AT91_ECC_NONE
310 bool "No ECC (testing only, DANGEROUS)"
311 depends on DEBUG_KERNEL
312 help
313 No ECC will be used.
314 It's not a good idea and it should be reserved for testing
315 purpose only.
316
317 If unsure, say N
318
319 endchoice
320
321endchoice
322
323config MTD_NAND_PXA3xx
324 bool "Support for NAND flash devices on PXA3xx"
325 depends on MTD_NAND && PXA3xx
326 help
327 This enables the driver for the NAND flash device found on
328 PXA3xx processors
281 329
282config MTD_NAND_CM_X270 330config MTD_NAND_CM_X270
283 tristate "Support for NAND Flash on CM-X270 modules" 331 tristate "Support for NAND Flash on CM-X270 modules"
@@ -330,4 +378,12 @@ config MTD_NAND_FSL_ELBC
330 Enabling this option will enable you to use this to control 378 Enabling this option will enable you to use this to control
331 external NAND devices. 379 external NAND devices.
332 380
381config MTD_NAND_FSL_UPM
382 tristate "Support for NAND on Freescale UPM"
383 depends on MTD_NAND && OF_GPIO && (PPC_83xx || PPC_85xx)
384 select FSL_LBC
385 help
386 Enables support for NAND Flash chips wired onto Freescale PowerPC
387 processor localbus with User-Programmable Machine support.
388
333endif # MTD_NAND 389endif # MTD_NAND
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index 80d575eeee96..a6e74a46992a 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -27,10 +27,12 @@ obj-$(CONFIG_MTD_NAND_NDFC) += ndfc.o
27obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o 27obj-$(CONFIG_MTD_NAND_AT91) += at91_nand.o
28obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o 28obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o
29obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o 29obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o
30obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o
30obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o 31obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o
31obj-$(CONFIG_MTD_ALAUDA) += alauda.o 32obj-$(CONFIG_MTD_ALAUDA) += alauda.o
32obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o 33obj-$(CONFIG_MTD_NAND_PASEMI) += pasemi_nand.o
33obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o 34obj-$(CONFIG_MTD_NAND_ORION) += orion_nand.o
34obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o 35obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o
36obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o
35 37
36nand-objs := nand_base.o nand_bbt.o 38nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/at91_nand.c b/drivers/mtd/nand/at91_nand.c
index c9fb2acf4056..414ceaecdb3a 100644
--- a/drivers/mtd/nand/at91_nand.c
+++ b/drivers/mtd/nand/at91_nand.c
@@ -9,6 +9,15 @@
9 * Derived from drivers/mtd/spia.c 9 * Derived from drivers/mtd/spia.c
10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com) 10 * Copyright (C) 2000 Steven J. Hill (sjhill@cotw.com)
11 * 11 *
12 *
13 * Add Hardware ECC support for AT91SAM9260 / AT91SAM9263
14 * Richard Genoud (richard.genoud@gmail.com), Adeneo Copyright (C) 2007
15 *
16 * Derived from Das U-Boot source code
17 * (u-boot-1.1.5/board/atmel/at91sam9263ek/nand.c)
18 * (C) Copyright 2006 ATMEL Rousset, Lacressonniere Nicolas
19 *
20 *
12 * This program is free software; you can redistribute it and/or modify 21 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2 as 22 * it under the terms of the GNU General Public License version 2 as
14 * published by the Free Software Foundation. 23 * published by the Free Software Foundation.
@@ -29,11 +38,59 @@
29#include <asm/arch/board.h> 38#include <asm/arch/board.h>
30#include <asm/arch/gpio.h> 39#include <asm/arch/gpio.h>
31 40
41#ifdef CONFIG_MTD_NAND_AT91_ECC_HW
42#define hard_ecc 1
43#else
44#define hard_ecc 0
45#endif
46
47#ifdef CONFIG_MTD_NAND_AT91_ECC_NONE
48#define no_ecc 1
49#else
50#define no_ecc 0
51#endif
52
53/* Register access macros */
54#define ecc_readl(add, reg) \
55 __raw_readl(add + AT91_ECC_##reg)
56#define ecc_writel(add, reg, value) \
57 __raw_writel((value), add + AT91_ECC_##reg)
58
59#include <asm/arch/at91_ecc.h> /* AT91SAM9260/3 ECC registers */
60
61/* oob layout for large page size
62 * bad block info is on bytes 0 and 1
63 * the bytes have to be consecutives to avoid
64 * several NAND_CMD_RNDOUT during read
65 */
66static struct nand_ecclayout at91_oobinfo_large = {
67 .eccbytes = 4,
68 .eccpos = {60, 61, 62, 63},
69 .oobfree = {
70 {2, 58}
71 },
72};
73
74/* oob layout for small page size
75 * bad block info is on bytes 4 and 5
76 * the bytes have to be consecutives to avoid
77 * several NAND_CMD_RNDOUT during read
78 */
79static struct nand_ecclayout at91_oobinfo_small = {
80 .eccbytes = 4,
81 .eccpos = {0, 1, 2, 3},
82 .oobfree = {
83 {6, 10}
84 },
85};
86
32struct at91_nand_host { 87struct at91_nand_host {
33 struct nand_chip nand_chip; 88 struct nand_chip nand_chip;
34 struct mtd_info mtd; 89 struct mtd_info mtd;
35 void __iomem *io_base; 90 void __iomem *io_base;
36 struct at91_nand_data *board; 91 struct at91_nand_data *board;
92 struct device *dev;
93 void __iomem *ecc;
37}; 94};
38 95
39/* 96/*
@@ -44,6 +101,12 @@ static void at91_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
44 struct nand_chip *nand_chip = mtd->priv; 101 struct nand_chip *nand_chip = mtd->priv;
45 struct at91_nand_host *host = nand_chip->priv; 102 struct at91_nand_host *host = nand_chip->priv;
46 103
104 if (host->board->enable_pin && (ctrl & NAND_CTRL_CHANGE)) {
105 if (ctrl & NAND_NCE)
106 at91_set_gpio_value(host->board->enable_pin, 0);
107 else
108 at91_set_gpio_value(host->board->enable_pin, 1);
109 }
47 if (cmd == NAND_CMD_NONE) 110 if (cmd == NAND_CMD_NONE)
48 return; 111 return;
49 112
@@ -82,8 +145,217 @@ static void at91_nand_disable(struct at91_nand_host *host)
82 at91_set_gpio_value(host->board->enable_pin, 1); 145 at91_set_gpio_value(host->board->enable_pin, 1);
83} 146}
84 147
148/*
149 * write oob for small pages
150 */
151static int at91_nand_write_oob_512(struct mtd_info *mtd,
152 struct nand_chip *chip, int page)
153{
154 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;
155 int eccsize = chip->ecc.size, length = mtd->oobsize;
156 int len, pos, status = 0;
157 const uint8_t *bufpoi = chip->oob_poi;
158
159 pos = eccsize + chunk;
160
161 chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page);
162 len = min_t(int, length, chunk);
163 chip->write_buf(mtd, bufpoi, len);
164 bufpoi += len;
165 length -= len;
166 if (length > 0)
167 chip->write_buf(mtd, bufpoi, length);
168
169 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
170 status = chip->waitfunc(mtd, chip);
171
172 return status & NAND_STATUS_FAIL ? -EIO : 0;
173
174}
175
176/*
177 * read oob for small pages
178 */
179static int at91_nand_read_oob_512(struct mtd_info *mtd,
180 struct nand_chip *chip, int page, int sndcmd)
181{
182 if (sndcmd) {
183 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
184 sndcmd = 0;
185 }
186 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
187 return sndcmd;
188}
189
190/*
191 * Calculate HW ECC
192 *
193 * function called after a write
194 *
195 * mtd: MTD block structure
196 * dat: raw data (unused)
197 * ecc_code: buffer for ECC
198 */
199static int at91_nand_calculate(struct mtd_info *mtd,
200 const u_char *dat, unsigned char *ecc_code)
201{
202 struct nand_chip *nand_chip = mtd->priv;
203 struct at91_nand_host *host = nand_chip->priv;
204 uint32_t *eccpos = nand_chip->ecc.layout->eccpos;
205 unsigned int ecc_value;
206
207 /* get the first 2 ECC bytes */
208 ecc_value = ecc_readl(host->ecc, PR);
209
210 ecc_code[eccpos[0]] = ecc_value & 0xFF;
211 ecc_code[eccpos[1]] = (ecc_value >> 8) & 0xFF;
212
213 /* get the last 2 ECC bytes */
214 ecc_value = ecc_readl(host->ecc, NPR) & AT91_ECC_NPARITY;
215
216 ecc_code[eccpos[2]] = ecc_value & 0xFF;
217 ecc_code[eccpos[3]] = (ecc_value >> 8) & 0xFF;
218
219 return 0;
220}
221
222/*
223 * HW ECC read page function
224 *
225 * mtd: mtd info structure
226 * chip: nand chip info structure
227 * buf: buffer to store read data
228 */
229static int at91_nand_read_page(struct mtd_info *mtd,
230 struct nand_chip *chip, uint8_t *buf)
231{
232 int eccsize = chip->ecc.size;
233 int eccbytes = chip->ecc.bytes;
234 uint32_t *eccpos = chip->ecc.layout->eccpos;
235 uint8_t *p = buf;
236 uint8_t *oob = chip->oob_poi;
237 uint8_t *ecc_pos;
238 int stat;
239
240 /* read the page */
241 chip->read_buf(mtd, p, eccsize);
242
243 /* move to ECC position if needed */
244 if (eccpos[0] != 0) {
245 /* This only works on large pages
246 * because the ECC controller waits for
247 * NAND_CMD_RNDOUTSTART after the
248 * NAND_CMD_RNDOUT.
249 * anyway, for small pages, the eccpos[0] == 0
250 */
251 chip->cmdfunc(mtd, NAND_CMD_RNDOUT,
252 mtd->writesize + eccpos[0], -1);
253 }
254
255 /* the ECC controller needs to read the ECC just after the data */
256 ecc_pos = oob + eccpos[0];
257 chip->read_buf(mtd, ecc_pos, eccbytes);
258
259 /* check if there's an error */
260 stat = chip->ecc.correct(mtd, p, oob, NULL);
261
262 if (stat < 0)
263 mtd->ecc_stats.failed++;
264 else
265 mtd->ecc_stats.corrected += stat;
266
267 /* get back to oob start (end of page) */
268 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1);
269
270 /* read the oob */
271 chip->read_buf(mtd, oob, mtd->oobsize);
272
273 return 0;
274}
275
276/*
277 * HW ECC Correction
278 *
279 * function called after a read
280 *
281 * mtd: MTD block structure
282 * dat: raw data read from the chip
283 * read_ecc: ECC from the chip (unused)
284 * isnull: unused
285 *
286 * Detect and correct a 1 bit error for a page
287 */
288static int at91_nand_correct(struct mtd_info *mtd, u_char *dat,
289 u_char *read_ecc, u_char *isnull)
290{
291 struct nand_chip *nand_chip = mtd->priv;
292 struct at91_nand_host *host = nand_chip->priv;
293 unsigned int ecc_status;
294 unsigned int ecc_word, ecc_bit;
295
296 /* get the status from the Status Register */
297 ecc_status = ecc_readl(host->ecc, SR);
298
299 /* if there's no error */
300 if (likely(!(ecc_status & AT91_ECC_RECERR)))
301 return 0;
302
303 /* get error bit offset (4 bits) */
304 ecc_bit = ecc_readl(host->ecc, PR) & AT91_ECC_BITADDR;
305 /* get word address (12 bits) */
306 ecc_word = ecc_readl(host->ecc, PR) & AT91_ECC_WORDADDR;
307 ecc_word >>= 4;
308
309 /* if there are multiple errors */
310 if (ecc_status & AT91_ECC_MULERR) {
311 /* check if it is a freshly erased block
312 * (filled with 0xff) */
313 if ((ecc_bit == AT91_ECC_BITADDR)
314 && (ecc_word == (AT91_ECC_WORDADDR >> 4))) {
315 /* the block has just been erased, return OK */
316 return 0;
317 }
318 /* it doesn't seems to be a freshly
319 * erased block.
320 * We can't correct so many errors */
321 dev_dbg(host->dev, "at91_nand : multiple errors detected."
322 " Unable to correct.\n");
323 return -EIO;
324 }
325
326 /* if there's a single bit error : we can correct it */
327 if (ecc_status & AT91_ECC_ECCERR) {
328 /* there's nothing much to do here.
329 * the bit error is on the ECC itself.
330 */
331 dev_dbg(host->dev, "at91_nand : one bit error on ECC code."
332 " Nothing to correct\n");
333 return 0;
334 }
335
336 dev_dbg(host->dev, "at91_nand : one bit error on data."
337 " (word offset in the page :"
338 " 0x%x bit offset : 0x%x)\n",
339 ecc_word, ecc_bit);
340 /* correct the error */
341 if (nand_chip->options & NAND_BUSWIDTH_16) {
342 /* 16 bits words */
343 ((unsigned short *) dat)[ecc_word] ^= (1 << ecc_bit);
344 } else {
345 /* 8 bits words */
346 dat[ecc_word] ^= (1 << ecc_bit);
347 }
348 dev_dbg(host->dev, "at91_nand : error corrected\n");
349 return 1;
350}
351
352/*
353 * Enable HW ECC : unsused
354 */
355static void at91_nand_hwctl(struct mtd_info *mtd, int mode) { ; }
356
85#ifdef CONFIG_MTD_PARTITIONS 357#ifdef CONFIG_MTD_PARTITIONS
86const char *part_probes[] = { "cmdlinepart", NULL }; 358static const char *part_probes[] = { "cmdlinepart", NULL };
87#endif 359#endif
88 360
89/* 361/*
@@ -94,6 +366,8 @@ static int __init at91_nand_probe(struct platform_device *pdev)
94 struct at91_nand_host *host; 366 struct at91_nand_host *host;
95 struct mtd_info *mtd; 367 struct mtd_info *mtd;
96 struct nand_chip *nand_chip; 368 struct nand_chip *nand_chip;
369 struct resource *regs;
370 struct resource *mem;
97 int res; 371 int res;
98 372
99#ifdef CONFIG_MTD_PARTITIONS 373#ifdef CONFIG_MTD_PARTITIONS
@@ -108,8 +382,13 @@ static int __init at91_nand_probe(struct platform_device *pdev)
108 return -ENOMEM; 382 return -ENOMEM;
109 } 383 }
110 384
111 host->io_base = ioremap(pdev->resource[0].start, 385 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
112 pdev->resource[0].end - pdev->resource[0].start + 1); 386 if (!mem) {
387 printk(KERN_ERR "at91_nand: can't get I/O resource mem\n");
388 return -ENXIO;
389 }
390
391 host->io_base = ioremap(mem->start, mem->end - mem->start + 1);
113 if (host->io_base == NULL) { 392 if (host->io_base == NULL) {
114 printk(KERN_ERR "at91_nand: ioremap failed\n"); 393 printk(KERN_ERR "at91_nand: ioremap failed\n");
115 kfree(host); 394 kfree(host);
@@ -119,6 +398,7 @@ static int __init at91_nand_probe(struct platform_device *pdev)
119 mtd = &host->mtd; 398 mtd = &host->mtd;
120 nand_chip = &host->nand_chip; 399 nand_chip = &host->nand_chip;
121 host->board = pdev->dev.platform_data; 400 host->board = pdev->dev.platform_data;
401 host->dev = &pdev->dev;
122 402
123 nand_chip->priv = host; /* link the private data structures */ 403 nand_chip->priv = host; /* link the private data structures */
124 mtd->priv = nand_chip; 404 mtd->priv = nand_chip;
@@ -132,7 +412,32 @@ static int __init at91_nand_probe(struct platform_device *pdev)
132 if (host->board->rdy_pin) 412 if (host->board->rdy_pin)
133 nand_chip->dev_ready = at91_nand_device_ready; 413 nand_chip->dev_ready = at91_nand_device_ready;
134 414
415 regs = platform_get_resource(pdev, IORESOURCE_MEM, 1);
416 if (!regs && hard_ecc) {
417 printk(KERN_ERR "at91_nand: can't get I/O resource "
418 "regs\nFalling back on software ECC\n");
419 }
420
135 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */ 421 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */
422 if (no_ecc)
423 nand_chip->ecc.mode = NAND_ECC_NONE;
424 if (hard_ecc && regs) {
425 host->ecc = ioremap(regs->start, regs->end - regs->start + 1);
426 if (host->ecc == NULL) {
427 printk(KERN_ERR "at91_nand: ioremap failed\n");
428 res = -EIO;
429 goto err_ecc_ioremap;
430 }
431 nand_chip->ecc.mode = NAND_ECC_HW_SYNDROME;
432 nand_chip->ecc.calculate = at91_nand_calculate;
433 nand_chip->ecc.correct = at91_nand_correct;
434 nand_chip->ecc.hwctl = at91_nand_hwctl;
435 nand_chip->ecc.read_page = at91_nand_read_page;
436 nand_chip->ecc.bytes = 4;
437 nand_chip->ecc.prepad = 0;
438 nand_chip->ecc.postpad = 0;
439 }
440
136 nand_chip->chip_delay = 20; /* 20us command delay time */ 441 nand_chip->chip_delay = 20; /* 20us command delay time */
137 442
138 if (host->board->bus_width_16) /* 16-bit bus width */ 443 if (host->board->bus_width_16) /* 16-bit bus width */
@@ -149,8 +454,53 @@ static int __init at91_nand_probe(struct platform_device *pdev)
149 } 454 }
150 } 455 }
151 456
152 /* Scan to find existance of the device */ 457 /* first scan to find the device and get the page size */
153 if (nand_scan(mtd, 1)) { 458 if (nand_scan_ident(mtd, 1)) {
459 res = -ENXIO;
460 goto out;
461 }
462
463 if (nand_chip->ecc.mode == NAND_ECC_HW_SYNDROME) {
464 /* ECC is calculated for the whole page (1 step) */
465 nand_chip->ecc.size = mtd->writesize;
466
467 /* set ECC page size and oob layout */
468 switch (mtd->writesize) {
469 case 512:
470 nand_chip->ecc.layout = &at91_oobinfo_small;
471 nand_chip->ecc.read_oob = at91_nand_read_oob_512;
472 nand_chip->ecc.write_oob = at91_nand_write_oob_512;
473 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_528);
474 break;
475 case 1024:
476 nand_chip->ecc.layout = &at91_oobinfo_large;
477 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_1056);
478 break;
479 case 2048:
480 nand_chip->ecc.layout = &at91_oobinfo_large;
481 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_2112);
482 break;
483 case 4096:
484 nand_chip->ecc.layout = &at91_oobinfo_large;
485 ecc_writel(host->ecc, MR, AT91_ECC_PAGESIZE_4224);
486 break;
487 default:
488 /* page size not handled by HW ECC */
489 /* switching back to soft ECC */
490 nand_chip->ecc.mode = NAND_ECC_SOFT;
491 nand_chip->ecc.calculate = NULL;
492 nand_chip->ecc.correct = NULL;
493 nand_chip->ecc.hwctl = NULL;
494 nand_chip->ecc.read_page = NULL;
495 nand_chip->ecc.postpad = 0;
496 nand_chip->ecc.prepad = 0;
497 nand_chip->ecc.bytes = 0;
498 break;
499 }
500 }
501
502 /* second phase scan */
503 if (nand_scan_tail(mtd)) {
154 res = -ENXIO; 504 res = -ENXIO;
155 goto out; 505 goto out;
156 } 506 }
@@ -179,9 +529,15 @@ static int __init at91_nand_probe(struct platform_device *pdev)
179 if (!res) 529 if (!res)
180 return res; 530 return res;
181 531
532#ifdef CONFIG_MTD_PARTITIONS
182release: 533release:
534#endif
183 nand_release(mtd); 535 nand_release(mtd);
536
184out: 537out:
538 iounmap(host->ecc);
539
540err_ecc_ioremap:
185 at91_nand_disable(host); 541 at91_nand_disable(host);
186 platform_set_drvdata(pdev, NULL); 542 platform_set_drvdata(pdev, NULL);
187 iounmap(host->io_base); 543 iounmap(host->io_base);
@@ -202,6 +558,7 @@ static int __devexit at91_nand_remove(struct platform_device *pdev)
202 at91_nand_disable(host); 558 at91_nand_disable(host);
203 559
204 iounmap(host->io_base); 560 iounmap(host->io_base);
561 iounmap(host->ecc);
205 kfree(host); 562 kfree(host);
206 563
207 return 0; 564 return 0;
@@ -233,4 +590,5 @@ module_exit(at91_nand_exit);
233 590
234MODULE_LICENSE("GPL"); 591MODULE_LICENSE("GPL");
235MODULE_AUTHOR("Rick Bronson"); 592MODULE_AUTHOR("Rick Bronson");
236MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200"); 593MODULE_DESCRIPTION("NAND/SmartMedia driver for AT91RM9200 / AT91SAM9");
594MODULE_ALIAS("platform:at91_nand");
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 747042ab094a..e87a57297328 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -1,6 +1,6 @@
1/* linux/drivers/mtd/nand/bf5xx_nand.c 1/* linux/drivers/mtd/nand/bf5xx_nand.c
2 * 2 *
3 * Copyright 2006-2007 Analog Devices Inc. 3 * Copyright 2006-2008 Analog Devices Inc.
4 * http://blackfin.uclinux.org/ 4 * http://blackfin.uclinux.org/
5 * Bryan Wu <bryan.wu@analog.com> 5 * Bryan Wu <bryan.wu@analog.com>
6 * 6 *
@@ -74,7 +74,7 @@ static int hardware_ecc = 1;
74static int hardware_ecc; 74static int hardware_ecc;
75#endif 75#endif
76 76
77static unsigned short bfin_nfc_pin_req[] = 77static const unsigned short bfin_nfc_pin_req[] =
78 {P_NAND_CE, 78 {P_NAND_CE,
79 P_NAND_RB, 79 P_NAND_RB,
80 P_NAND_D0, 80 P_NAND_D0,
@@ -581,12 +581,6 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
581 bfin_write_NFC_IRQSTAT(val); 581 bfin_write_NFC_IRQSTAT(val);
582 SSYNC(); 582 SSYNC();
583 583
584 if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
585 printk(KERN_ERR DRV_NAME
586 ": Requesting Peripherals failed\n");
587 return -EFAULT;
588 }
589
590 /* DMA initialization */ 584 /* DMA initialization */
591 if (bf5xx_nand_dma_init(info)) 585 if (bf5xx_nand_dma_init(info))
592 err = -ENXIO; 586 err = -ENXIO;
@@ -654,6 +648,12 @@ static int bf5xx_nand_probe(struct platform_device *pdev)
654 648
655 dev_dbg(&pdev->dev, "(%p)\n", pdev); 649 dev_dbg(&pdev->dev, "(%p)\n", pdev);
656 650
651 if (peripheral_request_list(bfin_nfc_pin_req, DRV_NAME)) {
652 printk(KERN_ERR DRV_NAME
653 ": Requesting Peripherals failed\n");
654 return -EFAULT;
655 }
656
657 if (!plat) { 657 if (!plat) {
658 dev_err(&pdev->dev, "no platform specific information\n"); 658 dev_err(&pdev->dev, "no platform specific information\n");
659 goto exit_error; 659 goto exit_error;
@@ -803,3 +803,4 @@ module_exit(bf5xx_nand_exit);
803MODULE_LICENSE("GPL"); 803MODULE_LICENSE("GPL");
804MODULE_AUTHOR(DRV_AUTHOR); 804MODULE_AUTHOR(DRV_AUTHOR);
805MODULE_DESCRIPTION(DRV_DESC); 805MODULE_DESCRIPTION(DRV_DESC);
806MODULE_ALIAS("platform:" DRV_NAME);
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 8dab69657b19..3370a800fd36 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -279,7 +279,7 @@ static int is_geode(void)
279 279
280 280
281#ifdef CONFIG_MTD_PARTITIONS 281#ifdef CONFIG_MTD_PARTITIONS
282const char *part_probes[] = { "cmdlinepart", NULL }; 282static const char *part_probes[] = { "cmdlinepart", NULL };
283#endif 283#endif
284 284
285 285
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 378b7aa63812..4b69aacdf5ca 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -184,11 +184,11 @@ static int fsl_elbc_run_command(struct mtd_info *mtd)
184 in_be32(&lbc->fbar), in_be32(&lbc->fpar), 184 in_be32(&lbc->fbar), in_be32(&lbc->fpar),
185 in_be32(&lbc->fbcr), priv->bank); 185 in_be32(&lbc->fbcr), priv->bank);
186 186
187 ctrl->irq_status = 0;
187 /* execute special operation */ 188 /* execute special operation */
188 out_be32(&lbc->lsor, priv->bank); 189 out_be32(&lbc->lsor, priv->bank);
189 190
190 /* wait for FCM complete flag or timeout */ 191 /* wait for FCM complete flag or timeout */
191 ctrl->irq_status = 0;
192 wait_event_timeout(ctrl->irq_wait, ctrl->irq_status, 192 wait_event_timeout(ctrl->irq_wait, ctrl->irq_status,
193 FCM_TIMEOUT_MSECS * HZ/1000); 193 FCM_TIMEOUT_MSECS * HZ/1000);
194 ctrl->status = ctrl->irq_status; 194 ctrl->status = ctrl->irq_status;
@@ -346,19 +346,20 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command,
346 ctrl->column = column; 346 ctrl->column = column;
347 ctrl->oob = 0; 347 ctrl->oob = 0;
348 348
349 fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) |
350 (NAND_CMD_SEQIN << FCR_CMD2_SHIFT);
351
352 if (priv->page_size) { 349 if (priv->page_size) {
350 fcr = (NAND_CMD_SEQIN << FCR_CMD0_SHIFT) |
351 (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT);
352
353 out_be32(&lbc->fir, 353 out_be32(&lbc->fir,
354 (FIR_OP_CW0 << FIR_OP0_SHIFT) | 354 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
355 (FIR_OP_CA << FIR_OP1_SHIFT) | 355 (FIR_OP_CA << FIR_OP1_SHIFT) |
356 (FIR_OP_PA << FIR_OP2_SHIFT) | 356 (FIR_OP_PA << FIR_OP2_SHIFT) |
357 (FIR_OP_WB << FIR_OP3_SHIFT) | 357 (FIR_OP_WB << FIR_OP3_SHIFT) |
358 (FIR_OP_CW1 << FIR_OP4_SHIFT)); 358 (FIR_OP_CW1 << FIR_OP4_SHIFT));
359
360 fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT;
361 } else { 359 } else {
360 fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) |
361 (NAND_CMD_SEQIN << FCR_CMD2_SHIFT);
362
362 out_be32(&lbc->fir, 363 out_be32(&lbc->fir,
363 (FIR_OP_CW0 << FIR_OP0_SHIFT) | 364 (FIR_OP_CW0 << FIR_OP0_SHIFT) |
364 (FIR_OP_CM2 << FIR_OP1_SHIFT) | 365 (FIR_OP_CM2 << FIR_OP1_SHIFT) |
@@ -480,7 +481,7 @@ static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
480 struct fsl_elbc_ctrl *ctrl = priv->ctrl; 481 struct fsl_elbc_ctrl *ctrl = priv->ctrl;
481 unsigned int bufsize = mtd->writesize + mtd->oobsize; 482 unsigned int bufsize = mtd->writesize + mtd->oobsize;
482 483
483 if (len < 0) { 484 if (len <= 0) {
484 dev_err(ctrl->dev, "write_buf of %d bytes", len); 485 dev_err(ctrl->dev, "write_buf of %d bytes", len);
485 ctrl->status = 0; 486 ctrl->status = 0;
486 return; 487 return;
@@ -495,6 +496,15 @@ static void fsl_elbc_write_buf(struct mtd_info *mtd, const u8 *buf, int len)
495 } 496 }
496 497
497 memcpy_toio(&ctrl->addr[ctrl->index], buf, len); 498 memcpy_toio(&ctrl->addr[ctrl->index], buf, len);
499 /*
500 * This is workaround for the weird elbc hangs during nand write,
501 * Scott Wood says: "...perhaps difference in how long it takes a
502 * write to make it through the localbus compared to a write to IMMR
503 * is causing problems, and sync isn't helping for some reason."
504 * Reading back the last byte helps though.
505 */
506 in_8(&ctrl->addr[ctrl->index] + len - 1);
507
498 ctrl->index += len; 508 ctrl->index += len;
499} 509}
500 510
@@ -666,7 +676,7 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
666 /* adjust Option Register and ECC to match Flash page size */ 676 /* adjust Option Register and ECC to match Flash page size */
667 if (mtd->writesize == 512) { 677 if (mtd->writesize == 512) {
668 priv->page_size = 0; 678 priv->page_size = 0;
669 clrbits32(&lbc->bank[priv->bank].or, ~OR_FCM_PGS); 679 clrbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
670 } else if (mtd->writesize == 2048) { 680 } else if (mtd->writesize == 2048) {
671 priv->page_size = 1; 681 priv->page_size = 1;
672 setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS); 682 setbits32(&lbc->bank[priv->bank].or, OR_FCM_PGS);
@@ -687,11 +697,6 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd)
687 return -1; 697 return -1;
688 } 698 }
689 699
690 /* The default u-boot configuration on MPC8313ERDB causes errors;
691 * more delay is needed. This should be safe for other boards
692 * as well.
693 */
694 setbits32(&lbc->bank[priv->bank].or, 0x70);
695 return 0; 700 return 0;
696} 701}
697 702
@@ -779,6 +784,8 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
779 784
780 nand_release(&priv->mtd); 785 nand_release(&priv->mtd);
781 786
787 kfree(priv->mtd.name);
788
782 if (priv->vbase) 789 if (priv->vbase)
783 iounmap(priv->vbase); 790 iounmap(priv->vbase);
784 791
@@ -839,6 +846,12 @@ static int fsl_elbc_chip_probe(struct fsl_elbc_ctrl *ctrl,
839 goto err; 846 goto err;
840 } 847 }
841 848
849 priv->mtd.name = kasprintf(GFP_KERNEL, "%x.flash", res.start);
850 if (!priv->mtd.name) {
851 ret = -ENOMEM;
852 goto err;
853 }
854
842 ret = fsl_elbc_chip_init(priv); 855 ret = fsl_elbc_chip_init(priv);
843 if (ret) 856 if (ret)
844 goto err; 857 goto err;
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
new file mode 100644
index 000000000000..1ebfd87f00b4
--- /dev/null
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -0,0 +1,291 @@
1/*
2 * Freescale UPM NAND driver.
3 *
4 * Copyright © 2007-2008 MontaVista Software, Inc.
5 *
6 * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 */
13
14#include <linux/kernel.h>
15#include <linux/module.h>
16#include <linux/mtd/nand.h>
17#include <linux/mtd/nand_ecc.h>
18#include <linux/mtd/partitions.h>
19#include <linux/mtd/mtd.h>
20#include <linux/of_platform.h>
21#include <linux/of_gpio.h>
22#include <linux/io.h>
23#include <asm/fsl_lbc.h>
24
25struct fsl_upm_nand {
26 struct device *dev;
27 struct mtd_info mtd;
28 struct nand_chip chip;
29 int last_ctrl;
30#ifdef CONFIG_MTD_PARTITIONS
31 struct mtd_partition *parts;
32#endif
33
34 struct fsl_upm upm;
35 uint8_t upm_addr_offset;
36 uint8_t upm_cmd_offset;
37 void __iomem *io_base;
38 int rnb_gpio;
39 const uint32_t *wait_pattern;
40 const uint32_t *wait_write;
41 int chip_delay;
42};
43
44#define to_fsl_upm_nand(mtd) container_of(mtd, struct fsl_upm_nand, mtd)
45
46static int fun_chip_ready(struct mtd_info *mtd)
47{
48 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
49
50 if (gpio_get_value(fun->rnb_gpio))
51 return 1;
52
53 dev_vdbg(fun->dev, "busy\n");
54 return 0;
55}
56
57static void fun_wait_rnb(struct fsl_upm_nand *fun)
58{
59 int cnt = 1000000;
60
61 if (fun->rnb_gpio >= 0) {
62 while (--cnt && !fun_chip_ready(&fun->mtd))
63 cpu_relax();
64 }
65
66 if (!cnt)
67 dev_err(fun->dev, "tired waiting for RNB\n");
68}
69
70static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
71{
72 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
73
74 if (!(ctrl & fun->last_ctrl)) {
75 fsl_upm_end_pattern(&fun->upm);
76
77 if (cmd == NAND_CMD_NONE)
78 return;
79
80 fun->last_ctrl = ctrl & (NAND_ALE | NAND_CLE);
81 }
82
83 if (ctrl & NAND_CTRL_CHANGE) {
84 if (ctrl & NAND_ALE)
85 fsl_upm_start_pattern(&fun->upm, fun->upm_addr_offset);
86 else if (ctrl & NAND_CLE)
87 fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset);
88 }
89
90 fsl_upm_run_pattern(&fun->upm, fun->io_base, cmd);
91
92 if (fun->wait_pattern)
93 fun_wait_rnb(fun);
94}
95
96static uint8_t fun_read_byte(struct mtd_info *mtd)
97{
98 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
99
100 return in_8(fun->chip.IO_ADDR_R);
101}
102
103static void fun_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
104{
105 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
106 int i;
107
108 for (i = 0; i < len; i++)
109 buf[i] = in_8(fun->chip.IO_ADDR_R);
110}
111
112static void fun_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
113{
114 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
115 int i;
116
117 for (i = 0; i < len; i++) {
118 out_8(fun->chip.IO_ADDR_W, buf[i]);
119 if (fun->wait_write)
120 fun_wait_rnb(fun);
121 }
122}
123
124static int __devinit fun_chip_init(struct fsl_upm_nand *fun)
125{
126 int ret;
127#ifdef CONFIG_MTD_PARTITIONS
128 static const char *part_types[] = { "cmdlinepart", NULL, };
129#endif
130
131 fun->chip.IO_ADDR_R = fun->io_base;
132 fun->chip.IO_ADDR_W = fun->io_base;
133 fun->chip.cmd_ctrl = fun_cmd_ctrl;
134 fun->chip.chip_delay = fun->chip_delay;
135 fun->chip.read_byte = fun_read_byte;
136 fun->chip.read_buf = fun_read_buf;
137 fun->chip.write_buf = fun_write_buf;
138 fun->chip.ecc.mode = NAND_ECC_SOFT;
139
140 if (fun->rnb_gpio >= 0)
141 fun->chip.dev_ready = fun_chip_ready;
142
143 fun->mtd.priv = &fun->chip;
144 fun->mtd.owner = THIS_MODULE;
145
146 ret = nand_scan(&fun->mtd, 1);
147 if (ret)
148 return ret;
149
150 fun->mtd.name = fun->dev->bus_id;
151
152#ifdef CONFIG_MTD_PARTITIONS
153 ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0);
154 if (ret > 0)
155 return add_mtd_partitions(&fun->mtd, fun->parts, ret);
156#endif
157 return add_mtd_device(&fun->mtd);
158}
159
160static int __devinit fun_probe(struct of_device *ofdev,
161 const struct of_device_id *ofid)
162{
163 struct fsl_upm_nand *fun;
164 struct resource io_res;
165 const uint32_t *prop;
166 int ret;
167 int size;
168
169 fun = kzalloc(sizeof(*fun), GFP_KERNEL);
170 if (!fun)
171 return -ENOMEM;
172
173 ret = of_address_to_resource(ofdev->node, 0, &io_res);
174 if (ret) {
175 dev_err(&ofdev->dev, "can't get IO base\n");
176 goto err1;
177 }
178
179 ret = fsl_upm_find(io_res.start, &fun->upm);
180 if (ret) {
181 dev_err(&ofdev->dev, "can't find UPM\n");
182 goto err1;
183 }
184
185 prop = of_get_property(ofdev->node, "fsl,upm-addr-offset", &size);
186 if (!prop || size != sizeof(uint32_t)) {
187 dev_err(&ofdev->dev, "can't get UPM address offset\n");
188 ret = -EINVAL;
189 goto err2;
190 }
191 fun->upm_addr_offset = *prop;
192
193 prop = of_get_property(ofdev->node, "fsl,upm-cmd-offset", &size);
194 if (!prop || size != sizeof(uint32_t)) {
195 dev_err(&ofdev->dev, "can't get UPM command offset\n");
196 ret = -EINVAL;
197 goto err2;
198 }
199 fun->upm_cmd_offset = *prop;
200
201 fun->rnb_gpio = of_get_gpio(ofdev->node, 0);
202 if (fun->rnb_gpio >= 0) {
203 ret = gpio_request(fun->rnb_gpio, ofdev->dev.bus_id);
204 if (ret) {
205 dev_err(&ofdev->dev, "can't request RNB gpio\n");
206 goto err2;
207 }
208 gpio_direction_input(fun->rnb_gpio);
209 } else if (fun->rnb_gpio == -EINVAL) {
210 dev_err(&ofdev->dev, "specified RNB gpio is invalid\n");
211 goto err2;
212 }
213
214 fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start,
215 io_res.end - io_res.start + 1);
216 if (!fun->io_base) {
217 ret = -ENOMEM;
218 goto err2;
219 }
220
221 fun->dev = &ofdev->dev;
222 fun->last_ctrl = NAND_CLE;
223 fun->wait_pattern = of_get_property(ofdev->node, "fsl,wait-pattern",
224 NULL);
225 fun->wait_write = of_get_property(ofdev->node, "fsl,wait-write", NULL);
226
227 prop = of_get_property(ofdev->node, "chip-delay", NULL);
228 if (prop)
229 fun->chip_delay = *prop;
230 else
231 fun->chip_delay = 50;
232
233 ret = fun_chip_init(fun);
234 if (ret)
235 goto err2;
236
237 dev_set_drvdata(&ofdev->dev, fun);
238
239 return 0;
240err2:
241 if (fun->rnb_gpio >= 0)
242 gpio_free(fun->rnb_gpio);
243err1:
244 kfree(fun);
245
246 return ret;
247}
248
249static int __devexit fun_remove(struct of_device *ofdev)
250{
251 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
252
253 nand_release(&fun->mtd);
254
255 if (fun->rnb_gpio >= 0)
256 gpio_free(fun->rnb_gpio);
257
258 kfree(fun);
259
260 return 0;
261}
262
263static struct of_device_id of_fun_match[] = {
264 { .compatible = "fsl,upm-nand" },
265 {},
266};
267MODULE_DEVICE_TABLE(of, of_fun_match);
268
269static struct of_platform_driver of_fun_driver = {
270 .name = "fsl,upm-nand",
271 .match_table = of_fun_match,
272 .probe = fun_probe,
273 .remove = __devexit_p(fun_remove),
274};
275
276static int __init fun_module_init(void)
277{
278 return of_register_platform_driver(&of_fun_driver);
279}
280module_init(fun_module_init);
281
282static void __exit fun_module_exit(void)
283{
284 of_unregister_platform_driver(&of_fun_driver);
285}
286module_exit(fun_module_exit);
287
288MODULE_LICENSE("GPL");
289MODULE_AUTHOR("Anton Vorontsov <avorontsov@ru.mvista.com>");
290MODULE_DESCRIPTION("Driver for NAND chips working through Freescale "
291 "LocalBus User-Programmable Machine");
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 7acb1a0e7409..ba1bdf787323 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -2229,6 +2229,7 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2229{ 2229{
2230 struct nand_flash_dev *type = NULL; 2230 struct nand_flash_dev *type = NULL;
2231 int i, dev_id, maf_idx; 2231 int i, dev_id, maf_idx;
2232 int tmp_id, tmp_manf;
2232 2233
2233 /* Select the device */ 2234 /* Select the device */
2234 chip->select_chip(mtd, 0); 2235 chip->select_chip(mtd, 0);
@@ -2240,6 +2241,26 @@ static struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,
2240 *maf_id = chip->read_byte(mtd); 2241 *maf_id = chip->read_byte(mtd);
2241 dev_id = chip->read_byte(mtd); 2242 dev_id = chip->read_byte(mtd);
2242 2243
2244 /* Try again to make sure, as some systems the bus-hold or other
2245 * interface concerns can cause random data which looks like a
2246 * possibly credible NAND flash to appear. If the two results do
2247 * not match, ignore the device completely.
2248 */
2249
2250 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1);
2251
2252 /* Read manufacturer and device IDs */
2253
2254 tmp_manf = chip->read_byte(mtd);
2255 tmp_id = chip->read_byte(mtd);
2256
2257 if (tmp_manf != *maf_id || tmp_id != dev_id) {
2258 printk(KERN_INFO "%s: second ID read did not match "
2259 "%02x,%02x against %02x,%02x\n", __func__,
2260 *maf_id, dev_id, tmp_manf, tmp_id);
2261 return ERR_PTR(-ENODEV);
2262 }
2263
2243 /* Lookup the flash id */ 2264 /* Lookup the flash id */
2244 for (i = 0; nand_flash_ids[i].name != NULL; i++) { 2265 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
2245 if (dev_id == nand_flash_ids[i].id) { 2266 if (dev_id == nand_flash_ids[i].id) {
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index 1c0e89f00e8d..955959eb02d4 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -317,3 +317,5 @@ module_exit(ndfc_nand_exit);
317MODULE_LICENSE("GPL"); 317MODULE_LICENSE("GPL");
318MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>"); 318MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>");
319MODULE_DESCRIPTION("Platform driver for NDFC"); 319MODULE_DESCRIPTION("Platform driver for NDFC");
320MODULE_ALIAS("platform:ndfc-chip");
321MODULE_ALIAS("platform:ndfc-nand");
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index ec5ad28b237e..59e05a1c50cf 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -169,3 +169,4 @@ module_exit(orion_nand_exit);
169MODULE_LICENSE("GPL"); 169MODULE_LICENSE("GPL");
170MODULE_AUTHOR("Tzachi Perelstein"); 170MODULE_AUTHOR("Tzachi Perelstein");
171MODULE_DESCRIPTION("NAND glue for Orion platforms"); 171MODULE_DESCRIPTION("NAND glue for Orion platforms");
172MODULE_ALIAS("platform:orion_nand");
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index f6d5c2adc4fd..f674c5427b17 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -54,6 +54,7 @@ static int __init plat_nand_probe(struct platform_device *pdev)
54 data->chip.priv = &data; 54 data->chip.priv = &data;
55 data->mtd.priv = &data->chip; 55 data->mtd.priv = &data->chip;
56 data->mtd.owner = THIS_MODULE; 56 data->mtd.owner = THIS_MODULE;
57 data->mtd.name = pdev->dev.bus_id;
57 58
58 data->chip.IO_ADDR_R = data->io_base; 59 data->chip.IO_ADDR_R = data->io_base;
59 data->chip.IO_ADDR_W = data->io_base; 60 data->chip.IO_ADDR_W = data->io_base;
@@ -150,3 +151,4 @@ module_exit(plat_nand_exit);
150MODULE_LICENSE("GPL"); 151MODULE_LICENSE("GPL");
151MODULE_AUTHOR("Vitaly Wool"); 152MODULE_AUTHOR("Vitaly Wool");
152MODULE_DESCRIPTION("Simple generic NAND driver"); 153MODULE_DESCRIPTION("Simple generic NAND driver");
154MODULE_ALIAS("platform:gen_nand");
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
new file mode 100644
index 000000000000..fceb468ccdec
--- /dev/null
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -0,0 +1,1249 @@
1/*
2 * drivers/mtd/nand/pxa3xx_nand.c
3 *
4 * Copyright © 2005 Intel Corporation
5 * Copyright © 2006 Marvell International Ltd.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/interrupt.h>
14#include <linux/platform_device.h>
15#include <linux/dma-mapping.h>
16#include <linux/delay.h>
17#include <linux/clk.h>
18#include <linux/mtd/mtd.h>
19#include <linux/mtd/nand.h>
20#include <linux/mtd/partitions.h>
21#include <linux/io.h>
22#include <linux/irq.h>
23#include <asm/dma.h>
24
25#include <asm/arch/pxa-regs.h>
26#include <asm/arch/pxa3xx_nand.h>
27
28#define CHIP_DELAY_TIMEOUT (2 * HZ/10)
29
30/* registers and bit definitions */
31#define NDCR (0x00) /* Control register */
32#define NDTR0CS0 (0x04) /* Timing Parameter 0 for CS0 */
33#define NDTR1CS0 (0x0C) /* Timing Parameter 1 for CS0 */
34#define NDSR (0x14) /* Status Register */
35#define NDPCR (0x18) /* Page Count Register */
36#define NDBDR0 (0x1C) /* Bad Block Register 0 */
37#define NDBDR1 (0x20) /* Bad Block Register 1 */
38#define NDDB (0x40) /* Data Buffer */
39#define NDCB0 (0x48) /* Command Buffer0 */
40#define NDCB1 (0x4C) /* Command Buffer1 */
41#define NDCB2 (0x50) /* Command Buffer2 */
42
43#define NDCR_SPARE_EN (0x1 << 31)
44#define NDCR_ECC_EN (0x1 << 30)
45#define NDCR_DMA_EN (0x1 << 29)
46#define NDCR_ND_RUN (0x1 << 28)
47#define NDCR_DWIDTH_C (0x1 << 27)
48#define NDCR_DWIDTH_M (0x1 << 26)
49#define NDCR_PAGE_SZ (0x1 << 24)
50#define NDCR_NCSX (0x1 << 23)
51#define NDCR_ND_MODE (0x3 << 21)
52#define NDCR_NAND_MODE (0x0)
53#define NDCR_CLR_PG_CNT (0x1 << 20)
54#define NDCR_CLR_ECC (0x1 << 19)
55#define NDCR_RD_ID_CNT_MASK (0x7 << 16)
56#define NDCR_RD_ID_CNT(x) (((x) << 16) & NDCR_RD_ID_CNT_MASK)
57
58#define NDCR_RA_START (0x1 << 15)
59#define NDCR_PG_PER_BLK (0x1 << 14)
60#define NDCR_ND_ARB_EN (0x1 << 12)
61
62#define NDSR_MASK (0xfff)
63#define NDSR_RDY (0x1 << 11)
64#define NDSR_CS0_PAGED (0x1 << 10)
65#define NDSR_CS1_PAGED (0x1 << 9)
66#define NDSR_CS0_CMDD (0x1 << 8)
67#define NDSR_CS1_CMDD (0x1 << 7)
68#define NDSR_CS0_BBD (0x1 << 6)
69#define NDSR_CS1_BBD (0x1 << 5)
70#define NDSR_DBERR (0x1 << 4)
71#define NDSR_SBERR (0x1 << 3)
72#define NDSR_WRDREQ (0x1 << 2)
73#define NDSR_RDDREQ (0x1 << 1)
74#define NDSR_WRCMDREQ (0x1)
75
76#define NDCB0_AUTO_RS (0x1 << 25)
77#define NDCB0_CSEL (0x1 << 24)
78#define NDCB0_CMD_TYPE_MASK (0x7 << 21)
79#define NDCB0_CMD_TYPE(x) (((x) << 21) & NDCB0_CMD_TYPE_MASK)
80#define NDCB0_NC (0x1 << 20)
81#define NDCB0_DBC (0x1 << 19)
82#define NDCB0_ADDR_CYC_MASK (0x7 << 16)
83#define NDCB0_ADDR_CYC(x) (((x) << 16) & NDCB0_ADDR_CYC_MASK)
84#define NDCB0_CMD2_MASK (0xff << 8)
85#define NDCB0_CMD1_MASK (0xff)
86#define NDCB0_ADDR_CYC_SHIFT (16)
87
88/* dma-able I/O address for the NAND data and commands */
89#define NDCB0_DMA_ADDR (0x43100048)
90#define NDDB_DMA_ADDR (0x43100040)
91
92/* macros for registers read/write */
93#define nand_writel(info, off, val) \
94 __raw_writel((val), (info)->mmio_base + (off))
95
96#define nand_readl(info, off) \
97 __raw_readl((info)->mmio_base + (off))
98
99/* error code and state */
100enum {
101 ERR_NONE = 0,
102 ERR_DMABUSERR = -1,
103 ERR_SENDCMD = -2,
104 ERR_DBERR = -3,
105 ERR_BBERR = -4,
106};
107
108enum {
109 STATE_READY = 0,
110 STATE_CMD_HANDLE,
111 STATE_DMA_READING,
112 STATE_DMA_WRITING,
113 STATE_DMA_DONE,
114 STATE_PIO_READING,
115 STATE_PIO_WRITING,
116};
117
118struct pxa3xx_nand_timing {
119 unsigned int tCH; /* Enable signal hold time */
120 unsigned int tCS; /* Enable signal setup time */
121 unsigned int tWH; /* ND_nWE high duration */
122 unsigned int tWP; /* ND_nWE pulse time */
123 unsigned int tRH; /* ND_nRE high duration */
124 unsigned int tRP; /* ND_nRE pulse width */
125 unsigned int tR; /* ND_nWE high to ND_nRE low for read */
126 unsigned int tWHR; /* ND_nWE high to ND_nRE low for status read */
127 unsigned int tAR; /* ND_ALE low to ND_nRE low delay */
128};
129
130struct pxa3xx_nand_cmdset {
131 uint16_t read1;
132 uint16_t read2;
133 uint16_t program;
134 uint16_t read_status;
135 uint16_t read_id;
136 uint16_t erase;
137 uint16_t reset;
138 uint16_t lock;
139 uint16_t unlock;
140 uint16_t lock_status;
141};
142
143struct pxa3xx_nand_flash {
144 struct pxa3xx_nand_timing *timing; /* NAND Flash timing */
145 struct pxa3xx_nand_cmdset *cmdset;
146
147 uint32_t page_per_block;/* Pages per block (PG_PER_BLK) */
148 uint32_t page_size; /* Page size in bytes (PAGE_SZ) */
149 uint32_t flash_width; /* Width of Flash memory (DWIDTH_M) */
150 uint32_t dfc_width; /* Width of flash controller(DWIDTH_C) */
151 uint32_t num_blocks; /* Number of physical blocks in Flash */
152 uint32_t chip_id;
153
154 /* NOTE: these are automatically calculated, do not define */
155 size_t oob_size;
156 size_t read_id_bytes;
157
158 unsigned int col_addr_cycles;
159 unsigned int row_addr_cycles;
160};
161
162struct pxa3xx_nand_info {
163 struct nand_chip nand_chip;
164
165 struct platform_device *pdev;
166 struct pxa3xx_nand_flash *flash_info;
167
168 struct clk *clk;
169 void __iomem *mmio_base;
170
171 unsigned int buf_start;
172 unsigned int buf_count;
173
174 /* DMA information */
175 int drcmr_dat;
176 int drcmr_cmd;
177
178 unsigned char *data_buff;
179 dma_addr_t data_buff_phys;
180 size_t data_buff_size;
181 int data_dma_ch;
182 struct pxa_dma_desc *data_desc;
183 dma_addr_t data_desc_addr;
184
185 uint32_t reg_ndcr;
186
187 /* saved column/page_addr during CMD_SEQIN */
188 int seqin_column;
189 int seqin_page_addr;
190
191 /* relate to the command */
192 unsigned int state;
193
194 int use_ecc; /* use HW ECC ? */
195 int use_dma; /* use DMA ? */
196
197 size_t data_size; /* data size in FIFO */
198 int retcode;
199 struct completion cmd_complete;
200
201 /* generated NDCBx register values */
202 uint32_t ndcb0;
203 uint32_t ndcb1;
204 uint32_t ndcb2;
205};
206
207static int use_dma = 1;
208module_param(use_dma, bool, 0444);
209MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
210
211static struct pxa3xx_nand_cmdset smallpage_cmdset = {
212 .read1 = 0x0000,
213 .read2 = 0x0050,
214 .program = 0x1080,
215 .read_status = 0x0070,
216 .read_id = 0x0090,
217 .erase = 0xD060,
218 .reset = 0x00FF,
219 .lock = 0x002A,
220 .unlock = 0x2423,
221 .lock_status = 0x007A,
222};
223
224static struct pxa3xx_nand_cmdset largepage_cmdset = {
225 .read1 = 0x3000,
226 .read2 = 0x0050,
227 .program = 0x1080,
228 .read_status = 0x0070,
229 .read_id = 0x0090,
230 .erase = 0xD060,
231 .reset = 0x00FF,
232 .lock = 0x002A,
233 .unlock = 0x2423,
234 .lock_status = 0x007A,
235};
236
237static struct pxa3xx_nand_timing samsung512MbX16_timing = {
238 .tCH = 10,
239 .tCS = 0,
240 .tWH = 20,
241 .tWP = 40,
242 .tRH = 30,
243 .tRP = 40,
244 .tR = 11123,
245 .tWHR = 110,
246 .tAR = 10,
247};
248
249static struct pxa3xx_nand_flash samsung512MbX16 = {
250 .timing = &samsung512MbX16_timing,
251 .cmdset = &smallpage_cmdset,
252 .page_per_block = 32,
253 .page_size = 512,
254 .flash_width = 16,
255 .dfc_width = 16,
256 .num_blocks = 4096,
257 .chip_id = 0x46ec,
258};
259
260static struct pxa3xx_nand_timing micron_timing = {
261 .tCH = 10,
262 .tCS = 25,
263 .tWH = 15,
264 .tWP = 25,
265 .tRH = 15,
266 .tRP = 25,
267 .tR = 25000,
268 .tWHR = 60,
269 .tAR = 10,
270};
271
272static struct pxa3xx_nand_flash micron1GbX8 = {
273 .timing = &micron_timing,
274 .cmdset = &largepage_cmdset,
275 .page_per_block = 64,
276 .page_size = 2048,
277 .flash_width = 8,
278 .dfc_width = 8,
279 .num_blocks = 1024,
280 .chip_id = 0xa12c,
281};
282
283static struct pxa3xx_nand_flash micron1GbX16 = {
284 .timing = &micron_timing,
285 .cmdset = &largepage_cmdset,
286 .page_per_block = 64,
287 .page_size = 2048,
288 .flash_width = 16,
289 .dfc_width = 16,
290 .num_blocks = 1024,
291 .chip_id = 0xb12c,
292};
293
294static struct pxa3xx_nand_flash *builtin_flash_types[] = {
295 &samsung512MbX16,
296 &micron1GbX8,
297 &micron1GbX16,
298};
299
300#define NDTR0_tCH(c) (min((c), 7) << 19)
301#define NDTR0_tCS(c) (min((c), 7) << 16)
302#define NDTR0_tWH(c) (min((c), 7) << 11)
303#define NDTR0_tWP(c) (min((c), 7) << 8)
304#define NDTR0_tRH(c) (min((c), 7) << 3)
305#define NDTR0_tRP(c) (min((c), 7) << 0)
306
307#define NDTR1_tR(c) (min((c), 65535) << 16)
308#define NDTR1_tWHR(c) (min((c), 15) << 4)
309#define NDTR1_tAR(c) (min((c), 15) << 0)
310
311/* convert nano-seconds to nand flash controller clock cycles */
312#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) + 1)
313
314static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
315 struct pxa3xx_nand_timing *t)
316{
317 unsigned long nand_clk = clk_get_rate(info->clk);
318 uint32_t ndtr0, ndtr1;
319
320 ndtr0 = NDTR0_tCH(ns2cycle(t->tCH, nand_clk)) |
321 NDTR0_tCS(ns2cycle(t->tCS, nand_clk)) |
322 NDTR0_tWH(ns2cycle(t->tWH, nand_clk)) |
323 NDTR0_tWP(ns2cycle(t->tWP, nand_clk)) |
324 NDTR0_tRH(ns2cycle(t->tRH, nand_clk)) |
325 NDTR0_tRP(ns2cycle(t->tRP, nand_clk));
326
327 ndtr1 = NDTR1_tR(ns2cycle(t->tR, nand_clk)) |
328 NDTR1_tWHR(ns2cycle(t->tWHR, nand_clk)) |
329 NDTR1_tAR(ns2cycle(t->tAR, nand_clk));
330
331 nand_writel(info, NDTR0CS0, ndtr0);
332 nand_writel(info, NDTR1CS0, ndtr1);
333}
334
335#define WAIT_EVENT_TIMEOUT 10
336
337static int wait_for_event(struct pxa3xx_nand_info *info, uint32_t event)
338{
339 int timeout = WAIT_EVENT_TIMEOUT;
340 uint32_t ndsr;
341
342 while (timeout--) {
343 ndsr = nand_readl(info, NDSR) & NDSR_MASK;
344 if (ndsr & event) {
345 nand_writel(info, NDSR, ndsr);
346 return 0;
347 }
348 udelay(10);
349 }
350
351 return -ETIMEDOUT;
352}
353
354static int prepare_read_prog_cmd(struct pxa3xx_nand_info *info,
355 uint16_t cmd, int column, int page_addr)
356{
357 struct pxa3xx_nand_flash *f = info->flash_info;
358 struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
359
360 /* calculate data size */
361 switch (f->page_size) {
362 case 2048:
363 info->data_size = (info->use_ecc) ? 2088 : 2112;
364 break;
365 case 512:
366 info->data_size = (info->use_ecc) ? 520 : 528;
367 break;
368 default:
369 return -EINVAL;
370 }
371
372 /* generate values for NDCBx registers */
373 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
374 info->ndcb1 = 0;
375 info->ndcb2 = 0;
376 info->ndcb0 |= NDCB0_ADDR_CYC(f->row_addr_cycles + f->col_addr_cycles);
377
378 if (f->col_addr_cycles == 2) {
379 /* large block, 2 cycles for column address
380 * row address starts from 3rd cycle
381 */
382 info->ndcb1 |= (page_addr << 16) | (column & 0xffff);
383 if (f->row_addr_cycles == 3)
384 info->ndcb2 = (page_addr >> 16) & 0xff;
385 } else
386 /* small block, 1 cycles for column address
387 * row address starts from 2nd cycle
388 */
389 info->ndcb1 = (page_addr << 8) | (column & 0xff);
390
391 if (cmd == cmdset->program)
392 info->ndcb0 |= NDCB0_CMD_TYPE(1) | NDCB0_AUTO_RS;
393
394 return 0;
395}
396
397static int prepare_erase_cmd(struct pxa3xx_nand_info *info,
398 uint16_t cmd, int page_addr)
399{
400 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
401 info->ndcb0 |= NDCB0_CMD_TYPE(2) | NDCB0_AUTO_RS | NDCB0_ADDR_CYC(3);
402 info->ndcb1 = page_addr;
403 info->ndcb2 = 0;
404 return 0;
405}
406
407static int prepare_other_cmd(struct pxa3xx_nand_info *info, uint16_t cmd)
408{
409 struct pxa3xx_nand_cmdset *cmdset = info->flash_info->cmdset;
410
411 info->ndcb0 = cmd | ((cmd & 0xff00) ? NDCB0_DBC : 0);
412 info->ndcb1 = 0;
413 info->ndcb2 = 0;
414
415 if (cmd == cmdset->read_id) {
416 info->ndcb0 |= NDCB0_CMD_TYPE(3);
417 info->data_size = 8;
418 } else if (cmd == cmdset->read_status) {
419 info->ndcb0 |= NDCB0_CMD_TYPE(4);
420 info->data_size = 8;
421 } else if (cmd == cmdset->reset || cmd == cmdset->lock ||
422 cmd == cmdset->unlock) {
423 info->ndcb0 |= NDCB0_CMD_TYPE(5);
424 } else
425 return -EINVAL;
426
427 return 0;
428}
429
430static void enable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
431{
432 uint32_t ndcr;
433
434 ndcr = nand_readl(info, NDCR);
435 nand_writel(info, NDCR, ndcr & ~int_mask);
436}
437
438static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)
439{
440 uint32_t ndcr;
441
442 ndcr = nand_readl(info, NDCR);
443 nand_writel(info, NDCR, ndcr | int_mask);
444}
445
446/* NOTE: it is a must to set ND_RUN firstly, then write command buffer
447 * otherwise, it does not work
448 */
449static int write_cmd(struct pxa3xx_nand_info *info)
450{
451 uint32_t ndcr;
452
453 /* clear status bits and run */
454 nand_writel(info, NDSR, NDSR_MASK);
455
456 ndcr = info->reg_ndcr;
457
458 ndcr |= info->use_ecc ? NDCR_ECC_EN : 0;
459 ndcr |= info->use_dma ? NDCR_DMA_EN : 0;
460 ndcr |= NDCR_ND_RUN;
461
462 nand_writel(info, NDCR, ndcr);
463
464 if (wait_for_event(info, NDSR_WRCMDREQ)) {
465 printk(KERN_ERR "timed out writing command\n");
466 return -ETIMEDOUT;
467 }
468
469 nand_writel(info, NDCB0, info->ndcb0);
470 nand_writel(info, NDCB0, info->ndcb1);
471 nand_writel(info, NDCB0, info->ndcb2);
472 return 0;
473}
474
475static int handle_data_pio(struct pxa3xx_nand_info *info)
476{
477 int ret, timeout = CHIP_DELAY_TIMEOUT;
478
479 switch (info->state) {
480 case STATE_PIO_WRITING:
481 __raw_writesl(info->mmio_base + NDDB, info->data_buff,
482 info->data_size << 2);
483
484 enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
485
486 ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
487 if (!ret) {
488 printk(KERN_ERR "program command time out\n");
489 return -1;
490 }
491 break;
492 case STATE_PIO_READING:
493 __raw_readsl(info->mmio_base + NDDB, info->data_buff,
494 info->data_size << 2);
495 break;
496 default:
497 printk(KERN_ERR "%s: invalid state %d\n", __func__,
498 info->state);
499 return -EINVAL;
500 }
501
502 info->state = STATE_READY;
503 return 0;
504}
505
506static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out)
507{
508 struct pxa_dma_desc *desc = info->data_desc;
509 int dma_len = ALIGN(info->data_size, 32);
510
511 desc->ddadr = DDADR_STOP;
512 desc->dcmd = DCMD_ENDIRQEN | DCMD_WIDTH4 | DCMD_BURST32 | dma_len;
513
514 if (dir_out) {
515 desc->dsadr = info->data_buff_phys;
516 desc->dtadr = NDDB_DMA_ADDR;
517 desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG;
518 } else {
519 desc->dtadr = info->data_buff_phys;
520 desc->dsadr = NDDB_DMA_ADDR;
521 desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC;
522 }
523
524 DRCMR(info->drcmr_dat) = DRCMR_MAPVLD | info->data_dma_ch;
525 DDADR(info->data_dma_ch) = info->data_desc_addr;
526 DCSR(info->data_dma_ch) |= DCSR_RUN;
527}
528
529static void pxa3xx_nand_data_dma_irq(int channel, void *data)
530{
531 struct pxa3xx_nand_info *info = data;
532 uint32_t dcsr;
533
534 dcsr = DCSR(channel);
535 DCSR(channel) = dcsr;
536
537 if (dcsr & DCSR_BUSERR) {
538 info->retcode = ERR_DMABUSERR;
539 complete(&info->cmd_complete);
540 }
541
542 if (info->state == STATE_DMA_WRITING) {
543 info->state = STATE_DMA_DONE;
544 enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
545 } else {
546 info->state = STATE_READY;
547 complete(&info->cmd_complete);
548 }
549}
550
551static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)
552{
553 struct pxa3xx_nand_info *info = devid;
554 unsigned int status;
555
556 status = nand_readl(info, NDSR);
557
558 if (status & (NDSR_RDDREQ | NDSR_DBERR)) {
559 if (status & NDSR_DBERR)
560 info->retcode = ERR_DBERR;
561
562 disable_int(info, NDSR_RDDREQ | NDSR_DBERR);
563
564 if (info->use_dma) {
565 info->state = STATE_DMA_READING;
566 start_data_dma(info, 0);
567 } else {
568 info->state = STATE_PIO_READING;
569 complete(&info->cmd_complete);
570 }
571 } else if (status & NDSR_WRDREQ) {
572 disable_int(info, NDSR_WRDREQ);
573 if (info->use_dma) {
574 info->state = STATE_DMA_WRITING;
575 start_data_dma(info, 1);
576 } else {
577 info->state = STATE_PIO_WRITING;
578 complete(&info->cmd_complete);
579 }
580 } else if (status & (NDSR_CS0_BBD | NDSR_CS0_CMDD)) {
581 if (status & NDSR_CS0_BBD)
582 info->retcode = ERR_BBERR;
583
584 disable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
585 info->state = STATE_READY;
586 complete(&info->cmd_complete);
587 }
588 nand_writel(info, NDSR, status);
589 return IRQ_HANDLED;
590}
591
592static int pxa3xx_nand_do_cmd(struct pxa3xx_nand_info *info, uint32_t event)
593{
594 uint32_t ndcr;
595 int ret, timeout = CHIP_DELAY_TIMEOUT;
596
597 if (write_cmd(info)) {
598 info->retcode = ERR_SENDCMD;
599 goto fail_stop;
600 }
601
602 info->state = STATE_CMD_HANDLE;
603
604 enable_int(info, event);
605
606 ret = wait_for_completion_timeout(&info->cmd_complete, timeout);
607 if (!ret) {
608 printk(KERN_ERR "command execution timed out\n");
609 info->retcode = ERR_SENDCMD;
610 goto fail_stop;
611 }
612
613 if (info->use_dma == 0 && info->data_size > 0)
614 if (handle_data_pio(info))
615 goto fail_stop;
616
617 return 0;
618
619fail_stop:
620 ndcr = nand_readl(info, NDCR);
621 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
622 udelay(10);
623 return -ETIMEDOUT;
624}
625
626static int pxa3xx_nand_dev_ready(struct mtd_info *mtd)
627{
628 struct pxa3xx_nand_info *info = mtd->priv;
629 return (nand_readl(info, NDSR) & NDSR_RDY) ? 1 : 0;
630}
631
632static inline int is_buf_blank(uint8_t *buf, size_t len)
633{
634 for (; len > 0; len--)
635 if (*buf++ != 0xff)
636 return 0;
637 return 1;
638}
639
640static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,
641 int column, int page_addr)
642{
643 struct pxa3xx_nand_info *info = mtd->priv;
644 struct pxa3xx_nand_flash *flash_info = info->flash_info;
645 struct pxa3xx_nand_cmdset *cmdset = flash_info->cmdset;
646 int ret;
647
648 info->use_dma = (use_dma) ? 1 : 0;
649 info->use_ecc = 0;
650 info->data_size = 0;
651 info->state = STATE_READY;
652
653 init_completion(&info->cmd_complete);
654
655 switch (command) {
656 case NAND_CMD_READOOB:
657 /* disable HW ECC to get all the OOB data */
658 info->buf_count = mtd->writesize + mtd->oobsize;
659 info->buf_start = mtd->writesize + column;
660
661 if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
662 break;
663
664 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
665
666 /* We only are OOB, so if the data has error, does not matter */
667 if (info->retcode == ERR_DBERR)
668 info->retcode = ERR_NONE;
669 break;
670
671 case NAND_CMD_READ0:
672 info->use_ecc = 1;
673 info->retcode = ERR_NONE;
674 info->buf_start = column;
675 info->buf_count = mtd->writesize + mtd->oobsize;
676 memset(info->data_buff, 0xFF, info->buf_count);
677
678 if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr))
679 break;
680
681 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ | NDSR_DBERR);
682
683 if (info->retcode == ERR_DBERR) {
684 /* for blank page (all 0xff), HW will calculate its ECC as
685 * 0, which is different from the ECC information within
686 * OOB, ignore such double bit errors
687 */
688 if (is_buf_blank(info->data_buff, mtd->writesize))
689 info->retcode = ERR_NONE;
690 }
691 break;
692 case NAND_CMD_SEQIN:
693 info->buf_start = column;
694 info->buf_count = mtd->writesize + mtd->oobsize;
695 memset(info->data_buff, 0xff, info->buf_count);
696
697 /* save column/page_addr for next CMD_PAGEPROG */
698 info->seqin_column = column;
699 info->seqin_page_addr = page_addr;
700 break;
701 case NAND_CMD_PAGEPROG:
702 info->use_ecc = (info->seqin_column >= mtd->writesize) ? 0 : 1;
703
704 if (prepare_read_prog_cmd(info, cmdset->program,
705 info->seqin_column, info->seqin_page_addr))
706 break;
707
708 pxa3xx_nand_do_cmd(info, NDSR_WRDREQ);
709 break;
710 case NAND_CMD_ERASE1:
711 if (prepare_erase_cmd(info, cmdset->erase, page_addr))
712 break;
713
714 pxa3xx_nand_do_cmd(info, NDSR_CS0_BBD | NDSR_CS0_CMDD);
715 break;
716 case NAND_CMD_ERASE2:
717 break;
718 case NAND_CMD_READID:
719 case NAND_CMD_STATUS:
720 info->use_dma = 0; /* force PIO read */
721 info->buf_start = 0;
722 info->buf_count = (command == NAND_CMD_READID) ?
723 flash_info->read_id_bytes : 1;
724
725 if (prepare_other_cmd(info, (command == NAND_CMD_READID) ?
726 cmdset->read_id : cmdset->read_status))
727 break;
728
729 pxa3xx_nand_do_cmd(info, NDSR_RDDREQ);
730 break;
731 case NAND_CMD_RESET:
732 if (prepare_other_cmd(info, cmdset->reset))
733 break;
734
735 ret = pxa3xx_nand_do_cmd(info, NDSR_CS0_CMDD);
736 if (ret == 0) {
737 int timeout = 2;
738 uint32_t ndcr;
739
740 while (timeout--) {
741 if (nand_readl(info, NDSR) & NDSR_RDY)
742 break;
743 msleep(10);
744 }
745
746 ndcr = nand_readl(info, NDCR);
747 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
748 }
749 break;
750 default:
751 printk(KERN_ERR "non-supported command.\n");
752 break;
753 }
754
755 if (info->retcode == ERR_DBERR) {
756 printk(KERN_ERR "double bit error @ page %08x\n", page_addr);
757 info->retcode = ERR_NONE;
758 }
759}
760
761static uint8_t pxa3xx_nand_read_byte(struct mtd_info *mtd)
762{
763 struct pxa3xx_nand_info *info = mtd->priv;
764 char retval = 0xFF;
765
766 if (info->buf_start < info->buf_count)
767 /* Has just send a new command? */
768 retval = info->data_buff[info->buf_start++];
769
770 return retval;
771}
772
773static u16 pxa3xx_nand_read_word(struct mtd_info *mtd)
774{
775 struct pxa3xx_nand_info *info = mtd->priv;
776 u16 retval = 0xFFFF;
777
778 if (!(info->buf_start & 0x01) && info->buf_start < info->buf_count) {
779 retval = *((u16 *)(info->data_buff+info->buf_start));
780 info->buf_start += 2;
781 }
782 return retval;
783}
784
785static void pxa3xx_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
786{
787 struct pxa3xx_nand_info *info = mtd->priv;
788 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
789
790 memcpy(buf, info->data_buff + info->buf_start, real_len);
791 info->buf_start += real_len;
792}
793
794static void pxa3xx_nand_write_buf(struct mtd_info *mtd,
795 const uint8_t *buf, int len)
796{
797 struct pxa3xx_nand_info *info = mtd->priv;
798 int real_len = min_t(size_t, len, info->buf_count - info->buf_start);
799
800 memcpy(info->data_buff + info->buf_start, buf, real_len);
801 info->buf_start += real_len;
802}
803
804static int pxa3xx_nand_verify_buf(struct mtd_info *mtd,
805 const uint8_t *buf, int len)
806{
807 return 0;
808}
809
810static void pxa3xx_nand_select_chip(struct mtd_info *mtd, int chip)
811{
812 return;
813}
814
815static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this)
816{
817 struct pxa3xx_nand_info *info = mtd->priv;
818
819 /* pxa3xx_nand_send_command has waited for command complete */
820 if (this->state == FL_WRITING || this->state == FL_ERASING) {
821 if (info->retcode == ERR_NONE)
822 return 0;
823 else {
824 /*
825 * any error make it return 0x01 which will tell
826 * the caller the erase and write fail
827 */
828 return 0x01;
829 }
830 }
831
832 return 0;
833}
834
835static void pxa3xx_nand_ecc_hwctl(struct mtd_info *mtd, int mode)
836{
837 return;
838}
839
840static int pxa3xx_nand_ecc_calculate(struct mtd_info *mtd,
841 const uint8_t *dat, uint8_t *ecc_code)
842{
843 return 0;
844}
845
846static int pxa3xx_nand_ecc_correct(struct mtd_info *mtd,
847 uint8_t *dat, uint8_t *read_ecc, uint8_t *calc_ecc)
848{
849 struct pxa3xx_nand_info *info = mtd->priv;
850 /*
851 * Any error include ERR_SEND_CMD, ERR_DBERR, ERR_BUSERR, we
852 * consider it as a ecc error which will tell the caller the
853 * read fail We have distinguish all the errors, but the
854 * nand_read_ecc only check this function return value
855 */
856 if (info->retcode != ERR_NONE)
857 return -1;
858
859 return 0;
860}
861
862static int __readid(struct pxa3xx_nand_info *info, uint32_t *id)
863{
864 struct pxa3xx_nand_flash *f = info->flash_info;
865 struct pxa3xx_nand_cmdset *cmdset = f->cmdset;
866 uint32_t ndcr;
867 uint8_t id_buff[8];
868
869 if (prepare_other_cmd(info, cmdset->read_id)) {
870 printk(KERN_ERR "failed to prepare command\n");
871 return -EINVAL;
872 }
873
874 /* Send command */
875 if (write_cmd(info))
876 goto fail_timeout;
877
878 /* Wait for CMDDM(command done successfully) */
879 if (wait_for_event(info, NDSR_RDDREQ))
880 goto fail_timeout;
881
882 __raw_readsl(info->mmio_base + NDDB, id_buff, 2);
883 *id = id_buff[0] | (id_buff[1] << 8);
884 return 0;
885
886fail_timeout:
887 ndcr = nand_readl(info, NDCR);
888 nand_writel(info, NDCR, ndcr & ~NDCR_ND_RUN);
889 udelay(10);
890 return -ETIMEDOUT;
891}
892
893static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
894 struct pxa3xx_nand_flash *f)
895{
896 struct platform_device *pdev = info->pdev;
897 struct pxa3xx_nand_platform_data *pdata = pdev->dev.platform_data;
898 uint32_t ndcr = 0x00000FFF; /* disable all interrupts */
899
900 if (f->page_size != 2048 && f->page_size != 512)
901 return -EINVAL;
902
903 if (f->flash_width != 16 && f->flash_width != 8)
904 return -EINVAL;
905
906 /* calculate flash information */
907 f->oob_size = (f->page_size == 2048) ? 64 : 16;
908 f->read_id_bytes = (f->page_size == 2048) ? 4 : 2;
909
910 /* calculate addressing information */
911 f->col_addr_cycles = (f->page_size == 2048) ? 2 : 1;
912
913 if (f->num_blocks * f->page_per_block > 65536)
914 f->row_addr_cycles = 3;
915 else
916 f->row_addr_cycles = 2;
917
918 ndcr |= (pdata->enable_arbiter) ? NDCR_ND_ARB_EN : 0;
919 ndcr |= (f->col_addr_cycles == 2) ? NDCR_RA_START : 0;
920 ndcr |= (f->page_per_block == 64) ? NDCR_PG_PER_BLK : 0;
921 ndcr |= (f->page_size == 2048) ? NDCR_PAGE_SZ : 0;
922 ndcr |= (f->flash_width == 16) ? NDCR_DWIDTH_M : 0;
923 ndcr |= (f->dfc_width == 16) ? NDCR_DWIDTH_C : 0;
924
925 ndcr |= NDCR_RD_ID_CNT(f->read_id_bytes);
926 ndcr |= NDCR_SPARE_EN; /* enable spare by default */
927
928 info->reg_ndcr = ndcr;
929
930 pxa3xx_nand_set_timing(info, f->timing);
931 info->flash_info = f;
932 return 0;
933}
934
935static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info)
936{
937 struct pxa3xx_nand_flash *f;
938 uint32_t id;
939 int i;
940
941 for (i = 0; i < ARRAY_SIZE(builtin_flash_types); i++) {
942
943 f = builtin_flash_types[i];
944
945 if (pxa3xx_nand_config_flash(info, f))
946 continue;
947
948 if (__readid(info, &id))
949 continue;
950
951 if (id == f->chip_id)
952 return 0;
953 }
954
955 return -ENODEV;
956}
957
958/* the maximum possible buffer size for large page with OOB data
959 * is: 2048 + 64 = 2112 bytes, allocate a page here for both the
960 * data buffer and the DMA descriptor
961 */
962#define MAX_BUFF_SIZE PAGE_SIZE
963
964static int pxa3xx_nand_init_buff(struct pxa3xx_nand_info *info)
965{
966 struct platform_device *pdev = info->pdev;
967 int data_desc_offset = MAX_BUFF_SIZE - sizeof(struct pxa_dma_desc);
968
969 if (use_dma == 0) {
970 info->data_buff = kmalloc(MAX_BUFF_SIZE, GFP_KERNEL);
971 if (info->data_buff == NULL)
972 return -ENOMEM;
973 return 0;
974 }
975
976 info->data_buff = dma_alloc_coherent(&pdev->dev, MAX_BUFF_SIZE,
977 &info->data_buff_phys, GFP_KERNEL);
978 if (info->data_buff == NULL) {
979 dev_err(&pdev->dev, "failed to allocate dma buffer\n");
980 return -ENOMEM;
981 }
982
983 info->data_buff_size = MAX_BUFF_SIZE;
984 info->data_desc = (void *)info->data_buff + data_desc_offset;
985 info->data_desc_addr = info->data_buff_phys + data_desc_offset;
986
987 info->data_dma_ch = pxa_request_dma("nand-data", DMA_PRIO_LOW,
988 pxa3xx_nand_data_dma_irq, info);
989 if (info->data_dma_ch < 0) {
990 dev_err(&pdev->dev, "failed to request data dma\n");
991 dma_free_coherent(&pdev->dev, info->data_buff_size,
992 info->data_buff, info->data_buff_phys);
993 return info->data_dma_ch;
994 }
995
996 return 0;
997}
998
999static struct nand_ecclayout hw_smallpage_ecclayout = {
1000 .eccbytes = 6,
1001 .eccpos = {8, 9, 10, 11, 12, 13 },
1002 .oobfree = { {2, 6} }
1003};
1004
1005static struct nand_ecclayout hw_largepage_ecclayout = {
1006 .eccbytes = 24,
1007 .eccpos = {
1008 40, 41, 42, 43, 44, 45, 46, 47,
1009 48, 49, 50, 51, 52, 53, 54, 55,
1010 56, 57, 58, 59, 60, 61, 62, 63},
1011 .oobfree = { {2, 38} }
1012};
1013
1014static void pxa3xx_nand_init_mtd(struct mtd_info *mtd,
1015 struct pxa3xx_nand_info *info)
1016{
1017 struct pxa3xx_nand_flash *f = info->flash_info;
1018 struct nand_chip *this = &info->nand_chip;
1019
1020 this->options = (f->flash_width == 16) ? NAND_BUSWIDTH_16: 0;
1021
1022 this->waitfunc = pxa3xx_nand_waitfunc;
1023 this->select_chip = pxa3xx_nand_select_chip;
1024 this->dev_ready = pxa3xx_nand_dev_ready;
1025 this->cmdfunc = pxa3xx_nand_cmdfunc;
1026 this->read_word = pxa3xx_nand_read_word;
1027 this->read_byte = pxa3xx_nand_read_byte;
1028 this->read_buf = pxa3xx_nand_read_buf;
1029 this->write_buf = pxa3xx_nand_write_buf;
1030 this->verify_buf = pxa3xx_nand_verify_buf;
1031
1032 this->ecc.mode = NAND_ECC_HW;
1033 this->ecc.hwctl = pxa3xx_nand_ecc_hwctl;
1034 this->ecc.calculate = pxa3xx_nand_ecc_calculate;
1035 this->ecc.correct = pxa3xx_nand_ecc_correct;
1036 this->ecc.size = f->page_size;
1037
1038 if (f->page_size == 2048)
1039 this->ecc.layout = &hw_largepage_ecclayout;
1040 else
1041 this->ecc.layout = &hw_smallpage_ecclayout;
1042
1043 this->chip_delay = 25;
1044}
1045
1046static int pxa3xx_nand_probe(struct platform_device *pdev)
1047{
1048 struct pxa3xx_nand_platform_data *pdata;
1049 struct pxa3xx_nand_info *info;
1050 struct nand_chip *this;
1051 struct mtd_info *mtd;
1052 struct resource *r;
1053 int ret = 0, irq;
1054
1055 pdata = pdev->dev.platform_data;
1056
1057 if (!pdata) {
1058 dev_err(&pdev->dev, "no platform data defined\n");
1059 return -ENODEV;
1060 }
1061
1062 mtd = kzalloc(sizeof(struct mtd_info) + sizeof(struct pxa3xx_nand_info),
1063 GFP_KERNEL);
1064 if (!mtd) {
1065 dev_err(&pdev->dev, "failed to allocate memory\n");
1066 return -ENOMEM;
1067 }
1068
1069 info = (struct pxa3xx_nand_info *)(&mtd[1]);
1070 info->pdev = pdev;
1071
1072 this = &info->nand_chip;
1073 mtd->priv = info;
1074
1075 info->clk = clk_get(&pdev->dev, "NANDCLK");
1076 if (IS_ERR(info->clk)) {
1077 dev_err(&pdev->dev, "failed to get nand clock\n");
1078 ret = PTR_ERR(info->clk);
1079 goto fail_free_mtd;
1080 }
1081 clk_enable(info->clk);
1082
1083 r = platform_get_resource(pdev, IORESOURCE_DMA, 0);
1084 if (r == NULL) {
1085 dev_err(&pdev->dev, "no resource defined for data DMA\n");
1086 ret = -ENXIO;
1087 goto fail_put_clk;
1088 }
1089 info->drcmr_dat = r->start;
1090
1091 r = platform_get_resource(pdev, IORESOURCE_DMA, 1);
1092 if (r == NULL) {
1093 dev_err(&pdev->dev, "no resource defined for command DMA\n");
1094 ret = -ENXIO;
1095 goto fail_put_clk;
1096 }
1097 info->drcmr_cmd = r->start;
1098
1099 irq = platform_get_irq(pdev, 0);
1100 if (irq < 0) {
1101 dev_err(&pdev->dev, "no IRQ resource defined\n");
1102 ret = -ENXIO;
1103 goto fail_put_clk;
1104 }
1105
1106 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1107 if (r == NULL) {
1108 dev_err(&pdev->dev, "no IO memory resource defined\n");
1109 ret = -ENODEV;
1110 goto fail_put_clk;
1111 }
1112
1113 r = request_mem_region(r->start, r->end - r->start + 1, pdev->name);
1114 if (r == NULL) {
1115 dev_err(&pdev->dev, "failed to request memory resource\n");
1116 ret = -EBUSY;
1117 goto fail_put_clk;
1118 }
1119
1120 info->mmio_base = ioremap(r->start, r->end - r->start + 1);
1121 if (info->mmio_base == NULL) {
1122 dev_err(&pdev->dev, "ioremap() failed\n");
1123 ret = -ENODEV;
1124 goto fail_free_res;
1125 }
1126
1127 ret = pxa3xx_nand_init_buff(info);
1128 if (ret)
1129 goto fail_free_io;
1130
1131 ret = request_irq(IRQ_NAND, pxa3xx_nand_irq, IRQF_DISABLED,
1132 pdev->name, info);
1133 if (ret < 0) {
1134 dev_err(&pdev->dev, "failed to request IRQ\n");
1135 goto fail_free_buf;
1136 }
1137
1138 ret = pxa3xx_nand_detect_flash(info);
1139 if (ret) {
1140 dev_err(&pdev->dev, "failed to detect flash\n");
1141 ret = -ENODEV;
1142 goto fail_free_irq;
1143 }
1144
1145 pxa3xx_nand_init_mtd(mtd, info);
1146
1147 platform_set_drvdata(pdev, mtd);
1148
1149 if (nand_scan(mtd, 1)) {
1150 dev_err(&pdev->dev, "failed to scan nand\n");
1151 ret = -ENXIO;
1152 goto fail_free_irq;
1153 }
1154
1155 return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
1156
1157fail_free_irq:
1158 free_irq(IRQ_NAND, info);
1159fail_free_buf:
1160 if (use_dma) {
1161 pxa_free_dma(info->data_dma_ch);
1162 dma_free_coherent(&pdev->dev, info->data_buff_size,
1163 info->data_buff, info->data_buff_phys);
1164 } else
1165 kfree(info->data_buff);
1166fail_free_io:
1167 iounmap(info->mmio_base);
1168fail_free_res:
1169 release_mem_region(r->start, r->end - r->start + 1);
1170fail_put_clk:
1171 clk_disable(info->clk);
1172 clk_put(info->clk);
1173fail_free_mtd:
1174 kfree(mtd);
1175 return ret;
1176}
1177
1178static int pxa3xx_nand_remove(struct platform_device *pdev)
1179{
1180 struct mtd_info *mtd = platform_get_drvdata(pdev);
1181 struct pxa3xx_nand_info *info = mtd->priv;
1182
1183 platform_set_drvdata(pdev, NULL);
1184
1185 del_mtd_device(mtd);
1186 del_mtd_partitions(mtd);
1187 free_irq(IRQ_NAND, info);
1188 if (use_dma) {
1189 pxa_free_dma(info->data_dma_ch);
1190 dma_free_writecombine(&pdev->dev, info->data_buff_size,
1191 info->data_buff, info->data_buff_phys);
1192 } else
1193 kfree(info->data_buff);
1194 kfree(mtd);
1195 return 0;
1196}
1197
1198#ifdef CONFIG_PM
1199static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state)
1200{
1201 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
1202 struct pxa3xx_nand_info *info = mtd->priv;
1203
1204 if (info->state != STATE_READY) {
1205 dev_err(&pdev->dev, "driver busy, state = %d\n", info->state);
1206 return -EAGAIN;
1207 }
1208
1209 return 0;
1210}
1211
1212static int pxa3xx_nand_resume(struct platform_device *pdev)
1213{
1214 struct mtd_info *mtd = (struct mtd_info *)platform_get_drvdata(pdev);
1215 struct pxa3xx_nand_info *info = mtd->priv;
1216
1217 clk_enable(info->clk);
1218
1219 return pxa3xx_nand_config_flash(info);
1220}
1221#else
1222#define pxa3xx_nand_suspend NULL
1223#define pxa3xx_nand_resume NULL
1224#endif
1225
1226static struct platform_driver pxa3xx_nand_driver = {
1227 .driver = {
1228 .name = "pxa3xx-nand",
1229 },
1230 .probe = pxa3xx_nand_probe,
1231 .remove = pxa3xx_nand_remove,
1232 .suspend = pxa3xx_nand_suspend,
1233 .resume = pxa3xx_nand_resume,
1234};
1235
1236static int __init pxa3xx_nand_init(void)
1237{
1238 return platform_driver_register(&pxa3xx_nand_driver);
1239}
1240module_init(pxa3xx_nand_init);
1241
1242static void __exit pxa3xx_nand_exit(void)
1243{
1244 platform_driver_unregister(&pxa3xx_nand_driver);
1245}
1246module_exit(pxa3xx_nand_exit);
1247
1248MODULE_LICENSE("GPL");
1249MODULE_DESCRIPTION("PXA3xx NAND controller driver");
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 0f6ac250f434..26f88215bc47 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -478,6 +478,7 @@ static int __init rtc_from4_init(void)
478 struct nand_chip *this; 478 struct nand_chip *this;
479 unsigned short bcr1, bcr2, wcr2; 479 unsigned short bcr1, bcr2, wcr2;
480 int i; 480 int i;
481 int ret;
481 482
482 /* Allocate memory for MTD device structure and private data */ 483 /* Allocate memory for MTD device structure and private data */
483 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL); 484 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), GFP_KERNEL);
@@ -537,6 +538,22 @@ static int __init rtc_from4_init(void)
537 this->ecc.hwctl = rtc_from4_enable_hwecc; 538 this->ecc.hwctl = rtc_from4_enable_hwecc;
538 this->ecc.calculate = rtc_from4_calculate_ecc; 539 this->ecc.calculate = rtc_from4_calculate_ecc;
539 this->ecc.correct = rtc_from4_correct_data; 540 this->ecc.correct = rtc_from4_correct_data;
541
542 /* We could create the decoder on demand, if memory is a concern.
543 * This way we have it handy, if an error happens
544 *
545 * Symbolsize is 10 (bits)
546 * Primitve polynomial is x^10+x^3+1
547 * first consecutive root is 0
548 * primitve element to generate roots = 1
549 * generator polinomial degree = 6
550 */
551 rs_decoder = init_rs(10, 0x409, 0, 1, 6);
552 if (!rs_decoder) {
553 printk(KERN_ERR "Could not create a RS decoder\n");
554 ret = -ENOMEM;
555 goto err_1;
556 }
540#else 557#else
541 printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n"); 558 printk(KERN_INFO "rtc_from4_init: using software ECC detection.\n");
542 559
@@ -549,8 +566,8 @@ static int __init rtc_from4_init(void)
549 566
550 /* Scan to find existence of the device */ 567 /* Scan to find existence of the device */
551 if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) { 568 if (nand_scan(rtc_from4_mtd, RTC_FROM4_MAX_CHIPS)) {
552 kfree(rtc_from4_mtd); 569 ret = -ENXIO;
553 return -ENXIO; 570 goto err_2;
554 } 571 }
555 572
556 /* Perform 'device recovery' for each chip in case there was a power loss. */ 573 /* Perform 'device recovery' for each chip in case there was a power loss. */
@@ -566,28 +583,19 @@ static int __init rtc_from4_init(void)
566#endif 583#endif
567 584
568 /* Register the partitions */ 585 /* Register the partitions */
569 add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS); 586 ret = add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
587 if (ret)
588 goto err_3;
570 589
571#ifdef RTC_FROM4_HWECC
572 /* We could create the decoder on demand, if memory is a concern.
573 * This way we have it handy, if an error happens
574 *
575 * Symbolsize is 10 (bits)
576 * Primitve polynomial is x^10+x^3+1
577 * first consecutive root is 0
578 * primitve element to generate roots = 1
579 * generator polinomial degree = 6
580 */
581 rs_decoder = init_rs(10, 0x409, 0, 1, 6);
582 if (!rs_decoder) {
583 printk(KERN_ERR "Could not create a RS decoder\n");
584 nand_release(rtc_from4_mtd);
585 kfree(rtc_from4_mtd);
586 return -ENOMEM;
587 }
588#endif
589 /* Return happy */ 590 /* Return happy */
590 return 0; 591 return 0;
592err_3:
593 nand_release(rtc_from4_mtd);
594err_2:
595 free_rs(rs_decoder);
596err_1:
597 kfree(rtc_from4_mtd);
598 return ret;
591} 599}
592 600
593module_init(rtc_from4_init); 601module_init(rtc_from4_init);
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 9260ad947524..b34a460ab679 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -119,8 +119,7 @@ struct s3c2410_nand_info {
119 void __iomem *sel_reg; 119 void __iomem *sel_reg;
120 int sel_bit; 120 int sel_bit;
121 int mtd_count; 121 int mtd_count;
122 122 unsigned long save_sel;
123 unsigned long save_nfconf;
124 123
125 enum s3c_cpu_type cpu_type; 124 enum s3c_cpu_type cpu_type;
126}; 125};
@@ -358,6 +357,14 @@ static int s3c2410_nand_correct_data(struct mtd_info *mtd, u_char *dat,
358 if (diff0 == 0 && diff1 == 0 && diff2 == 0) 357 if (diff0 == 0 && diff1 == 0 && diff2 == 0)
359 return 0; /* ECC is ok */ 358 return 0; /* ECC is ok */
360 359
360 /* sometimes people do not think about using the ECC, so check
361 * to see if we have an 0xff,0xff,0xff read ECC and then ignore
362 * the error, on the assumption that this is an un-eccd page.
363 */
364 if (read_ecc[0] == 0xff && read_ecc[1] == 0xff && read_ecc[2] == 0xff
365 && info->platform->ignore_unset_ecc)
366 return 0;
367
361 /* Can we correct this ECC (ie, one row and column change). 368 /* Can we correct this ECC (ie, one row and column change).
362 * Note, this is similar to the 256 error code on smartmedia */ 369 * Note, this is similar to the 256 error code on smartmedia */
363 370
@@ -473,7 +480,7 @@ static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u
473 ecc_code[1] = ecc >> 8; 480 ecc_code[1] = ecc >> 8;
474 ecc_code[2] = ecc >> 16; 481 ecc_code[2] = ecc >> 16;
475 482
476 pr_debug("%s: returning ecc %06lx\n", __func__, ecc); 483 pr_debug("%s: returning ecc %06lx\n", __func__, ecc & 0xffffff);
477 484
478 return 0; 485 return 0;
479} 486}
@@ -644,9 +651,6 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
644 chip->ecc.calculate = s3c2410_nand_calculate_ecc; 651 chip->ecc.calculate = s3c2410_nand_calculate_ecc;
645 chip->ecc.correct = s3c2410_nand_correct_data; 652 chip->ecc.correct = s3c2410_nand_correct_data;
646 chip->ecc.mode = NAND_ECC_HW; 653 chip->ecc.mode = NAND_ECC_HW;
647 chip->ecc.size = 512;
648 chip->ecc.bytes = 3;
649 chip->ecc.layout = &nand_hw_eccoob;
650 654
651 switch (info->cpu_type) { 655 switch (info->cpu_type) {
652 case TYPE_S3C2410: 656 case TYPE_S3C2410:
@@ -668,6 +672,40 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info,
668 } else { 672 } else {
669 chip->ecc.mode = NAND_ECC_SOFT; 673 chip->ecc.mode = NAND_ECC_SOFT;
670 } 674 }
675
676 if (set->ecc_layout != NULL)
677 chip->ecc.layout = set->ecc_layout;
678
679 if (set->disable_ecc)
680 chip->ecc.mode = NAND_ECC_NONE;
681}
682
683/* s3c2410_nand_update_chip
684 *
685 * post-probe chip update, to change any items, such as the
686 * layout for large page nand
687 */
688
689static void s3c2410_nand_update_chip(struct s3c2410_nand_info *info,
690 struct s3c2410_nand_mtd *nmtd)
691{
692 struct nand_chip *chip = &nmtd->chip;
693
694 printk("%s: chip %p: %d\n", __func__, chip, chip->page_shift);
695
696 if (hardware_ecc) {
697 /* change the behaviour depending on wether we are using
698 * the large or small page nand device */
699
700 if (chip->page_shift > 10) {
701 chip->ecc.size = 256;
702 chip->ecc.bytes = 3;
703 } else {
704 chip->ecc.size = 512;
705 chip->ecc.bytes = 3;
706 chip->ecc.layout = &nand_hw_eccoob;
707 }
708 }
671} 709}
672 710
673/* s3c2410_nand_probe 711/* s3c2410_nand_probe
@@ -776,9 +814,12 @@ static int s3c24xx_nand_probe(struct platform_device *pdev,
776 814
777 s3c2410_nand_init_chip(info, nmtd, sets); 815 s3c2410_nand_init_chip(info, nmtd, sets);
778 816
779 nmtd->scan_res = nand_scan(&nmtd->mtd, (sets) ? sets->nr_chips : 1); 817 nmtd->scan_res = nand_scan_ident(&nmtd->mtd,
818 (sets) ? sets->nr_chips : 1);
780 819
781 if (nmtd->scan_res == 0) { 820 if (nmtd->scan_res == 0) {
821 s3c2410_nand_update_chip(info, nmtd);
822 nand_scan_tail(&nmtd->mtd);
782 s3c2410_nand_add_partition(info, nmtd, sets); 823 s3c2410_nand_add_partition(info, nmtd, sets);
783 } 824 }
784 825
@@ -810,15 +851,14 @@ static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
810 struct s3c2410_nand_info *info = platform_get_drvdata(dev); 851 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
811 852
812 if (info) { 853 if (info) {
813 info->save_nfconf = readl(info->regs + S3C2410_NFCONF); 854 info->save_sel = readl(info->sel_reg);
814 855
815 /* For the moment, we must ensure nFCE is high during 856 /* For the moment, we must ensure nFCE is high during
816 * the time we are suspended. This really should be 857 * the time we are suspended. This really should be
817 * handled by suspending the MTDs we are using, but 858 * handled by suspending the MTDs we are using, but
818 * that is currently not the case. */ 859 * that is currently not the case. */
819 860
820 writel(info->save_nfconf | info->sel_bit, 861 writel(info->save_sel | info->sel_bit, info->sel_reg);
821 info->regs + S3C2410_NFCONF);
822 862
823 if (!allow_clk_stop(info)) 863 if (!allow_clk_stop(info))
824 clk_disable(info->clk); 864 clk_disable(info->clk);
@@ -830,7 +870,7 @@ static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
830static int s3c24xx_nand_resume(struct platform_device *dev) 870static int s3c24xx_nand_resume(struct platform_device *dev)
831{ 871{
832 struct s3c2410_nand_info *info = platform_get_drvdata(dev); 872 struct s3c2410_nand_info *info = platform_get_drvdata(dev);
833 unsigned long nfconf; 873 unsigned long sel;
834 874
835 if (info) { 875 if (info) {
836 clk_enable(info->clk); 876 clk_enable(info->clk);
@@ -838,10 +878,10 @@ static int s3c24xx_nand_resume(struct platform_device *dev)
838 878
839 /* Restore the state of the nFCE line. */ 879 /* Restore the state of the nFCE line. */
840 880
841 nfconf = readl(info->regs + S3C2410_NFCONF); 881 sel = readl(info->sel_reg);
842 nfconf &= ~info->sel_bit; 882 sel &= ~info->sel_bit;
843 nfconf |= info->save_nfconf & info->sel_bit; 883 sel |= info->save_sel & info->sel_bit;
844 writel(nfconf, info->regs + S3C2410_NFCONF); 884 writel(sel, info->sel_reg);
845 885
846 if (allow_clk_stop(info)) 886 if (allow_clk_stop(info))
847 clk_disable(info->clk); 887 clk_disable(info->clk);
@@ -927,3 +967,6 @@ module_exit(s3c2410_nand_exit);
927MODULE_LICENSE("GPL"); 967MODULE_LICENSE("GPL");
928MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 968MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>");
929MODULE_DESCRIPTION("S3C24XX MTD NAND driver"); 969MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
970MODULE_ALIAS("platform:s3c2410-nand");
971MODULE_ALIAS("platform:s3c2412-nand");
972MODULE_ALIAS("platform:s3c2440-nand");
diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
index 0513cbc8834d..345e6eff89ce 100644
--- a/drivers/mtd/nftlmount.c
+++ b/drivers/mtd/nftlmount.c
@@ -33,11 +33,6 @@
33 33
34char nftlmountrev[]="$Revision: 1.41 $"; 34char nftlmountrev[]="$Revision: 1.41 $";
35 35
36extern int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len,
37 size_t *retlen, uint8_t *buf);
38extern int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len,
39 size_t *retlen, uint8_t *buf);
40
41/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the 36/* find_boot_record: Find the NFTL Media Header and its Spare copy which contains the
42 * various device information of the NFTL partition and Bad Unit Table. Update 37 * various device information of the NFTL partition and Bad Unit Table. Update
43 * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[] 38 * the ReplUnitTable[] table accroding to the Bad Unit Table. ReplUnitTable[]
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index f86e06934cd8..4f80c2fd89af 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -72,3 +72,5 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
72 return nr_parts; 72 return nr_parts;
73} 73}
74EXPORT_SYMBOL(of_mtd_parse_partitions); 74EXPORT_SYMBOL(of_mtd_parse_partitions);
75
76MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 8d7d21be1541..5d7965f7e9ce 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -329,6 +329,21 @@ static int onenand_wait(struct mtd_info *mtd, int state)
329 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl); 329 printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", ctrl);
330 if (ctrl & ONENAND_CTRL_LOCK) 330 if (ctrl & ONENAND_CTRL_LOCK)
331 printk(KERN_ERR "onenand_wait: it's locked error.\n"); 331 printk(KERN_ERR "onenand_wait: it's locked error.\n");
332 if (state == FL_READING) {
333 /*
334 * A power loss while writing can result in a page
335 * becoming unreadable. When the device is mounted
336 * again, reading that page gives controller errors.
337 * Upper level software like JFFS2 treat -EIO as fatal,
338 * refusing to mount at all. That means it is necessary
339 * to treat the error as an ECC error to allow recovery.
340 * Note that typically in this case, the eraseblock can
341 * still be erased and rewritten i.e. it has not become
342 * a bad block.
343 */
344 mtd->ecc_stats.failed++;
345 return -EBADMSG;
346 }
332 return -EIO; 347 return -EIO;
333 } 348 }
334 349
@@ -1336,7 +1351,7 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len,
1336 } 1351 }
1337 1352
1338 /* Reject writes, which are not page aligned */ 1353 /* Reject writes, which are not page aligned */
1339 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1354 if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
1340 printk(KERN_ERR "onenand_panic_write: Attempt to write not page aligned data\n"); 1355 printk(KERN_ERR "onenand_panic_write: Attempt to write not page aligned data\n");
1341 return -EINVAL; 1356 return -EINVAL;
1342 } 1357 }
@@ -1466,7 +1481,7 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1466 } 1481 }
1467 1482
1468 /* Reject writes, which are not page aligned */ 1483 /* Reject writes, which are not page aligned */
1469 if (unlikely(NOTALIGNED(to)) || unlikely(NOTALIGNED(len))) { 1484 if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) {
1470 printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n"); 1485 printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n");
1471 return -EINVAL; 1486 return -EINVAL;
1472 } 1487 }
@@ -2052,7 +2067,7 @@ static int onenand_unlock(struct mtd_info *mtd, loff_t ofs, size_t len)
2052 * 2067 *
2053 * Check lock status 2068 * Check lock status
2054 */ 2069 */
2055static void onenand_check_lock_status(struct onenand_chip *this) 2070static int onenand_check_lock_status(struct onenand_chip *this)
2056{ 2071{
2057 unsigned int value, block, status; 2072 unsigned int value, block, status;
2058 unsigned int end; 2073 unsigned int end;
@@ -2070,9 +2085,13 @@ static void onenand_check_lock_status(struct onenand_chip *this)
2070 2085
2071 /* Check lock status */ 2086 /* Check lock status */
2072 status = this->read_word(this->base + ONENAND_REG_WP_STATUS); 2087 status = this->read_word(this->base + ONENAND_REG_WP_STATUS);
2073 if (!(status & ONENAND_WP_US)) 2088 if (!(status & ONENAND_WP_US)) {
2074 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); 2089 printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status);
2090 return 0;
2091 }
2075 } 2092 }
2093
2094 return 1;
2076} 2095}
2077 2096
2078/** 2097/**
@@ -2081,9 +2100,11 @@ static void onenand_check_lock_status(struct onenand_chip *this)
2081 * 2100 *
2082 * Unlock all blocks 2101 * Unlock all blocks
2083 */ 2102 */
2084static int onenand_unlock_all(struct mtd_info *mtd) 2103static void onenand_unlock_all(struct mtd_info *mtd)
2085{ 2104{
2086 struct onenand_chip *this = mtd->priv; 2105 struct onenand_chip *this = mtd->priv;
2106 loff_t ofs = 0;
2107 size_t len = this->chipsize;
2087 2108
2088 if (this->options & ONENAND_HAS_UNLOCK_ALL) { 2109 if (this->options & ONENAND_HAS_UNLOCK_ALL) {
2089 /* Set start block address */ 2110 /* Set start block address */
@@ -2099,23 +2120,19 @@ static int onenand_unlock_all(struct mtd_info *mtd)
2099 & ONENAND_CTRL_ONGO) 2120 & ONENAND_CTRL_ONGO)
2100 continue; 2121 continue;
2101 2122
2123 /* Check lock status */
2124 if (onenand_check_lock_status(this))
2125 return;
2126
2102 /* Workaround for all block unlock in DDP */ 2127 /* Workaround for all block unlock in DDP */
2103 if (ONENAND_IS_DDP(this)) { 2128 if (ONENAND_IS_DDP(this)) {
2104 /* 1st block on another chip */ 2129 /* All blocks on another chip */
2105 loff_t ofs = this->chipsize >> 1; 2130 ofs = this->chipsize >> 1;
2106 size_t len = mtd->erasesize; 2131 len = this->chipsize >> 1;
2107
2108 onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
2109 } 2132 }
2110
2111 onenand_check_lock_status(this);
2112
2113 return 0;
2114 } 2133 }
2115 2134
2116 onenand_do_lock_cmd(mtd, 0x0, this->chipsize, ONENAND_CMD_UNLOCK); 2135 onenand_do_lock_cmd(mtd, ofs, len, ONENAND_CMD_UNLOCK);
2117
2118 return 0;
2119} 2136}
2120 2137
2121#ifdef CONFIG_MTD_ONENAND_OTP 2138#ifdef CONFIG_MTD_ONENAND_OTP
diff --git a/drivers/mtd/onenand/onenand_bbt.c b/drivers/mtd/onenand/onenand_bbt.c
index aecdd50a1781..2f53b51c6805 100644
--- a/drivers/mtd/onenand/onenand_bbt.c
+++ b/drivers/mtd/onenand/onenand_bbt.c
@@ -17,9 +17,6 @@
17#include <linux/mtd/onenand.h> 17#include <linux/mtd/onenand.h>
18#include <linux/mtd/compatmac.h> 18#include <linux/mtd/compatmac.h>
19 19
20extern int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
21 struct mtd_oob_ops *ops);
22
23/** 20/**
24 * check_short_pattern - [GENERIC] check if a pattern is in the buffer 21 * check_short_pattern - [GENERIC] check if a pattern is in the buffer
25 * @param buf the buffer to search 22 * @param buf the buffer to search
diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c
index 823fba4e6d2f..c84e45465499 100644
--- a/drivers/mtd/rfd_ftl.c
+++ b/drivers/mtd/rfd_ftl.c
@@ -823,7 +823,7 @@ static void rfd_ftl_remove_dev(struct mtd_blktrans_dev *dev)
823 kfree(part); 823 kfree(part);
824} 824}
825 825
826struct mtd_blktrans_ops rfd_ftl_tr = { 826static struct mtd_blktrans_ops rfd_ftl_tr = {
827 .name = "rfd", 827 .name = "rfd",
828 .major = RFD_FTL_MAJOR, 828 .major = RFD_FTL_MAJOR,
829 .part_bits = PART_BITS, 829 .part_bits = PART_BITS,
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig
index b9daf159a4a7..3f063108e95f 100644
--- a/drivers/mtd/ubi/Kconfig
+++ b/drivers/mtd/ubi/Kconfig
@@ -24,8 +24,13 @@ config MTD_UBI_WL_THRESHOLD
24 erase counter value and the lowest erase counter value of eraseblocks 24 erase counter value and the lowest erase counter value of eraseblocks
25 of UBI devices. When this threshold is exceeded, UBI starts performing 25 of UBI devices. When this threshold is exceeded, UBI starts performing
26 wear leveling by means of moving data from eraseblock with low erase 26 wear leveling by means of moving data from eraseblock with low erase
27 counter to eraseblocks with high erase counter. Leave the default 27 counter to eraseblocks with high erase counter.
28 value if unsure. 28
29 The default value should be OK for SLC NAND flashes, NOR flashes and
30 other flashes which have eraseblock life-cycle 100000 or more.
31 However, in case of MLC NAND flashes which typically have eraseblock
32 life-cycle less then 10000, the threshold should be lessened (e.g.,
33 to 128 or 256, although it does not have to be power of 2).
29 34
30config MTD_UBI_BEB_RESERVE 35config MTD_UBI_BEB_RESERVE
31 int "Percentage of reserved eraseblocks for bad eraseblocks handling" 36 int "Percentage of reserved eraseblocks for bad eraseblocks handling"
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 275960462970..961416ac0616 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -606,8 +606,16 @@ static int io_init(struct ubi_device *ubi)
606 ubi->ro_mode = 1; 606 ubi->ro_mode = 1;
607 } 607 }
608 608
609 dbg_msg("leb_size %d", ubi->leb_size); 609 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
610 dbg_msg("ro_mode %d", ubi->ro_mode); 610 ubi->peb_size, ubi->peb_size >> 10);
611 ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
612 ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
613 if (ubi->hdrs_min_io_size != ubi->min_io_size)
614 ubi_msg("sub-page size: %d",
615 ubi->hdrs_min_io_size);
616 ubi_msg("VID header offset: %d (aligned %d)",
617 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
618 ubi_msg("data offset: %d", ubi->leb_start);
611 619
612 /* 620 /*
613 * Note, ideally, we have to initialize ubi->bad_peb_count here. But 621 * Note, ideally, we have to initialize ubi->bad_peb_count here. But
@@ -755,8 +763,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
755 mutex_init(&ubi->volumes_mutex); 763 mutex_init(&ubi->volumes_mutex);
756 spin_lock_init(&ubi->volumes_lock); 764 spin_lock_init(&ubi->volumes_lock);
757 765
758 dbg_msg("attaching mtd%d to ubi%d: VID header offset %d", 766 ubi_msg("attaching mtd%d to ubi%d", mtd->index, ubi_num);
759 mtd->index, ubi_num, vid_hdr_offset);
760 767
761 err = io_init(ubi); 768 err = io_init(ubi);
762 if (err) 769 if (err)
@@ -804,15 +811,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
804 ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num); 811 ubi_msg("attached mtd%d to ubi%d", mtd->index, ubi_num);
805 ubi_msg("MTD device name: \"%s\"", mtd->name); 812 ubi_msg("MTD device name: \"%s\"", mtd->name);
806 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20); 813 ubi_msg("MTD device size: %llu MiB", ubi->flash_size >> 20);
807 ubi_msg("physical eraseblock size: %d bytes (%d KiB)",
808 ubi->peb_size, ubi->peb_size >> 10);
809 ubi_msg("logical eraseblock size: %d bytes", ubi->leb_size);
810 ubi_msg("number of good PEBs: %d", ubi->good_peb_count); 814 ubi_msg("number of good PEBs: %d", ubi->good_peb_count);
811 ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count); 815 ubi_msg("number of bad PEBs: %d", ubi->bad_peb_count);
812 ubi_msg("smallest flash I/O unit: %d", ubi->min_io_size);
813 ubi_msg("VID header offset: %d (aligned %d)",
814 ubi->vid_hdr_offset, ubi->vid_hdr_aloffset);
815 ubi_msg("data offset: %d", ubi->leb_start);
816 ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots); 816 ubi_msg("max. allowed volumes: %d", ubi->vtbl_slots);
817 ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD); 817 ubi_msg("wear-leveling threshold: %d", CONFIG_MTD_UBI_WL_THRESHOLD);
818 ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT); 818 ubi_msg("number of internal volumes: %d", UBI_INT_VOL_COUNT);
@@ -950,8 +950,7 @@ static int __init ubi_init(void)
950 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64); 950 BUILD_BUG_ON(sizeof(struct ubi_vid_hdr) != 64);
951 951
952 if (mtd_devs > UBI_MAX_DEVICES) { 952 if (mtd_devs > UBI_MAX_DEVICES) {
953 printk(KERN_ERR "UBI error: too many MTD devices, " 953 ubi_err("too many MTD devices, maximum is %d", UBI_MAX_DEVICES);
954 "maximum is %d\n", UBI_MAX_DEVICES);
955 return -EINVAL; 954 return -EINVAL;
956 } 955 }
957 956
@@ -959,25 +958,25 @@ static int __init ubi_init(void)
959 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR); 958 ubi_class = class_create(THIS_MODULE, UBI_NAME_STR);
960 if (IS_ERR(ubi_class)) { 959 if (IS_ERR(ubi_class)) {
961 err = PTR_ERR(ubi_class); 960 err = PTR_ERR(ubi_class);
962 printk(KERN_ERR "UBI error: cannot create UBI class\n"); 961 ubi_err("cannot create UBI class");
963 goto out; 962 goto out;
964 } 963 }
965 964
966 err = class_create_file(ubi_class, &ubi_version); 965 err = class_create_file(ubi_class, &ubi_version);
967 if (err) { 966 if (err) {
968 printk(KERN_ERR "UBI error: cannot create sysfs file\n"); 967 ubi_err("cannot create sysfs file");
969 goto out_class; 968 goto out_class;
970 } 969 }
971 970
972 err = misc_register(&ubi_ctrl_cdev); 971 err = misc_register(&ubi_ctrl_cdev);
973 if (err) { 972 if (err) {
974 printk(KERN_ERR "UBI error: cannot register device\n"); 973 ubi_err("cannot register device");
975 goto out_version; 974 goto out_version;
976 } 975 }
977 976
978 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab", 977 ubi_wl_entry_slab = kmem_cache_create("ubi_wl_entry_slab",
979 sizeof(struct ubi_wl_entry), 978 sizeof(struct ubi_wl_entry),
980 0, 0, NULL); 979 0, 0, NULL);
981 if (!ubi_wl_entry_slab) 980 if (!ubi_wl_entry_slab)
982 goto out_dev_unreg; 981 goto out_dev_unreg;
983 982
@@ -1000,8 +999,7 @@ static int __init ubi_init(void)
1000 mutex_unlock(&ubi_devices_mutex); 999 mutex_unlock(&ubi_devices_mutex);
1001 if (err < 0) { 1000 if (err < 0) {
1002 put_mtd_device(mtd); 1001 put_mtd_device(mtd);
1003 printk(KERN_ERR "UBI error: cannot attach mtd%d\n", 1002 ubi_err("cannot attach mtd%d", mtd->index);
1004 mtd->index);
1005 goto out_detach; 1003 goto out_detach;
1006 } 1004 }
1007 } 1005 }
@@ -1023,7 +1021,7 @@ out_version:
1023out_class: 1021out_class:
1024 class_destroy(ubi_class); 1022 class_destroy(ubi_class);
1025out: 1023out:
1026 printk(KERN_ERR "UBI error: cannot initialize UBI, error %d\n", err); 1024 ubi_err("UBI error: cannot initialize UBI, error %d", err);
1027 return err; 1025 return err;
1028} 1026}
1029module_init(ubi_init); 1027module_init(ubi_init);
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index 51c40b17f1ec..8ea99d8c9e1f 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -41,7 +41,7 @@
41/* Generic debugging message */ 41/* Generic debugging message */
42#define dbg_msg(fmt, ...) \ 42#define dbg_msg(fmt, ...) \
43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \ 43 printk(KERN_DEBUG "UBI DBG (pid %d): %s: " fmt "\n", \
44 current->pid, __FUNCTION__, ##__VA_ARGS__) 44 current->pid, __func__, ##__VA_ARGS__)
45 45
46#define ubi_dbg_dump_stack() dump_stack() 46#define ubi_dbg_dump_stack() dump_stack()
47 47
@@ -99,8 +99,10 @@ void ubi_dbg_dump_mkvol_req(const struct ubi_mkvol_req *req);
99#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD 99#ifdef CONFIG_MTD_UBI_DEBUG_MSG_BLD
100/* Initialization and build messages */ 100/* Initialization and build messages */
101#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__) 101#define dbg_bld(fmt, ...) dbg_msg(fmt, ##__VA_ARGS__)
102#define UBI_IO_DEBUG 1
102#else 103#else
103#define dbg_bld(fmt, ...) ({}) 104#define dbg_bld(fmt, ...) ({})
105#define UBI_IO_DEBUG 0
104#endif 106#endif
105 107
106#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS 108#ifdef CONFIG_MTD_UBI_DEBUG_EMULATE_BITFLIPS
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index d397219238d3..e909b390069a 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -291,11 +291,12 @@ int ubi_create_gluebi(struct ubi_device *ubi, struct ubi_volume *vol)
291 /* 291 /*
292 * In case of dynamic volume, MTD device size is just volume size. In 292 * In case of dynamic volume, MTD device size is just volume size. In
293 * case of a static volume the size is equivalent to the amount of data 293 * case of a static volume the size is equivalent to the amount of data
294 * bytes, which is zero at this moment and will be changed after volume 294 * bytes.
295 * update.
296 */ 295 */
297 if (vol->vol_type == UBI_DYNAMIC_VOLUME) 296 if (vol->vol_type == UBI_DYNAMIC_VOLUME)
298 mtd->size = vol->usable_leb_size * vol->reserved_pebs; 297 mtd->size = vol->usable_leb_size * vol->reserved_pebs;
298 else
299 mtd->size = vol->used_bytes;
299 300
300 if (add_mtd_device(mtd)) { 301 if (add_mtd_device(mtd)) {
301 ubi_err("cannot not add MTD device\n"); 302 ubi_err("cannot not add MTD device\n");
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index db3efdef2433..4ac11df7b048 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -631,6 +631,8 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
631 631
632 dbg_io("read EC header from PEB %d", pnum); 632 dbg_io("read EC header from PEB %d", pnum);
633 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 633 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
634 if (UBI_IO_DEBUG)
635 verbose = 1;
634 636
635 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE); 637 err = ubi_io_read(ubi, ec_hdr, pnum, 0, UBI_EC_HDR_SIZE);
636 if (err) { 638 if (err) {
@@ -904,6 +906,8 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
904 906
905 dbg_io("read VID header from PEB %d", pnum); 907 dbg_io("read VID header from PEB %d", pnum);
906 ubi_assert(pnum >= 0 && pnum < ubi->peb_count); 908 ubi_assert(pnum >= 0 && pnum < ubi->peb_count);
909 if (UBI_IO_DEBUG)
910 verbose = 1;
907 911
908 p = (char *)vid_hdr - ubi->vid_hdr_shift; 912 p = (char *)vid_hdr - ubi->vid_hdr_shift;
909 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset, 913 err = ubi_io_read(ubi, p, pnum, ubi->vid_hdr_aloffset,
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 05aa3e7daba1..96d410e106ab 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -42,6 +42,7 @@
42 42
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/crc32.h> 44#include <linux/crc32.h>
45#include <asm/div64.h>
45#include "ubi.h" 46#include "ubi.h"
46 47
47#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 48#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -92,27 +93,6 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
92} 93}
93 94
94/** 95/**
95 * commit_to_mean_value - commit intermediate results to the final mean erase
96 * counter value.
97 * @si: scanning information
98 *
99 * This is a helper function which calculates partial mean erase counter mean
100 * value and adds it to the resulting mean value. As we can work only in
101 * integer arithmetic and we want to calculate the mean value of erase counter
102 * accurately, we first sum erase counter values in @si->ec_sum variable and
103 * count these components in @si->ec_count. If this temporary @si->ec_sum is
104 * going to overflow, we calculate the partial mean value
105 * (@si->ec_sum/@si->ec_count) and add it to @si->mean_ec.
106 */
107static void commit_to_mean_value(struct ubi_scan_info *si)
108{
109 si->ec_sum /= si->ec_count;
110 if (si->ec_sum % si->ec_count >= si->ec_count / 2)
111 si->mean_ec += 1;
112 si->mean_ec += si->ec_sum;
113}
114
115/**
116 * validate_vid_hdr - check that volume identifier header is correct and 96 * validate_vid_hdr - check that volume identifier header is correct and
117 * consistent. 97 * consistent.
118 * @vid_hdr: the volume identifier header to check 98 * @vid_hdr: the volume identifier header to check
@@ -901,15 +881,8 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si, int pnum
901 881
902adjust_mean_ec: 882adjust_mean_ec:
903 if (!ec_corr) { 883 if (!ec_corr) {
904 if (si->ec_sum + ec < ec) { 884 si->ec_sum += ec;
905 commit_to_mean_value(si); 885 si->ec_count += 1;
906 si->ec_sum = 0;
907 si->ec_count = 0;
908 } else {
909 si->ec_sum += ec;
910 si->ec_count += 1;
911 }
912
913 if (ec > si->max_ec) 886 if (ec > si->max_ec)
914 si->max_ec = ec; 887 si->max_ec = ec;
915 if (ec < si->min_ec) 888 if (ec < si->min_ec)
@@ -965,9 +938,11 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
965 938
966 dbg_msg("scanning is finished"); 939 dbg_msg("scanning is finished");
967 940
968 /* Finish mean erase counter calculations */ 941 /* Calculate mean erase counter */
969 if (si->ec_count) 942 if (si->ec_count) {
970 commit_to_mean_value(si); 943 do_div(si->ec_sum, si->ec_count);
944 si->mean_ec = si->ec_sum;
945 }
971 946
972 if (si->is_empty) 947 if (si->is_empty)
973 ubi_msg("empty MTD device detected"); 948 ubi_msg("empty MTD device detected");
diff --git a/drivers/mtd/ubi/scan.h b/drivers/mtd/ubi/scan.h
index 46d444af471a..966b9b682a42 100644
--- a/drivers/mtd/ubi/scan.h
+++ b/drivers/mtd/ubi/scan.h
@@ -124,7 +124,7 @@ struct ubi_scan_info {
124 int max_ec; 124 int max_ec;
125 unsigned long long max_sqnum; 125 unsigned long long max_sqnum;
126 int mean_ec; 126 int mean_ec;
127 int ec_sum; 127 uint64_t ec_sum;
128 int ec_count; 128 int ec_count;
129}; 129};
130 130
diff --git a/drivers/mtd/ubi/ubi-media.h b/drivers/mtd/ubi/ubi-media.h
new file mode 100644
index 000000000000..c3185d9fd048
--- /dev/null
+++ b/drivers/mtd/ubi/ubi-media.h
@@ -0,0 +1,372 @@
1/*
2 * Copyright (c) International Business Machines Corp., 2006
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
12 * the GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 *
18 * Authors: Artem Bityutskiy (Битюцкий Артём)
19 * Thomas Gleixner
20 * Frank Haverkamp
21 * Oliver Lohmann
22 * Andreas Arnez
23 */
24
25/*
26 * This file defines the layout of UBI headers and all the other UBI on-flash
27 * data structures.
28 */
29
30#ifndef __UBI_MEDIA_H__
31#define __UBI_MEDIA_H__
32
33#include <asm/byteorder.h>
34
35/* The version of UBI images supported by this implementation */
36#define UBI_VERSION 1
37
38/* The highest erase counter value supported by this implementation */
39#define UBI_MAX_ERASECOUNTER 0x7FFFFFFF
40
41/* The initial CRC32 value used when calculating CRC checksums */
42#define UBI_CRC32_INIT 0xFFFFFFFFU
43
44/* Erase counter header magic number (ASCII "UBI#") */
45#define UBI_EC_HDR_MAGIC 0x55424923
46/* Volume identifier header magic number (ASCII "UBI!") */
47#define UBI_VID_HDR_MAGIC 0x55424921
48
49/*
50 * Volume type constants used in the volume identifier header.
51 *
52 * @UBI_VID_DYNAMIC: dynamic volume
53 * @UBI_VID_STATIC: static volume
54 */
55enum {
56 UBI_VID_DYNAMIC = 1,
57 UBI_VID_STATIC = 2
58};
59
60/*
61 * Volume flags used in the volume table record.
62 *
63 * @UBI_VTBL_AUTORESIZE_FLG: auto-resize this volume
64 *
65 * %UBI_VTBL_AUTORESIZE_FLG flag can be set only for one volume in the volume
66 * table. UBI automatically re-sizes the volume which has this flag and makes
67 * the volume to be of largest possible size. This means that if after the
68 * initialization UBI finds out that there are available physical eraseblocks
69 * present on the device, it automatically appends all of them to the volume
70 * (the physical eraseblocks reserved for bad eraseblocks handling and other
71 * reserved physical eraseblocks are not taken). So, if there is a volume with
72 * the %UBI_VTBL_AUTORESIZE_FLG flag set, the amount of available logical
73 * eraseblocks will be zero after UBI is loaded, because all of them will be
74 * reserved for this volume. Note, the %UBI_VTBL_AUTORESIZE_FLG bit is cleared
75 * after the volume had been initialized.
76 *
77 * The auto-resize feature is useful for device production purposes. For
78 * example, different NAND flash chips may have different amount of initial bad
79 * eraseblocks, depending of particular chip instance. Manufacturers of NAND
80 * chips usually guarantee that the amount of initial bad eraseblocks does not
81 * exceed certain percent, e.g. 2%. When one creates an UBI image which will be
82 * flashed to the end devices in production, he does not know the exact amount
83 * of good physical eraseblocks the NAND chip on the device will have, but this
84 * number is required to calculate the volume sized and put them to the volume
85 * table of the UBI image. In this case, one of the volumes (e.g., the one
86 * which will store the root file system) is marked as "auto-resizable", and
87 * UBI will adjust its size on the first boot if needed.
88 *
89 * Note, first UBI reserves some amount of physical eraseblocks for bad
90 * eraseblock handling, and then re-sizes the volume, not vice-versa. This
91 * means that the pool of reserved physical eraseblocks will always be present.
92 */
93enum {
94 UBI_VTBL_AUTORESIZE_FLG = 0x01,
95};
96
97/*
98 * Compatibility constants used by internal volumes.
99 *
100 * @UBI_COMPAT_DELETE: delete this internal volume before anything is written
101 * to the flash
102 * @UBI_COMPAT_RO: attach this device in read-only mode
103 * @UBI_COMPAT_PRESERVE: preserve this internal volume - do not touch its
104 * physical eraseblocks, don't allow the wear-leveling unit to move them
105 * @UBI_COMPAT_REJECT: reject this UBI image
106 */
107enum {
108 UBI_COMPAT_DELETE = 1,
109 UBI_COMPAT_RO = 2,
110 UBI_COMPAT_PRESERVE = 4,
111 UBI_COMPAT_REJECT = 5
112};
113
114/* Sizes of UBI headers */
115#define UBI_EC_HDR_SIZE sizeof(struct ubi_ec_hdr)
116#define UBI_VID_HDR_SIZE sizeof(struct ubi_vid_hdr)
117
118/* Sizes of UBI headers without the ending CRC */
119#define UBI_EC_HDR_SIZE_CRC (UBI_EC_HDR_SIZE - sizeof(__be32))
120#define UBI_VID_HDR_SIZE_CRC (UBI_VID_HDR_SIZE - sizeof(__be32))
121
122/**
123 * struct ubi_ec_hdr - UBI erase counter header.
124 * @magic: erase counter header magic number (%UBI_EC_HDR_MAGIC)
125 * @version: version of UBI implementation which is supposed to accept this
126 * UBI image
127 * @padding1: reserved for future, zeroes
128 * @ec: the erase counter
129 * @vid_hdr_offset: where the VID header starts
130 * @data_offset: where the user data start
131 * @padding2: reserved for future, zeroes
132 * @hdr_crc: erase counter header CRC checksum
133 *
134 * The erase counter header takes 64 bytes and has a plenty of unused space for
135 * future usage. The unused fields are zeroed. The @version field is used to
136 * indicate the version of UBI implementation which is supposed to be able to
137 * work with this UBI image. If @version is greater then the current UBI
138 * version, the image is rejected. This may be useful in future if something
139 * is changed radically. This field is duplicated in the volume identifier
140 * header.
141 *
142 * The @vid_hdr_offset and @data_offset fields contain the offset of the the
143 * volume identifier header and user data, relative to the beginning of the
144 * physical eraseblock. These values have to be the same for all physical
145 * eraseblocks.
146 */
147struct ubi_ec_hdr {
148 __be32 magic;
149 __u8 version;
150 __u8 padding1[3];
151 __be64 ec; /* Warning: the current limit is 31-bit anyway! */
152 __be32 vid_hdr_offset;
153 __be32 data_offset;
154 __u8 padding2[36];
155 __be32 hdr_crc;
156} __attribute__ ((packed));
157
158/**
159 * struct ubi_vid_hdr - on-flash UBI volume identifier header.
160 * @magic: volume identifier header magic number (%UBI_VID_HDR_MAGIC)
161 * @version: UBI implementation version which is supposed to accept this UBI
162 * image (%UBI_VERSION)
163 * @vol_type: volume type (%UBI_VID_DYNAMIC or %UBI_VID_STATIC)
164 * @copy_flag: if this logical eraseblock was copied from another physical
165 * eraseblock (for wear-leveling reasons)
166 * @compat: compatibility of this volume (%0, %UBI_COMPAT_DELETE,
167 * %UBI_COMPAT_IGNORE, %UBI_COMPAT_PRESERVE, or %UBI_COMPAT_REJECT)
168 * @vol_id: ID of this volume
169 * @lnum: logical eraseblock number
170 * @leb_ver: version of this logical eraseblock (IMPORTANT: obsolete, to be
171 * removed, kept only for not breaking older UBI users)
172 * @data_size: how many bytes of data this logical eraseblock contains
173 * @used_ebs: total number of used logical eraseblocks in this volume
174 * @data_pad: how many bytes at the end of this physical eraseblock are not
175 * used
176 * @data_crc: CRC checksum of the data stored in this logical eraseblock
177 * @padding1: reserved for future, zeroes
178 * @sqnum: sequence number
179 * @padding2: reserved for future, zeroes
180 * @hdr_crc: volume identifier header CRC checksum
181 *
182 * The @sqnum is the value of the global sequence counter at the time when this
183 * VID header was created. The global sequence counter is incremented each time
184 * UBI writes a new VID header to the flash, i.e. when it maps a logical
185 * eraseblock to a new physical eraseblock. The global sequence counter is an
186 * unsigned 64-bit integer and we assume it never overflows. The @sqnum
187 * (sequence number) is used to distinguish between older and newer versions of
188 * logical eraseblocks.
189 *
190 * There are 2 situations when there may be more then one physical eraseblock
191 * corresponding to the same logical eraseblock, i.e., having the same @vol_id
192 * and @lnum values in the volume identifier header. Suppose we have a logical
193 * eraseblock L and it is mapped to the physical eraseblock P.
194 *
195 * 1. Because UBI may erase physical eraseblocks asynchronously, the following
196 * situation is possible: L is asynchronously erased, so P is scheduled for
197 * erasure, then L is written to,i.e. mapped to another physical eraseblock P1,
198 * so P1 is written to, then an unclean reboot happens. Result - there are 2
199 * physical eraseblocks P and P1 corresponding to the same logical eraseblock
200 * L. But P1 has greater sequence number, so UBI picks P1 when it attaches the
201 * flash.
202 *
203 * 2. From time to time UBI moves logical eraseblocks to other physical
204 * eraseblocks for wear-leveling reasons. If, for example, UBI moves L from P
205 * to P1, and an unclean reboot happens before P is physically erased, there
206 * are two physical eraseblocks P and P1 corresponding to L and UBI has to
207 * select one of them when the flash is attached. The @sqnum field says which
208 * PEB is the original (obviously P will have lower @sqnum) and the copy. But
209 * it is not enough to select the physical eraseblock with the higher sequence
210 * number, because the unclean reboot could have happen in the middle of the
211 * copying process, so the data in P is corrupted. It is also not enough to
212 * just select the physical eraseblock with lower sequence number, because the
213 * data there may be old (consider a case if more data was added to P1 after
214 * the copying). Moreover, the unclean reboot may happen when the erasure of P
215 * was just started, so it result in unstable P, which is "mostly" OK, but
216 * still has unstable bits.
217 *
218 * UBI uses the @copy_flag field to indicate that this logical eraseblock is a
219 * copy. UBI also calculates data CRC when the data is moved and stores it at
220 * the @data_crc field of the copy (P1). So when UBI needs to pick one physical
221 * eraseblock of two (P or P1), the @copy_flag of the newer one (P1) is
222 * examined. If it is cleared, the situation* is simple and the newer one is
223 * picked. If it is set, the data CRC of the copy (P1) is examined. If the CRC
224 * checksum is correct, this physical eraseblock is selected (P1). Otherwise
225 * the older one (P) is selected.
226 *
227 * Note, there is an obsolete @leb_ver field which was used instead of @sqnum
228 * in the past. But it is not used anymore and we keep it in order to be able
229 * to deal with old UBI images. It will be removed at some point.
230 *
231 * There are 2 sorts of volumes in UBI: user volumes and internal volumes.
232 * Internal volumes are not seen from outside and are used for various internal
233 * UBI purposes. In this implementation there is only one internal volume - the
234 * layout volume. Internal volumes are the main mechanism of UBI extensions.
235 * For example, in future one may introduce a journal internal volume. Internal
236 * volumes have their own reserved range of IDs.
237 *
238 * The @compat field is only used for internal volumes and contains the "degree
239 * of their compatibility". It is always zero for user volumes. This field
240 * provides a mechanism to introduce UBI extensions and to be still compatible
241 * with older UBI binaries. For example, if someone introduced a journal in
242 * future, he would probably use %UBI_COMPAT_DELETE compatibility for the
243 * journal volume. And in this case, older UBI binaries, which know nothing
244 * about the journal volume, would just delete this volume and work perfectly
245 * fine. This is similar to what Ext2fs does when it is fed by an Ext3fs image
246 * - it just ignores the Ext3fs journal.
247 *
248 * The @data_crc field contains the CRC checksum of the contents of the logical
249 * eraseblock if this is a static volume. In case of dynamic volumes, it does
250 * not contain the CRC checksum as a rule. The only exception is when the
251 * data of the physical eraseblock was moved by the wear-leveling unit, then
252 * the wear-leveling unit calculates the data CRC and stores it in the
253 * @data_crc field. And of course, the @copy_flag is %in this case.
254 *
255 * The @data_size field is used only for static volumes because UBI has to know
256 * how many bytes of data are stored in this eraseblock. For dynamic volumes,
257 * this field usually contains zero. The only exception is when the data of the
258 * physical eraseblock was moved to another physical eraseblock for
259 * wear-leveling reasons. In this case, UBI calculates CRC checksum of the
260 * contents and uses both @data_crc and @data_size fields. In this case, the
261 * @data_size field contains data size.
262 *
263 * The @used_ebs field is used only for static volumes and indicates how many
264 * eraseblocks the data of the volume takes. For dynamic volumes this field is
265 * not used and always contains zero.
266 *
267 * The @data_pad is calculated when volumes are created using the alignment
268 * parameter. So, effectively, the @data_pad field reduces the size of logical
269 * eraseblocks of this volume. This is very handy when one uses block-oriented
270 * software (say, cramfs) on top of the UBI volume.
271 */
272struct ubi_vid_hdr {
273 __be32 magic;
274 __u8 version;
275 __u8 vol_type;
276 __u8 copy_flag;
277 __u8 compat;
278 __be32 vol_id;
279 __be32 lnum;
280 __be32 leb_ver; /* obsolete, to be removed, don't use */
281 __be32 data_size;
282 __be32 used_ebs;
283 __be32 data_pad;
284 __be32 data_crc;
285 __u8 padding1[4];
286 __be64 sqnum;
287 __u8 padding2[12];
288 __be32 hdr_crc;
289} __attribute__ ((packed));
290
291/* Internal UBI volumes count */
292#define UBI_INT_VOL_COUNT 1
293
294/*
295 * Starting ID of internal volumes. There is reserved room for 4096 internal
296 * volumes.
297 */
298#define UBI_INTERNAL_VOL_START (0x7FFFFFFF - 4096)
299
300/* The layout volume contains the volume table */
301
302#define UBI_LAYOUT_VOLUME_ID UBI_INTERNAL_VOL_START
303#define UBI_LAYOUT_VOLUME_TYPE UBI_VID_DYNAMIC
304#define UBI_LAYOUT_VOLUME_ALIGN 1
305#define UBI_LAYOUT_VOLUME_EBS 2
306#define UBI_LAYOUT_VOLUME_NAME "layout volume"
307#define UBI_LAYOUT_VOLUME_COMPAT UBI_COMPAT_REJECT
308
309/* The maximum number of volumes per one UBI device */
310#define UBI_MAX_VOLUMES 128
311
312/* The maximum volume name length */
313#define UBI_VOL_NAME_MAX 127
314
315/* Size of the volume table record */
316#define UBI_VTBL_RECORD_SIZE sizeof(struct ubi_vtbl_record)
317
318/* Size of the volume table record without the ending CRC */
319#define UBI_VTBL_RECORD_SIZE_CRC (UBI_VTBL_RECORD_SIZE - sizeof(__be32))
320
321/**
322 * struct ubi_vtbl_record - a record in the volume table.
323 * @reserved_pebs: how many physical eraseblocks are reserved for this volume
324 * @alignment: volume alignment
325 * @data_pad: how many bytes are unused at the end of the each physical
326 * eraseblock to satisfy the requested alignment
327 * @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
328 * @upd_marker: if volume update was started but not finished
329 * @name_len: volume name length
330 * @name: the volume name
331 * @flags: volume flags (%UBI_VTBL_AUTORESIZE_FLG)
332 * @padding: reserved, zeroes
333 * @crc: a CRC32 checksum of the record
334 *
335 * The volume table records are stored in the volume table, which is stored in
336 * the layout volume. The layout volume consists of 2 logical eraseblock, each
337 * of which contains a copy of the volume table (i.e., the volume table is
338 * duplicated). The volume table is an array of &struct ubi_vtbl_record
339 * objects indexed by the volume ID.
340 *
341 * If the size of the logical eraseblock is large enough to fit
342 * %UBI_MAX_VOLUMES records, the volume table contains %UBI_MAX_VOLUMES
343 * records. Otherwise, it contains as many records as it can fit (i.e., size of
344 * logical eraseblock divided by sizeof(struct ubi_vtbl_record)).
345 *
346 * The @upd_marker flag is used to implement volume update. It is set to %1
347 * before update and set to %0 after the update. So if the update operation was
348 * interrupted, UBI knows that the volume is corrupted.
349 *
350 * The @alignment field is specified when the volume is created and cannot be
351 * later changed. It may be useful, for example, when a block-oriented file
352 * system works on top of UBI. The @data_pad field is calculated using the
353 * logical eraseblock size and @alignment. The alignment must be multiple to the
354 * minimal flash I/O unit. If @alignment is 1, all the available space of
355 * the physical eraseblocks is used.
356 *
357 * Empty records contain all zeroes and the CRC checksum of those zeroes.
358 */
359struct ubi_vtbl_record {
360 __be32 reserved_pebs;
361 __be32 alignment;
362 __be32 data_pad;
363 __u8 vol_type;
364 __u8 upd_marker;
365 __be16 name_len;
366 __u8 name[UBI_VOL_NAME_MAX+1];
367 __u8 flags;
368 __u8 padding[23];
369 __be32 crc;
370} __attribute__ ((packed));
371
372#endif /* !__UBI_MEDIA_H__ */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index a548c1d28fa8..67dcbd11c15c 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -37,10 +37,9 @@
37#include <linux/string.h> 37#include <linux/string.h>
38#include <linux/vmalloc.h> 38#include <linux/vmalloc.h>
39#include <linux/mtd/mtd.h> 39#include <linux/mtd/mtd.h>
40
41#include <mtd/ubi-header.h>
42#include <linux/mtd/ubi.h> 40#include <linux/mtd/ubi.h>
43 41
42#include "ubi-media.h"
44#include "scan.h" 43#include "scan.h"
45#include "debug.h" 44#include "debug.h"
46 45
@@ -54,10 +53,10 @@
54#define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__) 53#define ubi_msg(fmt, ...) printk(KERN_NOTICE "UBI: " fmt "\n", ##__VA_ARGS__)
55/* UBI warning messages */ 54/* UBI warning messages */
56#define ubi_warn(fmt, ...) printk(KERN_WARNING "UBI warning: %s: " fmt "\n", \ 55#define ubi_warn(fmt, ...) printk(KERN_WARNING "UBI warning: %s: " fmt "\n", \
57 __FUNCTION__, ##__VA_ARGS__) 56 __func__, ##__VA_ARGS__)
58/* UBI error messages */ 57/* UBI error messages */
59#define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \ 58#define ubi_err(fmt, ...) printk(KERN_ERR "UBI error: %s: " fmt "\n", \
60 __FUNCTION__, ##__VA_ARGS__) 59 __func__, ##__VA_ARGS__)
61 60
62/* Lowest number PEBs reserved for bad PEB handling */ 61/* Lowest number PEBs reserved for bad PEB handling */
63#define MIN_RESEVED_PEBS 2 62#define MIN_RESEVED_PEBS 2