diff options
Diffstat (limited to 'drivers/mtd')
105 files changed, 4034 insertions, 2603 deletions
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index 82d1e4de475b..4521b1ecce45 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile | |||
@@ -4,7 +4,7 @@ | |||
4 | 4 | ||
5 | # Core functionality. | 5 | # Core functionality. |
6 | obj-$(CONFIG_MTD) += mtd.o | 6 | obj-$(CONFIG_MTD) += mtd.o |
7 | mtd-y := mtdcore.o mtdsuper.o mtdbdi.o | 7 | mtd-y := mtdcore.o mtdsuper.o |
8 | mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o | 8 | mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o |
9 | 9 | ||
10 | obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o | 10 | obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o |
diff --git a/drivers/mtd/chips/Kconfig b/drivers/mtd/chips/Kconfig index 9408099eec48..35c6a23b183b 100644 --- a/drivers/mtd/chips/Kconfig +++ b/drivers/mtd/chips/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/chips/Kconfig | ||
2 | |||
3 | menu "RAM/ROM/Flash chip drivers" | 1 | menu "RAM/ROM/Flash chip drivers" |
4 | depends on MTD!=n | 2 | depends on MTD!=n |
5 | 3 | ||
@@ -242,4 +240,3 @@ config MTD_XIP | |||
242 | then say N. | 240 | then say N. |
243 | 241 | ||
244 | endmenu | 242 | endmenu |
245 | |||
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c index e7563a9872d0..5fbf29e1e64f 100644 --- a/drivers/mtd/chips/cfi_cmdset_0001.c +++ b/drivers/mtd/chips/cfi_cmdset_0001.c | |||
@@ -43,15 +43,17 @@ | |||
43 | // debugging, turns off buffer write mode if set to 1 | 43 | // debugging, turns off buffer write mode if set to 1 |
44 | #define FORCE_WORD_WRITE 0 | 44 | #define FORCE_WORD_WRITE 0 |
45 | 45 | ||
46 | #define MANUFACTURER_INTEL 0x0089 | 46 | /* Intel chips */ |
47 | #define I82802AB 0x00ad | 47 | #define I82802AB 0x00ad |
48 | #define I82802AC 0x00ac | 48 | #define I82802AC 0x00ac |
49 | #define PF38F4476 0x881c | 49 | #define PF38F4476 0x881c |
50 | #define MANUFACTURER_ST 0x0020 | 50 | /* STMicroelectronics chips */ |
51 | #define M50LPW080 0x002F | 51 | #define M50LPW080 0x002F |
52 | #define M50FLW080A 0x0080 | 52 | #define M50FLW080A 0x0080 |
53 | #define M50FLW080B 0x0081 | 53 | #define M50FLW080B 0x0081 |
54 | /* Atmel chips */ | ||
54 | #define AT49BV640D 0x02de | 55 | #define AT49BV640D 0x02de |
56 | #define AT49BV640DT 0x02db | ||
55 | 57 | ||
56 | static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); | 58 | static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); |
57 | static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); | 59 | static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); |
@@ -199,6 +201,16 @@ static void fixup_convert_atmel_pri(struct mtd_info *mtd, void *param) | |||
199 | cfi->cfiq->BufWriteTimeoutMax = 0; | 201 | cfi->cfiq->BufWriteTimeoutMax = 0; |
200 | } | 202 | } |
201 | 203 | ||
204 | static void fixup_at49bv640dx_lock(struct mtd_info *mtd, void *param) | ||
205 | { | ||
206 | struct map_info *map = mtd->priv; | ||
207 | struct cfi_private *cfi = map->fldrv_priv; | ||
208 | struct cfi_pri_intelext *cfip = cfi->cmdset_priv; | ||
209 | |||
210 | cfip->FeatureSupport |= (1 << 5); | ||
211 | mtd->flags |= MTD_POWERUP_LOCK; | ||
212 | } | ||
213 | |||
202 | #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE | 214 | #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE |
203 | /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */ | 215 | /* Some Intel Strata Flash prior to FPO revision C has bugs in this area */ |
204 | static void fixup_intel_strataflash(struct mtd_info *mtd, void* param) | 216 | static void fixup_intel_strataflash(struct mtd_info *mtd, void* param) |
@@ -283,6 +295,8 @@ static void fixup_unlock_powerup_lock(struct mtd_info *mtd, void *param) | |||
283 | 295 | ||
284 | static struct cfi_fixup cfi_fixup_table[] = { | 296 | static struct cfi_fixup cfi_fixup_table[] = { |
285 | { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, | 297 | { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, |
298 | { CFI_MFR_ATMEL, AT49BV640D, fixup_at49bv640dx_lock, NULL }, | ||
299 | { CFI_MFR_ATMEL, AT49BV640DT, fixup_at49bv640dx_lock, NULL }, | ||
286 | #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE | 300 | #ifdef CMDSET0001_DISABLE_ERASE_SUSPEND_ON_WRITE |
287 | { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL }, | 301 | { CFI_MFR_ANY, CFI_ID_ANY, fixup_intel_strataflash, NULL }, |
288 | #endif | 302 | #endif |
@@ -294,16 +308,16 @@ static struct cfi_fixup cfi_fixup_table[] = { | |||
294 | #endif | 308 | #endif |
295 | { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct, NULL }, | 309 | { CFI_MFR_ST, 0x00ba, /* M28W320CT */ fixup_st_m28w320ct, NULL }, |
296 | { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb, NULL }, | 310 | { CFI_MFR_ST, 0x00bb, /* M28W320CB */ fixup_st_m28w320cb, NULL }, |
297 | { MANUFACTURER_INTEL, CFI_ID_ANY, fixup_unlock_powerup_lock, NULL, }, | 311 | { CFI_MFR_INTEL, CFI_ID_ANY, fixup_unlock_powerup_lock, NULL, }, |
298 | { 0, 0, NULL, NULL } | 312 | { 0, 0, NULL, NULL } |
299 | }; | 313 | }; |
300 | 314 | ||
301 | static struct cfi_fixup jedec_fixup_table[] = { | 315 | static struct cfi_fixup jedec_fixup_table[] = { |
302 | { MANUFACTURER_INTEL, I82802AB, fixup_use_fwh_lock, NULL, }, | 316 | { CFI_MFR_INTEL, I82802AB, fixup_use_fwh_lock, NULL, }, |
303 | { MANUFACTURER_INTEL, I82802AC, fixup_use_fwh_lock, NULL, }, | 317 | { CFI_MFR_INTEL, I82802AC, fixup_use_fwh_lock, NULL, }, |
304 | { MANUFACTURER_ST, M50LPW080, fixup_use_fwh_lock, NULL, }, | 318 | { CFI_MFR_ST, M50LPW080, fixup_use_fwh_lock, NULL, }, |
305 | { MANUFACTURER_ST, M50FLW080A, fixup_use_fwh_lock, NULL, }, | 319 | { CFI_MFR_ST, M50FLW080A, fixup_use_fwh_lock, NULL, }, |
306 | { MANUFACTURER_ST, M50FLW080B, fixup_use_fwh_lock, NULL, }, | 320 | { CFI_MFR_ST, M50FLW080B, fixup_use_fwh_lock, NULL, }, |
307 | { 0, 0, NULL, NULL } | 321 | { 0, 0, NULL, NULL } |
308 | }; | 322 | }; |
309 | static struct cfi_fixup fixup_table[] = { | 323 | static struct cfi_fixup fixup_table[] = { |
@@ -319,7 +333,7 @@ static struct cfi_fixup fixup_table[] = { | |||
319 | static void cfi_fixup_major_minor(struct cfi_private *cfi, | 333 | static void cfi_fixup_major_minor(struct cfi_private *cfi, |
320 | struct cfi_pri_intelext *extp) | 334 | struct cfi_pri_intelext *extp) |
321 | { | 335 | { |
322 | if (cfi->mfr == MANUFACTURER_INTEL && | 336 | if (cfi->mfr == CFI_MFR_INTEL && |
323 | cfi->id == PF38F4476 && extp->MinorVersion == '3') | 337 | cfi->id == PF38F4476 && extp->MinorVersion == '3') |
324 | extp->MinorVersion = '1'; | 338 | extp->MinorVersion = '1'; |
325 | } | 339 | } |
@@ -2235,7 +2249,7 @@ static int cfi_intelext_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, | |||
2235 | 2249 | ||
2236 | /* Some chips have OTP located in the _top_ partition only. | 2250 | /* Some chips have OTP located in the _top_ partition only. |
2237 | For example: Intel 28F256L18T (T means top-parameter device) */ | 2251 | For example: Intel 28F256L18T (T means top-parameter device) */ |
2238 | if (cfi->mfr == MANUFACTURER_INTEL) { | 2252 | if (cfi->mfr == CFI_MFR_INTEL) { |
2239 | switch (cfi->id) { | 2253 | switch (cfi->id) { |
2240 | case 0x880b: | 2254 | case 0x880b: |
2241 | case 0x880c: | 2255 | case 0x880c: |
@@ -2564,6 +2578,7 @@ static int cfi_intelext_reset(struct mtd_info *mtd) | |||
2564 | if (!ret) { | 2578 | if (!ret) { |
2565 | map_write(map, CMD(0xff), chip->start); | 2579 | map_write(map, CMD(0xff), chip->start); |
2566 | chip->state = FL_SHUTDOWN; | 2580 | chip->state = FL_SHUTDOWN; |
2581 | put_chip(map, chip, chip->start); | ||
2567 | } | 2582 | } |
2568 | spin_unlock(chip->mutex); | 2583 | spin_unlock(chip->mutex); |
2569 | } | 2584 | } |
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c index 94bb61e19047..f3600e8d5382 100644 --- a/drivers/mtd/chips/cfi_cmdset_0002.c +++ b/drivers/mtd/chips/cfi_cmdset_0002.c | |||
@@ -490,10 +490,6 @@ static struct mtd_info *cfi_amdstd_setup(struct mtd_info *mtd) | |||
490 | } | 490 | } |
491 | #endif | 491 | #endif |
492 | 492 | ||
493 | /* FIXME: erase-suspend-program is broken. See | ||
494 | http://lists.infradead.org/pipermail/linux-mtd/2003-December/009001.html */ | ||
495 | printk(KERN_NOTICE "cfi_cmdset_0002: Disabling erase-suspend-program due to code brokenness.\n"); | ||
496 | |||
497 | __module_get(THIS_MODULE); | 493 | __module_get(THIS_MODULE); |
498 | return mtd; | 494 | return mtd; |
499 | 495 | ||
@@ -573,7 +569,6 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr | |||
573 | 569 | ||
574 | if (time_after(jiffies, timeo)) { | 570 | if (time_after(jiffies, timeo)) { |
575 | printk(KERN_ERR "Waiting for chip to be ready timed out.\n"); | 571 | printk(KERN_ERR "Waiting for chip to be ready timed out.\n"); |
576 | spin_unlock(chip->mutex); | ||
577 | return -EIO; | 572 | return -EIO; |
578 | } | 573 | } |
579 | spin_unlock(chip->mutex); | 574 | spin_unlock(chip->mutex); |
@@ -589,15 +584,9 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr | |||
589 | return 0; | 584 | return 0; |
590 | 585 | ||
591 | case FL_ERASING: | 586 | case FL_ERASING: |
592 | if (mode == FL_WRITING) /* FIXME: Erase-suspend-program appears broken. */ | 587 | if (!cfip || !(cfip->EraseSuspend & (0x1|0x2)) || |
593 | goto sleep; | 588 | !(mode == FL_READY || mode == FL_POINT || |
594 | 589 | (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)))) | |
595 | if (!( mode == FL_READY | ||
596 | || mode == FL_POINT | ||
597 | || !cfip | ||
598 | || (mode == FL_WRITING && (cfip->EraseSuspend & 0x2)) | ||
599 | || (mode == FL_WRITING && (cfip->EraseSuspend & 0x1) | ||
600 | ))) | ||
601 | goto sleep; | 590 | goto sleep; |
602 | 591 | ||
603 | /* We could check to see if we're trying to access the sector | 592 | /* We could check to see if we're trying to access the sector |
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c index c5a84fda5410..ca584d0380b4 100755..100644 --- a/drivers/mtd/chips/cfi_util.c +++ b/drivers/mtd/chips/cfi_util.c | |||
@@ -71,6 +71,13 @@ int __xipram cfi_qry_mode_on(uint32_t base, struct map_info *map, | |||
71 | cfi_send_gen_cmd(0x98, 0x555, base, map, cfi, cfi->device_type, NULL); | 71 | cfi_send_gen_cmd(0x98, 0x555, base, map, cfi, cfi->device_type, NULL); |
72 | if (cfi_qry_present(map, base, cfi)) | 72 | if (cfi_qry_present(map, base, cfi)) |
73 | return 1; | 73 | return 1; |
74 | /* some old SST chips, e.g. 39VF160x/39VF320x */ | ||
75 | cfi_send_gen_cmd(0xF0, 0, base, map, cfi, cfi->device_type, NULL); | ||
76 | cfi_send_gen_cmd(0xAA, 0x5555, base, map, cfi, cfi->device_type, NULL); | ||
77 | cfi_send_gen_cmd(0x55, 0x2AAA, base, map, cfi, cfi->device_type, NULL); | ||
78 | cfi_send_gen_cmd(0x98, 0x5555, base, map, cfi, cfi->device_type, NULL); | ||
79 | if (cfi_qry_present(map, base, cfi)) | ||
80 | return 1; | ||
74 | /* QRY not found */ | 81 | /* QRY not found */ |
75 | return 0; | 82 | return 0; |
76 | } | 83 | } |
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c index 736a3be265f2..8db1148dfa47 100644 --- a/drivers/mtd/chips/jedec_probe.c +++ b/drivers/mtd/chips/jedec_probe.c | |||
@@ -142,8 +142,8 @@ | |||
142 | 142 | ||
143 | /* ST - www.st.com */ | 143 | /* ST - www.st.com */ |
144 | #define M29F800AB 0x0058 | 144 | #define M29F800AB 0x0058 |
145 | #define M29W800DT 0x00D7 | 145 | #define M29W800DT 0x22D7 |
146 | #define M29W800DB 0x005B | 146 | #define M29W800DB 0x225B |
147 | #define M29W400DT 0x00EE | 147 | #define M29W400DT 0x00EE |
148 | #define M29W400DB 0x00EF | 148 | #define M29W400DB 0x00EF |
149 | #define M29W160DT 0x22C4 | 149 | #define M29W160DT 0x22C4 |
@@ -226,7 +226,7 @@ struct unlock_addr { | |||
226 | * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore, | 226 | * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore, |
227 | * should not be used. The problem is that structures with | 227 | * should not be used. The problem is that structures with |
228 | * initializers have extra fields initialized to 0. It is _very_ | 228 | * initializers have extra fields initialized to 0. It is _very_ |
229 | * desireable to have the unlock address entries for unsupported | 229 | * desirable to have the unlock address entries for unsupported |
230 | * data widths automatically initialized - that means that | 230 | * data widths automatically initialized - that means that |
231 | * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here | 231 | * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here |
232 | * must go unused. | 232 | * must go unused. |
@@ -1575,7 +1575,7 @@ static const struct amd_flash_info jedec_table[] = { | |||
1575 | .dev_id = M29W800DT, | 1575 | .dev_id = M29W800DT, |
1576 | .name = "ST M29W800DT", | 1576 | .name = "ST M29W800DT", |
1577 | .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8, | 1577 | .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8, |
1578 | .uaddr = MTD_UADDR_0x5555_0x2AAA, /* ???? */ | 1578 | .uaddr = MTD_UADDR_0x0AAA_0x0555, |
1579 | .dev_size = SIZE_1MiB, | 1579 | .dev_size = SIZE_1MiB, |
1580 | .cmd_set = P_ID_AMD_STD, | 1580 | .cmd_set = P_ID_AMD_STD, |
1581 | .nr_regions = 4, | 1581 | .nr_regions = 4, |
@@ -1590,7 +1590,7 @@ static const struct amd_flash_info jedec_table[] = { | |||
1590 | .dev_id = M29W800DB, | 1590 | .dev_id = M29W800DB, |
1591 | .name = "ST M29W800DB", | 1591 | .name = "ST M29W800DB", |
1592 | .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8, | 1592 | .devtypes = CFI_DEVICETYPE_X16|CFI_DEVICETYPE_X8, |
1593 | .uaddr = MTD_UADDR_0x5555_0x2AAA, /* ???? */ | 1593 | .uaddr = MTD_UADDR_0x0AAA_0x0555, |
1594 | .dev_size = SIZE_1MiB, | 1594 | .dev_size = SIZE_1MiB, |
1595 | .cmd_set = P_ID_AMD_STD, | 1595 | .cmd_set = P_ID_AMD_STD, |
1596 | .nr_regions = 4, | 1596 | .nr_regions = 4, |
diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index c222514bb70d..35081ce77fbd 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/maps/Kconfig | ||
2 | |||
3 | menu "Self-contained MTD device drivers" | 1 | menu "Self-contained MTD device drivers" |
4 | depends on MTD!=n | 2 | depends on MTD!=n |
5 | 3 | ||
@@ -308,4 +306,3 @@ config MTD_DOCPROBE_55AA | |||
308 | you have managed to wipe the first block. | 306 | you have managed to wipe the first block. |
309 | 307 | ||
310 | endmenu | 308 | endmenu |
311 | |||
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index 8c295f40d2ac..ce6424008ed9 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/buffer_head.h> | 17 | #include <linux/buffer_head.h> |
18 | #include <linux/mutex.h> | 18 | #include <linux/mutex.h> |
19 | #include <linux/mount.h> | 19 | #include <linux/mount.h> |
20 | #include <linux/slab.h> | ||
20 | 21 | ||
21 | #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) | 22 | #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) |
22 | #define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args) | 23 | #define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args) |
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 4c19269de91a..81e49a9b017e 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c | |||
@@ -21,7 +21,9 @@ | |||
21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
22 | #include <linux/mutex.h> | 22 | #include <linux/mutex.h> |
23 | #include <linux/math64.h> | 23 | #include <linux/math64.h> |
24 | #include <linux/slab.h> | ||
24 | #include <linux/sched.h> | 25 | #include <linux/sched.h> |
26 | #include <linux/mod_devicetable.h> | ||
25 | 27 | ||
26 | #include <linux/mtd/mtd.h> | 28 | #include <linux/mtd/mtd.h> |
27 | #include <linux/mtd/partitions.h> | 29 | #include <linux/mtd/partitions.h> |
@@ -29,9 +31,6 @@ | |||
29 | #include <linux/spi/spi.h> | 31 | #include <linux/spi/spi.h> |
30 | #include <linux/spi/flash.h> | 32 | #include <linux/spi/flash.h> |
31 | 33 | ||
32 | |||
33 | #define FLASH_PAGESIZE 256 | ||
34 | |||
35 | /* Flash opcodes. */ | 34 | /* Flash opcodes. */ |
36 | #define OPCODE_WREN 0x06 /* Write enable */ | 35 | #define OPCODE_WREN 0x06 /* Write enable */ |
37 | #define OPCODE_RDSR 0x05 /* Read status register */ | 36 | #define OPCODE_RDSR 0x05 /* Read status register */ |
@@ -61,7 +60,7 @@ | |||
61 | 60 | ||
62 | /* Define max times to check status register before we give up. */ | 61 | /* Define max times to check status register before we give up. */ |
63 | #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ | 62 | #define MAX_READY_WAIT_JIFFIES (40 * HZ) /* M25P16 specs 40s max chip erase */ |
64 | #define CMD_SIZE 4 | 63 | #define MAX_CMD_SIZE 4 |
65 | 64 | ||
66 | #ifdef CONFIG_M25PXX_USE_FAST_READ | 65 | #ifdef CONFIG_M25PXX_USE_FAST_READ |
67 | #define OPCODE_READ OPCODE_FAST_READ | 66 | #define OPCODE_READ OPCODE_FAST_READ |
@@ -78,8 +77,10 @@ struct m25p { | |||
78 | struct mutex lock; | 77 | struct mutex lock; |
79 | struct mtd_info mtd; | 78 | struct mtd_info mtd; |
80 | unsigned partitioned:1; | 79 | unsigned partitioned:1; |
80 | u16 page_size; | ||
81 | u16 addr_width; | ||
81 | u8 erase_opcode; | 82 | u8 erase_opcode; |
82 | u8 command[CMD_SIZE + FAST_READ_DUMMY_BYTE]; | 83 | u8 *command; |
83 | }; | 84 | }; |
84 | 85 | ||
85 | static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) | 86 | static inline struct m25p *mtd_to_m25p(struct mtd_info *mtd) |
@@ -198,6 +199,19 @@ static int erase_chip(struct m25p *flash) | |||
198 | return 0; | 199 | return 0; |
199 | } | 200 | } |
200 | 201 | ||
202 | static void m25p_addr2cmd(struct m25p *flash, unsigned int addr, u8 *cmd) | ||
203 | { | ||
204 | /* opcode is in cmd[0] */ | ||
205 | cmd[1] = addr >> (flash->addr_width * 8 - 8); | ||
206 | cmd[2] = addr >> (flash->addr_width * 8 - 16); | ||
207 | cmd[3] = addr >> (flash->addr_width * 8 - 24); | ||
208 | } | ||
209 | |||
210 | static int m25p_cmdsz(struct m25p *flash) | ||
211 | { | ||
212 | return 1 + flash->addr_width; | ||
213 | } | ||
214 | |||
201 | /* | 215 | /* |
202 | * Erase one sector of flash memory at offset ``offset'' which is any | 216 | * Erase one sector of flash memory at offset ``offset'' which is any |
203 | * address within the sector which should be erased. | 217 | * address within the sector which should be erased. |
@@ -219,11 +233,9 @@ static int erase_sector(struct m25p *flash, u32 offset) | |||
219 | 233 | ||
220 | /* Set up command buffer. */ | 234 | /* Set up command buffer. */ |
221 | flash->command[0] = flash->erase_opcode; | 235 | flash->command[0] = flash->erase_opcode; |
222 | flash->command[1] = offset >> 16; | 236 | m25p_addr2cmd(flash, offset, flash->command); |
223 | flash->command[2] = offset >> 8; | ||
224 | flash->command[3] = offset; | ||
225 | 237 | ||
226 | spi_write(flash->spi, flash->command, CMD_SIZE); | 238 | spi_write(flash->spi, flash->command, m25p_cmdsz(flash)); |
227 | 239 | ||
228 | return 0; | 240 | return 0; |
229 | } | 241 | } |
@@ -325,7 +337,7 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
325 | * Should add 1 byte DUMMY_BYTE. | 337 | * Should add 1 byte DUMMY_BYTE. |
326 | */ | 338 | */ |
327 | t[0].tx_buf = flash->command; | 339 | t[0].tx_buf = flash->command; |
328 | t[0].len = CMD_SIZE + FAST_READ_DUMMY_BYTE; | 340 | t[0].len = m25p_cmdsz(flash) + FAST_READ_DUMMY_BYTE; |
329 | spi_message_add_tail(&t[0], &m); | 341 | spi_message_add_tail(&t[0], &m); |
330 | 342 | ||
331 | t[1].rx_buf = buf; | 343 | t[1].rx_buf = buf; |
@@ -352,13 +364,11 @@ static int m25p80_read(struct mtd_info *mtd, loff_t from, size_t len, | |||
352 | 364 | ||
353 | /* Set up the write data buffer. */ | 365 | /* Set up the write data buffer. */ |
354 | flash->command[0] = OPCODE_READ; | 366 | flash->command[0] = OPCODE_READ; |
355 | flash->command[1] = from >> 16; | 367 | m25p_addr2cmd(flash, from, flash->command); |
356 | flash->command[2] = from >> 8; | ||
357 | flash->command[3] = from; | ||
358 | 368 | ||
359 | spi_sync(flash->spi, &m); | 369 | spi_sync(flash->spi, &m); |
360 | 370 | ||
361 | *retlen = m.actual_length - CMD_SIZE - FAST_READ_DUMMY_BYTE; | 371 | *retlen = m.actual_length - m25p_cmdsz(flash) - FAST_READ_DUMMY_BYTE; |
362 | 372 | ||
363 | mutex_unlock(&flash->lock); | 373 | mutex_unlock(&flash->lock); |
364 | 374 | ||
@@ -396,7 +406,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
396 | memset(t, 0, (sizeof t)); | 406 | memset(t, 0, (sizeof t)); |
397 | 407 | ||
398 | t[0].tx_buf = flash->command; | 408 | t[0].tx_buf = flash->command; |
399 | t[0].len = CMD_SIZE; | 409 | t[0].len = m25p_cmdsz(flash); |
400 | spi_message_add_tail(&t[0], &m); | 410 | spi_message_add_tail(&t[0], &m); |
401 | 411 | ||
402 | t[1].tx_buf = buf; | 412 | t[1].tx_buf = buf; |
@@ -414,41 +424,36 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
414 | 424 | ||
415 | /* Set up the opcode in the write buffer. */ | 425 | /* Set up the opcode in the write buffer. */ |
416 | flash->command[0] = OPCODE_PP; | 426 | flash->command[0] = OPCODE_PP; |
417 | flash->command[1] = to >> 16; | 427 | m25p_addr2cmd(flash, to, flash->command); |
418 | flash->command[2] = to >> 8; | ||
419 | flash->command[3] = to; | ||
420 | 428 | ||
421 | /* what page do we start with? */ | 429 | page_offset = to & (flash->page_size - 1); |
422 | page_offset = to % FLASH_PAGESIZE; | ||
423 | 430 | ||
424 | /* do all the bytes fit onto one page? */ | 431 | /* do all the bytes fit onto one page? */ |
425 | if (page_offset + len <= FLASH_PAGESIZE) { | 432 | if (page_offset + len <= flash->page_size) { |
426 | t[1].len = len; | 433 | t[1].len = len; |
427 | 434 | ||
428 | spi_sync(flash->spi, &m); | 435 | spi_sync(flash->spi, &m); |
429 | 436 | ||
430 | *retlen = m.actual_length - CMD_SIZE; | 437 | *retlen = m.actual_length - m25p_cmdsz(flash); |
431 | } else { | 438 | } else { |
432 | u32 i; | 439 | u32 i; |
433 | 440 | ||
434 | /* the size of data remaining on the first page */ | 441 | /* the size of data remaining on the first page */ |
435 | page_size = FLASH_PAGESIZE - page_offset; | 442 | page_size = flash->page_size - page_offset; |
436 | 443 | ||
437 | t[1].len = page_size; | 444 | t[1].len = page_size; |
438 | spi_sync(flash->spi, &m); | 445 | spi_sync(flash->spi, &m); |
439 | 446 | ||
440 | *retlen = m.actual_length - CMD_SIZE; | 447 | *retlen = m.actual_length - m25p_cmdsz(flash); |
441 | 448 | ||
442 | /* write everything in PAGESIZE chunks */ | 449 | /* write everything in flash->page_size chunks */ |
443 | for (i = page_size; i < len; i += page_size) { | 450 | for (i = page_size; i < len; i += page_size) { |
444 | page_size = len - i; | 451 | page_size = len - i; |
445 | if (page_size > FLASH_PAGESIZE) | 452 | if (page_size > flash->page_size) |
446 | page_size = FLASH_PAGESIZE; | 453 | page_size = flash->page_size; |
447 | 454 | ||
448 | /* write the next page to flash */ | 455 | /* write the next page to flash */ |
449 | flash->command[1] = (to + i) >> 16; | 456 | m25p_addr2cmd(flash, to + i, flash->command); |
450 | flash->command[2] = (to + i) >> 8; | ||
451 | flash->command[3] = (to + i); | ||
452 | 457 | ||
453 | t[1].tx_buf = buf + i; | 458 | t[1].tx_buf = buf + i; |
454 | t[1].len = page_size; | 459 | t[1].len = page_size; |
@@ -460,7 +465,7 @@ static int m25p80_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
460 | spi_sync(flash->spi, &m); | 465 | spi_sync(flash->spi, &m); |
461 | 466 | ||
462 | if (retlen) | 467 | if (retlen) |
463 | *retlen += m.actual_length - CMD_SIZE; | 468 | *retlen += m.actual_length - m25p_cmdsz(flash); |
464 | } | 469 | } |
465 | } | 470 | } |
466 | 471 | ||
@@ -492,7 +497,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
492 | memset(t, 0, (sizeof t)); | 497 | memset(t, 0, (sizeof t)); |
493 | 498 | ||
494 | t[0].tx_buf = flash->command; | 499 | t[0].tx_buf = flash->command; |
495 | t[0].len = CMD_SIZE; | 500 | t[0].len = m25p_cmdsz(flash); |
496 | spi_message_add_tail(&t[0], &m); | 501 | spi_message_add_tail(&t[0], &m); |
497 | 502 | ||
498 | t[1].tx_buf = buf; | 503 | t[1].tx_buf = buf; |
@@ -511,9 +516,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
511 | /* Start write from odd address. */ | 516 | /* Start write from odd address. */ |
512 | if (actual) { | 517 | if (actual) { |
513 | flash->command[0] = OPCODE_BP; | 518 | flash->command[0] = OPCODE_BP; |
514 | flash->command[1] = to >> 16; | 519 | m25p_addr2cmd(flash, to, flash->command); |
515 | flash->command[2] = to >> 8; | ||
516 | flash->command[3] = to; | ||
517 | 520 | ||
518 | /* write one byte. */ | 521 | /* write one byte. */ |
519 | t[1].len = 1; | 522 | t[1].len = 1; |
@@ -521,17 +524,15 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
521 | ret = wait_till_ready(flash); | 524 | ret = wait_till_ready(flash); |
522 | if (ret) | 525 | if (ret) |
523 | goto time_out; | 526 | goto time_out; |
524 | *retlen += m.actual_length - CMD_SIZE; | 527 | *retlen += m.actual_length - m25p_cmdsz(flash); |
525 | } | 528 | } |
526 | to += actual; | 529 | to += actual; |
527 | 530 | ||
528 | flash->command[0] = OPCODE_AAI_WP; | 531 | flash->command[0] = OPCODE_AAI_WP; |
529 | flash->command[1] = to >> 16; | 532 | m25p_addr2cmd(flash, to, flash->command); |
530 | flash->command[2] = to >> 8; | ||
531 | flash->command[3] = to; | ||
532 | 533 | ||
533 | /* Write out most of the data here. */ | 534 | /* Write out most of the data here. */ |
534 | cmd_sz = CMD_SIZE; | 535 | cmd_sz = m25p_cmdsz(flash); |
535 | for (; actual < len - 1; actual += 2) { | 536 | for (; actual < len - 1; actual += 2) { |
536 | t[0].len = cmd_sz; | 537 | t[0].len = cmd_sz; |
537 | /* write two bytes. */ | 538 | /* write two bytes. */ |
@@ -555,10 +556,8 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
555 | if (actual != len) { | 556 | if (actual != len) { |
556 | write_enable(flash); | 557 | write_enable(flash); |
557 | flash->command[0] = OPCODE_BP; | 558 | flash->command[0] = OPCODE_BP; |
558 | flash->command[1] = to >> 16; | 559 | m25p_addr2cmd(flash, to, flash->command); |
559 | flash->command[2] = to >> 8; | 560 | t[0].len = m25p_cmdsz(flash); |
560 | flash->command[3] = to; | ||
561 | t[0].len = CMD_SIZE; | ||
562 | t[1].len = 1; | 561 | t[1].len = 1; |
563 | t[1].tx_buf = buf + actual; | 562 | t[1].tx_buf = buf + actual; |
564 | 563 | ||
@@ -566,7 +565,7 @@ static int sst_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
566 | ret = wait_till_ready(flash); | 565 | ret = wait_till_ready(flash); |
567 | if (ret) | 566 | if (ret) |
568 | goto time_out; | 567 | goto time_out; |
569 | *retlen += m.actual_length - CMD_SIZE; | 568 | *retlen += m.actual_length - m25p_cmdsz(flash); |
570 | write_disable(flash); | 569 | write_disable(flash); |
571 | } | 570 | } |
572 | 571 | ||
@@ -582,8 +581,6 @@ time_out: | |||
582 | */ | 581 | */ |
583 | 582 | ||
584 | struct flash_info { | 583 | struct flash_info { |
585 | char *name; | ||
586 | |||
587 | /* JEDEC id zero means "no ID" (most older chips); otherwise it has | 584 | /* JEDEC id zero means "no ID" (most older chips); otherwise it has |
588 | * a high byte of zero plus three data bytes: the manufacturer id, | 585 | * a high byte of zero plus three data bytes: the manufacturer id, |
589 | * then a two byte device id. | 586 | * then a two byte device id. |
@@ -597,87 +594,119 @@ struct flash_info { | |||
597 | unsigned sector_size; | 594 | unsigned sector_size; |
598 | u16 n_sectors; | 595 | u16 n_sectors; |
599 | 596 | ||
597 | u16 page_size; | ||
598 | u16 addr_width; | ||
599 | |||
600 | u16 flags; | 600 | u16 flags; |
601 | #define SECT_4K 0x01 /* OPCODE_BE_4K works uniformly */ | 601 | #define SECT_4K 0x01 /* OPCODE_BE_4K works uniformly */ |
602 | #define M25P_NO_ERASE 0x02 /* No erase command needed */ | ||
602 | }; | 603 | }; |
603 | 604 | ||
605 | #define INFO(_jedec_id, _ext_id, _sector_size, _n_sectors, _flags) \ | ||
606 | ((kernel_ulong_t)&(struct flash_info) { \ | ||
607 | .jedec_id = (_jedec_id), \ | ||
608 | .ext_id = (_ext_id), \ | ||
609 | .sector_size = (_sector_size), \ | ||
610 | .n_sectors = (_n_sectors), \ | ||
611 | .page_size = 256, \ | ||
612 | .addr_width = 3, \ | ||
613 | .flags = (_flags), \ | ||
614 | }) | ||
615 | |||
616 | #define CAT25_INFO(_sector_size, _n_sectors, _page_size, _addr_width) \ | ||
617 | ((kernel_ulong_t)&(struct flash_info) { \ | ||
618 | .sector_size = (_sector_size), \ | ||
619 | .n_sectors = (_n_sectors), \ | ||
620 | .page_size = (_page_size), \ | ||
621 | .addr_width = (_addr_width), \ | ||
622 | .flags = M25P_NO_ERASE, \ | ||
623 | }) | ||
604 | 624 | ||
605 | /* NOTE: double check command sets and memory organization when you add | 625 | /* NOTE: double check command sets and memory organization when you add |
606 | * more flash chips. This current list focusses on newer chips, which | 626 | * more flash chips. This current list focusses on newer chips, which |
607 | * have been converging on command sets which including JEDEC ID. | 627 | * have been converging on command sets which including JEDEC ID. |
608 | */ | 628 | */ |
609 | static struct flash_info __devinitdata m25p_data [] = { | 629 | static const struct spi_device_id m25p_ids[] = { |
610 | |||
611 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ | 630 | /* Atmel -- some are (confusingly) marketed as "DataFlash" */ |
612 | { "at25fs010", 0x1f6601, 0, 32 * 1024, 4, SECT_4K, }, | 631 | { "at25fs010", INFO(0x1f6601, 0, 32 * 1024, 4, SECT_4K) }, |
613 | { "at25fs040", 0x1f6604, 0, 64 * 1024, 8, SECT_4K, }, | 632 | { "at25fs040", INFO(0x1f6604, 0, 64 * 1024, 8, SECT_4K) }, |
614 | 633 | ||
615 | { "at25df041a", 0x1f4401, 0, 64 * 1024, 8, SECT_4K, }, | 634 | { "at25df041a", INFO(0x1f4401, 0, 64 * 1024, 8, SECT_4K) }, |
616 | { "at25df641", 0x1f4800, 0, 64 * 1024, 128, SECT_4K, }, | 635 | { "at25df641", INFO(0x1f4800, 0, 64 * 1024, 128, SECT_4K) }, |
617 | 636 | ||
618 | { "at26f004", 0x1f0400, 0, 64 * 1024, 8, SECT_4K, }, | 637 | { "at26f004", INFO(0x1f0400, 0, 64 * 1024, 8, SECT_4K) }, |
619 | { "at26df081a", 0x1f4501, 0, 64 * 1024, 16, SECT_4K, }, | 638 | { "at26df081a", INFO(0x1f4501, 0, 64 * 1024, 16, SECT_4K) }, |
620 | { "at26df161a", 0x1f4601, 0, 64 * 1024, 32, SECT_4K, }, | 639 | { "at26df161a", INFO(0x1f4601, 0, 64 * 1024, 32, SECT_4K) }, |
621 | { "at26df321", 0x1f4701, 0, 64 * 1024, 64, SECT_4K, }, | 640 | { "at26df321", INFO(0x1f4701, 0, 64 * 1024, 64, SECT_4K) }, |
622 | 641 | ||
623 | /* Macronix */ | 642 | /* Macronix */ |
624 | { "mx25l3205d", 0xc22016, 0, 64 * 1024, 64, }, | 643 | { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, |
625 | { "mx25l6405d", 0xc22017, 0, 64 * 1024, 128, }, | 644 | { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) }, |
626 | { "mx25l12805d", 0xc22018, 0, 64 * 1024, 256, }, | 645 | { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) }, |
627 | { "mx25l12855e", 0xc22618, 0, 64 * 1024, 256, }, | 646 | { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, |
647 | { "mx25l12855e", INFO(0xc22618, 0, 64 * 1024, 256, 0) }, | ||
628 | 648 | ||
629 | /* Spansion -- single (large) sector size only, at least | 649 | /* Spansion -- single (large) sector size only, at least |
630 | * for the chips listed here (without boot sectors). | 650 | * for the chips listed here (without boot sectors). |
631 | */ | 651 | */ |
632 | { "s25sl004a", 0x010212, 0, 64 * 1024, 8, }, | 652 | { "s25sl004a", INFO(0x010212, 0, 64 * 1024, 8, 0) }, |
633 | { "s25sl008a", 0x010213, 0, 64 * 1024, 16, }, | 653 | { "s25sl008a", INFO(0x010213, 0, 64 * 1024, 16, 0) }, |
634 | { "s25sl016a", 0x010214, 0, 64 * 1024, 32, }, | 654 | { "s25sl016a", INFO(0x010214, 0, 64 * 1024, 32, 0) }, |
635 | { "s25sl032a", 0x010215, 0, 64 * 1024, 64, }, | 655 | { "s25sl032a", INFO(0x010215, 0, 64 * 1024, 64, 0) }, |
636 | { "s25sl064a", 0x010216, 0, 64 * 1024, 128, }, | 656 | { "s25sl064a", INFO(0x010216, 0, 64 * 1024, 128, 0) }, |
637 | { "s25sl12800", 0x012018, 0x0300, 256 * 1024, 64, }, | 657 | { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, |
638 | { "s25sl12801", 0x012018, 0x0301, 64 * 1024, 256, }, | 658 | { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, |
639 | { "s25fl129p0", 0x012018, 0x4d00, 256 * 1024, 64, }, | 659 | { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, 0) }, |
640 | { "s25fl129p1", 0x012018, 0x4d01, 64 * 1024, 256, }, | 660 | { "s25fl129p1", INFO(0x012018, 0x4d01, 64 * 1024, 256, 0) }, |
641 | 661 | ||
642 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ | 662 | /* SST -- large erase sizes are "overlays", "sectors" are 4K */ |
643 | { "sst25vf040b", 0xbf258d, 0, 64 * 1024, 8, SECT_4K, }, | 663 | { "sst25vf040b", INFO(0xbf258d, 0, 64 * 1024, 8, SECT_4K) }, |
644 | { "sst25vf080b", 0xbf258e, 0, 64 * 1024, 16, SECT_4K, }, | 664 | { "sst25vf080b", INFO(0xbf258e, 0, 64 * 1024, 16, SECT_4K) }, |
645 | { "sst25vf016b", 0xbf2541, 0, 64 * 1024, 32, SECT_4K, }, | 665 | { "sst25vf016b", INFO(0xbf2541, 0, 64 * 1024, 32, SECT_4K) }, |
646 | { "sst25vf032b", 0xbf254a, 0, 64 * 1024, 64, SECT_4K, }, | 666 | { "sst25vf032b", INFO(0xbf254a, 0, 64 * 1024, 64, SECT_4K) }, |
647 | { "sst25wf512", 0xbf2501, 0, 64 * 1024, 1, SECT_4K, }, | 667 | { "sst25wf512", INFO(0xbf2501, 0, 64 * 1024, 1, SECT_4K) }, |
648 | { "sst25wf010", 0xbf2502, 0, 64 * 1024, 2, SECT_4K, }, | 668 | { "sst25wf010", INFO(0xbf2502, 0, 64 * 1024, 2, SECT_4K) }, |
649 | { "sst25wf020", 0xbf2503, 0, 64 * 1024, 4, SECT_4K, }, | 669 | { "sst25wf020", INFO(0xbf2503, 0, 64 * 1024, 4, SECT_4K) }, |
650 | { "sst25wf040", 0xbf2504, 0, 64 * 1024, 8, SECT_4K, }, | 670 | { "sst25wf040", INFO(0xbf2504, 0, 64 * 1024, 8, SECT_4K) }, |
651 | 671 | ||
652 | /* ST Microelectronics -- newer production may have feature updates */ | 672 | /* ST Microelectronics -- newer production may have feature updates */ |
653 | { "m25p05", 0x202010, 0, 32 * 1024, 2, }, | 673 | { "m25p05", INFO(0x202010, 0, 32 * 1024, 2, 0) }, |
654 | { "m25p10", 0x202011, 0, 32 * 1024, 4, }, | 674 | { "m25p10", INFO(0x202011, 0, 32 * 1024, 4, 0) }, |
655 | { "m25p20", 0x202012, 0, 64 * 1024, 4, }, | 675 | { "m25p20", INFO(0x202012, 0, 64 * 1024, 4, 0) }, |
656 | { "m25p40", 0x202013, 0, 64 * 1024, 8, }, | 676 | { "m25p40", INFO(0x202013, 0, 64 * 1024, 8, 0) }, |
657 | { "m25p80", 0, 0, 64 * 1024, 16, }, | 677 | { "m25p80", INFO(0x202014, 0, 64 * 1024, 16, 0) }, |
658 | { "m25p16", 0x202015, 0, 64 * 1024, 32, }, | 678 | { "m25p16", INFO(0x202015, 0, 64 * 1024, 32, 0) }, |
659 | { "m25p32", 0x202016, 0, 64 * 1024, 64, }, | 679 | { "m25p32", INFO(0x202016, 0, 64 * 1024, 64, 0) }, |
660 | { "m25p64", 0x202017, 0, 64 * 1024, 128, }, | 680 | { "m25p64", INFO(0x202017, 0, 64 * 1024, 128, 0) }, |
661 | { "m25p128", 0x202018, 0, 256 * 1024, 64, }, | 681 | { "m25p128", INFO(0x202018, 0, 256 * 1024, 64, 0) }, |
662 | 682 | ||
663 | { "m45pe10", 0x204011, 0, 64 * 1024, 2, }, | 683 | { "m45pe10", INFO(0x204011, 0, 64 * 1024, 2, 0) }, |
664 | { "m45pe80", 0x204014, 0, 64 * 1024, 16, }, | 684 | { "m45pe80", INFO(0x204014, 0, 64 * 1024, 16, 0) }, |
665 | { "m45pe16", 0x204015, 0, 64 * 1024, 32, }, | 685 | { "m45pe16", INFO(0x204015, 0, 64 * 1024, 32, 0) }, |
666 | 686 | ||
667 | { "m25pe80", 0x208014, 0, 64 * 1024, 16, }, | 687 | { "m25pe80", INFO(0x208014, 0, 64 * 1024, 16, 0) }, |
668 | { "m25pe16", 0x208015, 0, 64 * 1024, 32, SECT_4K, }, | 688 | { "m25pe16", INFO(0x208015, 0, 64 * 1024, 32, SECT_4K) }, |
669 | 689 | ||
670 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ | 690 | /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ |
671 | { "w25x10", 0xef3011, 0, 64 * 1024, 2, SECT_4K, }, | 691 | { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) }, |
672 | { "w25x20", 0xef3012, 0, 64 * 1024, 4, SECT_4K, }, | 692 | { "w25x20", INFO(0xef3012, 0, 64 * 1024, 4, SECT_4K) }, |
673 | { "w25x40", 0xef3013, 0, 64 * 1024, 8, SECT_4K, }, | 693 | { "w25x40", INFO(0xef3013, 0, 64 * 1024, 8, SECT_4K) }, |
674 | { "w25x80", 0xef3014, 0, 64 * 1024, 16, SECT_4K, }, | 694 | { "w25x80", INFO(0xef3014, 0, 64 * 1024, 16, SECT_4K) }, |
675 | { "w25x16", 0xef3015, 0, 64 * 1024, 32, SECT_4K, }, | 695 | { "w25x16", INFO(0xef3015, 0, 64 * 1024, 32, SECT_4K) }, |
676 | { "w25x32", 0xef3016, 0, 64 * 1024, 64, SECT_4K, }, | 696 | { "w25x32", INFO(0xef3016, 0, 64 * 1024, 64, SECT_4K) }, |
677 | { "w25x64", 0xef3017, 0, 64 * 1024, 128, SECT_4K, }, | 697 | { "w25x64", INFO(0xef3017, 0, 64 * 1024, 128, SECT_4K) }, |
698 | |||
699 | /* Catalyst / On Semiconductor -- non-JEDEC */ | ||
700 | { "cat25c11", CAT25_INFO( 16, 8, 16, 1) }, | ||
701 | { "cat25c03", CAT25_INFO( 32, 8, 16, 2) }, | ||
702 | { "cat25c09", CAT25_INFO( 128, 8, 32, 2) }, | ||
703 | { "cat25c17", CAT25_INFO( 256, 8, 32, 2) }, | ||
704 | { "cat25128", CAT25_INFO(2048, 8, 64, 2) }, | ||
705 | { }, | ||
678 | }; | 706 | }; |
707 | MODULE_DEVICE_TABLE(spi, m25p_ids); | ||
679 | 708 | ||
680 | static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | 709 | static const struct spi_device_id *__devinit jedec_probe(struct spi_device *spi) |
681 | { | 710 | { |
682 | int tmp; | 711 | int tmp; |
683 | u8 code = OPCODE_RDID; | 712 | u8 code = OPCODE_RDID; |
@@ -702,18 +731,24 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | |||
702 | jedec = jedec << 8; | 731 | jedec = jedec << 8; |
703 | jedec |= id[2]; | 732 | jedec |= id[2]; |
704 | 733 | ||
734 | /* | ||
735 | * Some chips (like Numonyx M25P80) have JEDEC and non-JEDEC variants, | ||
736 | * which depend on technology process. Officially RDID command doesn't | ||
737 | * exist for non-JEDEC chips, but for compatibility they return ID 0. | ||
738 | */ | ||
739 | if (jedec == 0) | ||
740 | return NULL; | ||
741 | |||
705 | ext_jedec = id[3] << 8 | id[4]; | 742 | ext_jedec = id[3] << 8 | id[4]; |
706 | 743 | ||
707 | for (tmp = 0, info = m25p_data; | 744 | for (tmp = 0; tmp < ARRAY_SIZE(m25p_ids) - 1; tmp++) { |
708 | tmp < ARRAY_SIZE(m25p_data); | 745 | info = (void *)m25p_ids[tmp].driver_data; |
709 | tmp++, info++) { | ||
710 | if (info->jedec_id == jedec) { | 746 | if (info->jedec_id == jedec) { |
711 | if (info->ext_id != 0 && info->ext_id != ext_jedec) | 747 | if (info->ext_id != 0 && info->ext_id != ext_jedec) |
712 | continue; | 748 | continue; |
713 | return info; | 749 | return &m25p_ids[tmp]; |
714 | } | 750 | } |
715 | } | 751 | } |
716 | dev_err(&spi->dev, "unrecognized JEDEC id %06x\n", jedec); | ||
717 | return NULL; | 752 | return NULL; |
718 | } | 753 | } |
719 | 754 | ||
@@ -725,6 +760,7 @@ static struct flash_info *__devinit jedec_probe(struct spi_device *spi) | |||
725 | */ | 760 | */ |
726 | static int __devinit m25p_probe(struct spi_device *spi) | 761 | static int __devinit m25p_probe(struct spi_device *spi) |
727 | { | 762 | { |
763 | const struct spi_device_id *id = spi_get_device_id(spi); | ||
728 | struct flash_platform_data *data; | 764 | struct flash_platform_data *data; |
729 | struct m25p *flash; | 765 | struct m25p *flash; |
730 | struct flash_info *info; | 766 | struct flash_info *info; |
@@ -737,50 +773,65 @@ static int __devinit m25p_probe(struct spi_device *spi) | |||
737 | */ | 773 | */ |
738 | data = spi->dev.platform_data; | 774 | data = spi->dev.platform_data; |
739 | if (data && data->type) { | 775 | if (data && data->type) { |
740 | for (i = 0, info = m25p_data; | 776 | const struct spi_device_id *plat_id; |
741 | i < ARRAY_SIZE(m25p_data); | ||
742 | i++, info++) { | ||
743 | if (strcmp(data->type, info->name) == 0) | ||
744 | break; | ||
745 | } | ||
746 | 777 | ||
747 | /* unrecognized chip? */ | 778 | for (i = 0; i < ARRAY_SIZE(m25p_ids) - 1; i++) { |
748 | if (i == ARRAY_SIZE(m25p_data)) { | 779 | plat_id = &m25p_ids[i]; |
749 | DEBUG(MTD_DEBUG_LEVEL0, "%s: unrecognized id %s\n", | 780 | if (strcmp(data->type, plat_id->name)) |
750 | dev_name(&spi->dev), data->type); | 781 | continue; |
751 | info = NULL; | 782 | break; |
752 | |||
753 | /* recognized; is that chip really what's there? */ | ||
754 | } else if (info->jedec_id) { | ||
755 | struct flash_info *chip = jedec_probe(spi); | ||
756 | |||
757 | if (!chip || chip != info) { | ||
758 | dev_warn(&spi->dev, "found %s, expected %s\n", | ||
759 | chip ? chip->name : "UNKNOWN", | ||
760 | info->name); | ||
761 | info = NULL; | ||
762 | } | ||
763 | } | 783 | } |
764 | } else | ||
765 | info = jedec_probe(spi); | ||
766 | 784 | ||
767 | if (!info) | 785 | if (plat_id) |
768 | return -ENODEV; | 786 | id = plat_id; |
787 | else | ||
788 | dev_warn(&spi->dev, "unrecognized id %s\n", data->type); | ||
789 | } | ||
790 | |||
791 | info = (void *)id->driver_data; | ||
792 | |||
793 | if (info->jedec_id) { | ||
794 | const struct spi_device_id *jid; | ||
795 | |||
796 | jid = jedec_probe(spi); | ||
797 | if (!jid) { | ||
798 | dev_info(&spi->dev, "non-JEDEC variant of %s\n", | ||
799 | id->name); | ||
800 | } else if (jid != id) { | ||
801 | /* | ||
802 | * JEDEC knows better, so overwrite platform ID. We | ||
803 | * can't trust partitions any longer, but we'll let | ||
804 | * mtd apply them anyway, since some partitions may be | ||
805 | * marked read-only, and we don't want to lose that | ||
806 | * information, even if it's not 100% accurate. | ||
807 | */ | ||
808 | dev_warn(&spi->dev, "found %s, expected %s\n", | ||
809 | jid->name, id->name); | ||
810 | id = jid; | ||
811 | info = (void *)jid->driver_data; | ||
812 | } | ||
813 | } | ||
769 | 814 | ||
770 | flash = kzalloc(sizeof *flash, GFP_KERNEL); | 815 | flash = kzalloc(sizeof *flash, GFP_KERNEL); |
771 | if (!flash) | 816 | if (!flash) |
772 | return -ENOMEM; | 817 | return -ENOMEM; |
818 | flash->command = kmalloc(MAX_CMD_SIZE + FAST_READ_DUMMY_BYTE, GFP_KERNEL); | ||
819 | if (!flash->command) { | ||
820 | kfree(flash); | ||
821 | return -ENOMEM; | ||
822 | } | ||
773 | 823 | ||
774 | flash->spi = spi; | 824 | flash->spi = spi; |
775 | mutex_init(&flash->lock); | 825 | mutex_init(&flash->lock); |
776 | dev_set_drvdata(&spi->dev, flash); | 826 | dev_set_drvdata(&spi->dev, flash); |
777 | 827 | ||
778 | /* | 828 | /* |
779 | * Atmel serial flash tend to power up | 829 | * Atmel and SST serial flash tend to power |
780 | * with the software protection bits set | 830 | * up with the software protection bits set |
781 | */ | 831 | */ |
782 | 832 | ||
783 | if (info->jedec_id >> 16 == 0x1f) { | 833 | if (info->jedec_id >> 16 == 0x1f || |
834 | info->jedec_id >> 16 == 0xbf) { | ||
784 | write_enable(flash); | 835 | write_enable(flash); |
785 | write_sr(flash, 0); | 836 | write_sr(flash, 0); |
786 | } | 837 | } |
@@ -812,9 +863,14 @@ static int __devinit m25p_probe(struct spi_device *spi) | |||
812 | flash->mtd.erasesize = info->sector_size; | 863 | flash->mtd.erasesize = info->sector_size; |
813 | } | 864 | } |
814 | 865 | ||
866 | if (info->flags & M25P_NO_ERASE) | ||
867 | flash->mtd.flags |= MTD_NO_ERASE; | ||
868 | |||
815 | flash->mtd.dev.parent = &spi->dev; | 869 | flash->mtd.dev.parent = &spi->dev; |
870 | flash->page_size = info->page_size; | ||
871 | flash->addr_width = info->addr_width; | ||
816 | 872 | ||
817 | dev_info(&spi->dev, "%s (%lld Kbytes)\n", info->name, | 873 | dev_info(&spi->dev, "%s (%lld Kbytes)\n", id->name, |
818 | (long long)flash->mtd.size >> 10); | 874 | (long long)flash->mtd.size >> 10); |
819 | 875 | ||
820 | DEBUG(MTD_DEBUG_LEVEL2, | 876 | DEBUG(MTD_DEBUG_LEVEL2, |
@@ -888,8 +944,10 @@ static int __devexit m25p_remove(struct spi_device *spi) | |||
888 | status = del_mtd_partitions(&flash->mtd); | 944 | status = del_mtd_partitions(&flash->mtd); |
889 | else | 945 | else |
890 | status = del_mtd_device(&flash->mtd); | 946 | status = del_mtd_device(&flash->mtd); |
891 | if (status == 0) | 947 | if (status == 0) { |
948 | kfree(flash->command); | ||
892 | kfree(flash); | 949 | kfree(flash); |
950 | } | ||
893 | return 0; | 951 | return 0; |
894 | } | 952 | } |
895 | 953 | ||
@@ -900,6 +958,7 @@ static struct spi_driver m25p80_driver = { | |||
900 | .bus = &spi_bus_type, | 958 | .bus = &spi_bus_type, |
901 | .owner = THIS_MODULE, | 959 | .owner = THIS_MODULE, |
902 | }, | 960 | }, |
961 | .id_table = m25p_ids, | ||
903 | .probe = m25p_probe, | 962 | .probe = m25p_probe, |
904 | .remove = __devexit_p(m25p_remove), | 963 | .remove = __devexit_p(m25p_remove), |
905 | 964 | ||
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c index 93e3627be74c..19817404ce7d 100644 --- a/drivers/mtd/devices/mtd_dataflash.c +++ b/drivers/mtd/devices/mtd_dataflash.c | |||
@@ -636,6 +636,7 @@ add_dataflash_otp(struct spi_device *spi, char *name, | |||
636 | struct mtd_info *device; | 636 | struct mtd_info *device; |
637 | struct flash_platform_data *pdata = spi->dev.platform_data; | 637 | struct flash_platform_data *pdata = spi->dev.platform_data; |
638 | char *otp_tag = ""; | 638 | char *otp_tag = ""; |
639 | int err = 0; | ||
639 | 640 | ||
640 | priv = kzalloc(sizeof *priv, GFP_KERNEL); | 641 | priv = kzalloc(sizeof *priv, GFP_KERNEL); |
641 | if (!priv) | 642 | if (!priv) |
@@ -693,13 +694,23 @@ add_dataflash_otp(struct spi_device *spi, char *name, | |||
693 | 694 | ||
694 | if (nr_parts > 0) { | 695 | if (nr_parts > 0) { |
695 | priv->partitioned = 1; | 696 | priv->partitioned = 1; |
696 | return add_mtd_partitions(device, parts, nr_parts); | 697 | err = add_mtd_partitions(device, parts, nr_parts); |
698 | goto out; | ||
697 | } | 699 | } |
698 | } else if (pdata && pdata->nr_parts) | 700 | } else if (pdata && pdata->nr_parts) |
699 | dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", | 701 | dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", |
700 | pdata->nr_parts, device->name); | 702 | pdata->nr_parts, device->name); |
701 | 703 | ||
702 | return add_mtd_device(device) == 1 ? -ENODEV : 0; | 704 | if (add_mtd_device(device) == 1) |
705 | err = -ENODEV; | ||
706 | |||
707 | out: | ||
708 | if (!err) | ||
709 | return 0; | ||
710 | |||
711 | dev_set_drvdata(&spi->dev, NULL); | ||
712 | kfree(priv); | ||
713 | return err; | ||
703 | } | 714 | } |
704 | 715 | ||
705 | static inline int __devinit | 716 | static inline int __devinit |
@@ -932,8 +943,10 @@ static int __devexit dataflash_remove(struct spi_device *spi) | |||
932 | status = del_mtd_partitions(&flash->mtd); | 943 | status = del_mtd_partitions(&flash->mtd); |
933 | else | 944 | else |
934 | status = del_mtd_device(&flash->mtd); | 945 | status = del_mtd_device(&flash->mtd); |
935 | if (status == 0) | 946 | if (status == 0) { |
947 | dev_set_drvdata(&spi->dev, NULL); | ||
936 | kfree(flash); | 948 | kfree(flash); |
949 | } | ||
937 | return status; | 950 | return status; |
938 | } | 951 | } |
939 | 952 | ||
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c index 3aa05cd18ea1..592016a0668f 100644 --- a/drivers/mtd/devices/slram.c +++ b/drivers/mtd/devices/slram.c | |||
@@ -18,7 +18,7 @@ | |||
18 | to specify the offset instead of the absolute address | 18 | to specify the offset instead of the absolute address |
19 | 19 | ||
20 | NOTE: | 20 | NOTE: |
21 | With slram it's only possible to map a contigous memory region. Therfore | 21 | With slram it's only possible to map a contiguous memory region. Therefore |
22 | if there's a device mapped somewhere in the region specified slram will | 22 | if there's a device mapped somewhere in the region specified slram will |
23 | fail to load (see kernel log if modprobe fails). | 23 | fail to load (see kernel log if modprobe fails). |
24 | 24 | ||
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c index 0a11721f146e..fe17054ee2fe 100644 --- a/drivers/mtd/devices/sst25l.c +++ b/drivers/mtd/devices/sst25l.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/device.h> | 20 | #include <linux/device.h> |
21 | #include <linux/mutex.h> | 21 | #include <linux/mutex.h> |
22 | #include <linux/interrupt.h> | 22 | #include <linux/interrupt.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/sched.h> | 24 | #include <linux/sched.h> |
24 | 25 | ||
25 | #include <linux/mtd/mtd.h> | 26 | #include <linux/mtd/mtd.h> |
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index 8aca5523a337..8aca5523a337 100755..100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c | |||
diff --git a/drivers/mtd/internal.h b/drivers/mtd/internal.h deleted file mode 100644 index c658fe7216b5..000000000000 --- a/drivers/mtd/internal.h +++ /dev/null | |||
@@ -1,17 +0,0 @@ | |||
1 | /* Internal MTD definitions | ||
2 | * | ||
3 | * Copyright © 2006 Red Hat, Inc. All Rights Reserved. | ||
4 | * Written by David Howells (dhowells@redhat.com) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | /* | ||
13 | * mtdbdi.c | ||
14 | */ | ||
15 | extern struct backing_dev_info mtd_bdi_unmappable; | ||
16 | extern struct backing_dev_info mtd_bdi_ro_mappable; | ||
17 | extern struct backing_dev_info mtd_bdi_rw_mappable; | ||
diff --git a/drivers/mtd/lpddr/Kconfig b/drivers/mtd/lpddr/Kconfig index 5a401d8047ab..265f969817e3 100644 --- a/drivers/mtd/lpddr/Kconfig +++ b/drivers/mtd/lpddr/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/chips/Kconfig | ||
2 | |||
3 | menu "LPDDR flash memory drivers" | 1 | menu "LPDDR flash memory drivers" |
4 | depends on MTD!=n | 2 | depends on MTD!=n |
5 | 3 | ||
@@ -20,4 +18,3 @@ config MTD_QINFO_PROBE | |||
20 | families of devices. This serves similar purpose of CFI on legacy | 18 | families of devices. This serves similar purpose of CFI on legacy |
21 | Flash products | 19 | Flash products |
22 | endmenu | 20 | endmenu |
23 | |||
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c index e22ca49583e7..a73ee12aad81 100644 --- a/drivers/mtd/lpddr/lpddr_cmds.c +++ b/drivers/mtd/lpddr/lpddr_cmds.c | |||
@@ -26,6 +26,7 @@ | |||
26 | */ | 26 | */ |
27 | #include <linux/mtd/pfow.h> | 27 | #include <linux/mtd/pfow.h> |
28 | #include <linux/mtd/qinfo.h> | 28 | #include <linux/mtd/qinfo.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len, | 31 | static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len, |
31 | size_t *retlen, u_char *buf); | 32 | size_t *retlen, u_char *buf); |
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index 14be0755d7cd..aa2807d0ce72 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/maps/Kconfig | ||
2 | |||
3 | menu "Mapping drivers for chip access" | 1 | menu "Mapping drivers for chip access" |
4 | depends on MTD!=n | 2 | depends on MTD!=n |
5 | 3 | ||
@@ -253,12 +251,6 @@ config MTD_NETtel | |||
253 | help | 251 | help |
254 | Support for flash chips on NETtel/SecureEdge/SnapGear boards. | 252 | Support for flash chips on NETtel/SecureEdge/SnapGear boards. |
255 | 253 | ||
256 | config MTD_ALCHEMY | ||
257 | tristate "AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support" | ||
258 | depends on SOC_AU1X00 && MTD_PARTITIONS && MTD_CFI | ||
259 | help | ||
260 | Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards | ||
261 | |||
262 | config MTD_DILNETPC | 254 | config MTD_DILNETPC |
263 | tristate "CFI Flash device mapped on DIL/Net PC" | 255 | tristate "CFI Flash device mapped on DIL/Net PC" |
264 | depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN | 256 | depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN |
@@ -361,12 +353,6 @@ config MTD_SA1100 | |||
361 | the SA1100 and SA1110, including the Assabet and the Compaq iPAQ. | 353 | the SA1100 and SA1110, including the Assabet and the Compaq iPAQ. |
362 | If you have such a board, say 'Y'. | 354 | If you have such a board, say 'Y'. |
363 | 355 | ||
364 | config MTD_IPAQ | ||
365 | tristate "CFI Flash device mapped on Compaq/HP iPAQ" | ||
366 | depends on IPAQ_HANDHELD && MTD_CFI | ||
367 | help | ||
368 | This provides a driver for the on-board flash of the iPAQ. | ||
369 | |||
370 | config MTD_DC21285 | 356 | config MTD_DC21285 |
371 | tristate "CFI Flash device mapped on DC21285 Footbridge" | 357 | tristate "CFI Flash device mapped on DC21285 Footbridge" |
372 | depends on MTD_CFI && ARCH_FOOTBRIDGE && MTD_COMPLEX_MAPPINGS | 358 | depends on MTD_CFI && ARCH_FOOTBRIDGE && MTD_COMPLEX_MAPPINGS |
@@ -389,9 +375,9 @@ config MTD_IXP2000 | |||
389 | depends on MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP2000 | 375 | depends on MTD_CFI && MTD_COMPLEX_MAPPINGS && ARCH_IXP2000 |
390 | help | 376 | help |
391 | This enables MTD access to flash devices on platforms based | 377 | This enables MTD access to flash devices on platforms based |
392 | on Intel's IXP2000 family of network processors such as the | 378 | on Intel's IXP2000 family of network processors. If you have an |
393 | IXDP425 and Coyote. If you have an IXP2000 based board and | 379 | IXP2000 based board and would like to use the flash chips on it, |
394 | would like to use the flash chips on it, say 'Y'. | 380 | say 'Y'. |
395 | 381 | ||
396 | config MTD_FORTUNET | 382 | config MTD_FORTUNET |
397 | tristate "CFI Flash device mapped on the FortuNet board" | 383 | tristate "CFI Flash device mapped on the FortuNet board" |
@@ -436,15 +422,6 @@ config MTD_H720X | |||
436 | This enables access to the flash chips on the Hynix evaluation boards. | 422 | This enables access to the flash chips on the Hynix evaluation boards. |
437 | If you have such a board, say 'Y'. | 423 | If you have such a board, say 'Y'. |
438 | 424 | ||
439 | config MTD_OMAP_NOR | ||
440 | tristate "TI OMAP board mappings" | ||
441 | depends on MTD_CFI && ARCH_OMAP | ||
442 | help | ||
443 | This enables access to the NOR flash chips on TI OMAP-based | ||
444 | boards defining flash platform devices and flash platform data. | ||
445 | These boards include the Innovator, H2, H3, OSK, Perseus2, and | ||
446 | more. If you have such a board, say 'Y'. | ||
447 | |||
448 | # This needs CFI or JEDEC, depending on the cards found. | 425 | # This needs CFI or JEDEC, depending on the cards found. |
449 | config MTD_PCI | 426 | config MTD_PCI |
450 | tristate "PCI MTD driver" | 427 | tristate "PCI MTD driver" |
@@ -557,4 +534,21 @@ config MTD_VMU | |||
557 | To build this as a module select M here, the module will be called | 534 | To build this as a module select M here, the module will be called |
558 | vmu-flash. | 535 | vmu-flash. |
559 | 536 | ||
537 | config MTD_PISMO | ||
538 | tristate "MTD discovery driver for PISMO modules" | ||
539 | depends on I2C | ||
540 | depends on ARCH_VERSATILE | ||
541 | help | ||
542 | This driver allows for discovery of PISMO modules - see | ||
543 | <http://www.pismoworld.org/>. These are small modules containing | ||
544 | up to five memory devices (eg, SRAM, flash, DOC) described by an | ||
545 | I2C EEPROM. | ||
546 | |||
547 | This driver does not create any MTD maps itself; instead it | ||
548 | creates MTD physmap and MTD SRAM platform devices. If you | ||
549 | enable this option, you should consider enabling MTD_PHYSMAP | ||
550 | and/or MTD_PLATRAM according to the devices on your module. | ||
551 | |||
552 | When built as a module, it will be called pismo.ko | ||
553 | |||
560 | endmenu | 554 | endmenu |
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index ae2f6dbe43c3..bb035cd54c72 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile | |||
@@ -24,12 +24,12 @@ obj-$(CONFIG_MTD_CEIVA) += ceiva.o | |||
24 | obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o | 24 | obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o |
25 | obj-$(CONFIG_MTD_PHYSMAP) += physmap.o | 25 | obj-$(CONFIG_MTD_PHYSMAP) += physmap.o |
26 | obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o | 26 | obj-$(CONFIG_MTD_PHYSMAP_OF) += physmap_of.o |
27 | obj-$(CONFIG_MTD_PISMO) += pismo.o | ||
27 | obj-$(CONFIG_MTD_PMC_MSP_EVM) += pmcmsp-flash.o | 28 | obj-$(CONFIG_MTD_PMC_MSP_EVM) += pmcmsp-flash.o |
28 | obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o | 29 | obj-$(CONFIG_MTD_PCMCIA) += pcmciamtd.o |
29 | obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o | 30 | obj-$(CONFIG_MTD_RPXLITE) += rpxlite.o |
30 | obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o | 31 | obj-$(CONFIG_MTD_TQM8XXL) += tqm8xxl.o |
31 | obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o | 32 | obj-$(CONFIG_MTD_SA1100) += sa1100-flash.o |
32 | obj-$(CONFIG_MTD_IPAQ) += ipaq-flash.o | ||
33 | obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o | 33 | obj-$(CONFIG_MTD_SBC_GXX) += sbc_gxx.o |
34 | obj-$(CONFIG_MTD_SC520CDP) += sc520cdp.o | 34 | obj-$(CONFIG_MTD_SC520CDP) += sc520cdp.o |
35 | obj-$(CONFIG_MTD_NETSC520) += netsc520.o | 35 | obj-$(CONFIG_MTD_NETSC520) += netsc520.o |
@@ -40,7 +40,6 @@ obj-$(CONFIG_MTD_SCx200_DOCFLASH)+= scx200_docflash.o | |||
40 | obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o | 40 | obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o |
41 | obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o | 41 | obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o |
42 | obj-$(CONFIG_MTD_PCI) += pci.o | 42 | obj-$(CONFIG_MTD_PCI) += pci.o |
43 | obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o | ||
44 | obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o | 43 | obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o |
45 | obj-$(CONFIG_MTD_EDB7312) += edb7312.o | 44 | obj-$(CONFIG_MTD_EDB7312) += edb7312.o |
46 | obj-$(CONFIG_MTD_IMPA7) += impa7.o | 45 | obj-$(CONFIG_MTD_IMPA7) += impa7.o |
@@ -55,7 +54,6 @@ obj-$(CONFIG_MTD_IXP2000) += ixp2000.o | |||
55 | obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o | 54 | obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o |
56 | obj-$(CONFIG_MTD_DMV182) += dmv182.o | 55 | obj-$(CONFIG_MTD_DMV182) += dmv182.o |
57 | obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o | 56 | obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o |
58 | obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o | ||
59 | obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o | 57 | obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o |
60 | obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o | 58 | obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o |
61 | obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o | 59 | obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o |
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c deleted file mode 100644 index 845ad4f2a542..000000000000 --- a/drivers/mtd/maps/alchemy-flash.c +++ /dev/null | |||
@@ -1,166 +0,0 @@ | |||
1 | /* | ||
2 | * Flash memory access on AMD Alchemy evaluation boards | ||
3 | * | ||
4 | * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com> | ||
5 | */ | ||
6 | |||
7 | #include <linux/init.h> | ||
8 | #include <linux/module.h> | ||
9 | #include <linux/types.h> | ||
10 | #include <linux/kernel.h> | ||
11 | |||
12 | #include <linux/mtd/mtd.h> | ||
13 | #include <linux/mtd/map.h> | ||
14 | #include <linux/mtd/partitions.h> | ||
15 | |||
16 | #include <asm/io.h> | ||
17 | |||
18 | #ifdef CONFIG_MIPS_PB1000 | ||
19 | #define BOARD_MAP_NAME "Pb1000 Flash" | ||
20 | #define BOARD_FLASH_SIZE 0x00800000 /* 8MB */ | ||
21 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
22 | #endif | ||
23 | |||
24 | #ifdef CONFIG_MIPS_PB1500 | ||
25 | #define BOARD_MAP_NAME "Pb1500 Flash" | ||
26 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ | ||
27 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
28 | #endif | ||
29 | |||
30 | #ifdef CONFIG_MIPS_PB1100 | ||
31 | #define BOARD_MAP_NAME "Pb1100 Flash" | ||
32 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ | ||
33 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
34 | #endif | ||
35 | |||
36 | #ifdef CONFIG_MIPS_PB1550 | ||
37 | #define BOARD_MAP_NAME "Pb1550 Flash" | ||
38 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ | ||
39 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
40 | #endif | ||
41 | |||
42 | #ifdef CONFIG_MIPS_PB1200 | ||
43 | #define BOARD_MAP_NAME "Pb1200 Flash" | ||
44 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ | ||
45 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ | ||
46 | #endif | ||
47 | |||
48 | #ifdef CONFIG_MIPS_DB1000 | ||
49 | #define BOARD_MAP_NAME "Db1000 Flash" | ||
50 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ | ||
51 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
52 | #endif | ||
53 | |||
54 | #ifdef CONFIG_MIPS_DB1500 | ||
55 | #define BOARD_MAP_NAME "Db1500 Flash" | ||
56 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ | ||
57 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
58 | #endif | ||
59 | |||
60 | #ifdef CONFIG_MIPS_DB1100 | ||
61 | #define BOARD_MAP_NAME "Db1100 Flash" | ||
62 | #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ | ||
63 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
64 | #endif | ||
65 | |||
66 | #ifdef CONFIG_MIPS_DB1550 | ||
67 | #define BOARD_MAP_NAME "Db1550 Flash" | ||
68 | #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ | ||
69 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
70 | #endif | ||
71 | |||
72 | #ifdef CONFIG_MIPS_DB1200 | ||
73 | #define BOARD_MAP_NAME "Db1200 Flash" | ||
74 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ | ||
75 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ | ||
76 | #endif | ||
77 | |||
78 | #ifdef CONFIG_MIPS_BOSPORUS | ||
79 | #define BOARD_MAP_NAME "Bosporus Flash" | ||
80 | #define BOARD_FLASH_SIZE 0x01000000 /* 16MB */ | ||
81 | #define BOARD_FLASH_WIDTH 2 /* 16-bits */ | ||
82 | #endif | ||
83 | |||
84 | #ifdef CONFIG_MIPS_MIRAGE | ||
85 | #define BOARD_MAP_NAME "Mirage Flash" | ||
86 | #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ | ||
87 | #define BOARD_FLASH_WIDTH 4 /* 32-bits */ | ||
88 | #define USE_LOCAL_ACCESSORS /* why? */ | ||
89 | #endif | ||
90 | |||
91 | static struct map_info alchemy_map = { | ||
92 | .name = BOARD_MAP_NAME, | ||
93 | }; | ||
94 | |||
95 | static struct mtd_partition alchemy_partitions[] = { | ||
96 | { | ||
97 | .name = "User FS", | ||
98 | .size = BOARD_FLASH_SIZE - 0x00400000, | ||
99 | .offset = 0x0000000 | ||
100 | },{ | ||
101 | .name = "YAMON", | ||
102 | .size = 0x0100000, | ||
103 | .offset = MTDPART_OFS_APPEND, | ||
104 | .mask_flags = MTD_WRITEABLE | ||
105 | },{ | ||
106 | .name = "raw kernel", | ||
107 | .size = (0x300000 - 0x40000), /* last 256KB is yamon env */ | ||
108 | .offset = MTDPART_OFS_APPEND, | ||
109 | } | ||
110 | }; | ||
111 | |||
112 | static struct mtd_info *mymtd; | ||
113 | |||
114 | static int __init alchemy_mtd_init(void) | ||
115 | { | ||
116 | struct mtd_partition *parts; | ||
117 | int nb_parts = 0; | ||
118 | unsigned long window_addr; | ||
119 | unsigned long window_size; | ||
120 | |||
121 | /* Default flash buswidth */ | ||
122 | alchemy_map.bankwidth = BOARD_FLASH_WIDTH; | ||
123 | |||
124 | window_addr = 0x20000000 - BOARD_FLASH_SIZE; | ||
125 | window_size = BOARD_FLASH_SIZE; | ||
126 | |||
127 | /* | ||
128 | * Static partition definition selection | ||
129 | */ | ||
130 | parts = alchemy_partitions; | ||
131 | nb_parts = ARRAY_SIZE(alchemy_partitions); | ||
132 | alchemy_map.size = window_size; | ||
133 | |||
134 | /* | ||
135 | * Now let's probe for the actual flash. Do it here since | ||
136 | * specific machine settings might have been set above. | ||
137 | */ | ||
138 | printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n", | ||
139 | alchemy_map.bankwidth*8); | ||
140 | alchemy_map.virt = ioremap(window_addr, window_size); | ||
141 | mymtd = do_map_probe("cfi_probe", &alchemy_map); | ||
142 | if (!mymtd) { | ||
143 | iounmap(alchemy_map.virt); | ||
144 | return -ENXIO; | ||
145 | } | ||
146 | mymtd->owner = THIS_MODULE; | ||
147 | |||
148 | add_mtd_partitions(mymtd, parts, nb_parts); | ||
149 | return 0; | ||
150 | } | ||
151 | |||
152 | static void __exit alchemy_mtd_cleanup(void) | ||
153 | { | ||
154 | if (mymtd) { | ||
155 | del_mtd_partitions(mymtd); | ||
156 | map_destroy(mymtd); | ||
157 | iounmap(alchemy_map.virt); | ||
158 | } | ||
159 | } | ||
160 | |||
161 | module_init(alchemy_mtd_init); | ||
162 | module_exit(alchemy_mtd_cleanup); | ||
163 | |||
164 | MODULE_AUTHOR("Embedded Alley Solutions, Inc"); | ||
165 | MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver"); | ||
166 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c index 237733d094c4..19fe92db0c46 100644 --- a/drivers/mtd/maps/amd76xrom.c +++ b/drivers/mtd/maps/amd76xrom.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
10 | #include <linux/init.h> | 10 | #include <linux/init.h> |
11 | #include <linux/slab.h> | ||
11 | #include <asm/io.h> | 12 | #include <asm/io.h> |
12 | #include <linux/mtd/mtd.h> | 13 | #include <linux/mtd/mtd.h> |
13 | #include <linux/mtd/map.h> | 14 | #include <linux/mtd/map.h> |
diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c index a7c808b577d3..c0fd99b0c525 100644 --- a/drivers/mtd/maps/bfin-async-flash.c +++ b/drivers/mtd/maps/bfin-async-flash.c | |||
@@ -22,6 +22,7 @@ | |||
22 | #include <linux/mtd/partitions.h> | 22 | #include <linux/mtd/partitions.h> |
23 | #include <linux/mtd/physmap.h> | 23 | #include <linux/mtd/physmap.h> |
24 | #include <linux/platform_device.h> | 24 | #include <linux/platform_device.h> |
25 | #include <linux/slab.h> | ||
25 | #include <linux/types.h> | 26 | #include <linux/types.h> |
26 | 27 | ||
27 | #include <asm/blackfin.h> | 28 | #include <asm/blackfin.h> |
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c index 424f17d6ffd1..ddb462bea9b5 100644 --- a/drivers/mtd/maps/ck804xrom.c +++ b/drivers/mtd/maps/ck804xrom.c | |||
@@ -11,6 +11,7 @@ | |||
11 | #include <linux/types.h> | 11 | #include <linux/types.h> |
12 | #include <linux/kernel.h> | 12 | #include <linux/kernel.h> |
13 | #include <linux/init.h> | 13 | #include <linux/init.h> |
14 | #include <linux/slab.h> | ||
14 | #include <asm/io.h> | 15 | #include <asm/io.h> |
15 | #include <linux/mtd/mtd.h> | 16 | #include <linux/mtd/mtd.h> |
16 | #include <linux/mtd/map.h> | 17 | #include <linux/mtd/map.h> |
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c index 11a2f57df9cf..d12c93dc1aad 100644 --- a/drivers/mtd/maps/esb2rom.c +++ b/drivers/mtd/maps/esb2rom.c | |||
@@ -14,6 +14,7 @@ | |||
14 | #include <linux/types.h> | 14 | #include <linux/types.h> |
15 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
16 | #include <linux/init.h> | 16 | #include <linux/init.h> |
17 | #include <linux/slab.h> | ||
17 | #include <asm/io.h> | 18 | #include <asm/io.h> |
18 | #include <linux/mtd/mtd.h> | 19 | #include <linux/mtd/mtd.h> |
19 | #include <linux/mtd/map.h> | 20 | #include <linux/mtd/map.h> |
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 1ad5caf9fe69..32e89d773b4e 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/mtd/partitions.h> | 23 | #include <linux/mtd/partitions.h> |
24 | #include <linux/mtd/physmap.h> | 24 | #include <linux/mtd/physmap.h> |
25 | #include <linux/platform_device.h> | 25 | #include <linux/platform_device.h> |
26 | #include <linux/slab.h> | ||
26 | #include <linux/types.h> | 27 | #include <linux/types.h> |
27 | 28 | ||
28 | #define pr_devinit(fmt, args...) ({ static const __devinitconst char __fmt[] = fmt; printk(__fmt, ## args); }) | 29 | #define pr_devinit(fmt, args...) ({ static const __devinitconst char __fmt[] = fmt; printk(__fmt, ## args); }) |
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c index c32bc28920b3..f102bf243a74 100644 --- a/drivers/mtd/maps/ichxrom.c +++ b/drivers/mtd/maps/ichxrom.c | |||
@@ -8,6 +8,7 @@ | |||
8 | #include <linux/types.h> | 8 | #include <linux/types.h> |
9 | #include <linux/kernel.h> | 9 | #include <linux/kernel.h> |
10 | #include <linux/init.h> | 10 | #include <linux/init.h> |
11 | #include <linux/slab.h> | ||
11 | #include <asm/io.h> | 12 | #include <asm/io.h> |
12 | #include <linux/mtd/mtd.h> | 13 | #include <linux/mtd/mtd.h> |
13 | #include <linux/mtd/map.h> | 14 | #include <linux/mtd/map.h> |
diff --git a/drivers/mtd/maps/intel_vr_nor.c b/drivers/mtd/maps/intel_vr_nor.c index 1e7814ae212a..fc1998512eb4 100644 --- a/drivers/mtd/maps/intel_vr_nor.c +++ b/drivers/mtd/maps/intel_vr_nor.c | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #include <linux/module.h> | 30 | #include <linux/module.h> |
31 | #include <linux/kernel.h> | 31 | #include <linux/kernel.h> |
32 | #include <linux/slab.h> | ||
32 | #include <linux/pci.h> | 33 | #include <linux/pci.h> |
33 | #include <linux/init.h> | 34 | #include <linux/init.h> |
34 | #include <linux/mtd/mtd.h> | 35 | #include <linux/mtd/mtd.h> |
diff --git a/drivers/mtd/maps/ipaq-flash.c b/drivers/mtd/maps/ipaq-flash.c deleted file mode 100644 index 76708e796b70..000000000000 --- a/drivers/mtd/maps/ipaq-flash.c +++ /dev/null | |||
@@ -1,460 +0,0 @@ | |||
1 | /* | ||
2 | * Flash memory access on iPAQ Handhelds (either SA1100 or PXA250 based) | ||
3 | * | ||
4 | * (C) 2000 Nicolas Pitre <nico@fluxnic.net> | ||
5 | * (C) 2002 Hewlett-Packard Company <jamey.hicks@hp.com> | ||
6 | * (C) 2003 Christian Pellegrin <chri@ascensit.com>, <chri@infis.univ.ts.it>: concatenation of multiple flashes | ||
7 | */ | ||
8 | |||
9 | #include <linux/module.h> | ||
10 | #include <linux/types.h> | ||
11 | #include <linux/kernel.h> | ||
12 | #include <linux/spinlock.h> | ||
13 | #include <linux/init.h> | ||
14 | #include <linux/slab.h> | ||
15 | #include <asm/page.h> | ||
16 | #include <asm/mach-types.h> | ||
17 | #include <asm/system.h> | ||
18 | #include <asm/errno.h> | ||
19 | |||
20 | #include <linux/mtd/mtd.h> | ||
21 | #include <linux/mtd/map.h> | ||
22 | #include <linux/mtd/partitions.h> | ||
23 | #ifdef CONFIG_MTD_CONCAT | ||
24 | #include <linux/mtd/concat.h> | ||
25 | #endif | ||
26 | |||
27 | #include <mach/hardware.h> | ||
28 | #include <mach/h3600.h> | ||
29 | #include <asm/io.h> | ||
30 | |||
31 | |||
32 | #ifndef CONFIG_IPAQ_HANDHELD | ||
33 | #error This is for iPAQ Handhelds only | ||
34 | #endif | ||
35 | #ifdef CONFIG_SA1100_JORNADA56X | ||
36 | |||
37 | static void jornada56x_set_vpp(struct map_info *map, int vpp) | ||
38 | { | ||
39 | if (vpp) | ||
40 | GPSR = GPIO_GPIO26; | ||
41 | else | ||
42 | GPCR = GPIO_GPIO26; | ||
43 | GPDR |= GPIO_GPIO26; | ||
44 | } | ||
45 | |||
46 | #endif | ||
47 | |||
48 | #ifdef CONFIG_SA1100_JORNADA720 | ||
49 | |||
50 | static void jornada720_set_vpp(struct map_info *map, int vpp) | ||
51 | { | ||
52 | if (vpp) | ||
53 | PPSR |= 0x80; | ||
54 | else | ||
55 | PPSR &= ~0x80; | ||
56 | PPDR |= 0x80; | ||
57 | } | ||
58 | |||
59 | #endif | ||
60 | |||
61 | #define MAX_IPAQ_CS 2 /* Number of CS we are going to test */ | ||
62 | |||
63 | #define IPAQ_MAP_INIT(X) \ | ||
64 | { \ | ||
65 | name: "IPAQ flash " X, \ | ||
66 | } | ||
67 | |||
68 | |||
69 | static struct map_info ipaq_map[MAX_IPAQ_CS] = { | ||
70 | IPAQ_MAP_INIT("bank 1"), | ||
71 | IPAQ_MAP_INIT("bank 2") | ||
72 | }; | ||
73 | |||
74 | static struct mtd_info *my_sub_mtd[MAX_IPAQ_CS] = { | ||
75 | NULL, | ||
76 | NULL | ||
77 | }; | ||
78 | |||
79 | /* | ||
80 | * Here are partition information for all known IPAQ-based devices. | ||
81 | * See include/linux/mtd/partitions.h for definition of the mtd_partition | ||
82 | * structure. | ||
83 | * | ||
84 | * The *_max_flash_size is the maximum possible mapped flash size which | ||
85 | * is not necessarily the actual flash size. It must be no more than | ||
86 | * the value specified in the "struct map_desc *_io_desc" mapping | ||
87 | * definition for the corresponding machine. | ||
88 | * | ||
89 | * Please keep these in alphabetical order, and formatted as per existing | ||
90 | * entries. Thanks. | ||
91 | */ | ||
92 | |||
93 | #ifdef CONFIG_IPAQ_HANDHELD | ||
94 | static unsigned long h3xxx_max_flash_size = 0x04000000; | ||
95 | static struct mtd_partition h3xxx_partitions[] = { | ||
96 | { | ||
97 | name: "H3XXX boot firmware", | ||
98 | #ifndef CONFIG_LAB | ||
99 | size: 0x00040000, | ||
100 | #else | ||
101 | size: 0x00080000, | ||
102 | #endif | ||
103 | offset: 0, | ||
104 | #ifndef CONFIG_LAB | ||
105 | mask_flags: MTD_WRITEABLE, /* force read-only */ | ||
106 | #endif | ||
107 | }, | ||
108 | { | ||
109 | name: "H3XXX root jffs2", | ||
110 | #ifndef CONFIG_LAB | ||
111 | size: 0x2000000 - 2*0x40000, /* Warning, this is fixed later */ | ||
112 | offset: 0x00040000, | ||
113 | #else | ||
114 | size: 0x2000000 - 0x40000 - 0x80000, /* Warning, this is fixed later */ | ||
115 | offset: 0x00080000, | ||
116 | #endif | ||
117 | }, | ||
118 | { | ||
119 | name: "asset", | ||
120 | size: 0x40000, | ||
121 | offset: 0x2000000 - 0x40000, /* Warning, this is fixed later */ | ||
122 | mask_flags: MTD_WRITEABLE, /* force read-only */ | ||
123 | } | ||
124 | }; | ||
125 | |||
126 | #ifndef CONFIG_MTD_CONCAT | ||
127 | static struct mtd_partition h3xxx_partitions_bank2[] = { | ||
128 | /* this is used only on 2 CS machines when concat is not present */ | ||
129 | { | ||
130 | name: "second H3XXX root jffs2", | ||
131 | size: 0x1000000 - 0x40000, /* Warning, this is fixed later */ | ||
132 | offset: 0x00000000, | ||
133 | }, | ||
134 | { | ||
135 | name: "second asset", | ||
136 | size: 0x40000, | ||
137 | offset: 0x1000000 - 0x40000, /* Warning, this is fixed later */ | ||
138 | mask_flags: MTD_WRITEABLE, /* force read-only */ | ||
139 | } | ||
140 | }; | ||
141 | #endif | ||
142 | |||
143 | static DEFINE_SPINLOCK(ipaq_vpp_lock); | ||
144 | |||
145 | static void h3xxx_set_vpp(struct map_info *map, int vpp) | ||
146 | { | ||
147 | static int nest = 0; | ||
148 | |||
149 | spin_lock(&ipaq_vpp_lock); | ||
150 | if (vpp) | ||
151 | nest++; | ||
152 | else | ||
153 | nest--; | ||
154 | if (nest) | ||
155 | assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 1); | ||
156 | else | ||
157 | assign_h3600_egpio(IPAQ_EGPIO_VPP_ON, 0); | ||
158 | spin_unlock(&ipaq_vpp_lock); | ||
159 | } | ||
160 | |||
161 | #endif | ||
162 | |||
163 | #if defined(CONFIG_SA1100_JORNADA56X) || defined(CONFIG_SA1100_JORNADA720) | ||
164 | static unsigned long jornada_max_flash_size = 0x02000000; | ||
165 | static struct mtd_partition jornada_partitions[] = { | ||
166 | { | ||
167 | name: "Jornada boot firmware", | ||
168 | size: 0x00040000, | ||
169 | offset: 0, | ||
170 | mask_flags: MTD_WRITEABLE, /* force read-only */ | ||
171 | }, { | ||
172 | name: "Jornada root jffs2", | ||
173 | size: MTDPART_SIZ_FULL, | ||
174 | offset: 0x00040000, | ||
175 | } | ||
176 | }; | ||
177 | #endif | ||
178 | |||
179 | |||
180 | static struct mtd_partition *parsed_parts; | ||
181 | static struct mtd_info *mymtd; | ||
182 | |||
183 | static unsigned long cs_phys[] = { | ||
184 | #ifdef CONFIG_ARCH_SA1100 | ||
185 | SA1100_CS0_PHYS, | ||
186 | SA1100_CS1_PHYS, | ||
187 | SA1100_CS2_PHYS, | ||
188 | SA1100_CS3_PHYS, | ||
189 | SA1100_CS4_PHYS, | ||
190 | SA1100_CS5_PHYS, | ||
191 | #else | ||
192 | PXA_CS0_PHYS, | ||
193 | PXA_CS1_PHYS, | ||
194 | PXA_CS2_PHYS, | ||
195 | PXA_CS3_PHYS, | ||
196 | PXA_CS4_PHYS, | ||
197 | PXA_CS5_PHYS, | ||
198 | #endif | ||
199 | }; | ||
200 | |||
201 | static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; | ||
202 | |||
203 | static int __init h1900_special_case(void); | ||
204 | |||
205 | static int __init ipaq_mtd_init(void) | ||
206 | { | ||
207 | struct mtd_partition *parts = NULL; | ||
208 | int nb_parts = 0; | ||
209 | int parsed_nr_parts = 0; | ||
210 | const char *part_type; | ||
211 | int i; /* used when we have >1 flash chips */ | ||
212 | unsigned long tot_flashsize = 0; /* used when we have >1 flash chips */ | ||
213 | |||
214 | /* Default flash bankwidth */ | ||
215 | // ipaq_map.bankwidth = (MSC0 & MSC_RBW) ? 2 : 4; | ||
216 | |||
217 | if (machine_is_h1900()) | ||
218 | { | ||
219 | /* For our intents, the h1900 is not a real iPAQ, so we special-case it. */ | ||
220 | return h1900_special_case(); | ||
221 | } | ||
222 | |||
223 | if (machine_is_h3100() || machine_is_h1900()) | ||
224 | for(i=0; i<MAX_IPAQ_CS; i++) | ||
225 | ipaq_map[i].bankwidth = 2; | ||
226 | else | ||
227 | for(i=0; i<MAX_IPAQ_CS; i++) | ||
228 | ipaq_map[i].bankwidth = 4; | ||
229 | |||
230 | /* | ||
231 | * Static partition definition selection | ||
232 | */ | ||
233 | part_type = "static"; | ||
234 | |||
235 | simple_map_init(&ipaq_map[0]); | ||
236 | simple_map_init(&ipaq_map[1]); | ||
237 | |||
238 | #ifdef CONFIG_IPAQ_HANDHELD | ||
239 | if (machine_is_ipaq()) { | ||
240 | parts = h3xxx_partitions; | ||
241 | nb_parts = ARRAY_SIZE(h3xxx_partitions); | ||
242 | for(i=0; i<MAX_IPAQ_CS; i++) { | ||
243 | ipaq_map[i].size = h3xxx_max_flash_size; | ||
244 | ipaq_map[i].set_vpp = h3xxx_set_vpp; | ||
245 | ipaq_map[i].phys = cs_phys[i]; | ||
246 | ipaq_map[i].virt = ioremap(cs_phys[i], 0x04000000); | ||
247 | if (machine_is_h3100 () || machine_is_h1900()) | ||
248 | ipaq_map[i].bankwidth = 2; | ||
249 | } | ||
250 | if (machine_is_h3600()) { | ||
251 | /* No asset partition here */ | ||
252 | h3xxx_partitions[1].size += 0x40000; | ||
253 | nb_parts--; | ||
254 | } | ||
255 | } | ||
256 | #endif | ||
257 | #ifdef CONFIG_ARCH_H5400 | ||
258 | if (machine_is_h5400()) { | ||
259 | ipaq_map[0].size = 0x02000000; | ||
260 | ipaq_map[1].size = 0x02000000; | ||
261 | ipaq_map[1].phys = 0x02000000; | ||
262 | ipaq_map[1].virt = ipaq_map[0].virt + 0x02000000; | ||
263 | } | ||
264 | #endif | ||
265 | #ifdef CONFIG_ARCH_H1900 | ||
266 | if (machine_is_h1900()) { | ||
267 | ipaq_map[0].size = 0x00400000; | ||
268 | ipaq_map[1].size = 0x02000000; | ||
269 | ipaq_map[1].phys = 0x00080000; | ||
270 | ipaq_map[1].virt = ipaq_map[0].virt + 0x00080000; | ||
271 | } | ||
272 | #endif | ||
273 | |||
274 | #ifdef CONFIG_SA1100_JORNADA56X | ||
275 | if (machine_is_jornada56x()) { | ||
276 | parts = jornada_partitions; | ||
277 | nb_parts = ARRAY_SIZE(jornada_partitions); | ||
278 | ipaq_map[0].size = jornada_max_flash_size; | ||
279 | ipaq_map[0].set_vpp = jornada56x_set_vpp; | ||
280 | ipaq_map[0].virt = (__u32)ioremap(0x0, 0x04000000); | ||
281 | } | ||
282 | #endif | ||
283 | #ifdef CONFIG_SA1100_JORNADA720 | ||
284 | if (machine_is_jornada720()) { | ||
285 | parts = jornada_partitions; | ||
286 | nb_parts = ARRAY_SIZE(jornada_partitions); | ||
287 | ipaq_map[0].size = jornada_max_flash_size; | ||
288 | ipaq_map[0].set_vpp = jornada720_set_vpp; | ||
289 | } | ||
290 | #endif | ||
291 | |||
292 | |||
293 | if (machine_is_ipaq()) { /* for iPAQs only */ | ||
294 | for(i=0; i<MAX_IPAQ_CS; i++) { | ||
295 | printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with CFI.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt); | ||
296 | my_sub_mtd[i] = do_map_probe("cfi_probe", &ipaq_map[i]); | ||
297 | if (!my_sub_mtd[i]) { | ||
298 | printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[i].bankwidth*8, ipaq_map[i].virt); | ||
299 | my_sub_mtd[i] = do_map_probe("jedec_probe", &ipaq_map[i]); | ||
300 | } | ||
301 | if (!my_sub_mtd[i]) { | ||
302 | printk(KERN_NOTICE "iPAQ flash: failed to find flash.\n"); | ||
303 | if (i) | ||
304 | break; | ||
305 | else | ||
306 | return -ENXIO; | ||
307 | } else | ||
308 | printk(KERN_NOTICE "iPAQ flash: found %d bytes\n", my_sub_mtd[i]->size); | ||
309 | |||
310 | /* do we really need this debugging? --joshua 20030703 */ | ||
311 | // printk("my_sub_mtd[%d]=%p\n", i, my_sub_mtd[i]); | ||
312 | my_sub_mtd[i]->owner = THIS_MODULE; | ||
313 | tot_flashsize += my_sub_mtd[i]->size; | ||
314 | } | ||
315 | #ifdef CONFIG_MTD_CONCAT | ||
316 | /* fix the asset location */ | ||
317 | # ifdef CONFIG_LAB | ||
318 | h3xxx_partitions[1].size = tot_flashsize - 0x40000 - 0x80000 /* extra big boot block */; | ||
319 | # else | ||
320 | h3xxx_partitions[1].size = tot_flashsize - 2 * 0x40000; | ||
321 | # endif | ||
322 | h3xxx_partitions[2].offset = tot_flashsize - 0x40000; | ||
323 | /* and concat the devices */ | ||
324 | mymtd = mtd_concat_create(&my_sub_mtd[0], i, | ||
325 | "ipaq"); | ||
326 | if (!mymtd) { | ||
327 | printk("Cannot create iPAQ concat device\n"); | ||
328 | return -ENXIO; | ||
329 | } | ||
330 | #else | ||
331 | mymtd = my_sub_mtd[0]; | ||
332 | |||
333 | /* | ||
334 | *In the very near future, command line partition parsing | ||
335 | * will use the device name as 'mtd-id' instead of a value | ||
336 | * passed to the parse_cmdline_partitions() routine. Since | ||
337 | * the bootldr says 'ipaq', make sure it continues to work. | ||
338 | */ | ||
339 | mymtd->name = "ipaq"; | ||
340 | |||
341 | if ((machine_is_h3600())) { | ||
342 | # ifdef CONFIG_LAB | ||
343 | h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x80000; | ||
344 | # else | ||
345 | h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000; | ||
346 | # endif | ||
347 | nb_parts = 2; | ||
348 | } else { | ||
349 | # ifdef CONFIG_LAB | ||
350 | h3xxx_partitions[1].size = my_sub_mtd[0]->size - 0x40000 - 0x80000; /* extra big boot block */ | ||
351 | # else | ||
352 | h3xxx_partitions[1].size = my_sub_mtd[0]->size - 2*0x40000; | ||
353 | # endif | ||
354 | h3xxx_partitions[2].offset = my_sub_mtd[0]->size - 0x40000; | ||
355 | } | ||
356 | |||
357 | if (my_sub_mtd[1]) { | ||
358 | # ifdef CONFIG_LAB | ||
359 | h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x80000; | ||
360 | # else | ||
361 | h3xxx_partitions_bank2[0].size = my_sub_mtd[1]->size - 0x40000; | ||
362 | # endif | ||
363 | h3xxx_partitions_bank2[1].offset = my_sub_mtd[1]->size - 0x40000; | ||
364 | } | ||
365 | #endif | ||
366 | } | ||
367 | else { | ||
368 | /* | ||
369 | * Now let's probe for the actual flash. Do it here since | ||
370 | * specific machine settings might have been set above. | ||
371 | */ | ||
372 | printk(KERN_NOTICE "IPAQ flash: probing %d-bit flash bus, window=%lx\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt); | ||
373 | mymtd = do_map_probe("cfi_probe", &ipaq_map[0]); | ||
374 | if (!mymtd) | ||
375 | return -ENXIO; | ||
376 | mymtd->owner = THIS_MODULE; | ||
377 | } | ||
378 | |||
379 | |||
380 | /* | ||
381 | * Dynamic partition selection stuff (might override the static ones) | ||
382 | */ | ||
383 | |||
384 | i = parse_mtd_partitions(mymtd, part_probes, &parsed_parts, 0); | ||
385 | |||
386 | if (i > 0) { | ||
387 | nb_parts = parsed_nr_parts = i; | ||
388 | parts = parsed_parts; | ||
389 | part_type = "dynamic"; | ||
390 | } | ||
391 | |||
392 | if (!parts) { | ||
393 | printk(KERN_NOTICE "IPAQ flash: no partition info available, registering whole flash at once\n"); | ||
394 | add_mtd_device(mymtd); | ||
395 | #ifndef CONFIG_MTD_CONCAT | ||
396 | if (my_sub_mtd[1]) | ||
397 | add_mtd_device(my_sub_mtd[1]); | ||
398 | #endif | ||
399 | } else { | ||
400 | printk(KERN_NOTICE "Using %s partition definition\n", part_type); | ||
401 | add_mtd_partitions(mymtd, parts, nb_parts); | ||
402 | #ifndef CONFIG_MTD_CONCAT | ||
403 | if (my_sub_mtd[1]) | ||
404 | add_mtd_partitions(my_sub_mtd[1], h3xxx_partitions_bank2, ARRAY_SIZE(h3xxx_partitions_bank2)); | ||
405 | #endif | ||
406 | } | ||
407 | |||
408 | return 0; | ||
409 | } | ||
410 | |||
411 | static void __exit ipaq_mtd_cleanup(void) | ||
412 | { | ||
413 | int i; | ||
414 | |||
415 | if (mymtd) { | ||
416 | del_mtd_partitions(mymtd); | ||
417 | #ifndef CONFIG_MTD_CONCAT | ||
418 | if (my_sub_mtd[1]) | ||
419 | del_mtd_partitions(my_sub_mtd[1]); | ||
420 | #endif | ||
421 | map_destroy(mymtd); | ||
422 | #ifdef CONFIG_MTD_CONCAT | ||
423 | for(i=0; i<MAX_IPAQ_CS; i++) | ||
424 | #else | ||
425 | for(i=1; i<MAX_IPAQ_CS; i++) | ||
426 | #endif | ||
427 | { | ||
428 | if (my_sub_mtd[i]) | ||
429 | map_destroy(my_sub_mtd[i]); | ||
430 | } | ||
431 | kfree(parsed_parts); | ||
432 | } | ||
433 | } | ||
434 | |||
435 | static int __init h1900_special_case(void) | ||
436 | { | ||
437 | /* The iPAQ h1900 is a special case - it has weird ROM. */ | ||
438 | simple_map_init(&ipaq_map[0]); | ||
439 | ipaq_map[0].size = 0x80000; | ||
440 | ipaq_map[0].set_vpp = h3xxx_set_vpp; | ||
441 | ipaq_map[0].phys = 0x0; | ||
442 | ipaq_map[0].virt = ioremap(0x0, 0x04000000); | ||
443 | ipaq_map[0].bankwidth = 2; | ||
444 | |||
445 | printk(KERN_NOTICE "iPAQ flash: probing %d-bit flash bus, window=%lx with JEDEC.\n", ipaq_map[0].bankwidth*8, ipaq_map[0].virt); | ||
446 | mymtd = do_map_probe("jedec_probe", &ipaq_map[0]); | ||
447 | if (!mymtd) | ||
448 | return -ENODEV; | ||
449 | add_mtd_device(mymtd); | ||
450 | printk(KERN_NOTICE "iPAQ flash: registered h1910 flash\n"); | ||
451 | |||
452 | return 0; | ||
453 | } | ||
454 | |||
455 | module_init(ipaq_mtd_init); | ||
456 | module_exit(ipaq_mtd_cleanup); | ||
457 | |||
458 | MODULE_AUTHOR("Jamey Hicks"); | ||
459 | MODULE_DESCRIPTION("IPAQ CFI map driver"); | ||
460 | MODULE_LICENSE("MIT"); | ||
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c index 7214b876feba..7b0515297411 100644 --- a/drivers/mtd/maps/ixp4xx.c +++ b/drivers/mtd/maps/ixp4xx.c | |||
@@ -210,7 +210,7 @@ static int ixp4xx_flash_probe(struct platform_device *dev) | |||
210 | * not attempt to do a direct access on us. | 210 | * not attempt to do a direct access on us. |
211 | */ | 211 | */ |
212 | info->map.phys = NO_XIP; | 212 | info->map.phys = NO_XIP; |
213 | info->map.size = dev->resource->end - dev->resource->start + 1; | 213 | info->map.size = resource_size(dev->resource); |
214 | 214 | ||
215 | /* | 215 | /* |
216 | * We only support 16-bit accesses for now. If and when | 216 | * We only support 16-bit accesses for now. If and when |
@@ -224,7 +224,7 @@ static int ixp4xx_flash_probe(struct platform_device *dev) | |||
224 | info->map.copy_from = ixp4xx_copy_from, | 224 | info->map.copy_from = ixp4xx_copy_from, |
225 | 225 | ||
226 | info->res = request_mem_region(dev->resource->start, | 226 | info->res = request_mem_region(dev->resource->start, |
227 | dev->resource->end - dev->resource->start + 1, | 227 | resource_size(dev->resource), |
228 | "IXP4XXFlash"); | 228 | "IXP4XXFlash"); |
229 | if (!info->res) { | 229 | if (!info->res) { |
230 | printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n"); | 230 | printk(KERN_ERR "IXP4XXFlash: Could not reserve memory region\n"); |
@@ -233,7 +233,7 @@ static int ixp4xx_flash_probe(struct platform_device *dev) | |||
233 | } | 233 | } |
234 | 234 | ||
235 | info->map.virt = ioremap(dev->resource->start, | 235 | info->map.virt = ioremap(dev->resource->start, |
236 | dev->resource->end - dev->resource->start + 1); | 236 | resource_size(dev->resource)); |
237 | if (!info->map.virt) { | 237 | if (!info->map.virt) { |
238 | printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n"); | 238 | printk(KERN_ERR "IXP4XXFlash: Failed to ioremap region\n"); |
239 | err = -EIO; | 239 | err = -EIO; |
diff --git a/drivers/mtd/maps/octagon-5066.c b/drivers/mtd/maps/octagon-5066.c index 2b2e45093218..23fe1786770f 100644 --- a/drivers/mtd/maps/octagon-5066.c +++ b/drivers/mtd/maps/octagon-5066.c | |||
@@ -24,7 +24,6 @@ | |||
24 | ##################################################################### */ | 24 | ##################################################################### */ |
25 | 25 | ||
26 | #include <linux/module.h> | 26 | #include <linux/module.h> |
27 | #include <linux/slab.h> | ||
28 | #include <linux/ioport.h> | 27 | #include <linux/ioport.h> |
29 | #include <linux/init.h> | 28 | #include <linux/init.h> |
30 | #include <asm/io.h> | 29 | #include <asm/io.h> |
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c deleted file mode 100644 index a24478102b11..000000000000 --- a/drivers/mtd/maps/omap_nor.c +++ /dev/null | |||
@@ -1,188 +0,0 @@ | |||
1 | /* | ||
2 | * Flash memory support for various TI OMAP boards | ||
3 | * | ||
4 | * Copyright (C) 2001-2002 MontaVista Software Inc. | ||
5 | * Copyright (C) 2003-2004 Texas Instruments | ||
6 | * Copyright (C) 2004 Nokia Corporation | ||
7 | * | ||
8 | * Assembled using driver code copyright the companies above | ||
9 | * and written by David Brownell, Jian Zhang <jzhang@ti.com>, | ||
10 | * Tony Lindgren <tony@atomide.com> and others. | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or modify it | ||
13 | * under the terms of the GNU General Public License as published by the | ||
14 | * Free Software Foundation; either version 2 of the License, or (at your | ||
15 | * option) any later version. | ||
16 | * | ||
17 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | ||
18 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||
19 | * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN | ||
20 | * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | ||
23 | * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | ||
24 | * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | ||
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
27 | * | ||
28 | * You should have received a copy of the GNU General Public License along | ||
29 | * with this program; if not, write to the Free Software Foundation, Inc., | ||
30 | * 675 Mass Ave, Cambridge, MA 02139, USA. | ||
31 | */ | ||
32 | |||
33 | #include <linux/platform_device.h> | ||
34 | #include <linux/module.h> | ||
35 | #include <linux/types.h> | ||
36 | #include <linux/kernel.h> | ||
37 | #include <linux/init.h> | ||
38 | #include <linux/ioport.h> | ||
39 | #include <linux/slab.h> | ||
40 | |||
41 | #include <linux/mtd/mtd.h> | ||
42 | #include <linux/mtd/map.h> | ||
43 | #include <linux/mtd/partitions.h> | ||
44 | |||
45 | #include <asm/io.h> | ||
46 | #include <mach/hardware.h> | ||
47 | #include <asm/mach/flash.h> | ||
48 | #include <mach/tc.h> | ||
49 | |||
50 | #ifdef CONFIG_MTD_PARTITIONS | ||
51 | static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL }; | ||
52 | #endif | ||
53 | |||
54 | struct omapflash_info { | ||
55 | struct mtd_partition *parts; | ||
56 | struct mtd_info *mtd; | ||
57 | struct map_info map; | ||
58 | }; | ||
59 | |||
60 | static void omap_set_vpp(struct map_info *map, int enable) | ||
61 | { | ||
62 | static int count; | ||
63 | u32 l; | ||
64 | |||
65 | if (cpu_class_is_omap1()) { | ||
66 | if (enable) { | ||
67 | if (count++ == 0) { | ||
68 | l = omap_readl(EMIFS_CONFIG); | ||
69 | l |= OMAP_EMIFS_CONFIG_WP; | ||
70 | omap_writel(l, EMIFS_CONFIG); | ||
71 | } | ||
72 | } else { | ||
73 | if (count && (--count == 0)) { | ||
74 | l = omap_readl(EMIFS_CONFIG); | ||
75 | l &= ~OMAP_EMIFS_CONFIG_WP; | ||
76 | omap_writel(l, EMIFS_CONFIG); | ||
77 | } | ||
78 | } | ||
79 | } | ||
80 | } | ||
81 | |||
82 | static int __init omapflash_probe(struct platform_device *pdev) | ||
83 | { | ||
84 | int err; | ||
85 | struct omapflash_info *info; | ||
86 | struct flash_platform_data *pdata = pdev->dev.platform_data; | ||
87 | struct resource *res = pdev->resource; | ||
88 | unsigned long size = res->end - res->start + 1; | ||
89 | |||
90 | info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL); | ||
91 | if (!info) | ||
92 | return -ENOMEM; | ||
93 | |||
94 | if (!request_mem_region(res->start, size, "flash")) { | ||
95 | err = -EBUSY; | ||
96 | goto out_free_info; | ||
97 | } | ||
98 | |||
99 | info->map.virt = ioremap(res->start, size); | ||
100 | if (!info->map.virt) { | ||
101 | err = -ENOMEM; | ||
102 | goto out_release_mem_region; | ||
103 | } | ||
104 | info->map.name = dev_name(&pdev->dev); | ||
105 | info->map.phys = res->start; | ||
106 | info->map.size = size; | ||
107 | info->map.bankwidth = pdata->width; | ||
108 | info->map.set_vpp = omap_set_vpp; | ||
109 | |||
110 | simple_map_init(&info->map); | ||
111 | info->mtd = do_map_probe(pdata->map_name, &info->map); | ||
112 | if (!info->mtd) { | ||
113 | err = -EIO; | ||
114 | goto out_iounmap; | ||
115 | } | ||
116 | info->mtd->owner = THIS_MODULE; | ||
117 | |||
118 | info->mtd->dev.parent = &pdev->dev; | ||
119 | |||
120 | #ifdef CONFIG_MTD_PARTITIONS | ||
121 | err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0); | ||
122 | if (err > 0) | ||
123 | add_mtd_partitions(info->mtd, info->parts, err); | ||
124 | else if (err <= 0 && pdata->parts) | ||
125 | add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); | ||
126 | else | ||
127 | #endif | ||
128 | add_mtd_device(info->mtd); | ||
129 | |||
130 | platform_set_drvdata(pdev, info); | ||
131 | |||
132 | return 0; | ||
133 | |||
134 | out_iounmap: | ||
135 | iounmap(info->map.virt); | ||
136 | out_release_mem_region: | ||
137 | release_mem_region(res->start, size); | ||
138 | out_free_info: | ||
139 | kfree(info); | ||
140 | |||
141 | return err; | ||
142 | } | ||
143 | |||
144 | static int __exit omapflash_remove(struct platform_device *pdev) | ||
145 | { | ||
146 | struct omapflash_info *info = platform_get_drvdata(pdev); | ||
147 | |||
148 | platform_set_drvdata(pdev, NULL); | ||
149 | |||
150 | if (info) { | ||
151 | if (info->parts) { | ||
152 | del_mtd_partitions(info->mtd); | ||
153 | kfree(info->parts); | ||
154 | } else | ||
155 | del_mtd_device(info->mtd); | ||
156 | map_destroy(info->mtd); | ||
157 | release_mem_region(info->map.phys, info->map.size); | ||
158 | iounmap((void __iomem *) info->map.virt); | ||
159 | kfree(info); | ||
160 | } | ||
161 | |||
162 | return 0; | ||
163 | } | ||
164 | |||
165 | static struct platform_driver omapflash_driver = { | ||
166 | .remove = __exit_p(omapflash_remove), | ||
167 | .driver = { | ||
168 | .name = "omapflash", | ||
169 | .owner = THIS_MODULE, | ||
170 | }, | ||
171 | }; | ||
172 | |||
173 | static int __init omapflash_init(void) | ||
174 | { | ||
175 | return platform_driver_probe(&omapflash_driver, omapflash_probe); | ||
176 | } | ||
177 | |||
178 | static void __exit omapflash_exit(void) | ||
179 | { | ||
180 | platform_driver_unregister(&omapflash_driver); | ||
181 | } | ||
182 | |||
183 | module_init(omapflash_init); | ||
184 | module_exit(omapflash_exit); | ||
185 | |||
186 | MODULE_LICENSE("GPL"); | ||
187 | MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards"); | ||
188 | MODULE_ALIAS("platform:omapflash"); | ||
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c index d600c2deff73..689d6a79ffc0 100644 --- a/drivers/mtd/maps/pcmciamtd.c +++ b/drivers/mtd/maps/pcmciamtd.c | |||
@@ -118,11 +118,9 @@ static caddr_t remap_window(struct map_info *map, unsigned long to) | |||
118 | DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x", | 118 | DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x", |
119 | dev->offset, mrq.CardOffset); | 119 | dev->offset, mrq.CardOffset); |
120 | mrq.Page = 0; | 120 | mrq.Page = 0; |
121 | ret = pcmcia_map_mem_page(win, &mrq); | 121 | ret = pcmcia_map_mem_page(dev->p_dev, win, &mrq); |
122 | if (ret != 0) { | 122 | if (ret != 0) |
123 | cs_error(dev->p_dev, MapMemPage, ret); | ||
124 | return NULL; | 123 | return NULL; |
125 | } | ||
126 | dev->offset = mrq.CardOffset; | 124 | dev->offset = mrq.CardOffset; |
127 | } | 125 | } |
128 | return dev->win_base + (to & (dev->win_size-1)); | 126 | return dev->win_base + (to & (dev->win_size-1)); |
@@ -327,8 +325,6 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on) | |||
327 | 325 | ||
328 | DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); | 326 | DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp); |
329 | ret = pcmcia_modify_configuration(link, &mod); | 327 | ret = pcmcia_modify_configuration(link, &mod); |
330 | if (ret != 0) | ||
331 | cs_error(link, ModifyConfiguration, ret); | ||
332 | } | 328 | } |
333 | 329 | ||
334 | 330 | ||
@@ -348,107 +344,116 @@ static void pcmciamtd_release(struct pcmcia_device *link) | |||
348 | iounmap(dev->win_base); | 344 | iounmap(dev->win_base); |
349 | dev->win_base = NULL; | 345 | dev->win_base = NULL; |
350 | } | 346 | } |
351 | pcmcia_release_window(link->win); | 347 | pcmcia_release_window(link, link->win); |
352 | } | 348 | } |
353 | pcmcia_disable_device(link); | 349 | pcmcia_disable_device(link); |
354 | } | 350 | } |
355 | 351 | ||
356 | 352 | ||
357 | static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, int *new_name) | 353 | #ifdef CONFIG_MTD_DEBUG |
354 | static int pcmciamtd_cistpl_format(struct pcmcia_device *p_dev, | ||
355 | tuple_t *tuple, | ||
356 | void *priv_data) | ||
358 | { | 357 | { |
359 | int rc; | ||
360 | tuple_t tuple; | ||
361 | cisparse_t parse; | 358 | cisparse_t parse; |
362 | u_char buf[64]; | ||
363 | |||
364 | tuple.Attributes = 0; | ||
365 | tuple.TupleData = (cisdata_t *)buf; | ||
366 | tuple.TupleDataMax = sizeof(buf); | ||
367 | tuple.TupleOffset = 0; | ||
368 | tuple.DesiredTuple = RETURN_FIRST_TUPLE; | ||
369 | |||
370 | rc = pcmcia_get_first_tuple(link, &tuple); | ||
371 | while (rc == 0) { | ||
372 | rc = pcmcia_get_tuple_data(link, &tuple); | ||
373 | if (rc != 0) { | ||
374 | cs_error(link, GetTupleData, rc); | ||
375 | break; | ||
376 | } | ||
377 | rc = pcmcia_parse_tuple(&tuple, &parse); | ||
378 | if (rc != 0) { | ||
379 | cs_error(link, ParseTuple, rc); | ||
380 | break; | ||
381 | } | ||
382 | 359 | ||
383 | switch(tuple.TupleCode) { | 360 | if (!pcmcia_parse_tuple(tuple, &parse)) { |
384 | case CISTPL_FORMAT: { | 361 | cistpl_format_t *t = &parse.format; |
385 | cistpl_format_t *t = &parse.format; | 362 | (void)t; /* Shut up, gcc */ |
386 | (void)t; /* Shut up, gcc */ | 363 | DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u", |
387 | DEBUG(2, "Format type: %u, Error Detection: %u, offset = %u, length =%u", | 364 | t->type, t->edc, t->offset, t->length); |
388 | t->type, t->edc, t->offset, t->length); | 365 | } |
389 | break; | 366 | return -ENOSPC; |
367 | } | ||
390 | 368 | ||
391 | } | 369 | static int pcmciamtd_cistpl_jedec(struct pcmcia_device *p_dev, |
370 | tuple_t *tuple, | ||
371 | void *priv_data) | ||
372 | { | ||
373 | cisparse_t parse; | ||
374 | int i; | ||
392 | 375 | ||
393 | case CISTPL_DEVICE: { | 376 | if (!pcmcia_parse_tuple(tuple, &parse)) { |
394 | cistpl_device_t *t = &parse.device; | 377 | cistpl_jedec_t *t = &parse.jedec; |
395 | int i; | 378 | for (i = 0; i < t->nid; i++) |
396 | DEBUG(2, "Common memory:"); | 379 | DEBUG(2, "JEDEC: 0x%02x 0x%02x", t->id[i].mfr, t->id[i].info); |
397 | dev->pcmcia_map.size = t->dev[0].size; | 380 | } |
398 | for(i = 0; i < t->ndev; i++) { | 381 | return -ENOSPC; |
399 | DEBUG(2, "Region %d, type = %u", i, t->dev[i].type); | 382 | } |
400 | DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp); | 383 | #endif |
401 | DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed); | ||
402 | DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size); | ||
403 | } | ||
404 | break; | ||
405 | } | ||
406 | 384 | ||
407 | case CISTPL_VERS_1: { | 385 | static int pcmciamtd_cistpl_device(struct pcmcia_device *p_dev, |
408 | cistpl_vers_1_t *t = &parse.version_1; | 386 | tuple_t *tuple, |
409 | int i; | 387 | void *priv_data) |
410 | if(t->ns) { | 388 | { |
411 | dev->mtd_name[0] = '\0'; | 389 | struct pcmciamtd_dev *dev = priv_data; |
412 | for(i = 0; i < t->ns; i++) { | 390 | cisparse_t parse; |
413 | if(i) | 391 | cistpl_device_t *t = &parse.device; |
414 | strcat(dev->mtd_name, " "); | 392 | int i; |
415 | strcat(dev->mtd_name, t->str+t->ofs[i]); | ||
416 | } | ||
417 | } | ||
418 | DEBUG(2, "Found name: %s", dev->mtd_name); | ||
419 | break; | ||
420 | } | ||
421 | 393 | ||
422 | case CISTPL_JEDEC_C: { | 394 | if (pcmcia_parse_tuple(tuple, &parse)) |
423 | cistpl_jedec_t *t = &parse.jedec; | 395 | return -EINVAL; |
424 | int i; | 396 | |
425 | for(i = 0; i < t->nid; i++) { | 397 | DEBUG(2, "Common memory:"); |
426 | DEBUG(2, "JEDEC: 0x%02x 0x%02x", t->id[i].mfr, t->id[i].info); | 398 | dev->pcmcia_map.size = t->dev[0].size; |
427 | } | 399 | /* from here on: DEBUG only */ |
428 | break; | 400 | for (i = 0; i < t->ndev; i++) { |
429 | } | 401 | DEBUG(2, "Region %d, type = %u", i, t->dev[i].type); |
402 | DEBUG(2, "Region %d, wp = %u", i, t->dev[i].wp); | ||
403 | DEBUG(2, "Region %d, speed = %u ns", i, t->dev[i].speed); | ||
404 | DEBUG(2, "Region %d, size = %u bytes", i, t->dev[i].size); | ||
405 | } | ||
406 | return 0; | ||
407 | } | ||
430 | 408 | ||
431 | case CISTPL_DEVICE_GEO: { | 409 | static int pcmciamtd_cistpl_geo(struct pcmcia_device *p_dev, |
432 | cistpl_device_geo_t *t = &parse.device_geo; | 410 | tuple_t *tuple, |
433 | int i; | 411 | void *priv_data) |
434 | dev->pcmcia_map.bankwidth = t->geo[0].buswidth; | 412 | { |
435 | for(i = 0; i < t->ngeo; i++) { | 413 | struct pcmciamtd_dev *dev = priv_data; |
436 | DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth); | 414 | cisparse_t parse; |
437 | DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block); | 415 | cistpl_device_geo_t *t = &parse.device_geo; |
438 | DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block); | 416 | int i; |
439 | DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block); | ||
440 | DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition); | ||
441 | DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave); | ||
442 | } | ||
443 | break; | ||
444 | } | ||
445 | 417 | ||
446 | default: | 418 | if (pcmcia_parse_tuple(tuple, &parse)) |
447 | DEBUG(2, "Unknown tuple code %d", tuple.TupleCode); | 419 | return -EINVAL; |
448 | } | 420 | |
421 | dev->pcmcia_map.bankwidth = t->geo[0].buswidth; | ||
422 | /* from here on: DEBUG only */ | ||
423 | for (i = 0; i < t->ngeo; i++) { | ||
424 | DEBUG(2, "region: %d bankwidth = %u", i, t->geo[i].buswidth); | ||
425 | DEBUG(2, "region: %d erase_block = %u", i, t->geo[i].erase_block); | ||
426 | DEBUG(2, "region: %d read_block = %u", i, t->geo[i].read_block); | ||
427 | DEBUG(2, "region: %d write_block = %u", i, t->geo[i].write_block); | ||
428 | DEBUG(2, "region: %d partition = %u", i, t->geo[i].partition); | ||
429 | DEBUG(2, "region: %d interleave = %u", i, t->geo[i].interleave); | ||
430 | } | ||
431 | return 0; | ||
432 | } | ||
433 | |||
434 | |||
435 | static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, int *new_name) | ||
436 | { | ||
437 | int i; | ||
449 | 438 | ||
450 | rc = pcmcia_get_next_tuple(link, &tuple); | 439 | if (p_dev->prod_id[0]) { |
440 | dev->mtd_name[0] = '\0'; | ||
441 | for (i = 0; i < 4; i++) { | ||
442 | if (i) | ||
443 | strcat(dev->mtd_name, " "); | ||
444 | if (p_dev->prod_id[i]) | ||
445 | strcat(dev->mtd_name, p_dev->prod_id[i]); | ||
446 | } | ||
447 | DEBUG(2, "Found name: %s", dev->mtd_name); | ||
451 | } | 448 | } |
449 | |||
450 | #ifdef CONFIG_MTD_DEBUG | ||
451 | pcmcia_loop_tuple(p_dev, CISTPL_FORMAT, pcmciamtd_cistpl_format, NULL); | ||
452 | pcmcia_loop_tuple(p_dev, CISTPL_JEDEC_C, pcmciamtd_cistpl_jedec, NULL); | ||
453 | #endif | ||
454 | pcmcia_loop_tuple(p_dev, CISTPL_DEVICE, pcmciamtd_cistpl_device, dev); | ||
455 | pcmcia_loop_tuple(p_dev, CISTPL_DEVICE_GEO, pcmciamtd_cistpl_geo, dev); | ||
456 | |||
452 | if(!dev->pcmcia_map.size) | 457 | if(!dev->pcmcia_map.size) |
453 | dev->pcmcia_map.size = MAX_PCMCIA_ADDR; | 458 | dev->pcmcia_map.size = MAX_PCMCIA_ADDR; |
454 | 459 | ||
@@ -481,16 +486,12 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link, | |||
481 | * MTD device available to the system. | 486 | * MTD device available to the system. |
482 | */ | 487 | */ |
483 | 488 | ||
484 | #define CS_CHECK(fn, ret) \ | ||
485 | do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0) | ||
486 | |||
487 | static int pcmciamtd_config(struct pcmcia_device *link) | 489 | static int pcmciamtd_config(struct pcmcia_device *link) |
488 | { | 490 | { |
489 | struct pcmciamtd_dev *dev = link->priv; | 491 | struct pcmciamtd_dev *dev = link->priv; |
490 | struct mtd_info *mtd = NULL; | 492 | struct mtd_info *mtd = NULL; |
491 | cs_status_t status; | 493 | cs_status_t status; |
492 | win_req_t req; | 494 | win_req_t req; |
493 | int last_ret = 0, last_fn = 0; | ||
494 | int ret; | 495 | int ret; |
495 | int i; | 496 | int i; |
496 | static char *probes[] = { "jedec_probe", "cfi_probe" }; | 497 | static char *probes[] = { "jedec_probe", "cfi_probe" }; |
@@ -529,7 +530,7 @@ static int pcmciamtd_config(struct pcmcia_device *link) | |||
529 | int ret; | 530 | int ret; |
530 | DEBUG(2, "requesting window with size = %dKiB memspeed = %d", | 531 | DEBUG(2, "requesting window with size = %dKiB memspeed = %d", |
531 | req.Size >> 10, req.AccessSpeed); | 532 | req.Size >> 10, req.AccessSpeed); |
532 | ret = pcmcia_request_window(&link, &req, &link->win); | 533 | ret = pcmcia_request_window(link, &req, &link->win); |
533 | DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); | 534 | DEBUG(2, "ret = %d dev->win_size = %d", ret, dev->win_size); |
534 | if(ret) { | 535 | if(ret) { |
535 | req.Size >>= 1; | 536 | req.Size >>= 1; |
@@ -577,7 +578,6 @@ static int pcmciamtd_config(struct pcmcia_device *link) | |||
577 | DEBUG(2, "Setting Configuration"); | 578 | DEBUG(2, "Setting Configuration"); |
578 | ret = pcmcia_request_configuration(link, &link->conf); | 579 | ret = pcmcia_request_configuration(link, &link->conf); |
579 | if (ret != 0) { | 580 | if (ret != 0) { |
580 | cs_error(link, RequestConfiguration, ret); | ||
581 | if (dev->win_base) { | 581 | if (dev->win_base) { |
582 | iounmap(dev->win_base); | 582 | iounmap(dev->win_base); |
583 | dev->win_base = NULL; | 583 | dev->win_base = NULL; |
@@ -652,8 +652,7 @@ static int pcmciamtd_config(struct pcmcia_device *link) | |||
652 | link->dev_node = &dev->node; | 652 | link->dev_node = &dev->node; |
653 | return 0; | 653 | return 0; |
654 | 654 | ||
655 | cs_failed: | 655 | failed: |
656 | cs_error(link, last_fn, last_ret); | ||
657 | err("CS Error, exiting"); | 656 | err("CS Error, exiting"); |
658 | pcmciamtd_release(link); | 657 | pcmciamtd_release(link); |
659 | return -ENODEV; | 658 | return -ENODEV; |
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 380648e9051a..d9603f7f9652 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c | |||
@@ -48,23 +48,22 @@ static int physmap_flash_remove(struct platform_device *dev) | |||
48 | 48 | ||
49 | if (info->cmtd) { | 49 | if (info->cmtd) { |
50 | #ifdef CONFIG_MTD_PARTITIONS | 50 | #ifdef CONFIG_MTD_PARTITIONS |
51 | if (info->nr_parts || physmap_data->nr_parts) | 51 | if (info->nr_parts || physmap_data->nr_parts) { |
52 | del_mtd_partitions(info->cmtd); | 52 | del_mtd_partitions(info->cmtd); |
53 | else | 53 | |
54 | if (info->nr_parts) | ||
55 | kfree(info->parts); | ||
56 | } else { | ||
54 | del_mtd_device(info->cmtd); | 57 | del_mtd_device(info->cmtd); |
58 | } | ||
55 | #else | 59 | #else |
56 | del_mtd_device(info->cmtd); | 60 | del_mtd_device(info->cmtd); |
57 | #endif | 61 | #endif |
58 | } | ||
59 | #ifdef CONFIG_MTD_PARTITIONS | ||
60 | if (info->nr_parts) | ||
61 | kfree(info->parts); | ||
62 | #endif | ||
63 | |||
64 | #ifdef CONFIG_MTD_CONCAT | 62 | #ifdef CONFIG_MTD_CONCAT |
65 | if (info->cmtd != info->mtd[0]) | 63 | if (info->cmtd != info->mtd[0]) |
66 | mtd_concat_destroy(info->cmtd); | 64 | mtd_concat_destroy(info->cmtd); |
67 | #endif | 65 | #endif |
66 | } | ||
68 | 67 | ||
69 | for (i = 0; i < MAX_RESOURCES; i++) { | 68 | for (i = 0; i < MAX_RESOURCES; i++) { |
70 | if (info->mtd[i] != NULL) | 69 | if (info->mtd[i] != NULL) |
@@ -130,7 +129,7 @@ static int physmap_flash_probe(struct platform_device *dev) | |||
130 | info->map[i].size); | 129 | info->map[i].size); |
131 | if (info->map[i].virt == NULL) { | 130 | if (info->map[i].virt == NULL) { |
132 | dev_err(&dev->dev, "Failed to ioremap flash region\n"); | 131 | dev_err(&dev->dev, "Failed to ioremap flash region\n"); |
133 | err = EIO; | 132 | err = -EIO; |
134 | goto err_out; | 133 | goto err_out; |
135 | } | 134 | } |
136 | 135 | ||
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 61e4eb48bb2d..101ee6ead05c 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/mtd/concat.h> | 23 | #include <linux/mtd/concat.h> |
24 | #include <linux/of.h> | 24 | #include <linux/of.h> |
25 | #include <linux/of_platform.h> | 25 | #include <linux/of_platform.h> |
26 | #include <linux/slab.h> | ||
26 | 27 | ||
27 | struct of_flash_list { | 28 | struct of_flash_list { |
28 | struct mtd_info *mtd; | 29 | struct mtd_info *mtd; |
diff --git a/drivers/mtd/maps/pismo.c b/drivers/mtd/maps/pismo.c new file mode 100644 index 000000000000..60c068db452d --- /dev/null +++ b/drivers/mtd/maps/pismo.c | |||
@@ -0,0 +1,321 @@ | |||
1 | /* | ||
2 | * PISMO memory driver - http://www.pismoworld.org/ | ||
3 | * | ||
4 | * For ARM Realview and Versatile platforms | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License. | ||
9 | */ | ||
10 | #include <linux/init.h> | ||
11 | #include <linux/module.h> | ||
12 | #include <linux/i2c.h> | ||
13 | #include <linux/slab.h> | ||
14 | #include <linux/platform_device.h> | ||
15 | #include <linux/spinlock.h> | ||
16 | #include <linux/mutex.h> | ||
17 | #include <linux/mtd/physmap.h> | ||
18 | #include <linux/mtd/plat-ram.h> | ||
19 | #include <linux/mtd/pismo.h> | ||
20 | |||
21 | #define PISMO_NUM_CS 5 | ||
22 | |||
23 | struct pismo_cs_block { | ||
24 | u8 type; | ||
25 | u8 width; | ||
26 | __le16 access; | ||
27 | __le32 size; | ||
28 | u32 reserved[2]; | ||
29 | char device[32]; | ||
30 | } __packed; | ||
31 | |||
32 | struct pismo_eeprom { | ||
33 | struct pismo_cs_block cs[PISMO_NUM_CS]; | ||
34 | char board[15]; | ||
35 | u8 sum; | ||
36 | } __packed; | ||
37 | |||
38 | struct pismo_mem { | ||
39 | phys_addr_t base; | ||
40 | u32 size; | ||
41 | u16 access; | ||
42 | u8 width; | ||
43 | u8 type; | ||
44 | }; | ||
45 | |||
46 | struct pismo_data { | ||
47 | struct i2c_client *client; | ||
48 | void (*vpp)(void *, int); | ||
49 | void *vpp_data; | ||
50 | struct platform_device *dev[PISMO_NUM_CS]; | ||
51 | }; | ||
52 | |||
53 | /* FIXME: set_vpp could do with a better calling convention */ | ||
54 | static struct pismo_data *vpp_pismo; | ||
55 | static DEFINE_MUTEX(pismo_mutex); | ||
56 | |||
57 | static int pismo_setvpp_probe_fix(struct pismo_data *pismo) | ||
58 | { | ||
59 | mutex_lock(&pismo_mutex); | ||
60 | if (vpp_pismo) { | ||
61 | mutex_unlock(&pismo_mutex); | ||
62 | kfree(pismo); | ||
63 | return -EBUSY; | ||
64 | } | ||
65 | vpp_pismo = pismo; | ||
66 | mutex_unlock(&pismo_mutex); | ||
67 | return 0; | ||
68 | } | ||
69 | |||
70 | static void pismo_setvpp_remove_fix(struct pismo_data *pismo) | ||
71 | { | ||
72 | mutex_lock(&pismo_mutex); | ||
73 | if (vpp_pismo == pismo) | ||
74 | vpp_pismo = NULL; | ||
75 | mutex_unlock(&pismo_mutex); | ||
76 | } | ||
77 | |||
78 | static void pismo_set_vpp(struct map_info *map, int on) | ||
79 | { | ||
80 | struct pismo_data *pismo = vpp_pismo; | ||
81 | |||
82 | pismo->vpp(pismo->vpp_data, on); | ||
83 | } | ||
84 | /* end of hack */ | ||
85 | |||
86 | |||
87 | static unsigned int __devinit pismo_width_to_bytes(unsigned int width) | ||
88 | { | ||
89 | width &= 15; | ||
90 | if (width > 2) | ||
91 | return 0; | ||
92 | return 1 << width; | ||
93 | } | ||
94 | |||
95 | static int __devinit pismo_eeprom_read(struct i2c_client *client, void *buf, | ||
96 | u8 addr, size_t size) | ||
97 | { | ||
98 | int ret; | ||
99 | struct i2c_msg msg[] = { | ||
100 | { | ||
101 | .addr = client->addr, | ||
102 | .len = sizeof(addr), | ||
103 | .buf = &addr, | ||
104 | }, { | ||
105 | .addr = client->addr, | ||
106 | .flags = I2C_M_RD, | ||
107 | .len = size, | ||
108 | .buf = buf, | ||
109 | }, | ||
110 | }; | ||
111 | |||
112 | ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg)); | ||
113 | |||
114 | return ret == ARRAY_SIZE(msg) ? size : -EIO; | ||
115 | } | ||
116 | |||
117 | static int __devinit pismo_add_device(struct pismo_data *pismo, int i, | ||
118 | struct pismo_mem *region, const char *name, void *pdata, size_t psize) | ||
119 | { | ||
120 | struct platform_device *dev; | ||
121 | struct resource res = { }; | ||
122 | phys_addr_t base = region->base; | ||
123 | int ret; | ||
124 | |||
125 | if (base == ~0) | ||
126 | return -ENXIO; | ||
127 | |||
128 | res.start = base; | ||
129 | res.end = base + region->size - 1; | ||
130 | res.flags = IORESOURCE_MEM; | ||
131 | |||
132 | dev = platform_device_alloc(name, i); | ||
133 | if (!dev) | ||
134 | return -ENOMEM; | ||
135 | dev->dev.parent = &pismo->client->dev; | ||
136 | |||
137 | do { | ||
138 | ret = platform_device_add_resources(dev, &res, 1); | ||
139 | if (ret) | ||
140 | break; | ||
141 | |||
142 | ret = platform_device_add_data(dev, pdata, psize); | ||
143 | if (ret) | ||
144 | break; | ||
145 | |||
146 | ret = platform_device_add(dev); | ||
147 | if (ret) | ||
148 | break; | ||
149 | |||
150 | pismo->dev[i] = dev; | ||
151 | return 0; | ||
152 | } while (0); | ||
153 | |||
154 | platform_device_put(dev); | ||
155 | return ret; | ||
156 | } | ||
157 | |||
158 | static int __devinit pismo_add_nor(struct pismo_data *pismo, int i, | ||
159 | struct pismo_mem *region) | ||
160 | { | ||
161 | struct physmap_flash_data data = { | ||
162 | .width = region->width, | ||
163 | }; | ||
164 | |||
165 | if (pismo->vpp) | ||
166 | data.set_vpp = pismo_set_vpp; | ||
167 | |||
168 | return pismo_add_device(pismo, i, region, "physmap-flash", | ||
169 | &data, sizeof(data)); | ||
170 | } | ||
171 | |||
172 | static int __devinit pismo_add_sram(struct pismo_data *pismo, int i, | ||
173 | struct pismo_mem *region) | ||
174 | { | ||
175 | struct platdata_mtd_ram data = { | ||
176 | .bankwidth = region->width, | ||
177 | }; | ||
178 | |||
179 | return pismo_add_device(pismo, i, region, "mtd-ram", | ||
180 | &data, sizeof(data)); | ||
181 | } | ||
182 | |||
183 | static void __devinit pismo_add_one(struct pismo_data *pismo, int i, | ||
184 | const struct pismo_cs_block *cs, phys_addr_t base) | ||
185 | { | ||
186 | struct device *dev = &pismo->client->dev; | ||
187 | struct pismo_mem region; | ||
188 | |||
189 | region.base = base; | ||
190 | region.type = cs->type; | ||
191 | region.width = pismo_width_to_bytes(cs->width); | ||
192 | region.access = le16_to_cpu(cs->access); | ||
193 | region.size = le32_to_cpu(cs->size); | ||
194 | |||
195 | if (region.width == 0) { | ||
196 | dev_err(dev, "cs%u: bad width: %02x, ignoring\n", i, cs->width); | ||
197 | return; | ||
198 | } | ||
199 | |||
200 | /* | ||
201 | * FIXME: may need to the platforms memory controller here, but at | ||
202 | * the moment we assume that it has already been correctly setup. | ||
203 | * The memory controller can also tell us the base address as well. | ||
204 | */ | ||
205 | |||
206 | dev_info(dev, "cs%u: %.32s: type %02x access %u00ps size %uK\n", | ||
207 | i, cs->device, region.type, region.access, region.size / 1024); | ||
208 | |||
209 | switch (region.type) { | ||
210 | case 0: | ||
211 | break; | ||
212 | case 1: | ||
213 | /* static DOC */ | ||
214 | break; | ||
215 | case 2: | ||
216 | /* static NOR */ | ||
217 | pismo_add_nor(pismo, i, ®ion); | ||
218 | break; | ||
219 | case 3: | ||
220 | /* static RAM */ | ||
221 | pismo_add_sram(pismo, i, ®ion); | ||
222 | break; | ||
223 | } | ||
224 | } | ||
225 | |||
226 | static int __devexit pismo_remove(struct i2c_client *client) | ||
227 | { | ||
228 | struct pismo_data *pismo = i2c_get_clientdata(client); | ||
229 | int i; | ||
230 | |||
231 | for (i = 0; i < ARRAY_SIZE(pismo->dev); i++) | ||
232 | platform_device_unregister(pismo->dev[i]); | ||
233 | |||
234 | /* FIXME: set_vpp needs saner arguments */ | ||
235 | pismo_setvpp_remove_fix(pismo); | ||
236 | |||
237 | kfree(pismo); | ||
238 | |||
239 | return 0; | ||
240 | } | ||
241 | |||
242 | static int __devinit pismo_probe(struct i2c_client *client, | ||
243 | const struct i2c_device_id *id) | ||
244 | { | ||
245 | struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent); | ||
246 | struct pismo_pdata *pdata = client->dev.platform_data; | ||
247 | struct pismo_eeprom eeprom; | ||
248 | struct pismo_data *pismo; | ||
249 | int ret, i; | ||
250 | |||
251 | if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) { | ||
252 | dev_err(&client->dev, "functionality mismatch\n"); | ||
253 | return -EIO; | ||
254 | } | ||
255 | |||
256 | pismo = kzalloc(sizeof(*pismo), GFP_KERNEL); | ||
257 | if (!pismo) | ||
258 | return -ENOMEM; | ||
259 | |||
260 | /* FIXME: set_vpp needs saner arguments */ | ||
261 | ret = pismo_setvpp_probe_fix(pismo); | ||
262 | if (ret) | ||
263 | return ret; | ||
264 | |||
265 | pismo->client = client; | ||
266 | if (pdata) { | ||
267 | pismo->vpp = pdata->set_vpp; | ||
268 | pismo->vpp_data = pdata->vpp_data; | ||
269 | } | ||
270 | i2c_set_clientdata(client, pismo); | ||
271 | |||
272 | ret = pismo_eeprom_read(client, &eeprom, 0, sizeof(eeprom)); | ||
273 | if (ret < 0) { | ||
274 | dev_err(&client->dev, "error reading EEPROM: %d\n", ret); | ||
275 | return ret; | ||
276 | } | ||
277 | |||
278 | dev_info(&client->dev, "%.15s board found\n", eeprom.board); | ||
279 | |||
280 | for (i = 0; i < ARRAY_SIZE(eeprom.cs); i++) | ||
281 | if (eeprom.cs[i].type != 0xff) | ||
282 | pismo_add_one(pismo, i, &eeprom.cs[i], | ||
283 | pdata->cs_addrs[i]); | ||
284 | |||
285 | return 0; | ||
286 | } | ||
287 | |||
288 | static const struct i2c_device_id pismo_id[] = { | ||
289 | { "pismo" }, | ||
290 | { }, | ||
291 | }; | ||
292 | MODULE_DEVICE_TABLE(i2c, pismo_id); | ||
293 | |||
294 | static struct i2c_driver pismo_driver = { | ||
295 | .driver = { | ||
296 | .name = "pismo", | ||
297 | .owner = THIS_MODULE, | ||
298 | }, | ||
299 | .probe = pismo_probe, | ||
300 | .remove = __devexit_p(pismo_remove), | ||
301 | .id_table = pismo_id, | ||
302 | }; | ||
303 | |||
304 | static int __init pismo_init(void) | ||
305 | { | ||
306 | BUILD_BUG_ON(sizeof(struct pismo_cs_block) != 48); | ||
307 | BUILD_BUG_ON(sizeof(struct pismo_eeprom) != 256); | ||
308 | |||
309 | return i2c_add_driver(&pismo_driver); | ||
310 | } | ||
311 | module_init(pismo_init); | ||
312 | |||
313 | static void __exit pismo_exit(void) | ||
314 | { | ||
315 | i2c_del_driver(&pismo_driver); | ||
316 | } | ||
317 | module_exit(pismo_exit); | ||
318 | |||
319 | MODULE_AUTHOR("Russell King <linux@arm.linux.org.uk>"); | ||
320 | MODULE_DESCRIPTION("PISMO memory driver"); | ||
321 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c index dafb91944e70..76a76be5a7bd 100644 --- a/drivers/mtd/maps/plat-ram.c +++ b/drivers/mtd/maps/plat-ram.c | |||
@@ -4,7 +4,7 @@ | |||
4 | * http://www.simtec.co.uk/products/SWLINUX/ | 4 | * http://www.simtec.co.uk/products/SWLINUX/ |
5 | * Ben Dooks <ben@simtec.co.uk> | 5 | * Ben Dooks <ben@simtec.co.uk> |
6 | * | 6 | * |
7 | * Generic platfrom device based RAM map | 7 | * Generic platform device based RAM map |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c index c8fd8da4bc87..acb13fa5001c 100644 --- a/drivers/mtd/maps/pmcmsp-flash.c +++ b/drivers/mtd/maps/pmcmsp-flash.c | |||
@@ -28,6 +28,7 @@ | |||
28 | * 675 Mass Ave, Cambridge, MA 02139, USA. | 28 | * 675 Mass Ave, Cambridge, MA 02139, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include <linux/slab.h> | ||
31 | #include <linux/module.h> | 32 | #include <linux/module.h> |
32 | #include <linux/types.h> | 33 | #include <linux/types.h> |
33 | #include <linux/kernel.h> | 34 | #include <linux/kernel.h> |
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 74fa075c838a..91dc6331053f 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c | |||
@@ -11,6 +11,7 @@ | |||
11 | 11 | ||
12 | #include <linux/module.h> | 12 | #include <linux/module.h> |
13 | #include <linux/types.h> | 13 | #include <linux/types.h> |
14 | #include <linux/slab.h> | ||
14 | #include <linux/kernel.h> | 15 | #include <linux/kernel.h> |
15 | #include <linux/init.h> | 16 | #include <linux/init.h> |
16 | #include <linux/platform_device.h> | 17 | #include <linux/platform_device.h> |
@@ -20,14 +21,23 @@ | |||
20 | 21 | ||
21 | #include <asm/io.h> | 22 | #include <asm/io.h> |
22 | #include <mach/hardware.h> | 23 | #include <mach/hardware.h> |
23 | #include <asm/cacheflush.h> | ||
24 | 24 | ||
25 | #include <asm/mach/flash.h> | 25 | #include <asm/mach/flash.h> |
26 | 26 | ||
27 | #define CACHELINESIZE 32 | ||
28 | |||
27 | static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from, | 29 | static void pxa2xx_map_inval_cache(struct map_info *map, unsigned long from, |
28 | ssize_t len) | 30 | ssize_t len) |
29 | { | 31 | { |
30 | flush_ioremap_region(map->phys, map->cached, from, len); | 32 | unsigned long start = (unsigned long)map->cached + from; |
33 | unsigned long end = start + len; | ||
34 | |||
35 | start &= ~(CACHELINESIZE - 1); | ||
36 | while (start < end) { | ||
37 | /* invalidate D cache line */ | ||
38 | asm volatile ("mcr p15, 0, %0, c7, c6, 1" : : "r" (start)); | ||
39 | start += CACHELINESIZE; | ||
40 | } | ||
31 | } | 41 | } |
32 | 42 | ||
33 | struct pxa2xx_flash_info { | 43 | struct pxa2xx_flash_info { |
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index d7a47574d21e..f3af87e08ecd 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c | |||
@@ -248,7 +248,7 @@ static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *pla | |||
248 | plat->exit(); | 248 | plat->exit(); |
249 | } | 249 | } |
250 | 250 | ||
251 | static struct sa_info *__init | 251 | static struct sa_info *__devinit |
252 | sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat) | 252 | sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat) |
253 | { | 253 | { |
254 | struct sa_info *info; | 254 | struct sa_info *info; |
diff --git a/drivers/mtd/maps/sbc_gxx.c b/drivers/mtd/maps/sbc_gxx.c index 1b1c0b7e11ef..04b2781fc627 100644 --- a/drivers/mtd/maps/sbc_gxx.c +++ b/drivers/mtd/maps/sbc_gxx.c | |||
@@ -45,7 +45,6 @@ separate MTD devices. | |||
45 | // Includes | 45 | // Includes |
46 | 46 | ||
47 | #include <linux/module.h> | 47 | #include <linux/module.h> |
48 | #include <linux/slab.h> | ||
49 | #include <linux/ioport.h> | 48 | #include <linux/ioport.h> |
50 | #include <linux/init.h> | 49 | #include <linux/init.h> |
51 | #include <asm/io.h> | 50 | #include <asm/io.h> |
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c index fd7a1017399a..fadc4c45b455 100644 --- a/drivers/mtd/maps/sun_uflash.c +++ b/drivers/mtd/maps/sun_uflash.c | |||
@@ -15,6 +15,7 @@ | |||
15 | #include <linux/ioport.h> | 15 | #include <linux/ioport.h> |
16 | #include <linux/of.h> | 16 | #include <linux/of.h> |
17 | #include <linux/of_device.h> | 17 | #include <linux/of_device.h> |
18 | #include <linux/slab.h> | ||
18 | #include <asm/prom.h> | 19 | #include <asm/prom.h> |
19 | #include <asm/uaccess.h> | 20 | #include <asm/uaccess.h> |
20 | #include <asm/io.h> | 21 | #include <asm/io.h> |
diff --git a/drivers/mtd/maps/vmax301.c b/drivers/mtd/maps/vmax301.c index 6d452dcdfe34..6adaa6acc193 100644 --- a/drivers/mtd/maps/vmax301.c +++ b/drivers/mtd/maps/vmax301.c | |||
@@ -16,7 +16,6 @@ | |||
16 | ##################################################################### */ | 16 | ##################################################################### */ |
17 | 17 | ||
18 | #include <linux/module.h> | 18 | #include <linux/module.h> |
19 | #include <linux/slab.h> | ||
20 | #include <linux/ioport.h> | 19 | #include <linux/ioport.h> |
21 | #include <linux/init.h> | 20 | #include <linux/init.h> |
22 | #include <linux/spinlock.h> | 21 | #include <linux/spinlock.h> |
diff --git a/drivers/mtd/maps/vmu-flash.c b/drivers/mtd/maps/vmu-flash.c index 1f73297e7776..4afc167731ef 100644 --- a/drivers/mtd/maps/vmu-flash.c +++ b/drivers/mtd/maps/vmu-flash.c | |||
@@ -8,6 +8,7 @@ | |||
8 | * GNU General Public Licence | 8 | * GNU General Public Licence |
9 | */ | 9 | */ |
10 | #include <linux/init.h> | 10 | #include <linux/init.h> |
11 | #include <linux/slab.h> | ||
11 | #include <linux/sched.h> | 12 | #include <linux/sched.h> |
12 | #include <linux/delay.h> | 13 | #include <linux/delay.h> |
13 | #include <linux/maple.h> | 14 | #include <linux/maple.h> |
@@ -612,16 +613,15 @@ static int __devinit vmu_connect(struct maple_device *mdev) | |||
612 | 613 | ||
613 | test_flash_data = be32_to_cpu(mdev->devinfo.function); | 614 | test_flash_data = be32_to_cpu(mdev->devinfo.function); |
614 | /* Need to count how many bits are set - to find out which | 615 | /* Need to count how many bits are set - to find out which |
615 | * function_data element has details of the memory card: | 616 | * function_data element has details of the memory card |
616 | * using Brian Kernighan's/Peter Wegner's method */ | 617 | */ |
617 | for (c = 0; test_flash_data; c++) | 618 | c = hweight_long(test_flash_data); |
618 | test_flash_data &= test_flash_data - 1; | ||
619 | 619 | ||
620 | basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]); | 620 | basic_flash_data = be32_to_cpu(mdev->devinfo.function_data[c - 1]); |
621 | 621 | ||
622 | card = kmalloc(sizeof(struct memcard), GFP_KERNEL); | 622 | card = kmalloc(sizeof(struct memcard), GFP_KERNEL); |
623 | if (!card) { | 623 | if (!card) { |
624 | error = ENOMEM; | 624 | error = -ENOMEM; |
625 | goto fail_nomem; | 625 | goto fail_nomem; |
626 | } | 626 | } |
627 | 627 | ||
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 8ca17a3e96ea..c82e09bbc5fd 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c | |||
@@ -59,12 +59,14 @@ static int do_blktrans_request(struct mtd_blktrans_ops *tr, | |||
59 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) | 59 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) |
60 | if (tr->readsect(dev, block, buf)) | 60 | if (tr->readsect(dev, block, buf)) |
61 | return -EIO; | 61 | return -EIO; |
62 | rq_flush_dcache_pages(req); | ||
62 | return 0; | 63 | return 0; |
63 | 64 | ||
64 | case WRITE: | 65 | case WRITE: |
65 | if (!tr->writesect) | 66 | if (!tr->writesect) |
66 | return -EIO; | 67 | return -EIO; |
67 | 68 | ||
69 | rq_flush_dcache_pages(req); | ||
68 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) | 70 | for (; nsect > 0; nsect--, block++, buf += tr->blksize) |
69 | if (tr->writesect(dev, block, buf)) | 71 | if (tr->writesect(dev, block, buf)) |
70 | return -EIO; | 72 | return -EIO; |
@@ -82,9 +84,6 @@ static int mtd_blktrans_thread(void *arg) | |||
82 | struct request_queue *rq = tr->blkcore_priv->rq; | 84 | struct request_queue *rq = tr->blkcore_priv->rq; |
83 | struct request *req = NULL; | 85 | struct request *req = NULL; |
84 | 86 | ||
85 | /* we might get involved when memory gets low, so use PF_MEMALLOC */ | ||
86 | current->flags |= PF_MEMALLOC; | ||
87 | |||
88 | spin_lock_irq(rq->queue_lock); | 87 | spin_lock_irq(rq->queue_lock); |
89 | 88 | ||
90 | while (!kthread_should_stop()) { | 89 | while (!kthread_should_stop()) { |
@@ -379,7 +378,7 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr) | |||
379 | tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr, | 378 | tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr, |
380 | "%sd", tr->name); | 379 | "%sd", tr->name); |
381 | if (IS_ERR(tr->blkcore_priv->thread)) { | 380 | if (IS_ERR(tr->blkcore_priv->thread)) { |
382 | int ret = PTR_ERR(tr->blkcore_priv->thread); | 381 | ret = PTR_ERR(tr->blkcore_priv->thread); |
383 | blk_cleanup_queue(tr->blkcore_priv->rq); | 382 | blk_cleanup_queue(tr->blkcore_priv->rq); |
384 | unregister_blkdev(tr->major, tr->name); | 383 | unregister_blkdev(tr->major, tr->name); |
385 | kfree(tr->blkcore_priv); | 384 | kfree(tr->blkcore_priv); |
diff --git a/drivers/mtd/mtdbdi.c b/drivers/mtd/mtdbdi.c deleted file mode 100644 index 5ca5aed0b225..000000000000 --- a/drivers/mtd/mtdbdi.c +++ /dev/null | |||
@@ -1,43 +0,0 @@ | |||
1 | /* MTD backing device capabilities | ||
2 | * | ||
3 | * Copyright © 2006 Red Hat, Inc. All Rights Reserved. | ||
4 | * Written by David Howells (dhowells@redhat.com) | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or | ||
7 | * modify it under the terms of the GNU General Public License | ||
8 | * as published by the Free Software Foundation; either version | ||
9 | * 2 of the License, or (at your option) any later version. | ||
10 | */ | ||
11 | |||
12 | #include <linux/backing-dev.h> | ||
13 | #include <linux/mtd/mtd.h> | ||
14 | #include "internal.h" | ||
15 | |||
16 | /* | ||
17 | * backing device capabilities for non-mappable devices (such as NAND flash) | ||
18 | * - permits private mappings, copies are taken of the data | ||
19 | */ | ||
20 | struct backing_dev_info mtd_bdi_unmappable = { | ||
21 | .capabilities = BDI_CAP_MAP_COPY, | ||
22 | }; | ||
23 | |||
24 | /* | ||
25 | * backing device capabilities for R/O mappable devices (such as ROM) | ||
26 | * - permits private mappings, copies are taken of the data | ||
27 | * - permits non-writable shared mappings | ||
28 | */ | ||
29 | struct backing_dev_info mtd_bdi_ro_mappable = { | ||
30 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
31 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP), | ||
32 | }; | ||
33 | |||
34 | /* | ||
35 | * backing device capabilities for writable mappable devices (such as RAM) | ||
36 | * - permits private mappings, copies are taken of the data | ||
37 | * - permits non-writable shared mappings | ||
38 | */ | ||
39 | struct backing_dev_info mtd_bdi_rw_mappable = { | ||
40 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
41 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP | | ||
42 | BDI_CAP_WRITE_MAP), | ||
43 | }; | ||
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 467a4f177bfb..b177e750efc3 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c | |||
@@ -2,12 +2,14 @@ | |||
2 | * Core registration and callback routines for MTD | 2 | * Core registration and callback routines for MTD |
3 | * drivers and users. | 3 | * drivers and users. |
4 | * | 4 | * |
5 | * bdi bits are: | ||
6 | * Copyright © 2006 Red Hat, Inc. All Rights Reserved. | ||
7 | * Written by David Howells (dhowells@redhat.com) | ||
5 | */ | 8 | */ |
6 | 9 | ||
7 | #include <linux/module.h> | 10 | #include <linux/module.h> |
8 | #include <linux/kernel.h> | 11 | #include <linux/kernel.h> |
9 | #include <linux/ptrace.h> | 12 | #include <linux/ptrace.h> |
10 | #include <linux/slab.h> | ||
11 | #include <linux/string.h> | 13 | #include <linux/string.h> |
12 | #include <linux/timer.h> | 14 | #include <linux/timer.h> |
13 | #include <linux/major.h> | 15 | #include <linux/major.h> |
@@ -17,11 +19,39 @@ | |||
17 | #include <linux/init.h> | 19 | #include <linux/init.h> |
18 | #include <linux/mtd/compatmac.h> | 20 | #include <linux/mtd/compatmac.h> |
19 | #include <linux/proc_fs.h> | 21 | #include <linux/proc_fs.h> |
22 | #include <linux/backing-dev.h> | ||
20 | 23 | ||
21 | #include <linux/mtd/mtd.h> | 24 | #include <linux/mtd/mtd.h> |
22 | #include "internal.h" | ||
23 | 25 | ||
24 | #include "mtdcore.h" | 26 | #include "mtdcore.h" |
27 | /* | ||
28 | * backing device capabilities for non-mappable devices (such as NAND flash) | ||
29 | * - permits private mappings, copies are taken of the data | ||
30 | */ | ||
31 | struct backing_dev_info mtd_bdi_unmappable = { | ||
32 | .capabilities = BDI_CAP_MAP_COPY, | ||
33 | }; | ||
34 | |||
35 | /* | ||
36 | * backing device capabilities for R/O mappable devices (such as ROM) | ||
37 | * - permits private mappings, copies are taken of the data | ||
38 | * - permits non-writable shared mappings | ||
39 | */ | ||
40 | struct backing_dev_info mtd_bdi_ro_mappable = { | ||
41 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
42 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP), | ||
43 | }; | ||
44 | |||
45 | /* | ||
46 | * backing device capabilities for writable mappable devices (such as RAM) | ||
47 | * - permits private mappings, copies are taken of the data | ||
48 | * - permits non-writable shared mappings | ||
49 | */ | ||
50 | struct backing_dev_info mtd_bdi_rw_mappable = { | ||
51 | .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT | | ||
52 | BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP | | ||
53 | BDI_CAP_WRITE_MAP), | ||
54 | }; | ||
25 | 55 | ||
26 | static int mtd_cls_suspend(struct device *dev, pm_message_t state); | 56 | static int mtd_cls_suspend(struct device *dev, pm_message_t state); |
27 | static int mtd_cls_resume(struct device *dev); | 57 | static int mtd_cls_resume(struct device *dev); |
@@ -447,7 +477,7 @@ struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) | |||
447 | for (i=0; i< MAX_MTD_DEVICES; i++) | 477 | for (i=0; i< MAX_MTD_DEVICES; i++) |
448 | if (mtd_table[i] == mtd) | 478 | if (mtd_table[i] == mtd) |
449 | ret = mtd_table[i]; | 479 | ret = mtd_table[i]; |
450 | } else if (num < MAX_MTD_DEVICES) { | 480 | } else if (num >= 0 && num < MAX_MTD_DEVICES) { |
451 | ret = mtd_table[num]; | 481 | ret = mtd_table[num]; |
452 | if (mtd && mtd != ret) | 482 | if (mtd && mtd != ret) |
453 | ret = NULL; | 483 | ret = NULL; |
@@ -629,20 +659,55 @@ done: | |||
629 | /*====================================================================*/ | 659 | /*====================================================================*/ |
630 | /* Init code */ | 660 | /* Init code */ |
631 | 661 | ||
662 | static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name) | ||
663 | { | ||
664 | int ret; | ||
665 | |||
666 | ret = bdi_init(bdi); | ||
667 | if (!ret) | ||
668 | ret = bdi_register(bdi, NULL, name); | ||
669 | |||
670 | if (ret) | ||
671 | bdi_destroy(bdi); | ||
672 | |||
673 | return ret; | ||
674 | } | ||
675 | |||
632 | static int __init init_mtd(void) | 676 | static int __init init_mtd(void) |
633 | { | 677 | { |
634 | int ret; | 678 | int ret; |
679 | |||
635 | ret = class_register(&mtd_class); | 680 | ret = class_register(&mtd_class); |
681 | if (ret) | ||
682 | goto err_reg; | ||
683 | |||
684 | ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap"); | ||
685 | if (ret) | ||
686 | goto err_bdi1; | ||
687 | |||
688 | ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap"); | ||
689 | if (ret) | ||
690 | goto err_bdi2; | ||
691 | |||
692 | ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap"); | ||
693 | if (ret) | ||
694 | goto err_bdi3; | ||
636 | 695 | ||
637 | if (ret) { | ||
638 | pr_err("Error registering mtd class: %d\n", ret); | ||
639 | return ret; | ||
640 | } | ||
641 | #ifdef CONFIG_PROC_FS | 696 | #ifdef CONFIG_PROC_FS |
642 | if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) | 697 | if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) |
643 | proc_mtd->read_proc = mtd_read_proc; | 698 | proc_mtd->read_proc = mtd_read_proc; |
644 | #endif /* CONFIG_PROC_FS */ | 699 | #endif /* CONFIG_PROC_FS */ |
645 | return 0; | 700 | return 0; |
701 | |||
702 | err_bdi3: | ||
703 | bdi_destroy(&mtd_bdi_ro_mappable); | ||
704 | err_bdi2: | ||
705 | bdi_destroy(&mtd_bdi_unmappable); | ||
706 | err_bdi1: | ||
707 | class_unregister(&mtd_class); | ||
708 | err_reg: | ||
709 | pr_err("Error registering mtd class or bdi: %d\n", ret); | ||
710 | return ret; | ||
646 | } | 711 | } |
647 | 712 | ||
648 | static void __exit cleanup_mtd(void) | 713 | static void __exit cleanup_mtd(void) |
@@ -652,6 +717,9 @@ static void __exit cleanup_mtd(void) | |||
652 | remove_proc_entry( "mtd", NULL); | 717 | remove_proc_entry( "mtd", NULL); |
653 | #endif /* CONFIG_PROC_FS */ | 718 | #endif /* CONFIG_PROC_FS */ |
654 | class_unregister(&mtd_class); | 719 | class_unregister(&mtd_class); |
720 | bdi_destroy(&mtd_bdi_unmappable); | ||
721 | bdi_destroy(&mtd_bdi_ro_mappable); | ||
722 | bdi_destroy(&mtd_bdi_rw_mappable); | ||
655 | } | 723 | } |
656 | 724 | ||
657 | module_init(init_mtd); | 725 | module_init(init_mtd); |
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 1060337c06df..92e12df0917f 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c | |||
@@ -29,14 +29,34 @@ | |||
29 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
30 | #include <linux/wait.h> | 30 | #include <linux/wait.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/spinlock.h> | ||
33 | #include <linux/interrupt.h> | 32 | #include <linux/interrupt.h> |
34 | #include <linux/mtd/mtd.h> | 33 | #include <linux/mtd/mtd.h> |
34 | #include <linux/kmsg_dump.h> | ||
35 | |||
36 | /* Maximum MTD partition size */ | ||
37 | #define MTDOOPS_MAX_MTD_SIZE (8 * 1024 * 1024) | ||
35 | 38 | ||
36 | #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 | 39 | #define MTDOOPS_KERNMSG_MAGIC 0x5d005d00 |
37 | #define OOPS_PAGE_SIZE 4096 | 40 | #define MTDOOPS_HEADER_SIZE 8 |
41 | |||
42 | static unsigned long record_size = 4096; | ||
43 | module_param(record_size, ulong, 0400); | ||
44 | MODULE_PARM_DESC(record_size, | ||
45 | "record size for MTD OOPS pages in bytes (default 4096)"); | ||
46 | |||
47 | static char mtddev[80]; | ||
48 | module_param_string(mtddev, mtddev, 80, 0400); | ||
49 | MODULE_PARM_DESC(mtddev, | ||
50 | "name or index number of the MTD device to use"); | ||
51 | |||
52 | static int dump_oops = 1; | ||
53 | module_param(dump_oops, int, 0600); | ||
54 | MODULE_PARM_DESC(dump_oops, | ||
55 | "set to 1 to dump oopses, 0 to only dump panics (default 1)"); | ||
38 | 56 | ||
39 | static struct mtdoops_context { | 57 | static struct mtdoops_context { |
58 | struct kmsg_dumper dump; | ||
59 | |||
40 | int mtd_index; | 60 | int mtd_index; |
41 | struct work_struct work_erase; | 61 | struct work_struct work_erase; |
42 | struct work_struct work_write; | 62 | struct work_struct work_write; |
@@ -44,28 +64,43 @@ static struct mtdoops_context { | |||
44 | int oops_pages; | 64 | int oops_pages; |
45 | int nextpage; | 65 | int nextpage; |
46 | int nextcount; | 66 | int nextcount; |
47 | char *name; | 67 | unsigned long *oops_page_used; |
48 | 68 | ||
49 | void *oops_buf; | 69 | void *oops_buf; |
50 | |||
51 | /* writecount and disabling ready are spin lock protected */ | ||
52 | spinlock_t writecount_lock; | ||
53 | int ready; | ||
54 | int writecount; | ||
55 | } oops_cxt; | 70 | } oops_cxt; |
56 | 71 | ||
72 | static void mark_page_used(struct mtdoops_context *cxt, int page) | ||
73 | { | ||
74 | set_bit(page, cxt->oops_page_used); | ||
75 | } | ||
76 | |||
77 | static void mark_page_unused(struct mtdoops_context *cxt, int page) | ||
78 | { | ||
79 | clear_bit(page, cxt->oops_page_used); | ||
80 | } | ||
81 | |||
82 | static int page_is_used(struct mtdoops_context *cxt, int page) | ||
83 | { | ||
84 | return test_bit(page, cxt->oops_page_used); | ||
85 | } | ||
86 | |||
57 | static void mtdoops_erase_callback(struct erase_info *done) | 87 | static void mtdoops_erase_callback(struct erase_info *done) |
58 | { | 88 | { |
59 | wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv; | 89 | wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv; |
60 | wake_up(wait_q); | 90 | wake_up(wait_q); |
61 | } | 91 | } |
62 | 92 | ||
63 | static int mtdoops_erase_block(struct mtd_info *mtd, int offset) | 93 | static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) |
64 | { | 94 | { |
95 | struct mtd_info *mtd = cxt->mtd; | ||
96 | u32 start_page_offset = mtd_div_by_eb(offset, mtd) * mtd->erasesize; | ||
97 | u32 start_page = start_page_offset / record_size; | ||
98 | u32 erase_pages = mtd->erasesize / record_size; | ||
65 | struct erase_info erase; | 99 | struct erase_info erase; |
66 | DECLARE_WAITQUEUE(wait, current); | 100 | DECLARE_WAITQUEUE(wait, current); |
67 | wait_queue_head_t wait_q; | 101 | wait_queue_head_t wait_q; |
68 | int ret; | 102 | int ret; |
103 | int page; | ||
69 | 104 | ||
70 | init_waitqueue_head(&wait_q); | 105 | init_waitqueue_head(&wait_q); |
71 | erase.mtd = mtd; | 106 | erase.mtd = mtd; |
@@ -81,25 +116,24 @@ static int mtdoops_erase_block(struct mtd_info *mtd, int offset) | |||
81 | if (ret) { | 116 | if (ret) { |
82 | set_current_state(TASK_RUNNING); | 117 | set_current_state(TASK_RUNNING); |
83 | remove_wait_queue(&wait_q, &wait); | 118 | remove_wait_queue(&wait_q, &wait); |
84 | printk (KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] " | 119 | printk(KERN_WARNING "mtdoops: erase of region [0x%llx, 0x%llx] on \"%s\" failed\n", |
85 | "on \"%s\" failed\n", | 120 | (unsigned long long)erase.addr, |
86 | (unsigned long long)erase.addr, (unsigned long long)erase.len, mtd->name); | 121 | (unsigned long long)erase.len, mtddev); |
87 | return ret; | 122 | return ret; |
88 | } | 123 | } |
89 | 124 | ||
90 | schedule(); /* Wait for erase to finish. */ | 125 | schedule(); /* Wait for erase to finish. */ |
91 | remove_wait_queue(&wait_q, &wait); | 126 | remove_wait_queue(&wait_q, &wait); |
92 | 127 | ||
128 | /* Mark pages as unused */ | ||
129 | for (page = start_page; page < start_page + erase_pages; page++) | ||
130 | mark_page_unused(cxt, page); | ||
131 | |||
93 | return 0; | 132 | return 0; |
94 | } | 133 | } |
95 | 134 | ||
96 | static void mtdoops_inc_counter(struct mtdoops_context *cxt) | 135 | static void mtdoops_inc_counter(struct mtdoops_context *cxt) |
97 | { | 136 | { |
98 | struct mtd_info *mtd = cxt->mtd; | ||
99 | size_t retlen; | ||
100 | u32 count; | ||
101 | int ret; | ||
102 | |||
103 | cxt->nextpage++; | 137 | cxt->nextpage++; |
104 | if (cxt->nextpage >= cxt->oops_pages) | 138 | if (cxt->nextpage >= cxt->oops_pages) |
105 | cxt->nextpage = 0; | 139 | cxt->nextpage = 0; |
@@ -107,25 +141,13 @@ static void mtdoops_inc_counter(struct mtdoops_context *cxt) | |||
107 | if (cxt->nextcount == 0xffffffff) | 141 | if (cxt->nextcount == 0xffffffff) |
108 | cxt->nextcount = 0; | 142 | cxt->nextcount = 0; |
109 | 143 | ||
110 | ret = mtd->read(mtd, cxt->nextpage * OOPS_PAGE_SIZE, 4, | 144 | if (page_is_used(cxt, cxt->nextpage)) { |
111 | &retlen, (u_char *) &count); | ||
112 | if ((retlen != 4) || ((ret < 0) && (ret != -EUCLEAN))) { | ||
113 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 4 read)" | ||
114 | ", err %d.\n", cxt->nextpage * OOPS_PAGE_SIZE, | ||
115 | retlen, ret); | ||
116 | schedule_work(&cxt->work_erase); | 145 | schedule_work(&cxt->work_erase); |
117 | return; | 146 | return; |
118 | } | 147 | } |
119 | 148 | ||
120 | /* See if we need to erase the next block */ | 149 | printk(KERN_DEBUG "mtdoops: ready %d, %d (no erase)\n", |
121 | if (count != 0xffffffff) { | 150 | cxt->nextpage, cxt->nextcount); |
122 | schedule_work(&cxt->work_erase); | ||
123 | return; | ||
124 | } | ||
125 | |||
126 | printk(KERN_DEBUG "mtdoops: Ready %d, %d (no erase)\n", | ||
127 | cxt->nextpage, cxt->nextcount); | ||
128 | cxt->ready = 1; | ||
129 | } | 151 | } |
130 | 152 | ||
131 | /* Scheduled work - when we can't proceed without erasing a block */ | 153 | /* Scheduled work - when we can't proceed without erasing a block */ |
@@ -140,47 +162,47 @@ static void mtdoops_workfunc_erase(struct work_struct *work) | |||
140 | if (!mtd) | 162 | if (!mtd) |
141 | return; | 163 | return; |
142 | 164 | ||
143 | mod = (cxt->nextpage * OOPS_PAGE_SIZE) % mtd->erasesize; | 165 | mod = (cxt->nextpage * record_size) % mtd->erasesize; |
144 | if (mod != 0) { | 166 | if (mod != 0) { |
145 | cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / OOPS_PAGE_SIZE); | 167 | cxt->nextpage = cxt->nextpage + ((mtd->erasesize - mod) / record_size); |
146 | if (cxt->nextpage >= cxt->oops_pages) | 168 | if (cxt->nextpage >= cxt->oops_pages) |
147 | cxt->nextpage = 0; | 169 | cxt->nextpage = 0; |
148 | } | 170 | } |
149 | 171 | ||
150 | while (mtd->block_isbad) { | 172 | while (mtd->block_isbad) { |
151 | ret = mtd->block_isbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE); | 173 | ret = mtd->block_isbad(mtd, cxt->nextpage * record_size); |
152 | if (!ret) | 174 | if (!ret) |
153 | break; | 175 | break; |
154 | if (ret < 0) { | 176 | if (ret < 0) { |
155 | printk(KERN_ERR "mtdoops: block_isbad failed, aborting.\n"); | 177 | printk(KERN_ERR "mtdoops: block_isbad failed, aborting\n"); |
156 | return; | 178 | return; |
157 | } | 179 | } |
158 | badblock: | 180 | badblock: |
159 | printk(KERN_WARNING "mtdoops: Bad block at %08x\n", | 181 | printk(KERN_WARNING "mtdoops: bad block at %08lx\n", |
160 | cxt->nextpage * OOPS_PAGE_SIZE); | 182 | cxt->nextpage * record_size); |
161 | i++; | 183 | i++; |
162 | cxt->nextpage = cxt->nextpage + (mtd->erasesize / OOPS_PAGE_SIZE); | 184 | cxt->nextpage = cxt->nextpage + (mtd->erasesize / record_size); |
163 | if (cxt->nextpage >= cxt->oops_pages) | 185 | if (cxt->nextpage >= cxt->oops_pages) |
164 | cxt->nextpage = 0; | 186 | cxt->nextpage = 0; |
165 | if (i == (cxt->oops_pages / (mtd->erasesize / OOPS_PAGE_SIZE))) { | 187 | if (i == cxt->oops_pages / (mtd->erasesize / record_size)) { |
166 | printk(KERN_ERR "mtdoops: All blocks bad!\n"); | 188 | printk(KERN_ERR "mtdoops: all blocks bad!\n"); |
167 | return; | 189 | return; |
168 | } | 190 | } |
169 | } | 191 | } |
170 | 192 | ||
171 | for (j = 0, ret = -1; (j < 3) && (ret < 0); j++) | 193 | for (j = 0, ret = -1; (j < 3) && (ret < 0); j++) |
172 | ret = mtdoops_erase_block(mtd, cxt->nextpage * OOPS_PAGE_SIZE); | 194 | ret = mtdoops_erase_block(cxt, cxt->nextpage * record_size); |
173 | 195 | ||
174 | if (ret >= 0) { | 196 | if (ret >= 0) { |
175 | printk(KERN_DEBUG "mtdoops: Ready %d, %d \n", cxt->nextpage, cxt->nextcount); | 197 | printk(KERN_DEBUG "mtdoops: ready %d, %d\n", |
176 | cxt->ready = 1; | 198 | cxt->nextpage, cxt->nextcount); |
177 | return; | 199 | return; |
178 | } | 200 | } |
179 | 201 | ||
180 | if (mtd->block_markbad && (ret == -EIO)) { | 202 | if (mtd->block_markbad && ret == -EIO) { |
181 | ret = mtd->block_markbad(mtd, cxt->nextpage * OOPS_PAGE_SIZE); | 203 | ret = mtd->block_markbad(mtd, cxt->nextpage * record_size); |
182 | if (ret < 0) { | 204 | if (ret < 0) { |
183 | printk(KERN_ERR "mtdoops: block_markbad failed, aborting.\n"); | 205 | printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n"); |
184 | return; | 206 | return; |
185 | } | 207 | } |
186 | } | 208 | } |
@@ -191,36 +213,37 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) | |||
191 | { | 213 | { |
192 | struct mtd_info *mtd = cxt->mtd; | 214 | struct mtd_info *mtd = cxt->mtd; |
193 | size_t retlen; | 215 | size_t retlen; |
216 | u32 *hdr; | ||
194 | int ret; | 217 | int ret; |
195 | 218 | ||
196 | if (cxt->writecount < OOPS_PAGE_SIZE) | 219 | /* Add mtdoops header to the buffer */ |
197 | memset(cxt->oops_buf + cxt->writecount, 0xff, | 220 | hdr = cxt->oops_buf; |
198 | OOPS_PAGE_SIZE - cxt->writecount); | 221 | hdr[0] = cxt->nextcount; |
222 | hdr[1] = MTDOOPS_KERNMSG_MAGIC; | ||
199 | 223 | ||
200 | if (panic) | 224 | if (panic) |
201 | ret = mtd->panic_write(mtd, cxt->nextpage * OOPS_PAGE_SIZE, | 225 | ret = mtd->panic_write(mtd, cxt->nextpage * record_size, |
202 | OOPS_PAGE_SIZE, &retlen, cxt->oops_buf); | 226 | record_size, &retlen, cxt->oops_buf); |
203 | else | 227 | else |
204 | ret = mtd->write(mtd, cxt->nextpage * OOPS_PAGE_SIZE, | 228 | ret = mtd->write(mtd, cxt->nextpage * record_size, |
205 | OOPS_PAGE_SIZE, &retlen, cxt->oops_buf); | 229 | record_size, &retlen, cxt->oops_buf); |
206 | |||
207 | cxt->writecount = 0; | ||
208 | 230 | ||
209 | if ((retlen != OOPS_PAGE_SIZE) || (ret < 0)) | 231 | if (retlen != record_size || ret < 0) |
210 | printk(KERN_ERR "mtdoops: Write failure at %d (%td of %d written), err %d.\n", | 232 | printk(KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n", |
211 | cxt->nextpage * OOPS_PAGE_SIZE, retlen, OOPS_PAGE_SIZE, ret); | 233 | cxt->nextpage * record_size, retlen, record_size, ret); |
234 | mark_page_used(cxt, cxt->nextpage); | ||
235 | memset(cxt->oops_buf, 0xff, record_size); | ||
212 | 236 | ||
213 | mtdoops_inc_counter(cxt); | 237 | mtdoops_inc_counter(cxt); |
214 | } | 238 | } |
215 | 239 | ||
216 | |||
217 | static void mtdoops_workfunc_write(struct work_struct *work) | 240 | static void mtdoops_workfunc_write(struct work_struct *work) |
218 | { | 241 | { |
219 | struct mtdoops_context *cxt = | 242 | struct mtdoops_context *cxt = |
220 | container_of(work, struct mtdoops_context, work_write); | 243 | container_of(work, struct mtdoops_context, work_write); |
221 | 244 | ||
222 | mtdoops_write(cxt, 0); | 245 | mtdoops_write(cxt, 0); |
223 | } | 246 | } |
224 | 247 | ||
225 | static void find_next_position(struct mtdoops_context *cxt) | 248 | static void find_next_position(struct mtdoops_context *cxt) |
226 | { | 249 | { |
@@ -230,28 +253,33 @@ static void find_next_position(struct mtdoops_context *cxt) | |||
230 | size_t retlen; | 253 | size_t retlen; |
231 | 254 | ||
232 | for (page = 0; page < cxt->oops_pages; page++) { | 255 | for (page = 0; page < cxt->oops_pages; page++) { |
233 | ret = mtd->read(mtd, page * OOPS_PAGE_SIZE, 8, &retlen, (u_char *) &count[0]); | 256 | /* Assume the page is used */ |
234 | if ((retlen != 8) || ((ret < 0) && (ret != -EUCLEAN))) { | 257 | mark_page_used(cxt, page); |
235 | printk(KERN_ERR "mtdoops: Read failure at %d (%td of 8 read)" | 258 | ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, |
236 | ", err %d.\n", page * OOPS_PAGE_SIZE, retlen, ret); | 259 | &retlen, (u_char *) &count[0]); |
260 | if (retlen != MTDOOPS_HEADER_SIZE || | ||
261 | (ret < 0 && ret != -EUCLEAN)) { | ||
262 | printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n", | ||
263 | page * record_size, retlen, | ||
264 | MTDOOPS_HEADER_SIZE, ret); | ||
237 | continue; | 265 | continue; |
238 | } | 266 | } |
239 | 267 | ||
240 | if (count[1] != MTDOOPS_KERNMSG_MAGIC) | 268 | if (count[0] == 0xffffffff && count[1] == 0xffffffff) |
241 | continue; | 269 | mark_page_unused(cxt, page); |
242 | if (count[0] == 0xffffffff) | 270 | if (count[0] == 0xffffffff) |
243 | continue; | 271 | continue; |
244 | if (maxcount == 0xffffffff) { | 272 | if (maxcount == 0xffffffff) { |
245 | maxcount = count[0]; | 273 | maxcount = count[0]; |
246 | maxpos = page; | 274 | maxpos = page; |
247 | } else if ((count[0] < 0x40000000) && (maxcount > 0xc0000000)) { | 275 | } else if (count[0] < 0x40000000 && maxcount > 0xc0000000) { |
248 | maxcount = count[0]; | 276 | maxcount = count[0]; |
249 | maxpos = page; | 277 | maxpos = page; |
250 | } else if ((count[0] > maxcount) && (count[0] < 0xc0000000)) { | 278 | } else if (count[0] > maxcount && count[0] < 0xc0000000) { |
251 | maxcount = count[0]; | 279 | maxcount = count[0]; |
252 | maxpos = page; | 280 | maxpos = page; |
253 | } else if ((count[0] > maxcount) && (count[0] > 0xc0000000) | 281 | } else if (count[0] > maxcount && count[0] > 0xc0000000 |
254 | && (maxcount > 0x80000000)) { | 282 | && maxcount > 0x80000000) { |
255 | maxcount = count[0]; | 283 | maxcount = count[0]; |
256 | maxpos = page; | 284 | maxpos = page; |
257 | } | 285 | } |
@@ -269,187 +297,170 @@ static void find_next_position(struct mtdoops_context *cxt) | |||
269 | mtdoops_inc_counter(cxt); | 297 | mtdoops_inc_counter(cxt); |
270 | } | 298 | } |
271 | 299 | ||
272 | 300 | static void mtdoops_do_dump(struct kmsg_dumper *dumper, | |
273 | static void mtdoops_notify_add(struct mtd_info *mtd) | 301 | enum kmsg_dump_reason reason, const char *s1, unsigned long l1, |
302 | const char *s2, unsigned long l2) | ||
274 | { | 303 | { |
275 | struct mtdoops_context *cxt = &oops_cxt; | 304 | struct mtdoops_context *cxt = container_of(dumper, |
305 | struct mtdoops_context, dump); | ||
306 | unsigned long s1_start, s2_start; | ||
307 | unsigned long l1_cpy, l2_cpy; | ||
308 | char *dst; | ||
309 | |||
310 | /* Only dump oopses if dump_oops is set */ | ||
311 | if (reason == KMSG_DUMP_OOPS && !dump_oops) | ||
312 | return; | ||
276 | 313 | ||
277 | if (cxt->name && !strcmp(mtd->name, cxt->name)) | 314 | dst = cxt->oops_buf + MTDOOPS_HEADER_SIZE; /* Skip the header */ |
278 | cxt->mtd_index = mtd->index; | 315 | l2_cpy = min(l2, record_size - MTDOOPS_HEADER_SIZE); |
316 | l1_cpy = min(l1, record_size - MTDOOPS_HEADER_SIZE - l2_cpy); | ||
279 | 317 | ||
280 | if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0) | 318 | s2_start = l2 - l2_cpy; |
281 | return; | 319 | s1_start = l1 - l1_cpy; |
282 | 320 | ||
283 | if (mtd->size < (mtd->erasesize * 2)) { | 321 | memcpy(dst, s1 + s1_start, l1_cpy); |
284 | printk(KERN_ERR "MTD partition %d not big enough for mtdoops\n", | 322 | memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy); |
285 | mtd->index); | ||
286 | return; | ||
287 | } | ||
288 | 323 | ||
289 | if (mtd->erasesize < OOPS_PAGE_SIZE) { | 324 | /* Panics must be written immediately */ |
290 | printk(KERN_ERR "Eraseblock size of MTD partition %d too small\n", | 325 | if (reason != KMSG_DUMP_OOPS) { |
291 | mtd->index); | 326 | if (!cxt->mtd->panic_write) |
327 | printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); | ||
328 | else | ||
329 | mtdoops_write(cxt, 1); | ||
292 | return; | 330 | return; |
293 | } | 331 | } |
294 | 332 | ||
295 | cxt->mtd = mtd; | 333 | /* For other cases, schedule work to write it "nicely" */ |
296 | if (mtd->size > INT_MAX) | 334 | schedule_work(&cxt->work_write); |
297 | cxt->oops_pages = INT_MAX / OOPS_PAGE_SIZE; | ||
298 | else | ||
299 | cxt->oops_pages = (int)mtd->size / OOPS_PAGE_SIZE; | ||
300 | |||
301 | find_next_position(cxt); | ||
302 | |||
303 | printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index); | ||
304 | } | 335 | } |
305 | 336 | ||
306 | static void mtdoops_notify_remove(struct mtd_info *mtd) | 337 | static void mtdoops_notify_add(struct mtd_info *mtd) |
307 | { | 338 | { |
308 | struct mtdoops_context *cxt = &oops_cxt; | 339 | struct mtdoops_context *cxt = &oops_cxt; |
340 | u64 mtdoops_pages = div_u64(mtd->size, record_size); | ||
341 | int err; | ||
309 | 342 | ||
310 | if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0) | 343 | if (!strcmp(mtd->name, mtddev)) |
311 | return; | 344 | cxt->mtd_index = mtd->index; |
312 | |||
313 | cxt->mtd = NULL; | ||
314 | flush_scheduled_work(); | ||
315 | } | ||
316 | |||
317 | static void mtdoops_console_sync(void) | ||
318 | { | ||
319 | struct mtdoops_context *cxt = &oops_cxt; | ||
320 | struct mtd_info *mtd = cxt->mtd; | ||
321 | unsigned long flags; | ||
322 | 345 | ||
323 | if (!cxt->ready || !mtd || cxt->writecount == 0) | 346 | if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) |
324 | return; | 347 | return; |
325 | 348 | ||
326 | /* | 349 | if (mtd->size < mtd->erasesize * 2) { |
327 | * Once ready is 0 and we've held the lock no further writes to the | 350 | printk(KERN_ERR "mtdoops: MTD partition %d not big enough for mtdoops\n", |
328 | * buffer will happen | 351 | mtd->index); |
329 | */ | ||
330 | spin_lock_irqsave(&cxt->writecount_lock, flags); | ||
331 | if (!cxt->ready) { | ||
332 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); | ||
333 | return; | 352 | return; |
334 | } | 353 | } |
335 | cxt->ready = 0; | 354 | if (mtd->erasesize < record_size) { |
336 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); | 355 | printk(KERN_ERR "mtdoops: eraseblock size of MTD partition %d too small\n", |
337 | 356 | mtd->index); | |
338 | if (mtd->panic_write && in_interrupt()) | ||
339 | /* Interrupt context, we're going to panic so try and log */ | ||
340 | mtdoops_write(cxt, 1); | ||
341 | else | ||
342 | schedule_work(&cxt->work_write); | ||
343 | } | ||
344 | |||
345 | static void | ||
346 | mtdoops_console_write(struct console *co, const char *s, unsigned int count) | ||
347 | { | ||
348 | struct mtdoops_context *cxt = co->data; | ||
349 | struct mtd_info *mtd = cxt->mtd; | ||
350 | unsigned long flags; | ||
351 | |||
352 | if (!oops_in_progress) { | ||
353 | mtdoops_console_sync(); | ||
354 | return; | 357 | return; |
355 | } | 358 | } |
356 | 359 | if (mtd->size > MTDOOPS_MAX_MTD_SIZE) { | |
357 | if (!cxt->ready || !mtd) | 360 | printk(KERN_ERR "mtdoops: mtd%d is too large (limit is %d MiB)\n", |
361 | mtd->index, MTDOOPS_MAX_MTD_SIZE / 1024 / 1024); | ||
358 | return; | 362 | return; |
363 | } | ||
359 | 364 | ||
360 | /* Locking on writecount ensures sequential writes to the buffer */ | 365 | /* oops_page_used is a bit field */ |
361 | spin_lock_irqsave(&cxt->writecount_lock, flags); | 366 | cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages, |
362 | 367 | BITS_PER_LONG)); | |
363 | /* Check ready status didn't change whilst waiting for the lock */ | 368 | if (!cxt->oops_page_used) { |
364 | if (!cxt->ready) { | 369 | printk(KERN_ERR "mtdoops: could not allocate page array\n"); |
365 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); | ||
366 | return; | 370 | return; |
367 | } | 371 | } |
368 | 372 | ||
369 | if (cxt->writecount == 0) { | 373 | cxt->dump.dump = mtdoops_do_dump; |
370 | u32 *stamp = cxt->oops_buf; | 374 | err = kmsg_dump_register(&cxt->dump); |
371 | *stamp++ = cxt->nextcount; | 375 | if (err) { |
372 | *stamp = MTDOOPS_KERNMSG_MAGIC; | 376 | printk(KERN_ERR "mtdoops: registering kmsg dumper failed, error %d\n", err); |
373 | cxt->writecount = 8; | 377 | vfree(cxt->oops_page_used); |
378 | cxt->oops_page_used = NULL; | ||
379 | return; | ||
374 | } | 380 | } |
375 | 381 | ||
376 | if ((count + cxt->writecount) > OOPS_PAGE_SIZE) | 382 | cxt->mtd = mtd; |
377 | count = OOPS_PAGE_SIZE - cxt->writecount; | 383 | cxt->oops_pages = (int)mtd->size / record_size; |
378 | 384 | find_next_position(cxt); | |
379 | memcpy(cxt->oops_buf + cxt->writecount, s, count); | 385 | printk(KERN_INFO "mtdoops: Attached to MTD device %d\n", mtd->index); |
380 | cxt->writecount += count; | ||
381 | |||
382 | spin_unlock_irqrestore(&cxt->writecount_lock, flags); | ||
383 | |||
384 | if (cxt->writecount == OOPS_PAGE_SIZE) | ||
385 | mtdoops_console_sync(); | ||
386 | } | 386 | } |
387 | 387 | ||
388 | static int __init mtdoops_console_setup(struct console *co, char *options) | 388 | static void mtdoops_notify_remove(struct mtd_info *mtd) |
389 | { | 389 | { |
390 | struct mtdoops_context *cxt = co->data; | 390 | struct mtdoops_context *cxt = &oops_cxt; |
391 | 391 | ||
392 | if (cxt->mtd_index != -1 || cxt->name) | 392 | if (mtd->index != cxt->mtd_index || cxt->mtd_index < 0) |
393 | return -EBUSY; | 393 | return; |
394 | if (options) { | ||
395 | cxt->name = kstrdup(options, GFP_KERNEL); | ||
396 | return 0; | ||
397 | } | ||
398 | if (co->index == -1) | ||
399 | return -EINVAL; | ||
400 | 394 | ||
401 | cxt->mtd_index = co->index; | 395 | if (kmsg_dump_unregister(&cxt->dump) < 0) |
402 | return 0; | 396 | printk(KERN_WARNING "mtdoops: could not unregister kmsg_dumper\n"); |
397 | |||
398 | cxt->mtd = NULL; | ||
399 | flush_scheduled_work(); | ||
403 | } | 400 | } |
404 | 401 | ||
402 | |||
405 | static struct mtd_notifier mtdoops_notifier = { | 403 | static struct mtd_notifier mtdoops_notifier = { |
406 | .add = mtdoops_notify_add, | 404 | .add = mtdoops_notify_add, |
407 | .remove = mtdoops_notify_remove, | 405 | .remove = mtdoops_notify_remove, |
408 | }; | 406 | }; |
409 | 407 | ||
410 | static struct console mtdoops_console = { | 408 | static int __init mtdoops_init(void) |
411 | .name = "ttyMTD", | ||
412 | .write = mtdoops_console_write, | ||
413 | .setup = mtdoops_console_setup, | ||
414 | .unblank = mtdoops_console_sync, | ||
415 | .index = -1, | ||
416 | .data = &oops_cxt, | ||
417 | }; | ||
418 | |||
419 | static int __init mtdoops_console_init(void) | ||
420 | { | 409 | { |
421 | struct mtdoops_context *cxt = &oops_cxt; | 410 | struct mtdoops_context *cxt = &oops_cxt; |
411 | int mtd_index; | ||
412 | char *endp; | ||
422 | 413 | ||
414 | if (strlen(mtddev) == 0) { | ||
415 | printk(KERN_ERR "mtdoops: mtd device (mtddev=name/number) must be supplied\n"); | ||
416 | return -EINVAL; | ||
417 | } | ||
418 | if ((record_size & 4095) != 0) { | ||
419 | printk(KERN_ERR "mtdoops: record_size must be a multiple of 4096\n"); | ||
420 | return -EINVAL; | ||
421 | } | ||
422 | if (record_size < 4096) { | ||
423 | printk(KERN_ERR "mtdoops: record_size must be over 4096 bytes\n"); | ||
424 | return -EINVAL; | ||
425 | } | ||
426 | |||
427 | /* Setup the MTD device to use */ | ||
423 | cxt->mtd_index = -1; | 428 | cxt->mtd_index = -1; |
424 | cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE); | 429 | mtd_index = simple_strtoul(mtddev, &endp, 0); |
425 | spin_lock_init(&cxt->writecount_lock); | 430 | if (*endp == '\0') |
431 | cxt->mtd_index = mtd_index; | ||
432 | if (cxt->mtd_index > MAX_MTD_DEVICES) { | ||
433 | printk(KERN_ERR "mtdoops: invalid mtd device number (%u) given\n", | ||
434 | mtd_index); | ||
435 | return -EINVAL; | ||
436 | } | ||
426 | 437 | ||
438 | cxt->oops_buf = vmalloc(record_size); | ||
427 | if (!cxt->oops_buf) { | 439 | if (!cxt->oops_buf) { |
428 | printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n"); | 440 | printk(KERN_ERR "mtdoops: failed to allocate buffer workspace\n"); |
429 | return -ENOMEM; | 441 | return -ENOMEM; |
430 | } | 442 | } |
443 | memset(cxt->oops_buf, 0xff, record_size); | ||
431 | 444 | ||
432 | INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); | 445 | INIT_WORK(&cxt->work_erase, mtdoops_workfunc_erase); |
433 | INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); | 446 | INIT_WORK(&cxt->work_write, mtdoops_workfunc_write); |
434 | 447 | ||
435 | register_console(&mtdoops_console); | ||
436 | register_mtd_user(&mtdoops_notifier); | 448 | register_mtd_user(&mtdoops_notifier); |
437 | return 0; | 449 | return 0; |
438 | } | 450 | } |
439 | 451 | ||
440 | static void __exit mtdoops_console_exit(void) | 452 | static void __exit mtdoops_exit(void) |
441 | { | 453 | { |
442 | struct mtdoops_context *cxt = &oops_cxt; | 454 | struct mtdoops_context *cxt = &oops_cxt; |
443 | 455 | ||
444 | unregister_mtd_user(&mtdoops_notifier); | 456 | unregister_mtd_user(&mtdoops_notifier); |
445 | unregister_console(&mtdoops_console); | ||
446 | kfree(cxt->name); | ||
447 | vfree(cxt->oops_buf); | 457 | vfree(cxt->oops_buf); |
458 | vfree(cxt->oops_page_used); | ||
448 | } | 459 | } |
449 | 460 | ||
450 | 461 | ||
451 | subsys_initcall(mtdoops_console_init); | 462 | module_init(mtdoops_init); |
452 | module_exit(mtdoops_console_exit); | 463 | module_exit(mtdoops_exit); |
453 | 464 | ||
454 | MODULE_LICENSE("GPL"); | 465 | MODULE_LICENSE("GPL"); |
455 | MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); | 466 | MODULE_AUTHOR("Richard Purdie <rpurdie@openedhand.com>"); |
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c index af8b42e0a55b..7c003191fca4 100644 --- a/drivers/mtd/mtdsuper.c +++ b/drivers/mtd/mtdsuper.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/mtd/super.h> | 13 | #include <linux/mtd/super.h> |
14 | #include <linux/namei.h> | 14 | #include <linux/namei.h> |
15 | #include <linux/ctype.h> | 15 | #include <linux/ctype.h> |
16 | #include <linux/slab.h> | ||
16 | 17 | ||
17 | /* | 18 | /* |
18 | * compare superblocks to see if they're equivalent | 19 | * compare superblocks to see if they're equivalent |
@@ -44,6 +45,7 @@ static int get_sb_mtd_set(struct super_block *sb, void *_mtd) | |||
44 | 45 | ||
45 | sb->s_mtd = mtd; | 46 | sb->s_mtd = mtd; |
46 | sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index); | 47 | sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index); |
48 | sb->s_bdi = mtd->backing_dev_info; | ||
47 | return 0; | 49 | return 0; |
48 | } | 50 | } |
49 | 51 | ||
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index 2fda0b615246..42e5ea49e975 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/nand/Kconfig | ||
2 | |||
3 | menuconfig MTD_NAND | 1 | menuconfig MTD_NAND |
4 | tristate "NAND Device Support" | 2 | tristate "NAND Device Support" |
5 | depends on MTD | 3 | depends on MTD |
@@ -203,6 +201,22 @@ config MTD_NAND_S3C2410_CLKSTOP | |||
203 | when the is NAND chip selected or released, but will save | 201 | when the is NAND chip selected or released, but will save |
204 | approximately 5mA of power when there is nothing happening. | 202 | approximately 5mA of power when there is nothing happening. |
205 | 203 | ||
204 | config MTD_NAND_BCM_UMI | ||
205 | tristate "NAND Flash support for BCM Reference Boards" | ||
206 | depends on ARCH_BCMRING && MTD_NAND | ||
207 | help | ||
208 | This enables the NAND flash controller on the BCM UMI block. | ||
209 | |||
210 | No board specfic support is done by this driver, each board | ||
211 | must advertise a platform_device for the driver to attach. | ||
212 | |||
213 | config MTD_NAND_BCM_UMI_HWCS | ||
214 | bool "BCM UMI NAND Hardware CS" | ||
215 | depends on MTD_NAND_BCM_UMI | ||
216 | help | ||
217 | Enable the use of the BCM UMI block's internal CS using NAND. | ||
218 | This should only be used if you know the external NAND CS can toggle. | ||
219 | |||
206 | config MTD_NAND_DISKONCHIP | 220 | config MTD_NAND_DISKONCHIP |
207 | tristate "DiskOnChip 2000, Millennium and Millennium Plus (NAND reimplementation) (EXPERIMENTAL)" | 221 | tristate "DiskOnChip 2000, Millennium and Millennium Plus (NAND reimplementation) (EXPERIMENTAL)" |
208 | depends on EXPERIMENTAL | 222 | depends on EXPERIMENTAL |
@@ -277,14 +291,6 @@ config MTD_NAND_SHARPSL | |||
277 | tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" | 291 | tristate "Support for NAND Flash on Sharp SL Series (C7xx + others)" |
278 | depends on ARCH_PXA | 292 | depends on ARCH_PXA |
279 | 293 | ||
280 | config MTD_NAND_BASLER_EXCITE | ||
281 | tristate "Support for NAND Flash on Basler eXcite" | ||
282 | depends on BASLER_EXCITE | ||
283 | help | ||
284 | This enables the driver for the NAND flash device found on the | ||
285 | Basler eXcite Smart Camera. If built as a module, the driver | ||
286 | will be named excite_nandflash. | ||
287 | |||
288 | config MTD_NAND_CAFE | 294 | config MTD_NAND_CAFE |
289 | tristate "NAND support for OLPC CAFÉ chip" | 295 | tristate "NAND support for OLPC CAFÉ chip" |
290 | depends on PCI | 296 | depends on PCI |
@@ -358,7 +364,7 @@ endchoice | |||
358 | 364 | ||
359 | config MTD_NAND_PXA3xx | 365 | config MTD_NAND_PXA3xx |
360 | tristate "Support for NAND flash devices on PXA3xx" | 366 | tristate "Support for NAND flash devices on PXA3xx" |
361 | depends on MTD_NAND && PXA3xx | 367 | depends on MTD_NAND && (PXA3xx || ARCH_MMP) |
362 | help | 368 | help |
363 | This enables the driver for the NAND flash device found on | 369 | This enables the driver for the NAND flash device found on |
364 | PXA3xx processors | 370 | PXA3xx processors |
@@ -438,7 +444,7 @@ config MTD_NAND_FSL_UPM | |||
438 | 444 | ||
439 | config MTD_NAND_MXC | 445 | config MTD_NAND_MXC |
440 | tristate "MXC NAND support" | 446 | tristate "MXC NAND support" |
441 | depends on ARCH_MX2 || ARCH_MX3 | 447 | depends on ARCH_MX2 || ARCH_MX25 || ARCH_MX3 |
442 | help | 448 | help |
443 | This enables the driver for the NAND flash controller on the | 449 | This enables the driver for the NAND flash controller on the |
444 | MXC processors. | 450 | MXC processors. |
@@ -451,10 +457,10 @@ config MTD_NAND_NOMADIK | |||
451 | 457 | ||
452 | config MTD_NAND_SH_FLCTL | 458 | config MTD_NAND_SH_FLCTL |
453 | tristate "Support for NAND on Renesas SuperH FLCTL" | 459 | tristate "Support for NAND on Renesas SuperH FLCTL" |
454 | depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723 | 460 | depends on MTD_NAND && (SUPERH || ARCH_SHMOBILE) |
455 | help | 461 | help |
456 | Several Renesas SuperH CPU has FLCTL. This option enables support | 462 | Several Renesas SuperH CPU has FLCTL. This option enables support |
457 | for NAND Flash using FLCTL. This driver support SH7723. | 463 | for NAND Flash using FLCTL. |
458 | 464 | ||
459 | config MTD_NAND_DAVINCI | 465 | config MTD_NAND_DAVINCI |
460 | tristate "Support NAND on DaVinci SoC" | 466 | tristate "Support NAND on DaVinci SoC" |
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile index 6950d3dabf10..1407bd144015 100644 --- a/drivers/mtd/nand/Makefile +++ b/drivers/mtd/nand/Makefile | |||
@@ -27,7 +27,6 @@ obj-$(CONFIG_MTD_NAND_ATMEL) += atmel_nand.o | |||
27 | obj-$(CONFIG_MTD_NAND_GPIO) += gpio.o | 27 | obj-$(CONFIG_MTD_NAND_GPIO) += gpio.o |
28 | obj-$(CONFIG_MTD_NAND_OMAP2) += omap2.o | 28 | obj-$(CONFIG_MTD_NAND_OMAP2) += omap2.o |
29 | obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o | 29 | obj-$(CONFIG_MTD_NAND_CM_X270) += cmx270_nand.o |
30 | obj-$(CONFIG_MTD_NAND_BASLER_EXCITE) += excite_nandflash.o | ||
31 | obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o | 30 | obj-$(CONFIG_MTD_NAND_PXA3xx) += pxa3xx_nand.o |
32 | obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o | 31 | obj-$(CONFIG_MTD_NAND_TMIO) += tmio_nand.o |
33 | obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o | 32 | obj-$(CONFIG_MTD_NAND_PLATFORM) += plat_nand.o |
@@ -42,5 +41,6 @@ obj-$(CONFIG_MTD_NAND_SOCRATES) += socrates_nand.o | |||
42 | obj-$(CONFIG_MTD_NAND_TXX9NDFMC) += txx9ndfmc.o | 41 | obj-$(CONFIG_MTD_NAND_TXX9NDFMC) += txx9ndfmc.o |
43 | obj-$(CONFIG_MTD_NAND_W90P910) += w90p910_nand.o | 42 | obj-$(CONFIG_MTD_NAND_W90P910) += w90p910_nand.o |
44 | obj-$(CONFIG_MTD_NAND_NOMADIK) += nomadik_nand.o | 43 | obj-$(CONFIG_MTD_NAND_NOMADIK) += nomadik_nand.o |
44 | obj-$(CONFIG_MTD_NAND_BCM_UMI) += bcm_umi_nand.o nand_bcm_umi.o | ||
45 | 45 | ||
46 | nand-objs := nand_base.o nand_bbt.o | 46 | nand-objs := nand_base.o nand_bbt.o |
diff --git a/drivers/mtd/nand/alauda.c b/drivers/mtd/nand/alauda.c index 6d9649159a18..2d6773281fd9 100644 --- a/drivers/mtd/nand/alauda.c +++ b/drivers/mtd/nand/alauda.c | |||
@@ -372,15 +372,6 @@ static int alauda_read_oob(struct mtd_info *mtd, loff_t from, void *oob) | |||
372 | return __alauda_read_page(mtd, from, ignore_buf, oob); | 372 | return __alauda_read_page(mtd, from, ignore_buf, oob); |
373 | } | 373 | } |
374 | 374 | ||
375 | static int popcount8(u8 c) | ||
376 | { | ||
377 | int ret = 0; | ||
378 | |||
379 | for ( ; c; c>>=1) | ||
380 | ret += c & 1; | ||
381 | return ret; | ||
382 | } | ||
383 | |||
384 | static int alauda_isbad(struct mtd_info *mtd, loff_t ofs) | 375 | static int alauda_isbad(struct mtd_info *mtd, loff_t ofs) |
385 | { | 376 | { |
386 | u8 oob[16]; | 377 | u8 oob[16]; |
@@ -391,7 +382,7 @@ static int alauda_isbad(struct mtd_info *mtd, loff_t ofs) | |||
391 | return err; | 382 | return err; |
392 | 383 | ||
393 | /* A block is marked bad if two or more bits are zero */ | 384 | /* A block is marked bad if two or more bits are zero */ |
394 | return popcount8(oob[5]) >= 7 ? 0 : 1; | 385 | return hweight8(oob[5]) >= 7 ? 0 : 1; |
395 | } | 386 | } |
396 | 387 | ||
397 | static int alauda_bounce_read(struct mtd_info *mtd, loff_t from, size_t len, | 388 | static int alauda_bounce_read(struct mtd_info *mtd, loff_t from, size_t len, |
diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c index 005b91f096f2..2548e1065bf8 100644 --- a/drivers/mtd/nand/ams-delta.c +++ b/drivers/mtd/nand/ams-delta.c | |||
@@ -25,7 +25,7 @@ | |||
25 | #include <mach/hardware.h> | 25 | #include <mach/hardware.h> |
26 | #include <asm/sizes.h> | 26 | #include <asm/sizes.h> |
27 | #include <mach/gpio.h> | 27 | #include <mach/gpio.h> |
28 | #include <mach/board-ams-delta.h> | 28 | #include <plat/board-ams-delta.h> |
29 | 29 | ||
30 | /* | 30 | /* |
31 | * MTD structure for E3 (Delta) | 31 | * MTD structure for E3 (Delta) |
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c index f8e9975c86e5..524e6c9e0672 100644 --- a/drivers/mtd/nand/atmel_nand.c +++ b/drivers/mtd/nand/atmel_nand.c | |||
@@ -192,7 +192,6 @@ static int atmel_nand_calculate(struct mtd_info *mtd, | |||
192 | { | 192 | { |
193 | struct nand_chip *nand_chip = mtd->priv; | 193 | struct nand_chip *nand_chip = mtd->priv; |
194 | struct atmel_nand_host *host = nand_chip->priv; | 194 | struct atmel_nand_host *host = nand_chip->priv; |
195 | uint32_t *eccpos = nand_chip->ecc.layout->eccpos; | ||
196 | unsigned int ecc_value; | 195 | unsigned int ecc_value; |
197 | 196 | ||
198 | /* get the first 2 ECC bytes */ | 197 | /* get the first 2 ECC bytes */ |
@@ -464,7 +463,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev) | |||
464 | if (host->board->det_pin) { | 463 | if (host->board->det_pin) { |
465 | if (gpio_get_value(host->board->det_pin)) { | 464 | if (gpio_get_value(host->board->det_pin)) { |
466 | printk(KERN_INFO "No SmartMedia card inserted.\n"); | 465 | printk(KERN_INFO "No SmartMedia card inserted.\n"); |
467 | res = ENXIO; | 466 | res = -ENXIO; |
468 | goto err_no_card; | 467 | goto err_no_card; |
469 | } | 468 | } |
470 | } | 469 | } |
@@ -535,7 +534,7 @@ static int __init atmel_nand_probe(struct platform_device *pdev) | |||
535 | 534 | ||
536 | if ((!partitions) || (num_partitions == 0)) { | 535 | if ((!partitions) || (num_partitions == 0)) { |
537 | printk(KERN_ERR "atmel_nand: No partitions defined, or unsupported device.\n"); | 536 | printk(KERN_ERR "atmel_nand: No partitions defined, or unsupported device.\n"); |
538 | res = ENXIO; | 537 | res = -ENXIO; |
539 | goto err_no_partitions; | 538 | goto err_no_partitions; |
540 | } | 539 | } |
541 | 540 | ||
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c index 92c334ff4508..43d46e424040 100644 --- a/drivers/mtd/nand/au1550nd.c +++ b/drivers/mtd/nand/au1550nd.c | |||
@@ -19,6 +19,7 @@ | |||
19 | #include <asm/io.h> | 19 | #include <asm/io.h> |
20 | 20 | ||
21 | #include <asm/mach-au1x00/au1xxx.h> | 21 | #include <asm/mach-au1x00/au1xxx.h> |
22 | #include <asm/mach-db1x00/bcsr.h> | ||
22 | 23 | ||
23 | /* | 24 | /* |
24 | * MTD structure for NAND controller | 25 | * MTD structure for NAND controller |
@@ -475,7 +476,8 @@ static int __init au1xxx_nand_init(void) | |||
475 | /* set gpio206 high */ | 476 | /* set gpio206 high */ |
476 | au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); | 477 | au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); |
477 | 478 | ||
478 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1); | 479 | boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1); |
480 | |||
479 | switch (boot_swapboot) { | 481 | switch (boot_swapboot) { |
480 | case 0: | 482 | case 0: |
481 | case 2: | 483 | case 2: |
diff --git a/drivers/mtd/nand/bcm_umi_bch.c b/drivers/mtd/nand/bcm_umi_bch.c new file mode 100644 index 000000000000..a930666d0687 --- /dev/null +++ b/drivers/mtd/nand/bcm_umi_bch.c | |||
@@ -0,0 +1,213 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright 2004 - 2009 Broadcom Corporation. All rights reserved. | ||
3 | * | ||
4 | * Unless you and Broadcom execute a separate written software license | ||
5 | * agreement governing use of this software, this software is licensed to you | ||
6 | * under the terms of the GNU General Public License version 2, available at | ||
7 | * http://www.broadcom.com/licenses/GPLv2.php (the "GPL"). | ||
8 | * | ||
9 | * Notwithstanding the above, under no circumstances may you combine this | ||
10 | * software in any way with any other Broadcom software provided under a | ||
11 | * license other than the GPL, without Broadcom's express prior written | ||
12 | * consent. | ||
13 | *****************************************************************************/ | ||
14 | |||
15 | /* ---- Include Files ---------------------------------------------------- */ | ||
16 | #include "nand_bcm_umi.h" | ||
17 | |||
18 | /* ---- External Variable Declarations ----------------------------------- */ | ||
19 | /* ---- External Function Prototypes ------------------------------------- */ | ||
20 | /* ---- Public Variables ------------------------------------------------- */ | ||
21 | /* ---- Private Constants and Types -------------------------------------- */ | ||
22 | |||
23 | /* ---- Private Function Prototypes -------------------------------------- */ | ||
24 | static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, | ||
25 | struct nand_chip *chip, uint8_t *buf, int page); | ||
26 | static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd, | ||
27 | struct nand_chip *chip, const uint8_t *buf); | ||
28 | |||
29 | /* ---- Private Variables ------------------------------------------------ */ | ||
30 | |||
31 | /* | ||
32 | ** nand_hw_eccoob | ||
33 | ** New oob placement block for use with hardware ecc generation. | ||
34 | */ | ||
35 | static struct nand_ecclayout nand_hw_eccoob_512 = { | ||
36 | /* Reserve 5 for BI indicator */ | ||
37 | .oobfree = { | ||
38 | #if (NAND_ECC_NUM_BYTES > 3) | ||
39 | {.offset = 0, .length = 2} | ||
40 | #else | ||
41 | {.offset = 0, .length = 5}, | ||
42 | {.offset = 6, .length = 7} | ||
43 | #endif | ||
44 | } | ||
45 | }; | ||
46 | |||
47 | /* | ||
48 | ** We treat the OOB for a 2K page as if it were 4 512 byte oobs, | ||
49 | ** except the BI is at byte 0. | ||
50 | */ | ||
51 | static struct nand_ecclayout nand_hw_eccoob_2048 = { | ||
52 | /* Reserve 0 as BI indicator */ | ||
53 | .oobfree = { | ||
54 | #if (NAND_ECC_NUM_BYTES > 10) | ||
55 | {.offset = 1, .length = 2}, | ||
56 | #elif (NAND_ECC_NUM_BYTES > 7) | ||
57 | {.offset = 1, .length = 5}, | ||
58 | {.offset = 16, .length = 6}, | ||
59 | {.offset = 32, .length = 6}, | ||
60 | {.offset = 48, .length = 6} | ||
61 | #else | ||
62 | {.offset = 1, .length = 8}, | ||
63 | {.offset = 16, .length = 9}, | ||
64 | {.offset = 32, .length = 9}, | ||
65 | {.offset = 48, .length = 9} | ||
66 | #endif | ||
67 | } | ||
68 | }; | ||
69 | |||
70 | /* We treat the OOB for a 4K page as if it were 8 512 byte oobs, | ||
71 | * except the BI is at byte 0. */ | ||
72 | static struct nand_ecclayout nand_hw_eccoob_4096 = { | ||
73 | /* Reserve 0 as BI indicator */ | ||
74 | .oobfree = { | ||
75 | #if (NAND_ECC_NUM_BYTES > 10) | ||
76 | {.offset = 1, .length = 2}, | ||
77 | {.offset = 16, .length = 3}, | ||
78 | {.offset = 32, .length = 3}, | ||
79 | {.offset = 48, .length = 3}, | ||
80 | {.offset = 64, .length = 3}, | ||
81 | {.offset = 80, .length = 3}, | ||
82 | {.offset = 96, .length = 3}, | ||
83 | {.offset = 112, .length = 3} | ||
84 | #else | ||
85 | {.offset = 1, .length = 5}, | ||
86 | {.offset = 16, .length = 6}, | ||
87 | {.offset = 32, .length = 6}, | ||
88 | {.offset = 48, .length = 6}, | ||
89 | {.offset = 64, .length = 6}, | ||
90 | {.offset = 80, .length = 6}, | ||
91 | {.offset = 96, .length = 6}, | ||
92 | {.offset = 112, .length = 6} | ||
93 | #endif | ||
94 | } | ||
95 | }; | ||
96 | |||
97 | /* ---- Private Functions ------------------------------------------------ */ | ||
98 | /* ==== Public Functions ================================================= */ | ||
99 | |||
100 | /**************************************************************************** | ||
101 | * | ||
102 | * bcm_umi_bch_read_page_hwecc - hardware ecc based page read function | ||
103 | * @mtd: mtd info structure | ||
104 | * @chip: nand chip info structure | ||
105 | * @buf: buffer to store read data | ||
106 | * | ||
107 | ***************************************************************************/ | ||
108 | static int bcm_umi_bch_read_page_hwecc(struct mtd_info *mtd, | ||
109 | struct nand_chip *chip, uint8_t * buf, | ||
110 | int page) | ||
111 | { | ||
112 | int sectorIdx = 0; | ||
113 | int eccsize = chip->ecc.size; | ||
114 | int eccsteps = chip->ecc.steps; | ||
115 | uint8_t *datap = buf; | ||
116 | uint8_t eccCalc[NAND_ECC_NUM_BYTES]; | ||
117 | int sectorOobSize = mtd->oobsize / eccsteps; | ||
118 | int stat; | ||
119 | |||
120 | for (sectorIdx = 0; sectorIdx < eccsteps; | ||
121 | sectorIdx++, datap += eccsize) { | ||
122 | if (sectorIdx > 0) { | ||
123 | /* Seek to page location within sector */ | ||
124 | chip->cmdfunc(mtd, NAND_CMD_RNDOUT, sectorIdx * eccsize, | ||
125 | -1); | ||
126 | } | ||
127 | |||
128 | /* Enable hardware ECC before reading the buf */ | ||
129 | nand_bcm_umi_bch_enable_read_hwecc(); | ||
130 | |||
131 | /* Read in data */ | ||
132 | bcm_umi_nand_read_buf(mtd, datap, eccsize); | ||
133 | |||
134 | /* Pause hardware ECC after reading the buf */ | ||
135 | nand_bcm_umi_bch_pause_read_ecc_calc(); | ||
136 | |||
137 | /* Read the OOB ECC */ | ||
138 | chip->cmdfunc(mtd, NAND_CMD_RNDOUT, | ||
139 | mtd->writesize + sectorIdx * sectorOobSize, -1); | ||
140 | nand_bcm_umi_bch_read_oobEcc(mtd->writesize, eccCalc, | ||
141 | NAND_ECC_NUM_BYTES, | ||
142 | chip->oob_poi + | ||
143 | sectorIdx * sectorOobSize); | ||
144 | |||
145 | /* Correct any ECC detected errors */ | ||
146 | stat = | ||
147 | nand_bcm_umi_bch_correct_page(datap, eccCalc, | ||
148 | NAND_ECC_NUM_BYTES); | ||
149 | |||
150 | /* Update Stats */ | ||
151 | if (stat < 0) { | ||
152 | #if defined(NAND_BCM_UMI_DEBUG) | ||
153 | printk(KERN_WARNING "%s uncorr_err sectorIdx=%d\n", | ||
154 | __func__, sectorIdx); | ||
155 | printk(KERN_WARNING | ||
156 | "%s data %02x %02x %02x %02x " | ||
157 | "%02x %02x %02x %02x\n", | ||
158 | __func__, datap[0], datap[1], datap[2], datap[3], | ||
159 | datap[4], datap[5], datap[6], datap[7]); | ||
160 | printk(KERN_WARNING | ||
161 | "%s ecc %02x %02x %02x %02x " | ||
162 | "%02x %02x %02x %02x %02x %02x " | ||
163 | "%02x %02x %02x\n", | ||
164 | __func__, eccCalc[0], eccCalc[1], eccCalc[2], | ||
165 | eccCalc[3], eccCalc[4], eccCalc[5], eccCalc[6], | ||
166 | eccCalc[7], eccCalc[8], eccCalc[9], eccCalc[10], | ||
167 | eccCalc[11], eccCalc[12]); | ||
168 | BUG(); | ||
169 | #endif | ||
170 | mtd->ecc_stats.failed++; | ||
171 | } else { | ||
172 | #if defined(NAND_BCM_UMI_DEBUG) | ||
173 | if (stat > 0) { | ||
174 | printk(KERN_INFO | ||
175 | "%s %d correctable_errors detected\n", | ||
176 | __func__, stat); | ||
177 | } | ||
178 | #endif | ||
179 | mtd->ecc_stats.corrected += stat; | ||
180 | } | ||
181 | } | ||
182 | return 0; | ||
183 | } | ||
184 | |||
185 | /**************************************************************************** | ||
186 | * | ||
187 | * bcm_umi_bch_write_page_hwecc - hardware ecc based page write function | ||
188 | * @mtd: mtd info structure | ||
189 | * @chip: nand chip info structure | ||
190 | * @buf: data buffer | ||
191 | * | ||
192 | ***************************************************************************/ | ||
193 | static void bcm_umi_bch_write_page_hwecc(struct mtd_info *mtd, | ||
194 | struct nand_chip *chip, const uint8_t *buf) | ||
195 | { | ||
196 | int sectorIdx = 0; | ||
197 | int eccsize = chip->ecc.size; | ||
198 | int eccsteps = chip->ecc.steps; | ||
199 | const uint8_t *datap = buf; | ||
200 | uint8_t *oobp = chip->oob_poi; | ||
201 | int sectorOobSize = mtd->oobsize / eccsteps; | ||
202 | |||
203 | for (sectorIdx = 0; sectorIdx < eccsteps; | ||
204 | sectorIdx++, datap += eccsize, oobp += sectorOobSize) { | ||
205 | /* Enable hardware ECC before writing the buf */ | ||
206 | nand_bcm_umi_bch_enable_write_hwecc(); | ||
207 | bcm_umi_nand_write_buf(mtd, datap, eccsize); | ||
208 | nand_bcm_umi_bch_write_oobEcc(mtd->writesize, oobp, | ||
209 | NAND_ECC_NUM_BYTES); | ||
210 | } | ||
211 | |||
212 | bcm_umi_nand_write_buf(mtd, chip->oob_poi, mtd->oobsize); | ||
213 | } | ||
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c new file mode 100644 index 000000000000..c997f98eeb3d --- /dev/null +++ b/drivers/mtd/nand/bcm_umi_nand.c | |||
@@ -0,0 +1,582 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright 2004 - 2009 Broadcom Corporation. All rights reserved. | ||
3 | * | ||
4 | * Unless you and Broadcom execute a separate written software license | ||
5 | * agreement governing use of this software, this software is licensed to you | ||
6 | * under the terms of the GNU General Public License version 2, available at | ||
7 | * http://www.broadcom.com/licenses/GPLv2.php (the "GPL"). | ||
8 | * | ||
9 | * Notwithstanding the above, under no circumstances may you combine this | ||
10 | * software in any way with any other Broadcom software provided under a | ||
11 | * license other than the GPL, without Broadcom's express prior written | ||
12 | * consent. | ||
13 | *****************************************************************************/ | ||
14 | |||
15 | /* ---- Include Files ---------------------------------------------------- */ | ||
16 | #include <linux/version.h> | ||
17 | #include <linux/module.h> | ||
18 | #include <linux/types.h> | ||
19 | #include <linux/init.h> | ||
20 | #include <linux/kernel.h> | ||
21 | #include <linux/slab.h> | ||
22 | #include <linux/string.h> | ||
23 | #include <linux/ioport.h> | ||
24 | #include <linux/device.h> | ||
25 | #include <linux/delay.h> | ||
26 | #include <linux/err.h> | ||
27 | #include <linux/io.h> | ||
28 | #include <linux/platform_device.h> | ||
29 | #include <linux/mtd/mtd.h> | ||
30 | #include <linux/mtd/nand.h> | ||
31 | #include <linux/mtd/nand_ecc.h> | ||
32 | #include <linux/mtd/partitions.h> | ||
33 | |||
34 | #include <asm/mach-types.h> | ||
35 | #include <asm/system.h> | ||
36 | |||
37 | #include <mach/reg_nand.h> | ||
38 | #include <mach/reg_umi.h> | ||
39 | |||
40 | #include "nand_bcm_umi.h" | ||
41 | |||
42 | #include <mach/memory_settings.h> | ||
43 | |||
44 | #define USE_DMA 1 | ||
45 | #include <mach/dma.h> | ||
46 | #include <linux/dma-mapping.h> | ||
47 | #include <linux/completion.h> | ||
48 | |||
49 | /* ---- External Variable Declarations ----------------------------------- */ | ||
50 | /* ---- External Function Prototypes ------------------------------------- */ | ||
51 | /* ---- Public Variables ------------------------------------------------- */ | ||
52 | /* ---- Private Constants and Types -------------------------------------- */ | ||
53 | static const __devinitconst char gBanner[] = KERN_INFO \ | ||
54 | "BCM UMI MTD NAND Driver: 1.00\n"; | ||
55 | |||
56 | #ifdef CONFIG_MTD_PARTITIONS | ||
57 | const char *part_probes[] = { "cmdlinepart", NULL }; | ||
58 | #endif | ||
59 | |||
60 | #if NAND_ECC_BCH | ||
61 | static uint8_t scan_ff_pattern[] = { 0xff }; | ||
62 | |||
63 | static struct nand_bbt_descr largepage_bbt = { | ||
64 | .options = 0, | ||
65 | .offs = 0, | ||
66 | .len = 1, | ||
67 | .pattern = scan_ff_pattern | ||
68 | }; | ||
69 | #endif | ||
70 | |||
71 | /* | ||
72 | ** Preallocate a buffer to avoid having to do this every dma operation. | ||
73 | ** This is the size of the preallocated coherent DMA buffer. | ||
74 | */ | ||
75 | #if USE_DMA | ||
76 | #define DMA_MIN_BUFLEN 512 | ||
77 | #define DMA_MAX_BUFLEN PAGE_SIZE | ||
78 | #define USE_DIRECT_IO(len) (((len) < DMA_MIN_BUFLEN) || \ | ||
79 | ((len) > DMA_MAX_BUFLEN)) | ||
80 | |||
81 | /* | ||
82 | * The current NAND data space goes from 0x80001900 to 0x80001FFF, | ||
83 | * which is only 0x700 = 1792 bytes long. This is too small for 2K, 4K page | ||
84 | * size NAND flash. Need to break the DMA down to multiple 1Ks. | ||
85 | * | ||
86 | * Need to make sure REG_NAND_DATA_PADDR + DMA_MAX_LEN < 0x80002000 | ||
87 | */ | ||
88 | #define DMA_MAX_LEN 1024 | ||
89 | |||
90 | #else /* !USE_DMA */ | ||
91 | #define DMA_MIN_BUFLEN 0 | ||
92 | #define DMA_MAX_BUFLEN 0 | ||
93 | #define USE_DIRECT_IO(len) 1 | ||
94 | #endif | ||
95 | /* ---- Private Function Prototypes -------------------------------------- */ | ||
96 | static void bcm_umi_nand_read_buf(struct mtd_info *mtd, u_char * buf, int len); | ||
97 | static void bcm_umi_nand_write_buf(struct mtd_info *mtd, const u_char * buf, | ||
98 | int len); | ||
99 | |||
100 | /* ---- Private Variables ------------------------------------------------ */ | ||
101 | static struct mtd_info *board_mtd; | ||
102 | static void __iomem *bcm_umi_io_base; | ||
103 | static void *virtPtr; | ||
104 | static dma_addr_t physPtr; | ||
105 | static struct completion nand_comp; | ||
106 | |||
107 | /* ---- Private Functions ------------------------------------------------ */ | ||
108 | #if NAND_ECC_BCH | ||
109 | #include "bcm_umi_bch.c" | ||
110 | #else | ||
111 | #include "bcm_umi_hamming.c" | ||
112 | #endif | ||
113 | |||
114 | #if USE_DMA | ||
115 | |||
116 | /* Handler called when the DMA finishes. */ | ||
117 | static void nand_dma_handler(DMA_Device_t dev, int reason, void *userData) | ||
118 | { | ||
119 | complete(&nand_comp); | ||
120 | } | ||
121 | |||
122 | static int nand_dma_init(void) | ||
123 | { | ||
124 | int rc; | ||
125 | |||
126 | rc = dma_set_device_handler(DMA_DEVICE_NAND_MEM_TO_MEM, | ||
127 | nand_dma_handler, NULL); | ||
128 | if (rc != 0) { | ||
129 | printk(KERN_ERR "dma_set_device_handler failed: %d\n", rc); | ||
130 | return rc; | ||
131 | } | ||
132 | |||
133 | virtPtr = | ||
134 | dma_alloc_coherent(NULL, DMA_MAX_BUFLEN, &physPtr, GFP_KERNEL); | ||
135 | if (virtPtr == NULL) { | ||
136 | printk(KERN_ERR "NAND - Failed to allocate memory for DMA buffer\n"); | ||
137 | return -ENOMEM; | ||
138 | } | ||
139 | |||
140 | return 0; | ||
141 | } | ||
142 | |||
143 | static void nand_dma_term(void) | ||
144 | { | ||
145 | if (virtPtr != NULL) | ||
146 | dma_free_coherent(NULL, DMA_MAX_BUFLEN, virtPtr, physPtr); | ||
147 | } | ||
148 | |||
149 | static void nand_dma_read(void *buf, int len) | ||
150 | { | ||
151 | int offset = 0; | ||
152 | int tmp_len = 0; | ||
153 | int len_left = len; | ||
154 | DMA_Handle_t hndl; | ||
155 | |||
156 | if (virtPtr == NULL) | ||
157 | panic("nand_dma_read: virtPtr == NULL\n"); | ||
158 | |||
159 | if ((void *)physPtr == NULL) | ||
160 | panic("nand_dma_read: physPtr == NULL\n"); | ||
161 | |||
162 | hndl = dma_request_channel(DMA_DEVICE_NAND_MEM_TO_MEM); | ||
163 | if (hndl < 0) { | ||
164 | printk(KERN_ERR | ||
165 | "nand_dma_read: unable to allocate dma channel: %d\n", | ||
166 | (int)hndl); | ||
167 | panic("\n"); | ||
168 | } | ||
169 | |||
170 | while (len_left > 0) { | ||
171 | if (len_left > DMA_MAX_LEN) { | ||
172 | tmp_len = DMA_MAX_LEN; | ||
173 | len_left -= DMA_MAX_LEN; | ||
174 | } else { | ||
175 | tmp_len = len_left; | ||
176 | len_left = 0; | ||
177 | } | ||
178 | |||
179 | init_completion(&nand_comp); | ||
180 | dma_transfer_mem_to_mem(hndl, REG_NAND_DATA_PADDR, | ||
181 | physPtr + offset, tmp_len); | ||
182 | wait_for_completion(&nand_comp); | ||
183 | |||
184 | offset += tmp_len; | ||
185 | } | ||
186 | |||
187 | dma_free_channel(hndl); | ||
188 | |||
189 | if (buf != NULL) | ||
190 | memcpy(buf, virtPtr, len); | ||
191 | } | ||
192 | |||
193 | static void nand_dma_write(const void *buf, int len) | ||
194 | { | ||
195 | int offset = 0; | ||
196 | int tmp_len = 0; | ||
197 | int len_left = len; | ||
198 | DMA_Handle_t hndl; | ||
199 | |||
200 | if (buf == NULL) | ||
201 | panic("nand_dma_write: buf == NULL\n"); | ||
202 | |||
203 | if (virtPtr == NULL) | ||
204 | panic("nand_dma_write: virtPtr == NULL\n"); | ||
205 | |||
206 | if ((void *)physPtr == NULL) | ||
207 | panic("nand_dma_write: physPtr == NULL\n"); | ||
208 | |||
209 | memcpy(virtPtr, buf, len); | ||
210 | |||
211 | |||
212 | hndl = dma_request_channel(DMA_DEVICE_NAND_MEM_TO_MEM); | ||
213 | if (hndl < 0) { | ||
214 | printk(KERN_ERR | ||
215 | "nand_dma_write: unable to allocate dma channel: %d\n", | ||
216 | (int)hndl); | ||
217 | panic("\n"); | ||
218 | } | ||
219 | |||
220 | while (len_left > 0) { | ||
221 | if (len_left > DMA_MAX_LEN) { | ||
222 | tmp_len = DMA_MAX_LEN; | ||
223 | len_left -= DMA_MAX_LEN; | ||
224 | } else { | ||
225 | tmp_len = len_left; | ||
226 | len_left = 0; | ||
227 | } | ||
228 | |||
229 | init_completion(&nand_comp); | ||
230 | dma_transfer_mem_to_mem(hndl, physPtr + offset, | ||
231 | REG_NAND_DATA_PADDR, tmp_len); | ||
232 | wait_for_completion(&nand_comp); | ||
233 | |||
234 | offset += tmp_len; | ||
235 | } | ||
236 | |||
237 | dma_free_channel(hndl); | ||
238 | } | ||
239 | |||
240 | #endif | ||
241 | |||
242 | static int nand_dev_ready(struct mtd_info *mtd) | ||
243 | { | ||
244 | return nand_bcm_umi_dev_ready(); | ||
245 | } | ||
246 | |||
247 | /**************************************************************************** | ||
248 | * | ||
249 | * bcm_umi_nand_inithw | ||
250 | * | ||
251 | * This routine does the necessary hardware (board-specific) | ||
252 | * initializations. This includes setting up the timings, etc. | ||
253 | * | ||
254 | ***************************************************************************/ | ||
255 | int bcm_umi_nand_inithw(void) | ||
256 | { | ||
257 | /* Configure nand timing parameters */ | ||
258 | REG_UMI_NAND_TCR &= ~0x7ffff; | ||
259 | REG_UMI_NAND_TCR |= HW_CFG_NAND_TCR; | ||
260 | |||
261 | #if !defined(CONFIG_MTD_NAND_BCM_UMI_HWCS) | ||
262 | /* enable software control of CS */ | ||
263 | REG_UMI_NAND_TCR |= REG_UMI_NAND_TCR_CS_SWCTRL; | ||
264 | #endif | ||
265 | |||
266 | /* keep NAND chip select asserted */ | ||
267 | REG_UMI_NAND_RCSR |= REG_UMI_NAND_RCSR_CS_ASSERTED; | ||
268 | |||
269 | REG_UMI_NAND_TCR &= ~REG_UMI_NAND_TCR_WORD16; | ||
270 | /* enable writes to flash */ | ||
271 | REG_UMI_MMD_ICR |= REG_UMI_MMD_ICR_FLASH_WP; | ||
272 | |||
273 | writel(NAND_CMD_RESET, bcm_umi_io_base + REG_NAND_CMD_OFFSET); | ||
274 | nand_bcm_umi_wait_till_ready(); | ||
275 | |||
276 | #if NAND_ECC_BCH | ||
277 | nand_bcm_umi_bch_config_ecc(NAND_ECC_NUM_BYTES); | ||
278 | #endif | ||
279 | |||
280 | return 0; | ||
281 | } | ||
282 | |||
283 | /* Used to turn latch the proper register for access. */ | ||
284 | static void bcm_umi_nand_hwcontrol(struct mtd_info *mtd, int cmd, | ||
285 | unsigned int ctrl) | ||
286 | { | ||
287 | /* send command to hardware */ | ||
288 | struct nand_chip *chip = mtd->priv; | ||
289 | if (ctrl & NAND_CTRL_CHANGE) { | ||
290 | if (ctrl & NAND_CLE) { | ||
291 | chip->IO_ADDR_W = bcm_umi_io_base + REG_NAND_CMD_OFFSET; | ||
292 | goto CMD; | ||
293 | } | ||
294 | if (ctrl & NAND_ALE) { | ||
295 | chip->IO_ADDR_W = | ||
296 | bcm_umi_io_base + REG_NAND_ADDR_OFFSET; | ||
297 | goto CMD; | ||
298 | } | ||
299 | chip->IO_ADDR_W = bcm_umi_io_base + REG_NAND_DATA8_OFFSET; | ||
300 | } | ||
301 | |||
302 | CMD: | ||
303 | /* Send command to chip directly */ | ||
304 | if (cmd != NAND_CMD_NONE) | ||
305 | writeb(cmd, chip->IO_ADDR_W); | ||
306 | } | ||
307 | |||
308 | static void bcm_umi_nand_write_buf(struct mtd_info *mtd, const u_char * buf, | ||
309 | int len) | ||
310 | { | ||
311 | if (USE_DIRECT_IO(len)) { | ||
312 | /* Do it the old way if the buffer is small or too large. | ||
313 | * Probably quicker than starting and checking dma. */ | ||
314 | int i; | ||
315 | struct nand_chip *this = mtd->priv; | ||
316 | |||
317 | for (i = 0; i < len; i++) | ||
318 | writeb(buf[i], this->IO_ADDR_W); | ||
319 | } | ||
320 | #if USE_DMA | ||
321 | else | ||
322 | nand_dma_write(buf, len); | ||
323 | #endif | ||
324 | } | ||
325 | |||
326 | static void bcm_umi_nand_read_buf(struct mtd_info *mtd, u_char * buf, int len) | ||
327 | { | ||
328 | if (USE_DIRECT_IO(len)) { | ||
329 | int i; | ||
330 | struct nand_chip *this = mtd->priv; | ||
331 | |||
332 | for (i = 0; i < len; i++) | ||
333 | buf[i] = readb(this->IO_ADDR_R); | ||
334 | } | ||
335 | #if USE_DMA | ||
336 | else | ||
337 | nand_dma_read(buf, len); | ||
338 | #endif | ||
339 | } | ||
340 | |||
341 | static uint8_t readbackbuf[NAND_MAX_PAGESIZE]; | ||
342 | static int bcm_umi_nand_verify_buf(struct mtd_info *mtd, const u_char * buf, | ||
343 | int len) | ||
344 | { | ||
345 | /* | ||
346 | * Try to readback page with ECC correction. This is necessary | ||
347 | * for MLC parts which may have permanently stuck bits. | ||
348 | */ | ||
349 | struct nand_chip *chip = mtd->priv; | ||
350 | int ret = chip->ecc.read_page(mtd, chip, readbackbuf, 0); | ||
351 | if (ret < 0) | ||
352 | return -EFAULT; | ||
353 | else { | ||
354 | if (memcmp(readbackbuf, buf, len) == 0) | ||
355 | return 0; | ||
356 | |||
357 | return -EFAULT; | ||
358 | } | ||
359 | return 0; | ||
360 | } | ||
361 | |||
362 | static int __devinit bcm_umi_nand_probe(struct platform_device *pdev) | ||
363 | { | ||
364 | struct nand_chip *this; | ||
365 | struct resource *r; | ||
366 | int err = 0; | ||
367 | |||
368 | printk(gBanner); | ||
369 | |||
370 | /* Allocate memory for MTD device structure and private data */ | ||
371 | board_mtd = | ||
372 | kmalloc(sizeof(struct mtd_info) + sizeof(struct nand_chip), | ||
373 | GFP_KERNEL); | ||
374 | if (!board_mtd) { | ||
375 | printk(KERN_WARNING | ||
376 | "Unable to allocate NAND MTD device structure.\n"); | ||
377 | return -ENOMEM; | ||
378 | } | ||
379 | |||
380 | r = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
381 | |||
382 | if (!r) | ||
383 | return -ENXIO; | ||
384 | |||
385 | /* map physical address */ | ||
386 | bcm_umi_io_base = ioremap(r->start, r->end - r->start + 1); | ||
387 | |||
388 | if (!bcm_umi_io_base) { | ||
389 | printk(KERN_ERR "ioremap to access BCM UMI NAND chip failed\n"); | ||
390 | kfree(board_mtd); | ||
391 | return -EIO; | ||
392 | } | ||
393 | |||
394 | /* Get pointer to private data */ | ||
395 | this = (struct nand_chip *)(&board_mtd[1]); | ||
396 | |||
397 | /* Initialize structures */ | ||
398 | memset((char *)board_mtd, 0, sizeof(struct mtd_info)); | ||
399 | memset((char *)this, 0, sizeof(struct nand_chip)); | ||
400 | |||
401 | /* Link the private data with the MTD structure */ | ||
402 | board_mtd->priv = this; | ||
403 | |||
404 | /* Initialize the NAND hardware. */ | ||
405 | if (bcm_umi_nand_inithw() < 0) { | ||
406 | printk(KERN_ERR "BCM UMI NAND chip could not be initialized\n"); | ||
407 | iounmap(bcm_umi_io_base); | ||
408 | kfree(board_mtd); | ||
409 | return -EIO; | ||
410 | } | ||
411 | |||
412 | /* Set address of NAND IO lines */ | ||
413 | this->IO_ADDR_W = bcm_umi_io_base + REG_NAND_DATA8_OFFSET; | ||
414 | this->IO_ADDR_R = bcm_umi_io_base + REG_NAND_DATA8_OFFSET; | ||
415 | |||
416 | /* Set command delay time, see datasheet for correct value */ | ||
417 | this->chip_delay = 0; | ||
418 | /* Assign the device ready function, if available */ | ||
419 | this->dev_ready = nand_dev_ready; | ||
420 | this->options = 0; | ||
421 | |||
422 | this->write_buf = bcm_umi_nand_write_buf; | ||
423 | this->read_buf = bcm_umi_nand_read_buf; | ||
424 | this->verify_buf = bcm_umi_nand_verify_buf; | ||
425 | |||
426 | this->cmd_ctrl = bcm_umi_nand_hwcontrol; | ||
427 | this->ecc.mode = NAND_ECC_HW; | ||
428 | this->ecc.size = 512; | ||
429 | this->ecc.bytes = NAND_ECC_NUM_BYTES; | ||
430 | #if NAND_ECC_BCH | ||
431 | this->ecc.read_page = bcm_umi_bch_read_page_hwecc; | ||
432 | this->ecc.write_page = bcm_umi_bch_write_page_hwecc; | ||
433 | #else | ||
434 | this->ecc.correct = nand_correct_data512; | ||
435 | this->ecc.calculate = bcm_umi_hamming_get_hw_ecc; | ||
436 | this->ecc.hwctl = bcm_umi_hamming_enable_hwecc; | ||
437 | #endif | ||
438 | |||
439 | #if USE_DMA | ||
440 | err = nand_dma_init(); | ||
441 | if (err != 0) | ||
442 | return err; | ||
443 | #endif | ||
444 | |||
445 | /* Figure out the size of the device that we have. | ||
446 | * We need to do this to figure out which ECC | ||
447 | * layout we'll be using. | ||
448 | */ | ||
449 | |||
450 | err = nand_scan_ident(board_mtd, 1); | ||
451 | if (err) { | ||
452 | printk(KERN_ERR "nand_scan failed: %d\n", err); | ||
453 | iounmap(bcm_umi_io_base); | ||
454 | kfree(board_mtd); | ||
455 | return err; | ||
456 | } | ||
457 | |||
458 | /* Now that we know the nand size, we can setup the ECC layout */ | ||
459 | |||
460 | switch (board_mtd->writesize) { /* writesize is the pagesize */ | ||
461 | case 4096: | ||
462 | this->ecc.layout = &nand_hw_eccoob_4096; | ||
463 | break; | ||
464 | case 2048: | ||
465 | this->ecc.layout = &nand_hw_eccoob_2048; | ||
466 | break; | ||
467 | case 512: | ||
468 | this->ecc.layout = &nand_hw_eccoob_512; | ||
469 | break; | ||
470 | default: | ||
471 | { | ||
472 | printk(KERN_ERR "NAND - Unrecognized pagesize: %d\n", | ||
473 | board_mtd->writesize); | ||
474 | return -EINVAL; | ||
475 | } | ||
476 | } | ||
477 | |||
478 | #if NAND_ECC_BCH | ||
479 | if (board_mtd->writesize > 512) { | ||
480 | if (this->options & NAND_USE_FLASH_BBT) | ||
481 | largepage_bbt.options = NAND_BBT_SCAN2NDPAGE; | ||
482 | this->badblock_pattern = &largepage_bbt; | ||
483 | } | ||
484 | #endif | ||
485 | |||
486 | /* Now finish off the scan, now that ecc.layout has been initialized. */ | ||
487 | |||
488 | err = nand_scan_tail(board_mtd); | ||
489 | if (err) { | ||
490 | printk(KERN_ERR "nand_scan failed: %d\n", err); | ||
491 | iounmap(bcm_umi_io_base); | ||
492 | kfree(board_mtd); | ||
493 | return err; | ||
494 | } | ||
495 | |||
496 | /* Register the partitions */ | ||
497 | { | ||
498 | int nr_partitions; | ||
499 | struct mtd_partition *partition_info; | ||
500 | |||
501 | board_mtd->name = "bcm_umi-nand"; | ||
502 | nr_partitions = | ||
503 | parse_mtd_partitions(board_mtd, part_probes, | ||
504 | &partition_info, 0); | ||
505 | |||
506 | if (nr_partitions <= 0) { | ||
507 | printk(KERN_ERR "BCM UMI NAND: Too few partitions - %d\n", | ||
508 | nr_partitions); | ||
509 | iounmap(bcm_umi_io_base); | ||
510 | kfree(board_mtd); | ||
511 | return -EIO; | ||
512 | } | ||
513 | add_mtd_partitions(board_mtd, partition_info, nr_partitions); | ||
514 | } | ||
515 | |||
516 | /* Return happy */ | ||
517 | return 0; | ||
518 | } | ||
519 | |||
520 | static int bcm_umi_nand_remove(struct platform_device *pdev) | ||
521 | { | ||
522 | #if USE_DMA | ||
523 | nand_dma_term(); | ||
524 | #endif | ||
525 | |||
526 | /* Release resources, unregister device */ | ||
527 | nand_release(board_mtd); | ||
528 | |||
529 | /* unmap physical address */ | ||
530 | iounmap(bcm_umi_io_base); | ||
531 | |||
532 | /* Free the MTD device structure */ | ||
533 | kfree(board_mtd); | ||
534 | |||
535 | return 0; | ||
536 | } | ||
537 | |||
538 | #ifdef CONFIG_PM | ||
539 | static int bcm_umi_nand_suspend(struct platform_device *pdev, | ||
540 | pm_message_t state) | ||
541 | { | ||
542 | printk(KERN_ERR "MTD NAND suspend is being called\n"); | ||
543 | return 0; | ||
544 | } | ||
545 | |||
546 | static int bcm_umi_nand_resume(struct platform_device *pdev) | ||
547 | { | ||
548 | printk(KERN_ERR "MTD NAND resume is being called\n"); | ||
549 | return 0; | ||
550 | } | ||
551 | #else | ||
552 | #define bcm_umi_nand_suspend NULL | ||
553 | #define bcm_umi_nand_resume NULL | ||
554 | #endif | ||
555 | |||
556 | static struct platform_driver nand_driver = { | ||
557 | .driver = { | ||
558 | .name = "bcm-nand", | ||
559 | .owner = THIS_MODULE, | ||
560 | }, | ||
561 | .probe = bcm_umi_nand_probe, | ||
562 | .remove = bcm_umi_nand_remove, | ||
563 | .suspend = bcm_umi_nand_suspend, | ||
564 | .resume = bcm_umi_nand_resume, | ||
565 | }; | ||
566 | |||
567 | static int __init nand_init(void) | ||
568 | { | ||
569 | return platform_driver_register(&nand_driver); | ||
570 | } | ||
571 | |||
572 | static void __exit nand_exit(void) | ||
573 | { | ||
574 | platform_driver_unregister(&nand_driver); | ||
575 | } | ||
576 | |||
577 | module_init(nand_init); | ||
578 | module_exit(nand_exit); | ||
579 | |||
580 | MODULE_LICENSE("GPL"); | ||
581 | MODULE_AUTHOR("Broadcom"); | ||
582 | MODULE_DESCRIPTION("BCM UMI MTD NAND driver"); | ||
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c index c828d9ac7bd7..e5a9f9ccea60 100644 --- a/drivers/mtd/nand/cafe_nand.c +++ b/drivers/mtd/nand/cafe_nand.c | |||
@@ -20,6 +20,7 @@ | |||
20 | #include <linux/delay.h> | 20 | #include <linux/delay.h> |
21 | #include <linux/interrupt.h> | 21 | #include <linux/interrupt.h> |
22 | #include <linux/dma-mapping.h> | 22 | #include <linux/dma-mapping.h> |
23 | #include <linux/slab.h> | ||
23 | #include <asm/io.h> | 24 | #include <asm/io.h> |
24 | 25 | ||
25 | #define CAFE_NAND_CTRL1 0x00 | 26 | #define CAFE_NAND_CTRL1 0x00 |
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c index 826cacffcefc..6e6495278258 100644 --- a/drivers/mtd/nand/cmx270_nand.c +++ b/drivers/mtd/nand/cmx270_nand.c | |||
@@ -20,6 +20,7 @@ | |||
20 | 20 | ||
21 | #include <linux/mtd/nand.h> | 21 | #include <linux/mtd/nand.h> |
22 | #include <linux/mtd/partitions.h> | 22 | #include <linux/mtd/partitions.h> |
23 | #include <linux/slab.h> | ||
23 | #include <linux/gpio.h> | 24 | #include <linux/gpio.h> |
24 | 25 | ||
25 | #include <asm/io.h> | 26 | #include <asm/io.h> |
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index f13f5b9afaf7..76e2dc8e62f7 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c | |||
@@ -32,6 +32,7 @@ | |||
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/mtd/nand.h> | 33 | #include <linux/mtd/nand.h> |
34 | #include <linux/mtd/partitions.h> | 34 | #include <linux/mtd/partitions.h> |
35 | #include <linux/slab.h> | ||
35 | 36 | ||
36 | #include <mach/nand.h> | 37 | #include <mach/nand.h> |
37 | 38 | ||
@@ -591,6 +592,8 @@ static int __init nand_davinci_probe(struct platform_device *pdev) | |||
591 | 592 | ||
592 | /* options such as NAND_USE_FLASH_BBT or 16-bit widths */ | 593 | /* options such as NAND_USE_FLASH_BBT or 16-bit widths */ |
593 | info->chip.options = pdata->options; | 594 | info->chip.options = pdata->options; |
595 | info->chip.bbt_td = pdata->bbt_td; | ||
596 | info->chip.bbt_md = pdata->bbt_md; | ||
594 | 597 | ||
595 | info->ioaddr = (uint32_t __force) vaddr; | 598 | info->ioaddr = (uint32_t __force) vaddr; |
596 | 599 | ||
@@ -599,7 +602,7 @@ static int __init nand_davinci_probe(struct platform_device *pdev) | |||
599 | info->mask_chipsel = pdata->mask_chipsel; | 602 | info->mask_chipsel = pdata->mask_chipsel; |
600 | 603 | ||
601 | /* use nandboot-capable ALE/CLE masks by default */ | 604 | /* use nandboot-capable ALE/CLE masks by default */ |
602 | info->mask_ale = pdata->mask_cle ? : MASK_ALE; | 605 | info->mask_ale = pdata->mask_ale ? : MASK_ALE; |
603 | info->mask_cle = pdata->mask_cle ? : MASK_CLE; | 606 | info->mask_cle = pdata->mask_cle ? : MASK_CLE; |
604 | 607 | ||
605 | /* Set address of hardware control function */ | 608 | /* Set address of hardware control function */ |
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c index e51c1ed7ac18..47067bc98248 100644 --- a/drivers/mtd/nand/diskonchip.c +++ b/drivers/mtd/nand/diskonchip.c | |||
@@ -23,6 +23,7 @@ | |||
23 | #include <linux/delay.h> | 23 | #include <linux/delay.h> |
24 | #include <linux/rslib.h> | 24 | #include <linux/rslib.h> |
25 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/slab.h> | ||
26 | #include <asm/io.h> | 27 | #include <asm/io.h> |
27 | 28 | ||
28 | #include <linux/mtd/mtd.h> | 29 | #include <linux/mtd/mtd.h> |
@@ -1056,7 +1057,7 @@ static struct nand_ecclayout doc200x_oobinfo = { | |||
1056 | }; | 1057 | }; |
1057 | 1058 | ||
1058 | /* Find the (I)NFTL Media Header, and optionally also the mirror media header. | 1059 | /* Find the (I)NFTL Media Header, and optionally also the mirror media header. |
1059 | On sucessful return, buf will contain a copy of the media header for | 1060 | On successful return, buf will contain a copy of the media header for |
1060 | further processing. id is the string to scan for, and will presumably be | 1061 | further processing. id is the string to scan for, and will presumably be |
1061 | either "ANAND" or "BNAND". If findmirror=1, also look for the mirror media | 1062 | either "ANAND" or "BNAND". If findmirror=1, also look for the mirror media |
1062 | header. The page #s of the found media headers are placed in mh0_page and | 1063 | header. The page #s of the found media headers are placed in mh0_page and |
diff --git a/drivers/mtd/nand/excite_nandflash.c b/drivers/mtd/nand/excite_nandflash.c deleted file mode 100644 index 72446fb48d4b..000000000000 --- a/drivers/mtd/nand/excite_nandflash.c +++ /dev/null | |||
@@ -1,248 +0,0 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2005 - 2007 by Basler Vision Technologies AG | ||
3 | * Author: Thomas Koeller <thomas.koeller.qbaslerweb.com> | ||
4 | * Original code by Thies Moeller <thies.moeller@baslerweb.com> | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify | ||
7 | * it under the terms of the GNU General Public License as published by | ||
8 | * the Free Software Foundation; either version 2 of the License, or | ||
9 | * (at your option) any later version. | ||
10 | * | ||
11 | * This program is distributed in the hope that it will be useful, | ||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
14 | * GNU General Public License for more details. | ||
15 | * | ||
16 | * You should have received a copy of the GNU General Public License | ||
17 | * along with this program; if not, write to the Free Software | ||
18 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
19 | */ | ||
20 | |||
21 | #include <linux/module.h> | ||
22 | #include <linux/types.h> | ||
23 | #include <linux/init.h> | ||
24 | #include <linux/kernel.h> | ||
25 | #include <linux/string.h> | ||
26 | #include <linux/ioport.h> | ||
27 | #include <linux/platform_device.h> | ||
28 | #include <linux/delay.h> | ||
29 | #include <linux/err.h> | ||
30 | |||
31 | #include <linux/mtd/mtd.h> | ||
32 | #include <linux/mtd/nand.h> | ||
33 | #include <linux/mtd/nand_ecc.h> | ||
34 | #include <linux/mtd/partitions.h> | ||
35 | |||
36 | #include <asm/io.h> | ||
37 | #include <asm/rm9k-ocd.h> | ||
38 | |||
39 | #include <excite_nandflash.h> | ||
40 | |||
41 | #define EXCITE_NANDFLASH_VERSION "0.1" | ||
42 | |||
43 | /* I/O register offsets */ | ||
44 | #define EXCITE_NANDFLASH_DATA_BYTE 0x00 | ||
45 | #define EXCITE_NANDFLASH_STATUS_BYTE 0x0c | ||
46 | #define EXCITE_NANDFLASH_ADDR_BYTE 0x10 | ||
47 | #define EXCITE_NANDFLASH_CMD_BYTE 0x14 | ||
48 | |||
49 | /* prefix for debug output */ | ||
50 | static const char module_id[] = "excite_nandflash"; | ||
51 | |||
52 | /* | ||
53 | * partition definition | ||
54 | */ | ||
55 | static const struct mtd_partition partition_info[] = { | ||
56 | { | ||
57 | .name = "eXcite RootFS", | ||
58 | .offset = 0, | ||
59 | .size = MTDPART_SIZ_FULL | ||
60 | } | ||
61 | }; | ||
62 | |||
63 | static inline const struct resource * | ||
64 | excite_nand_get_resource(struct platform_device *d, unsigned long flags, | ||
65 | const char *basename) | ||
66 | { | ||
67 | char buf[80]; | ||
68 | |||
69 | if (snprintf(buf, sizeof buf, "%s_%u", basename, d->id) >= sizeof buf) | ||
70 | return NULL; | ||
71 | return platform_get_resource_byname(d, flags, buf); | ||
72 | } | ||
73 | |||
74 | static inline void __iomem * | ||
75 | excite_nand_map_regs(struct platform_device *d, const char *basename) | ||
76 | { | ||
77 | void *result = NULL; | ||
78 | const struct resource *const r = | ||
79 | excite_nand_get_resource(d, IORESOURCE_MEM, basename); | ||
80 | |||
81 | if (r) | ||
82 | result = ioremap_nocache(r->start, r->end + 1 - r->start); | ||
83 | return result; | ||
84 | } | ||
85 | |||
86 | /* controller and mtd information */ | ||
87 | struct excite_nand_drvdata { | ||
88 | struct mtd_info board_mtd; | ||
89 | struct nand_chip board_chip; | ||
90 | void __iomem *regs; | ||
91 | void __iomem *tgt; | ||
92 | }; | ||
93 | |||
94 | /* Control function */ | ||
95 | static void excite_nand_control(struct mtd_info *mtd, int cmd, | ||
96 | unsigned int ctrl) | ||
97 | { | ||
98 | struct excite_nand_drvdata * const d = | ||
99 | container_of(mtd, struct excite_nand_drvdata, board_mtd); | ||
100 | |||
101 | switch (ctrl) { | ||
102 | case NAND_CTRL_CHANGE | NAND_CTRL_CLE: | ||
103 | d->tgt = d->regs + EXCITE_NANDFLASH_CMD_BYTE; | ||
104 | break; | ||
105 | case NAND_CTRL_CHANGE | NAND_CTRL_ALE: | ||
106 | d->tgt = d->regs + EXCITE_NANDFLASH_ADDR_BYTE; | ||
107 | break; | ||
108 | case NAND_CTRL_CHANGE | NAND_NCE: | ||
109 | d->tgt = d->regs + EXCITE_NANDFLASH_DATA_BYTE; | ||
110 | break; | ||
111 | } | ||
112 | |||
113 | if (cmd != NAND_CMD_NONE) | ||
114 | __raw_writeb(cmd, d->tgt); | ||
115 | } | ||
116 | |||
117 | /* Return 0 if flash is busy, 1 if ready */ | ||
118 | static int excite_nand_devready(struct mtd_info *mtd) | ||
119 | { | ||
120 | struct excite_nand_drvdata * const drvdata = | ||
121 | container_of(mtd, struct excite_nand_drvdata, board_mtd); | ||
122 | |||
123 | return __raw_readb(drvdata->regs + EXCITE_NANDFLASH_STATUS_BYTE); | ||
124 | } | ||
125 | |||
126 | /* | ||
127 | * Called by device layer to remove the driver. | ||
128 | * The binding to the mtd and all allocated | ||
129 | * resources are released. | ||
130 | */ | ||
131 | static int __exit excite_nand_remove(struct platform_device *dev) | ||
132 | { | ||
133 | struct excite_nand_drvdata * const this = platform_get_drvdata(dev); | ||
134 | |||
135 | platform_set_drvdata(dev, NULL); | ||
136 | |||
137 | if (unlikely(!this)) { | ||
138 | printk(KERN_ERR "%s: called %s without private data!!", | ||
139 | module_id, __func__); | ||
140 | return -EINVAL; | ||
141 | } | ||
142 | |||
143 | /* first thing we need to do is release our mtd | ||
144 | * then go through freeing the resource used | ||
145 | */ | ||
146 | nand_release(&this->board_mtd); | ||
147 | |||
148 | /* free the common resources */ | ||
149 | iounmap(this->regs); | ||
150 | kfree(this); | ||
151 | |||
152 | DEBUG(MTD_DEBUG_LEVEL1, "%s: removed\n", module_id); | ||
153 | return 0; | ||
154 | } | ||
155 | |||
156 | /* | ||
157 | * Called by device layer when it finds a device matching | ||
158 | * one our driver can handle. This code checks to see if | ||
159 | * it can allocate all necessary resources then calls the | ||
160 | * nand layer to look for devices. | ||
161 | */ | ||
162 | static int __init excite_nand_probe(struct platform_device *pdev) | ||
163 | { | ||
164 | struct excite_nand_drvdata *drvdata; /* private driver data */ | ||
165 | struct nand_chip *board_chip; /* private flash chip data */ | ||
166 | struct mtd_info *board_mtd; /* mtd info for this board */ | ||
167 | int scan_res; | ||
168 | |||
169 | drvdata = kzalloc(sizeof(*drvdata), GFP_KERNEL); | ||
170 | if (unlikely(!drvdata)) { | ||
171 | printk(KERN_ERR "%s: no memory for drvdata\n", | ||
172 | module_id); | ||
173 | return -ENOMEM; | ||
174 | } | ||
175 | |||
176 | /* bind private data into driver */ | ||
177 | platform_set_drvdata(pdev, drvdata); | ||
178 | |||
179 | /* allocate and map the resource */ | ||
180 | drvdata->regs = | ||
181 | excite_nand_map_regs(pdev, EXCITE_NANDFLASH_RESOURCE_REGS); | ||
182 | |||
183 | if (unlikely(!drvdata->regs)) { | ||
184 | printk(KERN_ERR "%s: cannot reserve register region\n", | ||
185 | module_id); | ||
186 | kfree(drvdata); | ||
187 | return -ENXIO; | ||
188 | } | ||
189 | |||
190 | drvdata->tgt = drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE; | ||
191 | |||
192 | /* initialise our chip */ | ||
193 | board_chip = &drvdata->board_chip; | ||
194 | board_chip->IO_ADDR_R = board_chip->IO_ADDR_W = | ||
195 | drvdata->regs + EXCITE_NANDFLASH_DATA_BYTE; | ||
196 | board_chip->cmd_ctrl = excite_nand_control; | ||
197 | board_chip->dev_ready = excite_nand_devready; | ||
198 | board_chip->chip_delay = 25; | ||
199 | board_chip->ecc.mode = NAND_ECC_SOFT; | ||
200 | |||
201 | /* link chip to mtd */ | ||
202 | board_mtd = &drvdata->board_mtd; | ||
203 | board_mtd->priv = board_chip; | ||
204 | |||
205 | DEBUG(MTD_DEBUG_LEVEL2, "%s: device scan\n", module_id); | ||
206 | scan_res = nand_scan(&drvdata->board_mtd, 1); | ||
207 | |||
208 | if (likely(!scan_res)) { | ||
209 | DEBUG(MTD_DEBUG_LEVEL2, "%s: register partitions\n", module_id); | ||
210 | add_mtd_partitions(&drvdata->board_mtd, partition_info, | ||
211 | ARRAY_SIZE(partition_info)); | ||
212 | } else { | ||
213 | iounmap(drvdata->regs); | ||
214 | kfree(drvdata); | ||
215 | printk(KERN_ERR "%s: device scan failed\n", module_id); | ||
216 | return -EIO; | ||
217 | } | ||
218 | return 0; | ||
219 | } | ||
220 | |||
221 | static struct platform_driver excite_nand_driver = { | ||
222 | .driver = { | ||
223 | .name = "excite_nand", | ||
224 | .owner = THIS_MODULE, | ||
225 | }, | ||
226 | .probe = excite_nand_probe, | ||
227 | .remove = __devexit_p(excite_nand_remove) | ||
228 | }; | ||
229 | |||
230 | static int __init excite_nand_init(void) | ||
231 | { | ||
232 | pr_info("Basler eXcite nand flash driver Version " | ||
233 | EXCITE_NANDFLASH_VERSION "\n"); | ||
234 | return platform_driver_register(&excite_nand_driver); | ||
235 | } | ||
236 | |||
237 | static void __exit excite_nand_exit(void) | ||
238 | { | ||
239 | platform_driver_unregister(&excite_nand_driver); | ||
240 | } | ||
241 | |||
242 | module_init(excite_nand_init); | ||
243 | module_exit(excite_nand_exit); | ||
244 | |||
245 | MODULE_AUTHOR("Thomas Koeller <thomas.koeller@baslerweb.com>"); | ||
246 | MODULE_DESCRIPTION("Basler eXcite NAND-Flash driver"); | ||
247 | MODULE_LICENSE("GPL"); | ||
248 | MODULE_VERSION(EXCITE_NANDFLASH_VERSION) | ||
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index ddd37d2554ed..ae30fb6eed97 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c | |||
@@ -237,12 +237,15 @@ static int fsl_elbc_run_command(struct mtd_info *mtd) | |||
237 | 237 | ||
238 | ctrl->use_mdr = 0; | 238 | ctrl->use_mdr = 0; |
239 | 239 | ||
240 | dev_vdbg(ctrl->dev, | 240 | if (ctrl->status != LTESR_CC) { |
241 | "fsl_elbc_run_command: stat=%08x mdr=%08x fmr=%08x\n", | 241 | dev_info(ctrl->dev, |
242 | ctrl->status, ctrl->mdr, in_be32(&lbc->fmr)); | 242 | "command failed: fir %x fcr %x status %x mdr %x\n", |
243 | in_be32(&lbc->fir), in_be32(&lbc->fcr), | ||
244 | ctrl->status, ctrl->mdr); | ||
245 | return -EIO; | ||
246 | } | ||
243 | 247 | ||
244 | /* returns 0 on success otherwise non-zero) */ | 248 | return 0; |
245 | return ctrl->status == LTESR_CC ? 0 : -EIO; | ||
246 | } | 249 | } |
247 | 250 | ||
248 | static void fsl_elbc_do_read(struct nand_chip *chip, int oob) | 251 | static void fsl_elbc_do_read(struct nand_chip *chip, int oob) |
@@ -253,17 +256,17 @@ static void fsl_elbc_do_read(struct nand_chip *chip, int oob) | |||
253 | 256 | ||
254 | if (priv->page_size) { | 257 | if (priv->page_size) { |
255 | out_be32(&lbc->fir, | 258 | out_be32(&lbc->fir, |
256 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 259 | (FIR_OP_CM0 << FIR_OP0_SHIFT) | |
257 | (FIR_OP_CA << FIR_OP1_SHIFT) | | 260 | (FIR_OP_CA << FIR_OP1_SHIFT) | |
258 | (FIR_OP_PA << FIR_OP2_SHIFT) | | 261 | (FIR_OP_PA << FIR_OP2_SHIFT) | |
259 | (FIR_OP_CW1 << FIR_OP3_SHIFT) | | 262 | (FIR_OP_CM1 << FIR_OP3_SHIFT) | |
260 | (FIR_OP_RBW << FIR_OP4_SHIFT)); | 263 | (FIR_OP_RBW << FIR_OP4_SHIFT)); |
261 | 264 | ||
262 | out_be32(&lbc->fcr, (NAND_CMD_READ0 << FCR_CMD0_SHIFT) | | 265 | out_be32(&lbc->fcr, (NAND_CMD_READ0 << FCR_CMD0_SHIFT) | |
263 | (NAND_CMD_READSTART << FCR_CMD1_SHIFT)); | 266 | (NAND_CMD_READSTART << FCR_CMD1_SHIFT)); |
264 | } else { | 267 | } else { |
265 | out_be32(&lbc->fir, | 268 | out_be32(&lbc->fir, |
266 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 269 | (FIR_OP_CM0 << FIR_OP0_SHIFT) | |
267 | (FIR_OP_CA << FIR_OP1_SHIFT) | | 270 | (FIR_OP_CA << FIR_OP1_SHIFT) | |
268 | (FIR_OP_PA << FIR_OP2_SHIFT) | | 271 | (FIR_OP_PA << FIR_OP2_SHIFT) | |
269 | (FIR_OP_RBW << FIR_OP3_SHIFT)); | 272 | (FIR_OP_RBW << FIR_OP3_SHIFT)); |
@@ -332,7 +335,7 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
332 | case NAND_CMD_READID: | 335 | case NAND_CMD_READID: |
333 | dev_vdbg(ctrl->dev, "fsl_elbc_cmdfunc: NAND_CMD_READID.\n"); | 336 | dev_vdbg(ctrl->dev, "fsl_elbc_cmdfunc: NAND_CMD_READID.\n"); |
334 | 337 | ||
335 | out_be32(&lbc->fir, (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 338 | out_be32(&lbc->fir, (FIR_OP_CM0 << FIR_OP0_SHIFT) | |
336 | (FIR_OP_UA << FIR_OP1_SHIFT) | | 339 | (FIR_OP_UA << FIR_OP1_SHIFT) | |
337 | (FIR_OP_RBW << FIR_OP2_SHIFT)); | 340 | (FIR_OP_RBW << FIR_OP2_SHIFT)); |
338 | out_be32(&lbc->fcr, NAND_CMD_READID << FCR_CMD0_SHIFT); | 341 | out_be32(&lbc->fcr, NAND_CMD_READID << FCR_CMD0_SHIFT); |
@@ -359,16 +362,20 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
359 | dev_vdbg(ctrl->dev, "fsl_elbc_cmdfunc: NAND_CMD_ERASE2.\n"); | 362 | dev_vdbg(ctrl->dev, "fsl_elbc_cmdfunc: NAND_CMD_ERASE2.\n"); |
360 | 363 | ||
361 | out_be32(&lbc->fir, | 364 | out_be32(&lbc->fir, |
362 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 365 | (FIR_OP_CM0 << FIR_OP0_SHIFT) | |
363 | (FIR_OP_PA << FIR_OP1_SHIFT) | | 366 | (FIR_OP_PA << FIR_OP1_SHIFT) | |
364 | (FIR_OP_CM1 << FIR_OP2_SHIFT)); | 367 | (FIR_OP_CM2 << FIR_OP2_SHIFT) | |
368 | (FIR_OP_CW1 << FIR_OP3_SHIFT) | | ||
369 | (FIR_OP_RS << FIR_OP4_SHIFT)); | ||
365 | 370 | ||
366 | out_be32(&lbc->fcr, | 371 | out_be32(&lbc->fcr, |
367 | (NAND_CMD_ERASE1 << FCR_CMD0_SHIFT) | | 372 | (NAND_CMD_ERASE1 << FCR_CMD0_SHIFT) | |
368 | (NAND_CMD_ERASE2 << FCR_CMD1_SHIFT)); | 373 | (NAND_CMD_STATUS << FCR_CMD1_SHIFT) | |
374 | (NAND_CMD_ERASE2 << FCR_CMD2_SHIFT)); | ||
369 | 375 | ||
370 | out_be32(&lbc->fbcr, 0); | 376 | out_be32(&lbc->fbcr, 0); |
371 | ctrl->read_bytes = 0; | 377 | ctrl->read_bytes = 0; |
378 | ctrl->use_mdr = 1; | ||
372 | 379 | ||
373 | fsl_elbc_run_command(mtd); | 380 | fsl_elbc_run_command(mtd); |
374 | return; | 381 | return; |
@@ -383,40 +390,41 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
383 | 390 | ||
384 | ctrl->column = column; | 391 | ctrl->column = column; |
385 | ctrl->oob = 0; | 392 | ctrl->oob = 0; |
393 | ctrl->use_mdr = 1; | ||
386 | 394 | ||
387 | if (priv->page_size) { | 395 | fcr = (NAND_CMD_STATUS << FCR_CMD1_SHIFT) | |
388 | fcr = (NAND_CMD_SEQIN << FCR_CMD0_SHIFT) | | 396 | (NAND_CMD_SEQIN << FCR_CMD2_SHIFT) | |
389 | (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT); | 397 | (NAND_CMD_PAGEPROG << FCR_CMD3_SHIFT); |
390 | 398 | ||
399 | if (priv->page_size) { | ||
391 | out_be32(&lbc->fir, | 400 | out_be32(&lbc->fir, |
392 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 401 | (FIR_OP_CM2 << FIR_OP0_SHIFT) | |
393 | (FIR_OP_CA << FIR_OP1_SHIFT) | | 402 | (FIR_OP_CA << FIR_OP1_SHIFT) | |
394 | (FIR_OP_PA << FIR_OP2_SHIFT) | | 403 | (FIR_OP_PA << FIR_OP2_SHIFT) | |
395 | (FIR_OP_WB << FIR_OP3_SHIFT) | | 404 | (FIR_OP_WB << FIR_OP3_SHIFT) | |
396 | (FIR_OP_CW1 << FIR_OP4_SHIFT)); | 405 | (FIR_OP_CM3 << FIR_OP4_SHIFT) | |
406 | (FIR_OP_CW1 << FIR_OP5_SHIFT) | | ||
407 | (FIR_OP_RS << FIR_OP6_SHIFT)); | ||
397 | } else { | 408 | } else { |
398 | fcr = (NAND_CMD_PAGEPROG << FCR_CMD1_SHIFT) | | ||
399 | (NAND_CMD_SEQIN << FCR_CMD2_SHIFT); | ||
400 | |||
401 | out_be32(&lbc->fir, | 409 | out_be32(&lbc->fir, |
402 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | 410 | (FIR_OP_CM0 << FIR_OP0_SHIFT) | |
403 | (FIR_OP_CM2 << FIR_OP1_SHIFT) | | 411 | (FIR_OP_CM2 << FIR_OP1_SHIFT) | |
404 | (FIR_OP_CA << FIR_OP2_SHIFT) | | 412 | (FIR_OP_CA << FIR_OP2_SHIFT) | |
405 | (FIR_OP_PA << FIR_OP3_SHIFT) | | 413 | (FIR_OP_PA << FIR_OP3_SHIFT) | |
406 | (FIR_OP_WB << FIR_OP4_SHIFT) | | 414 | (FIR_OP_WB << FIR_OP4_SHIFT) | |
407 | (FIR_OP_CW1 << FIR_OP5_SHIFT)); | 415 | (FIR_OP_CM3 << FIR_OP5_SHIFT) | |
416 | (FIR_OP_CW1 << FIR_OP6_SHIFT) | | ||
417 | (FIR_OP_RS << FIR_OP7_SHIFT)); | ||
408 | 418 | ||
409 | if (column >= mtd->writesize) { | 419 | if (column >= mtd->writesize) { |
410 | /* OOB area --> READOOB */ | 420 | /* OOB area --> READOOB */ |
411 | column -= mtd->writesize; | 421 | column -= mtd->writesize; |
412 | fcr |= NAND_CMD_READOOB << FCR_CMD0_SHIFT; | 422 | fcr |= NAND_CMD_READOOB << FCR_CMD0_SHIFT; |
413 | ctrl->oob = 1; | 423 | ctrl->oob = 1; |
414 | } else if (column < 256) { | 424 | } else { |
425 | WARN_ON(column != 0); | ||
415 | /* First 256 bytes --> READ0 */ | 426 | /* First 256 bytes --> READ0 */ |
416 | fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT; | 427 | fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT; |
417 | } else { | ||
418 | /* Second 256 bytes --> READ1 */ | ||
419 | fcr |= NAND_CMD_READ1 << FCR_CMD0_SHIFT; | ||
420 | } | 428 | } |
421 | } | 429 | } |
422 | 430 | ||
@@ -628,22 +636,6 @@ static int fsl_elbc_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
628 | { | 636 | { |
629 | struct fsl_elbc_mtd *priv = chip->priv; | 637 | struct fsl_elbc_mtd *priv = chip->priv; |
630 | struct fsl_elbc_ctrl *ctrl = priv->ctrl; | 638 | struct fsl_elbc_ctrl *ctrl = priv->ctrl; |
631 | struct fsl_lbc_regs __iomem *lbc = ctrl->regs; | ||
632 | |||
633 | if (ctrl->status != LTESR_CC) | ||
634 | return NAND_STATUS_FAIL; | ||
635 | |||
636 | /* Use READ_STATUS command, but wait for the device to be ready */ | ||
637 | ctrl->use_mdr = 0; | ||
638 | out_be32(&lbc->fir, | ||
639 | (FIR_OP_CW0 << FIR_OP0_SHIFT) | | ||
640 | (FIR_OP_RBW << FIR_OP1_SHIFT)); | ||
641 | out_be32(&lbc->fcr, NAND_CMD_STATUS << FCR_CMD0_SHIFT); | ||
642 | out_be32(&lbc->fbcr, 1); | ||
643 | set_addr(mtd, 0, 0, 0); | ||
644 | ctrl->read_bytes = 1; | ||
645 | |||
646 | fsl_elbc_run_command(mtd); | ||
647 | 639 | ||
648 | if (ctrl->status != LTESR_CC) | 640 | if (ctrl->status != LTESR_CC) |
649 | return NAND_STATUS_FAIL; | 641 | return NAND_STATUS_FAIL; |
@@ -651,8 +643,7 @@ static int fsl_elbc_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
651 | /* The chip always seems to report that it is | 643 | /* The chip always seems to report that it is |
652 | * write-protected, even when it is not. | 644 | * write-protected, even when it is not. |
653 | */ | 645 | */ |
654 | setbits8(ctrl->addr, NAND_STATUS_WP); | 646 | return (ctrl->mdr & 0xff) | NAND_STATUS_WP; |
655 | return fsl_elbc_read_byte(mtd); | ||
656 | } | 647 | } |
657 | 648 | ||
658 | static int fsl_elbc_chip_init_tail(struct mtd_info *mtd) | 649 | static int fsl_elbc_chip_init_tail(struct mtd_info *mtd) |
@@ -946,6 +937,13 @@ static int __devinit fsl_elbc_ctrl_init(struct fsl_elbc_ctrl *ctrl) | |||
946 | { | 937 | { |
947 | struct fsl_lbc_regs __iomem *lbc = ctrl->regs; | 938 | struct fsl_lbc_regs __iomem *lbc = ctrl->regs; |
948 | 939 | ||
940 | /* | ||
941 | * NAND transactions can tie up the bus for a long time, so set the | ||
942 | * bus timeout to max by clearing LBCR[BMT] (highest base counter | ||
943 | * value) and setting LBCR[BMTPS] to the highest prescaler value. | ||
944 | */ | ||
945 | clrsetbits_be32(&lbc->lbcr, LBCR_BMT, 15); | ||
946 | |||
949 | /* clear event registers */ | 947 | /* clear event registers */ |
950 | setbits32(&lbc->ltesr, LTESR_NAND_MASK); | 948 | setbits32(&lbc->ltesr, LTESR_NAND_MASK); |
951 | out_be32(&lbc->lteatr, 0); | 949 | out_be32(&lbc->lteatr, 0); |
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c index d120cd8d7267..4b96296af321 100644 --- a/drivers/mtd/nand/fsl_upm.c +++ b/drivers/mtd/nand/fsl_upm.c | |||
@@ -21,6 +21,7 @@ | |||
21 | #include <linux/of_platform.h> | 21 | #include <linux/of_platform.h> |
22 | #include <linux/of_gpio.h> | 22 | #include <linux/of_gpio.h> |
23 | #include <linux/io.h> | 23 | #include <linux/io.h> |
24 | #include <linux/slab.h> | ||
24 | #include <asm/fsl_lbc.h> | 25 | #include <asm/fsl_lbc.h> |
25 | 26 | ||
26 | #define FSL_UPM_WAIT_RUN_PATTERN 0x1 | 27 | #define FSL_UPM_WAIT_RUN_PATTERN 0x1 |
@@ -112,7 +113,7 @@ static void fun_select_chip(struct mtd_info *mtd, int mchip_nr) | |||
112 | 113 | ||
113 | if (mchip_nr == -1) { | 114 | if (mchip_nr == -1) { |
114 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); | 115 | chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); |
115 | } else if (mchip_nr >= 0) { | 116 | } else if (mchip_nr >= 0 && mchip_nr < NAND_MAX_CHIPS) { |
116 | fun->mchip_number = mchip_nr; | 117 | fun->mchip_number = mchip_nr; |
117 | chip->IO_ADDR_R = fun->io_base + fun->mchip_offsets[mchip_nr]; | 118 | chip->IO_ADDR_R = fun->io_base + fun->mchip_offsets[mchip_nr]; |
118 | chip->IO_ADDR_W = chip->IO_ADDR_R; | 119 | chip->IO_ADDR_W = chip->IO_ADDR_R; |
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 65b26d5a5c0d..b2900d8406d3 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c | |||
@@ -33,9 +33,13 @@ | |||
33 | 33 | ||
34 | #include <asm/mach/flash.h> | 34 | #include <asm/mach/flash.h> |
35 | #include <mach/mxc_nand.h> | 35 | #include <mach/mxc_nand.h> |
36 | #include <mach/hardware.h> | ||
36 | 37 | ||
37 | #define DRIVER_NAME "mxc_nand" | 38 | #define DRIVER_NAME "mxc_nand" |
38 | 39 | ||
40 | #define nfc_is_v21() (cpu_is_mx25() || cpu_is_mx35()) | ||
41 | #define nfc_is_v1() (cpu_is_mx31() || cpu_is_mx27()) | ||
42 | |||
39 | /* Addresses for NFC registers */ | 43 | /* Addresses for NFC registers */ |
40 | #define NFC_BUF_SIZE 0xE00 | 44 | #define NFC_BUF_SIZE 0xE00 |
41 | #define NFC_BUF_ADDR 0xE04 | 45 | #define NFC_BUF_ADDR 0xE04 |
@@ -46,24 +50,14 @@ | |||
46 | #define NFC_RSLTMAIN_AREA 0xE0E | 50 | #define NFC_RSLTMAIN_AREA 0xE0E |
47 | #define NFC_RSLTSPARE_AREA 0xE10 | 51 | #define NFC_RSLTSPARE_AREA 0xE10 |
48 | #define NFC_WRPROT 0xE12 | 52 | #define NFC_WRPROT 0xE12 |
49 | #define NFC_UNLOCKSTART_BLKADDR 0xE14 | 53 | #define NFC_V1_UNLOCKSTART_BLKADDR 0xe14 |
50 | #define NFC_UNLOCKEND_BLKADDR 0xE16 | 54 | #define NFC_V1_UNLOCKEND_BLKADDR 0xe16 |
55 | #define NFC_V21_UNLOCKSTART_BLKADDR 0xe20 | ||
56 | #define NFC_V21_UNLOCKEND_BLKADDR 0xe22 | ||
51 | #define NFC_NF_WRPRST 0xE18 | 57 | #define NFC_NF_WRPRST 0xE18 |
52 | #define NFC_CONFIG1 0xE1A | 58 | #define NFC_CONFIG1 0xE1A |
53 | #define NFC_CONFIG2 0xE1C | 59 | #define NFC_CONFIG2 0xE1C |
54 | 60 | ||
55 | /* Addresses for NFC RAM BUFFER Main area 0 */ | ||
56 | #define MAIN_AREA0 0x000 | ||
57 | #define MAIN_AREA1 0x200 | ||
58 | #define MAIN_AREA2 0x400 | ||
59 | #define MAIN_AREA3 0x600 | ||
60 | |||
61 | /* Addresses for NFC SPARE BUFFER Spare area 0 */ | ||
62 | #define SPARE_AREA0 0x800 | ||
63 | #define SPARE_AREA1 0x810 | ||
64 | #define SPARE_AREA2 0x820 | ||
65 | #define SPARE_AREA3 0x830 | ||
66 | |||
67 | /* Set INT to 0, FCMD to 1, rest to 0 in NFC_CONFIG2 Register | 61 | /* Set INT to 0, FCMD to 1, rest to 0 in NFC_CONFIG2 Register |
68 | * for Command operation */ | 62 | * for Command operation */ |
69 | #define NFC_CMD 0x1 | 63 | #define NFC_CMD 0x1 |
@@ -106,48 +100,66 @@ struct mxc_nand_host { | |||
106 | struct mtd_partition *parts; | 100 | struct mtd_partition *parts; |
107 | struct device *dev; | 101 | struct device *dev; |
108 | 102 | ||
103 | void *spare0; | ||
104 | void *main_area0; | ||
105 | void *main_area1; | ||
106 | |||
107 | void __iomem *base; | ||
109 | void __iomem *regs; | 108 | void __iomem *regs; |
110 | int spare_only; | ||
111 | int status_request; | 109 | int status_request; |
112 | int pagesize_2k; | ||
113 | uint16_t col_addr; | ||
114 | struct clk *clk; | 110 | struct clk *clk; |
115 | int clk_act; | 111 | int clk_act; |
116 | int irq; | 112 | int irq; |
117 | 113 | ||
118 | wait_queue_head_t irq_waitq; | 114 | wait_queue_head_t irq_waitq; |
119 | }; | ||
120 | |||
121 | /* Define delays in microsec for NAND device operations */ | ||
122 | #define TROP_US_DELAY 2000 | ||
123 | /* Macros to get byte and bit positions of ECC */ | ||
124 | #define COLPOS(x) ((x) >> 3) | ||
125 | #define BITPOS(x) ((x) & 0xf) | ||
126 | 115 | ||
127 | /* Define single bit Error positions in Main & Spare area */ | 116 | uint8_t *data_buf; |
128 | #define MAIN_SINGLEBIT_ERROR 0x4 | 117 | unsigned int buf_start; |
129 | #define SPARE_SINGLEBIT_ERROR 0x1 | 118 | int spare_len; |
130 | |||
131 | /* OOB placement block for use with hardware ecc generation */ | ||
132 | static struct nand_ecclayout nand_hw_eccoob_8 = { | ||
133 | .eccbytes = 5, | ||
134 | .eccpos = {6, 7, 8, 9, 10}, | ||
135 | .oobfree = {{0, 5}, {11, 5}, } | ||
136 | }; | 119 | }; |
137 | 120 | ||
138 | static struct nand_ecclayout nand_hw_eccoob_16 = { | 121 | /* OOB placement block for use with hardware ecc generation */ |
122 | static struct nand_ecclayout nandv1_hw_eccoob_smallpage = { | ||
139 | .eccbytes = 5, | 123 | .eccbytes = 5, |
140 | .eccpos = {6, 7, 8, 9, 10}, | 124 | .eccpos = {6, 7, 8, 9, 10}, |
141 | .oobfree = {{0, 5}, {11, 5}, } | 125 | .oobfree = {{0, 5}, {12, 4}, } |
142 | }; | 126 | }; |
143 | 127 | ||
144 | static struct nand_ecclayout nand_hw_eccoob_64 = { | 128 | static struct nand_ecclayout nandv1_hw_eccoob_largepage = { |
145 | .eccbytes = 20, | 129 | .eccbytes = 20, |
146 | .eccpos = {6, 7, 8, 9, 10, 22, 23, 24, 25, 26, | 130 | .eccpos = {6, 7, 8, 9, 10, 22, 23, 24, 25, 26, |
147 | 38, 39, 40, 41, 42, 54, 55, 56, 57, 58}, | 131 | 38, 39, 40, 41, 42, 54, 55, 56, 57, 58}, |
148 | .oobfree = {{2, 4}, {11, 10}, {27, 10}, {43, 10}, {59, 5}, } | 132 | .oobfree = {{2, 4}, {11, 10}, {27, 10}, {43, 10}, {59, 5}, } |
149 | }; | 133 | }; |
150 | 134 | ||
135 | /* OOB description for 512 byte pages with 16 byte OOB */ | ||
136 | static struct nand_ecclayout nandv2_hw_eccoob_smallpage = { | ||
137 | .eccbytes = 1 * 9, | ||
138 | .eccpos = { | ||
139 | 7, 8, 9, 10, 11, 12, 13, 14, 15 | ||
140 | }, | ||
141 | .oobfree = { | ||
142 | {.offset = 0, .length = 5} | ||
143 | } | ||
144 | }; | ||
145 | |||
146 | /* OOB description for 2048 byte pages with 64 byte OOB */ | ||
147 | static struct nand_ecclayout nandv2_hw_eccoob_largepage = { | ||
148 | .eccbytes = 4 * 9, | ||
149 | .eccpos = { | ||
150 | 7, 8, 9, 10, 11, 12, 13, 14, 15, | ||
151 | 23, 24, 25, 26, 27, 28, 29, 30, 31, | ||
152 | 39, 40, 41, 42, 43, 44, 45, 46, 47, | ||
153 | 55, 56, 57, 58, 59, 60, 61, 62, 63 | ||
154 | }, | ||
155 | .oobfree = { | ||
156 | {.offset = 2, .length = 4}, | ||
157 | {.offset = 16, .length = 7}, | ||
158 | {.offset = 32, .length = 7}, | ||
159 | {.offset = 48, .length = 7} | ||
160 | } | ||
161 | }; | ||
162 | |||
151 | #ifdef CONFIG_MTD_PARTITIONS | 163 | #ifdef CONFIG_MTD_PARTITIONS |
152 | static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL }; | 164 | static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL }; |
153 | #endif | 165 | #endif |
@@ -170,10 +182,10 @@ static irqreturn_t mxc_nfc_irq(int irq, void *dev_id) | |||
170 | /* This function polls the NANDFC to wait for the basic operation to | 182 | /* This function polls the NANDFC to wait for the basic operation to |
171 | * complete by checking the INT bit of config2 register. | 183 | * complete by checking the INT bit of config2 register. |
172 | */ | 184 | */ |
173 | static void wait_op_done(struct mxc_nand_host *host, int max_retries, | 185 | static void wait_op_done(struct mxc_nand_host *host, int useirq) |
174 | uint16_t param, int useirq) | ||
175 | { | 186 | { |
176 | uint32_t tmp; | 187 | uint32_t tmp; |
188 | int max_retries = 2000; | ||
177 | 189 | ||
178 | if (useirq) { | 190 | if (useirq) { |
179 | if ((readw(host->regs + NFC_CONFIG2) & NFC_INT) == 0) { | 191 | if ((readw(host->regs + NFC_CONFIG2) & NFC_INT) == 0) { |
@@ -200,8 +212,8 @@ static void wait_op_done(struct mxc_nand_host *host, int max_retries, | |||
200 | udelay(1); | 212 | udelay(1); |
201 | } | 213 | } |
202 | if (max_retries < 0) | 214 | if (max_retries < 0) |
203 | DEBUG(MTD_DEBUG_LEVEL0, "%s(%d): INT not set\n", | 215 | DEBUG(MTD_DEBUG_LEVEL0, "%s: INT not set\n", |
204 | __func__, param); | 216 | __func__); |
205 | } | 217 | } |
206 | } | 218 | } |
207 | 219 | ||
@@ -215,7 +227,7 @@ static void send_cmd(struct mxc_nand_host *host, uint16_t cmd, int useirq) | |||
215 | writew(NFC_CMD, host->regs + NFC_CONFIG2); | 227 | writew(NFC_CMD, host->regs + NFC_CONFIG2); |
216 | 228 | ||
217 | /* Wait for operation to complete */ | 229 | /* Wait for operation to complete */ |
218 | wait_op_done(host, TROP_US_DELAY, cmd, useirq); | 230 | wait_op_done(host, useirq); |
219 | } | 231 | } |
220 | 232 | ||
221 | /* This function sends an address (or partial address) to the | 233 | /* This function sends an address (or partial address) to the |
@@ -229,82 +241,47 @@ static void send_addr(struct mxc_nand_host *host, uint16_t addr, int islast) | |||
229 | writew(NFC_ADDR, host->regs + NFC_CONFIG2); | 241 | writew(NFC_ADDR, host->regs + NFC_CONFIG2); |
230 | 242 | ||
231 | /* Wait for operation to complete */ | 243 | /* Wait for operation to complete */ |
232 | wait_op_done(host, TROP_US_DELAY, addr, islast); | 244 | wait_op_done(host, islast); |
233 | } | 245 | } |
234 | 246 | ||
235 | /* This function requests the NANDFC to initate the transfer | 247 | static void send_page(struct mtd_info *mtd, unsigned int ops) |
236 | * of data currently in the NANDFC RAM buffer to the NAND device. */ | ||
237 | static void send_prog_page(struct mxc_nand_host *host, uint8_t buf_id, | ||
238 | int spare_only) | ||
239 | { | 248 | { |
240 | DEBUG(MTD_DEBUG_LEVEL3, "send_prog_page (%d)\n", spare_only); | 249 | struct nand_chip *nand_chip = mtd->priv; |
241 | 250 | struct mxc_nand_host *host = nand_chip->priv; | |
242 | /* NANDFC buffer 0 is used for page read/write */ | 251 | int bufs, i; |
243 | writew(buf_id, host->regs + NFC_BUF_ADDR); | ||
244 | |||
245 | /* Configure spare or page+spare access */ | ||
246 | if (!host->pagesize_2k) { | ||
247 | uint16_t config1 = readw(host->regs + NFC_CONFIG1); | ||
248 | if (spare_only) | ||
249 | config1 |= NFC_SP_EN; | ||
250 | else | ||
251 | config1 &= ~(NFC_SP_EN); | ||
252 | writew(config1, host->regs + NFC_CONFIG1); | ||
253 | } | ||
254 | 252 | ||
255 | writew(NFC_INPUT, host->regs + NFC_CONFIG2); | 253 | if (nfc_is_v1() && mtd->writesize > 512) |
254 | bufs = 4; | ||
255 | else | ||
256 | bufs = 1; | ||
256 | 257 | ||
257 | /* Wait for operation to complete */ | 258 | for (i = 0; i < bufs; i++) { |
258 | wait_op_done(host, TROP_US_DELAY, spare_only, true); | ||
259 | } | ||
260 | 259 | ||
261 | /* Requests NANDFC to initated the transfer of data from the | 260 | /* NANDFC buffer 0 is used for page read/write */ |
262 | * NAND device into in the NANDFC ram buffer. */ | 261 | writew(i, host->regs + NFC_BUF_ADDR); |
263 | static void send_read_page(struct mxc_nand_host *host, uint8_t buf_id, | ||
264 | int spare_only) | ||
265 | { | ||
266 | DEBUG(MTD_DEBUG_LEVEL3, "send_read_page (%d)\n", spare_only); | ||
267 | 262 | ||
268 | /* NANDFC buffer 0 is used for page read/write */ | 263 | writew(ops, host->regs + NFC_CONFIG2); |
269 | writew(buf_id, host->regs + NFC_BUF_ADDR); | ||
270 | 264 | ||
271 | /* Configure spare or page+spare access */ | 265 | /* Wait for operation to complete */ |
272 | if (!host->pagesize_2k) { | 266 | wait_op_done(host, true); |
273 | uint32_t config1 = readw(host->regs + NFC_CONFIG1); | ||
274 | if (spare_only) | ||
275 | config1 |= NFC_SP_EN; | ||
276 | else | ||
277 | config1 &= ~NFC_SP_EN; | ||
278 | writew(config1, host->regs + NFC_CONFIG1); | ||
279 | } | 267 | } |
280 | |||
281 | writew(NFC_OUTPUT, host->regs + NFC_CONFIG2); | ||
282 | |||
283 | /* Wait for operation to complete */ | ||
284 | wait_op_done(host, TROP_US_DELAY, spare_only, true); | ||
285 | } | 268 | } |
286 | 269 | ||
287 | /* Request the NANDFC to perform a read of the NAND device ID. */ | 270 | /* Request the NANDFC to perform a read of the NAND device ID. */ |
288 | static void send_read_id(struct mxc_nand_host *host) | 271 | static void send_read_id(struct mxc_nand_host *host) |
289 | { | 272 | { |
290 | struct nand_chip *this = &host->nand; | 273 | struct nand_chip *this = &host->nand; |
291 | uint16_t tmp; | ||
292 | 274 | ||
293 | /* NANDFC buffer 0 is used for device ID output */ | 275 | /* NANDFC buffer 0 is used for device ID output */ |
294 | writew(0x0, host->regs + NFC_BUF_ADDR); | 276 | writew(0x0, host->regs + NFC_BUF_ADDR); |
295 | 277 | ||
296 | /* Read ID into main buffer */ | ||
297 | tmp = readw(host->regs + NFC_CONFIG1); | ||
298 | tmp &= ~NFC_SP_EN; | ||
299 | writew(tmp, host->regs + NFC_CONFIG1); | ||
300 | |||
301 | writew(NFC_ID, host->regs + NFC_CONFIG2); | 278 | writew(NFC_ID, host->regs + NFC_CONFIG2); |
302 | 279 | ||
303 | /* Wait for operation to complete */ | 280 | /* Wait for operation to complete */ |
304 | wait_op_done(host, TROP_US_DELAY, 0, true); | 281 | wait_op_done(host, true); |
305 | 282 | ||
306 | if (this->options & NAND_BUSWIDTH_16) { | 283 | if (this->options & NAND_BUSWIDTH_16) { |
307 | void __iomem *main_buf = host->regs + MAIN_AREA0; | 284 | void __iomem *main_buf = host->main_area0; |
308 | /* compress the ID info */ | 285 | /* compress the ID info */ |
309 | writeb(readb(main_buf + 2), main_buf + 1); | 286 | writeb(readb(main_buf + 2), main_buf + 1); |
310 | writeb(readb(main_buf + 4), main_buf + 2); | 287 | writeb(readb(main_buf + 4), main_buf + 2); |
@@ -312,15 +289,16 @@ static void send_read_id(struct mxc_nand_host *host) | |||
312 | writeb(readb(main_buf + 8), main_buf + 4); | 289 | writeb(readb(main_buf + 8), main_buf + 4); |
313 | writeb(readb(main_buf + 10), main_buf + 5); | 290 | writeb(readb(main_buf + 10), main_buf + 5); |
314 | } | 291 | } |
292 | memcpy(host->data_buf, host->main_area0, 16); | ||
315 | } | 293 | } |
316 | 294 | ||
317 | /* This function requests the NANDFC to perform a read of the | 295 | /* This function requests the NANDFC to perform a read of the |
318 | * NAND device status and returns the current status. */ | 296 | * NAND device status and returns the current status. */ |
319 | static uint16_t get_dev_status(struct mxc_nand_host *host) | 297 | static uint16_t get_dev_status(struct mxc_nand_host *host) |
320 | { | 298 | { |
321 | void __iomem *main_buf = host->regs + MAIN_AREA1; | 299 | void __iomem *main_buf = host->main_area1; |
322 | uint32_t store; | 300 | uint32_t store; |
323 | uint16_t ret, tmp; | 301 | uint16_t ret; |
324 | /* Issue status request to NAND device */ | 302 | /* Issue status request to NAND device */ |
325 | 303 | ||
326 | /* store the main area1 first word, later do recovery */ | 304 | /* store the main area1 first word, later do recovery */ |
@@ -329,15 +307,10 @@ static uint16_t get_dev_status(struct mxc_nand_host *host) | |||
329 | * corruption of read/write buffer on status requests. */ | 307 | * corruption of read/write buffer on status requests. */ |
330 | writew(1, host->regs + NFC_BUF_ADDR); | 308 | writew(1, host->regs + NFC_BUF_ADDR); |
331 | 309 | ||
332 | /* Read status into main buffer */ | ||
333 | tmp = readw(host->regs + NFC_CONFIG1); | ||
334 | tmp &= ~NFC_SP_EN; | ||
335 | writew(tmp, host->regs + NFC_CONFIG1); | ||
336 | |||
337 | writew(NFC_STATUS, host->regs + NFC_CONFIG2); | 310 | writew(NFC_STATUS, host->regs + NFC_CONFIG2); |
338 | 311 | ||
339 | /* Wait for operation to complete */ | 312 | /* Wait for operation to complete */ |
340 | wait_op_done(host, TROP_US_DELAY, 0, true); | 313 | wait_op_done(host, true); |
341 | 314 | ||
342 | /* Status is placed in first word of main buffer */ | 315 | /* Status is placed in first word of main buffer */ |
343 | /* get status, then recovery area 1 data */ | 316 | /* get status, then recovery area 1 data */ |
@@ -397,32 +370,14 @@ static u_char mxc_nand_read_byte(struct mtd_info *mtd) | |||
397 | { | 370 | { |
398 | struct nand_chip *nand_chip = mtd->priv; | 371 | struct nand_chip *nand_chip = mtd->priv; |
399 | struct mxc_nand_host *host = nand_chip->priv; | 372 | struct mxc_nand_host *host = nand_chip->priv; |
400 | uint8_t ret = 0; | 373 | uint8_t ret; |
401 | uint16_t col, rd_word; | ||
402 | uint16_t __iomem *main_buf = host->regs + MAIN_AREA0; | ||
403 | uint16_t __iomem *spare_buf = host->regs + SPARE_AREA0; | ||
404 | 374 | ||
405 | /* Check for status request */ | 375 | /* Check for status request */ |
406 | if (host->status_request) | 376 | if (host->status_request) |
407 | return get_dev_status(host) & 0xFF; | 377 | return get_dev_status(host) & 0xFF; |
408 | 378 | ||
409 | /* Get column for 16-bit access */ | 379 | ret = *(uint8_t *)(host->data_buf + host->buf_start); |
410 | col = host->col_addr >> 1; | 380 | host->buf_start++; |
411 | |||
412 | /* If we are accessing the spare region */ | ||
413 | if (host->spare_only) | ||
414 | rd_word = readw(&spare_buf[col]); | ||
415 | else | ||
416 | rd_word = readw(&main_buf[col]); | ||
417 | |||
418 | /* Pick upper/lower byte of word from RAM buffer */ | ||
419 | if (host->col_addr & 0x1) | ||
420 | ret = (rd_word >> 8) & 0xFF; | ||
421 | else | ||
422 | ret = rd_word & 0xFF; | ||
423 | |||
424 | /* Update saved column address */ | ||
425 | host->col_addr++; | ||
426 | 381 | ||
427 | return ret; | 382 | return ret; |
428 | } | 383 | } |
@@ -431,33 +386,10 @@ static uint16_t mxc_nand_read_word(struct mtd_info *mtd) | |||
431 | { | 386 | { |
432 | struct nand_chip *nand_chip = mtd->priv; | 387 | struct nand_chip *nand_chip = mtd->priv; |
433 | struct mxc_nand_host *host = nand_chip->priv; | 388 | struct mxc_nand_host *host = nand_chip->priv; |
434 | uint16_t col, rd_word, ret; | 389 | uint16_t ret; |
435 | uint16_t __iomem *p; | ||
436 | |||
437 | DEBUG(MTD_DEBUG_LEVEL3, | ||
438 | "mxc_nand_read_word(col = %d)\n", host->col_addr); | ||
439 | |||
440 | col = host->col_addr; | ||
441 | /* Adjust saved column address */ | ||
442 | if (col < mtd->writesize && host->spare_only) | ||
443 | col += mtd->writesize; | ||
444 | 390 | ||
445 | if (col < mtd->writesize) | 391 | ret = *(uint16_t *)(host->data_buf + host->buf_start); |
446 | p = (host->regs + MAIN_AREA0) + (col >> 1); | 392 | host->buf_start += 2; |
447 | else | ||
448 | p = (host->regs + SPARE_AREA0) + ((col - mtd->writesize) >> 1); | ||
449 | |||
450 | if (col & 1) { | ||
451 | rd_word = readw(p); | ||
452 | ret = (rd_word >> 8) & 0xff; | ||
453 | rd_word = readw(&p[1]); | ||
454 | ret |= (rd_word << 8) & 0xff00; | ||
455 | |||
456 | } else | ||
457 | ret = readw(p); | ||
458 | |||
459 | /* Update saved column address */ | ||
460 | host->col_addr = col + 2; | ||
461 | 393 | ||
462 | return ret; | 394 | return ret; |
463 | } | 395 | } |
@@ -470,94 +402,14 @@ static void mxc_nand_write_buf(struct mtd_info *mtd, | |||
470 | { | 402 | { |
471 | struct nand_chip *nand_chip = mtd->priv; | 403 | struct nand_chip *nand_chip = mtd->priv; |
472 | struct mxc_nand_host *host = nand_chip->priv; | 404 | struct mxc_nand_host *host = nand_chip->priv; |
473 | int n, col, i = 0; | 405 | u16 col = host->buf_start; |
474 | 406 | int n = mtd->oobsize + mtd->writesize - col; | |
475 | DEBUG(MTD_DEBUG_LEVEL3, | ||
476 | "mxc_nand_write_buf(col = %d, len = %d)\n", host->col_addr, | ||
477 | len); | ||
478 | |||
479 | col = host->col_addr; | ||
480 | 407 | ||
481 | /* Adjust saved column address */ | 408 | n = min(n, len); |
482 | if (col < mtd->writesize && host->spare_only) | ||
483 | col += mtd->writesize; | ||
484 | 409 | ||
485 | n = mtd->writesize + mtd->oobsize - col; | 410 | memcpy(host->data_buf + col, buf, n); |
486 | n = min(len, n); | ||
487 | |||
488 | DEBUG(MTD_DEBUG_LEVEL3, | ||
489 | "%s:%d: col = %d, n = %d\n", __func__, __LINE__, col, n); | ||
490 | |||
491 | while (n) { | ||
492 | void __iomem *p; | ||
493 | |||
494 | if (col < mtd->writesize) | ||
495 | p = host->regs + MAIN_AREA0 + (col & ~3); | ||
496 | else | ||
497 | p = host->regs + SPARE_AREA0 - | ||
498 | mtd->writesize + (col & ~3); | ||
499 | |||
500 | DEBUG(MTD_DEBUG_LEVEL3, "%s:%d: p = %p\n", __func__, | ||
501 | __LINE__, p); | ||
502 | |||
503 | if (((col | (int)&buf[i]) & 3) || n < 16) { | ||
504 | uint32_t data = 0; | ||
505 | |||
506 | if (col & 3 || n < 4) | ||
507 | data = readl(p); | ||
508 | |||
509 | switch (col & 3) { | ||
510 | case 0: | ||
511 | if (n) { | ||
512 | data = (data & 0xffffff00) | | ||
513 | (buf[i++] << 0); | ||
514 | n--; | ||
515 | col++; | ||
516 | } | ||
517 | case 1: | ||
518 | if (n) { | ||
519 | data = (data & 0xffff00ff) | | ||
520 | (buf[i++] << 8); | ||
521 | n--; | ||
522 | col++; | ||
523 | } | ||
524 | case 2: | ||
525 | if (n) { | ||
526 | data = (data & 0xff00ffff) | | ||
527 | (buf[i++] << 16); | ||
528 | n--; | ||
529 | col++; | ||
530 | } | ||
531 | case 3: | ||
532 | if (n) { | ||
533 | data = (data & 0x00ffffff) | | ||
534 | (buf[i++] << 24); | ||
535 | n--; | ||
536 | col++; | ||
537 | } | ||
538 | } | ||
539 | |||
540 | writel(data, p); | ||
541 | } else { | ||
542 | int m = mtd->writesize - col; | ||
543 | 411 | ||
544 | if (col >= mtd->writesize) | 412 | host->buf_start += n; |
545 | m += mtd->oobsize; | ||
546 | |||
547 | m = min(n, m) & ~3; | ||
548 | |||
549 | DEBUG(MTD_DEBUG_LEVEL3, | ||
550 | "%s:%d: n = %d, m = %d, i = %d, col = %d\n", | ||
551 | __func__, __LINE__, n, m, i, col); | ||
552 | |||
553 | memcpy(p, &buf[i], m); | ||
554 | col += m; | ||
555 | i += m; | ||
556 | n -= m; | ||
557 | } | ||
558 | } | ||
559 | /* Update saved column address */ | ||
560 | host->col_addr = col; | ||
561 | } | 413 | } |
562 | 414 | ||
563 | /* Read the data buffer from the NAND Flash. To read the data from NAND | 415 | /* Read the data buffer from the NAND Flash. To read the data from NAND |
@@ -568,75 +420,14 @@ static void mxc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) | |||
568 | { | 420 | { |
569 | struct nand_chip *nand_chip = mtd->priv; | 421 | struct nand_chip *nand_chip = mtd->priv; |
570 | struct mxc_nand_host *host = nand_chip->priv; | 422 | struct mxc_nand_host *host = nand_chip->priv; |
571 | int n, col, i = 0; | 423 | u16 col = host->buf_start; |
572 | 424 | int n = mtd->oobsize + mtd->writesize - col; | |
573 | DEBUG(MTD_DEBUG_LEVEL3, | ||
574 | "mxc_nand_read_buf(col = %d, len = %d)\n", host->col_addr, len); | ||
575 | |||
576 | col = host->col_addr; | ||
577 | 425 | ||
578 | /* Adjust saved column address */ | 426 | n = min(n, len); |
579 | if (col < mtd->writesize && host->spare_only) | ||
580 | col += mtd->writesize; | ||
581 | 427 | ||
582 | n = mtd->writesize + mtd->oobsize - col; | 428 | memcpy(buf, host->data_buf + col, len); |
583 | n = min(len, n); | ||
584 | |||
585 | while (n) { | ||
586 | void __iomem *p; | ||
587 | |||
588 | if (col < mtd->writesize) | ||
589 | p = host->regs + MAIN_AREA0 + (col & ~3); | ||
590 | else | ||
591 | p = host->regs + SPARE_AREA0 - | ||
592 | mtd->writesize + (col & ~3); | ||
593 | |||
594 | if (((col | (int)&buf[i]) & 3) || n < 16) { | ||
595 | uint32_t data; | ||
596 | |||
597 | data = readl(p); | ||
598 | switch (col & 3) { | ||
599 | case 0: | ||
600 | if (n) { | ||
601 | buf[i++] = (uint8_t) (data); | ||
602 | n--; | ||
603 | col++; | ||
604 | } | ||
605 | case 1: | ||
606 | if (n) { | ||
607 | buf[i++] = (uint8_t) (data >> 8); | ||
608 | n--; | ||
609 | col++; | ||
610 | } | ||
611 | case 2: | ||
612 | if (n) { | ||
613 | buf[i++] = (uint8_t) (data >> 16); | ||
614 | n--; | ||
615 | col++; | ||
616 | } | ||
617 | case 3: | ||
618 | if (n) { | ||
619 | buf[i++] = (uint8_t) (data >> 24); | ||
620 | n--; | ||
621 | col++; | ||
622 | } | ||
623 | } | ||
624 | } else { | ||
625 | int m = mtd->writesize - col; | ||
626 | |||
627 | if (col >= mtd->writesize) | ||
628 | m += mtd->oobsize; | ||
629 | |||
630 | m = min(n, m) & ~3; | ||
631 | memcpy(&buf[i], p, m); | ||
632 | col += m; | ||
633 | i += m; | ||
634 | n -= m; | ||
635 | } | ||
636 | } | ||
637 | /* Update saved column address */ | ||
638 | host->col_addr = col; | ||
639 | 429 | ||
430 | host->buf_start += len; | ||
640 | } | 431 | } |
641 | 432 | ||
642 | /* Used by the upper layer to verify the data in NAND Flash | 433 | /* Used by the upper layer to verify the data in NAND Flash |
@@ -654,23 +445,6 @@ static void mxc_nand_select_chip(struct mtd_info *mtd, int chip) | |||
654 | struct nand_chip *nand_chip = mtd->priv; | 445 | struct nand_chip *nand_chip = mtd->priv; |
655 | struct mxc_nand_host *host = nand_chip->priv; | 446 | struct mxc_nand_host *host = nand_chip->priv; |
656 | 447 | ||
657 | #ifdef CONFIG_MTD_NAND_MXC_FORCE_CE | ||
658 | if (chip > 0) { | ||
659 | DEBUG(MTD_DEBUG_LEVEL0, | ||
660 | "ERROR: Illegal chip select (chip = %d)\n", chip); | ||
661 | return; | ||
662 | } | ||
663 | |||
664 | if (chip == -1) { | ||
665 | writew(readw(host->regs + NFC_CONFIG1) & ~NFC_CE, | ||
666 | host->regs + NFC_CONFIG1); | ||
667 | return; | ||
668 | } | ||
669 | |||
670 | writew(readw(host->regs + NFC_CONFIG1) | NFC_CE, | ||
671 | host->regs + NFC_CONFIG1); | ||
672 | #endif | ||
673 | |||
674 | switch (chip) { | 448 | switch (chip) { |
675 | case -1: | 449 | case -1: |
676 | /* Disable the NFC clock */ | 450 | /* Disable the NFC clock */ |
@@ -692,94 +466,40 @@ static void mxc_nand_select_chip(struct mtd_info *mtd, int chip) | |||
692 | } | 466 | } |
693 | } | 467 | } |
694 | 468 | ||
695 | /* Used by the upper layer to write command to NAND Flash for | 469 | /* |
696 | * different operations to be carried out on NAND Flash */ | 470 | * Function to transfer data to/from spare area. |
697 | static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | 471 | */ |
698 | int column, int page_addr) | 472 | static void copy_spare(struct mtd_info *mtd, bool bfrom) |
699 | { | 473 | { |
700 | struct nand_chip *nand_chip = mtd->priv; | 474 | struct nand_chip *this = mtd->priv; |
701 | struct mxc_nand_host *host = nand_chip->priv; | 475 | struct mxc_nand_host *host = this->priv; |
702 | int useirq = true; | 476 | u16 i, j; |
703 | 477 | u16 n = mtd->writesize >> 9; | |
704 | DEBUG(MTD_DEBUG_LEVEL3, | 478 | u8 *d = host->data_buf + mtd->writesize; |
705 | "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n", | 479 | u8 *s = host->spare0; |
706 | command, column, page_addr); | 480 | u16 t = host->spare_len; |
707 | 481 | ||
708 | /* Reset command state information */ | 482 | j = (mtd->oobsize / n >> 1) << 1; |
709 | host->status_request = false; | 483 | |
710 | 484 | if (bfrom) { | |
711 | /* Command pre-processing step */ | 485 | for (i = 0; i < n - 1; i++) |
712 | switch (command) { | 486 | memcpy(d + i * j, s + i * t, j); |
713 | 487 | ||
714 | case NAND_CMD_STATUS: | 488 | /* the last section */ |
715 | host->col_addr = 0; | 489 | memcpy(d + i * j, s + i * t, mtd->oobsize - i * j); |
716 | host->status_request = true; | 490 | } else { |
717 | break; | 491 | for (i = 0; i < n - 1; i++) |
718 | 492 | memcpy(&s[i * t], &d[i * j], j); | |
719 | case NAND_CMD_READ0: | ||
720 | host->col_addr = column; | ||
721 | host->spare_only = false; | ||
722 | useirq = false; | ||
723 | break; | ||
724 | |||
725 | case NAND_CMD_READOOB: | ||
726 | host->col_addr = column; | ||
727 | host->spare_only = true; | ||
728 | useirq = false; | ||
729 | if (host->pagesize_2k) | ||
730 | command = NAND_CMD_READ0; /* only READ0 is valid */ | ||
731 | break; | ||
732 | |||
733 | case NAND_CMD_SEQIN: | ||
734 | if (column >= mtd->writesize) { | ||
735 | /* | ||
736 | * FIXME: before send SEQIN command for write OOB, | ||
737 | * We must read one page out. | ||
738 | * For K9F1GXX has no READ1 command to set current HW | ||
739 | * pointer to spare area, we must write the whole page | ||
740 | * including OOB together. | ||
741 | */ | ||
742 | if (host->pagesize_2k) | ||
743 | /* call ourself to read a page */ | ||
744 | mxc_nand_command(mtd, NAND_CMD_READ0, 0, | ||
745 | page_addr); | ||
746 | |||
747 | host->col_addr = column - mtd->writesize; | ||
748 | host->spare_only = true; | ||
749 | |||
750 | /* Set program pointer to spare region */ | ||
751 | if (!host->pagesize_2k) | ||
752 | send_cmd(host, NAND_CMD_READOOB, false); | ||
753 | } else { | ||
754 | host->spare_only = false; | ||
755 | host->col_addr = column; | ||
756 | |||
757 | /* Set program pointer to page start */ | ||
758 | if (!host->pagesize_2k) | ||
759 | send_cmd(host, NAND_CMD_READ0, false); | ||
760 | } | ||
761 | useirq = false; | ||
762 | break; | ||
763 | |||
764 | case NAND_CMD_PAGEPROG: | ||
765 | send_prog_page(host, 0, host->spare_only); | ||
766 | |||
767 | if (host->pagesize_2k) { | ||
768 | /* data in 4 areas datas */ | ||
769 | send_prog_page(host, 1, host->spare_only); | ||
770 | send_prog_page(host, 2, host->spare_only); | ||
771 | send_prog_page(host, 3, host->spare_only); | ||
772 | } | ||
773 | |||
774 | break; | ||
775 | 493 | ||
776 | case NAND_CMD_ERASE1: | 494 | /* the last section */ |
777 | useirq = false; | 495 | memcpy(&s[i * t], &d[i * j], mtd->oobsize - i * j); |
778 | break; | ||
779 | } | 496 | } |
497 | } | ||
780 | 498 | ||
781 | /* Write out the command to the device. */ | 499 | static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr) |
782 | send_cmd(host, command, useirq); | 500 | { |
501 | struct nand_chip *nand_chip = mtd->priv; | ||
502 | struct mxc_nand_host *host = nand_chip->priv; | ||
783 | 503 | ||
784 | /* Write out column address, if necessary */ | 504 | /* Write out column address, if necessary */ |
785 | if (column != -1) { | 505 | if (column != -1) { |
@@ -787,11 +507,11 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | |||
787 | * MXC NANDFC can only perform full page+spare or | 507 | * MXC NANDFC can only perform full page+spare or |
788 | * spare-only read/write. When the upper layers | 508 | * spare-only read/write. When the upper layers |
789 | * layers perform a read/write buf operation, | 509 | * layers perform a read/write buf operation, |
790 | * we will used the saved column adress to index into | 510 | * we will used the saved column address to index into |
791 | * the full page. | 511 | * the full page. |
792 | */ | 512 | */ |
793 | send_addr(host, 0, page_addr == -1); | 513 | send_addr(host, 0, page_addr == -1); |
794 | if (host->pagesize_2k) | 514 | if (mtd->writesize > 512) |
795 | /* another col addr cycle for 2k page */ | 515 | /* another col addr cycle for 2k page */ |
796 | send_addr(host, 0, false); | 516 | send_addr(host, 0, false); |
797 | } | 517 | } |
@@ -801,7 +521,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | |||
801 | /* paddr_0 - p_addr_7 */ | 521 | /* paddr_0 - p_addr_7 */ |
802 | send_addr(host, (page_addr & 0xff), false); | 522 | send_addr(host, (page_addr & 0xff), false); |
803 | 523 | ||
804 | if (host->pagesize_2k) { | 524 | if (mtd->writesize > 512) { |
805 | if (mtd->size >= 0x10000000) { | 525 | if (mtd->size >= 0x10000000) { |
806 | /* paddr_8 - paddr_15 */ | 526 | /* paddr_8 - paddr_15 */ |
807 | send_addr(host, (page_addr >> 8) & 0xff, false); | 527 | send_addr(host, (page_addr >> 8) & 0xff, false); |
@@ -820,52 +540,136 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | |||
820 | send_addr(host, (page_addr >> 8) & 0xff, true); | 540 | send_addr(host, (page_addr >> 8) & 0xff, true); |
821 | } | 541 | } |
822 | } | 542 | } |
543 | } | ||
544 | |||
545 | /* Used by the upper layer to write command to NAND Flash for | ||
546 | * different operations to be carried out on NAND Flash */ | ||
547 | static void mxc_nand_command(struct mtd_info *mtd, unsigned command, | ||
548 | int column, int page_addr) | ||
549 | { | ||
550 | struct nand_chip *nand_chip = mtd->priv; | ||
551 | struct mxc_nand_host *host = nand_chip->priv; | ||
552 | |||
553 | DEBUG(MTD_DEBUG_LEVEL3, | ||
554 | "mxc_nand_command (cmd = 0x%x, col = 0x%x, page = 0x%x)\n", | ||
555 | command, column, page_addr); | ||
556 | |||
557 | /* Reset command state information */ | ||
558 | host->status_request = false; | ||
823 | 559 | ||
824 | /* Command post-processing step */ | 560 | /* Command pre-processing step */ |
825 | switch (command) { | 561 | switch (command) { |
826 | 562 | ||
827 | case NAND_CMD_RESET: | 563 | case NAND_CMD_STATUS: |
564 | host->buf_start = 0; | ||
565 | host->status_request = true; | ||
566 | |||
567 | send_cmd(host, command, true); | ||
568 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
828 | break; | 569 | break; |
829 | 570 | ||
830 | case NAND_CMD_READOOB: | ||
831 | case NAND_CMD_READ0: | 571 | case NAND_CMD_READ0: |
832 | if (host->pagesize_2k) { | 572 | case NAND_CMD_READOOB: |
833 | /* send read confirm command */ | 573 | if (command == NAND_CMD_READ0) |
574 | host->buf_start = column; | ||
575 | else | ||
576 | host->buf_start = column + mtd->writesize; | ||
577 | |||
578 | if (mtd->writesize > 512) | ||
579 | command = NAND_CMD_READ0; /* only READ0 is valid */ | ||
580 | |||
581 | send_cmd(host, command, false); | ||
582 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
583 | |||
584 | if (mtd->writesize > 512) | ||
834 | send_cmd(host, NAND_CMD_READSTART, true); | 585 | send_cmd(host, NAND_CMD_READSTART, true); |
835 | /* read for each AREA */ | 586 | |
836 | send_read_page(host, 0, host->spare_only); | 587 | send_page(mtd, NFC_OUTPUT); |
837 | send_read_page(host, 1, host->spare_only); | 588 | |
838 | send_read_page(host, 2, host->spare_only); | 589 | memcpy(host->data_buf, host->main_area0, mtd->writesize); |
839 | send_read_page(host, 3, host->spare_only); | 590 | copy_spare(mtd, true); |
840 | } else | ||
841 | send_read_page(host, 0, host->spare_only); | ||
842 | break; | 591 | break; |
843 | 592 | ||
844 | case NAND_CMD_READID: | 593 | case NAND_CMD_SEQIN: |
845 | host->col_addr = 0; | 594 | if (column >= mtd->writesize) { |
846 | send_read_id(host); | 595 | /* |
596 | * FIXME: before send SEQIN command for write OOB, | ||
597 | * We must read one page out. | ||
598 | * For K9F1GXX has no READ1 command to set current HW | ||
599 | * pointer to spare area, we must write the whole page | ||
600 | * including OOB together. | ||
601 | */ | ||
602 | if (mtd->writesize > 512) | ||
603 | /* call ourself to read a page */ | ||
604 | mxc_nand_command(mtd, NAND_CMD_READ0, 0, | ||
605 | page_addr); | ||
606 | |||
607 | host->buf_start = column; | ||
608 | |||
609 | /* Set program pointer to spare region */ | ||
610 | if (mtd->writesize == 512) | ||
611 | send_cmd(host, NAND_CMD_READOOB, false); | ||
612 | } else { | ||
613 | host->buf_start = column; | ||
614 | |||
615 | /* Set program pointer to page start */ | ||
616 | if (mtd->writesize == 512) | ||
617 | send_cmd(host, NAND_CMD_READ0, false); | ||
618 | } | ||
619 | |||
620 | send_cmd(host, command, false); | ||
621 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
847 | break; | 622 | break; |
848 | 623 | ||
849 | case NAND_CMD_PAGEPROG: | 624 | case NAND_CMD_PAGEPROG: |
625 | memcpy(host->main_area0, host->data_buf, mtd->writesize); | ||
626 | copy_spare(mtd, false); | ||
627 | send_page(mtd, NFC_INPUT); | ||
628 | send_cmd(host, command, true); | ||
629 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
850 | break; | 630 | break; |
851 | 631 | ||
852 | case NAND_CMD_STATUS: | 632 | case NAND_CMD_READID: |
633 | send_cmd(host, command, true); | ||
634 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
635 | send_read_id(host); | ||
636 | host->buf_start = column; | ||
853 | break; | 637 | break; |
854 | 638 | ||
639 | case NAND_CMD_ERASE1: | ||
855 | case NAND_CMD_ERASE2: | 640 | case NAND_CMD_ERASE2: |
641 | send_cmd(host, command, false); | ||
642 | mxc_do_addr_cycle(mtd, column, page_addr); | ||
643 | |||
856 | break; | 644 | break; |
857 | } | 645 | } |
858 | } | 646 | } |
859 | 647 | ||
860 | /* Define some generic bad / good block scan pattern which are used | 648 | /* |
861 | * while scanning a device for factory marked good / bad blocks. */ | 649 | * The generic flash bbt decriptors overlap with our ecc |
862 | static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; | 650 | * hardware, so define some i.MX specific ones. |
651 | */ | ||
652 | static uint8_t bbt_pattern[] = { 'B', 'b', 't', '0' }; | ||
653 | static uint8_t mirror_pattern[] = { '1', 't', 'b', 'B' }; | ||
654 | |||
655 | static struct nand_bbt_descr bbt_main_descr = { | ||
656 | .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE | ||
657 | | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, | ||
658 | .offs = 0, | ||
659 | .len = 4, | ||
660 | .veroffs = 4, | ||
661 | .maxblocks = 4, | ||
662 | .pattern = bbt_pattern, | ||
663 | }; | ||
863 | 664 | ||
864 | static struct nand_bbt_descr smallpage_memorybased = { | 665 | static struct nand_bbt_descr bbt_mirror_descr = { |
865 | .options = NAND_BBT_SCAN2NDPAGE, | 666 | .options = NAND_BBT_LASTBLOCK | NAND_BBT_CREATE | NAND_BBT_WRITE |
866 | .offs = 5, | 667 | | NAND_BBT_2BIT | NAND_BBT_VERSION | NAND_BBT_PERCHIP, |
867 | .len = 1, | 668 | .offs = 0, |
868 | .pattern = scan_ff_pattern | 669 | .len = 4, |
670 | .veroffs = 4, | ||
671 | .maxblocks = 4, | ||
672 | .pattern = mirror_pattern, | ||
869 | }; | 673 | }; |
870 | 674 | ||
871 | static int __init mxcnd_probe(struct platform_device *pdev) | 675 | static int __init mxcnd_probe(struct platform_device *pdev) |
@@ -877,12 +681,16 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
877 | struct resource *res; | 681 | struct resource *res; |
878 | uint16_t tmp; | 682 | uint16_t tmp; |
879 | int err = 0, nr_parts = 0; | 683 | int err = 0, nr_parts = 0; |
684 | struct nand_ecclayout *oob_smallpage, *oob_largepage; | ||
880 | 685 | ||
881 | /* Allocate memory for MTD device structure and private data */ | 686 | /* Allocate memory for MTD device structure and private data */ |
882 | host = kzalloc(sizeof(struct mxc_nand_host), GFP_KERNEL); | 687 | host = kzalloc(sizeof(struct mxc_nand_host) + NAND_MAX_PAGESIZE + |
688 | NAND_MAX_OOBSIZE, GFP_KERNEL); | ||
883 | if (!host) | 689 | if (!host) |
884 | return -ENOMEM; | 690 | return -ENOMEM; |
885 | 691 | ||
692 | host->data_buf = (uint8_t *)(host + 1); | ||
693 | |||
886 | host->dev = &pdev->dev; | 694 | host->dev = &pdev->dev; |
887 | /* structures must be linked */ | 695 | /* structures must be linked */ |
888 | this = &host->nand; | 696 | this = &host->nand; |
@@ -890,7 +698,7 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
890 | mtd->priv = this; | 698 | mtd->priv = this; |
891 | mtd->owner = THIS_MODULE; | 699 | mtd->owner = THIS_MODULE; |
892 | mtd->dev.parent = &pdev->dev; | 700 | mtd->dev.parent = &pdev->dev; |
893 | mtd->name = "mxc_nand"; | 701 | mtd->name = DRIVER_NAME; |
894 | 702 | ||
895 | /* 50 us command delay time */ | 703 | /* 50 us command delay time */ |
896 | this->chip_delay = 5; | 704 | this->chip_delay = 5; |
@@ -920,62 +728,93 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
920 | goto eres; | 728 | goto eres; |
921 | } | 729 | } |
922 | 730 | ||
923 | host->regs = ioremap(res->start, res->end - res->start + 1); | 731 | host->base = ioremap(res->start, resource_size(res)); |
924 | if (!host->regs) { | 732 | if (!host->base) { |
925 | err = -ENOMEM; | 733 | err = -ENOMEM; |
926 | goto eres; | 734 | goto eres; |
927 | } | 735 | } |
928 | 736 | ||
737 | host->main_area0 = host->base; | ||
738 | host->main_area1 = host->base + 0x200; | ||
739 | |||
740 | if (nfc_is_v21()) { | ||
741 | host->regs = host->base + 0x1000; | ||
742 | host->spare0 = host->base + 0x1000; | ||
743 | host->spare_len = 64; | ||
744 | oob_smallpage = &nandv2_hw_eccoob_smallpage; | ||
745 | oob_largepage = &nandv2_hw_eccoob_largepage; | ||
746 | } else if (nfc_is_v1()) { | ||
747 | host->regs = host->base; | ||
748 | host->spare0 = host->base + 0x800; | ||
749 | host->spare_len = 16; | ||
750 | oob_smallpage = &nandv1_hw_eccoob_smallpage; | ||
751 | oob_largepage = &nandv1_hw_eccoob_largepage; | ||
752 | } else | ||
753 | BUG(); | ||
754 | |||
755 | /* disable interrupt and spare enable */ | ||
929 | tmp = readw(host->regs + NFC_CONFIG1); | 756 | tmp = readw(host->regs + NFC_CONFIG1); |
930 | tmp |= NFC_INT_MSK; | 757 | tmp |= NFC_INT_MSK; |
758 | tmp &= ~NFC_SP_EN; | ||
931 | writew(tmp, host->regs + NFC_CONFIG1); | 759 | writew(tmp, host->regs + NFC_CONFIG1); |
932 | 760 | ||
933 | init_waitqueue_head(&host->irq_waitq); | 761 | init_waitqueue_head(&host->irq_waitq); |
934 | 762 | ||
935 | host->irq = platform_get_irq(pdev, 0); | 763 | host->irq = platform_get_irq(pdev, 0); |
936 | 764 | ||
937 | err = request_irq(host->irq, mxc_nfc_irq, 0, "mxc_nd", host); | 765 | err = request_irq(host->irq, mxc_nfc_irq, 0, DRIVER_NAME, host); |
938 | if (err) | 766 | if (err) |
939 | goto eirq; | 767 | goto eirq; |
940 | 768 | ||
769 | /* Reset NAND */ | ||
770 | this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | ||
771 | |||
772 | /* preset operation */ | ||
773 | /* Unlock the internal RAM Buffer */ | ||
774 | writew(0x2, host->regs + NFC_CONFIG); | ||
775 | |||
776 | /* Blocks to be unlocked */ | ||
777 | if (nfc_is_v21()) { | ||
778 | writew(0x0, host->regs + NFC_V21_UNLOCKSTART_BLKADDR); | ||
779 | writew(0xffff, host->regs + NFC_V21_UNLOCKEND_BLKADDR); | ||
780 | this->ecc.bytes = 9; | ||
781 | } else if (nfc_is_v1()) { | ||
782 | writew(0x0, host->regs + NFC_V1_UNLOCKSTART_BLKADDR); | ||
783 | writew(0x4000, host->regs + NFC_V1_UNLOCKEND_BLKADDR); | ||
784 | this->ecc.bytes = 3; | ||
785 | } else | ||
786 | BUG(); | ||
787 | |||
788 | /* Unlock Block Command for given address range */ | ||
789 | writew(0x4, host->regs + NFC_WRPROT); | ||
790 | |||
791 | this->ecc.size = 512; | ||
792 | this->ecc.layout = oob_smallpage; | ||
793 | |||
941 | if (pdata->hw_ecc) { | 794 | if (pdata->hw_ecc) { |
942 | this->ecc.calculate = mxc_nand_calculate_ecc; | 795 | this->ecc.calculate = mxc_nand_calculate_ecc; |
943 | this->ecc.hwctl = mxc_nand_enable_hwecc; | 796 | this->ecc.hwctl = mxc_nand_enable_hwecc; |
944 | this->ecc.correct = mxc_nand_correct_data; | 797 | this->ecc.correct = mxc_nand_correct_data; |
945 | this->ecc.mode = NAND_ECC_HW; | 798 | this->ecc.mode = NAND_ECC_HW; |
946 | this->ecc.size = 512; | ||
947 | this->ecc.bytes = 3; | ||
948 | tmp = readw(host->regs + NFC_CONFIG1); | 799 | tmp = readw(host->regs + NFC_CONFIG1); |
949 | tmp |= NFC_ECC_EN; | 800 | tmp |= NFC_ECC_EN; |
950 | writew(tmp, host->regs + NFC_CONFIG1); | 801 | writew(tmp, host->regs + NFC_CONFIG1); |
951 | } else { | 802 | } else { |
952 | this->ecc.size = 512; | ||
953 | this->ecc.bytes = 3; | ||
954 | this->ecc.layout = &nand_hw_eccoob_8; | ||
955 | this->ecc.mode = NAND_ECC_SOFT; | 803 | this->ecc.mode = NAND_ECC_SOFT; |
956 | tmp = readw(host->regs + NFC_CONFIG1); | 804 | tmp = readw(host->regs + NFC_CONFIG1); |
957 | tmp &= ~NFC_ECC_EN; | 805 | tmp &= ~NFC_ECC_EN; |
958 | writew(tmp, host->regs + NFC_CONFIG1); | 806 | writew(tmp, host->regs + NFC_CONFIG1); |
959 | } | 807 | } |
960 | 808 | ||
961 | /* Reset NAND */ | ||
962 | this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); | ||
963 | |||
964 | /* preset operation */ | ||
965 | /* Unlock the internal RAM Buffer */ | ||
966 | writew(0x2, host->regs + NFC_CONFIG); | ||
967 | |||
968 | /* Blocks to be unlocked */ | ||
969 | writew(0x0, host->regs + NFC_UNLOCKSTART_BLKADDR); | ||
970 | writew(0x4000, host->regs + NFC_UNLOCKEND_BLKADDR); | ||
971 | |||
972 | /* Unlock Block Command for given address range */ | ||
973 | writew(0x4, host->regs + NFC_WRPROT); | ||
974 | |||
975 | /* NAND bus width determines access funtions used by upper layer */ | 809 | /* NAND bus width determines access funtions used by upper layer */ |
976 | if (pdata->width == 2) { | 810 | if (pdata->width == 2) |
977 | this->options |= NAND_BUSWIDTH_16; | 811 | this->options |= NAND_BUSWIDTH_16; |
978 | this->ecc.layout = &nand_hw_eccoob_16; | 812 | |
813 | if (pdata->flash_bbt) { | ||
814 | this->bbt_td = &bbt_main_descr; | ||
815 | this->bbt_md = &bbt_mirror_descr; | ||
816 | /* update flash based bbt */ | ||
817 | this->options |= NAND_USE_FLASH_BBT; | ||
979 | } | 818 | } |
980 | 819 | ||
981 | /* first scan to find the device and get the page size */ | 820 | /* first scan to find the device and get the page size */ |
@@ -984,38 +823,8 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
984 | goto escan; | 823 | goto escan; |
985 | } | 824 | } |
986 | 825 | ||
987 | if (mtd->writesize == 2048) { | 826 | if (mtd->writesize == 2048) |
988 | host->pagesize_2k = 1; | 827 | this->ecc.layout = oob_largepage; |
989 | this->badblock_pattern = &smallpage_memorybased; | ||
990 | } | ||
991 | |||
992 | if (this->ecc.mode == NAND_ECC_HW) { | ||
993 | switch (mtd->oobsize) { | ||
994 | case 8: | ||
995 | this->ecc.layout = &nand_hw_eccoob_8; | ||
996 | break; | ||
997 | case 16: | ||
998 | this->ecc.layout = &nand_hw_eccoob_16; | ||
999 | break; | ||
1000 | case 64: | ||
1001 | this->ecc.layout = &nand_hw_eccoob_64; | ||
1002 | break; | ||
1003 | default: | ||
1004 | /* page size not handled by HW ECC */ | ||
1005 | /* switching back to soft ECC */ | ||
1006 | this->ecc.size = 512; | ||
1007 | this->ecc.bytes = 3; | ||
1008 | this->ecc.layout = &nand_hw_eccoob_8; | ||
1009 | this->ecc.mode = NAND_ECC_SOFT; | ||
1010 | this->ecc.calculate = NULL; | ||
1011 | this->ecc.correct = NULL; | ||
1012 | this->ecc.hwctl = NULL; | ||
1013 | tmp = readw(host->regs + NFC_CONFIG1); | ||
1014 | tmp &= ~NFC_ECC_EN; | ||
1015 | writew(tmp, host->regs + NFC_CONFIG1); | ||
1016 | break; | ||
1017 | } | ||
1018 | } | ||
1019 | 828 | ||
1020 | /* second phase scan */ | 829 | /* second phase scan */ |
1021 | if (nand_scan_tail(mtd)) { | 830 | if (nand_scan_tail(mtd)) { |
@@ -1043,7 +852,7 @@ static int __init mxcnd_probe(struct platform_device *pdev) | |||
1043 | escan: | 852 | escan: |
1044 | free_irq(host->irq, host); | 853 | free_irq(host->irq, host); |
1045 | eirq: | 854 | eirq: |
1046 | iounmap(host->regs); | 855 | iounmap(host->base); |
1047 | eres: | 856 | eres: |
1048 | clk_put(host->clk); | 857 | clk_put(host->clk); |
1049 | eclk: | 858 | eclk: |
@@ -1062,7 +871,7 @@ static int __devexit mxcnd_remove(struct platform_device *pdev) | |||
1062 | 871 | ||
1063 | nand_release(&host->mtd); | 872 | nand_release(&host->mtd); |
1064 | free_irq(host->irq, host); | 873 | free_irq(host->irq, host); |
1065 | iounmap(host->regs); | 874 | iounmap(host->base); |
1066 | kfree(host); | 875 | kfree(host); |
1067 | 876 | ||
1068 | return 0; | 877 | return 0; |
@@ -1113,7 +922,7 @@ static struct platform_driver mxcnd_driver = { | |||
1113 | .driver = { | 922 | .driver = { |
1114 | .name = DRIVER_NAME, | 923 | .name = DRIVER_NAME, |
1115 | }, | 924 | }, |
1116 | .remove = __exit_p(mxcnd_remove), | 925 | .remove = __devexit_p(mxcnd_remove), |
1117 | .suspend = mxcnd_suspend, | 926 | .suspend = mxcnd_suspend, |
1118 | .resume = mxcnd_resume, | 927 | .resume = mxcnd_resume, |
1119 | }; | 928 | }; |
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 2957cc70da3d..8f2958fe2148 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c | |||
@@ -428,6 +428,28 @@ static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int getchip, | |||
428 | return nand_isbad_bbt(mtd, ofs, allowbbt); | 428 | return nand_isbad_bbt(mtd, ofs, allowbbt); |
429 | } | 429 | } |
430 | 430 | ||
431 | /** | ||
432 | * panic_nand_wait_ready - [GENERIC] Wait for the ready pin after commands. | ||
433 | * @mtd: MTD device structure | ||
434 | * @timeo: Timeout | ||
435 | * | ||
436 | * Helper function for nand_wait_ready used when needing to wait in interrupt | ||
437 | * context. | ||
438 | */ | ||
439 | static void panic_nand_wait_ready(struct mtd_info *mtd, unsigned long timeo) | ||
440 | { | ||
441 | struct nand_chip *chip = mtd->priv; | ||
442 | int i; | ||
443 | |||
444 | /* Wait for the device to get ready */ | ||
445 | for (i = 0; i < timeo; i++) { | ||
446 | if (chip->dev_ready(mtd)) | ||
447 | break; | ||
448 | touch_softlockup_watchdog(); | ||
449 | mdelay(1); | ||
450 | } | ||
451 | } | ||
452 | |||
431 | /* | 453 | /* |
432 | * Wait for the ready pin, after a command | 454 | * Wait for the ready pin, after a command |
433 | * The timeout is catched later. | 455 | * The timeout is catched later. |
@@ -437,6 +459,10 @@ void nand_wait_ready(struct mtd_info *mtd) | |||
437 | struct nand_chip *chip = mtd->priv; | 459 | struct nand_chip *chip = mtd->priv; |
438 | unsigned long timeo = jiffies + 2; | 460 | unsigned long timeo = jiffies + 2; |
439 | 461 | ||
462 | /* 400ms timeout */ | ||
463 | if (in_interrupt() || oops_in_progress) | ||
464 | return panic_nand_wait_ready(mtd, 400); | ||
465 | |||
440 | led_trigger_event(nand_led_trigger, LED_FULL); | 466 | led_trigger_event(nand_led_trigger, LED_FULL); |
441 | /* wait until command is processed or timeout occures */ | 467 | /* wait until command is processed or timeout occures */ |
442 | do { | 468 | do { |
@@ -672,6 +698,22 @@ static void nand_command_lp(struct mtd_info *mtd, unsigned int command, | |||
672 | } | 698 | } |
673 | 699 | ||
674 | /** | 700 | /** |
701 | * panic_nand_get_device - [GENERIC] Get chip for selected access | ||
702 | * @chip: the nand chip descriptor | ||
703 | * @mtd: MTD device structure | ||
704 | * @new_state: the state which is requested | ||
705 | * | ||
706 | * Used when in panic, no locks are taken. | ||
707 | */ | ||
708 | static void panic_nand_get_device(struct nand_chip *chip, | ||
709 | struct mtd_info *mtd, int new_state) | ||
710 | { | ||
711 | /* Hardware controller shared among independend devices */ | ||
712 | chip->controller->active = chip; | ||
713 | chip->state = new_state; | ||
714 | } | ||
715 | |||
716 | /** | ||
675 | * nand_get_device - [GENERIC] Get chip for selected access | 717 | * nand_get_device - [GENERIC] Get chip for selected access |
676 | * @chip: the nand chip descriptor | 718 | * @chip: the nand chip descriptor |
677 | * @mtd: MTD device structure | 719 | * @mtd: MTD device structure |
@@ -698,8 +740,14 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state) | |||
698 | return 0; | 740 | return 0; |
699 | } | 741 | } |
700 | if (new_state == FL_PM_SUSPENDED) { | 742 | if (new_state == FL_PM_SUSPENDED) { |
701 | spin_unlock(lock); | 743 | if (chip->controller->active->state == FL_PM_SUSPENDED) { |
702 | return (chip->state == FL_PM_SUSPENDED) ? 0 : -EAGAIN; | 744 | chip->state = FL_PM_SUSPENDED; |
745 | spin_unlock(lock); | ||
746 | return 0; | ||
747 | } else { | ||
748 | spin_unlock(lock); | ||
749 | return -EAGAIN; | ||
750 | } | ||
703 | } | 751 | } |
704 | set_current_state(TASK_UNINTERRUPTIBLE); | 752 | set_current_state(TASK_UNINTERRUPTIBLE); |
705 | add_wait_queue(wq, &wait); | 753 | add_wait_queue(wq, &wait); |
@@ -710,6 +758,32 @@ nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, int new_state) | |||
710 | } | 758 | } |
711 | 759 | ||
712 | /** | 760 | /** |
761 | * panic_nand_wait - [GENERIC] wait until the command is done | ||
762 | * @mtd: MTD device structure | ||
763 | * @chip: NAND chip structure | ||
764 | * @timeo: Timeout | ||
765 | * | ||
766 | * Wait for command done. This is a helper function for nand_wait used when | ||
767 | * we are in interrupt context. May happen when in panic and trying to write | ||
768 | * an oops trough mtdoops. | ||
769 | */ | ||
770 | static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip, | ||
771 | unsigned long timeo) | ||
772 | { | ||
773 | int i; | ||
774 | for (i = 0; i < timeo; i++) { | ||
775 | if (chip->dev_ready) { | ||
776 | if (chip->dev_ready(mtd)) | ||
777 | break; | ||
778 | } else { | ||
779 | if (chip->read_byte(mtd) & NAND_STATUS_READY) | ||
780 | break; | ||
781 | } | ||
782 | mdelay(1); | ||
783 | } | ||
784 | } | ||
785 | |||
786 | /** | ||
713 | * nand_wait - [DEFAULT] wait until the command is done | 787 | * nand_wait - [DEFAULT] wait until the command is done |
714 | * @mtd: MTD device structure | 788 | * @mtd: MTD device structure |
715 | * @chip: NAND chip structure | 789 | * @chip: NAND chip structure |
@@ -740,15 +814,19 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) | |||
740 | else | 814 | else |
741 | chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); | 815 | chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); |
742 | 816 | ||
743 | while (time_before(jiffies, timeo)) { | 817 | if (in_interrupt() || oops_in_progress) |
744 | if (chip->dev_ready) { | 818 | panic_nand_wait(mtd, chip, timeo); |
745 | if (chip->dev_ready(mtd)) | 819 | else { |
746 | break; | 820 | while (time_before(jiffies, timeo)) { |
747 | } else { | 821 | if (chip->dev_ready) { |
748 | if (chip->read_byte(mtd) & NAND_STATUS_READY) | 822 | if (chip->dev_ready(mtd)) |
749 | break; | 823 | break; |
824 | } else { | ||
825 | if (chip->read_byte(mtd) & NAND_STATUS_READY) | ||
826 | break; | ||
827 | } | ||
828 | cond_resched(); | ||
750 | } | 829 | } |
751 | cond_resched(); | ||
752 | } | 830 | } |
753 | led_trigger_event(nand_led_trigger, LED_OFF); | 831 | led_trigger_event(nand_led_trigger, LED_OFF); |
754 | 832 | ||
@@ -1949,6 +2027,45 @@ static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, | |||
1949 | } | 2027 | } |
1950 | 2028 | ||
1951 | /** | 2029 | /** |
2030 | * panic_nand_write - [MTD Interface] NAND write with ECC | ||
2031 | * @mtd: MTD device structure | ||
2032 | * @to: offset to write to | ||
2033 | * @len: number of bytes to write | ||
2034 | * @retlen: pointer to variable to store the number of written bytes | ||
2035 | * @buf: the data to write | ||
2036 | * | ||
2037 | * NAND write with ECC. Used when performing writes in interrupt context, this | ||
2038 | * may for example be called by mtdoops when writing an oops while in panic. | ||
2039 | */ | ||
2040 | static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, | ||
2041 | size_t *retlen, const uint8_t *buf) | ||
2042 | { | ||
2043 | struct nand_chip *chip = mtd->priv; | ||
2044 | int ret; | ||
2045 | |||
2046 | /* Do not allow reads past end of device */ | ||
2047 | if ((to + len) > mtd->size) | ||
2048 | return -EINVAL; | ||
2049 | if (!len) | ||
2050 | return 0; | ||
2051 | |||
2052 | /* Wait for the device to get ready. */ | ||
2053 | panic_nand_wait(mtd, chip, 400); | ||
2054 | |||
2055 | /* Grab the device. */ | ||
2056 | panic_nand_get_device(chip, mtd, FL_WRITING); | ||
2057 | |||
2058 | chip->ops.len = len; | ||
2059 | chip->ops.datbuf = (uint8_t *)buf; | ||
2060 | chip->ops.oobbuf = NULL; | ||
2061 | |||
2062 | ret = nand_do_write_ops(mtd, to, &chip->ops); | ||
2063 | |||
2064 | *retlen = chip->ops.retlen; | ||
2065 | return ret; | ||
2066 | } | ||
2067 | |||
2068 | /** | ||
1952 | * nand_write - [MTD Interface] NAND write with ECC | 2069 | * nand_write - [MTD Interface] NAND write with ECC |
1953 | * @mtd: MTD device structure | 2070 | * @mtd: MTD device structure |
1954 | * @to: offset to write to | 2071 | * @to: offset to write to |
@@ -2645,7 +2762,8 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips) | |||
2645 | type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id); | 2762 | type = nand_get_flash_type(mtd, chip, busw, &nand_maf_id); |
2646 | 2763 | ||
2647 | if (IS_ERR(type)) { | 2764 | if (IS_ERR(type)) { |
2648 | printk(KERN_WARNING "No NAND device found!!!\n"); | 2765 | if (!(chip->options & NAND_SCAN_SILENT_NODEV)) |
2766 | printk(KERN_WARNING "No NAND device found.\n"); | ||
2649 | chip->select_chip(mtd, -1); | 2767 | chip->select_chip(mtd, -1); |
2650 | return PTR_ERR(type); | 2768 | return PTR_ERR(type); |
2651 | } | 2769 | } |
@@ -2877,6 +2995,7 @@ int nand_scan_tail(struct mtd_info *mtd) | |||
2877 | mtd->unpoint = NULL; | 2995 | mtd->unpoint = NULL; |
2878 | mtd->read = nand_read; | 2996 | mtd->read = nand_read; |
2879 | mtd->write = nand_write; | 2997 | mtd->write = nand_write; |
2998 | mtd->panic_write = panic_nand_write; | ||
2880 | mtd->read_oob = nand_read_oob; | 2999 | mtd->read_oob = nand_read_oob; |
2881 | mtd->write_oob = nand_write_oob; | 3000 | mtd->write_oob = nand_write_oob; |
2882 | mtd->sync = nand_sync; | 3001 | mtd->sync = nand_sync; |
diff --git a/drivers/mtd/nand/nand_bcm_umi.c b/drivers/mtd/nand/nand_bcm_umi.c new file mode 100644 index 000000000000..46a6bc9c4b74 --- /dev/null +++ b/drivers/mtd/nand/nand_bcm_umi.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright 2004 - 2009 Broadcom Corporation. All rights reserved. | ||
3 | * | ||
4 | * Unless you and Broadcom execute a separate written software license | ||
5 | * agreement governing use of this software, this software is licensed to you | ||
6 | * under the terms of the GNU General Public License version 2, available at | ||
7 | * http://www.broadcom.com/licenses/GPLv2.php (the "GPL"). | ||
8 | * | ||
9 | * Notwithstanding the above, under no circumstances may you combine this | ||
10 | * software in any way with any other Broadcom software provided under a | ||
11 | * license other than the GPL, without Broadcom's express prior written | ||
12 | * consent. | ||
13 | *****************************************************************************/ | ||
14 | |||
15 | /* ---- Include Files ---------------------------------------------------- */ | ||
16 | #include <mach/reg_umi.h> | ||
17 | #include "nand_bcm_umi.h" | ||
18 | #ifdef BOOT0_BUILD | ||
19 | #include <uart.h> | ||
20 | #endif | ||
21 | |||
22 | /* ---- External Variable Declarations ----------------------------------- */ | ||
23 | /* ---- External Function Prototypes ------------------------------------- */ | ||
24 | /* ---- Public Variables ------------------------------------------------- */ | ||
25 | /* ---- Private Constants and Types -------------------------------------- */ | ||
26 | /* ---- Private Function Prototypes -------------------------------------- */ | ||
27 | /* ---- Private Variables ------------------------------------------------ */ | ||
28 | /* ---- Private Functions ------------------------------------------------ */ | ||
29 | |||
30 | #if NAND_ECC_BCH | ||
31 | /**************************************************************************** | ||
32 | * nand_bch_ecc_flip_bit - Routine to flip an errored bit | ||
33 | * | ||
34 | * PURPOSE: | ||
35 | * This is a helper routine that flips the bit (0 -> 1 or 1 -> 0) of the | ||
36 | * errored bit specified | ||
37 | * | ||
38 | * PARAMETERS: | ||
39 | * datap - Container that holds the 512 byte data | ||
40 | * errorLocation - Location of the bit that needs to be flipped | ||
41 | * | ||
42 | * RETURNS: | ||
43 | * None | ||
44 | ****************************************************************************/ | ||
45 | static void nand_bcm_umi_bch_ecc_flip_bit(uint8_t *datap, int errorLocation) | ||
46 | { | ||
47 | int locWithinAByte = (errorLocation & REG_UMI_BCH_ERR_LOC_BYTE) >> 0; | ||
48 | int locWithinAWord = (errorLocation & REG_UMI_BCH_ERR_LOC_WORD) >> 3; | ||
49 | int locWithinAPage = (errorLocation & REG_UMI_BCH_ERR_LOC_PAGE) >> 5; | ||
50 | |||
51 | uint8_t errorByte = 0; | ||
52 | uint8_t byteMask = 1 << locWithinAByte; | ||
53 | |||
54 | /* BCH uses big endian, need to change the location | ||
55 | * bits to little endian */ | ||
56 | locWithinAWord = 3 - locWithinAWord; | ||
57 | |||
58 | errorByte = datap[locWithinAPage * sizeof(uint32_t) + locWithinAWord]; | ||
59 | |||
60 | #ifdef BOOT0_BUILD | ||
61 | puthexs("\nECC Correct Offset: ", | ||
62 | locWithinAPage * sizeof(uint32_t) + locWithinAWord); | ||
63 | puthexs(" errorByte:", errorByte); | ||
64 | puthex8(" Bit: ", locWithinAByte); | ||
65 | #endif | ||
66 | |||
67 | if (errorByte & byteMask) { | ||
68 | /* bit needs to be cleared */ | ||
69 | errorByte &= ~byteMask; | ||
70 | } else { | ||
71 | /* bit needs to be set */ | ||
72 | errorByte |= byteMask; | ||
73 | } | ||
74 | |||
75 | /* write back the value with the fixed bit */ | ||
76 | datap[locWithinAPage * sizeof(uint32_t) + locWithinAWord] = errorByte; | ||
77 | } | ||
78 | |||
79 | /**************************************************************************** | ||
80 | * nand_correct_page_bch - Routine to correct bit errors when reading NAND | ||
81 | * | ||
82 | * PURPOSE: | ||
83 | * This routine reads the BCH registers to determine if there are any bit | ||
84 | * errors during the read of the last 512 bytes of data + ECC bytes. If | ||
85 | * errors exists, the routine fixes it. | ||
86 | * | ||
87 | * PARAMETERS: | ||
88 | * datap - Container that holds the 512 byte data | ||
89 | * | ||
90 | * RETURNS: | ||
91 | * 0 or greater = Number of errors corrected | ||
92 | * (No errors are found or errors have been fixed) | ||
93 | * -1 = Error(s) cannot be fixed | ||
94 | ****************************************************************************/ | ||
95 | int nand_bcm_umi_bch_correct_page(uint8_t *datap, uint8_t *readEccData, | ||
96 | int numEccBytes) | ||
97 | { | ||
98 | int numErrors; | ||
99 | int errorLocation; | ||
100 | int idx; | ||
101 | uint32_t regValue; | ||
102 | |||
103 | /* wait for read ECC to be valid */ | ||
104 | regValue = nand_bcm_umi_bch_poll_read_ecc_calc(); | ||
105 | |||
106 | /* | ||
107 | * read the control status register to determine if there | ||
108 | * are error'ed bits | ||
109 | * see if errors are correctible | ||
110 | */ | ||
111 | if ((regValue & REG_UMI_BCH_CTRL_STATUS_UNCORR_ERR) > 0) { | ||
112 | int i; | ||
113 | |||
114 | for (i = 0; i < numEccBytes; i++) { | ||
115 | if (readEccData[i] != 0xff) { | ||
116 | /* errors cannot be fixed, return -1 */ | ||
117 | return -1; | ||
118 | } | ||
119 | } | ||
120 | /* If ECC is unprogrammed then we can't correct, | ||
121 | * assume everything OK */ | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | if ((regValue & REG_UMI_BCH_CTRL_STATUS_CORR_ERR) == 0) { | ||
126 | /* no errors */ | ||
127 | return 0; | ||
128 | } | ||
129 | |||
130 | /* | ||
131 | * Fix errored bits by doing the following: | ||
132 | * 1. Read the number of errors in the control and status register | ||
133 | * 2. Read the error location registers that corresponds to the number | ||
134 | * of errors reported | ||
135 | * 3. Invert the bit in the data | ||
136 | */ | ||
137 | numErrors = (regValue & REG_UMI_BCH_CTRL_STATUS_NB_CORR_ERROR) >> 20; | ||
138 | |||
139 | for (idx = 0; idx < numErrors; idx++) { | ||
140 | errorLocation = | ||
141 | REG_UMI_BCH_ERR_LOC_ADDR(idx) & REG_UMI_BCH_ERR_LOC_MASK; | ||
142 | |||
143 | /* Flip bit */ | ||
144 | nand_bcm_umi_bch_ecc_flip_bit(datap, errorLocation); | ||
145 | } | ||
146 | /* Errors corrected */ | ||
147 | return numErrors; | ||
148 | } | ||
149 | #endif | ||
diff --git a/drivers/mtd/nand/nand_bcm_umi.h b/drivers/mtd/nand/nand_bcm_umi.h new file mode 100644 index 000000000000..7cec2cd97854 --- /dev/null +++ b/drivers/mtd/nand/nand_bcm_umi.h | |||
@@ -0,0 +1,358 @@ | |||
1 | /***************************************************************************** | ||
2 | * Copyright 2003 - 2009 Broadcom Corporation. All rights reserved. | ||
3 | * | ||
4 | * Unless you and Broadcom execute a separate written software license | ||
5 | * agreement governing use of this software, this software is licensed to you | ||
6 | * under the terms of the GNU General Public License version 2, available at | ||
7 | * http://www.broadcom.com/licenses/GPLv2.php (the "GPL"). | ||
8 | * | ||
9 | * Notwithstanding the above, under no circumstances may you combine this | ||
10 | * software in any way with any other Broadcom software provided under a | ||
11 | * license other than the GPL, without Broadcom's express prior written | ||
12 | * consent. | ||
13 | *****************************************************************************/ | ||
14 | #ifndef NAND_BCM_UMI_H | ||
15 | #define NAND_BCM_UMI_H | ||
16 | |||
17 | /* ---- Include Files ---------------------------------------------------- */ | ||
18 | #include <mach/reg_umi.h> | ||
19 | #include <mach/reg_nand.h> | ||
20 | #include <cfg_global.h> | ||
21 | |||
22 | /* ---- Constants and Types ---------------------------------------------- */ | ||
23 | #if (CFG_GLOBAL_CHIP_FAMILY == CFG_GLOBAL_CHIP_FAMILY_BCMRING) | ||
24 | #define NAND_ECC_BCH (CFG_GLOBAL_CHIP_REV > 0xA0) | ||
25 | #else | ||
26 | #define NAND_ECC_BCH 0 | ||
27 | #endif | ||
28 | |||
29 | #define CFG_GLOBAL_NAND_ECC_BCH_NUM_BYTES 13 | ||
30 | |||
31 | #if NAND_ECC_BCH | ||
32 | #ifdef BOOT0_BUILD | ||
33 | #define NAND_ECC_NUM_BYTES 13 | ||
34 | #else | ||
35 | #define NAND_ECC_NUM_BYTES CFG_GLOBAL_NAND_ECC_BCH_NUM_BYTES | ||
36 | #endif | ||
37 | #else | ||
38 | #define NAND_ECC_NUM_BYTES 3 | ||
39 | #endif | ||
40 | |||
41 | #define NAND_DATA_ACCESS_SIZE 512 | ||
42 | |||
43 | /* ---- Variable Externs ------------------------------------------ */ | ||
44 | /* ---- Function Prototypes --------------------------------------- */ | ||
45 | int nand_bcm_umi_bch_correct_page(uint8_t *datap, uint8_t *readEccData, | ||
46 | int numEccBytes); | ||
47 | |||
48 | /* Check in device is ready */ | ||
49 | static inline int nand_bcm_umi_dev_ready(void) | ||
50 | { | ||
51 | return REG_UMI_NAND_RCSR & REG_UMI_NAND_RCSR_RDY; | ||
52 | } | ||
53 | |||
54 | /* Wait until device is ready */ | ||
55 | static inline void nand_bcm_umi_wait_till_ready(void) | ||
56 | { | ||
57 | while (nand_bcm_umi_dev_ready() == 0) | ||
58 | ; | ||
59 | } | ||
60 | |||
61 | /* Enable Hamming ECC */ | ||
62 | static inline void nand_bcm_umi_hamming_enable_hwecc(void) | ||
63 | { | ||
64 | /* disable and reset ECC, 512 byte page */ | ||
65 | REG_UMI_NAND_ECC_CSR &= ~(REG_UMI_NAND_ECC_CSR_ECC_ENABLE | | ||
66 | REG_UMI_NAND_ECC_CSR_256BYTE); | ||
67 | /* enable ECC */ | ||
68 | REG_UMI_NAND_ECC_CSR |= REG_UMI_NAND_ECC_CSR_ECC_ENABLE; | ||
69 | } | ||
70 | |||
71 | #if NAND_ECC_BCH | ||
72 | /* BCH ECC specifics */ | ||
73 | #define ECC_BITS_PER_CORRECTABLE_BIT 13 | ||
74 | |||
75 | /* Enable BCH Read ECC */ | ||
76 | static inline void nand_bcm_umi_bch_enable_read_hwecc(void) | ||
77 | { | ||
78 | /* disable and reset ECC */ | ||
79 | REG_UMI_BCH_CTRL_STATUS = REG_UMI_BCH_CTRL_STATUS_RD_ECC_VALID; | ||
80 | /* Turn on ECC */ | ||
81 | REG_UMI_BCH_CTRL_STATUS = REG_UMI_BCH_CTRL_STATUS_ECC_RD_EN; | ||
82 | } | ||
83 | |||
84 | /* Enable BCH Write ECC */ | ||
85 | static inline void nand_bcm_umi_bch_enable_write_hwecc(void) | ||
86 | { | ||
87 | /* disable and reset ECC */ | ||
88 | REG_UMI_BCH_CTRL_STATUS = REG_UMI_BCH_CTRL_STATUS_WR_ECC_VALID; | ||
89 | /* Turn on ECC */ | ||
90 | REG_UMI_BCH_CTRL_STATUS = REG_UMI_BCH_CTRL_STATUS_ECC_WR_EN; | ||
91 | } | ||
92 | |||
93 | /* Config number of BCH ECC bytes */ | ||
94 | static inline void nand_bcm_umi_bch_config_ecc(uint8_t numEccBytes) | ||
95 | { | ||
96 | uint32_t nValue; | ||
97 | uint32_t tValue; | ||
98 | uint32_t kValue; | ||
99 | uint32_t numBits = numEccBytes * 8; | ||
100 | |||
101 | /* disable and reset ECC */ | ||
102 | REG_UMI_BCH_CTRL_STATUS = | ||
103 | REG_UMI_BCH_CTRL_STATUS_WR_ECC_VALID | | ||
104 | REG_UMI_BCH_CTRL_STATUS_RD_ECC_VALID; | ||
105 | |||
106 | /* Every correctible bit requires 13 ECC bits */ | ||
107 | tValue = (uint32_t) (numBits / ECC_BITS_PER_CORRECTABLE_BIT); | ||
108 | |||
109 | /* Total data in number of bits for generating and computing BCH ECC */ | ||
110 | nValue = (NAND_DATA_ACCESS_SIZE + numEccBytes) * 8; | ||
111 | |||
112 | /* K parameter is used internally. K = N - (T * 13) */ | ||
113 | kValue = nValue - (tValue * ECC_BITS_PER_CORRECTABLE_BIT); | ||
114 | |||
115 | /* Write the settings */ | ||
116 | REG_UMI_BCH_N = nValue; | ||
117 | REG_UMI_BCH_T = tValue; | ||
118 | REG_UMI_BCH_K = kValue; | ||
119 | } | ||
120 | |||
121 | /* Pause during ECC read calculation to skip bytes in OOB */ | ||
122 | static inline void nand_bcm_umi_bch_pause_read_ecc_calc(void) | ||
123 | { | ||
124 | REG_UMI_BCH_CTRL_STATUS = | ||
125 | REG_UMI_BCH_CTRL_STATUS_ECC_RD_EN | | ||
126 | REG_UMI_BCH_CTRL_STATUS_PAUSE_ECC_DEC; | ||
127 | } | ||
128 | |||
129 | /* Resume during ECC read calculation after skipping bytes in OOB */ | ||
130 | static inline void nand_bcm_umi_bch_resume_read_ecc_calc(void) | ||
131 | { | ||
132 | REG_UMI_BCH_CTRL_STATUS = REG_UMI_BCH_CTRL_STATUS_ECC_RD_EN; | ||
133 | } | ||
134 | |||
135 | /* Poll read ECC calc to check when hardware completes */ | ||
136 | static inline uint32_t nand_bcm_umi_bch_poll_read_ecc_calc(void) | ||
137 | { | ||
138 | uint32_t regVal; | ||
139 | |||
140 | do { | ||
141 | /* wait for ECC to be valid */ | ||
142 | regVal = REG_UMI_BCH_CTRL_STATUS; | ||
143 | } while ((regVal & REG_UMI_BCH_CTRL_STATUS_RD_ECC_VALID) == 0); | ||
144 | |||
145 | return regVal; | ||
146 | } | ||
147 | |||
148 | /* Poll write ECC calc to check when hardware completes */ | ||
149 | static inline void nand_bcm_umi_bch_poll_write_ecc_calc(void) | ||
150 | { | ||
151 | /* wait for ECC to be valid */ | ||
152 | while ((REG_UMI_BCH_CTRL_STATUS & REG_UMI_BCH_CTRL_STATUS_WR_ECC_VALID) | ||
153 | == 0) | ||
154 | ; | ||
155 | } | ||
156 | |||
157 | /* Read the OOB and ECC, for kernel write OOB to a buffer */ | ||
158 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
159 | static inline void nand_bcm_umi_bch_read_oobEcc(uint32_t pageSize, | ||
160 | uint8_t *eccCalc, int numEccBytes, uint8_t *oobp) | ||
161 | #else | ||
162 | static inline void nand_bcm_umi_bch_read_oobEcc(uint32_t pageSize, | ||
163 | uint8_t *eccCalc, int numEccBytes) | ||
164 | #endif | ||
165 | { | ||
166 | int eccPos = 0; | ||
167 | int numToRead = 16; /* There are 16 bytes per sector in the OOB */ | ||
168 | |||
169 | /* ECC is already paused when this function is called */ | ||
170 | |||
171 | if (pageSize == NAND_DATA_ACCESS_SIZE) { | ||
172 | while (numToRead > numEccBytes) { | ||
173 | /* skip free oob region */ | ||
174 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
175 | *oobp++ = REG_NAND_DATA8; | ||
176 | #else | ||
177 | REG_NAND_DATA8; | ||
178 | #endif | ||
179 | numToRead--; | ||
180 | } | ||
181 | |||
182 | /* read ECC bytes before BI */ | ||
183 | nand_bcm_umi_bch_resume_read_ecc_calc(); | ||
184 | |||
185 | while (numToRead > 11) { | ||
186 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
187 | *oobp = REG_NAND_DATA8; | ||
188 | eccCalc[eccPos++] = *oobp; | ||
189 | oobp++; | ||
190 | #else | ||
191 | eccCalc[eccPos++] = REG_NAND_DATA8; | ||
192 | #endif | ||
193 | } | ||
194 | |||
195 | nand_bcm_umi_bch_pause_read_ecc_calc(); | ||
196 | |||
197 | if (numToRead == 11) { | ||
198 | /* read BI */ | ||
199 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
200 | *oobp++ = REG_NAND_DATA8; | ||
201 | #else | ||
202 | REG_NAND_DATA8; | ||
203 | #endif | ||
204 | numToRead--; | ||
205 | } | ||
206 | |||
207 | /* read ECC bytes */ | ||
208 | nand_bcm_umi_bch_resume_read_ecc_calc(); | ||
209 | while (numToRead) { | ||
210 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
211 | *oobp = REG_NAND_DATA8; | ||
212 | eccCalc[eccPos++] = *oobp; | ||
213 | oobp++; | ||
214 | #else | ||
215 | eccCalc[eccPos++] = REG_NAND_DATA8; | ||
216 | #endif | ||
217 | numToRead--; | ||
218 | } | ||
219 | } else { | ||
220 | /* skip BI */ | ||
221 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
222 | *oobp++ = REG_NAND_DATA8; | ||
223 | #else | ||
224 | REG_NAND_DATA8; | ||
225 | #endif | ||
226 | numToRead--; | ||
227 | |||
228 | while (numToRead > numEccBytes) { | ||
229 | /* skip free oob region */ | ||
230 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
231 | *oobp++ = REG_NAND_DATA8; | ||
232 | #else | ||
233 | REG_NAND_DATA8; | ||
234 | #endif | ||
235 | numToRead--; | ||
236 | } | ||
237 | |||
238 | /* read ECC bytes */ | ||
239 | nand_bcm_umi_bch_resume_read_ecc_calc(); | ||
240 | while (numToRead) { | ||
241 | #if defined(__KERNEL__) && !defined(STANDALONE) | ||
242 | *oobp = REG_NAND_DATA8; | ||
243 | eccCalc[eccPos++] = *oobp; | ||
244 | oobp++; | ||
245 | #else | ||
246 | eccCalc[eccPos++] = REG_NAND_DATA8; | ||
247 | #endif | ||
248 | numToRead--; | ||
249 | } | ||
250 | } | ||
251 | } | ||
252 | |||
253 | /* Helper function to write ECC */ | ||
254 | static inline void NAND_BCM_UMI_ECC_WRITE(int numEccBytes, int eccBytePos, | ||
255 | uint8_t *oobp, uint8_t eccVal) | ||
256 | { | ||
257 | if (eccBytePos <= numEccBytes) | ||
258 | *oobp = eccVal; | ||
259 | } | ||
260 | |||
261 | /* Write OOB with ECC */ | ||
262 | static inline void nand_bcm_umi_bch_write_oobEcc(uint32_t pageSize, | ||
263 | uint8_t *oobp, int numEccBytes) | ||
264 | { | ||
265 | uint32_t eccVal = 0xffffffff; | ||
266 | |||
267 | /* wait for write ECC to be valid */ | ||
268 | nand_bcm_umi_bch_poll_write_ecc_calc(); | ||
269 | |||
270 | /* | ||
271 | ** Get the hardware ecc from the 32-bit result registers. | ||
272 | ** Read after 512 byte accesses. Format B3B2B1B0 | ||
273 | ** where B3 = ecc3, etc. | ||
274 | */ | ||
275 | |||
276 | if (pageSize == NAND_DATA_ACCESS_SIZE) { | ||
277 | /* Now fill in the ECC bytes */ | ||
278 | if (numEccBytes >= 13) | ||
279 | eccVal = REG_UMI_BCH_WR_ECC_3; | ||
280 | |||
281 | /* Usually we skip CM in oob[0,1] */ | ||
282 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 15, &oobp[0], | ||
283 | (eccVal >> 16) & 0xff); | ||
284 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 14, &oobp[1], | ||
285 | (eccVal >> 8) & 0xff); | ||
286 | |||
287 | /* Write ECC in oob[2,3,4] */ | ||
288 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 13, &oobp[2], | ||
289 | eccVal & 0xff); /* ECC 12 */ | ||
290 | |||
291 | if (numEccBytes >= 9) | ||
292 | eccVal = REG_UMI_BCH_WR_ECC_2; | ||
293 | |||
294 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 12, &oobp[3], | ||
295 | (eccVal >> 24) & 0xff); /* ECC11 */ | ||
296 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 11, &oobp[4], | ||
297 | (eccVal >> 16) & 0xff); /* ECC10 */ | ||
298 | |||
299 | /* Always Skip BI in oob[5] */ | ||
300 | } else { | ||
301 | /* Always Skip BI in oob[0] */ | ||
302 | |||
303 | /* Now fill in the ECC bytes */ | ||
304 | if (numEccBytes >= 13) | ||
305 | eccVal = REG_UMI_BCH_WR_ECC_3; | ||
306 | |||
307 | /* Usually skip CM in oob[1,2] */ | ||
308 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 15, &oobp[1], | ||
309 | (eccVal >> 16) & 0xff); | ||
310 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 14, &oobp[2], | ||
311 | (eccVal >> 8) & 0xff); | ||
312 | |||
313 | /* Write ECC in oob[3-15] */ | ||
314 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 13, &oobp[3], | ||
315 | eccVal & 0xff); /* ECC12 */ | ||
316 | |||
317 | if (numEccBytes >= 9) | ||
318 | eccVal = REG_UMI_BCH_WR_ECC_2; | ||
319 | |||
320 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 12, &oobp[4], | ||
321 | (eccVal >> 24) & 0xff); /* ECC11 */ | ||
322 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 11, &oobp[5], | ||
323 | (eccVal >> 16) & 0xff); /* ECC10 */ | ||
324 | } | ||
325 | |||
326 | /* Fill in the remainder of ECC locations */ | ||
327 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 10, &oobp[6], | ||
328 | (eccVal >> 8) & 0xff); /* ECC9 */ | ||
329 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 9, &oobp[7], | ||
330 | eccVal & 0xff); /* ECC8 */ | ||
331 | |||
332 | if (numEccBytes >= 5) | ||
333 | eccVal = REG_UMI_BCH_WR_ECC_1; | ||
334 | |||
335 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 8, &oobp[8], | ||
336 | (eccVal >> 24) & 0xff); /* ECC7 */ | ||
337 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 7, &oobp[9], | ||
338 | (eccVal >> 16) & 0xff); /* ECC6 */ | ||
339 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 6, &oobp[10], | ||
340 | (eccVal >> 8) & 0xff); /* ECC5 */ | ||
341 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 5, &oobp[11], | ||
342 | eccVal & 0xff); /* ECC4 */ | ||
343 | |||
344 | if (numEccBytes >= 1) | ||
345 | eccVal = REG_UMI_BCH_WR_ECC_0; | ||
346 | |||
347 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 4, &oobp[12], | ||
348 | (eccVal >> 24) & 0xff); /* ECC3 */ | ||
349 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 3, &oobp[13], | ||
350 | (eccVal >> 16) & 0xff); /* ECC2 */ | ||
351 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 2, &oobp[14], | ||
352 | (eccVal >> 8) & 0xff); /* ECC1 */ | ||
353 | NAND_BCM_UMI_ECC_WRITE(numEccBytes, 1, &oobp[15], | ||
354 | eccVal & 0xff); /* ECC0 */ | ||
355 | } | ||
356 | #endif | ||
357 | |||
358 | #endif /* NAND_BCM_UMI_H */ | ||
diff --git a/drivers/mtd/nand/nand_ecc.c b/drivers/mtd/nand/nand_ecc.c index db7ae9d6a296..271b8e735e8f 100644 --- a/drivers/mtd/nand/nand_ecc.c +++ b/drivers/mtd/nand/nand_ecc.c | |||
@@ -150,20 +150,19 @@ static const char addressbits[256] = { | |||
150 | }; | 150 | }; |
151 | 151 | ||
152 | /** | 152 | /** |
153 | * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte | 153 | * __nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte |
154 | * block | 154 | * block |
155 | * @mtd: MTD block structure | ||
156 | * @buf: input buffer with raw data | 155 | * @buf: input buffer with raw data |
156 | * @eccsize: data bytes per ecc step (256 or 512) | ||
157 | * @code: output buffer with ECC | 157 | * @code: output buffer with ECC |
158 | */ | 158 | */ |
159 | int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, | 159 | void __nand_calculate_ecc(const unsigned char *buf, unsigned int eccsize, |
160 | unsigned char *code) | 160 | unsigned char *code) |
161 | { | 161 | { |
162 | int i; | 162 | int i; |
163 | const uint32_t *bp = (uint32_t *)buf; | 163 | const uint32_t *bp = (uint32_t *)buf; |
164 | /* 256 or 512 bytes/ecc */ | 164 | /* 256 or 512 bytes/ecc */ |
165 | const uint32_t eccsize_mult = | 165 | const uint32_t eccsize_mult = eccsize >> 8; |
166 | (((struct nand_chip *)mtd->priv)->ecc.size) >> 8; | ||
167 | uint32_t cur; /* current value in buffer */ | 166 | uint32_t cur; /* current value in buffer */ |
168 | /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ | 167 | /* rp0..rp15..rp17 are the various accumulated parities (per byte) */ |
169 | uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7; | 168 | uint32_t rp0, rp1, rp2, rp3, rp4, rp5, rp6, rp7; |
@@ -412,6 +411,22 @@ int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, | |||
412 | (invparity[par & 0x55] << 2) | | 411 | (invparity[par & 0x55] << 2) | |
413 | (invparity[rp17] << 1) | | 412 | (invparity[rp17] << 1) | |
414 | (invparity[rp16] << 0); | 413 | (invparity[rp16] << 0); |
414 | } | ||
415 | EXPORT_SYMBOL(__nand_calculate_ecc); | ||
416 | |||
417 | /** | ||
418 | * nand_calculate_ecc - [NAND Interface] Calculate 3-byte ECC for 256/512-byte | ||
419 | * block | ||
420 | * @mtd: MTD block structure | ||
421 | * @buf: input buffer with raw data | ||
422 | * @code: output buffer with ECC | ||
423 | */ | ||
424 | int nand_calculate_ecc(struct mtd_info *mtd, const unsigned char *buf, | ||
425 | unsigned char *code) | ||
426 | { | ||
427 | __nand_calculate_ecc(buf, | ||
428 | ((struct nand_chip *)mtd->priv)->ecc.size, code); | ||
429 | |||
415 | return 0; | 430 | return 0; |
416 | } | 431 | } |
417 | EXPORT_SYMBOL(nand_calculate_ecc); | 432 | EXPORT_SYMBOL(nand_calculate_ecc); |
@@ -475,7 +490,7 @@ int __nand_correct_data(unsigned char *buf, | |||
475 | * | 490 | * |
476 | * The b2 shift is there to get rid of the lowest two bits. | 491 | * The b2 shift is there to get rid of the lowest two bits. |
477 | * We could also do addressbits[b2] >> 1 but for the | 492 | * We could also do addressbits[b2] >> 1 but for the |
478 | * performace it does not make any difference | 493 | * performance it does not make any difference |
479 | */ | 494 | */ |
480 | if (eccsize_mult == 1) | 495 | if (eccsize_mult == 1) |
481 | byte_addr = (addressbits[b1] << 4) + addressbits[b0]; | 496 | byte_addr = (addressbits[b1] << 4) + addressbits[b0]; |
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index cd0711b83ac4..7281000fef2d 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c | |||
@@ -161,7 +161,7 @@ MODULE_PARM_DESC(overridesize, "Specifies the NAND Flash size overriding the I | |||
161 | MODULE_PARM_DESC(cache_file, "File to use to cache nand pages instead of memory"); | 161 | MODULE_PARM_DESC(cache_file, "File to use to cache nand pages instead of memory"); |
162 | 162 | ||
163 | /* The largest possible page size */ | 163 | /* The largest possible page size */ |
164 | #define NS_LARGEST_PAGE_SIZE 2048 | 164 | #define NS_LARGEST_PAGE_SIZE 4096 |
165 | 165 | ||
166 | /* The prefix for simulator output */ | 166 | /* The prefix for simulator output */ |
167 | #define NS_OUTPUT_PREFIX "[nandsim]" | 167 | #define NS_OUTPUT_PREFIX "[nandsim]" |
@@ -259,7 +259,8 @@ MODULE_PARM_DESC(cache_file, "File to use to cache nand pages instead of mem | |||
259 | #define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ | 259 | #define OPT_SMARTMEDIA 0x00000010 /* SmartMedia technology chips */ |
260 | #define OPT_AUTOINCR 0x00000020 /* page number auto inctimentation is possible */ | 260 | #define OPT_AUTOINCR 0x00000020 /* page number auto inctimentation is possible */ |
261 | #define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ | 261 | #define OPT_PAGE512_8BIT 0x00000040 /* 512-byte page chips with 8-bit bus width */ |
262 | #define OPT_LARGEPAGE (OPT_PAGE2048) /* 2048-byte page chips */ | 262 | #define OPT_PAGE4096 0x00000080 /* 4096-byte page chips */ |
263 | #define OPT_LARGEPAGE (OPT_PAGE2048 | OPT_PAGE4096) /* 2048 & 4096-byte page chips */ | ||
263 | #define OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */ | 264 | #define OPT_SMALLPAGE (OPT_PAGE256 | OPT_PAGE512) /* 256 and 512-byte page chips */ |
264 | 265 | ||
265 | /* Remove action bits ftom state */ | 266 | /* Remove action bits ftom state */ |
@@ -588,6 +589,8 @@ static int init_nandsim(struct mtd_info *mtd) | |||
588 | ns->options |= OPT_PAGE512_8BIT; | 589 | ns->options |= OPT_PAGE512_8BIT; |
589 | } else if (ns->geom.pgsz == 2048) { | 590 | } else if (ns->geom.pgsz == 2048) { |
590 | ns->options |= OPT_PAGE2048; | 591 | ns->options |= OPT_PAGE2048; |
592 | } else if (ns->geom.pgsz == 4096) { | ||
593 | ns->options |= OPT_PAGE4096; | ||
591 | } else { | 594 | } else { |
592 | NS_ERR("init_nandsim: unknown page size %u\n", ns->geom.pgsz); | 595 | NS_ERR("init_nandsim: unknown page size %u\n", ns->geom.pgsz); |
593 | return -EIO; | 596 | return -EIO; |
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c index 40b5658bdbe6..b983cae8c298 100644 --- a/drivers/mtd/nand/ndfc.c +++ b/drivers/mtd/nand/ndfc.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/mtd/nand_ecc.h> | 28 | #include <linux/mtd/nand_ecc.h> |
29 | #include <linux/mtd/partitions.h> | 29 | #include <linux/mtd/partitions.h> |
30 | #include <linux/mtd/ndfc.h> | 30 | #include <linux/mtd/ndfc.h> |
31 | #include <linux/slab.h> | ||
31 | #include <linux/mtd/mtd.h> | 32 | #include <linux/mtd/mtd.h> |
32 | #include <linux/of_platform.h> | 33 | #include <linux/of_platform.h> |
33 | #include <asm/io.h> | 34 | #include <asm/io.h> |
diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c index 7c302d55910e..1f6f741af5da 100644 --- a/drivers/mtd/nand/nomadik_nand.c +++ b/drivers/mtd/nand/nomadik_nand.c | |||
@@ -30,6 +30,7 @@ | |||
30 | #include <linux/platform_device.h> | 30 | #include <linux/platform_device.h> |
31 | #include <linux/mtd/partitions.h> | 31 | #include <linux/mtd/partitions.h> |
32 | #include <linux/io.h> | 32 | #include <linux/io.h> |
33 | #include <linux/slab.h> | ||
33 | #include <mach/nand.h> | 34 | #include <mach/nand.h> |
34 | #include <mach/fsmc.h> | 35 | #include <mach/fsmc.h> |
35 | 36 | ||
@@ -216,7 +217,7 @@ static int nomadik_nand_resume(struct device *dev) | |||
216 | return 0; | 217 | return 0; |
217 | } | 218 | } |
218 | 219 | ||
219 | static struct dev_pm_ops nomadik_nand_pm_ops = { | 220 | static const struct dev_pm_ops nomadik_nand_pm_ops = { |
220 | .suspend = nomadik_nand_suspend, | 221 | .suspend = nomadik_nand_suspend, |
221 | .resume = nomadik_nand_resume, | 222 | .resume = nomadik_nand_resume, |
222 | }; | 223 | }; |
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index 090ab87086b5..7545568fce47 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c | |||
@@ -17,10 +17,11 @@ | |||
17 | #include <linux/mtd/nand.h> | 17 | #include <linux/mtd/nand.h> |
18 | #include <linux/mtd/partitions.h> | 18 | #include <linux/mtd/partitions.h> |
19 | #include <linux/io.h> | 19 | #include <linux/io.h> |
20 | #include <linux/slab.h> | ||
20 | 21 | ||
21 | #include <mach/dma.h> | 22 | #include <plat/dma.h> |
22 | #include <mach/gpmc.h> | 23 | #include <plat/gpmc.h> |
23 | #include <mach/nand.h> | 24 | #include <plat/nand.h> |
24 | 25 | ||
25 | #define GPMC_IRQ_STATUS 0x18 | 26 | #define GPMC_IRQ_STATUS 0x18 |
26 | #define GPMC_ECC_CONFIG 0x1F4 | 27 | #define GPMC_ECC_CONFIG 0x1F4 |
@@ -30,12 +31,8 @@ | |||
30 | 31 | ||
31 | #define DRIVER_NAME "omap2-nand" | 32 | #define DRIVER_NAME "omap2-nand" |
32 | 33 | ||
33 | /* size (4 KiB) for IO mapping */ | ||
34 | #define NAND_IO_SIZE SZ_4K | ||
35 | |||
36 | #define NAND_WP_OFF 0 | 34 | #define NAND_WP_OFF 0 |
37 | #define NAND_WP_BIT 0x00000010 | 35 | #define NAND_WP_BIT 0x00000010 |
38 | #define WR_RD_PIN_MONITORING 0x00600000 | ||
39 | 36 | ||
40 | #define GPMC_BUF_FULL 0x00000001 | 37 | #define GPMC_BUF_FULL 0x00000001 |
41 | #define GPMC_BUF_EMPTY 0x00000000 | 38 | #define GPMC_BUF_EMPTY 0x00000000 |
@@ -882,8 +879,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev) | |||
882 | struct omap_nand_info *info; | 879 | struct omap_nand_info *info; |
883 | struct omap_nand_platform_data *pdata; | 880 | struct omap_nand_platform_data *pdata; |
884 | int err; | 881 | int err; |
885 | unsigned long val; | ||
886 | |||
887 | 882 | ||
888 | pdata = pdev->dev.platform_data; | 883 | pdata = pdev->dev.platform_data; |
889 | if (pdata == NULL) { | 884 | if (pdata == NULL) { |
@@ -905,28 +900,14 @@ static int __devinit omap_nand_probe(struct platform_device *pdev) | |||
905 | info->gpmc_cs = pdata->cs; | 900 | info->gpmc_cs = pdata->cs; |
906 | info->gpmc_baseaddr = pdata->gpmc_baseaddr; | 901 | info->gpmc_baseaddr = pdata->gpmc_baseaddr; |
907 | info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr; | 902 | info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr; |
903 | info->phys_base = pdata->phys_base; | ||
908 | 904 | ||
909 | info->mtd.priv = &info->nand; | 905 | info->mtd.priv = &info->nand; |
910 | info->mtd.name = dev_name(&pdev->dev); | 906 | info->mtd.name = dev_name(&pdev->dev); |
911 | info->mtd.owner = THIS_MODULE; | 907 | info->mtd.owner = THIS_MODULE; |
912 | 908 | ||
913 | err = gpmc_cs_request(info->gpmc_cs, NAND_IO_SIZE, &info->phys_base); | 909 | info->nand.options |= pdata->devsize ? NAND_BUSWIDTH_16 : 0; |
914 | if (err < 0) { | 910 | info->nand.options |= NAND_SKIP_BBTSCAN; |
915 | dev_err(&pdev->dev, "Cannot request GPMC CS\n"); | ||
916 | goto out_free_info; | ||
917 | } | ||
918 | |||
919 | /* Enable RD PIN Monitoring Reg */ | ||
920 | if (pdata->dev_ready) { | ||
921 | val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1); | ||
922 | val |= WR_RD_PIN_MONITORING; | ||
923 | gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG1, val); | ||
924 | } | ||
925 | |||
926 | val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG7); | ||
927 | val &= ~(0xf << 8); | ||
928 | val |= (0xc & 0xf) << 8; | ||
929 | gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG7, val); | ||
930 | 911 | ||
931 | /* NAND write protect off */ | 912 | /* NAND write protect off */ |
932 | omap_nand_wp(&info->mtd, NAND_WP_OFF); | 913 | omap_nand_wp(&info->mtd, NAND_WP_OFF); |
@@ -934,7 +915,7 @@ static int __devinit omap_nand_probe(struct platform_device *pdev) | |||
934 | if (!request_mem_region(info->phys_base, NAND_IO_SIZE, | 915 | if (!request_mem_region(info->phys_base, NAND_IO_SIZE, |
935 | pdev->dev.driver->name)) { | 916 | pdev->dev.driver->name)) { |
936 | err = -EBUSY; | 917 | err = -EBUSY; |
937 | goto out_free_cs; | 918 | goto out_free_info; |
938 | } | 919 | } |
939 | 920 | ||
940 | info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE); | 921 | info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE); |
@@ -963,11 +944,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev) | |||
963 | info->nand.chip_delay = 50; | 944 | info->nand.chip_delay = 50; |
964 | } | 945 | } |
965 | 946 | ||
966 | info->nand.options |= NAND_SKIP_BBTSCAN; | ||
967 | if ((gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1) & 0x3000) | ||
968 | == 0x1000) | ||
969 | info->nand.options |= NAND_BUSWIDTH_16; | ||
970 | |||
971 | if (use_prefetch) { | 947 | if (use_prefetch) { |
972 | /* copy the virtual address of nand base for fifo access */ | 948 | /* copy the virtual address of nand base for fifo access */ |
973 | info->nand_pref_fifo_add = info->nand.IO_ADDR_R; | 949 | info->nand_pref_fifo_add = info->nand.IO_ADDR_R; |
@@ -1043,8 +1019,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev) | |||
1043 | 1019 | ||
1044 | out_release_mem_region: | 1020 | out_release_mem_region: |
1045 | release_mem_region(info->phys_base, NAND_IO_SIZE); | 1021 | release_mem_region(info->phys_base, NAND_IO_SIZE); |
1046 | out_free_cs: | ||
1047 | gpmc_cs_free(info->gpmc_cs); | ||
1048 | out_free_info: | 1022 | out_free_info: |
1049 | kfree(info); | 1023 | kfree(info); |
1050 | 1024 | ||
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c index f59c07427af3..d60fc5719fef 100644 --- a/drivers/mtd/nand/orion_nand.c +++ b/drivers/mtd/nand/orion_nand.c | |||
@@ -60,7 +60,13 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | |||
60 | } | 60 | } |
61 | buf64 = (uint64_t *)buf; | 61 | buf64 = (uint64_t *)buf; |
62 | while (i < len/8) { | 62 | while (i < len/8) { |
63 | uint64_t x; | 63 | /* |
64 | * Since GCC has no proper constraint (PR 43518) | ||
65 | * force x variable to r2/r3 registers as ldrd instruction | ||
66 | * requires first register to be even. | ||
67 | */ | ||
68 | register uint64_t x asm ("r2"); | ||
69 | |||
64 | asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base)); | 70 | asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base)); |
65 | buf64[i++] = x; | 71 | buf64[i++] = x; |
66 | } | 72 | } |
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c index 4e16c6f5bdd5..8d467315f02b 100644 --- a/drivers/mtd/nand/plat_nand.c +++ b/drivers/mtd/nand/plat_nand.c | |||
@@ -34,7 +34,12 @@ static int __devinit plat_nand_probe(struct platform_device *pdev) | |||
34 | { | 34 | { |
35 | struct platform_nand_data *pdata = pdev->dev.platform_data; | 35 | struct platform_nand_data *pdata = pdev->dev.platform_data; |
36 | struct plat_nand_data *data; | 36 | struct plat_nand_data *data; |
37 | int res = 0; | 37 | struct resource *res; |
38 | int err = 0; | ||
39 | |||
40 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
41 | if (!res) | ||
42 | return -ENXIO; | ||
38 | 43 | ||
39 | /* Allocate memory for the device structure (and zero it) */ | 44 | /* Allocate memory for the device structure (and zero it) */ |
40 | data = kzalloc(sizeof(struct plat_nand_data), GFP_KERNEL); | 45 | data = kzalloc(sizeof(struct plat_nand_data), GFP_KERNEL); |
@@ -43,12 +48,18 @@ static int __devinit plat_nand_probe(struct platform_device *pdev) | |||
43 | return -ENOMEM; | 48 | return -ENOMEM; |
44 | } | 49 | } |
45 | 50 | ||
46 | data->io_base = ioremap(pdev->resource[0].start, | 51 | if (!request_mem_region(res->start, resource_size(res), |
47 | pdev->resource[0].end - pdev->resource[0].start + 1); | 52 | dev_name(&pdev->dev))) { |
53 | dev_err(&pdev->dev, "request_mem_region failed\n"); | ||
54 | err = -EBUSY; | ||
55 | goto out_free; | ||
56 | } | ||
57 | |||
58 | data->io_base = ioremap(res->start, resource_size(res)); | ||
48 | if (data->io_base == NULL) { | 59 | if (data->io_base == NULL) { |
49 | dev_err(&pdev->dev, "ioremap failed\n"); | 60 | dev_err(&pdev->dev, "ioremap failed\n"); |
50 | kfree(data); | 61 | err = -EIO; |
51 | return -EIO; | 62 | goto out_release_io; |
52 | } | 63 | } |
53 | 64 | ||
54 | data->chip.priv = &data; | 65 | data->chip.priv = &data; |
@@ -74,24 +85,24 @@ static int __devinit plat_nand_probe(struct platform_device *pdev) | |||
74 | 85 | ||
75 | /* Handle any platform specific setup */ | 86 | /* Handle any platform specific setup */ |
76 | if (pdata->ctrl.probe) { | 87 | if (pdata->ctrl.probe) { |
77 | res = pdata->ctrl.probe(pdev); | 88 | err = pdata->ctrl.probe(pdev); |
78 | if (res) | 89 | if (err) |
79 | goto out; | 90 | goto out; |
80 | } | 91 | } |
81 | 92 | ||
82 | /* Scan to find existance of the device */ | 93 | /* Scan to find existance of the device */ |
83 | if (nand_scan(&data->mtd, 1)) { | 94 | if (nand_scan(&data->mtd, 1)) { |
84 | res = -ENXIO; | 95 | err = -ENXIO; |
85 | goto out; | 96 | goto out; |
86 | } | 97 | } |
87 | 98 | ||
88 | #ifdef CONFIG_MTD_PARTITIONS | 99 | #ifdef CONFIG_MTD_PARTITIONS |
89 | if (pdata->chip.part_probe_types) { | 100 | if (pdata->chip.part_probe_types) { |
90 | res = parse_mtd_partitions(&data->mtd, | 101 | err = parse_mtd_partitions(&data->mtd, |
91 | pdata->chip.part_probe_types, | 102 | pdata->chip.part_probe_types, |
92 | &data->parts, 0); | 103 | &data->parts, 0); |
93 | if (res > 0) { | 104 | if (err > 0) { |
94 | add_mtd_partitions(&data->mtd, data->parts, res); | 105 | add_mtd_partitions(&data->mtd, data->parts, err); |
95 | return 0; | 106 | return 0; |
96 | } | 107 | } |
97 | } | 108 | } |
@@ -99,14 +110,14 @@ static int __devinit plat_nand_probe(struct platform_device *pdev) | |||
99 | pdata->chip.set_parts(data->mtd.size, &pdata->chip); | 110 | pdata->chip.set_parts(data->mtd.size, &pdata->chip); |
100 | if (pdata->chip.partitions) { | 111 | if (pdata->chip.partitions) { |
101 | data->parts = pdata->chip.partitions; | 112 | data->parts = pdata->chip.partitions; |
102 | res = add_mtd_partitions(&data->mtd, data->parts, | 113 | err = add_mtd_partitions(&data->mtd, data->parts, |
103 | pdata->chip.nr_partitions); | 114 | pdata->chip.nr_partitions); |
104 | } else | 115 | } else |
105 | #endif | 116 | #endif |
106 | res = add_mtd_device(&data->mtd); | 117 | err = add_mtd_device(&data->mtd); |
107 | 118 | ||
108 | if (!res) | 119 | if (!err) |
109 | return res; | 120 | return err; |
110 | 121 | ||
111 | nand_release(&data->mtd); | 122 | nand_release(&data->mtd); |
112 | out: | 123 | out: |
@@ -114,8 +125,11 @@ out: | |||
114 | pdata->ctrl.remove(pdev); | 125 | pdata->ctrl.remove(pdev); |
115 | platform_set_drvdata(pdev, NULL); | 126 | platform_set_drvdata(pdev, NULL); |
116 | iounmap(data->io_base); | 127 | iounmap(data->io_base); |
128 | out_release_io: | ||
129 | release_mem_region(res->start, resource_size(res)); | ||
130 | out_free: | ||
117 | kfree(data); | 131 | kfree(data); |
118 | return res; | 132 | return err; |
119 | } | 133 | } |
120 | 134 | ||
121 | /* | 135 | /* |
@@ -125,6 +139,9 @@ static int __devexit plat_nand_remove(struct platform_device *pdev) | |||
125 | { | 139 | { |
126 | struct plat_nand_data *data = platform_get_drvdata(pdev); | 140 | struct plat_nand_data *data = platform_get_drvdata(pdev); |
127 | struct platform_nand_data *pdata = pdev->dev.platform_data; | 141 | struct platform_nand_data *pdata = pdev->dev.platform_data; |
142 | struct resource *res; | ||
143 | |||
144 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | ||
128 | 145 | ||
129 | nand_release(&data->mtd); | 146 | nand_release(&data->mtd); |
130 | #ifdef CONFIG_MTD_PARTITIONS | 147 | #ifdef CONFIG_MTD_PARTITIONS |
@@ -134,6 +151,7 @@ static int __devexit plat_nand_remove(struct platform_device *pdev) | |||
134 | if (pdata->ctrl.remove) | 151 | if (pdata->ctrl.remove) |
135 | pdata->ctrl.remove(pdev); | 152 | pdata->ctrl.remove(pdev); |
136 | iounmap(data->io_base); | 153 | iounmap(data->io_base); |
154 | release_mem_region(res->start, resource_size(res)); | ||
137 | kfree(data); | 155 | kfree(data); |
138 | 156 | ||
139 | return 0; | 157 | return 0; |
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 6ea520ae2410..5d55152162cf 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c | |||
@@ -9,6 +9,7 @@ | |||
9 | * published by the Free Software Foundation. | 9 | * published by the Free Software Foundation. |
10 | */ | 10 | */ |
11 | 11 | ||
12 | #include <linux/kernel.h> | ||
12 | #include <linux/module.h> | 13 | #include <linux/module.h> |
13 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
14 | #include <linux/platform_device.h> | 15 | #include <linux/platform_device.h> |
@@ -20,9 +21,10 @@ | |||
20 | #include <linux/mtd/partitions.h> | 21 | #include <linux/mtd/partitions.h> |
21 | #include <linux/io.h> | 22 | #include <linux/io.h> |
22 | #include <linux/irq.h> | 23 | #include <linux/irq.h> |
24 | #include <linux/slab.h> | ||
23 | 25 | ||
24 | #include <mach/dma.h> | 26 | #include <mach/dma.h> |
25 | #include <mach/pxa3xx_nand.h> | 27 | #include <plat/pxa3xx_nand.h> |
26 | 28 | ||
27 | #define CHIP_DELAY_TIMEOUT (2 * HZ/10) | 29 | #define CHIP_DELAY_TIMEOUT (2 * HZ/10) |
28 | 30 | ||
@@ -84,10 +86,6 @@ | |||
84 | #define NDCB0_CMD1_MASK (0xff) | 86 | #define NDCB0_CMD1_MASK (0xff) |
85 | #define NDCB0_ADDR_CYC_SHIFT (16) | 87 | #define NDCB0_ADDR_CYC_SHIFT (16) |
86 | 88 | ||
87 | /* dma-able I/O address for the NAND data and commands */ | ||
88 | #define NDCB0_DMA_ADDR (0x43100048) | ||
89 | #define NDDB_DMA_ADDR (0x43100040) | ||
90 | |||
91 | /* macros for registers read/write */ | 89 | /* macros for registers read/write */ |
92 | #define nand_writel(info, off, val) \ | 90 | #define nand_writel(info, off, val) \ |
93 | __raw_writel((val), (info)->mmio_base + (off)) | 91 | __raw_writel((val), (info)->mmio_base + (off)) |
@@ -123,6 +121,7 @@ struct pxa3xx_nand_info { | |||
123 | 121 | ||
124 | struct clk *clk; | 122 | struct clk *clk; |
125 | void __iomem *mmio_base; | 123 | void __iomem *mmio_base; |
124 | unsigned long mmio_phys; | ||
126 | 125 | ||
127 | unsigned int buf_start; | 126 | unsigned int buf_start; |
128 | unsigned int buf_count; | 127 | unsigned int buf_count; |
@@ -228,13 +227,35 @@ static struct pxa3xx_nand_flash samsung512MbX16 = { | |||
228 | .chip_id = 0x46ec, | 227 | .chip_id = 0x46ec, |
229 | }; | 228 | }; |
230 | 229 | ||
230 | static struct pxa3xx_nand_flash samsung2GbX8 = { | ||
231 | .timing = &samsung512MbX16_timing, | ||
232 | .cmdset = &smallpage_cmdset, | ||
233 | .page_per_block = 64, | ||
234 | .page_size = 2048, | ||
235 | .flash_width = 8, | ||
236 | .dfc_width = 8, | ||
237 | .num_blocks = 2048, | ||
238 | .chip_id = 0xdaec, | ||
239 | }; | ||
240 | |||
241 | static struct pxa3xx_nand_flash samsung32GbX8 = { | ||
242 | .timing = &samsung512MbX16_timing, | ||
243 | .cmdset = &smallpage_cmdset, | ||
244 | .page_per_block = 128, | ||
245 | .page_size = 4096, | ||
246 | .flash_width = 8, | ||
247 | .dfc_width = 8, | ||
248 | .num_blocks = 8192, | ||
249 | .chip_id = 0xd7ec, | ||
250 | }; | ||
251 | |||
231 | static struct pxa3xx_nand_timing micron_timing = { | 252 | static struct pxa3xx_nand_timing micron_timing = { |
232 | .tCH = 10, | 253 | .tCH = 10, |
233 | .tCS = 25, | 254 | .tCS = 25, |
234 | .tWH = 15, | 255 | .tWH = 15, |
235 | .tWP = 25, | 256 | .tWP = 25, |
236 | .tRH = 15, | 257 | .tRH = 15, |
237 | .tRP = 25, | 258 | .tRP = 30, |
238 | .tR = 25000, | 259 | .tR = 25000, |
239 | .tWHR = 60, | 260 | .tWHR = 60, |
240 | .tAR = 10, | 261 | .tAR = 10, |
@@ -262,6 +283,28 @@ static struct pxa3xx_nand_flash micron1GbX16 = { | |||
262 | .chip_id = 0xb12c, | 283 | .chip_id = 0xb12c, |
263 | }; | 284 | }; |
264 | 285 | ||
286 | static struct pxa3xx_nand_flash micron4GbX8 = { | ||
287 | .timing = µn_timing, | ||
288 | .cmdset = &largepage_cmdset, | ||
289 | .page_per_block = 64, | ||
290 | .page_size = 2048, | ||
291 | .flash_width = 8, | ||
292 | .dfc_width = 8, | ||
293 | .num_blocks = 4096, | ||
294 | .chip_id = 0xdc2c, | ||
295 | }; | ||
296 | |||
297 | static struct pxa3xx_nand_flash micron4GbX16 = { | ||
298 | .timing = µn_timing, | ||
299 | .cmdset = &largepage_cmdset, | ||
300 | .page_per_block = 64, | ||
301 | .page_size = 2048, | ||
302 | .flash_width = 16, | ||
303 | .dfc_width = 16, | ||
304 | .num_blocks = 4096, | ||
305 | .chip_id = 0xcc2c, | ||
306 | }; | ||
307 | |||
265 | static struct pxa3xx_nand_timing stm2GbX16_timing = { | 308 | static struct pxa3xx_nand_timing stm2GbX16_timing = { |
266 | .tCH = 10, | 309 | .tCH = 10, |
267 | .tCS = 35, | 310 | .tCS = 35, |
@@ -287,8 +330,12 @@ static struct pxa3xx_nand_flash stm2GbX16 = { | |||
287 | 330 | ||
288 | static struct pxa3xx_nand_flash *builtin_flash_types[] = { | 331 | static struct pxa3xx_nand_flash *builtin_flash_types[] = { |
289 | &samsung512MbX16, | 332 | &samsung512MbX16, |
333 | &samsung2GbX8, | ||
334 | &samsung32GbX8, | ||
290 | µn1GbX8, | 335 | µn1GbX8, |
291 | µn1GbX16, | 336 | µn1GbX16, |
337 | µn4GbX8, | ||
338 | µn4GbX16, | ||
292 | &stm2GbX16, | 339 | &stm2GbX16, |
293 | }; | 340 | }; |
294 | #endif /* CONFIG_MTD_NAND_PXA3xx_BUILTIN */ | 341 | #endif /* CONFIG_MTD_NAND_PXA3xx_BUILTIN */ |
@@ -489,7 +536,7 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) | |||
489 | switch (info->state) { | 536 | switch (info->state) { |
490 | case STATE_PIO_WRITING: | 537 | case STATE_PIO_WRITING: |
491 | __raw_writesl(info->mmio_base + NDDB, info->data_buff, | 538 | __raw_writesl(info->mmio_base + NDDB, info->data_buff, |
492 | info->data_size << 2); | 539 | DIV_ROUND_UP(info->data_size, 4)); |
493 | 540 | ||
494 | enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); | 541 | enable_int(info, NDSR_CS0_BBD | NDSR_CS0_CMDD); |
495 | 542 | ||
@@ -501,7 +548,7 @@ static int handle_data_pio(struct pxa3xx_nand_info *info) | |||
501 | break; | 548 | break; |
502 | case STATE_PIO_READING: | 549 | case STATE_PIO_READING: |
503 | __raw_readsl(info->mmio_base + NDDB, info->data_buff, | 550 | __raw_readsl(info->mmio_base + NDDB, info->data_buff, |
504 | info->data_size << 2); | 551 | DIV_ROUND_UP(info->data_size, 4)); |
505 | break; | 552 | break; |
506 | default: | 553 | default: |
507 | printk(KERN_ERR "%s: invalid state %d\n", __func__, | 554 | printk(KERN_ERR "%s: invalid state %d\n", __func__, |
@@ -523,11 +570,11 @@ static void start_data_dma(struct pxa3xx_nand_info *info, int dir_out) | |||
523 | 570 | ||
524 | if (dir_out) { | 571 | if (dir_out) { |
525 | desc->dsadr = info->data_buff_phys; | 572 | desc->dsadr = info->data_buff_phys; |
526 | desc->dtadr = NDDB_DMA_ADDR; | 573 | desc->dtadr = info->mmio_phys + NDDB; |
527 | desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG; | 574 | desc->dcmd |= DCMD_INCSRCADDR | DCMD_FLOWTRG; |
528 | } else { | 575 | } else { |
529 | desc->dtadr = info->data_buff_phys; | 576 | desc->dtadr = info->data_buff_phys; |
530 | desc->dsadr = NDDB_DMA_ADDR; | 577 | desc->dsadr = info->mmio_phys + NDDB; |
531 | desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC; | 578 | desc->dcmd |= DCMD_INCTRGADDR | DCMD_FLOWSRC; |
532 | } | 579 | } |
533 | 580 | ||
@@ -669,6 +716,7 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, | |||
669 | /* disable HW ECC to get all the OOB data */ | 716 | /* disable HW ECC to get all the OOB data */ |
670 | info->buf_count = mtd->writesize + mtd->oobsize; | 717 | info->buf_count = mtd->writesize + mtd->oobsize; |
671 | info->buf_start = mtd->writesize + column; | 718 | info->buf_start = mtd->writesize + column; |
719 | memset(info->data_buff, 0xFF, info->buf_count); | ||
672 | 720 | ||
673 | if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr)) | 721 | if (prepare_read_prog_cmd(info, cmdset->read1, column, page_addr)) |
674 | break; | 722 | break; |
@@ -1239,13 +1287,17 @@ static int pxa3xx_nand_probe(struct platform_device *pdev) | |||
1239 | ret = -ENODEV; | 1287 | ret = -ENODEV; |
1240 | goto fail_free_res; | 1288 | goto fail_free_res; |
1241 | } | 1289 | } |
1290 | info->mmio_phys = r->start; | ||
1242 | 1291 | ||
1243 | ret = pxa3xx_nand_init_buff(info); | 1292 | ret = pxa3xx_nand_init_buff(info); |
1244 | if (ret) | 1293 | if (ret) |
1245 | goto fail_free_io; | 1294 | goto fail_free_io; |
1246 | 1295 | ||
1247 | ret = request_irq(IRQ_NAND, pxa3xx_nand_irq, IRQF_DISABLED, | 1296 | /* initialize all interrupts to be disabled */ |
1248 | pdev->name, info); | 1297 | disable_int(info, NDSR_MASK); |
1298 | |||
1299 | ret = request_irq(irq, pxa3xx_nand_irq, IRQF_DISABLED, | ||
1300 | pdev->name, info); | ||
1249 | if (ret < 0) { | 1301 | if (ret < 0) { |
1250 | dev_err(&pdev->dev, "failed to request IRQ\n"); | 1302 | dev_err(&pdev->dev, "failed to request IRQ\n"); |
1251 | goto fail_free_buf; | 1303 | goto fail_free_buf; |
@@ -1271,7 +1323,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev) | |||
1271 | return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); | 1323 | return add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); |
1272 | 1324 | ||
1273 | fail_free_irq: | 1325 | fail_free_irq: |
1274 | free_irq(IRQ_NAND, info); | 1326 | free_irq(irq, info); |
1275 | fail_free_buf: | 1327 | fail_free_buf: |
1276 | if (use_dma) { | 1328 | if (use_dma) { |
1277 | pxa_free_dma(info->data_dma_ch); | 1329 | pxa_free_dma(info->data_dma_ch); |
@@ -1296,12 +1348,15 @@ static int pxa3xx_nand_remove(struct platform_device *pdev) | |||
1296 | struct mtd_info *mtd = platform_get_drvdata(pdev); | 1348 | struct mtd_info *mtd = platform_get_drvdata(pdev); |
1297 | struct pxa3xx_nand_info *info = mtd->priv; | 1349 | struct pxa3xx_nand_info *info = mtd->priv; |
1298 | struct resource *r; | 1350 | struct resource *r; |
1351 | int irq; | ||
1299 | 1352 | ||
1300 | platform_set_drvdata(pdev, NULL); | 1353 | platform_set_drvdata(pdev, NULL); |
1301 | 1354 | ||
1302 | del_mtd_device(mtd); | 1355 | del_mtd_device(mtd); |
1303 | del_mtd_partitions(mtd); | 1356 | del_mtd_partitions(mtd); |
1304 | free_irq(IRQ_NAND, info); | 1357 | irq = platform_get_irq(pdev, 0); |
1358 | if (irq >= 0) | ||
1359 | free_irq(irq, info); | ||
1305 | if (use_dma) { | 1360 | if (use_dma) { |
1306 | pxa_free_dma(info->data_dma_ch); | 1361 | pxa_free_dma(info->data_dma_ch); |
1307 | dma_free_writecombine(&pdev->dev, info->data_buff_size, | 1362 | dma_free_writecombine(&pdev->dev, info->data_buff_size, |
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c index 11dc7e69c4fb..fa6e9c7fe511 100644 --- a/drivers/mtd/nand/s3c2410.c +++ b/drivers/mtd/nand/s3c2410.c | |||
@@ -774,7 +774,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info, | |||
774 | chip->select_chip = s3c2410_nand_select_chip; | 774 | chip->select_chip = s3c2410_nand_select_chip; |
775 | chip->chip_delay = 50; | 775 | chip->chip_delay = 50; |
776 | chip->priv = nmtd; | 776 | chip->priv = nmtd; |
777 | chip->options = 0; | 777 | chip->options = set->options; |
778 | chip->controller = &info->controller; | 778 | chip->controller = &info->controller; |
779 | 779 | ||
780 | switch (info->cpu_type) { | 780 | switch (info->cpu_type) { |
@@ -875,7 +875,7 @@ static void s3c2410_nand_init_chip(struct s3c2410_nand_info *info, | |||
875 | * @info: The controller instance. | 875 | * @info: The controller instance. |
876 | * @nmtd: The driver version of the MTD instance. | 876 | * @nmtd: The driver version of the MTD instance. |
877 | * | 877 | * |
878 | * This routine is called after the chip probe has succesfully completed | 878 | * This routine is called after the chip probe has successfully completed |
879 | * and the relevant per-chip information updated. This call ensure that | 879 | * and the relevant per-chip information updated. This call ensure that |
880 | * we update the internal state accordingly. | 880 | * we update the internal state accordingly. |
881 | * | 881 | * |
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c index 02bef21f2e4b..34752fce0793 100644 --- a/drivers/mtd/nand/sh_flctl.c +++ b/drivers/mtd/nand/sh_flctl.c | |||
@@ -1,10 +1,10 @@ | |||
1 | /* | 1 | /* |
2 | * SuperH FLCTL nand controller | 2 | * SuperH FLCTL nand controller |
3 | * | 3 | * |
4 | * Copyright © 2008 Renesas Solutions Corp. | 4 | * Copyright (c) 2008 Renesas Solutions Corp. |
5 | * Copyright © 2008 Atom Create Engineering Co., Ltd. | 5 | * Copyright (c) 2008 Atom Create Engineering Co., Ltd. |
6 | * | 6 | * |
7 | * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor | 7 | * Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor |
8 | * | 8 | * |
9 | * This program is free software; you can redistribute it and/or modify | 9 | * This program is free software; you can redistribute it and/or modify |
10 | * it under the terms of the GNU General Public License as published by | 10 | * it under the terms of the GNU General Public License as published by |
@@ -26,6 +26,7 @@ | |||
26 | #include <linux/delay.h> | 26 | #include <linux/delay.h> |
27 | #include <linux/io.h> | 27 | #include <linux/io.h> |
28 | #include <linux/platform_device.h> | 28 | #include <linux/platform_device.h> |
29 | #include <linux/slab.h> | ||
29 | 30 | ||
30 | #include <linux/mtd/mtd.h> | 31 | #include <linux/mtd/mtd.h> |
31 | #include <linux/mtd/nand.h> | 32 | #include <linux/mtd/nand.h> |
@@ -75,6 +76,11 @@ static void start_translation(struct sh_flctl *flctl) | |||
75 | writeb(TRSTRT, FLTRCR(flctl)); | 76 | writeb(TRSTRT, FLTRCR(flctl)); |
76 | } | 77 | } |
77 | 78 | ||
79 | static void timeout_error(struct sh_flctl *flctl, const char *str) | ||
80 | { | ||
81 | dev_err(&flctl->pdev->dev, "Timeout occured in %s\n", str); | ||
82 | } | ||
83 | |||
78 | static void wait_completion(struct sh_flctl *flctl) | 84 | static void wait_completion(struct sh_flctl *flctl) |
79 | { | 85 | { |
80 | uint32_t timeout = LOOP_TIMEOUT_MAX; | 86 | uint32_t timeout = LOOP_TIMEOUT_MAX; |
@@ -87,7 +93,7 @@ static void wait_completion(struct sh_flctl *flctl) | |||
87 | udelay(1); | 93 | udelay(1); |
88 | } | 94 | } |
89 | 95 | ||
90 | printk(KERN_ERR "wait_completion(): Timeout occured \n"); | 96 | timeout_error(flctl, __func__); |
91 | writeb(0x0, FLTRCR(flctl)); | 97 | writeb(0x0, FLTRCR(flctl)); |
92 | } | 98 | } |
93 | 99 | ||
@@ -100,6 +106,8 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr) | |||
100 | addr = page_addr; /* ERASE1 */ | 106 | addr = page_addr; /* ERASE1 */ |
101 | } else if (page_addr != -1) { | 107 | } else if (page_addr != -1) { |
102 | /* SEQIN, READ0, etc.. */ | 108 | /* SEQIN, READ0, etc.. */ |
109 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
110 | column >>= 1; | ||
103 | if (flctl->page_size) { | 111 | if (flctl->page_size) { |
104 | addr = column & 0x0FFF; | 112 | addr = column & 0x0FFF; |
105 | addr |= (page_addr & 0xff) << 16; | 113 | addr |= (page_addr & 0xff) << 16; |
@@ -132,7 +140,7 @@ static void wait_rfifo_ready(struct sh_flctl *flctl) | |||
132 | return; | 140 | return; |
133 | udelay(1); | 141 | udelay(1); |
134 | } | 142 | } |
135 | printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); | 143 | timeout_error(flctl, __func__); |
136 | } | 144 | } |
137 | 145 | ||
138 | static void wait_wfifo_ready(struct sh_flctl *flctl) | 146 | static void wait_wfifo_ready(struct sh_flctl *flctl) |
@@ -146,7 +154,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl) | |||
146 | return; | 154 | return; |
147 | udelay(1); | 155 | udelay(1); |
148 | } | 156 | } |
149 | printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); | 157 | timeout_error(flctl, __func__); |
150 | } | 158 | } |
151 | 159 | ||
152 | static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) | 160 | static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) |
@@ -198,7 +206,7 @@ static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) | |||
198 | writel(0, FL4ECCCR(flctl)); | 206 | writel(0, FL4ECCCR(flctl)); |
199 | } | 207 | } |
200 | 208 | ||
201 | printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); | 209 | timeout_error(flctl, __func__); |
202 | return 1; /* timeout */ | 210 | return 1; /* timeout */ |
203 | } | 211 | } |
204 | 212 | ||
@@ -214,7 +222,7 @@ static void wait_wecfifo_ready(struct sh_flctl *flctl) | |||
214 | return; | 222 | return; |
215 | udelay(1); | 223 | udelay(1); |
216 | } | 224 | } |
217 | printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); | 225 | timeout_error(flctl, __func__); |
218 | } | 226 | } |
219 | 227 | ||
220 | static void read_datareg(struct sh_flctl *flctl, int offset) | 228 | static void read_datareg(struct sh_flctl *flctl, int offset) |
@@ -275,7 +283,7 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset) | |||
275 | static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) | 283 | static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) |
276 | { | 284 | { |
277 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | 285 | struct sh_flctl *flctl = mtd_to_flctl(mtd); |
278 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)); | 286 | uint32_t flcmncr_val = readl(FLCMNCR(flctl)) & ~SEL_16BIT; |
279 | uint32_t flcmdcr_val, addr_len_bytes = 0; | 287 | uint32_t flcmdcr_val, addr_len_bytes = 0; |
280 | 288 | ||
281 | /* Set SNAND bit if page size is 2048byte */ | 289 | /* Set SNAND bit if page size is 2048byte */ |
@@ -297,6 +305,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va | |||
297 | case NAND_CMD_READOOB: | 305 | case NAND_CMD_READOOB: |
298 | addr_len_bytes = flctl->rw_ADRCNT; | 306 | addr_len_bytes = flctl->rw_ADRCNT; |
299 | flcmdcr_val |= CDSRC_E; | 307 | flcmdcr_val |= CDSRC_E; |
308 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
309 | flcmncr_val |= SEL_16BIT; | ||
300 | break; | 310 | break; |
301 | case NAND_CMD_SEQIN: | 311 | case NAND_CMD_SEQIN: |
302 | /* This case is that cmd is READ0 or READ1 or READ00 */ | 312 | /* This case is that cmd is READ0 or READ1 or READ00 */ |
@@ -305,6 +315,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va | |||
305 | case NAND_CMD_PAGEPROG: | 315 | case NAND_CMD_PAGEPROG: |
306 | addr_len_bytes = flctl->rw_ADRCNT; | 316 | addr_len_bytes = flctl->rw_ADRCNT; |
307 | flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; | 317 | flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; |
318 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
319 | flcmncr_val |= SEL_16BIT; | ||
308 | break; | 320 | break; |
309 | case NAND_CMD_READID: | 321 | case NAND_CMD_READID: |
310 | flcmncr_val &= ~SNAND_E; | 322 | flcmncr_val &= ~SNAND_E; |
@@ -523,6 +535,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command, | |||
523 | set_addr(mtd, 0, page_addr); | 535 | set_addr(mtd, 0, page_addr); |
524 | 536 | ||
525 | flctl->read_bytes = mtd->writesize + mtd->oobsize; | 537 | flctl->read_bytes = mtd->writesize + mtd->oobsize; |
538 | if (flctl->chip.options & NAND_BUSWIDTH_16) | ||
539 | column >>= 1; | ||
526 | flctl->index += column; | 540 | flctl->index += column; |
527 | goto read_normal_exit; | 541 | goto read_normal_exit; |
528 | 542 | ||
@@ -686,6 +700,18 @@ static uint8_t flctl_read_byte(struct mtd_info *mtd) | |||
686 | return data; | 700 | return data; |
687 | } | 701 | } |
688 | 702 | ||
703 | static uint16_t flctl_read_word(struct mtd_info *mtd) | ||
704 | { | ||
705 | struct sh_flctl *flctl = mtd_to_flctl(mtd); | ||
706 | int index = flctl->index; | ||
707 | uint16_t data; | ||
708 | uint16_t *buf = (uint16_t *)&flctl->done_buff[index]; | ||
709 | |||
710 | data = *buf; | ||
711 | flctl->index += 2; | ||
712 | return data; | ||
713 | } | ||
714 | |||
689 | static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) | 715 | static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) |
690 | { | 716 | { |
691 | int i; | 717 | int i; |
@@ -769,38 +795,36 @@ static int flctl_chip_init_tail(struct mtd_info *mtd) | |||
769 | return 0; | 795 | return 0; |
770 | } | 796 | } |
771 | 797 | ||
772 | static int __init flctl_probe(struct platform_device *pdev) | 798 | static int __devinit flctl_probe(struct platform_device *pdev) |
773 | { | 799 | { |
774 | struct resource *res; | 800 | struct resource *res; |
775 | struct sh_flctl *flctl; | 801 | struct sh_flctl *flctl; |
776 | struct mtd_info *flctl_mtd; | 802 | struct mtd_info *flctl_mtd; |
777 | struct nand_chip *nand; | 803 | struct nand_chip *nand; |
778 | struct sh_flctl_platform_data *pdata; | 804 | struct sh_flctl_platform_data *pdata; |
779 | int ret; | 805 | int ret = -ENXIO; |
780 | 806 | ||
781 | pdata = pdev->dev.platform_data; | 807 | pdata = pdev->dev.platform_data; |
782 | if (pdata == NULL) { | 808 | if (pdata == NULL) { |
783 | printk(KERN_ERR "sh_flctl platform_data not found.\n"); | 809 | dev_err(&pdev->dev, "no platform data defined\n"); |
784 | return -ENODEV; | 810 | return -EINVAL; |
785 | } | 811 | } |
786 | 812 | ||
787 | flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); | 813 | flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); |
788 | if (!flctl) { | 814 | if (!flctl) { |
789 | printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); | 815 | dev_err(&pdev->dev, "failed to allocate driver data\n"); |
790 | return -ENOMEM; | 816 | return -ENOMEM; |
791 | } | 817 | } |
792 | 818 | ||
793 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); | 819 | res = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
794 | if (!res) { | 820 | if (!res) { |
795 | printk(KERN_ERR "%s: resource not found.\n", __func__); | 821 | dev_err(&pdev->dev, "failed to get I/O memory\n"); |
796 | ret = -ENODEV; | ||
797 | goto err; | 822 | goto err; |
798 | } | 823 | } |
799 | 824 | ||
800 | flctl->reg = ioremap(res->start, res->end - res->start + 1); | 825 | flctl->reg = ioremap(res->start, resource_size(res)); |
801 | if (flctl->reg == NULL) { | 826 | if (flctl->reg == NULL) { |
802 | printk(KERN_ERR "%s: ioremap error.\n", __func__); | 827 | dev_err(&pdev->dev, "failed to remap I/O memory\n"); |
803 | ret = -ENOMEM; | ||
804 | goto err; | 828 | goto err; |
805 | } | 829 | } |
806 | 830 | ||
@@ -808,6 +832,7 @@ static int __init flctl_probe(struct platform_device *pdev) | |||
808 | flctl_mtd = &flctl->mtd; | 832 | flctl_mtd = &flctl->mtd; |
809 | nand = &flctl->chip; | 833 | nand = &flctl->chip; |
810 | flctl_mtd->priv = nand; | 834 | flctl_mtd->priv = nand; |
835 | flctl->pdev = pdev; | ||
811 | flctl->hwecc = pdata->has_hwecc; | 836 | flctl->hwecc = pdata->has_hwecc; |
812 | 837 | ||
813 | flctl_register_init(flctl, pdata->flcmncr_val); | 838 | flctl_register_init(flctl, pdata->flcmncr_val); |
@@ -825,6 +850,11 @@ static int __init flctl_probe(struct platform_device *pdev) | |||
825 | nand->select_chip = flctl_select_chip; | 850 | nand->select_chip = flctl_select_chip; |
826 | nand->cmdfunc = flctl_cmdfunc; | 851 | nand->cmdfunc = flctl_cmdfunc; |
827 | 852 | ||
853 | if (pdata->flcmncr_val & SEL_16BIT) { | ||
854 | nand->options |= NAND_BUSWIDTH_16; | ||
855 | nand->read_word = flctl_read_word; | ||
856 | } | ||
857 | |||
828 | ret = nand_scan_ident(flctl_mtd, 1); | 858 | ret = nand_scan_ident(flctl_mtd, 1); |
829 | if (ret) | 859 | if (ret) |
830 | goto err; | 860 | goto err; |
@@ -846,7 +876,7 @@ err: | |||
846 | return ret; | 876 | return ret; |
847 | } | 877 | } |
848 | 878 | ||
849 | static int __exit flctl_remove(struct platform_device *pdev) | 879 | static int __devexit flctl_remove(struct platform_device *pdev) |
850 | { | 880 | { |
851 | struct sh_flctl *flctl = platform_get_drvdata(pdev); | 881 | struct sh_flctl *flctl = platform_get_drvdata(pdev); |
852 | 882 | ||
diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c index 92c73344a669..fa28f01ae009 100644 --- a/drivers/mtd/nand/tmio_nand.c +++ b/drivers/mtd/nand/tmio_nand.c | |||
@@ -37,6 +37,7 @@ | |||
37 | #include <linux/mtd/nand.h> | 37 | #include <linux/mtd/nand.h> |
38 | #include <linux/mtd/nand_ecc.h> | 38 | #include <linux/mtd/nand_ecc.h> |
39 | #include <linux/mtd/partitions.h> | 39 | #include <linux/mtd/partitions.h> |
40 | #include <linux/slab.h> | ||
40 | 41 | ||
41 | /*--------------------------------------------------------------------------*/ | 42 | /*--------------------------------------------------------------------------*/ |
42 | 43 | ||
diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c index 73af8324d0d0..863513c3b69a 100644 --- a/drivers/mtd/nand/txx9ndfmc.c +++ b/drivers/mtd/nand/txx9ndfmc.c | |||
@@ -429,11 +429,10 @@ static int __exit txx9ndfmc_remove(struct platform_device *dev) | |||
429 | chip = mtd->priv; | 429 | chip = mtd->priv; |
430 | txx9_priv = chip->priv; | 430 | txx9_priv = chip->priv; |
431 | 431 | ||
432 | nand_release(mtd); | ||
432 | #ifdef CONFIG_MTD_PARTITIONS | 433 | #ifdef CONFIG_MTD_PARTITIONS |
433 | del_mtd_partitions(mtd); | ||
434 | kfree(drvdata->parts[i]); | 434 | kfree(drvdata->parts[i]); |
435 | #endif | 435 | #endif |
436 | del_mtd_device(mtd); | ||
437 | kfree(txx9_priv->mtdname); | 436 | kfree(txx9_priv->mtdname); |
438 | kfree(txx9_priv); | 437 | kfree(txx9_priv); |
439 | } | 438 | } |
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c index 62d6a78c4eee..4f0d635674f3 100644 --- a/drivers/mtd/ofpart.c +++ b/drivers/mtd/ofpart.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/init.h> | 17 | #include <linux/init.h> |
18 | #include <linux/of.h> | 18 | #include <linux/of.h> |
19 | #include <linux/mtd/mtd.h> | 19 | #include <linux/mtd/mtd.h> |
20 | #include <linux/slab.h> | ||
20 | #include <linux/mtd/partitions.h> | 21 | #include <linux/mtd/partitions.h> |
21 | 22 | ||
22 | int __devinit of_mtd_parse_partitions(struct device *dev, | 23 | int __devinit of_mtd_parse_partitions(struct device *dev, |
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig index a38f580c2bb3..3a9f15784600 100644 --- a/drivers/mtd/onenand/Kconfig +++ b/drivers/mtd/onenand/Kconfig | |||
@@ -1,7 +1,3 @@ | |||
1 | # | ||
2 | # linux/drivers/mtd/onenand/Kconfig | ||
3 | # | ||
4 | |||
5 | menuconfig MTD_ONENAND | 1 | menuconfig MTD_ONENAND |
6 | tristate "OneNAND Device Support" | 2 | tristate "OneNAND Device Support" |
7 | depends on MTD | 3 | depends on MTD |
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c index 0108ed42e877..fd406348fdfd 100644 --- a/drivers/mtd/onenand/omap2.c +++ b/drivers/mtd/onenand/omap2.c | |||
@@ -34,15 +34,16 @@ | |||
34 | #include <linux/delay.h> | 34 | #include <linux/delay.h> |
35 | #include <linux/dma-mapping.h> | 35 | #include <linux/dma-mapping.h> |
36 | #include <linux/io.h> | 36 | #include <linux/io.h> |
37 | #include <linux/slab.h> | ||
37 | 38 | ||
38 | #include <asm/mach/flash.h> | 39 | #include <asm/mach/flash.h> |
39 | #include <mach/gpmc.h> | 40 | #include <plat/gpmc.h> |
40 | #include <mach/onenand.h> | 41 | #include <plat/onenand.h> |
41 | #include <mach/gpio.h> | 42 | #include <mach/gpio.h> |
42 | 43 | ||
43 | #include <mach/dma.h> | 44 | #include <plat/dma.h> |
44 | 45 | ||
45 | #include <mach/board.h> | 46 | #include <plat/board.h> |
46 | 47 | ||
47 | #define DRIVER_NAME "omap2-onenand" | 48 | #define DRIVER_NAME "omap2-onenand" |
48 | 49 | ||
@@ -112,10 +113,24 @@ static int omap2_onenand_wait(struct mtd_info *mtd, int state) | |||
112 | unsigned long timeout; | 113 | unsigned long timeout; |
113 | u32 syscfg; | 114 | u32 syscfg; |
114 | 115 | ||
115 | if (state == FL_RESETING) { | 116 | if (state == FL_RESETING || state == FL_PREPARING_ERASE || |
116 | int i; | 117 | state == FL_VERIFYING_ERASE) { |
118 | int i = 21; | ||
119 | unsigned int intr_flags = ONENAND_INT_MASTER; | ||
117 | 120 | ||
118 | for (i = 0; i < 20; i++) { | 121 | switch (state) { |
122 | case FL_RESETING: | ||
123 | intr_flags |= ONENAND_INT_RESET; | ||
124 | break; | ||
125 | case FL_PREPARING_ERASE: | ||
126 | intr_flags |= ONENAND_INT_ERASE; | ||
127 | break; | ||
128 | case FL_VERIFYING_ERASE: | ||
129 | i = 101; | ||
130 | break; | ||
131 | } | ||
132 | |||
133 | while (--i) { | ||
119 | udelay(1); | 134 | udelay(1); |
120 | intr = read_reg(c, ONENAND_REG_INTERRUPT); | 135 | intr = read_reg(c, ONENAND_REG_INTERRUPT); |
121 | if (intr & ONENAND_INT_MASTER) | 136 | if (intr & ONENAND_INT_MASTER) |
@@ -126,7 +141,7 @@ static int omap2_onenand_wait(struct mtd_info *mtd, int state) | |||
126 | wait_err("controller error", state, ctrl, intr); | 141 | wait_err("controller error", state, ctrl, intr); |
127 | return -EIO; | 142 | return -EIO; |
128 | } | 143 | } |
129 | if (!(intr & ONENAND_INT_RESET)) { | 144 | if ((intr & intr_flags) != intr_flags) { |
130 | wait_err("timeout", state, ctrl, intr); | 145 | wait_err("timeout", state, ctrl, intr); |
131 | return -EIO; | 146 | return -EIO; |
132 | } | 147 | } |
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c index ff66e4330aa7..32f0ed33afe0 100644 --- a/drivers/mtd/onenand/onenand_base.c +++ b/drivers/mtd/onenand/onenand_base.c | |||
@@ -1,17 +1,19 @@ | |||
1 | /* | 1 | /* |
2 | * linux/drivers/mtd/onenand/onenand_base.c | 2 | * linux/drivers/mtd/onenand/onenand_base.c |
3 | * | 3 | * |
4 | * Copyright (C) 2005-2007 Samsung Electronics | 4 | * Copyright © 2005-2009 Samsung Electronics |
5 | * Copyright © 2007 Nokia Corporation | ||
6 | * | ||
5 | * Kyungmin Park <kyungmin.park@samsung.com> | 7 | * Kyungmin Park <kyungmin.park@samsung.com> |
6 | * | 8 | * |
7 | * Credits: | 9 | * Credits: |
8 | * Adrian Hunter <ext-adrian.hunter@nokia.com>: | 10 | * Adrian Hunter <ext-adrian.hunter@nokia.com>: |
9 | * auto-placement support, read-while load support, various fixes | 11 | * auto-placement support, read-while load support, various fixes |
10 | * Copyright (C) Nokia Corporation, 2007 | ||
11 | * | 12 | * |
12 | * Vishak G <vishak.g at samsung.com>, Rohit Hagargundgi <h.rohit at samsung.com> | 13 | * Vishak G <vishak.g at samsung.com>, Rohit Hagargundgi <h.rohit at samsung.com> |
13 | * Flex-OneNAND support | 14 | * Flex-OneNAND support |
14 | * Copyright (C) Samsung Electronics, 2008 | 15 | * Amul Kumar Saha <amul.saha at samsung.com> |
16 | * OTP support | ||
15 | * | 17 | * |
16 | * This program is free software; you can redistribute it and/or modify | 18 | * This program is free software; you can redistribute it and/or modify |
17 | * it under the terms of the GNU General Public License version 2 as | 19 | * it under the terms of the GNU General Public License version 2 as |
@@ -21,6 +23,7 @@ | |||
21 | #include <linux/kernel.h> | 23 | #include <linux/kernel.h> |
22 | #include <linux/module.h> | 24 | #include <linux/module.h> |
23 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/slab.h> | ||
24 | #include <linux/init.h> | 27 | #include <linux/init.h> |
25 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
26 | #include <linux/delay.h> | 29 | #include <linux/delay.h> |
@@ -32,6 +35,13 @@ | |||
32 | 35 | ||
33 | #include <asm/io.h> | 36 | #include <asm/io.h> |
34 | 37 | ||
38 | /* | ||
39 | * Multiblock erase if number of blocks to erase is 2 or more. | ||
40 | * Maximum number of blocks for simultaneous erase is 64. | ||
41 | */ | ||
42 | #define MB_ERASE_MIN_BLK_COUNT 2 | ||
43 | #define MB_ERASE_MAX_BLK_COUNT 64 | ||
44 | |||
35 | /* Default Flex-OneNAND boundary and lock respectively */ | 45 | /* Default Flex-OneNAND boundary and lock respectively */ |
36 | static int flex_bdry[MAX_DIES * 2] = { -1, 0, -1, 0 }; | 46 | static int flex_bdry[MAX_DIES * 2] = { -1, 0, -1, 0 }; |
37 | 47 | ||
@@ -43,6 +53,18 @@ MODULE_PARM_DESC(flex_bdry, "SLC Boundary information for Flex-OneNAND" | |||
43 | " : 0->Set boundary in unlocked status" | 53 | " : 0->Set boundary in unlocked status" |
44 | " : 1->Set boundary in locked status"); | 54 | " : 1->Set boundary in locked status"); |
45 | 55 | ||
56 | /* Default OneNAND/Flex-OneNAND OTP options*/ | ||
57 | static int otp; | ||
58 | |||
59 | module_param(otp, int, 0400); | ||
60 | MODULE_PARM_DESC(otp, "Corresponding behaviour of OneNAND in OTP" | ||
61 | "Syntax : otp=LOCK_TYPE" | ||
62 | "LOCK_TYPE : Keys issued, for specific OTP Lock type" | ||
63 | " : 0 -> Default (No Blocks Locked)" | ||
64 | " : 1 -> OTP Block lock" | ||
65 | " : 2 -> 1st Block lock" | ||
66 | " : 3 -> BOTH OTP Block and 1st Block lock"); | ||
67 | |||
46 | /** | 68 | /** |
47 | * onenand_oob_128 - oob info for Flex-Onenand with 4KB page | 69 | * onenand_oob_128 - oob info for Flex-Onenand with 4KB page |
48 | * For now, we expose only 64 out of 80 ecc bytes | 70 | * For now, we expose only 64 out of 80 ecc bytes |
@@ -339,6 +361,8 @@ static int onenand_command(struct mtd_info *mtd, int cmd, loff_t addr, size_t le | |||
339 | break; | 361 | break; |
340 | 362 | ||
341 | case ONENAND_CMD_ERASE: | 363 | case ONENAND_CMD_ERASE: |
364 | case ONENAND_CMD_MULTIBLOCK_ERASE: | ||
365 | case ONENAND_CMD_ERASE_VERIFY: | ||
342 | case ONENAND_CMD_BUFFERRAM: | 366 | case ONENAND_CMD_BUFFERRAM: |
343 | case ONENAND_CMD_OTP_ACCESS: | 367 | case ONENAND_CMD_OTP_ACCESS: |
344 | block = onenand_block(this, addr); | 368 | block = onenand_block(this, addr); |
@@ -483,7 +507,7 @@ static int onenand_wait(struct mtd_info *mtd, int state) | |||
483 | if (interrupt & flags) | 507 | if (interrupt & flags) |
484 | break; | 508 | break; |
485 | 509 | ||
486 | if (state != FL_READING) | 510 | if (state != FL_READING && state != FL_PREPARING_ERASE) |
487 | cond_resched(); | 511 | cond_resched(); |
488 | } | 512 | } |
489 | /* To get correct interrupt status in timeout case */ | 513 | /* To get correct interrupt status in timeout case */ |
@@ -500,25 +524,40 @@ static int onenand_wait(struct mtd_info *mtd, int state) | |||
500 | int ecc = onenand_read_ecc(this); | 524 | int ecc = onenand_read_ecc(this); |
501 | if (ecc) { | 525 | if (ecc) { |
502 | if (ecc & ONENAND_ECC_2BIT_ALL) { | 526 | if (ecc & ONENAND_ECC_2BIT_ALL) { |
503 | printk(KERN_ERR "onenand_wait: ECC error = 0x%04x\n", ecc); | 527 | printk(KERN_ERR "%s: ECC error = 0x%04x\n", |
528 | __func__, ecc); | ||
504 | mtd->ecc_stats.failed++; | 529 | mtd->ecc_stats.failed++; |
505 | return -EBADMSG; | 530 | return -EBADMSG; |
506 | } else if (ecc & ONENAND_ECC_1BIT_ALL) { | 531 | } else if (ecc & ONENAND_ECC_1BIT_ALL) { |
507 | printk(KERN_DEBUG "onenand_wait: correctable ECC error = 0x%04x\n", ecc); | 532 | printk(KERN_DEBUG "%s: correctable ECC error = 0x%04x\n", |
533 | __func__, ecc); | ||
508 | mtd->ecc_stats.corrected++; | 534 | mtd->ecc_stats.corrected++; |
509 | } | 535 | } |
510 | } | 536 | } |
511 | } else if (state == FL_READING) { | 537 | } else if (state == FL_READING) { |
512 | printk(KERN_ERR "onenand_wait: read timeout! ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt); | 538 | printk(KERN_ERR "%s: read timeout! ctrl=0x%04x intr=0x%04x\n", |
539 | __func__, ctrl, interrupt); | ||
540 | return -EIO; | ||
541 | } | ||
542 | |||
543 | if (state == FL_PREPARING_ERASE && !(interrupt & ONENAND_INT_ERASE)) { | ||
544 | printk(KERN_ERR "%s: mb erase timeout! ctrl=0x%04x intr=0x%04x\n", | ||
545 | __func__, ctrl, interrupt); | ||
546 | return -EIO; | ||
547 | } | ||
548 | |||
549 | if (!(interrupt & ONENAND_INT_MASTER)) { | ||
550 | printk(KERN_ERR "%s: timeout! ctrl=0x%04x intr=0x%04x\n", | ||
551 | __func__, ctrl, interrupt); | ||
513 | return -EIO; | 552 | return -EIO; |
514 | } | 553 | } |
515 | 554 | ||
516 | /* If there's controller error, it's a real error */ | 555 | /* If there's controller error, it's a real error */ |
517 | if (ctrl & ONENAND_CTRL_ERROR) { | 556 | if (ctrl & ONENAND_CTRL_ERROR) { |
518 | printk(KERN_ERR "onenand_wait: controller error = 0x%04x\n", | 557 | printk(KERN_ERR "%s: controller error = 0x%04x\n", |
519 | ctrl); | 558 | __func__, ctrl); |
520 | if (ctrl & ONENAND_CTRL_LOCK) | 559 | if (ctrl & ONENAND_CTRL_LOCK) |
521 | printk(KERN_ERR "onenand_wait: it's locked error.\n"); | 560 | printk(KERN_ERR "%s: it's locked error.\n", __func__); |
522 | return -EIO; | 561 | return -EIO; |
523 | } | 562 | } |
524 | 563 | ||
@@ -1015,7 +1054,8 @@ static int onenand_recover_lsb(struct mtd_info *mtd, loff_t addr, int status) | |||
1015 | /* We are attempting to reread, so decrement stats.failed | 1054 | /* We are attempting to reread, so decrement stats.failed |
1016 | * which was incremented by onenand_wait due to read failure | 1055 | * which was incremented by onenand_wait due to read failure |
1017 | */ | 1056 | */ |
1018 | printk(KERN_INFO "onenand_recover_lsb: Attempting to recover from uncorrectable read\n"); | 1057 | printk(KERN_INFO "%s: Attempting to recover from uncorrectable read\n", |
1058 | __func__); | ||
1019 | mtd->ecc_stats.failed--; | 1059 | mtd->ecc_stats.failed--; |
1020 | 1060 | ||
1021 | /* Issue the LSB page recovery command */ | 1061 | /* Issue the LSB page recovery command */ |
@@ -1046,7 +1086,8 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from, | |||
1046 | int ret = 0; | 1086 | int ret = 0; |
1047 | int writesize = this->writesize; | 1087 | int writesize = this->writesize; |
1048 | 1088 | ||
1049 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_mlc_read_ops_nolock: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); | 1089 | DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", |
1090 | __func__, (unsigned int) from, (int) len); | ||
1050 | 1091 | ||
1051 | if (ops->mode == MTD_OOB_AUTO) | 1092 | if (ops->mode == MTD_OOB_AUTO) |
1052 | oobsize = this->ecclayout->oobavail; | 1093 | oobsize = this->ecclayout->oobavail; |
@@ -1057,7 +1098,8 @@ static int onenand_mlc_read_ops_nolock(struct mtd_info *mtd, loff_t from, | |||
1057 | 1098 | ||
1058 | /* Do not allow reads past end of device */ | 1099 | /* Do not allow reads past end of device */ |
1059 | if (from + len > mtd->size) { | 1100 | if (from + len > mtd->size) { |
1060 | printk(KERN_ERR "onenand_mlc_read_ops_nolock: Attempt read beyond end of device\n"); | 1101 | printk(KERN_ERR "%s: Attempt read beyond end of device\n", |
1102 | __func__); | ||
1061 | ops->retlen = 0; | 1103 | ops->retlen = 0; |
1062 | ops->oobretlen = 0; | 1104 | ops->oobretlen = 0; |
1063 | return -EINVAL; | 1105 | return -EINVAL; |
@@ -1146,7 +1188,8 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from, | |||
1146 | int ret = 0, boundary = 0; | 1188 | int ret = 0, boundary = 0; |
1147 | int writesize = this->writesize; | 1189 | int writesize = this->writesize; |
1148 | 1190 | ||
1149 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_ops_nolock: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); | 1191 | DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", |
1192 | __func__, (unsigned int) from, (int) len); | ||
1150 | 1193 | ||
1151 | if (ops->mode == MTD_OOB_AUTO) | 1194 | if (ops->mode == MTD_OOB_AUTO) |
1152 | oobsize = this->ecclayout->oobavail; | 1195 | oobsize = this->ecclayout->oobavail; |
@@ -1157,7 +1200,8 @@ static int onenand_read_ops_nolock(struct mtd_info *mtd, loff_t from, | |||
1157 | 1200 | ||
1158 | /* Do not allow reads past end of device */ | 1201 | /* Do not allow reads past end of device */ |
1159 | if ((from + len) > mtd->size) { | 1202 | if ((from + len) > mtd->size) { |
1160 | printk(KERN_ERR "onenand_read_ops_nolock: Attempt read beyond end of device\n"); | 1203 | printk(KERN_ERR "%s: Attempt read beyond end of device\n", |
1204 | __func__); | ||
1161 | ops->retlen = 0; | 1205 | ops->retlen = 0; |
1162 | ops->oobretlen = 0; | 1206 | ops->oobretlen = 0; |
1163 | return -EINVAL; | 1207 | return -EINVAL; |
@@ -1275,7 +1319,8 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, | |||
1275 | 1319 | ||
1276 | from += ops->ooboffs; | 1320 | from += ops->ooboffs; |
1277 | 1321 | ||
1278 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_read_oob_nolock: from = 0x%08x, len = %i\n", (unsigned int) from, (int) len); | 1322 | DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %i\n", |
1323 | __func__, (unsigned int) from, (int) len); | ||
1279 | 1324 | ||
1280 | /* Initialize return length value */ | 1325 | /* Initialize return length value */ |
1281 | ops->oobretlen = 0; | 1326 | ops->oobretlen = 0; |
@@ -1288,7 +1333,8 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, | |||
1288 | column = from & (mtd->oobsize - 1); | 1333 | column = from & (mtd->oobsize - 1); |
1289 | 1334 | ||
1290 | if (unlikely(column >= oobsize)) { | 1335 | if (unlikely(column >= oobsize)) { |
1291 | printk(KERN_ERR "onenand_read_oob_nolock: Attempted to start read outside oob\n"); | 1336 | printk(KERN_ERR "%s: Attempted to start read outside oob\n", |
1337 | __func__); | ||
1292 | return -EINVAL; | 1338 | return -EINVAL; |
1293 | } | 1339 | } |
1294 | 1340 | ||
@@ -1296,7 +1342,8 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, | |||
1296 | if (unlikely(from >= mtd->size || | 1342 | if (unlikely(from >= mtd->size || |
1297 | column + len > ((mtd->size >> this->page_shift) - | 1343 | column + len > ((mtd->size >> this->page_shift) - |
1298 | (from >> this->page_shift)) * oobsize)) { | 1344 | (from >> this->page_shift)) * oobsize)) { |
1299 | printk(KERN_ERR "onenand_read_oob_nolock: Attempted to read beyond end of device\n"); | 1345 | printk(KERN_ERR "%s: Attempted to read beyond end of device\n", |
1346 | __func__); | ||
1300 | return -EINVAL; | 1347 | return -EINVAL; |
1301 | } | 1348 | } |
1302 | 1349 | ||
@@ -1319,7 +1366,8 @@ static int onenand_read_oob_nolock(struct mtd_info *mtd, loff_t from, | |||
1319 | ret = onenand_recover_lsb(mtd, from, ret); | 1366 | ret = onenand_recover_lsb(mtd, from, ret); |
1320 | 1367 | ||
1321 | if (ret && ret != -EBADMSG) { | 1368 | if (ret && ret != -EBADMSG) { |
1322 | printk(KERN_ERR "onenand_read_oob_nolock: read failed = 0x%x\n", ret); | 1369 | printk(KERN_ERR "%s: read failed = 0x%x\n", |
1370 | __func__, ret); | ||
1323 | break; | 1371 | break; |
1324 | } | 1372 | } |
1325 | 1373 | ||
@@ -1450,20 +1498,21 @@ static int onenand_bbt_wait(struct mtd_info *mtd, int state) | |||
1450 | if (interrupt & ONENAND_INT_READ) { | 1498 | if (interrupt & ONENAND_INT_READ) { |
1451 | int ecc = onenand_read_ecc(this); | 1499 | int ecc = onenand_read_ecc(this); |
1452 | if (ecc & ONENAND_ECC_2BIT_ALL) { | 1500 | if (ecc & ONENAND_ECC_2BIT_ALL) { |
1453 | printk(KERN_INFO "onenand_bbt_wait: ecc error = 0x%04x" | 1501 | printk(KERN_WARNING "%s: ecc error = 0x%04x, " |
1454 | ", controller error 0x%04x\n", ecc, ctrl); | 1502 | "controller error 0x%04x\n", |
1503 | __func__, ecc, ctrl); | ||
1455 | return ONENAND_BBT_READ_ECC_ERROR; | 1504 | return ONENAND_BBT_READ_ECC_ERROR; |
1456 | } | 1505 | } |
1457 | } else { | 1506 | } else { |
1458 | printk(KERN_ERR "onenand_bbt_wait: read timeout!" | 1507 | printk(KERN_ERR "%s: read timeout! ctrl=0x%04x intr=0x%04x\n", |
1459 | "ctrl=0x%04x intr=0x%04x\n", ctrl, interrupt); | 1508 | __func__, ctrl, interrupt); |
1460 | return ONENAND_BBT_READ_FATAL_ERROR; | 1509 | return ONENAND_BBT_READ_FATAL_ERROR; |
1461 | } | 1510 | } |
1462 | 1511 | ||
1463 | /* Initial bad block case: 0x2400 or 0x0400 */ | 1512 | /* Initial bad block case: 0x2400 or 0x0400 */ |
1464 | if (ctrl & ONENAND_CTRL_ERROR) { | 1513 | if (ctrl & ONENAND_CTRL_ERROR) { |
1465 | printk(KERN_DEBUG "onenand_bbt_wait: " | 1514 | printk(KERN_DEBUG "%s: controller error = 0x%04x\n", |
1466 | "controller error = 0x%04x\n", ctrl); | 1515 | __func__, ctrl); |
1467 | return ONENAND_BBT_READ_ERROR; | 1516 | return ONENAND_BBT_READ_ERROR; |
1468 | } | 1517 | } |
1469 | 1518 | ||
@@ -1487,14 +1536,16 @@ int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, | |||
1487 | size_t len = ops->ooblen; | 1536 | size_t len = ops->ooblen; |
1488 | u_char *buf = ops->oobbuf; | 1537 | u_char *buf = ops->oobbuf; |
1489 | 1538 | ||
1490 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_bbt_read_oob: from = 0x%08x, len = %zi\n", (unsigned int) from, len); | 1539 | DEBUG(MTD_DEBUG_LEVEL3, "%s: from = 0x%08x, len = %zi\n", |
1540 | __func__, (unsigned int) from, len); | ||
1491 | 1541 | ||
1492 | /* Initialize return value */ | 1542 | /* Initialize return value */ |
1493 | ops->oobretlen = 0; | 1543 | ops->oobretlen = 0; |
1494 | 1544 | ||
1495 | /* Do not allow reads past end of device */ | 1545 | /* Do not allow reads past end of device */ |
1496 | if (unlikely((from + len) > mtd->size)) { | 1546 | if (unlikely((from + len) > mtd->size)) { |
1497 | printk(KERN_ERR "onenand_bbt_read_oob: Attempt read beyond end of device\n"); | 1547 | printk(KERN_ERR "%s: Attempt read beyond end of device\n", |
1548 | __func__); | ||
1498 | return ONENAND_BBT_READ_FATAL_ERROR; | 1549 | return ONENAND_BBT_READ_FATAL_ERROR; |
1499 | } | 1550 | } |
1500 | 1551 | ||
@@ -1661,21 +1712,23 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
1661 | /* Wait for any existing operation to clear */ | 1712 | /* Wait for any existing operation to clear */ |
1662 | onenand_panic_wait(mtd); | 1713 | onenand_panic_wait(mtd); |
1663 | 1714 | ||
1664 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_panic_write: to = 0x%08x, len = %i\n", | 1715 | DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", |
1665 | (unsigned int) to, (int) len); | 1716 | __func__, (unsigned int) to, (int) len); |
1666 | 1717 | ||
1667 | /* Initialize retlen, in case of early exit */ | 1718 | /* Initialize retlen, in case of early exit */ |
1668 | *retlen = 0; | 1719 | *retlen = 0; |
1669 | 1720 | ||
1670 | /* Do not allow writes past end of device */ | 1721 | /* Do not allow writes past end of device */ |
1671 | if (unlikely((to + len) > mtd->size)) { | 1722 | if (unlikely((to + len) > mtd->size)) { |
1672 | printk(KERN_ERR "onenand_panic_write: Attempt write to past end of device\n"); | 1723 | printk(KERN_ERR "%s: Attempt write to past end of device\n", |
1724 | __func__); | ||
1673 | return -EINVAL; | 1725 | return -EINVAL; |
1674 | } | 1726 | } |
1675 | 1727 | ||
1676 | /* Reject writes, which are not page aligned */ | 1728 | /* Reject writes, which are not page aligned */ |
1677 | if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { | 1729 | if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { |
1678 | printk(KERN_ERR "onenand_panic_write: Attempt to write not page aligned data\n"); | 1730 | printk(KERN_ERR "%s: Attempt to write not page aligned data\n", |
1731 | __func__); | ||
1679 | return -EINVAL; | 1732 | return -EINVAL; |
1680 | } | 1733 | } |
1681 | 1734 | ||
@@ -1711,7 +1764,7 @@ static int onenand_panic_write(struct mtd_info *mtd, loff_t to, size_t len, | |||
1711 | } | 1764 | } |
1712 | 1765 | ||
1713 | if (ret) { | 1766 | if (ret) { |
1714 | printk(KERN_ERR "onenand_panic_write: write failed %d\n", ret); | 1767 | printk(KERN_ERR "%s: write failed %d\n", __func__, ret); |
1715 | break; | 1768 | break; |
1716 | } | 1769 | } |
1717 | 1770 | ||
@@ -1792,7 +1845,8 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, | |||
1792 | u_char *oobbuf; | 1845 | u_char *oobbuf; |
1793 | int ret = 0; | 1846 | int ret = 0; |
1794 | 1847 | ||
1795 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_ops_nolock: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); | 1848 | DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", |
1849 | __func__, (unsigned int) to, (int) len); | ||
1796 | 1850 | ||
1797 | /* Initialize retlen, in case of early exit */ | 1851 | /* Initialize retlen, in case of early exit */ |
1798 | ops->retlen = 0; | 1852 | ops->retlen = 0; |
@@ -1800,13 +1854,15 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, | |||
1800 | 1854 | ||
1801 | /* Do not allow writes past end of device */ | 1855 | /* Do not allow writes past end of device */ |
1802 | if (unlikely((to + len) > mtd->size)) { | 1856 | if (unlikely((to + len) > mtd->size)) { |
1803 | printk(KERN_ERR "onenand_write_ops_nolock: Attempt write to past end of device\n"); | 1857 | printk(KERN_ERR "%s: Attempt write to past end of device\n", |
1858 | __func__); | ||
1804 | return -EINVAL; | 1859 | return -EINVAL; |
1805 | } | 1860 | } |
1806 | 1861 | ||
1807 | /* Reject writes, which are not page aligned */ | 1862 | /* Reject writes, which are not page aligned */ |
1808 | if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { | 1863 | if (unlikely(NOTALIGNED(to) || NOTALIGNED(len))) { |
1809 | printk(KERN_ERR "onenand_write_ops_nolock: Attempt to write not page aligned data\n"); | 1864 | printk(KERN_ERR "%s: Attempt to write not page aligned data\n", |
1865 | __func__); | ||
1810 | return -EINVAL; | 1866 | return -EINVAL; |
1811 | } | 1867 | } |
1812 | 1868 | ||
@@ -1879,7 +1935,8 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, | |||
1879 | onenand_update_bufferram(mtd, prev, !ret && !prev_subpage); | 1935 | onenand_update_bufferram(mtd, prev, !ret && !prev_subpage); |
1880 | if (ret) { | 1936 | if (ret) { |
1881 | written -= prevlen; | 1937 | written -= prevlen; |
1882 | printk(KERN_ERR "onenand_write_ops_nolock: write failed %d\n", ret); | 1938 | printk(KERN_ERR "%s: write failed %d\n", |
1939 | __func__, ret); | ||
1883 | break; | 1940 | break; |
1884 | } | 1941 | } |
1885 | 1942 | ||
@@ -1887,7 +1944,8 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, | |||
1887 | /* Only check verify write turn on */ | 1944 | /* Only check verify write turn on */ |
1888 | ret = onenand_verify(mtd, buf - len, to - len, len); | 1945 | ret = onenand_verify(mtd, buf - len, to - len, len); |
1889 | if (ret) | 1946 | if (ret) |
1890 | printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret); | 1947 | printk(KERN_ERR "%s: verify failed %d\n", |
1948 | __func__, ret); | ||
1891 | break; | 1949 | break; |
1892 | } | 1950 | } |
1893 | 1951 | ||
@@ -1905,14 +1963,16 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to, | |||
1905 | /* In partial page write we don't update bufferram */ | 1963 | /* In partial page write we don't update bufferram */ |
1906 | onenand_update_bufferram(mtd, to, !ret && !subpage); | 1964 | onenand_update_bufferram(mtd, to, !ret && !subpage); |
1907 | if (ret) { | 1965 | if (ret) { |
1908 | printk(KERN_ERR "onenand_write_ops_nolock: write failed %d\n", ret); | 1966 | printk(KERN_ERR "%s: write failed %d\n", |
1967 | __func__, ret); | ||
1909 | break; | 1968 | break; |
1910 | } | 1969 | } |
1911 | 1970 | ||
1912 | /* Only check verify write turn on */ | 1971 | /* Only check verify write turn on */ |
1913 | ret = onenand_verify(mtd, buf, to, thislen); | 1972 | ret = onenand_verify(mtd, buf, to, thislen); |
1914 | if (ret) { | 1973 | if (ret) { |
1915 | printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret); | 1974 | printk(KERN_ERR "%s: verify failed %d\n", |
1975 | __func__, ret); | ||
1916 | break; | 1976 | break; |
1917 | } | 1977 | } |
1918 | 1978 | ||
@@ -1968,7 +2028,8 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, | |||
1968 | 2028 | ||
1969 | to += ops->ooboffs; | 2029 | to += ops->ooboffs; |
1970 | 2030 | ||
1971 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_write_oob_nolock: to = 0x%08x, len = %i\n", (unsigned int) to, (int) len); | 2031 | DEBUG(MTD_DEBUG_LEVEL3, "%s: to = 0x%08x, len = %i\n", |
2032 | __func__, (unsigned int) to, (int) len); | ||
1972 | 2033 | ||
1973 | /* Initialize retlen, in case of early exit */ | 2034 | /* Initialize retlen, in case of early exit */ |
1974 | ops->oobretlen = 0; | 2035 | ops->oobretlen = 0; |
@@ -1981,14 +2042,15 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, | |||
1981 | column = to & (mtd->oobsize - 1); | 2042 | column = to & (mtd->oobsize - 1); |
1982 | 2043 | ||
1983 | if (unlikely(column >= oobsize)) { | 2044 | if (unlikely(column >= oobsize)) { |
1984 | printk(KERN_ERR "onenand_write_oob_nolock: Attempted to start write outside oob\n"); | 2045 | printk(KERN_ERR "%s: Attempted to start write outside oob\n", |
2046 | __func__); | ||
1985 | return -EINVAL; | 2047 | return -EINVAL; |
1986 | } | 2048 | } |
1987 | 2049 | ||
1988 | /* For compatibility with NAND: Do not allow write past end of page */ | 2050 | /* For compatibility with NAND: Do not allow write past end of page */ |
1989 | if (unlikely(column + len > oobsize)) { | 2051 | if (unlikely(column + len > oobsize)) { |
1990 | printk(KERN_ERR "onenand_write_oob_nolock: " | 2052 | printk(KERN_ERR "%s: Attempt to write past end of page\n", |
1991 | "Attempt to write past end of page\n"); | 2053 | __func__); |
1992 | return -EINVAL; | 2054 | return -EINVAL; |
1993 | } | 2055 | } |
1994 | 2056 | ||
@@ -1996,7 +2058,8 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, | |||
1996 | if (unlikely(to >= mtd->size || | 2058 | if (unlikely(to >= mtd->size || |
1997 | column + len > ((mtd->size >> this->page_shift) - | 2059 | column + len > ((mtd->size >> this->page_shift) - |
1998 | (to >> this->page_shift)) * oobsize)) { | 2060 | (to >> this->page_shift)) * oobsize)) { |
1999 | printk(KERN_ERR "onenand_write_oob_nolock: Attempted to write past end of device\n"); | 2061 | printk(KERN_ERR "%s: Attempted to write past end of device\n", |
2062 | __func__); | ||
2000 | return -EINVAL; | 2063 | return -EINVAL; |
2001 | } | 2064 | } |
2002 | 2065 | ||
@@ -2038,13 +2101,14 @@ static int onenand_write_oob_nolock(struct mtd_info *mtd, loff_t to, | |||
2038 | 2101 | ||
2039 | ret = this->wait(mtd, FL_WRITING); | 2102 | ret = this->wait(mtd, FL_WRITING); |
2040 | if (ret) { | 2103 | if (ret) { |
2041 | printk(KERN_ERR "onenand_write_oob_nolock: write failed %d\n", ret); | 2104 | printk(KERN_ERR "%s: write failed %d\n", __func__, ret); |
2042 | break; | 2105 | break; |
2043 | } | 2106 | } |
2044 | 2107 | ||
2045 | ret = onenand_verify_oob(mtd, oobbuf, to); | 2108 | ret = onenand_verify_oob(mtd, oobbuf, to); |
2046 | if (ret) { | 2109 | if (ret) { |
2047 | printk(KERN_ERR "onenand_write_oob_nolock: verify failed %d\n", ret); | 2110 | printk(KERN_ERR "%s: verify failed %d\n", |
2111 | __func__, ret); | ||
2048 | break; | 2112 | break; |
2049 | } | 2113 | } |
2050 | 2114 | ||
@@ -2140,78 +2204,186 @@ static int onenand_block_isbad_nolock(struct mtd_info *mtd, loff_t ofs, int allo | |||
2140 | return bbm->isbad_bbt(mtd, ofs, allowbbt); | 2204 | return bbm->isbad_bbt(mtd, ofs, allowbbt); |
2141 | } | 2205 | } |
2142 | 2206 | ||
2207 | |||
2208 | static int onenand_multiblock_erase_verify(struct mtd_info *mtd, | ||
2209 | struct erase_info *instr) | ||
2210 | { | ||
2211 | struct onenand_chip *this = mtd->priv; | ||
2212 | loff_t addr = instr->addr; | ||
2213 | int len = instr->len; | ||
2214 | unsigned int block_size = (1 << this->erase_shift); | ||
2215 | int ret = 0; | ||
2216 | |||
2217 | while (len) { | ||
2218 | this->command(mtd, ONENAND_CMD_ERASE_VERIFY, addr, block_size); | ||
2219 | ret = this->wait(mtd, FL_VERIFYING_ERASE); | ||
2220 | if (ret) { | ||
2221 | printk(KERN_ERR "%s: Failed verify, block %d\n", | ||
2222 | __func__, onenand_block(this, addr)); | ||
2223 | instr->state = MTD_ERASE_FAILED; | ||
2224 | instr->fail_addr = addr; | ||
2225 | return -1; | ||
2226 | } | ||
2227 | len -= block_size; | ||
2228 | addr += block_size; | ||
2229 | } | ||
2230 | return 0; | ||
2231 | } | ||
2232 | |||
2143 | /** | 2233 | /** |
2144 | * onenand_erase - [MTD Interface] erase block(s) | 2234 | * onenand_multiblock_erase - [Internal] erase block(s) using multiblock erase |
2145 | * @param mtd MTD device structure | 2235 | * @param mtd MTD device structure |
2146 | * @param instr erase instruction | 2236 | * @param instr erase instruction |
2237 | * @param region erase region | ||
2147 | * | 2238 | * |
2148 | * Erase one ore more blocks | 2239 | * Erase one or more blocks up to 64 block at a time |
2149 | */ | 2240 | */ |
2150 | static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) | 2241 | static int onenand_multiblock_erase(struct mtd_info *mtd, |
2242 | struct erase_info *instr, | ||
2243 | unsigned int block_size) | ||
2151 | { | 2244 | { |
2152 | struct onenand_chip *this = mtd->priv; | 2245 | struct onenand_chip *this = mtd->priv; |
2153 | unsigned int block_size; | ||
2154 | loff_t addr = instr->addr; | 2246 | loff_t addr = instr->addr; |
2155 | loff_t len = instr->len; | 2247 | int len = instr->len; |
2156 | int ret = 0, i; | 2248 | int eb_count = 0; |
2157 | struct mtd_erase_region_info *region = NULL; | 2249 | int ret = 0; |
2158 | loff_t region_end = 0; | 2250 | int bdry_block = 0; |
2159 | 2251 | ||
2160 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_erase: start = 0x%012llx, len = %llu\n", (unsigned long long) instr->addr, (unsigned long long) instr->len); | 2252 | instr->state = MTD_ERASING; |
2161 | 2253 | ||
2162 | /* Do not allow erase past end of device */ | 2254 | if (ONENAND_IS_DDP(this)) { |
2163 | if (unlikely((len + addr) > mtd->size)) { | 2255 | loff_t bdry_addr = this->chipsize >> 1; |
2164 | printk(KERN_ERR "onenand_erase: Erase past end of device\n"); | 2256 | if (addr < bdry_addr && (addr + len) > bdry_addr) |
2165 | return -EINVAL; | 2257 | bdry_block = bdry_addr >> this->erase_shift; |
2166 | } | 2258 | } |
2167 | 2259 | ||
2168 | if (FLEXONENAND(this)) { | 2260 | /* Pre-check bbs */ |
2169 | /* Find the eraseregion of this address */ | 2261 | while (len) { |
2170 | i = flexonenand_region(mtd, addr); | 2262 | /* Check if we have a bad block, we do not erase bad blocks */ |
2171 | region = &mtd->eraseregions[i]; | 2263 | if (onenand_block_isbad_nolock(mtd, addr, 0)) { |
2264 | printk(KERN_WARNING "%s: attempt to erase a bad block " | ||
2265 | "at addr 0x%012llx\n", | ||
2266 | __func__, (unsigned long long) addr); | ||
2267 | instr->state = MTD_ERASE_FAILED; | ||
2268 | return -EIO; | ||
2269 | } | ||
2270 | len -= block_size; | ||
2271 | addr += block_size; | ||
2272 | } | ||
2172 | 2273 | ||
2173 | block_size = region->erasesize; | 2274 | len = instr->len; |
2174 | region_end = region->offset + region->erasesize * region->numblocks; | 2275 | addr = instr->addr; |
2175 | 2276 | ||
2176 | /* Start address within region must align on block boundary. | 2277 | /* loop over 64 eb batches */ |
2177 | * Erase region's start offset is always block start address. | 2278 | while (len) { |
2178 | */ | 2279 | struct erase_info verify_instr = *instr; |
2179 | if (unlikely((addr - region->offset) & (block_size - 1))) { | 2280 | int max_eb_count = MB_ERASE_MAX_BLK_COUNT; |
2180 | printk(KERN_ERR "onenand_erase: Unaligned address\n"); | 2281 | |
2181 | return -EINVAL; | 2282 | verify_instr.addr = addr; |
2283 | verify_instr.len = 0; | ||
2284 | |||
2285 | /* do not cross chip boundary */ | ||
2286 | if (bdry_block) { | ||
2287 | int this_block = (addr >> this->erase_shift); | ||
2288 | |||
2289 | if (this_block < bdry_block) { | ||
2290 | max_eb_count = min(max_eb_count, | ||
2291 | (bdry_block - this_block)); | ||
2292 | } | ||
2182 | } | 2293 | } |
2183 | } else { | ||
2184 | block_size = 1 << this->erase_shift; | ||
2185 | 2294 | ||
2186 | /* Start address must align on block boundary */ | 2295 | eb_count = 0; |
2187 | if (unlikely(addr & (block_size - 1))) { | 2296 | |
2188 | printk(KERN_ERR "onenand_erase: Unaligned address\n"); | 2297 | while (len > block_size && eb_count < (max_eb_count - 1)) { |
2189 | return -EINVAL; | 2298 | this->command(mtd, ONENAND_CMD_MULTIBLOCK_ERASE, |
2299 | addr, block_size); | ||
2300 | onenand_invalidate_bufferram(mtd, addr, block_size); | ||
2301 | |||
2302 | ret = this->wait(mtd, FL_PREPARING_ERASE); | ||
2303 | if (ret) { | ||
2304 | printk(KERN_ERR "%s: Failed multiblock erase, " | ||
2305 | "block %d\n", __func__, | ||
2306 | onenand_block(this, addr)); | ||
2307 | instr->state = MTD_ERASE_FAILED; | ||
2308 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; | ||
2309 | return -EIO; | ||
2310 | } | ||
2311 | |||
2312 | len -= block_size; | ||
2313 | addr += block_size; | ||
2314 | eb_count++; | ||
2315 | } | ||
2316 | |||
2317 | /* last block of 64-eb series */ | ||
2318 | cond_resched(); | ||
2319 | this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); | ||
2320 | onenand_invalidate_bufferram(mtd, addr, block_size); | ||
2321 | |||
2322 | ret = this->wait(mtd, FL_ERASING); | ||
2323 | /* Check if it is write protected */ | ||
2324 | if (ret) { | ||
2325 | printk(KERN_ERR "%s: Failed erase, block %d\n", | ||
2326 | __func__, onenand_block(this, addr)); | ||
2327 | instr->state = MTD_ERASE_FAILED; | ||
2328 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; | ||
2329 | return -EIO; | ||
2330 | } | ||
2331 | |||
2332 | len -= block_size; | ||
2333 | addr += block_size; | ||
2334 | eb_count++; | ||
2335 | |||
2336 | /* verify */ | ||
2337 | verify_instr.len = eb_count * block_size; | ||
2338 | if (onenand_multiblock_erase_verify(mtd, &verify_instr)) { | ||
2339 | instr->state = verify_instr.state; | ||
2340 | instr->fail_addr = verify_instr.fail_addr; | ||
2341 | return -EIO; | ||
2190 | } | 2342 | } |
2191 | } | ||
2192 | 2343 | ||
2193 | /* Length must align on block boundary */ | ||
2194 | if (unlikely(len & (block_size - 1))) { | ||
2195 | printk(KERN_ERR "onenand_erase: Length not block aligned\n"); | ||
2196 | return -EINVAL; | ||
2197 | } | 2344 | } |
2345 | return 0; | ||
2346 | } | ||
2198 | 2347 | ||
2199 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; | ||
2200 | 2348 | ||
2201 | /* Grab the lock and see if the device is available */ | 2349 | /** |
2202 | onenand_get_device(mtd, FL_ERASING); | 2350 | * onenand_block_by_block_erase - [Internal] erase block(s) using regular erase |
2351 | * @param mtd MTD device structure | ||
2352 | * @param instr erase instruction | ||
2353 | * @param region erase region | ||
2354 | * @param block_size erase block size | ||
2355 | * | ||
2356 | * Erase one or more blocks one block at a time | ||
2357 | */ | ||
2358 | static int onenand_block_by_block_erase(struct mtd_info *mtd, | ||
2359 | struct erase_info *instr, | ||
2360 | struct mtd_erase_region_info *region, | ||
2361 | unsigned int block_size) | ||
2362 | { | ||
2363 | struct onenand_chip *this = mtd->priv; | ||
2364 | loff_t addr = instr->addr; | ||
2365 | int len = instr->len; | ||
2366 | loff_t region_end = 0; | ||
2367 | int ret = 0; | ||
2368 | |||
2369 | if (region) { | ||
2370 | /* region is set for Flex-OneNAND */ | ||
2371 | region_end = region->offset + region->erasesize * region->numblocks; | ||
2372 | } | ||
2203 | 2373 | ||
2204 | /* Loop through the blocks */ | ||
2205 | instr->state = MTD_ERASING; | 2374 | instr->state = MTD_ERASING; |
2206 | 2375 | ||
2376 | /* Loop through the blocks */ | ||
2207 | while (len) { | 2377 | while (len) { |
2208 | cond_resched(); | 2378 | cond_resched(); |
2209 | 2379 | ||
2210 | /* Check if we have a bad block, we do not erase bad blocks */ | 2380 | /* Check if we have a bad block, we do not erase bad blocks */ |
2211 | if (onenand_block_isbad_nolock(mtd, addr, 0)) { | 2381 | if (onenand_block_isbad_nolock(mtd, addr, 0)) { |
2212 | printk (KERN_WARNING "onenand_erase: attempt to erase a bad block at addr 0x%012llx\n", (unsigned long long) addr); | 2382 | printk(KERN_WARNING "%s: attempt to erase a bad block " |
2383 | "at addr 0x%012llx\n", | ||
2384 | __func__, (unsigned long long) addr); | ||
2213 | instr->state = MTD_ERASE_FAILED; | 2385 | instr->state = MTD_ERASE_FAILED; |
2214 | goto erase_exit; | 2386 | return -EIO; |
2215 | } | 2387 | } |
2216 | 2388 | ||
2217 | this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); | 2389 | this->command(mtd, ONENAND_CMD_ERASE, addr, block_size); |
@@ -2221,11 +2393,11 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
2221 | ret = this->wait(mtd, FL_ERASING); | 2393 | ret = this->wait(mtd, FL_ERASING); |
2222 | /* Check, if it is write protected */ | 2394 | /* Check, if it is write protected */ |
2223 | if (ret) { | 2395 | if (ret) { |
2224 | printk(KERN_ERR "onenand_erase: Failed erase, block %d\n", | 2396 | printk(KERN_ERR "%s: Failed erase, block %d\n", |
2225 | onenand_block(this, addr)); | 2397 | __func__, onenand_block(this, addr)); |
2226 | instr->state = MTD_ERASE_FAILED; | 2398 | instr->state = MTD_ERASE_FAILED; |
2227 | instr->fail_addr = addr; | 2399 | instr->fail_addr = addr; |
2228 | goto erase_exit; | 2400 | return -EIO; |
2229 | } | 2401 | } |
2230 | 2402 | ||
2231 | len -= block_size; | 2403 | len -= block_size; |
@@ -2241,25 +2413,88 @@ static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) | |||
2241 | 2413 | ||
2242 | if (len & (block_size - 1)) { | 2414 | if (len & (block_size - 1)) { |
2243 | /* FIXME: This should be handled at MTD partitioning level. */ | 2415 | /* FIXME: This should be handled at MTD partitioning level. */ |
2244 | printk(KERN_ERR "onenand_erase: Unaligned address\n"); | 2416 | printk(KERN_ERR "%s: Unaligned address\n", |
2245 | goto erase_exit; | 2417 | __func__); |
2418 | return -EIO; | ||
2246 | } | 2419 | } |
2247 | } | 2420 | } |
2421 | } | ||
2422 | return 0; | ||
2423 | } | ||
2424 | |||
2425 | /** | ||
2426 | * onenand_erase - [MTD Interface] erase block(s) | ||
2427 | * @param mtd MTD device structure | ||
2428 | * @param instr erase instruction | ||
2429 | * | ||
2430 | * Erase one or more blocks | ||
2431 | */ | ||
2432 | static int onenand_erase(struct mtd_info *mtd, struct erase_info *instr) | ||
2433 | { | ||
2434 | struct onenand_chip *this = mtd->priv; | ||
2435 | unsigned int block_size; | ||
2436 | loff_t addr = instr->addr; | ||
2437 | loff_t len = instr->len; | ||
2438 | int ret = 0; | ||
2439 | struct mtd_erase_region_info *region = NULL; | ||
2440 | loff_t region_offset = 0; | ||
2441 | |||
2442 | DEBUG(MTD_DEBUG_LEVEL3, "%s: start=0x%012llx, len=%llu\n", __func__, | ||
2443 | (unsigned long long) instr->addr, (unsigned long long) instr->len); | ||
2444 | |||
2445 | /* Do not allow erase past end of device */ | ||
2446 | if (unlikely((len + addr) > mtd->size)) { | ||
2447 | printk(KERN_ERR "%s: Erase past end of device\n", __func__); | ||
2448 | return -EINVAL; | ||
2449 | } | ||
2450 | |||
2451 | if (FLEXONENAND(this)) { | ||
2452 | /* Find the eraseregion of this address */ | ||
2453 | int i = flexonenand_region(mtd, addr); | ||
2454 | |||
2455 | region = &mtd->eraseregions[i]; | ||
2456 | block_size = region->erasesize; | ||
2457 | |||
2458 | /* Start address within region must align on block boundary. | ||
2459 | * Erase region's start offset is always block start address. | ||
2460 | */ | ||
2461 | region_offset = region->offset; | ||
2462 | } else | ||
2463 | block_size = 1 << this->erase_shift; | ||
2464 | |||
2465 | /* Start address must align on block boundary */ | ||
2466 | if (unlikely((addr - region_offset) & (block_size - 1))) { | ||
2467 | printk(KERN_ERR "%s: Unaligned address\n", __func__); | ||
2468 | return -EINVAL; | ||
2469 | } | ||
2248 | 2470 | ||
2471 | /* Length must align on block boundary */ | ||
2472 | if (unlikely(len & (block_size - 1))) { | ||
2473 | printk(KERN_ERR "%s: Length not block aligned\n", __func__); | ||
2474 | return -EINVAL; | ||
2249 | } | 2475 | } |
2250 | 2476 | ||
2251 | instr->state = MTD_ERASE_DONE; | 2477 | instr->fail_addr = MTD_FAIL_ADDR_UNKNOWN; |
2252 | 2478 | ||
2253 | erase_exit: | 2479 | /* Grab the lock and see if the device is available */ |
2480 | onenand_get_device(mtd, FL_ERASING); | ||
2254 | 2481 | ||
2255 | ret = instr->state == MTD_ERASE_DONE ? 0 : -EIO; | 2482 | if (region || instr->len < MB_ERASE_MIN_BLK_COUNT * block_size) { |
2483 | /* region is set for Flex-OneNAND (no mb erase) */ | ||
2484 | ret = onenand_block_by_block_erase(mtd, instr, | ||
2485 | region, block_size); | ||
2486 | } else { | ||
2487 | ret = onenand_multiblock_erase(mtd, instr, block_size); | ||
2488 | } | ||
2256 | 2489 | ||
2257 | /* Deselect and wake up anyone waiting on the device */ | 2490 | /* Deselect and wake up anyone waiting on the device */ |
2258 | onenand_release_device(mtd); | 2491 | onenand_release_device(mtd); |
2259 | 2492 | ||
2260 | /* Do call back function */ | 2493 | /* Do call back function */ |
2261 | if (!ret) | 2494 | if (!ret) { |
2495 | instr->state = MTD_ERASE_DONE; | ||
2262 | mtd_erase_callback(instr); | 2496 | mtd_erase_callback(instr); |
2497 | } | ||
2263 | 2498 | ||
2264 | return ret; | 2499 | return ret; |
2265 | } | 2500 | } |
@@ -2272,7 +2507,7 @@ erase_exit: | |||
2272 | */ | 2507 | */ |
2273 | static void onenand_sync(struct mtd_info *mtd) | 2508 | static void onenand_sync(struct mtd_info *mtd) |
2274 | { | 2509 | { |
2275 | DEBUG(MTD_DEBUG_LEVEL3, "onenand_sync: called\n"); | 2510 | DEBUG(MTD_DEBUG_LEVEL3, "%s: called\n", __func__); |
2276 | 2511 | ||
2277 | /* Grab the lock and see if the device is available */ | 2512 | /* Grab the lock and see if the device is available */ |
2278 | onenand_get_device(mtd, FL_SYNCING); | 2513 | onenand_get_device(mtd, FL_SYNCING); |
@@ -2406,7 +2641,8 @@ static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int | |||
2406 | /* Check lock status */ | 2641 | /* Check lock status */ |
2407 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); | 2642 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
2408 | if (!(status & wp_status_mask)) | 2643 | if (!(status & wp_status_mask)) |
2409 | printk(KERN_ERR "wp status = 0x%x\n", status); | 2644 | printk(KERN_ERR "%s: wp status = 0x%x\n", |
2645 | __func__, status); | ||
2410 | 2646 | ||
2411 | return 0; | 2647 | return 0; |
2412 | } | 2648 | } |
@@ -2435,7 +2671,8 @@ static int onenand_do_lock_cmd(struct mtd_info *mtd, loff_t ofs, size_t len, int | |||
2435 | /* Check lock status */ | 2671 | /* Check lock status */ |
2436 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); | 2672 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
2437 | if (!(status & wp_status_mask)) | 2673 | if (!(status & wp_status_mask)) |
2438 | printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); | 2674 | printk(KERN_ERR "%s: block = %d, wp status = 0x%x\n", |
2675 | __func__, block, status); | ||
2439 | } | 2676 | } |
2440 | 2677 | ||
2441 | return 0; | 2678 | return 0; |
@@ -2502,7 +2739,8 @@ static int onenand_check_lock_status(struct onenand_chip *this) | |||
2502 | /* Check lock status */ | 2739 | /* Check lock status */ |
2503 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); | 2740 | status = this->read_word(this->base + ONENAND_REG_WP_STATUS); |
2504 | if (!(status & ONENAND_WP_US)) { | 2741 | if (!(status & ONENAND_WP_US)) { |
2505 | printk(KERN_ERR "block = %d, wp status = 0x%x\n", block, status); | 2742 | printk(KERN_ERR "%s: block = %d, wp status = 0x%x\n", |
2743 | __func__, block, status); | ||
2506 | return 0; | 2744 | return 0; |
2507 | } | 2745 | } |
2508 | } | 2746 | } |
@@ -2557,6 +2795,208 @@ static void onenand_unlock_all(struct mtd_info *mtd) | |||
2557 | 2795 | ||
2558 | #ifdef CONFIG_MTD_ONENAND_OTP | 2796 | #ifdef CONFIG_MTD_ONENAND_OTP |
2559 | 2797 | ||
2798 | /** | ||
2799 | * onenand_otp_command - Send OTP specific command to OneNAND device | ||
2800 | * @param mtd MTD device structure | ||
2801 | * @param cmd the command to be sent | ||
2802 | * @param addr offset to read from or write to | ||
2803 | * @param len number of bytes to read or write | ||
2804 | */ | ||
2805 | static int onenand_otp_command(struct mtd_info *mtd, int cmd, loff_t addr, | ||
2806 | size_t len) | ||
2807 | { | ||
2808 | struct onenand_chip *this = mtd->priv; | ||
2809 | int value, block, page; | ||
2810 | |||
2811 | /* Address translation */ | ||
2812 | switch (cmd) { | ||
2813 | case ONENAND_CMD_OTP_ACCESS: | ||
2814 | block = (int) (addr >> this->erase_shift); | ||
2815 | page = -1; | ||
2816 | break; | ||
2817 | |||
2818 | default: | ||
2819 | block = (int) (addr >> this->erase_shift); | ||
2820 | page = (int) (addr >> this->page_shift); | ||
2821 | |||
2822 | if (ONENAND_IS_2PLANE(this)) { | ||
2823 | /* Make the even block number */ | ||
2824 | block &= ~1; | ||
2825 | /* Is it the odd plane? */ | ||
2826 | if (addr & this->writesize) | ||
2827 | block++; | ||
2828 | page >>= 1; | ||
2829 | } | ||
2830 | page &= this->page_mask; | ||
2831 | break; | ||
2832 | } | ||
2833 | |||
2834 | if (block != -1) { | ||
2835 | /* Write 'DFS, FBA' of Flash */ | ||
2836 | value = onenand_block_address(this, block); | ||
2837 | this->write_word(value, this->base + | ||
2838 | ONENAND_REG_START_ADDRESS1); | ||
2839 | } | ||
2840 | |||
2841 | if (page != -1) { | ||
2842 | /* Now we use page size operation */ | ||
2843 | int sectors = 4, count = 4; | ||
2844 | int dataram; | ||
2845 | |||
2846 | switch (cmd) { | ||
2847 | default: | ||
2848 | if (ONENAND_IS_2PLANE(this) && cmd == ONENAND_CMD_PROG) | ||
2849 | cmd = ONENAND_CMD_2X_PROG; | ||
2850 | dataram = ONENAND_CURRENT_BUFFERRAM(this); | ||
2851 | break; | ||
2852 | } | ||
2853 | |||
2854 | /* Write 'FPA, FSA' of Flash */ | ||
2855 | value = onenand_page_address(page, sectors); | ||
2856 | this->write_word(value, this->base + | ||
2857 | ONENAND_REG_START_ADDRESS8); | ||
2858 | |||
2859 | /* Write 'BSA, BSC' of DataRAM */ | ||
2860 | value = onenand_buffer_address(dataram, sectors, count); | ||
2861 | this->write_word(value, this->base + ONENAND_REG_START_BUFFER); | ||
2862 | } | ||
2863 | |||
2864 | /* Interrupt clear */ | ||
2865 | this->write_word(ONENAND_INT_CLEAR, this->base + ONENAND_REG_INTERRUPT); | ||
2866 | |||
2867 | /* Write command */ | ||
2868 | this->write_word(cmd, this->base + ONENAND_REG_COMMAND); | ||
2869 | |||
2870 | return 0; | ||
2871 | } | ||
2872 | |||
2873 | /** | ||
2874 | * onenand_otp_write_oob_nolock - [Internal] OneNAND write out-of-band, specific to OTP | ||
2875 | * @param mtd MTD device structure | ||
2876 | * @param to offset to write to | ||
2877 | * @param len number of bytes to write | ||
2878 | * @param retlen pointer to variable to store the number of written bytes | ||
2879 | * @param buf the data to write | ||
2880 | * | ||
2881 | * OneNAND write out-of-band only for OTP | ||
2882 | */ | ||
2883 | static int onenand_otp_write_oob_nolock(struct mtd_info *mtd, loff_t to, | ||
2884 | struct mtd_oob_ops *ops) | ||
2885 | { | ||
2886 | struct onenand_chip *this = mtd->priv; | ||
2887 | int column, ret = 0, oobsize; | ||
2888 | int written = 0; | ||
2889 | u_char *oobbuf; | ||
2890 | size_t len = ops->ooblen; | ||
2891 | const u_char *buf = ops->oobbuf; | ||
2892 | int block, value, status; | ||
2893 | |||
2894 | to += ops->ooboffs; | ||
2895 | |||
2896 | /* Initialize retlen, in case of early exit */ | ||
2897 | ops->oobretlen = 0; | ||
2898 | |||
2899 | oobsize = mtd->oobsize; | ||
2900 | |||
2901 | column = to & (mtd->oobsize - 1); | ||
2902 | |||
2903 | oobbuf = this->oob_buf; | ||
2904 | |||
2905 | /* Loop until all data write */ | ||
2906 | while (written < len) { | ||
2907 | int thislen = min_t(int, oobsize, len - written); | ||
2908 | |||
2909 | cond_resched(); | ||
2910 | |||
2911 | block = (int) (to >> this->erase_shift); | ||
2912 | /* | ||
2913 | * Write 'DFS, FBA' of Flash | ||
2914 | * Add: F100h DQ=DFS, FBA | ||
2915 | */ | ||
2916 | |||
2917 | value = onenand_block_address(this, block); | ||
2918 | this->write_word(value, this->base + | ||
2919 | ONENAND_REG_START_ADDRESS1); | ||
2920 | |||
2921 | /* | ||
2922 | * Select DataRAM for DDP | ||
2923 | * Add: F101h DQ=DBS | ||
2924 | */ | ||
2925 | |||
2926 | value = onenand_bufferram_address(this, block); | ||
2927 | this->write_word(value, this->base + | ||
2928 | ONENAND_REG_START_ADDRESS2); | ||
2929 | ONENAND_SET_NEXT_BUFFERRAM(this); | ||
2930 | |||
2931 | /* | ||
2932 | * Enter OTP access mode | ||
2933 | */ | ||
2934 | this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); | ||
2935 | this->wait(mtd, FL_OTPING); | ||
2936 | |||
2937 | /* We send data to spare ram with oobsize | ||
2938 | * to prevent byte access */ | ||
2939 | memcpy(oobbuf + column, buf, thislen); | ||
2940 | |||
2941 | /* | ||
2942 | * Write Data into DataRAM | ||
2943 | * Add: 8th Word | ||
2944 | * in sector0/spare/page0 | ||
2945 | * DQ=XXFCh | ||
2946 | */ | ||
2947 | this->write_bufferram(mtd, ONENAND_SPARERAM, | ||
2948 | oobbuf, 0, mtd->oobsize); | ||
2949 | |||
2950 | onenand_otp_command(mtd, ONENAND_CMD_PROGOOB, to, mtd->oobsize); | ||
2951 | onenand_update_bufferram(mtd, to, 0); | ||
2952 | if (ONENAND_IS_2PLANE(this)) { | ||
2953 | ONENAND_SET_BUFFERRAM1(this); | ||
2954 | onenand_update_bufferram(mtd, to + this->writesize, 0); | ||
2955 | } | ||
2956 | |||
2957 | ret = this->wait(mtd, FL_WRITING); | ||
2958 | if (ret) { | ||
2959 | printk(KERN_ERR "%s: write failed %d\n", __func__, ret); | ||
2960 | break; | ||
2961 | } | ||
2962 | |||
2963 | /* Exit OTP access mode */ | ||
2964 | this->command(mtd, ONENAND_CMD_RESET, 0, 0); | ||
2965 | this->wait(mtd, FL_RESETING); | ||
2966 | |||
2967 | status = this->read_word(this->base + ONENAND_REG_CTRL_STATUS); | ||
2968 | status &= 0x60; | ||
2969 | |||
2970 | if (status == 0x60) { | ||
2971 | printk(KERN_DEBUG "\nBLOCK\tSTATUS\n"); | ||
2972 | printk(KERN_DEBUG "1st Block\tLOCKED\n"); | ||
2973 | printk(KERN_DEBUG "OTP Block\tLOCKED\n"); | ||
2974 | } else if (status == 0x20) { | ||
2975 | printk(KERN_DEBUG "\nBLOCK\tSTATUS\n"); | ||
2976 | printk(KERN_DEBUG "1st Block\tLOCKED\n"); | ||
2977 | printk(KERN_DEBUG "OTP Block\tUN-LOCKED\n"); | ||
2978 | } else if (status == 0x40) { | ||
2979 | printk(KERN_DEBUG "\nBLOCK\tSTATUS\n"); | ||
2980 | printk(KERN_DEBUG "1st Block\tUN-LOCKED\n"); | ||
2981 | printk(KERN_DEBUG "OTP Block\tLOCKED\n"); | ||
2982 | } else { | ||
2983 | printk(KERN_DEBUG "Reboot to check\n"); | ||
2984 | } | ||
2985 | |||
2986 | written += thislen; | ||
2987 | if (written == len) | ||
2988 | break; | ||
2989 | |||
2990 | to += mtd->writesize; | ||
2991 | buf += thislen; | ||
2992 | column = 0; | ||
2993 | } | ||
2994 | |||
2995 | ops->oobretlen = written; | ||
2996 | |||
2997 | return ret; | ||
2998 | } | ||
2999 | |||
2560 | /* Internal OTP operation */ | 3000 | /* Internal OTP operation */ |
2561 | typedef int (*otp_op_t)(struct mtd_info *mtd, loff_t form, size_t len, | 3001 | typedef int (*otp_op_t)(struct mtd_info *mtd, loff_t form, size_t len, |
2562 | size_t *retlen, u_char *buf); | 3002 | size_t *retlen, u_char *buf); |
@@ -2659,11 +3099,11 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len, | |||
2659 | struct mtd_oob_ops ops; | 3099 | struct mtd_oob_ops ops; |
2660 | int ret; | 3100 | int ret; |
2661 | 3101 | ||
2662 | /* Enter OTP access mode */ | ||
2663 | this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); | ||
2664 | this->wait(mtd, FL_OTPING); | ||
2665 | |||
2666 | if (FLEXONENAND(this)) { | 3102 | if (FLEXONENAND(this)) { |
3103 | |||
3104 | /* Enter OTP access mode */ | ||
3105 | this->command(mtd, ONENAND_CMD_OTP_ACCESS, 0, 0); | ||
3106 | this->wait(mtd, FL_OTPING); | ||
2667 | /* | 3107 | /* |
2668 | * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of | 3108 | * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of |
2669 | * main area of page 49. | 3109 | * main area of page 49. |
@@ -2674,19 +3114,19 @@ static int do_otp_lock(struct mtd_info *mtd, loff_t from, size_t len, | |||
2674 | ops.oobbuf = NULL; | 3114 | ops.oobbuf = NULL; |
2675 | ret = onenand_write_ops_nolock(mtd, mtd->writesize * 49, &ops); | 3115 | ret = onenand_write_ops_nolock(mtd, mtd->writesize * 49, &ops); |
2676 | *retlen = ops.retlen; | 3116 | *retlen = ops.retlen; |
3117 | |||
3118 | /* Exit OTP access mode */ | ||
3119 | this->command(mtd, ONENAND_CMD_RESET, 0, 0); | ||
3120 | this->wait(mtd, FL_RESETING); | ||
2677 | } else { | 3121 | } else { |
2678 | ops.mode = MTD_OOB_PLACE; | 3122 | ops.mode = MTD_OOB_PLACE; |
2679 | ops.ooblen = len; | 3123 | ops.ooblen = len; |
2680 | ops.oobbuf = buf; | 3124 | ops.oobbuf = buf; |
2681 | ops.ooboffs = 0; | 3125 | ops.ooboffs = 0; |
2682 | ret = onenand_write_oob_nolock(mtd, from, &ops); | 3126 | ret = onenand_otp_write_oob_nolock(mtd, from, &ops); |
2683 | *retlen = ops.oobretlen; | 3127 | *retlen = ops.oobretlen; |
2684 | } | 3128 | } |
2685 | 3129 | ||
2686 | /* Exit OTP access mode */ | ||
2687 | this->command(mtd, ONENAND_CMD_RESET, 0, 0); | ||
2688 | this->wait(mtd, FL_RESETING); | ||
2689 | |||
2690 | return ret; | 3130 | return ret; |
2691 | } | 3131 | } |
2692 | 3132 | ||
@@ -2717,16 +3157,21 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, | |||
2717 | if (density < ONENAND_DEVICE_DENSITY_512Mb) | 3157 | if (density < ONENAND_DEVICE_DENSITY_512Mb) |
2718 | otp_pages = 20; | 3158 | otp_pages = 20; |
2719 | else | 3159 | else |
2720 | otp_pages = 10; | 3160 | otp_pages = 50; |
2721 | 3161 | ||
2722 | if (mode == MTD_OTP_FACTORY) { | 3162 | if (mode == MTD_OTP_FACTORY) { |
2723 | from += mtd->writesize * otp_pages; | 3163 | from += mtd->writesize * otp_pages; |
2724 | otp_pages = 64 - otp_pages; | 3164 | otp_pages = ONENAND_PAGES_PER_BLOCK - otp_pages; |
2725 | } | 3165 | } |
2726 | 3166 | ||
2727 | /* Check User/Factory boundary */ | 3167 | /* Check User/Factory boundary */ |
2728 | if (((mtd->writesize * otp_pages) - (from + len)) < 0) | 3168 | if (mode == MTD_OTP_USER) { |
2729 | return 0; | 3169 | if (mtd->writesize * otp_pages < from + len) |
3170 | return 0; | ||
3171 | } else { | ||
3172 | if (mtd->writesize * otp_pages < len) | ||
3173 | return 0; | ||
3174 | } | ||
2730 | 3175 | ||
2731 | onenand_get_device(mtd, FL_OTPING); | 3176 | onenand_get_device(mtd, FL_OTPING); |
2732 | while (len > 0 && otp_pages > 0) { | 3177 | while (len > 0 && otp_pages > 0) { |
@@ -2749,13 +3194,12 @@ static int onenand_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, | |||
2749 | *retlen += sizeof(struct otp_info); | 3194 | *retlen += sizeof(struct otp_info); |
2750 | } else { | 3195 | } else { |
2751 | size_t tmp_retlen; | 3196 | size_t tmp_retlen; |
2752 | int size = len; | ||
2753 | 3197 | ||
2754 | ret = action(mtd, from, len, &tmp_retlen, buf); | 3198 | ret = action(mtd, from, len, &tmp_retlen, buf); |
2755 | 3199 | ||
2756 | buf += size; | 3200 | buf += tmp_retlen; |
2757 | len -= size; | 3201 | len -= tmp_retlen; |
2758 | *retlen += size; | 3202 | *retlen += tmp_retlen; |
2759 | 3203 | ||
2760 | if (ret) | 3204 | if (ret) |
2761 | break; | 3205 | break; |
@@ -2868,21 +3312,11 @@ static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, | |||
2868 | u_char *buf = FLEXONENAND(this) ? this->page_buf : this->oob_buf; | 3312 | u_char *buf = FLEXONENAND(this) ? this->page_buf : this->oob_buf; |
2869 | size_t retlen; | 3313 | size_t retlen; |
2870 | int ret; | 3314 | int ret; |
3315 | unsigned int otp_lock_offset = ONENAND_OTP_LOCK_OFFSET; | ||
2871 | 3316 | ||
2872 | memset(buf, 0xff, FLEXONENAND(this) ? this->writesize | 3317 | memset(buf, 0xff, FLEXONENAND(this) ? this->writesize |
2873 | : mtd->oobsize); | 3318 | : mtd->oobsize); |
2874 | /* | 3319 | /* |
2875 | * Note: OTP lock operation | ||
2876 | * OTP block : 0xXXFC | ||
2877 | * 1st block : 0xXXF3 (If chip support) | ||
2878 | * Both : 0xXXF0 (If chip support) | ||
2879 | */ | ||
2880 | if (FLEXONENAND(this)) | ||
2881 | buf[FLEXONENAND_OTP_LOCK_OFFSET] = 0xFC; | ||
2882 | else | ||
2883 | buf[ONENAND_OTP_LOCK_OFFSET] = 0xFC; | ||
2884 | |||
2885 | /* | ||
2886 | * Write lock mark to 8th word of sector0 of page0 of the spare0. | 3320 | * Write lock mark to 8th word of sector0 of page0 of the spare0. |
2887 | * We write 16 bytes spare area instead of 2 bytes. | 3321 | * We write 16 bytes spare area instead of 2 bytes. |
2888 | * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of | 3322 | * For Flex-OneNAND, we write lock mark to 1st word of sector 4 of |
@@ -2892,10 +3326,30 @@ static int onenand_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, | |||
2892 | from = 0; | 3326 | from = 0; |
2893 | len = FLEXONENAND(this) ? mtd->writesize : 16; | 3327 | len = FLEXONENAND(this) ? mtd->writesize : 16; |
2894 | 3328 | ||
3329 | /* | ||
3330 | * Note: OTP lock operation | ||
3331 | * OTP block : 0xXXFC XX 1111 1100 | ||
3332 | * 1st block : 0xXXF3 (If chip support) XX 1111 0011 | ||
3333 | * Both : 0xXXF0 (If chip support) XX 1111 0000 | ||
3334 | */ | ||
3335 | if (FLEXONENAND(this)) | ||
3336 | otp_lock_offset = FLEXONENAND_OTP_LOCK_OFFSET; | ||
3337 | |||
3338 | /* ONENAND_OTP_AREA | ONENAND_OTP_BLOCK0 | ONENAND_OTP_AREA_BLOCK0 */ | ||
3339 | if (otp == 1) | ||
3340 | buf[otp_lock_offset] = 0xFC; | ||
3341 | else if (otp == 2) | ||
3342 | buf[otp_lock_offset] = 0xF3; | ||
3343 | else if (otp == 3) | ||
3344 | buf[otp_lock_offset] = 0xF0; | ||
3345 | else if (otp != 0) | ||
3346 | printk(KERN_DEBUG "[OneNAND] Invalid option selected for OTP\n"); | ||
3347 | |||
2895 | ret = onenand_otp_walk(mtd, from, len, &retlen, buf, do_otp_lock, MTD_OTP_USER); | 3348 | ret = onenand_otp_walk(mtd, from, len, &retlen, buf, do_otp_lock, MTD_OTP_USER); |
2896 | 3349 | ||
2897 | return ret ? : retlen; | 3350 | return ret ? : retlen; |
2898 | } | 3351 | } |
3352 | |||
2899 | #endif /* CONFIG_MTD_ONENAND_OTP */ | 3353 | #endif /* CONFIG_MTD_ONENAND_OTP */ |
2900 | 3354 | ||
2901 | /** | 3355 | /** |
@@ -3172,7 +3626,8 @@ static int flexonenand_check_blocks_erased(struct mtd_info *mtd, int start, int | |||
3172 | break; | 3626 | break; |
3173 | 3627 | ||
3174 | if (i != mtd->oobsize) { | 3628 | if (i != mtd->oobsize) { |
3175 | printk(KERN_WARNING "Block %d not erased.\n", block); | 3629 | printk(KERN_WARNING "%s: Block %d not erased.\n", |
3630 | __func__, block); | ||
3176 | return 1; | 3631 | return 1; |
3177 | } | 3632 | } |
3178 | } | 3633 | } |
@@ -3204,8 +3659,8 @@ int flexonenand_set_boundary(struct mtd_info *mtd, int die, | |||
3204 | blksperdie >>= ONENAND_IS_DDP(this) ? 1 : 0; | 3659 | blksperdie >>= ONENAND_IS_DDP(this) ? 1 : 0; |
3205 | 3660 | ||
3206 | if (boundary >= blksperdie) { | 3661 | if (boundary >= blksperdie) { |
3207 | printk(KERN_ERR "flexonenand_set_boundary: Invalid boundary value. " | 3662 | printk(KERN_ERR "%s: Invalid boundary value. " |
3208 | "Boundary not changed.\n"); | 3663 | "Boundary not changed.\n", __func__); |
3209 | return -EINVAL; | 3664 | return -EINVAL; |
3210 | } | 3665 | } |
3211 | 3666 | ||
@@ -3214,7 +3669,8 @@ int flexonenand_set_boundary(struct mtd_info *mtd, int die, | |||
3214 | new = boundary + (die * this->density_mask); | 3669 | new = boundary + (die * this->density_mask); |
3215 | ret = flexonenand_check_blocks_erased(mtd, min(old, new) + 1, max(old, new)); | 3670 | ret = flexonenand_check_blocks_erased(mtd, min(old, new) + 1, max(old, new)); |
3216 | if (ret) { | 3671 | if (ret) { |
3217 | printk(KERN_ERR "flexonenand_set_boundary: Please erase blocks before boundary change\n"); | 3672 | printk(KERN_ERR "%s: Please erase blocks " |
3673 | "before boundary change\n", __func__); | ||
3218 | return ret; | 3674 | return ret; |
3219 | } | 3675 | } |
3220 | 3676 | ||
@@ -3227,12 +3683,12 @@ int flexonenand_set_boundary(struct mtd_info *mtd, int die, | |||
3227 | 3683 | ||
3228 | thisboundary = this->read_word(this->base + ONENAND_DATARAM); | 3684 | thisboundary = this->read_word(this->base + ONENAND_DATARAM); |
3229 | if ((thisboundary >> FLEXONENAND_PI_UNLOCK_SHIFT) != 3) { | 3685 | if ((thisboundary >> FLEXONENAND_PI_UNLOCK_SHIFT) != 3) { |
3230 | printk(KERN_ERR "flexonenand_set_boundary: boundary locked\n"); | 3686 | printk(KERN_ERR "%s: boundary locked\n", __func__); |
3231 | ret = 1; | 3687 | ret = 1; |
3232 | goto out; | 3688 | goto out; |
3233 | } | 3689 | } |
3234 | 3690 | ||
3235 | printk(KERN_INFO "flexonenand_set_boundary: Changing die %d boundary: %d%s\n", | 3691 | printk(KERN_INFO "Changing die %d boundary: %d%s\n", |
3236 | die, boundary, lock ? "(Locked)" : "(Unlocked)"); | 3692 | die, boundary, lock ? "(Locked)" : "(Unlocked)"); |
3237 | 3693 | ||
3238 | addr = die ? this->diesize[0] : 0; | 3694 | addr = die ? this->diesize[0] : 0; |
@@ -3243,7 +3699,8 @@ int flexonenand_set_boundary(struct mtd_info *mtd, int die, | |||
3243 | this->command(mtd, ONENAND_CMD_ERASE, addr, 0); | 3699 | this->command(mtd, ONENAND_CMD_ERASE, addr, 0); |
3244 | ret = this->wait(mtd, FL_ERASING); | 3700 | ret = this->wait(mtd, FL_ERASING); |
3245 | if (ret) { | 3701 | if (ret) { |
3246 | printk(KERN_ERR "flexonenand_set_boundary: Failed PI erase for Die %d\n", die); | 3702 | printk(KERN_ERR "%s: Failed PI erase for Die %d\n", |
3703 | __func__, die); | ||
3247 | goto out; | 3704 | goto out; |
3248 | } | 3705 | } |
3249 | 3706 | ||
@@ -3251,7 +3708,8 @@ int flexonenand_set_boundary(struct mtd_info *mtd, int die, | |||
3251 | this->command(mtd, ONENAND_CMD_PROG, addr, 0); | 3708 | this->command(mtd, ONENAND_CMD_PROG, addr, 0); |
3252 | ret = this->wait(mtd, FL_WRITING); | 3709 | ret = this->wait(mtd, FL_WRITING); |
3253 | if (ret) { | 3710 | if (ret) { |
3254 | printk(KERN_ERR "flexonenand_set_boundary: Failed PI write for Die %d\n", die); | 3711 | printk(KERN_ERR "%s: Failed PI write for Die %d\n", |
3712 | __func__, die); | ||
3255 | goto out; | 3713 | goto out; |
3256 | } | 3714 | } |
3257 | 3715 | ||
@@ -3408,8 +3866,8 @@ static void onenand_resume(struct mtd_info *mtd) | |||
3408 | if (this->state == FL_PM_SUSPENDED) | 3866 | if (this->state == FL_PM_SUSPENDED) |
3409 | onenand_release_device(mtd); | 3867 | onenand_release_device(mtd); |
3410 | else | 3868 | else |
3411 | printk(KERN_ERR "resume() called for the chip which is not" | 3869 | printk(KERN_ERR "%s: resume() called for the chip which is not " |
3412 | "in suspended state\n"); | 3870 | "in suspended state\n", __func__); |
3413 | } | 3871 | } |
3414 | 3872 | ||
3415 | /** | 3873 | /** |
@@ -3464,7 +3922,8 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) | |||
3464 | if (!this->page_buf) { | 3922 | if (!this->page_buf) { |
3465 | this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); | 3923 | this->page_buf = kzalloc(mtd->writesize, GFP_KERNEL); |
3466 | if (!this->page_buf) { | 3924 | if (!this->page_buf) { |
3467 | printk(KERN_ERR "onenand_scan(): Can't allocate page_buf\n"); | 3925 | printk(KERN_ERR "%s: Can't allocate page_buf\n", |
3926 | __func__); | ||
3468 | return -ENOMEM; | 3927 | return -ENOMEM; |
3469 | } | 3928 | } |
3470 | this->options |= ONENAND_PAGEBUF_ALLOC; | 3929 | this->options |= ONENAND_PAGEBUF_ALLOC; |
@@ -3472,7 +3931,8 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) | |||
3472 | if (!this->oob_buf) { | 3931 | if (!this->oob_buf) { |
3473 | this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); | 3932 | this->oob_buf = kzalloc(mtd->oobsize, GFP_KERNEL); |
3474 | if (!this->oob_buf) { | 3933 | if (!this->oob_buf) { |
3475 | printk(KERN_ERR "onenand_scan(): Can't allocate oob_buf\n"); | 3934 | printk(KERN_ERR "%s: Can't allocate oob_buf\n", |
3935 | __func__); | ||
3476 | if (this->options & ONENAND_PAGEBUF_ALLOC) { | 3936 | if (this->options & ONENAND_PAGEBUF_ALLOC) { |
3477 | this->options &= ~ONENAND_PAGEBUF_ALLOC; | 3937 | this->options &= ~ONENAND_PAGEBUF_ALLOC; |
3478 | kfree(this->page_buf); | 3938 | kfree(this->page_buf); |
@@ -3505,8 +3965,8 @@ int onenand_scan(struct mtd_info *mtd, int maxchips) | |||
3505 | break; | 3965 | break; |
3506 | 3966 | ||
3507 | default: | 3967 | default: |
3508 | printk(KERN_WARNING "No OOB scheme defined for oobsize %d\n", | 3968 | printk(KERN_WARNING "%s: No OOB scheme defined for oobsize %d\n", |
3509 | mtd->oobsize); | 3969 | __func__, mtd->oobsize); |
3510 | mtd->subpage_sft = 0; | 3970 | mtd->subpage_sft = 0; |
3511 | /* To prevent kernel oops */ | 3971 | /* To prevent kernel oops */ |
3512 | this->ecclayout = &onenand_oob_32; | 3972 | this->ecclayout = &onenand_oob_32; |
diff --git a/drivers/mtd/onenand/onenand_sim.c b/drivers/mtd/onenand/onenand_sim.c index f6e3c8aebd3a..8b246061d511 100644 --- a/drivers/mtd/onenand/onenand_sim.c +++ b/drivers/mtd/onenand/onenand_sim.c | |||
@@ -16,6 +16,7 @@ | |||
16 | */ | 16 | */ |
17 | 17 | ||
18 | #include <linux/kernel.h> | 18 | #include <linux/kernel.h> |
19 | #include <linux/slab.h> | ||
19 | #include <linux/module.h> | 20 | #include <linux/module.h> |
20 | #include <linux/init.h> | 21 | #include <linux/init.h> |
21 | #include <linux/vmalloc.h> | 22 | #include <linux/vmalloc.h> |
diff --git a/drivers/mtd/tests/Makefile b/drivers/mtd/tests/Makefile index c1d501335006..b44dcab940d8 100644 --- a/drivers/mtd/tests/Makefile +++ b/drivers/mtd/tests/Makefile | |||
@@ -5,3 +5,4 @@ obj-$(CONFIG_MTD_TESTS) += mtd_speedtest.o | |||
5 | obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o | 5 | obj-$(CONFIG_MTD_TESTS) += mtd_stresstest.o |
6 | obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o | 6 | obj-$(CONFIG_MTD_TESTS) += mtd_subpagetest.o |
7 | obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o | 7 | obj-$(CONFIG_MTD_TESTS) += mtd_torturetest.o |
8 | obj-$(CONFIG_MTD_TESTS) += mtd_nandecctest.o | ||
diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c new file mode 100644 index 000000000000..70d6d7d0d656 --- /dev/null +++ b/drivers/mtd/tests/mtd_nandecctest.c | |||
@@ -0,0 +1,86 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/module.h> | ||
3 | #include <linux/list.h> | ||
4 | #include <linux/random.h> | ||
5 | #include <linux/string.h> | ||
6 | #include <linux/bitops.h> | ||
7 | #include <linux/jiffies.h> | ||
8 | #include <linux/mtd/nand_ecc.h> | ||
9 | |||
10 | #if defined(CONFIG_MTD_NAND) || defined(CONFIG_MTD_NAND_MODULE) | ||
11 | |||
12 | static void inject_single_bit_error(void *data, size_t size) | ||
13 | { | ||
14 | unsigned long offset = random32() % (size * BITS_PER_BYTE); | ||
15 | |||
16 | __change_bit(offset, data); | ||
17 | } | ||
18 | |||
19 | static unsigned char data[512]; | ||
20 | static unsigned char error_data[512]; | ||
21 | |||
22 | static int nand_ecc_test(const size_t size) | ||
23 | { | ||
24 | unsigned char code[3]; | ||
25 | unsigned char error_code[3]; | ||
26 | char testname[30]; | ||
27 | |||
28 | BUG_ON(sizeof(data) < size); | ||
29 | |||
30 | sprintf(testname, "nand-ecc-%zu", size); | ||
31 | |||
32 | get_random_bytes(data, size); | ||
33 | |||
34 | memcpy(error_data, data, size); | ||
35 | inject_single_bit_error(error_data, size); | ||
36 | |||
37 | __nand_calculate_ecc(data, size, code); | ||
38 | __nand_calculate_ecc(error_data, size, error_code); | ||
39 | __nand_correct_data(error_data, code, error_code, size); | ||
40 | |||
41 | if (!memcmp(data, error_data, size)) { | ||
42 | printk(KERN_INFO "mtd_nandecctest: ok - %s\n", testname); | ||
43 | return 0; | ||
44 | } | ||
45 | |||
46 | printk(KERN_ERR "mtd_nandecctest: not ok - %s\n", testname); | ||
47 | |||
48 | printk(KERN_DEBUG "hexdump of data:\n"); | ||
49 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4, | ||
50 | data, size, false); | ||
51 | printk(KERN_DEBUG "hexdump of error data:\n"); | ||
52 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 16, 4, | ||
53 | error_data, size, false); | ||
54 | |||
55 | return -1; | ||
56 | } | ||
57 | |||
58 | #else | ||
59 | |||
60 | static int nand_ecc_test(const size_t size) | ||
61 | { | ||
62 | return 0; | ||
63 | } | ||
64 | |||
65 | #endif | ||
66 | |||
67 | static int __init ecc_test_init(void) | ||
68 | { | ||
69 | srandom32(jiffies); | ||
70 | |||
71 | nand_ecc_test(256); | ||
72 | nand_ecc_test(512); | ||
73 | |||
74 | return 0; | ||
75 | } | ||
76 | |||
77 | static void __exit ecc_test_exit(void) | ||
78 | { | ||
79 | } | ||
80 | |||
81 | module_init(ecc_test_init); | ||
82 | module_exit(ecc_test_exit); | ||
83 | |||
84 | MODULE_DESCRIPTION("NAND ECC function test module"); | ||
85 | MODULE_AUTHOR("Akinobu Mita"); | ||
86 | MODULE_LICENSE("GPL"); | ||
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 5553cd4eab20..dec92ae6111a 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/mtd/mtd.h> | 27 | #include <linux/mtd/mtd.h> |
28 | #include <linux/slab.h> | ||
28 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
29 | 30 | ||
30 | #define PRINT_PREF KERN_INFO "mtd_oobtest: " | 31 | #define PRINT_PREF KERN_INFO "mtd_oobtest: " |
@@ -343,7 +344,6 @@ static int scan_for_bad_eraseblocks(void) | |||
343 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 344 | printk(PRINT_PREF "error: cannot allocate memory\n"); |
344 | return -ENOMEM; | 345 | return -ENOMEM; |
345 | } | 346 | } |
346 | memset(bbt, 0 , ebcnt); | ||
347 | 347 | ||
348 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); | 348 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); |
349 | for (i = 0; i < ebcnt; ++i) { | 349 | for (i = 0; i < ebcnt; ++i) { |
@@ -392,7 +392,6 @@ static int __init mtd_oobtest_init(void) | |||
392 | mtd->writesize, ebcnt, pgcnt, mtd->oobsize); | 392 | mtd->writesize, ebcnt, pgcnt, mtd->oobsize); |
393 | 393 | ||
394 | err = -ENOMEM; | 394 | err = -ENOMEM; |
395 | mtd->erasesize = mtd->erasesize; | ||
396 | readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); | 395 | readbuf = kmalloc(mtd->erasesize, GFP_KERNEL); |
397 | if (!readbuf) { | 396 | if (!readbuf) { |
398 | printk(PRINT_PREF "error: cannot allocate memory\n"); | 397 | printk(PRINT_PREF "error: cannot allocate memory\n"); |
@@ -476,18 +475,10 @@ static int __init mtd_oobtest_init(void) | |||
476 | use_len_max = mtd->ecclayout->oobavail; | 475 | use_len_max = mtd->ecclayout->oobavail; |
477 | vary_offset = 1; | 476 | vary_offset = 1; |
478 | simple_srand(5); | 477 | simple_srand(5); |
479 | printk(PRINT_PREF "writing OOBs of whole device\n"); | 478 | |
480 | for (i = 0; i < ebcnt; ++i) { | 479 | err = write_whole_device(); |
481 | if (bbt[i]) | 480 | if (err) |
482 | continue; | 481 | goto out; |
483 | err = write_eraseblock(i); | ||
484 | if (err) | ||
485 | goto out; | ||
486 | if (i % 256 == 0) | ||
487 | printk(PRINT_PREF "written up to eraseblock %u\n", i); | ||
488 | cond_resched(); | ||
489 | } | ||
490 | printk(PRINT_PREF "written %u eraseblocks\n", i); | ||
491 | 482 | ||
492 | /* Check all eraseblocks */ | 483 | /* Check all eraseblocks */ |
493 | use_offset = 0; | 484 | use_offset = 0; |
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 103cac480fee..921a85df9196 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include <linux/moduleparam.h> | 25 | #include <linux/moduleparam.h> |
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/mtd/mtd.h> | 27 | #include <linux/mtd/mtd.h> |
28 | #include <linux/slab.h> | ||
28 | #include <linux/sched.h> | 29 | #include <linux/sched.h> |
29 | 30 | ||
30 | #define PRINT_PREF KERN_INFO "mtd_pagetest: " | 31 | #define PRINT_PREF KERN_INFO "mtd_pagetest: " |
@@ -523,6 +524,7 @@ static int __init mtd_pagetest_init(void) | |||
523 | do_div(tmp, mtd->erasesize); | 524 | do_div(tmp, mtd->erasesize); |
524 | ebcnt = tmp; | 525 | ebcnt = tmp; |
525 | pgcnt = mtd->erasesize / mtd->writesize; | 526 | pgcnt = mtd->erasesize / mtd->writesize; |
527 | pgsize = mtd->writesize; | ||
526 | 528 | ||
527 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " | 529 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " |
528 | "page size %u, count of eraseblocks %u, pages per " | 530 | "page size %u, count of eraseblocks %u, pages per " |
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 79fc4530987b..7107fccbc7de 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/moduleparam.h> | 24 | #include <linux/moduleparam.h> |
25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
26 | #include <linux/mtd/mtd.h> | 26 | #include <linux/mtd/mtd.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
28 | 29 | ||
29 | #define PRINT_PREF KERN_INFO "mtd_readtest: " | 30 | #define PRINT_PREF KERN_INFO "mtd_readtest: " |
@@ -147,6 +148,10 @@ static int scan_for_bad_eraseblocks(void) | |||
147 | } | 148 | } |
148 | memset(bbt, 0 , ebcnt); | 149 | memset(bbt, 0 , ebcnt); |
149 | 150 | ||
151 | /* NOR flash does not implement block_isbad */ | ||
152 | if (mtd->block_isbad == NULL) | ||
153 | return 0; | ||
154 | |||
150 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); | 155 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); |
151 | for (i = 0; i < ebcnt; ++i) { | 156 | for (i = 0; i < ebcnt; ++i) { |
152 | bbt[i] = is_block_bad(i) ? 1 : 0; | 157 | bbt[i] = is_block_bad(i) ? 1 : 0; |
@@ -184,7 +189,7 @@ static int __init mtd_readtest_init(void) | |||
184 | tmp = mtd->size; | 189 | tmp = mtd->size; |
185 | do_div(tmp, mtd->erasesize); | 190 | do_div(tmp, mtd->erasesize); |
186 | ebcnt = tmp; | 191 | ebcnt = tmp; |
187 | pgcnt = mtd->erasesize / mtd->writesize; | 192 | pgcnt = mtd->erasesize / pgsize; |
188 | 193 | ||
189 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " | 194 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " |
190 | "page size %u, count of eraseblocks %u, pages per " | 195 | "page size %u, count of eraseblocks %u, pages per " |
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index 141363a7e805..56ca62bb96bf 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/moduleparam.h> | 24 | #include <linux/moduleparam.h> |
25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
26 | #include <linux/mtd/mtd.h> | 26 | #include <linux/mtd/mtd.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
28 | 29 | ||
29 | #define PRINT_PREF KERN_INFO "mtd_speedtest: " | 30 | #define PRINT_PREF KERN_INFO "mtd_speedtest: " |
@@ -301,6 +302,10 @@ static int scan_for_bad_eraseblocks(void) | |||
301 | } | 302 | } |
302 | memset(bbt, 0 , ebcnt); | 303 | memset(bbt, 0 , ebcnt); |
303 | 304 | ||
305 | /* NOR flash does not implement block_isbad */ | ||
306 | if (mtd->block_isbad == NULL) | ||
307 | goto out; | ||
308 | |||
304 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); | 309 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); |
305 | for (i = 0; i < ebcnt; ++i) { | 310 | for (i = 0; i < ebcnt; ++i) { |
306 | bbt[i] = is_block_bad(i) ? 1 : 0; | 311 | bbt[i] = is_block_bad(i) ? 1 : 0; |
@@ -309,6 +314,7 @@ static int scan_for_bad_eraseblocks(void) | |||
309 | cond_resched(); | 314 | cond_resched(); |
310 | } | 315 | } |
311 | printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); | 316 | printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); |
317 | out: | ||
312 | goodebcnt = ebcnt - bad; | 318 | goodebcnt = ebcnt - bad; |
313 | return 0; | 319 | return 0; |
314 | } | 320 | } |
@@ -340,7 +346,7 @@ static int __init mtd_speedtest_init(void) | |||
340 | tmp = mtd->size; | 346 | tmp = mtd->size; |
341 | do_div(tmp, mtd->erasesize); | 347 | do_div(tmp, mtd->erasesize); |
342 | ebcnt = tmp; | 348 | ebcnt = tmp; |
343 | pgcnt = mtd->erasesize / mtd->writesize; | 349 | pgcnt = mtd->erasesize / pgsize; |
344 | 350 | ||
345 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " | 351 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " |
346 | "page size %u, count of eraseblocks %u, pages per " | 352 | "page size %u, count of eraseblocks %u, pages per " |
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 63920476b57a..3854afec56d0 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/moduleparam.h> | 24 | #include <linux/moduleparam.h> |
25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
26 | #include <linux/mtd/mtd.h> | 26 | #include <linux/mtd/mtd.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
28 | #include <linux/vmalloc.h> | 29 | #include <linux/vmalloc.h> |
29 | 30 | ||
@@ -227,6 +228,10 @@ static int scan_for_bad_eraseblocks(void) | |||
227 | } | 228 | } |
228 | memset(bbt, 0 , ebcnt); | 229 | memset(bbt, 0 , ebcnt); |
229 | 230 | ||
231 | /* NOR flash does not implement block_isbad */ | ||
232 | if (mtd->block_isbad == NULL) | ||
233 | return 0; | ||
234 | |||
230 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); | 235 | printk(PRINT_PREF "scanning for bad eraseblocks\n"); |
231 | for (i = 0; i < ebcnt; ++i) { | 236 | for (i = 0; i < ebcnt; ++i) { |
232 | bbt[i] = is_block_bad(i) ? 1 : 0; | 237 | bbt[i] = is_block_bad(i) ? 1 : 0; |
@@ -265,7 +270,7 @@ static int __init mtd_stresstest_init(void) | |||
265 | tmp = mtd->size; | 270 | tmp = mtd->size; |
266 | do_div(tmp, mtd->erasesize); | 271 | do_div(tmp, mtd->erasesize); |
267 | ebcnt = tmp; | 272 | ebcnt = tmp; |
268 | pgcnt = mtd->erasesize / mtd->writesize; | 273 | pgcnt = mtd->erasesize / pgsize; |
269 | 274 | ||
270 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " | 275 | printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " |
271 | "page size %u, count of eraseblocks %u, pages per " | 276 | "page size %u, count of eraseblocks %u, pages per " |
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 5b889724268e..700237a3d120 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/moduleparam.h> | 24 | #include <linux/moduleparam.h> |
25 | #include <linux/err.h> | 25 | #include <linux/err.h> |
26 | #include <linux/mtd/mtd.h> | 26 | #include <linux/mtd/mtd.h> |
27 | #include <linux/slab.h> | ||
27 | #include <linux/sched.h> | 28 | #include <linux/sched.h> |
28 | 29 | ||
29 | #define PRINT_PREF KERN_INFO "mtd_subpagetest: " | 30 | #define PRINT_PREF KERN_INFO "mtd_subpagetest: " |
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 631a0ab3a33c..5c6c3d248901 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c | |||
@@ -28,6 +28,7 @@ | |||
28 | #include <linux/moduleparam.h> | 28 | #include <linux/moduleparam.h> |
29 | #include <linux/err.h> | 29 | #include <linux/err.h> |
30 | #include <linux/mtd/mtd.h> | 30 | #include <linux/mtd/mtd.h> |
31 | #include <linux/slab.h> | ||
31 | #include <linux/sched.h> | 32 | #include <linux/sched.h> |
32 | 33 | ||
33 | #define PRINT_PREF KERN_INFO "mtd_torturetest: " | 34 | #define PRINT_PREF KERN_INFO "mtd_torturetest: " |
diff --git a/drivers/mtd/ubi/Kconfig b/drivers/mtd/ubi/Kconfig index b1cd7a1a2191..0a8c7ea764ae 100644 --- a/drivers/mtd/ubi/Kconfig +++ b/drivers/mtd/ubi/Kconfig | |||
@@ -1,5 +1,3 @@ | |||
1 | # drivers/mtd/ubi/Kconfig | ||
2 | |||
3 | menu "UBI - Unsorted block images" | 1 | menu "UBI - Unsorted block images" |
4 | depends on MTD | 2 | depends on MTD |
5 | 3 | ||
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 14cec04c34f9..55c726dde942 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c | |||
@@ -37,12 +37,14 @@ | |||
37 | #include <linux/module.h> | 37 | #include <linux/module.h> |
38 | #include <linux/moduleparam.h> | 38 | #include <linux/moduleparam.h> |
39 | #include <linux/stringify.h> | 39 | #include <linux/stringify.h> |
40 | #include <linux/namei.h> | ||
40 | #include <linux/stat.h> | 41 | #include <linux/stat.h> |
41 | #include <linux/miscdevice.h> | 42 | #include <linux/miscdevice.h> |
42 | #include <linux/log2.h> | 43 | #include <linux/log2.h> |
43 | #include <linux/kthread.h> | 44 | #include <linux/kthread.h> |
44 | #include <linux/reboot.h> | 45 | #include <linux/reboot.h> |
45 | #include <linux/kernel.h> | 46 | #include <linux/kernel.h> |
47 | #include <linux/slab.h> | ||
46 | #include "ubi.h" | 48 | #include "ubi.h" |
47 | 49 | ||
48 | /* Maximum length of the 'mtd=' parameter */ | 50 | /* Maximum length of the 'mtd=' parameter */ |
@@ -50,7 +52,8 @@ | |||
50 | 52 | ||
51 | /** | 53 | /** |
52 | * struct mtd_dev_param - MTD device parameter description data structure. | 54 | * struct mtd_dev_param - MTD device parameter description data structure. |
53 | * @name: MTD device name or number string | 55 | * @name: MTD character device node path, MTD device name, or MTD device number |
56 | * string | ||
54 | * @vid_hdr_offs: VID header offset | 57 | * @vid_hdr_offs: VID header offset |
55 | */ | 58 | */ |
56 | struct mtd_dev_param { | 59 | struct mtd_dev_param { |
@@ -59,10 +62,10 @@ struct mtd_dev_param { | |||
59 | }; | 62 | }; |
60 | 63 | ||
61 | /* Numbers of elements set in the @mtd_dev_param array */ | 64 | /* Numbers of elements set in the @mtd_dev_param array */ |
62 | static int mtd_devs; | 65 | static int __initdata mtd_devs; |
63 | 66 | ||
64 | /* MTD devices specification parameters */ | 67 | /* MTD devices specification parameters */ |
65 | static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; | 68 | static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES]; |
66 | 69 | ||
67 | /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ | 70 | /* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ |
68 | struct class *ubi_class; | 71 | struct class *ubi_class; |
@@ -87,7 +90,8 @@ DEFINE_MUTEX(ubi_devices_mutex); | |||
87 | static DEFINE_SPINLOCK(ubi_devices_lock); | 90 | static DEFINE_SPINLOCK(ubi_devices_lock); |
88 | 91 | ||
89 | /* "Show" method for files in '/<sysfs>/class/ubi/' */ | 92 | /* "Show" method for files in '/<sysfs>/class/ubi/' */ |
90 | static ssize_t ubi_version_show(struct class *class, char *buf) | 93 | static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr, |
94 | char *buf) | ||
91 | { | 95 | { |
92 | return sprintf(buf, "%d\n", UBI_VERSION); | 96 | return sprintf(buf, "%d\n", UBI_VERSION); |
93 | } | 97 | } |
@@ -363,11 +367,13 @@ static void dev_release(struct device *dev) | |||
363 | /** | 367 | /** |
364 | * ubi_sysfs_init - initialize sysfs for an UBI device. | 368 | * ubi_sysfs_init - initialize sysfs for an UBI device. |
365 | * @ubi: UBI device description object | 369 | * @ubi: UBI device description object |
370 | * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was | ||
371 | * taken | ||
366 | * | 372 | * |
367 | * This function returns zero in case of success and a negative error code in | 373 | * This function returns zero in case of success and a negative error code in |
368 | * case of failure. | 374 | * case of failure. |
369 | */ | 375 | */ |
370 | static int ubi_sysfs_init(struct ubi_device *ubi) | 376 | static int ubi_sysfs_init(struct ubi_device *ubi, int *ref) |
371 | { | 377 | { |
372 | int err; | 378 | int err; |
373 | 379 | ||
@@ -379,6 +385,7 @@ static int ubi_sysfs_init(struct ubi_device *ubi) | |||
379 | if (err) | 385 | if (err) |
380 | return err; | 386 | return err; |
381 | 387 | ||
388 | *ref = 1; | ||
382 | err = device_create_file(&ubi->dev, &dev_eraseblock_size); | 389 | err = device_create_file(&ubi->dev, &dev_eraseblock_size); |
383 | if (err) | 390 | if (err) |
384 | return err; | 391 | return err; |
@@ -434,7 +441,7 @@ static void ubi_sysfs_close(struct ubi_device *ubi) | |||
434 | } | 441 | } |
435 | 442 | ||
436 | /** | 443 | /** |
437 | * kill_volumes - destroy all volumes. | 444 | * kill_volumes - destroy all user volumes. |
438 | * @ubi: UBI device description object | 445 | * @ubi: UBI device description object |
439 | */ | 446 | */ |
440 | static void kill_volumes(struct ubi_device *ubi) | 447 | static void kill_volumes(struct ubi_device *ubi) |
@@ -447,36 +454,29 @@ static void kill_volumes(struct ubi_device *ubi) | |||
447 | } | 454 | } |
448 | 455 | ||
449 | /** | 456 | /** |
450 | * free_user_volumes - free all user volumes. | ||
451 | * @ubi: UBI device description object | ||
452 | * | ||
453 | * Normally the volumes are freed at the release function of the volume device | ||
454 | * objects. However, on error paths the volumes have to be freed before the | ||
455 | * device objects have been initialized. | ||
456 | */ | ||
457 | static void free_user_volumes(struct ubi_device *ubi) | ||
458 | { | ||
459 | int i; | ||
460 | |||
461 | for (i = 0; i < ubi->vtbl_slots; i++) | ||
462 | if (ubi->volumes[i]) { | ||
463 | kfree(ubi->volumes[i]->eba_tbl); | ||
464 | kfree(ubi->volumes[i]); | ||
465 | } | ||
466 | } | ||
467 | |||
468 | /** | ||
469 | * uif_init - initialize user interfaces for an UBI device. | 457 | * uif_init - initialize user interfaces for an UBI device. |
470 | * @ubi: UBI device description object | 458 | * @ubi: UBI device description object |
459 | * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was | ||
460 | * taken, otherwise set to %0 | ||
461 | * | ||
462 | * This function initializes various user interfaces for an UBI device. If the | ||
463 | * initialization fails at an early stage, this function frees all the | ||
464 | * resources it allocated, returns an error, and @ref is set to %0. However, | ||
465 | * if the initialization fails after the UBI device was registered in the | ||
466 | * driver core subsystem, this function takes a reference to @ubi->dev, because | ||
467 | * otherwise the release function ('dev_release()') would free whole @ubi | ||
468 | * object. The @ref argument is set to %1 in this case. The caller has to put | ||
469 | * this reference. | ||
471 | * | 470 | * |
472 | * This function returns zero in case of success and a negative error code in | 471 | * This function returns zero in case of success and a negative error code in |
473 | * case of failure. Note, this function destroys all volumes if it fails. | 472 | * case of failure. |
474 | */ | 473 | */ |
475 | static int uif_init(struct ubi_device *ubi) | 474 | static int uif_init(struct ubi_device *ubi, int *ref) |
476 | { | 475 | { |
477 | int i, err; | 476 | int i, err; |
478 | dev_t dev; | 477 | dev_t dev; |
479 | 478 | ||
479 | *ref = 0; | ||
480 | sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); | 480 | sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); |
481 | 481 | ||
482 | /* | 482 | /* |
@@ -504,7 +504,7 @@ static int uif_init(struct ubi_device *ubi) | |||
504 | goto out_unreg; | 504 | goto out_unreg; |
505 | } | 505 | } |
506 | 506 | ||
507 | err = ubi_sysfs_init(ubi); | 507 | err = ubi_sysfs_init(ubi, ref); |
508 | if (err) | 508 | if (err) |
509 | goto out_sysfs; | 509 | goto out_sysfs; |
510 | 510 | ||
@@ -522,6 +522,8 @@ static int uif_init(struct ubi_device *ubi) | |||
522 | out_volumes: | 522 | out_volumes: |
523 | kill_volumes(ubi); | 523 | kill_volumes(ubi); |
524 | out_sysfs: | 524 | out_sysfs: |
525 | if (*ref) | ||
526 | get_device(&ubi->dev); | ||
525 | ubi_sysfs_close(ubi); | 527 | ubi_sysfs_close(ubi); |
526 | cdev_del(&ubi->cdev); | 528 | cdev_del(&ubi->cdev); |
527 | out_unreg: | 529 | out_unreg: |
@@ -875,7 +877,7 @@ static int ubi_reboot_notifier(struct notifier_block *n, unsigned long state, | |||
875 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | 877 | int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) |
876 | { | 878 | { |
877 | struct ubi_device *ubi; | 879 | struct ubi_device *ubi; |
878 | int i, err, do_free = 1; | 880 | int i, err, ref = 0; |
879 | 881 | ||
880 | /* | 882 | /* |
881 | * Check if we already have the same MTD device attached. | 883 | * Check if we already have the same MTD device attached. |
@@ -975,9 +977,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
975 | goto out_detach; | 977 | goto out_detach; |
976 | } | 978 | } |
977 | 979 | ||
978 | err = uif_init(ubi); | 980 | err = uif_init(ubi, &ref); |
979 | if (err) | 981 | if (err) |
980 | goto out_nofree; | 982 | goto out_detach; |
981 | 983 | ||
982 | ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); | 984 | ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); |
983 | if (IS_ERR(ubi->bgt_thread)) { | 985 | if (IS_ERR(ubi->bgt_thread)) { |
@@ -1025,12 +1027,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) | |||
1025 | 1027 | ||
1026 | out_uif: | 1028 | out_uif: |
1027 | uif_close(ubi); | 1029 | uif_close(ubi); |
1028 | out_nofree: | ||
1029 | do_free = 0; | ||
1030 | out_detach: | 1030 | out_detach: |
1031 | ubi_wl_close(ubi); | 1031 | ubi_wl_close(ubi); |
1032 | if (do_free) | ||
1033 | free_user_volumes(ubi); | ||
1034 | free_internal_volumes(ubi); | 1032 | free_internal_volumes(ubi); |
1035 | vfree(ubi->vtbl); | 1033 | vfree(ubi->vtbl); |
1036 | out_free: | 1034 | out_free: |
@@ -1039,7 +1037,10 @@ out_free: | |||
1039 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 1037 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
1040 | vfree(ubi->dbg_peb_buf); | 1038 | vfree(ubi->dbg_peb_buf); |
1041 | #endif | 1039 | #endif |
1042 | kfree(ubi); | 1040 | if (ref) |
1041 | put_device(&ubi->dev); | ||
1042 | else | ||
1043 | kfree(ubi); | ||
1043 | return err; | 1044 | return err; |
1044 | } | 1045 | } |
1045 | 1046 | ||
@@ -1096,7 +1097,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1096 | 1097 | ||
1097 | /* | 1098 | /* |
1098 | * Get a reference to the device in order to prevent 'dev_release()' | 1099 | * Get a reference to the device in order to prevent 'dev_release()' |
1099 | * from freeing @ubi object. | 1100 | * from freeing the @ubi object. |
1100 | */ | 1101 | */ |
1101 | get_device(&ubi->dev); | 1102 | get_device(&ubi->dev); |
1102 | 1103 | ||
@@ -1116,13 +1117,50 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) | |||
1116 | } | 1117 | } |
1117 | 1118 | ||
1118 | /** | 1119 | /** |
1119 | * find_mtd_device - open an MTD device by its name or number. | 1120 | * open_mtd_by_chdev - open an MTD device by its character device node path. |
1120 | * @mtd_dev: name or number of the device | 1121 | * @mtd_dev: MTD character device node path |
1122 | * | ||
1123 | * This helper function opens an MTD device by its character node device path. | ||
1124 | * Returns MTD device description object in case of success and a negative | ||
1125 | * error code in case of failure. | ||
1126 | */ | ||
1127 | static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) | ||
1128 | { | ||
1129 | int err, major, minor, mode; | ||
1130 | struct path path; | ||
1131 | |||
1132 | /* Probably this is an MTD character device node path */ | ||
1133 | err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path); | ||
1134 | if (err) | ||
1135 | return ERR_PTR(err); | ||
1136 | |||
1137 | /* MTD device number is defined by the major / minor numbers */ | ||
1138 | major = imajor(path.dentry->d_inode); | ||
1139 | minor = iminor(path.dentry->d_inode); | ||
1140 | mode = path.dentry->d_inode->i_mode; | ||
1141 | path_put(&path); | ||
1142 | if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode)) | ||
1143 | return ERR_PTR(-EINVAL); | ||
1144 | |||
1145 | if (minor & 1) | ||
1146 | /* | ||
1147 | * Just do not think the "/dev/mtdrX" devices support is need, | ||
1148 | * so do not support them to avoid doing extra work. | ||
1149 | */ | ||
1150 | return ERR_PTR(-EINVAL); | ||
1151 | |||
1152 | return get_mtd_device(NULL, minor / 2); | ||
1153 | } | ||
1154 | |||
1155 | /** | ||
1156 | * open_mtd_device - open MTD device by name, character device path, or number. | ||
1157 | * @mtd_dev: name, character device node path, or MTD device device number | ||
1121 | * | 1158 | * |
1122 | * This function tries to open and MTD device described by @mtd_dev string, | 1159 | * This function tries to open and MTD device described by @mtd_dev string, |
1123 | * which is first treated as an ASCII number, and if it is not true, it is | 1160 | * which is first treated as ASCII MTD device number, and if it is not true, it |
1124 | * treated as MTD device name. Returns MTD device description object in case of | 1161 | * is treated as MTD device name, and if that is also not true, it is treated |
1125 | * success and a negative error code in case of failure. | 1162 | * as MTD character device node path. Returns MTD device description object in |
1163 | * case of success and a negative error code in case of failure. | ||
1126 | */ | 1164 | */ |
1127 | static struct mtd_info * __init open_mtd_device(const char *mtd_dev) | 1165 | static struct mtd_info * __init open_mtd_device(const char *mtd_dev) |
1128 | { | 1166 | { |
@@ -1137,6 +1175,9 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev) | |||
1137 | * MTD device name. | 1175 | * MTD device name. |
1138 | */ | 1176 | */ |
1139 | mtd = get_mtd_device_nm(mtd_dev); | 1177 | mtd = get_mtd_device_nm(mtd_dev); |
1178 | if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV) | ||
1179 | /* Probably this is an MTD character device node path */ | ||
1180 | mtd = open_mtd_by_chdev(mtd_dev); | ||
1140 | } else | 1181 | } else |
1141 | mtd = get_mtd_device(NULL, mtd_num); | 1182 | mtd = get_mtd_device(NULL, mtd_num); |
1142 | 1183 | ||
@@ -1352,13 +1393,15 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp) | |||
1352 | 1393 | ||
1353 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); | 1394 | module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); |
1354 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " | 1395 | MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " |
1355 | "mtd=<name|num>[,<vid_hdr_offs>].\n" | 1396 | "mtd=<name|num|path>[,<vid_hdr_offs>].\n" |
1356 | "Multiple \"mtd\" parameters may be specified.\n" | 1397 | "Multiple \"mtd\" parameters may be specified.\n" |
1357 | "MTD devices may be specified by their number or name.\n" | 1398 | "MTD devices may be specified by their number, name, or " |
1399 | "path to the MTD character device node.\n" | ||
1358 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID " | 1400 | "Optional \"vid_hdr_offs\" parameter specifies UBI VID " |
1359 | "header position and data starting position to be used " | 1401 | "header position to be used by UBI.\n" |
1360 | "by UBI.\n" | 1402 | "Example 1: mtd=/dev/mtd0 - attach MTD device " |
1361 | "Example: mtd=content,1984 mtd=4 - attach MTD device" | 1403 | "/dev/mtd0.\n" |
1404 | "Example 2: mtd=content,1984 mtd=4 - attach MTD device " | ||
1362 | "with name \"content\" using VID header offset 1984, and " | 1405 | "with name \"content\" using VID header offset 1984, and " |
1363 | "MTD device number 4 with default VID header offset."); | 1406 | "MTD device number 4 with default VID header offset."); |
1364 | 1407 | ||
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c index f237ddbb2713..72ebb3f06b86 100644 --- a/drivers/mtd/ubi/cdev.c +++ b/drivers/mtd/ubi/cdev.c | |||
@@ -37,6 +37,7 @@ | |||
37 | 37 | ||
38 | #include <linux/module.h> | 38 | #include <linux/module.h> |
39 | #include <linux/stat.h> | 39 | #include <linux/stat.h> |
40 | #include <linux/slab.h> | ||
40 | #include <linux/ioctl.h> | 41 | #include <linux/ioctl.h> |
41 | #include <linux/capability.h> | 42 | #include <linux/capability.h> |
42 | #include <linux/uaccess.h> | 43 | #include <linux/uaccess.h> |
@@ -853,7 +854,6 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd, | |||
853 | break; | 854 | break; |
854 | } | 855 | } |
855 | 856 | ||
856 | req.name[req.name_len] = '\0'; | ||
857 | err = verify_mkvol_req(ubi, &req); | 857 | err = verify_mkvol_req(ubi, &req); |
858 | if (err) | 858 | if (err) |
859 | break; | 859 | break; |
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h index f30bcb372c05..17a107129726 100644 --- a/drivers/mtd/ubi/debug.h +++ b/drivers/mtd/ubi/debug.h | |||
@@ -96,8 +96,11 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len); | |||
96 | 96 | ||
97 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 97 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
98 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); | 98 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); |
99 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | ||
100 | int offset, int len); | ||
99 | #else | 101 | #else |
100 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 | 102 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 |
103 | #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0 | ||
101 | #endif | 104 | #endif |
102 | 105 | ||
103 | #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT | 106 | #ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT |
@@ -176,6 +179,7 @@ static inline int ubi_dbg_is_erase_failure(void) | |||
176 | #define ubi_dbg_is_write_failure() 0 | 179 | #define ubi_dbg_is_write_failure() 0 |
177 | #define ubi_dbg_is_erase_failure() 0 | 180 | #define ubi_dbg_is_erase_failure() 0 |
178 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 | 181 | #define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 |
182 | #define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0 | ||
179 | 183 | ||
180 | #endif /* !CONFIG_MTD_UBI_DEBUG */ | 184 | #endif /* !CONFIG_MTD_UBI_DEBUG */ |
181 | #endif /* !__UBI_DEBUG_H__ */ | 185 | #endif /* !__UBI_DEBUG_H__ */ |
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c index b5e478fa2661..9aa81584c8a2 100644 --- a/drivers/mtd/ubi/gluebi.c +++ b/drivers/mtd/ubi/gluebi.c | |||
@@ -31,6 +31,7 @@ | |||
31 | 31 | ||
32 | #include <linux/err.h> | 32 | #include <linux/err.h> |
33 | #include <linux/list.h> | 33 | #include <linux/list.h> |
34 | #include <linux/slab.h> | ||
34 | #include <linux/sched.h> | 35 | #include <linux/sched.h> |
35 | #include <linux/math64.h> | 36 | #include <linux/math64.h> |
36 | #include <linux/module.h> | 37 | #include <linux/module.h> |
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 8aa51e7a6a7d..533b1a4b9af1 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c | |||
@@ -88,6 +88,7 @@ | |||
88 | 88 | ||
89 | #include <linux/crc32.h> | 89 | #include <linux/crc32.h> |
90 | #include <linux/err.h> | 90 | #include <linux/err.h> |
91 | #include <linux/slab.h> | ||
91 | #include "ubi.h" | 92 | #include "ubi.h" |
92 | 93 | ||
93 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 94 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
@@ -143,7 +144,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, | |||
143 | 144 | ||
144 | err = paranoid_check_not_bad(ubi, pnum); | 145 | err = paranoid_check_not_bad(ubi, pnum); |
145 | if (err) | 146 | if (err) |
146 | return err > 0 ? -EINVAL : err; | 147 | return err; |
147 | 148 | ||
148 | addr = (loff_t)pnum * ubi->peb_size + offset; | 149 | addr = (loff_t)pnum * ubi->peb_size + offset; |
149 | retry: | 150 | retry: |
@@ -236,12 +237,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
236 | 237 | ||
237 | err = paranoid_check_not_bad(ubi, pnum); | 238 | err = paranoid_check_not_bad(ubi, pnum); |
238 | if (err) | 239 | if (err) |
239 | return err > 0 ? -EINVAL : err; | 240 | return err; |
240 | 241 | ||
241 | /* The area we are writing to has to contain all 0xFF bytes */ | 242 | /* The area we are writing to has to contain all 0xFF bytes */ |
242 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); | 243 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); |
243 | if (err) | 244 | if (err) |
244 | return err > 0 ? -EINVAL : err; | 245 | return err; |
245 | 246 | ||
246 | if (offset >= ubi->leb_start) { | 247 | if (offset >= ubi->leb_start) { |
247 | /* | 248 | /* |
@@ -250,10 +251,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
250 | */ | 251 | */ |
251 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 252 | err = paranoid_check_peb_ec_hdr(ubi, pnum); |
252 | if (err) | 253 | if (err) |
253 | return err > 0 ? -EINVAL : err; | 254 | return err; |
254 | err = paranoid_check_peb_vid_hdr(ubi, pnum); | 255 | err = paranoid_check_peb_vid_hdr(ubi, pnum); |
255 | if (err) | 256 | if (err) |
256 | return err > 0 ? -EINVAL : err; | 257 | return err; |
257 | } | 258 | } |
258 | 259 | ||
259 | if (ubi_dbg_is_write_failure()) { | 260 | if (ubi_dbg_is_write_failure()) { |
@@ -273,6 +274,21 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, | |||
273 | } else | 274 | } else |
274 | ubi_assert(written == len); | 275 | ubi_assert(written == len); |
275 | 276 | ||
277 | if (!err) { | ||
278 | err = ubi_dbg_check_write(ubi, buf, pnum, offset, len); | ||
279 | if (err) | ||
280 | return err; | ||
281 | |||
282 | /* | ||
283 | * Since we always write sequentially, the rest of the PEB has | ||
284 | * to contain only 0xFF bytes. | ||
285 | */ | ||
286 | offset += len; | ||
287 | len = ubi->peb_size - offset; | ||
288 | if (len) | ||
289 | err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); | ||
290 | } | ||
291 | |||
276 | return err; | 292 | return err; |
277 | } | 293 | } |
278 | 294 | ||
@@ -348,7 +364,7 @@ retry: | |||
348 | 364 | ||
349 | err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); | 365 | err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); |
350 | if (err) | 366 | if (err) |
351 | return err > 0 ? -EINVAL : err; | 367 | return err; |
352 | 368 | ||
353 | if (ubi_dbg_is_erase_failure() && !err) { | 369 | if (ubi_dbg_is_erase_failure() && !err) { |
354 | dbg_err("cannot erase PEB %d (emulated)", pnum); | 370 | dbg_err("cannot erase PEB %d (emulated)", pnum); |
@@ -542,7 +558,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture) | |||
542 | 558 | ||
543 | err = paranoid_check_not_bad(ubi, pnum); | 559 | err = paranoid_check_not_bad(ubi, pnum); |
544 | if (err != 0) | 560 | if (err != 0) |
545 | return err > 0 ? -EINVAL : err; | 561 | return err; |
546 | 562 | ||
547 | if (ubi->ro_mode) { | 563 | if (ubi->ro_mode) { |
548 | ubi_err("read-only mode"); | 564 | ubi_err("read-only mode"); |
@@ -819,7 +835,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum, | |||
819 | 835 | ||
820 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); | 836 | err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); |
821 | if (err) | 837 | if (err) |
822 | return -EINVAL; | 838 | return err; |
823 | 839 | ||
824 | err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); | 840 | err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); |
825 | return err; | 841 | return err; |
@@ -1083,7 +1099,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1083 | 1099 | ||
1084 | err = paranoid_check_peb_ec_hdr(ubi, pnum); | 1100 | err = paranoid_check_peb_ec_hdr(ubi, pnum); |
1085 | if (err) | 1101 | if (err) |
1086 | return err > 0 ? -EINVAL : err; | 1102 | return err; |
1087 | 1103 | ||
1088 | vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); | 1104 | vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); |
1089 | vid_hdr->version = UBI_VERSION; | 1105 | vid_hdr->version = UBI_VERSION; |
@@ -1092,7 +1108,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1092 | 1108 | ||
1093 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); | 1109 | err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); |
1094 | if (err) | 1110 | if (err) |
1095 | return -EINVAL; | 1111 | return err; |
1096 | 1112 | ||
1097 | p = (char *)vid_hdr - ubi->vid_hdr_shift; | 1113 | p = (char *)vid_hdr - ubi->vid_hdr_shift; |
1098 | err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, | 1114 | err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, |
@@ -1107,8 +1123,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum, | |||
1107 | * @ubi: UBI device description object | 1123 | * @ubi: UBI device description object |
1108 | * @pnum: physical eraseblock number to check | 1124 | * @pnum: physical eraseblock number to check |
1109 | * | 1125 | * |
1110 | * This function returns zero if the physical eraseblock is good, a positive | 1126 | * This function returns zero if the physical eraseblock is good, %-EINVAL if |
1111 | * number if it is bad and a negative error code if an error occurred. | 1127 | * it is bad and a negative error code if an error occurred. |
1112 | */ | 1128 | */ |
1113 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | 1129 | static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) |
1114 | { | 1130 | { |
@@ -1120,7 +1136,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1120 | 1136 | ||
1121 | ubi_err("paranoid check failed for PEB %d", pnum); | 1137 | ubi_err("paranoid check failed for PEB %d", pnum); |
1122 | ubi_dbg_dump_stack(); | 1138 | ubi_dbg_dump_stack(); |
1123 | return err; | 1139 | return err > 0 ? -EINVAL : err; |
1124 | } | 1140 | } |
1125 | 1141 | ||
1126 | /** | 1142 | /** |
@@ -1130,7 +1146,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) | |||
1130 | * @ec_hdr: the erase counter header to check | 1146 | * @ec_hdr: the erase counter header to check |
1131 | * | 1147 | * |
1132 | * This function returns zero if the erase counter header contains valid | 1148 | * This function returns zero if the erase counter header contains valid |
1133 | * values, and %1 if not. | 1149 | * values, and %-EINVAL if not. |
1134 | */ | 1150 | */ |
1135 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | 1151 | static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, |
1136 | const struct ubi_ec_hdr *ec_hdr) | 1152 | const struct ubi_ec_hdr *ec_hdr) |
@@ -1156,7 +1172,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, | |||
1156 | fail: | 1172 | fail: |
1157 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1173 | ubi_dbg_dump_ec_hdr(ec_hdr); |
1158 | ubi_dbg_dump_stack(); | 1174 | ubi_dbg_dump_stack(); |
1159 | return 1; | 1175 | return -EINVAL; |
1160 | } | 1176 | } |
1161 | 1177 | ||
1162 | /** | 1178 | /** |
@@ -1164,8 +1180,8 @@ fail: | |||
1164 | * @ubi: UBI device description object | 1180 | * @ubi: UBI device description object |
1165 | * @pnum: the physical eraseblock number to check | 1181 | * @pnum: the physical eraseblock number to check |
1166 | * | 1182 | * |
1167 | * This function returns zero if the erase counter header is all right, %1 if | 1183 | * This function returns zero if the erase counter header is all right and and |
1168 | * not, and a negative error code if an error occurred. | 1184 | * a negative error code if not or if an error occurred. |
1169 | */ | 1185 | */ |
1170 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | 1186 | static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) |
1171 | { | 1187 | { |
@@ -1188,7 +1204,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) | |||
1188 | ubi_err("paranoid check failed for PEB %d", pnum); | 1204 | ubi_err("paranoid check failed for PEB %d", pnum); |
1189 | ubi_dbg_dump_ec_hdr(ec_hdr); | 1205 | ubi_dbg_dump_ec_hdr(ec_hdr); |
1190 | ubi_dbg_dump_stack(); | 1206 | ubi_dbg_dump_stack(); |
1191 | err = 1; | 1207 | err = -EINVAL; |
1192 | goto exit; | 1208 | goto exit; |
1193 | } | 1209 | } |
1194 | 1210 | ||
@@ -1206,7 +1222,7 @@ exit: | |||
1206 | * @vid_hdr: the volume identifier header to check | 1222 | * @vid_hdr: the volume identifier header to check |
1207 | * | 1223 | * |
1208 | * This function returns zero if the volume identifier header is all right, and | 1224 | * This function returns zero if the volume identifier header is all right, and |
1209 | * %1 if not. | 1225 | * %-EINVAL if not. |
1210 | */ | 1226 | */ |
1211 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, | 1227 | static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, |
1212 | const struct ubi_vid_hdr *vid_hdr) | 1228 | const struct ubi_vid_hdr *vid_hdr) |
@@ -1233,7 +1249,7 @@ fail: | |||
1233 | ubi_err("paranoid check failed for PEB %d", pnum); | 1249 | ubi_err("paranoid check failed for PEB %d", pnum); |
1234 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1250 | ubi_dbg_dump_vid_hdr(vid_hdr); |
1235 | ubi_dbg_dump_stack(); | 1251 | ubi_dbg_dump_stack(); |
1236 | return 1; | 1252 | return -EINVAL; |
1237 | 1253 | ||
1238 | } | 1254 | } |
1239 | 1255 | ||
@@ -1243,7 +1259,7 @@ fail: | |||
1243 | * @pnum: the physical eraseblock number to check | 1259 | * @pnum: the physical eraseblock number to check |
1244 | * | 1260 | * |
1245 | * This function returns zero if the volume identifier header is all right, | 1261 | * This function returns zero if the volume identifier header is all right, |
1246 | * %1 if not, and a negative error code if an error occurred. | 1262 | * and a negative error code if not or if an error occurred. |
1247 | */ | 1263 | */ |
1248 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | 1264 | static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) |
1249 | { | 1265 | { |
@@ -1270,7 +1286,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) | |||
1270 | ubi_err("paranoid check failed for PEB %d", pnum); | 1286 | ubi_err("paranoid check failed for PEB %d", pnum); |
1271 | ubi_dbg_dump_vid_hdr(vid_hdr); | 1287 | ubi_dbg_dump_vid_hdr(vid_hdr); |
1272 | ubi_dbg_dump_stack(); | 1288 | ubi_dbg_dump_stack(); |
1273 | err = 1; | 1289 | err = -EINVAL; |
1274 | goto exit; | 1290 | goto exit; |
1275 | } | 1291 | } |
1276 | 1292 | ||
@@ -1282,6 +1298,61 @@ exit: | |||
1282 | } | 1298 | } |
1283 | 1299 | ||
1284 | /** | 1300 | /** |
1301 | * ubi_dbg_check_write - make sure write succeeded. | ||
1302 | * @ubi: UBI device description object | ||
1303 | * @buf: buffer with data which were written | ||
1304 | * @pnum: physical eraseblock number the data were written to | ||
1305 | * @offset: offset within the physical eraseblock the data were written to | ||
1306 | * @len: how many bytes were written | ||
1307 | * | ||
1308 | * This functions reads data which were recently written and compares it with | ||
1309 | * the original data buffer - the data have to match. Returns zero if the data | ||
1310 | * match and a negative error code if not or in case of failure. | ||
1311 | */ | ||
1312 | int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, | ||
1313 | int offset, int len) | ||
1314 | { | ||
1315 | int err, i; | ||
1316 | |||
1317 | mutex_lock(&ubi->dbg_buf_mutex); | ||
1318 | err = ubi_io_read(ubi, ubi->dbg_peb_buf, pnum, offset, len); | ||
1319 | if (err) | ||
1320 | goto out_unlock; | ||
1321 | |||
1322 | for (i = 0; i < len; i++) { | ||
1323 | uint8_t c = ((uint8_t *)buf)[i]; | ||
1324 | uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i]; | ||
1325 | int dump_len; | ||
1326 | |||
1327 | if (c == c1) | ||
1328 | continue; | ||
1329 | |||
1330 | ubi_err("paranoid check failed for PEB %d:%d, len %d", | ||
1331 | pnum, offset, len); | ||
1332 | ubi_msg("data differ at position %d", i); | ||
1333 | dump_len = max_t(int, 128, len - i); | ||
1334 | ubi_msg("hex dump of the original buffer from %d to %d", | ||
1335 | i, i + dump_len); | ||
1336 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | ||
1337 | buf + i, dump_len, 1); | ||
1338 | ubi_msg("hex dump of the read buffer from %d to %d", | ||
1339 | i, i + dump_len); | ||
1340 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | ||
1341 | ubi->dbg_peb_buf + i, dump_len, 1); | ||
1342 | ubi_dbg_dump_stack(); | ||
1343 | err = -EINVAL; | ||
1344 | goto out_unlock; | ||
1345 | } | ||
1346 | mutex_unlock(&ubi->dbg_buf_mutex); | ||
1347 | |||
1348 | return 0; | ||
1349 | |||
1350 | out_unlock: | ||
1351 | mutex_unlock(&ubi->dbg_buf_mutex); | ||
1352 | return err; | ||
1353 | } | ||
1354 | |||
1355 | /** | ||
1285 | * ubi_dbg_check_all_ff - check that a region of flash is empty. | 1356 | * ubi_dbg_check_all_ff - check that a region of flash is empty. |
1286 | * @ubi: UBI device description object | 1357 | * @ubi: UBI device description object |
1287 | * @pnum: the physical eraseblock number to check | 1358 | * @pnum: the physical eraseblock number to check |
@@ -1289,8 +1360,8 @@ exit: | |||
1289 | * @len: the length of the region to check | 1360 | * @len: the length of the region to check |
1290 | * | 1361 | * |
1291 | * This function returns zero if only 0xFF bytes are present at offset | 1362 | * This function returns zero if only 0xFF bytes are present at offset |
1292 | * @offset of the physical eraseblock @pnum, %1 if not, and a negative error | 1363 | * @offset of the physical eraseblock @pnum, and a negative error code if not |
1293 | * code if an error occurred. | 1364 | * or if an error occurred. |
1294 | */ | 1365 | */ |
1295 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) | 1366 | int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) |
1296 | { | 1367 | { |
@@ -1321,7 +1392,7 @@ fail: | |||
1321 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); | 1392 | ubi_msg("hex dump of the %d-%d region", offset, offset + len); |
1322 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, | 1393 | print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, |
1323 | ubi->dbg_peb_buf, len, 1); | 1394 | ubi->dbg_peb_buf, len, 1); |
1324 | err = 1; | 1395 | err = -EINVAL; |
1325 | error: | 1396 | error: |
1326 | ubi_dbg_dump_stack(); | 1397 | ubi_dbg_dump_stack(); |
1327 | mutex_unlock(&ubi->dbg_buf_mutex); | 1398 | mutex_unlock(&ubi->dbg_buf_mutex); |
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 88a72e9c8beb..17f287decc36 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c | |||
@@ -22,6 +22,9 @@ | |||
22 | 22 | ||
23 | #include <linux/module.h> | 23 | #include <linux/module.h> |
24 | #include <linux/err.h> | 24 | #include <linux/err.h> |
25 | #include <linux/slab.h> | ||
26 | #include <linux/namei.h> | ||
27 | #include <linux/fs.h> | ||
25 | #include <asm/div64.h> | 28 | #include <asm/div64.h> |
26 | #include "ubi.h" | 29 | #include "ubi.h" |
27 | 30 | ||
@@ -280,6 +283,43 @@ struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name, | |||
280 | EXPORT_SYMBOL_GPL(ubi_open_volume_nm); | 283 | EXPORT_SYMBOL_GPL(ubi_open_volume_nm); |
281 | 284 | ||
282 | /** | 285 | /** |
286 | * ubi_open_volume_path - open UBI volume by its character device node path. | ||
287 | * @pathname: volume character device node path | ||
288 | * @mode: open mode | ||
289 | * | ||
290 | * This function is similar to 'ubi_open_volume()', but opens a volume the path | ||
291 | * to its character device node. | ||
292 | */ | ||
293 | struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) | ||
294 | { | ||
295 | int error, ubi_num, vol_id, mod; | ||
296 | struct inode *inode; | ||
297 | struct path path; | ||
298 | |||
299 | dbg_gen("open volume %s, mode %d", pathname, mode); | ||
300 | |||
301 | if (!pathname || !*pathname) | ||
302 | return ERR_PTR(-EINVAL); | ||
303 | |||
304 | error = kern_path(pathname, LOOKUP_FOLLOW, &path); | ||
305 | if (error) | ||
306 | return ERR_PTR(error); | ||
307 | |||
308 | inode = path.dentry->d_inode; | ||
309 | mod = inode->i_mode; | ||
310 | ubi_num = ubi_major2num(imajor(inode)); | ||
311 | vol_id = iminor(inode) - 1; | ||
312 | path_put(&path); | ||
313 | |||
314 | if (!S_ISCHR(mod)) | ||
315 | return ERR_PTR(-EINVAL); | ||
316 | if (vol_id >= 0 && ubi_num >= 0) | ||
317 | return ubi_open_volume(ubi_num, vol_id, mode); | ||
318 | return ERR_PTR(-ENODEV); | ||
319 | } | ||
320 | EXPORT_SYMBOL_GPL(ubi_open_volume_path); | ||
321 | |||
322 | /** | ||
283 | * ubi_close_volume - close UBI volume. | 323 | * ubi_close_volume - close UBI volume. |
284 | * @desc: volume descriptor | 324 | * @desc: volume descriptor |
285 | */ | 325 | */ |
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c index 90af61a2c3e4..dc5f688699da 100644 --- a/drivers/mtd/ubi/scan.c +++ b/drivers/mtd/ubi/scan.c | |||
@@ -41,6 +41,7 @@ | |||
41 | */ | 41 | */ |
42 | 42 | ||
43 | #include <linux/err.h> | 43 | #include <linux/err.h> |
44 | #include <linux/slab.h> | ||
44 | #include <linux/crc32.h> | 45 | #include <linux/crc32.h> |
45 | #include <linux/math64.h> | 46 | #include <linux/math64.h> |
46 | #include "ubi.h" | 47 | #include "ubi.h" |
@@ -974,11 +975,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi) | |||
974 | seb->ec = si->mean_ec; | 975 | seb->ec = si->mean_ec; |
975 | 976 | ||
976 | err = paranoid_check_si(ubi, si); | 977 | err = paranoid_check_si(ubi, si); |
977 | if (err) { | 978 | if (err) |
978 | if (err > 0) | ||
979 | err = -EINVAL; | ||
980 | goto out_vidh; | 979 | goto out_vidh; |
981 | } | ||
982 | 980 | ||
983 | ubi_free_vid_hdr(ubi, vidh); | 981 | ubi_free_vid_hdr(ubi, vidh); |
984 | kfree(ech); | 982 | kfree(ech); |
@@ -1086,8 +1084,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si) | |||
1086 | * @ubi: UBI device description object | 1084 | * @ubi: UBI device description object |
1087 | * @si: scanning information | 1085 | * @si: scanning information |
1088 | * | 1086 | * |
1089 | * This function returns zero if the scanning information is all right, %1 if | 1087 | * This function returns zero if the scanning information is all right, and a |
1090 | * not and a negative error code if an error occurred. | 1088 | * negative error code if not or if an error occurred. |
1091 | */ | 1089 | */ |
1092 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) | 1090 | static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) |
1093 | { | 1091 | { |
@@ -1346,7 +1344,7 @@ bad_vid_hdr: | |||
1346 | 1344 | ||
1347 | out: | 1345 | out: |
1348 | ubi_dbg_dump_stack(); | 1346 | ubi_dbg_dump_stack(); |
1349 | return 1; | 1347 | return -EINVAL; |
1350 | } | 1348 | } |
1351 | 1349 | ||
1352 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ | 1350 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ |
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h index 1af08178defd..5176d4886518 100644 --- a/drivers/mtd/ubi/ubi.h +++ b/drivers/mtd/ubi/ubi.h | |||
@@ -34,6 +34,7 @@ | |||
34 | #include <linux/fs.h> | 34 | #include <linux/fs.h> |
35 | #include <linux/cdev.h> | 35 | #include <linux/cdev.h> |
36 | #include <linux/device.h> | 36 | #include <linux/device.h> |
37 | #include <linux/slab.h> | ||
37 | #include <linux/string.h> | 38 | #include <linux/string.h> |
38 | #include <linux/vmalloc.h> | 39 | #include <linux/vmalloc.h> |
39 | #include <linux/notifier.h> | 40 | #include <linux/notifier.h> |
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c index 74fdc40c8627..425bf5a3edd4 100644 --- a/drivers/mtd/ubi/upd.c +++ b/drivers/mtd/ubi/upd.c | |||
@@ -147,12 +147,15 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol, | |||
147 | } | 147 | } |
148 | 148 | ||
149 | if (bytes == 0) { | 149 | if (bytes == 0) { |
150 | err = ubi_wl_flush(ubi); | ||
151 | if (err) | ||
152 | return err; | ||
153 | |||
150 | err = clear_update_marker(ubi, vol, 0); | 154 | err = clear_update_marker(ubi, vol, 0); |
151 | if (err) | 155 | if (err) |
152 | return err; | 156 | return err; |
153 | err = ubi_wl_flush(ubi); | 157 | vol->updating = 0; |
154 | if (!err) | 158 | return 0; |
155 | vol->updating = 0; | ||
156 | } | 159 | } |
157 | 160 | ||
158 | vol->upd_buf = vmalloc(ubi->leb_size); | 161 | vol->upd_buf = vmalloc(ubi->leb_size); |
@@ -362,16 +365,16 @@ int ubi_more_update_data(struct ubi_device *ubi, struct ubi_volume *vol, | |||
362 | 365 | ||
363 | ubi_assert(vol->upd_received <= vol->upd_bytes); | 366 | ubi_assert(vol->upd_received <= vol->upd_bytes); |
364 | if (vol->upd_received == vol->upd_bytes) { | 367 | if (vol->upd_received == vol->upd_bytes) { |
368 | err = ubi_wl_flush(ubi); | ||
369 | if (err) | ||
370 | return err; | ||
365 | /* The update is finished, clear the update marker */ | 371 | /* The update is finished, clear the update marker */ |
366 | err = clear_update_marker(ubi, vol, vol->upd_bytes); | 372 | err = clear_update_marker(ubi, vol, vol->upd_bytes); |
367 | if (err) | 373 | if (err) |
368 | return err; | 374 | return err; |
369 | err = ubi_wl_flush(ubi); | 375 | vol->updating = 0; |
370 | if (err == 0) { | 376 | err = to_write; |
371 | vol->updating = 0; | 377 | vfree(vol->upd_buf); |
372 | err = to_write; | ||
373 | vfree(vol->upd_buf); | ||
374 | } | ||
375 | } | 378 | } |
376 | 379 | ||
377 | return err; | 380 | return err; |
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c index ab64cb56df6e..e42afab9a9fe 100644 --- a/drivers/mtd/ubi/vmt.c +++ b/drivers/mtd/ubi/vmt.c | |||
@@ -25,6 +25,7 @@ | |||
25 | 25 | ||
26 | #include <linux/err.h> | 26 | #include <linux/err.h> |
27 | #include <linux/math64.h> | 27 | #include <linux/math64.h> |
28 | #include <linux/slab.h> | ||
28 | #include "ubi.h" | 29 | #include "ubi.h" |
29 | 30 | ||
30 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID | 31 | #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID |
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c index 1afc61e7455d..cd90ff3b76b1 100644 --- a/drivers/mtd/ubi/vtbl.c +++ b/drivers/mtd/ubi/vtbl.c | |||
@@ -58,6 +58,7 @@ | |||
58 | 58 | ||
59 | #include <linux/crc32.h> | 59 | #include <linux/crc32.h> |
60 | #include <linux/err.h> | 60 | #include <linux/err.h> |
61 | #include <linux/slab.h> | ||
61 | #include <asm/div64.h> | 62 | #include <asm/div64.h> |
62 | #include "ubi.h" | 63 | #include "ubi.h" |
63 | 64 | ||
@@ -566,6 +567,7 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si, | |||
566 | vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); | 567 | vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); |
567 | vol->alignment = be32_to_cpu(vtbl[i].alignment); | 568 | vol->alignment = be32_to_cpu(vtbl[i].alignment); |
568 | vol->data_pad = be32_to_cpu(vtbl[i].data_pad); | 569 | vol->data_pad = be32_to_cpu(vtbl[i].data_pad); |
570 | vol->upd_marker = vtbl[i].upd_marker; | ||
569 | vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? | 571 | vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? |
570 | UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; | 572 | UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; |
571 | vol->name_len = be16_to_cpu(vtbl[i].name_len); | 573 | vol->name_len = be16_to_cpu(vtbl[i].name_len); |
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c index 600c7229d5cf..f64ddabd4ac8 100644 --- a/drivers/mtd/ubi/wl.c +++ b/drivers/mtd/ubi/wl.c | |||
@@ -464,7 +464,7 @@ retry: | |||
464 | ubi->peb_size - ubi->vid_hdr_aloffset); | 464 | ubi->peb_size - ubi->vid_hdr_aloffset); |
465 | if (err) { | 465 | if (err) { |
466 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); | 466 | ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); |
467 | return err > 0 ? -EINVAL : err; | 467 | return err; |
468 | } | 468 | } |
469 | 469 | ||
470 | return e->pnum; | 470 | return e->pnum; |
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e, | |||
513 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); | 513 | dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); |
514 | 514 | ||
515 | err = paranoid_check_ec(ubi, e->pnum, e->ec); | 515 | err = paranoid_check_ec(ubi, e->pnum, e->ec); |
516 | if (err > 0) | 516 | if (err) |
517 | return -EINVAL; | 517 | return -EINVAL; |
518 | 518 | ||
519 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); | 519 | ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); |
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi) | |||
1572 | * @ec: the erase counter to check | 1572 | * @ec: the erase counter to check |
1573 | * | 1573 | * |
1574 | * This function returns zero if the erase counter of physical eraseblock @pnum | 1574 | * This function returns zero if the erase counter of physical eraseblock @pnum |
1575 | * is equivalent to @ec, %1 if not, and a negative error code if an error | 1575 | * is equivalent to @ec, and a negative error code if not or if an error occurred. |
1576 | * occurred. | ||
1577 | */ | 1576 | */ |
1578 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) | 1577 | static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) |
1579 | { | 1578 | { |
@@ -1611,8 +1610,8 @@ out_free: | |||
1611 | * @e: the wear-leveling entry to check | 1610 | * @e: the wear-leveling entry to check |
1612 | * @root: the root of the tree | 1611 | * @root: the root of the tree |
1613 | * | 1612 | * |
1614 | * This function returns zero if @e is in the @root RB-tree and %1 if it is | 1613 | * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it |
1615 | * not. | 1614 | * is not. |
1616 | */ | 1615 | */ |
1617 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | 1616 | static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, |
1618 | struct rb_root *root) | 1617 | struct rb_root *root) |
@@ -1623,7 +1622,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | |||
1623 | ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", | 1622 | ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", |
1624 | e->pnum, e->ec, root); | 1623 | e->pnum, e->ec, root); |
1625 | ubi_dbg_dump_stack(); | 1624 | ubi_dbg_dump_stack(); |
1626 | return 1; | 1625 | return -EINVAL; |
1627 | } | 1626 | } |
1628 | 1627 | ||
1629 | /** | 1628 | /** |
@@ -1632,7 +1631,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, | |||
1632 | * @ubi: UBI device description object | 1631 | * @ubi: UBI device description object |
1633 | * @e: the wear-leveling entry to check | 1632 | * @e: the wear-leveling entry to check |
1634 | * | 1633 | * |
1635 | * This function returns zero if @e is in @ubi->pq and %1 if it is not. | 1634 | * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not. |
1636 | */ | 1635 | */ |
1637 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) | 1636 | static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) |
1638 | { | 1637 | { |
@@ -1647,6 +1646,6 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) | |||
1647 | ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", | 1646 | ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", |
1648 | e->pnum, e->ec); | 1647 | e->pnum, e->ec); |
1649 | ubi_dbg_dump_stack(); | 1648 | ubi_dbg_dump_stack(); |
1650 | return 1; | 1649 | return -EINVAL; |
1651 | } | 1650 | } |
1652 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ | 1651 | #endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ |