aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorDavid Woodhouse <David.Woodhouse@intel.com>2010-03-26 10:55:59 -0400
committerDavid Woodhouse <David.Woodhouse@intel.com>2010-03-26 10:55:59 -0400
commit329f9052dbadf6f4afe2231668bd00c579a4aa10 (patch)
treee080a5c70df40f3ae8cf28a95a3267757668ab97 /drivers/mtd
parent395b228858778d3c44f7c413693a6acaa8bb62dc (diff)
parent220bf991b0366cc50a94feede3d7341fa5710ee4 (diff)
Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
Conflicts: drivers/mtd/nand/sh_flctl.c Maxim's patch to initialise sysfs attributes depends on the patch which actually adds sysfs_attr_init().
Diffstat (limited to 'drivers/mtd')
-rw-r--r--[-rwxr-xr-x]drivers/mtd/chips/cfi_util.c0
-rw-r--r--drivers/mtd/chips/jedec_probe.c2
-rw-r--r--[-rwxr-xr-x]drivers/mtd/inftlcore.c0
-rw-r--r--drivers/mtd/maps/Kconfig15
-rw-r--r--drivers/mtd/maps/Makefile2
-rw-r--r--drivers/mtd/maps/alchemy-flash.c166
-rw-r--r--drivers/mtd/maps/omap_nor.c188
-rw-r--r--drivers/mtd/maps/pismo.c2
-rw-r--r--drivers/mtd/maps/plat-ram.c2
-rw-r--r--drivers/mtd/nand/Kconfig6
-rw-r--r--drivers/mtd/nand/au1550nd.c4
-rw-r--r--drivers/mtd/nand/bcm_umi_nand.c4
-rw-r--r--drivers/mtd/nand/mxc_nand.c2
-rw-r--r--drivers/mtd/nand/omap2.c35
-rw-r--r--drivers/mtd/nand/sh_flctl.c67
-rw-r--r--drivers/mtd/ubi/build.c136
-rw-r--r--drivers/mtd/ubi/debug.h4
-rw-r--r--drivers/mtd/ubi/io.c120
-rw-r--r--drivers/mtd/ubi/scan.c11
-rw-r--r--drivers/mtd/ubi/wl.c17
20 files changed, 264 insertions, 519 deletions
diff --git a/drivers/mtd/chips/cfi_util.c b/drivers/mtd/chips/cfi_util.c
index ca584d0380b4..ca584d0380b4 100755..100644
--- a/drivers/mtd/chips/cfi_util.c
+++ b/drivers/mtd/chips/cfi_util.c
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 1bec5e1ce6ac..8db1148dfa47 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -226,7 +226,7 @@ struct unlock_addr {
226 * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore, 226 * exists, but is for MTD_UADDR_NOT_SUPPORTED - and, therefore,
227 * should not be used. The problem is that structures with 227 * should not be used. The problem is that structures with
228 * initializers have extra fields initialized to 0. It is _very_ 228 * initializers have extra fields initialized to 0. It is _very_
229 * desireable to have the unlock address entries for unsupported 229 * desirable to have the unlock address entries for unsupported
230 * data widths automatically initialized - that means that 230 * data widths automatically initialized - that means that
231 * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here 231 * MTD_UADDR_NOT_SUPPORTED must be 0 and the first entry here
232 * must go unused. 232 * must go unused.
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 015a7fe1b6ee..015a7fe1b6ee 100755..100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 2de0cc823d60..aa2807d0ce72 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -251,12 +251,6 @@ config MTD_NETtel
251 help 251 help
252 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 252 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
253 253
254config MTD_ALCHEMY
255 tristate "AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support"
256 depends on SOC_AU1X00 && MTD_PARTITIONS && MTD_CFI
257 help
258 Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards
259
260config MTD_DILNETPC 254config MTD_DILNETPC
261 tristate "CFI Flash device mapped on DIL/Net PC" 255 tristate "CFI Flash device mapped on DIL/Net PC"
262 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN 256 depends on X86 && MTD_CONCAT && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN
@@ -428,15 +422,6 @@ config MTD_H720X
428 This enables access to the flash chips on the Hynix evaluation boards. 422 This enables access to the flash chips on the Hynix evaluation boards.
429 If you have such a board, say 'Y'. 423 If you have such a board, say 'Y'.
430 424
431config MTD_OMAP_NOR
432 tristate "TI OMAP board mappings"
433 depends on MTD_CFI && ARCH_OMAP
434 help
435 This enables access to the NOR flash chips on TI OMAP-based
436 boards defining flash platform devices and flash platform data.
437 These boards include the Innovator, H2, H3, OSK, Perseus2, and
438 more. If you have such a board, say 'Y'.
439
440# This needs CFI or JEDEC, depending on the cards found. 425# This needs CFI or JEDEC, depending on the cards found.
441config MTD_PCI 426config MTD_PCI
442 tristate "PCI MTD driver" 427 tristate "PCI MTD driver"
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index ce315214ff2b..bb035cd54c72 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -40,7 +40,6 @@ obj-$(CONFIG_MTD_SCx200_DOCFLASH)+= scx200_docflash.o
40obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o 40obj-$(CONFIG_MTD_DBOX2) += dbox2-flash.o
41obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 41obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o
42obj-$(CONFIG_MTD_PCI) += pci.o 42obj-$(CONFIG_MTD_PCI) += pci.o
43obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o
44obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o 43obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o
45obj-$(CONFIG_MTD_EDB7312) += edb7312.o 44obj-$(CONFIG_MTD_EDB7312) += edb7312.o
46obj-$(CONFIG_MTD_IMPA7) += impa7.o 45obj-$(CONFIG_MTD_IMPA7) += impa7.o
@@ -55,7 +54,6 @@ obj-$(CONFIG_MTD_IXP2000) += ixp2000.o
55obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o 54obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o
56obj-$(CONFIG_MTD_DMV182) += dmv182.o 55obj-$(CONFIG_MTD_DMV182) += dmv182.o
57obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o 56obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
58obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
59obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o 57obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o
60obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o 58obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o
61obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o 59obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o
diff --git a/drivers/mtd/maps/alchemy-flash.c b/drivers/mtd/maps/alchemy-flash.c
deleted file mode 100644
index 845ad4f2a542..000000000000
--- a/drivers/mtd/maps/alchemy-flash.c
+++ /dev/null
@@ -1,166 +0,0 @@
1/*
2 * Flash memory access on AMD Alchemy evaluation boards
3 *
4 * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com>
5 */
6
7#include <linux/init.h>
8#include <linux/module.h>
9#include <linux/types.h>
10#include <linux/kernel.h>
11
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/map.h>
14#include <linux/mtd/partitions.h>
15
16#include <asm/io.h>
17
18#ifdef CONFIG_MIPS_PB1000
19#define BOARD_MAP_NAME "Pb1000 Flash"
20#define BOARD_FLASH_SIZE 0x00800000 /* 8MB */
21#define BOARD_FLASH_WIDTH 4 /* 32-bits */
22#endif
23
24#ifdef CONFIG_MIPS_PB1500
25#define BOARD_MAP_NAME "Pb1500 Flash"
26#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
27#define BOARD_FLASH_WIDTH 4 /* 32-bits */
28#endif
29
30#ifdef CONFIG_MIPS_PB1100
31#define BOARD_MAP_NAME "Pb1100 Flash"
32#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
33#define BOARD_FLASH_WIDTH 4 /* 32-bits */
34#endif
35
36#ifdef CONFIG_MIPS_PB1550
37#define BOARD_MAP_NAME "Pb1550 Flash"
38#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
39#define BOARD_FLASH_WIDTH 4 /* 32-bits */
40#endif
41
42#ifdef CONFIG_MIPS_PB1200
43#define BOARD_MAP_NAME "Pb1200 Flash"
44#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
45#define BOARD_FLASH_WIDTH 2 /* 16-bits */
46#endif
47
48#ifdef CONFIG_MIPS_DB1000
49#define BOARD_MAP_NAME "Db1000 Flash"
50#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
51#define BOARD_FLASH_WIDTH 4 /* 32-bits */
52#endif
53
54#ifdef CONFIG_MIPS_DB1500
55#define BOARD_MAP_NAME "Db1500 Flash"
56#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
57#define BOARD_FLASH_WIDTH 4 /* 32-bits */
58#endif
59
60#ifdef CONFIG_MIPS_DB1100
61#define BOARD_MAP_NAME "Db1100 Flash"
62#define BOARD_FLASH_SIZE 0x02000000 /* 32MB */
63#define BOARD_FLASH_WIDTH 4 /* 32-bits */
64#endif
65
66#ifdef CONFIG_MIPS_DB1550
67#define BOARD_MAP_NAME "Db1550 Flash"
68#define BOARD_FLASH_SIZE 0x08000000 /* 128MB */
69#define BOARD_FLASH_WIDTH 4 /* 32-bits */
70#endif
71
72#ifdef CONFIG_MIPS_DB1200
73#define BOARD_MAP_NAME "Db1200 Flash"
74#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
75#define BOARD_FLASH_WIDTH 2 /* 16-bits */
76#endif
77
78#ifdef CONFIG_MIPS_BOSPORUS
79#define BOARD_MAP_NAME "Bosporus Flash"
80#define BOARD_FLASH_SIZE 0x01000000 /* 16MB */
81#define BOARD_FLASH_WIDTH 2 /* 16-bits */
82#endif
83
84#ifdef CONFIG_MIPS_MIRAGE
85#define BOARD_MAP_NAME "Mirage Flash"
86#define BOARD_FLASH_SIZE 0x04000000 /* 64MB */
87#define BOARD_FLASH_WIDTH 4 /* 32-bits */
88#define USE_LOCAL_ACCESSORS /* why? */
89#endif
90
91static struct map_info alchemy_map = {
92 .name = BOARD_MAP_NAME,
93};
94
95static struct mtd_partition alchemy_partitions[] = {
96 {
97 .name = "User FS",
98 .size = BOARD_FLASH_SIZE - 0x00400000,
99 .offset = 0x0000000
100 },{
101 .name = "YAMON",
102 .size = 0x0100000,
103 .offset = MTDPART_OFS_APPEND,
104 .mask_flags = MTD_WRITEABLE
105 },{
106 .name = "raw kernel",
107 .size = (0x300000 - 0x40000), /* last 256KB is yamon env */
108 .offset = MTDPART_OFS_APPEND,
109 }
110};
111
112static struct mtd_info *mymtd;
113
114static int __init alchemy_mtd_init(void)
115{
116 struct mtd_partition *parts;
117 int nb_parts = 0;
118 unsigned long window_addr;
119 unsigned long window_size;
120
121 /* Default flash buswidth */
122 alchemy_map.bankwidth = BOARD_FLASH_WIDTH;
123
124 window_addr = 0x20000000 - BOARD_FLASH_SIZE;
125 window_size = BOARD_FLASH_SIZE;
126
127 /*
128 * Static partition definition selection
129 */
130 parts = alchemy_partitions;
131 nb_parts = ARRAY_SIZE(alchemy_partitions);
132 alchemy_map.size = window_size;
133
134 /*
135 * Now let's probe for the actual flash. Do it here since
136 * specific machine settings might have been set above.
137 */
138 printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n",
139 alchemy_map.bankwidth*8);
140 alchemy_map.virt = ioremap(window_addr, window_size);
141 mymtd = do_map_probe("cfi_probe", &alchemy_map);
142 if (!mymtd) {
143 iounmap(alchemy_map.virt);
144 return -ENXIO;
145 }
146 mymtd->owner = THIS_MODULE;
147
148 add_mtd_partitions(mymtd, parts, nb_parts);
149 return 0;
150}
151
152static void __exit alchemy_mtd_cleanup(void)
153{
154 if (mymtd) {
155 del_mtd_partitions(mymtd);
156 map_destroy(mymtd);
157 iounmap(alchemy_map.virt);
158 }
159}
160
161module_init(alchemy_mtd_init);
162module_exit(alchemy_mtd_cleanup);
163
164MODULE_AUTHOR("Embedded Alley Solutions, Inc");
165MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver");
166MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
deleted file mode 100644
index ead0b2fab670..000000000000
--- a/drivers/mtd/maps/omap_nor.c
+++ /dev/null
@@ -1,188 +0,0 @@
1/*
2 * Flash memory support for various TI OMAP boards
3 *
4 * Copyright (C) 2001-2002 MontaVista Software Inc.
5 * Copyright (C) 2003-2004 Texas Instruments
6 * Copyright (C) 2004 Nokia Corporation
7 *
8 * Assembled using driver code copyright the companies above
9 * and written by David Brownell, Jian Zhang <jzhang@ti.com>,
10 * Tony Lindgren <tony@atomide.com> and others.
11 *
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
16 *
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/platform_device.h>
34#include <linux/module.h>
35#include <linux/types.h>
36#include <linux/kernel.h>
37#include <linux/init.h>
38#include <linux/ioport.h>
39#include <linux/slab.h>
40
41#include <linux/mtd/mtd.h>
42#include <linux/mtd/map.h>
43#include <linux/mtd/partitions.h>
44
45#include <asm/io.h>
46#include <mach/hardware.h>
47#include <asm/mach/flash.h>
48#include <plat/tc.h>
49
50#ifdef CONFIG_MTD_PARTITIONS
51static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL };
52#endif
53
54struct omapflash_info {
55 struct mtd_partition *parts;
56 struct mtd_info *mtd;
57 struct map_info map;
58};
59
60static void omap_set_vpp(struct map_info *map, int enable)
61{
62 static int count;
63 u32 l;
64
65 if (cpu_class_is_omap1()) {
66 if (enable) {
67 if (count++ == 0) {
68 l = omap_readl(EMIFS_CONFIG);
69 l |= OMAP_EMIFS_CONFIG_WP;
70 omap_writel(l, EMIFS_CONFIG);
71 }
72 } else {
73 if (count && (--count == 0)) {
74 l = omap_readl(EMIFS_CONFIG);
75 l &= ~OMAP_EMIFS_CONFIG_WP;
76 omap_writel(l, EMIFS_CONFIG);
77 }
78 }
79 }
80}
81
82static int __init omapflash_probe(struct platform_device *pdev)
83{
84 int err;
85 struct omapflash_info *info;
86 struct flash_platform_data *pdata = pdev->dev.platform_data;
87 struct resource *res = pdev->resource;
88 unsigned long size = res->end - res->start + 1;
89
90 info = kzalloc(sizeof(struct omapflash_info), GFP_KERNEL);
91 if (!info)
92 return -ENOMEM;
93
94 if (!request_mem_region(res->start, size, "flash")) {
95 err = -EBUSY;
96 goto out_free_info;
97 }
98
99 info->map.virt = ioremap(res->start, size);
100 if (!info->map.virt) {
101 err = -ENOMEM;
102 goto out_release_mem_region;
103 }
104 info->map.name = dev_name(&pdev->dev);
105 info->map.phys = res->start;
106 info->map.size = size;
107 info->map.bankwidth = pdata->width;
108 info->map.set_vpp = omap_set_vpp;
109
110 simple_map_init(&info->map);
111 info->mtd = do_map_probe(pdata->map_name, &info->map);
112 if (!info->mtd) {
113 err = -EIO;
114 goto out_iounmap;
115 }
116 info->mtd->owner = THIS_MODULE;
117
118 info->mtd->dev.parent = &pdev->dev;
119
120#ifdef CONFIG_MTD_PARTITIONS
121 err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
122 if (err > 0)
123 add_mtd_partitions(info->mtd, info->parts, err);
124 else if (err <= 0 && pdata->parts)
125 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
126 else
127#endif
128 add_mtd_device(info->mtd);
129
130 platform_set_drvdata(pdev, info);
131
132 return 0;
133
134out_iounmap:
135 iounmap(info->map.virt);
136out_release_mem_region:
137 release_mem_region(res->start, size);
138out_free_info:
139 kfree(info);
140
141 return err;
142}
143
144static int __exit omapflash_remove(struct platform_device *pdev)
145{
146 struct omapflash_info *info = platform_get_drvdata(pdev);
147
148 platform_set_drvdata(pdev, NULL);
149
150 if (info) {
151 if (info->parts) {
152 del_mtd_partitions(info->mtd);
153 kfree(info->parts);
154 } else
155 del_mtd_device(info->mtd);
156 map_destroy(info->mtd);
157 release_mem_region(info->map.phys, info->map.size);
158 iounmap((void __iomem *) info->map.virt);
159 kfree(info);
160 }
161
162 return 0;
163}
164
165static struct platform_driver omapflash_driver = {
166 .remove = __exit_p(omapflash_remove),
167 .driver = {
168 .name = "omapflash",
169 .owner = THIS_MODULE,
170 },
171};
172
173static int __init omapflash_init(void)
174{
175 return platform_driver_probe(&omapflash_driver, omapflash_probe);
176}
177
178static void __exit omapflash_exit(void)
179{
180 platform_driver_unregister(&omapflash_driver);
181}
182
183module_init(omapflash_init);
184module_exit(omapflash_exit);
185
186MODULE_LICENSE("GPL");
187MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards");
188MODULE_ALIAS("platform:omapflash");
diff --git a/drivers/mtd/maps/pismo.c b/drivers/mtd/maps/pismo.c
index 0a5e243d2bc6..f021018e0741 100644
--- a/drivers/mtd/maps/pismo.c
+++ b/drivers/mtd/maps/pismo.c
@@ -118,7 +118,7 @@ static int __devinit pismo_add_device(struct pismo_data *pismo, int i,
118{ 118{
119 struct platform_device *dev; 119 struct platform_device *dev;
120 struct resource res = { }; 120 struct resource res = { };
121 phys_addr_t base = region.base; 121 phys_addr_t base = region->base;
122 int ret; 122 int ret;
123 123
124 if (base == ~0) 124 if (base == ~0)
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index dafb91944e70..76a76be5a7bd 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -4,7 +4,7 @@
4 * http://www.simtec.co.uk/products/SWLINUX/ 4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk> 5 * Ben Dooks <ben@simtec.co.uk>
6 * 6 *
7 * Generic platfrom device based RAM map 7 * Generic platform device based RAM map
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 226206e06230..164bd56b9d1a 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -461,7 +461,7 @@ config MTD_NAND_MPC5121_NFC
461 461
462config MTD_NAND_MXC 462config MTD_NAND_MXC
463 tristate "MXC NAND support" 463 tristate "MXC NAND support"
464 depends on ARCH_MX2 || ARCH_MX3 464 depends on ARCH_MX2 || ARCH_MX25 || ARCH_MX3
465 help 465 help
466 This enables the driver for the NAND flash controller on the 466 This enables the driver for the NAND flash controller on the
467 MXC processors. 467 MXC processors.
@@ -474,10 +474,10 @@ config MTD_NAND_NOMADIK
474 474
475config MTD_NAND_SH_FLCTL 475config MTD_NAND_SH_FLCTL
476 tristate "Support for NAND on Renesas SuperH FLCTL" 476 tristate "Support for NAND on Renesas SuperH FLCTL"
477 depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723 477 depends on MTD_NAND && (SUPERH || ARCH_SHMOBILE)
478 help 478 help
479 Several Renesas SuperH CPU has FLCTL. This option enables support 479 Several Renesas SuperH CPU has FLCTL. This option enables support
480 for NAND Flash using FLCTL. This driver support SH7723. 480 for NAND Flash using FLCTL.
481 481
482config MTD_NAND_DAVINCI 482config MTD_NAND_DAVINCI
483 tristate "Support NAND on DaVinci SoC" 483 tristate "Support NAND on DaVinci SoC"
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 58c55db504e2..3ffe05db4923 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -19,6 +19,7 @@
19#include <asm/io.h> 19#include <asm/io.h>
20 20
21#include <asm/mach-au1x00/au1xxx.h> 21#include <asm/mach-au1x00/au1xxx.h>
22#include <asm/mach-db1x00/bcsr.h>
22 23
23/* 24/*
24 * MTD structure for NAND controller 25 * MTD structure for NAND controller
@@ -471,7 +472,8 @@ static int __init au1xxx_nand_init(void)
471 /* set gpio206 high */ 472 /* set gpio206 high */
472 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); 473 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR);
473 474
474 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1); 475 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1);
476
475 switch (boot_swapboot) { 477 switch (boot_swapboot) {
476 case 0: 478 case 0:
477 case 2: 479 case 2:
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index 5ff90b7e565e..7eb8674c9cf9 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -381,7 +381,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
381 if (!r) 381 if (!r)
382 return -ENXIO; 382 return -ENXIO;
383 383
384 /* map physical adress */ 384 /* map physical address */
385 bcm_umi_io_base = ioremap(r->start, r->end - r->start + 1); 385 bcm_umi_io_base = ioremap(r->start, r->end - r->start + 1);
386 386
387 if (!bcm_umi_io_base) { 387 if (!bcm_umi_io_base) {
@@ -525,7 +525,7 @@ static int bcm_umi_nand_remove(struct platform_device *pdev)
525 /* Release resources, unregister device */ 525 /* Release resources, unregister device */
526 nand_release(board_mtd); 526 nand_release(board_mtd);
527 527
528 /* unmap physical adress */ 528 /* unmap physical address */
529 iounmap(bcm_umi_io_base); 529 iounmap(bcm_umi_io_base);
530 530
531 /* Free the MTD device structure */ 531 /* Free the MTD device structure */
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 474a09e53131..2ba3be1f4937 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -507,7 +507,7 @@ static void mxc_do_addr_cycle(struct mtd_info *mtd, int column, int page_addr)
507 * MXC NANDFC can only perform full page+spare or 507 * MXC NANDFC can only perform full page+spare or
508 * spare-only read/write. When the upper layers 508 * spare-only read/write. When the upper layers
509 * layers perform a read/write buf operation, 509 * layers perform a read/write buf operation,
510 * we will used the saved column adress to index into 510 * we will used the saved column address to index into
511 * the full page. 511 * the full page.
512 */ 512 */
513 send_addr(host, 0, page_addr == -1); 513 send_addr(host, 0, page_addr == -1);
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 7df303aed8a4..ad07d39d4d5a 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -30,12 +30,8 @@
30 30
31#define DRIVER_NAME "omap2-nand" 31#define DRIVER_NAME "omap2-nand"
32 32
33/* size (4 KiB) for IO mapping */
34#define NAND_IO_SIZE SZ_4K
35
36#define NAND_WP_OFF 0 33#define NAND_WP_OFF 0
37#define NAND_WP_BIT 0x00000010 34#define NAND_WP_BIT 0x00000010
38#define WR_RD_PIN_MONITORING 0x00600000
39 35
40#define GPMC_BUF_FULL 0x00000001 36#define GPMC_BUF_FULL 0x00000001
41#define GPMC_BUF_EMPTY 0x00000000 37#define GPMC_BUF_EMPTY 0x00000000
@@ -885,8 +881,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
885 struct omap_nand_info *info; 881 struct omap_nand_info *info;
886 struct omap_nand_platform_data *pdata; 882 struct omap_nand_platform_data *pdata;
887 int err; 883 int err;
888 unsigned long val;
889
890 884
891 pdata = pdev->dev.platform_data; 885 pdata = pdev->dev.platform_data;
892 if (pdata == NULL) { 886 if (pdata == NULL) {
@@ -908,28 +902,14 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
908 info->gpmc_cs = pdata->cs; 902 info->gpmc_cs = pdata->cs;
909 info->gpmc_baseaddr = pdata->gpmc_baseaddr; 903 info->gpmc_baseaddr = pdata->gpmc_baseaddr;
910 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr; 904 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr;
905 info->phys_base = pdata->phys_base;
911 906
912 info->mtd.priv = &info->nand; 907 info->mtd.priv = &info->nand;
913 info->mtd.name = dev_name(&pdev->dev); 908 info->mtd.name = dev_name(&pdev->dev);
914 info->mtd.owner = THIS_MODULE; 909 info->mtd.owner = THIS_MODULE;
915 910
916 err = gpmc_cs_request(info->gpmc_cs, NAND_IO_SIZE, &info->phys_base); 911 info->nand.options |= pdata->devsize ? NAND_BUSWIDTH_16 : 0;
917 if (err < 0) { 912 info->nand.options |= NAND_SKIP_BBTSCAN;
918 dev_err(&pdev->dev, "Cannot request GPMC CS\n");
919 goto out_free_info;
920 }
921
922 /* Enable RD PIN Monitoring Reg */
923 if (pdata->dev_ready) {
924 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1);
925 val |= WR_RD_PIN_MONITORING;
926 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG1, val);
927 }
928
929 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG7);
930 val &= ~(0xf << 8);
931 val |= (0xc & 0xf) << 8;
932 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG7, val);
933 913
934 /* NAND write protect off */ 914 /* NAND write protect off */
935 omap_nand_wp(&info->mtd, NAND_WP_OFF); 915 omap_nand_wp(&info->mtd, NAND_WP_OFF);
@@ -937,7 +917,7 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
937 if (!request_mem_region(info->phys_base, NAND_IO_SIZE, 917 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
938 pdev->dev.driver->name)) { 918 pdev->dev.driver->name)) {
939 err = -EBUSY; 919 err = -EBUSY;
940 goto out_free_cs; 920 goto out_free_info;
941 } 921 }
942 922
943 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE); 923 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
@@ -966,11 +946,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
966 info->nand.chip_delay = 50; 946 info->nand.chip_delay = 50;
967 } 947 }
968 948
969 info->nand.options |= NAND_SKIP_BBTSCAN;
970 if ((gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1) & 0x3000)
971 == 0x1000)
972 info->nand.options |= NAND_BUSWIDTH_16;
973
974 if (use_prefetch) { 949 if (use_prefetch) {
975 /* copy the virtual address of nand base for fifo access */ 950 /* copy the virtual address of nand base for fifo access */
976 info->nand_pref_fifo_add = info->nand.IO_ADDR_R; 951 info->nand_pref_fifo_add = info->nand.IO_ADDR_R;
@@ -1046,8 +1021,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1046 1021
1047out_release_mem_region: 1022out_release_mem_region:
1048 release_mem_region(info->phys_base, NAND_IO_SIZE); 1023 release_mem_region(info->phys_base, NAND_IO_SIZE);
1049out_free_cs:
1050 gpmc_cs_free(info->gpmc_cs);
1051out_free_info: 1024out_free_info:
1052 kfree(info); 1025 kfree(info);
1053 1026
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index dbc09a81866e..88c802cd947f 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * SuperH FLCTL nand controller 2 * SuperH FLCTL nand controller
3 * 3 *
4 * Copyright © 2008 Renesas Solutions Corp. 4 * Copyright (c) 2008 Renesas Solutions Corp.
5 * Copyright © 2008 Atom Create Engineering Co., Ltd. 5 * Copyright (c) 2008 Atom Create Engineering Co., Ltd.
6 * 6 *
7 * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor 7 * Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -75,6 +75,11 @@ static void start_translation(struct sh_flctl *flctl)
75 writeb(TRSTRT, FLTRCR(flctl)); 75 writeb(TRSTRT, FLTRCR(flctl));
76} 76}
77 77
78static void timeout_error(struct sh_flctl *flctl, const char *str)
79{
80 dev_err(&flctl->pdev->dev, "Timeout occured in %s\n", str);
81}
82
78static void wait_completion(struct sh_flctl *flctl) 83static void wait_completion(struct sh_flctl *flctl)
79{ 84{
80 uint32_t timeout = LOOP_TIMEOUT_MAX; 85 uint32_t timeout = LOOP_TIMEOUT_MAX;
@@ -87,7 +92,7 @@ static void wait_completion(struct sh_flctl *flctl)
87 udelay(1); 92 udelay(1);
88 } 93 }
89 94
90 printk(KERN_ERR "wait_completion(): Timeout occured \n"); 95 timeout_error(flctl, __func__);
91 writeb(0x0, FLTRCR(flctl)); 96 writeb(0x0, FLTRCR(flctl));
92} 97}
93 98
@@ -100,6 +105,8 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr)
100 addr = page_addr; /* ERASE1 */ 105 addr = page_addr; /* ERASE1 */
101 } else if (page_addr != -1) { 106 } else if (page_addr != -1) {
102 /* SEQIN, READ0, etc.. */ 107 /* SEQIN, READ0, etc.. */
108 if (flctl->chip.options & NAND_BUSWIDTH_16)
109 column >>= 1;
103 if (flctl->page_size) { 110 if (flctl->page_size) {
104 addr = column & 0x0FFF; 111 addr = column & 0x0FFF;
105 addr |= (page_addr & 0xff) << 16; 112 addr |= (page_addr & 0xff) << 16;
@@ -132,7 +139,7 @@ static void wait_rfifo_ready(struct sh_flctl *flctl)
132 return; 139 return;
133 udelay(1); 140 udelay(1);
134 } 141 }
135 printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); 142 timeout_error(flctl, __func__);
136} 143}
137 144
138static void wait_wfifo_ready(struct sh_flctl *flctl) 145static void wait_wfifo_ready(struct sh_flctl *flctl)
@@ -146,7 +153,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl)
146 return; 153 return;
147 udelay(1); 154 udelay(1);
148 } 155 }
149 printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); 156 timeout_error(flctl, __func__);
150} 157}
151 158
152static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) 159static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
@@ -198,7 +205,7 @@ static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
198 writel(0, FL4ECCCR(flctl)); 205 writel(0, FL4ECCCR(flctl));
199 } 206 }
200 207
201 printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); 208 timeout_error(flctl, __func__);
202 return 1; /* timeout */ 209 return 1; /* timeout */
203} 210}
204 211
@@ -214,7 +221,7 @@ static void wait_wecfifo_ready(struct sh_flctl *flctl)
214 return; 221 return;
215 udelay(1); 222 udelay(1);
216 } 223 }
217 printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); 224 timeout_error(flctl, __func__);
218} 225}
219 226
220static void read_datareg(struct sh_flctl *flctl, int offset) 227static void read_datareg(struct sh_flctl *flctl, int offset)
@@ -275,7 +282,7 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
275static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) 282static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val)
276{ 283{
277 struct sh_flctl *flctl = mtd_to_flctl(mtd); 284 struct sh_flctl *flctl = mtd_to_flctl(mtd);
278 uint32_t flcmncr_val = readl(FLCMNCR(flctl)); 285 uint32_t flcmncr_val = readl(FLCMNCR(flctl)) & ~SEL_16BIT;
279 uint32_t flcmdcr_val, addr_len_bytes = 0; 286 uint32_t flcmdcr_val, addr_len_bytes = 0;
280 287
281 /* Set SNAND bit if page size is 2048byte */ 288 /* Set SNAND bit if page size is 2048byte */
@@ -297,6 +304,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
297 case NAND_CMD_READOOB: 304 case NAND_CMD_READOOB:
298 addr_len_bytes = flctl->rw_ADRCNT; 305 addr_len_bytes = flctl->rw_ADRCNT;
299 flcmdcr_val |= CDSRC_E; 306 flcmdcr_val |= CDSRC_E;
307 if (flctl->chip.options & NAND_BUSWIDTH_16)
308 flcmncr_val |= SEL_16BIT;
300 break; 309 break;
301 case NAND_CMD_SEQIN: 310 case NAND_CMD_SEQIN:
302 /* This case is that cmd is READ0 or READ1 or READ00 */ 311 /* This case is that cmd is READ0 or READ1 or READ00 */
@@ -305,6 +314,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
305 case NAND_CMD_PAGEPROG: 314 case NAND_CMD_PAGEPROG:
306 addr_len_bytes = flctl->rw_ADRCNT; 315 addr_len_bytes = flctl->rw_ADRCNT;
307 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; 316 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW;
317 if (flctl->chip.options & NAND_BUSWIDTH_16)
318 flcmncr_val |= SEL_16BIT;
308 break; 319 break;
309 case NAND_CMD_READID: 320 case NAND_CMD_READID:
310 flcmncr_val &= ~SNAND_E; 321 flcmncr_val &= ~SNAND_E;
@@ -523,6 +534,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command,
523 set_addr(mtd, 0, page_addr); 534 set_addr(mtd, 0, page_addr);
524 535
525 flctl->read_bytes = mtd->writesize + mtd->oobsize; 536 flctl->read_bytes = mtd->writesize + mtd->oobsize;
537 if (flctl->chip.options & NAND_BUSWIDTH_16)
538 column >>= 1;
526 flctl->index += column; 539 flctl->index += column;
527 goto read_normal_exit; 540 goto read_normal_exit;
528 541
@@ -686,6 +699,18 @@ static uint8_t flctl_read_byte(struct mtd_info *mtd)
686 return data; 699 return data;
687} 700}
688 701
702static uint16_t flctl_read_word(struct mtd_info *mtd)
703{
704 struct sh_flctl *flctl = mtd_to_flctl(mtd);
705 int index = flctl->index;
706 uint16_t data;
707 uint16_t *buf = (uint16_t *)&flctl->done_buff[index];
708
709 data = *buf;
710 flctl->index += 2;
711 return data;
712}
713
689static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 714static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
690{ 715{
691 int i; 716 int i;
@@ -769,38 +794,36 @@ static int flctl_chip_init_tail(struct mtd_info *mtd)
769 return 0; 794 return 0;
770} 795}
771 796
772static int __init flctl_probe(struct platform_device *pdev) 797static int __devinit flctl_probe(struct platform_device *pdev)
773{ 798{
774 struct resource *res; 799 struct resource *res;
775 struct sh_flctl *flctl; 800 struct sh_flctl *flctl;
776 struct mtd_info *flctl_mtd; 801 struct mtd_info *flctl_mtd;
777 struct nand_chip *nand; 802 struct nand_chip *nand;
778 struct sh_flctl_platform_data *pdata; 803 struct sh_flctl_platform_data *pdata;
779 int ret; 804 int ret = -ENXIO;
780 805
781 pdata = pdev->dev.platform_data; 806 pdata = pdev->dev.platform_data;
782 if (pdata == NULL) { 807 if (pdata == NULL) {
783 printk(KERN_ERR "sh_flctl platform_data not found.\n"); 808 dev_err(&pdev->dev, "no platform data defined\n");
784 return -ENODEV; 809 return -EINVAL;
785 } 810 }
786 811
787 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); 812 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL);
788 if (!flctl) { 813 if (!flctl) {
789 printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); 814 dev_err(&pdev->dev, "failed to allocate driver data\n");
790 return -ENOMEM; 815 return -ENOMEM;
791 } 816 }
792 817
793 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 818 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
794 if (!res) { 819 if (!res) {
795 printk(KERN_ERR "%s: resource not found.\n", __func__); 820 dev_err(&pdev->dev, "failed to get I/O memory\n");
796 ret = -ENODEV;
797 goto err; 821 goto err;
798 } 822 }
799 823
800 flctl->reg = ioremap(res->start, resource_size(res)); 824 flctl->reg = ioremap(res->start, resource_size(res));
801 if (flctl->reg == NULL) { 825 if (flctl->reg == NULL) {
802 printk(KERN_ERR "%s: ioremap error.\n", __func__); 826 dev_err(&pdev->dev, "failed to remap I/O memory\n");
803 ret = -ENOMEM;
804 goto err; 827 goto err;
805 } 828 }
806 829
@@ -808,6 +831,7 @@ static int __init flctl_probe(struct platform_device *pdev)
808 flctl_mtd = &flctl->mtd; 831 flctl_mtd = &flctl->mtd;
809 nand = &flctl->chip; 832 nand = &flctl->chip;
810 flctl_mtd->priv = nand; 833 flctl_mtd->priv = nand;
834 flctl->pdev = pdev;
811 flctl->hwecc = pdata->has_hwecc; 835 flctl->hwecc = pdata->has_hwecc;
812 836
813 flctl_register_init(flctl, pdata->flcmncr_val); 837 flctl_register_init(flctl, pdata->flcmncr_val);
@@ -825,6 +849,11 @@ static int __init flctl_probe(struct platform_device *pdev)
825 nand->select_chip = flctl_select_chip; 849 nand->select_chip = flctl_select_chip;
826 nand->cmdfunc = flctl_cmdfunc; 850 nand->cmdfunc = flctl_cmdfunc;
827 851
852 if (pdata->flcmncr_val & SEL_16BIT) {
853 nand->options |= NAND_BUSWIDTH_16;
854 nand->read_word = flctl_read_word;
855 }
856
828 ret = nand_scan_ident(flctl_mtd, 1, NULL); 857 ret = nand_scan_ident(flctl_mtd, 1, NULL);
829 if (ret) 858 if (ret)
830 goto err; 859 goto err;
@@ -846,7 +875,7 @@ err:
846 return ret; 875 return ret;
847} 876}
848 877
849static int __exit flctl_remove(struct platform_device *pdev) 878static int __devexit flctl_remove(struct platform_device *pdev)
850{ 879{
851 struct sh_flctl *flctl = platform_get_drvdata(pdev); 880 struct sh_flctl *flctl = platform_get_drvdata(pdev);
852 881
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 14cec04c34f9..fad40aa6f099 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -37,6 +37,7 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/stringify.h> 39#include <linux/stringify.h>
40#include <linux/namei.h>
40#include <linux/stat.h> 41#include <linux/stat.h>
41#include <linux/miscdevice.h> 42#include <linux/miscdevice.h>
42#include <linux/log2.h> 43#include <linux/log2.h>
@@ -50,7 +51,8 @@
50 51
51/** 52/**
52 * struct mtd_dev_param - MTD device parameter description data structure. 53 * struct mtd_dev_param - MTD device parameter description data structure.
53 * @name: MTD device name or number string 54 * @name: MTD character device node path, MTD device name, or MTD device number
55 * string
54 * @vid_hdr_offs: VID header offset 56 * @vid_hdr_offs: VID header offset
55 */ 57 */
56struct mtd_dev_param { 58struct mtd_dev_param {
@@ -59,10 +61,10 @@ struct mtd_dev_param {
59}; 61};
60 62
61/* Numbers of elements set in the @mtd_dev_param array */ 63/* Numbers of elements set in the @mtd_dev_param array */
62static int mtd_devs; 64static int __initdata mtd_devs;
63 65
64/* MTD devices specification parameters */ 66/* MTD devices specification parameters */
65static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 67static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
66 68
67/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 69/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
68struct class *ubi_class; 70struct class *ubi_class;
@@ -87,7 +89,8 @@ DEFINE_MUTEX(ubi_devices_mutex);
87static DEFINE_SPINLOCK(ubi_devices_lock); 89static DEFINE_SPINLOCK(ubi_devices_lock);
88 90
89/* "Show" method for files in '/<sysfs>/class/ubi/' */ 91/* "Show" method for files in '/<sysfs>/class/ubi/' */
90static ssize_t ubi_version_show(struct class *class, char *buf) 92static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr,
93 char *buf)
91{ 94{
92 return sprintf(buf, "%d\n", UBI_VERSION); 95 return sprintf(buf, "%d\n", UBI_VERSION);
93} 96}
@@ -363,11 +366,13 @@ static void dev_release(struct device *dev)
363/** 366/**
364 * ubi_sysfs_init - initialize sysfs for an UBI device. 367 * ubi_sysfs_init - initialize sysfs for an UBI device.
365 * @ubi: UBI device description object 368 * @ubi: UBI device description object
369 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
370 * taken
366 * 371 *
367 * This function returns zero in case of success and a negative error code in 372 * This function returns zero in case of success and a negative error code in
368 * case of failure. 373 * case of failure.
369 */ 374 */
370static int ubi_sysfs_init(struct ubi_device *ubi) 375static int ubi_sysfs_init(struct ubi_device *ubi, int *ref)
371{ 376{
372 int err; 377 int err;
373 378
@@ -379,6 +384,7 @@ static int ubi_sysfs_init(struct ubi_device *ubi)
379 if (err) 384 if (err)
380 return err; 385 return err;
381 386
387 *ref = 1;
382 err = device_create_file(&ubi->dev, &dev_eraseblock_size); 388 err = device_create_file(&ubi->dev, &dev_eraseblock_size);
383 if (err) 389 if (err)
384 return err; 390 return err;
@@ -434,7 +440,7 @@ static void ubi_sysfs_close(struct ubi_device *ubi)
434} 440}
435 441
436/** 442/**
437 * kill_volumes - destroy all volumes. 443 * kill_volumes - destroy all user volumes.
438 * @ubi: UBI device description object 444 * @ubi: UBI device description object
439 */ 445 */
440static void kill_volumes(struct ubi_device *ubi) 446static void kill_volumes(struct ubi_device *ubi)
@@ -447,36 +453,29 @@ static void kill_volumes(struct ubi_device *ubi)
447} 453}
448 454
449/** 455/**
450 * free_user_volumes - free all user volumes.
451 * @ubi: UBI device description object
452 *
453 * Normally the volumes are freed at the release function of the volume device
454 * objects. However, on error paths the volumes have to be freed before the
455 * device objects have been initialized.
456 */
457static void free_user_volumes(struct ubi_device *ubi)
458{
459 int i;
460
461 for (i = 0; i < ubi->vtbl_slots; i++)
462 if (ubi->volumes[i]) {
463 kfree(ubi->volumes[i]->eba_tbl);
464 kfree(ubi->volumes[i]);
465 }
466}
467
468/**
469 * uif_init - initialize user interfaces for an UBI device. 456 * uif_init - initialize user interfaces for an UBI device.
470 * @ubi: UBI device description object 457 * @ubi: UBI device description object
458 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
459 * taken, otherwise set to %0
460 *
461 * This function initializes various user interfaces for an UBI device. If the
462 * initialization fails at an early stage, this function frees all the
463 * resources it allocated, returns an error, and @ref is set to %0. However,
464 * if the initialization fails after the UBI device was registered in the
465 * driver core subsystem, this function takes a reference to @ubi->dev, because
466 * otherwise the release function ('dev_release()') would free whole @ubi
467 * object. The @ref argument is set to %1 in this case. The caller has to put
468 * this reference.
471 * 469 *
472 * This function returns zero in case of success and a negative error code in 470 * This function returns zero in case of success and a negative error code in
473 * case of failure. Note, this function destroys all volumes if it fails. 471 * case of failure.
474 */ 472 */
475static int uif_init(struct ubi_device *ubi) 473static int uif_init(struct ubi_device *ubi, int *ref)
476{ 474{
477 int i, err; 475 int i, err;
478 dev_t dev; 476 dev_t dev;
479 477
478 *ref = 0;
480 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 479 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
481 480
482 /* 481 /*
@@ -504,7 +503,7 @@ static int uif_init(struct ubi_device *ubi)
504 goto out_unreg; 503 goto out_unreg;
505 } 504 }
506 505
507 err = ubi_sysfs_init(ubi); 506 err = ubi_sysfs_init(ubi, ref);
508 if (err) 507 if (err)
509 goto out_sysfs; 508 goto out_sysfs;
510 509
@@ -522,6 +521,8 @@ static int uif_init(struct ubi_device *ubi)
522out_volumes: 521out_volumes:
523 kill_volumes(ubi); 522 kill_volumes(ubi);
524out_sysfs: 523out_sysfs:
524 if (*ref)
525 get_device(&ubi->dev);
525 ubi_sysfs_close(ubi); 526 ubi_sysfs_close(ubi);
526 cdev_del(&ubi->cdev); 527 cdev_del(&ubi->cdev);
527out_unreg: 528out_unreg:
@@ -875,7 +876,7 @@ static int ubi_reboot_notifier(struct notifier_block *n, unsigned long state,
875int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset) 876int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
876{ 877{
877 struct ubi_device *ubi; 878 struct ubi_device *ubi;
878 int i, err, do_free = 1; 879 int i, err, ref = 0;
879 880
880 /* 881 /*
881 * Check if we already have the same MTD device attached. 882 * Check if we already have the same MTD device attached.
@@ -975,9 +976,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
975 goto out_detach; 976 goto out_detach;
976 } 977 }
977 978
978 err = uif_init(ubi); 979 err = uif_init(ubi, &ref);
979 if (err) 980 if (err)
980 goto out_nofree; 981 goto out_detach;
981 982
982 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 983 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name);
983 if (IS_ERR(ubi->bgt_thread)) { 984 if (IS_ERR(ubi->bgt_thread)) {
@@ -1025,12 +1026,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
1025 1026
1026out_uif: 1027out_uif:
1027 uif_close(ubi); 1028 uif_close(ubi);
1028out_nofree:
1029 do_free = 0;
1030out_detach: 1029out_detach:
1031 ubi_wl_close(ubi); 1030 ubi_wl_close(ubi);
1032 if (do_free)
1033 free_user_volumes(ubi);
1034 free_internal_volumes(ubi); 1031 free_internal_volumes(ubi);
1035 vfree(ubi->vtbl); 1032 vfree(ubi->vtbl);
1036out_free: 1033out_free:
@@ -1039,7 +1036,10 @@ out_free:
1039#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1036#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1040 vfree(ubi->dbg_peb_buf); 1037 vfree(ubi->dbg_peb_buf);
1041#endif 1038#endif
1042 kfree(ubi); 1039 if (ref)
1040 put_device(&ubi->dev);
1041 else
1042 kfree(ubi);
1043 return err; 1043 return err;
1044} 1044}
1045 1045
@@ -1096,7 +1096,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1096 1096
1097 /* 1097 /*
1098 * Get a reference to the device in order to prevent 'dev_release()' 1098 * Get a reference to the device in order to prevent 'dev_release()'
1099 * from freeing @ubi object. 1099 * from freeing the @ubi object.
1100 */ 1100 */
1101 get_device(&ubi->dev); 1101 get_device(&ubi->dev);
1102 1102
@@ -1116,13 +1116,50 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1116} 1116}
1117 1117
1118/** 1118/**
1119 * find_mtd_device - open an MTD device by its name or number. 1119 * open_mtd_by_chdev - open an MTD device by its character device node path.
1120 * @mtd_dev: name or number of the device 1120 * @mtd_dev: MTD character device node path
1121 *
1122 * This helper function opens an MTD device by its character node device path.
1123 * Returns MTD device description object in case of success and a negative
1124 * error code in case of failure.
1125 */
1126static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
1127{
1128 int err, major, minor, mode;
1129 struct path path;
1130
1131 /* Probably this is an MTD character device node path */
1132 err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
1133 if (err)
1134 return ERR_PTR(err);
1135
1136 /* MTD device number is defined by the major / minor numbers */
1137 major = imajor(path.dentry->d_inode);
1138 minor = iminor(path.dentry->d_inode);
1139 mode = path.dentry->d_inode->i_mode;
1140 path_put(&path);
1141 if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
1142 return ERR_PTR(-EINVAL);
1143
1144 if (minor & 1)
1145 /*
1146 * Just do not think the "/dev/mtdrX" devices support is need,
1147 * so do not support them to avoid doing extra work.
1148 */
1149 return ERR_PTR(-EINVAL);
1150
1151 return get_mtd_device(NULL, minor / 2);
1152}
1153
1154/**
1155 * open_mtd_device - open MTD device by name, character device path, or number.
1156 * @mtd_dev: name, character device node path, or MTD device device number
1121 * 1157 *
1122 * This function tries to open and MTD device described by @mtd_dev string, 1158 * This function tries to open and MTD device described by @mtd_dev string,
1123 * which is first treated as an ASCII number, and if it is not true, it is 1159 * which is first treated as ASCII MTD device number, and if it is not true, it
1124 * treated as MTD device name. Returns MTD device description object in case of 1160 * is treated as MTD device name, and if that is also not true, it is treated
1125 * success and a negative error code in case of failure. 1161 * as MTD character device node path. Returns MTD device description object in
1162 * case of success and a negative error code in case of failure.
1126 */ 1163 */
1127static struct mtd_info * __init open_mtd_device(const char *mtd_dev) 1164static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1128{ 1165{
@@ -1137,6 +1174,9 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1137 * MTD device name. 1174 * MTD device name.
1138 */ 1175 */
1139 mtd = get_mtd_device_nm(mtd_dev); 1176 mtd = get_mtd_device_nm(mtd_dev);
1177 if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV)
1178 /* Probably this is an MTD character device node path */
1179 mtd = open_mtd_by_chdev(mtd_dev);
1140 } else 1180 } else
1141 mtd = get_mtd_device(NULL, mtd_num); 1181 mtd = get_mtd_device(NULL, mtd_num);
1142 1182
@@ -1352,13 +1392,15 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1352 1392
1353module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); 1393module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1354MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " 1394MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
1355 "mtd=<name|num>[,<vid_hdr_offs>].\n" 1395 "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
1356 "Multiple \"mtd\" parameters may be specified.\n" 1396 "Multiple \"mtd\" parameters may be specified.\n"
1357 "MTD devices may be specified by their number or name.\n" 1397 "MTD devices may be specified by their number, name, or "
1398 "path to the MTD character device node.\n"
1358 "Optional \"vid_hdr_offs\" parameter specifies UBI VID " 1399 "Optional \"vid_hdr_offs\" parameter specifies UBI VID "
1359 "header position and data starting position to be used " 1400 "header position to be used by UBI.\n"
1360 "by UBI.\n" 1401 "Example 1: mtd=/dev/mtd0 - attach MTD device "
1361 "Example: mtd=content,1984 mtd=4 - attach MTD device" 1402 "/dev/mtd0.\n"
1403 "Example 2: mtd=content,1984 mtd=4 - attach MTD device "
1362 "with name \"content\" using VID header offset 1984, and " 1404 "with name \"content\" using VID header offset 1984, and "
1363 "MTD device number 4 with default VID header offset."); 1405 "MTD device number 4 with default VID header offset.");
1364 1406
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index f30bcb372c05..17a107129726 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -96,8 +96,11 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
96 96
97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
98int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len); 98int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len);
99int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
100 int offset, int len);
99#else 101#else
100#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 102#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
103#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
101#endif 104#endif
102 105
103#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT 106#ifdef CONFIG_MTD_UBI_DEBUG_DISABLE_BGT
@@ -176,6 +179,7 @@ static inline int ubi_dbg_is_erase_failure(void)
176#define ubi_dbg_is_write_failure() 0 179#define ubi_dbg_is_write_failure() 0
177#define ubi_dbg_is_erase_failure() 0 180#define ubi_dbg_is_erase_failure() 0
178#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0 181#define ubi_dbg_check_all_ff(ubi, pnum, offset, len) 0
182#define ubi_dbg_check_write(ubi, buf, pnum, offset, len) 0
179 183
180#endif /* !CONFIG_MTD_UBI_DEBUG */ 184#endif /* !CONFIG_MTD_UBI_DEBUG */
181#endif /* !__UBI_DEBUG_H__ */ 185#endif /* !__UBI_DEBUG_H__ */
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 8aa51e7a6a7d..b4ecc84c7549 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -143,7 +143,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
143 143
144 err = paranoid_check_not_bad(ubi, pnum); 144 err = paranoid_check_not_bad(ubi, pnum);
145 if (err) 145 if (err)
146 return err > 0 ? -EINVAL : err; 146 return err;
147 147
148 addr = (loff_t)pnum * ubi->peb_size + offset; 148 addr = (loff_t)pnum * ubi->peb_size + offset;
149retry: 149retry:
@@ -236,12 +236,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
236 236
237 err = paranoid_check_not_bad(ubi, pnum); 237 err = paranoid_check_not_bad(ubi, pnum);
238 if (err) 238 if (err)
239 return err > 0 ? -EINVAL : err; 239 return err;
240 240
241 /* The area we are writing to has to contain all 0xFF bytes */ 241 /* The area we are writing to has to contain all 0xFF bytes */
242 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); 242 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
243 if (err) 243 if (err)
244 return err > 0 ? -EINVAL : err; 244 return err;
245 245
246 if (offset >= ubi->leb_start) { 246 if (offset >= ubi->leb_start) {
247 /* 247 /*
@@ -250,10 +250,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
250 */ 250 */
251 err = paranoid_check_peb_ec_hdr(ubi, pnum); 251 err = paranoid_check_peb_ec_hdr(ubi, pnum);
252 if (err) 252 if (err)
253 return err > 0 ? -EINVAL : err; 253 return err;
254 err = paranoid_check_peb_vid_hdr(ubi, pnum); 254 err = paranoid_check_peb_vid_hdr(ubi, pnum);
255 if (err) 255 if (err)
256 return err > 0 ? -EINVAL : err; 256 return err;
257 } 257 }
258 258
259 if (ubi_dbg_is_write_failure()) { 259 if (ubi_dbg_is_write_failure()) {
@@ -273,6 +273,21 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
273 } else 273 } else
274 ubi_assert(written == len); 274 ubi_assert(written == len);
275 275
276 if (!err) {
277 err = ubi_dbg_check_write(ubi, buf, pnum, offset, len);
278 if (err)
279 return err;
280
281 /*
282 * Since we always write sequentially, the rest of the PEB has
283 * to contain only 0xFF bytes.
284 */
285 offset += len;
286 len = ubi->peb_size - offset;
287 if (len)
288 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
289 }
290
276 return err; 291 return err;
277} 292}
278 293
@@ -348,7 +363,7 @@ retry:
348 363
349 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); 364 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
350 if (err) 365 if (err)
351 return err > 0 ? -EINVAL : err; 366 return err;
352 367
353 if (ubi_dbg_is_erase_failure() && !err) { 368 if (ubi_dbg_is_erase_failure() && !err) {
354 dbg_err("cannot erase PEB %d (emulated)", pnum); 369 dbg_err("cannot erase PEB %d (emulated)", pnum);
@@ -542,7 +557,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
542 557
543 err = paranoid_check_not_bad(ubi, pnum); 558 err = paranoid_check_not_bad(ubi, pnum);
544 if (err != 0) 559 if (err != 0)
545 return err > 0 ? -EINVAL : err; 560 return err;
546 561
547 if (ubi->ro_mode) { 562 if (ubi->ro_mode) {
548 ubi_err("read-only mode"); 563 ubi_err("read-only mode");
@@ -819,7 +834,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
819 834
820 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 835 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
821 if (err) 836 if (err)
822 return -EINVAL; 837 return err;
823 838
824 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 839 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
825 return err; 840 return err;
@@ -1083,7 +1098,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1083 1098
1084 err = paranoid_check_peb_ec_hdr(ubi, pnum); 1099 err = paranoid_check_peb_ec_hdr(ubi, pnum);
1085 if (err) 1100 if (err)
1086 return err > 0 ? -EINVAL : err; 1101 return err;
1087 1102
1088 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); 1103 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
1089 vid_hdr->version = UBI_VERSION; 1104 vid_hdr->version = UBI_VERSION;
@@ -1092,7 +1107,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1092 1107
1093 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1108 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
1094 if (err) 1109 if (err)
1095 return -EINVAL; 1110 return err;
1096 1111
1097 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1112 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1098 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, 1113 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
@@ -1107,8 +1122,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1107 * @ubi: UBI device description object 1122 * @ubi: UBI device description object
1108 * @pnum: physical eraseblock number to check 1123 * @pnum: physical eraseblock number to check
1109 * 1124 *
1110 * This function returns zero if the physical eraseblock is good, a positive 1125 * This function returns zero if the physical eraseblock is good, %-EINVAL if
1111 * number if it is bad and a negative error code if an error occurred. 1126 * it is bad and a negative error code if an error occurred.
1112 */ 1127 */
1113static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) 1128static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1114{ 1129{
@@ -1120,7 +1135,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1120 1135
1121 ubi_err("paranoid check failed for PEB %d", pnum); 1136 ubi_err("paranoid check failed for PEB %d", pnum);
1122 ubi_dbg_dump_stack(); 1137 ubi_dbg_dump_stack();
1123 return err; 1138 return err > 0 ? -EINVAL : err;
1124} 1139}
1125 1140
1126/** 1141/**
@@ -1130,7 +1145,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1130 * @ec_hdr: the erase counter header to check 1145 * @ec_hdr: the erase counter header to check
1131 * 1146 *
1132 * This function returns zero if the erase counter header contains valid 1147 * This function returns zero if the erase counter header contains valid
1133 * values, and %1 if not. 1148 * values, and %-EINVAL if not.
1134 */ 1149 */
1135static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, 1150static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1136 const struct ubi_ec_hdr *ec_hdr) 1151 const struct ubi_ec_hdr *ec_hdr)
@@ -1156,7 +1171,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1156fail: 1171fail:
1157 ubi_dbg_dump_ec_hdr(ec_hdr); 1172 ubi_dbg_dump_ec_hdr(ec_hdr);
1158 ubi_dbg_dump_stack(); 1173 ubi_dbg_dump_stack();
1159 return 1; 1174 return -EINVAL;
1160} 1175}
1161 1176
1162/** 1177/**
@@ -1164,8 +1179,8 @@ fail:
1164 * @ubi: UBI device description object 1179 * @ubi: UBI device description object
1165 * @pnum: the physical eraseblock number to check 1180 * @pnum: the physical eraseblock number to check
1166 * 1181 *
1167 * This function returns zero if the erase counter header is all right, %1 if 1182 * This function returns zero if the erase counter header is all right and and
1168 * not, and a negative error code if an error occurred. 1183 * a negative error code if not or if an error occurred.
1169 */ 1184 */
1170static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) 1185static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1171{ 1186{
@@ -1188,7 +1203,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1188 ubi_err("paranoid check failed for PEB %d", pnum); 1203 ubi_err("paranoid check failed for PEB %d", pnum);
1189 ubi_dbg_dump_ec_hdr(ec_hdr); 1204 ubi_dbg_dump_ec_hdr(ec_hdr);
1190 ubi_dbg_dump_stack(); 1205 ubi_dbg_dump_stack();
1191 err = 1; 1206 err = -EINVAL;
1192 goto exit; 1207 goto exit;
1193 } 1208 }
1194 1209
@@ -1206,7 +1221,7 @@ exit:
1206 * @vid_hdr: the volume identifier header to check 1221 * @vid_hdr: the volume identifier header to check
1207 * 1222 *
1208 * This function returns zero if the volume identifier header is all right, and 1223 * This function returns zero if the volume identifier header is all right, and
1209 * %1 if not. 1224 * %-EINVAL if not.
1210 */ 1225 */
1211static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 1226static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
1212 const struct ubi_vid_hdr *vid_hdr) 1227 const struct ubi_vid_hdr *vid_hdr)
@@ -1233,7 +1248,7 @@ fail:
1233 ubi_err("paranoid check failed for PEB %d", pnum); 1248 ubi_err("paranoid check failed for PEB %d", pnum);
1234 ubi_dbg_dump_vid_hdr(vid_hdr); 1249 ubi_dbg_dump_vid_hdr(vid_hdr);
1235 ubi_dbg_dump_stack(); 1250 ubi_dbg_dump_stack();
1236 return 1; 1251 return -EINVAL;
1237 1252
1238} 1253}
1239 1254
@@ -1243,7 +1258,7 @@ fail:
1243 * @pnum: the physical eraseblock number to check 1258 * @pnum: the physical eraseblock number to check
1244 * 1259 *
1245 * This function returns zero if the volume identifier header is all right, 1260 * This function returns zero if the volume identifier header is all right,
1246 * %1 if not, and a negative error code if an error occurred. 1261 * and a negative error code if not or if an error occurred.
1247 */ 1262 */
1248static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) 1263static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1249{ 1264{
@@ -1270,7 +1285,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1270 ubi_err("paranoid check failed for PEB %d", pnum); 1285 ubi_err("paranoid check failed for PEB %d", pnum);
1271 ubi_dbg_dump_vid_hdr(vid_hdr); 1286 ubi_dbg_dump_vid_hdr(vid_hdr);
1272 ubi_dbg_dump_stack(); 1287 ubi_dbg_dump_stack();
1273 err = 1; 1288 err = -EINVAL;
1274 goto exit; 1289 goto exit;
1275 } 1290 }
1276 1291
@@ -1282,6 +1297,61 @@ exit:
1282} 1297}
1283 1298
1284/** 1299/**
1300 * ubi_dbg_check_write - make sure write succeeded.
1301 * @ubi: UBI device description object
1302 * @buf: buffer with data which were written
1303 * @pnum: physical eraseblock number the data were written to
1304 * @offset: offset within the physical eraseblock the data were written to
1305 * @len: how many bytes were written
1306 *
1307 * This functions reads data which were recently written and compares it with
1308 * the original data buffer - the data have to match. Returns zero if the data
1309 * match and a negative error code if not or in case of failure.
1310 */
1311int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1312 int offset, int len)
1313{
1314 int err, i;
1315
1316 mutex_lock(&ubi->dbg_buf_mutex);
1317 err = ubi_io_read(ubi, ubi->dbg_peb_buf, pnum, offset, len);
1318 if (err)
1319 goto out_unlock;
1320
1321 for (i = 0; i < len; i++) {
1322 uint8_t c = ((uint8_t *)buf)[i];
1323 uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i];
1324 int dump_len;
1325
1326 if (c == c1)
1327 continue;
1328
1329 ubi_err("paranoid check failed for PEB %d:%d, len %d",
1330 pnum, offset, len);
1331 ubi_msg("data differ at position %d", i);
1332 dump_len = max_t(int, 128, len - i);
1333 ubi_msg("hex dump of the original buffer from %d to %d",
1334 i, i + dump_len);
1335 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1336 buf + i, dump_len, 1);
1337 ubi_msg("hex dump of the read buffer from %d to %d",
1338 i, i + dump_len);
1339 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1340 ubi->dbg_peb_buf + i, dump_len, 1);
1341 ubi_dbg_dump_stack();
1342 err = -EINVAL;
1343 goto out_unlock;
1344 }
1345 mutex_unlock(&ubi->dbg_buf_mutex);
1346
1347 return 0;
1348
1349out_unlock:
1350 mutex_unlock(&ubi->dbg_buf_mutex);
1351 return err;
1352}
1353
1354/**
1285 * ubi_dbg_check_all_ff - check that a region of flash is empty. 1355 * ubi_dbg_check_all_ff - check that a region of flash is empty.
1286 * @ubi: UBI device description object 1356 * @ubi: UBI device description object
1287 * @pnum: the physical eraseblock number to check 1357 * @pnum: the physical eraseblock number to check
@@ -1289,8 +1359,8 @@ exit:
1289 * @len: the length of the region to check 1359 * @len: the length of the region to check
1290 * 1360 *
1291 * This function returns zero if only 0xFF bytes are present at offset 1361 * This function returns zero if only 0xFF bytes are present at offset
1292 * @offset of the physical eraseblock @pnum, %1 if not, and a negative error 1362 * @offset of the physical eraseblock @pnum, and a negative error code if not
1293 * code if an error occurred. 1363 * or if an error occurred.
1294 */ 1364 */
1295int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) 1365int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1296{ 1366{
@@ -1321,7 +1391,7 @@ fail:
1321 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1391 ubi_msg("hex dump of the %d-%d region", offset, offset + len);
1322 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1392 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1323 ubi->dbg_peb_buf, len, 1); 1393 ubi->dbg_peb_buf, len, 1);
1324 err = 1; 1394 err = -EINVAL;
1325error: 1395error:
1326 ubi_dbg_dump_stack(); 1396 ubi_dbg_dump_stack();
1327 mutex_unlock(&ubi->dbg_buf_mutex); 1397 mutex_unlock(&ubi->dbg_buf_mutex);
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 90af61a2c3e4..594184bbd56a 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -974,11 +974,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
974 seb->ec = si->mean_ec; 974 seb->ec = si->mean_ec;
975 975
976 err = paranoid_check_si(ubi, si); 976 err = paranoid_check_si(ubi, si);
977 if (err) { 977 if (err)
978 if (err > 0)
979 err = -EINVAL;
980 goto out_vidh; 978 goto out_vidh;
981 }
982 979
983 ubi_free_vid_hdr(ubi, vidh); 980 ubi_free_vid_hdr(ubi, vidh);
984 kfree(ech); 981 kfree(ech);
@@ -1086,8 +1083,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
1086 * @ubi: UBI device description object 1083 * @ubi: UBI device description object
1087 * @si: scanning information 1084 * @si: scanning information
1088 * 1085 *
1089 * This function returns zero if the scanning information is all right, %1 if 1086 * This function returns zero if the scanning information is all right, and a
1090 * not and a negative error code if an error occurred. 1087 * negative error code if not or if an error occurred.
1091 */ 1088 */
1092static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) 1089static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1093{ 1090{
@@ -1346,7 +1343,7 @@ bad_vid_hdr:
1346 1343
1347out: 1344out:
1348 ubi_dbg_dump_stack(); 1345 ubi_dbg_dump_stack();
1349 return 1; 1346 return -EINVAL;
1350} 1347}
1351 1348
1352#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ 1349#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 600c7229d5cf..f64ddabd4ac8 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -464,7 +464,7 @@ retry:
464 ubi->peb_size - ubi->vid_hdr_aloffset); 464 ubi->peb_size - ubi->vid_hdr_aloffset);
465 if (err) { 465 if (err) {
466 ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); 466 ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum);
467 return err > 0 ? -EINVAL : err; 467 return err;
468 } 468 }
469 469
470 return e->pnum; 470 return e->pnum;
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
513 dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); 513 dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec);
514 514
515 err = paranoid_check_ec(ubi, e->pnum, e->ec); 515 err = paranoid_check_ec(ubi, e->pnum, e->ec);
516 if (err > 0) 516 if (err)
517 return -EINVAL; 517 return -EINVAL;
518 518
519 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); 519 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi)
1572 * @ec: the erase counter to check 1572 * @ec: the erase counter to check
1573 * 1573 *
1574 * This function returns zero if the erase counter of physical eraseblock @pnum 1574 * This function returns zero if the erase counter of physical eraseblock @pnum
1575 * is equivalent to @ec, %1 if not, and a negative error code if an error 1575 * is equivalent to @ec, and a negative error code if not or if an error occurred.
1576 * occurred.
1577 */ 1576 */
1578static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec) 1577static int paranoid_check_ec(struct ubi_device *ubi, int pnum, int ec)
1579{ 1578{
@@ -1611,8 +1610,8 @@ out_free:
1611 * @e: the wear-leveling entry to check 1610 * @e: the wear-leveling entry to check
1612 * @root: the root of the tree 1611 * @root: the root of the tree
1613 * 1612 *
1614 * This function returns zero if @e is in the @root RB-tree and %1 if it is 1613 * This function returns zero if @e is in the @root RB-tree and %-EINVAL if it
1615 * not. 1614 * is not.
1616 */ 1615 */
1617static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e, 1616static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
1618 struct rb_root *root) 1617 struct rb_root *root)
@@ -1623,7 +1622,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
1623 ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ", 1622 ubi_err("paranoid check failed for PEB %d, EC %d, RB-tree %p ",
1624 e->pnum, e->ec, root); 1623 e->pnum, e->ec, root);
1625 ubi_dbg_dump_stack(); 1624 ubi_dbg_dump_stack();
1626 return 1; 1625 return -EINVAL;
1627} 1626}
1628 1627
1629/** 1628/**
@@ -1632,7 +1631,7 @@ static int paranoid_check_in_wl_tree(struct ubi_wl_entry *e,
1632 * @ubi: UBI device description object 1631 * @ubi: UBI device description object
1633 * @e: the wear-leveling entry to check 1632 * @e: the wear-leveling entry to check
1634 * 1633 *
1635 * This function returns zero if @e is in @ubi->pq and %1 if it is not. 1634 * This function returns zero if @e is in @ubi->pq and %-EINVAL if it is not.
1636 */ 1635 */
1637static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e) 1636static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
1638{ 1637{
@@ -1647,6 +1646,6 @@ static int paranoid_check_in_pq(struct ubi_device *ubi, struct ubi_wl_entry *e)
1647 ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue", 1646 ubi_err("paranoid check failed for PEB %d, EC %d, Protect queue",
1648 e->pnum, e->ec); 1647 e->pnum, e->ec);
1649 ubi_dbg_dump_stack(); 1648 ubi_dbg_dump_stack();
1650 return 1; 1649 return -EINVAL;
1651} 1650}
1652#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ 1651#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */