From c1257b4798d48b73ad1a9ca359504cd49caefa0d Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 2 Nov 2011 13:34:42 -0700 Subject: mtd: nand: add Macronix manufacturer Macronix is produing SLC NAND MX30LF1208AA, so add their manufacturer code to the manufacturer lists. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/nand_ids.c | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers') diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c index 00cf1b0d6053..56c688dafe92 100644 --- a/drivers/mtd/nand/nand_ids.c +++ b/drivers/mtd/nand/nand_ids.c @@ -176,6 +176,7 @@ struct nand_manufacturers nand_manuf_ids[] = { {NAND_MFR_HYNIX, "Hynix"}, {NAND_MFR_MICRON, "Micron"}, {NAND_MFR_AMD, "AMD"}, + {NAND_MFR_MACRONIX, "Macronix"}, {0x0, "Unknown"} }; -- cgit v1.2.3 From c01804edde20414b0cadbe38cc9974a54a31e36f Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 2 Nov 2011 13:34:43 -0700 Subject: mtd: nand: add 512 Mbit device code (Macronix) Macronix MX30LF1208AA is a 512 Mbit NAND with device code 0xF0. Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/nand_ids.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/nand_ids.c b/drivers/mtd/nand/nand_ids.c index 56c688dafe92..af4fe8ca7b5e 100644 --- a/drivers/mtd/nand/nand_ids.c +++ b/drivers/mtd/nand/nand_ids.c @@ -73,11 +73,12 @@ struct nand_flash_dev nand_flash_ids[] = { #define LP_OPTIONS (NAND_SAMSUNG_LP_OPTIONS | NAND_NO_READRDY | NAND_NO_AUTOINCR) #define LP_OPTIONS16 (LP_OPTIONS | NAND_BUSWIDTH_16) - /*512 Megabit */ + /* 512 Megabit */ {"NAND 64MiB 1,8V 8-bit", 0xA2, 0, 64, 0, LP_OPTIONS}, {"NAND 64MiB 1,8V 8-bit", 0xA0, 0, 64, 0, LP_OPTIONS}, {"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, LP_OPTIONS}, {"NAND 64MiB 3,3V 8-bit", 0xD0, 0, 64, 0, LP_OPTIONS}, + {"NAND 64MiB 3,3V 8-bit", 0xF0, 0, 64, 0, LP_OPTIONS}, {"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, LP_OPTIONS16}, {"NAND 64MiB 1,8V 16-bit", 0xB0, 0, 64, 0, LP_OPTIONS16}, {"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, LP_OPTIONS16}, -- cgit v1.2.3 From 8c3423359644d01cfba3a401e403c549c3f88ac4 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Wed, 2 Nov 2011 13:34:44 -0700 Subject: mtd: nand: scan 1st and 2nd page for Macronix SLC Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/nand_base.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c index 3ed9c5e4d34e..35b4565050f1 100644 --- a/drivers/mtd/nand/nand_base.c +++ b/drivers/mtd/nand/nand_base.c @@ -3132,8 +3132,8 @@ ident_done: * Bad block marker is stored in the last page of each block * on Samsung and Hynix MLC devices; stored in first two pages * of each block on Micron devices with 2KiB pages and on - * SLC Samsung, Hynix, Toshiba and AMD/Spansion. All others scan - * only the first page. + * SLC Samsung, Hynix, Toshiba, AMD/Spansion, and Macronix. + * All others scan only the first page. */ if ((chip->cellinfo & NAND_CI_CELLTYPE_MSK) && (*maf_id == NAND_MFR_SAMSUNG || @@ -3143,7 +3143,8 @@ ident_done: (*maf_id == NAND_MFR_SAMSUNG || *maf_id == NAND_MFR_HYNIX || *maf_id == NAND_MFR_TOSHIBA || - *maf_id == NAND_MFR_AMD)) || + *maf_id == NAND_MFR_AMD || + *maf_id == NAND_MFR_MACRONIX)) || (mtd->writesize == 2048 && *maf_id == NAND_MFR_MICRON)) chip->bbt_options |= NAND_BBT_SCAN2NDPAGE; -- cgit v1.2.3 From 342ff28f5a2e5aa3236617bd2bddf6c749677ef2 Mon Sep 17 00:00:00 2001 From: Brian Norris Date: Mon, 7 Nov 2011 15:51:05 -0800 Subject: mtd: mtd_blkdevs: don't increase 'open' count on error path Some error paths in mtd_blkdevs were fixed in the following commit: commit 94735ec4044a6d318b83ad3c5794e931ed168d10 mtd: mtd_blkdevs: fix error path in blktrans_open But on these error paths, the block device's `dev->open' count is already incremented before we check for errors. This meant that, while the error path was handled correctly on the first time through blktrans_open(), the device is erroneously considered already open on the second time through. This problem can be seen, for instance, when a UBI volume is simultaneously mounted as a UBIFS partition and read through its corresponding gluebi mtdblockX device. This results in blktrans_open() passing its error checks (with `dev->open > 0') without actually having a handle on the device. Here's a summarized log of the actions and results with nandsim: # modprobe nandsim # modprobe mtdblock # modprobe gluebi # modprobe ubifs # ubiattach /dev/ubi_ctrl -m 0 ... # ubimkvol /dev/ubi0 -N test -s 16MiB ... # mount -t ubifs ubi0:test /mnt # ls /dev/mtdblock* /dev/mtdblock0 /dev/mtdblock1 # cat /dev/mtdblock1 > /dev/null cat: can't open '/dev/mtdblock4': Device or resource busy # cat /dev/mtdblock1 > /dev/null CPU 0 Unable to handle kernel paging request at virtual address fffffff0, epc == 8031536c, ra == 8031f280 Oops[#1]: ... Call Trace: [<8031536c>] ubi_leb_read+0x14/0x164 [<8031f280>] gluebi_read+0xf0/0x148 [<802edba8>] mtdblock_readsect+0x64/0x198 [<802ecfe4>] mtd_blktrans_thread+0x330/0x3f4 [<8005be98>] kthread+0x88/0x90 [<8000bc04>] kernel_thread_helper+0x10/0x18 Cc: stable@kernel.org [3.0+] Signed-off-by: Brian Norris Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtd_blkdevs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index ed8b5e744b12..424ca5f93c6c 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -215,7 +215,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) mutex_lock(&dev->lock); - if (dev->open++) + if (dev->open) goto unlock; kref_get(&dev->ref); @@ -235,6 +235,7 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode) goto error_release; unlock: + dev->open++; mutex_unlock(&dev->lock); blktrans_dev_put(dev); return ret; -- cgit v1.2.3 From 8e987465a137d4824710e02550f06aa891c9b865 Mon Sep 17 00:00:00 2001 From: Aaron Sierra Date: Mon, 14 Nov 2011 18:44:34 -0600 Subject: mtd: cfi: Allow per-mapping CFI device endianness This patch allows each CFI device map to use its own endianness. The globally defined CFI endianness (CONFIG_MTD_CFI_NOSWAP, CONFIG_MTD_CFI_BE_BYTE_SWAP or CONFIG_MTD_CFI_LE_BYTE_SWAP) becomes the default value which can be overridden by a driver for a particular device. Signed-off-by: Aaron Sierra Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/chips/cfi_cmdset_0020.c | 5 ++- include/linux/mtd/cfi.h | 16 ++++---- include/linux/mtd/cfi_endian.h | 76 ++++++++++++++----------------------- include/linux/mtd/map.h | 1 + 4 files changed, 41 insertions(+), 57 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c index 179814a95f3a..666c52f8bf8d 100644 --- a/drivers/mtd/chips/cfi_cmdset_0020.c +++ b/drivers/mtd/chips/cfi_cmdset_0020.c @@ -139,8 +139,9 @@ struct mtd_info *cfi_cmdset_0020(struct map_info *map, int primary) } /* Do some byteswapping if necessary */ - extp->FeatureSupport = cfi32_to_cpu(extp->FeatureSupport); - extp->BlkStatusRegMask = cfi32_to_cpu(extp->BlkStatusRegMask); + extp->FeatureSupport = cfi32_to_cpu(map, extp->FeatureSupport); + extp->BlkStatusRegMask = cfi32_to_cpu(map, + extp->BlkStatusRegMask); #ifdef DEBUG_CFI_FEATURES /* Tell the user about it in lots of lovely detail */ diff --git a/include/linux/mtd/cfi.h b/include/linux/mtd/cfi.h index d24925492972..d5d2ec6494bb 100644 --- a/include/linux/mtd/cfi.h +++ b/include/linux/mtd/cfi.h @@ -354,10 +354,10 @@ static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cf onecmd = cmd; break; case 2: - onecmd = cpu_to_cfi16(cmd); + onecmd = cpu_to_cfi16(map, cmd); break; case 4: - onecmd = cpu_to_cfi32(cmd); + onecmd = cpu_to_cfi32(map, cmd); break; } @@ -437,10 +437,10 @@ static inline unsigned long cfi_merge_status(map_word val, struct map_info *map, case 1: break; case 2: - res = cfi16_to_cpu(res); + res = cfi16_to_cpu(map, res); break; case 4: - res = cfi32_to_cpu(res); + res = cfi32_to_cpu(map, res); break; default: BUG(); } @@ -480,12 +480,12 @@ static inline uint8_t cfi_read_query(struct map_info *map, uint32_t addr) if (map_bankwidth_is_1(map)) { return val.x[0]; } else if (map_bankwidth_is_2(map)) { - return cfi16_to_cpu(val.x[0]); + return cfi16_to_cpu(map, val.x[0]); } else { /* No point in a 64-bit byteswap since that would just be swapping the responses from different chips, and we are only interested in one chip (a representative sample) */ - return cfi32_to_cpu(val.x[0]); + return cfi32_to_cpu(map, val.x[0]); } } @@ -496,12 +496,12 @@ static inline uint16_t cfi_read_query16(struct map_info *map, uint32_t addr) if (map_bankwidth_is_1(map)) { return val.x[0] & 0xff; } else if (map_bankwidth_is_2(map)) { - return cfi16_to_cpu(val.x[0]); + return cfi16_to_cpu(map, val.x[0]); } else { /* No point in a 64-bit byteswap since that would just be swapping the responses from different chips, and we are only interested in one chip (a representative sample) */ - return cfi32_to_cpu(val.x[0]); + return cfi32_to_cpu(map, val.x[0]); } } diff --git a/include/linux/mtd/cfi_endian.h b/include/linux/mtd/cfi_endian.h index 51cc3f5917a8..b97a625071f8 100644 --- a/include/linux/mtd/cfi_endian.h +++ b/include/linux/mtd/cfi_endian.h @@ -19,53 +19,35 @@ #include -#ifndef CONFIG_MTD_CFI_ADV_OPTIONS - -#define CFI_HOST_ENDIAN - -#else - -#ifdef CONFIG_MTD_CFI_NOSWAP -#define CFI_HOST_ENDIAN -#endif - -#ifdef CONFIG_MTD_CFI_LE_BYTE_SWAP -#define CFI_LITTLE_ENDIAN -#endif - -#ifdef CONFIG_MTD_CFI_BE_BYTE_SWAP -#define CFI_BIG_ENDIAN -#endif - -#endif - -#if defined(CFI_LITTLE_ENDIAN) -#define cpu_to_cfi8(x) (x) -#define cfi8_to_cpu(x) (x) -#define cpu_to_cfi16(x) cpu_to_le16(x) -#define cpu_to_cfi32(x) cpu_to_le32(x) -#define cpu_to_cfi64(x) cpu_to_le64(x) -#define cfi16_to_cpu(x) le16_to_cpu(x) -#define cfi32_to_cpu(x) le32_to_cpu(x) -#define cfi64_to_cpu(x) le64_to_cpu(x) -#elif defined (CFI_BIG_ENDIAN) -#define cpu_to_cfi8(x) (x) -#define cfi8_to_cpu(x) (x) -#define cpu_to_cfi16(x) cpu_to_be16(x) -#define cpu_to_cfi32(x) cpu_to_be32(x) -#define cpu_to_cfi64(x) cpu_to_be64(x) -#define cfi16_to_cpu(x) be16_to_cpu(x) -#define cfi32_to_cpu(x) be32_to_cpu(x) -#define cfi64_to_cpu(x) be64_to_cpu(x) -#elif defined (CFI_HOST_ENDIAN) -#define cpu_to_cfi8(x) (x) -#define cfi8_to_cpu(x) (x) -#define cpu_to_cfi16(x) (x) -#define cpu_to_cfi32(x) (x) -#define cpu_to_cfi64(x) (x) -#define cfi16_to_cpu(x) (x) -#define cfi32_to_cpu(x) (x) -#define cfi64_to_cpu(x) (x) +#define CFI_HOST_ENDIAN 1 +#define CFI_LITTLE_ENDIAN 2 +#define CFI_BIG_ENDIAN 3 + +#if !defined(CONFIG_MTD_CFI_ADV_OPTIONS) || defined(CONFIG_MTD_CFI_NOSWAP) +#define CFI_DEFAULT_ENDIAN CFI_HOST_ENDIAN +#elif defined(CONFIG_MTD_CFI_LE_BYTE_SWAP) +#define CFI_DEFAULT_ENDIAN CFI_LITTLE_ENDIAN +#elif defined(CONFIG_MTD_CFI_BE_BYTE_SWAP) +#define CFI_DEFAULT_ENDIAN CFI_BIG_ENDIAN #else #error No CFI endianness defined #endif + +#define cfi_default(s) ((s)?:CFI_DEFAULT_ENDIAN) +#define cfi_be(s) (cfi_default(s) == CFI_BIG_ENDIAN) +#define cfi_le(s) (cfi_default(s) == CFI_LITTLE_ENDIAN) +#define cfi_host(s) (cfi_default(s) == CFI_HOST_ENDIAN) + +#define cpu_to_cfi8(map, x) (x) +#define cfi8_to_cpu(map, x) (x) +#define cpu_to_cfi16(map, x) _cpu_to_cfi(16, (map)->swap, (x)) +#define cpu_to_cfi32(map, x) _cpu_to_cfi(32, (map)->swap, (x)) +#define cpu_to_cfi64(map, x) _cpu_to_cfi(64, (map)->swap, (x)) +#define cfi16_to_cpu(map, x) _cfi_to_cpu(16, (map)->swap, (x)) +#define cfi32_to_cpu(map, x) _cfi_to_cpu(32, (map)->swap, (x)) +#define cfi64_to_cpu(map, x) _cfi_to_cpu(64, (map)->swap, (x)) + +#define _cpu_to_cfi(w, s, x) (cfi_host(s)?(x):_swap_to_cfi(w, s, x)) +#define _cfi_to_cpu(w, s, x) (cfi_host(s)?(x):_swap_to_cpu(w, s, x)) +#define _swap_to_cfi(w, s, x) (cfi_be(s)?cpu_to_be##w(x):cpu_to_le##w(x)) +#define _swap_to_cpu(w, s, x) (cfi_be(s)?be##w##_to_cpu(x):le##w##_to_cpu(x)) diff --git a/include/linux/mtd/map.h b/include/linux/mtd/map.h index a9e6ba46865e..1132410f14c6 100644 --- a/include/linux/mtd/map.h +++ b/include/linux/mtd/map.h @@ -214,6 +214,7 @@ struct map_info { void __iomem *virt; void *cached; + int swap; /* this mapping's byte-swapping requirement */ int bankwidth; /* in octets. This isn't necessarily the width of actual bus cycles -- it's the repeat interval in bytes, before you are talking to the first chip again. -- cgit v1.2.3 From 12f049bd59676a672f529586b9b13c986c4bf40f Mon Sep 17 00:00:00 2001 From: Shubhrajyoti D Date: Wed, 16 Nov 2011 10:48:00 +0530 Subject: mtd: nand: Making MTD_NAND_OMAP2 depend on ARCH_OMAP2PLUS Making MTD_NAND_OMAP2 depend on ARCH_OMAP2PLUS instead of oring with ARCH2/3/4. Reported-by: Russell King Signed-off-by: Shubhrajyoti D Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig index cce7b70824c3..07c47749ffa6 100644 --- a/drivers/mtd/nand/Kconfig +++ b/drivers/mtd/nand/Kconfig @@ -110,7 +110,7 @@ config MTD_NAND_AMS_DELTA config MTD_NAND_OMAP2 tristate "NAND Flash device on OMAP2, OMAP3 and OMAP4" - depends on ARM && (ARCH_OMAP2 || ARCH_OMAP3 || ARCH_OMAP4) + depends on ARCH_OMAP2PLUS help Support for NAND flash on Texas Instruments OMAP2, OMAP3 and OMAP4 platforms. -- cgit v1.2.3 From ac48e800c077738f18d3789d5eb8958bf52cf2d7 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:43 +0100 Subject: mtd: docg3: fix debug log verbosity Change the NOP debug log verbosity to very verbose to unburden log analysis. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index bdcf5df982e8..6f5233da3929 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -143,7 +143,7 @@ static void doc_delay(struct docg3 *docg3, int nbNOPs) { int i; - doc_dbg("NOP x %d\n", nbNOPs); + doc_vdbg("NOP x %d\n", nbNOPs); for (i = 0; i < nbNOPs; i++) doc_writeb(docg3, 0, DOC_NOP); } -- cgit v1.2.3 From 84a930581ef45e81cff0450b19ce5a70f24d50bb Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:44 +0100 Subject: mtd: docg3: fix tracing of IO in writeb Writeb was incorrectly traced as a 16 bits write, instead of a 8 bits write. Fix it by tracing the correct width. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 6f5233da3929..8942a751342e 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -82,7 +82,7 @@ static inline u16 doc_readw(struct docg3 *docg3, u16 reg) static inline void doc_writeb(struct docg3 *docg3, u8 val, u16 reg) { writeb(val, docg3->base + reg); - trace_docg3_io(1, 16, reg, val); + trace_docg3_io(1, 8, reg, val); } static inline void doc_writew(struct docg3 *docg3, u16 val, u16 reg) -- cgit v1.2.3 From dbc26d98f8b4a3d1d2f25d997a0a0aba4ea46add Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:45 +0100 Subject: mtd: docg3: fix protection areas reading The protection areas boundaries were on 16bit registers, not 8bit. This is consistent with block numbers, which can extend up to 4096 on bigger chips (and is 2048 on the docg3). Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 8942a751342e..5834e6e65d1c 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -852,13 +852,15 @@ static int dbg_protection_show(struct seq_file *s, void *p) { struct docg3 *docg3 = (struct docg3 *)s->private; int pos = 0; - int protect = doc_register_readb(docg3, DOC_PROTECTION); - int dps0 = doc_register_readb(docg3, DOC_DPS0_STATUS); - int dps0_low = doc_register_readb(docg3, DOC_DPS0_ADDRLOW); - int dps0_high = doc_register_readb(docg3, DOC_DPS0_ADDRHIGH); - int dps1 = doc_register_readb(docg3, DOC_DPS1_STATUS); - int dps1_low = doc_register_readb(docg3, DOC_DPS1_ADDRLOW); - int dps1_high = doc_register_readb(docg3, DOC_DPS1_ADDRHIGH); + int protect, dps0, dps0_low, dps0_high, dps1, dps1_low, dps1_high; + + protect = doc_register_readb(docg3, DOC_PROTECTION); + dps0 = doc_register_readb(docg3, DOC_DPS0_STATUS); + dps0_low = doc_register_readw(docg3, DOC_DPS0_ADDRLOW); + dps0_high = doc_register_readw(docg3, DOC_DPS0_ADDRHIGH); + dps1 = doc_register_readb(docg3, DOC_DPS1_STATUS); + dps1_low = doc_register_readw(docg3, DOC_DPS1_ADDRLOW); + dps1_high = doc_register_readw(docg3, DOC_DPS1_ADDRHIGH); pos += seq_printf(s, "Protection = 0x%02x (", protect); -- cgit v1.2.3 From 34db8a5a72c5c5eb5d2811f237dcc9bf3c6425a9 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:46 +0100 Subject: mtd: docg3: fix BCH registers BCH registers are contiguous, not on every byte. Fix the register definitions. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 0d407be24594..62af5aaeec43 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -105,7 +105,7 @@ #define DOC_ECCCONF1 0x1042 #define DOC_ECCPRESET 0x1044 #define DOC_HAMMINGPARITY 0x1046 -#define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 1)) +#define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 0)) #define DOC_PROTECTION 0x1056 #define DOC_DPS0_ADDRLOW 0x1060 -- cgit v1.2.3 From 32a50b3a457fda9606fd0946eb77ba28a520cd7f Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:47 +0100 Subject: mtd: docg3: fix reading oob+data without correction Fix the docg3 reads to be able to cope with all possible data buffer / oob buffer / file mode combinations from docg3_read_oob(). This especially ensures that raw reads do not use ECC corrections, and AUTOOOB and PLACEOOB do use ECC correction. The approach is to empty docg3_read() and make it a wrapper to docg3_read_oob(). As docg3_read_oob() handles all the funny cases (no data buffer but oob buffer, data buffer but no oob buffer, ...), docg3_read() is just a special use of docg3_read_oob(). Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 194 ++++++++++++++++++++++---------------------- 1 file changed, 95 insertions(+), 99 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 5834e6e65d1c..1c2f54d23c7e 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -196,8 +196,8 @@ static int doc_reset_seq(struct docg3 *docg3) /** * doc_read_data_area - Read data from data area * @docg3: the device - * @buf: the buffer to fill in - * @len: the lenght to read + * @buf: the buffer to fill in (might be NULL is dummy reads) + * @len: the length to read * @first: first time read, DOC_READADDRESS should be set * * Reads bytes from flash data. Handles the single byte / even bytes reads. @@ -218,8 +218,10 @@ static void doc_read_data_area(struct docg3 *docg3, void *buf, int len, dst16 = buf; for (i = 0; i < len4; i += 2) { data16 = doc_readw(docg3, DOC_IOSPACE_DATA); - *dst16 = data16; - dst16++; + if (dst16) { + *dst16 = data16; + dst16++; + } } if (cdr) { @@ -229,8 +231,10 @@ static void doc_read_data_area(struct docg3 *docg3, void *buf, int len, dst8 = (u8 *)dst16; for (i = 0; i < cdr; i++) { data8 = doc_readb(docg3, DOC_IOSPACE_DATA); - *dst8 = data8; - dst8++; + if (dst8) { + *dst8 = data8; + dst8++; + } } } } @@ -542,96 +546,109 @@ static void calc_block_sector(loff_t from, int *block0, int *block1, int *page, } /** - * doc_read - Read bytes from flash + * doc_read_oob - Read out of band bytes from flash * @mtd: the device * @from: the offset from first block and first page, in bytes, aligned on page * size - * @len: the number of bytes to read (must be a multiple of 4) - * @retlen: the number of bytes actually read - * @buf: the filled in buffer + * @ops: the mtd oob structure * - * Reads flash memory pages. This function does not read the OOB chunk, but only - * the page data. + * Reads flash memory OOB area of pages. * * Returns 0 if read successfull, of -EIO, -EINVAL if an error occured */ -static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, - size_t *retlen, u_char *buf) +static int doc_read_oob(struct mtd_info *mtd, loff_t from, + struct mtd_oob_ops *ops) { struct docg3 *docg3 = mtd->priv; - int block0, block1, page, readlen, ret, ofs = 0; - int syn[DOC_ECC_BCH_SIZE], eccconf1; - u8 oob[DOC_LAYOUT_OOB_SIZE]; + int block0, block1, page, ret, ofs = 0; + u8 *oobbuf = ops->oobbuf; + u8 *buf = ops->datbuf; + size_t len, ooblen, nbdata, nboob; + u8 calc_ecc[DOC_ECC_BCH_SIZE], eccconf1; + + if (buf) + len = ops->len; + else + len = 0; + if (oobbuf) + ooblen = ops->ooblen; + else + ooblen = 0; + + if (oobbuf && ops->mode == MTD_OPS_PLACE_OOB) + oobbuf += ops->ooboffs; + + doc_dbg("doc_read_oob(from=%lld, mode=%d, data=(%p:%zu), oob=(%p:%zu))\n", + from, ops->mode, buf, len, oobbuf, ooblen); + if ((len % DOC_LAYOUT_PAGE_SIZE) || (ooblen % DOC_LAYOUT_OOB_SIZE) || + (from % DOC_LAYOUT_PAGE_SIZE)) + return -EINVAL; ret = -EINVAL; - doc_dbg("doc_read(from=%lld, len=%zu, buf=%p)\n", from, len, buf); - if (from % DOC_LAYOUT_PAGE_SIZE) - goto err; - if (len % 4) - goto err; - calc_block_sector(from, &block0, &block1, &page, &ofs); + calc_block_sector(from + len, &block0, &block1, &page, &ofs); if (block1 > docg3->max_block) goto err; - *retlen = 0; + ops->oobretlen = 0; + ops->retlen = 0; ret = 0; - readlen = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE); - while (!ret && len > 0) { - readlen = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE); + while (!ret && (len > 0 || ooblen > 0)) { + calc_block_sector(from, &block0, &block1, &page, &ofs); + nbdata = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE); + nboob = min_t(size_t, ooblen, (size_t)DOC_LAYOUT_OOB_SIZE); ret = doc_read_page_prepare(docg3, block0, block1, page, ofs); if (ret < 0) goto err; ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_COVERED_BYTES); if (ret < 0) goto err_in_read; - ret = doc_read_page_getbytes(docg3, readlen, buf, 1); - if (ret < readlen) + ret = doc_read_page_getbytes(docg3, nbdata, buf, 1); + if (ret < nbdata) goto err_in_read; - ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE, - oob, 0); - if (ret < DOC_LAYOUT_OOB_SIZE) + doc_read_page_getbytes(docg3, DOC_LAYOUT_PAGE_SIZE - nbdata, + NULL, 0); + ret = doc_read_page_getbytes(docg3, nboob, oobbuf, 0); + if (ret < nboob) goto err_in_read; + doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob, + NULL, 0); - *retlen += readlen; - buf += readlen; - len -= readlen; - - ofs ^= DOC_LAYOUT_PAGE_OOB_SIZE; - if (ofs == 0) - page += 2; - if (page > DOC_ADDR_PAGE_MASK) { - page = 0; - block0 += 2; - block1 += 2; - } - - /* - * There should be a BCH bitstream fixing algorithm here ... - * By now, a page read failure is triggered by BCH error - */ - doc_get_hw_bch_syndroms(docg3, syn); + doc_get_hw_bch_syndroms(docg3, calc_ecc); eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1); - doc_dbg("OOB - INFO: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - oob[0], oob[1], oob[2], oob[3], oob[4], - oob[5], oob[6]); - doc_dbg("OOB - HAMMING: %02x\n", oob[7]); - doc_dbg("OOB - BCH_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - oob[8], oob[9], oob[10], oob[11], oob[12], - oob[13], oob[14]); - doc_dbg("OOB - UNUSED: %02x\n", oob[15]); + if (nboob >= DOC_LAYOUT_OOB_SIZE) { + doc_dbg("OOB - INFO: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + oobbuf[0], oobbuf[1], oobbuf[2], oobbuf[3], + oobbuf[4], oobbuf[5], oobbuf[6]); + doc_dbg("OOB - HAMMING: %02x\n", oobbuf[7]); + doc_dbg("OOB - BCH_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + oobbuf[8], oobbuf[9], oobbuf[10], oobbuf[11], + oobbuf[12], oobbuf[13], oobbuf[14]); + doc_dbg("OOB - UNUSED: %02x\n", oobbuf[15]); + } doc_dbg("ECC checks: ECCConf1=%x\n", eccconf1); - doc_dbg("ECC BCH syndrom: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - syn[0], syn[1], syn[2], syn[3], syn[4], syn[5], syn[6]); + doc_dbg("ECC CALC_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + calc_ecc[0], calc_ecc[1], calc_ecc[2], + calc_ecc[3], calc_ecc[4], calc_ecc[5], + calc_ecc[6]); ret = -EBADMSG; if (block0 >= DOC_LAYOUT_BLOCK_FIRST_DATA) { - if (eccconf1 & DOC_ECCCONF1_BCH_SYNDROM_ERR) + if ((eccconf1 & DOC_ECCCONF1_BCH_SYNDROM_ERR) && + (eccconf1 & DOC_ECCCONF1_PAGE_IS_WRITTEN)) goto err_in_read; if (is_prot_seq_error(docg3)) goto err_in_read; } + doc_read_page_finish(docg3); + ops->retlen += nbdata; + ops->oobretlen += nboob; + buf += nbdata; + oobbuf += nboob; + len -= nbdata; + ooblen -= nboob; + from += DOC_LAYOUT_PAGE_SIZE; } return 0; @@ -642,54 +659,33 @@ err: } /** - * doc_read_oob - Read out of band bytes from flash + * doc_read - Read bytes from flash * @mtd: the device * @from: the offset from first block and first page, in bytes, aligned on page * size - * @ops: the mtd oob structure + * @len: the number of bytes to read (must be a multiple of 4) + * @retlen: the number of bytes actually read + * @buf: the filled in buffer * - * Reads flash memory OOB area of pages. + * Reads flash memory pages. This function does not read the OOB chunk, but only + * the page data. * * Returns 0 if read successfull, of -EIO, -EINVAL if an error occured */ -static int doc_read_oob(struct mtd_info *mtd, loff_t from, - struct mtd_oob_ops *ops) +static int doc_read(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, u_char *buf) { - struct docg3 *docg3 = mtd->priv; - int block0, block1, page, ofs, ret; - u8 *buf = ops->oobbuf; - size_t len = ops->ooblen; + struct mtd_oob_ops ops; + size_t ret; - doc_dbg("doc_read_oob(from=%lld, buf=%p, len=%zu)\n", from, buf, len); - if (len != DOC_LAYOUT_OOB_SIZE) - return -EINVAL; + memset(&ops, 0, sizeof(ops)); + ops.datbuf = buf; + ops.len = len; + ops.mode = MTD_OPS_AUTO_OOB; - switch (ops->mode) { - case MTD_OPS_PLACE_OOB: - buf += ops->ooboffs; - break; - default: - break; - } - - calc_block_sector(from, &block0, &block1, &page, &ofs); - if (block1 > docg3->max_block) - return -EINVAL; - - ret = doc_read_page_prepare(docg3, block0, block1, page, - ofs + DOC_LAYOUT_PAGE_SIZE); - if (!ret) - ret = doc_read_page_ecc_init(docg3, DOC_LAYOUT_OOB_SIZE); - if (!ret) - ret = doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE, - buf, 1); - doc_read_page_finish(docg3); - - if (ret > 0) - ops->oobretlen = ret; - else - ops->oobretlen = 0; - return (ret > 0) ? 0 : ret; + ret = doc_read_oob(mtd, from, &ops); + *retlen = ops.retlen; + return ret; } static int doc_reload_bbt(struct docg3 *docg3) -- cgit v1.2.3 From ae9d4934b2d76a9fba21f5ad3692378d0e7fc24b Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:48 +0100 Subject: mtd: docg3: add multiple floor support Add support for multiple floors, ie. cascaded docg3 chips. There might be 4 docg3 chips cascaded, sharing the same address space, and providing up to 4 times the storage capacity of a unique chip. Each floor will be seen as an independant mtd device. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 181 ++++++++++++++++++++++++++++++-------------- drivers/mtd/devices/docg3.h | 1 + 2 files changed, 126 insertions(+), 56 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 1c2f54d23c7e..6eca7f6c072c 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -948,7 +948,8 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) switch (chip_id) { case DOC_CHIPID_G3: - mtd->name = "DiskOnChip G3"; + mtd->name = kasprintf(GFP_KERNEL, "DiskOnChip G3 floor %d", + docg3->device_id); docg3->max_block = 2047; break; } @@ -975,22 +976,24 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) } /** - * doc_probe - Probe the IO space for a DiskOnChip G3 chip - * @pdev: platform device + * doc_probe_device - Check if a device is available + * @base: the io space where the device is probed + * @floor: the floor of the probed device + * @dev: the device * - * Probes for a G3 chip at the specified IO space in the platform data - * ressources. + * Checks whether a device at the specified IO range, and floor is available. * - * Returns 0 on success, -ENOMEM, -ENXIO on error + * Returns a mtd_info struct if there is a device, ENODEV if none found, ENOMEM + * if a memory allocation failed. If floor 0 is checked, a reset of the ASIC is + * launched. */ -static int __init docg3_probe(struct platform_device *pdev) +static struct mtd_info *doc_probe_device(void __iomem *base, int floor, + struct device *dev) { - struct device *dev = &pdev->dev; - struct docg3 *docg3; - struct mtd_info *mtd; - struct resource *ress; int ret, bbt_nbpages; u16 chip_id, chip_id_inv; + struct docg3 *docg3; + struct mtd_info *mtd; ret = -ENOMEM; docg3 = kzalloc(sizeof(struct docg3), GFP_KERNEL); @@ -1000,69 +1003,132 @@ static int __init docg3_probe(struct platform_device *pdev) if (!mtd) goto nomem2; mtd->priv = docg3; + bbt_nbpages = DIV_ROUND_UP(docg3->max_block + 1, + 8 * DOC_LAYOUT_PAGE_SIZE); + docg3->bbt = kzalloc(bbt_nbpages * DOC_LAYOUT_PAGE_SIZE, GFP_KERNEL); + if (!docg3->bbt) + goto nomem3; - ret = -ENXIO; - ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!ress) { - dev_err(dev, "No I/O memory resource defined\n"); - goto noress; - } - docg3->base = ioremap(ress->start, DOC_IOSPACE_SIZE); - - docg3->dev = &pdev->dev; - docg3->device_id = 0; + docg3->dev = dev; + docg3->device_id = floor; + docg3->base = base; doc_set_device_id(docg3, docg3->device_id); - doc_set_asic_mode(docg3, DOC_ASICMODE_RESET); + if (!floor) + doc_set_asic_mode(docg3, DOC_ASICMODE_RESET); doc_set_asic_mode(docg3, DOC_ASICMODE_NORMAL); chip_id = doc_register_readw(docg3, DOC_CHIPID); chip_id_inv = doc_register_readw(docg3, DOC_CHIPID_INV); - ret = -ENODEV; + ret = 0; if (chip_id != (u16)(~chip_id_inv)) { - doc_info("No device found at IO addr %p\n", - (void *)ress->start); - goto nochipfound; + goto nomem3; } switch (chip_id) { case DOC_CHIPID_G3: - doc_info("Found a G3 DiskOnChip at addr %p\n", - (void *)ress->start); + doc_info("Found a G3 DiskOnChip at addr %p, floor %d\n", + base, floor); break; default: doc_err("Chip id %04x is not a DiskOnChip G3 chip\n", chip_id); - goto nochipfound; + goto nomem3; } doc_set_driver_info(chip_id, mtd); - platform_set_drvdata(pdev, mtd); - ret = -ENOMEM; - bbt_nbpages = DIV_ROUND_UP(docg3->max_block + 1, - 8 * DOC_LAYOUT_PAGE_SIZE); - docg3->bbt = kzalloc(bbt_nbpages * DOC_LAYOUT_PAGE_SIZE, GFP_KERNEL); - if (!docg3->bbt) - goto nochipfound; doc_reload_bbt(docg3); + return mtd; - ret = mtd_device_parse_register(mtd, part_probes, - NULL, NULL, 0); - if (ret) - goto register_error; - - doc_dbg_register(docg3); - return 0; - -register_error: - kfree(docg3->bbt); -nochipfound: - iounmap(docg3->base); -noress: +nomem3: kfree(mtd); nomem2: kfree(docg3); nomem1: + return ERR_PTR(ret); +} + +/** + * doc_release_device - Release a docg3 floor + * @mtd: the device + */ +static void doc_release_device(struct mtd_info *mtd) +{ + struct docg3 *docg3 = mtd->priv; + + mtd_device_unregister(mtd); + kfree(docg3->bbt); + kfree(docg3); + kfree(mtd->name); + kfree(mtd); +} + +/** + * doc_probe - Probe the IO space for a DiskOnChip G3 chip + * @pdev: platform device + * + * Probes for a G3 chip at the specified IO space in the platform data + * ressources. The floor 0 must be available. + * + * Returns 0 on success, -ENOMEM, -ENXIO on error + */ +static int __init docg3_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct mtd_info *mtd; + struct resource *ress; + void __iomem *base; + int ret, floor, found = 0; + struct mtd_info **docg3_floors; + + ret = -ENXIO; + ress = platform_get_resource(pdev, IORESOURCE_MEM, 0); + if (!ress) { + dev_err(dev, "No I/O memory resource defined\n"); + goto noress; + } + base = ioremap(ress->start, DOC_IOSPACE_SIZE); + + ret = -ENOMEM; + docg3_floors = kzalloc(sizeof(*docg3_floors) * DOC_MAX_NBFLOORS, + GFP_KERNEL); + if (!docg3_floors) + goto nomem; + + ret = 0; + for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { + mtd = doc_probe_device(base, floor, dev); + if (floor == 0 && !mtd) + goto notfound; + if (!IS_ERR_OR_NULL(mtd)) + ret = mtd_device_parse_register(mtd, part_probes, + NULL, NULL, 0); + else + ret = PTR_ERR(mtd); + docg3_floors[floor] = mtd; + if (ret) + goto err_probe; + if (mtd) + found++; + } + + if (!found) + goto notfound; + + platform_set_drvdata(pdev, docg3_floors); + doc_dbg_register(docg3_floors[0]->priv); + return 0; + +notfound: + ret = -ENODEV; + dev_info(dev, "No supported DiskOnChip found\n"); +err_probe: + for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) + if (docg3_floors[floor]) + doc_release_device(docg3_floors[floor]); +nomem: + iounmap(base); +noress: return ret; } @@ -1074,15 +1140,18 @@ nomem1: */ static int __exit docg3_release(struct platform_device *pdev) { - struct mtd_info *mtd = platform_get_drvdata(pdev); - struct docg3 *docg3 = mtd->priv; + struct mtd_info **docg3_floors = platform_get_drvdata(pdev); + struct docg3 *docg3 = docg3_floors[0]->priv; + void __iomem *base = docg3->base; + int floor; doc_dbg_unregister(docg3); - mtd_device_unregister(mtd); - iounmap(docg3->base); - kfree(docg3->bbt); - kfree(docg3); - kfree(mtd); + for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) + if (docg3_floors[floor]) + doc_release_device(docg3_floors[floor]); + + kfree(docg3_floors); + iounmap(base); return 0; } diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 62af5aaeec43..75df3a1060fb 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -80,6 +80,7 @@ #define DOC_CHIPID_G3 0x200 #define DOC_ERASE_MARK 0xaa +#define DOC_MAX_NBFLOORS 4 /* * Flash registers */ -- cgit v1.2.3 From 732b63bd8c70bf8fbc50d3d3cd56c748edb8cfac Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:49 +0100 Subject: mtd: docg3: add OOB layout to mtdinfo Add OOB layout description for docg3, so that userspace can use this information to setup the data for write_oob(). Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 6eca7f6c072c..27c4feae132f 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -63,6 +63,20 @@ * */ +/** + * struct docg3_oobinfo - DiskOnChip G3 OOB layout + * @eccbytes: 8 bytes are used (1 for Hamming ECC, 7 for BCH ECC) + * @eccpos: ecc positions (byte 7 is Hamming ECC, byte 8-14 are BCH ECC) + * @oobfree: free pageinfo bytes (byte 0 until byte 6, byte 15 + * @oobavail: 8 available bytes remaining after ECC toll + */ +static struct nand_ecclayout docg3_oobinfo = { + .eccbytes = 8, + .eccpos = {7, 8, 9, 10, 11, 12, 13, 14}, + .oobfree = {{0, 7}, {15, 1} }, + .oobavail = 8, +}; + static inline u8 doc_readb(struct docg3 *docg3, u16 reg) { u8 val = readb(docg3->base + reg); @@ -973,6 +987,7 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) mtd->write_oob = NULL; mtd->sync = NULL; mtd->block_isbad = doc_block_isbad; + mtd->ecclayout = &docg3_oobinfo; } /** -- cgit v1.2.3 From 376fbf208700f2105d4047b198ca43e1d9db0b33 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:50 +0100 Subject: mtd: docg3: add registers for erasing and writing Add the required registers and commands to erase and write flash pages / blocks. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.h | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 75df3a1060fb..e9967aba80a8 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -130,6 +130,8 @@ #define DOC_SEQ_SET_PLANE1 0x0e #define DOC_SEQ_SET_PLANE2 0x10 #define DOC_SEQ_PAGE_SETUP 0x1d +#define DOC_SEQ_ERASE 0x27 +#define DOC_SEQ_PLANES_STATUS 0x31 /* * Flash commands @@ -144,7 +146,10 @@ #define DOC_CMD_PROG_BLOCK_ADDR 0x60 #define DOC_CMD_PROG_CYCLE1 0x80 #define DOC_CMD_PROG_CYCLE2 0x10 +#define DOC_CMD_PROG_CYCLE3 0x11 #define DOC_CMD_ERASECYCLE2 0xd0 +#define DOC_CMD_READ_STATUS 0x70 +#define DOC_CMD_PLANES_STATUS 0x71 #define DOC_CMD_RELIABLE_MODE 0x22 #define DOC_CMD_FAST_MODE 0xa2 @@ -186,7 +191,7 @@ */ #define DOC_ECCCONF1_BCH_SYNDROM_ERR 0x80 #define DOC_ECCCONF1_UNKOWN1 0x40 -#define DOC_ECCCONF1_UNKOWN2 0x20 +#define DOC_ECCCONF1_PAGE_IS_WRITTEN 0x20 #define DOC_ECCCONF1_UNKOWN3 0x10 #define DOC_ECCCONF1_HAMMING_BITS_MASK 0x0f @@ -224,6 +229,13 @@ #define DOC_READADDR_ONE_BYTE 0x4000 #define DOC_READADDR_ADDR_MASK 0x1fff +/* + * Status of erase and write operation + */ +#define DOC_PLANES_STATUS_FAIL 0x01 +#define DOC_PLANES_STATUS_PLANE0_KO 0x02 +#define DOC_PLANES_STATUS_PLANE1_KO 0x04 + /** * struct docg3 - DiskOnChip driver private data * @dev: the device currently under control -- cgit v1.2.3 From 316e627edcd8186f199120931f5381615a0d9aa4 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:51 +0100 Subject: mtd: docg3: add OOB buffer to device structure Add OOB buffer area to store the OOB data until the actual page is written, so that it can be completed by hardware ECC generator. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.h | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index e9967aba80a8..397e4616796e 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -243,6 +243,11 @@ * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3) * @if_cfg: if true, reads are on 16bits, else reads are on 8bits * @bbt: bad block table cache + * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next + * page_write) + * @oob_autoecc: if 1, use only bytes 0-7, 15, and fill the others with HW ECC + * if 0, use all the 16 bytes. + * @oob_write_buf: prepared OOB for next page_write * @debugfs_root: debugfs root node */ struct docg3 { @@ -252,6 +257,9 @@ struct docg3 { unsigned int if_cfg:1; int max_block; u8 *bbt; + loff_t oob_write_ofs; + int oob_autoecc; + u8 oob_write_buf[DOC_LAYOUT_OOB_SIZE]; struct dentry *debugfs_root; }; -- cgit v1.2.3 From fb50b58e488d5fb3e3600592646909ddad7bd1e5 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:52 +0100 Subject: mtd: docg3: add write functions Add write capability to the docg3 driver. The writes are possible on a single page (512 bytes + 16 bytes), even if that page is split on 2 physical pages on 2 blocks (each on one plane). Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 553 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 541 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 27c4feae132f..fd4d47bdeec2 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -253,6 +253,40 @@ static void doc_read_data_area(struct docg3 *docg3, void *buf, int len, } } +/** + * doc_write_data_area - Write data into data area + * @docg3: the device + * @buf: the buffer to get input bytes from + * @len: the length to write + * + * Writes bytes into flash data. Handles the single byte / even bytes writes. + */ +static void doc_write_data_area(struct docg3 *docg3, const void *buf, int len) +{ + int i, cdr, len4; + u16 *src16; + u8 *src8; + + doc_dbg("doc_write_data_area(buf=%p, len=%d)\n", buf, len); + cdr = len & 0x3; + len4 = len - cdr; + + doc_writew(docg3, DOC_IOSPACE_DATA, DOC_READADDRESS); + src16 = (u16 *)buf; + for (i = 0; i < len4; i += 2) { + doc_writew(docg3, *src16, DOC_IOSPACE_DATA); + src16++; + } + + src8 = (u8 *)src16; + for (i = 0; i < cdr; i++) { + doc_writew(docg3, DOC_IOSPACE_DATA | DOC_READADDR_ONE_BYTE, + DOC_READADDRESS); + doc_writeb(docg3, *src8, DOC_IOSPACE_DATA); + src8++; + } +} + /** * doc_set_data_mode - Sets the flash to reliable data mode * @docg3: the device @@ -342,6 +376,37 @@ static int doc_set_extra_page_mode(struct docg3 *docg3) return 0; } +/** + * doc_setup_addr_sector - Setup blocks/page/ofs address for one plane + * @docg3: the device + * @sector: the sector + */ +static void doc_setup_addr_sector(struct docg3 *docg3, int sector) +{ + doc_delay(docg3, 1); + doc_flash_address(docg3, sector & 0xff); + doc_flash_address(docg3, (sector >> 8) & 0xff); + doc_flash_address(docg3, (sector >> 16) & 0xff); + doc_delay(docg3, 1); +} + +/** + * doc_setup_writeaddr_sector - Setup blocks/page/ofs address for one plane + * @docg3: the device + * @sector: the sector + * @ofs: the offset in the page, between 0 and (512 + 16 + 512) + */ +static void doc_setup_writeaddr_sector(struct docg3 *docg3, int sector, int ofs) +{ + ofs = ofs >> 2; + doc_delay(docg3, 1); + doc_flash_address(docg3, ofs & 0xff); + doc_flash_address(docg3, sector & 0xff); + doc_flash_address(docg3, (sector >> 8) & 0xff); + doc_flash_address(docg3, (sector >> 16) & 0xff); + doc_delay(docg3, 1); +} + /** * doc_seek - Set both flash planes to the specified block, page for reading * @docg3: the device @@ -378,27 +443,73 @@ static int doc_read_seek(struct docg3 *docg3, int block0, int block1, int page, if (ret) goto out; - sector = (block0 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK); doc_flash_sequence(docg3, DOC_SEQ_READ); + sector = (block0 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK); doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR); - doc_delay(docg3, 1); - doc_flash_address(docg3, sector & 0xff); - doc_flash_address(docg3, (sector >> 8) & 0xff); - doc_flash_address(docg3, (sector >> 16) & 0xff); - doc_delay(docg3, 1); + doc_setup_addr_sector(docg3, sector); sector = (block1 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK); doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR); + doc_setup_addr_sector(docg3, sector); doc_delay(docg3, 1); - doc_flash_address(docg3, sector & 0xff); - doc_flash_address(docg3, (sector >> 8) & 0xff); - doc_flash_address(docg3, (sector >> 16) & 0xff); + +out: + return ret; +} + +/** + * doc_write_seek - Set both flash planes to the specified block, page for writing + * @docg3: the device + * @block0: the first plane block index + * @block1: the second plane block index + * @page: the page index within the block + * @ofs: offset in page to write + * + * Programs the flash even and odd planes to the specific block and page. + * Alternatively, programs the flash to the wear area of the specified page. + */ +static int doc_write_seek(struct docg3 *docg3, int block0, int block1, int page, + int ofs) +{ + int ret = 0, sector; + + doc_dbg("doc_write_seek(blocks=(%d,%d), page=%d, ofs=%d)\n", + block0, block1, page, ofs); + + doc_set_reliable_mode(docg3); + + if (ofs < 2 * DOC_LAYOUT_PAGE_SIZE) { + doc_flash_sequence(docg3, DOC_SEQ_SET_PLANE1); + doc_flash_command(docg3, DOC_CMD_READ_PLANE1); + doc_delay(docg3, 2); + } else { + doc_flash_sequence(docg3, DOC_SEQ_SET_PLANE2); + doc_flash_command(docg3, DOC_CMD_READ_PLANE2); + doc_delay(docg3, 2); + } + + doc_flash_sequence(docg3, DOC_SEQ_PAGE_SETUP); + doc_flash_command(docg3, DOC_CMD_PROG_CYCLE1); + + sector = (block0 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK); + doc_setup_writeaddr_sector(docg3, sector, ofs); + + doc_flash_command(docg3, DOC_CMD_PROG_CYCLE3); doc_delay(docg3, 2); + ret = doc_wait_ready(docg3); + if (ret) + goto out; + + doc_flash_command(docg3, DOC_CMD_PROG_CYCLE1); + sector = (block1 << DOC_ADDR_BLOCK_SHIFT) + (page & DOC_ADDR_PAGE_MASK); + doc_setup_writeaddr_sector(docg3, sector, ofs); + doc_delay(docg3, 1); out: return ret; } + /** * doc_read_page_ecc_init - Initialize hardware ECC engine * @docg3: the device @@ -420,6 +531,58 @@ static int doc_read_page_ecc_init(struct docg3 *docg3, int len) return doc_wait_ready(docg3); } +/** + * doc_write_page_ecc_init - Initialize hardware BCH ECC engine + * @docg3: the device + * @len: the number of bytes covered by the ECC (BCH covered) + * + * The function does initialize the hardware ECC engine to compute the Hamming + * ECC (on 1 byte) and the BCH Syndroms (on 7 bytes). + * + * Return 0 if succeeded, -EIO on error + */ +static int doc_write_page_ecc_init(struct docg3 *docg3, int len) +{ + doc_writew(docg3, !DOC_ECCCONF0_READ_MODE + | DOC_ECCCONF0_BCH_ENABLE | DOC_ECCCONF0_HAMMING_ENABLE + | (len & DOC_ECCCONF0_DATA_BYTES_MASK), + DOC_ECCCONF0); + doc_delay(docg3, 4); + doc_register_readb(docg3, DOC_FLASHCONTROL); + return doc_wait_ready(docg3); +} + +/** + * doc_ecc_disable - Disable Hamming and BCH ECC hardware calculator + * @docg3: the device + * + * Disables the hardware ECC generator and checker, for unchecked reads (as when + * reading OOB only or write status byte). + */ +static void doc_ecc_disable(struct docg3 *docg3) +{ + doc_writew(docg3, DOC_ECCCONF0_READ_MODE, DOC_ECCCONF0); + doc_delay(docg3, 4); +} + +/** + * doc_hamming_ecc_init - Initialize hardware Hamming ECC engine + * @docg3: the device + * @nb_bytes: the number of bytes covered by the ECC (Hamming covered) + * + * This function programs the ECC hardware to compute the hamming code on the + * last provided N bytes to the hardware generator. + */ +static void doc_hamming_ecc_init(struct docg3 *docg3, int nb_bytes) +{ + u8 ecc_conf1; + + ecc_conf1 = doc_register_readb(docg3, DOC_ECCCONF1); + ecc_conf1 &= ~DOC_ECCCONF1_HAMMING_BITS_MASK; + ecc_conf1 |= (nb_bytes & DOC_ECCCONF1_HAMMING_BITS_MASK); + doc_writeb(docg3, ecc_conf1, DOC_ECCCONF1); +} + /** * doc_read_page_prepare - Prepares reading data from a flash page * @docg3: the device @@ -505,12 +668,26 @@ static int doc_read_page_getbytes(struct docg3 *docg3, int len, u_char *buf, return len; } +/** + * doc_write_page_putbytes - Writes bytes into a prepared page + * @docg3: the device + * @len: the number of bytes to be written + * @buf: the buffer of input bytes + * + */ +static void doc_write_page_putbytes(struct docg3 *docg3, int len, + const u_char *buf) +{ + doc_write_data_area(docg3, buf, len); + doc_delay(docg3, 2); +} + /** * doc_get_hw_bch_syndroms - Get hardware calculated BCH syndroms * @docg3: the device * @syns: the array of 7 integers where the syndroms will be stored */ -static void doc_get_hw_bch_syndroms(struct docg3 *docg3, int *syns) +static void doc_get_hw_bch_syndroms(struct docg3 *docg3, u8 *syns) { int i; @@ -518,6 +695,16 @@ static void doc_get_hw_bch_syndroms(struct docg3 *docg3, int *syns) syns[i] = doc_register_readb(docg3, DOC_BCH_SYNDROM(i)); } +/** + * doc_page_finish - Ends reading/writing of a flash page + * @docg3: the device + */ +static void doc_page_finish(struct docg3 *docg3) +{ + doc_writeb(docg3, 0, DOC_DATAEND); + doc_delay(docg3, 2); +} + /** * doc_read_page_finish - Ends reading of a flash page * @docg3: the device @@ -528,8 +715,7 @@ static void doc_get_hw_bch_syndroms(struct docg3 *docg3, int *syns) */ static void doc_read_page_finish(struct docg3 *docg3) { - doc_writeb(docg3, 0, DOC_DATAEND); - doc_delay(docg3, 2); + doc_page_finish(docg3); doc_set_device_id(docg3, 0); } @@ -791,6 +977,348 @@ static int doc_get_erase_count(struct docg3 *docg3, loff_t from) return max(plane1_erase_count, plane2_erase_count); } +/** + * doc_get_op_status - get erase/write operation status + * @docg3: the device + * + * Queries the status from the chip, and returns it + * + * Returns the status (bits DOC_PLANES_STATUS_*) + */ +static int doc_get_op_status(struct docg3 *docg3) +{ + u8 status; + + doc_flash_sequence(docg3, DOC_SEQ_PLANES_STATUS); + doc_flash_command(docg3, DOC_CMD_PLANES_STATUS); + doc_delay(docg3, 5); + + doc_ecc_disable(docg3); + doc_read_data_area(docg3, &status, 1, 1); + return status; +} + +/** + * doc_write_erase_wait_status - wait for write or erase completion + * @docg3: the device + * + * Wait for the chip to be ready again after erase or write operation, and check + * erase/write status. + * + * Returns 0 if erase successfull, -EIO if erase/write issue, -ETIMEOUT if + * timeout + */ +static int doc_write_erase_wait_status(struct docg3 *docg3) +{ + int status, ret = 0; + + if (!doc_is_ready(docg3)) + usleep_range(3000, 3000); + if (!doc_is_ready(docg3)) { + doc_dbg("Timeout reached and the chip is still not ready\n"); + ret = -EAGAIN; + goto out; + } + + status = doc_get_op_status(docg3); + if (status & DOC_PLANES_STATUS_FAIL) { + doc_dbg("Erase/Write failed on (a) plane(s), status = %x\n", + status); + ret = -EIO; + } + +out: + doc_page_finish(docg3); + return ret; +} + +/** + * doc_write_page - Write a single page to the chip + * @docg3: the device + * @to: the offset from first block and first page, in bytes, aligned on page + * size + * @buf: buffer to get bytes from + * @oob: buffer to get out of band bytes from (can be NULL if no OOB should be + * written) + * @autoecc: if 0, all 16 bytes from OOB are taken, regardless of HW Hamming or + * BCH computations. If 1, only bytes 0-7 and byte 15 are taken, + * remaining ones are filled with hardware Hamming and BCH + * computations. Its value is not meaningfull is oob == NULL. + * + * Write one full page (ie. 1 page split on two planes), of 512 bytes, with the + * OOB data. The OOB ECC is automatically computed by the hardware Hamming and + * BCH generator if autoecc is not null. + * + * Returns 0 if write successful, -EIO if write error, -EAGAIN if timeout + */ +static int doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, + const u_char *oob, int autoecc) +{ + int block0, block1, page, ret, ofs = 0; + u8 syn[DOC_ECC_BCH_SIZE], hamming; + + doc_dbg("doc_write_page(to=%lld)\n", to); + calc_block_sector(to, &block0, &block1, &page, &ofs); + + doc_set_device_id(docg3, docg3->device_id); + ret = doc_reset_seq(docg3); + if (ret) + goto err; + + /* Program the flash address block and page */ + ret = doc_write_seek(docg3, block0, block1, page, ofs); + if (ret) + goto err; + + doc_write_page_ecc_init(docg3, DOC_ECC_BCH_COVERED_BYTES); + doc_delay(docg3, 2); + doc_write_page_putbytes(docg3, DOC_LAYOUT_PAGE_SIZE, buf); + + if (oob && autoecc) { + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_PAGEINFO_SZ, oob); + doc_delay(docg3, 2); + oob += DOC_LAYOUT_OOB_UNUSED_OFS; + + hamming = doc_register_readb(docg3, DOC_HAMMINGPARITY); + doc_delay(docg3, 2); + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_HAMMING_SZ, + &hamming); + doc_delay(docg3, 2); + + doc_get_hw_bch_syndroms(docg3, syn); + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_BCH_SZ, syn); + doc_delay(docg3, 2); + + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_UNUSED_SZ, oob); + } + if (oob && !autoecc) + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_SIZE, oob); + + doc_delay(docg3, 2); + doc_page_finish(docg3); + doc_delay(docg3, 2); + doc_flash_command(docg3, DOC_CMD_PROG_CYCLE2); + doc_delay(docg3, 2); + + /* + * The wait status will perform another doc_page_finish() call, but that + * seems to please the docg3, so leave it. + */ + ret = doc_write_erase_wait_status(docg3); + return ret; +err: + doc_read_page_finish(docg3); + return ret; +} + +/** + * doc_guess_autoecc - Guess autoecc mode from mbd_oob_ops + * @ops: the oob operations + * + * Returns 0 or 1 if success, -EINVAL if invalid oob mode + */ +static int doc_guess_autoecc(struct mtd_oob_ops *ops) +{ + int autoecc; + + switch (ops->mode) { + case MTD_OPS_PLACE_OOB: + case MTD_OPS_AUTO_OOB: + autoecc = 1; + break; + case MTD_OPS_RAW: + autoecc = 0; + break; + default: + autoecc = -EINVAL; + } + return autoecc; +} + +/** + * doc_fill_autooob - Fill a 16 bytes OOB from 8 non-ECC bytes + * @dst: the target 16 bytes OOB buffer + * @oobsrc: the source 8 bytes non-ECC OOB buffer + * + */ +static void doc_fill_autooob(u8 *dst, u8 *oobsrc) +{ + memcpy(dst, oobsrc, DOC_LAYOUT_OOB_PAGEINFO_SZ); + dst[DOC_LAYOUT_OOB_UNUSED_OFS] = oobsrc[DOC_LAYOUT_OOB_PAGEINFO_SZ]; +} + +/** + * doc_backup_oob - Backup OOB into docg3 structure + * @docg3: the device + * @to: the page offset in the chip + * @ops: the OOB size and buffer + * + * As the docg3 should write a page with its OOB in one pass, and some userland + * applications do write_oob() to setup the OOB and then write(), store the OOB + * into a temporary storage. This is very dangerous, as 2 concurrent + * applications could store an OOB, and then write their pages (which will + * result into one having its OOB corrupted). + * + * The only reliable way would be for userland to call doc_write_oob() with both + * the page data _and_ the OOB area. + * + * Returns 0 if success, -EINVAL if ops content invalid + */ +static int doc_backup_oob(struct docg3 *docg3, loff_t to, + struct mtd_oob_ops *ops) +{ + int ooblen = ops->ooblen, autoecc; + + if (ooblen != DOC_LAYOUT_OOB_SIZE) + return -EINVAL; + autoecc = doc_guess_autoecc(ops); + if (autoecc < 0) + return autoecc; + + docg3->oob_write_ofs = to; + docg3->oob_autoecc = autoecc; + if (ops->mode == MTD_OPS_AUTO_OOB) { + doc_fill_autooob(docg3->oob_write_buf, ops->oobbuf); + ops->oobretlen = 8; + } else { + memcpy(docg3->oob_write_buf, ops->oobbuf, DOC_LAYOUT_OOB_SIZE); + ops->oobretlen = DOC_LAYOUT_OOB_SIZE; + } + return 0; +} + +/** + * doc_write_oob - Write out of band bytes to flash + * @mtd: the device + * @ofs: the offset from first block and first page, in bytes, aligned on page + * size + * @ops: the mtd oob structure + * + * Either write OOB data into a temporary buffer, for the subsequent write + * page. The provided OOB should be 16 bytes long. If a data buffer is provided + * as well, issue the page write. + * Or provide data without OOB, and then a all zeroed OOB will be used (ECC will + * still be filled in if asked for). + * + * Returns 0 is successfull, EINVAL if length is not 14 bytes + */ +static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, + struct mtd_oob_ops *ops) +{ + struct docg3 *docg3 = mtd->priv; + int block0, block1, page, ret, pofs = 0, autoecc, oobdelta; + u8 *oobbuf = ops->oobbuf; + u8 *buf = ops->datbuf; + size_t len, ooblen; + u8 oob[DOC_LAYOUT_OOB_SIZE]; + + if (buf) + len = ops->len; + else + len = 0; + if (oobbuf) + ooblen = ops->ooblen; + else + ooblen = 0; + + if (oobbuf && ops->mode == MTD_OPS_PLACE_OOB) + oobbuf += ops->ooboffs; + + doc_dbg("doc_write_oob(from=%lld, mode=%d, data=(%p:%zu), oob=(%p:%zu))\n", + ofs, ops->mode, buf, len, oobbuf, ooblen); + switch (ops->mode) { + case MTD_OPS_PLACE_OOB: + case MTD_OPS_RAW: + oobdelta = mtd->oobsize; + break; + case MTD_OPS_AUTO_OOB: + oobdelta = mtd->ecclayout->oobavail; + break; + default: + oobdelta = 0; + } + if ((len % DOC_LAYOUT_PAGE_SIZE) || (ooblen % oobdelta) || + (ofs % DOC_LAYOUT_PAGE_SIZE)) + return -EINVAL; + if (len && ooblen && + (len / DOC_LAYOUT_PAGE_SIZE) != (ooblen / oobdelta)) + return -EINVAL; + + ret = -EINVAL; + calc_block_sector(ofs + len, &block0, &block1, &page, &pofs); + if (block1 > docg3->max_block) + goto err; + + ops->oobretlen = 0; + ops->retlen = 0; + ret = 0; + if (len == 0 && ooblen == 0) + return -EINVAL; + if (len == 0 && ooblen > 0) + return doc_backup_oob(docg3, ofs, ops); + + autoecc = doc_guess_autoecc(ops); + if (autoecc < 0) + return autoecc; + + while (!ret && len > 0) { + memset(oob, 0, sizeof(oob)); + if (ofs == docg3->oob_write_ofs) + memcpy(oob, docg3->oob_write_buf, DOC_LAYOUT_OOB_SIZE); + else if (ooblen > 0 && ops->mode == MTD_OPS_AUTO_OOB) + doc_fill_autooob(oob, oobbuf); + else if (ooblen > 0) + memcpy(oob, oobbuf, DOC_LAYOUT_OOB_SIZE); + ret = doc_write_page(docg3, ofs, buf, oob, autoecc); + + ofs += DOC_LAYOUT_PAGE_SIZE; + len -= DOC_LAYOUT_PAGE_SIZE; + buf += DOC_LAYOUT_PAGE_SIZE; + if (ooblen) { + oobbuf += oobdelta; + ooblen -= oobdelta; + ops->oobretlen += oobdelta; + } + ops->retlen += DOC_LAYOUT_PAGE_SIZE; + } +err: + doc_set_device_id(docg3, 0); + return ret; +} + +/** + * doc_write - Write a buffer to the chip + * @mtd: the device + * @to: the offset from first block and first page, in bytes, aligned on page + * size + * @len: the number of bytes to write (must be a full page size, ie. 512) + * @retlen: the number of bytes actually written (0 or 512) + * @buf: the buffer to get bytes from + * + * Writes data to the chip. + * + * Returns 0 if write successful, -EIO if write error + */ +static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf) +{ + struct docg3 *docg3 = mtd->priv; + int ret; + struct mtd_oob_ops ops; + + doc_dbg("doc_write(to=%lld, len=%zu)\n", to, len); + ops.datbuf = (char *)buf; + ops.len = len; + ops.mode = MTD_OPS_PLACE_OOB; + ops.oobbuf = NULL; + ops.ooblen = 0; + ops.ooboffs = 0; + + ret = doc_write_oob(mtd, to, &ops); + *retlen = ops.retlen; + return ret; +} + /* * Debug sysfs entries */ @@ -1052,6 +1580,7 @@ static struct mtd_info *doc_probe_device(void __iomem *base, int floor, doc_set_driver_info(chip_id, mtd); + doc_hamming_ecc_init(docg3, DOC_LAYOUT_OOB_PAGEINFO_SZ); doc_reload_bbt(docg3); return mtd; -- cgit v1.2.3 From de03cd716ba7b8103ef9bef425be1ac72b81aeca Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:53 +0100 Subject: mtd: docg3: add erase functions Add erase capability to the docg3 driver. The erase block is made of 2 physical blocks, as both share all 64 pages. That makes an erase block of at least 64 kBytes. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 90 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index fd4d47bdeec2..3087b1564a4d 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1032,6 +1032,96 @@ out: return ret; } +/** + * doc_erase_block - Erase a couple of blocks + * @docg3: the device + * @block0: the first block to erase (leftmost plane) + * @block1: the second block to erase (rightmost plane) + * + * Erase both blocks, and return operation status + * + * Returns 0 if erase successful, -EIO if erase issue, -ETIMEOUT if chip not + * ready for too long + */ +static int doc_erase_block(struct docg3 *docg3, int block0, int block1) +{ + int ret, sector; + + doc_dbg("doc_erase_block(blocks=(%d,%d))\n", block0, block1); + ret = doc_reset_seq(docg3); + if (ret) + return -EIO; + + doc_set_reliable_mode(docg3); + doc_flash_sequence(docg3, DOC_SEQ_ERASE); + + sector = block0 << DOC_ADDR_BLOCK_SHIFT; + doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR); + doc_setup_addr_sector(docg3, sector); + sector = block1 << DOC_ADDR_BLOCK_SHIFT; + doc_flash_command(docg3, DOC_CMD_PROG_BLOCK_ADDR); + doc_setup_addr_sector(docg3, sector); + doc_delay(docg3, 1); + + doc_flash_command(docg3, DOC_CMD_ERASECYCLE2); + doc_delay(docg3, 2); + + if (is_prot_seq_error(docg3)) { + doc_err("Erase blocks %d,%d error\n", block0, block1); + return -EIO; + } + + return doc_write_erase_wait_status(docg3); +} + +/** + * doc_erase - Erase a portion of the chip + * @mtd: the device + * @info: the erase info + * + * Erase a bunch of contiguous blocks, by pairs, as a "mtd" page of 1024 is + * split into 2 pages of 512 bytes on 2 contiguous blocks. + * + * Returns 0 if erase successful, -EINVAL if adressing error, -EIO if erase + * issue + */ +static int doc_erase(struct mtd_info *mtd, struct erase_info *info) +{ + struct docg3 *docg3 = mtd->priv; + uint64_t len; + int block0, block1, page, ret, ofs = 0; + + doc_dbg("doc_erase(from=%lld, len=%lld\n", info->addr, info->len); + doc_set_device_id(docg3, docg3->device_id); + + info->state = MTD_ERASE_PENDING; + calc_block_sector(info->addr + info->len, + &block0, &block1, &page, &ofs); + ret = -EINVAL; + if (block1 > docg3->max_block || page || ofs) + goto reset_err; + + ret = 0; + calc_block_sector(info->addr, &block0, &block1, &page, &ofs); + doc_set_reliable_mode(docg3); + for (len = info->len; !ret && len > 0; len -= mtd->erasesize) { + info->state = MTD_ERASING; + ret = doc_erase_block(docg3, block0, block1); + block0 += 2; + block1 += 2; + } + + if (ret) + goto reset_err; + + info->state = MTD_ERASE_DONE; + return 0; + +reset_err: + info->state = MTD_ERASE_FAILED; + return ret; +} + /** * doc_write_page - Write a single page to the chip * @docg3: the device -- cgit v1.2.3 From 7a7fcf14021bc0f0728dd0aaa2635475de0db54c Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:54 +0100 Subject: mtd: docg3: map erase and write functions Map the developped write and erase functions into the mtd structure. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 3087b1564a4d..1f949eac6351 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -41,8 +41,6 @@ * * As no specification is available from M-Systems/Sandisk, this drivers lacks * several functions available on the chip, as : - * - block erase - * - page write * - IPL write * - ECC fixing (lack of BCH algorith understanding) * - powerdown / powerup @@ -1586,23 +1584,19 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) break; } mtd->type = MTD_NANDFLASH; - /* - * Once write methods are added, the correct flags will be set. - * mtd->flags = MTD_CAP_NANDFLASH; - */ - mtd->flags = MTD_CAP_ROM; + mtd->flags = MTD_CAP_NANDFLASH; mtd->size = (docg3->max_block + 1) * DOC_LAYOUT_BLOCK_SIZE; mtd->erasesize = DOC_LAYOUT_BLOCK_SIZE * DOC_LAYOUT_NBPLANES; mtd->writesize = DOC_LAYOUT_PAGE_SIZE; mtd->oobsize = DOC_LAYOUT_OOB_SIZE; mtd->owner = THIS_MODULE; - mtd->erase = NULL; + mtd->erase = doc_erase; mtd->point = NULL; mtd->unpoint = NULL; mtd->read = doc_read; - mtd->write = NULL; + mtd->write = doc_write; mtd->read_oob = doc_read_oob; - mtd->write_oob = NULL; + mtd->write_oob = doc_write_oob; mtd->sync = NULL; mtd->block_isbad = doc_block_isbad; mtd->ecclayout = &docg3_oobinfo; -- cgit v1.2.3 From d13d19ece39f20bf097782e1812a9c31a5a4fcf1 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:55 +0100 Subject: mtd: docg3: add ECC correction code Credit for discovering the BCH algorith parameters, and bit reversing algorithm is to be give to Mike Dunn and Ivan Djelic. The BCH correction code relied upon the BCH library, where all data and ECC is bit-reversed. The BCH library works correctly when each input byte is bit-reversed, and accordingly ECC output is also bit-reversed. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/Kconfig | 9 ++++ drivers/mtd/devices/docg3.c | 116 +++++++++++++++++++++++++++++++++++--------- drivers/mtd/devices/docg3.h | 11 ++++- 3 files changed, 113 insertions(+), 23 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 283d887f7825..952e956ef01d 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -251,6 +251,8 @@ config MTD_DOC2001PLUS config MTD_DOCG3 tristate "M-Systems Disk-On-Chip G3" + select BCH + select BCH_CONST_PARAMS ---help--- This provides an MTD device driver for the M-Systems DiskOnChip G3 devices. @@ -259,6 +261,13 @@ config MTD_DOCG3 M-Systems and now Sandisk. The support is very experimental, and doesn't give access to any write operations. +if MTD_DOCG3 +config BCH_CONST_M + default 14 +config BCH_CONST_T + default 4 +endif + config MTD_DOCPROBE tristate select MTD_DOCECC diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 1f949eac6351..26cc17909b16 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -29,6 +29,9 @@ #include #include #include +#include +#include +#include #include #include @@ -42,7 +45,6 @@ * As no specification is available from M-Systems/Sandisk, this drivers lacks * several functions available on the chip, as : * - IPL write - * - ECC fixing (lack of BCH algorith understanding) * - powerdown / powerup * * The bus data width (8bits versus 16bits) is not handled (if_cfg flag), and @@ -51,8 +53,7 @@ * DocG3 relies on 2 ECC algorithms, which are handled in hardware : * - a 1 byte Hamming code stored in the OOB for each page * - a 7 bytes BCH code stored in the OOB for each page - * The BCH part is only used for check purpose, no correction is available as - * some information is missing. What is known is that : + * The BCH ECC is : * - BCH is in GF(2^14) * - BCH is over data of 520 bytes (512 page + 7 page_info bytes * + 1 hamming byte) @@ -75,6 +76,11 @@ static struct nand_ecclayout docg3_oobinfo = { .oobavail = 8, }; +/** + * struct docg3_bch - BCH engine + */ +static struct bch_control *docg3_bch; + static inline u8 doc_readb(struct docg3 *docg3, u16 reg) { u8 val = readb(docg3->base + reg); @@ -581,6 +587,54 @@ static void doc_hamming_ecc_init(struct docg3 *docg3, int nb_bytes) doc_writeb(docg3, ecc_conf1, DOC_ECCCONF1); } +/** + * doc_correct_data - Fix if need be read data from flash + * @docg3: the device + * @buf: the buffer of read data (512 + 7 + 1 bytes) + * @hwecc: the hardware calculated ECC. + * It's in fact recv_ecc ^ calc_ecc, where recv_ecc was read from OOB + * area data, and calc_ecc the ECC calculated by the hardware generator. + * + * Checks if the received data matches the ECC, and if an error is detected, + * tries to fix the bit flips (at most 4) in the buffer buf. As the docg3 + * understands the (data, ecc, syndroms) in an inverted order in comparison to + * the BCH library, the function reverses the order of bits (ie. bit7 and bit0, + * bit6 and bit 1, ...) for all ECC data. + * + * The hardware ecc unit produces oob_ecc ^ calc_ecc. The kernel's bch + * algorithm is used to decode this. However the hw operates on page + * data in a bit order that is the reverse of that of the bch alg, + * requiring that the bits be reversed on the result. Thanks to Ivan + * Djelic for his analysis. + * + * Returns number of fixed bits (0, 1, 2, 3, 4) or -EBADMSG if too many bit + * errors were detected and cannot be fixed. + */ +static int doc_ecc_bch_fix_data(struct docg3 *docg3, void *buf, u8 *hwecc) +{ + u8 ecc[DOC_ECC_BCH_SIZE]; + int errorpos[DOC_ECC_BCH_T], i, numerrs; + + for (i = 0; i < DOC_ECC_BCH_SIZE; i++) + ecc[i] = bitrev8(hwecc[i]); + numerrs = decode_bch(docg3_bch, NULL, DOC_ECC_BCH_COVERED_BYTES, + NULL, ecc, NULL, errorpos); + BUG_ON(numerrs == -EINVAL); + if (numerrs < 0) + goto out; + + for (i = 0; i < numerrs; i++) + errorpos[i] = (errorpos[i] & ~7) | (7 - (errorpos[i] & 7)); + for (i = 0; i < numerrs; i++) + if (errorpos[i] < DOC_ECC_BCH_COVERED_BYTES*8) + /* error is located in data, correct it */ + change_bit(errorpos[i], buf); +out: + doc_dbg("doc_ecc_bch_fix_data: flipped %d bits\n", numerrs); + return numerrs; +} + + /** * doc_read_page_prepare - Prepares reading data from a flash page * @docg3: the device @@ -762,7 +816,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, u8 *oobbuf = ops->oobbuf; u8 *buf = ops->datbuf; size_t len, ooblen, nbdata, nboob; - u8 calc_ecc[DOC_ECC_BCH_SIZE], eccconf1; + u8 hwecc[DOC_ECC_BCH_SIZE], eccconf1; if (buf) len = ops->len; @@ -797,7 +851,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, ret = doc_read_page_prepare(docg3, block0, block1, page, ofs); if (ret < 0) goto err; - ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_COVERED_BYTES); + ret = doc_read_page_ecc_init(docg3, DOC_ECC_BCH_TOTAL_BYTES); if (ret < 0) goto err_in_read; ret = doc_read_page_getbytes(docg3, nbdata, buf, 1); @@ -811,7 +865,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob, NULL, 0); - doc_get_hw_bch_syndroms(docg3, calc_ecc); + doc_get_hw_bch_syndroms(docg3, hwecc); eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1); if (nboob >= DOC_LAYOUT_OOB_SIZE) { @@ -825,18 +879,28 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, doc_dbg("OOB - UNUSED: %02x\n", oobbuf[15]); } doc_dbg("ECC checks: ECCConf1=%x\n", eccconf1); - doc_dbg("ECC CALC_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", - calc_ecc[0], calc_ecc[1], calc_ecc[2], - calc_ecc[3], calc_ecc[4], calc_ecc[5], - calc_ecc[6]); - - ret = -EBADMSG; - if (block0 >= DOC_LAYOUT_BLOCK_FIRST_DATA) { - if ((eccconf1 & DOC_ECCCONF1_BCH_SYNDROM_ERR) && - (eccconf1 & DOC_ECCCONF1_PAGE_IS_WRITTEN)) - goto err_in_read; - if (is_prot_seq_error(docg3)) - goto err_in_read; + doc_dbg("ECC HW_ECC: %02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + hwecc[0], hwecc[1], hwecc[2], hwecc[3], hwecc[4], + hwecc[5], hwecc[6]); + + ret = -EIO; + if (is_prot_seq_error(docg3)) + goto err_in_read; + ret = 0; + if ((block0 >= DOC_LAYOUT_BLOCK_FIRST_DATA) && + (eccconf1 & DOC_ECCCONF1_BCH_SYNDROM_ERR) && + (eccconf1 & DOC_ECCCONF1_PAGE_IS_WRITTEN) && + (ops->mode != MTD_OPS_RAW) && + (nbdata == DOC_LAYOUT_PAGE_SIZE)) { + ret = doc_ecc_bch_fix_data(docg3, buf, hwecc); + if (ret < 0) { + mtd->ecc_stats.failed++; + ret = -EBADMSG; + } + if (ret > 0) { + mtd->ecc_stats.corrected += ret; + ret = -EUCLEAN; + } } doc_read_page_finish(docg3); @@ -849,7 +913,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, from += DOC_LAYOUT_PAGE_SIZE; } - return 0; + return ret; err_in_read: doc_read_page_finish(docg3); err: @@ -1158,7 +1222,7 @@ static int doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, if (ret) goto err; - doc_write_page_ecc_init(docg3, DOC_ECC_BCH_COVERED_BYTES); + doc_write_page_ecc_init(docg3, DOC_ECC_BCH_TOTAL_BYTES); doc_delay(docg3, 2); doc_write_page_putbytes(docg3, DOC_LAYOUT_PAGE_SIZE, buf); @@ -1721,7 +1785,11 @@ static int __init docg3_probe(struct platform_device *pdev) docg3_floors = kzalloc(sizeof(*docg3_floors) * DOC_MAX_NBFLOORS, GFP_KERNEL); if (!docg3_floors) - goto nomem; + goto nomem1; + docg3_bch = init_bch(DOC_ECC_BCH_M, DOC_ECC_BCH_T, + DOC_ECC_BCH_PRIMPOLY); + if (!docg3_bch) + goto nomem2; ret = 0; for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { @@ -1751,10 +1819,13 @@ notfound: ret = -ENODEV; dev_info(dev, "No supported DiskOnChip found\n"); err_probe: + free_bch(docg3_bch); for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) if (docg3_floors[floor]) doc_release_device(docg3_floors[floor]); -nomem: +nomem2: + kfree(docg3_floors); +nomem1: iounmap(base); noress: return ret; @@ -1779,6 +1850,7 @@ static int __exit docg3_release(struct platform_device *pdev) doc_release_device(docg3_floors[floor]); kfree(docg3_floors); + free_bch(docg3_bch); iounmap(base); return 0; } diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 397e4616796e..33db7272c460 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -51,10 +51,19 @@ #define DOC_LAYOUT_WEAR_OFFSET (DOC_LAYOUT_PAGE_OOB_SIZE * 2) #define DOC_LAYOUT_BLOCK_SIZE \ (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_PAGE_SIZE) + +/* + * ECC related constants + */ +#define DOC_ECC_BCH_M 14 +#define DOC_ECC_BCH_T 4 +#define DOC_ECC_BCH_PRIMPOLY 0x4443 #define DOC_ECC_BCH_SIZE 7 #define DOC_ECC_BCH_COVERED_BYTES \ (DOC_LAYOUT_PAGE_SIZE + DOC_LAYOUT_OOB_PAGEINFO_SZ + \ - DOC_LAYOUT_OOB_HAMMING_SZ + DOC_LAYOUT_OOB_BCH_SZ) + DOC_LAYOUT_OOB_HAMMING_SZ) +#define DOC_ECC_BCH_TOTAL_BYTES \ + (DOC_ECC_BCH_COVERED_BYTES + DOC_LAYOUT_OOB_BCH_SZ) /* * Blocks distribution -- cgit v1.2.3 From e4b2a96aeb2b3dfee8d19d0335c6151d4cca4631 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:56 +0100 Subject: mtd: docg3: add suspend and resume Add functions to powerdown and powerup from suspend, in order to save power. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 75 ++++++++++++++++++++++++++++++++++++++++++++- drivers/mtd/devices/docg3.h | 6 ++++ 2 files changed, 80 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 26cc17909b16..d94c759d3ea7 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -45,7 +45,6 @@ * As no specification is available from M-Systems/Sandisk, this drivers lacks * several functions available on the chip, as : * - IPL write - * - powerdown / powerup * * The bus data width (8bits versus 16bits) is not handled (if_cfg flag), and * the driver assumes a 16bits data bus. @@ -1755,6 +1754,78 @@ static void doc_release_device(struct mtd_info *mtd) kfree(mtd); } +/** + * docg3_resume - Awakens docg3 floor + * @pdev: platfrom device + * + * Returns 0 (always successfull) + */ +static int docg3_resume(struct platform_device *pdev) +{ + int i; + struct mtd_info **docg3_floors, *mtd; + struct docg3 *docg3; + + docg3_floors = platform_get_drvdata(pdev); + mtd = docg3_floors[0]; + docg3 = mtd->priv; + + doc_dbg("docg3_resume()\n"); + for (i = 0; i < 12; i++) + doc_readb(docg3, DOC_IOSPACE_IPL); + return 0; +} + +/** + * docg3_suspend - Put in low power mode the docg3 floor + * @pdev: platform device + * @state: power state + * + * Shuts off most of docg3 circuitery to lower power consumption. + * + * Returns 0 if suspend succeeded, -EIO if chip refused suspend + */ +static int docg3_suspend(struct platform_device *pdev, pm_message_t state) +{ + int floor, i; + struct mtd_info **docg3_floors, *mtd; + struct docg3 *docg3; + u8 ctrl, pwr_down; + + docg3_floors = platform_get_drvdata(pdev); + for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { + mtd = docg3_floors[floor]; + if (!mtd) + continue; + docg3 = mtd->priv; + + doc_writeb(docg3, floor, DOC_DEVICESELECT); + ctrl = doc_register_readb(docg3, DOC_FLASHCONTROL); + ctrl &= ~DOC_CTRL_VIOLATION & ~DOC_CTRL_CE; + doc_writeb(docg3, ctrl, DOC_FLASHCONTROL); + + for (i = 0; i < 10; i++) { + usleep_range(3000, 4000); + pwr_down = doc_register_readb(docg3, DOC_POWERMODE); + if (pwr_down & DOC_POWERDOWN_READY) + break; + } + if (pwr_down & DOC_POWERDOWN_READY) { + doc_dbg("docg3_suspend(): floor %d powerdown ok\n", + floor); + } else { + doc_err("docg3_suspend(): floor %d powerdown failed\n", + floor); + return -EIO; + } + } + + mtd = docg3_floors[0]; + docg3 = mtd->priv; + doc_set_asic_mode(docg3, DOC_ASICMODE_POWERDOWN); + return 0; +} + /** * doc_probe - Probe the IO space for a DiskOnChip G3 chip * @pdev: platform device @@ -1860,6 +1931,8 @@ static struct platform_driver g3_driver = { .name = "docg3", .owner = THIS_MODULE, }, + .suspend = docg3_suspend, + .resume = docg3_resume, .remove = __exit_p(docg3_release), }; diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 33db7272c460..cd70b181f797 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -127,6 +127,7 @@ #define DOC_ASICMODECONFIRM 0x1072 #define DOC_CHIPID_INV 0x1074 +#define DOC_POWERMODE 0x107c /* * Flash sequences @@ -238,6 +239,11 @@ #define DOC_READADDR_ONE_BYTE 0x4000 #define DOC_READADDR_ADDR_MASK 0x1fff +/* + * Flash register : DOC_POWERMODE + */ +#define DOC_POWERDOWN_READY 0x80 + /* * Status of erase and write operation */ -- cgit v1.2.3 From c3de8a8a5a28603f8d318245992dbcda2e88a007 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:57 +0100 Subject: mtd: docg3: add fast mode Docg3 chips can work in 3 modes : normal MLC mode, fast mode and reliable mode. Normally, as docg3 is a MLC chip, it should be configured to work in normal mode. In both normal mode, each page is distinct. This means that writing to page 12 of blocks 14,15 writes only to that page, and reading from page 12 of blocks 14,15 reads only from that page. In reliable and fast modes, pages are coupled by pairs, and are clones one of each other. This means that the available capacity of the chip is halved. Pages are coupled in each block, and page of index 2*n contains the same data as page 2*n+1 of the same block. In fast mode, the reads occur a bit faster, but are a bit less reliable that in normal mode. When reading from page 2*n, the chip reads bytes from both page 2*n and page 2*n+1, makes a logical and for each byte, and returns the result. As programming a page means "clearing bits", even if a bit was not cleared on one page because the flash is worn out, the other page has the bit cleared, and the result of the "AND" gives a correct result. When writing to page 2*n, the chip writes data to both page 2*n and page 2*n+1. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 86 +++++++++++++++++++++++++++++++++++---------- drivers/mtd/devices/docg3.h | 9 ++++- 2 files changed, 75 insertions(+), 20 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index d94c759d3ea7..35df3778f8fd 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -61,6 +61,11 @@ * */ +static unsigned int reliable_mode = 0; +module_param(reliable_mode, uint, 0); +MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode (0=normal MLC, 1=fast, " + "2=reliable) : MLC normal operations are in normal mode"); + /** * struct docg3_oobinfo - DiskOnChip G3 OOB layout * @eccbytes: 8 bytes are used (1 for Hamming ECC, 7 for BCH ECC) @@ -291,19 +296,41 @@ static void doc_write_data_area(struct docg3 *docg3, const void *buf, int len) } /** - * doc_set_data_mode - Sets the flash to reliable data mode + * doc_set_data_mode - Sets the flash to normal or reliable data mode * @docg3: the device * * The reliable data mode is a bit slower than the fast mode, but less errors * occur. Entering the reliable mode cannot be done without entering the fast * mode first. + * + * In reliable mode, pages 2*n and 2*n+1 are clones. Writing to page 0 of blocks + * (4,5) make the hardware write also to page 1 of blocks blocks(4,5). Reading + * from page 0 of blocks (4,5) or from page 1 of blocks (4,5) gives the same + * result, which is a logical and between bytes from page 0 and page 1 (which is + * consistent with the fact that writing to a page is _clearing_ bits of that + * page). */ static void doc_set_reliable_mode(struct docg3 *docg3) { - doc_dbg("doc_set_reliable_mode()\n"); - doc_flash_sequence(docg3, DOC_SEQ_SET_MODE); - doc_flash_command(docg3, DOC_CMD_FAST_MODE); - doc_flash_command(docg3, DOC_CMD_RELIABLE_MODE); + static char *strmode[] = { "normal", "fast", "reliable", "invalid" }; + + doc_dbg("doc_set_reliable_mode(%s)\n", strmode[docg3->reliable]); + switch (docg3->reliable) { + case 0: + break; + case 1: + doc_flash_sequence(docg3, DOC_SEQ_SET_FASTMODE); + doc_flash_command(docg3, DOC_CMD_FAST_MODE); + break; + case 2: + doc_flash_sequence(docg3, DOC_SEQ_SET_RELIABLEMODE); + doc_flash_command(docg3, DOC_CMD_FAST_MODE); + doc_flash_command(docg3, DOC_CMD_RELIABLE_MODE); + break; + default: + doc_err("doc_set_reliable_mode(): invalid mode\n"); + break; + } doc_delay(docg3, 2); } @@ -778,18 +805,29 @@ static void doc_read_page_finish(struct docg3 *docg3) * @block1: second plane block index calculated * @page: page calculated * @ofs: offset in page + * @reliable: 0 if docg3 in normal mode, 1 if docg3 in fast mode, 2 if docg3 in + * reliable mode. + * + * The calculation is based on the reliable/normal mode. In normal mode, the 64 + * pages of a block are available. In reliable mode, as pages 2*n and 2*n+1 are + * clones, only 32 pages per block are available. */ static void calc_block_sector(loff_t from, int *block0, int *block1, int *page, - int *ofs) + int *ofs, int reliable) { - uint sector; + uint sector, pages_biblock; + + pages_biblock = DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_NBPLANES; + if (reliable == 1 || reliable == 2) + pages_biblock /= 2; sector = from / DOC_LAYOUT_PAGE_SIZE; - *block0 = sector / (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_NBPLANES) - * DOC_LAYOUT_NBPLANES; + *block0 = sector / pages_biblock * DOC_LAYOUT_NBPLANES; *block1 = *block0 + 1; - *page = sector % (DOC_LAYOUT_PAGES_PER_BLOCK * DOC_LAYOUT_NBPLANES); + *page = sector % pages_biblock; *page /= DOC_LAYOUT_NBPLANES; + if (reliable == 1 || reliable == 2) + *page *= 2; if (sector % 2) *ofs = DOC_LAYOUT_PAGE_OOB_SIZE; else @@ -836,7 +874,8 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, return -EINVAL; ret = -EINVAL; - calc_block_sector(from + len, &block0, &block1, &page, &ofs); + calc_block_sector(from + len, &block0, &block1, &page, &ofs, + docg3->reliable); if (block1 > docg3->max_block) goto err; @@ -844,7 +883,8 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, ops->retlen = 0; ret = 0; while (!ret && (len > 0 || ooblen > 0)) { - calc_block_sector(from, &block0, &block1, &page, &ofs); + calc_block_sector(from, &block0, &block1, &page, &ofs, + docg3->reliable); nbdata = min_t(size_t, len, (size_t)DOC_LAYOUT_PAGE_SIZE); nboob = min_t(size_t, ooblen, (size_t)DOC_LAYOUT_OOB_SIZE); ret = doc_read_page_prepare(docg3, block0, block1, page, ofs); @@ -983,7 +1023,8 @@ static int doc_block_isbad(struct mtd_info *mtd, loff_t from) struct docg3 *docg3 = mtd->priv; int block0, block1, page, ofs, is_good; - calc_block_sector(from, &block0, &block1, &page, &ofs); + calc_block_sector(from, &block0, &block1, &page, &ofs, + docg3->reliable); doc_dbg("doc_block_isbad(from=%lld) => block=(%d,%d), page=%d, ofs=%d\n", from, block0, block1, page, ofs); @@ -1015,7 +1056,7 @@ static int doc_get_erase_count(struct docg3 *docg3, loff_t from) doc_dbg("doc_get_erase_count(from=%lld, buf=%p)\n", from, buf); if (from % DOC_LAYOUT_PAGE_SIZE) return -EINVAL; - calc_block_sector(from, &block0, &block1, &page, &ofs); + calc_block_sector(from, &block0, &block1, &page, &ofs, docg3->reliable); if (block1 > docg3->max_block) return -EINVAL; @@ -1156,14 +1197,15 @@ static int doc_erase(struct mtd_info *mtd, struct erase_info *info) doc_set_device_id(docg3, docg3->device_id); info->state = MTD_ERASE_PENDING; - calc_block_sector(info->addr + info->len, - &block0, &block1, &page, &ofs); + calc_block_sector(info->addr + info->len, &block0, &block1, &page, + &ofs, docg3->reliable); ret = -EINVAL; if (block1 > docg3->max_block || page || ofs) goto reset_err; ret = 0; - calc_block_sector(info->addr, &block0, &block1, &page, &ofs); + calc_block_sector(info->addr, &block0, &block1, &page, &ofs, + docg3->reliable); doc_set_reliable_mode(docg3); for (len = info->len; !ret && len > 0; len -= mtd->erasesize) { info->state = MTD_ERASING; @@ -1209,7 +1251,7 @@ static int doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, u8 syn[DOC_ECC_BCH_SIZE], hamming; doc_dbg("doc_write_page(to=%lld)\n", to); - calc_block_sector(to, &block0, &block1, &page, &ofs); + calc_block_sector(to, &block0, &block1, &page, &ofs, docg3->reliable); doc_set_device_id(docg3, docg3->device_id); ret = doc_reset_seq(docg3); @@ -1396,7 +1438,8 @@ static int doc_write_oob(struct mtd_info *mtd, loff_t ofs, return -EINVAL; ret = -EINVAL; - calc_block_sector(ofs + len, &block0, &block1, &page, &pofs); + calc_block_sector(ofs + len, &block0, &block1, &page, &pofs, + docg3->reliable); if (block1 > docg3->max_block) goto err; @@ -1638,6 +1681,7 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) cfg = doc_register_readb(docg3, DOC_CONFIGURATION); docg3->if_cfg = (cfg & DOC_CONF_IF_CFG ? 1 : 0); + docg3->reliable = reliable_mode; switch (chip_id) { case DOC_CHIPID_G3: @@ -1649,7 +1693,11 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) mtd->type = MTD_NANDFLASH; mtd->flags = MTD_CAP_NANDFLASH; mtd->size = (docg3->max_block + 1) * DOC_LAYOUT_BLOCK_SIZE; + if (docg3->reliable == 2) + mtd->size /= 2; mtd->erasesize = DOC_LAYOUT_BLOCK_SIZE * DOC_LAYOUT_NBPLANES; + if (docg3->reliable == 2) + mtd->erasesize /= 2; mtd->writesize = DOC_LAYOUT_PAGE_SIZE; mtd->oobsize = DOC_LAYOUT_OOB_SIZE; mtd->owner = THIS_MODULE; diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index cd70b181f797..07182f9d484d 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -135,7 +135,8 @@ */ #define DOC_SEQ_RESET 0x00 #define DOC_SEQ_PAGE_SIZE_532 0x03 -#define DOC_SEQ_SET_MODE 0x09 +#define DOC_SEQ_SET_FASTMODE 0x05 +#define DOC_SEQ_SET_RELIABLEMODE 0x09 #define DOC_SEQ_READ 0x12 #define DOC_SEQ_SET_PLANE1 0x0e #define DOC_SEQ_SET_PLANE2 0x10 @@ -257,6 +258,11 @@ * @base: mapped IO space * @device_id: number of the cascaded DoCG3 device (0, 1, 2 or 3) * @if_cfg: if true, reads are on 16bits, else reads are on 8bits + + * @reliable: if 0, docg3 in normal mode, if 1 docg3 in fast mode, if 2 in + * reliable mode + * Fast mode implies more errors than normal mode. + * Reliable mode implies that page 2*n and 2*n+1 are clones. * @bbt: bad block table cache * @oob_write_ofs: offset of the MTD where this OOB should belong (ie. in next * page_write) @@ -270,6 +276,7 @@ struct docg3 { void __iomem *base; unsigned int device_id:4; unsigned int if_cfg:1; + unsigned int reliable:2; int max_block; u8 *bbt; loff_t oob_write_ofs; -- cgit v1.2.3 From 0f769d3f9e2ef3e88930ff190a20cfbfe6206d3a Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Sat, 19 Nov 2011 16:02:58 +0100 Subject: mtd: docg3: add protection areas sysfs access As each docg3 chip has 2 protection areas (DPS0 and DPS1), and because theses areas can prevent user access to the chip data, add for each floor the sysfs entries which insert the protection key into the right DPS. Signed-off-by: Robert Jarzmik Reviewed-by: Ivan Djelic Reviewed-by: Mike Dunn Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 121 ++++++++++++++++++++++++++++++++++++++++++++ drivers/mtd/devices/docg3.h | 13 +++++ 2 files changed, 134 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 35df3778f8fd..d7df3114aa17 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1513,6 +1513,123 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len, return ret; } +static struct docg3 *sysfs_dev2docg3(struct device *dev, + struct device_attribute *attr) +{ + int floor; + struct platform_device *pdev = to_platform_device(dev); + struct mtd_info **docg3_floors = platform_get_drvdata(pdev); + + floor = attr->attr.name[1] - '0'; + if (floor < 0 || floor >= DOC_MAX_NBFLOORS) + return NULL; + else + return docg3_floors[floor]->priv; +} + +static ssize_t dps0_is_key_locked(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct docg3 *docg3 = sysfs_dev2docg3(dev, attr); + int dps0; + + doc_set_device_id(docg3, docg3->device_id); + dps0 = doc_register_readb(docg3, DOC_DPS0_STATUS); + doc_set_device_id(docg3, 0); + + return sprintf(buf, "%d\n", !(dps0 & DOC_DPS_KEY_OK)); +} + +static ssize_t dps1_is_key_locked(struct device *dev, + struct device_attribute *attr, char *buf) +{ + struct docg3 *docg3 = sysfs_dev2docg3(dev, attr); + int dps1; + + doc_set_device_id(docg3, docg3->device_id); + dps1 = doc_register_readb(docg3, DOC_DPS1_STATUS); + doc_set_device_id(docg3, 0); + + return sprintf(buf, "%d\n", !(dps1 & DOC_DPS_KEY_OK)); +} + +static ssize_t dps0_insert_key(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct docg3 *docg3 = sysfs_dev2docg3(dev, attr); + int i; + + if (count != DOC_LAYOUT_DPS_KEY_LENGTH) + return -EINVAL; + + doc_set_device_id(docg3, docg3->device_id); + for (i = 0; i < DOC_LAYOUT_DPS_KEY_LENGTH; i++) + doc_writeb(docg3, buf[i], DOC_DPS0_KEY); + doc_set_device_id(docg3, 0); + return count; +} + +static ssize_t dps1_insert_key(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t count) +{ + struct docg3 *docg3 = sysfs_dev2docg3(dev, attr); + int i; + + if (count != DOC_LAYOUT_DPS_KEY_LENGTH) + return -EINVAL; + + doc_set_device_id(docg3, docg3->device_id); + for (i = 0; i < DOC_LAYOUT_DPS_KEY_LENGTH; i++) + doc_writeb(docg3, buf[i], DOC_DPS1_KEY); + doc_set_device_id(docg3, 0); + return count; +} + +#define FLOOR_SYSFS(id) { \ + __ATTR(f##id##_dps0_is_keylocked, S_IRUGO, dps0_is_key_locked, NULL), \ + __ATTR(f##id##_dps1_is_keylocked, S_IRUGO, dps1_is_key_locked, NULL), \ + __ATTR(f##id##_dps0_protection_key, S_IWUGO, NULL, dps0_insert_key), \ + __ATTR(f##id##_dps1_protection_key, S_IWUGO, NULL, dps1_insert_key), \ +} + +static struct device_attribute doc_sys_attrs[DOC_MAX_NBFLOORS][4] = { + FLOOR_SYSFS(0), FLOOR_SYSFS(1), FLOOR_SYSFS(2), FLOOR_SYSFS(3) +}; + +static int doc_register_sysfs(struct platform_device *pdev, + struct mtd_info **floors) +{ + int ret = 0, floor, i = 0; + struct device *dev = &pdev->dev; + + for (floor = 0; !ret && floor < DOC_MAX_NBFLOORS && floors[floor]; + floor++) + for (i = 0; !ret && i < 4; i++) + ret = device_create_file(dev, &doc_sys_attrs[floor][i]); + if (!ret) + return 0; + do { + while (--i >= 0) + device_remove_file(dev, &doc_sys_attrs[floor][i]); + i = 4; + } while (--floor >= 0); + return ret; +} + +static void doc_unregister_sysfs(struct platform_device *pdev, + struct mtd_info **floors) +{ + struct device *dev = &pdev->dev; + int floor, i; + + for (floor = 0; floor < DOC_MAX_NBFLOORS && floors[floor]; + floor++) + for (i = 0; i < 4; i++) + device_remove_file(dev, &doc_sys_attrs[floor][i]); +} + /* * Debug sysfs entries */ @@ -1927,6 +2044,9 @@ static int __init docg3_probe(struct platform_device *pdev) found++; } + ret = doc_register_sysfs(pdev, docg3_floors); + if (ret) + goto err_probe; if (!found) goto notfound; @@ -1963,6 +2083,7 @@ static int __exit docg3_release(struct platform_device *pdev) void __iomem *base = docg3->base; int floor; + doc_unregister_sysfs(pdev, docg3_floors); doc_dbg_unregister(docg3); for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) if (docg3_floors[floor]) diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index 07182f9d484d..a349915da77d 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -118,6 +118,8 @@ #define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 0)) #define DOC_PROTECTION 0x1056 +#define DOC_DPS0_KEY 0x105c +#define DOC_DPS1_KEY 0x105e #define DOC_DPS0_ADDRLOW 0x1060 #define DOC_DPS0_ADDRHIGH 0x1062 #define DOC_DPS1_ADDRLOW 0x1064 @@ -252,6 +254,17 @@ #define DOC_PLANES_STATUS_PLANE0_KO 0x02 #define DOC_PLANES_STATUS_PLANE1_KO 0x04 +/* + * DPS key management + * + * Each floor of docg3 has 2 protection areas: DPS0 and DPS1. These areas span + * across block boundaries, and define whether these blocks can be read or + * written. + * The definition is dynamically stored in page 0 of blocks (2,3) for DPS0, and + * page 0 of blocks (4,5) for DPS1. + */ +#define DOC_LAYOUT_DPS_KEY_LENGTH 8 + /** * struct docg3 - DiskOnChip driver private data * @dev: the device currently under control -- cgit v1.2.3 From 5d3667eee40a88f79f7f826f0b4c3c9647d7ea7a Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Thu, 24 Nov 2011 16:29:16 +0100 Subject: mtd: Remove redundant spi driver bus initialization In ancient times it was necessary to manually initialize the bus field of an spi_driver to spi_bus_type. These days this is done in spi_driver_register(), so we can drop the manual assignment. The patch was generated using the following coccinelle semantic patch: // @@ identifier _driver; @@ struct spi_driver _driver = { .driver = { - .bus = &spi_bus_type, }, }; // Signed-off-by: Lars-Peter Clausen Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/m25p80.c | 1 - drivers/mtd/devices/mtd_dataflash.c | 1 - drivers/mtd/devices/sst25l.c | 1 - 3 files changed, 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c index 884904d3f9d2..7c60dddbefc0 100644 --- a/drivers/mtd/devices/m25p80.c +++ b/drivers/mtd/devices/m25p80.c @@ -992,7 +992,6 @@ static int __devexit m25p_remove(struct spi_device *spi) static struct spi_driver m25p80_driver = { .driver = { .name = "m25p80", - .bus = &spi_bus_type, .owner = THIS_MODULE, }, .id_table = m25p_ids, diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c index d75c7af18a63..236057ead0d2 100644 --- a/drivers/mtd/devices/mtd_dataflash.c +++ b/drivers/mtd/devices/mtd_dataflash.c @@ -936,7 +936,6 @@ static int __devexit dataflash_remove(struct spi_device *spi) static struct spi_driver dataflash_driver = { .driver = { .name = "mtd_dataflash", - .bus = &spi_bus_type, .owner = THIS_MODULE, .of_match_table = dataflash_dt_ids, }, diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c index d38ef3bffe8d..e45f62e8f195 100644 --- a/drivers/mtd/devices/sst25l.c +++ b/drivers/mtd/devices/sst25l.c @@ -444,7 +444,6 @@ static int __devexit sst25l_remove(struct spi_device *spi) static struct spi_driver sst25l_driver = { .driver = { .name = "sst25l", - .bus = &spi_bus_type, .owner = THIS_MODULE, }, .probe = sst25l_probe, -- cgit v1.2.3 From b49e345e61a2e0c4decbe9b1bd670ed5599fac6e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 28 Nov 2011 16:53:13 +0300 Subject: mtd: docg3: dereferencing an ERR_PTR() in docg3_probe() If doc_probe_device() returned an ERR_PTR, then we accidentally saved that to docg3_floors[floor] = mtd; which gets derefenced in the error handling when we call doc_release_device(). I've reworked the error handling to take care of that and hopefully make it a little simpler. Signed-off-by: Dan Carpenter Acked-by: Robert Jarzmik Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index d7df3114aa17..f7490a014e78 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -2027,21 +2027,24 @@ static int __init docg3_probe(struct platform_device *pdev) if (!docg3_bch) goto nomem2; - ret = 0; for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++) { mtd = doc_probe_device(base, floor, dev); - if (floor == 0 && !mtd) - goto notfound; - if (!IS_ERR_OR_NULL(mtd)) - ret = mtd_device_parse_register(mtd, part_probes, - NULL, NULL, 0); - else + if (IS_ERR(mtd)) { ret = PTR_ERR(mtd); + goto err_probe; + } + if (!mtd) { + if (floor == 0) + goto notfound; + else + continue; + } docg3_floors[floor] = mtd; + ret = mtd_device_parse_register(mtd, part_probes, NULL, NULL, + 0); if (ret) goto err_probe; - if (mtd) - found++; + found++; } ret = doc_register_sysfs(pdev, docg3_floors); -- cgit v1.2.3 From f99640dee209df4730f35a28b02693affd571ad5 Mon Sep 17 00:00:00 2001 From: Axel Lin Date: Sun, 27 Nov 2011 20:45:03 +0800 Subject: mtd: convert drivers/mtd/* to use module_platform_driver() This patch converts the drivers in drivers/mtd/* to use the module_platform_driver() macro which makes the code smaller and a bit simpler. Signed-off-by: Axel Lin Acked by: Haojian Zhuang Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/bcm963xx-flash.c | 13 +------------ drivers/mtd/maps/bfin-async-flash.c | 12 +----------- drivers/mtd/maps/gpio-addr-flash.c | 12 +----------- drivers/mtd/maps/ixp2000.c | 12 +----------- drivers/mtd/maps/ixp4xx.c | 14 +------------- drivers/mtd/maps/latch-addr-flash.c | 12 +----------- drivers/mtd/maps/physmap_of.c | 13 +------------ drivers/mtd/maps/pxa2xx-flash.c | 13 +------------ drivers/mtd/maps/rbtx4939-flash.c | 13 +------------ drivers/mtd/maps/sa1100-flash.c | 13 +------------ drivers/mtd/maps/sun_uflash.c | 13 +------------ drivers/mtd/nand/ams-delta.c | 12 +----------- drivers/mtd/nand/bcm_umi_nand.c | 13 +------------ drivers/mtd/nand/fsl_elbc_nand.c | 13 +------------ drivers/mtd/nand/fsl_upm.c | 12 +----------- drivers/mtd/nand/jz4740_nand.c | 12 +----------- drivers/mtd/nand/mpc5121_nfc.c | 14 +------------- drivers/mtd/nand/ndfc.c | 13 +------------ drivers/mtd/nand/nomadik_nand.c | 14 +------------- drivers/mtd/nand/nuc900_nand.c | 13 +------------ drivers/mtd/nand/omap2.c | 15 +-------------- drivers/mtd/nand/pasemi_nand.c | 12 +----------- drivers/mtd/nand/plat_nand.c | 13 +------------ drivers/mtd/nand/pxa3xx_nand.c | 12 +----------- drivers/mtd/nand/sharpsl.c | 12 +----------- drivers/mtd/nand/socrates_nand.c | 13 +------------ drivers/mtd/nand/tmio_nand.c | 13 +------------ drivers/mtd/onenand/generic.c | 16 ++-------------- drivers/mtd/onenand/samsung.c | 13 +------------ 29 files changed, 30 insertions(+), 345 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c index 736ca10ca9f1..56927f5302c1 100644 --- a/drivers/mtd/maps/bcm963xx-flash.c +++ b/drivers/mtd/maps/bcm963xx-flash.c @@ -257,18 +257,7 @@ static struct platform_driver bcm63xx_mtd_dev = { }, }; -static int __init bcm963xx_mtd_init(void) -{ - return platform_driver_register(&bcm63xx_mtd_dev); -} - -static void __exit bcm963xx_mtd_exit(void) -{ - platform_driver_unregister(&bcm63xx_mtd_dev); -} - -module_init(bcm963xx_mtd_init); -module_exit(bcm963xx_mtd_exit); +module_platform_driver(bcm63xx_mtd_dev); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("Broadcom BCM63xx MTD driver for CFE and RedBoot"); diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c index 6d6b2b5674ee..650126c361f1 100644 --- a/drivers/mtd/maps/bfin-async-flash.c +++ b/drivers/mtd/maps/bfin-async-flash.c @@ -190,17 +190,7 @@ static struct platform_driver bfin_flash_driver = { }, }; -static int __init bfin_flash_init(void) -{ - return platform_driver_register(&bfin_flash_driver); -} -module_init(bfin_flash_init); - -static void __exit bfin_flash_exit(void) -{ - platform_driver_unregister(&bfin_flash_driver); -} -module_exit(bfin_flash_exit); +module_platform_driver(bfin_flash_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("MTD map driver for Blackfins with flash/ethernet on same async bank"); diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c index 1ec66f031c51..33cce895859f 100644 --- a/drivers/mtd/maps/gpio-addr-flash.c +++ b/drivers/mtd/maps/gpio-addr-flash.c @@ -279,17 +279,7 @@ static struct platform_driver gpio_flash_driver = { }, }; -static int __init gpio_flash_init(void) -{ - return platform_driver_register(&gpio_flash_driver); -} -module_init(gpio_flash_init); - -static void __exit gpio_flash_exit(void) -{ - platform_driver_unregister(&gpio_flash_driver); -} -module_exit(gpio_flash_exit); +module_platform_driver(gpio_flash_driver); MODULE_AUTHOR("Mike Frysinger "); MODULE_DESCRIPTION("MTD map driver for flashes addressed physically and with gpios"); diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c index 437fcd2f352f..fc7d4d0d9a4e 100644 --- a/drivers/mtd/maps/ixp2000.c +++ b/drivers/mtd/maps/ixp2000.c @@ -246,18 +246,8 @@ static struct platform_driver ixp2000_flash_driver = { }, }; -static int __init ixp2000_flash_init(void) -{ - return platform_driver_register(&ixp2000_flash_driver); -} - -static void __exit ixp2000_flash_exit(void) -{ - platform_driver_unregister(&ixp2000_flash_driver); -} +module_platform_driver(ixp2000_flash_driver); -module_init(ixp2000_flash_init); -module_exit(ixp2000_flash_exit); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Deepak Saxena "); MODULE_ALIAS("platform:IXP2000-Flash"); diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c index 30409015a3de..8b5410162d70 100644 --- a/drivers/mtd/maps/ixp4xx.c +++ b/drivers/mtd/maps/ixp4xx.c @@ -270,19 +270,7 @@ static struct platform_driver ixp4xx_flash_driver = { }, }; -static int __init ixp4xx_flash_init(void) -{ - return platform_driver_register(&ixp4xx_flash_driver); -} - -static void __exit ixp4xx_flash_exit(void) -{ - platform_driver_unregister(&ixp4xx_flash_driver); -} - - -module_init(ixp4xx_flash_init); -module_exit(ixp4xx_flash_exit); +module_platform_driver(ixp4xx_flash_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("MTD map driver for Intel IXP4xx systems"); diff --git a/drivers/mtd/maps/latch-addr-flash.c b/drivers/mtd/maps/latch-addr-flash.c index 119baa7d7477..8fed58e3a4a8 100644 --- a/drivers/mtd/maps/latch-addr-flash.c +++ b/drivers/mtd/maps/latch-addr-flash.c @@ -223,17 +223,7 @@ static struct platform_driver latch_addr_flash_driver = { }, }; -static int __init latch_addr_flash_init(void) -{ - return platform_driver_register(&latch_addr_flash_driver); -} -module_init(latch_addr_flash_init); - -static void __exit latch_addr_flash_exit(void) -{ - platform_driver_unregister(&latch_addr_flash_driver); -} -module_exit(latch_addr_flash_exit); +module_platform_driver(latch_addr_flash_driver); MODULE_AUTHOR("David Griego "); MODULE_DESCRIPTION("MTD map driver for flashes addressed physically with upper " diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c index 7d65f9d3e690..2e6fb6831d55 100644 --- a/drivers/mtd/maps/physmap_of.c +++ b/drivers/mtd/maps/physmap_of.c @@ -338,18 +338,7 @@ static struct platform_driver of_flash_driver = { .remove = of_flash_remove, }; -static int __init of_flash_init(void) -{ - return platform_driver_register(&of_flash_driver); -} - -static void __exit of_flash_exit(void) -{ - platform_driver_unregister(&of_flash_driver); -} - -module_init(of_flash_init); -module_exit(of_flash_exit); +module_platform_driver(of_flash_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Vitaly Wool "); diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 2a25b6789af4..274e39914332 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c @@ -142,18 +142,7 @@ static struct platform_driver pxa2xx_flash_driver = { .shutdown = pxa2xx_flash_shutdown, }; -static int __init init_pxa2xx_flash(void) -{ - return platform_driver_register(&pxa2xx_flash_driver); -} - -static void __exit cleanup_pxa2xx_flash(void) -{ - platform_driver_unregister(&pxa2xx_flash_driver); -} - -module_init(init_pxa2xx_flash); -module_exit(cleanup_pxa2xx_flash); +module_platform_driver(pxa2xx_flash_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Nicolas Pitre "); diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c index 0237f197fd12..bb7d2042affa 100644 --- a/drivers/mtd/maps/rbtx4939-flash.c +++ b/drivers/mtd/maps/rbtx4939-flash.c @@ -137,18 +137,7 @@ static struct platform_driver rbtx4939_flash_driver = { }, }; -static int __init rbtx4939_flash_init(void) -{ - return platform_driver_register(&rbtx4939_flash_driver); -} - -static void __exit rbtx4939_flash_exit(void) -{ - platform_driver_unregister(&rbtx4939_flash_driver); -} - -module_init(rbtx4939_flash_init); -module_exit(rbtx4939_flash_exit); +module_platform_driver(rbtx4939_flash_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("RBTX4939 MTD map driver"); diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index fa9c0a9670cd..ac3a290748cd 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c @@ -394,18 +394,7 @@ static struct platform_driver sa1100_mtd_driver = { }, }; -static int __init sa1100_mtd_init(void) -{ - return platform_driver_register(&sa1100_mtd_driver); -} - -static void __exit sa1100_mtd_exit(void) -{ - platform_driver_unregister(&sa1100_mtd_driver); -} - -module_init(sa1100_mtd_init); -module_exit(sa1100_mtd_exit); +module_platform_driver(sa1100_mtd_driver); MODULE_AUTHOR("Nicolas Pitre"); MODULE_DESCRIPTION("SA1100 CFI map driver"); diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c index 2d66234f57cb..175e537b444f 100644 --- a/drivers/mtd/maps/sun_uflash.c +++ b/drivers/mtd/maps/sun_uflash.c @@ -158,15 +158,4 @@ static struct platform_driver uflash_driver = { .remove = __devexit_p(uflash_remove), }; -static int __init uflash_init(void) -{ - return platform_driver_register(&uflash_driver); -} - -static void __exit uflash_exit(void) -{ - platform_driver_unregister(&uflash_driver); -} - -module_init(uflash_init); -module_exit(uflash_exit); +module_platform_driver(uflash_driver); diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c index 9e6b498c9beb..3197e9764fcd 100644 --- a/drivers/mtd/nand/ams-delta.c +++ b/drivers/mtd/nand/ams-delta.c @@ -280,17 +280,7 @@ static struct platform_driver ams_delta_nand_driver = { }, }; -static int __init ams_delta_nand_init(void) -{ - return platform_driver_register(&ams_delta_nand_driver); -} -module_init(ams_delta_nand_init); - -static void __exit ams_delta_nand_exit(void) -{ - platform_driver_unregister(&ams_delta_nand_driver); -} -module_exit(ams_delta_nand_exit); +module_platform_driver(ams_delta_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Jonathan McDowell "); diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c index 46b58d672847..50387fd4009b 100644 --- a/drivers/mtd/nand/bcm_umi_nand.c +++ b/drivers/mtd/nand/bcm_umi_nand.c @@ -546,18 +546,7 @@ static struct platform_driver nand_driver = { .resume = bcm_umi_nand_resume, }; -static int __init nand_init(void) -{ - return platform_driver_register(&nand_driver); -} - -static void __exit nand_exit(void) -{ - platform_driver_unregister(&nand_driver); -} - -module_init(nand_init); -module_exit(nand_exit); +module_platform_driver(nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Broadcom"); diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index eedd8ee2c9ac..f2f6e874d4de 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -971,18 +971,7 @@ static struct platform_driver fsl_elbc_nand_driver = { .remove = fsl_elbc_nand_remove, }; -static int __init fsl_elbc_nand_init(void) -{ - return platform_driver_register(&fsl_elbc_nand_driver); -} - -static void __exit fsl_elbc_nand_exit(void) -{ - platform_driver_unregister(&fsl_elbc_nand_driver); -} - -module_init(fsl_elbc_nand_init); -module_exit(fsl_elbc_nand_exit); +module_platform_driver(fsl_elbc_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Freescale"); diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c index b4f3cc9f32fb..45df542b9c61 100644 --- a/drivers/mtd/nand/fsl_upm.c +++ b/drivers/mtd/nand/fsl_upm.c @@ -353,17 +353,7 @@ static struct platform_driver of_fun_driver = { .remove = __devexit_p(fun_remove), }; -static int __init fun_module_init(void) -{ - return platform_driver_register(&of_fun_driver); -} -module_init(fun_module_init); - -static void __exit fun_module_exit(void) -{ - platform_driver_unregister(&of_fun_driver); -} -module_exit(fun_module_exit); +module_platform_driver(of_fun_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Anton Vorontsov "); diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c index e2664073a89b..ac3b9f255e00 100644 --- a/drivers/mtd/nand/jz4740_nand.c +++ b/drivers/mtd/nand/jz4740_nand.c @@ -423,17 +423,7 @@ static struct platform_driver jz_nand_driver = { }, }; -static int __init jz_nand_init(void) -{ - return platform_driver_register(&jz_nand_driver); -} -module_init(jz_nand_init); - -static void __exit jz_nand_exit(void) -{ - platform_driver_unregister(&jz_nand_driver); -} -module_exit(jz_nand_exit); +module_platform_driver(jz_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Lars-Peter Clausen "); diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c index 5ede64706346..c240cf1af961 100644 --- a/drivers/mtd/nand/mpc5121_nfc.c +++ b/drivers/mtd/nand/mpc5121_nfc.c @@ -879,19 +879,7 @@ static struct platform_driver mpc5121_nfc_driver = { }, }; -static int __init mpc5121_nfc_init(void) -{ - return platform_driver_register(&mpc5121_nfc_driver); -} - -module_init(mpc5121_nfc_init); - -static void __exit mpc5121_nfc_cleanup(void) -{ - platform_driver_unregister(&mpc5121_nfc_driver); -} - -module_exit(mpc5121_nfc_cleanup); +module_platform_driver(mpc5121_nfc_driver); MODULE_AUTHOR("Freescale Semiconductor, Inc."); MODULE_DESCRIPTION("MPC5121 NAND MTD driver"); diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c index f8aacf48ecdd..ec688548c880 100644 --- a/drivers/mtd/nand/ndfc.c +++ b/drivers/mtd/nand/ndfc.c @@ -294,18 +294,7 @@ static struct platform_driver ndfc_driver = { .remove = __devexit_p(ndfc_remove), }; -static int __init ndfc_nand_init(void) -{ - return platform_driver_register(&ndfc_driver); -} - -static void __exit ndfc_nand_exit(void) -{ - platform_driver_unregister(&ndfc_driver); -} - -module_init(ndfc_nand_init); -module_exit(ndfc_nand_exit); +module_platform_driver(ndfc_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Thomas Gleixner "); diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c index b463ecfb4c1a..673dc6c68f9a 100644 --- a/drivers/mtd/nand/nomadik_nand.c +++ b/drivers/mtd/nand/nomadik_nand.c @@ -228,19 +228,7 @@ static struct platform_driver nomadik_nand_driver = { }, }; -static int __init nand_nomadik_init(void) -{ - pr_info("Nomadik NAND driver\n"); - return platform_driver_register(&nomadik_nand_driver); -} - -static void __exit nand_nomadik_exit(void) -{ - platform_driver_unregister(&nomadik_nand_driver); -} - -module_init(nand_nomadik_init); -module_exit(nand_nomadik_exit); +module_platform_driver(nomadik_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("ST Microelectronics (sachin.verma@st.com)"); diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c index fa8faedfad6e..8febe46e1105 100644 --- a/drivers/mtd/nand/nuc900_nand.c +++ b/drivers/mtd/nand/nuc900_nand.c @@ -364,18 +364,7 @@ static struct platform_driver nuc900_nand_driver = { }, }; -static int __init nuc900_nand_init(void) -{ - return platform_driver_register(&nuc900_nand_driver); -} - -static void __exit nuc900_nand_exit(void) -{ - platform_driver_unregister(&nuc900_nand_driver); -} - -module_init(nuc900_nand_init); -module_exit(nuc900_nand_exit); +module_platform_driver(nuc900_nand_driver); MODULE_AUTHOR("Wan ZongShun "); MODULE_DESCRIPTION("w90p910/NUC9xx nand driver!"); diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c index f745f00f3167..b3a883e2a22f 100644 --- a/drivers/mtd/nand/omap2.c +++ b/drivers/mtd/nand/omap2.c @@ -1145,20 +1145,7 @@ static struct platform_driver omap_nand_driver = { }, }; -static int __init omap_nand_init(void) -{ - pr_info("%s driver initializing\n", DRIVER_NAME); - - return platform_driver_register(&omap_nand_driver); -} - -static void __exit omap_nand_exit(void) -{ - platform_driver_unregister(&omap_nand_driver); -} - -module_init(omap_nand_init); -module_exit(omap_nand_exit); +module_platform_driver(omap_nand_driver); MODULE_ALIAS("platform:" DRIVER_NAME); MODULE_LICENSE("GPL"); diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c index a97264ececdb..974dbf8251c9 100644 --- a/drivers/mtd/nand/pasemi_nand.c +++ b/drivers/mtd/nand/pasemi_nand.c @@ -230,17 +230,7 @@ static struct platform_driver pasemi_nand_driver = .remove = pasemi_nand_remove, }; -static int __init pasemi_nand_init(void) -{ - return platform_driver_register(&pasemi_nand_driver); -} -module_init(pasemi_nand_init); - -static void __exit pasemi_nand_exit(void) -{ - platform_driver_unregister(&pasemi_nand_driver); -} -module_exit(pasemi_nand_exit); +module_platform_driver(pasemi_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Egor Martovetsky "); diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c index ea8e1234e0e2..7f2da6953357 100644 --- a/drivers/mtd/nand/plat_nand.c +++ b/drivers/mtd/nand/plat_nand.c @@ -148,18 +148,7 @@ static struct platform_driver plat_nand_driver = { }, }; -static int __init plat_nand_init(void) -{ - return platform_driver_register(&plat_nand_driver); -} - -static void __exit plat_nand_exit(void) -{ - platform_driver_unregister(&plat_nand_driver); -} - -module_init(plat_nand_init); -module_exit(plat_nand_exit); +module_platform_driver(plat_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Vitaly Wool"); diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 9eb7f879969e..90d60169ae40 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c @@ -1311,17 +1311,7 @@ static struct platform_driver pxa3xx_nand_driver = { .resume = pxa3xx_nand_resume, }; -static int __init pxa3xx_nand_init(void) -{ - return platform_driver_register(&pxa3xx_nand_driver); -} -module_init(pxa3xx_nand_init); - -static void __exit pxa3xx_nand_exit(void) -{ - platform_driver_unregister(&pxa3xx_nand_driver); -} -module_exit(pxa3xx_nand_exit); +module_platform_driver(pxa3xx_nand_driver); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("PXA3xx NAND controller driver"); diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c index 619d2a504788..b175c0fd8b93 100644 --- a/drivers/mtd/nand/sharpsl.c +++ b/drivers/mtd/nand/sharpsl.c @@ -230,17 +230,7 @@ static struct platform_driver sharpsl_nand_driver = { .remove = __devexit_p(sharpsl_nand_remove), }; -static int __init sharpsl_nand_init(void) -{ - return platform_driver_register(&sharpsl_nand_driver); -} -module_init(sharpsl_nand_init); - -static void __exit sharpsl_nand_exit(void) -{ - platform_driver_unregister(&sharpsl_nand_driver); -} -module_exit(sharpsl_nand_exit); +module_platform_driver(sharpsl_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Richard Purdie "); diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c index 0fb24f9c2327..e02b08bcf0c0 100644 --- a/drivers/mtd/nand/socrates_nand.c +++ b/drivers/mtd/nand/socrates_nand.c @@ -273,18 +273,7 @@ static struct platform_driver socrates_nand_driver = { .remove = __devexit_p(socrates_nand_remove), }; -static int __init socrates_nand_init(void) -{ - return platform_driver_register(&socrates_nand_driver); -} - -static void __exit socrates_nand_exit(void) -{ - platform_driver_unregister(&socrates_nand_driver); -} - -module_init(socrates_nand_init); -module_exit(socrates_nand_exit); +module_platform_driver(socrates_nand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Ilya Yanok"); diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c index beebd95f7690..6caa0cd9d6a7 100644 --- a/drivers/mtd/nand/tmio_nand.c +++ b/drivers/mtd/nand/tmio_nand.c @@ -533,18 +533,7 @@ static struct platform_driver tmio_driver = { .resume = tmio_resume, }; -static int __init tmio_init(void) -{ - return platform_driver_register(&tmio_driver); -} - -static void __exit tmio_exit(void) -{ - platform_driver_unregister(&tmio_driver); -} - -module_init(tmio_init); -module_exit(tmio_exit); +module_platform_driver(tmio_driver); MODULE_LICENSE("GPL v2"); MODULE_AUTHOR("Ian Molton, Dirk Opfer, Chris Humbert, Dmitry Baryshkov"); diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c index 7813095264a5..0ccd5bff2544 100644 --- a/drivers/mtd/onenand/generic.c +++ b/drivers/mtd/onenand/generic.c @@ -115,21 +115,9 @@ static struct platform_driver generic_onenand_driver = { .remove = __devexit_p(generic_onenand_remove), }; -MODULE_ALIAS("platform:" DRIVER_NAME); - -static int __init generic_onenand_init(void) -{ - return platform_driver_register(&generic_onenand_driver); -} - -static void __exit generic_onenand_exit(void) -{ - platform_driver_unregister(&generic_onenand_driver); -} - -module_init(generic_onenand_init); -module_exit(generic_onenand_exit); +module_platform_driver(generic_onenand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Kyungmin Park "); MODULE_DESCRIPTION("Glue layer for OneNAND flash on generic boards"); +MODULE_ALIAS("platform:" DRIVER_NAME); diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c index 5474547eafc2..fa1ee43f735b 100644 --- a/drivers/mtd/onenand/samsung.c +++ b/drivers/mtd/onenand/samsung.c @@ -1133,18 +1133,7 @@ static struct platform_driver s3c_onenand_driver = { .remove = __devexit_p(s3c_onenand_remove), }; -static int __init s3c_onenand_init(void) -{ - return platform_driver_register(&s3c_onenand_driver); -} - -static void __exit s3c_onenand_exit(void) -{ - platform_driver_unregister(&s3c_onenand_driver); -} - -module_init(s3c_onenand_init); -module_exit(s3c_onenand_exit); +module_platform_driver(s3c_onenand_driver); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Kyungmin Park "); -- cgit v1.2.3 From 2f4478ccff7df845dc9c0f8996a96373122c4417 Mon Sep 17 00:00:00 2001 From: Wolfram Sang Date: Tue, 29 Nov 2011 15:34:08 +0100 Subject: mtd: tests: stresstest: bail out if device has not enough eraseblocks stresstest needs at least two eraseblocks. Bail out gracefully if that condition is not met. Fixes the following 'division by zero' OOPS: [ 619.100000] mtd_stresstest: MTD device size 131072, eraseblock size 131072, page size 2048, count of eraseblocks 1, pages per eraseblock 64, OOB size 64 [ 619.120000] mtd_stresstest: scanning for bad eraseblocks [ 619.120000] mtd_stresstest: scanned 1 eraseblocks, 0 are bad [ 619.130000] mtd_stresstest: doing operations [ 619.130000] mtd_stresstest: 0 operations done [ 619.140000] Division by zero in kernel. ... caused by /* Read or write up 2 eraseblocks at a time - hence 'ebcnt - 1' */ eb %= (ebcnt - 1); Cc: stable@kernel.org Signed-off-by: Wolfram Sang Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/tests/mtd_stresstest.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 52ffd9120e0d..811642fea6b4 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -284,6 +284,12 @@ static int __init mtd_stresstest_init(void) (unsigned long long)mtd->size, mtd->erasesize, pgsize, ebcnt, pgcnt, mtd->oobsize); + if (ebcnt < 2) { + printk(PRINT_PREF "error: need at least 2 eraseblocks\n"); + err = -ENOSPC; + goto out_put_mtd; + } + /* Read or write up 2 eraseblocks at a time */ bufsize = mtd->erasesize * 2; @@ -322,6 +328,7 @@ out: kfree(bbt); vfree(writebuf); vfree(readbuf); +out_put_mtd: put_mtd_device(mtd); if (err) printk(PRINT_PREF "error %d occurred\n", err); -- cgit v1.2.3 From 3538c56329936c78f7d356889908790006d0124c Mon Sep 17 00:00:00 2001 From: Roman Tereshonkov Date: Fri, 2 Dec 2011 15:07:17 +0200 Subject: mtd: mtdoops: skip reading initially bad blocks Use block_isbad to check and skip the bad blocks reading. This will allow to get rid of the read errors if bad blocks are present initially. Cc: stable@kernel.org Signed-off-by: Roman Tereshonkov Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdoops.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 1e2fa6236705..cea9279ceabf 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -253,6 +253,9 @@ static void find_next_position(struct mtdoops_context *cxt) size_t retlen; for (page = 0; page < cxt->oops_pages; page++) { + if (mtd->block_isbad && + mtd->block_isbad(mtd, page * record_size)) + continue; /* Assume the page is used */ mark_page_used(cxt, page); ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, -- cgit v1.2.3 From b604436cb06626363f0da357759797a5e1894baf Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Fri, 2 Dec 2011 20:00:12 +0100 Subject: mtd: docg3: fixes and cleanups This patch takes into account checkpatch, sparse and ECC comments. Signed-off-by: Robert Jarzmik Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 26 +++++++++++++------------- drivers/mtd/devices/docg3.h | 3 ++- 2 files changed, 15 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index f7490a014e78..2a32072c7908 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -61,7 +61,7 @@ * */ -static unsigned int reliable_mode = 0; +static unsigned int reliable_mode; module_param(reliable_mode, uint, 0); MODULE_PARM_DESC(reliable_mode, "Set the docg3 mode (0=normal MLC, 1=fast, " "2=reliable) : MLC normal operations are in normal mode"); @@ -546,7 +546,7 @@ out: * @len: the number of bytes covered by the ECC (BCH covered) * * The function does initialize the hardware ECC engine to compute the Hamming - * ECC (on 1 byte) and the BCH Syndroms (on 7 bytes). + * ECC (on 1 byte) and the BCH hardware ECC (on 7 bytes). * * Return 0 if succeeded, -EIO on error */ @@ -567,13 +567,13 @@ static int doc_read_page_ecc_init(struct docg3 *docg3, int len) * @len: the number of bytes covered by the ECC (BCH covered) * * The function does initialize the hardware ECC engine to compute the Hamming - * ECC (on 1 byte) and the BCH Syndroms (on 7 bytes). + * ECC (on 1 byte) and the BCH hardware ECC (on 7 bytes). * * Return 0 if succeeded, -EIO on error */ static int doc_write_page_ecc_init(struct docg3 *docg3, int len) { - doc_writew(docg3, !DOC_ECCCONF0_READ_MODE + doc_writew(docg3, DOC_ECCCONF0_WRITE_MODE | DOC_ECCCONF0_BCH_ENABLE | DOC_ECCCONF0_HAMMING_ENABLE | (len & DOC_ECCCONF0_DATA_BYTES_MASK), DOC_ECCCONF0); @@ -614,7 +614,7 @@ static void doc_hamming_ecc_init(struct docg3 *docg3, int nb_bytes) } /** - * doc_correct_data - Fix if need be read data from flash + * doc_ecc_bch_fix_data - Fix if need be read data from flash * @docg3: the device * @buf: the buffer of read data (512 + 7 + 1 bytes) * @hwecc: the hardware calculated ECC. @@ -761,16 +761,16 @@ static void doc_write_page_putbytes(struct docg3 *docg3, int len, } /** - * doc_get_hw_bch_syndroms - Get hardware calculated BCH syndroms + * doc_get_bch_hw_ecc - Get hardware calculated BCH ECC * @docg3: the device - * @syns: the array of 7 integers where the syndroms will be stored + * @hwecc: the array of 7 integers where the hardware ecc will be stored */ -static void doc_get_hw_bch_syndroms(struct docg3 *docg3, u8 *syns) +static void doc_get_bch_hw_ecc(struct docg3 *docg3, u8 *hwecc) { int i; for (i = 0; i < DOC_ECC_BCH_SIZE; i++) - syns[i] = doc_register_readb(docg3, DOC_BCH_SYNDROM(i)); + hwecc[i] = doc_register_readb(docg3, DOC_BCH_HW_ECC(i)); } /** @@ -904,7 +904,7 @@ static int doc_read_oob(struct mtd_info *mtd, loff_t from, doc_read_page_getbytes(docg3, DOC_LAYOUT_OOB_SIZE - nboob, NULL, 0); - doc_get_hw_bch_syndroms(docg3, hwecc); + doc_get_bch_hw_ecc(docg3, hwecc); eccconf1 = doc_register_readb(docg3, DOC_ECCCONF1); if (nboob >= DOC_LAYOUT_OOB_SIZE) { @@ -1248,7 +1248,7 @@ static int doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, const u_char *oob, int autoecc) { int block0, block1, page, ret, ofs = 0; - u8 syn[DOC_ECC_BCH_SIZE], hamming; + u8 hwecc[DOC_ECC_BCH_SIZE], hamming; doc_dbg("doc_write_page(to=%lld)\n", to); calc_block_sector(to, &block0, &block1, &page, &ofs, docg3->reliable); @@ -1278,8 +1278,8 @@ static int doc_write_page(struct docg3 *docg3, loff_t to, const u_char *buf, &hamming); doc_delay(docg3, 2); - doc_get_hw_bch_syndroms(docg3, syn); - doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_BCH_SZ, syn); + doc_get_bch_hw_ecc(docg3, hwecc); + doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_BCH_SZ, hwecc); doc_delay(docg3, 2); doc_write_page_putbytes(docg3, DOC_LAYOUT_OOB_UNUSED_SZ, oob); diff --git a/drivers/mtd/devices/docg3.h b/drivers/mtd/devices/docg3.h index a349915da77d..db0da436b493 100644 --- a/drivers/mtd/devices/docg3.h +++ b/drivers/mtd/devices/docg3.h @@ -115,7 +115,7 @@ #define DOC_ECCCONF1 0x1042 #define DOC_ECCPRESET 0x1044 #define DOC_HAMMINGPARITY 0x1046 -#define DOC_BCH_SYNDROM(idx) (0x1048 + (idx << 0)) +#define DOC_BCH_HW_ECC(idx) (0x1048 + idx) #define DOC_PROTECTION 0x1056 #define DOC_DPS0_KEY 0x105c @@ -193,6 +193,7 @@ /* * Flash register : DOC_ECCCONF0 */ +#define DOC_ECCCONF0_WRITE_MODE 0x0000 #define DOC_ECCCONF0_READ_MODE 0x8000 #define DOC_ECCCONF0_AUTO_ECC_ENABLE 0x4000 #define DOC_ECCCONF0_HAMMING_ENABLE 0x1000 -- cgit v1.2.3 From a9a552f0bf6258c3593e8887c7212f0fbec8b44c Mon Sep 17 00:00:00 2001 From: Liu Shuo Date: Sun, 4 Dec 2011 12:31:36 +0800 Subject: mtd: nand: use elbc_fcm_ctrl->oob to set FPAR_MS bit of FPAR On both of large-page chip and small-page chip, we always should use 'elbc_fcm_ctrl->oob' to set the FPAR_LP_MS/FPAR_SP_MS bit of FPAR, don't use a overflowed 'column' to set it. Signed-off-by: Liu Shuo Signed-off-by: Li Yang Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/fsl_elbc_nand.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index f2f6e874d4de..c554c2f9c0ec 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -407,9 +407,17 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, page_addr, column); elbc_fcm_ctrl->column = column; - elbc_fcm_ctrl->oob = 0; elbc_fcm_ctrl->use_mdr = 1; + if (column >= mtd->writesize) { + /* OOB area */ + column -= mtd->writesize; + elbc_fcm_ctrl->oob = 1; + } else { + WARN_ON(column != 0); + elbc_fcm_ctrl->oob = 0; + } + fcr = (NAND_CMD_STATUS << FCR_CMD1_SHIFT) | (NAND_CMD_SEQIN << FCR_CMD2_SHIFT) | (NAND_CMD_PAGEPROG << FCR_CMD3_SHIFT); @@ -434,16 +442,12 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, (FIR_OP_CW1 << FIR_OP6_SHIFT) | (FIR_OP_RS << FIR_OP7_SHIFT)); - if (column >= mtd->writesize) { + if (elbc_fcm_ctrl->oob) /* OOB area --> READOOB */ - column -= mtd->writesize; fcr |= NAND_CMD_READOOB << FCR_CMD0_SHIFT; - elbc_fcm_ctrl->oob = 1; - } else { - WARN_ON(column != 0); + else /* First 256 bytes --> READ0 */ fcr |= NAND_CMD_READ0 << FCR_CMD0_SHIFT; - } } out_be32(&lbc->fcr, fcr); -- cgit v1.2.3 From e32de766c2eb65f775438dd6d8ec5007619d2fe5 Mon Sep 17 00:00:00 2001 From: Liu Shuo Date: Sun, 4 Dec 2011 12:31:37 +0800 Subject: mtd: nand: set correct length to FBCR for a non-full-page write When we do a non-full-page write, the length be set to FBCR should not be 'elbc_fcm_ctrl->index', it should be 'elbc_fcm_ctrl->index - elbc_fcm_ctrl->column'. Signed-off-by: Liu Shuo Signed-off-by: Li Yang Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/fsl_elbc_nand.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index c554c2f9c0ec..7db573e9bf78 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -467,7 +467,8 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, */ if (elbc_fcm_ctrl->oob || elbc_fcm_ctrl->column != 0 || elbc_fcm_ctrl->index != mtd->writesize + mtd->oobsize) - out_be32(&lbc->fbcr, elbc_fcm_ctrl->index); + out_be32(&lbc->fbcr, + elbc_fcm_ctrl->index - elbc_fcm_ctrl->column); else out_be32(&lbc->fbcr, 0); -- cgit v1.2.3 From 47882d78250a8b92a9837d14bab32915622a9f12 Mon Sep 17 00:00:00 2001 From: Heiko Schocher Date: Sun, 4 Dec 2011 10:37:36 +0100 Subject: mtd: davinci: if no amif timing is passed, don; t setup cscfg register Signed-off-by: Heiko Schocher Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/davinci_nand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c index c153e1f77f90..6e566156956f 100644 --- a/drivers/mtd/nand/davinci_nand.c +++ b/drivers/mtd/nand/davinci_nand.c @@ -675,7 +675,9 @@ static int __init nand_davinci_probe(struct platform_device *pdev) davinci_nand_writel(info, A1CR_OFFSET + info->core_chipsel * 4, val); - ret = davinci_aemif_setup_timing(info->timing, info->base, + ret = 0; + if (info->timing) + ret = davinci_aemif_setup_timing(info->timing, info->base, info->core_chipsel); if (ret < 0) { dev_dbg(&pdev->dev, "NAND timing values setup fail\n"); -- cgit v1.2.3 From 35096cb54be6ff3a366e28492d4cbf21ffe3efdd Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:05 +0100 Subject: mtd: maps: bcm963xx-flash: fix word order for spare partition Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/bcm963xx-flash.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c index 56927f5302c1..bcdb6dd3f131 100644 --- a/drivers/mtd/maps/bcm963xx-flash.c +++ b/drivers/mtd/maps/bcm963xx-flash.c @@ -145,7 +145,7 @@ static int parse_cfe_partitions(struct mtd_info *master, (long unsigned int)(parts[i].offset), (long unsigned int)(parts[i].size)); - printk(KERN_INFO PFX "Spare partition is %x offset and length %x\n", + printk(KERN_INFO PFX "Spare partition is offset %x and length %x\n", spareaddr, sparelen); *pparts = parts; vfree(buf); -- cgit v1.2.3 From 6ae9c1c82a6ed0858b2fb1c03f11b19194788a31 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:06 +0100 Subject: mtd: maps: bcm963xx-flash: remove superfluous semicolons Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/bcm963xx-flash.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c index bcdb6dd3f131..701f4e51609a 100644 --- a/drivers/mtd/maps/bcm963xx-flash.c +++ b/drivers/mtd/maps/bcm963xx-flash.c @@ -94,18 +94,18 @@ static int parse_cfe_partitions(struct mtd_info *master, if (rootfslen > 0) { nrparts++; namelen += 6; - }; + } if (kernellen > 0) { nrparts++; namelen += 6; - }; + } /* Ask kernel for more memory */ parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); if (!parts) { vfree(buf); return -ENOMEM; - }; + } /* Start building partition list */ parts[curpart].name = "CFE"; @@ -118,7 +118,7 @@ static int parse_cfe_partitions(struct mtd_info *master, parts[curpart].offset = kerneladdr; parts[curpart].size = kernellen; curpart++; - }; + } if (rootfslen > 0) { parts[curpart].name = "rootfs"; @@ -127,7 +127,7 @@ static int parse_cfe_partitions(struct mtd_info *master, if (sparelen > 0) parts[curpart].size += sparelen; curpart++; - }; + } parts[curpart].name = "nvram"; parts[curpart].offset = master->size - master->erasesize; -- cgit v1.2.3 From ca105f4d9823f916a4718c4bc766fd14842056f2 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:07 +0100 Subject: mtd: maps: bcm963xx-flash: clean up printk usage Replace raw printk's with their pr_XXX equivalent and unify broken up strings so they become grepable. Also replace the PFX definition with a pr_fmt(). Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/bcm963xx-flash.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c index 701f4e51609a..e5e3c0a04aaf 100644 --- a/drivers/mtd/maps/bcm963xx-flash.c +++ b/drivers/mtd/maps/bcm963xx-flash.c @@ -18,6 +18,8 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + #include #include #include @@ -34,8 +36,6 @@ #define BCM63XX_BUSWIDTH 2 /* Buswidth */ #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ -#define PFX KBUILD_MODNAME ": " - static struct mtd_partition *parsed_parts; static struct mtd_info *bcm963xx_mtd_info; @@ -80,8 +80,8 @@ static int parse_cfe_partitions(struct mtd_info *master, tagversion = &(buf->tag_version[0]); boardid = &(buf->board_id[0]); - printk(KERN_INFO PFX "CFE boot tag found with version %s " - "and board type %s\n", tagversion, boardid); + pr_info("CFE boot tag found with version %s and board type %s\n", + tagversion, boardid); kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; rootfsaddr = kerneladdr + kernellen; @@ -140,13 +140,13 @@ static int parse_cfe_partitions(struct mtd_info *master, parts[curpart].size = master->size - parts[0].size - parts[3].size; for (i = 0; i < nrparts; i++) - printk(KERN_INFO PFX "Partition %d is %s offset %lx and " - "length %lx\n", i, parts[i].name, - (long unsigned int)(parts[i].offset), - (long unsigned int)(parts[i].size)); + pr_info("Partition %d is %s offset %lx and length %lx\n", i, + parts[i].name, (long unsigned int)(parts[i].offset), + (long unsigned int)(parts[i].size)); + + pr_info("Spare partition is offset %x and length %x\n", spareaddr, + sparelen); - printk(KERN_INFO PFX "Spare partition is offset %x and length %x\n", - spareaddr, sparelen); *pparts = parts; vfree(buf); -- cgit v1.2.3 From 70a3c167c4bf38b5ffd07d8506230ecc20ef7ab1 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:08 +0100 Subject: mtd: maps: bcm963xx-flash: make CFE partition parsing an mtd parser Recent BCM63XX devices support a variety of flash types (parallel, SPI, NAND) and share the partition layout. To prevent code duplication make the CFE partition parsing code a stand alone mtd parser to allow SPI or NAND flash drivers to use it. Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/Kconfig | 8 ++ drivers/mtd/Makefile | 1 + drivers/mtd/bcm63xxpart.c | 189 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/maps/Kconfig | 1 + drivers/mtd/maps/bcm963xx-flash.c | 153 +----------------------------- 5 files changed, 202 insertions(+), 150 deletions(-) create mode 100644 drivers/mtd/bcm63xxpart.c (limited to 'drivers') diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig index 318a869286ab..1be621841400 100644 --- a/drivers/mtd/Kconfig +++ b/drivers/mtd/Kconfig @@ -140,6 +140,14 @@ config MTD_AR7_PARTS ---help--- TI AR7 partitioning support +config MTD_BCM63XX_PARTS + tristate "BCM63XX CFE partitioning support" + depends on BCM63XX + select CRC32 + help + This provides partions parsing for BCM63xx devices with CFE + bootloaders. + comment "User Modules And Translation Layers" config MTD_CHAR diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile index 9aaac3ac89f3..f90135429dc7 100644 --- a/drivers/mtd/Makefile +++ b/drivers/mtd/Makefile @@ -11,6 +11,7 @@ obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o obj-$(CONFIG_MTD_CMDLINE_PARTS) += cmdlinepart.o obj-$(CONFIG_MTD_AFS_PARTS) += afs.o obj-$(CONFIG_MTD_AR7_PARTS) += ar7part.o +obj-$(CONFIG_MTD_BCM63XX_PARTS) += bcm63xxpart.o # 'Users' - code which presents functionality to userspace. obj-$(CONFIG_MTD_CHAR) += mtdchar.o diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c new file mode 100644 index 000000000000..ac7d3c823949 --- /dev/null +++ b/drivers/mtd/bcm63xxpart.c @@ -0,0 +1,189 @@ +/* + * BCM63XX CFE image tag parser + * + * Copyright © 2006-2008 Florian Fainelli + * Mike Albon + * Copyright © 2009-2010 Daniel Dickinson + * Copyright © 2011 Jonas Gorski + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + */ + +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt + +#include +#include +#include +#include +#include +#include + +#include + +#define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ + +static int bcm63xx_detect_cfe(struct mtd_info *master) +{ + int idoffset = 0x4e0; + static char idstring[8] = "CFE1CFE1"; + char buf[9]; + int ret; + size_t retlen; + + ret = master->read(master, idoffset, 8, &retlen, (void *)buf); + buf[retlen] = 0; + pr_info("Read Signature value of %s\n", buf); + + return strncmp(idstring, buf, 8); +} + +static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, + struct mtd_partition **pparts, + struct mtd_part_parser_data *data) +{ + /* CFE, NVRAM and global Linux are always present */ + int nrparts = 3, curpart = 0; + struct bcm_tag *buf; + struct mtd_partition *parts; + int ret; + size_t retlen; + unsigned int rootfsaddr, kerneladdr, spareaddr; + unsigned int rootfslen, kernellen, sparelen, totallen; + int namelen = 0; + int i; + char *boardid; + char *tagversion; + + if (bcm63xx_detect_cfe(master)) + return -EINVAL; + + /* Allocate memory for buffer */ + buf = vmalloc(sizeof(struct bcm_tag)); + if (!buf) + return -ENOMEM; + + /* Get the tag */ + ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), + &retlen, (void *)buf); + if (retlen != sizeof(struct bcm_tag)) { + vfree(buf); + return -EIO; + } + + sscanf(buf->kernel_address, "%u", &kerneladdr); + sscanf(buf->kernel_length, "%u", &kernellen); + sscanf(buf->total_length, "%u", &totallen); + tagversion = &(buf->tag_version[0]); + boardid = &(buf->board_id[0]); + + pr_info("CFE boot tag found with version %s and board type %s\n", + tagversion, boardid); + + kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; + rootfsaddr = kerneladdr + kernellen; + spareaddr = roundup(totallen, master->erasesize) + master->erasesize; + sparelen = master->size - spareaddr - master->erasesize; + rootfslen = spareaddr - rootfsaddr; + + /* Determine number of partitions */ + namelen = 8; + if (rootfslen > 0) { + nrparts++; + namelen += 6; + } + if (kernellen > 0) { + nrparts++; + namelen += 6; + } + + /* Ask kernel for more memory */ + parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); + if (!parts) { + vfree(buf); + return -ENOMEM; + } + + /* Start building partition list */ + parts[curpart].name = "CFE"; + parts[curpart].offset = 0; + parts[curpart].size = master->erasesize; + curpart++; + + if (kernellen > 0) { + parts[curpart].name = "kernel"; + parts[curpart].offset = kerneladdr; + parts[curpart].size = kernellen; + curpart++; + } + + if (rootfslen > 0) { + parts[curpart].name = "rootfs"; + parts[curpart].offset = rootfsaddr; + parts[curpart].size = rootfslen; + if (sparelen > 0) + parts[curpart].size += sparelen; + curpart++; + } + + parts[curpart].name = "nvram"; + parts[curpart].offset = master->size - master->erasesize; + parts[curpart].size = master->erasesize; + + /* Global partition "linux" to make easy firmware upgrade */ + curpart++; + parts[curpart].name = "linux"; + parts[curpart].offset = parts[0].size; + parts[curpart].size = master->size - parts[0].size - parts[3].size; + + for (i = 0; i < nrparts; i++) + pr_info("Partition %d is %s offset %lx and length %lx\n", i, + parts[i].name, (long unsigned int)(parts[i].offset), + (long unsigned int)(parts[i].size)); + + pr_info("Spare partition is offset %x and length %x\n", spareaddr, + sparelen); + + *pparts = parts; + vfree(buf); + + return nrparts; +}; + +static struct mtd_part_parser bcm63xx_cfe_parser = { + .owner = THIS_MODULE, + .parse_fn = bcm63xx_parse_cfe_partitions, + .name = "bcm63xxpart", +}; + +static int __init bcm63xx_cfe_parser_init(void) +{ + return register_mtd_parser(&bcm63xx_cfe_parser); +} + +static void __exit bcm63xx_cfe_parser_exit(void) +{ + deregister_mtd_parser(&bcm63xx_cfe_parser); +} + +module_init(bcm63xx_cfe_parser_init); +module_exit(bcm63xx_cfe_parser_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Daniel Dickinson "); +MODULE_AUTHOR("Florian Fainelli "); +MODULE_AUTHOR("Mike Albon "); +MODULE_AUTHOR("Jonas Gorski #include #include -#include #include #include -#include - #define BCM63XX_BUSWIDTH 2 /* Buswidth */ -#define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ - -static struct mtd_partition *parsed_parts; static struct mtd_info *bcm963xx_mtd_info; @@ -45,134 +39,11 @@ static struct map_info bcm963xx_map = { .bankwidth = BCM63XX_BUSWIDTH, }; -static int parse_cfe_partitions(struct mtd_info *master, - struct mtd_partition **pparts) -{ - /* CFE, NVRAM and global Linux are always present */ - int nrparts = 3, curpart = 0; - struct bcm_tag *buf; - struct mtd_partition *parts; - int ret; - size_t retlen; - unsigned int rootfsaddr, kerneladdr, spareaddr; - unsigned int rootfslen, kernellen, sparelen, totallen; - int namelen = 0; - int i; - char *boardid; - char *tagversion; - - /* Allocate memory for buffer */ - buf = vmalloc(sizeof(struct bcm_tag)); - if (!buf) - return -ENOMEM; - - /* Get the tag */ - ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), - &retlen, (void *)buf); - if (retlen != sizeof(struct bcm_tag)) { - vfree(buf); - return -EIO; - } - - sscanf(buf->kernel_address, "%u", &kerneladdr); - sscanf(buf->kernel_length, "%u", &kernellen); - sscanf(buf->total_length, "%u", &totallen); - tagversion = &(buf->tag_version[0]); - boardid = &(buf->board_id[0]); - - pr_info("CFE boot tag found with version %s and board type %s\n", - tagversion, boardid); - - kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; - rootfsaddr = kerneladdr + kernellen; - spareaddr = roundup(totallen, master->erasesize) + master->erasesize; - sparelen = master->size - spareaddr - master->erasesize; - rootfslen = spareaddr - rootfsaddr; - - /* Determine number of partitions */ - namelen = 8; - if (rootfslen > 0) { - nrparts++; - namelen += 6; - } - if (kernellen > 0) { - nrparts++; - namelen += 6; - } - - /* Ask kernel for more memory */ - parts = kzalloc(sizeof(*parts) * nrparts + 10 * nrparts, GFP_KERNEL); - if (!parts) { - vfree(buf); - return -ENOMEM; - } - - /* Start building partition list */ - parts[curpart].name = "CFE"; - parts[curpart].offset = 0; - parts[curpart].size = master->erasesize; - curpart++; - - if (kernellen > 0) { - parts[curpart].name = "kernel"; - parts[curpart].offset = kerneladdr; - parts[curpart].size = kernellen; - curpart++; - } - - if (rootfslen > 0) { - parts[curpart].name = "rootfs"; - parts[curpart].offset = rootfsaddr; - parts[curpart].size = rootfslen; - if (sparelen > 0) - parts[curpart].size += sparelen; - curpart++; - } - - parts[curpart].name = "nvram"; - parts[curpart].offset = master->size - master->erasesize; - parts[curpart].size = master->erasesize; - - /* Global partition "linux" to make easy firmware upgrade */ - curpart++; - parts[curpart].name = "linux"; - parts[curpart].offset = parts[0].size; - parts[curpart].size = master->size - parts[0].size - parts[3].size; - - for (i = 0; i < nrparts; i++) - pr_info("Partition %d is %s offset %lx and length %lx\n", i, - parts[i].name, (long unsigned int)(parts[i].offset), - (long unsigned int)(parts[i].size)); - - pr_info("Spare partition is offset %x and length %x\n", spareaddr, - sparelen); - - *pparts = parts; - vfree(buf); - - return nrparts; -}; - -static int bcm963xx_detect_cfe(struct mtd_info *master) -{ - int idoffset = 0x4e0; - static char idstring[8] = "CFE1CFE1"; - char buf[9]; - int ret; - size_t retlen; - - ret = master->read(master, idoffset, 8, &retlen, (void *)buf); - buf[retlen] = 0; - printk(KERN_INFO PFX "Read Signature value of %s\n", buf); - - return strncmp(idstring, buf, 8); -} +static const char *part_types[] = { "bcm63xxpart", NULL }; static int bcm963xx_probe(struct platform_device *pdev) { int err = 0; - int parsed_nr_parts = 0; - char *part_type; struct resource *r; r = platform_get_resource(pdev, IORESOURCE_MEM, 0); @@ -208,26 +79,8 @@ static int bcm963xx_probe(struct platform_device *pdev) probe_ok: bcm963xx_mtd_info->owner = THIS_MODULE; - /* This is mutually exclusive */ - if (bcm963xx_detect_cfe(bcm963xx_mtd_info) == 0) { - dev_info(&pdev->dev, "CFE bootloader detected\n"); - if (parsed_nr_parts == 0) { - int ret = parse_cfe_partitions(bcm963xx_mtd_info, - &parsed_parts); - if (ret > 0) { - part_type = "CFE"; - parsed_nr_parts = ret; - } - } - } else { - dev_info(&pdev->dev, "unsupported bootloader\n"); - err = -ENODEV; - goto err_probe; - } - - return mtd_device_register(bcm963xx_mtd_info, parsed_parts, - parsed_nr_parts); - + return mtd_device_parse_register(bcm963xx_mtd_info, part_types, NULL, + NULL, 0); err_probe: iounmap(bcm963xx_map.virt); return err; -- cgit v1.2.3 From 529688fed64a7759323cbd170754c61aad0dd48b Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:09 +0100 Subject: mtd: maps: physmap: allow partition parsers for physmap_flash_data Arch setup code might want to use their own partition parsers, but still use the generic physmap flash driver. Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/physmap.c | 5 ++++- include/linux/mtd/physmap.h | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 66e8200079c2..1f749d58ae6f 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -85,6 +85,7 @@ static int physmap_flash_probe(struct platform_device *dev) struct physmap_flash_data *physmap_data; struct physmap_flash_info *info; const char **probe_type; + const char **part_types; int err = 0; int i; int devices_found = 0; @@ -171,7 +172,9 @@ static int physmap_flash_probe(struct platform_device *dev) if (err) goto err_out; - mtd_device_parse_register(info->cmtd, part_probe_types, 0, + part_types = physmap_data->part_probe_types ? : part_probe_types; + + mtd_device_parse_register(info->cmtd, part_types, 0, physmap_data->parts, physmap_data->nr_parts); return 0; diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h index 04e018160e2b..d2887e76b7f6 100644 --- a/include/linux/mtd/physmap.h +++ b/include/linux/mtd/physmap.h @@ -30,6 +30,7 @@ struct physmap_flash_data { unsigned int pfow_base; char *probe_type; struct mtd_partition *parts; + const char **part_probe_types; }; #endif /* __LINUX_MTD_PHYSMAP__ */ -- cgit v1.2.3 From fa3ae714c763f3e9d8fd876879338d2b674b8db2 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 5 Dec 2011 16:08:11 +0100 Subject: mtd: maps: remove the now unused bcm963xx-flash bcm963xx-flash does nothing meaningful anymore. Signed-off-by: Jonas Gorski Acked-by: Florian Fainelli Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/Kconfig | 10 ---- drivers/mtd/maps/Makefile | 1 - drivers/mtd/maps/bcm963xx-flash.c | 119 -------------------------------------- 3 files changed, 130 deletions(-) delete mode 100644 drivers/mtd/maps/bcm963xx-flash.c (limited to 'drivers') diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig index acc5e0816000..6c5c431c64af 100644 --- a/drivers/mtd/maps/Kconfig +++ b/drivers/mtd/maps/Kconfig @@ -242,16 +242,6 @@ config MTD_NETtel help Support for flash chips on NETtel/SecureEdge/SnapGear boards. -config MTD_BCM963XX - tristate "Map driver for Broadcom BCM963xx boards" - depends on BCM63XX - select MTD_MAP_BANK_WIDTH_2 - select MTD_CFI_I1 - select MTD_BCM63XX_PARTS - help - Support for parsing CFE image tag and creating MTD partitions on - Broadcom BCM63xx boards. - config MTD_LANTIQ tristate "Lantiq SoC NOR support" depends on LANTIQ diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile index 45dcb8b14f22..68a9a91d344f 100644 --- a/drivers/mtd/maps/Makefile +++ b/drivers/mtd/maps/Makefile @@ -55,6 +55,5 @@ obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o obj-$(CONFIG_MTD_VMU) += vmu-flash.o obj-$(CONFIG_MTD_GPIO_ADDR) += gpio-addr-flash.o -obj-$(CONFIG_MTD_BCM963XX) += bcm963xx-flash.o obj-$(CONFIG_MTD_LATCH_ADDR) += latch-addr-flash.o obj-$(CONFIG_MTD_LANTIQ) += lantiq-flash.o diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c deleted file mode 100644 index 830264807bb4..000000000000 --- a/drivers/mtd/maps/bcm963xx-flash.c +++ /dev/null @@ -1,119 +0,0 @@ -/* - * Copyright © 2006-2008 Florian Fainelli - * Mike Albon - * Copyright © 2009-2010 Daniel Dickinson - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA - */ - -#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#define BCM63XX_BUSWIDTH 2 /* Buswidth */ - -static struct mtd_info *bcm963xx_mtd_info; - -static struct map_info bcm963xx_map = { - .name = "bcm963xx", - .bankwidth = BCM63XX_BUSWIDTH, -}; - -static const char *part_types[] = { "bcm63xxpart", NULL }; - -static int bcm963xx_probe(struct platform_device *pdev) -{ - int err = 0; - struct resource *r; - - r = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!r) { - dev_err(&pdev->dev, "no resource supplied\n"); - return -ENODEV; - } - - bcm963xx_map.phys = r->start; - bcm963xx_map.size = resource_size(r); - bcm963xx_map.virt = ioremap(r->start, resource_size(r)); - if (!bcm963xx_map.virt) { - dev_err(&pdev->dev, "failed to ioremap\n"); - return -EIO; - } - - dev_info(&pdev->dev, "0x%08lx at 0x%08x\n", - bcm963xx_map.size, bcm963xx_map.phys); - - simple_map_init(&bcm963xx_map); - - bcm963xx_mtd_info = do_map_probe("cfi_probe", &bcm963xx_map); - if (!bcm963xx_mtd_info) { - dev_err(&pdev->dev, "failed to probe using CFI\n"); - bcm963xx_mtd_info = do_map_probe("jedec_probe", &bcm963xx_map); - if (bcm963xx_mtd_info) - goto probe_ok; - dev_err(&pdev->dev, "failed to probe using JEDEC\n"); - err = -EIO; - goto err_probe; - } - -probe_ok: - bcm963xx_mtd_info->owner = THIS_MODULE; - - return mtd_device_parse_register(bcm963xx_mtd_info, part_types, NULL, - NULL, 0); -err_probe: - iounmap(bcm963xx_map.virt); - return err; -} - -static int bcm963xx_remove(struct platform_device *pdev) -{ - if (bcm963xx_mtd_info) { - mtd_device_unregister(bcm963xx_mtd_info); - map_destroy(bcm963xx_mtd_info); - } - - if (bcm963xx_map.virt) { - iounmap(bcm963xx_map.virt); - bcm963xx_map.virt = 0; - } - - return 0; -} - -static struct platform_driver bcm63xx_mtd_dev = { - .probe = bcm963xx_probe, - .remove = bcm963xx_remove, - .driver = { - .name = "bcm963xx-flash", - .owner = THIS_MODULE, - }, -}; - -module_platform_driver(bcm63xx_mtd_dev); - -MODULE_LICENSE("GPL"); -MODULE_DESCRIPTION("Broadcom BCM63xx MTD driver for CFE and RedBoot"); -MODULE_AUTHOR("Daniel Dickinson "); -MODULE_AUTHOR("Florian Fainelli "); -MODULE_AUTHOR("Mike Albon "); -- cgit v1.2.3 From 556f063580db2953a7e53cd46b47724246320f60 Mon Sep 17 00:00:00 2001 From: Roman Tereshonkov Date: Tue, 29 Nov 2011 12:49:18 +0200 Subject: mtdoops: fix the oops_page_used array size The array of unsigned long pointed by oops_page_used is allocated by vmalloc which requires the size to be in bytes. BITS_PER_LONG is equal to 32. If we want to allocate memory for 32 pages with one bit per page then 32 / BITS_PER_LONG is equal to 1 byte that is 8 bits. To fix it we need to multiply the result by sizeof(unsigned long) equal to 4. Cc: stable@kernel.org Signed-off-by: Roman Tereshonkov Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdoops.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index cea9279ceabf..f3cdce9a85a6 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -372,7 +372,7 @@ static void mtdoops_notify_add(struct mtd_info *mtd) /* oops_page_used is a bit field */ cxt->oops_page_used = vmalloc(DIV_ROUND_UP(mtdoops_pages, - BITS_PER_LONG)); + BITS_PER_LONG) * sizeof(unsigned long)); if (!cxt->oops_page_used) { printk(KERN_ERR "mtdoops: could not allocate page array\n"); return; -- cgit v1.2.3 From 9ae84fe8c18cabc348b9c7cd1e98419cd0cbf481 Mon Sep 17 00:00:00 2001 From: Liu Shuo Date: Fri, 9 Dec 2011 17:42:54 +0800 Subject: mtd: fsl_elbc_nand: set Nand flash page address to FBAR and FPAR correctly If we use the Nand flash chip whose number of pages in a block is greater than 64(for large page), we must treat the low bit of FBAR as being the high bit of the page address due to the limitation of FCM, it simply uses the low 6-bits (for large page) of the combined block/page address as the FPAR component, rather than considering the actual block size. Signed-off-by: Liu Shuo Signed-off-by: Jerry Huang Signed-off-by: Tang Yuantian Signed-off-by: Li Yang Acked-by: Scott Wood Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/fsl_elbc_nand.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index 7db573e9bf78..d29479abe504 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -166,15 +166,22 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr, int oob) elbc_fcm_ctrl->page = page_addr; - out_be32(&lbc->fbar, - page_addr >> (chip->phys_erase_shift - chip->page_shift)); - if (priv->page_size) { + /* + * large page size chip : FPAR[PI] save the lowest 6 bits, + * FBAR[BLK] save the other bits. + */ + out_be32(&lbc->fbar, page_addr >> 6); out_be32(&lbc->fpar, ((page_addr << FPAR_LP_PI_SHIFT) & FPAR_LP_PI) | (oob ? FPAR_LP_MS : 0) | column); buf_num = (page_addr & 1) << 2; } else { + /* + * small page size chip : FPAR[PI] save the lowest 5 bits, + * FBAR[BLK] save the other bits. + */ + out_be32(&lbc->fbar, page_addr >> 5); out_be32(&lbc->fpar, ((page_addr << FPAR_SP_PI_SHIFT) & FPAR_SP_PI) | (oob ? FPAR_SP_MS : 0) | column); -- cgit v1.2.3 From d8251108e0def5a2f15124a8e6314b14bfa5eb9c Mon Sep 17 00:00:00 2001 From: Shengzhou Liu Date: Mon, 12 Dec 2011 17:40:52 +0800 Subject: mtd: nand: fixup for fmr initialization of Freescale NAND controller There was a bug for fmr initialization, which lead to fmr was always 0x100 in fsl_elbc_chip_init() and caused FCM command timeout before calling fsl_elbc_chip_init_tail(), now we initialize CWTO to maximum timeout value and not relying on the setting of bootloader. Signed-off-by: Shengzhou Liu Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/fsl_elbc_nand.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index d29479abe504..080e6037cbfb 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -671,9 +671,7 @@ static int fsl_elbc_chip_init_tail(struct mtd_info *mtd) if (chip->pagemask & 0xff000000) al++; - /* add to ECCM mode set in fsl_elbc_init */ - priv->fmr |= (12 << FMR_CWTO_SHIFT) | /* Timeout > 12 ms */ - (al << FMR_AL_SHIFT); + priv->fmr |= al << FMR_AL_SHIFT; dev_dbg(priv->dev, "fsl_elbc_init: nand->numchips = %d\n", chip->numchips); @@ -776,8 +774,10 @@ static int fsl_elbc_chip_init(struct fsl_elbc_mtd *priv) priv->mtd.priv = chip; priv->mtd.owner = THIS_MODULE; - /* Set the ECCM according to the settings in bootloader.*/ - priv->fmr = in_be32(&lbc->fmr) & FMR_ECCM; + /* set timeout to maximum */ + priv->fmr = 15 << FMR_CWTO_SHIFT; + if (in_be32(&lbc->bank[priv->bank].or) & OR_FCM_PGS) + priv->fmr |= FMR_ECCM; /* fill in nand_chip structure */ /* set up function call table */ -- cgit v1.2.3 From f57eb5cc5394afb2a6f41da7509b794ed9ca5f6d Mon Sep 17 00:00:00 2001 From: Shengzhou Liu Date: Mon, 12 Dec 2011 17:40:53 +0800 Subject: mtd: nand: Add ONFI support for FSL NAND controller - fix NAND_CMD_READID command for ONFI detect. - add NAND_CMD_PARAM command to read the ONFI parameter page. Signed-off-by: Shengzhou Liu Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/fsl_elbc_nand.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c index 080e6037cbfb..7195ee6efe12 100644 --- a/drivers/mtd/nand/fsl_elbc_nand.c +++ b/drivers/mtd/nand/fsl_elbc_nand.c @@ -356,20 +356,22 @@ static void fsl_elbc_cmdfunc(struct mtd_info *mtd, unsigned int command, fsl_elbc_run_command(mtd); return; - /* READID must read all 5 possible bytes while CEB is active */ case NAND_CMD_READID: - dev_vdbg(priv->dev, "fsl_elbc_cmdfunc: NAND_CMD_READID.\n"); + case NAND_CMD_PARAM: + dev_vdbg(priv->dev, "fsl_elbc_cmdfunc: NAND_CMD %x\n", command); out_be32(&lbc->fir, (FIR_OP_CM0 << FIR_OP0_SHIFT) | (FIR_OP_UA << FIR_OP1_SHIFT) | (FIR_OP_RBW << FIR_OP2_SHIFT)); - out_be32(&lbc->fcr, NAND_CMD_READID << FCR_CMD0_SHIFT); - /* nand_get_flash_type() reads 8 bytes of entire ID string */ - out_be32(&lbc->fbcr, 8); - elbc_fcm_ctrl->read_bytes = 8; + out_be32(&lbc->fcr, command << FCR_CMD0_SHIFT); + /* + * although currently it's 8 bytes for READID, we always read + * the maximum 256 bytes(for PARAM) + */ + out_be32(&lbc->fbcr, 256); + elbc_fcm_ctrl->read_bytes = 256; elbc_fcm_ctrl->use_mdr = 1; - elbc_fcm_ctrl->mdr = 0; - + elbc_fcm_ctrl->mdr = column; set_addr(mtd, 0, 0, 0); fsl_elbc_run_command(mtd); return; -- cgit v1.2.3 From e10019bce9cbeb7675d5d08221012a2cfee0d498 Mon Sep 17 00:00:00 2001 From: Robert Jarzmik Date: Fri, 16 Dec 2011 23:25:23 +0100 Subject: mtd: docg3: remove unused function As the MTD api has no use for the number of erase cycles each block has endured, remove the function which calculated that value. If one day MTD api finds it usefull for wear levelling algorithms to have this information, the function should be put back in place. Signed-off-by: Robert Jarzmik Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/docg3.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 2a32072c7908..22d5099f7786 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1037,6 +1037,7 @@ static int doc_block_isbad(struct mtd_info *mtd, loff_t from) return !is_good; } +#if 0 /** * doc_get_erase_count - Get block erase count * @docg3: the device @@ -1078,6 +1079,7 @@ static int doc_get_erase_count(struct docg3 *docg3, loff_t from) return max(plane1_erase_count, plane2_erase_count); } +#endif /** * doc_get_op_status - get erase/write operation status -- cgit v1.2.3 From f9fbcdc357f37d6c82a75a89c64efbe8bd5274e1 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Thu, 15 Dec 2011 13:35:49 +1030 Subject: mtd: sm_ftl: fix module parameter You didn't mean this to be a bool. Signed-off-by: Rusty Russell Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/sm_ftl.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index fddb714e323c..1c9f307ae0a1 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -25,7 +25,7 @@ struct workqueue_struct *cache_flush_workqueue; static int cache_timeout = 1000; -module_param(cache_timeout, bool, S_IRUGO); +module_param(cache_timeout, int, S_IRUGO); MODULE_PARM_DESC(cache_timeout, "Timeout (in ms) for cache flush (1000 ms default"); -- cgit v1.2.3 From f2d9739b8e0bc9bdcc972950dd433b5083edf72f Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Sat, 17 Dec 2011 13:58:14 +0100 Subject: mtd: bcm63xxpart: check version marker string for newer CFEs Recent CFEs do not contain the CFE1CFE1 magic anymore, so check for the "cfe-v" version marker string instead. As very old CFEs do not have this string, leave the CFE1CFE1 magic as a fallback for detection. Signed-off-by: Jonas Gorski Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/bcm63xxpart.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index ac7d3c823949..9933b347a555 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -32,22 +32,34 @@ #include #include +#include #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ +#define BCM63XX_CFE_MAGIC_OFFSET 0x4e0 + static int bcm63xx_detect_cfe(struct mtd_info *master) { - int idoffset = 0x4e0; - static char idstring[8] = "CFE1CFE1"; char buf[9]; int ret; size_t retlen; - ret = master->read(master, idoffset, 8, &retlen, (void *)buf); + ret = master->read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen, + (void *)buf); + buf[retlen] = 0; + + if (ret) + return ret; + + if (strncmp("cfe-v", buf, 5) == 0) + return 0; + + /* very old CFE's do not have the cfe-v string, so check for magic */ + ret = master->read(master, BCM63XX_CFE_MAGIC_OFFSET, 8, &retlen, + (void *)buf); buf[retlen] = 0; - pr_info("Read Signature value of %s\n", buf); - return strncmp(idstring, buf, 8); + return strncmp("CFE1CFE1", buf, 8); } static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, -- cgit v1.2.3 From 678eb9bb8114c47a7b89fd1288ff5dc760c53c1c Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Mon, 19 Dec 2011 11:36:04 +0100 Subject: mtd: bcm63xxpart: make sure CFE and NVRAM partitions are at least 64KiB The CFE boot loader on BCM63XX platforms assumes itself and the NVRAM partition to be 64 KiB (or erase block sized, if larger). Ensure this assumption is also met when creating the partitions to prevent accidential erasure of CFE or NVRAM. Signed-off-by: Jonas Gorski Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/bcm63xxpart.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index 9933b347a555..17e137080a6b 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -36,6 +36,9 @@ #define BCM63XX_EXTENDED_SIZE 0xBFC00000 /* Extended flash address */ +#define BCM63XX_MIN_CFE_SIZE 0x10000 /* always at least 64KiB */ +#define BCM63XX_MIN_NVRAM_SIZE 0x10000 /* always at least 64KiB */ + #define BCM63XX_CFE_MAGIC_OFFSET 0x4e0 static int bcm63xx_detect_cfe(struct mtd_info *master) @@ -74,6 +77,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, size_t retlen; unsigned int rootfsaddr, kerneladdr, spareaddr; unsigned int rootfslen, kernellen, sparelen, totallen; + unsigned int cfelen, nvramlen; int namelen = 0; int i; char *boardid; @@ -82,14 +86,18 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, if (bcm63xx_detect_cfe(master)) return -EINVAL; + cfelen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_CFE_SIZE); + nvramlen = max_t(uint32_t, master->erasesize, BCM63XX_MIN_NVRAM_SIZE); + /* Allocate memory for buffer */ buf = vmalloc(sizeof(struct bcm_tag)); if (!buf) return -ENOMEM; /* Get the tag */ - ret = master->read(master, master->erasesize, sizeof(struct bcm_tag), - &retlen, (void *)buf); + ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen, + (void *)buf); + if (retlen != sizeof(struct bcm_tag)) { vfree(buf); return -EIO; @@ -106,8 +114,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; rootfsaddr = kerneladdr + kernellen; - spareaddr = roundup(totallen, master->erasesize) + master->erasesize; - sparelen = master->size - spareaddr - master->erasesize; + spareaddr = roundup(totallen, master->erasesize) + cfelen; + sparelen = master->size - spareaddr - nvramlen; rootfslen = spareaddr - rootfsaddr; /* Determine number of partitions */ @@ -131,7 +139,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, /* Start building partition list */ parts[curpart].name = "CFE"; parts[curpart].offset = 0; - parts[curpart].size = master->erasesize; + parts[curpart].size = cfelen; curpart++; if (kernellen > 0) { @@ -151,8 +159,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, } parts[curpart].name = "nvram"; - parts[curpart].offset = master->size - master->erasesize; - parts[curpart].size = master->erasesize; + parts[curpart].offset = master->size - nvramlen; + parts[curpart].size = nvramlen; /* Global partition "linux" to make easy firmware upgrade */ curpart++; -- cgit v1.2.3 From 327c62c554a78af399938445094a7dc834b7fd0b Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Sat, 17 Dec 2011 13:58:16 +0100 Subject: mtd: bcm63xxpart: don't assume NVRAM is always the fourth partition Instead of referencing the sizes of fixed partitions, use the precomputed CFE/NVRAM lengths. Signed-off-by: Jonas Gorski Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/bcm63xxpart.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index 17e137080a6b..6afc4aa3c622 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -165,8 +165,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, /* Global partition "linux" to make easy firmware upgrade */ curpart++; parts[curpart].name = "linux"; - parts[curpart].offset = parts[0].size; - parts[curpart].size = master->size - parts[0].size - parts[3].size; + parts[curpart].offset = cfelen; + parts[curpart].size = master->size - cfelen - nvramlen; for (i = 0; i < nrparts; i++) pr_info("Partition %d is %s offset %lx and length %lx\n", i, -- cgit v1.2.3 From f98872fc14ecb96f796443911b6bc4767e58e885 Mon Sep 17 00:00:00 2001 From: Jonas Gorski Date: Sat, 17 Dec 2011 13:58:18 +0100 Subject: mtd: bcm63xxpart: check the image tag's crc32 Only use the values from the image tag if it is valid. Always create the CFE, NVRAM and linux partitions, to allow flashing a new image even if the old is invalid without overwriting CFE or NVRAM. Signed-off-by: Jonas Gorski Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/bcm63xxpart.c | 45 +++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index 6afc4aa3c622..9ee8bc426e93 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -24,6 +24,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include #include #include #include @@ -80,8 +81,7 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, unsigned int cfelen, nvramlen; int namelen = 0; int i; - char *boardid; - char *tagversion; + u32 computed_crc; if (bcm63xx_detect_cfe(master)) return -EINVAL; @@ -103,20 +103,33 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, return -EIO; } - sscanf(buf->kernel_address, "%u", &kerneladdr); - sscanf(buf->kernel_length, "%u", &kernellen); - sscanf(buf->total_length, "%u", &totallen); - tagversion = &(buf->tag_version[0]); - boardid = &(buf->board_id[0]); - - pr_info("CFE boot tag found with version %s and board type %s\n", - tagversion, boardid); - - kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; - rootfsaddr = kerneladdr + kernellen; - spareaddr = roundup(totallen, master->erasesize) + cfelen; - sparelen = master->size - spareaddr - nvramlen; - rootfslen = spareaddr - rootfsaddr; + computed_crc = crc32_le(IMAGETAG_CRC_START, (u8 *)buf, + offsetof(struct bcm_tag, header_crc)); + if (computed_crc == buf->header_crc) { + char *boardid = &(buf->board_id[0]); + char *tagversion = &(buf->tag_version[0]); + + sscanf(buf->kernel_address, "%u", &kerneladdr); + sscanf(buf->kernel_length, "%u", &kernellen); + sscanf(buf->total_length, "%u", &totallen); + + pr_info("CFE boot tag found with version %s and board type %s\n", + tagversion, boardid); + + kerneladdr = kerneladdr - BCM63XX_EXTENDED_SIZE; + rootfsaddr = kerneladdr + kernellen; + spareaddr = roundup(totallen, master->erasesize) + cfelen; + sparelen = master->size - spareaddr - nvramlen; + rootfslen = spareaddr - rootfsaddr; + } else { + pr_warn("CFE boot tag CRC invalid (expected %08x, actual %08x)\n", + buf->header_crc, computed_crc); + kernellen = 0; + rootfslen = 0; + rootfsaddr = 0; + spareaddr = cfelen; + sparelen = master->size - cfelen - nvramlen; + } /* Determine number of partitions */ namelen = 8; -- cgit v1.2.3 From 775c32208708de3e2e2379c85e429ab11957f864 Mon Sep 17 00:00:00 2001 From: Jamie Iles Date: Sun, 18 Dec 2011 10:00:49 +0000 Subject: mtd: gpio-nand: add device tree bindings Add device tree bindings so that the gpio-nand driver may be instantiated from the device tree. This also allows the partitions to be specified in the device tree. v7: - restore runtime device tree/non device tree detection v6: - convert to mtd_device_parse_register() v5: - fold dt config helpers into a single gpio_nand_of_get_config() v4: - get io sync address from gpio-control-nand,io-sync-reg property rather than a resource - clarified a few details in the binding v3: - remove redundant cast and a couple of whitespace/naming changes v2: - add CONFIG_OF guards for non-dt platforms - compatible becomes gpio-control-nand - clarify some binding details Signed-off-by: Jamie Iles Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- .../devicetree/bindings/mtd/gpio-control-nand.txt | 44 ++++++++ drivers/mtd/nand/gpio.c | 115 +++++++++++++++++++-- 2 files changed, 152 insertions(+), 7 deletions(-) create mode 100644 Documentation/devicetree/bindings/mtd/gpio-control-nand.txt (limited to 'drivers') diff --git a/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt new file mode 100644 index 000000000000..719f4dc58df7 --- /dev/null +++ b/Documentation/devicetree/bindings/mtd/gpio-control-nand.txt @@ -0,0 +1,44 @@ +GPIO assisted NAND flash + +The GPIO assisted NAND flash uses a memory mapped interface to +read/write the NAND commands and data and GPIO pins for the control +signals. + +Required properties: +- compatible : "gpio-control-nand" +- reg : should specify localbus chip select and size used for the chip. The + resource describes the data bus connected to the NAND flash and all accesses + are made in native endianness. +- #address-cells, #size-cells : Must be present if the device has sub-nodes + representing partitions. +- gpios : specifies the gpio pins to control the NAND device. nwp is an + optional gpio and may be set to 0 if not present. + +Optional properties: +- bank-width : Width (in bytes) of the device. If not present, the width + defaults to 1 byte. +- chip-delay : chip dependent delay for transferring data from array to + read registers (tR). If not present then a default of 20us is used. +- gpio-control-nand,io-sync-reg : A 64-bit physical address for a read + location used to guard against bus reordering with regards to accesses to + the GPIO's and the NAND flash data bus. If present, then after changing + GPIO state and before and after command byte writes, this register will be + read to ensure that the GPIO accesses have completed. + +Examples: + +gpio-nand@1,0 { + compatible = "gpio-control-nand"; + reg = <1 0x0000 0x2>; + #address-cells = <1>; + #size-cells = <1>; + gpios = <&banka 1 0 /* rdy */ + &banka 2 0 /* nce */ + &banka 3 0 /* ale */ + &banka 4 0 /* cle */ + 0 /* nwp */>; + + partition@0 { + ... + }; +}; diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c index 2c2060b2800e..27000a5f5f47 100644 --- a/drivers/mtd/nand/gpio.c +++ b/drivers/mtd/nand/gpio.c @@ -27,6 +27,9 @@ #include #include #include +#include +#include +#include struct gpiomtd { void __iomem *io_sync; @@ -171,6 +174,96 @@ static int gpio_nand_devready(struct mtd_info *mtd) return gpio_get_value(gpiomtd->plat.gpio_rdy); } +#ifdef CONFIG_OF +static const struct of_device_id gpio_nand_id_table[] = { + { .compatible = "gpio-control-nand" }, + {} +}; +MODULE_DEVICE_TABLE(of, gpio_nand_id_table); + +static int gpio_nand_get_config_of(const struct device *dev, + struct gpio_nand_platdata *plat) +{ + u32 val; + + if (!of_property_read_u32(dev->of_node, "bank-width", &val)) { + if (val == 2) { + plat->options |= NAND_BUSWIDTH_16; + } else if (val != 1) { + dev_err(dev, "invalid bank-width %u\n", val); + return -EINVAL; + } + } + + plat->gpio_rdy = of_get_gpio(dev->of_node, 0); + plat->gpio_nce = of_get_gpio(dev->of_node, 1); + plat->gpio_ale = of_get_gpio(dev->of_node, 2); + plat->gpio_cle = of_get_gpio(dev->of_node, 3); + plat->gpio_nwp = of_get_gpio(dev->of_node, 4); + + if (!of_property_read_u32(dev->of_node, "chip-delay", &val)) + plat->chip_delay = val; + + return 0; +} + +static struct resource *gpio_nand_get_io_sync_of(struct platform_device *pdev) +{ + struct resource *r = devm_kzalloc(&pdev->dev, sizeof(*r), GFP_KERNEL); + u64 addr; + + if (!r || of_property_read_u64(pdev->dev.of_node, + "gpio-control-nand,io-sync-reg", &addr)) + return NULL; + + r->start = addr; + r->end = r->start + 0x3; + r->flags = IORESOURCE_MEM; + + return r; +} +#else /* CONFIG_OF */ +#define gpio_nand_id_table NULL +static inline int gpio_nand_get_config_of(const struct device *dev, + struct gpio_nand_platdata *plat) +{ + return -ENOSYS; +} + +static inline struct resource * +gpio_nand_get_io_sync_of(struct platform_device *pdev) +{ + return NULL; +} +#endif /* CONFIG_OF */ + +static inline int gpio_nand_get_config(const struct device *dev, + struct gpio_nand_platdata *plat) +{ + int ret = gpio_nand_get_config_of(dev, plat); + + if (!ret) + return ret; + + if (dev->platform_data) { + memcpy(plat, dev->platform_data, sizeof(*plat)); + return 0; + } + + return -EINVAL; +} + +static inline struct resource * +gpio_nand_get_io_sync(struct platform_device *pdev) +{ + struct resource *r = gpio_nand_get_io_sync_of(pdev); + + if (r) + return r; + + return platform_get_resource(pdev, IORESOURCE_MEM, 1); +} + static int __devexit gpio_nand_remove(struct platform_device *dev) { struct gpiomtd *gpiomtd = platform_get_drvdata(dev); @@ -178,7 +271,7 @@ static int __devexit gpio_nand_remove(struct platform_device *dev) nand_release(&gpiomtd->mtd_info); - res = platform_get_resource(dev, IORESOURCE_MEM, 1); + res = gpio_nand_get_io_sync(dev); iounmap(gpiomtd->io_sync); if (res) release_mem_region(res->start, resource_size(res)); @@ -226,9 +319,10 @@ static int __devinit gpio_nand_probe(struct platform_device *dev) struct gpiomtd *gpiomtd; struct nand_chip *this; struct resource *res0, *res1; - int ret; + struct mtd_part_parser_data ppdata = {}; + int ret = 0; - if (!dev->dev.platform_data) + if (!dev->dev.of_node && !dev->dev.platform_data) return -EINVAL; res0 = platform_get_resource(dev, IORESOURCE_MEM, 0); @@ -248,7 +342,7 @@ static int __devinit gpio_nand_probe(struct platform_device *dev) goto err_map; } - res1 = platform_get_resource(dev, IORESOURCE_MEM, 1); + res1 = gpio_nand_get_io_sync(dev); if (res1) { gpiomtd->io_sync = request_and_remap(res1, 4, "NAND sync", &ret); if (!gpiomtd->io_sync) { @@ -257,7 +351,9 @@ static int __devinit gpio_nand_probe(struct platform_device *dev) } } - memcpy(&gpiomtd->plat, dev->dev.platform_data, sizeof(gpiomtd->plat)); + ret = gpio_nand_get_config(&dev->dev, &gpiomtd->plat); + if (ret) + goto err_nce; ret = gpio_request(gpiomtd->plat.gpio_nce, "NAND NCE"); if (ret) @@ -316,8 +412,12 @@ static int __devinit gpio_nand_probe(struct platform_device *dev) gpiomtd->plat.adjust_parts(&gpiomtd->plat, gpiomtd->mtd_info.size); - mtd_device_register(&gpiomtd->mtd_info, gpiomtd->plat.parts, - gpiomtd->plat.num_parts); + ppdata.of_node = dev->dev.of_node; + ret = mtd_device_parse_register(&gpiomtd->mtd_info, NULL, &ppdata, + gpiomtd->plat.parts, + gpiomtd->plat.num_parts); + if (ret) + goto err_wp; platform_set_drvdata(dev, gpiomtd); return 0; @@ -352,6 +452,7 @@ static struct platform_driver gpio_nand_driver = { .remove = gpio_nand_remove, .driver = { .name = "gpio-nand", + .of_match_table = gpio_nand_id_table, }, }; -- cgit v1.2.3 From af32b36095147e1828496b58987c1e24ef40487d Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Mon, 26 Dec 2011 18:38:01 +0100 Subject: mtd: lantiq-flash: drop iounmap for devm_ allocated data Data allocated with devm_ioremap or devm_ioremap_nocache should not be freed using iounmap, because doing so causes a dangling pointer, and a subsequent double free. The semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // @r@ expression x; @@ ( x = devm_ioremap(...) | x = devm_ioremap_nocache(...) ) @@ expression r.x; @@ * iounmap(x) // Signed-off-by: Julia Lawall Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/lantiq-flash.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/lantiq-flash.c b/drivers/mtd/maps/lantiq-flash.c index 4f10e27ada55..7b889de9477b 100644 --- a/drivers/mtd/maps/lantiq-flash.c +++ b/drivers/mtd/maps/lantiq-flash.c @@ -159,7 +159,7 @@ ltq_mtd_probe(struct platform_device *pdev) if (!ltq_mtd->mtd) { dev_err(&pdev->dev, "probing failed\n"); err = -ENXIO; - goto err_unmap; + goto err_free; } ltq_mtd->mtd->owner = THIS_MODULE; @@ -179,8 +179,6 @@ ltq_mtd_probe(struct platform_device *pdev) err_destroy: map_destroy(ltq_mtd->mtd); -err_unmap: - iounmap(ltq_mtd->map->virt); err_free: kfree(ltq_mtd->map); err_out: @@ -198,8 +196,6 @@ ltq_mtd_remove(struct platform_device *pdev) mtd_device_unregister(ltq_mtd->mtd); map_destroy(ltq_mtd->mtd); } - if (ltq_mtd->map->virt) - iounmap(ltq_mtd->map->virt); kfree(ltq_mtd->map); kfree(ltq_mtd); } -- cgit v1.2.3 From bca7f5f71389547489fffe6c757eaff8659bcd16 Mon Sep 17 00:00:00 2001 From: Julia Lawall Date: Tue, 27 Dec 2011 15:01:31 +0100 Subject: mtd: txx9ndfmc: use devm_request_and_ioremap Reimplement a call to devm_request_mem_region followed by a call to ioremap or ioremap_nocache by a call to devm_request_and_ioremap. The semantic patch that makes this transformation is as follows: (http://coccinelle.lip6.fr/) // @nm@ expression myname; identifier i; @@ struct platform_driver i = { .driver = { .name = myname } }; @@ expression dev,res,size; expression nm.myname; @@ -if (!devm_request_mem_region(dev, res->start, size, - \(res->name\|dev_name(dev)\|myname\))) { - ... - return ...; -} ... when != res->start ( -devm_ioremap(dev,res->start,size) +devm_request_and_ioremap(dev,res) | -devm_ioremap_nocache(dev,res->start,size) +devm_request_and_ioremap(dev,res) ) ... when any when != res->start // Signed-off-by: Julia Lawall Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/nand/txx9ndfmc.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c index ace46fdaef58..c7c4f1d11c77 100644 --- a/drivers/mtd/nand/txx9ndfmc.c +++ b/drivers/mtd/nand/txx9ndfmc.c @@ -298,11 +298,7 @@ static int __init txx9ndfmc_probe(struct platform_device *dev) drvdata = devm_kzalloc(&dev->dev, sizeof(*drvdata), GFP_KERNEL); if (!drvdata) return -ENOMEM; - if (!devm_request_mem_region(&dev->dev, res->start, - resource_size(res), dev_name(&dev->dev))) - return -EBUSY; - drvdata->base = devm_ioremap(&dev->dev, res->start, - resource_size(res)); + drvdata->base = devm_request_and_ioremap(&dev->dev, res); if (!drvdata->base) return -EBUSY; -- cgit v1.2.3 From cdfe5ed0f271f1d5693fbd68809cc7e0e6c3af66 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Tue, 27 Dec 2011 17:59:04 +0200 Subject: mtd: lpddr: drop unnecessary zeroing We allocate the "mtd" structure using kzalloc which means we do not have to initialize unused MTD function pointers to NULL, since it is safe to assume in Linux that NULL contains all zeroes. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/lpddr/lpddr_cmds.c | 7 ------- 1 file changed, 7 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c index 1dca31d9a8b3..536bbceaeaad 100644 --- a/drivers/mtd/lpddr/lpddr_cmds.c +++ b/drivers/mtd/lpddr/lpddr_cmds.c @@ -70,19 +70,12 @@ struct mtd_info *lpddr_cmdset(struct map_info *map) mtd->erase = lpddr_erase; mtd->write = lpddr_write_buffers; mtd->writev = lpddr_writev; - mtd->read_oob = NULL; - mtd->write_oob = NULL; - mtd->sync = NULL; mtd->lock = lpddr_lock; mtd->unlock = lpddr_unlock; - mtd->suspend = NULL; - mtd->resume = NULL; if (map_is_linear(map)) { mtd->point = lpddr_point; mtd->unpoint = lpddr_unpoint; } - mtd->block_isbad = NULL; - mtd->block_markbad = NULL; mtd->size = 1 << lpddr->qinfo->DevSizeShift; mtd->erasesize = 1 << lpddr->qinfo->UniformBlockSizeShift; mtd->writesize = 1 << lpddr->qinfo->BufSizeShift; -- cgit v1.2.3 From 969e57adc2589a0a0ae5edbbe7b92062565ce70b Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:27:46 +0200 Subject: mtd: mtdchar: rename functions We are going to re-work the MTD interface and change 'mtd->write()' to 'mtd_write()', 'mtd->read()' to 'mtd_read()' and so forth for all functions in the 'struct mtd_info' structure. However, mtdchar.c has its own 'mtd_read()', 'mtd_write()', etc functions which collide with our changes. This patch renames these functions to 'mtdchar_read()', 'mtdchar_write()', etc. Additionally, to make the 'mtdchar.c' file look consistent, rename similarly all the other functions starting with 'mtd_'. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 76 ++++++++++++++++++++++++++------------------------- 1 file changed, 39 insertions(+), 37 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index e7dc732ddabc..00423cc85807 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -51,7 +51,7 @@ struct mtd_file_info { enum mtd_file_modes mode; }; -static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) +static loff_t mtdchar_lseek(struct file *file, loff_t offset, int orig) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; @@ -77,7 +77,7 @@ static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) -static int mtd_open(struct inode *inode, struct file *file) +static int mtdchar_open(struct inode *inode, struct file *file) { int minor = iminor(inode); int devnum = minor >> 1; @@ -142,11 +142,11 @@ static int mtd_open(struct inode *inode, struct file *file) out: mutex_unlock(&mtd_mutex); return ret; -} /* mtd_open */ +} /* mtdchar_open */ /*====================================================================*/ -static int mtd_close(struct inode *inode, struct file *file) +static int mtdchar_close(struct inode *inode, struct file *file) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; @@ -164,7 +164,7 @@ static int mtd_close(struct inode *inode, struct file *file) kfree(mfi); return 0; -} /* mtd_close */ +} /* mtdchar_close */ /* Back in June 2001, dwmw2 wrote: * @@ -184,7 +184,8 @@ static int mtd_close(struct inode *inode, struct file *file) * alignment requirements are not met in the NAND subdriver. */ -static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos) +static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, + loff_t *ppos) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; @@ -265,9 +266,10 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t kfree(kbuf); return total_retlen; -} /* mtd_read */ +} /* mtdchar_read */ -static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos) +static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t count, + loff_t *ppos) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; @@ -345,7 +347,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count kfree(kbuf); return total_retlen; -} /* mtd_write */ +} /* mtdchar_write */ /*====================================================================== @@ -387,7 +389,7 @@ static int otp_select_filemode(struct mtd_file_info *mfi, int mode) # define otp_select_filemode(f,m) -EOPNOTSUPP #endif -static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd, +static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, uint64_t start, uint32_t length, void __user *ptr, uint32_t __user *retp) { @@ -436,7 +438,7 @@ static int mtd_do_writeoob(struct file *file, struct mtd_info *mtd, return ret; } -static int mtd_do_readoob(struct file *file, struct mtd_info *mtd, +static int mtdchar_readoob(struct file *file, struct mtd_info *mtd, uint64_t start, uint32_t length, void __user *ptr, uint32_t __user *retp) { @@ -530,7 +532,7 @@ static int shrink_ecclayout(const struct nand_ecclayout *from, return 0; } -static int mtd_blkpg_ioctl(struct mtd_info *mtd, +static int mtdchar_blkpg_ioctl(struct mtd_info *mtd, struct blkpg_ioctl_arg __user *arg) { struct blkpg_ioctl_arg a; @@ -566,7 +568,7 @@ static int mtd_blkpg_ioctl(struct mtd_info *mtd, } } -static int mtd_write_ioctl(struct mtd_info *mtd, +static int mtdchar_write_ioctl(struct mtd_info *mtd, struct mtd_write_req __user *argp) { struct mtd_write_req req; @@ -615,7 +617,7 @@ static int mtd_write_ioctl(struct mtd_info *mtd, return ret; } -static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) +static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; @@ -755,7 +757,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_writeoob(file, mtd, buf.start, buf.length, + ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, buf.ptr, &buf_user->length); break; } @@ -769,7 +771,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_readoob(file, mtd, buf.start, buf.length, + ret = mtdchar_readoob(file, mtd, buf.start, buf.length, buf.ptr, &buf_user->start); break; } @@ -782,7 +784,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_writeoob(file, mtd, buf.start, buf.length, + ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, (void __user *)(uintptr_t)buf.usr_ptr, &buf_user->length); break; @@ -796,7 +798,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_readoob(file, mtd, buf.start, buf.length, + ret = mtdchar_readoob(file, mtd, buf.start, buf.length, (void __user *)(uintptr_t)buf.usr_ptr, &buf_user->length); break; @@ -804,7 +806,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) case MEMWRITE: { - ret = mtd_write_ioctl(mtd, + ret = mtdchar_write_ioctl(mtd, (struct mtd_write_req __user *)arg); break; } @@ -1014,7 +1016,7 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) case BLKPG: { - ret = mtd_blkpg_ioctl(mtd, + ret = mtdchar_blkpg_ioctl(mtd, (struct blkpg_ioctl_arg __user *)arg); break; } @@ -1033,12 +1035,12 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) return ret; } /* memory_ioctl */ -static long mtd_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) +static long mtdchar_unlocked_ioctl(struct file *file, u_int cmd, u_long arg) { int ret; mutex_lock(&mtd_mutex); - ret = mtd_ioctl(file, cmd, arg); + ret = mtdchar_ioctl(file, cmd, arg); mutex_unlock(&mtd_mutex); return ret; @@ -1055,7 +1057,7 @@ struct mtd_oob_buf32 { #define MEMWRITEOOB32 _IOWR('M', 3, struct mtd_oob_buf32) #define MEMREADOOB32 _IOWR('M', 4, struct mtd_oob_buf32) -static long mtd_compat_ioctl(struct file *file, unsigned int cmd, +static long mtdchar_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) { struct mtd_file_info *mfi = file->private_data; @@ -1074,7 +1076,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_writeoob(file, mtd, buf.start, + ret = mtdchar_writeoob(file, mtd, buf.start, buf.length, compat_ptr(buf.ptr), &buf_user->length); break; @@ -1089,13 +1091,13 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, if (copy_from_user(&buf, argp, sizeof(buf))) ret = -EFAULT; else - ret = mtd_do_readoob(file, mtd, buf.start, + ret = mtdchar_readoob(file, mtd, buf.start, buf.length, compat_ptr(buf.ptr), &buf_user->start); break; } default: - ret = mtd_ioctl(file, cmd, (unsigned long)argp); + ret = mtdchar_ioctl(file, cmd, (unsigned long)argp); } mutex_unlock(&mtd_mutex); @@ -1111,7 +1113,7 @@ static long mtd_compat_ioctl(struct file *file, unsigned int cmd, * mappings) */ #ifndef CONFIG_MMU -static unsigned long mtd_get_unmapped_area(struct file *file, +static unsigned long mtdchar_get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, unsigned long pgoff, @@ -1144,7 +1146,7 @@ static unsigned long mtd_get_unmapped_area(struct file *file, /* * set up a mapping for shared memory segments */ -static int mtd_mmap(struct file *file, struct vm_area_struct *vma) +static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma) { #ifdef CONFIG_MMU struct mtd_file_info *mfi = file->private_data; @@ -1185,18 +1187,18 @@ static int mtd_mmap(struct file *file, struct vm_area_struct *vma) static const struct file_operations mtd_fops = { .owner = THIS_MODULE, - .llseek = mtd_lseek, - .read = mtd_read, - .write = mtd_write, - .unlocked_ioctl = mtd_unlocked_ioctl, + .llseek = mtdchar_lseek, + .read = mtdchar_read, + .write = mtdchar_write, + .unlocked_ioctl = mtdchar_unlocked_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = mtd_compat_ioctl, + .compat_ioctl = mtdchar_compat_ioctl, #endif - .open = mtd_open, - .release = mtd_close, - .mmap = mtd_mmap, + .open = mtdchar_open, + .release = mtdchar_close, + .mmap = mtdchar_mmap, #ifndef CONFIG_MMU - .get_unmapped_area = mtd_get_unmapped_area, + .get_unmapped_area = mtdchar_get_unmapped_area, #endif }; -- cgit v1.2.3 From 7e1f0dc0551b99acb5e8fa161a7ac401994d57d8 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 15:25:39 +0200 Subject: mtd: introduce mtd_erase interface This patch is part of a patch-set which changes the MTD interface from 'mtd->func()' form to 'mtd_func()' form. We need this because we want to add common code to to all drivers in the mtd core level, which is impossible with the current interface when MTD clients call driver functions like 'read()' or 'write()' directly. At this point we just introduce a new inline wrapper function, but later some of them are expected to gain more code. E.g., the input parameters check should be moved to the wrappers rather than be duplicated at many drivers. This particular patch introduced the 'mtd_erase()' interface. The following patches add all the other interfaces one by one. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/ftl.c | 2 +- drivers/mtd/inftlmount.c | 4 ++-- drivers/mtd/mtdblock.c | 2 +- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/mtdswap.c | 2 +- drivers/mtd/nftlmount.c | 2 +- drivers/mtd/rfd_ftl.c | 2 +- drivers/mtd/sm_ftl.c | 2 +- drivers/mtd/tests/mtd_oobtest.c | 2 +- drivers/mtd/tests/mtd_pagetest.c | 2 +- drivers/mtd/tests/mtd_speedtest.c | 4 ++-- drivers/mtd/tests/mtd_stresstest.c | 2 +- drivers/mtd/tests/mtd_subpagetest.c | 2 +- drivers/mtd/tests/mtd_torturetest.c | 2 +- drivers/mtd/ubi/io.c | 2 +- drivers/staging/spectra/lld_mtd.c | 2 +- fs/jffs2/erase.c | 2 +- fs/logfs/dev_mtd.c | 2 +- include/linux/mtd/mtd.h | 19 ++++++++++++++----- 22 files changed, 37 insertions(+), 28 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index c7382bb686c6..a982889277c8 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -355,7 +355,7 @@ static int erase_xfer(partition_t *part, erase->len = 1 << part->header.EraseUnitSize; erase->priv = (u_long)part; - ret = part->mbd.mtd->erase(part->mbd.mtd, erase); + ret = mtd_erase(part->mbd.mtd, erase); if (!ret) xfer->EraseCount++; diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 2ff601f816ce..0d946f10a682 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -220,7 +220,7 @@ static int find_boot_record(struct INFTLrecord *inftl) */ instr->addr = ip->Reserved0 * inftl->EraseSize; instr->len = inftl->EraseSize; - mtd->erase(mtd, instr); + mtd_erase(mtd, instr); } if ((ip->lastUnit - ip->firstUnit + 1) < ip->virtualUnits) { printk(KERN_WARNING "INFTL: Media Header " @@ -393,7 +393,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) mark only the failed block in the bbt. */ for (physblock = 0; physblock < inftl->EraseSize; physblock += instr->len, instr->addr += instr->len) { - mtd->erase(inftl->mbd.mtd, instr); + mtd_erase(inftl->mbd.mtd, instr); if (instr->state == MTD_ERASE_FAILED) { printk(KERN_WARNING "INFTL: error while formatting block %d\n", diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index 7c1dc908a174..9b01cb0266e4 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -85,7 +85,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&wait_q, &wait); - ret = mtd->erase(mtd, &erase); + ret = mtd_erase(mtd, &erase); if (ret) { set_current_state(TASK_RUNNING); remove_wait_queue(&wait_q, &wait); diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 00423cc85807..41d64ff4c252 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -731,7 +731,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) wq_head is no longer there when the callback routine tries to wake us up. */ - ret = mtd->erase(mtd, erase); + ret = mtd_erase(mtd, erase); if (!ret) { set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&waitq, &wait); diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 6df4d4d4eb92..76123bd49314 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -379,7 +379,7 @@ static int concat_dev_erase(struct mtd_info *mtd, struct erase_info *erase) * FIXME: Allow INTERRUPTIBLE. Which means * not having the wait_queue head on the stack. */ - err = mtd->erase(mtd, erase); + err = mtd_erase(mtd, erase); if (!err) { set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&waitq, &wait); diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index f3cdce9a85a6..9b2d86323169 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -112,7 +112,7 @@ static int mtdoops_erase_block(struct mtdoops_context *cxt, int offset) set_current_state(TASK_INTERRUPTIBLE); add_wait_queue(&wait_q, &wait); - ret = mtd->erase(mtd, &erase); + ret = mtd_erase(mtd, &erase); if (ret) { set_current_state(TASK_RUNNING); remove_wait_queue(&wait_q, &wait); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index a0bd2de4752b..d318fee28595 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -257,7 +257,7 @@ static int part_erase(struct mtd_info *mtd, struct erase_info *instr) if (instr->addr >= mtd->size) return -EINVAL; instr->addr += part->offset; - ret = part->master->erase(part->master, instr); + ret = mtd_erase(part->master, instr); if (ret) { if (instr->fail_addr != MTD_FAIL_ADDR_UNKNOWN) instr->fail_addr -= part->offset; diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index bd9590c723e4..4e12875a916c 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -567,7 +567,7 @@ retry: erase.len = mtd->erasesize; erase.priv = (u_long)&wq; - ret = mtd->erase(mtd, &erase); + ret = mtd_erase(mtd, &erase); if (ret) { if (retries++ < MTDSWAP_ERASE_RETRIES) { dev_warn(d->dev, diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index ac4092591aea..9164a56fb5c0 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c @@ -326,7 +326,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) instr->mtd = nftl->mbd.mtd; instr->addr = block * nftl->EraseSize; instr->len = nftl->EraseSize; - mtd->erase(mtd, instr); + mtd_erase(mtd, instr); if (instr->state == MTD_ERASE_FAILED) { printk("Error while formatting block %d\n", block); diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index 73ae217a4252..39de8727a524 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -342,7 +342,7 @@ static int erase_block(struct partition *part, int block) part->blocks[block].state = BLOCK_ERASING; part->blocks[block].free_sectors = 0; - rc = part->mbd.mtd->erase(part->mbd.mtd, erase); + rc = mtd_erase(part->mbd.mtd, erase); if (rc) { printk(KERN_ERR PREFIX "erase of region %llx,%llx on '%s' " diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index 1c9f307ae0a1..2f1acb1ab5e8 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -479,7 +479,7 @@ static int sm_erase_block(struct sm_ftl *ftl, int zone_num, uint16_t block, return -EIO; } - if (mtd->erase(mtd, &erase)) { + if (mtd_erase(mtd, &erase)) { sm_printk("erase of block %d in zone %d failed", block, zone_num); goto error; diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 933f7e5f32d3..7d52854c16dd 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -78,7 +78,7 @@ static int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index afafb6935fd0..271819fabb55 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -77,7 +77,7 @@ static int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index 493b367bdd35..f67a65e21043 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -79,7 +79,7 @@ static int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; @@ -105,7 +105,7 @@ static int multiblock_erase(int ebnum, int blocks) ei.addr = addr; ei.len = mtd->erasesize * blocks; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d, blocks %d\n", err, ebnum, blocks); diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 811642fea6b4..a204a9f90524 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -112,7 +112,7 @@ static int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (unlikely(err)) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 1a05bfac4eee..16d0c05024d7 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -80,7 +80,7 @@ static int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 03ab649a6964..102c79b7ac66 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -105,7 +105,7 @@ static inline int erase_eraseblock(int ebnum) ei.addr = addr; ei.len = mtd->erasesize; - err = mtd->erase(mtd, &ei); + err = mtd_erase(mtd, &ei); if (err) { printk(PRINT_PREF "error %d while erasing EB %d\n", err, ebnum); return err; diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index f20b6f22f240..b6c8959e6c7e 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -361,7 +361,7 @@ retry: ei.callback = erase_callback; ei.priv = (unsigned long)&wq; - err = ubi->mtd->erase(ubi->mtd, &ei); + err = mtd_erase(ubi->mtd, &ei); if (err) { if (retries++ < UBI_IO_RETRIES) { dbg_io("error %d while erasing PEB %d, retry", diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index a9c309a167c2..d638fafab649 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -188,7 +188,7 @@ u16 mtd_Erase_Block(u32 block_add) erase.len = spectra_mtd->erasesize; erase.priv = (unsigned long)∁ - ret = spectra_mtd->erase(spectra_mtd, &erase); + ret = mtd_erase(spectra_mtd, &erase); if (!ret) { wait_for_completion(&comp); if (erase.state != MTD_ERASE_DONE) diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c index e513f1913c15..540e8eca1b49 100644 --- a/fs/jffs2/erase.c +++ b/fs/jffs2/erase.c @@ -74,7 +74,7 @@ static void jffs2_erase_block(struct jffs2_sb_info *c, ((struct erase_priv_struct *)instr->priv)->jeb = jeb; ((struct erase_priv_struct *)instr->priv)->c = c; - ret = c->mtd->erase(c->mtd, instr); + ret = mtd_erase(c->mtd, instr); if (!ret) return; diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index eb423ebcf538..046362894352 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -105,7 +105,7 @@ static int logfs_mtd_erase(struct super_block *sb, loff_t ofs, size_t len, ei.len = len; ei.callback = logfs_erase_callback; ei.priv = (long)&complete; - ret = mtd->erase(mtd, &ei); + ret = mtd_erase(mtd, &ei); if (ret) return -EIO; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9f5b312af783..201bad557047 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -171,11 +171,8 @@ struct mtd_info { struct mtd_erase_region_info *eraseregions; /* - * Erase is an asynchronous operation. Device drivers are supposed - * to call instr->callback() whenever the operation completes, even - * if it completes with a failure. - * Callers are supposed to pass a callback function and wait for it - * to be called before writing to the block. + * Do not call via these pointers, use corresponding mtd_*() + * wrappers instead. */ int (*erase) (struct mtd_info *mtd, struct erase_info *instr); @@ -274,6 +271,18 @@ struct mtd_info { void (*put_device) (struct mtd_info *mtd); }; +/* + * Erase is an asynchronous operation. Device drivers are supposed + * to call instr->callback() whenever the operation completes, even + * if it completes with a failure. + * Callers are supposed to pass a callback function and wait for it + * to be called before writing to the block. + */ +static inline int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) +{ + return mtd->erase(mtd, instr); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From d35ea200c0fb5315f16fb2599a4bafd9c1a7b386 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:00:37 +0200 Subject: mtd: introduce mtd_point interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdpart.c | 4 ++-- fs/jffs2/erase.c | 4 ++-- fs/jffs2/readinode.c | 4 ++-- fs/jffs2/scan.c | 4 ++-- include/linux/mtd/mtd.h | 14 ++++++++++---- 5 files changed, 18 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index d318fee28595..5b664722e5b0 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -89,8 +89,8 @@ static int part_point(struct mtd_info *mtd, loff_t from, size_t len, len = 0; else if (from + len > mtd->size) len = mtd->size - from; - return part->master->point (part->master, from + part->offset, - len, retlen, virt, phys); + return mtd_point(part->master, from + part->offset, len, retlen, + virt, phys); } static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c index 540e8eca1b49..53f8794fda6a 100644 --- a/fs/jffs2/erase.c +++ b/fs/jffs2/erase.c @@ -340,8 +340,8 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl if (c->mtd->point) { unsigned long *wordebuf; - ret = c->mtd->point(c->mtd, jeb->offset, c->sector_size, - &retlen, &ebuf, NULL); + ret = mtd_point(c->mtd, jeb->offset, c->sector_size, &retlen, + &ebuf, NULL); if (ret) { D1(printk(KERN_DEBUG "MTD point failed %d\n", ret)); goto do_flash_read; diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c index ee57bac1ba6d..dde61effeda2 100644 --- a/fs/jffs2/readinode.c +++ b/fs/jffs2/readinode.c @@ -63,8 +63,8 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info /* TODO: instead, incapsulate point() stuff to jffs2_flash_read(), * adding and jffs2_flash_read_end() interface. */ if (c->mtd->point) { - err = c->mtd->point(c->mtd, ofs, len, &retlen, - (void **)&buffer, NULL); + err = mtd_point(c->mtd, ofs, len, &retlen, (void **)&buffer, + NULL); if (!err && retlen < len) { JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize); c->mtd->unpoint(c->mtd, ofs, retlen); diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 28107ca136e4..53e05c8e5b69 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -97,8 +97,8 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) size_t pointlen, try_size; if (c->mtd->point) { - ret = c->mtd->point(c->mtd, 0, c->mtd->size, &pointlen, - (void **)&flashbuf, NULL); + ret = mtd_point(c->mtd, 0, c->mtd->size, &pointlen, + (void **)&flashbuf, NULL); if (!ret && pointlen < c->mtd->size) { /* Don't muck about if it won't let us point to the whole flash */ D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", pointlen)); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 201bad557047..ca7bfdaf7a6f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -175,11 +175,8 @@ struct mtd_info { * wrappers instead. */ int (*erase) (struct mtd_info *mtd, struct erase_info *instr); - - /* This stuff for eXecute-In-Place */ - /* phys is optional and may be set to NULL */ int (*point) (struct mtd_info *mtd, loff_t from, size_t len, - size_t *retlen, void **virt, resource_size_t *phys); + size_t *retlen, void **virt, resource_size_t *phys); /* We probably shouldn't allow XIP if the unpoint isn't a NULL */ void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len); @@ -283,6 +280,15 @@ static inline int mtd_erase(struct mtd_info *mtd, struct erase_info *instr) return mtd->erase(mtd, instr); } +/* + * This stuff for eXecute-In-Place. phys is optional and may be set to NULL. + */ +static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, void **virt, resource_size_t *phys) +{ + return mtd->point(mtd, from, len, retlen, virt, phys); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 7219778ad9c18cc2c05c7fca0abe026afbc19dfb Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:05:52 +0200 Subject: mtd: introduce mtd_unpoint interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdpart.c | 2 +- fs/jffs2/erase.c | 4 ++-- fs/jffs2/readinode.c | 6 +++--- fs/jffs2/scan.c | 4 ++-- include/linux/mtd/mtd.h | 8 ++++++-- 5 files changed, 14 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 5b664722e5b0..b09624a5497c 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -97,7 +97,7 @@ static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len) { struct mtd_part *part = PART(mtd); - part->master->unpoint(part->master, from + part->offset, len); + mtd_unpoint(part->master, from + part->offset, len); } static unsigned long part_get_unmapped_area(struct mtd_info *mtd, diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c index 53f8794fda6a..ffdf4fca9c54 100644 --- a/fs/jffs2/erase.c +++ b/fs/jffs2/erase.c @@ -349,7 +349,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl if (retlen < c->sector_size) { /* Don't muck about if it won't let us point to the whole erase sector */ D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", retlen)); - c->mtd->unpoint(c->mtd, jeb->offset, retlen); + mtd_unpoint(c->mtd, jeb->offset, retlen); goto do_flash_read; } wordebuf = ebuf-sizeof(*wordebuf); @@ -358,7 +358,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl if (*++wordebuf != ~0) break; } while(--retlen); - c->mtd->unpoint(c->mtd, jeb->offset, c->sector_size); + mtd_unpoint(c->mtd, jeb->offset, c->sector_size); if (retlen) { printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08tx\n", *wordebuf, jeb->offset + c->sector_size-retlen*sizeof(*wordebuf)); diff --git a/fs/jffs2/readinode.c b/fs/jffs2/readinode.c index dde61effeda2..fca2f84e1add 100644 --- a/fs/jffs2/readinode.c +++ b/fs/jffs2/readinode.c @@ -67,7 +67,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info NULL); if (!err && retlen < len) { JFFS2_WARNING("MTD point returned len too short: %zu instead of %u.\n", retlen, tn->csize); - c->mtd->unpoint(c->mtd, ofs, retlen); + mtd_unpoint(c->mtd, ofs, retlen); } else if (err) JFFS2_WARNING("MTD point failed: error code %d.\n", err); else @@ -101,7 +101,7 @@ static int check_node_data(struct jffs2_sb_info *c, struct jffs2_tmp_dnode_info kfree(buffer); #ifndef __ECOS else - c->mtd->unpoint(c->mtd, ofs, len); + mtd_unpoint(c->mtd, ofs, len); #endif if (crc != tn->data_crc) { @@ -137,7 +137,7 @@ free_out: kfree(buffer); #ifndef __ECOS else - c->mtd->unpoint(c->mtd, ofs, len); + mtd_unpoint(c->mtd, ofs, len); #endif return err; } diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 53e05c8e5b69..72f3960f44a9 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -102,7 +102,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) if (!ret && pointlen < c->mtd->size) { /* Don't muck about if it won't let us point to the whole flash */ D1(printk(KERN_DEBUG "MTD point returned len too short: 0x%zx\n", pointlen)); - c->mtd->unpoint(c->mtd, 0, pointlen); + mtd_unpoint(c->mtd, 0, pointlen); flashbuf = NULL; } if (ret) @@ -273,7 +273,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c) kfree(flashbuf); #ifndef __ECOS else - c->mtd->unpoint(c->mtd, 0, c->mtd->size); + mtd_unpoint(c->mtd, 0, c->mtd->size); #endif kfree(s); return ret; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index ca7bfdaf7a6f..a7d22b7fcb4c 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -177,8 +177,6 @@ struct mtd_info { int (*erase) (struct mtd_info *mtd, struct erase_info *instr); int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, void **virt, resource_size_t *phys); - - /* We probably shouldn't allow XIP if the unpoint isn't a NULL */ void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len); /* Allow NOMMU mmap() to directly map the device (if not NULL) @@ -289,6 +287,12 @@ static inline int mtd_point(struct mtd_info *mtd, loff_t from, size_t len, return mtd->point(mtd, from, len, retlen, virt, phys); } +/* We probably shouldn't allow XIP if the unpoint isn't a NULL */ +static inline void mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) +{ + return mtd->unpoint(mtd, from, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 04c601bfa4cb29c968dcb66e44c799c9c01d8675 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:10:15 +0200 Subject: mtd: introduce mtd_get_unmapped_area interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 4 ++-- drivers/mtd/mtdpart.c | 3 +-- fs/romfs/mmap-nommu.c | 2 +- include/linux/mtd/mtd.h | 18 +++++++++++++----- 5 files changed, 18 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 41d64ff4c252..c51f04a00afb 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -1135,7 +1135,7 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file, if (offset > mtd->size - len) return (unsigned long) -EINVAL; - return mtd->get_unmapped_area(mtd, len, offset, flags); + return mtd_get_unmapped_area(mtd, len, offset, flags); } /* can't map directly */ diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 76123bd49314..b3895cf20bb2 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -726,8 +726,8 @@ static unsigned long concat_get_unmapped_area(struct mtd_info *mtd, return (unsigned long) -EINVAL; if (subdev->get_unmapped_area) - return subdev->get_unmapped_area(subdev, len, offset, - flags); + return mtd_get_unmapped_area(subdev, len, offset, + flags); break; } diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index b09624a5497c..55a9cb544fc1 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -108,8 +108,7 @@ static unsigned long part_get_unmapped_area(struct mtd_info *mtd, struct mtd_part *part = PART(mtd); offset += part->offset; - return part->master->get_unmapped_area(part->master, len, offset, - flags); + return mtd_get_unmapped_area(part->master, len, offset, flags); } static int part_read_oob(struct mtd_info *mtd, loff_t from, diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c index eed99428f104..d5168e8e7dcb 100644 --- a/fs/romfs/mmap-nommu.c +++ b/fs/romfs/mmap-nommu.c @@ -53,7 +53,7 @@ static unsigned long romfs_get_unmapped_area(struct file *file, if (offset > mtd->size - len) return (unsigned long) -EINVAL; - return mtd->get_unmapped_area(mtd, len, offset, flags); + return mtd_get_unmapped_area(mtd, len, offset, flags); } cant_map_directly: diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index a7d22b7fcb4c..f38e8276b408 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -178,11 +178,6 @@ struct mtd_info { int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, void **virt, resource_size_t *phys); void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len); - - /* Allow NOMMU mmap() to directly map the device (if not NULL) - * - return the address to which the offset maps - * - return -ENOSYS to indicate refusal to do the mapping - */ unsigned long (*get_unmapped_area) (struct mtd_info *mtd, unsigned long len, unsigned long offset, @@ -293,6 +288,19 @@ static inline void mtd_unpoint(struct mtd_info *mtd, loff_t from, size_t len) return mtd->unpoint(mtd, from, len); } +/* + * Allow NOMMU mmap() to directly map the device (if not NULL) + * - return the address to which the offset maps + * - return -ENOSYS to indicate refusal to do the mapping + */ +static inline unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, + unsigned long len, + unsigned long offset, + unsigned long flags) +{ + return mtd->get_unmapped_area(mtd, len, offset, flags); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 329ad399a9b3adf52c90637b21ca029fcf7f8795 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:30:16 +0200 Subject: mtd: introduce mtd_read interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- arch/arm/mach-davinci/board-da850-evm.c | 2 +- arch/cris/arch-v32/drivers/axisflashmap.c | 4 +-- drivers/mtd/afs.c | 4 +-- drivers/mtd/ar7part.c | 15 ++++++----- drivers/mtd/bcm63xxpart.c | 12 ++++----- drivers/mtd/ftl.c | 41 ++++++++++++++++--------------- drivers/mtd/inftlcore.c | 19 ++++++++------ drivers/mtd/inftlmount.c | 10 ++++---- drivers/mtd/mtdblock.c | 8 +++--- drivers/mtd/mtdblock_ro.c | 2 +- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 4 +-- drivers/mtd/mtdpart.c | 3 +-- drivers/mtd/mtdswap.c | 4 +-- drivers/mtd/nand/diskonchip.c | 4 +-- drivers/mtd/nand/nand_bbt.c | 6 ++--- drivers/mtd/nftlcore.c | 17 ++++++++----- drivers/mtd/nftlmount.c | 6 ++--- drivers/mtd/redboot.c | 4 +-- drivers/mtd/rfd_ftl.c | 24 +++++++++--------- drivers/mtd/ssfdc.c | 6 ++--- drivers/mtd/tests/mtd_pagetest.c | 28 ++++++++++----------- drivers/mtd/tests/mtd_readtest.c | 2 +- drivers/mtd/tests/mtd_speedtest.c | 8 +++--- drivers/mtd/tests/mtd_stresstest.c | 2 +- drivers/mtd/tests/mtd_subpagetest.c | 8 +++--- drivers/mtd/tests/mtd_torturetest.c | 2 +- drivers/mtd/ubi/debug.c | 2 +- drivers/mtd/ubi/io.c | 6 ++--- drivers/staging/spectra/lld_mtd.c | 8 +++--- fs/jffs2/erase.c | 2 +- fs/jffs2/wbuf.c | 9 ++++--- fs/logfs/dev_mtd.c | 2 +- include/linux/mtd/mtd.h | 9 ++++++- 35 files changed, 152 insertions(+), 135 deletions(-) (limited to 'drivers') diff --git a/arch/arm/mach-davinci/board-da850-evm.c b/arch/arm/mach-davinci/board-da850-evm.c index 6659a90dbcad..8b079f9d6924 100644 --- a/arch/arm/mach-davinci/board-da850-evm.c +++ b/arch/arm/mach-davinci/board-da850-evm.c @@ -127,7 +127,7 @@ static void da850_evm_m25p80_notify_add(struct mtd_info *mtd) size_t retlen; if (!strcmp(mtd->name, "MAC-Address")) { - mtd->read(mtd, 0, ETH_ALEN, &retlen, mac_addr); + mtd_read(mtd, 0, ETH_ALEN, &retlen, mac_addr); if (retlen == ETH_ALEN) pr_info("Read MAC addr from SPI Flash: %pM\n", mac_addr); diff --git a/arch/cris/arch-v32/drivers/axisflashmap.c b/arch/cris/arch-v32/drivers/axisflashmap.c index a2bde3744622..011bddbf073f 100644 --- a/arch/cris/arch-v32/drivers/axisflashmap.c +++ b/arch/cris/arch-v32/drivers/axisflashmap.c @@ -413,8 +413,8 @@ static int __init init_axis_flash(void) } while (blockstat && ptable_sector); #endif if (ptable_sector) { - main_mtd->read(main_mtd, ptable_sector, PAGESIZE, - &len, page); + mtd_read(main_mtd, ptable_sector, PAGESIZE, &len, + page); ptable_head = &((struct partitiontable *) page)->head; } diff --git a/drivers/mtd/afs.c b/drivers/mtd/afs.c index 89a02f6f65dc..5a3942bf109c 100644 --- a/drivers/mtd/afs.c +++ b/drivers/mtd/afs.c @@ -75,7 +75,7 @@ afs_read_footer(struct mtd_info *mtd, u_int *img_start, u_int *iis_start, size_t sz; int ret; - ret = mtd->read(mtd, ptr, sizeof(fs), &sz, (u_char *) &fs); + ret = mtd_read(mtd, ptr, sizeof(fs), &sz, (u_char *)&fs); if (ret >= 0 && sz != sizeof(fs)) ret = -EINVAL; @@ -132,7 +132,7 @@ afs_read_iis(struct mtd_info *mtd, struct image_info_struct *iis, u_int ptr) int ret, i; memset(iis, 0, sizeof(*iis)); - ret = mtd->read(mtd, ptr, sizeof(*iis), &sz, (u_char *) iis); + ret = mtd_read(mtd, ptr, sizeof(*iis), &sz, (u_char *)iis); if (ret < 0) goto failed; diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c index f40ea4547554..945393129952 100644 --- a/drivers/mtd/ar7part.c +++ b/drivers/mtd/ar7part.c @@ -73,8 +73,8 @@ static int create_mtd_partitions(struct mtd_info *master, do { /* Try 10 blocks starting from master->erasesize */ offset = pre_size; - master->read(master, offset, - sizeof(header), &len, (uint8_t *)&header); + mtd_read(master, offset, sizeof(header), &len, + (uint8_t *)&header); if (!strncmp((char *)&header, "TIENV0.8", 8)) ar7_parts[1].offset = pre_size; if (header.checksum == LOADER_MAGIC1) @@ -95,16 +95,16 @@ static int create_mtd_partitions(struct mtd_info *master, case LOADER_MAGIC1: while (header.length) { offset += sizeof(header) + header.length; - master->read(master, offset, sizeof(header), - &len, (uint8_t *)&header); + mtd_read(master, offset, sizeof(header), &len, + (uint8_t *)&header); } root_offset = offset + sizeof(header) + 4; break; case LOADER_MAGIC2: while (header.length) { offset += sizeof(header) + header.length; - master->read(master, offset, sizeof(header), - &len, (uint8_t *)&header); + mtd_read(master, offset, sizeof(header), &len, + (uint8_t *)&header); } root_offset = offset + sizeof(header) + 4 + 0xff; root_offset &= ~(uint32_t)0xff; @@ -114,8 +114,7 @@ static int create_mtd_partitions(struct mtd_info *master, break; } - master->read(master, root_offset, - sizeof(header), &len, (u8 *)&header); + mtd_read(master, root_offset, sizeof(header), &len, (u8 *)&header); if (header.checksum != SQUASHFS_MAGIC) { root_offset += master->erasesize - 1; root_offset &= ~(master->erasesize - 1); diff --git a/drivers/mtd/bcm63xxpart.c b/drivers/mtd/bcm63xxpart.c index 9ee8bc426e93..608321ee056e 100644 --- a/drivers/mtd/bcm63xxpart.c +++ b/drivers/mtd/bcm63xxpart.c @@ -48,8 +48,8 @@ static int bcm63xx_detect_cfe(struct mtd_info *master) int ret; size_t retlen; - ret = master->read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen, - (void *)buf); + ret = mtd_read(master, BCM963XX_CFE_VERSION_OFFSET, 5, &retlen, + (void *)buf); buf[retlen] = 0; if (ret) @@ -59,8 +59,8 @@ static int bcm63xx_detect_cfe(struct mtd_info *master) return 0; /* very old CFE's do not have the cfe-v string, so check for magic */ - ret = master->read(master, BCM63XX_CFE_MAGIC_OFFSET, 8, &retlen, - (void *)buf); + ret = mtd_read(master, BCM63XX_CFE_MAGIC_OFFSET, 8, &retlen, + (void *)buf); buf[retlen] = 0; return strncmp("CFE1CFE1", buf, 8); @@ -95,8 +95,8 @@ static int bcm63xx_parse_cfe_partitions(struct mtd_info *master, return -ENOMEM; /* Get the tag */ - ret = master->read(master, cfelen, sizeof(struct bcm_tag), &retlen, - (void *)buf); + ret = mtd_read(master, cfelen, sizeof(struct bcm_tag), &retlen, + (void *)buf); if (retlen != sizeof(struct bcm_tag)) { vfree(buf); diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index a982889277c8..12fd7ebd3fd8 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -168,8 +168,8 @@ static int scan_header(partition_t *part) (offset + sizeof(header)) < max_offset; offset += part->mbd.mtd->erasesize ? : 0x2000) { - err = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &ret, - (unsigned char *)&header); + err = mtd_read(part->mbd.mtd, offset, sizeof(header), &ret, + (unsigned char *)&header); if (err) return err; @@ -224,8 +224,8 @@ static int build_maps(partition_t *part) for (i = 0; i < le16_to_cpu(part->header.NumEraseUnits); i++) { offset = ((i + le16_to_cpu(part->header.FirstPhysicalEUN)) << part->header.EraseUnitSize); - ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(header), &retval, - (unsigned char *)&header); + ret = mtd_read(part->mbd.mtd, offset, sizeof(header), &retval, + (unsigned char *)&header); if (ret) goto out_XferInfo; @@ -289,9 +289,9 @@ static int build_maps(partition_t *part) part->EUNInfo[i].Deleted = 0; offset = part->EUNInfo[i].Offset + le32_to_cpu(header.BAMOffset); - ret = part->mbd.mtd->read(part->mbd.mtd, offset, - part->BlocksPerUnit * sizeof(uint32_t), &retval, - (unsigned char *)part->bam_cache); + ret = mtd_read(part->mbd.mtd, offset, + part->BlocksPerUnit * sizeof(uint32_t), &retval, + (unsigned char *)part->bam_cache); if (ret) goto out_bam_cache; @@ -485,9 +485,9 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, offset = eun->Offset + le32_to_cpu(part->header.BAMOffset); - ret = part->mbd.mtd->read(part->mbd.mtd, offset, - part->BlocksPerUnit * sizeof(uint32_t), - &retlen, (u_char *) (part->bam_cache)); + ret = mtd_read(part->mbd.mtd, offset, + part->BlocksPerUnit * sizeof(uint32_t), &retlen, + (u_char *)(part->bam_cache)); /* mark the cache bad, in case we get an error later */ part->bam_index = 0xffff; @@ -523,8 +523,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, break; case BLOCK_DATA: case BLOCK_REPLACEMENT: - ret = part->mbd.mtd->read(part->mbd.mtd, src, SECTOR_SIZE, - &retlen, (u_char *) buf); + ret = mtd_read(part->mbd.mtd, src, SECTOR_SIZE, &retlen, + (u_char *)buf); if (ret) { printk(KERN_WARNING "ftl: Error reading old xfer unit in copy_erase_unit\n"); return ret; @@ -747,10 +747,11 @@ static uint32_t find_free(partition_t *part) /* Invalidate cache */ part->bam_index = 0xffff; - ret = part->mbd.mtd->read(part->mbd.mtd, - part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), - part->BlocksPerUnit * sizeof(uint32_t), - &retlen, (u_char *) (part->bam_cache)); + ret = mtd_read(part->mbd.mtd, + part->EUNInfo[eun].Offset + le32_to_cpu(part->header.BAMOffset), + part->BlocksPerUnit * sizeof(uint32_t), + &retlen, + (u_char *)(part->bam_cache)); if (ret) { printk(KERN_WARNING"ftl: Error reading BAM in find_free\n"); @@ -810,8 +811,8 @@ static int ftl_read(partition_t *part, caddr_t buffer, else { offset = (part->EUNInfo[log_addr / bsize].Offset + (log_addr % bsize)); - ret = part->mbd.mtd->read(part->mbd.mtd, offset, SECTOR_SIZE, - &retlen, (u_char *) buffer); + ret = mtd_read(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, + (u_char *)buffer); if (ret) { printk(KERN_WARNING "Error reading MTD device in ftl_read()\n"); @@ -849,8 +850,8 @@ static int set_bam_entry(partition_t *part, uint32_t log_addr, le32_to_cpu(part->header.BAMOffset)); #ifdef PSYCHO_DEBUG - ret = part->mbd.mtd->read(part->mbd.mtd, offset, sizeof(uint32_t), - &retlen, (u_char *)&old_addr); + ret = mtd_read(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, + (u_char *)&old_addr); if (ret) { printk(KERN_WARNING"ftl: Error reading old_addr in set_bam_entry: %d\n",ret); return ret; diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index dd034efd1875..0b038bed7b9c 100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c @@ -343,14 +343,17 @@ static u16 INFTL_foldchain(struct INFTLrecord *inftl, unsigned thisVUC, unsigned if (BlockMap[block] == BLOCK_NIL) continue; - ret = mtd->read(mtd, (inftl->EraseSize * BlockMap[block]) + - (block * SECTORSIZE), SECTORSIZE, &retlen, - movebuf); + ret = mtd_read(mtd, + (inftl->EraseSize * BlockMap[block]) + (block * SECTORSIZE), + SECTORSIZE, + &retlen, + movebuf); if (ret < 0 && !mtd_is_bitflip(ret)) { - ret = mtd->read(mtd, - (inftl->EraseSize * BlockMap[block]) + - (block * SECTORSIZE), SECTORSIZE, - &retlen, movebuf); + ret = mtd_read(mtd, + (inftl->EraseSize * BlockMap[block]) + (block * SECTORSIZE), + SECTORSIZE, + &retlen, + movebuf); if (ret != -EIO) pr_debug("INFTL: error went away on retry?\n"); } @@ -914,7 +917,7 @@ foundit: } else { size_t retlen; loff_t ptr = (thisEUN * inftl->EraseSize) + blockofs; - int ret = mtd->read(mtd, ptr, SECTORSIZE, &retlen, buffer); + int ret = mtd_read(mtd, ptr, SECTORSIZE, &retlen, buffer); /* Handle corrected bit flips gracefully */ if (ret < 0 && !mtd_is_bitflip(ret)) diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 0d946f10a682..9bfbca5d88d6 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -73,8 +73,8 @@ static int find_boot_record(struct INFTLrecord *inftl) * Check for BNAND header first. Then whinge if it's found * but later checks fail. */ - ret = mtd->read(mtd, block * inftl->EraseSize, - SECTORSIZE, &retlen, buf); + ret = mtd_read(mtd, block * inftl->EraseSize, SECTORSIZE, + &retlen, buf); /* We ignore ret in case the ECC of the MediaHeader is invalid (which is apparently acceptable) */ if (retlen != SECTORSIZE) { @@ -118,8 +118,8 @@ static int find_boot_record(struct INFTLrecord *inftl) memcpy(mh, buf, sizeof(struct INFTLMediaHeader)); /* Read the spare media header at offset 4096 */ - mtd->read(mtd, block * inftl->EraseSize + 4096, - SECTORSIZE, &retlen, buf); + mtd_read(mtd, block * inftl->EraseSize + 4096, SECTORSIZE, + &retlen, buf); if (retlen != SECTORSIZE) { printk(KERN_WARNING "INFTL: Unable to read spare " "Media Header\n"); @@ -342,7 +342,7 @@ static int check_free_sectors(struct INFTLrecord *inftl, unsigned int address, int i; for (i = 0; i < len; i += SECTORSIZE) { - if (mtd->read(mtd, address, SECTORSIZE, &retlen, buf)) + if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf)) return -1; if (memcmpb(buf, 0xff, SECTORSIZE) != 0) return -1; diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index 9b01cb0266e4..b0644d2d2a6e 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -184,8 +184,8 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, mtdblk->cache_offset != sect_start) { /* fill the cache with the current sector */ mtdblk->cache_state = STATE_EMPTY; - ret = mtd->read(mtd, sect_start, sect_size, - &retlen, mtdblk->cache_data); + ret = mtd_read(mtd, sect_start, sect_size, + &retlen, mtdblk->cache_data); if (ret) return ret; if (retlen != sect_size) @@ -222,7 +222,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, mtd->name, pos, len); if (!sect_size) - return mtd->read(mtd, pos, len, &retlen, buf); + return mtd_read(mtd, pos, len, &retlen, buf); while (len > 0) { unsigned long sect_start = (pos/sect_size)*sect_size; @@ -241,7 +241,7 @@ static int do_cached_read (struct mtdblk_dev *mtdblk, unsigned long pos, mtdblk->cache_offset == sect_start) { memcpy (buf, mtdblk->cache_data + offset, size); } else { - ret = mtd->read(mtd, pos, size, &retlen, buf); + ret = mtd_read(mtd, pos, size, &retlen, buf); if (ret) return ret; if (retlen != size) diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c index 0470a6e86309..f5737b1153fa 100644 --- a/drivers/mtd/mtdblock_ro.c +++ b/drivers/mtd/mtdblock_ro.c @@ -30,7 +30,7 @@ static int mtdblock_readsect(struct mtd_blktrans_dev *dev, { size_t retlen; - if (dev->mtd->read(dev->mtd, (block * 512), 512, &retlen, buf)) + if (mtd_read(dev->mtd, (block * 512), 512, &retlen, buf)) return 1; return 0; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index c51f04a00afb..c7f484687fa3 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -232,7 +232,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, break; } default: - ret = mtd->read(mtd, *ppos, len, &retlen, kbuf); + ret = mtd_read(mtd, *ppos, len, &retlen, kbuf); } /* Nand returns -EBADMSG on ECC errors, but it returns * the data. For our userspace tools it is important diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index b3895cf20bb2..45460349fd12 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -91,7 +91,7 @@ concat_read(struct mtd_info *mtd, loff_t from, size_t len, /* Entire transaction goes into this subdev */ size = len; - err = subdev->read(subdev, from, size, &retsize, buf); + err = mtd_read(subdev, from, size, &retsize, buf); /* Save information about bitflips! */ if (unlikely(err)) { diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 9b2d86323169..23629ad08507 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -258,8 +258,8 @@ static void find_next_position(struct mtdoops_context *cxt) continue; /* Assume the page is used */ mark_page_used(cxt, page); - ret = mtd->read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, - &retlen, (u_char *) &count[0]); + ret = mtd_read(mtd, page * record_size, MTDOOPS_HEADER_SIZE, + &retlen, (u_char *)&count[0]); if (retlen != MTDOOPS_HEADER_SIZE || (ret < 0 && !mtd_is_bitflip(ret))) { printk(KERN_ERR "mtdoops: read failure at %ld (%td of %d read), err %d\n", diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 55a9cb544fc1..59cd7974bc50 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -70,8 +70,7 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len, len = 0; else if (from + len > mtd->size) len = mtd->size - from; - res = part->master->read(part->master, from + part->offset, - len, retlen, buf); + res = mtd_read(part->master, from + part->offset, len, retlen, buf); if (unlikely(res)) { if (mtd_is_bitflip(res)) mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected; diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 4e12875a916c..b3282d2aa8f8 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -736,7 +736,7 @@ static int mtdswap_move_block(struct mtdswap_dev *d, unsigned int oldblock, retries = 0; retry: - ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf); + ret = mtd_read(mtd, readpos, PAGE_SIZE, &retlen, d->page_buf); if (ret < 0 && !mtd_is_bitflip(ret)) { oldeb = d->eb_data + oldblock / d->pages_per_eblk; @@ -1161,7 +1161,7 @@ static int mtdswap_readsect(struct mtd_blktrans_dev *dev, retries = 0; retry: - ret = mtd->read(mtd, readpos, PAGE_SIZE, &retlen, buf); + ret = mtd_read(mtd, readpos, PAGE_SIZE, &retlen, buf); d->mtd_read_count++; if (mtd_is_bitflip(ret)) { diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c index 5780dbab6113..df921e7a496c 100644 --- a/drivers/mtd/nand/diskonchip.c +++ b/drivers/mtd/nand/diskonchip.c @@ -1072,7 +1072,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch size_t retlen; for (offs = 0; offs < mtd->size; offs += mtd->erasesize) { - ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf); + ret = mtd_read(mtd, offs, mtd->writesize, &retlen, buf); if (retlen != mtd->writesize) continue; if (ret) { @@ -1097,7 +1097,7 @@ static int __init find_media_headers(struct mtd_info *mtd, u_char *buf, const ch /* Only one mediaheader was found. We want buf to contain a mediaheader on return, so we'll have to re-read the one we found. */ offs = doc->mh0_page << this->page_shift; - ret = mtd->read(mtd, offs, mtd->writesize, &retlen, buf); + ret = mtd_read(mtd, offs, mtd->writesize, &retlen, buf); if (retlen != mtd->writesize) { /* Insanity. Give up. */ printk(KERN_ERR "Read DiskOnChip Media Header once, but can't reread it???\n"); diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 69148ae3bf58..1bcd6bc6798c 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -201,7 +201,7 @@ static int read_bbt(struct mtd_info *mtd, uint8_t *buf, int page, int num, from += marker_len; marker_len = 0; } - res = mtd->read(mtd, from, len, &retlen, buf); + res = mtd_read(mtd, from, len, &retlen, buf); if (res < 0) { if (mtd_is_eccerr(res)) { pr_info("nand_bbt: ECC error in BBT at " @@ -298,7 +298,7 @@ static int scan_read_raw_data(struct mtd_info *mtd, uint8_t *buf, loff_t offs, if (td->options & NAND_BBT_VERSION) len++; - return mtd->read(mtd, offs, len, &retlen, buf); + return mtd_read(mtd, offs, len, &retlen, buf); } /* Scan read raw data from flash */ @@ -756,7 +756,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, /* Make it block aligned */ to &= ~((loff_t)((1 << this->bbt_erase_shift) - 1)); len = 1 << this->bbt_erase_shift; - res = mtd->read(mtd, to, len, &retlen, buf); + res = mtd_read(mtd, to, len, &retlen, buf); if (res < 0) { if (retlen != len) { pr_info("nand_bbt: error reading block " diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index cda77b562ad4..1a9d9c1d3a74 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -423,12 +423,17 @@ static u16 NFTL_foldchain (struct NFTLrecord *nftl, unsigned thisVUC, unsigned p if (BlockMap[block] == BLOCK_NIL) continue; - ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) + (block * 512), - 512, &retlen, movebuf); + ret = mtd_read(mtd, + (nftl->EraseSize * BlockMap[block]) + (block * 512), + 512, + &retlen, + movebuf); if (ret < 0 && !mtd_is_bitflip(ret)) { - ret = mtd->read(mtd, (nftl->EraseSize * BlockMap[block]) - + (block * 512), 512, &retlen, - movebuf); + ret = mtd_read(mtd, + (nftl->EraseSize * BlockMap[block]) + (block * 512), + 512, + &retlen, + movebuf); if (ret != -EIO) printk("Error went away on retry.\n"); } @@ -771,7 +776,7 @@ static int nftl_readblock(struct mtd_blktrans_dev *mbd, unsigned long block, } else { loff_t ptr = (lastgoodEUN * nftl->EraseSize) + blockofs; size_t retlen; - int res = mtd->read(mtd, ptr, 512, &retlen, buffer); + int res = mtd_read(mtd, ptr, 512, &retlen, buffer); if (res < 0 && !mtd_is_bitflip(res)) return -EIO; diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index 9164a56fb5c0..b068dc8a3666 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c @@ -63,8 +63,8 @@ static int find_boot_record(struct NFTLrecord *nftl) /* Check for ANAND header first. Then can whinge if it's found but later checks fail */ - ret = mtd->read(mtd, block * nftl->EraseSize, SECTORSIZE, - &retlen, buf); + ret = mtd_read(mtd, block * nftl->EraseSize, SECTORSIZE, + &retlen, buf); /* We ignore ret in case the ECC of the MediaHeader is invalid (which is apparently acceptable) */ if (retlen != SECTORSIZE) { @@ -274,7 +274,7 @@ static int check_free_sectors(struct NFTLrecord *nftl, unsigned int address, int int i; for (i = 0; i < len; i += SECTORSIZE) { - if (mtd->read(mtd, address, SECTORSIZE, &retlen, buf)) + if (mtd_read(mtd, address, SECTORSIZE, &retlen, buf)) return -1; if (memcmpb(buf, 0xff, SECTORSIZE) != 0) return -1; diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c index e366b1d84ead..623d9b86d0d9 100644 --- a/drivers/mtd/redboot.c +++ b/drivers/mtd/redboot.c @@ -104,8 +104,8 @@ static int parse_redboot_partitions(struct mtd_info *master, printk(KERN_NOTICE "Searching for RedBoot partition table in %s at offset 0x%lx\n", master->name, offset); - ret = master->read(master, offset, - master->erasesize, &retlen, (void *)buf); + ret = mtd_read(master, offset, master->erasesize, &retlen, + (void *)buf); if (ret) goto out; diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index 39de8727a524..d9fe2d0533d9 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -200,9 +200,9 @@ static int scan_header(struct partition *part) part->sector_map[i] = -1; for (i=0, blocks_found=0; itotal_blocks; i++) { - rc = part->mbd.mtd->read(part->mbd.mtd, - i * part->block_size, part->header_size, - &retlen, (u_char*)part->header_cache); + rc = mtd_read(part->mbd.mtd, i * part->block_size, + part->header_size, &retlen, + (u_char *)part->header_cache); if (!rc && retlen != part->header_size) rc = -EIO; @@ -250,8 +250,8 @@ static int rfd_ftl_readsect(struct mtd_blktrans_dev *dev, u_long sector, char *b addr = part->sector_map[sector]; if (addr != -1) { - rc = part->mbd.mtd->read(part->mbd.mtd, addr, SECTOR_SIZE, - &retlen, (u_char*)buf); + rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, + (u_char *)buf); if (!rc && retlen != SECTOR_SIZE) rc = -EIO; @@ -372,9 +372,8 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old if (!map) goto err2; - rc = part->mbd.mtd->read(part->mbd.mtd, - part->blocks[block_no].offset, part->header_size, - &retlen, (u_char*)map); + rc = mtd_read(part->mbd.mtd, part->blocks[block_no].offset, + part->header_size, &retlen, (u_char *)map); if (!rc && retlen != part->header_size) rc = -EIO; @@ -413,8 +412,8 @@ static int move_block_contents(struct partition *part, int block_no, u_long *old } continue; } - rc = part->mbd.mtd->read(part->mbd.mtd, addr, - SECTOR_SIZE, &retlen, sector_data); + rc = mtd_read(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, + sector_data); if (!rc && retlen != SECTOR_SIZE) rc = -EIO; @@ -563,8 +562,9 @@ static int find_writable_block(struct partition *part, u_long *old_sector) } } - rc = part->mbd.mtd->read(part->mbd.mtd, part->blocks[block].offset, - part->header_size, &retlen, (u_char*)part->header_cache); + rc = mtd_read(part->mbd.mtd, part->blocks[block].offset, + part->header_size, &retlen, + (u_char *)part->header_cache); if (!rc && retlen != part->header_size) rc = -EIO; diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index 976e3d28b962..293e22a5710f 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c @@ -123,8 +123,8 @@ static int get_valid_cis_sector(struct mtd_info *mtd) */ for (k = 0, offset = 0; k < 4; k++, offset += mtd->erasesize) { if (!mtd->block_isbad(mtd, offset)) { - ret = mtd->read(mtd, offset, SECTOR_SIZE, &retlen, - sect_buf); + ret = mtd_read(mtd, offset, SECTOR_SIZE, &retlen, + sect_buf); /* CIS pattern match on the sector buffer */ if (ret < 0 || retlen != SECTOR_SIZE) { @@ -156,7 +156,7 @@ static int read_physical_sector(struct mtd_info *mtd, uint8_t *sect_buf, size_t retlen; loff_t offset = (loff_t)sect_no << SECTOR_SHIFT; - ret = mtd->read(mtd, offset, SECTOR_SIZE, &retlen, sect_buf); + ret = mtd_read(mtd, offset, SECTOR_SIZE, &retlen, sect_buf); if (ret < 0 || retlen != SECTOR_SIZE) return -1; diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 271819fabb55..6d62e24a03ed 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -127,7 +127,7 @@ static int verify_eraseblock(int ebnum) set_random_data(writebuf, mtd->erasesize); for (j = 0; j < pgcnt - 1; ++j, addr += pgsize) { /* Do a read to set the internal dataRAMs to different data */ - err = mtd->read(mtd, addr0, bufsize, &read, twopages); + err = mtd_read(mtd, addr0, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -135,7 +135,7 @@ static int verify_eraseblock(int ebnum) (long long)addr0); return err; } - err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); + err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -145,7 +145,7 @@ static int verify_eraseblock(int ebnum) } memset(twopages, 0, bufsize); read = 0; - err = mtd->read(mtd, addr, bufsize, &read, twopages); + err = mtd_read(mtd, addr, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -163,7 +163,7 @@ static int verify_eraseblock(int ebnum) if (addr <= addrn - pgsize - pgsize && !bbt[ebnum + 1]) { unsigned long oldnext = next; /* Do a read to set the internal dataRAMs to different data */ - err = mtd->read(mtd, addr0, bufsize, &read, twopages); + err = mtd_read(mtd, addr0, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -171,7 +171,7 @@ static int verify_eraseblock(int ebnum) (long long)addr0); return err; } - err = mtd->read(mtd, addrn - bufsize, bufsize, &read, twopages); + err = mtd_read(mtd, addrn - bufsize, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -181,7 +181,7 @@ static int verify_eraseblock(int ebnum) } memset(twopages, 0, bufsize); read = 0; - err = mtd->read(mtd, addr, bufsize, &read, twopages); + err = mtd_read(mtd, addr, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != bufsize) { @@ -230,7 +230,7 @@ static int crosstest(void) /* Read 2nd-to-last page to pp1 */ read = 0; addr = addrn - pgsize - pgsize; - err = mtd->read(mtd, addr, pgsize, &read, pp1); + err = mtd_read(mtd, addr, pgsize, &read, pp1); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -243,7 +243,7 @@ static int crosstest(void) /* Read 3rd-to-last page to pp1 */ read = 0; addr = addrn - pgsize - pgsize - pgsize; - err = mtd->read(mtd, addr, pgsize, &read, pp1); + err = mtd_read(mtd, addr, pgsize, &read, pp1); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -257,7 +257,7 @@ static int crosstest(void) read = 0; addr = addr0; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); - err = mtd->read(mtd, addr, pgsize, &read, pp2); + err = mtd_read(mtd, addr, pgsize, &read, pp2); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -271,7 +271,7 @@ static int crosstest(void) read = 0; addr = addrn - pgsize; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); - err = mtd->read(mtd, addr, pgsize, &read, pp3); + err = mtd_read(mtd, addr, pgsize, &read, pp3); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -285,7 +285,7 @@ static int crosstest(void) read = 0; addr = addr0; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); - err = mtd->read(mtd, addr, pgsize, &read, pp4); + err = mtd_read(mtd, addr, pgsize, &read, pp4); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -344,7 +344,7 @@ static int erasecrosstest(void) printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); memset(readbuf, 0, pgsize); - err = mtd->read(mtd, addr0, pgsize, &read, readbuf); + err = mtd_read(mtd, addr0, pgsize, &read, readbuf); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -382,7 +382,7 @@ static int erasecrosstest(void) printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); memset(readbuf, 0, pgsize); - err = mtd->read(mtd, addr0, pgsize, &read, readbuf); + err = mtd_read(mtd, addr0, pgsize, &read, readbuf); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { @@ -438,7 +438,7 @@ static int erasetest(void) return err; printk(PRINT_PREF "reading 1st page of block %d\n", ebnum); - err = mtd->read(mtd, addr0, pgsize, &read, twopages); + err = mtd_read(mtd, addr0, pgsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; if (err || read != pgsize) { diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 550fe51225a7..0c58d2976c76 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -52,7 +52,7 @@ static int read_eraseblock_by_page(int ebnum) for (i = 0; i < pgcnt; i++) { memset(buf, 0 , pgcnt); - ret = mtd->read(mtd, addr, pgsize, &read, buf); + ret = mtd_read(mtd, addr, pgsize, &read, buf); if (ret == -EUCLEAN) ret = 0; if (ret || read != pgsize) { diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index f67a65e21043..3c9529bd0a62 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -214,7 +214,7 @@ static int read_eraseblock(int ebnum) int err = 0; loff_t addr = ebnum * mtd->erasesize; - err = mtd->read(mtd, addr, mtd->erasesize, &read, iobuf); + err = mtd_read(mtd, addr, mtd->erasesize, &read, iobuf); /* Ignore corrected ECC errors */ if (mtd_is_bitflip(err)) err = 0; @@ -235,7 +235,7 @@ static int read_eraseblock_by_page(int ebnum) void *buf = iobuf; for (i = 0; i < pgcnt; i++) { - err = mtd->read(mtd, addr, pgsize, &read, buf); + err = mtd_read(mtd, addr, pgsize, &read, buf); /* Ignore corrected ECC errors */ if (mtd_is_bitflip(err)) err = 0; @@ -261,7 +261,7 @@ static int read_eraseblock_by_2pages(int ebnum) void *buf = iobuf; for (i = 0; i < n; i++) { - err = mtd->read(mtd, addr, sz, &read, buf); + err = mtd_read(mtd, addr, sz, &read, buf); /* Ignore corrected ECC errors */ if (mtd_is_bitflip(err)) err = 0; @@ -276,7 +276,7 @@ static int read_eraseblock_by_2pages(int ebnum) buf += sz; } if (pgcnt % 2) { - err = mtd->read(mtd, addr, pgsize, &read, buf); + err = mtd_read(mtd, addr, pgsize, &read, buf); /* Ignore corrected ECC errors */ if (mtd_is_bitflip(err)) err = 0; diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index a204a9f90524..83a843723880 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -153,7 +153,7 @@ static int do_read(void) len = mtd->erasesize - offs; } addr = eb * mtd->erasesize + offs; - err = mtd->read(mtd, addr, len, &read, readbuf); + err = mtd_read(mtd, addr, len, &read, readbuf); if (mtd_is_bitflip(err)) err = 0; if (unlikely(err || read != len)) { diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 16d0c05024d7..d81f89a19daa 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -196,7 +196,7 @@ static int verify_eraseblock(int ebnum) set_random_data(writebuf, subpgsize); clear_data(readbuf, subpgsize); read = 0; - err = mtd->read(mtd, addr, subpgsize, &read, readbuf); + err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { printk(PRINT_PREF "ECC correction at %#llx\n", @@ -224,7 +224,7 @@ static int verify_eraseblock(int ebnum) set_random_data(writebuf, subpgsize); clear_data(readbuf, subpgsize); read = 0; - err = mtd->read(mtd, addr, subpgsize, &read, readbuf); + err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { printk(PRINT_PREF "ECC correction at %#llx\n", @@ -262,7 +262,7 @@ static int verify_eraseblock2(int ebnum) set_random_data(writebuf, subpgsize * k); clear_data(readbuf, subpgsize * k); read = 0; - err = mtd->read(mtd, addr, subpgsize * k, &read, readbuf); + err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf); if (unlikely(err || read != subpgsize * k)) { if (mtd_is_bitflip(err) && read == subpgsize * k) { printk(PRINT_PREF "ECC correction at %#llx\n", @@ -296,7 +296,7 @@ static int verify_eraseblock_ff(int ebnum) for (j = 0; j < mtd->erasesize / subpgsize; ++j) { clear_data(readbuf, subpgsize); read = 0; - err = mtd->read(mtd, addr, subpgsize, &read, readbuf); + err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { printk(PRINT_PREF "ECC correction at %#llx\n", diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 102c79b7ac66..ecc68bf3f3f2 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -137,7 +137,7 @@ static inline int check_eraseblock(int ebnum, unsigned char *buf) } retry: - err = mtd->read(mtd, addr, len, &read, check_buf); + err = mtd_read(mtd, addr, len, &read, check_buf); if (mtd_is_bitflip(err)) printk(PRINT_PREF "single bit flip occurred at EB %d " "MTD reported that it was fixed.\n", ebnum); diff --git a/drivers/mtd/ubi/debug.c b/drivers/mtd/ubi/debug.c index ab80c0debac8..e2cdebf40840 100644 --- a/drivers/mtd/ubi/debug.c +++ b/drivers/mtd/ubi/debug.c @@ -216,7 +216,7 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len) buf = vmalloc(len); if (!buf) return; - err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); + err = mtd_read(ubi->mtd, addr, len, &read, buf); if (err && err != -EUCLEAN) { ubi_err("error %d while reading %d bytes from PEB %d:%d, " "read %zd bytes", err, len, pnum, offset, read); diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index b6c8959e6c7e..433382951d3d 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -170,7 +170,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset, addr = (loff_t)pnum * ubi->peb_size + offset; retry: - err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); + err = mtd_read(ubi->mtd, addr, len, &read, buf); if (err) { const char *errstr = mtd_is_eccerr(err) ? " (ECC error)" : ""; @@ -1357,7 +1357,7 @@ int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum, return 0; } - err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf1); + err = mtd_read(ubi->mtd, addr, len, &read, buf1); if (err && !mtd_is_bitflip(err)) goto out_free; @@ -1421,7 +1421,7 @@ int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) return 0; } - err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf); + err = mtd_read(ubi->mtd, addr, len, &read, buf); if (err && !mtd_is_bitflip(err)) { ubi_err("error %d while reading %d bytes from PEB %d:%d, " "read %zd bytes", err, len, pnum, offset, read); diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index d638fafab649..eccd08d0e009 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -283,9 +283,11 @@ u16 mtd_Read_Page_Main(u8 *read_data, u32 Block, while (PageCount) { - ret = spectra_mtd->read(spectra_mtd, - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), - DeviceInfo.wPageDataSize, &retlen, read_data); + ret = mtd_read(spectra_mtd, + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), + DeviceInfo.wPageDataSize, + &retlen, + read_data); if (ret) { printk(KERN_ERR "%s failed %d\n", __func__, ret); return FAIL; diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c index ffdf4fca9c54..c59d642cade2 100644 --- a/fs/jffs2/erase.c +++ b/fs/jffs2/erase.c @@ -381,7 +381,7 @@ static int jffs2_block_check_erase(struct jffs2_sb_info *c, struct jffs2_erasebl *bad_offset = ofs; - ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf); + ret = mtd_read(c->mtd, ofs, readlen, &retlen, ebuf); if (ret) { printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret); ret = -EIO; diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index b09e51d2f81f..a24d3d21b63d 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -228,7 +228,7 @@ static int jffs2_verify_write(struct jffs2_sb_info *c, unsigned char *buf, size_t retlen; char *eccstr; - ret = c->mtd->read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify); + ret = mtd_read(c->mtd, ofs, c->wbuf_pagesize, &retlen, c->wbuf_verify); if (ret && ret != -EUCLEAN && ret != -EBADMSG) { printk(KERN_WARNING "jffs2_verify_write(): Read back of page at %08x failed: %d\n", c->wbuf_ofs, ret); return ret; @@ -337,7 +337,8 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c) } /* Do the read... */ - ret = c->mtd->read(c->mtd, start, c->wbuf_ofs - start, &retlen, buf); + ret = mtd_read(c->mtd, start, c->wbuf_ofs - start, &retlen, + buf); /* ECC recovered ? */ if ((ret == -EUCLEAN || ret == -EBADMSG) && @@ -948,11 +949,11 @@ int jffs2_flash_read(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *re int ret; if (!jffs2_is_writebuffered(c)) - return c->mtd->read(c->mtd, ofs, len, retlen, buf); + return mtd_read(c->mtd, ofs, len, retlen, buf); /* Read flash */ down_read(&c->wbuf_sem); - ret = c->mtd->read(c->mtd, ofs, len, retlen, buf); + ret = mtd_read(c->mtd, ofs, len, retlen, buf); if ( (ret == -EBADMSG || ret == -EUCLEAN) && (*retlen == len) ) { if (ret == -EBADMSG) diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 046362894352..3ee64351685f 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -20,7 +20,7 @@ static int logfs_mtd_read(struct super_block *sb, loff_t ofs, size_t len, size_t retlen; int ret; - ret = mtd->read(mtd, ofs, len, &retlen, buf); + ret = mtd_read(mtd, ofs, len, &retlen, buf); BUG_ON(ret == -EINVAL); if (ret) return ret; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index f38e8276b408..56478eb4bbc0 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -182,6 +182,8 @@ struct mtd_info { unsigned long len, unsigned long offset, unsigned long flags); + int (*read) (struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities @@ -189,7 +191,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; - int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); /* In blackbox flight recorder like scenarios we want to make successful @@ -301,6 +302,12 @@ static inline unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, return mtd->get_unmapped_area(mtd, len, offset, flags); } +static inline int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, + size_t *retlen, u_char *buf) +{ + return mtd->read(mtd, from, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From eda95cbf75193808f62948fb0142ba0901d8bee2 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 17:35:41 +0200 Subject: mtd: introduce mtd_write interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/chips/cfi_cmdset_0020.c | 8 +++++--- drivers/mtd/ftl.c | 35 ++++++++++++++++++----------------- drivers/mtd/mtdblock.c | 4 ++-- drivers/mtd/mtdblock_ro.c | 2 +- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdcore.c | 3 ++- drivers/mtd/mtdoops.c | 4 ++-- drivers/mtd/mtdpart.c | 3 +-- drivers/mtd/mtdswap.c | 2 +- drivers/mtd/rfd_ftl.c | 17 ++++++++--------- drivers/mtd/tests/mtd_pagetest.c | 8 ++++---- drivers/mtd/tests/mtd_speedtest.c | 8 ++++---- drivers/mtd/tests/mtd_stresstest.c | 2 +- drivers/mtd/tests/mtd_subpagetest.c | 6 +++--- drivers/mtd/tests/mtd_torturetest.c | 2 +- drivers/mtd/ubi/io.c | 7 +++---- drivers/staging/spectra/lld_mtd.c | 8 +++++--- fs/jffs2/wbuf.c | 18 +++++++++--------- fs/jffs2/writev.c | 5 +++-- fs/logfs/dev_mtd.c | 2 +- include/linux/mtd/mtd.h | 9 ++++++++- 22 files changed, 84 insertions(+), 73 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c index 666c52f8bf8d..85e80180b65b 100644 --- a/drivers/mtd/chips/cfi_cmdset_0020.c +++ b/drivers/mtd/chips/cfi_cmdset_0020.c @@ -699,7 +699,8 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs, continue; } memcpy(buffer+buflen, elem_base, ECCBUF_SIZE-buflen); - ret = mtd->write(mtd, to, ECCBUF_SIZE, &thislen, buffer); + ret = mtd_write(mtd, to, ECCBUF_SIZE, &thislen, + buffer); totlen += thislen; if (ret || thislen != ECCBUF_SIZE) goto write_error; @@ -708,7 +709,8 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs, to += ECCBUF_SIZE; } if (ECCBUF_DIV(elem_len)) { /* write clean aligned data */ - ret = mtd->write(mtd, to, ECCBUF_DIV(elem_len), &thislen, elem_base); + ret = mtd_write(mtd, to, ECCBUF_DIV(elem_len), + &thislen, elem_base); totlen += thislen; if (ret || thislen != ECCBUF_DIV(elem_len)) goto write_error; @@ -722,7 +724,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs, } if (buflen) { /* flush last page, even if not full */ /* This is sometimes intended behaviour, really */ - ret = mtd->write(mtd, to, buflen, &thislen, buffer); + ret = mtd_write(mtd, to, buflen, &thislen, buffer); totlen += thislen; if (ret || thislen != ECCBUF_SIZE) goto write_error; diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index 12fd7ebd3fd8..d591b1d0a6c1 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -422,8 +422,8 @@ static int prepare_xfer(partition_t *part, int i) header.LogicalEUN = cpu_to_le16(0xffff); header.EraseCount = cpu_to_le32(xfer->EraseCount); - ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset, sizeof(header), - &retlen, (u_char *)&header); + ret = mtd_write(part->mbd.mtd, xfer->Offset, sizeof(header), &retlen, + (u_char *)&header); if (ret) { return ret; @@ -438,8 +438,8 @@ static int prepare_xfer(partition_t *part, int i) for (i = 0; i < nbam; i++, offset += sizeof(uint32_t)) { - ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(uint32_t), - &retlen, (u_char *)&ctl); + ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, + (u_char *)&ctl); if (ret) return ret; @@ -503,8 +503,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, offset = xfer->Offset + 20; /* Bad! */ unit = cpu_to_le16(0x7fff); - ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(uint16_t), - &retlen, (u_char *) &unit); + ret = mtd_write(part->mbd.mtd, offset, sizeof(uint16_t), &retlen, + (u_char *)&unit); if (ret) { printk( KERN_WARNING "ftl: Failed to write back to BAM cache in copy_erase_unit()!\n"); @@ -531,8 +531,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, } - ret = part->mbd.mtd->write(part->mbd.mtd, dest, SECTOR_SIZE, - &retlen, (u_char *) buf); + ret = mtd_write(part->mbd.mtd, dest, SECTOR_SIZE, &retlen, + (u_char *)buf); if (ret) { printk(KERN_WARNING "ftl: Error writing new xfer unit in copy_erase_unit\n"); return ret; @@ -550,9 +550,11 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, } /* Write the BAM to the transfer unit */ - ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + le32_to_cpu(part->header.BAMOffset), - part->BlocksPerUnit * sizeof(int32_t), &retlen, - (u_char *)part->bam_cache); + ret = mtd_write(part->mbd.mtd, + xfer->Offset + le32_to_cpu(part->header.BAMOffset), + part->BlocksPerUnit * sizeof(int32_t), + &retlen, + (u_char *)part->bam_cache); if (ret) { printk( KERN_WARNING "ftl: Error writing BAM in copy_erase_unit\n"); return ret; @@ -560,8 +562,8 @@ static int copy_erase_unit(partition_t *part, uint16_t srcunit, /* All clear? Then update the LogicalEUN again */ - ret = part->mbd.mtd->write(part->mbd.mtd, xfer->Offset + 20, sizeof(uint16_t), - &retlen, (u_char *)&srcunitswap); + ret = mtd_write(part->mbd.mtd, xfer->Offset + 20, sizeof(uint16_t), + &retlen, (u_char *)&srcunitswap); if (ret) { printk(KERN_WARNING "ftl: Error writing new LogicalEUN in copy_erase_unit\n"); @@ -887,8 +889,8 @@ static int set_bam_entry(partition_t *part, uint32_t log_addr, #endif part->bam_cache[blk] = le_virt_addr; } - ret = part->mbd.mtd->write(part->mbd.mtd, offset, sizeof(uint32_t), - &retlen, (u_char *)&le_virt_addr); + ret = mtd_write(part->mbd.mtd, offset, sizeof(uint32_t), &retlen, + (u_char *)&le_virt_addr); if (ret) { printk(KERN_NOTICE "ftl_cs: set_bam_entry() failed!\n"); @@ -947,8 +949,7 @@ static int ftl_write(partition_t *part, caddr_t buffer, part->EUNInfo[part->bam_index].Deleted++; offset = (part->EUNInfo[part->bam_index].Offset + blk * SECTOR_SIZE); - ret = part->mbd.mtd->write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, - buffer); + ret = mtd_write(part->mbd.mtd, offset, SECTOR_SIZE, &retlen, buffer); if (ret) { printk(KERN_NOTICE "ftl_cs: block write failed!\n"); diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index b0644d2d2a6e..ac7f1f1faa2d 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -102,7 +102,7 @@ static int erase_write (struct mtd_info *mtd, unsigned long pos, * Next, write the data to flash. */ - ret = mtd->write(mtd, pos, len, &retlen, buf); + ret = mtd_write(mtd, pos, len, &retlen, buf); if (ret) return ret; if (retlen != len) @@ -152,7 +152,7 @@ static int do_cached_write (struct mtdblk_dev *mtdblk, unsigned long pos, mtd->name, pos, len); if (!sect_size) - return mtd->write(mtd, pos, len, &retlen, buf); + return mtd_write(mtd, pos, len, &retlen, buf); while (len > 0) { unsigned long sect_start = (pos/sect_size)*sect_size; diff --git a/drivers/mtd/mtdblock_ro.c b/drivers/mtd/mtdblock_ro.c index f5737b1153fa..92759a9d2985 100644 --- a/drivers/mtd/mtdblock_ro.c +++ b/drivers/mtd/mtdblock_ro.c @@ -40,7 +40,7 @@ static int mtdblock_writesect(struct mtd_blktrans_dev *dev, { size_t retlen; - if (dev->mtd->write(dev->mtd, (block * 512), 512, &retlen, buf)) + if (mtd_write(dev->mtd, (block * 512), 512, &retlen, buf)) return 1; return 0; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index c7f484687fa3..922da31d2c6b 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -331,7 +331,7 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c } default: - ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf); + ret = mtd_write(mtd, *ppos, len, &retlen, kbuf); } if (!ret) { *ppos += retlen; diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 45460349fd12..45215501c4c7 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -148,7 +148,7 @@ concat_write(struct mtd_info *mtd, loff_t to, size_t len, if (!(subdev->flags & MTD_WRITEABLE)) err = -EROFS; else - err = subdev->write(subdev, to, size, &retsize, buf); + err = mtd_write(subdev, to, size, &retsize, buf); if (err) break; diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index b01993ea260e..e36191ab47c3 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -699,7 +699,8 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, for (i=0; iwrite(mtd, to, vecs[i].iov_len, &thislen, vecs[i].iov_base); + ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen, + vecs[i].iov_base); totlen += thislen; if (ret || thislen != vecs[i].iov_len) break; diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 23629ad08507..9c9d58617c98 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -225,8 +225,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) ret = mtd->panic_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); else - ret = mtd->write(mtd, cxt->nextpage * record_size, - record_size, &retlen, cxt->oops_buf); + ret = mtd_write(mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf); if (retlen != record_size || ret < 0) printk(KERN_ERR "mtdoops: write failure at %ld (%td of %ld written), error %d\n", diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 59cd7974bc50..96574a036567 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -188,8 +188,7 @@ static int part_write(struct mtd_info *mtd, loff_t to, size_t len, len = 0; else if (to + len > mtd->size) len = mtd->size - to; - return part->master->write(part->master, to + part->offset, - len, retlen, buf); + return mtd_write(part->master, to + part->offset, len, retlen, buf); } static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len, diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index b3282d2aa8f8..6ff823e29c0c 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -689,7 +689,7 @@ retry: return ret; writepos = (loff_t)*bp << PAGE_SHIFT; - ret = mtd->write(mtd, writepos, PAGE_SIZE, &retlen, buf); + ret = mtd_write(mtd, writepos, PAGE_SIZE, &retlen, buf); if (ret == -EIO || mtd_is_eccerr(ret)) { d->curr_write_pos--; eb->active_count--; diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index d9fe2d0533d9..c594bb7abfa3 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -304,9 +304,8 @@ static void erase_callback(struct erase_info *erase) part->blocks[i].used_sectors = 0; part->blocks[i].erases++; - rc = part->mbd.mtd->write(part->mbd.mtd, - part->blocks[i].offset, sizeof(magic), &retlen, - (u_char*)&magic); + rc = mtd_write(part->mbd.mtd, part->blocks[i].offset, sizeof(magic), + &retlen, (u_char *)&magic); if (!rc && retlen != sizeof(magic)) rc = -EIO; @@ -595,8 +594,8 @@ static int mark_sector_deleted(struct partition *part, u_long old_addr) addr = part->blocks[block].offset + (HEADER_MAP_OFFSET + offset) * sizeof(u16); - rc = part->mbd.mtd->write(part->mbd.mtd, addr, - sizeof(del), &retlen, (u_char*)&del); + rc = mtd_write(part->mbd.mtd, addr, sizeof(del), &retlen, + (u_char *)&del); if (!rc && retlen != sizeof(del)) rc = -EIO; @@ -668,8 +667,8 @@ static int do_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *buf, addr = (i + part->header_sectors_per_block) * SECTOR_SIZE + block->offset; - rc = part->mbd.mtd->write(part->mbd.mtd, - addr, SECTOR_SIZE, &retlen, (u_char*)buf); + rc = mtd_write(part->mbd.mtd, addr, SECTOR_SIZE, &retlen, + (u_char *)buf); if (!rc && retlen != SECTOR_SIZE) rc = -EIO; @@ -688,8 +687,8 @@ static int do_writesect(struct mtd_blktrans_dev *dev, u_long sector, char *buf, part->header_cache[i + HEADER_MAP_OFFSET] = entry; addr = block->offset + (HEADER_MAP_OFFSET + i) * sizeof(u16); - rc = part->mbd.mtd->write(part->mbd.mtd, addr, - sizeof(entry), &retlen, (u_char*)&entry); + rc = mtd_write(part->mbd.mtd, addr, sizeof(entry), &retlen, + (u_char *)&entry); if (!rc && retlen != sizeof(entry)) rc = -EIO; diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 6d62e24a03ed..83da97e54f97 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -100,7 +100,7 @@ static int write_eraseblock(int ebnum) set_random_data(writebuf, mtd->erasesize); cond_resched(); - err = mtd->write(mtd, addr, mtd->erasesize, &written, writebuf); + err = mtd_write(mtd, addr, mtd->erasesize, &written, writebuf); if (err || written != mtd->erasesize) printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr); @@ -335,7 +335,7 @@ static int erasecrosstest(void) printk(PRINT_PREF "writing 1st page of block %d\n", ebnum); set_random_data(writebuf, pgsize); strcpy(writebuf, "There is no data like this!"); - err = mtd->write(mtd, addr0, pgsize, &written, writebuf); + err = mtd_write(mtd, addr0, pgsize, &written, writebuf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr0); @@ -368,7 +368,7 @@ static int erasecrosstest(void) printk(PRINT_PREF "writing 1st page of block %d\n", ebnum); set_random_data(writebuf, pgsize); strcpy(writebuf, "There is no data like this!"); - err = mtd->write(mtd, addr0, pgsize, &written, writebuf); + err = mtd_write(mtd, addr0, pgsize, &written, writebuf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr0); @@ -425,7 +425,7 @@ static int erasetest(void) printk(PRINT_PREF "writing 1st page of block %d\n", ebnum); set_random_data(writebuf, pgsize); - err = mtd->write(mtd, addr0, pgsize, &written, writebuf); + err = mtd_write(mtd, addr0, pgsize, &written, writebuf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr0); diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index 3c9529bd0a62..c7b18e189082 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -143,7 +143,7 @@ static int write_eraseblock(int ebnum) int err = 0; loff_t addr = ebnum * mtd->erasesize; - err = mtd->write(mtd, addr, mtd->erasesize, &written, iobuf); + err = mtd_write(mtd, addr, mtd->erasesize, &written, iobuf); if (err || written != mtd->erasesize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); if (!err) @@ -161,7 +161,7 @@ static int write_eraseblock_by_page(int ebnum) void *buf = iobuf; for (i = 0; i < pgcnt; i++) { - err = mtd->write(mtd, addr, pgsize, &written, buf); + err = mtd_write(mtd, addr, pgsize, &written, buf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); @@ -184,7 +184,7 @@ static int write_eraseblock_by_2pages(int ebnum) void *buf = iobuf; for (i = 0; i < n; i++) { - err = mtd->write(mtd, addr, sz, &written, buf); + err = mtd_write(mtd, addr, sz, &written, buf); if (err || written != sz) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); @@ -196,7 +196,7 @@ static int write_eraseblock_by_2pages(int ebnum) buf += sz; } if (pgcnt % 2) { - err = mtd->write(mtd, addr, pgsize, &written, buf); + err = mtd_write(mtd, addr, pgsize, &written, buf); if (err || written != pgsize) { printk(PRINT_PREF "error: write failed at %#llx\n", addr); diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 83a843723880..f8aac4b7e59a 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -192,7 +192,7 @@ static int do_write(void) } } addr = eb * mtd->erasesize + offs; - err = mtd->write(mtd, addr, len, &written, writebuf); + err = mtd_write(mtd, addr, len, &written, writebuf); if (unlikely(err || written != len)) { printk(PRINT_PREF "error: write failed at 0x%llx\n", (long long)addr); diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index d81f89a19daa..b90c01036b49 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -120,7 +120,7 @@ static int write_eraseblock(int ebnum) loff_t addr = ebnum * mtd->erasesize; set_random_data(writebuf, subpgsize); - err = mtd->write(mtd, addr, subpgsize, &written, writebuf); + err = mtd_write(mtd, addr, subpgsize, &written, writebuf); if (unlikely(err || written != subpgsize)) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr); @@ -134,7 +134,7 @@ static int write_eraseblock(int ebnum) addr += subpgsize; set_random_data(writebuf, subpgsize); - err = mtd->write(mtd, addr, subpgsize, &written, writebuf); + err = mtd_write(mtd, addr, subpgsize, &written, writebuf); if (unlikely(err || written != subpgsize)) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr); @@ -158,7 +158,7 @@ static int write_eraseblock2(int ebnum) if (addr + (subpgsize * k) > (ebnum + 1) * mtd->erasesize) break; set_random_data(writebuf, subpgsize * k); - err = mtd->write(mtd, addr, subpgsize * k, &written, writebuf); + err = mtd_write(mtd, addr, subpgsize * k, &written, writebuf); if (unlikely(err || written != subpgsize * k)) { printk(PRINT_PREF "error: write failed at %#llx\n", (long long)addr); diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index ecc68bf3f3f2..dd34a519fa7a 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -189,7 +189,7 @@ static inline int write_pattern(int ebnum, void *buf) addr = (ebnum + 1) * mtd->erasesize - pgcnt * pgsize; len = pgcnt * pgsize; } - err = mtd->write(mtd, addr, len, &written, buf); + err = mtd_write(mtd, addr, len, &written, buf); if (err) { printk(PRINT_PREF "error %d while writing EB %d, written %zd" " bytes\n", err, ebnum, written); diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 433382951d3d..8d832fc9e9e4 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -289,7 +289,7 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset, } addr = (loff_t)pnum * ubi->peb_size + offset; - err = ubi->mtd->write(ubi->mtd, addr, len, &written, buf); + err = mtd_write(ubi->mtd, addr, len, &written, buf); if (err) { ubi_err("error %d while writing %d bytes to PEB %d:%d, written " "%zd bytes", err, len, pnum, offset, written); @@ -525,11 +525,10 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum) * the header comment in scan.c for more information). */ addr = (loff_t)pnum * ubi->peb_size; - err = ubi->mtd->write(ubi->mtd, addr, 4, &written, (void *)&data); + err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data); if (!err) { addr += ubi->vid_hdr_aloffset; - err = ubi->mtd->write(ubi->mtd, addr, 4, &written, - (void *)&data); + err = mtd_write(ubi->mtd, addr, 4, &written, (void *)&data); if (!err) return 0; } diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index eccd08d0e009..2eb032131960 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -233,9 +233,11 @@ u16 mtd_Write_Page_Main(u8 *write_data, u32 Block, while (PageCount) { - ret = spectra_mtd->write(spectra_mtd, - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), - DeviceInfo.wPageDataSize, &retlen, write_data); + ret = mtd_write(spectra_mtd, + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), + DeviceInfo.wPageDataSize, + &retlen, + write_data); if (ret) { printk(KERN_ERR "%s failed %d\n", __func__, ret); return FAIL; diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index a24d3d21b63d..3ea2f8db9358 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -414,13 +414,12 @@ static void jffs2_wbuf_recover(struct jffs2_sb_info *c) if (breakme++ == 20) { printk(KERN_NOTICE "Faking write error at 0x%08x\n", ofs); breakme = 0; - c->mtd->write(c->mtd, ofs, towrite, &retlen, - brokenbuf); + mtd_write(c->mtd, ofs, towrite, &retlen, brokenbuf); ret = -EIO; } else #endif - ret = c->mtd->write(c->mtd, ofs, towrite, &retlen, - rewrite_buf); + ret = mtd_write(c->mtd, ofs, towrite, &retlen, + rewrite_buf); if (ret || retlen != towrite || jffs2_verify_write(c, rewrite_buf, ofs)) { /* Argh. We tried. Really we did. */ @@ -620,13 +619,14 @@ static int __jffs2_flush_wbuf(struct jffs2_sb_info *c, int pad) if (breakme++ == 20) { printk(KERN_NOTICE "Faking write error at 0x%08x\n", c->wbuf_ofs); breakme = 0; - c->mtd->write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, - brokenbuf); + mtd_write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, + brokenbuf); ret = -EIO; } else #endif - ret = c->mtd->write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, &retlen, c->wbuf); + ret = mtd_write(c->mtd, c->wbuf_ofs, c->wbuf_pagesize, + &retlen, c->wbuf); if (ret) { printk(KERN_WARNING "jffs2_flush_wbuf(): Write failed with %d\n", ret); @@ -862,8 +862,8 @@ int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, v += wbuf_retlen; if (vlen >= c->wbuf_pagesize) { - ret = c->mtd->write(c->mtd, outvec_to, PAGE_DIV(vlen), - &wbuf_retlen, v); + ret = mtd_write(c->mtd, outvec_to, PAGE_DIV(vlen), + &wbuf_retlen, v); if (ret < 0 || wbuf_retlen != PAGE_DIV(vlen)) goto outfile; diff --git a/fs/jffs2/writev.c b/fs/jffs2/writev.c index b9276b11bac6..b05710fd552a 100644 --- a/fs/jffs2/writev.c +++ b/fs/jffs2/writev.c @@ -26,7 +26,8 @@ static inline int mtd_fake_writev(struct mtd_info *mtd, const struct kvec *vecs, for (i=0; iwrite(mtd, to, vecs[i].iov_len, &thislen, vecs[i].iov_base); + ret = mtd_write(mtd, to, vecs[i].iov_len, &thislen, + vecs[i].iov_base); totlen += thislen; if (ret || thislen != vecs[i].iov_len) break; @@ -61,7 +62,7 @@ int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, size_t *retlen, const u_char *buf) { int ret; - ret = c->mtd->write(c->mtd, ofs, len, retlen, buf); + ret = mtd_write(c->mtd, ofs, len, retlen, buf); if (jffs2_sum_active()) { struct kvec vecs[1]; diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 3ee64351685f..1842440d6564 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -49,7 +49,7 @@ static int loffs_mtd_write(struct super_block *sb, loff_t ofs, size_t len, BUG_ON(len > PAGE_CACHE_SIZE); page_start = ofs & PAGE_CACHE_MASK; page_end = PAGE_CACHE_ALIGN(ofs + len) - 1; - ret = mtd->write(mtd, ofs, len, &retlen, buf); + ret = mtd_write(mtd, ofs, len, &retlen, buf); if (ret || (retlen != len)) return -EIO; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 56478eb4bbc0..1da7f4a6ef88 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -184,6 +184,8 @@ struct mtd_info { unsigned long flags); int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); + int (*write) (struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities @@ -191,7 +193,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; - int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); /* In blackbox flight recorder like scenarios we want to make successful writes in interrupt context. panic_write() is only intended to be @@ -308,6 +309,12 @@ static inline int mtd_read(struct mtd_info *mtd, loff_t from, size_t len, return mtd->read(mtd, from, len, retlen, buf); } +static inline int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf) +{ + return mtd->write(mtd, to, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 7ae79d7ff1769a3e9c47076b46e4eaa11204a2ee Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:03:17 +0200 Subject: mtd: introduce mtd_panic_write interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdoops.c | 4 ++-- drivers/mtd/mtdpart.c | 4 ++-- include/linux/mtd/mtd.h | 25 +++++++++++++++---------- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 9c9d58617c98..7be2018ffbcc 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -222,8 +222,8 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) hdr[1] = MTDOOPS_KERNMSG_MAGIC; if (panic) - ret = mtd->panic_write(mtd, cxt->nextpage * record_size, - record_size, &retlen, cxt->oops_buf); + ret = mtd_panic_write(mtd, cxt->nextpage * record_size, + record_size, &retlen, cxt->oops_buf); else ret = mtd_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 96574a036567..9ed58f7d7466 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -201,8 +201,8 @@ static int part_panic_write(struct mtd_info *mtd, loff_t to, size_t len, len = 0; else if (to + len > mtd->size) len = mtd->size - to; - return part->master->panic_write(part->master, to + part->offset, - len, retlen, buf); + return mtd_panic_write(part->master, to + part->offset, len, retlen, + buf); } static int part_write_oob(struct mtd_info *mtd, loff_t to, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 1da7f4a6ef88..2fb83cd3d264 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -186,6 +186,8 @@ struct mtd_info { size_t *retlen, u_char *buf); int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); + int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities @@ -193,16 +195,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; - - /* In blackbox flight recorder like scenarios we want to make successful - writes in interrupt context. panic_write() is only intended to be - called when its known the kernel is about to panic and we need the - write to succeed. Since the kernel is not going to be running for much - longer, this function can break locks and delay to ensure the write - succeeds (but not sleep). */ - - int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); - int (*read_oob) (struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops); int (*write_oob) (struct mtd_info *mtd, loff_t to, @@ -315,6 +307,19 @@ static inline int mtd_write(struct mtd_info *mtd, loff_t to, size_t len, return mtd->write(mtd, to, len, retlen, buf); } +/* + * In blackbox flight recorder like scenarios we want to make successful writes + * in interrupt context. panic_write() is only intended to be called when its + * known the kernel is about to panic and we need the write to succeed. Since + * the kernel is not going to be running for much longer, this function can + * break locks and delay to ensure the write succeeds (but not sleep). + */ +static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, const u_char *buf) +{ + return mtd->panic_write(mtd, to, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From fd2819bbc92fc98bed5d612e4acbe16b6326f6bf Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:27:05 +0200 Subject: mtd: introduce mtd_read_oob interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/inftlcore.c | 2 +- drivers/mtd/mtdchar.c | 4 ++-- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/mtdswap.c | 4 ++-- drivers/mtd/nand/nand_bbt.c | 6 +++--- drivers/mtd/nftlcore.c | 2 +- drivers/mtd/sm_ftl.c | 2 +- drivers/mtd/ssfdc.c | 2 +- drivers/mtd/tests/mtd_oobtest.c | 14 +++++++------- drivers/mtd/tests/mtd_readtest.c | 2 +- drivers/staging/spectra/lld_mtd.c | 12 ++++++------ fs/jffs2/wbuf.c | 4 ++-- include/linux/mtd/mtd.h | 10 ++++++++-- 14 files changed, 37 insertions(+), 31 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index 0b038bed7b9c..07646e1273e2 100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c @@ -158,7 +158,7 @@ int inftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd_read_oob(mtd, offs & ~(mtd->writesize - 1), &ops); *retlen = ops.oobretlen; return res; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 922da31d2c6b..e74f570a7b93 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -227,7 +227,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, ops.oobbuf = NULL; ops.len = len; - ret = mtd->read_oob(mtd, *ppos, &ops); + ret = mtd_read_oob(mtd, *ppos, &ops); retlen = ops.retlen; break; } @@ -471,7 +471,7 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd, return -ENOMEM; start &= ~((uint64_t)mtd->writesize - 1); - ret = mtd->read_oob(mtd, start, &ops); + ret = mtd_read_oob(mtd, start, &ops); if (put_user(ops.oobretlen, retp)) ret = -EFAULT; diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 45215501c4c7..cf35642e5f49 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -273,7 +273,7 @@ concat_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) if (from + devops.len > subdev->size) devops.len = subdev->size - from; - err = subdev->read_oob(subdev, from, &devops); + err = mtd_read_oob(subdev, from, &devops); ops->retlen += devops.retlen; ops->oobretlen += devops.oobretlen; diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 9ed58f7d7466..6fdc74ef19c1 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -138,7 +138,7 @@ static int part_read_oob(struct mtd_info *mtd, loff_t from, return -EINVAL; } - res = part->master->read_oob(part->master, from + part->offset, ops); + res = mtd_read_oob(part->master, from + part->offset, ops); if (unlikely(res)) { if (mtd_is_bitflip(res)) mtd->ecc_stats.corrected++; diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 6ff823e29c0c..0f0ab18d4405 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -312,7 +312,7 @@ static int mtdswap_handle_write_error(struct mtdswap_dev *d, struct swap_eb *eb) static int mtdswap_read_oob(struct mtdswap_dev *d, loff_t from, struct mtd_oob_ops *ops) { - int ret = d->mtd->read_oob(d->mtd, from, ops); + int ret = mtd_read_oob(d->mtd, from, ops); if (mtd_is_bitflip(ret)) return ret; @@ -955,7 +955,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d, pos = base; for (i = 0; i < mtd_pages; i++) { - ret = mtd->read_oob(mtd, pos, &ops); + ret = mtd_read_oob(mtd, pos, &ops); if (ret) goto error; diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index 1bcd6bc6798c..fcab50e80b90 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -317,7 +317,7 @@ static int scan_read_raw_oob(struct mtd_info *mtd, uint8_t *buf, loff_t offs, ops.len = min(len, (size_t)mtd->writesize); ops.oobbuf = buf + ops.len; - res = mtd->read_oob(mtd, offs, &ops); + res = mtd_read_oob(mtd, offs, &ops); if (res) return res; @@ -434,7 +434,7 @@ static int scan_block_fast(struct mtd_info *mtd, struct nand_bbt_descr *bd, * Read the full oob until read_oob is fixed to handle single * byte reads for 16 bit buswidth. */ - ret = mtd->read_oob(mtd, offs, &ops); + ret = mtd_read_oob(mtd, offs, &ops); /* Ignore ECC errors when checking for BBM */ if (ret && !mtd_is_bitflip_or_eccerr(ret)) return ret; @@ -769,7 +769,7 @@ static int write_bbt(struct mtd_info *mtd, uint8_t *buf, /* Read oob data */ ops.ooblen = (len >> this->page_shift) * mtd->oobsize; ops.oobbuf = &buf[len]; - res = mtd->read_oob(mtd, to + mtd->writesize, &ops); + res = mtd_read_oob(mtd, to + mtd->writesize, &ops); if (res < 0 || ops.oobretlen != ops.ooblen) goto outerr; diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index 1a9d9c1d3a74..7497f5efc26b 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -153,7 +153,7 @@ int nftl_read_oob(struct mtd_info *mtd, loff_t offs, size_t len, ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->read_oob(mtd, offs & ~mask, &ops); + res = mtd_read_oob(mtd, offs & ~mask, &ops); *retlen = ops.oobretlen; return res; } diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index 2f1acb1ab5e8..748aa4416691 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -278,7 +278,7 @@ again: /* Unfortunately, oob read will _always_ succeed, despite card removal..... */ - ret = mtd->read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); + ret = mtd_read_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); /* Test for unknown errors */ if (ret != 0 && !mtd_is_bitflip_or_eccerr(ret)) { diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index 293e22a5710f..0e6881338357 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c @@ -175,7 +175,7 @@ static int read_raw_oob(struct mtd_info *mtd, loff_t offs, uint8_t *buf) ops.oobbuf = buf; ops.datbuf = NULL; - ret = mtd->read_oob(mtd, offs, &ops); + ret = mtd_read_oob(mtd, offs, &ops); if (ret < 0 || ops.oobretlen != OOB_SIZE) return -1; diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 7d52854c16dd..962d27a64e64 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -192,7 +192,7 @@ static int verify_eraseblock(int ebnum) ops.ooboffs = use_offset; ops.datbuf = NULL; ops.oobbuf = readbuf; - err = mtd->read_oob(mtd, addr, &ops); + err = mtd_read_oob(mtd, addr, &ops); if (err || ops.oobretlen != use_len) { printk(PRINT_PREF "error: readoob failed at %#llx\n", (long long)addr); @@ -219,7 +219,7 @@ static int verify_eraseblock(int ebnum) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = readbuf; - err = mtd->read_oob(mtd, addr, &ops); + err = mtd_read_oob(mtd, addr, &ops); if (err || ops.oobretlen != mtd->ecclayout->oobavail) { printk(PRINT_PREF "error: readoob failed at " "%#llx\n", (long long)addr); @@ -284,7 +284,7 @@ static int verify_eraseblock_in_one_go(int ebnum) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = readbuf; - err = mtd->read_oob(mtd, addr, &ops); + err = mtd_read_oob(mtd, addr, &ops); if (err || ops.oobretlen != len) { printk(PRINT_PREF "error: readoob failed at %#llx\n", (long long)addr); @@ -544,7 +544,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = readbuf; printk(PRINT_PREF "attempting to start read past end of OOB\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->read_oob(mtd, addr0, &ops); + err = mtd_read_oob(mtd, addr0, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -588,7 +588,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = readbuf; printk(PRINT_PREF "attempting to read past end of device\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops); + err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -632,7 +632,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = readbuf; printk(PRINT_PREF "attempting to read past end of device\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->read_oob(mtd, mtd->size - mtd->writesize, &ops); + err = mtd_read_oob(mtd, mtd->size - mtd->writesize, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -698,7 +698,7 @@ static int __init mtd_oobtest_init(void) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = readbuf; - err = mtd->read_oob(mtd, addr, &ops); + err = mtd_read_oob(mtd, addr, &ops); if (err) goto out; if (memcmp(readbuf, writebuf, mtd->ecclayout->oobavail * 2)) { diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 0c58d2976c76..5eaeada84284 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -74,7 +74,7 @@ static int read_eraseblock_by_page(int ebnum) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = oobbuf; - ret = mtd->read_oob(mtd, addr, &ops); + ret = mtd_read_oob(mtd, addr, &ops); if ((ret && !mtd_is_bitflip(ret)) || ops.oobretlen != mtd->oobsize) { printk(PRINT_PREF "error: read oob failed at " diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index 2eb032131960..ed8e5f067087 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -351,9 +351,9 @@ u16 mtd_Read_Page_Main_Spare(u8 *read_data, u32 Block, ops.ooblen = BTSIG_BYTES; ops.ooboffs = 0; - ret = spectra_mtd->read_oob(spectra_mtd, - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), - &ops); + ret = mtd_read_oob(spectra_mtd, + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), + &ops); if (ret) { printk(KERN_ERR "%s failed %d\n", __func__, ret); return FAIL; @@ -484,9 +484,9 @@ u16 mtd_Read_Page_Spare(u8 *read_data, u32 Block, ops.ooblen = BTSIG_BYTES; ops.ooboffs = 0; - ret = spectra_mtd->read_oob(spectra_mtd, - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), - &ops); + ret = mtd_read_oob(spectra_mtd, + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), + &ops); if (ret) { printk(KERN_ERR "%s failed %d\n", __func__, ret); return FAIL; diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index 3ea2f8db9358..efc0cb370306 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -1032,7 +1032,7 @@ int jffs2_check_oob_empty(struct jffs2_sb_info *c, ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; ops.datbuf = NULL; - ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops); + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); if (ret || ops.oobretlen != ops.ooblen) { printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd" " bytes, read %zd bytes, error %d\n", @@ -1075,7 +1075,7 @@ int jffs2_check_nand_cleanmarker(struct jffs2_sb_info *c, ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; ops.datbuf = NULL; - ret = c->mtd->read_oob(c->mtd, jeb->offset, &ops); + ret = mtd_read_oob(c->mtd, jeb->offset, &ops); if (ret || ops.oobretlen != ops.ooblen) { printk(KERN_ERR "cannot read OOB for EB at %08x, requested %zd" " bytes, read %zd bytes, error %d\n", diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 2fb83cd3d264..0db8d87ce451 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -188,6 +188,8 @@ struct mtd_info { size_t *retlen, const u_char *buf); int (*panic_write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); + int (*read_oob) (struct mtd_info *mtd, loff_t from, + struct mtd_oob_ops *ops); /* Backing device capabilities for this device * - provides mmap capabilities @@ -195,8 +197,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; - int (*read_oob) (struct mtd_info *mtd, loff_t from, - struct mtd_oob_ops *ops); int (*write_oob) (struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops); @@ -320,6 +320,12 @@ static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, return mtd->panic_write(mtd, to, len, retlen, buf); } +static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, + struct mtd_oob_ops *ops) +{ + return mtd->read_oob(mtd, from, ops); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From a2cc5ba075f9bc837d0b4d4ec7328dcefc11859d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:29:55 +0200 Subject: mtd: introduce mtd_write_oob interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/inftlcore.c | 4 ++-- drivers/mtd/mtdchar.c | 6 +++--- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/mtdswap.c | 4 ++-- drivers/mtd/nand/nand_bbt.c | 2 +- drivers/mtd/nand/sm_common.c | 2 +- drivers/mtd/nftlcore.c | 4 ++-- drivers/mtd/sm_ftl.c | 2 +- drivers/mtd/tests/mtd_oobtest.c | 10 +++++----- drivers/staging/spectra/lld_mtd.c | 6 +++--- fs/jffs2/wbuf.c | 2 +- include/linux/mtd/mtd.h | 12 ++++++++---- 13 files changed, 31 insertions(+), 27 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c index 07646e1273e2..28646c95cfb8 100644 --- a/drivers/mtd/inftlcore.c +++ b/drivers/mtd/inftlcore.c @@ -178,7 +178,7 @@ int inftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd_write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); *retlen = ops.oobretlen; return res; } @@ -199,7 +199,7 @@ static int inftl_write(struct mtd_info *mtd, loff_t offs, size_t len, ops.datbuf = buf; ops.len = len; - res = mtd->write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); + res = mtd_write_oob(mtd, offs & ~(mtd->writesize - 1), &ops); *retlen = ops.retlen; return res; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index e74f570a7b93..234e3d27143c 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -325,7 +325,7 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c ops.ooboffs = 0; ops.len = len; - ret = mtd->write_oob(mtd, *ppos, &ops); + ret = mtd_write_oob(mtd, *ppos, &ops); retlen = ops.retlen; break; } @@ -426,7 +426,7 @@ static int mtdchar_writeoob(struct file *file, struct mtd_info *mtd, return PTR_ERR(ops.oobbuf); start &= ~((uint64_t)mtd->writesize - 1); - ret = mtd->write_oob(mtd, start, &ops); + ret = mtd_write_oob(mtd, start, &ops); if (ops.oobretlen > 0xFFFFFFFFU) ret = -EOVERFLOW; @@ -609,7 +609,7 @@ static int mtdchar_write_ioctl(struct mtd_info *mtd, ops.oobbuf = NULL; } - ret = mtd->write_oob(mtd, (loff_t)req.start, &ops); + ret = mtd_write_oob(mtd, (loff_t)req.start, &ops); kfree(ops.datbuf); kfree(ops.oobbuf); diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index cf35642e5f49..3d9c1ffdbbbf 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -333,7 +333,7 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) if (to + devops.len > subdev->size) devops.len = subdev->size - to; - err = subdev->write_oob(subdev, to, &devops); + err = mtd_write_oob(subdev, to, &devops); ops->retlen += devops.oobretlen; if (err) return err; diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 6fdc74ef19c1..8a46cd2bb78f 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -217,7 +217,7 @@ static int part_write_oob(struct mtd_info *mtd, loff_t to, return -EINVAL; if (ops->datbuf && to + ops->len > mtd->size) return -EINVAL; - return part->master->write_oob(part->master, to + part->offset, ops); + return mtd_write_oob(part->master, to + part->offset, ops); } static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 0f0ab18d4405..85797390e3dd 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -403,7 +403,7 @@ static int mtdswap_write_marker(struct mtdswap_dev *d, struct swap_eb *eb, offset = mtdswap_eb_offset(d, eb) + d->mtd->writesize; } - ret = d->mtd->write_oob(d->mtd, offset , &ops); + ret = mtd_write_oob(d->mtd, offset, &ops); if (ret) { dev_warn(d->dev, "Write OOB failed for block at %08llx " @@ -946,7 +946,7 @@ static unsigned int mtdswap_eblk_passes(struct mtdswap_dev *d, patt = mtdswap_test_patt(test + i); memset(d->page_buf, patt, mtd->writesize); memset(d->oob_buf, patt, mtd->ecclayout->oobavail); - ret = mtd->write_oob(mtd, pos, &ops); + ret = mtd_write_oob(mtd, pos, &ops); if (ret) goto error; diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c index fcab50e80b90..20a112f591fe 100644 --- a/drivers/mtd/nand/nand_bbt.c +++ b/drivers/mtd/nand/nand_bbt.c @@ -350,7 +350,7 @@ static int scan_write_bbt(struct mtd_info *mtd, loff_t offs, size_t len, ops.oobbuf = oob; ops.len = len; - return mtd->write_oob(mtd, offs, &ops); + return mtd_write_oob(mtd, offs, &ops); } static u32 bbt_get_ver_offs(struct mtd_info *mtd, struct nand_bbt_descr *td) diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c index 32ae5af7444f..774c3c266713 100644 --- a/drivers/mtd/nand/sm_common.c +++ b/drivers/mtd/nand/sm_common.c @@ -55,7 +55,7 @@ static int sm_block_markbad(struct mtd_info *mtd, loff_t ofs) ops.datbuf = NULL; - ret = mtd->write_oob(mtd, ofs, &ops); + ret = mtd_write_oob(mtd, ofs, &ops); if (ret < 0 || ops.oobretlen != SM_OOB_SIZE) { printk(KERN_NOTICE "sm_common: can't mark sector at %i as bad\n", diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index 7497f5efc26b..8847e60ad167 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -174,7 +174,7 @@ int nftl_write_oob(struct mtd_info *mtd, loff_t offs, size_t len, ops.oobbuf = buf; ops.datbuf = NULL; - res = mtd->write_oob(mtd, offs & ~mask, &ops); + res = mtd_write_oob(mtd, offs & ~mask, &ops); *retlen = ops.oobretlen; return res; } @@ -198,7 +198,7 @@ static int nftl_write(struct mtd_info *mtd, loff_t offs, size_t len, ops.datbuf = buf; ops.len = len; - res = mtd->write_oob(mtd, offs & ~mask, &ops); + res = mtd_write_oob(mtd, offs & ~mask, &ops); *retlen = ops.retlen; return res; } diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index 748aa4416691..4ec2af7fb845 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -343,7 +343,7 @@ static int sm_write_sector(struct sm_ftl *ftl, ops.ooblen = SM_OOB_SIZE; ops.oobbuf = (void *)oob; - ret = mtd->write_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); + ret = mtd_write_oob(mtd, sm_mkoffset(ftl, zone, block, boffset), &ops); /* Now we assume that hardware will catch write bitflip errors */ /* If you are paranoid, use CONFIG_MTD_NAND_VERIFY_WRITE */ diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 962d27a64e64..81113885e086 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -139,7 +139,7 @@ static int write_eraseblock(int ebnum) ops.ooboffs = use_offset; ops.datbuf = NULL; ops.oobbuf = writebuf; - err = mtd->write_oob(mtd, addr, &ops); + err = mtd_write_oob(mtd, addr, &ops); if (err || ops.oobretlen != use_len) { printk(PRINT_PREF "error: writeoob failed at %#llx\n", (long long)addr); @@ -524,7 +524,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = writebuf; printk(PRINT_PREF "attempting to start write past end of OOB\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->write_oob(mtd, addr0, &ops); + err = mtd_write_oob(mtd, addr0, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -568,7 +568,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = writebuf; printk(PRINT_PREF "attempting to write past end of device\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops); + err = mtd_write_oob(mtd, mtd->size - mtd->writesize, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -612,7 +612,7 @@ static int __init mtd_oobtest_init(void) ops.oobbuf = writebuf; printk(PRINT_PREF "attempting to write past end of device\n"); printk(PRINT_PREF "an error is expected...\n"); - err = mtd->write_oob(mtd, mtd->size - mtd->writesize, &ops); + err = mtd_write_oob(mtd, mtd->size - mtd->writesize, &ops); if (err) { printk(PRINT_PREF "error occurred as expected\n"); err = 0; @@ -670,7 +670,7 @@ static int __init mtd_oobtest_init(void) ops.ooboffs = 0; ops.datbuf = NULL; ops.oobbuf = writebuf; - err = mtd->write_oob(mtd, addr, &ops); + err = mtd_write_oob(mtd, addr, &ops); if (err) goto out; if (i % 256 == 0) diff --git a/drivers/staging/spectra/lld_mtd.c b/drivers/staging/spectra/lld_mtd.c index ed8e5f067087..4aa48ddf979c 100644 --- a/drivers/staging/spectra/lld_mtd.c +++ b/drivers/staging/spectra/lld_mtd.c @@ -411,9 +411,9 @@ u16 mtd_Write_Page_Main_Spare(u8 *write_data, u32 Block, ops.ooblen = BTSIG_BYTES; ops.ooboffs = 0; - ret = spectra_mtd->write_oob(spectra_mtd, - (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), - &ops); + ret = mtd_write_oob(spectra_mtd, + (Block * spectra_mtd->erasesize) + (Page * spectra_mtd->writesize), + &ops); if (ret) { printk(KERN_ERR "%s failed %d\n", __func__, ret); return FAIL; diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index efc0cb370306..eae5be483682 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -1101,7 +1101,7 @@ int jffs2_write_nand_cleanmarker(struct jffs2_sb_info *c, ops.len = ops.ooboffs = ops.retlen = ops.oobretlen = 0; ops.datbuf = NULL; - ret = c->mtd->write_oob(c->mtd, jeb->offset, &ops); + ret = mtd_write_oob(c->mtd, jeb->offset, &ops); if (ret || ops.oobretlen != ops.ooblen) { printk(KERN_ERR "cannot write OOB for EB at %08x, requested %zd" " bytes, read %zd bytes, error %d\n", diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 0db8d87ce451..abbc96ad3b2c 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -190,16 +190,14 @@ struct mtd_info { size_t *retlen, const u_char *buf); int (*read_oob) (struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops); + int (*write_oob) (struct mtd_info *mtd, loff_t to, + struct mtd_oob_ops *ops); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - - int (*write_oob) (struct mtd_info *mtd, loff_t to, - struct mtd_oob_ops *ops); - /* * Methods to access the protection register area, present in some * flash devices. The user data is one time programmable but the @@ -326,6 +324,12 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, return mtd->read_oob(mtd, from, ops); } +static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, + struct mtd_oob_ops *ops) +{ + return mtd->write_oob(mtd, to, ops); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From a750b5ce5e1174ea68f66bf79962c479f7f23998 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:33:28 +0200 Subject: mtd: introduce mtd_get_fact_prot_info interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 19 +++++++++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 234e3d27143c..4b1772feeafc 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -925,7 +925,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) switch (mfi->mode) { case MTD_FILE_MODE_OTP_FACTORY: if (mtd->get_fact_prot_info) - ret = mtd->get_fact_prot_info(mtd, buf, 4096); + ret = mtd_get_fact_prot_info(mtd, buf, 4096); break; case MTD_FILE_MODE_OTP_USER: if (mtd->get_user_prot_info) diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 8a46cd2bb78f..6bed8bb3b15d 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -175,7 +175,7 @@ static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { struct mtd_part *part = PART(mtd); - return part->master->get_fact_prot_info(part->master, buf, len); + return mtd_get_fact_prot_info(part->master, buf, len); } static int part_write(struct mtd_info *mtd, loff_t to, size_t len, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index abbc96ad3b2c..9a7a7f2d2296 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -192,18 +192,14 @@ struct mtd_info { struct mtd_oob_ops *ops); int (*write_oob) (struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops); + int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, + size_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - /* - * Methods to access the protection register area, present in some - * flash devices. The user data is one time programmable but the - * factory data is read only. - */ - int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); @@ -330,6 +326,17 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, return mtd->write_oob(mtd, to, ops); } +/* + * Method to access the protection register area, present in some flash + * devices. The user data is one time programmable but the factory data is read + * only. + */ +static inline int mtd_get_fact_prot_info(struct mtd_info *mtd, + struct otp_info *buf, size_t len) +{ + return mtd->get_fact_prot_info(mtd, buf, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From d264f72ae56245358025109d9d066d159589802d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:40:06 +0200 Subject: mtd: introduce mtd_read_fact_prot_reg interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 3 ++- drivers/mtd/mtdpart.c | 3 +-- include/linux/mtd/mtd.h | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 4b1772feeafc..6afb05469bbd 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -213,7 +213,8 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, switch (mfi->mode) { case MTD_FILE_MODE_OTP_FACTORY: - ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); + ret = mtd_read_fact_prot_reg(mtd, *ppos, len, + &retlen, kbuf); break; case MTD_FILE_MODE_OTP_USER: ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 6bed8bb3b15d..4f2c9137cd49 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -167,8 +167,7 @@ static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct mtd_part *part = PART(mtd); - return part->master->read_fact_prot_reg(part->master, from, - len, retlen, buf); + return mtd_read_fact_prot_reg(part->master, from, len, retlen, buf); } static int part_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 9a7a7f2d2296..d77a7f83270f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -194,13 +194,14 @@ struct mtd_info { struct mtd_oob_ops *ops); int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); + int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, + size_t len, size_t *retlen, u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); @@ -337,6 +338,13 @@ static inline int mtd_get_fact_prot_info(struct mtd_info *mtd, return mtd->get_fact_prot_info(mtd, buf, len); } +static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, + size_t len, size_t *retlen, + u_char *buf) +{ + return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 855e5d8cfebc21f45c9446a88b61e29d94c03781 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:45:11 +0200 Subject: mtd: introduce mtd_get_user_prot_info interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 10 +++++++++- 3 files changed, 11 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 6afb05469bbd..002a8b5428cc 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -930,7 +930,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) break; case MTD_FILE_MODE_OTP_USER: if (mtd->get_user_prot_info) - ret = mtd->get_user_prot_info(mtd, buf, 4096); + ret = mtd_get_user_prot_info(mtd, buf, 4096); break; default: break; diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 4f2c9137cd49..bf1ab56afb8e 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -160,7 +160,7 @@ static int part_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { struct mtd_part *part = PART(mtd); - return part->master->get_user_prot_info(part->master, buf, len); + return mtd_get_user_prot_info(part->master, buf, len); } static int part_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index d77a7f83270f..ff0a3a18f397 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -196,13 +196,14 @@ struct mtd_info { size_t len); int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); + int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, + size_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); @@ -345,6 +346,13 @@ static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf); } +static inline int mtd_get_user_prot_info(struct mtd_info *mtd, + struct otp_info *buf, + size_t len) +{ + return mtd->get_user_prot_info(mtd, buf, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 4ea1cabb926f03a8dbd6e3f064538d9a290ee9fd Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:47:59 +0200 Subject: mtd: introduce mtd_read_user_prot_reg interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 3 ++- drivers/mtd/mtdpart.c | 3 +-- include/linux/mtd/mtd.h | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 002a8b5428cc..6aa3fb4a0292 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -217,7 +217,8 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, &retlen, kbuf); break; case MTD_FILE_MODE_OTP_USER: - ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); + ret = mtd_read_user_prot_reg(mtd, *ppos, len, + &retlen, kbuf); break; case MTD_FILE_MODE_RAW: { diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index bf1ab56afb8e..f018373ef3b4 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -152,8 +152,7 @@ static int part_read_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct mtd_part *part = PART(mtd); - return part->master->read_user_prot_reg(part->master, from, - len, retlen, buf); + return mtd_read_user_prot_reg(part->master, from, len, retlen, buf); } static int part_get_user_prot_info(struct mtd_info *mtd, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index ff0a3a18f397..855fb7fab697 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -198,13 +198,14 @@ struct mtd_info { size_t len, size_t *retlen, u_char *buf); int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); + int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, + size_t len, size_t *retlen, u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); @@ -353,6 +354,13 @@ static inline int mtd_get_user_prot_info(struct mtd_info *mtd, return mtd->get_user_prot_info(mtd, buf, len); } +static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, + size_t len, size_t *retlen, + u_char *buf) +{ + return mtd->read_user_prot_reg(mtd, from, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 482b43adbb7b124316ec72c161b0d1655e759368 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:50:04 +0200 Subject: mtd: introduce mtd_write_user_prot_reg interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 3 ++- drivers/mtd/mtdpart.c | 3 +-- include/linux/mtd/mtd.h | 10 +++++++++- 3 files changed, 12 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 6aa3fb4a0292..d8881707ca60 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -314,7 +314,8 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c ret = -EOPNOTSUPP; break; } - ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); + ret = mtd_write_user_prot_reg(mtd, *ppos, len, + &retlen, kbuf); break; case MTD_FILE_MODE_RAW: diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index f018373ef3b4..1e7b8d1693aa 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -222,8 +222,7 @@ static int part_write_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) { struct mtd_part *part = PART(mtd); - return part->master->write_user_prot_reg(part->master, from, - len, retlen, buf); + return mtd_write_user_prot_reg(part->master, from, len, retlen, buf); } static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 855fb7fab697..554960793e37 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -200,13 +200,14 @@ struct mtd_info { size_t len); int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); + int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t to, size_t len, + size_t *retlen, u_char *buf); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); /* kvec-based read/write methods. @@ -361,6 +362,13 @@ static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, return mtd->read_user_prot_reg(mtd, from, len, retlen, buf); } +static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, + size_t len, size_t *retlen, + u_char *buf) +{ + return mtd->write_user_prot_reg(mtd, to, len, retlen, buf); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 4403dbfb4541d34e5db33db709094d57d09f7467 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:55:49 +0200 Subject: mtd: introduce mtd_lock_user_prot_reg interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 10 ++++++++-- 3 files changed, 10 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index d8881707ca60..86308acb40e0 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -960,7 +960,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) return -EFAULT; if (!mtd->lock_user_prot_reg) return -EOPNOTSUPP; - ret = mtd->lock_user_prot_reg(mtd, oinfo.start, oinfo.length); + ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length); break; } #endif diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 1e7b8d1693aa..0bb16d6ed08a 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -229,7 +229,7 @@ static int part_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len) { struct mtd_part *part = PART(mtd); - return part->master->lock_user_prot_reg(part->master, from, len); + return mtd_lock_user_prot_reg(part->master, from, len); } static int part_writev(struct mtd_info *mtd, const struct kvec *vecs, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 554960793e37..b58e5e8746ec 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -202,14 +202,14 @@ struct mtd_info { size_t len, size_t *retlen, u_char *buf); int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, u_char *buf); + int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, + size_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); - /* kvec-based read/write methods. NB: The 'count' parameter is the number of _vectors_, each of which contains an (ofs, len) tuple. @@ -369,6 +369,12 @@ static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, return mtd->write_user_prot_reg(mtd, to, len, retlen, buf); } +static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, + size_t len) +{ + return mtd->lock_user_prot_reg(mtd, from, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From b0a31f7b2a668f00a8d0546dfeed65fac871b2da Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 18:59:12 +0200 Subject: mtd: introduce mtd_writev interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdconcat.c | 5 +++-- drivers/mtd/mtdpart.c | 4 ++-- fs/jffs2/writev.c | 2 +- include/linux/mtd/mtd.h | 18 ++++++++++++------ 4 files changed, 18 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 3d9c1ffdbbbf..6fdae191e1ba 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -227,8 +227,9 @@ concat_writev(struct mtd_info *mtd, const struct kvec *vecs, if (!(subdev->flags & MTD_WRITEABLE)) err = -EROFS; else - err = subdev->writev(subdev, &vecs_copy[entry_low], - entry_high - entry_low + 1, to, &retsize); + err = mtd_writev(subdev, &vecs_copy[entry_low], + entry_high - entry_low + 1, to, + &retsize); vecs_copy[entry_high].iov_len = old_iov_len - size; vecs_copy[entry_high].iov_base += size; diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 0bb16d6ed08a..c0bfa88c82f3 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -238,8 +238,8 @@ static int part_writev(struct mtd_info *mtd, const struct kvec *vecs, struct mtd_part *part = PART(mtd); if (!(mtd->flags & MTD_WRITEABLE)) return -EROFS; - return part->master->writev(part->master, vecs, count, - to + part->offset, retlen); + return mtd_writev(part->master, vecs, count, to + part->offset, + retlen); } static int part_erase(struct mtd_info *mtd, struct erase_info *instr) diff --git a/fs/jffs2/writev.c b/fs/jffs2/writev.c index b05710fd552a..d0ef068709ad 100644 --- a/fs/jffs2/writev.c +++ b/fs/jffs2/writev.c @@ -52,7 +52,7 @@ int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, } if (c->mtd->writev) - return c->mtd->writev(c->mtd, vecs, count, to, retlen); + return mtd_writev(c->mtd, vecs, count, to, retlen); else { return mtd_fake_writev(c->mtd, vecs, count, to, retlen); } diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index b58e5e8746ec..4129cb5c3de4 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -204,18 +204,14 @@ struct mtd_info { size_t *retlen, u_char *buf); int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); + int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, + unsigned long count, loff_t to, size_t *retlen); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - /* kvec-based read/write methods. - NB: The 'count' parameter is the number of _vectors_, each of - which contains an (ofs, len) tuple. - */ - int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); - /* Sync */ void (*sync) (struct mtd_info *mtd); @@ -375,6 +371,16 @@ static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, return mtd->lock_user_prot_reg(mtd, from, len); } +/* + * kvec-based read/write method. NB: The 'count' parameter is the number of + * _vectors_, each of which contains an (ofs, len) tuple. + */ +static inline int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, + unsigned long count, loff_t to, size_t *retlen) +{ + return mtd->writev(mtd, vecs, count, to, retlen); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 85f2f2a809d658c15b574df02ede92090f45a1f2 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:03:12 +0200 Subject: mtd: introduce mtd_sync interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/ftl.c | 2 +- drivers/mtd/mtdblock.c | 4 ++-- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/mtdswap.c | 2 +- drivers/mtd/rfd_ftl.c | 2 +- drivers/mtd/ubi/kapi.c | 2 +- fs/jffs2/super.c | 2 +- fs/logfs/dev_mtd.c | 2 +- include/linux/mtd/mtd.h | 9 ++++++--- 11 files changed, 17 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index d591b1d0a6c1..c9c90299c9e2 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -651,7 +651,7 @@ static int reclaim_block(partition_t *part) pr_debug("ftl_cs: waiting for transfer " "unit to be prepared...\n"); if (part->mbd.mtd->sync) - part->mbd.mtd->sync(part->mbd.mtd); + mtd_sync(part->mbd.mtd); } else { static int ne = 0; if (++ne < 5) diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index ac7f1f1faa2d..496e1a6e8029 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -323,7 +323,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd) if (!--mtdblk->count) { /* It was the last usage. Free the cache */ if (mbd->mtd->sync) - mbd->mtd->sync(mbd->mtd); + mtd_sync(mbd->mtd); vfree(mtdblk->cache_data); } @@ -343,7 +343,7 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev) mutex_unlock(&mtdblk->cache_mutex); if (dev->mtd->sync) - dev->mtd->sync(dev->mtd); + mtd_sync(dev->mtd); return 0; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 86308acb40e0..b5722ecf19d3 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -155,7 +155,7 @@ static int mtdchar_close(struct inode *inode, struct file *file) /* Only sync if opened RW */ if ((file->f_mode & FMODE_WRITE) && mtd->sync) - mtd->sync(mtd); + mtd_sync(mtd); iput(mfi->ino); diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 6fdae191e1ba..cc2336edfe28 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -620,7 +620,7 @@ static void concat_sync(struct mtd_info *mtd) for (i = 0; i < concat->num_subdev; i++) { struct mtd_info *subdev = concat->subdev[i]; - subdev->sync(subdev); + mtd_sync(subdev); } } diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index c0bfa88c82f3..2b545052795e 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -301,7 +301,7 @@ static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) static void part_sync(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); - part->master->sync(part->master); + mtd_sync(part->master); } static int part_suspend(struct mtd_info *mtd) diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 85797390e3dd..cb794e761012 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -1048,7 +1048,7 @@ static int mtdswap_flush(struct mtd_blktrans_dev *dev) struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev); if (d->mtd->sync) - d->mtd->sync(d->mtd); + mtd_sync(d->mtd); return 0; } diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index c594bb7abfa3..5426d42cdea7 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -449,7 +449,7 @@ static int reclaim_block(struct partition *part, u_long *old_sector) /* we have a race if sync doesn't exist */ if (part->mbd.mtd->sync) - part->mbd.mtd->sync(part->mbd.mtd); + mtd_sync(part->mbd.mtd); score = 0x7fffffff; /* MAX_INT */ best_block = -1; diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 1a35fc5e3b40..9f265cc1a0d3 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c @@ -715,7 +715,7 @@ int ubi_sync(int ubi_num) return -ENODEV; if (ubi->mtd->sync) - ubi->mtd->sync(ubi->mtd); + mtd_sync(ubi->mtd); ubi_put_device(ubi); return 0; diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c index e7e974454115..e78bf3cd1b73 100644 --- a/fs/jffs2/super.c +++ b/fs/jffs2/super.c @@ -337,7 +337,7 @@ static void jffs2_put_super (struct super_block *sb) kfree(c->inocache_list); jffs2_clear_xattr_subsystem(c); if (c->mtd->sync) - c->mtd->sync(c->mtd); + mtd_sync(c->mtd); D1(printk(KERN_DEBUG "jffs2_put_super returning\n")); } diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 1842440d6564..0ca7a07db6c1 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -120,7 +120,7 @@ static void logfs_mtd_sync(struct super_block *sb) struct mtd_info *mtd = logfs_super(sb)->s_mtd; if (mtd->sync) - mtd->sync(mtd); + mtd_sync(mtd); } static int logfs_mtd_readpage(void *_sb, struct page *page) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 4129cb5c3de4..47ea19c1e523 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -206,15 +206,13 @@ struct mtd_info { size_t len); int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); + void (*sync) (struct mtd_info *mtd); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - /* Sync */ - void (*sync) (struct mtd_info *mtd); - /* Chip-supported device locking */ int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); @@ -381,6 +379,11 @@ static inline int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, return mtd->writev(mtd, vecs, count, to, retlen); } +static inline void mtd_sync(struct mtd_info *mtd) +{ + mtd->sync(mtd); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 7799f9ac8d8ff2db14736950275249df442baeac Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:15:39 +0200 Subject: mtd: introduce mtd_lock interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/scb2_flash.c | 2 +- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 9 +++++++-- 5 files changed, 11 insertions(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c index d88c8426bb0f..01af34778de3 100644 --- a/drivers/mtd/maps/scb2_flash.c +++ b/drivers/mtd/maps/scb2_flash.c @@ -205,7 +205,7 @@ scb2_flash_remove(struct pci_dev *dev) /* disable flash writes */ if (scb2_mtd->lock) - scb2_mtd->lock(scb2_mtd, 0, scb2_mtd->size); + mtd_lock(scb2_mtd, 0, scb2_mtd->size); mtd_device_unregister(scb2_mtd); map_destroy(scb2_mtd); diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index b5722ecf19d3..870f2cb415cb 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -824,7 +824,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (!mtd->lock) ret = -EOPNOTSUPP; else - ret = mtd->lock(mtd, einfo.start, einfo.length); + ret = mtd_lock(mtd, einfo.start, einfo.length); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index cc2336edfe28..97d6360986c8 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -556,7 +556,7 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) size = len; if (subdev->lock) { - err = subdev->lock(subdev, ofs, size); + err = mtd_lock(subdev, ofs, size); if (err) break; } else diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 2b545052795e..a5e7a2103dcf 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -279,7 +279,7 @@ static int part_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) struct mtd_part *part = PART(mtd); if ((len + ofs) > mtd->size) return -EINVAL; - return part->master->lock(part->master, ofs + part->offset, len); + return mtd_lock(part->master, ofs + part->offset, len); } static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 47ea19c1e523..167bac2e380e 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -207,14 +207,13 @@ struct mtd_info { int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen); void (*sync) (struct mtd_info *mtd); + int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - /* Chip-supported device locking */ - int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); @@ -384,6 +383,12 @@ static inline void mtd_sync(struct mtd_info *mtd) mtd->sync(mtd); } +/* Chip-supported device locking */ +static inline int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + return mtd->lock(mtd, ofs, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From b66005cd3e6f104e0a1b6492110c337269b53ec3 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:18:22 +0200 Subject: mtd: introduce mtd_unlock interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdcore.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 7 ++++++- 5 files changed, 10 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 870f2cb415cb..fe09cd2a4540 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -838,7 +838,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (!mtd->unlock) ret = -EOPNOTSUPP; else - ret = mtd->unlock(mtd, einfo.start, einfo.length); + ret = mtd_unlock(mtd, einfo.start, einfo.length); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 97d6360986c8..272ebc01f95b 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -596,7 +596,7 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) size = len; if (subdev->unlock) { - err = subdev->unlock(subdev, ofs, size); + err = mtd_unlock(subdev, ofs, size); if (err) break; } else diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index e36191ab47c3..4a2155748fa3 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -340,7 +340,7 @@ int add_mtd_device(struct mtd_info *mtd) /* Some chips always power up locked. Unlock them now */ if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) { - if (mtd->unlock(mtd, 0, mtd->size)) + if (mtd_unlock(mtd, 0, mtd->size)) printk(KERN_WARNING "%s: unlock failed, writes may not work\n", mtd->name); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index a5e7a2103dcf..d65af3752331 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -287,7 +287,7 @@ static int part_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) struct mtd_part *part = PART(mtd); if ((len + ofs) > mtd->size) return -EINVAL; - return part->master->unlock(part->master, ofs + part->offset, len); + return mtd_unlock(part->master, ofs + part->offset, len); } static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 167bac2e380e..f30c35886f7c 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -208,13 +208,13 @@ struct mtd_info { unsigned long count, loff_t to, size_t *retlen); void (*sync) (struct mtd_info *mtd); int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); + int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); /* Power Management functions */ @@ -389,6 +389,11 @@ static inline int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) return mtd->lock(mtd, ofs, len); } +static inline int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + return mtd->unlock(mtd, ofs, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From e95e9786455c11c8eac30d76e5289d4e40187f9a Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:21:16 +0200 Subject: mtd: introduce mtd_is_locked interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdpart.c | 2 +- include/linux/mtd/mtd.h | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index fe09cd2a4540..6d598b23cf3a 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -852,7 +852,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (!mtd->is_locked) ret = -EOPNOTSUPP; else - ret = mtd->is_locked(mtd, einfo.start, einfo.length); + ret = mtd_is_locked(mtd, einfo.start, einfo.length); break; } diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index d65af3752331..ad487fcd423f 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -295,7 +295,7 @@ static int part_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) struct mtd_part *part = PART(mtd); if ((len + ofs) > mtd->size) return -EINVAL; - return part->master->is_locked(part->master, ofs + part->offset, len); + return mtd_is_locked(part->master, ofs + part->offset, len); } static void part_sync(struct mtd_info *mtd) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index f30c35886f7c..8b9901986c86 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -209,14 +209,13 @@ struct mtd_info { void (*sync) (struct mtd_info *mtd); int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); + int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); - /* Power Management functions */ int (*suspend) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd); @@ -394,6 +393,11 @@ static inline int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) return mtd->unlock(mtd, ofs, len); } +static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) +{ + return mtd->is_locked(mtd, ofs, len); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 3fe4bae88460869a8e553397cd9057a4ee7ca341 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:25:16 +0200 Subject: mtd: introduce mtd_suspend interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/physmap.c | 2 +- drivers/mtd/maps/pxa2xx-flash.c | 2 +- drivers/mtd/maps/rbtx4939-flash.c | 2 +- drivers/mtd/maps/sa1100-flash.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdcore.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/nand/nomadik_nand.c | 2 +- drivers/mtd/nand/pxa3xx_nand.c | 2 +- include/linux/mtd/mtd.h | 7 ++++++- 10 files changed, 15 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index 1f749d58ae6f..b7f0cd14ae2b 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -191,7 +191,7 @@ static void physmap_flash_shutdown(struct platform_device *dev) for (i = 0; i < MAX_RESOURCES && info->mtd[i]; i++) if (info->mtd[i]->suspend && info->mtd[i]->resume) - if (info->mtd[i]->suspend(info->mtd[i]) == 0) + if (mtd_suspend(info->mtd[i]) == 0) info->mtd[i]->resume(info->mtd[i]); } #else diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 274e39914332..9cb427320c04 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c @@ -125,7 +125,7 @@ static void pxa2xx_flash_shutdown(struct platform_device *dev) { struct pxa2xx_flash_info *info = platform_get_drvdata(dev); - if (info && info->mtd->suspend(info->mtd) == 0) + if (info && mtd_suspend(info->mtd) == 0) info->mtd->resume(info->mtd); } #else diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c index bb7d2042affa..5856aa2d99f7 100644 --- a/drivers/mtd/maps/rbtx4939-flash.c +++ b/drivers/mtd/maps/rbtx4939-flash.c @@ -120,7 +120,7 @@ static void rbtx4939_flash_shutdown(struct platform_device *dev) struct rbtx4939_flash_info *info = platform_get_drvdata(dev); if (info->mtd->suspend && info->mtd->resume) - if (info->mtd->suspend(info->mtd) == 0) + if (mtd_suspend(info->mtd) == 0) info->mtd->resume(info->mtd); } #else diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index ac3a290748cd..20944f054867 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c @@ -377,7 +377,7 @@ static int __exit sa1100_mtd_remove(struct platform_device *pdev) static void sa1100_mtd_shutdown(struct platform_device *dev) { struct sa_info *info = platform_get_drvdata(dev); - if (info && info->mtd->suspend(info->mtd) == 0) + if (info && mtd_suspend(info->mtd) == 0) info->mtd->resume(info->mtd); } #else diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 272ebc01f95b..36bb1c99925b 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -631,7 +631,7 @@ static int concat_suspend(struct mtd_info *mtd) for (i = 0; i < concat->num_subdev; i++) { struct mtd_info *subdev = concat->subdev[i]; - if ((rc = subdev->suspend(subdev)) < 0) + if ((rc = mtd_suspend(subdev)) < 0) return rc; } return rc; diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 4a2155748fa3..0db455d31148 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -119,7 +119,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state) struct mtd_info *mtd = dev_to_mtd(dev); if (mtd && mtd->suspend) - return mtd->suspend(mtd); + return mtd_suspend(mtd); else return 0; } diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index ad487fcd423f..c5e556a92641 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -307,7 +307,7 @@ static void part_sync(struct mtd_info *mtd) static int part_suspend(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); - return part->master->suspend(part->master); + return mtd_suspend(part->master); } static void part_resume(struct mtd_info *mtd) diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c index 673dc6c68f9a..9461babdb308 100644 --- a/drivers/mtd/nand/nomadik_nand.c +++ b/drivers/mtd/nand/nomadik_nand.c @@ -201,7 +201,7 @@ static int nomadik_nand_suspend(struct device *dev) struct nomadik_nand_host *host = dev_get_drvdata(dev); int ret = 0; if (host) - ret = host->mtd.suspend(&host->mtd); + ret = mtd_suspend(&host->mtd); return ret; } diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 90d60169ae40..7a028cf1206e 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c @@ -1258,7 +1258,7 @@ static int pxa3xx_nand_suspend(struct platform_device *pdev, pm_message_t state) for (cs = 0; cs < pdata->num_cs; cs++) { mtd = info->host[cs]->mtd; - mtd->suspend(mtd); + mtd_suspend(mtd); } return 0; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 8b9901986c86..8e01bad44e25 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -210,6 +210,7 @@ struct mtd_info { int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); + int (*suspend) (struct mtd_info *mtd); /* Backing device capabilities for this device * - provides mmap capabilities @@ -217,7 +218,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; /* Power Management functions */ - int (*suspend) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd); /* Bad block management functions */ @@ -398,6 +398,11 @@ static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) return mtd->is_locked(mtd, ofs, len); } +static inline int mtd_suspend(struct mtd_info *mtd) +{ + return mtd->suspend(mtd); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From ead995f8d4da1e2f1ef40b0e5f4133fee38a3d3d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:31:25 +0200 Subject: mtd: introduce mtd_resume interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/physmap.c | 2 +- drivers/mtd/maps/pxa2xx-flash.c | 2 +- drivers/mtd/maps/rbtx4939-flash.c | 2 +- drivers/mtd/maps/sa1100-flash.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdcore.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/nand/nomadik_nand.c | 2 +- drivers/mtd/nand/pxa3xx_nand.c | 2 +- include/linux/mtd/mtd.h | 9 ++++++--- 10 files changed, 15 insertions(+), 12 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index b7f0cd14ae2b..d94cc62186c1 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -192,7 +192,7 @@ static void physmap_flash_shutdown(struct platform_device *dev) for (i = 0; i < MAX_RESOURCES && info->mtd[i]; i++) if (info->mtd[i]->suspend && info->mtd[i]->resume) if (mtd_suspend(info->mtd[i]) == 0) - info->mtd[i]->resume(info->mtd[i]); + mtd_resume(info->mtd[i]); } #else #define physmap_flash_shutdown NULL diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c index 9cb427320c04..436d121185b1 100644 --- a/drivers/mtd/maps/pxa2xx-flash.c +++ b/drivers/mtd/maps/pxa2xx-flash.c @@ -126,7 +126,7 @@ static void pxa2xx_flash_shutdown(struct platform_device *dev) struct pxa2xx_flash_info *info = platform_get_drvdata(dev); if (info && mtd_suspend(info->mtd) == 0) - info->mtd->resume(info->mtd); + mtd_resume(info->mtd); } #else #define pxa2xx_flash_shutdown NULL diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c index 5856aa2d99f7..717628312040 100644 --- a/drivers/mtd/maps/rbtx4939-flash.c +++ b/drivers/mtd/maps/rbtx4939-flash.c @@ -121,7 +121,7 @@ static void rbtx4939_flash_shutdown(struct platform_device *dev) if (info->mtd->suspend && info->mtd->resume) if (mtd_suspend(info->mtd) == 0) - info->mtd->resume(info->mtd); + mtd_resume(info->mtd); } #else #define rbtx4939_flash_shutdown NULL diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c index 20944f054867..502821997707 100644 --- a/drivers/mtd/maps/sa1100-flash.c +++ b/drivers/mtd/maps/sa1100-flash.c @@ -378,7 +378,7 @@ static void sa1100_mtd_shutdown(struct platform_device *dev) { struct sa_info *info = platform_get_drvdata(dev); if (info && mtd_suspend(info->mtd) == 0) - info->mtd->resume(info->mtd); + mtd_resume(info->mtd); } #else #define sa1100_mtd_shutdown NULL diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 36bb1c99925b..4b7f825ce015 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -644,7 +644,7 @@ static void concat_resume(struct mtd_info *mtd) for (i = 0; i < concat->num_subdev; i++) { struct mtd_info *subdev = concat->subdev[i]; - subdev->resume(subdev); + mtd_resume(subdev); } } diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 0db455d31148..376fbfdb09aa 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -129,7 +129,7 @@ static int mtd_cls_resume(struct device *dev) struct mtd_info *mtd = dev_to_mtd(dev); if (mtd && mtd->resume) - mtd->resume(mtd); + mtd_resume(mtd); return 0; } diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index c5e556a92641..8610750852ac 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -313,7 +313,7 @@ static int part_suspend(struct mtd_info *mtd) static void part_resume(struct mtd_info *mtd) { struct mtd_part *part = PART(mtd); - part->master->resume(part->master); + mtd_resume(part->master); } static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c index 9461babdb308..a86aa812ca13 100644 --- a/drivers/mtd/nand/nomadik_nand.c +++ b/drivers/mtd/nand/nomadik_nand.c @@ -209,7 +209,7 @@ static int nomadik_nand_resume(struct device *dev) { struct nomadik_nand_host *host = dev_get_drvdata(dev); if (host) - host->mtd.resume(&host->mtd); + mtd_resume(&host->mtd); return 0; } diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c index 7a028cf1206e..8544d6bf50a0 100644 --- a/drivers/mtd/nand/pxa3xx_nand.c +++ b/drivers/mtd/nand/pxa3xx_nand.c @@ -1291,7 +1291,7 @@ static int pxa3xx_nand_resume(struct platform_device *pdev) nand_writel(info, NDSR, NDSR_MASK); for (cs = 0; cs < pdata->num_cs; cs++) { mtd = info->host[cs]->mtd; - mtd->resume(mtd); + mtd_resume(mtd); } return 0; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 8e01bad44e25..d6b4aa177505 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -211,15 +211,13 @@ struct mtd_info { int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*suspend) (struct mtd_info *mtd); + void (*resume) (struct mtd_info *mtd); /* Backing device capabilities for this device * - provides mmap capabilities */ struct backing_dev_info *backing_dev_info; - /* Power Management functions */ - void (*resume) (struct mtd_info *mtd); - /* Bad block management functions */ int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); @@ -403,6 +401,11 @@ static inline int mtd_suspend(struct mtd_info *mtd) return mtd->suspend(mtd); } +static inline void mtd_resume(struct mtd_info *mtd) +{ + mtd->resume(mtd); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 7086c19d07429d697057587caf1e5e0345442d16 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:35:30 +0200 Subject: mtd: introduce mtd_block_isbad interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- arch/cris/arch-v32/drivers/axisflashmap.c | 3 +-- drivers/mtd/inftlmount.c | 3 ++- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 4 ++-- drivers/mtd/mtdpart.c | 5 ++--- drivers/mtd/mtdswap.c | 4 ++-- drivers/mtd/nftlmount.c | 3 ++- drivers/mtd/redboot.c | 4 ++-- drivers/mtd/ssfdc.c | 4 ++-- drivers/mtd/tests/mtd_oobtest.c | 2 +- drivers/mtd/tests/mtd_pagetest.c | 2 +- drivers/mtd/tests/mtd_readtest.c | 2 +- drivers/mtd/tests/mtd_speedtest.c | 2 +- drivers/mtd/tests/mtd_stresstest.c | 2 +- drivers/mtd/tests/mtd_subpagetest.c | 2 +- drivers/mtd/tests/mtd_torturetest.c | 3 +-- drivers/mtd/ubi/io.c | 2 +- fs/jffs2/scan.c | 2 +- fs/logfs/dev_mtd.c | 4 ++-- include/linux/mtd/mtd.h | 7 ++++++- 21 files changed, 34 insertions(+), 30 deletions(-) (limited to 'drivers') diff --git a/arch/cris/arch-v32/drivers/axisflashmap.c b/arch/cris/arch-v32/drivers/axisflashmap.c index 011bddbf073f..b34438e026be 100644 --- a/arch/cris/arch-v32/drivers/axisflashmap.c +++ b/arch/cris/arch-v32/drivers/axisflashmap.c @@ -404,8 +404,7 @@ static int __init init_axis_flash(void) */ int blockstat; do { - blockstat = main_mtd->block_isbad(main_mtd, - ptable_sector); + blockstat = mtd_block_isbad(main_mtd, ptable_sector); if (blockstat < 0) ptable_sector = 0; /* read error */ else if (blockstat) diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 9bfbca5d88d6..38519401196b 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -306,7 +306,8 @@ static int find_boot_record(struct INFTLrecord *inftl) /* If any of the physical eraseblocks are bad, don't use the unit. */ for (physblock = 0; physblock < inftl->EraseSize; physblock += inftl->mbd.mtd->erasesize) { - if (inftl->mbd.mtd->block_isbad(inftl->mbd.mtd, i * inftl->EraseSize + physblock)) + if (mtd_block_isbad(inftl->mbd.mtd, + i * inftl->EraseSize + physblock)) inftl->PUtable[i] = BLOCK_RESERVED; } } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 6d598b23cf3a..a499bf7a8214 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -886,7 +886,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (!mtd->block_isbad) ret = -EOPNOTSUPP; else - return mtd->block_isbad(mtd, offs); + return mtd_block_isbad(mtd, offs); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 4b7f825ce015..d0db5e61d5af 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -667,7 +667,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs) continue; } - res = subdev->block_isbad(subdev, ofs); + res = mtd_block_isbad(subdev, ofs); break; } diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 7be2018ffbcc..bc43d2f7272c 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -170,7 +170,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work) } while (mtd->block_isbad) { - ret = mtd->block_isbad(mtd, cxt->nextpage * record_size); + ret = mtd_block_isbad(mtd, cxt->nextpage * record_size); if (!ret) break; if (ret < 0) { @@ -254,7 +254,7 @@ static void find_next_position(struct mtdoops_context *cxt) for (page = 0; page < cxt->oops_pages; page++) { if (mtd->block_isbad && - mtd->block_isbad(mtd, page * record_size)) + mtd_block_isbad(mtd, page * record_size)) continue; /* Assume the page is used */ mark_page_used(cxt, page); diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 8610750852ac..0e7dfc79d337 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -322,7 +322,7 @@ static int part_block_isbad(struct mtd_info *mtd, loff_t ofs) if (ofs >= mtd->size) return -EINVAL; ofs += part->offset; - return part->master->block_isbad(part->master, ofs); + return mtd_block_isbad(part->master, ofs); } static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) @@ -553,8 +553,7 @@ static struct mtd_part *allocate_partition(struct mtd_info *master, uint64_t offs = 0; while (offs < slave->mtd.size) { - if (master->block_isbad(master, - offs + slave->offset)) + if (mtd_block_isbad(master, offs + slave->offset)) slave->mtd.ecc_stats.badblocks++; offs += slave->mtd.erasesize; } diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index cb794e761012..87aa0a6323c3 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb) offset = mtdswap_eb_offset(d, eb); /* Check first if the block is bad. */ - if (d->mtd->block_isbad && d->mtd->block_isbad(d->mtd, offset)) + if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset)) return MTDSWAP_SCANNED_BAD; ops.ooblen = 2 * d->mtd->ecclayout->oobavail; @@ -1061,7 +1061,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size) if (mtd->block_isbad) for (offset = 0; offset < size; offset += mtd->erasesize) - if (mtd->block_isbad(mtd, offset)) + if (mtd_block_isbad(mtd, offset)) badcnt++; return badcnt; diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index b068dc8a3666..156af9f87961 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c @@ -242,7 +242,8 @@ The new DiskOnChip driver already scanned the bad block table. Just query it. if (buf[i & (SECTORSIZE - 1)] != 0xff) nftl->ReplUnitTable[i] = BLOCK_RESERVED; #endif - if (nftl->mbd.mtd->block_isbad(nftl->mbd.mtd, i * nftl->EraseSize)) + if (mtd_block_isbad(nftl->mbd.mtd, + i * nftl->EraseSize)) nftl->ReplUnitTable[i] = BLOCK_RESERVED; } diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c index 623d9b86d0d9..09bb81ea3a7e 100644 --- a/drivers/mtd/redboot.c +++ b/drivers/mtd/redboot.c @@ -79,7 +79,7 @@ static int parse_redboot_partitions(struct mtd_info *master, if ( directory < 0 ) { offset = master->size + directory * master->erasesize; while (master->block_isbad && - master->block_isbad(master, offset)) { + mtd_block_isbad(master, offset)) { if (!offset) { nogood: printk(KERN_NOTICE "Failed to find a non-bad block to check for RedBoot partition table\n"); @@ -90,7 +90,7 @@ static int parse_redboot_partitions(struct mtd_info *master, } else { offset = directory * master->erasesize; while (master->block_isbad && - master->block_isbad(master, offset)) { + mtd_block_isbad(master, offset)) { offset += master->erasesize; if (offset == master->size) goto nogood; diff --git a/drivers/mtd/ssfdc.c b/drivers/mtd/ssfdc.c index 0e6881338357..ab2a52a039c3 100644 --- a/drivers/mtd/ssfdc.c +++ b/drivers/mtd/ssfdc.c @@ -122,7 +122,7 @@ static int get_valid_cis_sector(struct mtd_info *mtd) * is not SSFDC formatted */ for (k = 0, offset = 0; k < 4; k++, offset += mtd->erasesize) { - if (!mtd->block_isbad(mtd, offset)) { + if (mtd_block_isbad(mtd, offset)) { ret = mtd_read(mtd, offset, SECTOR_SIZE, &retlen, sect_buf); @@ -255,7 +255,7 @@ static int build_logical_block_map(struct ssfdcr_record *ssfdc) for (phys_block = ssfdc->cis_block + 1; phys_block < ssfdc->map_len; phys_block++) { offset = (unsigned long)phys_block * ssfdc->erase_size; - if (mtd->block_isbad(mtd, offset)) + if (mtd_block_isbad(mtd, offset)) continue; /* skip bad blocks */ ret = read_raw_oob(mtd, offset, oob_buf); diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c index 81113885e086..ed9b62827f1b 100644 --- a/drivers/mtd/tests/mtd_oobtest.c +++ b/drivers/mtd/tests/mtd_oobtest.c @@ -329,7 +329,7 @@ static int is_block_bad(int ebnum) int ret; loff_t addr = ebnum * mtd->erasesize; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 83da97e54f97..8024eaf4c1ac 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -469,7 +469,7 @@ static int is_block_bad(int ebnum) loff_t addr = ebnum * mtd->erasesize; int ret; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 5eaeada84284..ad5fd0df86ee 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -132,7 +132,7 @@ static int is_block_bad(int ebnum) loff_t addr = ebnum * mtd->erasesize; int ret; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index c7b18e189082..ecb287847505 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -296,7 +296,7 @@ static int is_block_bad(int ebnum) loff_t addr = ebnum * mtd->erasesize; int ret; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index f8aac4b7e59a..4789c0ee3e9a 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -132,7 +132,7 @@ static int is_block_bad(int ebnum) loff_t addr = ebnum * mtd->erasesize; int ret; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index b90c01036b49..4b873d49fe6a 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -344,7 +344,7 @@ static int is_block_bad(int ebnum) loff_t addr = ebnum * mtd->erasesize; int ret; - ret = mtd->block_isbad(mtd, addr); + ret = mtd_block_isbad(mtd, addr); if (ret) printk(PRINT_PREF "block %d is bad\n", ebnum); return ret; diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index dd34a519fa7a..30c4ed9855ec 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -292,8 +292,7 @@ static int __init tort_init(void) memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); if (mtd->block_isbad) { for (i = eb; i < eb + ebcnt; i++) { - err = mtd->block_isbad(mtd, - (loff_t)i * mtd->erasesize); + err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); if (err < 0) { printk(PRINT_PREF "block_isbad() returned %d " diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index 8d832fc9e9e4..a1b683ad639e 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -634,7 +634,7 @@ int ubi_io_is_bad(const struct ubi_device *ubi, int pnum) if (ubi->bad_allowed) { int ret; - ret = mtd->block_isbad(mtd, (loff_t)pnum * ubi->peb_size); + ret = mtd_block_isbad(mtd, (loff_t)pnum * ubi->peb_size); if (ret < 0) ubi_err("error %d while checking if PEB %d is bad", ret, pnum); diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c index 72f3960f44a9..83e1665e2574 100644 --- a/fs/jffs2/scan.c +++ b/fs/jffs2/scan.c @@ -455,7 +455,7 @@ static int jffs2_scan_eraseblock (struct jffs2_sb_info *c, struct jffs2_eraseblo if (jffs2_cleanmarker_oob(c)) { int ret; - if (c->mtd->block_isbad(c->mtd, jeb->offset)) + if (mtd_block_isbad(c->mtd, jeb->offset)) return BLK_STATE_BADBLOCK; ret = jffs2_check_nand_cleanmarker(c, jeb); diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 0ca7a07db6c1..136c7360a9b6 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -157,7 +157,7 @@ static struct page *logfs_mtd_find_first_sb(struct super_block *sb, u64 *ofs) return NULL; *ofs = 0; - while (mtd->block_isbad(mtd, *ofs)) { + while (mtd_block_isbad(mtd, *ofs)) { *ofs += mtd->erasesize; if (*ofs >= mtd->size) return NULL; @@ -177,7 +177,7 @@ static struct page *logfs_mtd_find_last_sb(struct super_block *sb, u64 *ofs) return NULL; *ofs = mtd->size - mtd->erasesize; - while (mtd->block_isbad(mtd, *ofs)) { + while (mtd_block_isbad(mtd, *ofs)) { *ofs -= mtd->erasesize; if (*ofs <= 0) return NULL; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index d6b4aa177505..a307ad093a54 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -210,6 +210,7 @@ struct mtd_info { int (*lock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); + int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); int (*suspend) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd); @@ -219,7 +220,6 @@ struct mtd_info { struct backing_dev_info *backing_dev_info; /* Bad block management functions */ - int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); struct notifier_block reboot_notifier; /* default mode before reboot */ @@ -406,6 +406,11 @@ static inline void mtd_resume(struct mtd_info *mtd) mtd->resume(mtd); } +static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) +{ + return mtd->block_isbad(mtd, ofs); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 5942ddbc500d1c9b75e571b656be97f65b26adfe Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 23 Dec 2011 19:37:38 +0200 Subject: mtd: introduce mtd_block_markbad interface Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/inftlmount.c | 2 +- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 2 +- drivers/mtd/mtdpart.c | 2 +- drivers/mtd/mtdswap.c | 2 +- drivers/mtd/nand/nandsim.c | 2 +- drivers/mtd/nftlmount.c | 2 +- drivers/mtd/onenand/onenand_base.c | 2 +- drivers/mtd/ubi/io.c | 2 +- fs/jffs2/wbuf.c | 2 +- include/linux/mtd/mtd.h | 9 ++++++--- 12 files changed, 17 insertions(+), 14 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c index 38519401196b..4adc0374fb6b 100644 --- a/drivers/mtd/inftlmount.c +++ b/drivers/mtd/inftlmount.c @@ -424,7 +424,7 @@ int INFTL_formatblock(struct INFTLrecord *inftl, int block) fail: /* could not format, update the bad block table (caller is responsible for setting the PUtable to BLOCK_RESERVED on failure) */ - inftl->mbd.mtd->block_markbad(inftl->mbd.mtd, instr->addr); + mtd_block_markbad(inftl->mbd.mtd, instr->addr); return -1; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index a499bf7a8214..15a3f6224be4 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -899,7 +899,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (!mtd->block_markbad) ret = -EOPNOTSUPP; else - return mtd->block_markbad(mtd, offs); + return mtd_block_markbad(mtd, offs); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index d0db5e61d5af..f694b51e7856 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -693,7 +693,7 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs) continue; } - err = subdev->block_markbad(subdev, ofs); + err = mtd_block_markbad(subdev, ofs); if (!err) mtd->ecc_stats.badblocks++; break; diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index bc43d2f7272c..69532a34e563 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -200,7 +200,7 @@ badblock: } if (mtd->block_markbad && ret == -EIO) { - ret = mtd->block_markbad(mtd, cxt->nextpage * record_size); + ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); if (ret < 0) { printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n"); return; diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c index 0e7dfc79d337..a3d44c3416b4 100644 --- a/drivers/mtd/mtdpart.c +++ b/drivers/mtd/mtdpart.c @@ -335,7 +335,7 @@ static int part_block_markbad(struct mtd_info *mtd, loff_t ofs) if (ofs >= mtd->size) return -EINVAL; ofs += part->offset; - res = part->master->block_markbad(part->master, ofs); + res = mtd_block_markbad(part->master, ofs); if (!res) mtd->ecc_stats.badblocks++; return res; diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 87aa0a6323c3..4441c08b082d 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -279,7 +279,7 @@ static int mtdswap_handle_badblock(struct mtdswap_dev *d, struct swap_eb *eb) offset = mtdswap_eb_offset(d, eb); dev_warn(d->dev, "Marking bad block at %08llx\n", offset); - ret = d->mtd->block_markbad(d->mtd, offset); + ret = mtd_block_markbad(d->mtd, offset); if (ret) { dev_warn(d->dev, "Mark block bad failed for block at %08llx " diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c index 34c03be77301..261f478f8cc3 100644 --- a/drivers/mtd/nand/nandsim.c +++ b/drivers/mtd/nand/nandsim.c @@ -737,7 +737,7 @@ static int parse_badblocks(struct nandsim *ns, struct mtd_info *mtd) return -EINVAL; } offset = erase_block_no * ns->geom.secsz; - if (mtd->block_markbad(mtd, offset)) { + if (mtd_block_markbad(mtd, offset)) { NS_ERR("invalid badblocks.\n"); return -EINVAL; } diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c index 156af9f87961..51b9d6af307f 100644 --- a/drivers/mtd/nftlmount.c +++ b/drivers/mtd/nftlmount.c @@ -356,7 +356,7 @@ int NFTL_formatblock(struct NFTLrecord *nftl, int block) fail: /* could not format, update the bad block table (caller is responsible for setting the ReplUnitTable to BLOCK_RESERVED on failure) */ - nftl->mbd.mtd->block_markbad(nftl->mbd.mtd, instr->addr); + mtd_block_markbad(nftl->mbd.mtd, instr->addr); return -1; } diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c index a8394730b4b6..dd278a284136 100644 --- a/drivers/mtd/onenand/onenand_base.c +++ b/drivers/mtd/onenand/onenand_base.c @@ -2645,7 +2645,7 @@ static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs) } onenand_get_device(mtd, FL_WRITING); - ret = this->block_markbad(mtd, ofs); + ret = mtd_block_markbad(mtd, ofs); onenand_release_device(mtd); return ret; } diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c index a1b683ad639e..5cde4e5ca3e5 100644 --- a/drivers/mtd/ubi/io.c +++ b/drivers/mtd/ubi/io.c @@ -669,7 +669,7 @@ int ubi_io_mark_bad(const struct ubi_device *ubi, int pnum) if (!ubi->bad_allowed) return 0; - err = mtd->block_markbad(mtd, (loff_t)pnum * ubi->peb_size); + err = mtd_block_markbad(mtd, (loff_t)pnum * ubi->peb_size); if (err) ubi_err("cannot mark PEB %d bad, error %d", pnum, err); return err; diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index eae5be483682..fd96b757433f 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -1134,7 +1134,7 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock * return 1; // What else can we do? printk(KERN_WARNING "JFFS2: marking eraseblock at %08x\n as bad", bad_offset); - ret = c->mtd->block_markbad(c->mtd, bad_offset); + ret = mtd_block_markbad(c->mtd, bad_offset); if (ret) { D1(printk(KERN_WARNING "jffs2_write_nand_badblock(): Write failed for block at %08x: error %d\n", jeb->offset, ret)); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index a307ad093a54..64aa54fba2df 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -211,6 +211,7 @@ struct mtd_info { int (*unlock) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*is_locked) (struct mtd_info *mtd, loff_t ofs, uint64_t len); int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); + int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); int (*suspend) (struct mtd_info *mtd); void (*resume) (struct mtd_info *mtd); @@ -219,9 +220,6 @@ struct mtd_info { */ struct backing_dev_info *backing_dev_info; - /* Bad block management functions */ - int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); - struct notifier_block reboot_notifier; /* default mode before reboot */ /* ECC status information */ @@ -411,6 +409,11 @@ static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) return mtd->block_isbad(mtd, ofs); } +static inline int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) +{ + return mtd->block_markbad(mtd, ofs); +} + static inline struct mtd_info *dev_to_mtd(struct device *dev) { return dev ? dev_get_drvdata(dev) : NULL; -- cgit v1.2.3 From 122f81d773a464220d64f1a382bde073df281d5a Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 11:36:19 +0200 Subject: mtd: docprobe: use kzalloc instead Instead of calling 'kmalloc()' and them 'memeset(0)', use 'kzalloc()'. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/docprobe.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/docprobe.c b/drivers/mtd/devices/docprobe.c index 45116bb30297..706b847b46b3 100644 --- a/drivers/mtd/devices/docprobe.c +++ b/drivers/mtd/devices/docprobe.c @@ -241,8 +241,7 @@ static void __init DoC_Probe(unsigned long physadr) return; } docfound = 1; - mtd = kmalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL); - + mtd = kzalloc(sizeof(struct DiskOnChip) + sizeof(struct mtd_info), GFP_KERNEL); if (!mtd) { printk(KERN_WARNING "Cannot allocate memory for data structures. Dropping.\n"); iounmap(docptr); @@ -250,10 +249,6 @@ static void __init DoC_Probe(unsigned long physadr) } this = (struct DiskOnChip *)(&mtd[1]); - - memset((char *)mtd,0, sizeof(struct mtd_info)); - memset((char *)this, 0, sizeof(struct DiskOnChip)); - mtd->priv = this; this->virtadr = docptr; this->physadr = physadr; -- cgit v1.2.3 From bea7fe031e5b81629f264f48335f1af74900f4b9 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 11:40:00 +0200 Subject: mtd: doc: do not initialize mtd_info fields to 0 or NULL The 'struct mtd_info' object is allocated with 'kzalloc()', so it contains only zeroes - no need to initialize various fields to 0 or NULL. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/doc2000.c | 9 --------- drivers/mtd/devices/doc2001.c | 8 -------- drivers/mtd/devices/doc2001plus.c | 9 --------- drivers/mtd/devices/docg3.c | 3 --- 4 files changed, 29 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c index e9fad9151219..b1cdf6479019 100644 --- a/drivers/mtd/devices/doc2000.c +++ b/drivers/mtd/devices/doc2000.c @@ -562,23 +562,14 @@ void DoC2k_init(struct mtd_info *mtd) mtd->type = MTD_NANDFLASH; mtd->flags = MTD_CAP_NANDFLASH; - mtd->size = 0; - mtd->erasesize = 0; mtd->writesize = 512; mtd->oobsize = 16; mtd->owner = THIS_MODULE; mtd->erase = doc_erase; - mtd->point = NULL; - mtd->unpoint = NULL; mtd->read = doc_read; mtd->write = doc_write; mtd->read_oob = doc_read_oob; mtd->write_oob = doc_write_oob; - mtd->sync = NULL; - - this->totlen = 0; - this->numchips = 0; - this->curfloor = -1; this->curchip = -1; mutex_init(&this->lock); diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c index a3f7a27499be..7543b98f46c4 100644 --- a/drivers/mtd/devices/doc2001.c +++ b/drivers/mtd/devices/doc2001.c @@ -343,25 +343,17 @@ void DoCMil_init(struct mtd_info *mtd) mtd->type = MTD_NANDFLASH; mtd->flags = MTD_CAP_NANDFLASH; - mtd->size = 0; /* FIXME: erase size is not always 8KiB */ mtd->erasesize = 0x2000; - mtd->writesize = 512; mtd->oobsize = 16; mtd->owner = THIS_MODULE; mtd->erase = doc_erase; - mtd->point = NULL; - mtd->unpoint = NULL; mtd->read = doc_read; mtd->write = doc_write; mtd->read_oob = doc_read_oob; mtd->write_oob = doc_write_oob; - mtd->sync = NULL; - - this->totlen = 0; - this->numchips = 0; this->curfloor = -1; this->curchip = -1; diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c index 99351bc3e0ed..177510d0e7ee 100644 --- a/drivers/mtd/devices/doc2001plus.c +++ b/drivers/mtd/devices/doc2001plus.c @@ -467,23 +467,14 @@ void DoCMilPlus_init(struct mtd_info *mtd) mtd->type = MTD_NANDFLASH; mtd->flags = MTD_CAP_NANDFLASH; - mtd->size = 0; - - mtd->erasesize = 0; mtd->writesize = 512; mtd->oobsize = 16; mtd->owner = THIS_MODULE; mtd->erase = doc_erase; - mtd->point = NULL; - mtd->unpoint = NULL; mtd->read = doc_read; mtd->write = doc_write; mtd->read_oob = doc_read_oob; mtd->write_oob = doc_write_oob; - mtd->sync = NULL; - - this->totlen = 0; - this->numchips = 0; this->curfloor = -1; this->curchip = -1; diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index 22d5099f7786..ad11ef0a81f4 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -1821,13 +1821,10 @@ static void __init doc_set_driver_info(int chip_id, struct mtd_info *mtd) mtd->oobsize = DOC_LAYOUT_OOB_SIZE; mtd->owner = THIS_MODULE; mtd->erase = doc_erase; - mtd->point = NULL; - mtd->unpoint = NULL; mtd->read = doc_read; mtd->write = doc_write; mtd->read_oob = doc_read_oob; mtd->write_oob = doc_write_oob; - mtd->sync = NULL; mtd->block_isbad = doc_block_isbad; mtd->ecclayout = &docg3_oobinfo; } -- cgit v1.2.3 From 30fa98480b782999248ce8290136aa58f22536cf Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 15:16:28 +0200 Subject: mtd: remove extra retlen assignment MTD functions always assign the 'retlen' argument to 0 at the very beginning - the callers do not have to do this. I used the following semantic patch to find these places: @@ identifier retlen; expression a, b, c, d, e; constant C; type T; @@ ( - retlen = C; | T -retlen = C + retlen ; ) ... when != retlen when exists ( mtd_read(a, b, c, &retlen, d) | mtd_write(a, b, c, &retlen, d) | mtd_panic_write(a, b, c, &retlen, d) | mtd_point(a, b, c, &retlen, d, e) | mtd_read_fact_prot_reg(a, b, c, &retlen, d) | mtd_write_user_prot_reg(a, b, c, &retlen, d) | mtd_read_user_prot_reg(a, b, c, &retlen, d) | mtd_writev(a, b, c, d, &retlen) ) I ran it twice, because there were cases of double zero assigments in mtd tests. Then I went through the patch to verify that spatch did not find any false positives. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/tests/mtd_pagetest.c | 17 +++++------------ drivers/mtd/tests/mtd_readtest.c | 2 +- drivers/mtd/tests/mtd_speedtest.c | 12 ++++++------ drivers/mtd/tests/mtd_stresstest.c | 4 ++-- drivers/mtd/tests/mtd_subpagetest.c | 14 +++++--------- drivers/mtd/tests/mtd_torturetest.c | 4 ++-- 7 files changed, 22 insertions(+), 33 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 15a3f6224be4..83b0c82e9c94 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -189,7 +189,7 @@ static ssize_t mtdchar_read(struct file *file, char __user *buf, size_t count, { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; - size_t retlen=0; + size_t retlen; size_t total_retlen=0; int ret=0; int len; diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c index 8024eaf4c1ac..252ddb092fb2 100644 --- a/drivers/mtd/tests/mtd_pagetest.c +++ b/drivers/mtd/tests/mtd_pagetest.c @@ -95,7 +95,7 @@ static int erase_eraseblock(int ebnum) static int write_eraseblock(int ebnum) { int err = 0; - size_t written = 0; + size_t written; loff_t addr = ebnum * mtd->erasesize; set_random_data(writebuf, mtd->erasesize); @@ -111,7 +111,7 @@ static int write_eraseblock(int ebnum) static int verify_eraseblock(int ebnum) { uint32_t j; - size_t read = 0; + size_t read; int err = 0, i; loff_t addr0, addrn; loff_t addr = ebnum * mtd->erasesize; @@ -144,7 +144,6 @@ static int verify_eraseblock(int ebnum) return err; } memset(twopages, 0, bufsize); - read = 0; err = mtd_read(mtd, addr, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; @@ -180,7 +179,6 @@ static int verify_eraseblock(int ebnum) return err; } memset(twopages, 0, bufsize); - read = 0; err = mtd_read(mtd, addr, bufsize, &read, twopages); if (mtd_is_bitflip(err)) err = 0; @@ -203,7 +201,7 @@ static int verify_eraseblock(int ebnum) static int crosstest(void) { - size_t read = 0; + size_t read; int err = 0, i; loff_t addr, addr0, addrn; unsigned char *pp1, *pp2, *pp3, *pp4; @@ -228,7 +226,6 @@ static int crosstest(void) addrn -= mtd->erasesize; /* Read 2nd-to-last page to pp1 */ - read = 0; addr = addrn - pgsize - pgsize; err = mtd_read(mtd, addr, pgsize, &read, pp1); if (mtd_is_bitflip(err)) @@ -241,7 +238,6 @@ static int crosstest(void) } /* Read 3rd-to-last page to pp1 */ - read = 0; addr = addrn - pgsize - pgsize - pgsize; err = mtd_read(mtd, addr, pgsize, &read, pp1); if (mtd_is_bitflip(err)) @@ -254,7 +250,6 @@ static int crosstest(void) } /* Read first page to pp2 */ - read = 0; addr = addr0; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); err = mtd_read(mtd, addr, pgsize, &read, pp2); @@ -268,7 +263,6 @@ static int crosstest(void) } /* Read last page to pp3 */ - read = 0; addr = addrn - pgsize; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); err = mtd_read(mtd, addr, pgsize, &read, pp3); @@ -282,7 +276,6 @@ static int crosstest(void) } /* Read first page again to pp4 */ - read = 0; addr = addr0; printk(PRINT_PREF "reading page at %#llx\n", (long long)addr); err = mtd_read(mtd, addr, pgsize, &read, pp4); @@ -309,7 +302,7 @@ static int crosstest(void) static int erasecrosstest(void) { - size_t read = 0, written = 0; + size_t read, written; int err = 0, i, ebnum, ebnum2; loff_t addr0; char *readbuf = twopages; @@ -405,7 +398,7 @@ static int erasecrosstest(void) static int erasetest(void) { - size_t read = 0, written = 0; + size_t read, written; int err = 0, i, ebnum, ok = 1; loff_t addr0; diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index ad5fd0df86ee..4228eb4e54c7 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -44,7 +44,7 @@ static int pgcnt; static int read_eraseblock_by_page(int ebnum) { - size_t read = 0; + size_t read; int i, ret, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index ecb287847505..4d2ed5c0807d 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -139,7 +139,7 @@ static int erase_whole_device(void) static int write_eraseblock(int ebnum) { - size_t written = 0; + size_t written; int err = 0; loff_t addr = ebnum * mtd->erasesize; @@ -155,7 +155,7 @@ static int write_eraseblock(int ebnum) static int write_eraseblock_by_page(int ebnum) { - size_t written = 0; + size_t written; int i, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; @@ -178,7 +178,7 @@ static int write_eraseblock_by_page(int ebnum) static int write_eraseblock_by_2pages(int ebnum) { - size_t written = 0, sz = pgsize * 2; + size_t written, sz = pgsize * 2; int i, n = pgcnt / 2, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; @@ -210,7 +210,7 @@ static int write_eraseblock_by_2pages(int ebnum) static int read_eraseblock(int ebnum) { - size_t read = 0; + size_t read; int err = 0; loff_t addr = ebnum * mtd->erasesize; @@ -229,7 +229,7 @@ static int read_eraseblock(int ebnum) static int read_eraseblock_by_page(int ebnum) { - size_t read = 0; + size_t read; int i, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; @@ -255,7 +255,7 @@ static int read_eraseblock_by_page(int ebnum) static int read_eraseblock_by_2pages(int ebnum) { - size_t read = 0, sz = pgsize * 2; + size_t read, sz = pgsize * 2; int i, n = pgcnt / 2, err = 0; loff_t addr = ebnum * mtd->erasesize; void *buf = iobuf; diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 4789c0ee3e9a..399aa2bf220d 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -140,7 +140,7 @@ static int is_block_bad(int ebnum) static int do_read(void) { - size_t read = 0; + size_t read; int eb = rand_eb(); int offs = rand_offs(); int len = rand_len(offs), err; @@ -169,7 +169,7 @@ static int do_read(void) static int do_write(void) { int eb = rand_eb(), offs, err, len; - size_t written = 0; + size_t written; loff_t addr; offs = offsets[eb]; diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c index 4b873d49fe6a..9667bf535282 100644 --- a/drivers/mtd/tests/mtd_subpagetest.c +++ b/drivers/mtd/tests/mtd_subpagetest.c @@ -115,7 +115,7 @@ static int erase_whole_device(void) static int write_eraseblock(int ebnum) { - size_t written = 0; + size_t written; int err = 0; loff_t addr = ebnum * mtd->erasesize; @@ -150,7 +150,7 @@ static int write_eraseblock(int ebnum) static int write_eraseblock2(int ebnum) { - size_t written = 0; + size_t written; int err = 0, k; loff_t addr = ebnum * mtd->erasesize; @@ -189,13 +189,12 @@ static void print_subpage(unsigned char *p) static int verify_eraseblock(int ebnum) { - size_t read = 0; + size_t read; int err = 0; loff_t addr = ebnum * mtd->erasesize; set_random_data(writebuf, subpgsize); clear_data(readbuf, subpgsize); - read = 0; err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { @@ -223,7 +222,6 @@ static int verify_eraseblock(int ebnum) set_random_data(writebuf, subpgsize); clear_data(readbuf, subpgsize); - read = 0; err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { @@ -252,7 +250,7 @@ static int verify_eraseblock(int ebnum) static int verify_eraseblock2(int ebnum) { - size_t read = 0; + size_t read; int err = 0, k; loff_t addr = ebnum * mtd->erasesize; @@ -261,7 +259,6 @@ static int verify_eraseblock2(int ebnum) break; set_random_data(writebuf, subpgsize * k); clear_data(readbuf, subpgsize * k); - read = 0; err = mtd_read(mtd, addr, subpgsize * k, &read, readbuf); if (unlikely(err || read != subpgsize * k)) { if (mtd_is_bitflip(err) && read == subpgsize * k) { @@ -288,14 +285,13 @@ static int verify_eraseblock2(int ebnum) static int verify_eraseblock_ff(int ebnum) { uint32_t j; - size_t read = 0; + size_t read; int err = 0; loff_t addr = ebnum * mtd->erasesize; memset(writebuf, 0xff, subpgsize); for (j = 0; j < mtd->erasesize / subpgsize; ++j) { clear_data(readbuf, subpgsize); - read = 0; err = mtd_read(mtd, addr, subpgsize, &read, readbuf); if (unlikely(err || read != subpgsize)) { if (mtd_is_bitflip(err) && read == subpgsize) { diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 30c4ed9855ec..557105f2ead3 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -127,7 +127,7 @@ static inline int erase_eraseblock(int ebnum) static inline int check_eraseblock(int ebnum, unsigned char *buf) { int err, retries = 0; - size_t read = 0; + size_t read; loff_t addr = ebnum * mtd->erasesize; size_t len = mtd->erasesize; @@ -181,7 +181,7 @@ retry: static inline int write_pattern(int ebnum, void *buf) { int err; - size_t written = 0; + size_t written; loff_t addr = ebnum * mtd->erasesize; size_t len = mtd->erasesize; -- cgit v1.2.3 From d5de20a9a1c5ad68c07e017d11f6dbb5e289750c Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 18:00:29 +0200 Subject: mtd: kill dev_to_mtd helper ... since it is not needed because the generic 'dev_get_drvdata()' can be used instead. Signed-off-by: Artem Bityutskiy Acked-by: Mike Frysinger Signed-off-by: David Woodhouse --- drivers/mtd/mtdcore.c | 25 +++++++++++++------------ include/linux/mtd/mtd.h | 5 ----- 2 files changed, 13 insertions(+), 17 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 376fbfdb09aa..8bea2d0fdb20 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -107,7 +107,8 @@ static LIST_HEAD(mtd_notifiers); */ static void mtd_release(struct device *dev) { - dev_t index = MTD_DEVT(dev_to_mtd(dev)->index); + struct mtd_info *mtd = dev_get_drvdata(dev); + dev_t index = MTD_DEVT(mtd->index); /* remove /dev/mtdXro node if needed */ if (index) @@ -116,7 +117,7 @@ static void mtd_release(struct device *dev) static int mtd_cls_suspend(struct device *dev, pm_message_t state) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); if (mtd && mtd->suspend) return mtd_suspend(mtd); @@ -126,7 +127,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state) static int mtd_cls_resume(struct device *dev) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); if (mtd && mtd->resume) mtd_resume(mtd); @@ -136,7 +137,7 @@ static int mtd_cls_resume(struct device *dev) static ssize_t mtd_type_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); char *type; switch (mtd->type) { @@ -172,7 +173,7 @@ static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL); static ssize_t mtd_flags_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags); @@ -182,7 +183,7 @@ static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL); static ssize_t mtd_size_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%llu\n", (unsigned long long)mtd->size); @@ -193,7 +194,7 @@ static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL); static ssize_t mtd_erasesize_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize); @@ -203,7 +204,7 @@ static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL); static ssize_t mtd_writesize_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize); @@ -213,7 +214,7 @@ static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL); static ssize_t mtd_subpagesize_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); unsigned int subpagesize = mtd->writesize >> mtd->subpage_sft; return snprintf(buf, PAGE_SIZE, "%u\n", subpagesize); @@ -224,7 +225,7 @@ static DEVICE_ATTR(subpagesize, S_IRUGO, mtd_subpagesize_show, NULL); static ssize_t mtd_oobsize_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize); @@ -234,7 +235,7 @@ static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL); static ssize_t mtd_numeraseregions_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions); @@ -245,7 +246,7 @@ static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show, static ssize_t mtd_name_show(struct device *dev, struct device_attribute *attr, char *buf) { - struct mtd_info *mtd = dev_to_mtd(dev); + struct mtd_info *mtd = dev_get_drvdata(dev); return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index a09077aca45b..cb33cc12e18f 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -422,11 +422,6 @@ static inline int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) return mtd->block_markbad(mtd, ofs); } -static inline struct mtd_info *dev_to_mtd(struct device *dev) -{ - return dev ? dev_get_drvdata(dev) : NULL; -} - static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd) { if (mtd->erasesize_shift) -- cgit v1.2.3 From ee16f2af2d464ee4c040e571c225dcbb1ce4a7d3 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 18:04:31 +0200 Subject: mtd: onenand: kill unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix this gcc warning: drivers/mtd/onenand/onenand_base.c: In function ‘onenand_block_markbad’: drivers/mtd/onenand/onenand_base.c:2636:23: warning: unused variable ‘this’ [-Wunused-variable] Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/onenand/onenand_base.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c index dd278a284136..a061bc163da2 100644 --- a/drivers/mtd/onenand/onenand_base.c +++ b/drivers/mtd/onenand/onenand_base.c @@ -2633,7 +2633,6 @@ static int onenand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) */ static int onenand_block_markbad(struct mtd_info *mtd, loff_t ofs) { - struct onenand_chip *this = mtd->priv; int ret; ret = onenand_block_isbad(mtd, ofs); -- cgit v1.2.3 From d81a32f2c16a3c42cf26f2216765c520630daa4e Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 18:06:01 +0200 Subject: mtd: sst25l: kill unused variable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix the following gcc warning: drivers/mtd/devices/sst25l.c: In function ‘sst25l_probe’: drivers/mtd/devices/sst25l.c:381:11: warning: unused variable ‘i’ [-Wunused-variable] Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/sst25l.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c index e45f62e8f195..5fc198350b94 100644 --- a/drivers/mtd/devices/sst25l.c +++ b/drivers/mtd/devices/sst25l.c @@ -378,7 +378,7 @@ static int __devinit sst25l_probe(struct spi_device *spi) struct flash_info *flash_info; struct sst25l_flash *flash; struct flash_platform_data *data; - int ret, i; + int ret; flash_info = sst25l_match_device(spi); if (!flash_info) -- cgit v1.2.3 From 52b020317f65114eeba2ee2cfa70a51a286f1d8a Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 15:57:25 +0200 Subject: mtd: clean-up the default_mtd_writev function 1. Teach 'mtd_write()' function to return '-EROFS' if the write method is undefined, and remove the corresponding check from 'default_mtd_writev()'. 2. Do not test 'retlen' for NULL - it cannot be NULL. 3. Few minor coding stile clean-ups. 4. Add a kerneldoc comment Additionally, minor fixes to the kerneldoc comments of the neighbor function. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdcore.c | 41 ++++++++++++++++++++++------------------- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 24 insertions(+), 19 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 8bea2d0fdb20..85a3f197e7f0 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -683,10 +683,17 @@ void __put_mtd_device(struct mtd_info *mtd) module_put(mtd->owner); } -/* default_mtd_writev - default mtd writev method for MTD devices that - * don't implement their own +/* + * default_mtd_writev - the default writev method + * @mtd: mtd device description object pointer + * @vecs: the vectors to write + * @count: count of vectors in @vecs + * @to: the MTD device offset to write to + * @retlen: on exit contains the count of bytes written to the MTD device. + * + * This function returns zero in case of success and a negative error code in + * case of failure. */ - int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen) { @@ -694,28 +701,24 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, size_t totlen = 0, thislen; int ret = 0; - if(!mtd->write) { - ret = -EROFS; - } else { - for (i=0; iwrite) + return -EROFS; return mtd->write(mtd, to, len, retlen, buf); } -- cgit v1.2.3 From 33c87b4a2c820316314542ce3f60b8a8c6a96928 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 16:11:14 +0200 Subject: mtd: mtdcore: export symbols cleanup The mtdcore.c file is a bit inconsistent - some EXPORT_SYMBOL_GPL declarations follow the corresponding functions, some are placed at the end. This patch harmonizes the file so that EXPORT_SYMBOL_GPL declarations follow the corresponding function. It also removes few extra newlines and trailing white-spaces. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdcore.c | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 85a3f197e7f0..53a200f722b6 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -128,7 +128,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state) static int mtd_cls_resume(struct device *dev) { struct mtd_info *mtd = dev_get_drvdata(dev); - + if (mtd && mtd->resume) mtd_resume(mtd); return 0; @@ -517,7 +517,6 @@ EXPORT_SYMBOL_GPL(mtd_device_unregister); * or removal of MTD devices. Causes the 'add' callback to be immediately * invoked for each MTD device currently present in the system. */ - void register_mtd_user (struct mtd_notifier *new) { struct mtd_info *mtd; @@ -533,6 +532,7 @@ void register_mtd_user (struct mtd_notifier *new) mutex_unlock(&mtd_table_mutex); } +EXPORT_SYMBOL_GPL(register_mtd_user); /** * unregister_mtd_user - unregister a 'user' of MTD devices. @@ -543,7 +543,6 @@ void register_mtd_user (struct mtd_notifier *new) * 'remove' callback to be immediately invoked for each MTD device * currently present in the system. */ - int unregister_mtd_user (struct mtd_notifier *old) { struct mtd_info *mtd; @@ -559,7 +558,7 @@ int unregister_mtd_user (struct mtd_notifier *old) mutex_unlock(&mtd_table_mutex); return 0; } - +EXPORT_SYMBOL_GPL(unregister_mtd_user); /** * get_mtd_device - obtain a validated handle for an MTD device @@ -572,7 +571,6 @@ int unregister_mtd_user (struct mtd_notifier *old) * both, return the num'th driver only if its address matches. Return * error code if not. */ - struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num) { struct mtd_info *ret = NULL, *other; @@ -605,6 +603,7 @@ out: mutex_unlock(&mtd_table_mutex); return ret; } +EXPORT_SYMBOL_GPL(get_mtd_device); int __get_mtd_device(struct mtd_info *mtd) @@ -625,6 +624,7 @@ int __get_mtd_device(struct mtd_info *mtd) mtd->usecount++; return 0; } +EXPORT_SYMBOL_GPL(__get_mtd_device); /** * get_mtd_device_nm - obtain a validated handle for an MTD device by @@ -634,7 +634,6 @@ int __get_mtd_device(struct mtd_info *mtd) * This function returns MTD device description structure in case of * success and an error code in case of failure. */ - struct mtd_info *get_mtd_device_nm(const char *name) { int err = -ENODEV; @@ -663,6 +662,7 @@ out_unlock: mutex_unlock(&mtd_table_mutex); return ERR_PTR(err); } +EXPORT_SYMBOL_GPL(get_mtd_device_nm); void put_mtd_device(struct mtd_info *mtd) { @@ -671,6 +671,7 @@ void put_mtd_device(struct mtd_info *mtd) mutex_unlock(&mtd_table_mutex); } +EXPORT_SYMBOL_GPL(put_mtd_device); void __put_mtd_device(struct mtd_info *mtd) { @@ -682,6 +683,7 @@ void __put_mtd_device(struct mtd_info *mtd) module_put(mtd->owner); } +EXPORT_SYMBOL_GPL(__put_mtd_device); /* * default_mtd_writev - the default writev method @@ -714,6 +716,7 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, *retlen = totlen; return ret; } +EXPORT_SYMBOL_GPL(default_mtd_writev); /** * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size @@ -763,15 +766,6 @@ void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size) */ return kmalloc(*size, GFP_KERNEL); } - -EXPORT_SYMBOL_GPL(get_mtd_device); -EXPORT_SYMBOL_GPL(get_mtd_device_nm); -EXPORT_SYMBOL_GPL(__get_mtd_device); -EXPORT_SYMBOL_GPL(put_mtd_device); -EXPORT_SYMBOL_GPL(__put_mtd_device); -EXPORT_SYMBOL_GPL(register_mtd_user); -EXPORT_SYMBOL_GPL(unregister_mtd_user); -EXPORT_SYMBOL_GPL(default_mtd_writev); EXPORT_SYMBOL_GPL(mtd_kmalloc_up_to); #ifdef CONFIG_PROC_FS -- cgit v1.2.3 From fc002e3c320602d0e206f607aca0460540d7637a Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 28 Dec 2011 18:35:07 +0200 Subject: mtd: introduce mtd_has_oob helper We are working in the direction of making sure that MTD clients to not use 'mtd->func' pointers directly. In some places we want to know if OOB operations are supported by an MTD device. Introduce 'mtd_has_oob()' helper for these purposes. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/sm_ftl.c | 4 ++-- include/linux/mtd/mtd.h | 5 +++++ 3 files changed, 8 insertions(+), 3 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 83b0c82e9c94..c501eec17b38 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -1004,7 +1004,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) break; case MTD_FILE_MODE_RAW: - if (!mtd->read_oob || !mtd->write_oob) + if (!mtd_has_oob(mtd)) return -EOPNOTSUPP; mfi->mode = arg; diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c index 4ec2af7fb845..072ed5970e2f 100644 --- a/drivers/mtd/sm_ftl.c +++ b/drivers/mtd/sm_ftl.c @@ -645,8 +645,8 @@ int sm_get_media_info(struct sm_ftl *ftl, struct mtd_info *mtd) if (!ftl->smallpagenand && mtd->oobsize < SM_OOB_SIZE) return -ENODEV; - /* We use these functions for IO */ - if (!mtd->read_oob || !mtd->write_oob) + /* We use OOB */ + if (!mtd_has_oob(mtd)) return -ENODEV; /* Find geometry information */ diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index f0dd5a305b89..478701566ba7 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -454,6 +454,11 @@ static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd) return do_div(sz, mtd->writesize); } +static inline int mtd_has_oob(const struct mtd_info *mtd) +{ + return mtd->read_oob && mtd->write_oob; +} + /* Kernel-side ioctl definitions */ struct mtd_partition; -- cgit v1.2.3 From cd621274b0ec747db8dedbf857624c067f481976 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 14:31:57 +0200 Subject: mtd: do not use mtd->get_unmapped_area directly Remove direct usage of mtd->get_unmapped_area. Instead, just call 'mtd_get_unmapped_area()' which will return -EOPNOTSUPP if the function is not implemented and test for this error code. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 26 +++++++++++--------------- drivers/mtd/mtdconcat.c | 6 +----- include/linux/mtd/mtd.h | 2 ++ 3 files changed, 14 insertions(+), 20 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index c501eec17b38..55f0961103a7 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -1124,25 +1124,21 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file, { struct mtd_file_info *mfi = file->private_data; struct mtd_info *mtd = mfi->mtd; + unsigned long offset; + int ret; - if (mtd->get_unmapped_area) { - unsigned long offset; - - if (addr != 0) - return (unsigned long) -EINVAL; - - if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) - return (unsigned long) -EINVAL; + if (addr != 0) + return (unsigned long) -EINVAL; - offset = pgoff << PAGE_SHIFT; - if (offset > mtd->size - len) - return (unsigned long) -EINVAL; + if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT)) + return (unsigned long) -EINVAL; - return mtd_get_unmapped_area(mtd, len, offset, flags); - } + offset = pgoff << PAGE_SHIFT; + if (offset > mtd->size - len) + return (unsigned long) -EINVAL; - /* can't map directly */ - return (unsigned long) -ENOSYS; + ret = mtd_get_unmapped_area(mtd, len, offset, flags); + return ret == -EOPNOTSUPP ? -ENOSYS : ret; } #endif diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index f694b51e7856..9119f76f87ff 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -726,11 +726,7 @@ static unsigned long concat_get_unmapped_area(struct mtd_info *mtd, if (offset + len > subdev->size) return (unsigned long) -EINVAL; - if (subdev->get_unmapped_area) - return mtd_get_unmapped_area(subdev, len, offset, - flags); - - break; + return mtd_get_unmapped_area(subdev, len, offset, flags); } return (unsigned long) -ENOSYS; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index b355a83e7cc2..2c2a92247e5a 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -280,6 +280,8 @@ static inline unsigned long mtd_get_unmapped_area(struct mtd_info *mtd, unsigned long offset, unsigned long flags) { + if (!mtd->get_unmapped_area) + return -EOPNOTSUPP; return mtd->get_unmapped_area(mtd, len, offset, flags); } -- cgit v1.2.3 From 016c1291ce70a22f15f666441a4fd2f0b450375b Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 28 Dec 2011 17:27:18 +0200 Subject: mtd: mtdoops: do not use mtd->panic_write directly Instead of checking if 'mtd->panic_write' is defined, call 'mtd_panic_write()' and check the error code - '-EOPNOTSUPP' will be returned if the function is not defined. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdoops.c | 17 ++++++++--------- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 10 insertions(+), 9 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index 69532a34e563..c8540b8a7fc6 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -221,10 +221,14 @@ static void mtdoops_write(struct mtdoops_context *cxt, int panic) hdr[0] = cxt->nextcount; hdr[1] = MTDOOPS_KERNMSG_MAGIC; - if (panic) + if (panic) { ret = mtd_panic_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); - else + if (ret == -EOPNOTSUPP) { + printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); + return; + } + } else ret = mtd_write(mtd, cxt->nextpage * record_size, record_size, &retlen, cxt->oops_buf); @@ -330,13 +334,8 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper, memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy); /* Panics must be written immediately */ - if (reason != KMSG_DUMP_OOPS) { - if (!cxt->mtd->panic_write) - printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); - else - mtdoops_write(cxt, 1); - return; - } + if (reason != KMSG_DUMP_OOPS) + mtdoops_write(cxt, 1); /* For other cases, schedule work to write it "nicely" */ schedule_work(&cxt->work_write); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 2c2a92247e5a..b72964049cdc 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -311,6 +311,8 @@ static inline int mtd_panic_write(struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf) { *retlen = 0; + if (!mtd->panic_write) + return -EOPNOTSUPP; return mtd->panic_write(mtd, to, len, retlen, buf); } -- cgit v1.2.3 From dac2639f9833e858139d7e07f6ee45fb2191a9f2 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 28 Dec 2011 17:50:34 +0200 Subject: mtd: do not use mtd->read_oob directly Instead of checking whether 'mtd->read_oob' is defined, just call 'mtd_read_oob()' and handle the '-EOPNOTSUPP' error which will be returned if the function is undefined. Additionally, make 'mtd_write_oob()' return '-EOPNOTSUPP' if the function is undefined. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 9 ++------- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 55f0961103a7..287ff0d35848 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -452,13 +452,8 @@ static int mtdchar_readoob(struct file *file, struct mtd_info *mtd, if (length > 4096) return -EINVAL; - if (!mtd->read_oob) - ret = -EOPNOTSUPP; - else - ret = access_ok(VERIFY_WRITE, ptr, - length) ? 0 : -EFAULT; - if (ret) - return ret; + if (!access_ok(VERIFY_WRITE, ptr, length)) + return -EFAULT; ops.ooblen = length; ops.ooboffs = start & (mtd->writesize - 1); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index b72964049cdc..721a63ffeb96 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -320,6 +320,8 @@ static inline int mtd_read_oob(struct mtd_info *mtd, loff_t from, struct mtd_oob_ops *ops) { ops->retlen = ops->oobretlen = 0; + if (!mtd->read_oob) + return -EOPNOTSUPP; return mtd->read_oob(mtd, from, ops); } @@ -327,6 +329,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops) { ops->retlen = ops->oobretlen = 0; + if (!mtd->write_oob) + return -EOPNOTSUPP; return mtd->write_oob(mtd, to, ops); } -- cgit v1.2.3 From 87e858a97e8a7010aedc01db7cd31cc7c02b0b6a Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Wed, 28 Dec 2011 18:47:46 +0200 Subject: mtd: do not use mtd->get_*_prot_info directly Instead, call 'mtd_get_*_prot_info()' and check for '-EOPNOTSUPP'. While on it, fix the return code from '-EOPNOTSUPP' to '-EINVAL' for the case when the mode parameter is invalid. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 8 +++----- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 7 insertions(+), 5 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 287ff0d35848..49340dc1b107 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -919,17 +919,15 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) struct otp_info *buf = kmalloc(4096, GFP_KERNEL); if (!buf) return -ENOMEM; - ret = -EOPNOTSUPP; switch (mfi->mode) { case MTD_FILE_MODE_OTP_FACTORY: - if (mtd->get_fact_prot_info) - ret = mtd_get_fact_prot_info(mtd, buf, 4096); + ret = mtd_get_fact_prot_info(mtd, buf, 4096); break; case MTD_FILE_MODE_OTP_USER: - if (mtd->get_user_prot_info) - ret = mtd_get_user_prot_info(mtd, buf, 4096); + ret = mtd_get_user_prot_info(mtd, buf, 4096); break; default: + ret = -EINVAL; break; } if (ret >= 0) { diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 721a63ffeb96..7122efdc6d99 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -342,6 +342,8 @@ static inline int mtd_write_oob(struct mtd_info *mtd, loff_t to, static inline int mtd_get_fact_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { + if (!mtd->get_fact_prot_info) + return -EOPNOTSUPP; return mtd->get_fact_prot_info(mtd, buf, len); } @@ -357,6 +359,8 @@ static inline int mtd_get_user_prot_info(struct mtd_info *mtd, struct otp_info *buf, size_t len) { + if (!mtd->get_user_prot_info) + return -EOPNOTSUPP; return mtd->get_user_prot_info(mtd, buf, len); } -- cgit v1.2.3 From b6de3d6cb63427178c4f1df88b81d1ceee637e6f Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 10:06:32 +0200 Subject: mtd: do not use mtd->read_*_prot_reg directly Instead, call 'mtd_read_*_prot_info()' and check for -EOPNOTSUPP. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 18 ++++++++++-------- include/linux/mtd/mtd.h | 4 ++++ 2 files changed, 14 insertions(+), 8 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 49340dc1b107..4e8e5fbc1e13 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -366,20 +366,22 @@ static void mtdchar_erase_callback (struct erase_info *instr) static int otp_select_filemode(struct mtd_file_info *mfi, int mode) { struct mtd_info *mtd = mfi->mtd; + size_t retlen; int ret = 0; + /* + * Make a fake call to mtd_read_fact_prot_reg() to check if OTP + * operations are supported. + */ + if (mtd_read_fact_prot_reg(mtd, -1, -1, &retlen, NULL) == -EOPNOTSUPP) + return -EOPNOTSUPP; + switch (mode) { case MTD_OTP_FACTORY: - if (!mtd->read_fact_prot_reg) - ret = -EOPNOTSUPP; - else - mfi->mode = MTD_FILE_MODE_OTP_FACTORY; + mfi->mode = MTD_FILE_MODE_OTP_FACTORY; break; case MTD_OTP_USER: - if (!mtd->read_fact_prot_reg) - ret = -EOPNOTSUPP; - else - mfi->mode = MTD_FILE_MODE_OTP_USER; + mfi->mode = MTD_FILE_MODE_OTP_USER; break; default: ret = -EINVAL; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 7122efdc6d99..e488cf910914 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -352,6 +352,8 @@ static inline int mtd_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, u_char *buf) { *retlen = 0; + if (!mtd->read_fact_prot_reg) + return -EOPNOTSUPP; return mtd->read_fact_prot_reg(mtd, from, len, retlen, buf); } @@ -369,6 +371,8 @@ static inline int mtd_read_user_prot_reg(struct mtd_info *mtd, loff_t from, u_char *buf) { *retlen = 0; + if (!mtd->read_user_prot_reg) + return -EOPNOTSUPP; return mtd->read_user_prot_reg(mtd, from, len, retlen, buf); } -- cgit v1.2.3 From 27c151a5e52efaa46d0938984f2ef591bdcb6d5b Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 10:39:20 +0200 Subject: mtd: mtd->write_user_prot_reg directly Instead, just call 'mtd_write_user_prot_reg()' and check the '-EOPNOTSUPP' return code. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 4 ---- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 2 insertions(+), 4 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 4e8e5fbc1e13..25bbbc3aa665 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -310,10 +310,6 @@ static ssize_t mtdchar_write(struct file *file, const char __user *buf, size_t c ret = -EROFS; break; case MTD_FILE_MODE_OTP_USER: - if (!mtd->write_user_prot_reg) { - ret = -EOPNOTSUPP; - break; - } ret = mtd_write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); break; diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index e488cf910914..7cd56d2b9419 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -381,6 +381,8 @@ static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, u_char *buf) { *retlen = 0; + if (!mtd->write_user_prot_reg) + return -EOPNOTSUPP; return mtd->write_user_prot_reg(mtd, to, len, retlen, buf); } -- cgit v1.2.3 From e2936b2af5562c8c66060e2bc2ae2e209d0acd3d Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Thu, 29 Dec 2011 10:45:04 +0200 Subject: mtd: do not use mtd->lock_user_prot_reg directly Instead, check the -EOPNOTSUPP return code of 'mtd_lock_user_prot_reg()'. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 2 -- include/linux/mtd/mtd.h | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 25bbbc3aa665..2020a169ed9c 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -949,8 +949,6 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) return -EINVAL; if (copy_from_user(&oinfo, argp, sizeof(oinfo))) return -EFAULT; - if (!mtd->lock_user_prot_reg) - return -EOPNOTSUPP; ret = mtd_lock_user_prot_reg(mtd, oinfo.start, oinfo.length); break; } diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 7cd56d2b9419..a994129ede55 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -389,6 +389,8 @@ static inline int mtd_write_user_prot_reg(struct mtd_info *mtd, loff_t to, static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, size_t len) { + if (!mtd->lock_user_prot_reg) + return -EOPNOTSUPP; return mtd->lock_user_prot_reg(mtd, from, len); } -- cgit v1.2.3 From 1dbebd32562b3c2caeca35960e5cb00bfcc12900 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 16:23:41 +0200 Subject: mtd: harmonize mtd_writev usage This patch makes the 'mtd_writev()' function more usable and logical. We first teach it to fall-back to the 'default_mtd_writev()' function if the MTD driver does not define its own '->writev()' method. Then we make block2mtd and JFFS2 just 'mtd_writev()' instead of 'default_mtd_writev()' function. This means we can now stop exporting 'default_mtd_writev()' and instead, export 'mtd_writev()'. This is much cleaner and more logical, as well as allows us to get read of another direct 'mtd->writev' access in JFFS2. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/block2mtd.c | 2 +- drivers/mtd/mtdcore.c | 26 +++++++++++++++++++++++--- fs/jffs2/writev.c | 6 +----- include/linux/mtd/mtd.h | 16 ++-------------- 4 files changed, 27 insertions(+), 23 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index b78f23169d4e..c16f6b4e8938 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -288,7 +288,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) dev->mtd.flags = MTD_CAP_RAM; dev->mtd.erase = block2mtd_erase; dev->mtd.write = block2mtd_write; - dev->mtd.writev = default_mtd_writev; + dev->mtd.writev = mtd_writev; dev->mtd.sync = block2mtd_sync; dev->mtd.read = block2mtd_read; dev->mtd.priv = dev; diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 53a200f722b6..4d0f3e557bd1 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -696,8 +696,8 @@ EXPORT_SYMBOL_GPL(__put_mtd_device); * This function returns zero in case of success and a negative error code in * case of failure. */ -int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, - unsigned long count, loff_t to, size_t *retlen) +static int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, + unsigned long count, loff_t to, size_t *retlen) { unsigned long i; size_t totlen = 0, thislen; @@ -716,7 +716,27 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, *retlen = totlen; return ret; } -EXPORT_SYMBOL_GPL(default_mtd_writev); + +/* + * mtd_writev - the vector-based MTD write method + * @mtd: mtd device description object pointer + * @vecs: the vectors to write + * @count: count of vectors in @vecs + * @to: the MTD device offset to write to + * @retlen: on exit contains the count of bytes written to the MTD device. + * + * This function returns zero in case of success and a negative error code in + * case of failure. + */ +int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, + unsigned long count, loff_t to, size_t *retlen) +{ + *retlen = 0; + if (!mtd->writev) + return default_mtd_writev(mtd, vecs, count, to, retlen); + return mtd->writev(mtd, vecs, count, to, retlen); +} +EXPORT_SYMBOL_GPL(mtd_writev); /** * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size diff --git a/fs/jffs2/writev.c b/fs/jffs2/writev.c index 8d704073f8b0..a1bda9dab3f8 100644 --- a/fs/jffs2/writev.c +++ b/fs/jffs2/writev.c @@ -26,11 +26,7 @@ int jffs2_flash_direct_writev(struct jffs2_sb_info *c, const struct kvec *vecs, } } - if (c->mtd->writev) - return mtd_writev(c->mtd, vecs, count, to, retlen); - else { - return default_mtd_writev(c->mtd, vecs, count, to, retlen); - } + return mtd_writev(c->mtd, vecs, count, to, retlen); } int jffs2_flash_direct_write(struct jffs2_sb_info *c, loff_t ofs, size_t len, diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index a994129ede55..a58ecf4d1f80 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -394,16 +394,8 @@ static inline int mtd_lock_user_prot_reg(struct mtd_info *mtd, loff_t from, return mtd->lock_user_prot_reg(mtd, from, len); } -/* - * kvec-based read/write method. NB: The 'count' parameter is the number of - * _vectors_, each of which contains an (ofs, len) tuple. - */ -static inline int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, - unsigned long count, loff_t to, size_t *retlen) -{ - *retlen = 0; - return mtd->writev(mtd, vecs, count, to, retlen); -} +int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, + unsigned long count, loff_t to, size_t *retlen); static inline void mtd_sync(struct mtd_info *mtd) { @@ -510,10 +502,6 @@ struct mtd_notifier { extern void register_mtd_user (struct mtd_notifier *new); extern int unregister_mtd_user (struct mtd_notifier *old); - -int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, - unsigned long count, loff_t to, size_t *retlen); - void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size); void mtd_erase_callback(struct erase_info *instr); -- cgit v1.2.3 From 327cf2922b4edf0439b219469722d2a502e37349 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 16:35:35 +0200 Subject: mtd: do not use mtd->sync directly This patch teaches 'mtd_sync()' to do nothing when the MTD driver does not have the '->sync()' method, which allows us to remove all direct 'mtd->sync' accesses. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/ftl.c | 3 +-- drivers/mtd/mtdblock.c | 7 ++----- drivers/mtd/mtdchar.c | 2 +- drivers/mtd/mtdswap.c | 3 +-- drivers/mtd/rfd_ftl.c | 3 +-- drivers/mtd/ubi/kapi.c | 4 +--- fs/jffs2/super.c | 4 +--- fs/logfs/dev_mtd.c | 3 +-- include/linux/mtd/mtd.h | 3 ++- 9 files changed, 11 insertions(+), 21 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/ftl.c b/drivers/mtd/ftl.c index c9c90299c9e2..19d637266fcd 100644 --- a/drivers/mtd/ftl.c +++ b/drivers/mtd/ftl.c @@ -650,8 +650,7 @@ static int reclaim_block(partition_t *part) if (queued) { pr_debug("ftl_cs: waiting for transfer " "unit to be prepared...\n"); - if (part->mbd.mtd->sync) - mtd_sync(part->mbd.mtd); + mtd_sync(part->mbd.mtd); } else { static int ne = 0; if (++ne < 5) diff --git a/drivers/mtd/mtdblock.c b/drivers/mtd/mtdblock.c index 496e1a6e8029..af6591237b9b 100644 --- a/drivers/mtd/mtdblock.c +++ b/drivers/mtd/mtdblock.c @@ -322,8 +322,7 @@ static int mtdblock_release(struct mtd_blktrans_dev *mbd) if (!--mtdblk->count) { /* It was the last usage. Free the cache */ - if (mbd->mtd->sync) - mtd_sync(mbd->mtd); + mtd_sync(mbd->mtd); vfree(mtdblk->cache_data); } @@ -341,9 +340,7 @@ static int mtdblock_flush(struct mtd_blktrans_dev *dev) mutex_lock(&mtdblk->cache_mutex); write_cached_data(mtdblk); mutex_unlock(&mtdblk->cache_mutex); - - if (dev->mtd->sync) - mtd_sync(dev->mtd); + mtd_sync(dev->mtd); return 0; } diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 2020a169ed9c..23a51104aeb5 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -154,7 +154,7 @@ static int mtdchar_close(struct inode *inode, struct file *file) pr_debug("MTD_close\n"); /* Only sync if opened RW */ - if ((file->f_mode & FMODE_WRITE) && mtd->sync) + if ((file->f_mode & FMODE_WRITE)) mtd_sync(mtd); iput(mfi->ino); diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 4441c08b082d..fe4426c1c736 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -1047,8 +1047,7 @@ static int mtdswap_flush(struct mtd_blktrans_dev *dev) { struct mtdswap_dev *d = MTDSWAP_MBD_TO_MTDSWAP(dev); - if (d->mtd->sync) - mtd_sync(d->mtd); + mtd_sync(d->mtd); return 0; } diff --git a/drivers/mtd/rfd_ftl.c b/drivers/mtd/rfd_ftl.c index 5426d42cdea7..233b946e5d66 100644 --- a/drivers/mtd/rfd_ftl.c +++ b/drivers/mtd/rfd_ftl.c @@ -448,8 +448,7 @@ static int reclaim_block(struct partition *part, u_long *old_sector) int rc; /* we have a race if sync doesn't exist */ - if (part->mbd.mtd->sync) - mtd_sync(part->mbd.mtd); + mtd_sync(part->mbd.mtd); score = 0x7fffffff; /* MAX_INT */ best_block = -1; diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c index 9f265cc1a0d3..9fdb35367fe0 100644 --- a/drivers/mtd/ubi/kapi.c +++ b/drivers/mtd/ubi/kapi.c @@ -714,9 +714,7 @@ int ubi_sync(int ubi_num) if (!ubi) return -ENODEV; - if (ubi->mtd->sync) - mtd_sync(ubi->mtd); - + mtd_sync(ubi->mtd); ubi_put_device(ubi); return 0; } diff --git a/fs/jffs2/super.c b/fs/jffs2/super.c index e78bf3cd1b73..5863a369d929 100644 --- a/fs/jffs2/super.c +++ b/fs/jffs2/super.c @@ -336,9 +336,7 @@ static void jffs2_put_super (struct super_block *sb) jffs2_flash_cleanup(c); kfree(c->inocache_list); jffs2_clear_xattr_subsystem(c); - if (c->mtd->sync) - mtd_sync(c->mtd); - + mtd_sync(c->mtd); D1(printk(KERN_DEBUG "jffs2_put_super returning\n")); } diff --git a/fs/logfs/dev_mtd.c b/fs/logfs/dev_mtd.c index 136c7360a9b6..3f465882ee70 100644 --- a/fs/logfs/dev_mtd.c +++ b/fs/logfs/dev_mtd.c @@ -119,8 +119,7 @@ static void logfs_mtd_sync(struct super_block *sb) { struct mtd_info *mtd = logfs_super(sb)->s_mtd; - if (mtd->sync) - mtd_sync(mtd); + mtd_sync(mtd); } static int logfs_mtd_readpage(void *_sb, struct page *page) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index a58ecf4d1f80..305f12b940f4 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -399,7 +399,8 @@ int mtd_writev(struct mtd_info *mtd, const struct kvec *vecs, static inline void mtd_sync(struct mtd_info *mtd) { - mtd->sync(mtd); + if (mtd->sync) + mtd->sync(mtd); } /* Chip-supported device locking */ -- cgit v1.2.3 From 381345652fca688aeaa967c231e5075cf68d05b6 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 17:00:35 +0200 Subject: mtd: do not use mtd->lock, unlock and is_locked directly Instead, call the corresponding MTD API function which will return '-EOPNOTSUPP' if the operation is not supported. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/scb2_flash.c | 3 +-- drivers/mtd/mtdchar.c | 15 +++------------ drivers/mtd/mtdconcat.c | 18 ++++++------------ drivers/mtd/mtdcore.c | 6 +++--- include/linux/mtd/mtd.h | 6 ++++++ 5 files changed, 19 insertions(+), 29 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c index 01af34778de3..934a72c80078 100644 --- a/drivers/mtd/maps/scb2_flash.c +++ b/drivers/mtd/maps/scb2_flash.c @@ -204,8 +204,7 @@ scb2_flash_remove(struct pci_dev *dev) return; /* disable flash writes */ - if (scb2_mtd->lock) - mtd_lock(scb2_mtd, 0, scb2_mtd->size); + mtd_lock(scb2_mtd, 0, scb2_mtd->size); mtd_device_unregister(scb2_mtd); map_destroy(scb2_mtd); diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 23a51104aeb5..92da621b1425 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -814,10 +814,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&einfo, argp, sizeof(einfo))) return -EFAULT; - if (!mtd->lock) - ret = -EOPNOTSUPP; - else - ret = mtd_lock(mtd, einfo.start, einfo.length); + ret = mtd_lock(mtd, einfo.start, einfo.length); break; } @@ -828,10 +825,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&einfo, argp, sizeof(einfo))) return -EFAULT; - if (!mtd->unlock) - ret = -EOPNOTSUPP; - else - ret = mtd_unlock(mtd, einfo.start, einfo.length); + ret = mtd_unlock(mtd, einfo.start, einfo.length); break; } @@ -842,10 +836,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&einfo, argp, sizeof(einfo))) return -EFAULT; - if (!mtd->is_locked) - ret = -EOPNOTSUPP; - else - ret = mtd_is_locked(mtd, einfo.start, einfo.length); + ret = mtd_is_locked(mtd, einfo.start, einfo.length); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index 9119f76f87ff..aaafb5e18765 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -555,12 +555,9 @@ static int concat_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) else size = len; - if (subdev->lock) { - err = mtd_lock(subdev, ofs, size); - if (err) - break; - } else - err = -EOPNOTSUPP; + err = mtd_lock(subdev, ofs, size); + if (err) + break; len -= size; if (len == 0) @@ -595,12 +592,9 @@ static int concat_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) else size = len; - if (subdev->unlock) { - err = mtd_unlock(subdev, ofs, size); - if (err) - break; - } else - err = -EOPNOTSUPP; + err = mtd_unlock(subdev, ofs, size); + if (err) + break; len -= size; if (len == 0) diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 4d0f3e557bd1..66494ee5355a 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -339,9 +339,9 @@ int add_mtd_device(struct mtd_info *mtd) mtd->writesize_mask = (1 << mtd->writesize_shift) - 1; /* Some chips always power up locked. Unlock them now */ - if ((mtd->flags & MTD_WRITEABLE) - && (mtd->flags & MTD_POWERUP_LOCK) && mtd->unlock) { - if (mtd_unlock(mtd, 0, mtd->size)) + if ((mtd->flags & MTD_WRITEABLE) && (mtd->flags & MTD_POWERUP_LOCK)) { + error = mtd_unlock(mtd, 0, mtd->size); + if (error && error != -EOPNOTSUPP) printk(KERN_WARNING "%s: unlock failed, writes may not work\n", mtd->name); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 305f12b940f4..6c91ba59c229 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -406,16 +406,22 @@ static inline void mtd_sync(struct mtd_info *mtd) /* Chip-supported device locking */ static inline int mtd_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + if (!mtd->lock) + return -EOPNOTSUPP; return mtd->lock(mtd, ofs, len); } static inline int mtd_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + if (!mtd->unlock) + return -EOPNOTSUPP; return mtd->unlock(mtd, ofs, len); } static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) { + if (!mtd->is_locked) + return -EOPNOTSUPP; return mtd->is_locked(mtd, ofs, len); } -- cgit v1.2.3 From 079c985e7a6f4ce60f931cebfdd5ee3c38347e31 Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Fri, 30 Dec 2011 17:15:59 +0200 Subject: mtd: do not use mtd->suspend and mtd->resume directly Just call the 'mtd_suspend()' and 'mtd_resume()' - they will do nothing if the operation is not defined. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/maps/physmap.c | 5 ++--- drivers/mtd/maps/rbtx4939-flash.c | 5 ++--- drivers/mtd/mtdcore.c | 5 +---- include/linux/mtd/mtd.h | 5 ++++- 4 files changed, 9 insertions(+), 11 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c index d94cc62186c1..abc562653b31 100644 --- a/drivers/mtd/maps/physmap.c +++ b/drivers/mtd/maps/physmap.c @@ -190,9 +190,8 @@ static void physmap_flash_shutdown(struct platform_device *dev) int i; for (i = 0; i < MAX_RESOURCES && info->mtd[i]; i++) - if (info->mtd[i]->suspend && info->mtd[i]->resume) - if (mtd_suspend(info->mtd[i]) == 0) - mtd_resume(info->mtd[i]); + if (mtd_suspend(info->mtd[i]) == 0) + mtd_resume(info->mtd[i]); } #else #define physmap_flash_shutdown NULL diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c index 717628312040..3da63fc6f16e 100644 --- a/drivers/mtd/maps/rbtx4939-flash.c +++ b/drivers/mtd/maps/rbtx4939-flash.c @@ -119,9 +119,8 @@ static void rbtx4939_flash_shutdown(struct platform_device *dev) { struct rbtx4939_flash_info *info = platform_get_drvdata(dev); - if (info->mtd->suspend && info->mtd->resume) - if (mtd_suspend(info->mtd) == 0) - mtd_resume(info->mtd); + if (mtd_suspend(info->mtd) == 0) + mtd_resume(info->mtd); } #else #define rbtx4939_flash_shutdown NULL diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c index 66494ee5355a..6ae9ca01388b 100644 --- a/drivers/mtd/mtdcore.c +++ b/drivers/mtd/mtdcore.c @@ -119,10 +119,7 @@ static int mtd_cls_suspend(struct device *dev, pm_message_t state) { struct mtd_info *mtd = dev_get_drvdata(dev); - if (mtd && mtd->suspend) - return mtd_suspend(mtd); - else - return 0; + return mtd_suspend(mtd); } static int mtd_cls_resume(struct device *dev) diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 6c91ba59c229..089370758fc9 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -427,12 +427,15 @@ static inline int mtd_is_locked(struct mtd_info *mtd, loff_t ofs, uint64_t len) static inline int mtd_suspend(struct mtd_info *mtd) { + if (!mtd->suspend) + return -EOPNOTSUPP; return mtd->suspend(mtd); } static inline void mtd_resume(struct mtd_info *mtd) { - mtd->resume(mtd); + if (mtd->resume) + mtd->resume(mtd); } static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) -- cgit v1.2.3 From 8f461a730242c528ca221948edceca49266a3ffb Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Mon, 2 Jan 2012 13:48:54 +0200 Subject: mtd: introduce mtd_can_have_bb helper This patch introduces new 'mtd_can_have_bb()' helper function which checks whether the flash can have bad eraseblocks. Then it changes all the direct 'mtd->block_isbad' use cases with 'mtd_can_have_bb()'. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 5 +---- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 4 ++-- drivers/mtd/mtdswap.c | 4 ++-- drivers/mtd/nftlcore.c | 2 +- drivers/mtd/redboot.c | 4 ++-- drivers/mtd/tests/mtd_readtest.c | 3 +-- drivers/mtd/tests/mtd_speedtest.c | 3 +-- drivers/mtd/tests/mtd_stresstest.c | 3 +-- drivers/mtd/tests/mtd_torturetest.c | 2 +- drivers/mtd/ubi/build.c | 2 +- include/linux/mtd/mtd.h | 7 +++++++ 12 files changed, 21 insertions(+), 20 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 92da621b1425..64efcbf087e9 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -867,10 +867,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&offs, argp, sizeof(loff_t))) return -EFAULT; - if (!mtd->block_isbad) - ret = -EOPNOTSUPP; - else - return mtd_block_isbad(mtd, offs); + return mtd_block_isbad(mtd, offs); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index aaafb5e18765..fbf3cb124a93 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -647,7 +647,7 @@ static int concat_block_isbad(struct mtd_info *mtd, loff_t ofs) struct mtd_concat *concat = CONCAT(mtd); int i, res = 0; - if (!concat->subdev[0]->block_isbad) + if (!mtd_can_have_bb(concat->subdev[0])) return res; if (ofs > mtd->size) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index c8540b8a7fc6..a4c8f67560e0 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -169,7 +169,7 @@ static void mtdoops_workfunc_erase(struct work_struct *work) cxt->nextpage = 0; } - while (mtd->block_isbad) { + while (mtd_can_have_bb(mtd)) { ret = mtd_block_isbad(mtd, cxt->nextpage * record_size); if (!ret) break; @@ -257,7 +257,7 @@ static void find_next_position(struct mtdoops_context *cxt) size_t retlen; for (page = 0; page < cxt->oops_pages; page++) { - if (mtd->block_isbad && + if (mtd_can_have_bb(mtd) && mtd_block_isbad(mtd, page * record_size)) continue; /* Assume the page is used */ diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index fe4426c1c736..3fc8cb2756c0 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -343,7 +343,7 @@ static int mtdswap_read_markers(struct mtdswap_dev *d, struct swap_eb *eb) offset = mtdswap_eb_offset(d, eb); /* Check first if the block is bad. */ - if (d->mtd->block_isbad && mtd_block_isbad(d->mtd, offset)) + if (mtd_can_have_bb(d->mtd) && mtd_block_isbad(d->mtd, offset)) return MTDSWAP_SCANNED_BAD; ops.ooblen = 2 * d->mtd->ecclayout->oobavail; @@ -1058,7 +1058,7 @@ static unsigned int mtdswap_badblocks(struct mtd_info *mtd, uint64_t size) badcnt = 0; - if (mtd->block_isbad) + if (mtd_can_have_bb(mtd)) for (offset = 0; offset < size; offset += mtd->erasesize) if (mtd_block_isbad(mtd, offset)) badcnt++; diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c index 8847e60ad167..a75382aff5f6 100644 --- a/drivers/mtd/nftlcore.c +++ b/drivers/mtd/nftlcore.c @@ -56,7 +56,7 @@ static void nftl_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd) if (memcmp(mtd->name, "DiskOnChip", 10)) return; - if (!mtd->block_isbad) { + if (!mtd_can_have_bb(mtd)) { printk(KERN_ERR "NFTL no longer supports the old DiskOnChip drivers loaded via docprobe.\n" "Please use the new diskonchip driver under the NAND subsystem.\n"); diff --git a/drivers/mtd/redboot.c b/drivers/mtd/redboot.c index 09bb81ea3a7e..48970c14beff 100644 --- a/drivers/mtd/redboot.c +++ b/drivers/mtd/redboot.c @@ -78,7 +78,7 @@ static int parse_redboot_partitions(struct mtd_info *master, if ( directory < 0 ) { offset = master->size + directory * master->erasesize; - while (master->block_isbad && + while (mtd_can_have_bb(master) && mtd_block_isbad(master, offset)) { if (!offset) { nogood: @@ -89,7 +89,7 @@ static int parse_redboot_partitions(struct mtd_info *master, } } else { offset = directory * master->erasesize; - while (master->block_isbad && + while (mtd_can_have_bb(master) && mtd_block_isbad(master, offset)) { offset += master->erasesize; if (offset == master->size) diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c index 4228eb4e54c7..121aba189cec 100644 --- a/drivers/mtd/tests/mtd_readtest.c +++ b/drivers/mtd/tests/mtd_readtest.c @@ -148,8 +148,7 @@ static int scan_for_bad_eraseblocks(void) return -ENOMEM; } - /* NOR flash does not implement block_isbad */ - if (mtd->block_isbad == NULL) + if (!mtd_can_have_bb(mtd)) return 0; printk(PRINT_PREF "scanning for bad eraseblocks\n"); diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c index 4d2ed5c0807d..2aec4f3b72be 100644 --- a/drivers/mtd/tests/mtd_speedtest.c +++ b/drivers/mtd/tests/mtd_speedtest.c @@ -336,8 +336,7 @@ static int scan_for_bad_eraseblocks(void) return -ENOMEM; } - /* NOR flash does not implement block_isbad */ - if (mtd->block_isbad == NULL) + if (!mtd_can_have_bb(mtd)) goto out; printk(PRINT_PREF "scanning for bad eraseblocks\n"); diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c index 399aa2bf220d..7b33f22d0b58 100644 --- a/drivers/mtd/tests/mtd_stresstest.c +++ b/drivers/mtd/tests/mtd_stresstest.c @@ -227,8 +227,7 @@ static int scan_for_bad_eraseblocks(void) return -ENOMEM; } - /* NOR flash does not implement block_isbad */ - if (mtd->block_isbad == NULL) + if (!mtd_can_have_bb(mtd)) return 0; printk(PRINT_PREF "scanning for bad eraseblocks\n"); diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c index 557105f2ead3..b65861bc7b8e 100644 --- a/drivers/mtd/tests/mtd_torturetest.c +++ b/drivers/mtd/tests/mtd_torturetest.c @@ -290,7 +290,7 @@ static int __init tort_init(void) * Check if there is a bad eraseblock among those we are going to test. */ memset(&bad_ebs[0], 0, sizeof(int) * ebcnt); - if (mtd->block_isbad) { + if (mtd_can_have_bb(mtd)) { for (i = eb; i < eb + ebcnt; i++) { err = mtd_block_isbad(mtd, (loff_t)i * mtd->erasesize); diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c index 6c3fb5ab20f5..115749f20f9e 100644 --- a/drivers/mtd/ubi/build.c +++ b/drivers/mtd/ubi/build.c @@ -664,7 +664,7 @@ static int io_init(struct ubi_device *ubi) ubi->peb_count = mtd_div_by_eb(ubi->mtd->size, ubi->mtd); ubi->flash_size = ubi->mtd->size; - if (ubi->mtd->block_isbad && ubi->mtd->block_markbad) + if (mtd_can_have_bb(ubi->mtd)) ubi->bad_allowed = 1; if (ubi->mtd->type == MTD_NORFLASH) { diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 089370758fc9..7e35755f6931 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -440,6 +440,8 @@ static inline void mtd_resume(struct mtd_info *mtd) static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) { + if (!mtd->block_isbad) + return -EOPNOTSUPP; return mtd->block_isbad(mtd, ofs); } @@ -483,6 +485,11 @@ static inline int mtd_has_oob(const struct mtd_info *mtd) return mtd->read_oob && mtd->write_oob; } +static inline int mtd_can_have_bb(const struct mtd_info *mtd) +{ + return !!mtd->block_isbad; +} + /* Kernel-side ioctl definitions */ struct mtd_partition; -- cgit v1.2.3 From 800ffd3496987e91f599a135060ef49731e045ac Mon Sep 17 00:00:00 2001 From: Artem Bityutskiy Date: Mon, 2 Jan 2012 13:59:12 +0200 Subject: mtd: do not use mtd->block_markbad directly Instead, use the new 'mtd_can_have_bb()', or just rely on 'mtd_block_markbad()' return code, which will be -EOPNOTSUPP if bad blocks are not supported. Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/mtdchar.c | 5 +---- drivers/mtd/mtdconcat.c | 2 +- drivers/mtd/mtdoops.c | 2 +- drivers/mtd/mtdswap.c | 2 +- fs/jffs2/wbuf.c | 3 --- include/linux/mtd/mtd.h | 2 ++ 6 files changed, 6 insertions(+), 10 deletions(-) (limited to 'drivers') diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c index 64efcbf087e9..50c6a1e7f675 100644 --- a/drivers/mtd/mtdchar.c +++ b/drivers/mtd/mtdchar.c @@ -877,10 +877,7 @@ static int mtdchar_ioctl(struct file *file, u_int cmd, u_long arg) if (copy_from_user(&offs, argp, sizeof(loff_t))) return -EFAULT; - if (!mtd->block_markbad) - ret = -EOPNOTSUPP; - else - return mtd_block_markbad(mtd, offs); + return mtd_block_markbad(mtd, offs); break; } diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c index fbf3cb124a93..1ed5103b219b 100644 --- a/drivers/mtd/mtdconcat.c +++ b/drivers/mtd/mtdconcat.c @@ -673,7 +673,7 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs) struct mtd_concat *concat = CONCAT(mtd); int i, err = -EINVAL; - if (!concat->subdev[0]->block_markbad) + if (!mtd_can_have_bb(concat->subdev[0])) return 0; if (ofs > mtd->size) diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c index a4c8f67560e0..db8e8272d69b 100644 --- a/drivers/mtd/mtdoops.c +++ b/drivers/mtd/mtdoops.c @@ -199,7 +199,7 @@ badblock: return; } - if (mtd->block_markbad && ret == -EIO) { + if (mtd_can_have_bb(mtd) && ret == -EIO) { ret = mtd_block_markbad(mtd, cxt->nextpage * record_size); if (ret < 0) { printk(KERN_ERR "mtdoops: block_markbad failed, aborting\n"); diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c index 3fc8cb2756c0..c92f0f6bc130 100644 --- a/drivers/mtd/mtdswap.c +++ b/drivers/mtd/mtdswap.c @@ -274,7 +274,7 @@ static int mtdswap_handle_badblock(struct mtdswap_dev *d, struct swap_eb *eb) eb->root = NULL; /* badblocks not supported */ - if (!d->mtd->block_markbad) + if (!mtd_can_have_bb(d->mtd)) return 1; offset = mtdswap_eb_offset(d, eb); diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c index fd96b757433f..30e8f47e8a23 100644 --- a/fs/jffs2/wbuf.c +++ b/fs/jffs2/wbuf.c @@ -1130,9 +1130,6 @@ int jffs2_write_nand_badblock(struct jffs2_sb_info *c, struct jffs2_eraseblock * if( ++jeb->bad_count < MAX_ERASE_FAILURES) return 0; - if (!c->mtd->block_markbad) - return 1; // What else can we do? - printk(KERN_WARNING "JFFS2: marking eraseblock at %08x\n as bad", bad_offset); ret = mtd_block_markbad(c->mtd, bad_offset); diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h index 7e35755f6931..1a81fde8f333 100644 --- a/include/linux/mtd/mtd.h +++ b/include/linux/mtd/mtd.h @@ -447,6 +447,8 @@ static inline int mtd_block_isbad(struct mtd_info *mtd, loff_t ofs) static inline int mtd_block_markbad(struct mtd_info *mtd, loff_t ofs) { + if (!mtd->block_markbad) + return -EOPNOTSUPP; return mtd->block_markbad(mtd, ofs); } -- cgit v1.2.3 From b60ef99c1164a8ad346cf41f9e71acfffb6d25a6 Mon Sep 17 00:00:00 2001 From: Fabio Estevam Date: Tue, 3 Jan 2012 16:35:25 -0200 Subject: mtd: Fix dependency for MTD_DOC200x Fix the following build warning: warning: (MTD_DOC2000 && MTD_DOC2001 && MTD_DOC2001PLUS) selects MTD_NAND_IDS which has unmet direct dependencies (MTD && MTD_NAND) Signed-off-by: Fabio Estevam Signed-off-by: Artem Bityutskiy Signed-off-by: David Woodhouse --- drivers/mtd/devices/Kconfig | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers') diff --git a/drivers/mtd/devices/Kconfig b/drivers/mtd/devices/Kconfig index 952e956ef01d..37b05c3f2792 100644 --- a/drivers/mtd/devices/Kconfig +++ b/drivers/mtd/devices/Kconfig @@ -191,6 +191,7 @@ comment "Disk-On-Chip Device Drivers" config MTD_DOC2000 tristate "M-Systems Disk-On-Chip 2000 and Millennium (DEPRECATED)" + depends on MTD_NAND select MTD_DOCPROBE select MTD_NAND_IDS ---help--- @@ -213,6 +214,7 @@ config MTD_DOC2000 config MTD_DOC2001 tristate "M-Systems Disk-On-Chip Millennium-only alternative driver (DEPRECATED)" + depends on MTD_NAND select MTD_DOCPROBE select MTD_NAND_IDS ---help--- @@ -234,6 +236,7 @@ config MTD_DOC2001 config MTD_DOC2001PLUS tristate "M-Systems Disk-On-Chip Millennium Plus" + depends on MTD_NAND select MTD_DOCPROBE select MTD_NAND_IDS ---help--- -- cgit v1.2.3