aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/mtd
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2010-04-29 19:53:17 -0400
committerH. Peter Anvin <hpa@zytor.com>2010-04-29 19:53:17 -0400
commitd9c5841e22231e4e49fd0a1004164e6fce59b7a6 (patch)
treee1f589c46b3ff79bbe7b1b2469f6362f94576da6 /drivers/mtd
parentb701a47ba48b698976fb2fe05fb285b0edc1d26a (diff)
parent5967ed87ade85a421ef814296c3c7f182b08c225 (diff)
Merge branch 'x86/asm' into x86/atomic
Merge reason: Conflict between LOCK_PREFIX_HERE and relative alternatives pointers Resolved Conflicts: arch/x86/include/asm/alternative.h arch/x86/kernel/alternative.c Signed-off-by: H. Peter Anvin <hpa@zytor.com>
Diffstat (limited to 'drivers/mtd')
-rw-r--r--drivers/mtd/Makefile2
-rw-r--r--[-rwxr-xr-x]drivers/mtd/chips/cfi_util.c0
-rw-r--r--drivers/mtd/chips/jedec_probe.c2
-rw-r--r--drivers/mtd/devices/block2mtd.c1
-rw-r--r--drivers/mtd/devices/m25p80.c1
-rw-r--r--drivers/mtd/devices/sst25l.c1
-rw-r--r--[-rwxr-xr-x]drivers/mtd/inftlcore.c0
-rw-r--r--drivers/mtd/internal.h17
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c1
-rw-r--r--drivers/mtd/maps/Kconfig32
-rw-r--r--drivers/mtd/maps/Makefile2
-rw-r--r--drivers/mtd/maps/alchemy-flash.c166
-rw-r--r--drivers/mtd/maps/amd76xrom.c1
-rw-r--r--drivers/mtd/maps/bfin-async-flash.c1
-rw-r--r--drivers/mtd/maps/ck804xrom.c1
-rw-r--r--drivers/mtd/maps/esb2rom.c1
-rw-r--r--drivers/mtd/maps/gpio-addr-flash.c1
-rw-r--r--drivers/mtd/maps/ichxrom.c1
-rw-r--r--drivers/mtd/maps/intel_vr_nor.c1
-rw-r--r--drivers/mtd/maps/octagon-5066.c1
-rw-r--r--drivers/mtd/maps/omap_nor.c188
-rw-r--r--drivers/mtd/maps/physmap_of.c1
-rw-r--r--drivers/mtd/maps/pismo.c321
-rw-r--r--drivers/mtd/maps/plat-ram.c2
-rw-r--r--drivers/mtd/maps/pmcmsp-flash.c1
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c1
-rw-r--r--drivers/mtd/maps/sbc_gxx.c1
-rw-r--r--drivers/mtd/maps/sun_uflash.c1
-rw-r--r--drivers/mtd/maps/vmax301.c1
-rw-r--r--drivers/mtd/maps/vmu-flash.c1
-rw-r--r--drivers/mtd/mtdbdi.c43
-rw-r--r--drivers/mtd/mtdcore.c80
-rw-r--r--drivers/mtd/mtdoops.c2
-rw-r--r--drivers/mtd/mtdsuper.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.c5
-rw-r--r--drivers/mtd/nand/cafe_nand.c1
-rw-r--r--drivers/mtd/nand/cmx270_nand.c1
-rw-r--r--drivers/mtd/nand/davinci_nand.c1
-rw-r--r--drivers/mtd/nand/diskonchip.c1
-rw-r--r--drivers/mtd/nand/fsl_upm.c1
-rw-r--r--drivers/mtd/nand/mxc_nand.c2
-rw-r--r--drivers/mtd/nand/ndfc.c1
-rw-r--r--drivers/mtd/nand/nomadik_nand.c1
-rw-r--r--drivers/mtd/nand/omap2.c36
-rw-r--r--drivers/mtd/nand/orion_nand.c8
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c1
-rw-r--r--drivers/mtd/nand/sh_flctl.c70
-rw-r--r--drivers/mtd/nand/tmio_nand.c1
-rw-r--r--drivers/mtd/ofpart.c1
-rw-r--r--drivers/mtd/onenand/omap2.c1
-rw-r--r--drivers/mtd/onenand/onenand_base.c1
-rw-r--r--drivers/mtd/onenand/onenand_sim.c1
-rw-r--r--drivers/mtd/tests/mtd_nandecctest.c1
-rw-r--r--drivers/mtd/tests/mtd_oobtest.c1
-rw-r--r--drivers/mtd/tests/mtd_pagetest.c1
-rw-r--r--drivers/mtd/tests/mtd_readtest.c7
-rw-r--r--drivers/mtd/tests/mtd_speedtest.c8
-rw-r--r--drivers/mtd/tests/mtd_stresstest.c7
-rw-r--r--drivers/mtd/tests/mtd_subpagetest.c1
-rw-r--r--drivers/mtd/tests/mtd_torturetest.c1
-rw-r--r--drivers/mtd/ubi/build.c137
-rw-r--r--drivers/mtd/ubi/cdev.c2
-rw-r--r--drivers/mtd/ubi/debug.h4
-rw-r--r--drivers/mtd/ubi/gluebi.c1
-rw-r--r--drivers/mtd/ubi/io.c121
-rw-r--r--drivers/mtd/ubi/kapi.c16
-rw-r--r--drivers/mtd/ubi/scan.c12
-rw-r--r--drivers/mtd/ubi/ubi.h1
-rw-r--r--drivers/mtd/ubi/upd.c1
-rw-r--r--drivers/mtd/ubi/vmt.c1
-rw-r--r--drivers/mtd/ubi/vtbl.c2
-rw-r--r--drivers/mtd/ubi/wl.c17
74 files changed, 760 insertions, 604 deletions
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 82d1e4de475b..4521b1ecce45 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -4,7 +4,7 @@
4 4
5# Core functionality. 5# Core functionality.
6obj-$(CONFIG_MTD) += mtd.o 6obj-$(CONFIG_MTD) += mtd.o
7mtd-y := mtdcore.o mtdsuper.o mtdbdi.o 7mtd-y := mtdcore.o mtdsuper.o
8mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o 8mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o
9 9
10obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o 10obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
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/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 8c295f40d2ac..ce6424008ed9 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -17,6 +17,7 @@
17#include <linux/buffer_head.h> 17#include <linux/buffer_head.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19#include <linux/mount.h> 19#include <linux/mount.h>
20#include <linux/slab.h>
20 21
21#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) 22#define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args)
22#define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args) 23#define INFO(fmt, args...) printk(KERN_INFO "block2mtd: " fmt "\n" , ## args)
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index f3f4768d6e18..81e49a9b017e 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -21,6 +21,7 @@
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/mutex.h> 22#include <linux/mutex.h>
23#include <linux/math64.h> 23#include <linux/math64.h>
24#include <linux/slab.h>
24#include <linux/sched.h> 25#include <linux/sched.h>
25#include <linux/mod_devicetable.h> 26#include <linux/mod_devicetable.h>
26 27
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c
index 0a11721f146e..fe17054ee2fe 100644
--- a/drivers/mtd/devices/sst25l.c
+++ b/drivers/mtd/devices/sst25l.c
@@ -20,6 +20,7 @@
20#include <linux/device.h> 20#include <linux/device.h>
21#include <linux/mutex.h> 21#include <linux/mutex.h>
22#include <linux/interrupt.h> 22#include <linux/interrupt.h>
23#include <linux/slab.h>
23#include <linux/sched.h> 24#include <linux/sched.h>
24 25
25#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/inftlcore.c b/drivers/mtd/inftlcore.c
index 8aca5523a337..8aca5523a337 100755..100644
--- a/drivers/mtd/inftlcore.c
+++ b/drivers/mtd/inftlcore.c
diff --git a/drivers/mtd/internal.h b/drivers/mtd/internal.h
index c658fe7216b5..e69de29bb2d1 100644
--- a/drivers/mtd/internal.h
+++ b/drivers/mtd/internal.h
@@ -1,17 +0,0 @@
1/* Internal MTD definitions
2 *
3 * Copyright © 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12/*
13 * mtdbdi.c
14 */
15extern struct backing_dev_info mtd_bdi_unmappable;
16extern struct backing_dev_info mtd_bdi_ro_mappable;
17extern struct backing_dev_info mtd_bdi_rw_mappable;
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index e22ca49583e7..a73ee12aad81 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -26,6 +26,7 @@
26 */ 26 */
27#include <linux/mtd/pfow.h> 27#include <linux/mtd/pfow.h>
28#include <linux/mtd/qinfo.h> 28#include <linux/mtd/qinfo.h>
29#include <linux/slab.h>
29 30
30static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len, 31static int lpddr_read(struct mtd_info *mtd, loff_t adr, size_t len,
31 size_t *retlen, u_char *buf); 32 size_t *retlen, u_char *buf);
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 4c364d44ad59..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"
@@ -549,4 +534,21 @@ config MTD_VMU
549 To build this as a module select M here, the module will be called 534 To build this as a module select M here, the module will be called
550 vmu-flash. 535 vmu-flash.
551 536
537config MTD_PISMO
538 tristate "MTD discovery driver for PISMO modules"
539 depends on I2C
540 depends on ARCH_VERSATILE
541 help
542 This driver allows for discovery of PISMO modules - see
543 <http://www.pismoworld.org/>. These are small modules containing
544 up to five memory devices (eg, SRAM, flash, DOC) described by an
545 I2C EEPROM.
546
547 This driver does not create any MTD maps itself; instead it
548 creates MTD physmap and MTD SRAM platform devices. If you
549 enable this option, you should consider enabling MTD_PHYSMAP
550 and/or MTD_PLATRAM according to the devices on your module.
551
552 When built as a module, it will be called pismo.ko
553
552endmenu 554endmenu
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/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 237733d094c4..19fe92db0c46 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -8,6 +8,7 @@
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/slab.h>
11#include <asm/io.h> 12#include <asm/io.h>
12#include <linux/mtd/mtd.h> 13#include <linux/mtd/mtd.h>
13#include <linux/mtd/map.h> 14#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c
index a7c808b577d3..c0fd99b0c525 100644
--- a/drivers/mtd/maps/bfin-async-flash.c
+++ b/drivers/mtd/maps/bfin-async-flash.c
@@ -22,6 +22,7 @@
22#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
23#include <linux/mtd/physmap.h> 23#include <linux/mtd/physmap.h>
24#include <linux/platform_device.h> 24#include <linux/platform_device.h>
25#include <linux/slab.h>
25#include <linux/types.h> 26#include <linux/types.h>
26 27
27#include <asm/blackfin.h> 28#include <asm/blackfin.h>
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 424f17d6ffd1..ddb462bea9b5 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -11,6 +11,7 @@
11#include <linux/types.h> 11#include <linux/types.h>
12#include <linux/kernel.h> 12#include <linux/kernel.h>
13#include <linux/init.h> 13#include <linux/init.h>
14#include <linux/slab.h>
14#include <asm/io.h> 15#include <asm/io.h>
15#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
16#include <linux/mtd/map.h> 17#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index 11a2f57df9cf..d12c93dc1aad 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -14,6 +14,7 @@
14#include <linux/types.h> 14#include <linux/types.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/init.h> 16#include <linux/init.h>
17#include <linux/slab.h>
17#include <asm/io.h> 18#include <asm/io.h>
18#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
19#include <linux/mtd/map.h> 20#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index 1ad5caf9fe69..32e89d773b4e 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -23,6 +23,7 @@
23#include <linux/mtd/partitions.h> 23#include <linux/mtd/partitions.h>
24#include <linux/mtd/physmap.h> 24#include <linux/mtd/physmap.h>
25#include <linux/platform_device.h> 25#include <linux/platform_device.h>
26#include <linux/slab.h>
26#include <linux/types.h> 27#include <linux/types.h>
27 28
28#define pr_devinit(fmt, args...) ({ static const __devinitconst char __fmt[] = fmt; printk(__fmt, ## args); }) 29#define pr_devinit(fmt, args...) ({ static const __devinitconst char __fmt[] = fmt; printk(__fmt, ## args); })
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index c32bc28920b3..f102bf243a74 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -8,6 +8,7 @@
8#include <linux/types.h> 8#include <linux/types.h>
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/slab.h>
11#include <asm/io.h> 12#include <asm/io.h>
12#include <linux/mtd/mtd.h> 13#include <linux/mtd/mtd.h>
13#include <linux/mtd/map.h> 14#include <linux/mtd/map.h>
diff --git a/drivers/mtd/maps/intel_vr_nor.c b/drivers/mtd/maps/intel_vr_nor.c
index 1e7814ae212a..fc1998512eb4 100644
--- a/drivers/mtd/maps/intel_vr_nor.c
+++ b/drivers/mtd/maps/intel_vr_nor.c
@@ -29,6 +29,7 @@
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/kernel.h> 31#include <linux/kernel.h>
32#include <linux/slab.h>
32#include <linux/pci.h> 33#include <linux/pci.h>
33#include <linux/init.h> 34#include <linux/init.h>
34#include <linux/mtd/mtd.h> 35#include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/maps/octagon-5066.c b/drivers/mtd/maps/octagon-5066.c
index 2b2e45093218..23fe1786770f 100644
--- a/drivers/mtd/maps/octagon-5066.c
+++ b/drivers/mtd/maps/octagon-5066.c
@@ -24,7 +24,6 @@
24 ##################################################################### */ 24 ##################################################################### */
25 25
26#include <linux/module.h> 26#include <linux/module.h>
27#include <linux/slab.h>
28#include <linux/ioport.h> 27#include <linux/ioport.h>
29#include <linux/init.h> 28#include <linux/init.h>
30#include <asm/io.h> 29#include <asm/io.h>
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
deleted file mode 100644
index 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/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index 61e4eb48bb2d..101ee6ead05c 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -23,6 +23,7 @@
23#include <linux/mtd/concat.h> 23#include <linux/mtd/concat.h>
24#include <linux/of.h> 24#include <linux/of.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/slab.h>
26 27
27struct of_flash_list { 28struct of_flash_list {
28 struct mtd_info *mtd; 29 struct mtd_info *mtd;
diff --git a/drivers/mtd/maps/pismo.c b/drivers/mtd/maps/pismo.c
new file mode 100644
index 000000000000..60c068db452d
--- /dev/null
+++ b/drivers/mtd/maps/pismo.c
@@ -0,0 +1,321 @@
1/*
2 * PISMO memory driver - http://www.pismoworld.org/
3 *
4 * For ARM Realview and Versatile platforms
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License.
9 */
10#include <linux/init.h>
11#include <linux/module.h>
12#include <linux/i2c.h>
13#include <linux/slab.h>
14#include <linux/platform_device.h>
15#include <linux/spinlock.h>
16#include <linux/mutex.h>
17#include <linux/mtd/physmap.h>
18#include <linux/mtd/plat-ram.h>
19#include <linux/mtd/pismo.h>
20
21#define PISMO_NUM_CS 5
22
23struct pismo_cs_block {
24 u8 type;
25 u8 width;
26 __le16 access;
27 __le32 size;
28 u32 reserved[2];
29 char device[32];
30} __packed;
31
32struct pismo_eeprom {
33 struct pismo_cs_block cs[PISMO_NUM_CS];
34 char board[15];
35 u8 sum;
36} __packed;
37
38struct pismo_mem {
39 phys_addr_t base;
40 u32 size;
41 u16 access;
42 u8 width;
43 u8 type;
44};
45
46struct pismo_data {
47 struct i2c_client *client;
48 void (*vpp)(void *, int);
49 void *vpp_data;
50 struct platform_device *dev[PISMO_NUM_CS];
51};
52
53/* FIXME: set_vpp could do with a better calling convention */
54static struct pismo_data *vpp_pismo;
55static DEFINE_MUTEX(pismo_mutex);
56
57static int pismo_setvpp_probe_fix(struct pismo_data *pismo)
58{
59 mutex_lock(&pismo_mutex);
60 if (vpp_pismo) {
61 mutex_unlock(&pismo_mutex);
62 kfree(pismo);
63 return -EBUSY;
64 }
65 vpp_pismo = pismo;
66 mutex_unlock(&pismo_mutex);
67 return 0;
68}
69
70static void pismo_setvpp_remove_fix(struct pismo_data *pismo)
71{
72 mutex_lock(&pismo_mutex);
73 if (vpp_pismo == pismo)
74 vpp_pismo = NULL;
75 mutex_unlock(&pismo_mutex);
76}
77
78static void pismo_set_vpp(struct map_info *map, int on)
79{
80 struct pismo_data *pismo = vpp_pismo;
81
82 pismo->vpp(pismo->vpp_data, on);
83}
84/* end of hack */
85
86
87static unsigned int __devinit pismo_width_to_bytes(unsigned int width)
88{
89 width &= 15;
90 if (width > 2)
91 return 0;
92 return 1 << width;
93}
94
95static int __devinit pismo_eeprom_read(struct i2c_client *client, void *buf,
96 u8 addr, size_t size)
97{
98 int ret;
99 struct i2c_msg msg[] = {
100 {
101 .addr = client->addr,
102 .len = sizeof(addr),
103 .buf = &addr,
104 }, {
105 .addr = client->addr,
106 .flags = I2C_M_RD,
107 .len = size,
108 .buf = buf,
109 },
110 };
111
112 ret = i2c_transfer(client->adapter, msg, ARRAY_SIZE(msg));
113
114 return ret == ARRAY_SIZE(msg) ? size : -EIO;
115}
116
117static int __devinit pismo_add_device(struct pismo_data *pismo, int i,
118 struct pismo_mem *region, const char *name, void *pdata, size_t psize)
119{
120 struct platform_device *dev;
121 struct resource res = { };
122 phys_addr_t base = region->base;
123 int ret;
124
125 if (base == ~0)
126 return -ENXIO;
127
128 res.start = base;
129 res.end = base + region->size - 1;
130 res.flags = IORESOURCE_MEM;
131
132 dev = platform_device_alloc(name, i);
133 if (!dev)
134 return -ENOMEM;
135 dev->dev.parent = &pismo->client->dev;
136
137 do {
138 ret = platform_device_add_resources(dev, &res, 1);
139 if (ret)
140 break;
141
142 ret = platform_device_add_data(dev, pdata, psize);
143 if (ret)
144 break;
145
146 ret = platform_device_add(dev);
147 if (ret)
148 break;
149
150 pismo->dev[i] = dev;
151 return 0;
152 } while (0);
153
154 platform_device_put(dev);
155 return ret;
156}
157
158static int __devinit pismo_add_nor(struct pismo_data *pismo, int i,
159 struct pismo_mem *region)
160{
161 struct physmap_flash_data data = {
162 .width = region->width,
163 };
164
165 if (pismo->vpp)
166 data.set_vpp = pismo_set_vpp;
167
168 return pismo_add_device(pismo, i, region, "physmap-flash",
169 &data, sizeof(data));
170}
171
172static int __devinit pismo_add_sram(struct pismo_data *pismo, int i,
173 struct pismo_mem *region)
174{
175 struct platdata_mtd_ram data = {
176 .bankwidth = region->width,
177 };
178
179 return pismo_add_device(pismo, i, region, "mtd-ram",
180 &data, sizeof(data));
181}
182
183static void __devinit pismo_add_one(struct pismo_data *pismo, int i,
184 const struct pismo_cs_block *cs, phys_addr_t base)
185{
186 struct device *dev = &pismo->client->dev;
187 struct pismo_mem region;
188
189 region.base = base;
190 region.type = cs->type;
191 region.width = pismo_width_to_bytes(cs->width);
192 region.access = le16_to_cpu(cs->access);
193 region.size = le32_to_cpu(cs->size);
194
195 if (region.width == 0) {
196 dev_err(dev, "cs%u: bad width: %02x, ignoring\n", i, cs->width);
197 return;
198 }
199
200 /*
201 * FIXME: may need to the platforms memory controller here, but at
202 * the moment we assume that it has already been correctly setup.
203 * The memory controller can also tell us the base address as well.
204 */
205
206 dev_info(dev, "cs%u: %.32s: type %02x access %u00ps size %uK\n",
207 i, cs->device, region.type, region.access, region.size / 1024);
208
209 switch (region.type) {
210 case 0:
211 break;
212 case 1:
213 /* static DOC */
214 break;
215 case 2:
216 /* static NOR */
217 pismo_add_nor(pismo, i, &region);
218 break;
219 case 3:
220 /* static RAM */
221 pismo_add_sram(pismo, i, &region);
222 break;
223 }
224}
225
226static int __devexit pismo_remove(struct i2c_client *client)
227{
228 struct pismo_data *pismo = i2c_get_clientdata(client);
229 int i;
230
231 for (i = 0; i < ARRAY_SIZE(pismo->dev); i++)
232 platform_device_unregister(pismo->dev[i]);
233
234 /* FIXME: set_vpp needs saner arguments */
235 pismo_setvpp_remove_fix(pismo);
236
237 kfree(pismo);
238
239 return 0;
240}
241
242static int __devinit pismo_probe(struct i2c_client *client,
243 const struct i2c_device_id *id)
244{
245 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
246 struct pismo_pdata *pdata = client->dev.platform_data;
247 struct pismo_eeprom eeprom;
248 struct pismo_data *pismo;
249 int ret, i;
250
251 if (!i2c_check_functionality(adapter, I2C_FUNC_I2C)) {
252 dev_err(&client->dev, "functionality mismatch\n");
253 return -EIO;
254 }
255
256 pismo = kzalloc(sizeof(*pismo), GFP_KERNEL);
257 if (!pismo)
258 return -ENOMEM;
259
260 /* FIXME: set_vpp needs saner arguments */
261 ret = pismo_setvpp_probe_fix(pismo);
262 if (ret)
263 return ret;
264
265 pismo->client = client;
266 if (pdata) {
267 pismo->vpp = pdata->set_vpp;
268 pismo->vpp_data = pdata->vpp_data;
269 }
270 i2c_set_clientdata(client, pismo);
271
272 ret = pismo_eeprom_read(client, &eeprom, 0, sizeof(eeprom));
273 if (ret < 0) {
274 dev_err(&client->dev, "error reading EEPROM: %d\n", ret);
275 return ret;
276 }
277
278 dev_info(&client->dev, "%.15s board found\n", eeprom.board);
279
280 for (i = 0; i < ARRAY_SIZE(eeprom.cs); i++)
281 if (eeprom.cs[i].type != 0xff)
282 pismo_add_one(pismo, i, &eeprom.cs[i],
283 pdata->cs_addrs[i]);
284
285 return 0;
286}
287
288static const struct i2c_device_id pismo_id[] = {
289 { "pismo" },
290 { },
291};
292MODULE_DEVICE_TABLE(i2c, pismo_id);
293
294static struct i2c_driver pismo_driver = {
295 .driver = {
296 .name = "pismo",
297 .owner = THIS_MODULE,
298 },
299 .probe = pismo_probe,
300 .remove = __devexit_p(pismo_remove),
301 .id_table = pismo_id,
302};
303
304static int __init pismo_init(void)
305{
306 BUILD_BUG_ON(sizeof(struct pismo_cs_block) != 48);
307 BUILD_BUG_ON(sizeof(struct pismo_eeprom) != 256);
308
309 return i2c_add_driver(&pismo_driver);
310}
311module_init(pismo_init);
312
313static void __exit pismo_exit(void)
314{
315 i2c_del_driver(&pismo_driver);
316}
317module_exit(pismo_exit);
318
319MODULE_AUTHOR("Russell King <linux@arm.linux.org.uk>");
320MODULE_DESCRIPTION("PISMO memory driver");
321MODULE_LICENSE("GPL");
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index dafb91944e70..76a76be5a7bd 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -4,7 +4,7 @@
4 * http://www.simtec.co.uk/products/SWLINUX/ 4 * http://www.simtec.co.uk/products/SWLINUX/
5 * Ben Dooks <ben@simtec.co.uk> 5 * Ben Dooks <ben@simtec.co.uk>
6 * 6 *
7 * Generic platfrom device based RAM map 7 * Generic platform device based RAM map
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index c8fd8da4bc87..acb13fa5001c 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -28,6 +28,7 @@
28 * 675 Mass Ave, Cambridge, MA 02139, USA. 28 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 */ 29 */
30 30
31#include <linux/slab.h>
31#include <linux/module.h> 32#include <linux/module.h>
32#include <linux/types.h> 33#include <linux/types.h>
33#include <linux/kernel.h> 34#include <linux/kernel.h>
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index b13f6417b5b2..91dc6331053f 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -11,6 +11,7 @@
11 11
12#include <linux/module.h> 12#include <linux/module.h>
13#include <linux/types.h> 13#include <linux/types.h>
14#include <linux/slab.h>
14#include <linux/kernel.h> 15#include <linux/kernel.h>
15#include <linux/init.h> 16#include <linux/init.h>
16#include <linux/platform_device.h> 17#include <linux/platform_device.h>
diff --git a/drivers/mtd/maps/sbc_gxx.c b/drivers/mtd/maps/sbc_gxx.c
index 1b1c0b7e11ef..04b2781fc627 100644
--- a/drivers/mtd/maps/sbc_gxx.c
+++ b/drivers/mtd/maps/sbc_gxx.c
@@ -45,7 +45,6 @@ separate MTD devices.
45// Includes 45// Includes
46 46
47#include <linux/module.h> 47#include <linux/module.h>
48#include <linux/slab.h>
49#include <linux/ioport.h> 48#include <linux/ioport.h>
50#include <linux/init.h> 49#include <linux/init.h>
51#include <asm/io.h> 50#include <asm/io.h>
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index fd7a1017399a..fadc4c45b455 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -15,6 +15,7 @@
15#include <linux/ioport.h> 15#include <linux/ioport.h>
16#include <linux/of.h> 16#include <linux/of.h>
17#include <linux/of_device.h> 17#include <linux/of_device.h>
18#include <linux/slab.h>
18#include <asm/prom.h> 19#include <asm/prom.h>
19#include <asm/uaccess.h> 20#include <asm/uaccess.h>
20#include <asm/io.h> 21#include <asm/io.h>
diff --git a/drivers/mtd/maps/vmax301.c b/drivers/mtd/maps/vmax301.c
index 6d452dcdfe34..6adaa6acc193 100644
--- a/drivers/mtd/maps/vmax301.c
+++ b/drivers/mtd/maps/vmax301.c
@@ -16,7 +16,6 @@
16 ##################################################################### */ 16 ##################################################################### */
17 17
18#include <linux/module.h> 18#include <linux/module.h>
19#include <linux/slab.h>
20#include <linux/ioport.h> 19#include <linux/ioport.h>
21#include <linux/init.h> 20#include <linux/init.h>
22#include <linux/spinlock.h> 21#include <linux/spinlock.h>
diff --git a/drivers/mtd/maps/vmu-flash.c b/drivers/mtd/maps/vmu-flash.c
index 82afad0ddd72..4afc167731ef 100644
--- a/drivers/mtd/maps/vmu-flash.c
+++ b/drivers/mtd/maps/vmu-flash.c
@@ -8,6 +8,7 @@
8 * GNU General Public Licence 8 * GNU General Public Licence
9 */ 9 */
10#include <linux/init.h> 10#include <linux/init.h>
11#include <linux/slab.h>
11#include <linux/sched.h> 12#include <linux/sched.h>
12#include <linux/delay.h> 13#include <linux/delay.h>
13#include <linux/maple.h> 14#include <linux/maple.h>
diff --git a/drivers/mtd/mtdbdi.c b/drivers/mtd/mtdbdi.c
index 5ca5aed0b225..e69de29bb2d1 100644
--- a/drivers/mtd/mtdbdi.c
+++ b/drivers/mtd/mtdbdi.c
@@ -1,43 +0,0 @@
1/* MTD backing device capabilities
2 *
3 * Copyright © 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/backing-dev.h>
13#include <linux/mtd/mtd.h>
14#include "internal.h"
15
16/*
17 * backing device capabilities for non-mappable devices (such as NAND flash)
18 * - permits private mappings, copies are taken of the data
19 */
20struct backing_dev_info mtd_bdi_unmappable = {
21 .capabilities = BDI_CAP_MAP_COPY,
22};
23
24/*
25 * backing device capabilities for R/O mappable devices (such as ROM)
26 * - permits private mappings, copies are taken of the data
27 * - permits non-writable shared mappings
28 */
29struct backing_dev_info mtd_bdi_ro_mappable = {
30 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
31 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
32};
33
34/*
35 * backing device capabilities for writable mappable devices (such as RAM)
36 * - permits private mappings, copies are taken of the data
37 * - permits non-writable shared mappings
38 */
39struct backing_dev_info mtd_bdi_rw_mappable = {
40 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
41 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
42 BDI_CAP_WRITE_MAP),
43};
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index c356c0a30c3e..b177e750efc3 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -2,12 +2,14 @@
2 * Core registration and callback routines for MTD 2 * Core registration and callback routines for MTD
3 * drivers and users. 3 * drivers and users.
4 * 4 *
5 * bdi bits are:
6 * Copyright © 2006 Red Hat, Inc. All Rights Reserved.
7 * Written by David Howells (dhowells@redhat.com)
5 */ 8 */
6 9
7#include <linux/module.h> 10#include <linux/module.h>
8#include <linux/kernel.h> 11#include <linux/kernel.h>
9#include <linux/ptrace.h> 12#include <linux/ptrace.h>
10#include <linux/slab.h>
11#include <linux/string.h> 13#include <linux/string.h>
12#include <linux/timer.h> 14#include <linux/timer.h>
13#include <linux/major.h> 15#include <linux/major.h>
@@ -17,11 +19,39 @@
17#include <linux/init.h> 19#include <linux/init.h>
18#include <linux/mtd/compatmac.h> 20#include <linux/mtd/compatmac.h>
19#include <linux/proc_fs.h> 21#include <linux/proc_fs.h>
22#include <linux/backing-dev.h>
20 23
21#include <linux/mtd/mtd.h> 24#include <linux/mtd/mtd.h>
22#include "internal.h"
23 25
24#include "mtdcore.h" 26#include "mtdcore.h"
27/*
28 * backing device capabilities for non-mappable devices (such as NAND flash)
29 * - permits private mappings, copies are taken of the data
30 */
31struct backing_dev_info mtd_bdi_unmappable = {
32 .capabilities = BDI_CAP_MAP_COPY,
33};
34
35/*
36 * backing device capabilities for R/O mappable devices (such as ROM)
37 * - permits private mappings, copies are taken of the data
38 * - permits non-writable shared mappings
39 */
40struct backing_dev_info mtd_bdi_ro_mappable = {
41 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
42 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
43};
44
45/*
46 * backing device capabilities for writable mappable devices (such as RAM)
47 * - permits private mappings, copies are taken of the data
48 * - permits non-writable shared mappings
49 */
50struct backing_dev_info mtd_bdi_rw_mappable = {
51 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
52 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
53 BDI_CAP_WRITE_MAP),
54};
25 55
26static int mtd_cls_suspend(struct device *dev, pm_message_t state); 56static int mtd_cls_suspend(struct device *dev, pm_message_t state);
27static int mtd_cls_resume(struct device *dev); 57static int mtd_cls_resume(struct device *dev);
@@ -629,20 +659,55 @@ done:
629/*====================================================================*/ 659/*====================================================================*/
630/* Init code */ 660/* Init code */
631 661
662static int __init mtd_bdi_init(struct backing_dev_info *bdi, const char *name)
663{
664 int ret;
665
666 ret = bdi_init(bdi);
667 if (!ret)
668 ret = bdi_register(bdi, NULL, name);
669
670 if (ret)
671 bdi_destroy(bdi);
672
673 return ret;
674}
675
632static int __init init_mtd(void) 676static int __init init_mtd(void)
633{ 677{
634 int ret; 678 int ret;
679
635 ret = class_register(&mtd_class); 680 ret = class_register(&mtd_class);
681 if (ret)
682 goto err_reg;
683
684 ret = mtd_bdi_init(&mtd_bdi_unmappable, "mtd-unmap");
685 if (ret)
686 goto err_bdi1;
687
688 ret = mtd_bdi_init(&mtd_bdi_ro_mappable, "mtd-romap");
689 if (ret)
690 goto err_bdi2;
691
692 ret = mtd_bdi_init(&mtd_bdi_rw_mappable, "mtd-rwmap");
693 if (ret)
694 goto err_bdi3;
636 695
637 if (ret) {
638 pr_err("Error registering mtd class: %d\n", ret);
639 return ret;
640 }
641#ifdef CONFIG_PROC_FS 696#ifdef CONFIG_PROC_FS
642 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 697 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
643 proc_mtd->read_proc = mtd_read_proc; 698 proc_mtd->read_proc = mtd_read_proc;
644#endif /* CONFIG_PROC_FS */ 699#endif /* CONFIG_PROC_FS */
645 return 0; 700 return 0;
701
702err_bdi3:
703 bdi_destroy(&mtd_bdi_ro_mappable);
704err_bdi2:
705 bdi_destroy(&mtd_bdi_unmappable);
706err_bdi1:
707 class_unregister(&mtd_class);
708err_reg:
709 pr_err("Error registering mtd class or bdi: %d\n", ret);
710 return ret;
646} 711}
647 712
648static void __exit cleanup_mtd(void) 713static void __exit cleanup_mtd(void)
@@ -652,6 +717,9 @@ static void __exit cleanup_mtd(void)
652 remove_proc_entry( "mtd", NULL); 717 remove_proc_entry( "mtd", NULL);
653#endif /* CONFIG_PROC_FS */ 718#endif /* CONFIG_PROC_FS */
654 class_unregister(&mtd_class); 719 class_unregister(&mtd_class);
720 bdi_destroy(&mtd_bdi_unmappable);
721 bdi_destroy(&mtd_bdi_ro_mappable);
722 bdi_destroy(&mtd_bdi_rw_mappable);
655} 723}
656 724
657module_init(init_mtd); 725module_init(init_mtd);
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index a714ec482761..92e12df0917f 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -322,7 +322,7 @@ static void mtdoops_do_dump(struct kmsg_dumper *dumper,
322 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy); 322 memcpy(dst + l1_cpy, s2 + s2_start, l2_cpy);
323 323
324 /* Panics must be written immediately */ 324 /* Panics must be written immediately */
325 if (reason == KMSG_DUMP_PANIC) { 325 if (reason != KMSG_DUMP_OOPS) {
326 if (!cxt->mtd->panic_write) 326 if (!cxt->mtd->panic_write)
327 printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n"); 327 printk(KERN_ERR "mtdoops: Cannot write from panic without panic_write\n");
328 else 328 else
diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c
index af8b42e0a55b..7c003191fca4 100644
--- a/drivers/mtd/mtdsuper.c
+++ b/drivers/mtd/mtdsuper.c
@@ -13,6 +13,7 @@
13#include <linux/mtd/super.h> 13#include <linux/mtd/super.h>
14#include <linux/namei.h> 14#include <linux/namei.h>
15#include <linux/ctype.h> 15#include <linux/ctype.h>
16#include <linux/slab.h>
16 17
17/* 18/*
18 * compare superblocks to see if they're equivalent 19 * compare superblocks to see if they're equivalent
@@ -44,6 +45,7 @@ static int get_sb_mtd_set(struct super_block *sb, void *_mtd)
44 45
45 sb->s_mtd = mtd; 46 sb->s_mtd = mtd;
46 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index); 47 sb->s_dev = MKDEV(MTD_BLOCK_MAJOR, mtd->index);
48 sb->s_bdi = mtd->backing_dev_info;
47 return 0; 49 return 0;
48} 50}
49 51
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 677cd53f18c3..42e5ea49e975 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -444,7 +444,7 @@ config MTD_NAND_FSL_UPM
444 444
445config MTD_NAND_MXC 445config MTD_NAND_MXC
446 tristate "MXC NAND support" 446 tristate "MXC NAND support"
447 depends on ARCH_MX2 || ARCH_MX3 447 depends on ARCH_MX2 || ARCH_MX25 || ARCH_MX3
448 help 448 help
449 This enables the driver for the NAND flash controller on the 449 This enables the driver for the NAND flash controller on the
450 MXC processors. 450 MXC processors.
@@ -457,10 +457,10 @@ config MTD_NAND_NOMADIK
457 457
458config MTD_NAND_SH_FLCTL 458config MTD_NAND_SH_FLCTL
459 tristate "Support for NAND on Renesas SuperH FLCTL" 459 tristate "Support for NAND on Renesas SuperH FLCTL"
460 depends on MTD_NAND && SUPERH && CPU_SUBTYPE_SH7723 460 depends on MTD_NAND && (SUPERH || ARCH_SHMOBILE)
461 help 461 help
462 Several Renesas SuperH CPU has FLCTL. This option enables support 462 Several Renesas SuperH CPU has FLCTL. This option enables support
463 for NAND Flash using FLCTL. This driver support SH7723. 463 for NAND Flash using FLCTL.
464 464
465config MTD_NAND_DAVINCI 465config MTD_NAND_DAVINCI
466 tristate "Support NAND on DaVinci SoC" 466 tristate "Support NAND on DaVinci SoC"
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 92c334ff4508..43d46e424040 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -19,6 +19,7 @@
19#include <asm/io.h> 19#include <asm/io.h>
20 20
21#include <asm/mach-au1x00/au1xxx.h> 21#include <asm/mach-au1x00/au1xxx.h>
22#include <asm/mach-db1x00/bcsr.h>
22 23
23/* 24/*
24 * MTD structure for NAND controller 25 * MTD structure for NAND controller
@@ -475,7 +476,8 @@ static int __init au1xxx_nand_init(void)
475 /* set gpio206 high */ 476 /* set gpio206 high */
476 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR); 477 au_writel(au_readl(GPIO2_DIR) & ~(1 << 6), GPIO2_DIR);
477 478
478 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr->status >> 6) & 0x1); 479 boot_swapboot = (au_readl(MEM_STSTAT) & (0x7 << 1)) | ((bcsr_read(BCSR_STATUS) >> 6) & 0x1);
480
479 switch (boot_swapboot) { 481 switch (boot_swapboot) {
480 case 0: 482 case 0:
481 case 2: 483 case 2:
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index 087bcd745bb7..c997f98eeb3d 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -18,6 +18,7 @@
18#include <linux/types.h> 18#include <linux/types.h>
19#include <linux/init.h> 19#include <linux/init.h>
20#include <linux/kernel.h> 20#include <linux/kernel.h>
21#include <linux/slab.h>
21#include <linux/string.h> 22#include <linux/string.h>
22#include <linux/ioport.h> 23#include <linux/ioport.h>
23#include <linux/device.h> 24#include <linux/device.h>
@@ -381,7 +382,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
381 if (!r) 382 if (!r)
382 return -ENXIO; 383 return -ENXIO;
383 384
384 /* map physical adress */ 385 /* map physical address */
385 bcm_umi_io_base = ioremap(r->start, r->end - r->start + 1); 386 bcm_umi_io_base = ioremap(r->start, r->end - r->start + 1);
386 387
387 if (!bcm_umi_io_base) { 388 if (!bcm_umi_io_base) {
@@ -525,7 +526,7 @@ static int bcm_umi_nand_remove(struct platform_device *pdev)
525 /* Release resources, unregister device */ 526 /* Release resources, unregister device */
526 nand_release(board_mtd); 527 nand_release(board_mtd);
527 528
528 /* unmap physical adress */ 529 /* unmap physical address */
529 iounmap(bcm_umi_io_base); 530 iounmap(bcm_umi_io_base);
530 531
531 /* Free the MTD device structure */ 532 /* Free the MTD device structure */
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index c828d9ac7bd7..e5a9f9ccea60 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -20,6 +20,7 @@
20#include <linux/delay.h> 20#include <linux/delay.h>
21#include <linux/interrupt.h> 21#include <linux/interrupt.h>
22#include <linux/dma-mapping.h> 22#include <linux/dma-mapping.h>
23#include <linux/slab.h>
23#include <asm/io.h> 24#include <asm/io.h>
24 25
25#define CAFE_NAND_CTRL1 0x00 26#define CAFE_NAND_CTRL1 0x00
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 826cacffcefc..6e6495278258 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -20,6 +20,7 @@
20 20
21#include <linux/mtd/nand.h> 21#include <linux/mtd/nand.h>
22#include <linux/mtd/partitions.h> 22#include <linux/mtd/partitions.h>
23#include <linux/slab.h>
23#include <linux/gpio.h> 24#include <linux/gpio.h>
24 25
25#include <asm/io.h> 26#include <asm/io.h>
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index fe3eba87de40..76e2dc8e62f7 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -32,6 +32,7 @@
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/mtd/nand.h> 33#include <linux/mtd/nand.h>
34#include <linux/mtd/partitions.h> 34#include <linux/mtd/partitions.h>
35#include <linux/slab.h>
35 36
36#include <mach/nand.h> 37#include <mach/nand.h>
37 38
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index b126cf887476..47067bc98248 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -23,6 +23,7 @@
23#include <linux/delay.h> 23#include <linux/delay.h>
24#include <linux/rslib.h> 24#include <linux/rslib.h>
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/slab.h>
26#include <asm/io.h> 27#include <asm/io.h>
27 28
28#include <linux/mtd/mtd.h> 29#include <linux/mtd/mtd.h>
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 071a60cb4204..4b96296af321 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -21,6 +21,7 @@
21#include <linux/of_platform.h> 21#include <linux/of_platform.h>
22#include <linux/of_gpio.h> 22#include <linux/of_gpio.h>
23#include <linux/io.h> 23#include <linux/io.h>
24#include <linux/slab.h>
24#include <asm/fsl_lbc.h> 25#include <asm/fsl_lbc.h>
25 26
26#define FSL_UPM_WAIT_RUN_PATTERN 0x1 27#define FSL_UPM_WAIT_RUN_PATTERN 0x1
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 45dec5770da0..b2900d8406d3 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/ndfc.c b/drivers/mtd/nand/ndfc.c
index 40b5658bdbe6..b983cae8c298 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -28,6 +28,7 @@
28#include <linux/mtd/nand_ecc.h> 28#include <linux/mtd/nand_ecc.h>
29#include <linux/mtd/partitions.h> 29#include <linux/mtd/partitions.h>
30#include <linux/mtd/ndfc.h> 30#include <linux/mtd/ndfc.h>
31#include <linux/slab.h>
31#include <linux/mtd/mtd.h> 32#include <linux/mtd/mtd.h>
32#include <linux/of_platform.h> 33#include <linux/of_platform.h>
33#include <asm/io.h> 34#include <asm/io.h>
diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c
index 66123419f65d..1f6f741af5da 100644
--- a/drivers/mtd/nand/nomadik_nand.c
+++ b/drivers/mtd/nand/nomadik_nand.c
@@ -30,6 +30,7 @@
30#include <linux/platform_device.h> 30#include <linux/platform_device.h>
31#include <linux/mtd/partitions.h> 31#include <linux/mtd/partitions.h>
32#include <linux/io.h> 32#include <linux/io.h>
33#include <linux/slab.h>
33#include <mach/nand.h> 34#include <mach/nand.h>
34#include <mach/fsmc.h> 35#include <mach/fsmc.h>
35 36
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index 1bb799f0125c..7545568fce47 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -17,6 +17,7 @@
17#include <linux/mtd/nand.h> 17#include <linux/mtd/nand.h>
18#include <linux/mtd/partitions.h> 18#include <linux/mtd/partitions.h>
19#include <linux/io.h> 19#include <linux/io.h>
20#include <linux/slab.h>
20 21
21#include <plat/dma.h> 22#include <plat/dma.h>
22#include <plat/gpmc.h> 23#include <plat/gpmc.h>
@@ -30,12 +31,8 @@
30 31
31#define DRIVER_NAME "omap2-nand" 32#define DRIVER_NAME "omap2-nand"
32 33
33/* size (4 KiB) for IO mapping */
34#define NAND_IO_SIZE SZ_4K
35
36#define NAND_WP_OFF 0 34#define NAND_WP_OFF 0
37#define NAND_WP_BIT 0x00000010 35#define NAND_WP_BIT 0x00000010
38#define WR_RD_PIN_MONITORING 0x00600000
39 36
40#define GPMC_BUF_FULL 0x00000001 37#define GPMC_BUF_FULL 0x00000001
41#define GPMC_BUF_EMPTY 0x00000000 38#define GPMC_BUF_EMPTY 0x00000000
@@ -882,8 +879,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
882 struct omap_nand_info *info; 879 struct omap_nand_info *info;
883 struct omap_nand_platform_data *pdata; 880 struct omap_nand_platform_data *pdata;
884 int err; 881 int err;
885 unsigned long val;
886
887 882
888 pdata = pdev->dev.platform_data; 883 pdata = pdev->dev.platform_data;
889 if (pdata == NULL) { 884 if (pdata == NULL) {
@@ -905,28 +900,14 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
905 info->gpmc_cs = pdata->cs; 900 info->gpmc_cs = pdata->cs;
906 info->gpmc_baseaddr = pdata->gpmc_baseaddr; 901 info->gpmc_baseaddr = pdata->gpmc_baseaddr;
907 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr; 902 info->gpmc_cs_baseaddr = pdata->gpmc_cs_baseaddr;
903 info->phys_base = pdata->phys_base;
908 904
909 info->mtd.priv = &info->nand; 905 info->mtd.priv = &info->nand;
910 info->mtd.name = dev_name(&pdev->dev); 906 info->mtd.name = dev_name(&pdev->dev);
911 info->mtd.owner = THIS_MODULE; 907 info->mtd.owner = THIS_MODULE;
912 908
913 err = gpmc_cs_request(info->gpmc_cs, NAND_IO_SIZE, &info->phys_base); 909 info->nand.options |= pdata->devsize ? NAND_BUSWIDTH_16 : 0;
914 if (err < 0) { 910 info->nand.options |= NAND_SKIP_BBTSCAN;
915 dev_err(&pdev->dev, "Cannot request GPMC CS\n");
916 goto out_free_info;
917 }
918
919 /* Enable RD PIN Monitoring Reg */
920 if (pdata->dev_ready) {
921 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1);
922 val |= WR_RD_PIN_MONITORING;
923 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG1, val);
924 }
925
926 val = gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG7);
927 val &= ~(0xf << 8);
928 val |= (0xc & 0xf) << 8;
929 gpmc_cs_write_reg(info->gpmc_cs, GPMC_CS_CONFIG7, val);
930 911
931 /* NAND write protect off */ 912 /* NAND write protect off */
932 omap_nand_wp(&info->mtd, NAND_WP_OFF); 913 omap_nand_wp(&info->mtd, NAND_WP_OFF);
@@ -934,7 +915,7 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
934 if (!request_mem_region(info->phys_base, NAND_IO_SIZE, 915 if (!request_mem_region(info->phys_base, NAND_IO_SIZE,
935 pdev->dev.driver->name)) { 916 pdev->dev.driver->name)) {
936 err = -EBUSY; 917 err = -EBUSY;
937 goto out_free_cs; 918 goto out_free_info;
938 } 919 }
939 920
940 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE); 921 info->nand.IO_ADDR_R = ioremap(info->phys_base, NAND_IO_SIZE);
@@ -963,11 +944,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
963 info->nand.chip_delay = 50; 944 info->nand.chip_delay = 50;
964 } 945 }
965 946
966 info->nand.options |= NAND_SKIP_BBTSCAN;
967 if ((gpmc_cs_read_reg(info->gpmc_cs, GPMC_CS_CONFIG1) & 0x3000)
968 == 0x1000)
969 info->nand.options |= NAND_BUSWIDTH_16;
970
971 if (use_prefetch) { 947 if (use_prefetch) {
972 /* copy the virtual address of nand base for fifo access */ 948 /* copy the virtual address of nand base for fifo access */
973 info->nand_pref_fifo_add = info->nand.IO_ADDR_R; 949 info->nand_pref_fifo_add = info->nand.IO_ADDR_R;
@@ -1043,8 +1019,6 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1043 1019
1044out_release_mem_region: 1020out_release_mem_region:
1045 release_mem_region(info->phys_base, NAND_IO_SIZE); 1021 release_mem_region(info->phys_base, NAND_IO_SIZE);
1046out_free_cs:
1047 gpmc_cs_free(info->gpmc_cs);
1048out_free_info: 1022out_free_info:
1049 kfree(info); 1023 kfree(info);
1050 1024
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index f59c07427af3..d60fc5719fef 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -60,7 +60,13 @@ static void orion_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
60 } 60 }
61 buf64 = (uint64_t *)buf; 61 buf64 = (uint64_t *)buf;
62 while (i < len/8) { 62 while (i < len/8) {
63 uint64_t x; 63 /*
64 * Since GCC has no proper constraint (PR 43518)
65 * force x variable to r2/r3 registers as ldrd instruction
66 * requires first register to be even.
67 */
68 register uint64_t x asm ("r2");
69
64 asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base)); 70 asm volatile ("ldrd\t%0, [%1]" : "=&r" (x) : "r" (io_base));
65 buf64[i++] = x; 71 buf64[i++] = x;
66 } 72 }
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 1a5a0365c983..5d55152162cf 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -21,6 +21,7 @@
21#include <linux/mtd/partitions.h> 21#include <linux/mtd/partitions.h>
22#include <linux/io.h> 22#include <linux/io.h>
23#include <linux/irq.h> 23#include <linux/irq.h>
24#include <linux/slab.h>
24 25
25#include <mach/dma.h> 26#include <mach/dma.h>
26#include <plat/pxa3xx_nand.h> 27#include <plat/pxa3xx_nand.h>
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 02bef21f2e4b..34752fce0793 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -1,10 +1,10 @@
1/* 1/*
2 * SuperH FLCTL nand controller 2 * SuperH FLCTL nand controller
3 * 3 *
4 * Copyright © 2008 Renesas Solutions Corp. 4 * Copyright (c) 2008 Renesas Solutions Corp.
5 * Copyright © 2008 Atom Create Engineering Co., Ltd. 5 * Copyright (c) 2008 Atom Create Engineering Co., Ltd.
6 * 6 *
7 * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor 7 * Based on fsl_elbc_nand.c, Copyright (c) 2006-2007 Freescale Semiconductor
8 * 8 *
9 * This program is free software; you can redistribute it and/or modify 9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by 10 * it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
26#include <linux/delay.h> 26#include <linux/delay.h>
27#include <linux/io.h> 27#include <linux/io.h>
28#include <linux/platform_device.h> 28#include <linux/platform_device.h>
29#include <linux/slab.h>
29 30
30#include <linux/mtd/mtd.h> 31#include <linux/mtd/mtd.h>
31#include <linux/mtd/nand.h> 32#include <linux/mtd/nand.h>
@@ -75,6 +76,11 @@ static void start_translation(struct sh_flctl *flctl)
75 writeb(TRSTRT, FLTRCR(flctl)); 76 writeb(TRSTRT, FLTRCR(flctl));
76} 77}
77 78
79static void timeout_error(struct sh_flctl *flctl, const char *str)
80{
81 dev_err(&flctl->pdev->dev, "Timeout occured in %s\n", str);
82}
83
78static void wait_completion(struct sh_flctl *flctl) 84static void wait_completion(struct sh_flctl *flctl)
79{ 85{
80 uint32_t timeout = LOOP_TIMEOUT_MAX; 86 uint32_t timeout = LOOP_TIMEOUT_MAX;
@@ -87,7 +93,7 @@ static void wait_completion(struct sh_flctl *flctl)
87 udelay(1); 93 udelay(1);
88 } 94 }
89 95
90 printk(KERN_ERR "wait_completion(): Timeout occured \n"); 96 timeout_error(flctl, __func__);
91 writeb(0x0, FLTRCR(flctl)); 97 writeb(0x0, FLTRCR(flctl));
92} 98}
93 99
@@ -100,6 +106,8 @@ static void set_addr(struct mtd_info *mtd, int column, int page_addr)
100 addr = page_addr; /* ERASE1 */ 106 addr = page_addr; /* ERASE1 */
101 } else if (page_addr != -1) { 107 } else if (page_addr != -1) {
102 /* SEQIN, READ0, etc.. */ 108 /* SEQIN, READ0, etc.. */
109 if (flctl->chip.options & NAND_BUSWIDTH_16)
110 column >>= 1;
103 if (flctl->page_size) { 111 if (flctl->page_size) {
104 addr = column & 0x0FFF; 112 addr = column & 0x0FFF;
105 addr |= (page_addr & 0xff) << 16; 113 addr |= (page_addr & 0xff) << 16;
@@ -132,7 +140,7 @@ static void wait_rfifo_ready(struct sh_flctl *flctl)
132 return; 140 return;
133 udelay(1); 141 udelay(1);
134 } 142 }
135 printk(KERN_ERR "wait_rfifo_ready(): Timeout occured \n"); 143 timeout_error(flctl, __func__);
136} 144}
137 145
138static void wait_wfifo_ready(struct sh_flctl *flctl) 146static void wait_wfifo_ready(struct sh_flctl *flctl)
@@ -146,7 +154,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl)
146 return; 154 return;
147 udelay(1); 155 udelay(1);
148 } 156 }
149 printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); 157 timeout_error(flctl, __func__);
150} 158}
151 159
152static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number) 160static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
@@ -198,7 +206,7 @@ static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
198 writel(0, FL4ECCCR(flctl)); 206 writel(0, FL4ECCCR(flctl));
199 } 207 }
200 208
201 printk(KERN_ERR "wait_recfifo_ready(): Timeout occured \n"); 209 timeout_error(flctl, __func__);
202 return 1; /* timeout */ 210 return 1; /* timeout */
203} 211}
204 212
@@ -214,7 +222,7 @@ static void wait_wecfifo_ready(struct sh_flctl *flctl)
214 return; 222 return;
215 udelay(1); 223 udelay(1);
216 } 224 }
217 printk(KERN_ERR "wait_wecfifo_ready(): Timeout occured \n"); 225 timeout_error(flctl, __func__);
218} 226}
219 227
220static void read_datareg(struct sh_flctl *flctl, int offset) 228static void read_datareg(struct sh_flctl *flctl, int offset)
@@ -275,7 +283,7 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
275static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val) 283static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val)
276{ 284{
277 struct sh_flctl *flctl = mtd_to_flctl(mtd); 285 struct sh_flctl *flctl = mtd_to_flctl(mtd);
278 uint32_t flcmncr_val = readl(FLCMNCR(flctl)); 286 uint32_t flcmncr_val = readl(FLCMNCR(flctl)) & ~SEL_16BIT;
279 uint32_t flcmdcr_val, addr_len_bytes = 0; 287 uint32_t flcmdcr_val, addr_len_bytes = 0;
280 288
281 /* Set SNAND bit if page size is 2048byte */ 289 /* Set SNAND bit if page size is 2048byte */
@@ -297,6 +305,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
297 case NAND_CMD_READOOB: 305 case NAND_CMD_READOOB:
298 addr_len_bytes = flctl->rw_ADRCNT; 306 addr_len_bytes = flctl->rw_ADRCNT;
299 flcmdcr_val |= CDSRC_E; 307 flcmdcr_val |= CDSRC_E;
308 if (flctl->chip.options & NAND_BUSWIDTH_16)
309 flcmncr_val |= SEL_16BIT;
300 break; 310 break;
301 case NAND_CMD_SEQIN: 311 case NAND_CMD_SEQIN:
302 /* This case is that cmd is READ0 or READ1 or READ00 */ 312 /* This case is that cmd is READ0 or READ1 or READ00 */
@@ -305,6 +315,8 @@ static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_va
305 case NAND_CMD_PAGEPROG: 315 case NAND_CMD_PAGEPROG:
306 addr_len_bytes = flctl->rw_ADRCNT; 316 addr_len_bytes = flctl->rw_ADRCNT;
307 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW; 317 flcmdcr_val |= DOCMD2_E | CDSRC_E | SELRW;
318 if (flctl->chip.options & NAND_BUSWIDTH_16)
319 flcmncr_val |= SEL_16BIT;
308 break; 320 break;
309 case NAND_CMD_READID: 321 case NAND_CMD_READID:
310 flcmncr_val &= ~SNAND_E; 322 flcmncr_val &= ~SNAND_E;
@@ -523,6 +535,8 @@ static void flctl_cmdfunc(struct mtd_info *mtd, unsigned int command,
523 set_addr(mtd, 0, page_addr); 535 set_addr(mtd, 0, page_addr);
524 536
525 flctl->read_bytes = mtd->writesize + mtd->oobsize; 537 flctl->read_bytes = mtd->writesize + mtd->oobsize;
538 if (flctl->chip.options & NAND_BUSWIDTH_16)
539 column >>= 1;
526 flctl->index += column; 540 flctl->index += column;
527 goto read_normal_exit; 541 goto read_normal_exit;
528 542
@@ -686,6 +700,18 @@ static uint8_t flctl_read_byte(struct mtd_info *mtd)
686 return data; 700 return data;
687} 701}
688 702
703static uint16_t flctl_read_word(struct mtd_info *mtd)
704{
705 struct sh_flctl *flctl = mtd_to_flctl(mtd);
706 int index = flctl->index;
707 uint16_t data;
708 uint16_t *buf = (uint16_t *)&flctl->done_buff[index];
709
710 data = *buf;
711 flctl->index += 2;
712 return data;
713}
714
689static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 715static void flctl_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
690{ 716{
691 int i; 717 int i;
@@ -769,38 +795,36 @@ static int flctl_chip_init_tail(struct mtd_info *mtd)
769 return 0; 795 return 0;
770} 796}
771 797
772static int __init flctl_probe(struct platform_device *pdev) 798static int __devinit flctl_probe(struct platform_device *pdev)
773{ 799{
774 struct resource *res; 800 struct resource *res;
775 struct sh_flctl *flctl; 801 struct sh_flctl *flctl;
776 struct mtd_info *flctl_mtd; 802 struct mtd_info *flctl_mtd;
777 struct nand_chip *nand; 803 struct nand_chip *nand;
778 struct sh_flctl_platform_data *pdata; 804 struct sh_flctl_platform_data *pdata;
779 int ret; 805 int ret = -ENXIO;
780 806
781 pdata = pdev->dev.platform_data; 807 pdata = pdev->dev.platform_data;
782 if (pdata == NULL) { 808 if (pdata == NULL) {
783 printk(KERN_ERR "sh_flctl platform_data not found.\n"); 809 dev_err(&pdev->dev, "no platform data defined\n");
784 return -ENODEV; 810 return -EINVAL;
785 } 811 }
786 812
787 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL); 813 flctl = kzalloc(sizeof(struct sh_flctl), GFP_KERNEL);
788 if (!flctl) { 814 if (!flctl) {
789 printk(KERN_ERR "Unable to allocate NAND MTD dev structure.\n"); 815 dev_err(&pdev->dev, "failed to allocate driver data\n");
790 return -ENOMEM; 816 return -ENOMEM;
791 } 817 }
792 818
793 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 819 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
794 if (!res) { 820 if (!res) {
795 printk(KERN_ERR "%s: resource not found.\n", __func__); 821 dev_err(&pdev->dev, "failed to get I/O memory\n");
796 ret = -ENODEV;
797 goto err; 822 goto err;
798 } 823 }
799 824
800 flctl->reg = ioremap(res->start, res->end - res->start + 1); 825 flctl->reg = ioremap(res->start, resource_size(res));
801 if (flctl->reg == NULL) { 826 if (flctl->reg == NULL) {
802 printk(KERN_ERR "%s: ioremap error.\n", __func__); 827 dev_err(&pdev->dev, "failed to remap I/O memory\n");
803 ret = -ENOMEM;
804 goto err; 828 goto err;
805 } 829 }
806 830
@@ -808,6 +832,7 @@ static int __init flctl_probe(struct platform_device *pdev)
808 flctl_mtd = &flctl->mtd; 832 flctl_mtd = &flctl->mtd;
809 nand = &flctl->chip; 833 nand = &flctl->chip;
810 flctl_mtd->priv = nand; 834 flctl_mtd->priv = nand;
835 flctl->pdev = pdev;
811 flctl->hwecc = pdata->has_hwecc; 836 flctl->hwecc = pdata->has_hwecc;
812 837
813 flctl_register_init(flctl, pdata->flcmncr_val); 838 flctl_register_init(flctl, pdata->flcmncr_val);
@@ -825,6 +850,11 @@ static int __init flctl_probe(struct platform_device *pdev)
825 nand->select_chip = flctl_select_chip; 850 nand->select_chip = flctl_select_chip;
826 nand->cmdfunc = flctl_cmdfunc; 851 nand->cmdfunc = flctl_cmdfunc;
827 852
853 if (pdata->flcmncr_val & SEL_16BIT) {
854 nand->options |= NAND_BUSWIDTH_16;
855 nand->read_word = flctl_read_word;
856 }
857
828 ret = nand_scan_ident(flctl_mtd, 1); 858 ret = nand_scan_ident(flctl_mtd, 1);
829 if (ret) 859 if (ret)
830 goto err; 860 goto err;
@@ -846,7 +876,7 @@ err:
846 return ret; 876 return ret;
847} 877}
848 878
849static int __exit flctl_remove(struct platform_device *pdev) 879static int __devexit flctl_remove(struct platform_device *pdev)
850{ 880{
851 struct sh_flctl *flctl = platform_get_drvdata(pdev); 881 struct sh_flctl *flctl = platform_get_drvdata(pdev);
852 882
diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index 92c73344a669..fa28f01ae009 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -37,6 +37,7 @@
37#include <linux/mtd/nand.h> 37#include <linux/mtd/nand.h>
38#include <linux/mtd/nand_ecc.h> 38#include <linux/mtd/nand_ecc.h>
39#include <linux/mtd/partitions.h> 39#include <linux/mtd/partitions.h>
40#include <linux/slab.h>
40 41
41/*--------------------------------------------------------------------------*/ 42/*--------------------------------------------------------------------------*/
42 43
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index 62d6a78c4eee..4f0d635674f3 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -17,6 +17,7 @@
17#include <linux/init.h> 17#include <linux/init.h>
18#include <linux/of.h> 18#include <linux/of.h>
19#include <linux/mtd/mtd.h> 19#include <linux/mtd/mtd.h>
20#include <linux/slab.h>
20#include <linux/mtd/partitions.h> 21#include <linux/mtd/partitions.h>
21 22
22int __devinit of_mtd_parse_partitions(struct device *dev, 23int __devinit of_mtd_parse_partitions(struct device *dev,
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
index 75f38b95811e..fd406348fdfd 100644
--- a/drivers/mtd/onenand/omap2.c
+++ b/drivers/mtd/onenand/omap2.c
@@ -34,6 +34,7 @@
34#include <linux/delay.h> 34#include <linux/delay.h>
35#include <linux/dma-mapping.h> 35#include <linux/dma-mapping.h>
36#include <linux/io.h> 36#include <linux/io.h>
37#include <linux/slab.h>
37 38
38#include <asm/mach/flash.h> 39#include <asm/mach/flash.h>
39#include <plat/gpmc.h> 40#include <plat/gpmc.h>
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index f63b1db3ffb3..32f0ed33afe0 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -23,6 +23,7 @@
23#include <linux/kernel.h> 23#include <linux/kernel.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/slab.h>
26#include <linux/init.h> 27#include <linux/init.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28#include <linux/delay.h> 29#include <linux/delay.h>
diff --git a/drivers/mtd/onenand/onenand_sim.c b/drivers/mtd/onenand/onenand_sim.c
index f6e3c8aebd3a..8b246061d511 100644
--- a/drivers/mtd/onenand/onenand_sim.c
+++ b/drivers/mtd/onenand/onenand_sim.c
@@ -16,6 +16,7 @@
16 */ 16 */
17 17
18#include <linux/kernel.h> 18#include <linux/kernel.h>
19#include <linux/slab.h>
19#include <linux/module.h> 20#include <linux/module.h>
20#include <linux/init.h> 21#include <linux/init.h>
21#include <linux/vmalloc.h> 22#include <linux/vmalloc.h>
diff --git a/drivers/mtd/tests/mtd_nandecctest.c b/drivers/mtd/tests/mtd_nandecctest.c
index c1f31051784c..70d6d7d0d656 100644
--- a/drivers/mtd/tests/mtd_nandecctest.c
+++ b/drivers/mtd/tests/mtd_nandecctest.c
@@ -1,7 +1,6 @@
1#include <linux/kernel.h> 1#include <linux/kernel.h>
2#include <linux/module.h> 2#include <linux/module.h>
3#include <linux/list.h> 3#include <linux/list.h>
4#include <linux/slab.h>
5#include <linux/random.h> 4#include <linux/random.h>
6#include <linux/string.h> 5#include <linux/string.h>
7#include <linux/bitops.h> 6#include <linux/bitops.h>
diff --git a/drivers/mtd/tests/mtd_oobtest.c b/drivers/mtd/tests/mtd_oobtest.c
index 5813920e79a5..dec92ae6111a 100644
--- a/drivers/mtd/tests/mtd_oobtest.c
+++ b/drivers/mtd/tests/mtd_oobtest.c
@@ -25,6 +25,7 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
28#include <linux/slab.h>
28#include <linux/sched.h> 29#include <linux/sched.h>
29 30
30#define PRINT_PREF KERN_INFO "mtd_oobtest: " 31#define PRINT_PREF KERN_INFO "mtd_oobtest: "
diff --git a/drivers/mtd/tests/mtd_pagetest.c b/drivers/mtd/tests/mtd_pagetest.c
index ce17cbe918c5..921a85df9196 100644
--- a/drivers/mtd/tests/mtd_pagetest.c
+++ b/drivers/mtd/tests/mtd_pagetest.c
@@ -25,6 +25,7 @@
25#include <linux/moduleparam.h> 25#include <linux/moduleparam.h>
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/mtd/mtd.h> 27#include <linux/mtd/mtd.h>
28#include <linux/slab.h>
28#include <linux/sched.h> 29#include <linux/sched.h>
29 30
30#define PRINT_PREF KERN_INFO "mtd_pagetest: " 31#define PRINT_PREF KERN_INFO "mtd_pagetest: "
diff --git a/drivers/mtd/tests/mtd_readtest.c b/drivers/mtd/tests/mtd_readtest.c
index 79fc4530987b..7107fccbc7de 100644
--- a/drivers/mtd/tests/mtd_readtest.c
+++ b/drivers/mtd/tests/mtd_readtest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_readtest: " 30#define PRINT_PREF KERN_INFO "mtd_readtest: "
@@ -147,6 +148,10 @@ static int scan_for_bad_eraseblocks(void)
147 } 148 }
148 memset(bbt, 0 , ebcnt); 149 memset(bbt, 0 , ebcnt);
149 150
151 /* NOR flash does not implement block_isbad */
152 if (mtd->block_isbad == NULL)
153 return 0;
154
150 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 155 printk(PRINT_PREF "scanning for bad eraseblocks\n");
151 for (i = 0; i < ebcnt; ++i) { 156 for (i = 0; i < ebcnt; ++i) {
152 bbt[i] = is_block_bad(i) ? 1 : 0; 157 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -184,7 +189,7 @@ static int __init mtd_readtest_init(void)
184 tmp = mtd->size; 189 tmp = mtd->size;
185 do_div(tmp, mtd->erasesize); 190 do_div(tmp, mtd->erasesize);
186 ebcnt = tmp; 191 ebcnt = tmp;
187 pgcnt = mtd->erasesize / mtd->writesize; 192 pgcnt = mtd->erasesize / pgsize;
188 193
189 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 194 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
190 "page size %u, count of eraseblocks %u, pages per " 195 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_speedtest.c b/drivers/mtd/tests/mtd_speedtest.c
index 141363a7e805..56ca62bb96bf 100644
--- a/drivers/mtd/tests/mtd_speedtest.c
+++ b/drivers/mtd/tests/mtd_speedtest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_speedtest: " 30#define PRINT_PREF KERN_INFO "mtd_speedtest: "
@@ -301,6 +302,10 @@ static int scan_for_bad_eraseblocks(void)
301 } 302 }
302 memset(bbt, 0 , ebcnt); 303 memset(bbt, 0 , ebcnt);
303 304
305 /* NOR flash does not implement block_isbad */
306 if (mtd->block_isbad == NULL)
307 goto out;
308
304 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 309 printk(PRINT_PREF "scanning for bad eraseblocks\n");
305 for (i = 0; i < ebcnt; ++i) { 310 for (i = 0; i < ebcnt; ++i) {
306 bbt[i] = is_block_bad(i) ? 1 : 0; 311 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -309,6 +314,7 @@ static int scan_for_bad_eraseblocks(void)
309 cond_resched(); 314 cond_resched();
310 } 315 }
311 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad); 316 printk(PRINT_PREF "scanned %d eraseblocks, %d are bad\n", i, bad);
317out:
312 goodebcnt = ebcnt - bad; 318 goodebcnt = ebcnt - bad;
313 return 0; 319 return 0;
314} 320}
@@ -340,7 +346,7 @@ static int __init mtd_speedtest_init(void)
340 tmp = mtd->size; 346 tmp = mtd->size;
341 do_div(tmp, mtd->erasesize); 347 do_div(tmp, mtd->erasesize);
342 ebcnt = tmp; 348 ebcnt = tmp;
343 pgcnt = mtd->erasesize / mtd->writesize; 349 pgcnt = mtd->erasesize / pgsize;
344 350
345 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 351 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
346 "page size %u, count of eraseblocks %u, pages per " 352 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_stresstest.c b/drivers/mtd/tests/mtd_stresstest.c
index 63920476b57a..3854afec56d0 100644
--- a/drivers/mtd/tests/mtd_stresstest.c
+++ b/drivers/mtd/tests/mtd_stresstest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28#include <linux/vmalloc.h> 29#include <linux/vmalloc.h>
29 30
@@ -227,6 +228,10 @@ static int scan_for_bad_eraseblocks(void)
227 } 228 }
228 memset(bbt, 0 , ebcnt); 229 memset(bbt, 0 , ebcnt);
229 230
231 /* NOR flash does not implement block_isbad */
232 if (mtd->block_isbad == NULL)
233 return 0;
234
230 printk(PRINT_PREF "scanning for bad eraseblocks\n"); 235 printk(PRINT_PREF "scanning for bad eraseblocks\n");
231 for (i = 0; i < ebcnt; ++i) { 236 for (i = 0; i < ebcnt; ++i) {
232 bbt[i] = is_block_bad(i) ? 1 : 0; 237 bbt[i] = is_block_bad(i) ? 1 : 0;
@@ -265,7 +270,7 @@ static int __init mtd_stresstest_init(void)
265 tmp = mtd->size; 270 tmp = mtd->size;
266 do_div(tmp, mtd->erasesize); 271 do_div(tmp, mtd->erasesize);
267 ebcnt = tmp; 272 ebcnt = tmp;
268 pgcnt = mtd->erasesize / mtd->writesize; 273 pgcnt = mtd->erasesize / pgsize;
269 274
270 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, " 275 printk(PRINT_PREF "MTD device size %llu, eraseblock size %u, "
271 "page size %u, count of eraseblocks %u, pages per " 276 "page size %u, count of eraseblocks %u, pages per "
diff --git a/drivers/mtd/tests/mtd_subpagetest.c b/drivers/mtd/tests/mtd_subpagetest.c
index 5b889724268e..700237a3d120 100644
--- a/drivers/mtd/tests/mtd_subpagetest.c
+++ b/drivers/mtd/tests/mtd_subpagetest.c
@@ -24,6 +24,7 @@
24#include <linux/moduleparam.h> 24#include <linux/moduleparam.h>
25#include <linux/err.h> 25#include <linux/err.h>
26#include <linux/mtd/mtd.h> 26#include <linux/mtd/mtd.h>
27#include <linux/slab.h>
27#include <linux/sched.h> 28#include <linux/sched.h>
28 29
29#define PRINT_PREF KERN_INFO "mtd_subpagetest: " 30#define PRINT_PREF KERN_INFO "mtd_subpagetest: "
diff --git a/drivers/mtd/tests/mtd_torturetest.c b/drivers/mtd/tests/mtd_torturetest.c
index 631a0ab3a33c..5c6c3d248901 100644
--- a/drivers/mtd/tests/mtd_torturetest.c
+++ b/drivers/mtd/tests/mtd_torturetest.c
@@ -28,6 +28,7 @@
28#include <linux/moduleparam.h> 28#include <linux/moduleparam.h>
29#include <linux/err.h> 29#include <linux/err.h>
30#include <linux/mtd/mtd.h> 30#include <linux/mtd/mtd.h>
31#include <linux/slab.h>
31#include <linux/sched.h> 32#include <linux/sched.h>
32 33
33#define PRINT_PREF KERN_INFO "mtd_torturetest: " 34#define PRINT_PREF KERN_INFO "mtd_torturetest: "
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 14cec04c34f9..55c726dde942 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -37,12 +37,14 @@
37#include <linux/module.h> 37#include <linux/module.h>
38#include <linux/moduleparam.h> 38#include <linux/moduleparam.h>
39#include <linux/stringify.h> 39#include <linux/stringify.h>
40#include <linux/namei.h>
40#include <linux/stat.h> 41#include <linux/stat.h>
41#include <linux/miscdevice.h> 42#include <linux/miscdevice.h>
42#include <linux/log2.h> 43#include <linux/log2.h>
43#include <linux/kthread.h> 44#include <linux/kthread.h>
44#include <linux/reboot.h> 45#include <linux/reboot.h>
45#include <linux/kernel.h> 46#include <linux/kernel.h>
47#include <linux/slab.h>
46#include "ubi.h" 48#include "ubi.h"
47 49
48/* Maximum length of the 'mtd=' parameter */ 50/* Maximum length of the 'mtd=' parameter */
@@ -50,7 +52,8 @@
50 52
51/** 53/**
52 * struct mtd_dev_param - MTD device parameter description data structure. 54 * struct mtd_dev_param - MTD device parameter description data structure.
53 * @name: MTD device name or number string 55 * @name: MTD character device node path, MTD device name, or MTD device number
56 * string
54 * @vid_hdr_offs: VID header offset 57 * @vid_hdr_offs: VID header offset
55 */ 58 */
56struct mtd_dev_param { 59struct mtd_dev_param {
@@ -59,10 +62,10 @@ struct mtd_dev_param {
59}; 62};
60 63
61/* Numbers of elements set in the @mtd_dev_param array */ 64/* Numbers of elements set in the @mtd_dev_param array */
62static int mtd_devs; 65static int __initdata mtd_devs;
63 66
64/* MTD devices specification parameters */ 67/* MTD devices specification parameters */
65static struct mtd_dev_param mtd_dev_param[UBI_MAX_DEVICES]; 68static struct mtd_dev_param __initdata mtd_dev_param[UBI_MAX_DEVICES];
66 69
67/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */ 70/* Root UBI "class" object (corresponds to '/<sysfs>/class/ubi/') */
68struct class *ubi_class; 71struct class *ubi_class;
@@ -87,7 +90,8 @@ DEFINE_MUTEX(ubi_devices_mutex);
87static DEFINE_SPINLOCK(ubi_devices_lock); 90static DEFINE_SPINLOCK(ubi_devices_lock);
88 91
89/* "Show" method for files in '/<sysfs>/class/ubi/' */ 92/* "Show" method for files in '/<sysfs>/class/ubi/' */
90static ssize_t ubi_version_show(struct class *class, char *buf) 93static ssize_t ubi_version_show(struct class *class, struct class_attribute *attr,
94 char *buf)
91{ 95{
92 return sprintf(buf, "%d\n", UBI_VERSION); 96 return sprintf(buf, "%d\n", UBI_VERSION);
93} 97}
@@ -363,11 +367,13 @@ static void dev_release(struct device *dev)
363/** 367/**
364 * ubi_sysfs_init - initialize sysfs for an UBI device. 368 * ubi_sysfs_init - initialize sysfs for an UBI device.
365 * @ubi: UBI device description object 369 * @ubi: UBI device description object
370 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
371 * taken
366 * 372 *
367 * This function returns zero in case of success and a negative error code in 373 * This function returns zero in case of success and a negative error code in
368 * case of failure. 374 * case of failure.
369 */ 375 */
370static int ubi_sysfs_init(struct ubi_device *ubi) 376static int ubi_sysfs_init(struct ubi_device *ubi, int *ref)
371{ 377{
372 int err; 378 int err;
373 379
@@ -379,6 +385,7 @@ static int ubi_sysfs_init(struct ubi_device *ubi)
379 if (err) 385 if (err)
380 return err; 386 return err;
381 387
388 *ref = 1;
382 err = device_create_file(&ubi->dev, &dev_eraseblock_size); 389 err = device_create_file(&ubi->dev, &dev_eraseblock_size);
383 if (err) 390 if (err)
384 return err; 391 return err;
@@ -434,7 +441,7 @@ static void ubi_sysfs_close(struct ubi_device *ubi)
434} 441}
435 442
436/** 443/**
437 * kill_volumes - destroy all volumes. 444 * kill_volumes - destroy all user volumes.
438 * @ubi: UBI device description object 445 * @ubi: UBI device description object
439 */ 446 */
440static void kill_volumes(struct ubi_device *ubi) 447static void kill_volumes(struct ubi_device *ubi)
@@ -447,36 +454,29 @@ static void kill_volumes(struct ubi_device *ubi)
447} 454}
448 455
449/** 456/**
450 * free_user_volumes - free all user volumes.
451 * @ubi: UBI device description object
452 *
453 * Normally the volumes are freed at the release function of the volume device
454 * objects. However, on error paths the volumes have to be freed before the
455 * device objects have been initialized.
456 */
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. 457 * uif_init - initialize user interfaces for an UBI device.
470 * @ubi: UBI device description object 458 * @ubi: UBI device description object
459 * @ref: set to %1 on exit in case of failure if a reference to @ubi->dev was
460 * taken, otherwise set to %0
461 *
462 * This function initializes various user interfaces for an UBI device. If the
463 * initialization fails at an early stage, this function frees all the
464 * resources it allocated, returns an error, and @ref is set to %0. However,
465 * if the initialization fails after the UBI device was registered in the
466 * driver core subsystem, this function takes a reference to @ubi->dev, because
467 * otherwise the release function ('dev_release()') would free whole @ubi
468 * object. The @ref argument is set to %1 in this case. The caller has to put
469 * this reference.
471 * 470 *
472 * This function returns zero in case of success and a negative error code in 471 * This function returns zero in case of success and a negative error code in
473 * case of failure. Note, this function destroys all volumes if it fails. 472 * case of failure.
474 */ 473 */
475static int uif_init(struct ubi_device *ubi) 474static int uif_init(struct ubi_device *ubi, int *ref)
476{ 475{
477 int i, err; 476 int i, err;
478 dev_t dev; 477 dev_t dev;
479 478
479 *ref = 0;
480 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num); 480 sprintf(ubi->ubi_name, UBI_NAME_STR "%d", ubi->ubi_num);
481 481
482 /* 482 /*
@@ -504,7 +504,7 @@ static int uif_init(struct ubi_device *ubi)
504 goto out_unreg; 504 goto out_unreg;
505 } 505 }
506 506
507 err = ubi_sysfs_init(ubi); 507 err = ubi_sysfs_init(ubi, ref);
508 if (err) 508 if (err)
509 goto out_sysfs; 509 goto out_sysfs;
510 510
@@ -522,6 +522,8 @@ static int uif_init(struct ubi_device *ubi)
522out_volumes: 522out_volumes:
523 kill_volumes(ubi); 523 kill_volumes(ubi);
524out_sysfs: 524out_sysfs:
525 if (*ref)
526 get_device(&ubi->dev);
525 ubi_sysfs_close(ubi); 527 ubi_sysfs_close(ubi);
526 cdev_del(&ubi->cdev); 528 cdev_del(&ubi->cdev);
527out_unreg: 529out_unreg:
@@ -875,7 +877,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) 877int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
876{ 878{
877 struct ubi_device *ubi; 879 struct ubi_device *ubi;
878 int i, err, do_free = 1; 880 int i, err, ref = 0;
879 881
880 /* 882 /*
881 * Check if we already have the same MTD device attached. 883 * Check if we already have the same MTD device attached.
@@ -975,9 +977,9 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
975 goto out_detach; 977 goto out_detach;
976 } 978 }
977 979
978 err = uif_init(ubi); 980 err = uif_init(ubi, &ref);
979 if (err) 981 if (err)
980 goto out_nofree; 982 goto out_detach;
981 983
982 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name); 984 ubi->bgt_thread = kthread_create(ubi_thread, ubi, ubi->bgt_name);
983 if (IS_ERR(ubi->bgt_thread)) { 985 if (IS_ERR(ubi->bgt_thread)) {
@@ -1025,12 +1027,8 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
1025 1027
1026out_uif: 1028out_uif:
1027 uif_close(ubi); 1029 uif_close(ubi);
1028out_nofree:
1029 do_free = 0;
1030out_detach: 1030out_detach:
1031 ubi_wl_close(ubi); 1031 ubi_wl_close(ubi);
1032 if (do_free)
1033 free_user_volumes(ubi);
1034 free_internal_volumes(ubi); 1032 free_internal_volumes(ubi);
1035 vfree(ubi->vtbl); 1033 vfree(ubi->vtbl);
1036out_free: 1034out_free:
@@ -1039,7 +1037,10 @@ out_free:
1039#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 1037#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
1040 vfree(ubi->dbg_peb_buf); 1038 vfree(ubi->dbg_peb_buf);
1041#endif 1039#endif
1042 kfree(ubi); 1040 if (ref)
1041 put_device(&ubi->dev);
1042 else
1043 kfree(ubi);
1043 return err; 1044 return err;
1044} 1045}
1045 1046
@@ -1096,7 +1097,7 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1096 1097
1097 /* 1098 /*
1098 * Get a reference to the device in order to prevent 'dev_release()' 1099 * Get a reference to the device in order to prevent 'dev_release()'
1099 * from freeing @ubi object. 1100 * from freeing the @ubi object.
1100 */ 1101 */
1101 get_device(&ubi->dev); 1102 get_device(&ubi->dev);
1102 1103
@@ -1116,13 +1117,50 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
1116} 1117}
1117 1118
1118/** 1119/**
1119 * find_mtd_device - open an MTD device by its name or number. 1120 * open_mtd_by_chdev - open an MTD device by its character device node path.
1120 * @mtd_dev: name or number of the device 1121 * @mtd_dev: MTD character device node path
1122 *
1123 * This helper function opens an MTD device by its character node device path.
1124 * Returns MTD device description object in case of success and a negative
1125 * error code in case of failure.
1126 */
1127static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
1128{
1129 int err, major, minor, mode;
1130 struct path path;
1131
1132 /* Probably this is an MTD character device node path */
1133 err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
1134 if (err)
1135 return ERR_PTR(err);
1136
1137 /* MTD device number is defined by the major / minor numbers */
1138 major = imajor(path.dentry->d_inode);
1139 minor = iminor(path.dentry->d_inode);
1140 mode = path.dentry->d_inode->i_mode;
1141 path_put(&path);
1142 if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
1143 return ERR_PTR(-EINVAL);
1144
1145 if (minor & 1)
1146 /*
1147 * Just do not think the "/dev/mtdrX" devices support is need,
1148 * so do not support them to avoid doing extra work.
1149 */
1150 return ERR_PTR(-EINVAL);
1151
1152 return get_mtd_device(NULL, minor / 2);
1153}
1154
1155/**
1156 * open_mtd_device - open MTD device by name, character device path, or number.
1157 * @mtd_dev: name, character device node path, or MTD device device number
1121 * 1158 *
1122 * This function tries to open and MTD device described by @mtd_dev string, 1159 * This function tries to open and MTD device described by @mtd_dev string,
1123 * which is first treated as an ASCII number, and if it is not true, it is 1160 * which is first treated as ASCII MTD device number, and if it is not true, it
1124 * treated as MTD device name. Returns MTD device description object in case of 1161 * is treated as MTD device name, and if that is also not true, it is treated
1125 * success and a negative error code in case of failure. 1162 * as MTD character device node path. Returns MTD device description object in
1163 * case of success and a negative error code in case of failure.
1126 */ 1164 */
1127static struct mtd_info * __init open_mtd_device(const char *mtd_dev) 1165static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1128{ 1166{
@@ -1137,6 +1175,9 @@ static struct mtd_info * __init open_mtd_device(const char *mtd_dev)
1137 * MTD device name. 1175 * MTD device name.
1138 */ 1176 */
1139 mtd = get_mtd_device_nm(mtd_dev); 1177 mtd = get_mtd_device_nm(mtd_dev);
1178 if (IS_ERR(mtd) && PTR_ERR(mtd) == -ENODEV)
1179 /* Probably this is an MTD character device node path */
1180 mtd = open_mtd_by_chdev(mtd_dev);
1140 } else 1181 } else
1141 mtd = get_mtd_device(NULL, mtd_num); 1182 mtd = get_mtd_device(NULL, mtd_num);
1142 1183
@@ -1352,13 +1393,15 @@ static int __init ubi_mtd_param_parse(const char *val, struct kernel_param *kp)
1352 1393
1353module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000); 1394module_param_call(mtd, ubi_mtd_param_parse, NULL, NULL, 000);
1354MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: " 1395MODULE_PARM_DESC(mtd, "MTD devices to attach. Parameter format: "
1355 "mtd=<name|num>[,<vid_hdr_offs>].\n" 1396 "mtd=<name|num|path>[,<vid_hdr_offs>].\n"
1356 "Multiple \"mtd\" parameters may be specified.\n" 1397 "Multiple \"mtd\" parameters may be specified.\n"
1357 "MTD devices may be specified by their number or name.\n" 1398 "MTD devices may be specified by their number, name, or "
1399 "path to the MTD character device node.\n"
1358 "Optional \"vid_hdr_offs\" parameter specifies UBI VID " 1400 "Optional \"vid_hdr_offs\" parameter specifies UBI VID "
1359 "header position and data starting position to be used " 1401 "header position to be used by UBI.\n"
1360 "by UBI.\n" 1402 "Example 1: mtd=/dev/mtd0 - attach MTD device "
1361 "Example: mtd=content,1984 mtd=4 - attach MTD device" 1403 "/dev/mtd0.\n"
1404 "Example 2: mtd=content,1984 mtd=4 - attach MTD device "
1362 "with name \"content\" using VID header offset 1984, and " 1405 "with name \"content\" using VID header offset 1984, and "
1363 "MTD device number 4 with default VID header offset."); 1406 "MTD device number 4 with default VID header offset.");
1364 1407
diff --git a/drivers/mtd/ubi/cdev.c b/drivers/mtd/ubi/cdev.c
index f237ddbb2713..72ebb3f06b86 100644
--- a/drivers/mtd/ubi/cdev.c
+++ b/drivers/mtd/ubi/cdev.c
@@ -37,6 +37,7 @@
37 37
38#include <linux/module.h> 38#include <linux/module.h>
39#include <linux/stat.h> 39#include <linux/stat.h>
40#include <linux/slab.h>
40#include <linux/ioctl.h> 41#include <linux/ioctl.h>
41#include <linux/capability.h> 42#include <linux/capability.h>
42#include <linux/uaccess.h> 43#include <linux/uaccess.h>
@@ -853,7 +854,6 @@ static long ubi_cdev_ioctl(struct file *file, unsigned int cmd,
853 break; 854 break;
854 } 855 }
855 856
856 req.name[req.name_len] = '\0';
857 err = verify_mkvol_req(ubi, &req); 857 err = verify_mkvol_req(ubi, &req);
858 if (err) 858 if (err)
859 break; 859 break;
diff --git a/drivers/mtd/ubi/debug.h b/drivers/mtd/ubi/debug.h
index f30bcb372c05..17a107129726 100644
--- a/drivers/mtd/ubi/debug.h
+++ b/drivers/mtd/ubi/debug.h
@@ -96,8 +96,11 @@ void ubi_dbg_dump_flash(struct ubi_device *ubi, int pnum, int offset, int len);
96 96
97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 97#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
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/gluebi.c b/drivers/mtd/ubi/gluebi.c
index b5e478fa2661..9aa81584c8a2 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -31,6 +31,7 @@
31 31
32#include <linux/err.h> 32#include <linux/err.h>
33#include <linux/list.h> 33#include <linux/list.h>
34#include <linux/slab.h>
34#include <linux/sched.h> 35#include <linux/sched.h>
35#include <linux/math64.h> 36#include <linux/math64.h>
36#include <linux/module.h> 37#include <linux/module.h>
diff --git a/drivers/mtd/ubi/io.c b/drivers/mtd/ubi/io.c
index 8aa51e7a6a7d..533b1a4b9af1 100644
--- a/drivers/mtd/ubi/io.c
+++ b/drivers/mtd/ubi/io.c
@@ -88,6 +88,7 @@
88 88
89#include <linux/crc32.h> 89#include <linux/crc32.h>
90#include <linux/err.h> 90#include <linux/err.h>
91#include <linux/slab.h>
91#include "ubi.h" 92#include "ubi.h"
92 93
93#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 94#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -143,7 +144,7 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
143 144
144 err = paranoid_check_not_bad(ubi, pnum); 145 err = paranoid_check_not_bad(ubi, pnum);
145 if (err) 146 if (err)
146 return err > 0 ? -EINVAL : err; 147 return err;
147 148
148 addr = (loff_t)pnum * ubi->peb_size + offset; 149 addr = (loff_t)pnum * ubi->peb_size + offset;
149retry: 150retry:
@@ -236,12 +237,12 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
236 237
237 err = paranoid_check_not_bad(ubi, pnum); 238 err = paranoid_check_not_bad(ubi, pnum);
238 if (err) 239 if (err)
239 return err > 0 ? -EINVAL : err; 240 return err;
240 241
241 /* The area we are writing to has to contain all 0xFF bytes */ 242 /* The area we are writing to has to contain all 0xFF bytes */
242 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len); 243 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
243 if (err) 244 if (err)
244 return err > 0 ? -EINVAL : err; 245 return err;
245 246
246 if (offset >= ubi->leb_start) { 247 if (offset >= ubi->leb_start) {
247 /* 248 /*
@@ -250,10 +251,10 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
250 */ 251 */
251 err = paranoid_check_peb_ec_hdr(ubi, pnum); 252 err = paranoid_check_peb_ec_hdr(ubi, pnum);
252 if (err) 253 if (err)
253 return err > 0 ? -EINVAL : err; 254 return err;
254 err = paranoid_check_peb_vid_hdr(ubi, pnum); 255 err = paranoid_check_peb_vid_hdr(ubi, pnum);
255 if (err) 256 if (err)
256 return err > 0 ? -EINVAL : err; 257 return err;
257 } 258 }
258 259
259 if (ubi_dbg_is_write_failure()) { 260 if (ubi_dbg_is_write_failure()) {
@@ -273,6 +274,21 @@ int ubi_io_write(struct ubi_device *ubi, const void *buf, int pnum, int offset,
273 } else 274 } else
274 ubi_assert(written == len); 275 ubi_assert(written == len);
275 276
277 if (!err) {
278 err = ubi_dbg_check_write(ubi, buf, pnum, offset, len);
279 if (err)
280 return err;
281
282 /*
283 * Since we always write sequentially, the rest of the PEB has
284 * to contain only 0xFF bytes.
285 */
286 offset += len;
287 len = ubi->peb_size - offset;
288 if (len)
289 err = ubi_dbg_check_all_ff(ubi, pnum, offset, len);
290 }
291
276 return err; 292 return err;
277} 293}
278 294
@@ -348,7 +364,7 @@ retry:
348 364
349 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size); 365 err = ubi_dbg_check_all_ff(ubi, pnum, 0, ubi->peb_size);
350 if (err) 366 if (err)
351 return err > 0 ? -EINVAL : err; 367 return err;
352 368
353 if (ubi_dbg_is_erase_failure() && !err) { 369 if (ubi_dbg_is_erase_failure() && !err) {
354 dbg_err("cannot erase PEB %d (emulated)", pnum); 370 dbg_err("cannot erase PEB %d (emulated)", pnum);
@@ -542,7 +558,7 @@ int ubi_io_sync_erase(struct ubi_device *ubi, int pnum, int torture)
542 558
543 err = paranoid_check_not_bad(ubi, pnum); 559 err = paranoid_check_not_bad(ubi, pnum);
544 if (err != 0) 560 if (err != 0)
545 return err > 0 ? -EINVAL : err; 561 return err;
546 562
547 if (ubi->ro_mode) { 563 if (ubi->ro_mode) {
548 ubi_err("read-only mode"); 564 ubi_err("read-only mode");
@@ -819,7 +835,7 @@ int ubi_io_write_ec_hdr(struct ubi_device *ubi, int pnum,
819 835
820 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr); 836 err = paranoid_check_ec_hdr(ubi, pnum, ec_hdr);
821 if (err) 837 if (err)
822 return -EINVAL; 838 return err;
823 839
824 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize); 840 err = ubi_io_write(ubi, ec_hdr, pnum, 0, ubi->ec_hdr_alsize);
825 return err; 841 return err;
@@ -1083,7 +1099,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1083 1099
1084 err = paranoid_check_peb_ec_hdr(ubi, pnum); 1100 err = paranoid_check_peb_ec_hdr(ubi, pnum);
1085 if (err) 1101 if (err)
1086 return err > 0 ? -EINVAL : err; 1102 return err;
1087 1103
1088 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC); 1104 vid_hdr->magic = cpu_to_be32(UBI_VID_HDR_MAGIC);
1089 vid_hdr->version = UBI_VERSION; 1105 vid_hdr->version = UBI_VERSION;
@@ -1092,7 +1108,7 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1092 1108
1093 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr); 1109 err = paranoid_check_vid_hdr(ubi, pnum, vid_hdr);
1094 if (err) 1110 if (err)
1095 return -EINVAL; 1111 return err;
1096 1112
1097 p = (char *)vid_hdr - ubi->vid_hdr_shift; 1113 p = (char *)vid_hdr - ubi->vid_hdr_shift;
1098 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset, 1114 err = ubi_io_write(ubi, p, pnum, ubi->vid_hdr_aloffset,
@@ -1107,8 +1123,8 @@ int ubi_io_write_vid_hdr(struct ubi_device *ubi, int pnum,
1107 * @ubi: UBI device description object 1123 * @ubi: UBI device description object
1108 * @pnum: physical eraseblock number to check 1124 * @pnum: physical eraseblock number to check
1109 * 1125 *
1110 * This function returns zero if the physical eraseblock is good, a positive 1126 * This function returns zero if the physical eraseblock is good, %-EINVAL if
1111 * number if it is bad and a negative error code if an error occurred. 1127 * it is bad and a negative error code if an error occurred.
1112 */ 1128 */
1113static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum) 1129static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1114{ 1130{
@@ -1120,7 +1136,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1120 1136
1121 ubi_err("paranoid check failed for PEB %d", pnum); 1137 ubi_err("paranoid check failed for PEB %d", pnum);
1122 ubi_dbg_dump_stack(); 1138 ubi_dbg_dump_stack();
1123 return err; 1139 return err > 0 ? -EINVAL : err;
1124} 1140}
1125 1141
1126/** 1142/**
@@ -1130,7 +1146,7 @@ static int paranoid_check_not_bad(const struct ubi_device *ubi, int pnum)
1130 * @ec_hdr: the erase counter header to check 1146 * @ec_hdr: the erase counter header to check
1131 * 1147 *
1132 * This function returns zero if the erase counter header contains valid 1148 * This function returns zero if the erase counter header contains valid
1133 * values, and %1 if not. 1149 * values, and %-EINVAL if not.
1134 */ 1150 */
1135static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum, 1151static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1136 const struct ubi_ec_hdr *ec_hdr) 1152 const struct ubi_ec_hdr *ec_hdr)
@@ -1156,7 +1172,7 @@ static int paranoid_check_ec_hdr(const struct ubi_device *ubi, int pnum,
1156fail: 1172fail:
1157 ubi_dbg_dump_ec_hdr(ec_hdr); 1173 ubi_dbg_dump_ec_hdr(ec_hdr);
1158 ubi_dbg_dump_stack(); 1174 ubi_dbg_dump_stack();
1159 return 1; 1175 return -EINVAL;
1160} 1176}
1161 1177
1162/** 1178/**
@@ -1164,8 +1180,8 @@ fail:
1164 * @ubi: UBI device description object 1180 * @ubi: UBI device description object
1165 * @pnum: the physical eraseblock number to check 1181 * @pnum: the physical eraseblock number to check
1166 * 1182 *
1167 * This function returns zero if the erase counter header is all right, %1 if 1183 * This function returns zero if the erase counter header is all right and and
1168 * not, and a negative error code if an error occurred. 1184 * a negative error code if not or if an error occurred.
1169 */ 1185 */
1170static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum) 1186static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1171{ 1187{
@@ -1188,7 +1204,7 @@ static int paranoid_check_peb_ec_hdr(const struct ubi_device *ubi, int pnum)
1188 ubi_err("paranoid check failed for PEB %d", pnum); 1204 ubi_err("paranoid check failed for PEB %d", pnum);
1189 ubi_dbg_dump_ec_hdr(ec_hdr); 1205 ubi_dbg_dump_ec_hdr(ec_hdr);
1190 ubi_dbg_dump_stack(); 1206 ubi_dbg_dump_stack();
1191 err = 1; 1207 err = -EINVAL;
1192 goto exit; 1208 goto exit;
1193 } 1209 }
1194 1210
@@ -1206,7 +1222,7 @@ exit:
1206 * @vid_hdr: the volume identifier header to check 1222 * @vid_hdr: the volume identifier header to check
1207 * 1223 *
1208 * This function returns zero if the volume identifier header is all right, and 1224 * This function returns zero if the volume identifier header is all right, and
1209 * %1 if not. 1225 * %-EINVAL if not.
1210 */ 1226 */
1211static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum, 1227static int paranoid_check_vid_hdr(const struct ubi_device *ubi, int pnum,
1212 const struct ubi_vid_hdr *vid_hdr) 1228 const struct ubi_vid_hdr *vid_hdr)
@@ -1233,7 +1249,7 @@ fail:
1233 ubi_err("paranoid check failed for PEB %d", pnum); 1249 ubi_err("paranoid check failed for PEB %d", pnum);
1234 ubi_dbg_dump_vid_hdr(vid_hdr); 1250 ubi_dbg_dump_vid_hdr(vid_hdr);
1235 ubi_dbg_dump_stack(); 1251 ubi_dbg_dump_stack();
1236 return 1; 1252 return -EINVAL;
1237 1253
1238} 1254}
1239 1255
@@ -1243,7 +1259,7 @@ fail:
1243 * @pnum: the physical eraseblock number to check 1259 * @pnum: the physical eraseblock number to check
1244 * 1260 *
1245 * This function returns zero if the volume identifier header is all right, 1261 * This function returns zero if the volume identifier header is all right,
1246 * %1 if not, and a negative error code if an error occurred. 1262 * and a negative error code if not or if an error occurred.
1247 */ 1263 */
1248static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum) 1264static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1249{ 1265{
@@ -1270,7 +1286,7 @@ static int paranoid_check_peb_vid_hdr(const struct ubi_device *ubi, int pnum)
1270 ubi_err("paranoid check failed for PEB %d", pnum); 1286 ubi_err("paranoid check failed for PEB %d", pnum);
1271 ubi_dbg_dump_vid_hdr(vid_hdr); 1287 ubi_dbg_dump_vid_hdr(vid_hdr);
1272 ubi_dbg_dump_stack(); 1288 ubi_dbg_dump_stack();
1273 err = 1; 1289 err = -EINVAL;
1274 goto exit; 1290 goto exit;
1275 } 1291 }
1276 1292
@@ -1282,6 +1298,61 @@ exit:
1282} 1298}
1283 1299
1284/** 1300/**
1301 * ubi_dbg_check_write - make sure write succeeded.
1302 * @ubi: UBI device description object
1303 * @buf: buffer with data which were written
1304 * @pnum: physical eraseblock number the data were written to
1305 * @offset: offset within the physical eraseblock the data were written to
1306 * @len: how many bytes were written
1307 *
1308 * This functions reads data which were recently written and compares it with
1309 * the original data buffer - the data have to match. Returns zero if the data
1310 * match and a negative error code if not or in case of failure.
1311 */
1312int ubi_dbg_check_write(struct ubi_device *ubi, const void *buf, int pnum,
1313 int offset, int len)
1314{
1315 int err, i;
1316
1317 mutex_lock(&ubi->dbg_buf_mutex);
1318 err = ubi_io_read(ubi, ubi->dbg_peb_buf, pnum, offset, len);
1319 if (err)
1320 goto out_unlock;
1321
1322 for (i = 0; i < len; i++) {
1323 uint8_t c = ((uint8_t *)buf)[i];
1324 uint8_t c1 = ((uint8_t *)ubi->dbg_peb_buf)[i];
1325 int dump_len;
1326
1327 if (c == c1)
1328 continue;
1329
1330 ubi_err("paranoid check failed for PEB %d:%d, len %d",
1331 pnum, offset, len);
1332 ubi_msg("data differ at position %d", i);
1333 dump_len = max_t(int, 128, len - i);
1334 ubi_msg("hex dump of the original buffer from %d to %d",
1335 i, i + dump_len);
1336 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1337 buf + i, dump_len, 1);
1338 ubi_msg("hex dump of the read buffer from %d to %d",
1339 i, i + dump_len);
1340 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1341 ubi->dbg_peb_buf + i, dump_len, 1);
1342 ubi_dbg_dump_stack();
1343 err = -EINVAL;
1344 goto out_unlock;
1345 }
1346 mutex_unlock(&ubi->dbg_buf_mutex);
1347
1348 return 0;
1349
1350out_unlock:
1351 mutex_unlock(&ubi->dbg_buf_mutex);
1352 return err;
1353}
1354
1355/**
1285 * ubi_dbg_check_all_ff - check that a region of flash is empty. 1356 * ubi_dbg_check_all_ff - check that a region of flash is empty.
1286 * @ubi: UBI device description object 1357 * @ubi: UBI device description object
1287 * @pnum: the physical eraseblock number to check 1358 * @pnum: the physical eraseblock number to check
@@ -1289,8 +1360,8 @@ exit:
1289 * @len: the length of the region to check 1360 * @len: the length of the region to check
1290 * 1361 *
1291 * This function returns zero if only 0xFF bytes are present at offset 1362 * This function returns zero if only 0xFF bytes are present at offset
1292 * @offset of the physical eraseblock @pnum, %1 if not, and a negative error 1363 * @offset of the physical eraseblock @pnum, and a negative error code if not
1293 * code if an error occurred. 1364 * or if an error occurred.
1294 */ 1365 */
1295int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len) 1366int ubi_dbg_check_all_ff(struct ubi_device *ubi, int pnum, int offset, int len)
1296{ 1367{
@@ -1321,7 +1392,7 @@ fail:
1321 ubi_msg("hex dump of the %d-%d region", offset, offset + len); 1392 ubi_msg("hex dump of the %d-%d region", offset, offset + len);
1322 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1, 1393 print_hex_dump(KERN_DEBUG, "", DUMP_PREFIX_OFFSET, 32, 1,
1323 ubi->dbg_peb_buf, len, 1); 1394 ubi->dbg_peb_buf, len, 1);
1324 err = 1; 1395 err = -EINVAL;
1325error: 1396error:
1326 ubi_dbg_dump_stack(); 1397 ubi_dbg_dump_stack();
1327 mutex_unlock(&ubi->dbg_buf_mutex); 1398 mutex_unlock(&ubi->dbg_buf_mutex);
diff --git a/drivers/mtd/ubi/kapi.c b/drivers/mtd/ubi/kapi.c
index 277786ebaa2c..17f287decc36 100644
--- a/drivers/mtd/ubi/kapi.c
+++ b/drivers/mtd/ubi/kapi.c
@@ -22,6 +22,7 @@
22 22
23#include <linux/module.h> 23#include <linux/module.h>
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/slab.h>
25#include <linux/namei.h> 26#include <linux/namei.h>
26#include <linux/fs.h> 27#include <linux/fs.h>
27#include <asm/div64.h> 28#include <asm/div64.h>
@@ -291,8 +292,7 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
291 */ 292 */
292struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) 293struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
293{ 294{
294 int error, ubi_num, vol_id; 295 int error, ubi_num, vol_id, mod;
295 struct ubi_volume_desc *ret;
296 struct inode *inode; 296 struct inode *inode;
297 struct path path; 297 struct path path;
298 298
@@ -306,16 +306,16 @@ struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
306 return ERR_PTR(error); 306 return ERR_PTR(error);
307 307
308 inode = path.dentry->d_inode; 308 inode = path.dentry->d_inode;
309 mod = inode->i_mode;
309 ubi_num = ubi_major2num(imajor(inode)); 310 ubi_num = ubi_major2num(imajor(inode));
310 vol_id = iminor(inode) - 1; 311 vol_id = iminor(inode) - 1;
312 path_put(&path);
311 313
314 if (!S_ISCHR(mod))
315 return ERR_PTR(-EINVAL);
312 if (vol_id >= 0 && ubi_num >= 0) 316 if (vol_id >= 0 && ubi_num >= 0)
313 ret = ubi_open_volume(ubi_num, vol_id, mode); 317 return ubi_open_volume(ubi_num, vol_id, mode);
314 else 318 return ERR_PTR(-ENODEV);
315 ret = ERR_PTR(-ENODEV);
316
317 path_put(&path);
318 return ret;
319} 319}
320EXPORT_SYMBOL_GPL(ubi_open_volume_path); 320EXPORT_SYMBOL_GPL(ubi_open_volume_path);
321 321
diff --git a/drivers/mtd/ubi/scan.c b/drivers/mtd/ubi/scan.c
index 90af61a2c3e4..dc5f688699da 100644
--- a/drivers/mtd/ubi/scan.c
+++ b/drivers/mtd/ubi/scan.c
@@ -41,6 +41,7 @@
41 */ 41 */
42 42
43#include <linux/err.h> 43#include <linux/err.h>
44#include <linux/slab.h>
44#include <linux/crc32.h> 45#include <linux/crc32.h>
45#include <linux/math64.h> 46#include <linux/math64.h>
46#include "ubi.h" 47#include "ubi.h"
@@ -974,11 +975,8 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
974 seb->ec = si->mean_ec; 975 seb->ec = si->mean_ec;
975 976
976 err = paranoid_check_si(ubi, si); 977 err = paranoid_check_si(ubi, si);
977 if (err) { 978 if (err)
978 if (err > 0)
979 err = -EINVAL;
980 goto out_vidh; 979 goto out_vidh;
981 }
982 980
983 ubi_free_vid_hdr(ubi, vidh); 981 ubi_free_vid_hdr(ubi, vidh);
984 kfree(ech); 982 kfree(ech);
@@ -1086,8 +1084,8 @@ void ubi_scan_destroy_si(struct ubi_scan_info *si)
1086 * @ubi: UBI device description object 1084 * @ubi: UBI device description object
1087 * @si: scanning information 1085 * @si: scanning information
1088 * 1086 *
1089 * This function returns zero if the scanning information is all right, %1 if 1087 * This function returns zero if the scanning information is all right, and a
1090 * not and a negative error code if an error occurred. 1088 * negative error code if not or if an error occurred.
1091 */ 1089 */
1092static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si) 1090static int paranoid_check_si(struct ubi_device *ubi, struct ubi_scan_info *si)
1093{ 1091{
@@ -1346,7 +1344,7 @@ bad_vid_hdr:
1346 1344
1347out: 1345out:
1348 ubi_dbg_dump_stack(); 1346 ubi_dbg_dump_stack();
1349 return 1; 1347 return -EINVAL;
1350} 1348}
1351 1349
1352#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */ 1350#endif /* CONFIG_MTD_UBI_DEBUG_PARANOID */
diff --git a/drivers/mtd/ubi/ubi.h b/drivers/mtd/ubi/ubi.h
index 1af08178defd..5176d4886518 100644
--- a/drivers/mtd/ubi/ubi.h
+++ b/drivers/mtd/ubi/ubi.h
@@ -34,6 +34,7 @@
34#include <linux/fs.h> 34#include <linux/fs.h>
35#include <linux/cdev.h> 35#include <linux/cdev.h>
36#include <linux/device.h> 36#include <linux/device.h>
37#include <linux/slab.h>
37#include <linux/string.h> 38#include <linux/string.h>
38#include <linux/vmalloc.h> 39#include <linux/vmalloc.h>
39#include <linux/notifier.h> 40#include <linux/notifier.h>
diff --git a/drivers/mtd/ubi/upd.c b/drivers/mtd/ubi/upd.c
index c1d7b880c795..425bf5a3edd4 100644
--- a/drivers/mtd/ubi/upd.c
+++ b/drivers/mtd/ubi/upd.c
@@ -155,6 +155,7 @@ int ubi_start_update(struct ubi_device *ubi, struct ubi_volume *vol,
155 if (err) 155 if (err)
156 return err; 156 return err;
157 vol->updating = 0; 157 vol->updating = 0;
158 return 0;
158 } 159 }
159 160
160 vol->upd_buf = vmalloc(ubi->leb_size); 161 vol->upd_buf = vmalloc(ubi->leb_size);
diff --git a/drivers/mtd/ubi/vmt.c b/drivers/mtd/ubi/vmt.c
index ab64cb56df6e..e42afab9a9fe 100644
--- a/drivers/mtd/ubi/vmt.c
+++ b/drivers/mtd/ubi/vmt.c
@@ -25,6 +25,7 @@
25 25
26#include <linux/err.h> 26#include <linux/err.h>
27#include <linux/math64.h> 27#include <linux/math64.h>
28#include <linux/slab.h>
28#include "ubi.h" 29#include "ubi.h"
29 30
30#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID 31#ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
diff --git a/drivers/mtd/ubi/vtbl.c b/drivers/mtd/ubi/vtbl.c
index 1afc61e7455d..cd90ff3b76b1 100644
--- a/drivers/mtd/ubi/vtbl.c
+++ b/drivers/mtd/ubi/vtbl.c
@@ -58,6 +58,7 @@
58 58
59#include <linux/crc32.h> 59#include <linux/crc32.h>
60#include <linux/err.h> 60#include <linux/err.h>
61#include <linux/slab.h>
61#include <asm/div64.h> 62#include <asm/div64.h>
62#include "ubi.h" 63#include "ubi.h"
63 64
@@ -566,6 +567,7 @@ static int init_volumes(struct ubi_device *ubi, const struct ubi_scan_info *si,
566 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs); 567 vol->reserved_pebs = be32_to_cpu(vtbl[i].reserved_pebs);
567 vol->alignment = be32_to_cpu(vtbl[i].alignment); 568 vol->alignment = be32_to_cpu(vtbl[i].alignment);
568 vol->data_pad = be32_to_cpu(vtbl[i].data_pad); 569 vol->data_pad = be32_to_cpu(vtbl[i].data_pad);
570 vol->upd_marker = vtbl[i].upd_marker;
569 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ? 571 vol->vol_type = vtbl[i].vol_type == UBI_VID_DYNAMIC ?
570 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME; 572 UBI_DYNAMIC_VOLUME : UBI_STATIC_VOLUME;
571 vol->name_len = be16_to_cpu(vtbl[i].name_len); 573 vol->name_len = be16_to_cpu(vtbl[i].name_len);
diff --git a/drivers/mtd/ubi/wl.c b/drivers/mtd/ubi/wl.c
index 600c7229d5cf..f64ddabd4ac8 100644
--- a/drivers/mtd/ubi/wl.c
+++ b/drivers/mtd/ubi/wl.c
@@ -464,7 +464,7 @@ retry:
464 ubi->peb_size - ubi->vid_hdr_aloffset); 464 ubi->peb_size - ubi->vid_hdr_aloffset);
465 if (err) { 465 if (err) {
466 ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum); 466 ubi_err("new PEB %d does not contain all 0xFF bytes", e->pnum);
467 return err > 0 ? -EINVAL : err; 467 return err;
468 } 468 }
469 469
470 return e->pnum; 470 return e->pnum;
@@ -513,7 +513,7 @@ static int sync_erase(struct ubi_device *ubi, struct ubi_wl_entry *e,
513 dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec); 513 dbg_wl("erase PEB %d, old EC %llu", e->pnum, ec);
514 514
515 err = paranoid_check_ec(ubi, e->pnum, e->ec); 515 err = paranoid_check_ec(ubi, e->pnum, e->ec);
516 if (err > 0) 516 if (err)
517 return -EINVAL; 517 return -EINVAL;
518 518
519 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS); 519 ec_hdr = kzalloc(ubi->ec_hdr_alsize, GFP_NOFS);
@@ -1572,8 +1572,7 @@ void ubi_wl_close(struct ubi_device *ubi)
1572 * @ec: the erase counter to check 1572 * @ec: the erase counter to check
1573 * 1573 *
1574 * This function returns zero if the erase counter of physical eraseblock @pnum 1574 * This function returns zero if the erase counter of physical eraseblock @pnum
1575 * is equivalent to @ec, %1 if not, and a negative error code if an error 1575 * is equivalent to @ec, and a negative error code if not or if an error occurred.
1576 * occurred.
1577 */ 1576 */
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 */