aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2011-05-27 23:06:53 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2011-05-27 23:06:53 -0400
commit29a6ccca3869bbe33879dae0cd7df2a1559eff54 (patch)
tree2d9d355d8662ede95af7bc812d686dc4d5f37ff3
parent426048313dfa7d65dbd2379b1665755511f9544f (diff)
parent6a8a98b22b10f1560d5f90aded4a54234b9b2724 (diff)
Merge git://git.infradead.org/mtd-2.6
* git://git.infradead.org/mtd-2.6: (97 commits) mtd: kill CONFIG_MTD_PARTITIONS mtd: remove add_mtd_partitions, add_mtd_device and friends mtd: convert remaining users to mtd_device_register() mtd: samsung onenand: convert to mtd_device_register() mtd: omap2 onenand: convert to mtd_device_register() mtd: txx9ndfmc: convert to mtd_device_register() mtd: tmio_nand: convert to mtd_device_register() mtd: socrates_nand: convert to mtd_device_register() mtd: sharpsl: convert to mtd_device_register() mtd: s3c2410 nand: convert to mtd_device_register() mtd: ppchameleonevb: convert to mtd_device_register() mtd: orion_nand: convert to mtd_device_register() mtd: omap2: convert to mtd_device_register() mtd: nomadik_nand: convert to mtd_device_register() mtd: ndfc: convert to mtd_device_register() mtd: mxc_nand: convert to mtd_device_register() mtd: mpc5121_nfc: convert to mtd_device_register() mtd: jz4740_nand: convert to mtd_device_register() mtd: h1910: convert to mtd_device_register() mtd: fsmc_nand: convert to mtd_device_register() ... Fixed up trivial conflicts in - drivers/mtd/maps/integrator-flash.c: removed in ARM tree - drivers/mtd/maps/physmap.c: addition of afs partition probe type clashing with removal of CONFIG_MTD_PARTITIONS
-rw-r--r--Documentation/DocBook/mtdnand.tmpl3
-rw-r--r--arch/arm/mach-gemini/board-wbd111.c7
-rw-r--r--arch/arm/mach-gemini/board-wbd222.c7
-rw-r--r--arch/arm/mach-ixp4xx/ixdp425-setup.c4
-rw-r--r--arch/arm/mach-pxa/Kconfig1
-rw-r--r--arch/arm/mach-s3c2410/mach-amlm5900.c5
-rw-r--r--arch/arm/mach-s3c2410/mach-tct_hammer.c6
-rw-r--r--arch/blackfin/mach-bf537/boards/stamp.c4
-rw-r--r--arch/blackfin/mach-bf561/boards/acvilon.c4
-rw-r--r--arch/cris/Kconfig1
-rw-r--r--arch/cris/arch-v10/drivers/axisflashmap.c10
-rw-r--r--arch/cris/arch-v32/drivers/Kconfig1
-rw-r--r--arch/cris/arch-v32/drivers/axisflashmap.c7
-rw-r--r--arch/mips/cavium-octeon/flash_setup.c11
-rw-r--r--arch/mips/txx9/generic/setup.c3
-rw-r--r--drivers/mtd/Kconfig18
-rw-r--r--drivers/mtd/Makefile3
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c10
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c10
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0020.c1
-rw-r--r--drivers/mtd/devices/block2mtd.c4
-rw-r--r--drivers/mtd/devices/doc2000.c4
-rw-r--r--drivers/mtd/devices/doc2001.c4
-rw-r--r--drivers/mtd/devices/doc2001plus.c4
-rw-r--r--drivers/mtd/devices/lart.c9
-rw-r--r--drivers/mtd/devices/m25p80.c109
-rw-r--r--drivers/mtd/devices/ms02-nv.c4
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c45
-rw-r--r--drivers/mtd/devices/mtdram.c5
-rw-r--r--drivers/mtd/devices/phram.c4
-rw-r--r--drivers/mtd/devices/pmc551.c6
-rw-r--r--drivers/mtd/devices/slram.c4
-rw-r--r--drivers/mtd/devices/sst25l.c68
-rw-r--r--drivers/mtd/lpddr/lpddr_cmds.c8
-rw-r--r--drivers/mtd/maps/Kconfig23
-rw-r--r--drivers/mtd/maps/amd76xrom.c4
-rw-r--r--drivers/mtd/maps/autcpu12-nvram.c4
-rw-r--r--drivers/mtd/maps/bcm963xx-flash.c6
-rw-r--r--drivers/mtd/maps/bfin-async-flash.c21
-rw-r--r--drivers/mtd/maps/cdb89712.c12
-rw-r--r--drivers/mtd/maps/ceiva.c6
-rw-r--r--drivers/mtd/maps/cfi_flagadm.c4
-rw-r--r--drivers/mtd/maps/ck804xrom.c4
-rw-r--r--drivers/mtd/maps/dbox2-flash.c4
-rw-r--r--drivers/mtd/maps/dc21285.c20
-rw-r--r--drivers/mtd/maps/dilnetpc.c9
-rw-r--r--drivers/mtd/maps/dmv182.c4
-rw-r--r--drivers/mtd/maps/edb7312.c26
-rw-r--r--drivers/mtd/maps/esb2rom.c4
-rw-r--r--drivers/mtd/maps/fortunet.c7
-rw-r--r--drivers/mtd/maps/gpio-addr-flash.c27
-rw-r--r--drivers/mtd/maps/h720x-flash.c6
-rw-r--r--drivers/mtd/maps/ichxrom.c4
-rw-r--r--drivers/mtd/maps/impa7.c22
-rw-r--r--drivers/mtd/maps/intel_vr_nor.c19
-rw-r--r--drivers/mtd/maps/ixp2000.c4
-rw-r--r--drivers/mtd/maps/ixp4xx.c16
-rw-r--r--drivers/mtd/maps/l440gx.c4
-rw-r--r--drivers/mtd/maps/latch-addr-flash.c45
-rw-r--r--drivers/mtd/maps/mbx860.c6
-rw-r--r--drivers/mtd/maps/netsc520.c4
-rw-r--r--drivers/mtd/maps/nettel.c12
-rw-r--r--drivers/mtd/maps/octagon-5066.c4
-rw-r--r--drivers/mtd/maps/pci.c4
-rw-r--r--drivers/mtd/maps/pcmciamtd.c4
-rw-r--r--drivers/mtd/maps/physmap.c34
-rw-r--r--drivers/mtd/maps/physmap_of.c30
-rw-r--r--drivers/mtd/maps/plat-ram.c24
-rw-r--r--drivers/mtd/maps/pmcmsp-flash.c6
-rw-r--r--drivers/mtd/maps/pxa2xx-flash.c18
-rw-r--r--drivers/mtd/maps/rbtx4939-flash.c24
-rw-r--r--drivers/mtd/maps/rpxlite.c4
-rw-r--r--drivers/mtd/maps/sa1100-flash.c21
-rw-r--r--drivers/mtd/maps/sbc_gxx.c4
-rw-r--r--drivers/mtd/maps/sc520cdp.c8
-rw-r--r--drivers/mtd/maps/scb2_flash.c6
-rw-r--r--drivers/mtd/maps/scx200_docflash.c16
-rw-r--r--drivers/mtd/maps/solutionengine.c12
-rw-r--r--drivers/mtd/maps/sun_uflash.c4
-rw-r--r--drivers/mtd/maps/tqm8xxl.c20
-rw-r--r--drivers/mtd/maps/ts5500_flash.c4
-rw-r--r--drivers/mtd/maps/tsunami_flash.c4
-rw-r--r--drivers/mtd/maps/uclinux.c12
-rw-r--r--drivers/mtd/maps/vmax301.c4
-rw-r--r--drivers/mtd/maps/vmu-flash.c4
-rw-r--r--drivers/mtd/maps/wr_sbc82xx_flash.c15
-rw-r--r--drivers/mtd/mtd_blkdevs.c24
-rw-r--r--drivers/mtd/mtdchar.c55
-rw-r--r--drivers/mtd/mtdconcat.c4
-rw-r--r--drivers/mtd/mtdcore.c167
-rw-r--r--drivers/mtd/mtdcore.h6
-rw-r--r--drivers/mtd/mtdpart.c9
-rw-r--r--drivers/mtd/mtdswap.c8
-rw-r--r--drivers/mtd/nand/Kconfig5
-rw-r--r--drivers/mtd/nand/alauda.c4
-rw-r--r--drivers/mtd/nand/ams-delta.c4
-rw-r--r--drivers/mtd/nand/atmel_nand.c13
-rw-r--r--drivers/mtd/nand/au1550nd.c3
-rw-r--r--drivers/mtd/nand/autcpu12.c16
-rw-r--r--drivers/mtd/nand/bcm_umi_nand.c4
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c7
-rw-r--r--drivers/mtd/nand/cafe_nand.c11
-rw-r--r--drivers/mtd/nand/cmx270_nand.c2
-rw-r--r--drivers/mtd/nand/cs553x_nand.c19
-rw-r--r--drivers/mtd/nand/davinci_nand.c51
-rw-r--r--drivers/mtd/nand/denali.c247
-rw-r--r--drivers/mtd/nand/denali.h373
-rw-r--r--drivers/mtd/nand/diskonchip.c18
-rw-r--r--drivers/mtd/nand/edb7312.c9
-rw-r--r--drivers/mtd/nand/fsl_elbc_nand.c12
-rw-r--r--drivers/mtd/nand/fsl_upm.c12
-rw-r--r--drivers/mtd/nand/fsmc_nand.c25
-rw-r--r--drivers/mtd/nand/gpio.c4
-rw-r--r--drivers/mtd/nand/h1910.c5
-rw-r--r--drivers/mtd/nand/jz4740_nand.c10
-rw-r--r--drivers/mtd/nand/mpc5121_nfc.c12
-rw-r--r--drivers/mtd/nand/mxc_nand.c64
-rw-r--r--drivers/mtd/nand/nand_base.c18
-rw-r--r--drivers/mtd/nand/nand_bbt.c27
-rw-r--r--drivers/mtd/nand/nandsim.c4
-rw-r--r--drivers/mtd/nand/ndfc.c65
-rw-r--r--drivers/mtd/nand/nomadik_nand.c7
-rw-r--r--drivers/mtd/nand/nuc900_nand.c4
-rw-r--r--drivers/mtd/nand/omap2.c32
-rw-r--r--drivers/mtd/nand/orion_nand.c14
-rw-r--r--drivers/mtd/nand/pasemi_nand.c2
-rw-r--r--drivers/mtd/nand/plat_nand.c12
-rw-r--r--drivers/mtd/nand/ppchameleonevb.c15
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c13
-rw-r--r--drivers/mtd/nand/rtc_from4.c3
-rw-r--r--drivers/mtd/nand/s3c2410.c75
-rw-r--r--drivers/mtd/nand/sh_flctl.c2
-rw-r--r--drivers/mtd/nand/sharpsl.c12
-rw-r--r--drivers/mtd/nand/sm_common.c2
-rw-r--r--drivers/mtd/nand/socrates_nand.c16
-rw-r--r--drivers/mtd/nand/spia.c2
-rw-r--r--drivers/mtd/nand/tmio_nand.c10
-rw-r--r--drivers/mtd/nand/txx9ndfmc.c14
-rw-r--r--drivers/mtd/onenand/Kconfig1
-rw-r--r--drivers/mtd/onenand/generic.c16
-rw-r--r--drivers/mtd/onenand/omap2.c10
-rw-r--r--drivers/mtd/onenand/onenand_base.c54
-rw-r--r--drivers/mtd/onenand/onenand_sim.c3
-rw-r--r--drivers/mtd/onenand/samsung.c12
-rw-r--r--drivers/mtd/ubi/gluebi.c6
-rw-r--r--drivers/net/sfc/mtd.c6
-rw-r--r--fs/jffs2/dir.c4
-rw-r--r--fs/jffs2/scan.c19
-rw-r--r--include/linux/mtd/mtd.h17
-rw-r--r--include/linux/mtd/nand.h4
-rw-r--r--include/linux/mtd/partitions.h16
-rw-r--r--include/linux/mtd/physmap.h4
152 files changed, 1041 insertions, 1690 deletions
diff --git a/Documentation/DocBook/mtdnand.tmpl b/Documentation/DocBook/mtdnand.tmpl
index 6f242d5dee9a..17910e2052ad 100644
--- a/Documentation/DocBook/mtdnand.tmpl
+++ b/Documentation/DocBook/mtdnand.tmpl
@@ -189,8 +189,7 @@ static void __iomem *baseaddr;
189 <title>Partition defines</title> 189 <title>Partition defines</title>
190 <para> 190 <para>
191 If you want to divide your device into partitions, then 191 If you want to divide your device into partitions, then
192 enable the configuration switch CONFIG_MTD_PARTITIONS and define 192 define a partitioning scheme suitable to your board.
193 a partitioning scheme suitable to your board.
194 </para> 193 </para>
195 <programlisting> 194 <programlisting>
196#define NUM_PARTITIONS 2 195#define NUM_PARTITIONS 2
diff --git a/arch/arm/mach-gemini/board-wbd111.c b/arch/arm/mach-gemini/board-wbd111.c
index af7b68a6b258..88cc422ee444 100644
--- a/arch/arm/mach-gemini/board-wbd111.c
+++ b/arch/arm/mach-gemini/board-wbd111.c
@@ -84,7 +84,6 @@ static struct sys_timer wbd111_timer = {
84 .init = gemini_timer_init, 84 .init = gemini_timer_init,
85}; 85};
86 86
87#ifdef CONFIG_MTD_PARTITIONS
88static struct mtd_partition wbd111_partitions[] = { 87static struct mtd_partition wbd111_partitions[] = {
89 { 88 {
90 .name = "RedBoot", 89 .name = "RedBoot",
@@ -116,11 +115,7 @@ static struct mtd_partition wbd111_partitions[] = {
116 .mask_flags = MTD_WRITEABLE, 115 .mask_flags = MTD_WRITEABLE,
117 } 116 }
118}; 117};
119#define wbd111_num_partitions ARRAY_SIZE(wbd111_partitions) 118#define wbd111_num_partitions ARRAY_SIZE(wbd111_partitions)
120#else
121#define wbd111_partitions NULL
122#define wbd111_num_partitions 0
123#endif /* CONFIG_MTD_PARTITIONS */
124 119
125static void __init wbd111_init(void) 120static void __init wbd111_init(void)
126{ 121{
diff --git a/arch/arm/mach-gemini/board-wbd222.c b/arch/arm/mach-gemini/board-wbd222.c
index 99e5bbecf923..3a220347bc88 100644
--- a/arch/arm/mach-gemini/board-wbd222.c
+++ b/arch/arm/mach-gemini/board-wbd222.c
@@ -84,7 +84,6 @@ static struct sys_timer wbd222_timer = {
84 .init = gemini_timer_init, 84 .init = gemini_timer_init,
85}; 85};
86 86
87#ifdef CONFIG_MTD_PARTITIONS
88static struct mtd_partition wbd222_partitions[] = { 87static struct mtd_partition wbd222_partitions[] = {
89 { 88 {
90 .name = "RedBoot", 89 .name = "RedBoot",
@@ -116,11 +115,7 @@ static struct mtd_partition wbd222_partitions[] = {
116 .mask_flags = MTD_WRITEABLE, 115 .mask_flags = MTD_WRITEABLE,
117 } 116 }
118}; 117};
119#define wbd222_num_partitions ARRAY_SIZE(wbd222_partitions) 118#define wbd222_num_partitions ARRAY_SIZE(wbd222_partitions)
120#else
121#define wbd222_partitions NULL
122#define wbd222_num_partitions 0
123#endif /* CONFIG_MTD_PARTITIONS */
124 119
125static void __init wbd222_init(void) 120static void __init wbd222_init(void)
126{ 121{
diff --git a/arch/arm/mach-ixp4xx/ixdp425-setup.c b/arch/arm/mach-ixp4xx/ixdp425-setup.c
index 140783386785..dca4f7f9f4f7 100644
--- a/arch/arm/mach-ixp4xx/ixdp425-setup.c
+++ b/arch/arm/mach-ixp4xx/ixdp425-setup.c
@@ -60,7 +60,6 @@ static struct platform_device ixdp425_flash = {
60#if defined(CONFIG_MTD_NAND_PLATFORM) || \ 60#if defined(CONFIG_MTD_NAND_PLATFORM) || \
61 defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 61 defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
62 62
63#ifdef CONFIG_MTD_PARTITIONS
64const char *part_probes[] = { "cmdlinepart", NULL }; 63const char *part_probes[] = { "cmdlinepart", NULL };
65 64
66static struct mtd_partition ixdp425_partitions[] = { 65static struct mtd_partition ixdp425_partitions[] = {
@@ -74,7 +73,6 @@ static struct mtd_partition ixdp425_partitions[] = {
74 .size = MTDPART_SIZ_FULL 73 .size = MTDPART_SIZ_FULL
75 }, 74 },
76}; 75};
77#endif
78 76
79static void 77static void
80ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 78ixdp425_flash_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
@@ -103,11 +101,9 @@ static struct platform_nand_data ixdp425_flash_nand_data = {
103 .nr_chips = 1, 101 .nr_chips = 1,
104 .chip_delay = 30, 102 .chip_delay = 30,
105 .options = NAND_NO_AUTOINCR, 103 .options = NAND_NO_AUTOINCR,
106#ifdef CONFIG_MTD_PARTITIONS
107 .part_probe_types = part_probes, 104 .part_probe_types = part_probes,
108 .partitions = ixdp425_partitions, 105 .partitions = ixdp425_partitions,
109 .nr_partitions = ARRAY_SIZE(ixdp425_partitions), 106 .nr_partitions = ARRAY_SIZE(ixdp425_partitions),
110#endif
111 }, 107 },
112 .ctrl = { 108 .ctrl = {
113 .cmd_ctrl = ixdp425_flash_nand_cmd_ctrl 109 .cmd_ctrl = ixdp425_flash_nand_cmd_ctrl
diff --git a/arch/arm/mach-pxa/Kconfig b/arch/arm/mach-pxa/Kconfig
index 2fc9f94cdd29..cd19309fd3b8 100644
--- a/arch/arm/mach-pxa/Kconfig
+++ b/arch/arm/mach-pxa/Kconfig
@@ -153,7 +153,6 @@ config MACH_XCEP
153 bool "Iskratel Electronics XCEP" 153 bool "Iskratel Electronics XCEP"
154 select PXA25x 154 select PXA25x
155 select MTD 155 select MTD
156 select MTD_PARTITIONS
157 select MTD_PHYSMAP 156 select MTD_PHYSMAP
158 select MTD_CFI_INTELEXT 157 select MTD_CFI_INTELEXT
159 select MTD_CFI 158 select MTD_CFI
diff --git a/arch/arm/mach-s3c2410/mach-amlm5900.c b/arch/arm/mach-s3c2410/mach-amlm5900.c
index 44440cbd7620..dabc141243f3 100644
--- a/arch/arm/mach-s3c2410/mach-amlm5900.c
+++ b/arch/arm/mach-s3c2410/mach-amlm5900.c
@@ -58,8 +58,6 @@
58#include <plat/cpu.h> 58#include <plat/cpu.h>
59#include <plat/gpio-cfg.h> 59#include <plat/gpio-cfg.h>
60 60
61#ifdef CONFIG_MTD_PARTITIONS
62
63#include <linux/mtd/mtd.h> 61#include <linux/mtd/mtd.h>
64#include <linux/mtd/partitions.h> 62#include <linux/mtd/partitions.h>
65#include <linux/mtd/map.h> 63#include <linux/mtd/map.h>
@@ -113,7 +111,6 @@ static struct platform_device amlm5900_device_nor = {
113 .num_resources = 1, 111 .num_resources = 1,
114 .resource = &amlm5900_nor_resource, 112 .resource = &amlm5900_nor_resource,
115}; 113};
116#endif
117 114
118static struct map_desc amlm5900_iodesc[] __initdata = { 115static struct map_desc amlm5900_iodesc[] __initdata = {
119}; 116};
@@ -158,9 +155,7 @@ static struct platform_device *amlm5900_devices[] __initdata = {
158 &s3c_device_rtc, 155 &s3c_device_rtc,
159 &s3c_device_usbgadget, 156 &s3c_device_usbgadget,
160 &s3c_device_sdi, 157 &s3c_device_sdi,
161#ifdef CONFIG_MTD_PARTITIONS
162 &amlm5900_device_nor, 158 &amlm5900_device_nor,
163#endif
164}; 159};
165 160
166static void __init amlm5900_map_io(void) 161static void __init amlm5900_map_io(void)
diff --git a/arch/arm/mach-s3c2410/mach-tct_hammer.c b/arch/arm/mach-s3c2410/mach-tct_hammer.c
index a15d0621c22f..43c2b831b9e8 100644
--- a/arch/arm/mach-s3c2410/mach-tct_hammer.c
+++ b/arch/arm/mach-s3c2410/mach-tct_hammer.c
@@ -49,8 +49,6 @@
49#include <plat/devs.h> 49#include <plat/devs.h>
50#include <plat/cpu.h> 50#include <plat/cpu.h>
51 51
52#ifdef CONFIG_MTD_PARTITIONS
53
54#include <linux/mtd/mtd.h> 52#include <linux/mtd/mtd.h>
55#include <linux/mtd/partitions.h> 53#include <linux/mtd/partitions.h>
56#include <linux/mtd/map.h> 54#include <linux/mtd/map.h>
@@ -91,8 +89,6 @@ static struct platform_device tct_hammer_device_nor = {
91 .resource = &tct_hammer_nor_resource, 89 .resource = &tct_hammer_nor_resource,
92}; 90};
93 91
94#endif
95
96static struct map_desc tct_hammer_iodesc[] __initdata = { 92static struct map_desc tct_hammer_iodesc[] __initdata = {
97}; 93};
98 94
@@ -133,9 +129,7 @@ static struct platform_device *tct_hammer_devices[] __initdata = {
133 &s3c_device_rtc, 129 &s3c_device_rtc,
134 &s3c_device_usbgadget, 130 &s3c_device_usbgadget,
135 &s3c_device_sdi, 131 &s3c_device_sdi,
136#ifdef CONFIG_MTD_PARTITIONS
137 &tct_hammer_device_nor, 132 &tct_hammer_device_nor,
138#endif
139}; 133};
140 134
141static void __init tct_hammer_map_io(void) 135static void __init tct_hammer_map_io(void)
diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
index e16dc4560048..76db1d483173 100644
--- a/arch/blackfin/mach-bf537/boards/stamp.c
+++ b/arch/blackfin/mach-bf537/boards/stamp.c
@@ -382,7 +382,6 @@ static struct platform_device net2272_bfin_device = {
382#endif 382#endif
383 383
384#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 384#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
385#ifdef CONFIG_MTD_PARTITIONS
386const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; 385const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
387 386
388static struct mtd_partition bfin_plat_nand_partitions[] = { 387static struct mtd_partition bfin_plat_nand_partitions[] = {
@@ -396,7 +395,6 @@ static struct mtd_partition bfin_plat_nand_partitions[] = {
396 .offset = MTDPART_OFS_APPEND, 395 .offset = MTDPART_OFS_APPEND,
397 }, 396 },
398}; 397};
399#endif
400 398
401#define BFIN_NAND_PLAT_CLE 2 399#define BFIN_NAND_PLAT_CLE 2
402#define BFIN_NAND_PLAT_ALE 1 400#define BFIN_NAND_PLAT_ALE 1
@@ -423,11 +421,9 @@ static struct platform_nand_data bfin_plat_nand_data = {
423 .chip = { 421 .chip = {
424 .nr_chips = 1, 422 .nr_chips = 1,
425 .chip_delay = 30, 423 .chip_delay = 30,
426#ifdef CONFIG_MTD_PARTITIONS
427 .part_probe_types = part_probes, 424 .part_probe_types = part_probes,
428 .partitions = bfin_plat_nand_partitions, 425 .partitions = bfin_plat_nand_partitions,
429 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions), 426 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
430#endif
431 }, 427 },
432 .ctrl = { 428 .ctrl = {
433 .cmd_ctrl = bfin_plat_nand_cmd_ctrl, 429 .cmd_ctrl = bfin_plat_nand_cmd_ctrl,
diff --git a/arch/blackfin/mach-bf561/boards/acvilon.c b/arch/blackfin/mach-bf561/boards/acvilon.c
index 3926cd909b66..9231a942892b 100644
--- a/arch/blackfin/mach-bf561/boards/acvilon.c
+++ b/arch/blackfin/mach-bf561/boards/acvilon.c
@@ -243,7 +243,6 @@ static struct platform_device bfin_uart0_device = {
243 243
244#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE) 244#if defined(CONFIG_MTD_NAND_PLATFORM) || defined(CONFIG_MTD_NAND_PLATFORM_MODULE)
245 245
246#ifdef CONFIG_MTD_PARTITIONS
247const char *part_probes[] = { "cmdlinepart", NULL }; 246const char *part_probes[] = { "cmdlinepart", NULL };
248 247
249static struct mtd_partition bfin_plat_nand_partitions[] = { 248static struct mtd_partition bfin_plat_nand_partitions[] = {
@@ -257,7 +256,6 @@ static struct mtd_partition bfin_plat_nand_partitions[] = {
257 .offset = MTDPART_OFS_APPEND, 256 .offset = MTDPART_OFS_APPEND,
258 }, 257 },
259}; 258};
260#endif
261 259
262#define BFIN_NAND_PLAT_CLE 2 260#define BFIN_NAND_PLAT_CLE 2
263#define BFIN_NAND_PLAT_ALE 3 261#define BFIN_NAND_PLAT_ALE 3
@@ -286,11 +284,9 @@ static struct platform_nand_data bfin_plat_nand_data = {
286 .chip = { 284 .chip = {
287 .nr_chips = 1, 285 .nr_chips = 1,
288 .chip_delay = 30, 286 .chip_delay = 30,
289#ifdef CONFIG_MTD_PARTITIONS
290 .part_probe_types = part_probes, 287 .part_probe_types = part_probes,
291 .partitions = bfin_plat_nand_partitions, 288 .partitions = bfin_plat_nand_partitions,
292 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions), 289 .nr_partitions = ARRAY_SIZE(bfin_plat_nand_partitions),
293#endif
294 }, 290 },
295 .ctrl = { 291 .ctrl = {
296 .cmd_ctrl = bfin_plat_nand_cmd_ctrl, 292 .cmd_ctrl = bfin_plat_nand_cmd_ctrl,
diff --git a/arch/cris/Kconfig b/arch/cris/Kconfig
index b6b94a27d276..17addacb169e 100644
--- a/arch/cris/Kconfig
+++ b/arch/cris/Kconfig
@@ -270,7 +270,6 @@ config ETRAX_AXISFLASHMAP
270 select MTD_JEDECPROBE if ETRAX_ARCH_V32 270 select MTD_JEDECPROBE if ETRAX_ARCH_V32
271 select MTD_CHAR 271 select MTD_CHAR
272 select MTD_BLOCK 272 select MTD_BLOCK
273 select MTD_PARTITIONS
274 select MTD_COMPLEX_MAPPINGS 273 select MTD_COMPLEX_MAPPINGS
275 help 274 help
276 This option enables MTD mapping of flash devices. Needed to use 275 This option enables MTD mapping of flash devices. Needed to use
diff --git a/arch/cris/arch-v10/drivers/axisflashmap.c b/arch/cris/arch-v10/drivers/axisflashmap.c
index ed708e19d09e..a4bbdfd37bd8 100644
--- a/arch/cris/arch-v10/drivers/axisflashmap.c
+++ b/arch/cris/arch-v10/drivers/axisflashmap.c
@@ -372,7 +372,7 @@ static int __init init_axis_flash(void)
372#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE 372#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
373 if (mymtd) { 373 if (mymtd) {
374 main_partition.size = mymtd->size; 374 main_partition.size = mymtd->size;
375 err = add_mtd_partitions(mymtd, &main_partition, 1); 375 err = mtd_device_register(mymtd, &main_partition, 1);
376 if (err) 376 if (err)
377 panic("axisflashmap: Could not initialize " 377 panic("axisflashmap: Could not initialize "
378 "partition for whole main mtd device!\n"); 378 "partition for whole main mtd device!\n");
@@ -382,10 +382,12 @@ static int __init init_axis_flash(void)
382 if (mymtd) { 382 if (mymtd) {
383 if (use_default_ptable) { 383 if (use_default_ptable) {
384 printk(KERN_INFO " Using default partition table.\n"); 384 printk(KERN_INFO " Using default partition table.\n");
385 err = add_mtd_partitions(mymtd, axis_default_partitions, 385 err = mtd_device_register(mymtd,
386 NUM_DEFAULT_PARTITIONS); 386 axis_default_partitions,
387 NUM_DEFAULT_PARTITIONS);
387 } else { 388 } else {
388 err = add_mtd_partitions(mymtd, axis_partitions, pidx); 389 err = mtd_device_register(mymtd, axis_partitions,
390 pidx);
389 } 391 }
390 392
391 if (err) 393 if (err)
diff --git a/arch/cris/arch-v32/drivers/Kconfig b/arch/cris/arch-v32/drivers/Kconfig
index 1633b120aa81..41a2732e8b9c 100644
--- a/arch/cris/arch-v32/drivers/Kconfig
+++ b/arch/cris/arch-v32/drivers/Kconfig
@@ -405,7 +405,6 @@ config ETRAX_AXISFLASHMAP
405 select MTD_JEDECPROBE 405 select MTD_JEDECPROBE
406 select MTD_CHAR 406 select MTD_CHAR
407 select MTD_BLOCK 407 select MTD_BLOCK
408 select MTD_PARTITIONS
409 select MTD_COMPLEX_MAPPINGS 408 select MTD_COMPLEX_MAPPINGS
410 help 409 help
411 This option enables MTD mapping of flash devices. Needed to use 410 This option enables MTD mapping of flash devices. Needed to use
diff --git a/arch/cris/arch-v32/drivers/axisflashmap.c b/arch/cris/arch-v32/drivers/axisflashmap.c
index 7b155f8203b8..a2bde3744622 100644
--- a/arch/cris/arch-v32/drivers/axisflashmap.c
+++ b/arch/cris/arch-v32/drivers/axisflashmap.c
@@ -561,7 +561,7 @@ static int __init init_axis_flash(void)
561#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE 561#ifdef CONFIG_ETRAX_AXISFLASHMAP_MTD0WHOLE
562 if (main_mtd) { 562 if (main_mtd) {
563 main_partition.size = main_mtd->size; 563 main_partition.size = main_mtd->size;
564 err = add_mtd_partitions(main_mtd, &main_partition, 1); 564 err = mtd_device_register(main_mtd, &main_partition, 1);
565 if (err) 565 if (err)
566 panic("axisflashmap: Could not initialize " 566 panic("axisflashmap: Could not initialize "
567 "partition for whole main mtd device!\n"); 567 "partition for whole main mtd device!\n");
@@ -597,7 +597,8 @@ static int __init init_axis_flash(void)
597 mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize : 597 mtd_ram->erasesize = (main_mtd ? main_mtd->erasesize :
598 CONFIG_ETRAX_PTABLE_SECTOR); 598 CONFIG_ETRAX_PTABLE_SECTOR);
599 } else { 599 } else {
600 err = add_mtd_partitions(main_mtd, &partition[part], 1); 600 err = mtd_device_register(main_mtd, &partition[part],
601 1);
601 if (err) 602 if (err)
602 panic("axisflashmap: Could not add mtd " 603 panic("axisflashmap: Could not add mtd "
603 "partition %d\n", part); 604 "partition %d\n", part);
@@ -633,7 +634,7 @@ static int __init init_axis_flash(void)
633#ifndef CONFIG_ETRAX_VCS_SIM 634#ifndef CONFIG_ETRAX_VCS_SIM
634 if (aux_mtd) { 635 if (aux_mtd) {
635 aux_partition.size = aux_mtd->size; 636 aux_partition.size = aux_mtd->size;
636 err = add_mtd_partitions(aux_mtd, &aux_partition, 1); 637 err = mtd_device_register(aux_mtd, &aux_partition, 1);
637 if (err) 638 if (err)
638 panic("axisflashmap: Could not initialize " 639 panic("axisflashmap: Could not initialize "
639 "aux mtd device!\n"); 640 "aux mtd device!\n");
diff --git a/arch/mips/cavium-octeon/flash_setup.c b/arch/mips/cavium-octeon/flash_setup.c
index 008f657116eb..0ee02f5e51cc 100644
--- a/arch/mips/cavium-octeon/flash_setup.c
+++ b/arch/mips/cavium-octeon/flash_setup.c
@@ -16,7 +16,6 @@
16 16
17static struct map_info flash_map; 17static struct map_info flash_map;
18static struct mtd_info *mymtd; 18static struct mtd_info *mymtd;
19#ifdef CONFIG_MTD_PARTITIONS
20static int nr_parts; 19static int nr_parts;
21static struct mtd_partition *parts; 20static struct mtd_partition *parts;
22static const char *part_probe_types[] = { 21static const char *part_probe_types[] = {
@@ -26,7 +25,6 @@ static const char *part_probe_types[] = {
26#endif 25#endif
27 NULL 26 NULL
28}; 27};
29#endif
30 28
31/** 29/**
32 * Module/ driver initialization. 30 * Module/ driver initialization.
@@ -63,17 +61,10 @@ static int __init flash_init(void)
63 if (mymtd) { 61 if (mymtd) {
64 mymtd->owner = THIS_MODULE; 62 mymtd->owner = THIS_MODULE;
65 63
66#ifdef CONFIG_MTD_PARTITIONS
67 nr_parts = parse_mtd_partitions(mymtd, 64 nr_parts = parse_mtd_partitions(mymtd,
68 part_probe_types, 65 part_probe_types,
69 &parts, 0); 66 &parts, 0);
70 if (nr_parts > 0) 67 mtd_device_register(mymtd, parts, nr_parts);
71 add_mtd_partitions(mymtd, parts, nr_parts);
72 else
73 add_mtd_device(mymtd);
74#else
75 add_mtd_device(mymtd);
76#endif
77 } else { 68 } else {
78 pr_err("Failed to register MTD device for flash\n"); 69 pr_err("Failed to register MTD device for flash\n");
79 } 70 }
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index 812816c45662..ec38e00b2559 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -639,7 +639,6 @@ void __init txx9_physmap_flash_init(int no, unsigned long addr,
639 .flags = IORESOURCE_MEM, 639 .flags = IORESOURCE_MEM,
640 }; 640 };
641 struct platform_device *pdev; 641 struct platform_device *pdev;
642#ifdef CONFIG_MTD_PARTITIONS
643 static struct mtd_partition parts[2]; 642 static struct mtd_partition parts[2];
644 struct physmap_flash_data pdata_part; 643 struct physmap_flash_data pdata_part;
645 644
@@ -658,7 +657,7 @@ void __init txx9_physmap_flash_init(int no, unsigned long addr,
658 pdata_part.parts = parts; 657 pdata_part.parts = parts;
659 pdata = &pdata_part; 658 pdata = &pdata_part;
660 } 659 }
661#endif 660
662 pdev = platform_device_alloc("physmap-flash", no); 661 pdev = platform_device_alloc("physmap-flash", no);
663 if (!pdev || 662 if (!pdev ||
664 platform_device_add_resources(pdev, &res, 1) || 663 platform_device_add_resources(pdev, &res, 1) ||
diff --git a/drivers/mtd/Kconfig b/drivers/mtd/Kconfig
index bc50d5ea5534..4be8373d43e5 100644
--- a/drivers/mtd/Kconfig
+++ b/drivers/mtd/Kconfig
@@ -33,20 +33,6 @@ config MTD_TESTS
33 should normally be compiled as kernel modules. The modules perform 33 should normally be compiled as kernel modules. The modules perform
34 various checks and verifications when loaded. 34 various checks and verifications when loaded.
35 35
36config MTD_PARTITIONS
37 bool "MTD partitioning support"
38 help
39 If you have a device which needs to divide its flash chip(s) up
40 into multiple 'partitions', each of which appears to the user as
41 a separate MTD device, you require this option to be enabled. If
42 unsure, say 'Y'.
43
44 Note, however, that you don't need this option for the DiskOnChip
45 devices. Partitioning on NFTL 'devices' is a different - that's the
46 'normal' form of partitioning used on a block device.
47
48if MTD_PARTITIONS
49
50config MTD_REDBOOT_PARTS 36config MTD_REDBOOT_PARTS
51 tristate "RedBoot partition table parsing" 37 tristate "RedBoot partition table parsing"
52 ---help--- 38 ---help---
@@ -99,7 +85,7 @@ endif # MTD_REDBOOT_PARTS
99 85
100config MTD_CMDLINE_PARTS 86config MTD_CMDLINE_PARTS
101 bool "Command line partition table parsing" 87 bool "Command line partition table parsing"
102 depends on MTD_PARTITIONS = "y" && MTD = "y" 88 depends on MTD = "y"
103 ---help--- 89 ---help---
104 Allow generic configuration of the MTD partition tables via the kernel 90 Allow generic configuration of the MTD partition tables via the kernel
105 command line. Multiple flash resources are supported for hardware where 91 command line. Multiple flash resources are supported for hardware where
@@ -163,8 +149,6 @@ config MTD_AR7_PARTS
163 ---help--- 149 ---help---
164 TI AR7 partitioning support 150 TI AR7 partitioning support
165 151
166endif # MTD_PARTITIONS
167
168comment "User Modules And Translation Layers" 152comment "User Modules And Translation Layers"
169 153
170config MTD_CHAR 154config MTD_CHAR
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index d578095fb255..39664c4229ff 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -4,8 +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 mtdconcat.o 7mtd-y := mtdcore.o mtdsuper.o mtdconcat.o mtdpart.o
8mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o
9mtd-$(CONFIG_MTD_OF_PARTS) += ofpart.o 8mtd-$(CONFIG_MTD_OF_PARTS) += ofpart.o
10 9
11obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o 10obj-$(CONFIG_MTD_REDBOOT_PARTS) += redboot.o
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index 09cb7c8d93b4..e1e122f2f929 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -812,12 +812,9 @@ static int chip_ready (struct map_info *map, struct flchip *chip, unsigned long
812 break; 812 break;
813 813
814 if (time_after(jiffies, timeo)) { 814 if (time_after(jiffies, timeo)) {
815 /* Urgh. Resume and pretend we weren't here. */ 815 /* Urgh. Resume and pretend we weren't here.
816 map_write(map, CMD(0xd0), adr); 816 * Make sure we're in 'read status' mode if it had finished */
817 /* Make sure we're in 'read status' mode if it had finished */ 817 put_chip(map, chip, adr);
818 map_write(map, CMD(0x70), adr);
819 chip->state = FL_ERASING;
820 chip->oldstate = FL_READY;
821 printk(KERN_ERR "%s: Chip not ready after erase " 818 printk(KERN_ERR "%s: Chip not ready after erase "
822 "suspended: status = 0x%lx\n", map->name, status.x[0]); 819 "suspended: status = 0x%lx\n", map->name, status.x[0]);
823 return -EIO; 820 return -EIO;
@@ -997,7 +994,6 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
997 994
998 switch(chip->oldstate) { 995 switch(chip->oldstate) {
999 case FL_ERASING: 996 case FL_ERASING:
1000 chip->state = chip->oldstate;
1001 /* What if one interleaved chip has finished and the 997 /* What if one interleaved chip has finished and the
1002 other hasn't? The old code would leave the finished 998 other hasn't? The old code would leave the finished
1003 one in READY mode. That's bad, and caused -EROFS 999 one in READY mode. That's bad, and caused -EROFS
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 0b49266840b9..23175edd5634 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -462,13 +462,14 @@ struct mtd_info *cfi_cmdset_0002(struct map_info *map, int primary)
462 cfi_fixup_major_minor(cfi, extp); 462 cfi_fixup_major_minor(cfi, extp);
463 463
464 /* 464 /*
465 * Valid primary extension versions are: 1.0, 1.1, 1.2, 1.3, 1.4 465 * Valid primary extension versions are: 1.0, 1.1, 1.2, 1.3, 1.4, 1.5
466 * see: http://cs.ozerki.net/zap/pub/axim-x5/docs/cfi_r20.pdf, page 19 466 * see: http://cs.ozerki.net/zap/pub/axim-x5/docs/cfi_r20.pdf, page 19
467 * http://www.spansion.com/Support/AppNotes/cfi_100_20011201.pdf 467 * http://www.spansion.com/Support/AppNotes/cfi_100_20011201.pdf
468 * http://www.spansion.com/Support/Datasheets/s29ws-p_00_a12_e.pdf 468 * http://www.spansion.com/Support/Datasheets/s29ws-p_00_a12_e.pdf
469 * http://www.spansion.com/Support/Datasheets/S29GL_128S_01GS_00_02_e.pdf
469 */ 470 */
470 if (extp->MajorVersion != '1' || 471 if (extp->MajorVersion != '1' ||
471 (extp->MajorVersion == '1' && (extp->MinorVersion < '0' || extp->MinorVersion > '4'))) { 472 (extp->MajorVersion == '1' && (extp->MinorVersion < '0' || extp->MinorVersion > '5'))) {
472 printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query " 473 printk(KERN_ERR " Unknown Amd/Fujitsu Extended Query "
473 "version %c.%c (%#02x/%#02x).\n", 474 "version %c.%c (%#02x/%#02x).\n",
474 extp->MajorVersion, extp->MinorVersion, 475 extp->MajorVersion, extp->MinorVersion,
@@ -710,9 +711,7 @@ static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr
710 * there was an error (so leave the erase 711 * there was an error (so leave the erase
711 * routine to recover from it) or we trying to 712 * routine to recover from it) or we trying to
712 * use the erase-in-progress sector. */ 713 * use the erase-in-progress sector. */
713 map_write(map, cfi->sector_erase_cmd, chip->in_progress_block_addr); 714 put_chip(map, chip, adr);
714 chip->state = FL_ERASING;
715 chip->oldstate = FL_READY;
716 printk(KERN_ERR "MTD %s(): chip not ready after erase suspend\n", __func__); 715 printk(KERN_ERR "MTD %s(): chip not ready after erase suspend\n", __func__);
717 return -EIO; 716 return -EIO;
718 } 717 }
@@ -762,7 +761,6 @@ static void put_chip(struct map_info *map, struct flchip *chip, unsigned long ad
762 761
763 switch(chip->oldstate) { 762 switch(chip->oldstate) {
764 case FL_ERASING: 763 case FL_ERASING:
765 chip->state = chip->oldstate;
766 map_write(map, cfi->sector_erase_cmd, chip->in_progress_block_addr); 764 map_write(map, cfi->sector_erase_cmd, chip->in_progress_block_addr);
767 chip->oldstate = FL_READY; 765 chip->oldstate = FL_READY;
768 chip->state = FL_ERASING; 766 chip->state = FL_ERASING;
diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
index ed56ad3884fb..179814a95f3a 100644
--- a/drivers/mtd/chips/cfi_cmdset_0020.c
+++ b/drivers/mtd/chips/cfi_cmdset_0020.c
@@ -296,6 +296,7 @@ static inline int do_read_onechip(struct map_info *map, struct flchip *chip, lof
296 /* make sure we're in 'read status' mode */ 296 /* make sure we're in 'read status' mode */
297 map_write(map, CMD(0x70), cmd_addr); 297 map_write(map, CMD(0x70), cmd_addr);
298 chip->state = FL_ERASING; 298 chip->state = FL_ERASING;
299 wake_up(&chip->wq);
299 mutex_unlock(&chip->mutex); 300 mutex_unlock(&chip->mutex);
300 printk(KERN_ERR "Chip not ready after erase " 301 printk(KERN_ERR "Chip not ready after erase "
301 "suspended: status = 0x%lx\n", status.x[0]); 302 "suspended: status = 0x%lx\n", status.x[0]);
diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c
index 97183c8c9e33..b78f23169d4e 100644
--- a/drivers/mtd/devices/block2mtd.c
+++ b/drivers/mtd/devices/block2mtd.c
@@ -294,7 +294,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
294 dev->mtd.priv = dev; 294 dev->mtd.priv = dev;
295 dev->mtd.owner = THIS_MODULE; 295 dev->mtd.owner = THIS_MODULE;
296 296
297 if (add_mtd_device(&dev->mtd)) { 297 if (mtd_device_register(&dev->mtd, NULL, 0)) {
298 /* Device didn't get added, so free the entry */ 298 /* Device didn't get added, so free the entry */
299 goto devinit_err; 299 goto devinit_err;
300 } 300 }
@@ -465,7 +465,7 @@ static void __devexit block2mtd_exit(void)
465 list_for_each_safe(pos, next, &blkmtd_device_list) { 465 list_for_each_safe(pos, next, &blkmtd_device_list) {
466 struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list); 466 struct block2mtd_dev *dev = list_entry(pos, typeof(*dev), list);
467 block2mtd_sync(&dev->mtd); 467 block2mtd_sync(&dev->mtd);
468 del_mtd_device(&dev->mtd); 468 mtd_device_unregister(&dev->mtd);
469 INFO("mtd%d: [%s] removed", dev->mtd.index, 469 INFO("mtd%d: [%s] removed", dev->mtd.index,
470 dev->mtd.name + strlen("block2mtd: ")); 470 dev->mtd.name + strlen("block2mtd: "));
471 list_del(&dev->list); 471 list_del(&dev->list);
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index 5bf5f460e132..f7fbf6025ef2 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -597,7 +597,7 @@ void DoC2k_init(struct mtd_info *mtd)
597 doc2klist = mtd; 597 doc2klist = mtd;
598 mtd->size = this->totlen; 598 mtd->size = this->totlen;
599 mtd->erasesize = this->erasesize; 599 mtd->erasesize = this->erasesize;
600 add_mtd_device(mtd); 600 mtd_device_register(mtd, NULL, 0);
601 return; 601 return;
602 } 602 }
603} 603}
@@ -1185,7 +1185,7 @@ static void __exit cleanup_doc2000(void)
1185 this = mtd->priv; 1185 this = mtd->priv;
1186 doc2klist = this->nextdoc; 1186 doc2klist = this->nextdoc;
1187 1187
1188 del_mtd_device(mtd); 1188 mtd_device_unregister(mtd);
1189 1189
1190 iounmap(this->virtadr); 1190 iounmap(this->virtadr);
1191 kfree(this->chips); 1191 kfree(this->chips);
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index 0990f7803628..241192f05bc8 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -376,7 +376,7 @@ void DoCMil_init(struct mtd_info *mtd)
376 this->nextdoc = docmillist; 376 this->nextdoc = docmillist;
377 docmillist = mtd; 377 docmillist = mtd;
378 mtd->size = this->totlen; 378 mtd->size = this->totlen;
379 add_mtd_device(mtd); 379 mtd_device_register(mtd, NULL, 0);
380 return; 380 return;
381 } 381 }
382} 382}
@@ -826,7 +826,7 @@ static void __exit cleanup_doc2001(void)
826 this = mtd->priv; 826 this = mtd->priv;
827 docmillist = this->nextdoc; 827 docmillist = this->nextdoc;
828 828
829 del_mtd_device(mtd); 829 mtd_device_unregister(mtd);
830 830
831 iounmap(this->virtadr); 831 iounmap(this->virtadr);
832 kfree(this->chips); 832 kfree(this->chips);
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index 8b36fa77a195..09ae0adc3ad0 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -499,7 +499,7 @@ void DoCMilPlus_init(struct mtd_info *mtd)
499 docmilpluslist = mtd; 499 docmilpluslist = mtd;
500 mtd->size = this->totlen; 500 mtd->size = this->totlen;
501 mtd->erasesize = this->erasesize; 501 mtd->erasesize = this->erasesize;
502 add_mtd_device(mtd); 502 mtd_device_register(mtd, NULL, 0);
503 return; 503 return;
504 } 504 }
505} 505}
@@ -1091,7 +1091,7 @@ static void __exit cleanup_doc2001plus(void)
1091 this = mtd->priv; 1091 this = mtd->priv;
1092 docmilpluslist = this->nextdoc; 1092 docmilpluslist = this->nextdoc;
1093 1093
1094 del_mtd_device(mtd); 1094 mtd_device_unregister(mtd);
1095 1095
1096 iounmap(this->virtadr); 1096 iounmap(this->virtadr);
1097 kfree(this->chips); 1097 kfree(this->chips);
diff --git a/drivers/mtd/devices/lart.c b/drivers/mtd/devices/lart.c
index 4b829f97d56c..772a0ff89e0f 100644
--- a/drivers/mtd/devices/lart.c
+++ b/drivers/mtd/devices/lart.c
@@ -684,9 +684,10 @@ static int __init lart_flash_init (void)
684#endif 684#endif
685 685
686#ifndef HAVE_PARTITIONS 686#ifndef HAVE_PARTITIONS
687 result = add_mtd_device (&mtd); 687 result = mtd_device_register(&mtd, NULL, 0);
688#else 688#else
689 result = add_mtd_partitions (&mtd,lart_partitions, ARRAY_SIZE(lart_partitions)); 689 result = mtd_device_register(&mtd, lart_partitions,
690 ARRAY_SIZE(lart_partitions));
690#endif 691#endif
691 692
692 return (result); 693 return (result);
@@ -695,9 +696,9 @@ static int __init lart_flash_init (void)
695static void __exit lart_flash_exit (void) 696static void __exit lart_flash_exit (void)
696{ 697{
697#ifndef HAVE_PARTITIONS 698#ifndef HAVE_PARTITIONS
698 del_mtd_device (&mtd); 699 mtd_device_unregister(&mtd);
699#else 700#else
700 del_mtd_partitions (&mtd); 701 mtd_device_unregister(&mtd);
701#endif 702#endif
702} 703}
703 704
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 3fb981d4bb51..35180e475c4c 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -27,6 +27,7 @@
27#include <linux/sched.h> 27#include <linux/sched.h>
28#include <linux/mod_devicetable.h> 28#include <linux/mod_devicetable.h>
29 29
30#include <linux/mtd/cfi.h>
30#include <linux/mtd/mtd.h> 31#include <linux/mtd/mtd.h>
31#include <linux/mtd/partitions.h> 32#include <linux/mtd/partitions.h>
32 33
@@ -55,6 +56,9 @@
55#define OPCODE_EN4B 0xb7 /* Enter 4-byte mode */ 56#define OPCODE_EN4B 0xb7 /* Enter 4-byte mode */
56#define OPCODE_EX4B 0xe9 /* Exit 4-byte mode */ 57#define OPCODE_EX4B 0xe9 /* Exit 4-byte mode */
57 58
59/* Used for Spansion flashes only. */
60#define OPCODE_BRWR 0x17 /* Bank register write */
61
58/* Status Register bits. */ 62/* Status Register bits. */
59#define SR_WIP 1 /* Write in progress */ 63#define SR_WIP 1 /* Write in progress */
60#define SR_WEL 2 /* Write enable latch */ 64#define SR_WEL 2 /* Write enable latch */
@@ -76,6 +80,8 @@
76#define FAST_READ_DUMMY_BYTE 0 80#define FAST_READ_DUMMY_BYTE 0
77#endif 81#endif
78 82
83#define JEDEC_MFR(_jedec_id) ((_jedec_id) >> 16)
84
79/****************************************************************************/ 85/****************************************************************************/
80 86
81struct m25p { 87struct m25p {
@@ -158,11 +164,18 @@ static inline int write_disable(struct m25p *flash)
158/* 164/*
159 * Enable/disable 4-byte addressing mode. 165 * Enable/disable 4-byte addressing mode.
160 */ 166 */
161static inline int set_4byte(struct m25p *flash, int enable) 167static inline int set_4byte(struct m25p *flash, u32 jedec_id, int enable)
162{ 168{
163 u8 code = enable ? OPCODE_EN4B : OPCODE_EX4B; 169 switch (JEDEC_MFR(jedec_id)) {
164 170 case CFI_MFR_MACRONIX:
165 return spi_write_then_read(flash->spi, &code, 1, NULL, 0); 171 flash->command[0] = enable ? OPCODE_EN4B : OPCODE_EX4B;
172 return spi_write(flash->spi, flash->command, 1);
173 default:
174 /* Spansion style */
175 flash->command[0] = OPCODE_BRWR;
176 flash->command[1] = enable << 7;
177 return spi_write(flash->spi, flash->command, 2);
178 }
166} 179}
167 180
168/* 181/*
@@ -668,6 +681,7 @@ static const struct spi_device_id m25p_ids[] = {
668 /* Macronix */ 681 /* Macronix */
669 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) }, 682 { "mx25l4005a", INFO(0xc22013, 0, 64 * 1024, 8, SECT_4K) },
670 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) }, 683 { "mx25l8005", INFO(0xc22014, 0, 64 * 1024, 16, 0) },
684 { "mx25l1606e", INFO(0xc22015, 0, 64 * 1024, 32, SECT_4K) },
671 { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) }, 685 { "mx25l3205d", INFO(0xc22016, 0, 64 * 1024, 64, 0) },
672 { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) }, 686 { "mx25l6405d", INFO(0xc22017, 0, 64 * 1024, 128, 0) },
673 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) }, 687 { "mx25l12805d", INFO(0xc22018, 0, 64 * 1024, 256, 0) },
@@ -684,6 +698,10 @@ static const struct spi_device_id m25p_ids[] = {
684 { "s25sl032a", INFO(0x010215, 0, 64 * 1024, 64, 0) }, 698 { "s25sl032a", INFO(0x010215, 0, 64 * 1024, 64, 0) },
685 { "s25sl032p", INFO(0x010215, 0x4d00, 64 * 1024, 64, SECT_4K) }, 699 { "s25sl032p", INFO(0x010215, 0x4d00, 64 * 1024, 64, SECT_4K) },
686 { "s25sl064a", INFO(0x010216, 0, 64 * 1024, 128, 0) }, 700 { "s25sl064a", INFO(0x010216, 0, 64 * 1024, 128, 0) },
701 { "s25fl256s0", INFO(0x010219, 0x4d00, 256 * 1024, 128, 0) },
702 { "s25fl256s1", INFO(0x010219, 0x4d01, 64 * 1024, 512, 0) },
703 { "s25fl512s", INFO(0x010220, 0x4d00, 256 * 1024, 256, 0) },
704 { "s70fl01gs", INFO(0x010221, 0x4d00, 256 * 1024, 256, 0) },
687 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) }, 705 { "s25sl12800", INFO(0x012018, 0x0300, 256 * 1024, 64, 0) },
688 { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) }, 706 { "s25sl12801", INFO(0x012018, 0x0301, 64 * 1024, 256, 0) },
689 { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, 0) }, 707 { "s25fl129p0", INFO(0x012018, 0x4d00, 256 * 1024, 64, 0) },
@@ -729,7 +747,10 @@ static const struct spi_device_id m25p_ids[] = {
729 { "m25pe80", INFO(0x208014, 0, 64 * 1024, 16, 0) }, 747 { "m25pe80", INFO(0x208014, 0, 64 * 1024, 16, 0) },
730 { "m25pe16", INFO(0x208015, 0, 64 * 1024, 32, SECT_4K) }, 748 { "m25pe16", INFO(0x208015, 0, 64 * 1024, 32, SECT_4K) },
731 749
732 { "m25px64", INFO(0x207117, 0, 64 * 1024, 128, 0) }, 750 { "m25px32", INFO(0x207116, 0, 64 * 1024, 64, SECT_4K) },
751 { "m25px32-s0", INFO(0x207316, 0, 64 * 1024, 64, SECT_4K) },
752 { "m25px32-s1", INFO(0x206316, 0, 64 * 1024, 64, SECT_4K) },
753 { "m25px64", INFO(0x207117, 0, 64 * 1024, 128, 0) },
733 754
734 /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */ 755 /* Winbond -- w25x "blocks" are 64K, "sectors" are 4KiB */
735 { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) }, 756 { "w25x10", INFO(0xef3011, 0, 64 * 1024, 2, SECT_4K) },
@@ -804,6 +825,8 @@ static int __devinit m25p_probe(struct spi_device *spi)
804 struct m25p *flash; 825 struct m25p *flash;
805 struct flash_info *info; 826 struct flash_info *info;
806 unsigned i; 827 unsigned i;
828 struct mtd_partition *parts = NULL;
829 int nr_parts = 0;
807 830
808 /* Platform data helps sort out which chip type we have, as 831 /* Platform data helps sort out which chip type we have, as
809 * well as how this board partitions it. If we don't have 832 * well as how this board partitions it. If we don't have
@@ -868,9 +891,9 @@ static int __devinit m25p_probe(struct spi_device *spi)
868 * up with the software protection bits set 891 * up with the software protection bits set
869 */ 892 */
870 893
871 if (info->jedec_id >> 16 == 0x1f || 894 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_ATMEL ||
872 info->jedec_id >> 16 == 0x89 || 895 JEDEC_MFR(info->jedec_id) == CFI_MFR_INTEL ||
873 info->jedec_id >> 16 == 0xbf) { 896 JEDEC_MFR(info->jedec_id) == CFI_MFR_SST) {
874 write_enable(flash); 897 write_enable(flash);
875 write_sr(flash, 0); 898 write_sr(flash, 0);
876 } 899 }
@@ -888,7 +911,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
888 flash->mtd.read = m25p80_read; 911 flash->mtd.read = m25p80_read;
889 912
890 /* sst flash chips use AAI word program */ 913 /* sst flash chips use AAI word program */
891 if (info->jedec_id >> 16 == 0xbf) 914 if (JEDEC_MFR(info->jedec_id) == CFI_MFR_SST)
892 flash->mtd.write = sst_write; 915 flash->mtd.write = sst_write;
893 else 916 else
894 flash->mtd.write = m25p80_write; 917 flash->mtd.write = m25p80_write;
@@ -914,7 +937,7 @@ static int __devinit m25p_probe(struct spi_device *spi)
914 /* enable 4-byte addressing if the device exceeds 16MiB */ 937 /* enable 4-byte addressing if the device exceeds 16MiB */
915 if (flash->mtd.size > 0x1000000) { 938 if (flash->mtd.size > 0x1000000) {
916 flash->addr_width = 4; 939 flash->addr_width = 4;
917 set_4byte(flash, 1); 940 set_4byte(flash, info->jedec_id, 1);
918 } else 941 } else
919 flash->addr_width = 3; 942 flash->addr_width = 3;
920 } 943 }
@@ -945,48 +968,41 @@ static int __devinit m25p_probe(struct spi_device *spi)
945 /* partitions should match sector boundaries; and it may be good to 968 /* partitions should match sector boundaries; and it may be good to
946 * use readonly partitions for writeprotected sectors (BP2..BP0). 969 * use readonly partitions for writeprotected sectors (BP2..BP0).
947 */ 970 */
948 if (mtd_has_partitions()) { 971 if (mtd_has_cmdlinepart()) {
949 struct mtd_partition *parts = NULL; 972 static const char *part_probes[]
950 int nr_parts = 0; 973 = { "cmdlinepart", NULL, };
951
952 if (mtd_has_cmdlinepart()) {
953 static const char *part_probes[]
954 = { "cmdlinepart", NULL, };
955 974
956 nr_parts = parse_mtd_partitions(&flash->mtd, 975 nr_parts = parse_mtd_partitions(&flash->mtd,
957 part_probes, &parts, 0); 976 part_probes, &parts, 0);
958 } 977 }
959 978
960 if (nr_parts <= 0 && data && data->parts) { 979 if (nr_parts <= 0 && data && data->parts) {
961 parts = data->parts; 980 parts = data->parts;
962 nr_parts = data->nr_parts; 981 nr_parts = data->nr_parts;
963 } 982 }
964 983
965#ifdef CONFIG_MTD_OF_PARTS 984#ifdef CONFIG_MTD_OF_PARTS
966 if (nr_parts <= 0 && spi->dev.of_node) { 985 if (nr_parts <= 0 && spi->dev.of_node) {
967 nr_parts = of_mtd_parse_partitions(&spi->dev, 986 nr_parts = of_mtd_parse_partitions(&spi->dev,
968 spi->dev.of_node, &parts); 987 spi->dev.of_node, &parts);
969 } 988 }
970#endif 989#endif
971 990
972 if (nr_parts > 0) { 991 if (nr_parts > 0) {
973 for (i = 0; i < nr_parts; i++) { 992 for (i = 0; i < nr_parts; i++) {
974 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = " 993 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = "
975 "{.name = %s, .offset = 0x%llx, " 994 "{.name = %s, .offset = 0x%llx, "
976 ".size = 0x%llx (%lldKiB) }\n", 995 ".size = 0x%llx (%lldKiB) }\n",
977 i, parts[i].name, 996 i, parts[i].name,
978 (long long)parts[i].offset, 997 (long long)parts[i].offset,
979 (long long)parts[i].size, 998 (long long)parts[i].size,
980 (long long)(parts[i].size >> 10)); 999 (long long)(parts[i].size >> 10));
981 }
982 flash->partitioned = 1;
983 return add_mtd_partitions(&flash->mtd, parts, nr_parts);
984 } 1000 }
985 } else if (data && data->nr_parts) 1001 flash->partitioned = 1;
986 dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", 1002 }
987 data->nr_parts, data->name);
988 1003
989 return add_mtd_device(&flash->mtd) == 1 ? -ENODEV : 0; 1004 return mtd_device_register(&flash->mtd, parts, nr_parts) == 1 ?
1005 -ENODEV : 0;
990} 1006}
991 1007
992 1008
@@ -996,10 +1012,7 @@ static int __devexit m25p_remove(struct spi_device *spi)
996 int status; 1012 int status;
997 1013
998 /* Clean up MTD stuff. */ 1014 /* Clean up MTD stuff. */
999 if (mtd_has_partitions() && flash->partitioned) 1015 status = mtd_device_unregister(&flash->mtd);
1000 status = del_mtd_partitions(&flash->mtd);
1001 else
1002 status = del_mtd_device(&flash->mtd);
1003 if (status == 0) { 1016 if (status == 0) {
1004 kfree(flash->command); 1017 kfree(flash->command);
1005 kfree(flash); 1018 kfree(flash);
diff --git a/drivers/mtd/devices/ms02-nv.c b/drivers/mtd/devices/ms02-nv.c
index 6a9a24a80a6d..8423fb6d4f26 100644
--- a/drivers/mtd/devices/ms02-nv.c
+++ b/drivers/mtd/devices/ms02-nv.c
@@ -220,7 +220,7 @@ static int __init ms02nv_init_one(ulong addr)
220 mtd->writesize = 1; 220 mtd->writesize = 1;
221 221
222 ret = -EIO; 222 ret = -EIO;
223 if (add_mtd_device(mtd)) { 223 if (mtd_device_register(mtd, NULL, 0)) {
224 printk(KERN_ERR 224 printk(KERN_ERR
225 "ms02-nv: Unable to register MTD device, aborting!\n"); 225 "ms02-nv: Unable to register MTD device, aborting!\n");
226 goto err_out_csr_res; 226 goto err_out_csr_res;
@@ -262,7 +262,7 @@ static void __exit ms02nv_remove_one(void)
262 262
263 root_ms02nv_mtd = mp->next; 263 root_ms02nv_mtd = mp->next;
264 264
265 del_mtd_device(mtd); 265 mtd_device_unregister(mtd);
266 266
267 release_resource(mp->resource.csr); 267 release_resource(mp->resource.csr);
268 kfree(mp->resource.csr); 268 kfree(mp->resource.csr);
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index c5015cc721d5..13749d458a31 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -637,6 +637,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
637 struct flash_platform_data *pdata = spi->dev.platform_data; 637 struct flash_platform_data *pdata = spi->dev.platform_data;
638 char *otp_tag = ""; 638 char *otp_tag = "";
639 int err = 0; 639 int err = 0;
640 struct mtd_partition *parts;
641 int nr_parts = 0;
640 642
641 priv = kzalloc(sizeof *priv, GFP_KERNEL); 643 priv = kzalloc(sizeof *priv, GFP_KERNEL);
642 if (!priv) 644 if (!priv)
@@ -675,33 +677,25 @@ add_dataflash_otp(struct spi_device *spi, char *name,
675 pagesize, otp_tag); 677 pagesize, otp_tag);
676 dev_set_drvdata(&spi->dev, priv); 678 dev_set_drvdata(&spi->dev, priv);
677 679
678 if (mtd_has_partitions()) { 680 if (mtd_has_cmdlinepart()) {
679 struct mtd_partition *parts; 681 static const char *part_probes[] = { "cmdlinepart", NULL, };
680 int nr_parts = 0;
681 682
682 if (mtd_has_cmdlinepart()) { 683 nr_parts = parse_mtd_partitions(device, part_probes, &parts,
683 static const char *part_probes[] 684 0);
684 = { "cmdlinepart", NULL, }; 685 }
685
686 nr_parts = parse_mtd_partitions(device,
687 part_probes, &parts, 0);
688 }
689 686
690 if (nr_parts <= 0 && pdata && pdata->parts) { 687 if (nr_parts <= 0 && pdata && pdata->parts) {
691 parts = pdata->parts; 688 parts = pdata->parts;
692 nr_parts = pdata->nr_parts; 689 nr_parts = pdata->nr_parts;
693 } 690 }
694 691
695 if (nr_parts > 0) { 692 if (nr_parts > 0) {
696 priv->partitioned = 1; 693 priv->partitioned = 1;
697 err = add_mtd_partitions(device, parts, nr_parts); 694 err = mtd_device_register(device, parts, nr_parts);
698 goto out; 695 goto out;
699 } 696 }
700 } else if (pdata && pdata->nr_parts)
701 dev_warn(&spi->dev, "ignoring %d default partitions on %s\n",
702 pdata->nr_parts, device->name);
703 697
704 if (add_mtd_device(device) == 1) 698 if (mtd_device_register(device, NULL, 0) == 1)
705 err = -ENODEV; 699 err = -ENODEV;
706 700
707out: 701out:
@@ -939,10 +933,7 @@ static int __devexit dataflash_remove(struct spi_device *spi)
939 933
940 DEBUG(MTD_DEBUG_LEVEL1, "%s: remove\n", dev_name(&spi->dev)); 934 DEBUG(MTD_DEBUG_LEVEL1, "%s: remove\n", dev_name(&spi->dev));
941 935
942 if (mtd_has_partitions() && flash->partitioned) 936 status = mtd_device_unregister(&flash->mtd);
943 status = del_mtd_partitions(&flash->mtd);
944 else
945 status = del_mtd_device(&flash->mtd);
946 if (status == 0) { 937 if (status == 0) {
947 dev_set_drvdata(&spi->dev, NULL); 938 dev_set_drvdata(&spi->dev, NULL);
948 kfree(flash); 939 kfree(flash);
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 1483e18971ce..2562689ba6b4 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -104,7 +104,7 @@ static int ram_write(struct mtd_info *mtd, loff_t to, size_t len,
104static void __exit cleanup_mtdram(void) 104static void __exit cleanup_mtdram(void)
105{ 105{
106 if (mtd_info) { 106 if (mtd_info) {
107 del_mtd_device(mtd_info); 107 mtd_device_unregister(mtd_info);
108 vfree(mtd_info->priv); 108 vfree(mtd_info->priv);
109 kfree(mtd_info); 109 kfree(mtd_info);
110 } 110 }
@@ -133,9 +133,8 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
133 mtd->read = ram_read; 133 mtd->read = ram_read;
134 mtd->write = ram_write; 134 mtd->write = ram_write;
135 135
136 if (add_mtd_device(mtd)) { 136 if (mtd_device_register(mtd, NULL, 0))
137 return -EIO; 137 return -EIO;
138 }
139 138
140 return 0; 139 return 0;
141} 140}
diff --git a/drivers/mtd/devices/phram.c b/drivers/mtd/devices/phram.c
index 8d28fa02a5a2..23423bd00b06 100644
--- a/drivers/mtd/devices/phram.c
+++ b/drivers/mtd/devices/phram.c
@@ -115,7 +115,7 @@ static void unregister_devices(void)
115 struct phram_mtd_list *this, *safe; 115 struct phram_mtd_list *this, *safe;
116 116
117 list_for_each_entry_safe(this, safe, &phram_list, list) { 117 list_for_each_entry_safe(this, safe, &phram_list, list) {
118 del_mtd_device(&this->mtd); 118 mtd_device_unregister(&this->mtd);
119 iounmap(this->mtd.priv); 119 iounmap(this->mtd.priv);
120 kfree(this->mtd.name); 120 kfree(this->mtd.name);
121 kfree(this); 121 kfree(this);
@@ -153,7 +153,7 @@ static int register_device(char *name, unsigned long start, unsigned long len)
153 new->mtd.writesize = 1; 153 new->mtd.writesize = 1;
154 154
155 ret = -EAGAIN; 155 ret = -EAGAIN;
156 if (add_mtd_device(&new->mtd)) { 156 if (mtd_device_register(&new->mtd, NULL, 0)) {
157 pr_err("Failed to register new device\n"); 157 pr_err("Failed to register new device\n");
158 goto out2; 158 goto out2;
159 } 159 }
diff --git a/drivers/mtd/devices/pmc551.c b/drivers/mtd/devices/pmc551.c
index 41b8cdcc64cb..ecff765579dd 100644
--- a/drivers/mtd/devices/pmc551.c
+++ b/drivers/mtd/devices/pmc551.c
@@ -798,7 +798,7 @@ static int __init init_pmc551(void)
798 mtd->writesize = 1; 798 mtd->writesize = 1;
799 mtd->owner = THIS_MODULE; 799 mtd->owner = THIS_MODULE;
800 800
801 if (add_mtd_device(mtd)) { 801 if (mtd_device_register(mtd, NULL, 0)) {
802 printk(KERN_NOTICE "pmc551: Failed to register new device\n"); 802 printk(KERN_NOTICE "pmc551: Failed to register new device\n");
803 pci_iounmap(PCI_Device, priv->start); 803 pci_iounmap(PCI_Device, priv->start);
804 kfree(mtd->priv); 804 kfree(mtd->priv);
@@ -806,7 +806,7 @@ static int __init init_pmc551(void)
806 break; 806 break;
807 } 807 }
808 808
809 /* Keep a reference as the add_mtd_device worked */ 809 /* Keep a reference as the mtd_device_register worked */
810 pci_dev_get(PCI_Device); 810 pci_dev_get(PCI_Device);
811 811
812 printk(KERN_NOTICE "Registered pmc551 memory device.\n"); 812 printk(KERN_NOTICE "Registered pmc551 memory device.\n");
@@ -856,7 +856,7 @@ static void __exit cleanup_pmc551(void)
856 pci_dev_put(priv->dev); 856 pci_dev_put(priv->dev);
857 857
858 kfree(mtd->priv); 858 kfree(mtd->priv);
859 del_mtd_device(mtd); 859 mtd_device_unregister(mtd);
860 kfree(mtd); 860 kfree(mtd);
861 found++; 861 found++;
862 } 862 }
diff --git a/drivers/mtd/devices/slram.c b/drivers/mtd/devices/slram.c
index 592016a0668f..e585263161b9 100644
--- a/drivers/mtd/devices/slram.c
+++ b/drivers/mtd/devices/slram.c
@@ -210,7 +210,7 @@ static int register_device(char *name, unsigned long start, unsigned long length
210 (*curmtd)->mtdinfo->erasesize = SLRAM_BLK_SZ; 210 (*curmtd)->mtdinfo->erasesize = SLRAM_BLK_SZ;
211 (*curmtd)->mtdinfo->writesize = 1; 211 (*curmtd)->mtdinfo->writesize = 1;
212 212
213 if (add_mtd_device((*curmtd)->mtdinfo)) { 213 if (mtd_device_register((*curmtd)->mtdinfo, NULL, 0)) {
214 E("slram: Failed to register new device\n"); 214 E("slram: Failed to register new device\n");
215 iounmap(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start); 215 iounmap(((slram_priv_t *)(*curmtd)->mtdinfo->priv)->start);
216 kfree((*curmtd)->mtdinfo->priv); 216 kfree((*curmtd)->mtdinfo->priv);
@@ -231,7 +231,7 @@ static void unregister_devices(void)
231 231
232 while (slram_mtdlist) { 232 while (slram_mtdlist) {
233 nextitem = slram_mtdlist->next; 233 nextitem = slram_mtdlist->next;
234 del_mtd_device(slram_mtdlist->mtdinfo); 234 mtd_device_unregister(slram_mtdlist->mtdinfo);
235 iounmap(((slram_priv_t *)slram_mtdlist->mtdinfo->priv)->start); 235 iounmap(((slram_priv_t *)slram_mtdlist->mtdinfo->priv)->start);
236 kfree(slram_mtdlist->mtdinfo->priv); 236 kfree(slram_mtdlist->mtdinfo->priv);
237 kfree(slram_mtdlist->mtdinfo); 237 kfree(slram_mtdlist->mtdinfo);
diff --git a/drivers/mtd/devices/sst25l.c b/drivers/mtd/devices/sst25l.c
index c163e619abc9..1e2c430aaad2 100644
--- a/drivers/mtd/devices/sst25l.c
+++ b/drivers/mtd/devices/sst25l.c
@@ -66,7 +66,7 @@ struct flash_info {
66 66
67#define to_sst25l_flash(x) container_of(x, struct sst25l_flash, mtd) 67#define to_sst25l_flash(x) container_of(x, struct sst25l_flash, mtd)
68 68
69static struct flash_info __initdata sst25l_flash_info[] = { 69static struct flash_info __devinitdata sst25l_flash_info[] = {
70 {"sst25lf020a", 0xbf43, 256, 1024, 4096}, 70 {"sst25lf020a", 0xbf43, 256, 1024, 4096},
71 {"sst25lf040a", 0xbf44, 256, 2048, 4096}, 71 {"sst25lf040a", 0xbf44, 256, 2048, 4096},
72}; 72};
@@ -381,6 +381,8 @@ static int __devinit sst25l_probe(struct spi_device *spi)
381 struct sst25l_flash *flash; 381 struct sst25l_flash *flash;
382 struct flash_platform_data *data; 382 struct flash_platform_data *data;
383 int ret, i; 383 int ret, i;
384 struct mtd_partition *parts = NULL;
385 int nr_parts = 0;
384 386
385 flash_info = sst25l_match_device(spi); 387 flash_info = sst25l_match_device(spi);
386 if (!flash_info) 388 if (!flash_info)
@@ -420,46 +422,37 @@ static int __devinit sst25l_probe(struct spi_device *spi)
420 flash->mtd.erasesize, flash->mtd.erasesize / 1024, 422 flash->mtd.erasesize, flash->mtd.erasesize / 1024,
421 flash->mtd.numeraseregions); 423 flash->mtd.numeraseregions);
422 424
423 if (mtd_has_partitions()) {
424 struct mtd_partition *parts = NULL;
425 int nr_parts = 0;
426 425
427 if (mtd_has_cmdlinepart()) { 426 if (mtd_has_cmdlinepart()) {
428 static const char *part_probes[] = 427 static const char *part_probes[] = {"cmdlinepart", NULL};
429 {"cmdlinepart", NULL};
430 428
431 nr_parts = parse_mtd_partitions(&flash->mtd, 429 nr_parts = parse_mtd_partitions(&flash->mtd,
432 part_probes, 430 part_probes,
433 &parts, 0); 431 &parts, 0);
434 } 432 }
435 433
436 if (nr_parts <= 0 && data && data->parts) { 434 if (nr_parts <= 0 && data && data->parts) {
437 parts = data->parts; 435 parts = data->parts;
438 nr_parts = data->nr_parts; 436 nr_parts = data->nr_parts;
439 } 437 }
440 438
441 if (nr_parts > 0) { 439 if (nr_parts > 0) {
442 for (i = 0; i < nr_parts; i++) { 440 for (i = 0; i < nr_parts; i++) {
443 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = " 441 DEBUG(MTD_DEBUG_LEVEL2, "partitions[%d] = "
444 "{.name = %s, .offset = 0x%llx, " 442 "{.name = %s, .offset = 0x%llx, "
445 ".size = 0x%llx (%lldKiB) }\n", 443 ".size = 0x%llx (%lldKiB) }\n",
446 i, parts[i].name, 444 i, parts[i].name,
447 (long long)parts[i].offset, 445 (long long)parts[i].offset,
448 (long long)parts[i].size, 446 (long long)parts[i].size,
449 (long long)(parts[i].size >> 10)); 447 (long long)(parts[i].size >> 10));
450 }
451
452 flash->partitioned = 1;
453 return add_mtd_partitions(&flash->mtd,
454 parts, nr_parts);
455 } 448 }
456 449
457 } else if (data && data->nr_parts) { 450 flash->partitioned = 1;
458 dev_warn(&spi->dev, "ignoring %d default partitions on %s\n", 451 return mtd_device_register(&flash->mtd, parts,
459 data->nr_parts, data->name); 452 nr_parts);
460 } 453 }
461 454
462 ret = add_mtd_device(&flash->mtd); 455 ret = mtd_device_register(&flash->mtd, NULL, 0);
463 if (ret == 1) { 456 if (ret == 1) {
464 kfree(flash); 457 kfree(flash);
465 dev_set_drvdata(&spi->dev, NULL); 458 dev_set_drvdata(&spi->dev, NULL);
@@ -469,15 +462,12 @@ static int __devinit sst25l_probe(struct spi_device *spi)
469 return 0; 462 return 0;
470} 463}
471 464
472static int __exit sst25l_remove(struct spi_device *spi) 465static int __devexit sst25l_remove(struct spi_device *spi)
473{ 466{
474 struct sst25l_flash *flash = dev_get_drvdata(&spi->dev); 467 struct sst25l_flash *flash = dev_get_drvdata(&spi->dev);
475 int ret; 468 int ret;
476 469
477 if (mtd_has_partitions() && flash->partitioned) 470 ret = mtd_device_unregister(&flash->mtd);
478 ret = del_mtd_partitions(&flash->mtd);
479 else
480 ret = del_mtd_device(&flash->mtd);
481 if (ret == 0) 471 if (ret == 0)
482 kfree(flash); 472 kfree(flash);
483 return ret; 473 return ret;
@@ -490,7 +480,7 @@ static struct spi_driver sst25l_driver = {
490 .owner = THIS_MODULE, 480 .owner = THIS_MODULE,
491 }, 481 },
492 .probe = sst25l_probe, 482 .probe = sst25l_probe,
493 .remove = __exit_p(sst25l_remove), 483 .remove = __devexit_p(sst25l_remove),
494}; 484};
495 485
496static int __init sst25l_init(void) 486static int __init sst25l_init(void)
diff --git a/drivers/mtd/lpddr/lpddr_cmds.c b/drivers/mtd/lpddr/lpddr_cmds.c
index 12679925b420..65655dd59e1f 100644
--- a/drivers/mtd/lpddr/lpddr_cmds.c
+++ b/drivers/mtd/lpddr/lpddr_cmds.c
@@ -313,12 +313,7 @@ static int chip_ready(struct map_info *map, struct flchip *chip, int mode)
313 if (ret) { 313 if (ret) {
314 /* Oops. something got wrong. */ 314 /* Oops. something got wrong. */
315 /* Resume and pretend we weren't here. */ 315 /* Resume and pretend we weren't here. */
316 map_write(map, CMD(LPDDR_RESUME), 316 put_chip(map, chip);
317 map->pfow_base + PFOW_COMMAND_CODE);
318 map_write(map, CMD(LPDDR_START_EXECUTION),
319 map->pfow_base + PFOW_COMMAND_EXECUTE);
320 chip->state = FL_ERASING;
321 chip->oldstate = FL_READY;
322 printk(KERN_ERR "%s: suspend operation failed." 317 printk(KERN_ERR "%s: suspend operation failed."
323 "State may be wrong \n", map->name); 318 "State may be wrong \n", map->name);
324 return -EIO; 319 return -EIO;
@@ -383,7 +378,6 @@ static void put_chip(struct map_info *map, struct flchip *chip)
383 378
384 switch (chip->oldstate) { 379 switch (chip->oldstate) {
385 case FL_ERASING: 380 case FL_ERASING:
386 chip->state = chip->oldstate;
387 map_write(map, CMD(LPDDR_RESUME), 381 map_write(map, CMD(LPDDR_RESUME),
388 map->pfow_base + PFOW_COMMAND_CODE); 382 map->pfow_base + PFOW_COMMAND_CODE);
389 map_write(map, CMD(LPDDR_START_EXECUTION), 383 map_write(map, CMD(LPDDR_START_EXECUTION),
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 5069111c81cc..c0c328c5b133 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -82,7 +82,6 @@ config MTD_PHYSMAP_OF
82config MTD_PMC_MSP_EVM 82config MTD_PMC_MSP_EVM
83 tristate "CFI Flash device mapped on PMC-Sierra MSP" 83 tristate "CFI Flash device mapped on PMC-Sierra MSP"
84 depends on PMC_MSP && MTD_CFI 84 depends on PMC_MSP && MTD_CFI
85 select MTD_PARTITIONS
86 help 85 help
87 This provides a 'mapping' driver which supports the way 86 This provides a 'mapping' driver which supports the way
88 in which user-programmable flash chips are connected on the 87 in which user-programmable flash chips are connected on the
@@ -122,7 +121,7 @@ config MTD_SC520CDP
122 121
123config MTD_NETSC520 122config MTD_NETSC520
124 tristate "CFI Flash device mapped on AMD NetSc520" 123 tristate "CFI Flash device mapped on AMD NetSc520"
125 depends on X86 && MTD_CFI && MTD_PARTITIONS 124 depends on X86 && MTD_CFI
126 help 125 help
127 This enables access routines for the flash chips on the AMD NetSc520 126 This enables access routines for the flash chips on the AMD NetSc520
128 demonstration board. If you have one of these boards and would like 127 demonstration board. If you have one of these boards and would like
@@ -131,7 +130,6 @@ config MTD_NETSC520
131config MTD_TS5500 130config MTD_TS5500
132 tristate "JEDEC Flash device mapped on Technologic Systems TS-5500" 131 tristate "JEDEC Flash device mapped on Technologic Systems TS-5500"
133 depends on X86 132 depends on X86
134 select MTD_PARTITIONS
135 select MTD_JEDECPROBE 133 select MTD_JEDECPROBE
136 select MTD_CFI_AMDSTD 134 select MTD_CFI_AMDSTD
137 help 135 help
@@ -149,7 +147,7 @@ config MTD_TS5500
149 147
150config MTD_SBC_GXX 148config MTD_SBC_GXX
151 tristate "CFI Flash device mapped on Arcom SBC-GXx boards" 149 tristate "CFI Flash device mapped on Arcom SBC-GXx boards"
152 depends on X86 && MTD_CFI_INTELEXT && MTD_PARTITIONS && MTD_COMPLEX_MAPPINGS 150 depends on X86 && MTD_CFI_INTELEXT && MTD_COMPLEX_MAPPINGS
153 help 151 help
154 This provides a driver for the on-board flash of Arcom Control 152 This provides a driver for the on-board flash of Arcom Control
155 Systems' SBC-GXn family of boards, formerly known as SBC-MediaGX. 153 Systems' SBC-GXn family of boards, formerly known as SBC-MediaGX.
@@ -161,7 +159,6 @@ config MTD_SBC_GXX
161config MTD_PXA2XX 159config MTD_PXA2XX
162 tristate "CFI Flash device mapped on Intel XScale PXA2xx based boards" 160 tristate "CFI Flash device mapped on Intel XScale PXA2xx based boards"
163 depends on (PXA25x || PXA27x) && MTD_CFI_INTELEXT 161 depends on (PXA25x || PXA27x) && MTD_CFI_INTELEXT
164 select MTD_PARTITIONS
165 help 162 help
166 This provides a driver for the NOR flash attached to a PXA2xx chip. 163 This provides a driver for the NOR flash attached to a PXA2xx chip.
167 164
@@ -185,7 +182,7 @@ config MTD_VMAX
185 182
186config MTD_SCx200_DOCFLASH 183config MTD_SCx200_DOCFLASH
187 tristate "Flash device mapped with DOCCS on NatSemi SCx200" 184 tristate "Flash device mapped with DOCCS on NatSemi SCx200"
188 depends on SCx200 && MTD_CFI && MTD_PARTITIONS 185 depends on SCx200 && MTD_CFI
189 help 186 help
190 Enable support for a flash chip mapped using the DOCCS signal on a 187 Enable support for a flash chip mapped using the DOCCS signal on a
191 National Semiconductor SCx200 processor. 188 National Semiconductor SCx200 processor.
@@ -247,7 +244,7 @@ config MTD_TSUNAMI
247 244
248config MTD_NETtel 245config MTD_NETtel
249 tristate "CFI flash device on SnapGear/SecureEdge" 246 tristate "CFI flash device on SnapGear/SecureEdge"
250 depends on X86 && MTD_PARTITIONS && MTD_JEDECPROBE 247 depends on X86 && MTD_JEDECPROBE
251 help 248 help
252 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 249 Support for flash chips on NETtel/SecureEdge/SnapGear boards.
253 250
@@ -269,7 +266,7 @@ config MTD_LANTIQ
269 266
270config MTD_DILNETPC 267config MTD_DILNETPC
271 tristate "CFI Flash device mapped on DIL/Net PC" 268 tristate "CFI Flash device mapped on DIL/Net PC"
272 depends on X86 && MTD_PARTITIONS && MTD_CFI_INTELEXT && BROKEN 269 depends on X86 && MTD_CFI_INTELEXT && BROKEN
273 help 270 help
274 MTD map driver for SSV DIL/Net PC Boards "DNP" and "ADNP". 271 MTD map driver for SSV DIL/Net PC Boards "DNP" and "ADNP".
275 For details, see <http://www.ssv-embedded.de/ssv/pc104/p169.htm> 272 For details, see <http://www.ssv-embedded.de/ssv/pc104/p169.htm>
@@ -355,7 +352,7 @@ config MTD_CDB89712
355 352
356config MTD_SA1100 353config MTD_SA1100
357 tristate "CFI Flash device mapped on StrongARM SA11x0" 354 tristate "CFI Flash device mapped on StrongARM SA11x0"
358 depends on MTD_CFI && ARCH_SA1100 && MTD_PARTITIONS 355 depends on MTD_CFI && ARCH_SA1100
359 help 356 help
360 This enables access to the flash chips on most platforms based on 357 This enables access to the flash chips on most platforms based on
361 the SA1100 and SA1110, including the Assabet and the Compaq iPAQ. 358 the SA1100 and SA1110, including the Assabet and the Compaq iPAQ.
@@ -389,7 +386,7 @@ config MTD_IXP2000
389 386
390config MTD_FORTUNET 387config MTD_FORTUNET
391 tristate "CFI Flash device mapped on the FortuNet board" 388 tristate "CFI Flash device mapped on the FortuNet board"
392 depends on MTD_CFI && MTD_PARTITIONS && SA1100_FORTUNET 389 depends on MTD_CFI && SA1100_FORTUNET
393 help 390 help
394 This enables access to the Flash on the FortuNet board. If you 391 This enables access to the Flash on the FortuNet board. If you
395 have such a board, say 'Y'. 392 have such a board, say 'Y'.
@@ -461,7 +458,6 @@ config MTD_PCMCIA_ANONYMOUS
461config MTD_BFIN_ASYNC 458config MTD_BFIN_ASYNC
462 tristate "Blackfin BF533-STAMP Flash Chip Support" 459 tristate "Blackfin BF533-STAMP Flash Chip Support"
463 depends on BFIN533_STAMP && MTD_CFI && MTD_COMPLEX_MAPPINGS 460 depends on BFIN533_STAMP && MTD_CFI && MTD_COMPLEX_MAPPINGS
464 select MTD_PARTITIONS
465 default y 461 default y
466 help 462 help
467 Map driver which allows for simultaneous utilization of 463 Map driver which allows for simultaneous utilization of
@@ -473,7 +469,6 @@ config MTD_GPIO_ADDR
473 tristate "GPIO-assisted Flash Chip Support" 469 tristate "GPIO-assisted Flash Chip Support"
474 depends on GENERIC_GPIO || GPIOLIB 470 depends on GENERIC_GPIO || GPIOLIB
475 depends on MTD_COMPLEX_MAPPINGS 471 depends on MTD_COMPLEX_MAPPINGS
476 select MTD_PARTITIONS
477 help 472 help
478 Map driver which allows flashes to be partially physically addressed 473 Map driver which allows flashes to be partially physically addressed
479 and assisted by GPIOs. 474 and assisted by GPIOs.
@@ -482,14 +477,13 @@ config MTD_GPIO_ADDR
482 477
483config MTD_UCLINUX 478config MTD_UCLINUX
484 bool "Generic uClinux RAM/ROM filesystem support" 479 bool "Generic uClinux RAM/ROM filesystem support"
485 depends on MTD_PARTITIONS && MTD_RAM=y && !MMU 480 depends on MTD_RAM=y && !MMU
486 help 481 help
487 Map driver to support image based filesystems for uClinux. 482 Map driver to support image based filesystems for uClinux.
488 483
489config MTD_WRSBC8260 484config MTD_WRSBC8260
490 tristate "Map driver for WindRiver PowerQUICC II MPC82xx board" 485 tristate "Map driver for WindRiver PowerQUICC II MPC82xx board"
491 depends on (SBC82xx || SBC8560) 486 depends on (SBC82xx || SBC8560)
492 select MTD_PARTITIONS
493 select MTD_MAP_BANK_WIDTH_4 487 select MTD_MAP_BANK_WIDTH_4
494 select MTD_MAP_BANK_WIDTH_1 488 select MTD_MAP_BANK_WIDTH_1
495 select MTD_CFI_I1 489 select MTD_CFI_I1
@@ -502,7 +496,6 @@ config MTD_WRSBC8260
502config MTD_DMV182 496config MTD_DMV182
503 tristate "Map driver for Dy-4 SVME/DMV-182 board." 497 tristate "Map driver for Dy-4 SVME/DMV-182 board."
504 depends on DMV182 498 depends on DMV182
505 select MTD_PARTITIONS
506 select MTD_MAP_BANK_WIDTH_32 499 select MTD_MAP_BANK_WIDTH_32
507 select MTD_CFI_I8 500 select MTD_CFI_I8
508 select MTD_CFI_AMDSTD 501 select MTD_CFI_AMDSTD
diff --git a/drivers/mtd/maps/amd76xrom.c b/drivers/mtd/maps/amd76xrom.c
index 92de7e3a49a5..e2875d6fe129 100644
--- a/drivers/mtd/maps/amd76xrom.c
+++ b/drivers/mtd/maps/amd76xrom.c
@@ -82,7 +82,7 @@ static void amd76xrom_cleanup(struct amd76xrom_window *window)
82 if (map->rsrc.parent) { 82 if (map->rsrc.parent) {
83 release_resource(&map->rsrc); 83 release_resource(&map->rsrc);
84 } 84 }
85 del_mtd_device(map->mtd); 85 mtd_device_unregister(map->mtd);
86 map_destroy(map->mtd); 86 map_destroy(map->mtd);
87 list_del(&map->list); 87 list_del(&map->list);
88 kfree(map); 88 kfree(map);
@@ -262,7 +262,7 @@ static int __devinit amd76xrom_init_one (struct pci_dev *pdev,
262 262
263 /* Now that the mtd devices is complete claim and export it */ 263 /* Now that the mtd devices is complete claim and export it */
264 map->mtd->owner = THIS_MODULE; 264 map->mtd->owner = THIS_MODULE;
265 if (add_mtd_device(map->mtd)) { 265 if (mtd_device_register(map->mtd, NULL, 0)) {
266 map_destroy(map->mtd); 266 map_destroy(map->mtd);
267 map->mtd = NULL; 267 map->mtd = NULL;
268 goto out; 268 goto out;
diff --git a/drivers/mtd/maps/autcpu12-nvram.c b/drivers/mtd/maps/autcpu12-nvram.c
index 53664188fc47..e5bfd0e093bb 100644
--- a/drivers/mtd/maps/autcpu12-nvram.c
+++ b/drivers/mtd/maps/autcpu12-nvram.c
@@ -88,7 +88,7 @@ map:
88 sram_mtd->owner = THIS_MODULE; 88 sram_mtd->owner = THIS_MODULE;
89 sram_mtd->erasesize = 16; 89 sram_mtd->erasesize = 16;
90 90
91 if (add_mtd_device(sram_mtd)) { 91 if (mtd_device_register(sram_mtd, NULL, 0)) {
92 printk("NV-RAM device addition failed\n"); 92 printk("NV-RAM device addition failed\n");
93 err = -ENOMEM; 93 err = -ENOMEM;
94 goto out_probe; 94 goto out_probe;
@@ -111,7 +111,7 @@ out:
111static void __exit cleanup_autcpu12_maps(void) 111static void __exit cleanup_autcpu12_maps(void)
112{ 112{
113 if (sram_mtd) { 113 if (sram_mtd) {
114 del_mtd_device(sram_mtd); 114 mtd_device_unregister(sram_mtd);
115 map_destroy(sram_mtd); 115 map_destroy(sram_mtd);
116 iounmap((void *)autcpu12_sram_map.virt); 116 iounmap((void *)autcpu12_sram_map.virt);
117 } 117 }
diff --git a/drivers/mtd/maps/bcm963xx-flash.c b/drivers/mtd/maps/bcm963xx-flash.c
index 1f3049590d9e..608967fe74c6 100644
--- a/drivers/mtd/maps/bcm963xx-flash.c
+++ b/drivers/mtd/maps/bcm963xx-flash.c
@@ -224,8 +224,8 @@ probe_ok:
224 goto err_probe; 224 goto err_probe;
225 } 225 }
226 226
227 return add_mtd_partitions(bcm963xx_mtd_info, parsed_parts, 227 return mtd_device_register(bcm963xx_mtd_info, parsed_parts,
228 parsed_nr_parts); 228 parsed_nr_parts);
229 229
230err_probe: 230err_probe:
231 iounmap(bcm963xx_map.virt); 231 iounmap(bcm963xx_map.virt);
@@ -235,7 +235,7 @@ err_probe:
235static int bcm963xx_remove(struct platform_device *pdev) 235static int bcm963xx_remove(struct platform_device *pdev)
236{ 236{
237 if (bcm963xx_mtd_info) { 237 if (bcm963xx_mtd_info) {
238 del_mtd_partitions(bcm963xx_mtd_info); 238 mtd_device_unregister(bcm963xx_mtd_info);
239 map_destroy(bcm963xx_mtd_info); 239 map_destroy(bcm963xx_mtd_info);
240 } 240 }
241 241
diff --git a/drivers/mtd/maps/bfin-async-flash.c b/drivers/mtd/maps/bfin-async-flash.c
index 85dd18193cf2..d4297a97e100 100644
--- a/drivers/mtd/maps/bfin-async-flash.c
+++ b/drivers/mtd/maps/bfin-async-flash.c
@@ -41,9 +41,7 @@ struct async_state {
41 uint32_t flash_ambctl0, flash_ambctl1; 41 uint32_t flash_ambctl0, flash_ambctl1;
42 uint32_t save_ambctl0, save_ambctl1; 42 uint32_t save_ambctl0, save_ambctl1;
43 unsigned long irq_flags; 43 unsigned long irq_flags;
44#ifdef CONFIG_MTD_PARTITIONS
45 struct mtd_partition *parts; 44 struct mtd_partition *parts;
46#endif
47}; 45};
48 46
49static void switch_to_flash(struct async_state *state) 47static void switch_to_flash(struct async_state *state)
@@ -124,9 +122,7 @@ static void bfin_flash_copy_to(struct map_info *map, unsigned long to, const voi
124 switch_back(state); 122 switch_back(state);
125} 123}
126 124
127#ifdef CONFIG_MTD_PARTITIONS
128static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL }; 125static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
129#endif
130 126
131static int __devinit bfin_flash_probe(struct platform_device *pdev) 127static int __devinit bfin_flash_probe(struct platform_device *pdev)
132{ 128{
@@ -169,22 +165,17 @@ static int __devinit bfin_flash_probe(struct platform_device *pdev)
169 return -ENXIO; 165 return -ENXIO;
170 } 166 }
171 167
172#ifdef CONFIG_MTD_PARTITIONS
173 ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0); 168 ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0);
174 if (ret > 0) { 169 if (ret > 0) {
175 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n"); 170 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using commandline partition definition\n");
176 add_mtd_partitions(state->mtd, pdata->parts, ret); 171 mtd_device_register(state->mtd, pdata->parts, ret);
177 state->parts = pdata->parts; 172 state->parts = pdata->parts;
178
179 } else if (pdata->nr_parts) { 173 } else if (pdata->nr_parts) {
180 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n"); 174 pr_devinit(KERN_NOTICE DRIVER_NAME ": Using board partition definition\n");
181 add_mtd_partitions(state->mtd, pdata->parts, pdata->nr_parts); 175 mtd_device_register(state->mtd, pdata->parts, pdata->nr_parts);
182 176 } else {
183 } else
184#endif
185 {
186 pr_devinit(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n"); 177 pr_devinit(KERN_NOTICE DRIVER_NAME ": no partition info available, registering whole flash at once\n");
187 add_mtd_device(state->mtd); 178 mtd_device_register(state->mtd, NULL, 0);
188 } 179 }
189 180
190 platform_set_drvdata(pdev, state); 181 platform_set_drvdata(pdev, state);
@@ -196,10 +187,8 @@ static int __devexit bfin_flash_remove(struct platform_device *pdev)
196{ 187{
197 struct async_state *state = platform_get_drvdata(pdev); 188 struct async_state *state = platform_get_drvdata(pdev);
198 gpio_free(state->enet_flash_pin); 189 gpio_free(state->enet_flash_pin);
199#ifdef CONFIG_MTD_PARTITIONS 190 mtd_device_unregister(state->mtd);
200 del_mtd_partitions(state->mtd);
201 kfree(state->parts); 191 kfree(state->parts);
202#endif
203 map_destroy(state->mtd); 192 map_destroy(state->mtd);
204 kfree(state); 193 kfree(state);
205 return 0; 194 return 0;
diff --git a/drivers/mtd/maps/cdb89712.c b/drivers/mtd/maps/cdb89712.c
index 8d92d8db9a98..c29cbf87ea0c 100644
--- a/drivers/mtd/maps/cdb89712.c
+++ b/drivers/mtd/maps/cdb89712.c
@@ -75,7 +75,7 @@ static int __init init_cdb89712_flash (void)
75 75
76 flash_mtd->owner = THIS_MODULE; 76 flash_mtd->owner = THIS_MODULE;
77 77
78 if (add_mtd_device(flash_mtd)) { 78 if (mtd_device_register(flash_mtd, NULL, 0)) {
79 printk("FLASH device addition failed\n"); 79 printk("FLASH device addition failed\n");
80 err = -ENOMEM; 80 err = -ENOMEM;
81 goto out_probe; 81 goto out_probe;
@@ -141,7 +141,7 @@ static int __init init_cdb89712_sram (void)
141 sram_mtd->owner = THIS_MODULE; 141 sram_mtd->owner = THIS_MODULE;
142 sram_mtd->erasesize = 16; 142 sram_mtd->erasesize = 16;
143 143
144 if (add_mtd_device(sram_mtd)) { 144 if (mtd_device_register(sram_mtd, NULL, 0)) {
145 printk("SRAM device addition failed\n"); 145 printk("SRAM device addition failed\n");
146 err = -ENOMEM; 146 err = -ENOMEM;
147 goto out_probe; 147 goto out_probe;
@@ -209,7 +209,7 @@ static int __init init_cdb89712_bootrom (void)
209 bootrom_mtd->owner = THIS_MODULE; 209 bootrom_mtd->owner = THIS_MODULE;
210 bootrom_mtd->erasesize = 0x10000; 210 bootrom_mtd->erasesize = 0x10000;
211 211
212 if (add_mtd_device(bootrom_mtd)) { 212 if (mtd_device_register(bootrom_mtd, NULL, 0)) {
213 printk("BootROM device addition failed\n"); 213 printk("BootROM device addition failed\n");
214 err = -ENOMEM; 214 err = -ENOMEM;
215 goto out_probe; 215 goto out_probe;
@@ -249,21 +249,21 @@ static int __init init_cdb89712_maps(void)
249static void __exit cleanup_cdb89712_maps(void) 249static void __exit cleanup_cdb89712_maps(void)
250{ 250{
251 if (sram_mtd) { 251 if (sram_mtd) {
252 del_mtd_device(sram_mtd); 252 mtd_device_unregister(sram_mtd);
253 map_destroy(sram_mtd); 253 map_destroy(sram_mtd);
254 iounmap((void *)cdb89712_sram_map.virt); 254 iounmap((void *)cdb89712_sram_map.virt);
255 release_resource (&cdb89712_sram_resource); 255 release_resource (&cdb89712_sram_resource);
256 } 256 }
257 257
258 if (flash_mtd) { 258 if (flash_mtd) {
259 del_mtd_device(flash_mtd); 259 mtd_device_unregister(flash_mtd);
260 map_destroy(flash_mtd); 260 map_destroy(flash_mtd);
261 iounmap((void *)cdb89712_flash_map.virt); 261 iounmap((void *)cdb89712_flash_map.virt);
262 release_resource (&cdb89712_flash_resource); 262 release_resource (&cdb89712_flash_resource);
263 } 263 }
264 264
265 if (bootrom_mtd) { 265 if (bootrom_mtd) {
266 del_mtd_device(bootrom_mtd); 266 mtd_device_unregister(bootrom_mtd);
267 map_destroy(bootrom_mtd); 267 map_destroy(bootrom_mtd);
268 iounmap((void *)cdb89712_bootrom_map.virt); 268 iounmap((void *)cdb89712_bootrom_map.virt);
269 release_resource (&cdb89712_bootrom_resource); 269 release_resource (&cdb89712_bootrom_resource);
diff --git a/drivers/mtd/maps/ceiva.c b/drivers/mtd/maps/ceiva.c
index 23f551dc8ca8..06f9c9815720 100644
--- a/drivers/mtd/maps/ceiva.c
+++ b/drivers/mtd/maps/ceiva.c
@@ -224,7 +224,7 @@ static void __exit clps_destroy_mtd(struct clps_info *clps, struct mtd_info *mtd
224{ 224{
225 int i; 225 int i;
226 226
227 del_mtd_partitions(mtd); 227 mtd_device_unregister(mtd);
228 228
229 if (mtd != clps[0].mtd) 229 if (mtd != clps[0].mtd)
230 mtd_concat_destroy(mtd); 230 mtd_concat_destroy(mtd);
@@ -292,11 +292,11 @@ static void __init clps_locate_partitions(struct mtd_info *mtd)
292 if (nr_parts == 0) { 292 if (nr_parts == 0) {
293 printk(KERN_NOTICE "clps flash: no partition info " 293 printk(KERN_NOTICE "clps flash: no partition info "
294 "available, registering whole flash\n"); 294 "available, registering whole flash\n");
295 add_mtd_device(mtd); 295 mtd_device_register(mtd, NULL, 0);
296 } else { 296 } else {
297 printk(KERN_NOTICE "clps flash: using %s partition " 297 printk(KERN_NOTICE "clps flash: using %s partition "
298 "definition\n", part_type); 298 "definition\n", part_type);
299 add_mtd_partitions(mtd, parsed_parts, nr_parts); 299 mtd_device_register(mtd, parsed_parts, nr_parts);
300 } 300 }
301 301
302 /* Always succeeds. */ 302 /* Always succeeds. */
diff --git a/drivers/mtd/maps/cfi_flagadm.c b/drivers/mtd/maps/cfi_flagadm.c
index f71343cd77cc..d16fc9d3b8cd 100644
--- a/drivers/mtd/maps/cfi_flagadm.c
+++ b/drivers/mtd/maps/cfi_flagadm.c
@@ -107,7 +107,7 @@ static int __init init_flagadm(void)
107 mymtd = do_map_probe("cfi_probe", &flagadm_map); 107 mymtd = do_map_probe("cfi_probe", &flagadm_map);
108 if (mymtd) { 108 if (mymtd) {
109 mymtd->owner = THIS_MODULE; 109 mymtd->owner = THIS_MODULE;
110 add_mtd_partitions(mymtd, flagadm_parts, PARTITION_COUNT); 110 mtd_device_register(mymtd, flagadm_parts, PARTITION_COUNT);
111 printk(KERN_NOTICE "FlagaDM flash device initialized\n"); 111 printk(KERN_NOTICE "FlagaDM flash device initialized\n");
112 return 0; 112 return 0;
113 } 113 }
@@ -119,7 +119,7 @@ static int __init init_flagadm(void)
119static void __exit cleanup_flagadm(void) 119static void __exit cleanup_flagadm(void)
120{ 120{
121 if (mymtd) { 121 if (mymtd) {
122 del_mtd_partitions(mymtd); 122 mtd_device_unregister(mymtd);
123 map_destroy(mymtd); 123 map_destroy(mymtd);
124 } 124 }
125 if (flagadm_map.virt) { 125 if (flagadm_map.virt) {
diff --git a/drivers/mtd/maps/ck804xrom.c b/drivers/mtd/maps/ck804xrom.c
index 5fdb7b26cea3..3d0e762fa5f2 100644
--- a/drivers/mtd/maps/ck804xrom.c
+++ b/drivers/mtd/maps/ck804xrom.c
@@ -94,7 +94,7 @@ static void ck804xrom_cleanup(struct ck804xrom_window *window)
94 if (map->rsrc.parent) 94 if (map->rsrc.parent)
95 release_resource(&map->rsrc); 95 release_resource(&map->rsrc);
96 96
97 del_mtd_device(map->mtd); 97 mtd_device_unregister(map->mtd);
98 map_destroy(map->mtd); 98 map_destroy(map->mtd);
99 list_del(&map->list); 99 list_del(&map->list);
100 kfree(map); 100 kfree(map);
@@ -291,7 +291,7 @@ static int __devinit ck804xrom_init_one (struct pci_dev *pdev,
291 291
292 /* Now that the mtd devices is complete claim and export it */ 292 /* Now that the mtd devices is complete claim and export it */
293 map->mtd->owner = THIS_MODULE; 293 map->mtd->owner = THIS_MODULE;
294 if (add_mtd_device(map->mtd)) { 294 if (mtd_device_register(map->mtd, NULL, 0)) {
295 map_destroy(map->mtd); 295 map_destroy(map->mtd);
296 map->mtd = NULL; 296 map->mtd = NULL;
297 goto out; 297 goto out;
diff --git a/drivers/mtd/maps/dbox2-flash.c b/drivers/mtd/maps/dbox2-flash.c
index cfacfa6f45dd..85bdece6ab3f 100644
--- a/drivers/mtd/maps/dbox2-flash.c
+++ b/drivers/mtd/maps/dbox2-flash.c
@@ -93,7 +93,7 @@ static int __init init_dbox2_flash(void)
93 mymtd->owner = THIS_MODULE; 93 mymtd->owner = THIS_MODULE;
94 94
95 /* Create MTD devices for each partition. */ 95 /* Create MTD devices for each partition. */
96 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); 96 mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
97 97
98 return 0; 98 return 0;
99 } 99 }
@@ -105,7 +105,7 @@ static int __init init_dbox2_flash(void)
105static void __exit cleanup_dbox2_flash(void) 105static void __exit cleanup_dbox2_flash(void)
106{ 106{
107 if (mymtd) { 107 if (mymtd) {
108 del_mtd_partitions(mymtd); 108 mtd_device_unregister(mymtd);
109 map_destroy(mymtd); 109 map_destroy(mymtd);
110 } 110 }
111 if (dbox2_flash_map.virt) { 111 if (dbox2_flash_map.virt) {
diff --git a/drivers/mtd/maps/dc21285.c b/drivers/mtd/maps/dc21285.c
index b3cb3a183809..7a9e1989c977 100644
--- a/drivers/mtd/maps/dc21285.c
+++ b/drivers/mtd/maps/dc21285.c
@@ -145,17 +145,13 @@ static struct map_info dc21285_map = {
145 145
146 146
147/* Partition stuff */ 147/* Partition stuff */
148#ifdef CONFIG_MTD_PARTITIONS
149static struct mtd_partition *dc21285_parts; 148static struct mtd_partition *dc21285_parts;
150static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 149static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
151#endif
152 150
153static int __init init_dc21285(void) 151static int __init init_dc21285(void)
154{ 152{
155 153
156#ifdef CONFIG_MTD_PARTITIONS
157 int nrparts; 154 int nrparts;
158#endif
159 155
160 /* Determine bankwidth */ 156 /* Determine bankwidth */
161 switch (*CSR_SA110_CNTL & (3<<14)) { 157 switch (*CSR_SA110_CNTL & (3<<14)) {
@@ -204,13 +200,8 @@ static int __init init_dc21285(void)
204 200
205 dc21285_mtd->owner = THIS_MODULE; 201 dc21285_mtd->owner = THIS_MODULE;
206 202
207#ifdef CONFIG_MTD_PARTITIONS
208 nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0); 203 nrparts = parse_mtd_partitions(dc21285_mtd, probes, &dc21285_parts, 0);
209 if (nrparts > 0) 204 mtd_device_register(dc21285_mtd, dc21285_parts, nrparts);
210 add_mtd_partitions(dc21285_mtd, dc21285_parts, nrparts);
211 else
212#endif
213 add_mtd_device(dc21285_mtd);
214 205
215 if(machine_is_ebsa285()) { 206 if(machine_is_ebsa285()) {
216 /* 207 /*
@@ -232,14 +223,9 @@ static int __init init_dc21285(void)
232 223
233static void __exit cleanup_dc21285(void) 224static void __exit cleanup_dc21285(void)
234{ 225{
235#ifdef CONFIG_MTD_PARTITIONS 226 mtd_device_unregister(dc21285_mtd);
236 if (dc21285_parts) { 227 if (dc21285_parts)
237 del_mtd_partitions(dc21285_mtd);
238 kfree(dc21285_parts); 228 kfree(dc21285_parts);
239 } else
240#endif
241 del_mtd_device(dc21285_mtd);
242
243 map_destroy(dc21285_mtd); 229 map_destroy(dc21285_mtd);
244 iounmap(dc21285_map.virt); 230 iounmap(dc21285_map.virt);
245} 231}
diff --git a/drivers/mtd/maps/dilnetpc.c b/drivers/mtd/maps/dilnetpc.c
index 0713e3a5a22c..3e393f0da823 100644
--- a/drivers/mtd/maps/dilnetpc.c
+++ b/drivers/mtd/maps/dilnetpc.c
@@ -450,7 +450,7 @@ static int __init init_dnpc(void)
450 partition_info[2].mtdp = &lowlvl_parts[1]; 450 partition_info[2].mtdp = &lowlvl_parts[1];
451 partition_info[3].mtdp = &lowlvl_parts[3]; 451 partition_info[3].mtdp = &lowlvl_parts[3];
452 452
453 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); 453 mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
454 454
455 /* 455 /*
456 ** now create a virtual MTD device by concatenating the for partitions 456 ** now create a virtual MTD device by concatenating the for partitions
@@ -463,7 +463,8 @@ static int __init init_dnpc(void)
463 ** we do not supply mtd pointers in higlvl_partition_info, so 463 ** we do not supply mtd pointers in higlvl_partition_info, so
464 ** add_mtd_partitions() will register the devices. 464 ** add_mtd_partitions() will register the devices.
465 */ 465 */
466 add_mtd_partitions(merged_mtd, higlvl_partition_info, NUM_HIGHLVL_PARTITIONS); 466 mtd_device_register(merged_mtd, higlvl_partition_info,
467 NUM_HIGHLVL_PARTITIONS);
467 } 468 }
468 469
469 return 0; 470 return 0;
@@ -472,12 +473,12 @@ static int __init init_dnpc(void)
472static void __exit cleanup_dnpc(void) 473static void __exit cleanup_dnpc(void)
473{ 474{
474 if(merged_mtd) { 475 if(merged_mtd) {
475 del_mtd_partitions(merged_mtd); 476 mtd_device_unregister(merged_mtd);
476 mtd_concat_destroy(merged_mtd); 477 mtd_concat_destroy(merged_mtd);
477 } 478 }
478 479
479 if (mymtd) { 480 if (mymtd) {
480 del_mtd_partitions(mymtd); 481 mtd_device_unregister(mymtd);
481 map_destroy(mymtd); 482 map_destroy(mymtd);
482 } 483 }
483 if (dnpc_map.virt) { 484 if (dnpc_map.virt) {
diff --git a/drivers/mtd/maps/dmv182.c b/drivers/mtd/maps/dmv182.c
index d171674eb2ed..6538ac675e00 100644
--- a/drivers/mtd/maps/dmv182.c
+++ b/drivers/mtd/maps/dmv182.c
@@ -120,7 +120,7 @@ static int __init init_svme182(void)
120 this_mtd->size >> 20, FLASH_BASE_ADDR); 120 this_mtd->size >> 20, FLASH_BASE_ADDR);
121 121
122 this_mtd->owner = THIS_MODULE; 122 this_mtd->owner = THIS_MODULE;
123 add_mtd_partitions(this_mtd, partitions, num_parts); 123 mtd_device_register(this_mtd, partitions, num_parts);
124 124
125 return 0; 125 return 0;
126} 126}
@@ -129,7 +129,7 @@ static void __exit cleanup_svme182(void)
129{ 129{
130 if (this_mtd) 130 if (this_mtd)
131 { 131 {
132 del_mtd_partitions(this_mtd); 132 mtd_device_unregister(this_mtd);
133 map_destroy(this_mtd); 133 map_destroy(this_mtd);
134 } 134 }
135 135
diff --git a/drivers/mtd/maps/edb7312.c b/drivers/mtd/maps/edb7312.c
index be9e90b44587..fe42a212bb3e 100644
--- a/drivers/mtd/maps/edb7312.c
+++ b/drivers/mtd/maps/edb7312.c
@@ -15,10 +15,7 @@
15#include <asm/io.h> 15#include <asm/io.h>
16#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h> 17#include <linux/mtd/map.h>
18
19#ifdef CONFIG_MTD_PARTITIONS
20#include <linux/mtd/partitions.h> 18#include <linux/mtd/partitions.h>
21#endif
22 19
23#define WINDOW_ADDR 0x00000000 /* physical properties of flash */ 20#define WINDOW_ADDR 0x00000000 /* physical properties of flash */
24#define WINDOW_SIZE 0x01000000 21#define WINDOW_SIZE 0x01000000
@@ -40,8 +37,6 @@ struct map_info edb7312nor_map = {
40 .phys = WINDOW_ADDR, 37 .phys = WINDOW_ADDR,
41}; 38};
42 39
43#ifdef CONFIG_MTD_PARTITIONS
44
45/* 40/*
46 * MTD partitioning stuff 41 * MTD partitioning stuff
47 */ 42 */
@@ -66,8 +61,6 @@ static struct mtd_partition static_partitions[3] =
66 61
67static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 62static const char *probes[] = { "RedBoot", "cmdlinepart", NULL };
68 63
69#endif
70
71static int mtd_parts_nb = 0; 64static int mtd_parts_nb = 0;
72static struct mtd_partition *mtd_parts = 0; 65static struct mtd_partition *mtd_parts = 0;
73 66
@@ -96,27 +89,24 @@ static int __init init_edb7312nor(void)
96 if (mymtd) { 89 if (mymtd) {
97 mymtd->owner = THIS_MODULE; 90 mymtd->owner = THIS_MODULE;
98 91
99#ifdef CONFIG_MTD_PARTITIONS
100 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID); 92 mtd_parts_nb = parse_mtd_partitions(mymtd, probes, &mtd_parts, MTDID);
101 if (mtd_parts_nb > 0) 93 if (mtd_parts_nb > 0)
102 part_type = "detected"; 94 part_type = "detected";
103 95
104 if (mtd_parts_nb == 0) 96 if (mtd_parts_nb == 0) {
105 {
106 mtd_parts = static_partitions; 97 mtd_parts = static_partitions;
107 mtd_parts_nb = ARRAY_SIZE(static_partitions); 98 mtd_parts_nb = ARRAY_SIZE(static_partitions);
108 part_type = "static"; 99 part_type = "static";
109 } 100 }
110#endif 101
111 add_mtd_device(mymtd);
112 if (mtd_parts_nb == 0) 102 if (mtd_parts_nb == 0)
113 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n"); 103 printk(KERN_NOTICE MSG_PREFIX "no partition info available\n");
114 else 104 else
115 {
116 printk(KERN_NOTICE MSG_PREFIX 105 printk(KERN_NOTICE MSG_PREFIX
117 "using %s partition definition\n", part_type); 106 "using %s partition definition\n", part_type);
118 add_mtd_partitions(mymtd, mtd_parts, mtd_parts_nb); 107 /* Register the whole device first. */
119 } 108 mtd_device_register(mymtd, NULL, 0);
109 mtd_device_register(mymtd, mtd_parts, mtd_parts_nb);
120 return 0; 110 return 0;
121 } 111 }
122 112
@@ -127,7 +117,7 @@ static int __init init_edb7312nor(void)
127static void __exit cleanup_edb7312nor(void) 117static void __exit cleanup_edb7312nor(void)
128{ 118{
129 if (mymtd) { 119 if (mymtd) {
130 del_mtd_device(mymtd); 120 mtd_device_unregister(mymtd);
131 map_destroy(mymtd); 121 map_destroy(mymtd);
132 } 122 }
133 if (edb7312nor_map.virt) { 123 if (edb7312nor_map.virt) {
diff --git a/drivers/mtd/maps/esb2rom.c b/drivers/mtd/maps/esb2rom.c
index 4feb7507ab7c..08322b1c3e81 100644
--- a/drivers/mtd/maps/esb2rom.c
+++ b/drivers/mtd/maps/esb2rom.c
@@ -128,7 +128,7 @@ static void esb2rom_cleanup(struct esb2rom_window *window)
128 list_for_each_entry_safe(map, scratch, &window->maps, list) { 128 list_for_each_entry_safe(map, scratch, &window->maps, list) {
129 if (map->rsrc.parent) 129 if (map->rsrc.parent)
130 release_resource(&map->rsrc); 130 release_resource(&map->rsrc);
131 del_mtd_device(map->mtd); 131 mtd_device_unregister(map->mtd);
132 map_destroy(map->mtd); 132 map_destroy(map->mtd);
133 list_del(&map->list); 133 list_del(&map->list);
134 kfree(map); 134 kfree(map);
@@ -352,7 +352,7 @@ static int __devinit esb2rom_init_one(struct pci_dev *pdev,
352 352
353 /* Now that the mtd devices is complete claim and export it */ 353 /* Now that the mtd devices is complete claim and export it */
354 map->mtd->owner = THIS_MODULE; 354 map->mtd->owner = THIS_MODULE;
355 if (add_mtd_device(map->mtd)) { 355 if (mtd_device_register(map->mtd, NULL, 0)) {
356 map_destroy(map->mtd); 356 map_destroy(map->mtd);
357 map->mtd = NULL; 357 map->mtd = NULL;
358 goto out; 358 goto out;
diff --git a/drivers/mtd/maps/fortunet.c b/drivers/mtd/maps/fortunet.c
index 1e43124d498b..956e2e4f30ea 100644
--- a/drivers/mtd/maps/fortunet.c
+++ b/drivers/mtd/maps/fortunet.c
@@ -243,8 +243,9 @@ static int __init init_fortunet(void)
243 &map_regions[ix].map_info); 243 &map_regions[ix].map_info);
244 } 244 }
245 map_regions[ix].mymtd->owner = THIS_MODULE; 245 map_regions[ix].mymtd->owner = THIS_MODULE;
246 add_mtd_partitions(map_regions[ix].mymtd, 246 mtd_device_register(map_regions[ix].mymtd,
247 map_regions[ix].parts,map_regions_parts[ix]); 247 map_regions[ix].parts,
248 map_regions_parts[ix]);
248 } 249 }
249 } 250 }
250 if(iy) 251 if(iy)
@@ -261,7 +262,7 @@ static void __exit cleanup_fortunet(void)
261 { 262 {
262 if( map_regions[ix].mymtd ) 263 if( map_regions[ix].mymtd )
263 { 264 {
264 del_mtd_partitions( map_regions[ix].mymtd ); 265 mtd_device_unregister(map_regions[ix].mymtd);
265 map_destroy( map_regions[ix].mymtd ); 266 map_destroy( map_regions[ix].mymtd );
266 } 267 }
267 iounmap((void *)map_regions[ix].map_info.virt); 268 iounmap((void *)map_regions[ix].map_info.virt);
diff --git a/drivers/mtd/maps/gpio-addr-flash.c b/drivers/mtd/maps/gpio-addr-flash.c
index af5707a80205..7568c5f8b8ae 100644
--- a/drivers/mtd/maps/gpio-addr-flash.c
+++ b/drivers/mtd/maps/gpio-addr-flash.c
@@ -155,9 +155,7 @@ static void gf_copy_to(struct map_info *map, unsigned long to, const void *from,
155 memcpy_toio(map->virt + (to % state->win_size), from, len); 155 memcpy_toio(map->virt + (to % state->win_size), from, len);
156} 156}
157 157
158#ifdef CONFIG_MTD_PARTITIONS
159static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL }; 158static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
160#endif
161 159
162/** 160/**
163 * gpio_flash_probe() - setup a mapping for a GPIO assisted flash 161 * gpio_flash_probe() - setup a mapping for a GPIO assisted flash
@@ -189,7 +187,7 @@ static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", NULL };
189 */ 187 */
190static int __devinit gpio_flash_probe(struct platform_device *pdev) 188static int __devinit gpio_flash_probe(struct platform_device *pdev)
191{ 189{
192 int ret; 190 int nr_parts;
193 size_t i, arr_size; 191 size_t i, arr_size;
194 struct physmap_flash_data *pdata; 192 struct physmap_flash_data *pdata;
195 struct resource *memory; 193 struct resource *memory;
@@ -254,24 +252,21 @@ static int __devinit gpio_flash_probe(struct platform_device *pdev)
254 return -ENXIO; 252 return -ENXIO;
255 } 253 }
256 254
257#ifdef CONFIG_MTD_PARTITIONS 255 nr_parts = parse_mtd_partitions(state->mtd, part_probe_types,
258 ret = parse_mtd_partitions(state->mtd, part_probe_types, &pdata->parts, 0); 256 &pdata->parts, 0);
259 if (ret > 0) { 257 if (nr_parts > 0) {
260 pr_devinit(KERN_NOTICE PFX "Using commandline partition definition\n"); 258 pr_devinit(KERN_NOTICE PFX "Using commandline partition definition\n");
261 add_mtd_partitions(state->mtd, pdata->parts, ret);
262 kfree(pdata->parts); 259 kfree(pdata->parts);
263
264 } else if (pdata->nr_parts) { 260 } else if (pdata->nr_parts) {
265 pr_devinit(KERN_NOTICE PFX "Using board partition definition\n"); 261 pr_devinit(KERN_NOTICE PFX "Using board partition definition\n");
266 add_mtd_partitions(state->mtd, pdata->parts, pdata->nr_parts); 262 nr_parts = pdata->nr_parts;
267 263 } else {
268 } else
269#endif
270 {
271 pr_devinit(KERN_NOTICE PFX "no partition info available, registering whole flash at once\n"); 264 pr_devinit(KERN_NOTICE PFX "no partition info available, registering whole flash at once\n");
272 add_mtd_device(state->mtd); 265 nr_parts = 0;
273 } 266 }
274 267
268 mtd_device_register(state->mtd, pdata->parts, nr_parts);
269
275 return 0; 270 return 0;
276} 271}
277 272
@@ -282,9 +277,7 @@ static int __devexit gpio_flash_remove(struct platform_device *pdev)
282 do { 277 do {
283 gpio_free(state->gpio_addrs[i]); 278 gpio_free(state->gpio_addrs[i]);
284 } while (++i < state->gpio_count); 279 } while (++i < state->gpio_count);
285#ifdef CONFIG_MTD_PARTITIONS 280 mtd_device_unregister(state->mtd);
286 del_mtd_partitions(state->mtd);
287#endif
288 map_destroy(state->mtd); 281 map_destroy(state->mtd);
289 kfree(state); 282 kfree(state);
290 return 0; 283 return 0;
diff --git a/drivers/mtd/maps/h720x-flash.c b/drivers/mtd/maps/h720x-flash.c
index 72c724fa8c27..7f035860a36b 100644
--- a/drivers/mtd/maps/h720x-flash.c
+++ b/drivers/mtd/maps/h720x-flash.c
@@ -92,18 +92,16 @@ static int __init h720x_mtd_init(void)
92 if (mymtd) { 92 if (mymtd) {
93 mymtd->owner = THIS_MODULE; 93 mymtd->owner = THIS_MODULE;
94 94
95#ifdef CONFIG_MTD_PARTITIONS
96 nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0); 95 nr_mtd_parts = parse_mtd_partitions(mymtd, probes, &mtd_parts, 0);
97 if (nr_mtd_parts > 0) 96 if (nr_mtd_parts > 0)
98 part_type = "command line"; 97 part_type = "command line";
99#endif
100 if (nr_mtd_parts <= 0) { 98 if (nr_mtd_parts <= 0) {
101 mtd_parts = h720x_partitions; 99 mtd_parts = h720x_partitions;
102 nr_mtd_parts = NUM_PARTITIONS; 100 nr_mtd_parts = NUM_PARTITIONS;
103 part_type = "builtin"; 101 part_type = "builtin";
104 } 102 }
105 printk(KERN_INFO "Using %s partition table\n", part_type); 103 printk(KERN_INFO "Using %s partition table\n", part_type);
106 add_mtd_partitions(mymtd, mtd_parts, nr_mtd_parts); 104 mtd_device_register(mymtd, mtd_parts, nr_mtd_parts);
107 return 0; 105 return 0;
108 } 106 }
109 107
@@ -118,7 +116,7 @@ static void __exit h720x_mtd_cleanup(void)
118{ 116{
119 117
120 if (mymtd) { 118 if (mymtd) {
121 del_mtd_partitions(mymtd); 119 mtd_device_unregister(mymtd);
122 map_destroy(mymtd); 120 map_destroy(mymtd);
123 } 121 }
124 122
diff --git a/drivers/mtd/maps/ichxrom.c b/drivers/mtd/maps/ichxrom.c
index 1337a4191a0c..6689dcb3124d 100644
--- a/drivers/mtd/maps/ichxrom.c
+++ b/drivers/mtd/maps/ichxrom.c
@@ -67,7 +67,7 @@ static void ichxrom_cleanup(struct ichxrom_window *window)
67 list_for_each_entry_safe(map, scratch, &window->maps, list) { 67 list_for_each_entry_safe(map, scratch, &window->maps, list) {
68 if (map->rsrc.parent) 68 if (map->rsrc.parent)
69 release_resource(&map->rsrc); 69 release_resource(&map->rsrc);
70 del_mtd_device(map->mtd); 70 mtd_device_unregister(map->mtd);
71 map_destroy(map->mtd); 71 map_destroy(map->mtd);
72 list_del(&map->list); 72 list_del(&map->list);
73 kfree(map); 73 kfree(map);
@@ -287,7 +287,7 @@ static int __devinit ichxrom_init_one (struct pci_dev *pdev,
287 287
288 /* Now that the mtd devices is complete claim and export it */ 288 /* Now that the mtd devices is complete claim and export it */
289 map->mtd->owner = THIS_MODULE; 289 map->mtd->owner = THIS_MODULE;
290 if (add_mtd_device(map->mtd)) { 290 if (mtd_device_register(map->mtd, NULL, 0)) {
291 map_destroy(map->mtd); 291 map_destroy(map->mtd);
292 map->mtd = NULL; 292 map->mtd = NULL;
293 goto out; 293 goto out;
diff --git a/drivers/mtd/maps/impa7.c b/drivers/mtd/maps/impa7.c
index 998a27da97f3..404a50cbafa0 100644
--- a/drivers/mtd/maps/impa7.c
+++ b/drivers/mtd/maps/impa7.c
@@ -15,10 +15,7 @@
15#include <asm/io.h> 15#include <asm/io.h>
16#include <linux/mtd/mtd.h> 16#include <linux/mtd/mtd.h>
17#include <linux/mtd/map.h> 17#include <linux/mtd/map.h>
18
19#ifdef CONFIG_MTD_PARTITIONS
20#include <linux/mtd/partitions.h> 18#include <linux/mtd/partitions.h>
21#endif
22 19
23#define WINDOW_ADDR0 0x00000000 /* physical properties of flash */ 20#define WINDOW_ADDR0 0x00000000 /* physical properties of flash */
24#define WINDOW_SIZE0 0x00800000 21#define WINDOW_SIZE0 0x00800000
@@ -49,8 +46,6 @@ static struct map_info impa7_map[NUM_FLASHBANKS] = {
49 }, 46 },
50}; 47};
51 48
52#ifdef CONFIG_MTD_PARTITIONS
53
54/* 49/*
55 * MTD partitioning stuff 50 * MTD partitioning stuff
56 */ 51 */
@@ -66,8 +61,6 @@ static struct mtd_partition static_partitions[] =
66static int mtd_parts_nb[NUM_FLASHBANKS]; 61static int mtd_parts_nb[NUM_FLASHBANKS];
67static struct mtd_partition *mtd_parts[NUM_FLASHBANKS]; 62static struct mtd_partition *mtd_parts[NUM_FLASHBANKS];
68 63
69#endif
70
71static const char *probes[] = { "cmdlinepart", NULL }; 64static const char *probes[] = { "cmdlinepart", NULL };
72 65
73static int __init init_impa7(void) 66static int __init init_impa7(void)
@@ -104,7 +97,6 @@ static int __init init_impa7(void)
104 if (impa7_mtd[i]) { 97 if (impa7_mtd[i]) {
105 impa7_mtd[i]->owner = THIS_MODULE; 98 impa7_mtd[i]->owner = THIS_MODULE;
106 devicesfound++; 99 devicesfound++;
107#ifdef CONFIG_MTD_PARTITIONS
108 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i], 100 mtd_parts_nb[i] = parse_mtd_partitions(impa7_mtd[i],
109 probes, 101 probes,
110 &mtd_parts[i], 102 &mtd_parts[i],
@@ -120,12 +112,8 @@ static int __init init_impa7(void)
120 printk(KERN_NOTICE MSG_PREFIX 112 printk(KERN_NOTICE MSG_PREFIX
121 "using %s partition definition\n", 113 "using %s partition definition\n",
122 part_type); 114 part_type);
123 add_mtd_partitions(impa7_mtd[i], 115 mtd_device_register(impa7_mtd[i],
124 mtd_parts[i], mtd_parts_nb[i]); 116 mtd_parts[i], mtd_parts_nb[i]);
125#else
126 add_mtd_device(impa7_mtd[i]);
127
128#endif
129 } 117 }
130 else 118 else
131 iounmap((void *)impa7_map[i].virt); 119 iounmap((void *)impa7_map[i].virt);
@@ -138,11 +126,7 @@ static void __exit cleanup_impa7(void)
138 int i; 126 int i;
139 for (i=0; i<NUM_FLASHBANKS; i++) { 127 for (i=0; i<NUM_FLASHBANKS; i++) {
140 if (impa7_mtd[i]) { 128 if (impa7_mtd[i]) {
141#ifdef CONFIG_MTD_PARTITIONS 129 mtd_device_unregister(impa7_mtd[i]);
142 del_mtd_partitions(impa7_mtd[i]);
143#else
144 del_mtd_device(impa7_mtd[i]);
145#endif
146 map_destroy(impa7_mtd[i]); 130 map_destroy(impa7_mtd[i]);
147 iounmap((void *)impa7_map[i].virt); 131 iounmap((void *)impa7_map[i].virt);
148 impa7_map[i].virt = 0; 132 impa7_map[i].virt = 0;
diff --git a/drivers/mtd/maps/intel_vr_nor.c b/drivers/mtd/maps/intel_vr_nor.c
index fc1998512eb4..d2f47be8754b 100644
--- a/drivers/mtd/maps/intel_vr_nor.c
+++ b/drivers/mtd/maps/intel_vr_nor.c
@@ -66,33 +66,18 @@ struct vr_nor_mtd {
66 66
67static void __devexit vr_nor_destroy_partitions(struct vr_nor_mtd *p) 67static void __devexit vr_nor_destroy_partitions(struct vr_nor_mtd *p)
68{ 68{
69 if (p->nr_parts > 0) { 69 mtd_device_unregister(p->info);
70#if defined(CONFIG_MTD_PARTITIONS) || defined(CONFIG_MTD_PARTITIONS_MODULE)
71 del_mtd_partitions(p->info);
72#endif
73 } else
74 del_mtd_device(p->info);
75} 70}
76 71
77static int __devinit vr_nor_init_partitions(struct vr_nor_mtd *p) 72static int __devinit vr_nor_init_partitions(struct vr_nor_mtd *p)
78{ 73{
79 int err = 0;
80#if defined(CONFIG_MTD_PARTITIONS) || defined(CONFIG_MTD_PARTITIONS_MODULE)
81 struct mtd_partition *parts; 74 struct mtd_partition *parts;
82 static const char *part_probes[] = { "cmdlinepart", NULL }; 75 static const char *part_probes[] = { "cmdlinepart", NULL };
83#endif
84 76
85 /* register the flash bank */ 77 /* register the flash bank */
86#if defined(CONFIG_MTD_PARTITIONS) || defined(CONFIG_MTD_PARTITIONS_MODULE)
87 /* partition the flash bank */ 78 /* partition the flash bank */
88 p->nr_parts = parse_mtd_partitions(p->info, part_probes, &parts, 0); 79 p->nr_parts = parse_mtd_partitions(p->info, part_probes, &parts, 0);
89 if (p->nr_parts > 0) 80 return mtd_device_register(p->info, parts, p->nr_parts);
90 err = add_mtd_partitions(p->info, parts, p->nr_parts);
91#endif
92 if (p->nr_parts <= 0)
93 err = add_mtd_device(p->info);
94
95 return err;
96} 81}
97 82
98static void __devexit vr_nor_destroy_mtd_setup(struct vr_nor_mtd *p) 83static void __devexit vr_nor_destroy_mtd_setup(struct vr_nor_mtd *p)
diff --git a/drivers/mtd/maps/ixp2000.c b/drivers/mtd/maps/ixp2000.c
index 9639d83a9d6c..c00b9175ba9e 100644
--- a/drivers/mtd/maps/ixp2000.c
+++ b/drivers/mtd/maps/ixp2000.c
@@ -119,7 +119,7 @@ static int ixp2000_flash_remove(struct platform_device *dev)
119 return 0; 119 return 0;
120 120
121 if (info->mtd) { 121 if (info->mtd) {
122 del_mtd_partitions(info->mtd); 122 mtd_device_unregister(info->mtd);
123 map_destroy(info->mtd); 123 map_destroy(info->mtd);
124 } 124 }
125 if (info->map.map_priv_1) 125 if (info->map.map_priv_1)
@@ -230,7 +230,7 @@ static int ixp2000_flash_probe(struct platform_device *dev)
230 230
231 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0); 231 err = parse_mtd_partitions(info->mtd, probes, &info->partitions, 0);
232 if (err > 0) { 232 if (err > 0) {
233 err = add_mtd_partitions(info->mtd, info->partitions, err); 233 err = mtd_device_register(info->mtd, info->partitions, err);
234 if(err) 234 if(err)
235 dev_err(&dev->dev, "Could not parse partitions\n"); 235 dev_err(&dev->dev, "Could not parse partitions\n");
236 } 236 }
diff --git a/drivers/mtd/maps/ixp4xx.c b/drivers/mtd/maps/ixp4xx.c
index 1f9fde0dad35..155b21942f47 100644
--- a/drivers/mtd/maps/ixp4xx.c
+++ b/drivers/mtd/maps/ixp4xx.c
@@ -162,7 +162,7 @@ static int ixp4xx_flash_remove(struct platform_device *dev)
162 return 0; 162 return 0;
163 163
164 if (info->mtd) { 164 if (info->mtd) {
165 del_mtd_partitions(info->mtd); 165 mtd_device_unregister(info->mtd);
166 map_destroy(info->mtd); 166 map_destroy(info->mtd);
167 } 167 }
168 if (info->map.virt) 168 if (info->map.virt)
@@ -252,10 +252,8 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
252 /* Use the fast version */ 252 /* Use the fast version */
253 info->map.write = ixp4xx_write16; 253 info->map.write = ixp4xx_write16;
254 254
255#ifdef CONFIG_MTD_PARTITIONS
256 nr_parts = parse_mtd_partitions(info->mtd, probes, &info->partitions, 255 nr_parts = parse_mtd_partitions(info->mtd, probes, &info->partitions,
257 dev->resource->start); 256 dev->resource->start);
258#endif
259 if (nr_parts > 0) { 257 if (nr_parts > 0) {
260 part_type = "dynamic"; 258 part_type = "dynamic";
261 } else { 259 } else {
@@ -263,18 +261,16 @@ static int ixp4xx_flash_probe(struct platform_device *dev)
263 nr_parts = plat->nr_parts; 261 nr_parts = plat->nr_parts;
264 part_type = "static"; 262 part_type = "static";
265 } 263 }
266 if (nr_parts == 0) { 264 if (nr_parts == 0)
267 printk(KERN_NOTICE "IXP4xx flash: no partition info " 265 printk(KERN_NOTICE "IXP4xx flash: no partition info "
268 "available, registering whole flash\n"); 266 "available, registering whole flash\n");
269 err = add_mtd_device(info->mtd); 267 else
270 } else {
271 printk(KERN_NOTICE "IXP4xx flash: using %s partition " 268 printk(KERN_NOTICE "IXP4xx flash: using %s partition "
272 "definition\n", part_type); 269 "definition\n", part_type);
273 err = add_mtd_partitions(info->mtd, info->partitions, nr_parts);
274 270
275 if(err) 271 err = mtd_device_register(info->mtd, info->partitions, nr_parts);
276 printk(KERN_ERR "Could not parse partitions\n"); 272 if (err)
277 } 273 printk(KERN_ERR "Could not parse partitions\n");
278 274
279 if (err) 275 if (err)
280 goto Error; 276 goto Error;
diff --git a/drivers/mtd/maps/l440gx.c b/drivers/mtd/maps/l440gx.c
index 9e054503c4cf..dd0360ba2412 100644
--- a/drivers/mtd/maps/l440gx.c
+++ b/drivers/mtd/maps/l440gx.c
@@ -138,7 +138,7 @@ static int __init init_l440gx(void)
138 if (mymtd) { 138 if (mymtd) {
139 mymtd->owner = THIS_MODULE; 139 mymtd->owner = THIS_MODULE;
140 140
141 add_mtd_device(mymtd); 141 mtd_device_register(mymtd, NULL, 0);
142 return 0; 142 return 0;
143 } 143 }
144 144
@@ -148,7 +148,7 @@ static int __init init_l440gx(void)
148 148
149static void __exit cleanup_l440gx(void) 149static void __exit cleanup_l440gx(void)
150{ 150{
151 del_mtd_device(mymtd); 151 mtd_device_unregister(mymtd);
152 map_destroy(mymtd); 152 map_destroy(mymtd);
153 153
154 iounmap(l440gx_map.virt); 154 iounmap(l440gx_map.virt);
diff --git a/drivers/mtd/maps/latch-addr-flash.c b/drivers/mtd/maps/latch-addr-flash.c
index ee2548085334..5936c466e901 100644
--- a/drivers/mtd/maps/latch-addr-flash.c
+++ b/drivers/mtd/maps/latch-addr-flash.c
@@ -112,18 +112,9 @@ static int latch_addr_flash_remove(struct platform_device *dev)
112 latch_addr_data = dev->dev.platform_data; 112 latch_addr_data = dev->dev.platform_data;
113 113
114 if (info->mtd != NULL) { 114 if (info->mtd != NULL) {
115 if (mtd_has_partitions()) { 115 if (info->nr_parts)
116 if (info->nr_parts) { 116 kfree(info->parts);
117 del_mtd_partitions(info->mtd); 117 mtd_device_unregister(info->mtd);
118 kfree(info->parts);
119 } else if (latch_addr_data->nr_parts) {
120 del_mtd_partitions(info->mtd);
121 } else {
122 del_mtd_device(info->mtd);
123 }
124 } else {
125 del_mtd_device(info->mtd);
126 }
127 map_destroy(info->mtd); 118 map_destroy(info->mtd);
128 } 119 }
129 120
@@ -215,23 +206,21 @@ static int __devinit latch_addr_flash_probe(struct platform_device *dev)
215 } 206 }
216 info->mtd->owner = THIS_MODULE; 207 info->mtd->owner = THIS_MODULE;
217 208
218 if (mtd_has_partitions()) { 209 err = parse_mtd_partitions(info->mtd, (const char **)part_probe_types,
219 210 &info->parts, 0);
220 err = parse_mtd_partitions(info->mtd, 211 if (err > 0) {
221 (const char **)part_probe_types, 212 mtd_device_register(info->mtd, info->parts, err);
222 &info->parts, 0); 213 return 0;
223 if (err > 0) { 214 }
224 add_mtd_partitions(info->mtd, info->parts, err); 215 if (latch_addr_data->nr_parts) {
225 return 0; 216 pr_notice("Using latch-addr-flash partition information\n");
226 } 217 mtd_device_register(info->mtd,
227 if (latch_addr_data->nr_parts) { 218 latch_addr_data->parts,
228 pr_notice("Using latch-addr-flash partition information\n"); 219 latch_addr_data->nr_parts);
229 add_mtd_partitions(info->mtd, latch_addr_data->parts, 220 return 0;
230 latch_addr_data->nr_parts);
231 return 0;
232 }
233 } 221 }
234 add_mtd_device(info->mtd); 222
223 mtd_device_register(info->mtd, NULL, 0);
235 return 0; 224 return 0;
236 225
237iounmap: 226iounmap:
diff --git a/drivers/mtd/maps/mbx860.c b/drivers/mtd/maps/mbx860.c
index 0eb5a7c85380..93fa56c33003 100644
--- a/drivers/mtd/maps/mbx860.c
+++ b/drivers/mtd/maps/mbx860.c
@@ -69,8 +69,8 @@ static int __init init_mbx(void)
69 mymtd = do_map_probe("jedec_probe", &mbx_map); 69 mymtd = do_map_probe("jedec_probe", &mbx_map);
70 if (mymtd) { 70 if (mymtd) {
71 mymtd->owner = THIS_MODULE; 71 mymtd->owner = THIS_MODULE;
72 add_mtd_device(mymtd); 72 mtd_device_register(mymtd, NULL, 0);
73 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); 73 mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
74 return 0; 74 return 0;
75 } 75 }
76 76
@@ -81,7 +81,7 @@ static int __init init_mbx(void)
81static void __exit cleanup_mbx(void) 81static void __exit cleanup_mbx(void)
82{ 82{
83 if (mymtd) { 83 if (mymtd) {
84 del_mtd_device(mymtd); 84 mtd_device_unregister(mymtd);
85 map_destroy(mymtd); 85 map_destroy(mymtd);
86 } 86 }
87 if (mbx_map.virt) { 87 if (mbx_map.virt) {
diff --git a/drivers/mtd/maps/netsc520.c b/drivers/mtd/maps/netsc520.c
index c0cb319b2b70..81dc2598bc0a 100644
--- a/drivers/mtd/maps/netsc520.c
+++ b/drivers/mtd/maps/netsc520.c
@@ -116,14 +116,14 @@ static int __init init_netsc520(void)
116 } 116 }
117 117
118 mymtd->owner = THIS_MODULE; 118 mymtd->owner = THIS_MODULE;
119 add_mtd_partitions( mymtd, partition_info, NUM_PARTITIONS ); 119 mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
120 return 0; 120 return 0;
121} 121}
122 122
123static void __exit cleanup_netsc520(void) 123static void __exit cleanup_netsc520(void)
124{ 124{
125 if (mymtd) { 125 if (mymtd) {
126 del_mtd_partitions(mymtd); 126 mtd_device_unregister(mymtd);
127 map_destroy(mymtd); 127 map_destroy(mymtd);
128 } 128 }
129 if (netsc520_map.virt) { 129 if (netsc520_map.virt) {
diff --git a/drivers/mtd/maps/nettel.c b/drivers/mtd/maps/nettel.c
index a97133eb9d70..eadcfffc4f9c 100644
--- a/drivers/mtd/maps/nettel.c
+++ b/drivers/mtd/maps/nettel.c
@@ -383,13 +383,13 @@ static int __init nettel_init(void)
383 /* No BIOS regions when AMD boot */ 383 /* No BIOS regions when AMD boot */
384 num_intel_partitions -= 2; 384 num_intel_partitions -= 2;
385 } 385 }
386 rc = add_mtd_partitions(intel_mtd, nettel_intel_partitions, 386 rc = mtd_device_register(intel_mtd, nettel_intel_partitions,
387 num_intel_partitions); 387 num_intel_partitions);
388#endif 388#endif
389 389
390 if (amd_mtd) { 390 if (amd_mtd) {
391 rc = add_mtd_partitions(amd_mtd, nettel_amd_partitions, 391 rc = mtd_device_register(amd_mtd, nettel_amd_partitions,
392 num_amd_partitions); 392 num_amd_partitions);
393 } 393 }
394 394
395#ifdef CONFIG_MTD_CFI_INTELEXT 395#ifdef CONFIG_MTD_CFI_INTELEXT
@@ -419,7 +419,7 @@ static void __exit nettel_cleanup(void)
419 unregister_reboot_notifier(&nettel_notifier_block); 419 unregister_reboot_notifier(&nettel_notifier_block);
420#endif 420#endif
421 if (amd_mtd) { 421 if (amd_mtd) {
422 del_mtd_partitions(amd_mtd); 422 mtd_device_unregister(amd_mtd);
423 map_destroy(amd_mtd); 423 map_destroy(amd_mtd);
424 } 424 }
425 if (nettel_mmcrp) { 425 if (nettel_mmcrp) {
@@ -432,7 +432,7 @@ static void __exit nettel_cleanup(void)
432 } 432 }
433#ifdef CONFIG_MTD_CFI_INTELEXT 433#ifdef CONFIG_MTD_CFI_INTELEXT
434 if (intel_mtd) { 434 if (intel_mtd) {
435 del_mtd_partitions(intel_mtd); 435 mtd_device_unregister(intel_mtd);
436 map_destroy(intel_mtd); 436 map_destroy(intel_mtd);
437 } 437 }
438 if (nettel_intel_map.virt) { 438 if (nettel_intel_map.virt) {
diff --git a/drivers/mtd/maps/octagon-5066.c b/drivers/mtd/maps/octagon-5066.c
index 23fe1786770f..807ac2a2e686 100644
--- a/drivers/mtd/maps/octagon-5066.c
+++ b/drivers/mtd/maps/octagon-5066.c
@@ -175,7 +175,7 @@ void cleanup_oct5066(void)
175 int i; 175 int i;
176 for (i=0; i<2; i++) { 176 for (i=0; i<2; i++) {
177 if (oct5066_mtd[i]) { 177 if (oct5066_mtd[i]) {
178 del_mtd_device(oct5066_mtd[i]); 178 mtd_device_unregister(oct5066_mtd[i]);
179 map_destroy(oct5066_mtd[i]); 179 map_destroy(oct5066_mtd[i]);
180 } 180 }
181 } 181 }
@@ -220,7 +220,7 @@ static int __init init_oct5066(void)
220 oct5066_mtd[i] = do_map_probe("map_rom", &oct5066_map[i]); 220 oct5066_mtd[i] = do_map_probe("map_rom", &oct5066_map[i]);
221 if (oct5066_mtd[i]) { 221 if (oct5066_mtd[i]) {
222 oct5066_mtd[i]->owner = THIS_MODULE; 222 oct5066_mtd[i]->owner = THIS_MODULE;
223 add_mtd_device(oct5066_mtd[i]); 223 mtd_device_register(oct5066_mtd[i], NULL, 0);
224 } 224 }
225 } 225 }
226 226
diff --git a/drivers/mtd/maps/pci.c b/drivers/mtd/maps/pci.c
index 48f4cf5cb9d1..1d005a3e9b41 100644
--- a/drivers/mtd/maps/pci.c
+++ b/drivers/mtd/maps/pci.c
@@ -313,7 +313,7 @@ mtd_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
313 goto release; 313 goto release;
314 314
315 mtd->owner = THIS_MODULE; 315 mtd->owner = THIS_MODULE;
316 add_mtd_device(mtd); 316 mtd_device_register(mtd, NULL, 0);
317 317
318 pci_set_drvdata(dev, mtd); 318 pci_set_drvdata(dev, mtd);
319 319
@@ -336,7 +336,7 @@ mtd_pci_remove(struct pci_dev *dev)
336 struct mtd_info *mtd = pci_get_drvdata(dev); 336 struct mtd_info *mtd = pci_get_drvdata(dev);
337 struct map_pci_info *map = mtd->priv; 337 struct map_pci_info *map = mtd->priv;
338 338
339 del_mtd_device(mtd); 339 mtd_device_unregister(mtd);
340 map_destroy(mtd); 340 map_destroy(mtd);
341 map->exit(dev, map); 341 map->exit(dev, map);
342 kfree(map); 342 kfree(map);
diff --git a/drivers/mtd/maps/pcmciamtd.c b/drivers/mtd/maps/pcmciamtd.c
index 33dc2829b01b..bbe168b65c26 100644
--- a/drivers/mtd/maps/pcmciamtd.c
+++ b/drivers/mtd/maps/pcmciamtd.c
@@ -630,7 +630,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
630 dev->pcmcia_map.copy_to = pcmcia_copy_to; 630 dev->pcmcia_map.copy_to = pcmcia_copy_to;
631 } 631 }
632 632
633 if(add_mtd_device(mtd)) { 633 if (mtd_device_register(mtd, NULL, 0)) {
634 map_destroy(mtd); 634 map_destroy(mtd);
635 dev->mtd_info = NULL; 635 dev->mtd_info = NULL;
636 dev_err(&dev->p_dev->dev, 636 dev_err(&dev->p_dev->dev,
@@ -669,7 +669,7 @@ static void pcmciamtd_detach(struct pcmcia_device *link)
669 DEBUG(3, "link=0x%p", link); 669 DEBUG(3, "link=0x%p", link);
670 670
671 if(dev->mtd_info) { 671 if(dev->mtd_info) {
672 del_mtd_device(dev->mtd_info); 672 mtd_device_unregister(dev->mtd_info);
673 dev_info(&dev->p_dev->dev, "mtd%d: Removing\n", 673 dev_info(&dev->p_dev->dev, "mtd%d: Removing\n",
674 dev->mtd_info->index); 674 dev->mtd_info->index);
675 map_destroy(dev->mtd_info); 675 map_destroy(dev->mtd_info);
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 1a9b94f0ee54..f64cee4a3bfb 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -27,10 +27,8 @@ struct physmap_flash_info {
27 struct mtd_info *mtd[MAX_RESOURCES]; 27 struct mtd_info *mtd[MAX_RESOURCES];
28 struct mtd_info *cmtd; 28 struct mtd_info *cmtd;
29 struct map_info map[MAX_RESOURCES]; 29 struct map_info map[MAX_RESOURCES];
30#ifdef CONFIG_MTD_PARTITIONS
31 int nr_parts; 30 int nr_parts;
32 struct mtd_partition *parts; 31 struct mtd_partition *parts;
33#endif
34}; 32};
35 33
36static int physmap_flash_remove(struct platform_device *dev) 34static int physmap_flash_remove(struct platform_device *dev)
@@ -47,18 +45,9 @@ static int physmap_flash_remove(struct platform_device *dev)
47 physmap_data = dev->dev.platform_data; 45 physmap_data = dev->dev.platform_data;
48 46
49 if (info->cmtd) { 47 if (info->cmtd) {
50#ifdef CONFIG_MTD_PARTITIONS 48 mtd_device_unregister(info->cmtd);
51 if (info->nr_parts || physmap_data->nr_parts) { 49 if (info->nr_parts)
52 del_mtd_partitions(info->cmtd); 50 kfree(info->parts);
53
54 if (info->nr_parts)
55 kfree(info->parts);
56 } else {
57 del_mtd_device(info->cmtd);
58 }
59#else
60 del_mtd_device(info->cmtd);
61#endif
62 if (info->cmtd != info->mtd[0]) 51 if (info->cmtd != info->mtd[0])
63 mtd_concat_destroy(info->cmtd); 52 mtd_concat_destroy(info->cmtd);
64 } 53 }
@@ -92,10 +81,8 @@ static const char *rom_probe_types[] = {
92 "qinfo_probe", 81 "qinfo_probe",
93 "map_rom", 82 "map_rom",
94 NULL }; 83 NULL };
95#ifdef CONFIG_MTD_PARTITIONS
96static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "afs", 84static const char *part_probe_types[] = { "cmdlinepart", "RedBoot", "afs",
97 NULL }; 85 NULL };
98#endif
99 86
100static int physmap_flash_probe(struct platform_device *dev) 87static int physmap_flash_probe(struct platform_device *dev)
101{ 88{
@@ -188,24 +175,23 @@ static int physmap_flash_probe(struct platform_device *dev)
188 if (err) 175 if (err)
189 goto err_out; 176 goto err_out;
190 177
191#ifdef CONFIG_MTD_PARTITIONS
192 err = parse_mtd_partitions(info->cmtd, part_probe_types, 178 err = parse_mtd_partitions(info->cmtd, part_probe_types,
193 &info->parts, 0); 179 &info->parts, 0);
194 if (err > 0) { 180 if (err > 0) {
195 add_mtd_partitions(info->cmtd, info->parts, err); 181 mtd_device_register(info->cmtd, info->parts, err);
196 info->nr_parts = err; 182 info->nr_parts = err;
197 return 0; 183 return 0;
198 } 184 }
199 185
200 if (physmap_data->nr_parts) { 186 if (physmap_data->nr_parts) {
201 printk(KERN_NOTICE "Using physmap partition information\n"); 187 printk(KERN_NOTICE "Using physmap partition information\n");
202 add_mtd_partitions(info->cmtd, physmap_data->parts, 188 mtd_device_register(info->cmtd, physmap_data->parts,
203 physmap_data->nr_parts); 189 physmap_data->nr_parts);
204 return 0; 190 return 0;
205 } 191 }
206#endif
207 192
208 add_mtd_device(info->cmtd); 193 mtd_device_register(info->cmtd, NULL, 0);
194
209 return 0; 195 return 0;
210 196
211err_out: 197err_out:
@@ -269,14 +255,12 @@ void physmap_configure(unsigned long addr, unsigned long size,
269 physmap_flash_data.set_vpp = set_vpp; 255 physmap_flash_data.set_vpp = set_vpp;
270} 256}
271 257
272#ifdef CONFIG_MTD_PARTITIONS
273void physmap_set_partitions(struct mtd_partition *parts, int num_parts) 258void physmap_set_partitions(struct mtd_partition *parts, int num_parts)
274{ 259{
275 physmap_flash_data.nr_parts = num_parts; 260 physmap_flash_data.nr_parts = num_parts;
276 physmap_flash_data.parts = parts; 261 physmap_flash_data.parts = parts;
277} 262}
278#endif 263#endif
279#endif
280 264
281static int __init physmap_init(void) 265static int __init physmap_init(void)
282{ 266{
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index c1d33464aee8..d251d1db129b 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -34,16 +34,12 @@ struct of_flash_list {
34 34
35struct of_flash { 35struct of_flash {
36 struct mtd_info *cmtd; 36 struct mtd_info *cmtd;
37#ifdef CONFIG_MTD_PARTITIONS
38 struct mtd_partition *parts; 37 struct mtd_partition *parts;
39#endif
40 int list_size; /* number of elements in of_flash_list */ 38 int list_size; /* number of elements in of_flash_list */
41 struct of_flash_list list[0]; 39 struct of_flash_list list[0];
42}; 40};
43 41
44#ifdef CONFIG_MTD_PARTITIONS
45#define OF_FLASH_PARTS(info) ((info)->parts) 42#define OF_FLASH_PARTS(info) ((info)->parts)
46
47static int parse_obsolete_partitions(struct platform_device *dev, 43static int parse_obsolete_partitions(struct platform_device *dev,
48 struct of_flash *info, 44 struct of_flash *info,
49 struct device_node *dp) 45 struct device_node *dp)
@@ -89,10 +85,6 @@ static int parse_obsolete_partitions(struct platform_device *dev,
89 85
90 return nr_parts; 86 return nr_parts;
91} 87}
92#else /* MTD_PARTITIONS */
93#define OF_FLASH_PARTS(info) (0)
94#define parse_partitions(info, dev) (0)
95#endif /* MTD_PARTITIONS */
96 88
97static int of_flash_remove(struct platform_device *dev) 89static int of_flash_remove(struct platform_device *dev)
98{ 90{
@@ -105,17 +97,14 @@ static int of_flash_remove(struct platform_device *dev)
105 dev_set_drvdata(&dev->dev, NULL); 97 dev_set_drvdata(&dev->dev, NULL);
106 98
107 if (info->cmtd != info->list[0].mtd) { 99 if (info->cmtd != info->list[0].mtd) {
108 del_mtd_device(info->cmtd); 100 mtd_device_unregister(info->cmtd);
109 mtd_concat_destroy(info->cmtd); 101 mtd_concat_destroy(info->cmtd);
110 } 102 }
111 103
112 if (info->cmtd) { 104 if (info->cmtd) {
113 if (OF_FLASH_PARTS(info)) { 105 if (OF_FLASH_PARTS(info))
114 del_mtd_partitions(info->cmtd);
115 kfree(OF_FLASH_PARTS(info)); 106 kfree(OF_FLASH_PARTS(info));
116 } else { 107 mtd_device_unregister(info->cmtd);
117 del_mtd_device(info->cmtd);
118 }
119 } 108 }
120 109
121 for (i = 0; i < info->list_size; i++) { 110 for (i = 0; i < info->list_size; i++) {
@@ -172,7 +161,6 @@ static struct mtd_info * __devinit obsolete_probe(struct platform_device *dev,
172 } 161 }
173} 162}
174 163
175#ifdef CONFIG_MTD_PARTITIONS
176/* When partitions are set we look for a linux,part-probe property which 164/* When partitions are set we look for a linux,part-probe property which
177 specifies the list of partition probers to use. If none is given then the 165 specifies the list of partition probers to use. If none is given then the
178 default is use. These take precedence over other device tree 166 default is use. These take precedence over other device tree
@@ -212,14 +200,11 @@ static void __devinit of_free_probes(const char **probes)
212 if (probes != part_probe_types_def) 200 if (probes != part_probe_types_def)
213 kfree(probes); 201 kfree(probes);
214} 202}
215#endif
216 203
217static struct of_device_id of_flash_match[]; 204static struct of_device_id of_flash_match[];
218static int __devinit of_flash_probe(struct platform_device *dev) 205static int __devinit of_flash_probe(struct platform_device *dev)
219{ 206{
220#ifdef CONFIG_MTD_PARTITIONS
221 const char **part_probe_types; 207 const char **part_probe_types;
222#endif
223 const struct of_device_id *match; 208 const struct of_device_id *match;
224 struct device_node *dp = dev->dev.of_node; 209 struct device_node *dp = dev->dev.of_node;
225 struct resource res; 210 struct resource res;
@@ -346,7 +331,6 @@ static int __devinit of_flash_probe(struct platform_device *dev)
346 if (err) 331 if (err)
347 goto err_out; 332 goto err_out;
348 333
349#ifdef CONFIG_MTD_PARTITIONS
350 part_probe_types = of_get_probes(dp); 334 part_probe_types = of_get_probes(dp);
351 err = parse_mtd_partitions(info->cmtd, part_probe_types, 335 err = parse_mtd_partitions(info->cmtd, part_probe_types,
352 &info->parts, 0); 336 &info->parts, 0);
@@ -356,13 +340,11 @@ static int __devinit of_flash_probe(struct platform_device *dev)
356 } 340 }
357 of_free_probes(part_probe_types); 341 of_free_probes(part_probe_types);
358 342
359#ifdef CONFIG_MTD_OF_PARTS
360 if (err == 0) { 343 if (err == 0) {
361 err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts); 344 err = of_mtd_parse_partitions(&dev->dev, dp, &info->parts);
362 if (err < 0) 345 if (err < 0)
363 goto err_out; 346 goto err_out;
364 } 347 }
365#endif
366 348
367 if (err == 0) { 349 if (err == 0) {
368 err = parse_obsolete_partitions(dev, info, dp); 350 err = parse_obsolete_partitions(dev, info, dp);
@@ -370,11 +352,7 @@ static int __devinit of_flash_probe(struct platform_device *dev)
370 goto err_out; 352 goto err_out;
371 } 353 }
372 354
373 if (err > 0) 355 mtd_device_register(info->cmtd, info->parts, err);
374 add_mtd_partitions(info->cmtd, info->parts, err);
375 else
376#endif
377 add_mtd_device(info->cmtd);
378 356
379 kfree(mtd_list); 357 kfree(mtd_list);
380 358
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index 76a76be5a7bd..9ca1eccba4bc 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -94,14 +94,11 @@ static int platram_remove(struct platform_device *pdev)
94 return 0; 94 return 0;
95 95
96 if (info->mtd) { 96 if (info->mtd) {
97#ifdef CONFIG_MTD_PARTITIONS 97 mtd_device_unregister(info->mtd);
98 if (info->partitions) { 98 if (info->partitions) {
99 del_mtd_partitions(info->mtd);
100 if (info->free_partitions) 99 if (info->free_partitions)
101 kfree(info->partitions); 100 kfree(info->partitions);
102 } 101 }
103#endif
104 del_mtd_device(info->mtd);
105 map_destroy(info->mtd); 102 map_destroy(info->mtd);
106 } 103 }
107 104
@@ -231,7 +228,6 @@ static int platram_probe(struct platform_device *pdev)
231 /* check to see if there are any available partitions, or wether 228 /* check to see if there are any available partitions, or wether
232 * to add this device whole */ 229 * to add this device whole */
233 230
234#ifdef CONFIG_MTD_PARTITIONS
235 if (!pdata->nr_partitions) { 231 if (!pdata->nr_partitions) {
236 /* try to probe using the supplied probe type */ 232 /* try to probe using the supplied probe type */
237 if (pdata->probes) { 233 if (pdata->probes) {
@@ -239,24 +235,22 @@ static int platram_probe(struct platform_device *pdev)
239 &info->partitions, 0); 235 &info->partitions, 0);
240 info->free_partitions = 1; 236 info->free_partitions = 1;
241 if (err > 0) 237 if (err > 0)
242 err = add_mtd_partitions(info->mtd, 238 err = mtd_device_register(info->mtd,
243 info->partitions, err); 239 info->partitions, err);
244 } 240 }
245 } 241 }
246 /* use the static mapping */ 242 /* use the static mapping */
247 else 243 else
248 err = add_mtd_partitions(info->mtd, pdata->partitions, 244 err = mtd_device_register(info->mtd, pdata->partitions,
249 pdata->nr_partitions); 245 pdata->nr_partitions);
250#endif /* CONFIG_MTD_PARTITIONS */
251
252 if (add_mtd_device(info->mtd)) {
253 dev_err(&pdev->dev, "add_mtd_device() failed\n");
254 err = -ENOMEM;
255 }
256
257 if (!err) 246 if (!err)
258 dev_info(&pdev->dev, "registered mtd device\n"); 247 dev_info(&pdev->dev, "registered mtd device\n");
259 248
249 /* add the whole device. */
250 err = mtd_device_register(info->mtd, NULL, 0);
251 if (err)
252 dev_err(&pdev->dev, "failed to register the entire device\n");
253
260 return err; 254 return err;
261 255
262 exit_free: 256 exit_free:
diff --git a/drivers/mtd/maps/pmcmsp-flash.c b/drivers/mtd/maps/pmcmsp-flash.c
index 64aea6acd48e..744ca5cacc9b 100644
--- a/drivers/mtd/maps/pmcmsp-flash.c
+++ b/drivers/mtd/maps/pmcmsp-flash.c
@@ -173,7 +173,7 @@ static int __init init_msp_flash(void)
173 msp_flash[i] = do_map_probe("cfi_probe", &msp_maps[i]); 173 msp_flash[i] = do_map_probe("cfi_probe", &msp_maps[i]);
174 if (msp_flash[i]) { 174 if (msp_flash[i]) {
175 msp_flash[i]->owner = THIS_MODULE; 175 msp_flash[i]->owner = THIS_MODULE;
176 add_mtd_partitions(msp_flash[i], msp_parts[i], pcnt); 176 mtd_device_register(msp_flash[i], msp_parts[i], pcnt);
177 } else { 177 } else {
178 printk(KERN_ERR "map probe failed for flash\n"); 178 printk(KERN_ERR "map probe failed for flash\n");
179 ret = -ENXIO; 179 ret = -ENXIO;
@@ -188,7 +188,7 @@ static int __init init_msp_flash(void)
188 188
189cleanup_loop: 189cleanup_loop:
190 while (i--) { 190 while (i--) {
191 del_mtd_partitions(msp_flash[i]); 191 mtd_device_unregister(msp_flash[i]);
192 map_destroy(msp_flash[i]); 192 map_destroy(msp_flash[i]);
193 kfree(msp_maps[i].name); 193 kfree(msp_maps[i].name);
194 iounmap(msp_maps[i].virt); 194 iounmap(msp_maps[i].virt);
@@ -207,7 +207,7 @@ static void __exit cleanup_msp_flash(void)
207 int i; 207 int i;
208 208
209 for (i = 0; i < fcnt; i++) { 209 for (i = 0; i < fcnt; i++) {
210 del_mtd_partitions(msp_flash[i]); 210 mtd_device_unregister(msp_flash[i]);
211 map_destroy(msp_flash[i]); 211 map_destroy(msp_flash[i]);
212 iounmap((void *)msp_maps[i].virt); 212 iounmap((void *)msp_maps[i].virt);
213 213
diff --git a/drivers/mtd/maps/pxa2xx-flash.c b/drivers/mtd/maps/pxa2xx-flash.c
index d8ae634d347e..f59d62f74d44 100644
--- a/drivers/mtd/maps/pxa2xx-flash.c
+++ b/drivers/mtd/maps/pxa2xx-flash.c
@@ -104,23 +104,18 @@ static int __devinit pxa2xx_flash_probe(struct platform_device *pdev)
104 } 104 }
105 info->mtd->owner = THIS_MODULE; 105 info->mtd->owner = THIS_MODULE;
106 106
107#ifdef CONFIG_MTD_PARTITIONS
108 ret = parse_mtd_partitions(info->mtd, probes, &parts, 0); 107 ret = parse_mtd_partitions(info->mtd, probes, &parts, 0);
109 108
110 if (ret > 0) { 109 if (ret > 0) {
111 info->nr_parts = ret; 110 info->nr_parts = ret;
112 info->parts = parts; 111 info->parts = parts;
113 } 112 }
114#endif
115 113
116 if (info->nr_parts) { 114 if (!info->nr_parts)
117 add_mtd_partitions(info->mtd, info->parts,
118 info->nr_parts);
119 } else {
120 printk("Registering %s as whole device\n", 115 printk("Registering %s as whole device\n",
121 info->map.name); 116 info->map.name);
122 add_mtd_device(info->mtd); 117
123 } 118 mtd_device_register(info->mtd, info->parts, info->nr_parts);
124 119
125 platform_set_drvdata(pdev, info); 120 platform_set_drvdata(pdev, info);
126 return 0; 121 return 0;
@@ -132,12 +127,7 @@ static int __devexit pxa2xx_flash_remove(struct platform_device *dev)
132 127
133 platform_set_drvdata(dev, NULL); 128 platform_set_drvdata(dev, NULL);
134 129
135#ifdef CONFIG_MTD_PARTITIONS 130 mtd_device_unregister(info->mtd);
136 if (info->nr_parts)
137 del_mtd_partitions(info->mtd);
138 else
139#endif
140 del_mtd_device(info->mtd);
141 131
142 map_destroy(info->mtd); 132 map_destroy(info->mtd);
143 iounmap(info->map.virt); 133 iounmap(info->map.virt);
diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c
index 83ed64512c5e..761fb459d2c7 100644
--- a/drivers/mtd/maps/rbtx4939-flash.c
+++ b/drivers/mtd/maps/rbtx4939-flash.c
@@ -25,10 +25,8 @@
25struct rbtx4939_flash_info { 25struct rbtx4939_flash_info {
26 struct mtd_info *mtd; 26 struct mtd_info *mtd;
27 struct map_info map; 27 struct map_info map;
28#ifdef CONFIG_MTD_PARTITIONS
29 int nr_parts; 28 int nr_parts;
30 struct mtd_partition *parts; 29 struct mtd_partition *parts;
31#endif
32}; 30};
33 31
34static int rbtx4939_flash_remove(struct platform_device *dev) 32static int rbtx4939_flash_remove(struct platform_device *dev)
@@ -41,28 +39,18 @@ static int rbtx4939_flash_remove(struct platform_device *dev)
41 platform_set_drvdata(dev, NULL); 39 platform_set_drvdata(dev, NULL);
42 40
43 if (info->mtd) { 41 if (info->mtd) {
44#ifdef CONFIG_MTD_PARTITIONS
45 struct rbtx4939_flash_data *pdata = dev->dev.platform_data; 42 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
46 43
47 if (info->nr_parts) { 44 if (info->nr_parts)
48 del_mtd_partitions(info->mtd);
49 kfree(info->parts); 45 kfree(info->parts);
50 } else if (pdata->nr_parts) 46 mtd_device_unregister(info->mtd);
51 del_mtd_partitions(info->mtd);
52 else
53 del_mtd_device(info->mtd);
54#else
55 del_mtd_device(info->mtd);
56#endif
57 map_destroy(info->mtd); 47 map_destroy(info->mtd);
58 } 48 }
59 return 0; 49 return 0;
60} 50}
61 51
62static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL }; 52static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
63#ifdef CONFIG_MTD_PARTITIONS
64static const char *part_probe_types[] = { "cmdlinepart", NULL }; 53static const char *part_probe_types[] = { "cmdlinepart", NULL };
65#endif
66 54
67static int rbtx4939_flash_probe(struct platform_device *dev) 55static int rbtx4939_flash_probe(struct platform_device *dev)
68{ 56{
@@ -120,23 +108,21 @@ static int rbtx4939_flash_probe(struct platform_device *dev)
120 if (err) 108 if (err)
121 goto err_out; 109 goto err_out;
122 110
123#ifdef CONFIG_MTD_PARTITIONS
124 err = parse_mtd_partitions(info->mtd, part_probe_types, 111 err = parse_mtd_partitions(info->mtd, part_probe_types,
125 &info->parts, 0); 112 &info->parts, 0);
126 if (err > 0) { 113 if (err > 0) {
127 add_mtd_partitions(info->mtd, info->parts, err); 114 mtd_device_register(info->mtd, info->parts, err);
128 info->nr_parts = err; 115 info->nr_parts = err;
129 return 0; 116 return 0;
130 } 117 }
131 118
132 if (pdata->nr_parts) { 119 if (pdata->nr_parts) {
133 pr_notice("Using rbtx4939 partition information\n"); 120 pr_notice("Using rbtx4939 partition information\n");
134 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); 121 mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
135 return 0; 122 return 0;
136 } 123 }
137#endif
138 124
139 add_mtd_device(info->mtd); 125 mtd_device_register(info->mtd, NULL, 0);
140 return 0; 126 return 0;
141 127
142err_out: 128err_out:
diff --git a/drivers/mtd/maps/rpxlite.c b/drivers/mtd/maps/rpxlite.c
index 3e3ef53d4fd4..ed88225bf667 100644
--- a/drivers/mtd/maps/rpxlite.c
+++ b/drivers/mtd/maps/rpxlite.c
@@ -36,7 +36,7 @@ static int __init init_rpxlite(void)
36 mymtd = do_map_probe("cfi_probe", &rpxlite_map); 36 mymtd = do_map_probe("cfi_probe", &rpxlite_map);
37 if (mymtd) { 37 if (mymtd) {
38 mymtd->owner = THIS_MODULE; 38 mymtd->owner = THIS_MODULE;
39 add_mtd_device(mymtd); 39 mtd_device_register(mymtd, NULL, 0);
40 return 0; 40 return 0;
41 } 41 }
42 42
@@ -47,7 +47,7 @@ static int __init init_rpxlite(void)
47static void __exit cleanup_rpxlite(void) 47static void __exit cleanup_rpxlite(void)
48{ 48{
49 if (mymtd) { 49 if (mymtd) {
50 del_mtd_device(mymtd); 50 mtd_device_unregister(mymtd);
51 map_destroy(mymtd); 51 map_destroy(mymtd);
52 } 52 }
53 if (rpxlite_map.virt) { 53 if (rpxlite_map.virt) {
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index da875908ea8e..a9b5e0e5c4c5 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -226,12 +226,7 @@ static void sa1100_destroy(struct sa_info *info, struct flash_platform_data *pla
226 int i; 226 int i;
227 227
228 if (info->mtd) { 228 if (info->mtd) {
229 if (info->nr_parts == 0) 229 mtd_device_unregister(info->mtd);
230 del_mtd_device(info->mtd);
231#ifdef CONFIG_MTD_PARTITIONS
232 else
233 del_mtd_partitions(info->mtd);
234#endif
235 if (info->mtd != info->subdev[0].mtd) 230 if (info->mtd != info->subdev[0].mtd)
236 mtd_concat_destroy(info->mtd); 231 mtd_concat_destroy(info->mtd);
237 } 232 }
@@ -363,28 +358,24 @@ static int __devinit sa1100_mtd_probe(struct platform_device *pdev)
363 /* 358 /*
364 * Partition selection stuff. 359 * Partition selection stuff.
365 */ 360 */
366#ifdef CONFIG_MTD_PARTITIONS
367 nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0); 361 nr_parts = parse_mtd_partitions(info->mtd, part_probes, &parts, 0);
368 if (nr_parts > 0) { 362 if (nr_parts > 0) {
369 info->parts = parts; 363 info->parts = parts;
370 part_type = "dynamic"; 364 part_type = "dynamic";
371 } else 365 } else {
372#endif
373 {
374 parts = plat->parts; 366 parts = plat->parts;
375 nr_parts = plat->nr_parts; 367 nr_parts = plat->nr_parts;
376 part_type = "static"; 368 part_type = "static";
377 } 369 }
378 370
379 if (nr_parts == 0) { 371 if (nr_parts == 0)
380 printk(KERN_NOTICE "SA1100 flash: no partition info " 372 printk(KERN_NOTICE "SA1100 flash: no partition info "
381 "available, registering whole flash\n"); 373 "available, registering whole flash\n");
382 add_mtd_device(info->mtd); 374 else
383 } else {
384 printk(KERN_NOTICE "SA1100 flash: using %s partition " 375 printk(KERN_NOTICE "SA1100 flash: using %s partition "
385 "definition\n", part_type); 376 "definition\n", part_type);
386 add_mtd_partitions(info->mtd, parts, nr_parts); 377
387 } 378 mtd_device_register(info->mtd, parts, nr_parts);
388 379
389 info->nr_parts = nr_parts; 380 info->nr_parts = nr_parts;
390 381
diff --git a/drivers/mtd/maps/sbc_gxx.c b/drivers/mtd/maps/sbc_gxx.c
index 04b2781fc627..556a2dfe94c5 100644
--- a/drivers/mtd/maps/sbc_gxx.c
+++ b/drivers/mtd/maps/sbc_gxx.c
@@ -182,7 +182,7 @@ static struct mtd_info *all_mtd;
182static void cleanup_sbc_gxx(void) 182static void cleanup_sbc_gxx(void)
183{ 183{
184 if( all_mtd ) { 184 if( all_mtd ) {
185 del_mtd_partitions( all_mtd ); 185 mtd_device_unregister(all_mtd);
186 map_destroy( all_mtd ); 186 map_destroy( all_mtd );
187 } 187 }
188 188
@@ -223,7 +223,7 @@ static int __init init_sbc_gxx(void)
223 all_mtd->owner = THIS_MODULE; 223 all_mtd->owner = THIS_MODULE;
224 224
225 /* Create MTD devices for each partition. */ 225 /* Create MTD devices for each partition. */
226 add_mtd_partitions(all_mtd, partition_info, NUM_PARTITIONS ); 226 mtd_device_register(all_mtd, partition_info, NUM_PARTITIONS);
227 227
228 return 0; 228 return 0;
229} 229}
diff --git a/drivers/mtd/maps/sc520cdp.c b/drivers/mtd/maps/sc520cdp.c
index 4d8aaaf4bb76..8fead8e46bce 100644
--- a/drivers/mtd/maps/sc520cdp.c
+++ b/drivers/mtd/maps/sc520cdp.c
@@ -266,10 +266,10 @@ static int __init init_sc520cdp(void)
266 /* Combine the two flash banks into a single MTD device & register it: */ 266 /* Combine the two flash banks into a single MTD device & register it: */
267 merged_mtd = mtd_concat_create(mymtd, 2, "SC520CDP Flash Banks #0 and #1"); 267 merged_mtd = mtd_concat_create(mymtd, 2, "SC520CDP Flash Banks #0 and #1");
268 if(merged_mtd) 268 if(merged_mtd)
269 add_mtd_device(merged_mtd); 269 mtd_device_register(merged_mtd, NULL, 0);
270 } 270 }
271 if(devices_found == 3) /* register the third (DIL-Flash) device */ 271 if(devices_found == 3) /* register the third (DIL-Flash) device */
272 add_mtd_device(mymtd[2]); 272 mtd_device_register(mymtd[2], NULL, 0);
273 return(devices_found ? 0 : -ENXIO); 273 return(devices_found ? 0 : -ENXIO);
274} 274}
275 275
@@ -278,11 +278,11 @@ static void __exit cleanup_sc520cdp(void)
278 int i; 278 int i;
279 279
280 if (merged_mtd) { 280 if (merged_mtd) {
281 del_mtd_device(merged_mtd); 281 mtd_device_unregister(merged_mtd);
282 mtd_concat_destroy(merged_mtd); 282 mtd_concat_destroy(merged_mtd);
283 } 283 }
284 if (mymtd[2]) 284 if (mymtd[2])
285 del_mtd_device(mymtd[2]); 285 mtd_device_unregister(mymtd[2]);
286 286
287 for (i = 0; i < NUM_FLASH_BANKS; i++) { 287 for (i = 0; i < NUM_FLASH_BANKS; i++) {
288 if (mymtd[i]) 288 if (mymtd[i])
diff --git a/drivers/mtd/maps/scb2_flash.c b/drivers/mtd/maps/scb2_flash.c
index 7e329f09a548..d88c8426bb0f 100644
--- a/drivers/mtd/maps/scb2_flash.c
+++ b/drivers/mtd/maps/scb2_flash.c
@@ -180,7 +180,7 @@ scb2_flash_probe(struct pci_dev *dev, const struct pci_device_id *ent)
180 180
181 scb2_mtd->owner = THIS_MODULE; 181 scb2_mtd->owner = THIS_MODULE;
182 if (scb2_fixup_mtd(scb2_mtd) < 0) { 182 if (scb2_fixup_mtd(scb2_mtd) < 0) {
183 del_mtd_device(scb2_mtd); 183 mtd_device_unregister(scb2_mtd);
184 map_destroy(scb2_mtd); 184 map_destroy(scb2_mtd);
185 iounmap(scb2_ioaddr); 185 iounmap(scb2_ioaddr);
186 if (!region_fail) 186 if (!region_fail)
@@ -192,7 +192,7 @@ scb2_flash_probe(struct pci_dev *dev, const struct pci_device_id *ent)
192 (unsigned long long)scb2_mtd->size, 192 (unsigned long long)scb2_mtd->size,
193 (unsigned long long)(SCB2_WINDOW - scb2_mtd->size)); 193 (unsigned long long)(SCB2_WINDOW - scb2_mtd->size));
194 194
195 add_mtd_device(scb2_mtd); 195 mtd_device_register(scb2_mtd, NULL, 0);
196 196
197 return 0; 197 return 0;
198} 198}
@@ -207,7 +207,7 @@ scb2_flash_remove(struct pci_dev *dev)
207 if (scb2_mtd->lock) 207 if (scb2_mtd->lock)
208 scb2_mtd->lock(scb2_mtd, 0, scb2_mtd->size); 208 scb2_mtd->lock(scb2_mtd, 0, scb2_mtd->size);
209 209
210 del_mtd_device(scb2_mtd); 210 mtd_device_unregister(scb2_mtd);
211 map_destroy(scb2_mtd); 211 map_destroy(scb2_mtd);
212 212
213 iounmap(scb2_ioaddr); 213 iounmap(scb2_ioaddr);
diff --git a/drivers/mtd/maps/scx200_docflash.c b/drivers/mtd/maps/scx200_docflash.c
index 027e628a4f1d..f1c1f737d0d7 100644
--- a/drivers/mtd/maps/scx200_docflash.c
+++ b/drivers/mtd/maps/scx200_docflash.c
@@ -44,7 +44,6 @@ static struct resource docmem = {
44 44
45static struct mtd_info *mymtd; 45static struct mtd_info *mymtd;
46 46
47#ifdef CONFIG_MTD_PARTITIONS
48static struct mtd_partition partition_info[] = { 47static struct mtd_partition partition_info[] = {
49 { 48 {
50 .name = "DOCCS Boot kernel", 49 .name = "DOCCS Boot kernel",
@@ -68,8 +67,6 @@ static struct mtd_partition partition_info[] = {
68 }, 67 },
69}; 68};
70#define NUM_PARTITIONS ARRAY_SIZE(partition_info) 69#define NUM_PARTITIONS ARRAY_SIZE(partition_info)
71#endif
72
73 70
74static struct map_info scx200_docflash_map = { 71static struct map_info scx200_docflash_map = {
75 .name = "NatSemi SCx200 DOCCS Flash", 72 .name = "NatSemi SCx200 DOCCS Flash",
@@ -198,24 +195,17 @@ static int __init init_scx200_docflash(void)
198 195
199 mymtd->owner = THIS_MODULE; 196 mymtd->owner = THIS_MODULE;
200 197
201#ifdef CONFIG_MTD_PARTITIONS
202 partition_info[3].offset = mymtd->size-partition_info[3].size; 198 partition_info[3].offset = mymtd->size-partition_info[3].size;
203 partition_info[2].size = partition_info[3].offset-partition_info[2].offset; 199 partition_info[2].size = partition_info[3].offset-partition_info[2].offset;
204 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS); 200 mtd_device_register(mymtd, partition_info, NUM_PARTITIONS);
205#else 201
206 add_mtd_device(mymtd);
207#endif
208 return 0; 202 return 0;
209} 203}
210 204
211static void __exit cleanup_scx200_docflash(void) 205static void __exit cleanup_scx200_docflash(void)
212{ 206{
213 if (mymtd) { 207 if (mymtd) {
214#ifdef CONFIG_MTD_PARTITIONS 208 mtd_device_unregister(mymtd);
215 del_mtd_partitions(mymtd);
216#else
217 del_mtd_device(mymtd);
218#endif
219 map_destroy(mymtd); 209 map_destroy(mymtd);
220 } 210 }
221 if (scx200_docflash_map.virt) { 211 if (scx200_docflash_map.virt) {
diff --git a/drivers/mtd/maps/solutionengine.c b/drivers/mtd/maps/solutionengine.c
index 0eb41d9c6786..cbf6bade9354 100644
--- a/drivers/mtd/maps/solutionengine.c
+++ b/drivers/mtd/maps/solutionengine.c
@@ -89,7 +89,7 @@ static int __init init_soleng_maps(void)
89 eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map); 89 eprom_mtd = do_map_probe("map_rom", &soleng_eprom_map);
90 if (eprom_mtd) { 90 if (eprom_mtd) {
91 eprom_mtd->owner = THIS_MODULE; 91 eprom_mtd->owner = THIS_MODULE;
92 add_mtd_device(eprom_mtd); 92 mtd_device_register(eprom_mtd, NULL, 0);
93 } 93 }
94 94
95 nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0); 95 nr_parts = parse_mtd_partitions(flash_mtd, probes, &parsed_parts, 0);
@@ -104,9 +104,9 @@ static int __init init_soleng_maps(void)
104#endif /* CONFIG_MTD_SUPERH_RESERVE */ 104#endif /* CONFIG_MTD_SUPERH_RESERVE */
105 105
106 if (nr_parts > 0) 106 if (nr_parts > 0)
107 add_mtd_partitions(flash_mtd, parsed_parts, nr_parts); 107 mtd_device_register(flash_mtd, parsed_parts, nr_parts);
108 else 108 else
109 add_mtd_device(flash_mtd); 109 mtd_device_register(flash_mtd, NULL, 0);
110 110
111 return 0; 111 return 0;
112} 112}
@@ -114,14 +114,14 @@ static int __init init_soleng_maps(void)
114static void __exit cleanup_soleng_maps(void) 114static void __exit cleanup_soleng_maps(void)
115{ 115{
116 if (eprom_mtd) { 116 if (eprom_mtd) {
117 del_mtd_device(eprom_mtd); 117 mtd_device_unregister(eprom_mtd);
118 map_destroy(eprom_mtd); 118 map_destroy(eprom_mtd);
119 } 119 }
120 120
121 if (parsed_parts) 121 if (parsed_parts)
122 del_mtd_partitions(flash_mtd); 122 mtd_device_unregister(flash_mtd);
123 else 123 else
124 del_mtd_device(flash_mtd); 124 mtd_device_unregister(flash_mtd);
125 map_destroy(flash_mtd); 125 map_destroy(flash_mtd);
126} 126}
127 127
diff --git a/drivers/mtd/maps/sun_uflash.c b/drivers/mtd/maps/sun_uflash.c
index 3f1cb328a574..2d66234f57cb 100644
--- a/drivers/mtd/maps/sun_uflash.c
+++ b/drivers/mtd/maps/sun_uflash.c
@@ -101,7 +101,7 @@ int uflash_devinit(struct platform_device *op, struct device_node *dp)
101 101
102 up->mtd->owner = THIS_MODULE; 102 up->mtd->owner = THIS_MODULE;
103 103
104 add_mtd_device(up->mtd); 104 mtd_device_register(up->mtd, NULL, 0);
105 105
106 dev_set_drvdata(&op->dev, up); 106 dev_set_drvdata(&op->dev, up);
107 107
@@ -126,7 +126,7 @@ static int __devexit uflash_remove(struct platform_device *op)
126 struct uflash_dev *up = dev_get_drvdata(&op->dev); 126 struct uflash_dev *up = dev_get_drvdata(&op->dev);
127 127
128 if (up->mtd) { 128 if (up->mtd) {
129 del_mtd_device(up->mtd); 129 mtd_device_unregister(up->mtd);
130 map_destroy(up->mtd); 130 map_destroy(up->mtd);
131 } 131 }
132 if (up->map.virt) { 132 if (up->map.virt) {
diff --git a/drivers/mtd/maps/tqm8xxl.c b/drivers/mtd/maps/tqm8xxl.c
index 0718dfb3ee64..d78587990e7e 100644
--- a/drivers/mtd/maps/tqm8xxl.c
+++ b/drivers/mtd/maps/tqm8xxl.c
@@ -62,7 +62,6 @@ static void __iomem *start_scan_addr;
62 * "struct map_desc *_io_desc" for the corresponding machine. 62 * "struct map_desc *_io_desc" for the corresponding machine.
63 */ 63 */
64 64
65#ifdef CONFIG_MTD_PARTITIONS
66/* Currently, TQM8xxL has up to 8MiB flash */ 65/* Currently, TQM8xxL has up to 8MiB flash */
67static unsigned long tqm8xxl_max_flash_size = 0x00800000; 66static unsigned long tqm8xxl_max_flash_size = 0x00800000;
68 67
@@ -107,7 +106,6 @@ static struct mtd_partition tqm8xxl_fs_partitions[] = {
107 //.size = MTDPART_SIZ_FULL, 106 //.size = MTDPART_SIZ_FULL,
108 } 107 }
109}; 108};
110#endif
111 109
112static int __init init_tqm_mtd(void) 110static int __init init_tqm_mtd(void)
113{ 111{
@@ -188,7 +186,6 @@ static int __init init_tqm_mtd(void)
188 goto error_mem; 186 goto error_mem;
189 } 187 }
190 188
191#ifdef CONFIG_MTD_PARTITIONS
192 /* 189 /*
193 * Select Static partition definitions 190 * Select Static partition definitions
194 */ 191 */
@@ -201,21 +198,14 @@ static int __init init_tqm_mtd(void)
201 part_banks[1].nums = ARRAY_SIZE(tqm8xxl_fs_partitions); 198 part_banks[1].nums = ARRAY_SIZE(tqm8xxl_fs_partitions);
202 199
203 for(idx = 0; idx < num_banks ; idx++) { 200 for(idx = 0; idx < num_banks ; idx++) {
204 if (part_banks[idx].nums == 0) { 201 if (part_banks[idx].nums == 0)
205 printk(KERN_NOTICE "TQM flash%d: no partition info available, registering whole flash at once\n", idx); 202 printk(KERN_NOTICE "TQM flash%d: no partition info available, registering whole flash at once\n", idx);
206 add_mtd_device(mtd_banks[idx]); 203 else
207 } else {
208 printk(KERN_NOTICE "TQM flash%d: Using %s partition definition\n", 204 printk(KERN_NOTICE "TQM flash%d: Using %s partition definition\n",
209 idx, part_banks[idx].type); 205 idx, part_banks[idx].type);
210 add_mtd_partitions(mtd_banks[idx], part_banks[idx].mtd_part, 206 mtd_device_register(mtd_banks[idx], part_banks[idx].mtd_part,
211 part_banks[idx].nums); 207 part_banks[idx].nums);
212 }
213 } 208 }
214#else
215 printk(KERN_NOTICE "TQM flash: registering %d whole flash banks at once\n", num_banks);
216 for(idx = 0 ; idx < num_banks ; idx++)
217 add_mtd_device(mtd_banks[idx]);
218#endif
219 return 0; 209 return 0;
220error_mem: 210error_mem:
221 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) { 211 for(idx = 0 ; idx < FLASH_BANK_MAX ; idx++) {
@@ -237,7 +227,7 @@ static void __exit cleanup_tqm_mtd(void)
237 for(idx = 0 ; idx < num_banks ; idx++) { 227 for(idx = 0 ; idx < num_banks ; idx++) {
238 /* destroy mtd_info previously allocated */ 228 /* destroy mtd_info previously allocated */
239 if (mtd_banks[idx]) { 229 if (mtd_banks[idx]) {
240 del_mtd_partitions(mtd_banks[idx]); 230 mtd_device_unregister(mtd_banks[idx]);
241 map_destroy(mtd_banks[idx]); 231 map_destroy(mtd_banks[idx]);
242 } 232 }
243 /* release map_info not used anymore */ 233 /* release map_info not used anymore */
diff --git a/drivers/mtd/maps/ts5500_flash.c b/drivers/mtd/maps/ts5500_flash.c
index e02dfa9d4ddd..d1d671daf235 100644
--- a/drivers/mtd/maps/ts5500_flash.c
+++ b/drivers/mtd/maps/ts5500_flash.c
@@ -89,7 +89,7 @@ static int __init init_ts5500_map(void)
89 } 89 }
90 90
91 mymtd->owner = THIS_MODULE; 91 mymtd->owner = THIS_MODULE;
92 add_mtd_partitions(mymtd, ts5500_partitions, NUM_PARTITIONS); 92 mtd_device_register(mymtd, ts5500_partitions, NUM_PARTITIONS);
93 93
94 return 0; 94 return 0;
95 95
@@ -102,7 +102,7 @@ err2:
102static void __exit cleanup_ts5500_map(void) 102static void __exit cleanup_ts5500_map(void)
103{ 103{
104 if (mymtd) { 104 if (mymtd) {
105 del_mtd_partitions(mymtd); 105 mtd_device_unregister(mymtd);
106 map_destroy(mymtd); 106 map_destroy(mymtd);
107 } 107 }
108 108
diff --git a/drivers/mtd/maps/tsunami_flash.c b/drivers/mtd/maps/tsunami_flash.c
index 77a8bfc02577..1de390e1c2fb 100644
--- a/drivers/mtd/maps/tsunami_flash.c
+++ b/drivers/mtd/maps/tsunami_flash.c
@@ -76,7 +76,7 @@ static void __exit cleanup_tsunami_flash(void)
76 struct mtd_info *mtd; 76 struct mtd_info *mtd;
77 mtd = tsunami_flash_mtd; 77 mtd = tsunami_flash_mtd;
78 if (mtd) { 78 if (mtd) {
79 del_mtd_device(mtd); 79 mtd_device_unregister(mtd);
80 map_destroy(mtd); 80 map_destroy(mtd);
81 } 81 }
82 tsunami_flash_mtd = 0; 82 tsunami_flash_mtd = 0;
@@ -97,7 +97,7 @@ static int __init init_tsunami_flash(void)
97 } 97 }
98 if (tsunami_flash_mtd) { 98 if (tsunami_flash_mtd) {
99 tsunami_flash_mtd->owner = THIS_MODULE; 99 tsunami_flash_mtd->owner = THIS_MODULE;
100 add_mtd_device(tsunami_flash_mtd); 100 mtd_device_register(tsunami_flash_mtd, NULL, 0);
101 return 0; 101 return 0;
102 } 102 }
103 return -ENXIO; 103 return -ENXIO;
diff --git a/drivers/mtd/maps/uclinux.c b/drivers/mtd/maps/uclinux.c
index 35009294b435..6793074f3f40 100644
--- a/drivers/mtd/maps/uclinux.c
+++ b/drivers/mtd/maps/uclinux.c
@@ -89,11 +89,7 @@ static int __init uclinux_mtd_init(void)
89 mtd->priv = mapp; 89 mtd->priv = mapp;
90 90
91 uclinux_ram_mtdinfo = mtd; 91 uclinux_ram_mtdinfo = mtd;
92#ifdef CONFIG_MTD_PARTITIONS 92 mtd_device_register(mtd, uclinux_romfs, NUM_PARTITIONS);
93 add_mtd_partitions(mtd, uclinux_romfs, NUM_PARTITIONS);
94#else
95 add_mtd_device(mtd);
96#endif
97 93
98 return(0); 94 return(0);
99} 95}
@@ -103,11 +99,7 @@ static int __init uclinux_mtd_init(void)
103static void __exit uclinux_mtd_cleanup(void) 99static void __exit uclinux_mtd_cleanup(void)
104{ 100{
105 if (uclinux_ram_mtdinfo) { 101 if (uclinux_ram_mtdinfo) {
106#ifdef CONFIG_MTD_PARTITIONS 102 mtd_device_unregister(uclinux_ram_mtdinfo);
107 del_mtd_partitions(uclinux_ram_mtdinfo);
108#else
109 del_mtd_device(uclinux_ram_mtdinfo);
110#endif
111 map_destroy(uclinux_ram_mtdinfo); 103 map_destroy(uclinux_ram_mtdinfo);
112 uclinux_ram_mtdinfo = NULL; 104 uclinux_ram_mtdinfo = NULL;
113 } 105 }
diff --git a/drivers/mtd/maps/vmax301.c b/drivers/mtd/maps/vmax301.c
index 6adaa6acc193..5e68de73eabc 100644
--- a/drivers/mtd/maps/vmax301.c
+++ b/drivers/mtd/maps/vmax301.c
@@ -138,7 +138,7 @@ static void __exit cleanup_vmax301(void)
138 138
139 for (i=0; i<2; i++) { 139 for (i=0; i<2; i++) {
140 if (vmax_mtd[i]) { 140 if (vmax_mtd[i]) {
141 del_mtd_device(vmax_mtd[i]); 141 mtd_device_unregister(vmax_mtd[i]);
142 map_destroy(vmax_mtd[i]); 142 map_destroy(vmax_mtd[i]);
143 } 143 }
144 } 144 }
@@ -176,7 +176,7 @@ static int __init init_vmax301(void)
176 vmax_mtd[i] = do_map_probe("map_rom", &vmax_map[i]); 176 vmax_mtd[i] = do_map_probe("map_rom", &vmax_map[i]);
177 if (vmax_mtd[i]) { 177 if (vmax_mtd[i]) {
178 vmax_mtd[i]->owner = THIS_MODULE; 178 vmax_mtd[i]->owner = THIS_MODULE;
179 add_mtd_device(vmax_mtd[i]); 179 mtd_device_register(vmax_mtd[i], NULL, 0);
180 } 180 }
181 } 181 }
182 182
diff --git a/drivers/mtd/maps/vmu-flash.c b/drivers/mtd/maps/vmu-flash.c
index 4afc167731ef..3a04b078576a 100644
--- a/drivers/mtd/maps/vmu-flash.c
+++ b/drivers/mtd/maps/vmu-flash.c
@@ -563,7 +563,7 @@ static void vmu_queryblocks(struct mapleq *mq)
563 goto fail_cache_create; 563 goto fail_cache_create;
564 part_cur->pcache = pcache; 564 part_cur->pcache = pcache;
565 565
566 error = add_mtd_device(mtd_cur); 566 error = mtd_device_register(mtd_cur, NULL, 0);
567 if (error) 567 if (error)
568 goto fail_mtd_register; 568 goto fail_mtd_register;
569 569
@@ -709,7 +709,7 @@ static void __devexit vmu_disconnect(struct maple_device *mdev)
709 for (x = 0; x < card->partitions; x++) { 709 for (x = 0; x < card->partitions; x++) {
710 mpart = ((card->mtd)[x]).priv; 710 mpart = ((card->mtd)[x]).priv;
711 mpart->mdev = NULL; 711 mpart->mdev = NULL;
712 del_mtd_device(&((card->mtd)[x])); 712 mtd_device_unregister(&((card->mtd)[x]));
713 kfree(((card->parts)[x]).name); 713 kfree(((card->parts)[x]).name);
714 } 714 }
715 kfree(card->parts); 715 kfree(card->parts);
diff --git a/drivers/mtd/maps/wr_sbc82xx_flash.c b/drivers/mtd/maps/wr_sbc82xx_flash.c
index 933a2b6598b4..901ce968efae 100644
--- a/drivers/mtd/maps/wr_sbc82xx_flash.c
+++ b/drivers/mtd/maps/wr_sbc82xx_flash.c
@@ -132,17 +132,20 @@ static int __init init_sbc82xx_flash(void)
132 nr_parts = parse_mtd_partitions(sbcmtd[i], part_probes, 132 nr_parts = parse_mtd_partitions(sbcmtd[i], part_probes,
133 &sbcmtd_parts[i], 0); 133 &sbcmtd_parts[i], 0);
134 if (nr_parts > 0) { 134 if (nr_parts > 0) {
135 add_mtd_partitions (sbcmtd[i], sbcmtd_parts[i], nr_parts); 135 mtd_device_register(sbcmtd[i], sbcmtd_parts[i],
136 nr_parts);
136 continue; 137 continue;
137 } 138 }
138 139
139 /* No partitioning detected. Use default */ 140 /* No partitioning detected. Use default */
140 if (i == 2) { 141 if (i == 2) {
141 add_mtd_device(sbcmtd[i]); 142 mtd_device_register(sbcmtd[i], NULL, 0);
142 } else if (i == bigflash) { 143 } else if (i == bigflash) {
143 add_mtd_partitions (sbcmtd[i], bigflash_parts, ARRAY_SIZE(bigflash_parts)); 144 mtd_device_register(sbcmtd[i], bigflash_parts,
145 ARRAY_SIZE(bigflash_parts));
144 } else { 146 } else {
145 add_mtd_partitions (sbcmtd[i], smallflash_parts, ARRAY_SIZE(smallflash_parts)); 147 mtd_device_register(sbcmtd[i], smallflash_parts,
148 ARRAY_SIZE(smallflash_parts));
146 } 149 }
147 } 150 }
148 return 0; 151 return 0;
@@ -157,9 +160,9 @@ static void __exit cleanup_sbc82xx_flash(void)
157 continue; 160 continue;
158 161
159 if (i<2 || sbcmtd_parts[i]) 162 if (i<2 || sbcmtd_parts[i])
160 del_mtd_partitions(sbcmtd[i]); 163 mtd_device_unregister(sbcmtd[i]);
161 else 164 else
162 del_mtd_device(sbcmtd[i]); 165 mtd_device_unregister(sbcmtd[i]);
163 166
164 kfree(sbcmtd_parts[i]); 167 kfree(sbcmtd_parts[i]);
165 map_destroy(sbcmtd[i]); 168 map_destroy(sbcmtd[i]);
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index a534e1f0c348..ca385697446e 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -221,15 +221,33 @@ static int blktrans_open(struct block_device *bdev, fmode_t mode)
221 kref_get(&dev->ref); 221 kref_get(&dev->ref);
222 __module_get(dev->tr->owner); 222 __module_get(dev->tr->owner);
223 223
224 if (dev->mtd) { 224 if (!dev->mtd)
225 ret = dev->tr->open ? dev->tr->open(dev) : 0; 225 goto unlock;
226 __get_mtd_device(dev->mtd); 226
227 if (dev->tr->open) {
228 ret = dev->tr->open(dev);
229 if (ret)
230 goto error_put;
227 } 231 }
228 232
233 ret = __get_mtd_device(dev->mtd);
234 if (ret)
235 goto error_release;
236
229unlock: 237unlock:
230 mutex_unlock(&dev->lock); 238 mutex_unlock(&dev->lock);
231 blktrans_dev_put(dev); 239 blktrans_dev_put(dev);
232 return ret; 240 return ret;
241
242error_release:
243 if (dev->tr->release)
244 dev->tr->release(dev);
245error_put:
246 module_put(dev->tr->owner);
247 kref_put(&dev->ref, blktrans_dev_release);
248 mutex_unlock(&dev->lock);
249 blktrans_dev_put(dev);
250 return ret;
233} 251}
234 252
235static int blktrans_release(struct gendisk *disk, fmode_t mode) 253static int blktrans_release(struct gendisk *disk, fmode_t mode)
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index 4c36ef66a46b..3f92731a5b9e 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -166,10 +166,23 @@ static int mtd_close(struct inode *inode, struct file *file)
166 return 0; 166 return 0;
167} /* mtd_close */ 167} /* mtd_close */
168 168
169/* FIXME: This _really_ needs to die. In 2.5, we should lock the 169/* Back in June 2001, dwmw2 wrote:
170 userspace buffer down and use it directly with readv/writev. 170 *
171*/ 171 * FIXME: This _really_ needs to die. In 2.5, we should lock the
172#define MAX_KMALLOC_SIZE 0x20000 172 * userspace buffer down and use it directly with readv/writev.
173 *
174 * The implementation below, using mtd_kmalloc_up_to, mitigates
175 * allocation failures when the system is under low-memory situations
176 * or if memory is highly fragmented at the cost of reducing the
177 * performance of the requested transfer due to a smaller buffer size.
178 *
179 * A more complex but more memory-efficient implementation based on
180 * get_user_pages and iovecs to cover extents of those pages is a
181 * longer-term goal, as intimated by dwmw2 above. However, for the
182 * write case, this requires yet more complex head and tail transfer
183 * handling when those head and tail offsets and sizes are such that
184 * alignment requirements are not met in the NAND subdriver.
185 */
173 186
174static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos) 187static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos)
175{ 188{
@@ -179,6 +192,7 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
179 size_t total_retlen=0; 192 size_t total_retlen=0;
180 int ret=0; 193 int ret=0;
181 int len; 194 int len;
195 size_t size = count;
182 char *kbuf; 196 char *kbuf;
183 197
184 DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n"); 198 DEBUG(MTD_DEBUG_LEVEL0,"MTD_read\n");
@@ -189,23 +203,12 @@ static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t
189 if (!count) 203 if (!count)
190 return 0; 204 return 0;
191 205
192 /* FIXME: Use kiovec in 2.5 to lock down the user's buffers 206 kbuf = mtd_kmalloc_up_to(mtd, &size);
193 and pass them directly to the MTD functions */
194
195 if (count > MAX_KMALLOC_SIZE)
196 kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
197 else
198 kbuf=kmalloc(count, GFP_KERNEL);
199
200 if (!kbuf) 207 if (!kbuf)
201 return -ENOMEM; 208 return -ENOMEM;
202 209
203 while (count) { 210 while (count) {
204 211 len = min_t(size_t, count, size);
205 if (count > MAX_KMALLOC_SIZE)
206 len = MAX_KMALLOC_SIZE;
207 else
208 len = count;
209 212
210 switch (mfi->mode) { 213 switch (mfi->mode) {
211 case MTD_MODE_OTP_FACTORY: 214 case MTD_MODE_OTP_FACTORY:
@@ -268,6 +271,7 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
268{ 271{
269 struct mtd_file_info *mfi = file->private_data; 272 struct mtd_file_info *mfi = file->private_data;
270 struct mtd_info *mtd = mfi->mtd; 273 struct mtd_info *mtd = mfi->mtd;
274 size_t size = count;
271 char *kbuf; 275 char *kbuf;
272 size_t retlen; 276 size_t retlen;
273 size_t total_retlen=0; 277 size_t total_retlen=0;
@@ -285,20 +289,12 @@ static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count
285 if (!count) 289 if (!count)
286 return 0; 290 return 0;
287 291
288 if (count > MAX_KMALLOC_SIZE) 292 kbuf = mtd_kmalloc_up_to(mtd, &size);
289 kbuf=kmalloc(MAX_KMALLOC_SIZE, GFP_KERNEL);
290 else
291 kbuf=kmalloc(count, GFP_KERNEL);
292
293 if (!kbuf) 293 if (!kbuf)
294 return -ENOMEM; 294 return -ENOMEM;
295 295
296 while (count) { 296 while (count) {
297 297 len = min_t(size_t, count, size);
298 if (count > MAX_KMALLOC_SIZE)
299 len = MAX_KMALLOC_SIZE;
300 else
301 len = count;
302 298
303 if (copy_from_user(kbuf, buf, len)) { 299 if (copy_from_user(kbuf, buf, len)) {
304 kfree(kbuf); 300 kfree(kbuf);
@@ -512,7 +508,6 @@ static int shrink_ecclayout(const struct nand_ecclayout *from,
512 return 0; 508 return 0;
513} 509}
514 510
515#ifdef CONFIG_MTD_PARTITIONS
516static int mtd_blkpg_ioctl(struct mtd_info *mtd, 511static int mtd_blkpg_ioctl(struct mtd_info *mtd,
517 struct blkpg_ioctl_arg __user *arg) 512 struct blkpg_ioctl_arg __user *arg)
518{ 513{
@@ -548,8 +543,6 @@ static int mtd_blkpg_ioctl(struct mtd_info *mtd,
548 return -EINVAL; 543 return -EINVAL;
549 } 544 }
550} 545}
551#endif
552
553 546
554static int mtd_ioctl(struct file *file, u_int cmd, u_long arg) 547static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
555{ 548{
@@ -941,7 +934,6 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
941 break; 934 break;
942 } 935 }
943 936
944#ifdef CONFIG_MTD_PARTITIONS
945 case BLKPG: 937 case BLKPG:
946 { 938 {
947 ret = mtd_blkpg_ioctl(mtd, 939 ret = mtd_blkpg_ioctl(mtd,
@@ -955,7 +947,6 @@ static int mtd_ioctl(struct file *file, u_int cmd, u_long arg)
955 ret = 0; 947 ret = 0;
956 break; 948 break;
957 } 949 }
958#endif
959 950
960 default: 951 default:
961 ret = -ENOTTY; 952 ret = -ENOTTY;
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 5060e608ea5d..e601672a5305 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -319,7 +319,7 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
319 if (!(mtd->flags & MTD_WRITEABLE)) 319 if (!(mtd->flags & MTD_WRITEABLE))
320 return -EROFS; 320 return -EROFS;
321 321
322 ops->retlen = 0; 322 ops->retlen = ops->oobretlen = 0;
323 323
324 for (i = 0; i < concat->num_subdev; i++) { 324 for (i = 0; i < concat->num_subdev; i++) {
325 struct mtd_info *subdev = concat->subdev[i]; 325 struct mtd_info *subdev = concat->subdev[i];
@@ -334,7 +334,7 @@ concat_write_oob(struct mtd_info *mtd, loff_t to, struct mtd_oob_ops *ops)
334 devops.len = subdev->size - to; 334 devops.len = subdev->size - to;
335 335
336 err = subdev->write_oob(subdev, to, &devops); 336 err = subdev->write_oob(subdev, to, &devops);
337 ops->retlen += devops.retlen; 337 ops->retlen += devops.oobretlen;
338 if (err) 338 if (err)
339 return err; 339 return err;
340 340
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index da69bc8a5a7d..c510aff289a8 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -24,6 +24,7 @@
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/kernel.h> 25#include <linux/kernel.h>
26#include <linux/ptrace.h> 26#include <linux/ptrace.h>
27#include <linux/seq_file.h>
27#include <linux/string.h> 28#include <linux/string.h>
28#include <linux/timer.h> 29#include <linux/timer.h>
29#include <linux/major.h> 30#include <linux/major.h>
@@ -37,6 +38,7 @@
37#include <linux/gfp.h> 38#include <linux/gfp.h>
38 39
39#include <linux/mtd/mtd.h> 40#include <linux/mtd/mtd.h>
41#include <linux/mtd/partitions.h>
40 42
41#include "mtdcore.h" 43#include "mtdcore.h"
42/* 44/*
@@ -391,7 +393,7 @@ fail_locked:
391 * if the requested device does not appear to be present in the list. 393 * if the requested device does not appear to be present in the list.
392 */ 394 */
393 395
394int del_mtd_device (struct mtd_info *mtd) 396int del_mtd_device(struct mtd_info *mtd)
395{ 397{
396 int ret; 398 int ret;
397 struct mtd_notifier *not; 399 struct mtd_notifier *not;
@@ -427,6 +429,50 @@ out_error:
427} 429}
428 430
429/** 431/**
432 * mtd_device_register - register an MTD device.
433 *
434 * @master: the MTD device to register
435 * @parts: the partitions to register - only valid if nr_parts > 0
436 * @nr_parts: the number of partitions in parts. If zero then the full MTD
437 * device is registered
438 *
439 * Register an MTD device with the system and optionally, a number of
440 * partitions. If nr_parts is 0 then the whole device is registered, otherwise
441 * only the partitions are registered. To register both the full device *and*
442 * the partitions, call mtd_device_register() twice, once with nr_parts == 0
443 * and once equal to the number of partitions.
444 */
445int mtd_device_register(struct mtd_info *master,
446 const struct mtd_partition *parts,
447 int nr_parts)
448{
449 return parts ? add_mtd_partitions(master, parts, nr_parts) :
450 add_mtd_device(master);
451}
452EXPORT_SYMBOL_GPL(mtd_device_register);
453
454/**
455 * mtd_device_unregister - unregister an existing MTD device.
456 *
457 * @master: the MTD device to unregister. This will unregister both the master
458 * and any partitions if registered.
459 */
460int mtd_device_unregister(struct mtd_info *master)
461{
462 int err;
463
464 err = del_mtd_partitions(master);
465 if (err)
466 return err;
467
468 if (!device_is_registered(&master->dev))
469 return 0;
470
471 return del_mtd_device(master);
472}
473EXPORT_SYMBOL_GPL(mtd_device_unregister);
474
475/**
430 * register_mtd_user - register a 'user' of MTD devices. 476 * register_mtd_user - register a 'user' of MTD devices.
431 * @new: pointer to notifier info structure 477 * @new: pointer to notifier info structure
432 * 478 *
@@ -443,7 +489,7 @@ void register_mtd_user (struct mtd_notifier *new)
443 489
444 list_add(&new->list, &mtd_notifiers); 490 list_add(&new->list, &mtd_notifiers);
445 491
446 __module_get(THIS_MODULE); 492 __module_get(THIS_MODULE);
447 493
448 mtd_for_each_device(mtd) 494 mtd_for_each_device(mtd)
449 new->add(mtd); 495 new->add(mtd);
@@ -532,7 +578,6 @@ int __get_mtd_device(struct mtd_info *mtd)
532 return -ENODEV; 578 return -ENODEV;
533 579
534 if (mtd->get_device) { 580 if (mtd->get_device) {
535
536 err = mtd->get_device(mtd); 581 err = mtd->get_device(mtd);
537 582
538 if (err) { 583 if (err) {
@@ -570,21 +615,13 @@ struct mtd_info *get_mtd_device_nm(const char *name)
570 if (!mtd) 615 if (!mtd)
571 goto out_unlock; 616 goto out_unlock;
572 617
573 if (!try_module_get(mtd->owner)) 618 err = __get_mtd_device(mtd);
619 if (err)
574 goto out_unlock; 620 goto out_unlock;
575 621
576 if (mtd->get_device) {
577 err = mtd->get_device(mtd);
578 if (err)
579 goto out_put;
580 }
581
582 mtd->usecount++;
583 mutex_unlock(&mtd_table_mutex); 622 mutex_unlock(&mtd_table_mutex);
584 return mtd; 623 return mtd;
585 624
586out_put:
587 module_put(mtd->owner);
588out_unlock: 625out_unlock:
589 mutex_unlock(&mtd_table_mutex); 626 mutex_unlock(&mtd_table_mutex);
590 return ERR_PTR(err); 627 return ERR_PTR(err);
@@ -638,8 +675,54 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
638 return ret; 675 return ret;
639} 676}
640 677
641EXPORT_SYMBOL_GPL(add_mtd_device); 678/**
642EXPORT_SYMBOL_GPL(del_mtd_device); 679 * mtd_kmalloc_up_to - allocate a contiguous buffer up to the specified size
680 * @size: A pointer to the ideal or maximum size of the allocation. Points
681 * to the actual allocation size on success.
682 *
683 * This routine attempts to allocate a contiguous kernel buffer up to
684 * the specified size, backing off the size of the request exponentially
685 * until the request succeeds or until the allocation size falls below
686 * the system page size. This attempts to make sure it does not adversely
687 * impact system performance, so when allocating more than one page, we
688 * ask the memory allocator to avoid re-trying, swapping, writing back
689 * or performing I/O.
690 *
691 * Note, this function also makes sure that the allocated buffer is aligned to
692 * the MTD device's min. I/O unit, i.e. the "mtd->writesize" value.
693 *
694 * This is called, for example by mtd_{read,write} and jffs2_scan_medium,
695 * to handle smaller (i.e. degraded) buffer allocations under low- or
696 * fragmented-memory situations where such reduced allocations, from a
697 * requested ideal, are allowed.
698 *
699 * Returns a pointer to the allocated buffer on success; otherwise, NULL.
700 */
701void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size)
702{
703 gfp_t flags = __GFP_NOWARN | __GFP_WAIT |
704 __GFP_NORETRY | __GFP_NO_KSWAPD;
705 size_t min_alloc = max_t(size_t, mtd->writesize, PAGE_SIZE);
706 void *kbuf;
707
708 *size = min_t(size_t, *size, KMALLOC_MAX_SIZE);
709
710 while (*size > min_alloc) {
711 kbuf = kmalloc(*size, flags);
712 if (kbuf)
713 return kbuf;
714
715 *size >>= 1;
716 *size = ALIGN(*size, mtd->writesize);
717 }
718
719 /*
720 * For the last resort allocation allow 'kmalloc()' to do all sorts of
721 * things (write-back, dropping caches, etc) by using GFP_KERNEL.
722 */
723 return kmalloc(*size, GFP_KERNEL);
724}
725
643EXPORT_SYMBOL_GPL(get_mtd_device); 726EXPORT_SYMBOL_GPL(get_mtd_device);
644EXPORT_SYMBOL_GPL(get_mtd_device_nm); 727EXPORT_SYMBOL_GPL(get_mtd_device_nm);
645EXPORT_SYMBOL_GPL(__get_mtd_device); 728EXPORT_SYMBOL_GPL(__get_mtd_device);
@@ -648,6 +731,7 @@ EXPORT_SYMBOL_GPL(__put_mtd_device);
648EXPORT_SYMBOL_GPL(register_mtd_user); 731EXPORT_SYMBOL_GPL(register_mtd_user);
649EXPORT_SYMBOL_GPL(unregister_mtd_user); 732EXPORT_SYMBOL_GPL(unregister_mtd_user);
650EXPORT_SYMBOL_GPL(default_mtd_writev); 733EXPORT_SYMBOL_GPL(default_mtd_writev);
734EXPORT_SYMBOL_GPL(mtd_kmalloc_up_to);
651 735
652#ifdef CONFIG_PROC_FS 736#ifdef CONFIG_PROC_FS
653 737
@@ -656,44 +740,32 @@ EXPORT_SYMBOL_GPL(default_mtd_writev);
656 740
657static struct proc_dir_entry *proc_mtd; 741static struct proc_dir_entry *proc_mtd;
658 742
659static inline int mtd_proc_info(char *buf, struct mtd_info *this) 743static int mtd_proc_show(struct seq_file *m, void *v)
660{
661 return sprintf(buf, "mtd%d: %8.8llx %8.8x \"%s\"\n", this->index,
662 (unsigned long long)this->size,
663 this->erasesize, this->name);
664}
665
666static int mtd_read_proc (char *page, char **start, off_t off, int count,
667 int *eof, void *data_unused)
668{ 744{
669 struct mtd_info *mtd; 745 struct mtd_info *mtd;
670 int len, l;
671 off_t begin = 0;
672 746
747 seq_puts(m, "dev: size erasesize name\n");
673 mutex_lock(&mtd_table_mutex); 748 mutex_lock(&mtd_table_mutex);
674
675 len = sprintf(page, "dev: size erasesize name\n");
676 mtd_for_each_device(mtd) { 749 mtd_for_each_device(mtd) {
677 l = mtd_proc_info(page + len, mtd); 750 seq_printf(m, "mtd%d: %8.8llx %8.8x \"%s\"\n",
678 len += l; 751 mtd->index, (unsigned long long)mtd->size,
679 if (len+begin > off+count) 752 mtd->erasesize, mtd->name);
680 goto done; 753 }
681 if (len+begin < off) {
682 begin += len;
683 len = 0;
684 }
685 }
686
687 *eof = 1;
688
689done:
690 mutex_unlock(&mtd_table_mutex); 754 mutex_unlock(&mtd_table_mutex);
691 if (off >= len+begin) 755 return 0;
692 return 0; 756}
693 *start = page + (off-begin); 757
694 return ((count < begin+len-off) ? count : begin+len-off); 758static int mtd_proc_open(struct inode *inode, struct file *file)
759{
760 return single_open(file, mtd_proc_show, NULL);
695} 761}
696 762
763static const struct file_operations mtd_proc_ops = {
764 .open = mtd_proc_open,
765 .read = seq_read,
766 .llseek = seq_lseek,
767 .release = single_release,
768};
697#endif /* CONFIG_PROC_FS */ 769#endif /* CONFIG_PROC_FS */
698 770
699/*====================================================================*/ 771/*====================================================================*/
@@ -734,8 +806,7 @@ static int __init init_mtd(void)
734 goto err_bdi3; 806 goto err_bdi3;
735 807
736#ifdef CONFIG_PROC_FS 808#ifdef CONFIG_PROC_FS
737 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 809 proc_mtd = proc_create("mtd", 0, NULL, &mtd_proc_ops);
738 proc_mtd->read_proc = mtd_read_proc;
739#endif /* CONFIG_PROC_FS */ 810#endif /* CONFIG_PROC_FS */
740 return 0; 811 return 0;
741 812
@@ -753,7 +824,7 @@ err_reg:
753static void __exit cleanup_mtd(void) 824static void __exit cleanup_mtd(void)
754{ 825{
755#ifdef CONFIG_PROC_FS 826#ifdef CONFIG_PROC_FS
756 if (proc_mtd) 827 if (proc_mtd)
757 remove_proc_entry( "mtd", NULL); 828 remove_proc_entry( "mtd", NULL);
758#endif /* CONFIG_PROC_FS */ 829#endif /* CONFIG_PROC_FS */
759 class_unregister(&mtd_class); 830 class_unregister(&mtd_class);
diff --git a/drivers/mtd/mtdcore.h b/drivers/mtd/mtdcore.h
index 6a64fdebc898..0ed6126b4c1f 100644
--- a/drivers/mtd/mtdcore.h
+++ b/drivers/mtd/mtdcore.h
@@ -10,6 +10,12 @@
10extern struct mutex mtd_table_mutex; 10extern struct mutex mtd_table_mutex;
11extern struct mtd_info *__mtd_next_device(int i); 11extern struct mtd_info *__mtd_next_device(int i);
12 12
13extern int add_mtd_device(struct mtd_info *mtd);
14extern int del_mtd_device(struct mtd_info *mtd);
15extern int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *,
16 int);
17extern int del_mtd_partitions(struct mtd_info *);
18
13#define mtd_for_each_device(mtd) \ 19#define mtd_for_each_device(mtd) \
14 for ((mtd) = __mtd_next_device(0); \ 20 for ((mtd) = __mtd_next_device(0); \
15 (mtd) != NULL; \ 21 (mtd) != NULL; \
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 0a4760174782..630be3e7da04 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -31,6 +31,8 @@
31#include <linux/mtd/partitions.h> 31#include <linux/mtd/partitions.h>
32#include <linux/err.h> 32#include <linux/err.h>
33 33
34#include "mtdcore.h"
35
34/* Our partition linked list */ 36/* Our partition linked list */
35static LIST_HEAD(mtd_partitions); 37static LIST_HEAD(mtd_partitions);
36static DEFINE_MUTEX(mtd_partitions_mutex); 38static DEFINE_MUTEX(mtd_partitions_mutex);
@@ -376,7 +378,6 @@ int del_mtd_partitions(struct mtd_info *master)
376 378
377 return err; 379 return err;
378} 380}
379EXPORT_SYMBOL(del_mtd_partitions);
380 381
381static struct mtd_part *allocate_partition(struct mtd_info *master, 382static struct mtd_part *allocate_partition(struct mtd_info *master,
382 const struct mtd_partition *part, int partno, 383 const struct mtd_partition *part, int partno,
@@ -671,7 +672,6 @@ int add_mtd_partitions(struct mtd_info *master,
671 672
672 return 0; 673 return 0;
673} 674}
674EXPORT_SYMBOL(add_mtd_partitions);
675 675
676static DEFINE_SPINLOCK(part_parser_lock); 676static DEFINE_SPINLOCK(part_parser_lock);
677static LIST_HEAD(part_parsers); 677static LIST_HEAD(part_parsers);
@@ -722,11 +722,8 @@ int parse_mtd_partitions(struct mtd_info *master, const char **types,
722 parser = get_partition_parser(*types); 722 parser = get_partition_parser(*types);
723 if (!parser && !request_module("%s", *types)) 723 if (!parser && !request_module("%s", *types))
724 parser = get_partition_parser(*types); 724 parser = get_partition_parser(*types);
725 if (!parser) { 725 if (!parser)
726 printk(KERN_NOTICE "%s partition parsing not available\n",
727 *types);
728 continue; 726 continue;
729 }
730 ret = (*parser->parse_fn)(master, pparts, origin); 727 ret = (*parser->parse_fn)(master, pparts, origin);
731 if (ret > 0) { 728 if (ret > 0) {
732 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n", 729 printk(KERN_NOTICE "%d %s partitions found on MTD device %s\n",
diff --git a/drivers/mtd/mtdswap.c b/drivers/mtd/mtdswap.c
index fed215c4cfa1..fd7885327611 100644
--- a/drivers/mtd/mtdswap.c
+++ b/drivers/mtd/mtdswap.c
@@ -1450,7 +1450,13 @@ static void mtdswap_add_mtd(struct mtd_blktrans_ops *tr, struct mtd_info *mtd)
1450 } 1450 }
1451 1451
1452 oinfo = mtd->ecclayout; 1452 oinfo = mtd->ecclayout;
1453 if (!mtd->oobsize || !oinfo || oinfo->oobavail < MTDSWAP_OOBSIZE) { 1453 if (!oinfo) {
1454 printk(KERN_ERR "%s: mtd%d does not have OOB\n",
1455 MTDSWAP_PREFIX, mtd->index);
1456 return;
1457 }
1458
1459 if (!mtd->oobsize || oinfo->oobavail < MTDSWAP_OOBSIZE) {
1454 printk(KERN_ERR "%s: Not enough free bytes in OOB, " 1460 printk(KERN_ERR "%s: Not enough free bytes in OOB, "
1455 "%d available, %zu needed.\n", 1461 "%d available, %zu needed.\n",
1456 MTDSWAP_PREFIX, oinfo->oobavail, MTDSWAP_OOBSIZE); 1462 MTDSWAP_PREFIX, oinfo->oobavail, MTDSWAP_OOBSIZE);
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index edec457d361d..4c3425235adc 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -92,7 +92,7 @@ config MTD_NAND_EDB7312
92 92
93config MTD_NAND_H1900 93config MTD_NAND_H1900
94 tristate "iPAQ H1900 flash" 94 tristate "iPAQ H1900 flash"
95 depends on ARCH_PXA && MTD_PARTITIONS 95 depends on ARCH_PXA
96 help 96 help
97 This enables the driver for the iPAQ h1900 flash. 97 This enables the driver for the iPAQ h1900 flash.
98 98
@@ -419,7 +419,6 @@ config MTD_NAND_TMIO
419 419
420config MTD_NAND_NANDSIM 420config MTD_NAND_NANDSIM
421 tristate "Support for NAND Flash Simulator" 421 tristate "Support for NAND Flash Simulator"
422 depends on MTD_PARTITIONS
423 help 422 help
424 The simulator may simulate various NAND flash chips for the 423 The simulator may simulate various NAND flash chips for the
425 MTD nand layer. 424 MTD nand layer.
@@ -513,7 +512,7 @@ config MTD_NAND_SOCRATES
513 512
514config MTD_NAND_NUC900 513config MTD_NAND_NUC900
515 tristate "Support for NAND on Nuvoton NUC9xx/w90p910 evaluation boards." 514 tristate "Support for NAND on Nuvoton NUC9xx/w90p910 evaluation boards."
516 depends on ARCH_W90X900 && MTD_PARTITIONS 515 depends on ARCH_W90X900
517 help 516 help
518 This enables the driver for the NAND Flash on evaluation board based 517 This enables the driver for the NAND Flash on evaluation board based
519 on w90p910 / NUC9xx. 518 on w90p910 / NUC9xx.
diff --git a/drivers/mtd/nand/alauda.c b/drivers/mtd/nand/alauda.c
index 8691e0482ed2..eb40ea829ab2 100644
--- a/drivers/mtd/nand/alauda.c
+++ b/drivers/mtd/nand/alauda.c
@@ -120,7 +120,7 @@ static void alauda_delete(struct kref *kref)
120 struct alauda *al = container_of(kref, struct alauda, kref); 120 struct alauda *al = container_of(kref, struct alauda, kref);
121 121
122 if (al->mtd) { 122 if (al->mtd) {
123 del_mtd_device(al->mtd); 123 mtd_device_unregister(al->mtd);
124 kfree(al->mtd); 124 kfree(al->mtd);
125 } 125 }
126 usb_put_dev(al->dev); 126 usb_put_dev(al->dev);
@@ -592,7 +592,7 @@ static int alauda_init_media(struct alauda *al)
592 mtd->priv = al; 592 mtd->priv = al;
593 mtd->owner = THIS_MODULE; 593 mtd->owner = THIS_MODULE;
594 594
595 err = add_mtd_device(mtd); 595 err = mtd_device_register(mtd, NULL, 0);
596 if (err) { 596 if (err) {
597 err = -ENFILE; 597 err = -ENFILE;
598 goto error; 598 goto error;
diff --git a/drivers/mtd/nand/ams-delta.c b/drivers/mtd/nand/ams-delta.c
index bc65bf71e1a2..78017eb9318e 100644
--- a/drivers/mtd/nand/ams-delta.c
+++ b/drivers/mtd/nand/ams-delta.c
@@ -235,8 +235,8 @@ static int __devinit ams_delta_init(struct platform_device *pdev)
235 } 235 }
236 236
237 /* Register the partitions */ 237 /* Register the partitions */
238 add_mtd_partitions(ams_delta_mtd, partition_info, 238 mtd_device_register(ams_delta_mtd, partition_info,
239 ARRAY_SIZE(partition_info)); 239 ARRAY_SIZE(partition_info));
240 240
241 goto out; 241 goto out;
242 242
diff --git a/drivers/mtd/nand/atmel_nand.c b/drivers/mtd/nand/atmel_nand.c
index 950646aa4c4b..b300705d41cb 100644
--- a/drivers/mtd/nand/atmel_nand.c
+++ b/drivers/mtd/nand/atmel_nand.c
@@ -30,6 +30,7 @@
30#include <linux/mtd/nand.h> 30#include <linux/mtd/nand.h>
31#include <linux/mtd/partitions.h> 31#include <linux/mtd/partitions.h>
32 32
33#include <linux/dmaengine.h>
33#include <linux/gpio.h> 34#include <linux/gpio.h>
34#include <linux/io.h> 35#include <linux/io.h>
35 36
@@ -494,11 +495,8 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
494 struct resource *regs; 495 struct resource *regs;
495 struct resource *mem; 496 struct resource *mem;
496 int res; 497 int res;
497
498#ifdef CONFIG_MTD_PARTITIONS
499 struct mtd_partition *partitions = NULL; 498 struct mtd_partition *partitions = NULL;
500 int num_partitions = 0; 499 int num_partitions = 0;
501#endif
502 500
503 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0); 501 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
504 if (!mem) { 502 if (!mem) {
@@ -656,7 +654,6 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
656 goto err_scan_tail; 654 goto err_scan_tail;
657 } 655 }
658 656
659#ifdef CONFIG_MTD_PARTITIONS
660#ifdef CONFIG_MTD_CMDLINE_PARTS 657#ifdef CONFIG_MTD_CMDLINE_PARTS
661 mtd->name = "atmel_nand"; 658 mtd->name = "atmel_nand";
662 num_partitions = parse_mtd_partitions(mtd, part_probes, 659 num_partitions = parse_mtd_partitions(mtd, part_probes,
@@ -672,17 +669,11 @@ static int __init atmel_nand_probe(struct platform_device *pdev)
672 goto err_no_partitions; 669 goto err_no_partitions;
673 } 670 }
674 671
675 res = add_mtd_partitions(mtd, partitions, num_partitions); 672 res = mtd_device_register(mtd, partitions, num_partitions);
676#else
677 res = add_mtd_device(mtd);
678#endif
679
680 if (!res) 673 if (!res)
681 return res; 674 return res;
682 675
683#ifdef CONFIG_MTD_PARTITIONS
684err_no_partitions: 676err_no_partitions:
685#endif
686 nand_release(mtd); 677 nand_release(mtd);
687err_scan_tail: 678err_scan_tail:
688err_scan_ident: 679err_scan_ident:
diff --git a/drivers/mtd/nand/au1550nd.c b/drivers/mtd/nand/au1550nd.c
index 5d513b54a7d7..e7767eef4505 100644
--- a/drivers/mtd/nand/au1550nd.c
+++ b/drivers/mtd/nand/au1550nd.c
@@ -581,7 +581,8 @@ static int __init au1xxx_nand_init(void)
581 } 581 }
582 582
583 /* Register the partitions */ 583 /* Register the partitions */
584 add_mtd_partitions(au1550_mtd, partition_info, ARRAY_SIZE(partition_info)); 584 mtd_device_register(au1550_mtd, partition_info,
585 ARRAY_SIZE(partition_info));
585 586
586 return 0; 587 return 0;
587 588
diff --git a/drivers/mtd/nand/autcpu12.c b/drivers/mtd/nand/autcpu12.c
index 0911cf03db80..eddc9a224985 100644
--- a/drivers/mtd/nand/autcpu12.c
+++ b/drivers/mtd/nand/autcpu12.c
@@ -185,20 +185,20 @@ static int __init autcpu12_init(void)
185 /* Register the partitions */ 185 /* Register the partitions */
186 switch (autcpu12_mtd->size) { 186 switch (autcpu12_mtd->size) {
187 case SZ_16M: 187 case SZ_16M:
188 add_mtd_partitions(autcpu12_mtd, partition_info16k, 188 mtd_device_register(autcpu12_mtd, partition_info16k,
189 NUM_PARTITIONS16K); 189 NUM_PARTITIONS16K);
190 break; 190 break;
191 case SZ_32M: 191 case SZ_32M:
192 add_mtd_partitions(autcpu12_mtd, partition_info32k, 192 mtd_device_register(autcpu12_mtd, partition_info32k,
193 NUM_PARTITIONS32K); 193 NUM_PARTITIONS32K);
194 break; 194 break;
195 case SZ_64M: 195 case SZ_64M:
196 add_mtd_partitions(autcpu12_mtd, partition_info64k, 196 mtd_device_register(autcpu12_mtd, partition_info64k,
197 NUM_PARTITIONS64K); 197 NUM_PARTITIONS64K);
198 break; 198 break;
199 case SZ_128M: 199 case SZ_128M:
200 add_mtd_partitions(autcpu12_mtd, partition_info128k, 200 mtd_device_register(autcpu12_mtd, partition_info128k,
201 NUM_PARTITIONS128K); 201 NUM_PARTITIONS128K);
202 break; 202 break;
203 default: 203 default:
204 printk("Unsupported SmartMedia device\n"); 204 printk("Unsupported SmartMedia device\n");
diff --git a/drivers/mtd/nand/bcm_umi_nand.c b/drivers/mtd/nand/bcm_umi_nand.c
index dfe262c726fb..9ec280738a9a 100644
--- a/drivers/mtd/nand/bcm_umi_nand.c
+++ b/drivers/mtd/nand/bcm_umi_nand.c
@@ -52,9 +52,7 @@
52static const __devinitconst char gBanner[] = KERN_INFO \ 52static const __devinitconst char gBanner[] = KERN_INFO \
53 "BCM UMI MTD NAND Driver: 1.00\n"; 53 "BCM UMI MTD NAND Driver: 1.00\n";
54 54
55#ifdef CONFIG_MTD_PARTITIONS
56const char *part_probes[] = { "cmdlinepart", NULL }; 55const char *part_probes[] = { "cmdlinepart", NULL };
57#endif
58 56
59#if NAND_ECC_BCH 57#if NAND_ECC_BCH
60static uint8_t scan_ff_pattern[] = { 0xff }; 58static uint8_t scan_ff_pattern[] = { 0xff };
@@ -509,7 +507,7 @@ static int __devinit bcm_umi_nand_probe(struct platform_device *pdev)
509 kfree(board_mtd); 507 kfree(board_mtd);
510 return -EIO; 508 return -EIO;
511 } 509 }
512 add_mtd_partitions(board_mtd, partition_info, nr_partitions); 510 mtd_device_register(board_mtd, partition_info, nr_partitions);
513 } 511 }
514 512
515 /* Return happy */ 513 /* Return happy */
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 79947bea4d57..dd899cb5d366 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -659,15 +659,10 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
659static int __devinit bf5xx_nand_add_partition(struct bf5xx_nand_info *info) 659static int __devinit bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
660{ 660{
661 struct mtd_info *mtd = &info->mtd; 661 struct mtd_info *mtd = &info->mtd;
662
663#ifdef CONFIG_MTD_PARTITIONS
664 struct mtd_partition *parts = info->platform->partitions; 662 struct mtd_partition *parts = info->platform->partitions;
665 int nr = info->platform->nr_partitions; 663 int nr = info->platform->nr_partitions;
666 664
667 return add_mtd_partitions(mtd, parts, nr); 665 return mtd_device_register(mtd, parts, nr);
668#else
669 return add_mtd_device(mtd);
670#endif
671} 666}
672 667
673static int __devexit bf5xx_nand_remove(struct platform_device *pdev) 668static int __devexit bf5xx_nand_remove(struct platform_device *pdev)
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index e06c8983978e..87ebb4e5b0c3 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -90,9 +90,7 @@ static unsigned int numtimings;
90static int timing[3]; 90static int timing[3];
91module_param_array(timing, int, &numtimings, 0644); 91module_param_array(timing, int, &numtimings, 0644);
92 92
93#ifdef CONFIG_MTD_PARTITIONS
94static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; 93static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
95#endif
96 94
97/* Hrm. Why isn't this already conditional on something in the struct device? */ 95/* Hrm. Why isn't this already conditional on something in the struct device? */
98#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0) 96#define cafe_dev_dbg(dev, args...) do { if (debug) dev_dbg(dev, ##args); } while(0)
@@ -632,10 +630,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
632 struct cafe_priv *cafe; 630 struct cafe_priv *cafe;
633 uint32_t ctrl; 631 uint32_t ctrl;
634 int err = 0; 632 int err = 0;
635#ifdef CONFIG_MTD_PARTITIONS
636 struct mtd_partition *parts; 633 struct mtd_partition *parts;
637 int nr_parts; 634 int nr_parts;
638#endif
639 635
640 /* Very old versions shared the same PCI ident for all three 636 /* Very old versions shared the same PCI ident for all three
641 functions on the chip. Verify the class too... */ 637 functions on the chip. Verify the class too... */
@@ -804,9 +800,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
804 pci_set_drvdata(pdev, mtd); 800 pci_set_drvdata(pdev, mtd);
805 801
806 /* We register the whole device first, separate from the partitions */ 802 /* We register the whole device first, separate from the partitions */
807 add_mtd_device(mtd); 803 mtd_device_register(mtd, NULL, 0);
808 804
809#ifdef CONFIG_MTD_PARTITIONS
810#ifdef CONFIG_MTD_CMDLINE_PARTS 805#ifdef CONFIG_MTD_CMDLINE_PARTS
811 mtd->name = "cafe_nand"; 806 mtd->name = "cafe_nand";
812#endif 807#endif
@@ -814,9 +809,8 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
814 if (nr_parts > 0) { 809 if (nr_parts > 0) {
815 cafe->parts = parts; 810 cafe->parts = parts;
816 dev_info(&cafe->pdev->dev, "%d partitions found\n", nr_parts); 811 dev_info(&cafe->pdev->dev, "%d partitions found\n", nr_parts);
817 add_mtd_partitions(mtd, parts, nr_parts); 812 mtd_device_register(mtd, parts, nr_parts);
818 } 813 }
819#endif
820 goto out; 814 goto out;
821 815
822 out_irq: 816 out_irq:
@@ -838,7 +832,6 @@ static void __devexit cafe_nand_remove(struct pci_dev *pdev)
838 struct mtd_info *mtd = pci_get_drvdata(pdev); 832 struct mtd_info *mtd = pci_get_drvdata(pdev);
839 struct cafe_priv *cafe = mtd->priv; 833 struct cafe_priv *cafe = mtd->priv;
840 834
841 del_mtd_device(mtd);
842 /* Disable NAND IRQ in global IRQ mask register */ 835 /* Disable NAND IRQ in global IRQ mask register */
843 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK); 836 cafe_writel(cafe, ~1 & cafe_readl(cafe, GLOBAL_IRQ_MASK), GLOBAL_IRQ_MASK);
844 free_irq(pdev->irq, mtd); 837 free_irq(pdev->irq, mtd);
diff --git a/drivers/mtd/nand/cmx270_nand.c b/drivers/mtd/nand/cmx270_nand.c
index 6e6495278258..6fc043a30d1e 100644
--- a/drivers/mtd/nand/cmx270_nand.c
+++ b/drivers/mtd/nand/cmx270_nand.c
@@ -238,7 +238,7 @@ static int __init cmx270_init(void)
238 238
239 /* Register the partitions */ 239 /* Register the partitions */
240 pr_notice("Using %s partition definition\n", part_type); 240 pr_notice("Using %s partition definition\n", part_type);
241 ret = add_mtd_partitions(cmx270_nand_mtd, mtd_parts, mtd_parts_nb); 241 ret = mtd_device_register(cmx270_nand_mtd, mtd_parts, mtd_parts_nb);
242 if (ret) 242 if (ret)
243 goto err_scan; 243 goto err_scan;
244 244
diff --git a/drivers/mtd/nand/cs553x_nand.c b/drivers/mtd/nand/cs553x_nand.c
index 71c35a0b9826..f59ad1f2d5db 100644
--- a/drivers/mtd/nand/cs553x_nand.c
+++ b/drivers/mtd/nand/cs553x_nand.c
@@ -277,22 +277,15 @@ static int is_geode(void)
277 return 0; 277 return 0;
278} 278}
279 279
280
281#ifdef CONFIG_MTD_PARTITIONS
282static const char *part_probes[] = { "cmdlinepart", NULL }; 280static const char *part_probes[] = { "cmdlinepart", NULL };
283#endif
284
285 281
286static int __init cs553x_init(void) 282static int __init cs553x_init(void)
287{ 283{
288 int err = -ENXIO; 284 int err = -ENXIO;
289 int i; 285 int i;
290 uint64_t val; 286 uint64_t val;
291
292#ifdef CONFIG_MTD_PARTITIONS
293 int mtd_parts_nb = 0; 287 int mtd_parts_nb = 0;
294 struct mtd_partition *mtd_parts = NULL; 288 struct mtd_partition *mtd_parts = NULL;
295#endif
296 289
297 /* If the CPU isn't a Geode GX or LX, abort */ 290 /* If the CPU isn't a Geode GX or LX, abort */
298 if (!is_geode()) 291 if (!is_geode())
@@ -324,17 +317,11 @@ static int __init cs553x_init(void)
324 if (cs553x_mtd[i]) { 317 if (cs553x_mtd[i]) {
325 318
326 /* If any devices registered, return success. Else the last error. */ 319 /* If any devices registered, return success. Else the last error. */
327#ifdef CONFIG_MTD_PARTITIONS
328 mtd_parts_nb = parse_mtd_partitions(cs553x_mtd[i], part_probes, &mtd_parts, 0); 320 mtd_parts_nb = parse_mtd_partitions(cs553x_mtd[i], part_probes, &mtd_parts, 0);
329 if (mtd_parts_nb > 0) { 321 if (mtd_parts_nb > 0)
330 printk(KERN_NOTICE "Using command line partition definition\n"); 322 printk(KERN_NOTICE "Using command line partition definition\n");
331 add_mtd_partitions(cs553x_mtd[i], mtd_parts, mtd_parts_nb); 323 mtd_device_register(cs553x_mtd[i], mtd_parts,
332 } else { 324 mtd_parts_nb);
333 add_mtd_device(cs553x_mtd[i]);
334 }
335#else
336 add_mtd_device(cs553x_mtd[i]);
337#endif
338 err = 0; 325 err = 0;
339 } 326 }
340 } 327 }
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
index aff3468867ac..1f34951ae1a7 100644
--- a/drivers/mtd/nand/davinci_nand.c
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -530,6 +530,8 @@ static int __init nand_davinci_probe(struct platform_device *pdev)
530 int ret; 530 int ret;
531 uint32_t val; 531 uint32_t val;
532 nand_ecc_modes_t ecc_mode; 532 nand_ecc_modes_t ecc_mode;
533 struct mtd_partition *mtd_parts = NULL;
534 int mtd_parts_nb = 0;
533 535
534 /* insist on board-specific configuration */ 536 /* insist on board-specific configuration */
535 if (!pdata) 537 if (!pdata)
@@ -749,41 +751,33 @@ syndrome_done:
749 if (ret < 0) 751 if (ret < 0)
750 goto err_scan; 752 goto err_scan;
751 753
752 if (mtd_has_partitions()) { 754 if (mtd_has_cmdlinepart()) {
753 struct mtd_partition *mtd_parts = NULL; 755 static const char *probes[] __initconst = {
754 int mtd_parts_nb = 0; 756 "cmdlinepart", NULL
757 };
755 758
756 if (mtd_has_cmdlinepart()) { 759 mtd_parts_nb = parse_mtd_partitions(&info->mtd, probes,
757 static const char *probes[] __initconst = 760 &mtd_parts, 0);
758 { "cmdlinepart", NULL }; 761 }
759
760 mtd_parts_nb = parse_mtd_partitions(&info->mtd, probes,
761 &mtd_parts, 0);
762 }
763
764 if (mtd_parts_nb <= 0) {
765 mtd_parts = pdata->parts;
766 mtd_parts_nb = pdata->nr_parts;
767 }
768 762
769 /* Register any partitions */ 763 if (mtd_parts_nb <= 0) {
770 if (mtd_parts_nb > 0) { 764 mtd_parts = pdata->parts;
771 ret = add_mtd_partitions(&info->mtd, 765 mtd_parts_nb = pdata->nr_parts;
772 mtd_parts, mtd_parts_nb); 766 }
773 if (ret == 0)
774 info->partitioned = true;
775 }
776 767
777 } else if (pdata->nr_parts) { 768 /* Register any partitions */
778 dev_warn(&pdev->dev, "ignoring %d default partitions on %s\n", 769 if (mtd_parts_nb > 0) {
779 pdata->nr_parts, info->mtd.name); 770 ret = mtd_device_register(&info->mtd, mtd_parts,
771 mtd_parts_nb);
772 if (ret == 0)
773 info->partitioned = true;
780 } 774 }
781 775
782 /* If there's no partition info, just package the whole chip 776 /* If there's no partition info, just package the whole chip
783 * as a single MTD device. 777 * as a single MTD device.
784 */ 778 */
785 if (!info->partitioned) 779 if (!info->partitioned)
786 ret = add_mtd_device(&info->mtd) ? -ENODEV : 0; 780 ret = mtd_device_register(&info->mtd, NULL, 0) ? -ENODEV : 0;
787 781
788 if (ret < 0) 782 if (ret < 0)
789 goto err_scan; 783 goto err_scan;
@@ -824,10 +818,7 @@ static int __exit nand_davinci_remove(struct platform_device *pdev)
824 struct davinci_nand_info *info = platform_get_drvdata(pdev); 818 struct davinci_nand_info *info = platform_get_drvdata(pdev);
825 int status; 819 int status;
826 820
827 if (mtd_has_partitions() && info->partitioned) 821 status = mtd_device_unregister(&info->mtd);
828 status = del_mtd_partitions(&info->mtd);
829 else
830 status = del_mtd_device(&info->mtd);
831 822
832 spin_lock_irq(&davinci_nand_lock); 823 spin_lock_irq(&davinci_nand_lock);
833 if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME) 824 if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME)
diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 4633f094c510..d5276218945f 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -19,6 +19,7 @@
19 19
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22#include <linux/dma-mapping.h>
22#include <linux/wait.h> 23#include <linux/wait.h>
23#include <linux/mutex.h> 24#include <linux/mutex.h>
24#include <linux/slab.h> 25#include <linux/slab.h>
@@ -44,16 +45,16 @@ MODULE_PARM_DESC(onfi_timing_mode, "Overrides default ONFI setting."
44 45
45/* We define a macro here that combines all interrupts this driver uses into 46/* We define a macro here that combines all interrupts this driver uses into
46 * a single constant value, for convenience. */ 47 * a single constant value, for convenience. */
47#define DENALI_IRQ_ALL (INTR_STATUS0__DMA_CMD_COMP | \ 48#define DENALI_IRQ_ALL (INTR_STATUS__DMA_CMD_COMP | \
48 INTR_STATUS0__ECC_TRANSACTION_DONE | \ 49 INTR_STATUS__ECC_TRANSACTION_DONE | \
49 INTR_STATUS0__ECC_ERR | \ 50 INTR_STATUS__ECC_ERR | \
50 INTR_STATUS0__PROGRAM_FAIL | \ 51 INTR_STATUS__PROGRAM_FAIL | \
51 INTR_STATUS0__LOAD_COMP | \ 52 INTR_STATUS__LOAD_COMP | \
52 INTR_STATUS0__PROGRAM_COMP | \ 53 INTR_STATUS__PROGRAM_COMP | \
53 INTR_STATUS0__TIME_OUT | \ 54 INTR_STATUS__TIME_OUT | \
54 INTR_STATUS0__ERASE_FAIL | \ 55 INTR_STATUS__ERASE_FAIL | \
55 INTR_STATUS0__RST_COMP | \ 56 INTR_STATUS__RST_COMP | \
56 INTR_STATUS0__ERASE_COMP) 57 INTR_STATUS__ERASE_COMP)
57 58
58/* indicates whether or not the internal value for the flash bank is 59/* indicates whether or not the internal value for the flash bank is
59 * valid or not */ 60 * valid or not */
@@ -95,30 +96,6 @@ static const struct pci_device_id denali_pci_ids[] = {
95 { /* end: all zeroes */ } 96 { /* end: all zeroes */ }
96}; 97};
97 98
98
99/* these are static lookup tables that give us easy access to
100 * registers in the NAND controller.
101 */
102static const uint32_t intr_status_addresses[4] = {INTR_STATUS0,
103 INTR_STATUS1,
104 INTR_STATUS2,
105 INTR_STATUS3};
106
107static const uint32_t device_reset_banks[4] = {DEVICE_RESET__BANK0,
108 DEVICE_RESET__BANK1,
109 DEVICE_RESET__BANK2,
110 DEVICE_RESET__BANK3};
111
112static const uint32_t operation_timeout[4] = {INTR_STATUS0__TIME_OUT,
113 INTR_STATUS1__TIME_OUT,
114 INTR_STATUS2__TIME_OUT,
115 INTR_STATUS3__TIME_OUT};
116
117static const uint32_t reset_complete[4] = {INTR_STATUS0__RST_COMP,
118 INTR_STATUS1__RST_COMP,
119 INTR_STATUS2__RST_COMP,
120 INTR_STATUS3__RST_COMP};
121
122/* forward declarations */ 99/* forward declarations */
123static void clear_interrupts(struct denali_nand_info *denali); 100static void clear_interrupts(struct denali_nand_info *denali);
124static uint32_t wait_for_irq(struct denali_nand_info *denali, 101static uint32_t wait_for_irq(struct denali_nand_info *denali,
@@ -180,19 +157,17 @@ static void read_status(struct denali_nand_info *denali)
180static void reset_bank(struct denali_nand_info *denali) 157static void reset_bank(struct denali_nand_info *denali)
181{ 158{
182 uint32_t irq_status = 0; 159 uint32_t irq_status = 0;
183 uint32_t irq_mask = reset_complete[denali->flash_bank] | 160 uint32_t irq_mask = INTR_STATUS__RST_COMP |
184 operation_timeout[denali->flash_bank]; 161 INTR_STATUS__TIME_OUT;
185 int bank = 0;
186 162
187 clear_interrupts(denali); 163 clear_interrupts(denali);
188 164
189 bank = device_reset_banks[denali->flash_bank]; 165 iowrite32(1 << denali->flash_bank, denali->flash_reg + DEVICE_RESET);
190 iowrite32(bank, denali->flash_reg + DEVICE_RESET);
191 166
192 irq_status = wait_for_irq(denali, irq_mask); 167 irq_status = wait_for_irq(denali, irq_mask);
193 168
194 if (irq_status & operation_timeout[denali->flash_bank]) 169 if (irq_status & INTR_STATUS__TIME_OUT)
195 dev_err(&denali->dev->dev, "reset bank failed.\n"); 170 dev_err(denali->dev, "reset bank failed.\n");
196} 171}
197 172
198/* Reset the flash controller */ 173/* Reset the flash controller */
@@ -200,29 +175,28 @@ static uint16_t denali_nand_reset(struct denali_nand_info *denali)
200{ 175{
201 uint32_t i; 176 uint32_t i;
202 177
203 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n", 178 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
204 __FILE__, __LINE__, __func__); 179 __FILE__, __LINE__, __func__);
205 180
206 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) 181 for (i = 0 ; i < denali->max_banks; i++)
207 iowrite32(reset_complete[i] | operation_timeout[i], 182 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
208 denali->flash_reg + intr_status_addresses[i]); 183 denali->flash_reg + INTR_STATUS(i));
209 184
210 for (i = 0 ; i < LLD_MAX_FLASH_BANKS; i++) { 185 for (i = 0 ; i < denali->max_banks; i++) {
211 iowrite32(device_reset_banks[i], 186 iowrite32(1 << i, denali->flash_reg + DEVICE_RESET);
212 denali->flash_reg + DEVICE_RESET);
213 while (!(ioread32(denali->flash_reg + 187 while (!(ioread32(denali->flash_reg +
214 intr_status_addresses[i]) & 188 INTR_STATUS(i)) &
215 (reset_complete[i] | operation_timeout[i]))) 189 (INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT)))
216 cpu_relax(); 190 cpu_relax();
217 if (ioread32(denali->flash_reg + intr_status_addresses[i]) & 191 if (ioread32(denali->flash_reg + INTR_STATUS(i)) &
218 operation_timeout[i]) 192 INTR_STATUS__TIME_OUT)
219 dev_dbg(&denali->dev->dev, 193 dev_dbg(denali->dev,
220 "NAND Reset operation timed out on bank %d\n", i); 194 "NAND Reset operation timed out on bank %d\n", i);
221 } 195 }
222 196
223 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) 197 for (i = 0; i < denali->max_banks; i++)
224 iowrite32(reset_complete[i] | operation_timeout[i], 198 iowrite32(INTR_STATUS__RST_COMP | INTR_STATUS__TIME_OUT,
225 denali->flash_reg + intr_status_addresses[i]); 199 denali->flash_reg + INTR_STATUS(i));
226 200
227 return PASS; 201 return PASS;
228} 202}
@@ -254,7 +228,7 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali,
254 uint16_t acc_clks; 228 uint16_t acc_clks;
255 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt; 229 uint16_t addr_2_data, re_2_we, re_2_re, we_2_re, cs_cnt;
256 230
257 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n", 231 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
258 __FILE__, __LINE__, __func__); 232 __FILE__, __LINE__, __func__);
259 233
260 en_lo = CEIL_DIV(Trp[mode], CLK_X); 234 en_lo = CEIL_DIV(Trp[mode], CLK_X);
@@ -291,7 +265,7 @@ static void nand_onfi_timing_set(struct denali_nand_info *denali,
291 acc_clks++; 265 acc_clks++;
292 266
293 if ((data_invalid - acc_clks * CLK_X) < 2) 267 if ((data_invalid - acc_clks * CLK_X) < 2)
294 dev_warn(&denali->dev->dev, "%s, Line %d: Warning!\n", 268 dev_warn(denali->dev, "%s, Line %d: Warning!\n",
295 __FILE__, __LINE__); 269 __FILE__, __LINE__);
296 270
297 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X); 271 addr_2_data = CEIL_DIV(Tadl[mode], CLK_X);
@@ -419,7 +393,7 @@ static void get_hynix_nand_para(struct denali_nand_info *denali,
419#endif 393#endif
420 break; 394 break;
421 default: 395 default:
422 dev_warn(&denali->dev->dev, 396 dev_warn(denali->dev,
423 "Spectra: Unknown Hynix NAND (Device ID: 0x%x)." 397 "Spectra: Unknown Hynix NAND (Device ID: 0x%x)."
424 "Will use default parameter values instead.\n", 398 "Will use default parameter values instead.\n",
425 device_id); 399 device_id);
@@ -431,17 +405,17 @@ static void get_hynix_nand_para(struct denali_nand_info *denali,
431 */ 405 */
432static void find_valid_banks(struct denali_nand_info *denali) 406static void find_valid_banks(struct denali_nand_info *denali)
433{ 407{
434 uint32_t id[LLD_MAX_FLASH_BANKS]; 408 uint32_t id[denali->max_banks];
435 int i; 409 int i;
436 410
437 denali->total_used_banks = 1; 411 denali->total_used_banks = 1;
438 for (i = 0; i < LLD_MAX_FLASH_BANKS; i++) { 412 for (i = 0; i < denali->max_banks; i++) {
439 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90); 413 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 0), 0x90);
440 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0); 414 index_addr(denali, (uint32_t)(MODE_11 | (i << 24) | 1), 0);
441 index_addr_read_data(denali, 415 index_addr_read_data(denali,
442 (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]); 416 (uint32_t)(MODE_11 | (i << 24) | 2), &id[i]);
443 417
444 dev_dbg(&denali->dev->dev, 418 dev_dbg(denali->dev,
445 "Return 1st ID for bank[%d]: %x\n", i, id[i]); 419 "Return 1st ID for bank[%d]: %x\n", i, id[i]);
446 420
447 if (i == 0) { 421 if (i == 0) {
@@ -461,16 +435,27 @@ static void find_valid_banks(struct denali_nand_info *denali)
461 * Multichip support is not enabled. 435 * Multichip support is not enabled.
462 */ 436 */
463 if (denali->total_used_banks != 1) { 437 if (denali->total_used_banks != 1) {
464 dev_err(&denali->dev->dev, 438 dev_err(denali->dev,
465 "Sorry, Intel CE4100 only supports " 439 "Sorry, Intel CE4100 only supports "
466 "a single NAND device.\n"); 440 "a single NAND device.\n");
467 BUG(); 441 BUG();
468 } 442 }
469 } 443 }
470 dev_dbg(&denali->dev->dev, 444 dev_dbg(denali->dev,
471 "denali->total_used_banks: %d\n", denali->total_used_banks); 445 "denali->total_used_banks: %d\n", denali->total_used_banks);
472} 446}
473 447
448/*
449 * Use the configuration feature register to determine the maximum number of
450 * banks that the hardware supports.
451 */
452static void detect_max_banks(struct denali_nand_info *denali)
453{
454 uint32_t features = ioread32(denali->flash_reg + FEATURES);
455
456 denali->max_banks = 2 << (features & FEATURES__N_BANKS);
457}
458
474static void detect_partition_feature(struct denali_nand_info *denali) 459static void detect_partition_feature(struct denali_nand_info *denali)
475{ 460{
476 /* For MRST platform, denali->fwblks represent the 461 /* For MRST platform, denali->fwblks represent the
@@ -480,15 +465,15 @@ static void detect_partition_feature(struct denali_nand_info *denali)
480 * blocks it can't touch. 465 * blocks it can't touch.
481 * */ 466 * */
482 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) { 467 if (ioread32(denali->flash_reg + FEATURES) & FEATURES__PARTITION) {
483 if ((ioread32(denali->flash_reg + PERM_SRC_ID_1) & 468 if ((ioread32(denali->flash_reg + PERM_SRC_ID(1)) &
484 PERM_SRC_ID_1__SRCID) == SPECTRA_PARTITION_ID) { 469 PERM_SRC_ID__SRCID) == SPECTRA_PARTITION_ID) {
485 denali->fwblks = 470 denali->fwblks =
486 ((ioread32(denali->flash_reg + MIN_MAX_BANK_1) & 471 ((ioread32(denali->flash_reg + MIN_MAX_BANK(1)) &
487 MIN_MAX_BANK_1__MIN_VALUE) * 472 MIN_MAX_BANK__MIN_VALUE) *
488 denali->blksperchip) 473 denali->blksperchip)
489 + 474 +
490 (ioread32(denali->flash_reg + MIN_BLK_ADDR_1) & 475 (ioread32(denali->flash_reg + MIN_BLK_ADDR(1)) &
491 MIN_BLK_ADDR_1__VALUE); 476 MIN_BLK_ADDR__VALUE);
492 } else 477 } else
493 denali->fwblks = SPECTRA_START_BLOCK; 478 denali->fwblks = SPECTRA_START_BLOCK;
494 } else 479 } else
@@ -501,7 +486,7 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
501 uint32_t id_bytes[5], addr; 486 uint32_t id_bytes[5], addr;
502 uint8_t i, maf_id, device_id; 487 uint8_t i, maf_id, device_id;
503 488
504 dev_dbg(&denali->dev->dev, 489 dev_dbg(denali->dev,
505 "%s, Line %d, Function: %s\n", 490 "%s, Line %d, Function: %s\n",
506 __FILE__, __LINE__, __func__); 491 __FILE__, __LINE__, __func__);
507 492
@@ -530,7 +515,7 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
530 get_hynix_nand_para(denali, device_id); 515 get_hynix_nand_para(denali, device_id);
531 } 516 }
532 517
533 dev_info(&denali->dev->dev, 518 dev_info(denali->dev,
534 "Dump timing register values:" 519 "Dump timing register values:"
535 "acc_clks: %d, re_2_we: %d, re_2_re: %d\n" 520 "acc_clks: %d, re_2_we: %d, re_2_re: %d\n"
536 "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n" 521 "we_2_re: %d, addr_2_data: %d, rdwr_en_lo_cnt: %d\n"
@@ -560,7 +545,7 @@ static uint16_t denali_nand_timing_set(struct denali_nand_info *denali)
560static void denali_set_intr_modes(struct denali_nand_info *denali, 545static void denali_set_intr_modes(struct denali_nand_info *denali,
561 uint16_t INT_ENABLE) 546 uint16_t INT_ENABLE)
562{ 547{
563 dev_dbg(&denali->dev->dev, "%s, Line %d, Function: %s\n", 548 dev_dbg(denali->dev, "%s, Line %d, Function: %s\n",
564 __FILE__, __LINE__, __func__); 549 __FILE__, __LINE__, __func__);
565 550
566 if (INT_ENABLE) 551 if (INT_ENABLE)
@@ -580,6 +565,7 @@ static inline bool is_flash_bank_valid(int flash_bank)
580static void denali_irq_init(struct denali_nand_info *denali) 565static void denali_irq_init(struct denali_nand_info *denali)
581{ 566{
582 uint32_t int_mask = 0; 567 uint32_t int_mask = 0;
568 int i;
583 569
584 /* Disable global interrupts */ 570 /* Disable global interrupts */
585 denali_set_intr_modes(denali, false); 571 denali_set_intr_modes(denali, false);
@@ -587,10 +573,8 @@ static void denali_irq_init(struct denali_nand_info *denali)
587 int_mask = DENALI_IRQ_ALL; 573 int_mask = DENALI_IRQ_ALL;
588 574
589 /* Clear all status bits */ 575 /* Clear all status bits */
590 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS0); 576 for (i = 0; i < denali->max_banks; ++i)
591 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS1); 577 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS(i));
592 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS2);
593 iowrite32(0xFFFF, denali->flash_reg + INTR_STATUS3);
594 578
595 denali_irq_enable(denali, int_mask); 579 denali_irq_enable(denali, int_mask);
596} 580}
@@ -604,10 +588,10 @@ static void denali_irq_cleanup(int irqnum, struct denali_nand_info *denali)
604static void denali_irq_enable(struct denali_nand_info *denali, 588static void denali_irq_enable(struct denali_nand_info *denali,
605 uint32_t int_mask) 589 uint32_t int_mask)
606{ 590{
607 iowrite32(int_mask, denali->flash_reg + INTR_EN0); 591 int i;
608 iowrite32(int_mask, denali->flash_reg + INTR_EN1); 592
609 iowrite32(int_mask, denali->flash_reg + INTR_EN2); 593 for (i = 0; i < denali->max_banks; ++i)
610 iowrite32(int_mask, denali->flash_reg + INTR_EN3); 594 iowrite32(int_mask, denali->flash_reg + INTR_EN(i));
611} 595}
612 596
613/* This function only returns when an interrupt that this driver cares about 597/* This function only returns when an interrupt that this driver cares about
@@ -624,7 +608,7 @@ static inline void clear_interrupt(struct denali_nand_info *denali,
624{ 608{
625 uint32_t intr_status_reg = 0; 609 uint32_t intr_status_reg = 0;
626 610
627 intr_status_reg = intr_status_addresses[denali->flash_bank]; 611 intr_status_reg = INTR_STATUS(denali->flash_bank);
628 612
629 iowrite32(irq_mask, denali->flash_reg + intr_status_reg); 613 iowrite32(irq_mask, denali->flash_reg + intr_status_reg);
630} 614}
@@ -645,7 +629,7 @@ static uint32_t read_interrupt_status(struct denali_nand_info *denali)
645{ 629{
646 uint32_t intr_status_reg = 0; 630 uint32_t intr_status_reg = 0;
647 631
648 intr_status_reg = intr_status_addresses[denali->flash_bank]; 632 intr_status_reg = INTR_STATUS(denali->flash_bank);
649 633
650 return ioread32(denali->flash_reg + intr_status_reg); 634 return ioread32(denali->flash_reg + intr_status_reg);
651} 635}
@@ -754,7 +738,7 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
754 irq_mask = 0; 738 irq_mask = 0;
755 739
756 if (op == DENALI_READ) 740 if (op == DENALI_READ)
757 irq_mask = INTR_STATUS0__LOAD_COMP; 741 irq_mask = INTR_STATUS__LOAD_COMP;
758 else if (op == DENALI_WRITE) 742 else if (op == DENALI_WRITE)
759 irq_mask = 0; 743 irq_mask = 0;
760 else 744 else
@@ -800,7 +784,7 @@ static int denali_send_pipeline_cmd(struct denali_nand_info *denali,
800 irq_status = wait_for_irq(denali, irq_mask); 784 irq_status = wait_for_irq(denali, irq_mask);
801 785
802 if (irq_status == 0) { 786 if (irq_status == 0) {
803 dev_err(&denali->dev->dev, 787 dev_err(denali->dev,
804 "cmd, page, addr on timeout " 788 "cmd, page, addr on timeout "
805 "(0x%x, 0x%x, 0x%x)\n", 789 "(0x%x, 0x%x, 0x%x)\n",
806 cmd, denali->page, addr); 790 cmd, denali->page, addr);
@@ -861,8 +845,8 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
861{ 845{
862 struct denali_nand_info *denali = mtd_to_denali(mtd); 846 struct denali_nand_info *denali = mtd_to_denali(mtd);
863 uint32_t irq_status = 0; 847 uint32_t irq_status = 0;
864 uint32_t irq_mask = INTR_STATUS0__PROGRAM_COMP | 848 uint32_t irq_mask = INTR_STATUS__PROGRAM_COMP |
865 INTR_STATUS0__PROGRAM_FAIL; 849 INTR_STATUS__PROGRAM_FAIL;
866 int status = 0; 850 int status = 0;
867 851
868 denali->page = page; 852 denali->page = page;
@@ -875,11 +859,11 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
875 irq_status = wait_for_irq(denali, irq_mask); 859 irq_status = wait_for_irq(denali, irq_mask);
876 860
877 if (irq_status == 0) { 861 if (irq_status == 0) {
878 dev_err(&denali->dev->dev, "OOB write failed\n"); 862 dev_err(denali->dev, "OOB write failed\n");
879 status = -EIO; 863 status = -EIO;
880 } 864 }
881 } else { 865 } else {
882 dev_err(&denali->dev->dev, "unable to send pipeline command\n"); 866 dev_err(denali->dev, "unable to send pipeline command\n");
883 status = -EIO; 867 status = -EIO;
884 } 868 }
885 return status; 869 return status;
@@ -889,7 +873,7 @@ static int write_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
889static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page) 873static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
890{ 874{
891 struct denali_nand_info *denali = mtd_to_denali(mtd); 875 struct denali_nand_info *denali = mtd_to_denali(mtd);
892 uint32_t irq_mask = INTR_STATUS0__LOAD_COMP, 876 uint32_t irq_mask = INTR_STATUS__LOAD_COMP,
893 irq_status = 0, addr = 0x0, cmd = 0x0; 877 irq_status = 0, addr = 0x0, cmd = 0x0;
894 878
895 denali->page = page; 879 denali->page = page;
@@ -904,7 +888,7 @@ static void read_oob_data(struct mtd_info *mtd, uint8_t *buf, int page)
904 irq_status = wait_for_irq(denali, irq_mask); 888 irq_status = wait_for_irq(denali, irq_mask);
905 889
906 if (irq_status == 0) 890 if (irq_status == 0)
907 dev_err(&denali->dev->dev, "page on OOB timeout %d\n", 891 dev_err(denali->dev, "page on OOB timeout %d\n",
908 denali->page); 892 denali->page);
909 893
910 /* We set the device back to MAIN_ACCESS here as I observed 894 /* We set the device back to MAIN_ACCESS here as I observed
@@ -944,7 +928,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
944{ 928{
945 bool check_erased_page = false; 929 bool check_erased_page = false;
946 930
947 if (irq_status & INTR_STATUS0__ECC_ERR) { 931 if (irq_status & INTR_STATUS__ECC_ERR) {
948 /* read the ECC errors. we'll ignore them for now */ 932 /* read the ECC errors. we'll ignore them for now */
949 uint32_t err_address = 0, err_correction_info = 0; 933 uint32_t err_address = 0, err_correction_info = 0;
950 uint32_t err_byte = 0, err_sector = 0, err_device = 0; 934 uint32_t err_byte = 0, err_sector = 0, err_device = 0;
@@ -995,7 +979,7 @@ static bool handle_ecc(struct denali_nand_info *denali, uint8_t *buf,
995 * for a while for this interrupt 979 * for a while for this interrupt
996 * */ 980 * */
997 while (!(read_interrupt_status(denali) & 981 while (!(read_interrupt_status(denali) &
998 INTR_STATUS0__ECC_TRANSACTION_DONE)) 982 INTR_STATUS__ECC_TRANSACTION_DONE))
999 cpu_relax(); 983 cpu_relax();
1000 clear_interrupts(denali); 984 clear_interrupts(denali);
1001 denali_set_intr_modes(denali, true); 985 denali_set_intr_modes(denali, true);
@@ -1045,14 +1029,13 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1045 const uint8_t *buf, bool raw_xfer) 1029 const uint8_t *buf, bool raw_xfer)
1046{ 1030{
1047 struct denali_nand_info *denali = mtd_to_denali(mtd); 1031 struct denali_nand_info *denali = mtd_to_denali(mtd);
1048 struct pci_dev *pci_dev = denali->dev;
1049 1032
1050 dma_addr_t addr = denali->buf.dma_buf; 1033 dma_addr_t addr = denali->buf.dma_buf;
1051 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1034 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1052 1035
1053 uint32_t irq_status = 0; 1036 uint32_t irq_status = 0;
1054 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP | 1037 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP |
1055 INTR_STATUS0__PROGRAM_FAIL; 1038 INTR_STATUS__PROGRAM_FAIL;
1056 1039
1057 /* if it is a raw xfer, we want to disable ecc, and send 1040 /* if it is a raw xfer, we want to disable ecc, and send
1058 * the spare area. 1041 * the spare area.
@@ -1071,7 +1054,7 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1071 mtd->oobsize); 1054 mtd->oobsize);
1072 } 1055 }
1073 1056
1074 pci_dma_sync_single_for_device(pci_dev, addr, size, PCI_DMA_TODEVICE); 1057 dma_sync_single_for_device(denali->dev, addr, size, DMA_TO_DEVICE);
1075 1058
1076 clear_interrupts(denali); 1059 clear_interrupts(denali);
1077 denali_enable_dma(denali, true); 1060 denali_enable_dma(denali, true);
@@ -1082,16 +1065,16 @@ static void write_page(struct mtd_info *mtd, struct nand_chip *chip,
1082 irq_status = wait_for_irq(denali, irq_mask); 1065 irq_status = wait_for_irq(denali, irq_mask);
1083 1066
1084 if (irq_status == 0) { 1067 if (irq_status == 0) {
1085 dev_err(&denali->dev->dev, 1068 dev_err(denali->dev,
1086 "timeout on write_page (type = %d)\n", 1069 "timeout on write_page (type = %d)\n",
1087 raw_xfer); 1070 raw_xfer);
1088 denali->status = 1071 denali->status =
1089 (irq_status & INTR_STATUS0__PROGRAM_FAIL) ? 1072 (irq_status & INTR_STATUS__PROGRAM_FAIL) ?
1090 NAND_STATUS_FAIL : PASS; 1073 NAND_STATUS_FAIL : PASS;
1091 } 1074 }
1092 1075
1093 denali_enable_dma(denali, false); 1076 denali_enable_dma(denali, false);
1094 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_TODEVICE); 1077 dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE);
1095} 1078}
1096 1079
1097/* NAND core entry points */ 1080/* NAND core entry points */
@@ -1139,18 +1122,17 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1139 uint8_t *buf, int page) 1122 uint8_t *buf, int page)
1140{ 1123{
1141 struct denali_nand_info *denali = mtd_to_denali(mtd); 1124 struct denali_nand_info *denali = mtd_to_denali(mtd);
1142 struct pci_dev *pci_dev = denali->dev;
1143 1125
1144 dma_addr_t addr = denali->buf.dma_buf; 1126 dma_addr_t addr = denali->buf.dma_buf;
1145 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1127 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1146 1128
1147 uint32_t irq_status = 0; 1129 uint32_t irq_status = 0;
1148 uint32_t irq_mask = INTR_STATUS0__ECC_TRANSACTION_DONE | 1130 uint32_t irq_mask = INTR_STATUS__ECC_TRANSACTION_DONE |
1149 INTR_STATUS0__ECC_ERR; 1131 INTR_STATUS__ECC_ERR;
1150 bool check_erased_page = false; 1132 bool check_erased_page = false;
1151 1133
1152 if (page != denali->page) { 1134 if (page != denali->page) {
1153 dev_err(&denali->dev->dev, "IN %s: page %d is not" 1135 dev_err(denali->dev, "IN %s: page %d is not"
1154 " equal to denali->page %d, investigate!!", 1136 " equal to denali->page %d, investigate!!",
1155 __func__, page, denali->page); 1137 __func__, page, denali->page);
1156 BUG(); 1138 BUG();
@@ -1159,7 +1141,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1159 setup_ecc_for_xfer(denali, true, false); 1141 setup_ecc_for_xfer(denali, true, false);
1160 1142
1161 denali_enable_dma(denali, true); 1143 denali_enable_dma(denali, true);
1162 pci_dma_sync_single_for_device(pci_dev, addr, size, PCI_DMA_FROMDEVICE); 1144 dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
1163 1145
1164 clear_interrupts(denali); 1146 clear_interrupts(denali);
1165 denali_setup_dma(denali, DENALI_READ); 1147 denali_setup_dma(denali, DENALI_READ);
@@ -1167,7 +1149,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
1167 /* wait for operation to complete */ 1149 /* wait for operation to complete */
1168 irq_status = wait_for_irq(denali, irq_mask); 1150 irq_status = wait_for_irq(denali, irq_mask);
1169 1151
1170 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_FROMDEVICE); 1152 dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
1171 1153
1172 memcpy(buf, denali->buf.buf, mtd->writesize); 1154 memcpy(buf, denali->buf.buf, mtd->writesize);
1173 1155
@@ -1192,16 +1174,15 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1192 uint8_t *buf, int page) 1174 uint8_t *buf, int page)
1193{ 1175{
1194 struct denali_nand_info *denali = mtd_to_denali(mtd); 1176 struct denali_nand_info *denali = mtd_to_denali(mtd);
1195 struct pci_dev *pci_dev = denali->dev;
1196 1177
1197 dma_addr_t addr = denali->buf.dma_buf; 1178 dma_addr_t addr = denali->buf.dma_buf;
1198 size_t size = denali->mtd.writesize + denali->mtd.oobsize; 1179 size_t size = denali->mtd.writesize + denali->mtd.oobsize;
1199 1180
1200 uint32_t irq_status = 0; 1181 uint32_t irq_status = 0;
1201 uint32_t irq_mask = INTR_STATUS0__DMA_CMD_COMP; 1182 uint32_t irq_mask = INTR_STATUS__DMA_CMD_COMP;
1202 1183
1203 if (page != denali->page) { 1184 if (page != denali->page) {
1204 dev_err(&denali->dev->dev, "IN %s: page %d is not" 1185 dev_err(denali->dev, "IN %s: page %d is not"
1205 " equal to denali->page %d, investigate!!", 1186 " equal to denali->page %d, investigate!!",
1206 __func__, page, denali->page); 1187 __func__, page, denali->page);
1207 BUG(); 1188 BUG();
@@ -1210,7 +1191,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1210 setup_ecc_for_xfer(denali, false, true); 1191 setup_ecc_for_xfer(denali, false, true);
1211 denali_enable_dma(denali, true); 1192 denali_enable_dma(denali, true);
1212 1193
1213 pci_dma_sync_single_for_device(pci_dev, addr, size, PCI_DMA_FROMDEVICE); 1194 dma_sync_single_for_device(denali->dev, addr, size, DMA_FROM_DEVICE);
1214 1195
1215 clear_interrupts(denali); 1196 clear_interrupts(denali);
1216 denali_setup_dma(denali, DENALI_READ); 1197 denali_setup_dma(denali, DENALI_READ);
@@ -1218,7 +1199,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1218 /* wait for operation to complete */ 1199 /* wait for operation to complete */
1219 irq_status = wait_for_irq(denali, irq_mask); 1200 irq_status = wait_for_irq(denali, irq_mask);
1220 1201
1221 pci_dma_sync_single_for_cpu(pci_dev, addr, size, PCI_DMA_FROMDEVICE); 1202 dma_sync_single_for_cpu(denali->dev, addr, size, DMA_FROM_DEVICE);
1222 1203
1223 denali_enable_dma(denali, false); 1204 denali_enable_dma(denali, false);
1224 1205
@@ -1271,10 +1252,10 @@ static void denali_erase(struct mtd_info *mtd, int page)
1271 index_addr(denali, (uint32_t)cmd, 0x1); 1252 index_addr(denali, (uint32_t)cmd, 0x1);
1272 1253
1273 /* wait for erase to complete or failure to occur */ 1254 /* wait for erase to complete or failure to occur */
1274 irq_status = wait_for_irq(denali, INTR_STATUS0__ERASE_COMP | 1255 irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP |
1275 INTR_STATUS0__ERASE_FAIL); 1256 INTR_STATUS__ERASE_FAIL);
1276 1257
1277 denali->status = (irq_status & INTR_STATUS0__ERASE_FAIL) ? 1258 denali->status = (irq_status & INTR_STATUS__ERASE_FAIL) ?
1278 NAND_STATUS_FAIL : PASS; 1259 NAND_STATUS_FAIL : PASS;
1279} 1260}
1280 1261
@@ -1330,7 +1311,7 @@ static int denali_ecc_calculate(struct mtd_info *mtd, const uint8_t *data,
1330 uint8_t *ecc_code) 1311 uint8_t *ecc_code)
1331{ 1312{
1332 struct denali_nand_info *denali = mtd_to_denali(mtd); 1313 struct denali_nand_info *denali = mtd_to_denali(mtd);
1333 dev_err(&denali->dev->dev, 1314 dev_err(denali->dev,
1334 "denali_ecc_calculate called unexpectedly\n"); 1315 "denali_ecc_calculate called unexpectedly\n");
1335 BUG(); 1316 BUG();
1336 return -EIO; 1317 return -EIO;
@@ -1340,7 +1321,7 @@ static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data,
1340 uint8_t *read_ecc, uint8_t *calc_ecc) 1321 uint8_t *read_ecc, uint8_t *calc_ecc)
1341{ 1322{
1342 struct denali_nand_info *denali = mtd_to_denali(mtd); 1323 struct denali_nand_info *denali = mtd_to_denali(mtd);
1343 dev_err(&denali->dev->dev, 1324 dev_err(denali->dev,
1344 "denali_ecc_correct called unexpectedly\n"); 1325 "denali_ecc_correct called unexpectedly\n");
1345 BUG(); 1326 BUG();
1346 return -EIO; 1327 return -EIO;
@@ -1349,7 +1330,7 @@ static int denali_ecc_correct(struct mtd_info *mtd, uint8_t *data,
1349static void denali_ecc_hwctl(struct mtd_info *mtd, int mode) 1330static void denali_ecc_hwctl(struct mtd_info *mtd, int mode)
1350{ 1331{
1351 struct denali_nand_info *denali = mtd_to_denali(mtd); 1332 struct denali_nand_info *denali = mtd_to_denali(mtd);
1352 dev_err(&denali->dev->dev, 1333 dev_err(denali->dev,
1353 "denali_ecc_hwctl called unexpectedly\n"); 1334 "denali_ecc_hwctl called unexpectedly\n");
1354 BUG(); 1335 BUG();
1355} 1336}
@@ -1375,6 +1356,7 @@ static void denali_hw_init(struct denali_nand_info *denali)
1375 /* Should set value for these registers when init */ 1356 /* Should set value for these registers when init */
1376 iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES); 1357 iowrite32(0, denali->flash_reg + TWO_ROW_ADDR_CYCLES);
1377 iowrite32(1, denali->flash_reg + ECC_ENABLE); 1358 iowrite32(1, denali->flash_reg + ECC_ENABLE);
1359 detect_max_banks(denali);
1378 denali_nand_timing_set(denali); 1360 denali_nand_timing_set(denali);
1379 denali_irq_init(denali); 1361 denali_irq_init(denali);
1380} 1362}
@@ -1484,24 +1466,22 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1484 } 1466 }
1485 1467
1486 /* Is 32-bit DMA supported? */ 1468 /* Is 32-bit DMA supported? */
1487 ret = pci_set_dma_mask(dev, DMA_BIT_MASK(32)); 1469 ret = dma_set_mask(&dev->dev, DMA_BIT_MASK(32));
1488
1489 if (ret) { 1470 if (ret) {
1490 printk(KERN_ERR "Spectra: no usable DMA configuration\n"); 1471 printk(KERN_ERR "Spectra: no usable DMA configuration\n");
1491 goto failed_enable_dev; 1472 goto failed_enable_dev;
1492 } 1473 }
1493 denali->buf.dma_buf = 1474 denali->buf.dma_buf = dma_map_single(&dev->dev, denali->buf.buf,
1494 pci_map_single(dev, denali->buf.buf, 1475 DENALI_BUF_SIZE,
1495 DENALI_BUF_SIZE, 1476 DMA_BIDIRECTIONAL);
1496 PCI_DMA_BIDIRECTIONAL);
1497 1477
1498 if (pci_dma_mapping_error(dev, denali->buf.dma_buf)) { 1478 if (dma_mapping_error(&dev->dev, denali->buf.dma_buf)) {
1499 dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n"); 1479 dev_err(&dev->dev, "Spectra: failed to map DMA buffer\n");
1500 goto failed_enable_dev; 1480 goto failed_enable_dev;
1501 } 1481 }
1502 1482
1503 pci_set_master(dev); 1483 pci_set_master(dev);
1504 denali->dev = dev; 1484 denali->dev = &dev->dev;
1505 denali->mtd.dev.parent = &dev->dev; 1485 denali->mtd.dev.parent = &dev->dev;
1506 1486
1507 ret = pci_request_regions(dev, DENALI_NAND_NAME); 1487 ret = pci_request_regions(dev, DENALI_NAND_NAME);
@@ -1554,7 +1534,7 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1554 /* scan for NAND devices attached to the controller 1534 /* scan for NAND devices attached to the controller
1555 * this is the first stage in a two step process to register 1535 * this is the first stage in a two step process to register
1556 * with the nand subsystem */ 1536 * with the nand subsystem */
1557 if (nand_scan_ident(&denali->mtd, LLD_MAX_FLASH_BANKS, NULL)) { 1537 if (nand_scan_ident(&denali->mtd, denali->max_banks, NULL)) {
1558 ret = -ENXIO; 1538 ret = -ENXIO;
1559 goto failed_req_irq; 1539 goto failed_req_irq;
1560 } 1540 }
@@ -1664,7 +1644,7 @@ static int denali_pci_probe(struct pci_dev *dev, const struct pci_device_id *id)
1664 goto failed_req_irq; 1644 goto failed_req_irq;
1665 } 1645 }
1666 1646
1667 ret = add_mtd_device(&denali->mtd); 1647 ret = mtd_device_register(&denali->mtd, NULL, 0);
1668 if (ret) { 1648 if (ret) {
1669 dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n", 1649 dev_err(&dev->dev, "Spectra: Failed to register MTD: %d\n",
1670 ret); 1650 ret);
@@ -1681,8 +1661,8 @@ failed_remap_reg:
1681failed_req_regions: 1661failed_req_regions:
1682 pci_release_regions(dev); 1662 pci_release_regions(dev);
1683failed_dma_map: 1663failed_dma_map:
1684 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE, 1664 dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
1685 PCI_DMA_BIDIRECTIONAL); 1665 DMA_BIDIRECTIONAL);
1686failed_enable_dev: 1666failed_enable_dev:
1687 pci_disable_device(dev); 1667 pci_disable_device(dev);
1688failed_alloc_memery: 1668failed_alloc_memery:
@@ -1696,7 +1676,7 @@ static void denali_pci_remove(struct pci_dev *dev)
1696 struct denali_nand_info *denali = pci_get_drvdata(dev); 1676 struct denali_nand_info *denali = pci_get_drvdata(dev);
1697 1677
1698 nand_release(&denali->mtd); 1678 nand_release(&denali->mtd);
1699 del_mtd_device(&denali->mtd); 1679 mtd_device_unregister(&denali->mtd);
1700 1680
1701 denali_irq_cleanup(dev->irq, denali); 1681 denali_irq_cleanup(dev->irq, denali);
1702 1682
@@ -1704,8 +1684,8 @@ static void denali_pci_remove(struct pci_dev *dev)
1704 iounmap(denali->flash_mem); 1684 iounmap(denali->flash_mem);
1705 pci_release_regions(dev); 1685 pci_release_regions(dev);
1706 pci_disable_device(dev); 1686 pci_disable_device(dev);
1707 pci_unmap_single(dev, denali->buf.dma_buf, DENALI_BUF_SIZE, 1687 dma_unmap_single(&dev->dev, denali->buf.dma_buf, DENALI_BUF_SIZE,
1708 PCI_DMA_BIDIRECTIONAL); 1688 DMA_BIDIRECTIONAL);
1709 pci_set_drvdata(dev, NULL); 1689 pci_set_drvdata(dev, NULL);
1710 kfree(denali); 1690 kfree(denali);
1711} 1691}
@@ -1721,8 +1701,7 @@ static struct pci_driver denali_pci_driver = {
1721 1701
1722static int __devinit denali_init(void) 1702static int __devinit denali_init(void)
1723{ 1703{
1724 printk(KERN_INFO "Spectra MTD driver built on %s @ %s\n", 1704 printk(KERN_INFO "Spectra MTD driver\n");
1725 __DATE__, __TIME__);
1726 return pci_register_driver(&denali_pci_driver); 1705 return pci_register_driver(&denali_pci_driver);
1727} 1706}
1728 1707
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 3918bcb1561e..fabb9d56b39e 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -211,185 +211,46 @@
211#define TRANSFER_MODE 0x400 211#define TRANSFER_MODE 0x400
212#define TRANSFER_MODE__VALUE 0x0003 212#define TRANSFER_MODE__VALUE 0x0003
213 213
214#define INTR_STATUS0 0x410 214#define INTR_STATUS(__bank) (0x410 + ((__bank) * 0x50))
215#define INTR_STATUS0__ECC_TRANSACTION_DONE 0x0001 215#define INTR_EN(__bank) (0x420 + ((__bank) * 0x50))
216#define INTR_STATUS0__ECC_ERR 0x0002 216
217#define INTR_STATUS0__DMA_CMD_COMP 0x0004 217#define INTR_STATUS__ECC_TRANSACTION_DONE 0x0001
218#define INTR_STATUS0__TIME_OUT 0x0008 218#define INTR_STATUS__ECC_ERR 0x0002
219#define INTR_STATUS0__PROGRAM_FAIL 0x0010 219#define INTR_STATUS__DMA_CMD_COMP 0x0004
220#define INTR_STATUS0__ERASE_FAIL 0x0020 220#define INTR_STATUS__TIME_OUT 0x0008
221#define INTR_STATUS0__LOAD_COMP 0x0040 221#define INTR_STATUS__PROGRAM_FAIL 0x0010
222#define INTR_STATUS0__PROGRAM_COMP 0x0080 222#define INTR_STATUS__ERASE_FAIL 0x0020
223#define INTR_STATUS0__ERASE_COMP 0x0100 223#define INTR_STATUS__LOAD_COMP 0x0040
224#define INTR_STATUS0__PIPE_CPYBCK_CMD_COMP 0x0200 224#define INTR_STATUS__PROGRAM_COMP 0x0080
225#define INTR_STATUS0__LOCKED_BLK 0x0400 225#define INTR_STATUS__ERASE_COMP 0x0100
226#define INTR_STATUS0__UNSUP_CMD 0x0800 226#define INTR_STATUS__PIPE_CPYBCK_CMD_COMP 0x0200
227#define INTR_STATUS0__INT_ACT 0x1000 227#define INTR_STATUS__LOCKED_BLK 0x0400
228#define INTR_STATUS0__RST_COMP 0x2000 228#define INTR_STATUS__UNSUP_CMD 0x0800
229#define INTR_STATUS0__PIPE_CMD_ERR 0x4000 229#define INTR_STATUS__INT_ACT 0x1000
230#define INTR_STATUS0__PAGE_XFER_INC 0x8000 230#define INTR_STATUS__RST_COMP 0x2000
231 231#define INTR_STATUS__PIPE_CMD_ERR 0x4000
232#define INTR_EN0 0x420 232#define INTR_STATUS__PAGE_XFER_INC 0x8000
233#define INTR_EN0__ECC_TRANSACTION_DONE 0x0001 233
234#define INTR_EN0__ECC_ERR 0x0002 234#define INTR_EN__ECC_TRANSACTION_DONE 0x0001
235#define INTR_EN0__DMA_CMD_COMP 0x0004 235#define INTR_EN__ECC_ERR 0x0002
236#define INTR_EN0__TIME_OUT 0x0008 236#define INTR_EN__DMA_CMD_COMP 0x0004
237#define INTR_EN0__PROGRAM_FAIL 0x0010 237#define INTR_EN__TIME_OUT 0x0008
238#define INTR_EN0__ERASE_FAIL 0x0020 238#define INTR_EN__PROGRAM_FAIL 0x0010
239#define INTR_EN0__LOAD_COMP 0x0040 239#define INTR_EN__ERASE_FAIL 0x0020
240#define INTR_EN0__PROGRAM_COMP 0x0080 240#define INTR_EN__LOAD_COMP 0x0040
241#define INTR_EN0__ERASE_COMP 0x0100 241#define INTR_EN__PROGRAM_COMP 0x0080
242#define INTR_EN0__PIPE_CPYBCK_CMD_COMP 0x0200 242#define INTR_EN__ERASE_COMP 0x0100
243#define INTR_EN0__LOCKED_BLK 0x0400 243#define INTR_EN__PIPE_CPYBCK_CMD_COMP 0x0200
244#define INTR_EN0__UNSUP_CMD 0x0800 244#define INTR_EN__LOCKED_BLK 0x0400
245#define INTR_EN0__INT_ACT 0x1000 245#define INTR_EN__UNSUP_CMD 0x0800
246#define INTR_EN0__RST_COMP 0x2000 246#define INTR_EN__INT_ACT 0x1000
247#define INTR_EN0__PIPE_CMD_ERR 0x4000 247#define INTR_EN__RST_COMP 0x2000
248#define INTR_EN0__PAGE_XFER_INC 0x8000 248#define INTR_EN__PIPE_CMD_ERR 0x4000
249 249#define INTR_EN__PAGE_XFER_INC 0x8000
250#define PAGE_CNT0 0x430 250
251#define PAGE_CNT0__VALUE 0x00ff 251#define PAGE_CNT(__bank) (0x430 + ((__bank) * 0x50))
252 252#define ERR_PAGE_ADDR(__bank) (0x440 + ((__bank) * 0x50))
253#define ERR_PAGE_ADDR0 0x440 253#define ERR_BLOCK_ADDR(__bank) (0x450 + ((__bank) * 0x50))
254#define ERR_PAGE_ADDR0__VALUE 0xffff
255
256#define ERR_BLOCK_ADDR0 0x450
257#define ERR_BLOCK_ADDR0__VALUE 0xffff
258
259#define INTR_STATUS1 0x460
260#define INTR_STATUS1__ECC_TRANSACTION_DONE 0x0001
261#define INTR_STATUS1__ECC_ERR 0x0002
262#define INTR_STATUS1__DMA_CMD_COMP 0x0004
263#define INTR_STATUS1__TIME_OUT 0x0008
264#define INTR_STATUS1__PROGRAM_FAIL 0x0010
265#define INTR_STATUS1__ERASE_FAIL 0x0020
266#define INTR_STATUS1__LOAD_COMP 0x0040
267#define INTR_STATUS1__PROGRAM_COMP 0x0080
268#define INTR_STATUS1__ERASE_COMP 0x0100
269#define INTR_STATUS1__PIPE_CPYBCK_CMD_COMP 0x0200
270#define INTR_STATUS1__LOCKED_BLK 0x0400
271#define INTR_STATUS1__UNSUP_CMD 0x0800
272#define INTR_STATUS1__INT_ACT 0x1000
273#define INTR_STATUS1__RST_COMP 0x2000
274#define INTR_STATUS1__PIPE_CMD_ERR 0x4000
275#define INTR_STATUS1__PAGE_XFER_INC 0x8000
276
277#define INTR_EN1 0x470
278#define INTR_EN1__ECC_TRANSACTION_DONE 0x0001
279#define INTR_EN1__ECC_ERR 0x0002
280#define INTR_EN1__DMA_CMD_COMP 0x0004
281#define INTR_EN1__TIME_OUT 0x0008
282#define INTR_EN1__PROGRAM_FAIL 0x0010
283#define INTR_EN1__ERASE_FAIL 0x0020
284#define INTR_EN1__LOAD_COMP 0x0040
285#define INTR_EN1__PROGRAM_COMP 0x0080
286#define INTR_EN1__ERASE_COMP 0x0100
287#define INTR_EN1__PIPE_CPYBCK_CMD_COMP 0x0200
288#define INTR_EN1__LOCKED_BLK 0x0400
289#define INTR_EN1__UNSUP_CMD 0x0800
290#define INTR_EN1__INT_ACT 0x1000
291#define INTR_EN1__RST_COMP 0x2000
292#define INTR_EN1__PIPE_CMD_ERR 0x4000
293#define INTR_EN1__PAGE_XFER_INC 0x8000
294
295#define PAGE_CNT1 0x480
296#define PAGE_CNT1__VALUE 0x00ff
297
298#define ERR_PAGE_ADDR1 0x490
299#define ERR_PAGE_ADDR1__VALUE 0xffff
300
301#define ERR_BLOCK_ADDR1 0x4a0
302#define ERR_BLOCK_ADDR1__VALUE 0xffff
303
304#define INTR_STATUS2 0x4b0
305#define INTR_STATUS2__ECC_TRANSACTION_DONE 0x0001
306#define INTR_STATUS2__ECC_ERR 0x0002
307#define INTR_STATUS2__DMA_CMD_COMP 0x0004
308#define INTR_STATUS2__TIME_OUT 0x0008
309#define INTR_STATUS2__PROGRAM_FAIL 0x0010
310#define INTR_STATUS2__ERASE_FAIL 0x0020
311#define INTR_STATUS2__LOAD_COMP 0x0040
312#define INTR_STATUS2__PROGRAM_COMP 0x0080
313#define INTR_STATUS2__ERASE_COMP 0x0100
314#define INTR_STATUS2__PIPE_CPYBCK_CMD_COMP 0x0200
315#define INTR_STATUS2__LOCKED_BLK 0x0400
316#define INTR_STATUS2__UNSUP_CMD 0x0800
317#define INTR_STATUS2__INT_ACT 0x1000
318#define INTR_STATUS2__RST_COMP 0x2000
319#define INTR_STATUS2__PIPE_CMD_ERR 0x4000
320#define INTR_STATUS2__PAGE_XFER_INC 0x8000
321
322#define INTR_EN2 0x4c0
323#define INTR_EN2__ECC_TRANSACTION_DONE 0x0001
324#define INTR_EN2__ECC_ERR 0x0002
325#define INTR_EN2__DMA_CMD_COMP 0x0004
326#define INTR_EN2__TIME_OUT 0x0008
327#define INTR_EN2__PROGRAM_FAIL 0x0010
328#define INTR_EN2__ERASE_FAIL 0x0020
329#define INTR_EN2__LOAD_COMP 0x0040
330#define INTR_EN2__PROGRAM_COMP 0x0080
331#define INTR_EN2__ERASE_COMP 0x0100
332#define INTR_EN2__PIPE_CPYBCK_CMD_COMP 0x0200
333#define INTR_EN2__LOCKED_BLK 0x0400
334#define INTR_EN2__UNSUP_CMD 0x0800
335#define INTR_EN2__INT_ACT 0x1000
336#define INTR_EN2__RST_COMP 0x2000
337#define INTR_EN2__PIPE_CMD_ERR 0x4000
338#define INTR_EN2__PAGE_XFER_INC 0x8000
339
340#define PAGE_CNT2 0x4d0
341#define PAGE_CNT2__VALUE 0x00ff
342
343#define ERR_PAGE_ADDR2 0x4e0
344#define ERR_PAGE_ADDR2__VALUE 0xffff
345
346#define ERR_BLOCK_ADDR2 0x4f0
347#define ERR_BLOCK_ADDR2__VALUE 0xffff
348
349#define INTR_STATUS3 0x500
350#define INTR_STATUS3__ECC_TRANSACTION_DONE 0x0001
351#define INTR_STATUS3__ECC_ERR 0x0002
352#define INTR_STATUS3__DMA_CMD_COMP 0x0004
353#define INTR_STATUS3__TIME_OUT 0x0008
354#define INTR_STATUS3__PROGRAM_FAIL 0x0010
355#define INTR_STATUS3__ERASE_FAIL 0x0020
356#define INTR_STATUS3__LOAD_COMP 0x0040
357#define INTR_STATUS3__PROGRAM_COMP 0x0080
358#define INTR_STATUS3__ERASE_COMP 0x0100
359#define INTR_STATUS3__PIPE_CPYBCK_CMD_COMP 0x0200
360#define INTR_STATUS3__LOCKED_BLK 0x0400
361#define INTR_STATUS3__UNSUP_CMD 0x0800
362#define INTR_STATUS3__INT_ACT 0x1000
363#define INTR_STATUS3__RST_COMP 0x2000
364#define INTR_STATUS3__PIPE_CMD_ERR 0x4000
365#define INTR_STATUS3__PAGE_XFER_INC 0x8000
366
367#define INTR_EN3 0x510
368#define INTR_EN3__ECC_TRANSACTION_DONE 0x0001
369#define INTR_EN3__ECC_ERR 0x0002
370#define INTR_EN3__DMA_CMD_COMP 0x0004
371#define INTR_EN3__TIME_OUT 0x0008
372#define INTR_EN3__PROGRAM_FAIL 0x0010
373#define INTR_EN3__ERASE_FAIL 0x0020
374#define INTR_EN3__LOAD_COMP 0x0040
375#define INTR_EN3__PROGRAM_COMP 0x0080
376#define INTR_EN3__ERASE_COMP 0x0100
377#define INTR_EN3__PIPE_CPYBCK_CMD_COMP 0x0200
378#define INTR_EN3__LOCKED_BLK 0x0400
379#define INTR_EN3__UNSUP_CMD 0x0800
380#define INTR_EN3__INT_ACT 0x1000
381#define INTR_EN3__RST_COMP 0x2000
382#define INTR_EN3__PIPE_CMD_ERR 0x4000
383#define INTR_EN3__PAGE_XFER_INC 0x8000
384
385#define PAGE_CNT3 0x520
386#define PAGE_CNT3__VALUE 0x00ff
387
388#define ERR_PAGE_ADDR3 0x530
389#define ERR_PAGE_ADDR3__VALUE 0xffff
390
391#define ERR_BLOCK_ADDR3 0x540
392#define ERR_BLOCK_ADDR3__VALUE 0xffff
393 254
394#define DATA_INTR 0x550 255#define DATA_INTR 0x550
395#define DATA_INTR__WRITE_SPACE_AV 0x0001 256#define DATA_INTR__WRITE_SPACE_AV 0x0001
@@ -484,141 +345,23 @@
484#define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010 345#define PTN_INTR_EN__ACCESS_ERROR_BANK3 0x0010
485#define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020 346#define PTN_INTR_EN__REG_ACCESS_ERROR 0x0020
486 347
487#define PERM_SRC_ID_0 0x830 348#define PERM_SRC_ID(__bank) (0x830 + ((__bank) * 0x40))
488#define PERM_SRC_ID_0__SRCID 0x00ff 349#define PERM_SRC_ID__SRCID 0x00ff
489#define PERM_SRC_ID_0__DIRECT_ACCESS_ACTIVE 0x0800 350#define PERM_SRC_ID__DIRECT_ACCESS_ACTIVE 0x0800
490#define PERM_SRC_ID_0__WRITE_ACTIVE 0x2000 351#define PERM_SRC_ID__WRITE_ACTIVE 0x2000
491#define PERM_SRC_ID_0__READ_ACTIVE 0x4000 352#define PERM_SRC_ID__READ_ACTIVE 0x4000
492#define PERM_SRC_ID_0__PARTITION_VALID 0x8000 353#define PERM_SRC_ID__PARTITION_VALID 0x8000
493 354
494#define MIN_BLK_ADDR_0 0x840 355#define MIN_BLK_ADDR(__bank) (0x840 + ((__bank) * 0x40))
495#define MIN_BLK_ADDR_0__VALUE 0xffff 356#define MIN_BLK_ADDR__VALUE 0xffff
496 357
497#define MAX_BLK_ADDR_0 0x850 358#define MAX_BLK_ADDR(__bank) (0x850 + ((__bank) * 0x40))
498#define MAX_BLK_ADDR_0__VALUE 0xffff 359#define MAX_BLK_ADDR__VALUE 0xffff
499 360
500#define MIN_MAX_BANK_0 0x860 361#define MIN_MAX_BANK(__bank) (0x860 + ((__bank) * 0x40))
501#define MIN_MAX_BANK_0__MIN_VALUE 0x0003 362#define MIN_MAX_BANK__MIN_VALUE 0x0003
502#define MIN_MAX_BANK_0__MAX_VALUE 0x000c 363#define MIN_MAX_BANK__MAX_VALUE 0x000c
503
504#define PERM_SRC_ID_1 0x870
505#define PERM_SRC_ID_1__SRCID 0x00ff
506#define PERM_SRC_ID_1__DIRECT_ACCESS_ACTIVE 0x0800
507#define PERM_SRC_ID_1__WRITE_ACTIVE 0x2000
508#define PERM_SRC_ID_1__READ_ACTIVE 0x4000
509#define PERM_SRC_ID_1__PARTITION_VALID 0x8000
510
511#define MIN_BLK_ADDR_1 0x880
512#define MIN_BLK_ADDR_1__VALUE 0xffff
513
514#define MAX_BLK_ADDR_1 0x890
515#define MAX_BLK_ADDR_1__VALUE 0xffff
516
517#define MIN_MAX_BANK_1 0x8a0
518#define MIN_MAX_BANK_1__MIN_VALUE 0x0003
519#define MIN_MAX_BANK_1__MAX_VALUE 0x000c
520
521#define PERM_SRC_ID_2 0x8b0
522#define PERM_SRC_ID_2__SRCID 0x00ff
523#define PERM_SRC_ID_2__DIRECT_ACCESS_ACTIVE 0x0800
524#define PERM_SRC_ID_2__WRITE_ACTIVE 0x2000
525#define PERM_SRC_ID_2__READ_ACTIVE 0x4000
526#define PERM_SRC_ID_2__PARTITION_VALID 0x8000
527
528#define MIN_BLK_ADDR_2 0x8c0
529#define MIN_BLK_ADDR_2__VALUE 0xffff
530
531#define MAX_BLK_ADDR_2 0x8d0
532#define MAX_BLK_ADDR_2__VALUE 0xffff
533
534#define MIN_MAX_BANK_2 0x8e0
535#define MIN_MAX_BANK_2__MIN_VALUE 0x0003
536#define MIN_MAX_BANK_2__MAX_VALUE 0x000c
537
538#define PERM_SRC_ID_3 0x8f0
539#define PERM_SRC_ID_3__SRCID 0x00ff
540#define PERM_SRC_ID_3__DIRECT_ACCESS_ACTIVE 0x0800
541#define PERM_SRC_ID_3__WRITE_ACTIVE 0x2000
542#define PERM_SRC_ID_3__READ_ACTIVE 0x4000
543#define PERM_SRC_ID_3__PARTITION_VALID 0x8000
544
545#define MIN_BLK_ADDR_3 0x900
546#define MIN_BLK_ADDR_3__VALUE 0xffff
547
548#define MAX_BLK_ADDR_3 0x910
549#define MAX_BLK_ADDR_3__VALUE 0xffff
550
551#define MIN_MAX_BANK_3 0x920
552#define MIN_MAX_BANK_3__MIN_VALUE 0x0003
553#define MIN_MAX_BANK_3__MAX_VALUE 0x000c
554
555#define PERM_SRC_ID_4 0x930
556#define PERM_SRC_ID_4__SRCID 0x00ff
557#define PERM_SRC_ID_4__DIRECT_ACCESS_ACTIVE 0x0800
558#define PERM_SRC_ID_4__WRITE_ACTIVE 0x2000
559#define PERM_SRC_ID_4__READ_ACTIVE 0x4000
560#define PERM_SRC_ID_4__PARTITION_VALID 0x8000
561
562#define MIN_BLK_ADDR_4 0x940
563#define MIN_BLK_ADDR_4__VALUE 0xffff
564
565#define MAX_BLK_ADDR_4 0x950
566#define MAX_BLK_ADDR_4__VALUE 0xffff
567
568#define MIN_MAX_BANK_4 0x960
569#define MIN_MAX_BANK_4__MIN_VALUE 0x0003
570#define MIN_MAX_BANK_4__MAX_VALUE 0x000c
571
572#define PERM_SRC_ID_5 0x970
573#define PERM_SRC_ID_5__SRCID 0x00ff
574#define PERM_SRC_ID_5__DIRECT_ACCESS_ACTIVE 0x0800
575#define PERM_SRC_ID_5__WRITE_ACTIVE 0x2000
576#define PERM_SRC_ID_5__READ_ACTIVE 0x4000
577#define PERM_SRC_ID_5__PARTITION_VALID 0x8000
578
579#define MIN_BLK_ADDR_5 0x980
580#define MIN_BLK_ADDR_5__VALUE 0xffff
581
582#define MAX_BLK_ADDR_5 0x990
583#define MAX_BLK_ADDR_5__VALUE 0xffff
584
585#define MIN_MAX_BANK_5 0x9a0
586#define MIN_MAX_BANK_5__MIN_VALUE 0x0003
587#define MIN_MAX_BANK_5__MAX_VALUE 0x000c
588
589#define PERM_SRC_ID_6 0x9b0
590#define PERM_SRC_ID_6__SRCID 0x00ff
591#define PERM_SRC_ID_6__DIRECT_ACCESS_ACTIVE 0x0800
592#define PERM_SRC_ID_6__WRITE_ACTIVE 0x2000
593#define PERM_SRC_ID_6__READ_ACTIVE 0x4000
594#define PERM_SRC_ID_6__PARTITION_VALID 0x8000
595
596#define MIN_BLK_ADDR_6 0x9c0
597#define MIN_BLK_ADDR_6__VALUE 0xffff
598
599#define MAX_BLK_ADDR_6 0x9d0
600#define MAX_BLK_ADDR_6__VALUE 0xffff
601
602#define MIN_MAX_BANK_6 0x9e0
603#define MIN_MAX_BANK_6__MIN_VALUE 0x0003
604#define MIN_MAX_BANK_6__MAX_VALUE 0x000c
605
606#define PERM_SRC_ID_7 0x9f0
607#define PERM_SRC_ID_7__SRCID 0x00ff
608#define PERM_SRC_ID_7__DIRECT_ACCESS_ACTIVE 0x0800
609#define PERM_SRC_ID_7__WRITE_ACTIVE 0x2000
610#define PERM_SRC_ID_7__READ_ACTIVE 0x4000
611#define PERM_SRC_ID_7__PARTITION_VALID 0x8000
612 364
613#define MIN_BLK_ADDR_7 0xa00
614#define MIN_BLK_ADDR_7__VALUE 0xffff
615
616#define MAX_BLK_ADDR_7 0xa10
617#define MAX_BLK_ADDR_7__VALUE 0xffff
618
619#define MIN_MAX_BANK_7 0xa20
620#define MIN_MAX_BANK_7__MIN_VALUE 0x0003
621#define MIN_MAX_BANK_7__MAX_VALUE 0x000c
622 365
623/* ffsdefs.h */ 366/* ffsdefs.h */
624#define CLEAR 0 /*use this to clear a field instead of "fail"*/ 367#define CLEAR 0 /*use this to clear a field instead of "fail"*/
@@ -711,7 +454,6 @@
711#define READ_WRITE_ENABLE_HIGH_COUNT 22 454#define READ_WRITE_ENABLE_HIGH_COUNT 22
712 455
713#define ECC_SECTOR_SIZE 512 456#define ECC_SECTOR_SIZE 512
714#define LLD_MAX_FLASH_BANKS 4
715 457
716#define DENALI_BUF_SIZE (NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE) 458#define DENALI_BUF_SIZE (NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE)
717 459
@@ -732,7 +474,7 @@ struct denali_nand_info {
732 int status; 474 int status;
733 int platform; 475 int platform;
734 struct nand_buf buf; 476 struct nand_buf buf;
735 struct pci_dev *dev; 477 struct device *dev;
736 int total_used_banks; 478 int total_used_banks;
737 uint32_t block; /* stored for future use */ 479 uint32_t block; /* stored for future use */
738 uint16_t page; 480 uint16_t page;
@@ -751,6 +493,7 @@ struct denali_nand_info {
751 uint32_t totalblks; 493 uint32_t totalblks;
752 uint32_t blksperchip; 494 uint32_t blksperchip;
753 uint32_t bbtskipbytes; 495 uint32_t bbtskipbytes;
496 uint32_t max_banks;
754}; 497};
755 498
756#endif /*_LLD_NAND_*/ 499#endif /*_LLD_NAND_*/
diff --git a/drivers/mtd/nand/diskonchip.c b/drivers/mtd/nand/diskonchip.c
index 657b9f4b6f9b..7837728d02ff 100644
--- a/drivers/mtd/nand/diskonchip.c
+++ b/drivers/mtd/nand/diskonchip.c
@@ -1360,11 +1360,9 @@ static int __init nftl_scan_bbt(struct mtd_info *mtd)
1360 At least as nand_bbt.c is currently written. */ 1360 At least as nand_bbt.c is currently written. */
1361 if ((ret = nand_scan_bbt(mtd, NULL))) 1361 if ((ret = nand_scan_bbt(mtd, NULL)))
1362 return ret; 1362 return ret;
1363 add_mtd_device(mtd); 1363 mtd_device_register(mtd, NULL, 0);
1364#ifdef CONFIG_MTD_PARTITIONS
1365 if (!no_autopart) 1364 if (!no_autopart)
1366 add_mtd_partitions(mtd, parts, numparts); 1365 mtd_device_register(mtd, parts, numparts);
1367#endif
1368 return 0; 1366 return 0;
1369} 1367}
1370 1368
@@ -1419,11 +1417,9 @@ static int __init inftl_scan_bbt(struct mtd_info *mtd)
1419 autopartitioning, but I want to give it more thought. */ 1417 autopartitioning, but I want to give it more thought. */
1420 if (!numparts) 1418 if (!numparts)
1421 return -EIO; 1419 return -EIO;
1422 add_mtd_device(mtd); 1420 mtd_device_register(mtd, NULL, 0);
1423#ifdef CONFIG_MTD_PARTITIONS
1424 if (!no_autopart) 1421 if (!no_autopart)
1425 add_mtd_partitions(mtd, parts, numparts); 1422 mtd_device_register(mtd, parts, numparts);
1426#endif
1427 return 0; 1423 return 0;
1428} 1424}
1429 1425
@@ -1678,9 +1674,9 @@ static int __init doc_probe(unsigned long physadr)
1678 /* DBB note: i believe nand_release is necessary here, as 1674 /* DBB note: i believe nand_release is necessary here, as
1679 buffers may have been allocated in nand_base. Check with 1675 buffers may have been allocated in nand_base. Check with
1680 Thomas. FIX ME! */ 1676 Thomas. FIX ME! */
1681 /* nand_release will call del_mtd_device, but we haven't yet 1677 /* nand_release will call mtd_device_unregister, but we
1682 added it. This is handled without incident by 1678 haven't yet added it. This is handled without incident by
1683 del_mtd_device, as far as I can tell. */ 1679 mtd_device_unregister, as far as I can tell. */
1684 nand_release(mtd); 1680 nand_release(mtd);
1685 kfree(mtd); 1681 kfree(mtd);
1686 goto fail; 1682 goto fail;
diff --git a/drivers/mtd/nand/edb7312.c b/drivers/mtd/nand/edb7312.c
index 86366bfba9f8..8400d0f6dada 100644
--- a/drivers/mtd/nand/edb7312.c
+++ b/drivers/mtd/nand/edb7312.c
@@ -55,7 +55,6 @@ static unsigned long ep7312_fio_pbase = EP7312_FIO_PBASE;
55static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR; 55static void __iomem *ep7312_pxdr = (void __iomem *)EP7312_PXDR;
56static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR; 56static void __iomem *ep7312_pxddr = (void __iomem *)EP7312_PXDDR;
57 57
58#ifdef CONFIG_MTD_PARTITIONS
59/* 58/*
60 * Define static partitions for flash device 59 * Define static partitions for flash device
61 */ 60 */
@@ -67,8 +66,6 @@ static struct mtd_partition partition_info[] = {
67 66
68#define NUM_PARTITIONS 1 67#define NUM_PARTITIONS 1
69 68
70#endif
71
72/* 69/*
73 * hardware specific access to control-lines 70 * hardware specific access to control-lines
74 * 71 *
@@ -101,9 +98,7 @@ static int ep7312_device_ready(struct mtd_info *mtd)
101 return 1; 98 return 1;
102} 99}
103 100
104#ifdef CONFIG_MTD_PARTITIONS
105const char *part_probes[] = { "cmdlinepart", NULL }; 101const char *part_probes[] = { "cmdlinepart", NULL };
106#endif
107 102
108/* 103/*
109 * Main initialization routine 104 * Main initialization routine
@@ -162,14 +157,12 @@ static int __init ep7312_init(void)
162 kfree(ep7312_mtd); 157 kfree(ep7312_mtd);
163 return -ENXIO; 158 return -ENXIO;
164 } 159 }
165#ifdef CONFIG_MTD_PARTITIONS
166 ep7312_mtd->name = "edb7312-nand"; 160 ep7312_mtd->name = "edb7312-nand";
167 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0); 161 mtd_parts_nb = parse_mtd_partitions(ep7312_mtd, part_probes, &mtd_parts, 0);
168 if (mtd_parts_nb > 0) 162 if (mtd_parts_nb > 0)
169 part_type = "command line"; 163 part_type = "command line";
170 else 164 else
171 mtd_parts_nb = 0; 165 mtd_parts_nb = 0;
172#endif
173 if (mtd_parts_nb == 0) { 166 if (mtd_parts_nb == 0) {
174 mtd_parts = partition_info; 167 mtd_parts = partition_info;
175 mtd_parts_nb = NUM_PARTITIONS; 168 mtd_parts_nb = NUM_PARTITIONS;
@@ -178,7 +171,7 @@ static int __init ep7312_init(void)
178 171
179 /* Register the partitions */ 172 /* Register the partitions */
180 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 173 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
181 add_mtd_partitions(ep7312_mtd, mtd_parts, mtd_parts_nb); 174 mtd_device_register(ep7312_mtd, mtd_parts, mtd_parts_nb);
182 175
183 /* Return happy */ 176 /* Return happy */
184 return 0; 177 return 0;
diff --git a/drivers/mtd/nand/fsl_elbc_nand.c b/drivers/mtd/nand/fsl_elbc_nand.c
index 537e380b8dcb..0bb254c7d2b1 100644
--- a/drivers/mtd/nand/fsl_elbc_nand.c
+++ b/drivers/mtd/nand/fsl_elbc_nand.c
@@ -841,12 +841,9 @@ static int __devinit fsl_elbc_nand_probe(struct platform_device *pdev)
841 struct fsl_elbc_mtd *priv; 841 struct fsl_elbc_mtd *priv;
842 struct resource res; 842 struct resource res;
843 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl; 843 struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl;
844
845#ifdef CONFIG_MTD_PARTITIONS
846 static const char *part_probe_types[] 844 static const char *part_probe_types[]
847 = { "cmdlinepart", "RedBoot", NULL }; 845 = { "cmdlinepart", "RedBoot", NULL };
848 struct mtd_partition *parts; 846 struct mtd_partition *parts;
849#endif
850 int ret; 847 int ret;
851 int bank; 848 int bank;
852 struct device *dev; 849 struct device *dev;
@@ -935,26 +932,19 @@ static int __devinit fsl_elbc_nand_probe(struct platform_device *pdev)
935 if (ret) 932 if (ret)
936 goto err; 933 goto err;
937 934
938#ifdef CONFIG_MTD_PARTITIONS
939 /* First look for RedBoot table or partitions on the command 935 /* First look for RedBoot table or partitions on the command
940 * line, these take precedence over device tree information */ 936 * line, these take precedence over device tree information */
941 ret = parse_mtd_partitions(&priv->mtd, part_probe_types, &parts, 0); 937 ret = parse_mtd_partitions(&priv->mtd, part_probe_types, &parts, 0);
942 if (ret < 0) 938 if (ret < 0)
943 goto err; 939 goto err;
944 940
945#ifdef CONFIG_MTD_OF_PARTS
946 if (ret == 0) { 941 if (ret == 0) {
947 ret = of_mtd_parse_partitions(priv->dev, node, &parts); 942 ret = of_mtd_parse_partitions(priv->dev, node, &parts);
948 if (ret < 0) 943 if (ret < 0)
949 goto err; 944 goto err;
950 } 945 }
951#endif
952 946
953 if (ret > 0) 947 mtd_device_register(&priv->mtd, parts, ret);
954 add_mtd_partitions(&priv->mtd, parts, ret);
955 else
956#endif
957 add_mtd_device(&priv->mtd);
958 948
959 printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n", 949 printk(KERN_INFO "eLBC NAND device at 0x%llx, bank %d\n",
960 (unsigned long long)res.start, priv->bank); 950 (unsigned long long)res.start, priv->bank);
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 073ee026a17c..23752fd5bc59 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -33,10 +33,7 @@ struct fsl_upm_nand {
33 struct mtd_info mtd; 33 struct mtd_info mtd;
34 struct nand_chip chip; 34 struct nand_chip chip;
35 int last_ctrl; 35 int last_ctrl;
36#ifdef CONFIG_MTD_PARTITIONS
37 struct mtd_partition *parts; 36 struct mtd_partition *parts;
38#endif
39
40 struct fsl_upm upm; 37 struct fsl_upm upm;
41 uint8_t upm_addr_offset; 38 uint8_t upm_addr_offset;
42 uint8_t upm_cmd_offset; 39 uint8_t upm_cmd_offset;
@@ -161,9 +158,7 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
161{ 158{
162 int ret; 159 int ret;
163 struct device_node *flash_np; 160 struct device_node *flash_np;
164#ifdef CONFIG_MTD_PARTITIONS
165 static const char *part_types[] = { "cmdlinepart", NULL, }; 161 static const char *part_types[] = { "cmdlinepart", NULL, };
166#endif
167 162
168 fun->chip.IO_ADDR_R = fun->io_base; 163 fun->chip.IO_ADDR_R = fun->io_base;
169 fun->chip.IO_ADDR_W = fun->io_base; 164 fun->chip.IO_ADDR_W = fun->io_base;
@@ -197,7 +192,6 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
197 if (ret) 192 if (ret)
198 goto err; 193 goto err;
199 194
200#ifdef CONFIG_MTD_PARTITIONS
201 ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0); 195 ret = parse_mtd_partitions(&fun->mtd, part_types, &fun->parts, 0);
202 196
203#ifdef CONFIG_MTD_OF_PARTS 197#ifdef CONFIG_MTD_OF_PARTS
@@ -207,11 +201,7 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
207 goto err; 201 goto err;
208 } 202 }
209#endif 203#endif
210 if (ret > 0) 204 ret = mtd_device_register(&fun->mtd, fun->parts, ret);
211 ret = add_mtd_partitions(&fun->mtd, fun->parts, ret);
212 else
213#endif
214 ret = add_mtd_device(&fun->mtd);
215err: 205err:
216 of_node_put(flash_np); 206 of_node_put(flash_np);
217 return ret; 207 return ret;
diff --git a/drivers/mtd/nand/fsmc_nand.c b/drivers/mtd/nand/fsmc_nand.c
index 0d45ef3883e8..e9b275ac381c 100644
--- a/drivers/mtd/nand/fsmc_nand.c
+++ b/drivers/mtd/nand/fsmc_nand.c
@@ -120,8 +120,6 @@ static struct fsmc_eccplace fsmc_ecc4_sp_place = {
120 } 120 }
121}; 121};
122 122
123
124#ifdef CONFIG_MTD_PARTITIONS
125/* 123/*
126 * Default partition tables to be used if the partition information not 124 * Default partition tables to be used if the partition information not
127 * provided through platform data. 125 * provided through platform data.
@@ -182,7 +180,6 @@ static struct mtd_partition partition_info_128KB_blk[] = {
182#ifdef CONFIG_MTD_CMDLINE_PARTS 180#ifdef CONFIG_MTD_CMDLINE_PARTS
183const char *part_probes[] = { "cmdlinepart", NULL }; 181const char *part_probes[] = { "cmdlinepart", NULL };
184#endif 182#endif
185#endif
186 183
187/** 184/**
188 * struct fsmc_nand_data - structure for FSMC NAND device state 185 * struct fsmc_nand_data - structure for FSMC NAND device state
@@ -719,7 +716,6 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
719 * platform data, 716 * platform data,
720 * default partition information present in driver. 717 * default partition information present in driver.
721 */ 718 */
722#ifdef CONFIG_MTD_PARTITIONS
723#ifdef CONFIG_MTD_CMDLINE_PARTS 719#ifdef CONFIG_MTD_CMDLINE_PARTS
724 /* 720 /*
725 * Check if partition info passed via command line 721 * Check if partition info passed via command line
@@ -777,19 +773,10 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
777 } 773 }
778#endif 774#endif
779 775
780 if (host->partitions) { 776 ret = mtd_device_register(&host->mtd, host->partitions,
781 ret = add_mtd_partitions(&host->mtd, host->partitions, 777 host->nr_partitions);
782 host->nr_partitions); 778 if (ret)
783 if (ret)
784 goto err_probe;
785 }
786#else
787 dev_info(&pdev->dev, "Registering %s as whole device\n", mtd->name);
788 if (!add_mtd_device(mtd)) {
789 ret = -ENXIO;
790 goto err_probe; 779 goto err_probe;
791 }
792#endif
793 780
794 platform_set_drvdata(pdev, host); 781 platform_set_drvdata(pdev, host);
795 dev_info(&pdev->dev, "FSMC NAND driver registration successful\n"); 782 dev_info(&pdev->dev, "FSMC NAND driver registration successful\n");
@@ -835,11 +822,7 @@ static int fsmc_nand_remove(struct platform_device *pdev)
835 platform_set_drvdata(pdev, NULL); 822 platform_set_drvdata(pdev, NULL);
836 823
837 if (host) { 824 if (host) {
838#ifdef CONFIG_MTD_PARTITIONS 825 mtd_device_unregister(&host->mtd);
839 del_mtd_partitions(&host->mtd);
840#else
841 del_mtd_device(&host->mtd);
842#endif
843 clk_disable(host->clk); 826 clk_disable(host->clk);
844 clk_put(host->clk); 827 clk_put(host->clk);
845 828
diff --git a/drivers/mtd/nand/gpio.c b/drivers/mtd/nand/gpio.c
index 0cde618bcc1e..2c2060b2800e 100644
--- a/drivers/mtd/nand/gpio.c
+++ b/drivers/mtd/nand/gpio.c
@@ -316,8 +316,8 @@ static int __devinit gpio_nand_probe(struct platform_device *dev)
316 gpiomtd->plat.adjust_parts(&gpiomtd->plat, 316 gpiomtd->plat.adjust_parts(&gpiomtd->plat,
317 gpiomtd->mtd_info.size); 317 gpiomtd->mtd_info.size);
318 318
319 add_mtd_partitions(&gpiomtd->mtd_info, gpiomtd->plat.parts, 319 mtd_device_register(&gpiomtd->mtd_info, gpiomtd->plat.parts,
320 gpiomtd->plat.num_parts); 320 gpiomtd->plat.num_parts);
321 platform_set_drvdata(dev, gpiomtd); 321 platform_set_drvdata(dev, gpiomtd);
322 322
323 return 0; 323 return 0;
diff --git a/drivers/mtd/nand/h1910.c b/drivers/mtd/nand/h1910.c
index f8ce79b446ed..02a03e67109c 100644
--- a/drivers/mtd/nand/h1910.c
+++ b/drivers/mtd/nand/h1910.c
@@ -38,7 +38,6 @@ static struct mtd_info *h1910_nand_mtd = NULL;
38 * Module stuff 38 * Module stuff
39 */ 39 */
40 40
41#ifdef CONFIG_MTD_PARTITIONS
42/* 41/*
43 * Define static partitions for flash device 42 * Define static partitions for flash device
44 */ 43 */
@@ -50,8 +49,6 @@ static struct mtd_partition partition_info[] = {
50 49
51#define NUM_PARTITIONS 1 50#define NUM_PARTITIONS 1
52 51
53#endif
54
55/* 52/*
56 * hardware specific access to control-lines 53 * hardware specific access to control-lines
57 * 54 *
@@ -154,7 +151,7 @@ static int __init h1910_init(void)
154 151
155 /* Register the partitions */ 152 /* Register the partitions */
156 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 153 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
157 add_mtd_partitions(h1910_nand_mtd, mtd_parts, mtd_parts_nb); 154 mtd_device_register(h1910_nand_mtd, mtd_parts, mtd_parts_nb);
158 155
159 /* Return happy */ 156 /* Return happy */
160 return 0; 157 return 0;
diff --git a/drivers/mtd/nand/jz4740_nand.c b/drivers/mtd/nand/jz4740_nand.c
index cea38a5d4ac5..6e813daed068 100644
--- a/drivers/mtd/nand/jz4740_nand.c
+++ b/drivers/mtd/nand/jz4740_nand.c
@@ -299,10 +299,8 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
299 struct nand_chip *chip; 299 struct nand_chip *chip;
300 struct mtd_info *mtd; 300 struct mtd_info *mtd;
301 struct jz_nand_platform_data *pdata = pdev->dev.platform_data; 301 struct jz_nand_platform_data *pdata = pdev->dev.platform_data;
302#ifdef CONFIG_MTD_PARTITIONS
303 struct mtd_partition *partition_info; 302 struct mtd_partition *partition_info;
304 int num_partitions = 0; 303 int num_partitions = 0;
305#endif
306 304
307 nand = kzalloc(sizeof(*nand), GFP_KERNEL); 305 nand = kzalloc(sizeof(*nand), GFP_KERNEL);
308 if (!nand) { 306 if (!nand) {
@@ -375,7 +373,6 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
375 goto err_gpio_free; 373 goto err_gpio_free;
376 } 374 }
377 375
378#ifdef CONFIG_MTD_PARTITIONS
379#ifdef CONFIG_MTD_CMDLINE_PARTS 376#ifdef CONFIG_MTD_CMDLINE_PARTS
380 num_partitions = parse_mtd_partitions(mtd, part_probes, 377 num_partitions = parse_mtd_partitions(mtd, part_probes,
381 &partition_info, 0); 378 &partition_info, 0);
@@ -384,12 +381,7 @@ static int __devinit jz_nand_probe(struct platform_device *pdev)
384 num_partitions = pdata->num_partitions; 381 num_partitions = pdata->num_partitions;
385 partition_info = pdata->partitions; 382 partition_info = pdata->partitions;
386 } 383 }
387 384 ret = mtd_device_register(mtd, partition_info, num_partitions);
388 if (num_partitions > 0)
389 ret = add_mtd_partitions(mtd, partition_info, num_partitions);
390 else
391#endif
392 ret = add_mtd_device(mtd);
393 385
394 if (ret) { 386 if (ret) {
395 dev_err(&pdev->dev, "Failed to add mtd device\n"); 387 dev_err(&pdev->dev, "Failed to add mtd device\n");
diff --git a/drivers/mtd/nand/mpc5121_nfc.c b/drivers/mtd/nand/mpc5121_nfc.c
index 0b81b5b499d1..2f7c930872f9 100644
--- a/drivers/mtd/nand/mpc5121_nfc.c
+++ b/drivers/mtd/nand/mpc5121_nfc.c
@@ -131,9 +131,7 @@ struct mpc5121_nfc_prv {
131 131
132static void mpc5121_nfc_done(struct mtd_info *mtd); 132static void mpc5121_nfc_done(struct mtd_info *mtd);
133 133
134#ifdef CONFIG_MTD_PARTITIONS
135static const char *mpc5121_nfc_pprobes[] = { "cmdlinepart", NULL }; 134static const char *mpc5121_nfc_pprobes[] = { "cmdlinepart", NULL };
136#endif
137 135
138/* Read NFC register */ 136/* Read NFC register */
139static inline u16 nfc_read(struct mtd_info *mtd, uint reg) 137static inline u16 nfc_read(struct mtd_info *mtd, uint reg)
@@ -658,9 +656,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
658 struct mpc5121_nfc_prv *prv; 656 struct mpc5121_nfc_prv *prv;
659 struct resource res; 657 struct resource res;
660 struct mtd_info *mtd; 658 struct mtd_info *mtd;
661#ifdef CONFIG_MTD_PARTITIONS
662 struct mtd_partition *parts; 659 struct mtd_partition *parts;
663#endif
664 struct nand_chip *chip; 660 struct nand_chip *chip;
665 unsigned long regs_paddr, regs_size; 661 unsigned long regs_paddr, regs_size;
666 const __be32 *chips_no; 662 const __be32 *chips_no;
@@ -841,7 +837,6 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
841 dev_set_drvdata(dev, mtd); 837 dev_set_drvdata(dev, mtd);
842 838
843 /* Register device in MTD */ 839 /* Register device in MTD */
844#ifdef CONFIG_MTD_PARTITIONS
845 retval = parse_mtd_partitions(mtd, mpc5121_nfc_pprobes, &parts, 0); 840 retval = parse_mtd_partitions(mtd, mpc5121_nfc_pprobes, &parts, 0);
846#ifdef CONFIG_MTD_OF_PARTS 841#ifdef CONFIG_MTD_OF_PARTS
847 if (retval == 0) 842 if (retval == 0)
@@ -854,12 +849,7 @@ static int __devinit mpc5121_nfc_probe(struct platform_device *op)
854 goto error; 849 goto error;
855 } 850 }
856 851
857 if (retval > 0) 852 retval = mtd_device_register(mtd, parts, retval);
858 retval = add_mtd_partitions(mtd, parts, retval);
859 else
860#endif
861 retval = add_mtd_device(mtd);
862
863 if (retval) { 853 if (retval) {
864 dev_err(dev, "Error adding MTD device!\n"); 854 dev_err(dev, "Error adding MTD device!\n");
865 devm_free_irq(dev, prv->irq, mtd); 855 devm_free_irq(dev, prv->irq, mtd);
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index 42a95fb41504..90df34c4d26c 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -56,8 +56,14 @@
56#define NFC_V1_V2_WRPROT (host->regs + 0x12) 56#define NFC_V1_V2_WRPROT (host->regs + 0x12)
57#define NFC_V1_UNLOCKSTART_BLKADDR (host->regs + 0x14) 57#define NFC_V1_UNLOCKSTART_BLKADDR (host->regs + 0x14)
58#define NFC_V1_UNLOCKEND_BLKADDR (host->regs + 0x16) 58#define NFC_V1_UNLOCKEND_BLKADDR (host->regs + 0x16)
59#define NFC_V21_UNLOCKSTART_BLKADDR (host->regs + 0x20) 59#define NFC_V21_UNLOCKSTART_BLKADDR0 (host->regs + 0x20)
60#define NFC_V21_UNLOCKEND_BLKADDR (host->regs + 0x22) 60#define NFC_V21_UNLOCKSTART_BLKADDR1 (host->regs + 0x24)
61#define NFC_V21_UNLOCKSTART_BLKADDR2 (host->regs + 0x28)
62#define NFC_V21_UNLOCKSTART_BLKADDR3 (host->regs + 0x2c)
63#define NFC_V21_UNLOCKEND_BLKADDR0 (host->regs + 0x22)
64#define NFC_V21_UNLOCKEND_BLKADDR1 (host->regs + 0x26)
65#define NFC_V21_UNLOCKEND_BLKADDR2 (host->regs + 0x2a)
66#define NFC_V21_UNLOCKEND_BLKADDR3 (host->regs + 0x2e)
61#define NFC_V1_V2_NF_WRPRST (host->regs + 0x18) 67#define NFC_V1_V2_NF_WRPRST (host->regs + 0x18)
62#define NFC_V1_V2_CONFIG1 (host->regs + 0x1a) 68#define NFC_V1_V2_CONFIG1 (host->regs + 0x1a)
63#define NFC_V1_V2_CONFIG2 (host->regs + 0x1c) 69#define NFC_V1_V2_CONFIG2 (host->regs + 0x1c)
@@ -152,6 +158,7 @@ struct mxc_nand_host {
152 int clk_act; 158 int clk_act;
153 int irq; 159 int irq;
154 int eccsize; 160 int eccsize;
161 int active_cs;
155 162
156 struct completion op_completion; 163 struct completion op_completion;
157 164
@@ -236,9 +243,7 @@ static struct nand_ecclayout nandv2_hw_eccoob_4k = {
236 } 243 }
237}; 244};
238 245
239#ifdef CONFIG_MTD_PARTITIONS
240static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL }; 246static const char *part_probes[] = { "RedBoot", "cmdlinepart", NULL };
241#endif
242 247
243static irqreturn_t mxc_nfc_irq(int irq, void *dev_id) 248static irqreturn_t mxc_nfc_irq(int irq, void *dev_id)
244{ 249{
@@ -445,7 +450,7 @@ static void send_page_v1_v2(struct mtd_info *mtd, unsigned int ops)
445 for (i = 0; i < bufs; i++) { 450 for (i = 0; i < bufs; i++) {
446 451
447 /* NANDFC buffer 0 is used for page read/write */ 452 /* NANDFC buffer 0 is used for page read/write */
448 writew(i, NFC_V1_V2_BUF_ADDR); 453 writew((host->active_cs << 4) | i, NFC_V1_V2_BUF_ADDR);
449 454
450 writew(ops, NFC_V1_V2_CONFIG2); 455 writew(ops, NFC_V1_V2_CONFIG2);
451 456
@@ -470,7 +475,7 @@ static void send_read_id_v1_v2(struct mxc_nand_host *host)
470 struct nand_chip *this = &host->nand; 475 struct nand_chip *this = &host->nand;
471 476
472 /* NANDFC buffer 0 is used for device ID output */ 477 /* NANDFC buffer 0 is used for device ID output */
473 writew(0x0, NFC_V1_V2_BUF_ADDR); 478 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
474 479
475 writew(NFC_ID, NFC_V1_V2_CONFIG2); 480 writew(NFC_ID, NFC_V1_V2_CONFIG2);
476 481
@@ -505,7 +510,7 @@ static uint16_t get_dev_status_v1_v2(struct mxc_nand_host *host)
505 uint32_t store; 510 uint32_t store;
506 uint16_t ret; 511 uint16_t ret;
507 512
508 writew(0x0, NFC_V1_V2_BUF_ADDR); 513 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
509 514
510 /* 515 /*
511 * The device status is stored in main_area0. To 516 * The device status is stored in main_area0. To
@@ -686,24 +691,24 @@ static void mxc_nand_select_chip(struct mtd_info *mtd, int chip)
686 struct nand_chip *nand_chip = mtd->priv; 691 struct nand_chip *nand_chip = mtd->priv;
687 struct mxc_nand_host *host = nand_chip->priv; 692 struct mxc_nand_host *host = nand_chip->priv;
688 693
689 switch (chip) { 694 if (chip == -1) {
690 case -1:
691 /* Disable the NFC clock */ 695 /* Disable the NFC clock */
692 if (host->clk_act) { 696 if (host->clk_act) {
693 clk_disable(host->clk); 697 clk_disable(host->clk);
694 host->clk_act = 0; 698 host->clk_act = 0;
695 } 699 }
696 break; 700 return;
697 case 0: 701 }
702
703 if (!host->clk_act) {
698 /* Enable the NFC clock */ 704 /* Enable the NFC clock */
699 if (!host->clk_act) { 705 clk_enable(host->clk);
700 clk_enable(host->clk); 706 host->clk_act = 1;
701 host->clk_act = 1; 707 }
702 }
703 break;
704 708
705 default: 709 if (nfc_is_v21()) {
706 break; 710 host->active_cs = chip;
711 writew(host->active_cs << 4, NFC_V1_V2_BUF_ADDR);
707 } 712 }
708} 713}
709 714
@@ -834,8 +839,14 @@ static void preset_v1_v2(struct mtd_info *mtd)
834 839
835 /* Blocks to be unlocked */ 840 /* Blocks to be unlocked */
836 if (nfc_is_v21()) { 841 if (nfc_is_v21()) {
837 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR); 842 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR0);
838 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR); 843 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR1);
844 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR2);
845 writew(0x0, NFC_V21_UNLOCKSTART_BLKADDR3);
846 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR0);
847 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR1);
848 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR2);
849 writew(0xffff, NFC_V21_UNLOCKEND_BLKADDR3);
839 } else if (nfc_is_v1()) { 850 } else if (nfc_is_v1()) {
840 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR); 851 writew(0x0, NFC_V1_UNLOCKSTART_BLKADDR);
841 writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR); 852 writew(0x4000, NFC_V1_UNLOCKEND_BLKADDR);
@@ -1200,7 +1211,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1200 irq_control_v1_v2(host, 1); 1211 irq_control_v1_v2(host, 1);
1201 1212
1202 /* first scan to find the device and get the page size */ 1213 /* first scan to find the device and get the page size */
1203 if (nand_scan_ident(mtd, 1, NULL)) { 1214 if (nand_scan_ident(mtd, nfc_is_v21() ? 4 : 1, NULL)) {
1204 err = -ENXIO; 1215 err = -ENXIO;
1205 goto escan; 1216 goto escan;
1206 } 1217 }
@@ -1220,18 +1231,15 @@ static int __init mxcnd_probe(struct platform_device *pdev)
1220 } 1231 }
1221 1232
1222 /* Register the partitions */ 1233 /* Register the partitions */
1223#ifdef CONFIG_MTD_PARTITIONS
1224 nr_parts = 1234 nr_parts =
1225 parse_mtd_partitions(mtd, part_probes, &host->parts, 0); 1235 parse_mtd_partitions(mtd, part_probes, &host->parts, 0);
1226 if (nr_parts > 0) 1236 if (nr_parts > 0)
1227 add_mtd_partitions(mtd, host->parts, nr_parts); 1237 mtd_device_register(mtd, host->parts, nr_parts);
1228 else if (pdata->parts) 1238 else if (pdata->parts)
1229 add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); 1239 mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
1230 else 1240 else {
1231#endif
1232 {
1233 pr_info("Registering %s as whole device\n", mtd->name); 1241 pr_info("Registering %s as whole device\n", mtd->name);
1234 add_mtd_device(mtd); 1242 mtd_device_register(mtd, NULL, 0);
1235 } 1243 }
1236 1244
1237 platform_set_drvdata(pdev, host); 1245 platform_set_drvdata(pdev, host);
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index c54a4cbac6bc..a46e9bb847bd 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -47,10 +47,7 @@
47#include <linux/bitops.h> 47#include <linux/bitops.h>
48#include <linux/leds.h> 48#include <linux/leds.h>
49#include <linux/io.h> 49#include <linux/io.h>
50
51#ifdef CONFIG_MTD_PARTITIONS
52#include <linux/mtd/partitions.h> 50#include <linux/mtd/partitions.h>
53#endif
54 51
55/* Define default oob placement schemes for large and small page devices */ 52/* Define default oob placement schemes for large and small page devices */
56static struct nand_ecclayout nand_oob_8 = { 53static struct nand_ecclayout nand_oob_8 = {
@@ -976,9 +973,6 @@ int nand_unlock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
976 ret = __nand_unlock(mtd, ofs, len, 0); 973 ret = __nand_unlock(mtd, ofs, len, 0);
977 974
978out: 975out:
979 /* de-select the NAND device */
980 chip->select_chip(mtd, -1);
981
982 nand_release_device(mtd); 976 nand_release_device(mtd);
983 977
984 return ret; 978 return ret;
@@ -1046,9 +1040,6 @@ int nand_lock(struct mtd_info *mtd, loff_t ofs, uint64_t len)
1046 ret = __nand_unlock(mtd, ofs, len, 0x1); 1040 ret = __nand_unlock(mtd, ofs, len, 0x1);
1047 1041
1048out: 1042out:
1049 /* de-select the NAND device */
1050 chip->select_chip(mtd, -1);
1051
1052 nand_release_device(mtd); 1043 nand_release_device(mtd);
1053 1044
1054 return ret; 1045 return ret;
@@ -3112,6 +3103,8 @@ ident_done:
3112 chip->chip_shift += 32 - 1; 3103 chip->chip_shift += 32 - 1;
3113 } 3104 }
3114 3105
3106 chip->badblockbits = 8;
3107
3115 /* Set the bad block position */ 3108 /* Set the bad block position */
3116 if (mtd->writesize > 512 || (busw & NAND_BUSWIDTH_16)) 3109 if (mtd->writesize > 512 || (busw & NAND_BUSWIDTH_16))
3117 chip->badblockpos = NAND_LARGE_BADBLOCK_POS; 3110 chip->badblockpos = NAND_LARGE_BADBLOCK_POS;
@@ -3539,12 +3532,7 @@ void nand_release(struct mtd_info *mtd)
3539 if (chip->ecc.mode == NAND_ECC_SOFT_BCH) 3532 if (chip->ecc.mode == NAND_ECC_SOFT_BCH)
3540 nand_bch_free((struct nand_bch_control *)chip->ecc.priv); 3533 nand_bch_free((struct nand_bch_control *)chip->ecc.priv);
3541 3534
3542#ifdef CONFIG_MTD_PARTITIONS 3535 mtd_device_unregister(mtd);
3543 /* Deregister partitions */
3544 del_mtd_partitions(mtd);
3545#endif
3546 /* Deregister the device */
3547 del_mtd_device(mtd);
3548 3536
3549 /* Free bad block table memory */ 3537 /* Free bad block table memory */
3550 kfree(chip->bbt); 3538 kfree(chip->bbt);
diff --git a/drivers/mtd/nand/nand_bbt.c b/drivers/mtd/nand/nand_bbt.c
index af46428286fe..ccbeaa1e4a8e 100644
--- a/drivers/mtd/nand/nand_bbt.c
+++ b/drivers/mtd/nand/nand_bbt.c
@@ -1276,20 +1276,6 @@ int nand_update_bbt(struct mtd_info *mtd, loff_t offs)
1276 * while scanning a device for factory marked good / bad blocks. */ 1276 * while scanning a device for factory marked good / bad blocks. */
1277static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 1277static uint8_t scan_ff_pattern[] = { 0xff, 0xff };
1278 1278
1279static struct nand_bbt_descr smallpage_flashbased = {
1280 .options = NAND_BBT_SCAN2NDPAGE,
1281 .offs = NAND_SMALL_BADBLOCK_POS,
1282 .len = 1,
1283 .pattern = scan_ff_pattern
1284};
1285
1286static struct nand_bbt_descr largepage_flashbased = {
1287 .options = NAND_BBT_SCAN2NDPAGE,
1288 .offs = NAND_LARGE_BADBLOCK_POS,
1289 .len = 2,
1290 .pattern = scan_ff_pattern
1291};
1292
1293static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 }; 1279static uint8_t scan_agand_pattern[] = { 0x1C, 0x71, 0xC7, 0x1C, 0x71, 0xC7 };
1294 1280
1295static struct nand_bbt_descr agand_flashbased = { 1281static struct nand_bbt_descr agand_flashbased = {
@@ -1355,10 +1341,6 @@ static struct nand_bbt_descr bbt_mirror_no_bbt_descr = {
1355 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when 1341 * this->badblock_pattern. Thus, this->badblock_pattern should be NULL when
1356 * passed to this function. 1342 * passed to this function.
1357 * 1343 *
1358 * TODO: Handle other flags, replace other static structs
1359 * (e.g. handle NAND_BBT_FLASH for flash-based BBT,
1360 * replace smallpage_flashbased)
1361 *
1362 */ 1344 */
1363static int nand_create_default_bbt_descr(struct nand_chip *this) 1345static int nand_create_default_bbt_descr(struct nand_chip *this)
1364{ 1346{
@@ -1422,15 +1404,14 @@ int nand_default_bbt(struct mtd_info *mtd)
1422 this->bbt_md = &bbt_mirror_descr; 1404 this->bbt_md = &bbt_mirror_descr;
1423 } 1405 }
1424 } 1406 }
1425 if (!this->badblock_pattern) {
1426 this->badblock_pattern = (mtd->writesize > 512) ? &largepage_flashbased : &smallpage_flashbased;
1427 }
1428 } else { 1407 } else {
1429 this->bbt_td = NULL; 1408 this->bbt_td = NULL;
1430 this->bbt_md = NULL; 1409 this->bbt_md = NULL;
1431 if (!this->badblock_pattern)
1432 nand_create_default_bbt_descr(this);
1433 } 1410 }
1411
1412 if (!this->badblock_pattern)
1413 nand_create_default_bbt_descr(this);
1414
1434 return nand_scan_bbt(mtd, this->badblock_pattern); 1415 return nand_scan_bbt(mtd, this->badblock_pattern);
1435} 1416}
1436 1417
diff --git a/drivers/mtd/nand/nandsim.c b/drivers/mtd/nand/nandsim.c
index 893d95bfea48..357e8c5252a8 100644
--- a/drivers/mtd/nand/nandsim.c
+++ b/drivers/mtd/nand/nandsim.c
@@ -2383,7 +2383,9 @@ static int __init ns_init_module(void)
2383 goto err_exit; 2383 goto err_exit;
2384 2384
2385 /* Register NAND partitions */ 2385 /* Register NAND partitions */
2386 if ((retval = add_mtd_partitions(nsmtd, &nand->partitions[0], nand->nbparts)) != 0) 2386 retval = mtd_device_register(nsmtd, &nand->partitions[0],
2387 nand->nbparts);
2388 if (retval != 0)
2387 goto err_exit; 2389 goto err_exit;
2388 2390
2389 return 0; 2391 return 0;
diff --git a/drivers/mtd/nand/ndfc.c b/drivers/mtd/nand/ndfc.c
index bbe6d451290d..ea2dea8a9c88 100644
--- a/drivers/mtd/nand/ndfc.c
+++ b/drivers/mtd/nand/ndfc.c
@@ -33,6 +33,7 @@
33#include <linux/of_platform.h> 33#include <linux/of_platform.h>
34#include <asm/io.h> 34#include <asm/io.h>
35 35
36#define NDFC_MAX_CS 4
36 37
37struct ndfc_controller { 38struct ndfc_controller {
38 struct platform_device *ofdev; 39 struct platform_device *ofdev;
@@ -41,17 +42,16 @@ struct ndfc_controller {
41 struct nand_chip chip; 42 struct nand_chip chip;
42 int chip_select; 43 int chip_select;
43 struct nand_hw_control ndfc_control; 44 struct nand_hw_control ndfc_control;
44#ifdef CONFIG_MTD_PARTITIONS
45 struct mtd_partition *parts; 45 struct mtd_partition *parts;
46#endif
47}; 46};
48 47
49static struct ndfc_controller ndfc_ctrl; 48static struct ndfc_controller ndfc_ctrl[NDFC_MAX_CS];
50 49
51static void ndfc_select_chip(struct mtd_info *mtd, int chip) 50static void ndfc_select_chip(struct mtd_info *mtd, int chip)
52{ 51{
53 uint32_t ccr; 52 uint32_t ccr;
54 struct ndfc_controller *ndfc = &ndfc_ctrl; 53 struct nand_chip *nchip = mtd->priv;
54 struct ndfc_controller *ndfc = nchip->priv;
55 55
56 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR); 56 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
57 if (chip >= 0) { 57 if (chip >= 0) {
@@ -64,7 +64,8 @@ static void ndfc_select_chip(struct mtd_info *mtd, int chip)
64 64
65static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl) 65static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
66{ 66{
67 struct ndfc_controller *ndfc = &ndfc_ctrl; 67 struct nand_chip *chip = mtd->priv;
68 struct ndfc_controller *ndfc = chip->priv;
68 69
69 if (cmd == NAND_CMD_NONE) 70 if (cmd == NAND_CMD_NONE)
70 return; 71 return;
@@ -77,7 +78,8 @@ static void ndfc_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
77 78
78static int ndfc_ready(struct mtd_info *mtd) 79static int ndfc_ready(struct mtd_info *mtd)
79{ 80{
80 struct ndfc_controller *ndfc = &ndfc_ctrl; 81 struct nand_chip *chip = mtd->priv;
82 struct ndfc_controller *ndfc = chip->priv;
81 83
82 return in_be32(ndfc->ndfcbase + NDFC_STAT) & NDFC_STAT_IS_READY; 84 return in_be32(ndfc->ndfcbase + NDFC_STAT) & NDFC_STAT_IS_READY;
83} 85}
@@ -85,7 +87,8 @@ static int ndfc_ready(struct mtd_info *mtd)
85static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode) 87static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode)
86{ 88{
87 uint32_t ccr; 89 uint32_t ccr;
88 struct ndfc_controller *ndfc = &ndfc_ctrl; 90 struct nand_chip *chip = mtd->priv;
91 struct ndfc_controller *ndfc = chip->priv;
89 92
90 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR); 93 ccr = in_be32(ndfc->ndfcbase + NDFC_CCR);
91 ccr |= NDFC_CCR_RESET_ECC; 94 ccr |= NDFC_CCR_RESET_ECC;
@@ -96,7 +99,8 @@ static void ndfc_enable_hwecc(struct mtd_info *mtd, int mode)
96static int ndfc_calculate_ecc(struct mtd_info *mtd, 99static int ndfc_calculate_ecc(struct mtd_info *mtd,
97 const u_char *dat, u_char *ecc_code) 100 const u_char *dat, u_char *ecc_code)
98{ 101{
99 struct ndfc_controller *ndfc = &ndfc_ctrl; 102 struct nand_chip *chip = mtd->priv;
103 struct ndfc_controller *ndfc = chip->priv;
100 uint32_t ecc; 104 uint32_t ecc;
101 uint8_t *p = (uint8_t *)&ecc; 105 uint8_t *p = (uint8_t *)&ecc;
102 106
@@ -119,7 +123,8 @@ static int ndfc_calculate_ecc(struct mtd_info *mtd,
119 */ 123 */
120static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) 124static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
121{ 125{
122 struct ndfc_controller *ndfc = &ndfc_ctrl; 126 struct nand_chip *chip = mtd->priv;
127 struct ndfc_controller *ndfc = chip->priv;
123 uint32_t *p = (uint32_t *) buf; 128 uint32_t *p = (uint32_t *) buf;
124 129
125 for(;len > 0; len -= 4) 130 for(;len > 0; len -= 4)
@@ -128,7 +133,8 @@ static void ndfc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
128 133
129static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 134static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
130{ 135{
131 struct ndfc_controller *ndfc = &ndfc_ctrl; 136 struct nand_chip *chip = mtd->priv;
137 struct ndfc_controller *ndfc = chip->priv;
132 uint32_t *p = (uint32_t *) buf; 138 uint32_t *p = (uint32_t *) buf;
133 139
134 for(;len > 0; len -= 4) 140 for(;len > 0; len -= 4)
@@ -137,7 +143,8 @@ static void ndfc_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
137 143
138static int ndfc_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len) 144static int ndfc_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
139{ 145{
140 struct ndfc_controller *ndfc = &ndfc_ctrl; 146 struct nand_chip *chip = mtd->priv;
147 struct ndfc_controller *ndfc = chip->priv;
141 uint32_t *p = (uint32_t *) buf; 148 uint32_t *p = (uint32_t *) buf;
142 149
143 for(;len > 0; len -= 4) 150 for(;len > 0; len -= 4)
@@ -152,13 +159,11 @@ static int ndfc_verify_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
152static int ndfc_chip_init(struct ndfc_controller *ndfc, 159static int ndfc_chip_init(struct ndfc_controller *ndfc,
153 struct device_node *node) 160 struct device_node *node)
154{ 161{
155#ifdef CONFIG_MTD_PARTITIONS
156#ifdef CONFIG_MTD_CMDLINE_PARTS 162#ifdef CONFIG_MTD_CMDLINE_PARTS
157 static const char *part_types[] = { "cmdlinepart", NULL }; 163 static const char *part_types[] = { "cmdlinepart", NULL };
158#else 164#else
159 static const char *part_types[] = { NULL }; 165 static const char *part_types[] = { NULL };
160#endif 166#endif
161#endif
162 struct device_node *flash_np; 167 struct device_node *flash_np;
163 struct nand_chip *chip = &ndfc->chip; 168 struct nand_chip *chip = &ndfc->chip;
164 int ret; 169 int ret;
@@ -179,6 +184,7 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
179 chip->ecc.mode = NAND_ECC_HW; 184 chip->ecc.mode = NAND_ECC_HW;
180 chip->ecc.size = 256; 185 chip->ecc.size = 256;
181 chip->ecc.bytes = 3; 186 chip->ecc.bytes = 3;
187 chip->priv = ndfc;
182 188
183 ndfc->mtd.priv = chip; 189 ndfc->mtd.priv = chip;
184 ndfc->mtd.owner = THIS_MODULE; 190 ndfc->mtd.owner = THIS_MODULE;
@@ -198,25 +204,18 @@ static int ndfc_chip_init(struct ndfc_controller *ndfc,
198 if (ret) 204 if (ret)
199 goto err; 205 goto err;
200 206
201#ifdef CONFIG_MTD_PARTITIONS
202 ret = parse_mtd_partitions(&ndfc->mtd, part_types, &ndfc->parts, 0); 207 ret = parse_mtd_partitions(&ndfc->mtd, part_types, &ndfc->parts, 0);
203 if (ret < 0) 208 if (ret < 0)
204 goto err; 209 goto err;
205 210
206#ifdef CONFIG_MTD_OF_PARTS
207 if (ret == 0) { 211 if (ret == 0) {
208 ret = of_mtd_parse_partitions(&ndfc->ofdev->dev, flash_np, 212 ret = of_mtd_parse_partitions(&ndfc->ofdev->dev, flash_np,
209 &ndfc->parts); 213 &ndfc->parts);
210 if (ret < 0) 214 if (ret < 0)
211 goto err; 215 goto err;
212 } 216 }
213#endif
214 217
215 if (ret > 0) 218 ret = mtd_device_register(&ndfc->mtd, ndfc->parts, ret);
216 ret = add_mtd_partitions(&ndfc->mtd, ndfc->parts, ret);
217 else
218#endif
219 ret = add_mtd_device(&ndfc->mtd);
220 219
221err: 220err:
222 of_node_put(flash_np); 221 of_node_put(flash_np);
@@ -227,15 +226,10 @@ err:
227 226
228static int __devinit ndfc_probe(struct platform_device *ofdev) 227static int __devinit ndfc_probe(struct platform_device *ofdev)
229{ 228{
230 struct ndfc_controller *ndfc = &ndfc_ctrl; 229 struct ndfc_controller *ndfc;
231 const __be32 *reg; 230 const __be32 *reg;
232 u32 ccr; 231 u32 ccr;
233 int err, len; 232 int err, len, cs;
234
235 spin_lock_init(&ndfc->ndfc_control.lock);
236 init_waitqueue_head(&ndfc->ndfc_control.wq);
237 ndfc->ofdev = ofdev;
238 dev_set_drvdata(&ofdev->dev, ndfc);
239 233
240 /* Read the reg property to get the chip select */ 234 /* Read the reg property to get the chip select */
241 reg = of_get_property(ofdev->dev.of_node, "reg", &len); 235 reg = of_get_property(ofdev->dev.of_node, "reg", &len);
@@ -243,7 +237,20 @@ static int __devinit ndfc_probe(struct platform_device *ofdev)
243 dev_err(&ofdev->dev, "unable read reg property (%d)\n", len); 237 dev_err(&ofdev->dev, "unable read reg property (%d)\n", len);
244 return -ENOENT; 238 return -ENOENT;
245 } 239 }
246 ndfc->chip_select = be32_to_cpu(reg[0]); 240
241 cs = be32_to_cpu(reg[0]);
242 if (cs >= NDFC_MAX_CS) {
243 dev_err(&ofdev->dev, "invalid CS number (%d)\n", cs);
244 return -EINVAL;
245 }
246
247 ndfc = &ndfc_ctrl[cs];
248 ndfc->chip_select = cs;
249
250 spin_lock_init(&ndfc->ndfc_control.lock);
251 init_waitqueue_head(&ndfc->ndfc_control.wq);
252 ndfc->ofdev = ofdev;
253 dev_set_drvdata(&ofdev->dev, ndfc);
247 254
248 ndfc->ndfcbase = of_iomap(ofdev->dev.of_node, 0); 255 ndfc->ndfcbase = of_iomap(ofdev->dev.of_node, 0);
249 if (!ndfc->ndfcbase) { 256 if (!ndfc->ndfcbase) {
diff --git a/drivers/mtd/nand/nomadik_nand.c b/drivers/mtd/nand/nomadik_nand.c
index a045a4a581b6..b6a5c86ab31e 100644
--- a/drivers/mtd/nand/nomadik_nand.c
+++ b/drivers/mtd/nand/nomadik_nand.c
@@ -158,12 +158,7 @@ static int nomadik_nand_probe(struct platform_device *pdev)
158 goto err_unmap; 158 goto err_unmap;
159 } 159 }
160 160
161#ifdef CONFIG_MTD_PARTITIONS 161 mtd_device_register(&host->mtd, pdata->parts, pdata->nparts);
162 add_mtd_partitions(&host->mtd, pdata->parts, pdata->nparts);
163#else
164 pr_info("Registering %s as whole device\n", mtd->name);
165 add_mtd_device(mtd);
166#endif
167 162
168 platform_set_drvdata(pdev, host); 163 platform_set_drvdata(pdev, host);
169 return 0; 164 return 0;
diff --git a/drivers/mtd/nand/nuc900_nand.c b/drivers/mtd/nand/nuc900_nand.c
index 6eddf7361ed7..9c30a0b03171 100644
--- a/drivers/mtd/nand/nuc900_nand.c
+++ b/drivers/mtd/nand/nuc900_nand.c
@@ -321,8 +321,8 @@ static int __devinit nuc900_nand_probe(struct platform_device *pdev)
321 goto fail3; 321 goto fail3;
322 } 322 }
323 323
324 add_mtd_partitions(&(nuc900_nand->mtd), partitions, 324 mtd_device_register(&(nuc900_nand->mtd), partitions,
325 ARRAY_SIZE(partitions)); 325 ARRAY_SIZE(partitions));
326 326
327 platform_set_drvdata(pdev, nuc900_nand); 327 platform_set_drvdata(pdev, nuc900_nand);
328 328
diff --git a/drivers/mtd/nand/omap2.c b/drivers/mtd/nand/omap2.c
index da9a351c9d79..0db2c0e7656a 100644
--- a/drivers/mtd/nand/omap2.c
+++ b/drivers/mtd/nand/omap2.c
@@ -94,9 +94,7 @@
94#define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0) 94#define P4e_s(a) (TF(a & NAND_Ecc_P4e) << 0)
95#define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1) 95#define P4o_s(a) (TF(a & NAND_Ecc_P4o) << 1)
96 96
97#ifdef CONFIG_MTD_PARTITIONS
98static const char *part_probes[] = { "cmdlinepart", NULL }; 97static const char *part_probes[] = { "cmdlinepart", NULL };
99#endif
100 98
101/* oob info generated runtime depending on ecc algorithm and layout selected */ 99/* oob info generated runtime depending on ecc algorithm and layout selected */
102static struct nand_ecclayout omap_oobinfo; 100static struct nand_ecclayout omap_oobinfo;
@@ -263,11 +261,10 @@ static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
263 if (ret) { 261 if (ret) {
264 /* PFPW engine is busy, use cpu copy method */ 262 /* PFPW engine is busy, use cpu copy method */
265 if (info->nand.options & NAND_BUSWIDTH_16) 263 if (info->nand.options & NAND_BUSWIDTH_16)
266 omap_read_buf16(mtd, buf, len); 264 omap_read_buf16(mtd, (u_char *)p, len);
267 else 265 else
268 omap_read_buf8(mtd, buf, len); 266 omap_read_buf8(mtd, (u_char *)p, len);
269 } else { 267 } else {
270 p = (u32 *) buf;
271 do { 268 do {
272 r_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT); 269 r_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
273 r_count = r_count >> 2; 270 r_count = r_count >> 2;
@@ -293,7 +290,7 @@ static void omap_write_buf_pref(struct mtd_info *mtd,
293 struct omap_nand_info, mtd); 290 struct omap_nand_info, mtd);
294 uint32_t w_count = 0; 291 uint32_t w_count = 0;
295 int i = 0, ret = 0; 292 int i = 0, ret = 0;
296 u16 *p; 293 u16 *p = (u16 *)buf;
297 unsigned long tim, limit; 294 unsigned long tim, limit;
298 295
299 /* take care of subpage writes */ 296 /* take care of subpage writes */
@@ -309,11 +306,10 @@ static void omap_write_buf_pref(struct mtd_info *mtd,
309 if (ret) { 306 if (ret) {
310 /* PFPW engine is busy, use cpu copy method */ 307 /* PFPW engine is busy, use cpu copy method */
311 if (info->nand.options & NAND_BUSWIDTH_16) 308 if (info->nand.options & NAND_BUSWIDTH_16)
312 omap_write_buf16(mtd, buf, len); 309 omap_write_buf16(mtd, (u_char *)p, len);
313 else 310 else
314 omap_write_buf8(mtd, buf, len); 311 omap_write_buf8(mtd, (u_char *)p, len);
315 } else { 312 } else {
316 p = (u16 *) buf;
317 while (len) { 313 while (len) {
318 w_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT); 314 w_count = gpmc_read_status(GPMC_PREFETCH_FIFO_CNT);
319 w_count = w_count >> 1; 315 w_count = w_count >> 1;
@@ -1073,9 +1069,9 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1073 /* DIP switches on some boards change between 8 and 16 bit 1069 /* DIP switches on some boards change between 8 and 16 bit
1074 * bus widths for flash. Try the other width if the first try fails. 1070 * bus widths for flash. Try the other width if the first try fails.
1075 */ 1071 */
1076 if (nand_scan(&info->mtd, 1)) { 1072 if (nand_scan_ident(&info->mtd, 1, NULL)) {
1077 info->nand.options ^= NAND_BUSWIDTH_16; 1073 info->nand.options ^= NAND_BUSWIDTH_16;
1078 if (nand_scan(&info->mtd, 1)) { 1074 if (nand_scan_ident(&info->mtd, 1, NULL)) {
1079 err = -ENXIO; 1075 err = -ENXIO;
1080 goto out_release_mem_region; 1076 goto out_release_mem_region;
1081 } 1077 }
@@ -1101,15 +1097,19 @@ static int __devinit omap_nand_probe(struct platform_device *pdev)
1101 info->nand.ecc.layout = &omap_oobinfo; 1097 info->nand.ecc.layout = &omap_oobinfo;
1102 } 1098 }
1103 1099
1104#ifdef CONFIG_MTD_PARTITIONS 1100 /* second phase scan */
1101 if (nand_scan_tail(&info->mtd)) {
1102 err = -ENXIO;
1103 goto out_release_mem_region;
1104 }
1105
1105 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); 1106 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
1106 if (err > 0) 1107 if (err > 0)
1107 add_mtd_partitions(&info->mtd, info->parts, err); 1108 mtd_device_register(&info->mtd, info->parts, err);
1108 else if (pdata->parts) 1109 else if (pdata->parts)
1109 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts); 1110 mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts);
1110 else 1111 else
1111#endif 1112 mtd_device_register(&info->mtd, NULL, 0);
1112 add_mtd_device(&info->mtd);
1113 1113
1114 platform_set_drvdata(pdev, &info->mtd); 1114 platform_set_drvdata(pdev, &info->mtd);
1115 1115
diff --git a/drivers/mtd/nand/orion_nand.c b/drivers/mtd/nand/orion_nand.c
index da6e75343052..7794d0680f91 100644
--- a/drivers/mtd/nand/orion_nand.c
+++ b/drivers/mtd/nand/orion_nand.c
@@ -21,9 +21,7 @@
21#include <mach/hardware.h> 21#include <mach/hardware.h>
22#include <plat/orion_nand.h> 22#include <plat/orion_nand.h>
23 23
24#ifdef CONFIG_MTD_CMDLINE_PARTS
25static const char *part_probes[] = { "cmdlinepart", NULL }; 24static const char *part_probes[] = { "cmdlinepart", NULL };
26#endif
27 25
28static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 26static void orion_nand_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
29{ 27{
@@ -83,10 +81,8 @@ static int __init orion_nand_probe(struct platform_device *pdev)
83 struct resource *res; 81 struct resource *res;
84 void __iomem *io_base; 82 void __iomem *io_base;
85 int ret = 0; 83 int ret = 0;
86#ifdef CONFIG_MTD_PARTITIONS
87 struct mtd_partition *partitions = NULL; 84 struct mtd_partition *partitions = NULL;
88 int num_part = 0; 85 int num_part = 0;
89#endif
90 86
91 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL); 87 nc = kzalloc(sizeof(struct nand_chip) + sizeof(struct mtd_info), GFP_KERNEL);
92 if (!nc) { 88 if (!nc) {
@@ -136,7 +132,6 @@ static int __init orion_nand_probe(struct platform_device *pdev)
136 goto no_dev; 132 goto no_dev;
137 } 133 }
138 134
139#ifdef CONFIG_MTD_PARTITIONS
140#ifdef CONFIG_MTD_CMDLINE_PARTS 135#ifdef CONFIG_MTD_CMDLINE_PARTS
141 mtd->name = "orion_nand"; 136 mtd->name = "orion_nand";
142 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0); 137 num_part = parse_mtd_partitions(mtd, part_probes, &partitions, 0);
@@ -147,14 +142,7 @@ static int __init orion_nand_probe(struct platform_device *pdev)
147 partitions = board->parts; 142 partitions = board->parts;
148 } 143 }
149 144
150 if (partitions && num_part > 0) 145 ret = mtd_device_register(mtd, partitions, num_part);
151 ret = add_mtd_partitions(mtd, partitions, num_part);
152 else
153 ret = add_mtd_device(mtd);
154#else
155 ret = add_mtd_device(mtd);
156#endif
157
158 if (ret) { 146 if (ret) {
159 nand_release(mtd); 147 nand_release(mtd);
160 goto no_dev; 148 goto no_dev;
diff --git a/drivers/mtd/nand/pasemi_nand.c b/drivers/mtd/nand/pasemi_nand.c
index 20bfe5f15afd..b1aa41b8a4eb 100644
--- a/drivers/mtd/nand/pasemi_nand.c
+++ b/drivers/mtd/nand/pasemi_nand.c
@@ -163,7 +163,7 @@ static int __devinit pasemi_nand_probe(struct platform_device *ofdev)
163 goto out_lpc; 163 goto out_lpc;
164 } 164 }
165 165
166 if (add_mtd_device(pasemi_nand_mtd)) { 166 if (mtd_device_register(pasemi_nand_mtd, NULL, 0)) {
167 printk(KERN_ERR "pasemi_nand: Unable to register MTD device\n"); 167 printk(KERN_ERR "pasemi_nand: Unable to register MTD device\n");
168 err = -ENODEV; 168 err = -ENODEV;
169 goto out_lpc; 169 goto out_lpc;
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index caf5a736340a..633c04bf76f6 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -21,10 +21,8 @@ struct plat_nand_data {
21 struct nand_chip chip; 21 struct nand_chip chip;
22 struct mtd_info mtd; 22 struct mtd_info mtd;
23 void __iomem *io_base; 23 void __iomem *io_base;
24#ifdef CONFIG_MTD_PARTITIONS
25 int nr_parts; 24 int nr_parts;
26 struct mtd_partition *parts; 25 struct mtd_partition *parts;
27#endif
28}; 26};
29 27
30/* 28/*
@@ -101,13 +99,12 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
101 goto out; 99 goto out;
102 } 100 }
103 101
104#ifdef CONFIG_MTD_PARTITIONS
105 if (pdata->chip.part_probe_types) { 102 if (pdata->chip.part_probe_types) {
106 err = parse_mtd_partitions(&data->mtd, 103 err = parse_mtd_partitions(&data->mtd,
107 pdata->chip.part_probe_types, 104 pdata->chip.part_probe_types,
108 &data->parts, 0); 105 &data->parts, 0);
109 if (err > 0) { 106 if (err > 0) {
110 add_mtd_partitions(&data->mtd, data->parts, err); 107 mtd_device_register(&data->mtd, data->parts, err);
111 return 0; 108 return 0;
112 } 109 }
113 } 110 }
@@ -115,11 +112,10 @@ static int __devinit plat_nand_probe(struct platform_device *pdev)
115 pdata->chip.set_parts(data->mtd.size, &pdata->chip); 112 pdata->chip.set_parts(data->mtd.size, &pdata->chip);
116 if (pdata->chip.partitions) { 113 if (pdata->chip.partitions) {
117 data->parts = pdata->chip.partitions; 114 data->parts = pdata->chip.partitions;
118 err = add_mtd_partitions(&data->mtd, data->parts, 115 err = mtd_device_register(&data->mtd, data->parts,
119 pdata->chip.nr_partitions); 116 pdata->chip.nr_partitions);
120 } else 117 } else
121#endif 118 err = mtd_device_register(&data->mtd, NULL, 0);
122 err = add_mtd_device(&data->mtd);
123 119
124 if (!err) 120 if (!err)
125 return err; 121 return err;
@@ -149,10 +145,8 @@ static int __devexit plat_nand_remove(struct platform_device *pdev)
149 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 145 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
150 146
151 nand_release(&data->mtd); 147 nand_release(&data->mtd);
152#ifdef CONFIG_MTD_PARTITIONS
153 if (data->parts && data->parts != pdata->chip.partitions) 148 if (data->parts && data->parts != pdata->chip.partitions)
154 kfree(data->parts); 149 kfree(data->parts);
155#endif
156 if (pdata->ctrl.remove) 150 if (pdata->ctrl.remove)
157 pdata->ctrl.remove(pdev); 151 pdata->ctrl.remove(pdev);
158 iounmap(data->io_base); 152 iounmap(data->io_base);
diff --git a/drivers/mtd/nand/ppchameleonevb.c b/drivers/mtd/nand/ppchameleonevb.c
index cc8658431851..3bbb796b451c 100644
--- a/drivers/mtd/nand/ppchameleonevb.c
+++ b/drivers/mtd/nand/ppchameleonevb.c
@@ -73,7 +73,6 @@ __setup("ppchameleon_fio_pbase=", ppchameleon_fio_pbase);
73__setup("ppchameleonevb_fio_pbase=", ppchameleonevb_fio_pbase); 73__setup("ppchameleonevb_fio_pbase=", ppchameleonevb_fio_pbase);
74#endif 74#endif
75 75
76#ifdef CONFIG_MTD_PARTITIONS
77/* 76/*
78 * Define static partitions for flash devices 77 * Define static partitions for flash devices
79 */ 78 */
@@ -101,7 +100,6 @@ static struct mtd_partition partition_info_evb[] = {
101#define NUM_PARTITIONS 1 100#define NUM_PARTITIONS 1
102 101
103extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id); 102extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, const char *mtd_id);
104#endif
105 103
106/* 104/*
107 * hardware specific access to control-lines 105 * hardware specific access to control-lines
@@ -189,10 +187,8 @@ static int ppchameleonevb_device_ready(struct mtd_info *minfo)
189} 187}
190#endif 188#endif
191 189
192#ifdef CONFIG_MTD_PARTITIONS
193const char *part_probes[] = { "cmdlinepart", NULL }; 190const char *part_probes[] = { "cmdlinepart", NULL };
194const char *part_probes_evb[] = { "cmdlinepart", NULL }; 191const char *part_probes_evb[] = { "cmdlinepart", NULL };
195#endif
196 192
197/* 193/*
198 * Main initialization routine 194 * Main initialization routine
@@ -284,14 +280,13 @@ static int __init ppchameleonevb_init(void)
284 this->chip_delay = NAND_SMALL_DELAY_US; 280 this->chip_delay = NAND_SMALL_DELAY_US;
285#endif 281#endif
286 282
287#ifdef CONFIG_MTD_PARTITIONS
288 ppchameleon_mtd->name = "ppchameleon-nand"; 283 ppchameleon_mtd->name = "ppchameleon-nand";
289 mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0); 284 mtd_parts_nb = parse_mtd_partitions(ppchameleon_mtd, part_probes, &mtd_parts, 0);
290 if (mtd_parts_nb > 0) 285 if (mtd_parts_nb > 0)
291 part_type = "command line"; 286 part_type = "command line";
292 else 287 else
293 mtd_parts_nb = 0; 288 mtd_parts_nb = 0;
294#endif 289
295 if (mtd_parts_nb == 0) { 290 if (mtd_parts_nb == 0) {
296 if (ppchameleon_mtd->size == NAND_SMALL_SIZE) 291 if (ppchameleon_mtd->size == NAND_SMALL_SIZE)
297 mtd_parts = partition_info_me; 292 mtd_parts = partition_info_me;
@@ -303,7 +298,7 @@ static int __init ppchameleonevb_init(void)
303 298
304 /* Register the partitions */ 299 /* Register the partitions */
305 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 300 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
306 add_mtd_partitions(ppchameleon_mtd, mtd_parts, mtd_parts_nb); 301 mtd_device_register(ppchameleon_mtd, mtd_parts, mtd_parts_nb);
307 302
308 nand_evb_init: 303 nand_evb_init:
309 /**************************** 304 /****************************
@@ -385,14 +380,14 @@ static int __init ppchameleonevb_init(void)
385 iounmap(ppchameleon_fio_base); 380 iounmap(ppchameleon_fio_base);
386 return -ENXIO; 381 return -ENXIO;
387 } 382 }
388#ifdef CONFIG_MTD_PARTITIONS 383
389 ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME; 384 ppchameleonevb_mtd->name = NAND_EVB_MTD_NAME;
390 mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0); 385 mtd_parts_nb = parse_mtd_partitions(ppchameleonevb_mtd, part_probes_evb, &mtd_parts, 0);
391 if (mtd_parts_nb > 0) 386 if (mtd_parts_nb > 0)
392 part_type = "command line"; 387 part_type = "command line";
393 else 388 else
394 mtd_parts_nb = 0; 389 mtd_parts_nb = 0;
395#endif 390
396 if (mtd_parts_nb == 0) { 391 if (mtd_parts_nb == 0) {
397 mtd_parts = partition_info_evb; 392 mtd_parts = partition_info_evb;
398 mtd_parts_nb = NUM_PARTITIONS; 393 mtd_parts_nb = NUM_PARTITIONS;
@@ -401,7 +396,7 @@ static int __init ppchameleonevb_init(void)
401 396
402 /* Register the partitions */ 397 /* Register the partitions */
403 printk(KERN_NOTICE "Using %s partition definition\n", part_type); 398 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
404 add_mtd_partitions(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb); 399 mtd_device_register(ppchameleonevb_mtd, mtd_parts, mtd_parts_nb);
405 400
406 /* Return happy */ 401 /* Return happy */
407 return 0; 402 return 0;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index ff0701276d65..1fb3b3a80581 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -1119,10 +1119,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1119 clk_put(info->clk); 1119 clk_put(info->clk);
1120 1120
1121 if (mtd) { 1121 if (mtd) {
1122 del_mtd_device(mtd); 1122 mtd_device_unregister(mtd);
1123#ifdef CONFIG_MTD_PARTITIONS
1124 del_mtd_partitions(mtd);
1125#endif
1126 kfree(mtd); 1123 kfree(mtd);
1127 } 1124 }
1128 return 0; 1125 return 0;
@@ -1149,7 +1146,6 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1149 return -ENODEV; 1146 return -ENODEV;
1150 } 1147 }
1151 1148
1152#ifdef CONFIG_MTD_PARTITIONS
1153 if (mtd_has_cmdlinepart()) { 1149 if (mtd_has_cmdlinepart()) {
1154 const char *probes[] = { "cmdlinepart", NULL }; 1150 const char *probes[] = { "cmdlinepart", NULL };
1155 struct mtd_partition *parts; 1151 struct mtd_partition *parts;
@@ -1158,13 +1154,10 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1158 nr_parts = parse_mtd_partitions(info->mtd, probes, &parts, 0); 1154 nr_parts = parse_mtd_partitions(info->mtd, probes, &parts, 0);
1159 1155
1160 if (nr_parts) 1156 if (nr_parts)
1161 return add_mtd_partitions(info->mtd, parts, nr_parts); 1157 return mtd_device_register(info->mtd, parts, nr_parts);
1162 } 1158 }
1163 1159
1164 return add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); 1160 return mtd_device_register(info->mtd, pdata->parts, pdata->nr_parts);
1165#else
1166 return 0;
1167#endif
1168} 1161}
1169 1162
1170#ifdef CONFIG_PM 1163#ifdef CONFIG_PM
diff --git a/drivers/mtd/nand/rtc_from4.c b/drivers/mtd/nand/rtc_from4.c
index 67440b5beef8..c9f9127ff770 100644
--- a/drivers/mtd/nand/rtc_from4.c
+++ b/drivers/mtd/nand/rtc_from4.c
@@ -580,7 +580,8 @@ static int __init rtc_from4_init(void)
580#endif 580#endif
581 581
582 /* Register the partitions */ 582 /* Register the partitions */
583 ret = add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS); 583 ret = mtd_device_register(rtc_from4_mtd, partition_info,
584 NUM_PARTITIONS);
584 if (ret) 585 if (ret)
585 goto err_3; 586 goto err_3;
586 587
diff --git a/drivers/mtd/nand/s3c2410.c b/drivers/mtd/nand/s3c2410.c
index 33d832dddfdd..4405468f196b 100644
--- a/drivers/mtd/nand/s3c2410.c
+++ b/drivers/mtd/nand/s3c2410.c
@@ -55,7 +55,7 @@ static int hardware_ecc = 0;
55#endif 55#endif
56 56
57#ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP 57#ifdef CONFIG_MTD_NAND_S3C2410_CLKSTOP
58static int clock_stop = 1; 58static const int clock_stop = 1;
59#else 59#else
60static const int clock_stop = 0; 60static const int clock_stop = 0;
61#endif 61#endif
@@ -96,6 +96,12 @@ enum s3c_cpu_type {
96 TYPE_S3C2440, 96 TYPE_S3C2440,
97}; 97};
98 98
99enum s3c_nand_clk_state {
100 CLOCK_DISABLE = 0,
101 CLOCK_ENABLE,
102 CLOCK_SUSPEND,
103};
104
99/* overview of the s3c2410 nand state */ 105/* overview of the s3c2410 nand state */
100 106
101/** 107/**
@@ -111,6 +117,7 @@ enum s3c_cpu_type {
111 * @mtd_count: The number of MTDs created from this controller. 117 * @mtd_count: The number of MTDs created from this controller.
112 * @save_sel: The contents of @sel_reg to be saved over suspend. 118 * @save_sel: The contents of @sel_reg to be saved over suspend.
113 * @clk_rate: The clock rate from @clk. 119 * @clk_rate: The clock rate from @clk.
120 * @clk_state: The current clock state.
114 * @cpu_type: The exact type of this controller. 121 * @cpu_type: The exact type of this controller.
115 */ 122 */
116struct s3c2410_nand_info { 123struct s3c2410_nand_info {
@@ -129,6 +136,7 @@ struct s3c2410_nand_info {
129 int mtd_count; 136 int mtd_count;
130 unsigned long save_sel; 137 unsigned long save_sel;
131 unsigned long clk_rate; 138 unsigned long clk_rate;
139 enum s3c_nand_clk_state clk_state;
132 140
133 enum s3c_cpu_type cpu_type; 141 enum s3c_cpu_type cpu_type;
134 142
@@ -159,11 +167,33 @@ static struct s3c2410_platform_nand *to_nand_plat(struct platform_device *dev)
159 return dev->dev.platform_data; 167 return dev->dev.platform_data;
160} 168}
161 169
162static inline int allow_clk_stop(struct s3c2410_nand_info *info) 170static inline int allow_clk_suspend(struct s3c2410_nand_info *info)
163{ 171{
164 return clock_stop; 172 return clock_stop;
165} 173}
166 174
175/**
176 * s3c2410_nand_clk_set_state - Enable, disable or suspend NAND clock.
177 * @info: The controller instance.
178 * @new_state: State to which clock should be set.
179 */
180static void s3c2410_nand_clk_set_state(struct s3c2410_nand_info *info,
181 enum s3c_nand_clk_state new_state)
182{
183 if (!allow_clk_suspend(info) && new_state == CLOCK_SUSPEND)
184 return;
185
186 if (info->clk_state == CLOCK_ENABLE) {
187 if (new_state != CLOCK_ENABLE)
188 clk_disable(info->clk);
189 } else {
190 if (new_state == CLOCK_ENABLE)
191 clk_enable(info->clk);
192 }
193
194 info->clk_state = new_state;
195}
196
167/* timing calculations */ 197/* timing calculations */
168 198
169#define NS_IN_KHZ 1000000 199#define NS_IN_KHZ 1000000
@@ -333,8 +363,8 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
333 nmtd = this->priv; 363 nmtd = this->priv;
334 info = nmtd->info; 364 info = nmtd->info;
335 365
336 if (chip != -1 && allow_clk_stop(info)) 366 if (chip != -1)
337 clk_enable(info->clk); 367 s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
338 368
339 cur = readl(info->sel_reg); 369 cur = readl(info->sel_reg);
340 370
@@ -356,8 +386,8 @@ static void s3c2410_nand_select_chip(struct mtd_info *mtd, int chip)
356 386
357 writel(cur, info->sel_reg); 387 writel(cur, info->sel_reg);
358 388
359 if (chip == -1 && allow_clk_stop(info)) 389 if (chip == -1)
360 clk_disable(info->clk); 390 s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
361} 391}
362 392
363/* s3c2410_nand_hwcontrol 393/* s3c2410_nand_hwcontrol
@@ -694,8 +724,7 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
694 /* free the common resources */ 724 /* free the common resources */
695 725
696 if (info->clk != NULL && !IS_ERR(info->clk)) { 726 if (info->clk != NULL && !IS_ERR(info->clk)) {
697 if (!allow_clk_stop(info)) 727 s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
698 clk_disable(info->clk);
699 clk_put(info->clk); 728 clk_put(info->clk);
700 } 729 }
701 730
@@ -715,7 +744,6 @@ static int s3c24xx_nand_remove(struct platform_device *pdev)
715 return 0; 744 return 0;
716} 745}
717 746
718#ifdef CONFIG_MTD_PARTITIONS
719const char *part_probes[] = { "cmdlinepart", NULL }; 747const char *part_probes[] = { "cmdlinepart", NULL };
720static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info, 748static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
721 struct s3c2410_nand_mtd *mtd, 749 struct s3c2410_nand_mtd *mtd,
@@ -725,7 +753,7 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
725 int nr_part = 0; 753 int nr_part = 0;
726 754
727 if (set == NULL) 755 if (set == NULL)
728 return add_mtd_device(&mtd->mtd); 756 return mtd_device_register(&mtd->mtd, NULL, 0);
729 757
730 mtd->mtd.name = set->name; 758 mtd->mtd.name = set->name;
731 nr_part = parse_mtd_partitions(&mtd->mtd, part_probes, &part_info, 0); 759 nr_part = parse_mtd_partitions(&mtd->mtd, part_probes, &part_info, 0);
@@ -735,19 +763,8 @@ static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
735 part_info = set->partitions; 763 part_info = set->partitions;
736 } 764 }
737 765
738 if (nr_part > 0 && part_info) 766 return mtd_device_register(&mtd->mtd, part_info, nr_part);
739 return add_mtd_partitions(&mtd->mtd, part_info, nr_part);
740
741 return add_mtd_device(&mtd->mtd);
742}
743#else
744static int s3c2410_nand_add_partition(struct s3c2410_nand_info *info,
745 struct s3c2410_nand_mtd *mtd,
746 struct s3c2410_nand_set *set)
747{
748 return add_mtd_device(&mtd->mtd);
749} 767}
750#endif
751 768
752/** 769/**
753 * s3c2410_nand_init_chip - initialise a single instance of an chip 770 * s3c2410_nand_init_chip - initialise a single instance of an chip
@@ -947,7 +964,7 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
947 goto exit_error; 964 goto exit_error;
948 } 965 }
949 966
950 clk_enable(info->clk); 967 s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
951 968
952 /* allocate and map the resource */ 969 /* allocate and map the resource */
953 970
@@ -1026,9 +1043,9 @@ static int s3c24xx_nand_probe(struct platform_device *pdev)
1026 goto exit_error; 1043 goto exit_error;
1027 } 1044 }
1028 1045
1029 if (allow_clk_stop(info)) { 1046 if (allow_clk_suspend(info)) {
1030 dev_info(&pdev->dev, "clock idle support enabled\n"); 1047 dev_info(&pdev->dev, "clock idle support enabled\n");
1031 clk_disable(info->clk); 1048 s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
1032 } 1049 }
1033 1050
1034 pr_debug("initialised ok\n"); 1051 pr_debug("initialised ok\n");
@@ -1059,8 +1076,7 @@ static int s3c24xx_nand_suspend(struct platform_device *dev, pm_message_t pm)
1059 1076
1060 writel(info->save_sel | info->sel_bit, info->sel_reg); 1077 writel(info->save_sel | info->sel_bit, info->sel_reg);
1061 1078
1062 if (!allow_clk_stop(info)) 1079 s3c2410_nand_clk_set_state(info, CLOCK_DISABLE);
1063 clk_disable(info->clk);
1064 } 1080 }
1065 1081
1066 return 0; 1082 return 0;
@@ -1072,7 +1088,7 @@ static int s3c24xx_nand_resume(struct platform_device *dev)
1072 unsigned long sel; 1088 unsigned long sel;
1073 1089
1074 if (info) { 1090 if (info) {
1075 clk_enable(info->clk); 1091 s3c2410_nand_clk_set_state(info, CLOCK_ENABLE);
1076 s3c2410_nand_inithw(info); 1092 s3c2410_nand_inithw(info);
1077 1093
1078 /* Restore the state of the nFCE line. */ 1094 /* Restore the state of the nFCE line. */
@@ -1082,8 +1098,7 @@ static int s3c24xx_nand_resume(struct platform_device *dev)
1082 sel |= info->save_sel & info->sel_bit; 1098 sel |= info->save_sel & info->sel_bit;
1083 writel(sel, info->sel_reg); 1099 writel(sel, info->sel_reg);
1084 1100
1085 if (allow_clk_stop(info)) 1101 s3c2410_nand_clk_set_state(info, CLOCK_SUSPEND);
1086 clk_disable(info->clk);
1087 } 1102 }
1088 1103
1089 return 0; 1104 return 0;
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 81bbb5ee148d..93b1f74321c2 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -867,7 +867,7 @@ static int __devinit flctl_probe(struct platform_device *pdev)
867 if (ret) 867 if (ret)
868 goto err; 868 goto err;
869 869
870 add_mtd_partitions(flctl_mtd, pdata->parts, pdata->nr_parts); 870 mtd_device_register(flctl_mtd, pdata->parts, pdata->nr_parts);
871 871
872 return 0; 872 return 0;
873 873
diff --git a/drivers/mtd/nand/sharpsl.c b/drivers/mtd/nand/sharpsl.c
index 54ec7542a7b7..19e24ed089ea 100644
--- a/drivers/mtd/nand/sharpsl.c
+++ b/drivers/mtd/nand/sharpsl.c
@@ -103,9 +103,7 @@ static int sharpsl_nand_calculate_ecc(struct mtd_info *mtd, const u_char * dat,
103 return readb(sharpsl->io + ECCCNTR) != 0; 103 return readb(sharpsl->io + ECCCNTR) != 0;
104} 104}
105 105
106#ifdef CONFIG_MTD_PARTITIONS
107static const char *part_probes[] = { "cmdlinepart", NULL }; 106static const char *part_probes[] = { "cmdlinepart", NULL };
108#endif
109 107
110/* 108/*
111 * Main initialization routine 109 * Main initialization routine
@@ -113,10 +111,8 @@ static const char *part_probes[] = { "cmdlinepart", NULL };
113static int __devinit sharpsl_nand_probe(struct platform_device *pdev) 111static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
114{ 112{
115 struct nand_chip *this; 113 struct nand_chip *this;
116#ifdef CONFIG_MTD_PARTITIONS
117 struct mtd_partition *sharpsl_partition_info; 114 struct mtd_partition *sharpsl_partition_info;
118 int nr_partitions; 115 int nr_partitions;
119#endif
120 struct resource *r; 116 struct resource *r;
121 int err = 0; 117 int err = 0;
122 struct sharpsl_nand *sharpsl; 118 struct sharpsl_nand *sharpsl;
@@ -188,18 +184,14 @@ static int __devinit sharpsl_nand_probe(struct platform_device *pdev)
188 184
189 /* Register the partitions */ 185 /* Register the partitions */
190 sharpsl->mtd.name = "sharpsl-nand"; 186 sharpsl->mtd.name = "sharpsl-nand";
191#ifdef CONFIG_MTD_PARTITIONS
192 nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0); 187 nr_partitions = parse_mtd_partitions(&sharpsl->mtd, part_probes, &sharpsl_partition_info, 0);
193 if (nr_partitions <= 0) { 188 if (nr_partitions <= 0) {
194 nr_partitions = data->nr_partitions; 189 nr_partitions = data->nr_partitions;
195 sharpsl_partition_info = data->partitions; 190 sharpsl_partition_info = data->partitions;
196 } 191 }
197 192
198 if (nr_partitions > 0) 193 err = mtd_device_register(&sharpsl->mtd, sharpsl_partition_info,
199 err = add_mtd_partitions(&sharpsl->mtd, sharpsl_partition_info, nr_partitions); 194 nr_partitions);
200 else
201#endif
202 err = add_mtd_device(&sharpsl->mtd);
203 if (err) 195 if (err)
204 goto err_add; 196 goto err_add;
205 197
diff --git a/drivers/mtd/nand/sm_common.c b/drivers/mtd/nand/sm_common.c
index 57cc80cd01a3..b6332e83b289 100644
--- a/drivers/mtd/nand/sm_common.c
+++ b/drivers/mtd/nand/sm_common.c
@@ -139,7 +139,7 @@ int sm_register_device(struct mtd_info *mtd, int smartmedia)
139 if (ret) 139 if (ret)
140 return ret; 140 return ret;
141 141
142 return add_mtd_device(mtd); 142 return mtd_device_register(mtd, NULL, 0);
143} 143}
144EXPORT_SYMBOL_GPL(sm_register_device); 144EXPORT_SYMBOL_GPL(sm_register_device);
145 145
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
index a853548986f0..ca2d0555729e 100644
--- a/drivers/mtd/nand/socrates_nand.c
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -155,9 +155,7 @@ static int socrates_nand_device_ready(struct mtd_info *mtd)
155 return 1; 155 return 1;
156} 156}
157 157
158#ifdef CONFIG_MTD_PARTITIONS
159static const char *part_probes[] = { "cmdlinepart", NULL }; 158static const char *part_probes[] = { "cmdlinepart", NULL };
160#endif
161 159
162/* 160/*
163 * Probe for the NAND device. 161 * Probe for the NAND device.
@@ -168,11 +166,8 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
168 struct mtd_info *mtd; 166 struct mtd_info *mtd;
169 struct nand_chip *nand_chip; 167 struct nand_chip *nand_chip;
170 int res; 168 int res;
171
172#ifdef CONFIG_MTD_PARTITIONS
173 struct mtd_partition *partitions = NULL; 169 struct mtd_partition *partitions = NULL;
174 int num_partitions = 0; 170 int num_partitions = 0;
175#endif
176 171
177 /* Allocate memory for the device structure (and zero it) */ 172 /* Allocate memory for the device structure (and zero it) */
178 host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL); 173 host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL);
@@ -230,7 +225,6 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
230 goto out; 225 goto out;
231 } 226 }
232 227
233#ifdef CONFIG_MTD_PARTITIONS
234#ifdef CONFIG_MTD_CMDLINE_PARTS 228#ifdef CONFIG_MTD_CMDLINE_PARTS
235 num_partitions = parse_mtd_partitions(mtd, part_probes, 229 num_partitions = parse_mtd_partitions(mtd, part_probes,
236 &partitions, 0); 230 &partitions, 0);
@@ -240,7 +234,6 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
240 } 234 }
241#endif 235#endif
242 236
243#ifdef CONFIG_MTD_OF_PARTS
244 if (num_partitions == 0) { 237 if (num_partitions == 0) {
245 num_partitions = of_mtd_parse_partitions(&ofdev->dev, 238 num_partitions = of_mtd_parse_partitions(&ofdev->dev,
246 ofdev->dev.of_node, 239 ofdev->dev.of_node,
@@ -250,19 +243,12 @@ static int __devinit socrates_nand_probe(struct platform_device *ofdev)
250 goto release; 243 goto release;
251 } 244 }
252 } 245 }
253#endif
254 if (partitions && (num_partitions > 0))
255 res = add_mtd_partitions(mtd, partitions, num_partitions);
256 else
257#endif
258 res = add_mtd_device(mtd);
259 246
247 res = mtd_device_register(mtd, partitions, num_partitions);
260 if (!res) 248 if (!res)
261 return res; 249 return res;
262 250
263#ifdef CONFIG_MTD_PARTITIONS
264release: 251release:
265#endif
266 nand_release(mtd); 252 nand_release(mtd);
267 253
268out: 254out:
diff --git a/drivers/mtd/nand/spia.c b/drivers/mtd/nand/spia.c
index 0cc6d0acb8fe..bef76cd7c24c 100644
--- a/drivers/mtd/nand/spia.c
+++ b/drivers/mtd/nand/spia.c
@@ -149,7 +149,7 @@ static int __init spia_init(void)
149 } 149 }
150 150
151 /* Register the partitions */ 151 /* Register the partitions */
152 add_mtd_partitions(spia_mtd, partition_info, NUM_PARTITIONS); 152 mtd_device_register(spia_mtd, partition_info, NUM_PARTITIONS);
153 153
154 /* Return happy */ 154 /* Return happy */
155 return 0; 155 return 0;
diff --git a/drivers/mtd/nand/tmio_nand.c b/drivers/mtd/nand/tmio_nand.c
index c004e474631b..11e8371b5683 100644
--- a/drivers/mtd/nand/tmio_nand.c
+++ b/drivers/mtd/nand/tmio_nand.c
@@ -381,10 +381,8 @@ static int tmio_probe(struct platform_device *dev)
381 struct tmio_nand *tmio; 381 struct tmio_nand *tmio;
382 struct mtd_info *mtd; 382 struct mtd_info *mtd;
383 struct nand_chip *nand_chip; 383 struct nand_chip *nand_chip;
384#ifdef CONFIG_MTD_PARTITIONS
385 struct mtd_partition *parts; 384 struct mtd_partition *parts;
386 int nbparts = 0; 385 int nbparts = 0;
387#endif
388 int retval; 386 int retval;
389 387
390 if (data == NULL) 388 if (data == NULL)
@@ -463,7 +461,6 @@ static int tmio_probe(struct platform_device *dev)
463 goto err_scan; 461 goto err_scan;
464 } 462 }
465 /* Register the partitions */ 463 /* Register the partitions */
466#ifdef CONFIG_MTD_PARTITIONS
467#ifdef CONFIG_MTD_CMDLINE_PARTS 464#ifdef CONFIG_MTD_CMDLINE_PARTS
468 nbparts = parse_mtd_partitions(mtd, part_probes, &parts, 0); 465 nbparts = parse_mtd_partitions(mtd, part_probes, &parts, 0);
469#endif 466#endif
@@ -472,12 +469,7 @@ static int tmio_probe(struct platform_device *dev)
472 nbparts = data->num_partitions; 469 nbparts = data->num_partitions;
473 } 470 }
474 471
475 if (nbparts) 472 retval = mtd_device_register(mtd, parts, nbparts);
476 retval = add_mtd_partitions(mtd, parts, nbparts);
477 else
478#endif
479 retval = add_mtd_device(mtd);
480
481 if (!retval) 473 if (!retval)
482 return retval; 474 return retval;
483 475
diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c
index ca270a4881a4..bfba4e39a6c5 100644
--- a/drivers/mtd/nand/txx9ndfmc.c
+++ b/drivers/mtd/nand/txx9ndfmc.c
@@ -74,9 +74,7 @@ struct txx9ndfmc_drvdata {
74 unsigned char hold; /* in gbusclock */ 74 unsigned char hold; /* in gbusclock */
75 unsigned char spw; /* in gbusclock */ 75 unsigned char spw; /* in gbusclock */
76 struct nand_hw_control hw_control; 76 struct nand_hw_control hw_control;
77#ifdef CONFIG_MTD_PARTITIONS
78 struct mtd_partition *parts[MAX_TXX9NDFMC_DEV]; 77 struct mtd_partition *parts[MAX_TXX9NDFMC_DEV];
79#endif
80}; 78};
81 79
82static struct platform_device *mtd_to_platdev(struct mtd_info *mtd) 80static struct platform_device *mtd_to_platdev(struct mtd_info *mtd)
@@ -289,9 +287,7 @@ static int txx9ndfmc_nand_scan(struct mtd_info *mtd)
289static int __init txx9ndfmc_probe(struct platform_device *dev) 287static int __init txx9ndfmc_probe(struct platform_device *dev)
290{ 288{
291 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data; 289 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
292#ifdef CONFIG_MTD_PARTITIONS
293 static const char *probes[] = { "cmdlinepart", NULL }; 290 static const char *probes[] = { "cmdlinepart", NULL };
294#endif
295 int hold, spw; 291 int hold, spw;
296 int i; 292 int i;
297 struct txx9ndfmc_drvdata *drvdata; 293 struct txx9ndfmc_drvdata *drvdata;
@@ -337,9 +333,7 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)
337 struct txx9ndfmc_priv *txx9_priv; 333 struct txx9ndfmc_priv *txx9_priv;
338 struct nand_chip *chip; 334 struct nand_chip *chip;
339 struct mtd_info *mtd; 335 struct mtd_info *mtd;
340#ifdef CONFIG_MTD_PARTITIONS
341 int nr_parts; 336 int nr_parts;
342#endif
343 337
344 if (!(plat->ch_mask & (1 << i))) 338 if (!(plat->ch_mask & (1 << i)))
345 continue; 339 continue;
@@ -399,13 +393,9 @@ static int __init txx9ndfmc_probe(struct platform_device *dev)
399 } 393 }
400 mtd->name = txx9_priv->mtdname; 394 mtd->name = txx9_priv->mtdname;
401 395
402#ifdef CONFIG_MTD_PARTITIONS
403 nr_parts = parse_mtd_partitions(mtd, probes, 396 nr_parts = parse_mtd_partitions(mtd, probes,
404 &drvdata->parts[i], 0); 397 &drvdata->parts[i], 0);
405 if (nr_parts > 0) 398 mtd_device_register(mtd, drvdata->parts[i], nr_parts);
406 add_mtd_partitions(mtd, drvdata->parts[i], nr_parts);
407#endif
408 add_mtd_device(mtd);
409 drvdata->mtds[i] = mtd; 399 drvdata->mtds[i] = mtd;
410 } 400 }
411 401
@@ -431,9 +421,7 @@ static int __exit txx9ndfmc_remove(struct platform_device *dev)
431 txx9_priv = chip->priv; 421 txx9_priv = chip->priv;
432 422
433 nand_release(mtd); 423 nand_release(mtd);
434#ifdef CONFIG_MTD_PARTITIONS
435 kfree(drvdata->parts[i]); 424 kfree(drvdata->parts[i]);
436#endif
437 kfree(txx9_priv->mtdname); 425 kfree(txx9_priv->mtdname);
438 kfree(txx9_priv); 426 kfree(txx9_priv);
439 } 427 }
diff --git a/drivers/mtd/onenand/Kconfig b/drivers/mtd/onenand/Kconfig
index 4f426195f8db..772ad2966619 100644
--- a/drivers/mtd/onenand/Kconfig
+++ b/drivers/mtd/onenand/Kconfig
@@ -1,7 +1,6 @@
1menuconfig MTD_ONENAND 1menuconfig MTD_ONENAND
2 tristate "OneNAND Device Support" 2 tristate "OneNAND Device Support"
3 depends on MTD 3 depends on MTD
4 select MTD_PARTITIONS
5 help 4 help
6 This enables support for accessing all type of OneNAND flash 5 This enables support for accessing all type of OneNAND flash
7 devices. For further information see 6 devices. For further information see
diff --git a/drivers/mtd/onenand/generic.c b/drivers/mtd/onenand/generic.c
index ac08750748a3..2d70d354d846 100644
--- a/drivers/mtd/onenand/generic.c
+++ b/drivers/mtd/onenand/generic.c
@@ -30,9 +30,7 @@
30 */ 30 */
31#define DRIVER_NAME "onenand-flash" 31#define DRIVER_NAME "onenand-flash"
32 32
33#ifdef CONFIG_MTD_PARTITIONS
34static const char *part_probes[] = { "cmdlinepart", NULL, }; 33static const char *part_probes[] = { "cmdlinepart", NULL, };
35#endif
36 34
37struct onenand_info { 35struct onenand_info {
38 struct mtd_info mtd; 36 struct mtd_info mtd;
@@ -75,15 +73,13 @@ static int __devinit generic_onenand_probe(struct platform_device *pdev)
75 goto out_iounmap; 73 goto out_iounmap;
76 } 74 }
77 75
78#ifdef CONFIG_MTD_PARTITIONS
79 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0); 76 err = parse_mtd_partitions(&info->mtd, part_probes, &info->parts, 0);
80 if (err > 0) 77 if (err > 0)
81 add_mtd_partitions(&info->mtd, info->parts, err); 78 mtd_device_register(&info->mtd, info->parts, err);
82 else if (err <= 0 && pdata && pdata->parts) 79 else if (err <= 0 && pdata && pdata->parts)
83 add_mtd_partitions(&info->mtd, pdata->parts, pdata->nr_parts); 80 mtd_device_register(&info->mtd, pdata->parts, pdata->nr_parts);
84 else 81 else
85#endif 82 err = mtd_device_register(&info->mtd, NULL, 0);
86 err = add_mtd_device(&info->mtd);
87 83
88 platform_set_drvdata(pdev, info); 84 platform_set_drvdata(pdev, info);
89 85
@@ -108,11 +104,7 @@ static int __devexit generic_onenand_remove(struct platform_device *pdev)
108 platform_set_drvdata(pdev, NULL); 104 platform_set_drvdata(pdev, NULL);
109 105
110 if (info) { 106 if (info) {
111 if (info->parts) 107 mtd_device_unregister(&info->mtd);
112 del_mtd_partitions(&info->mtd);
113 else
114 del_mtd_device(&info->mtd);
115
116 onenand_release(&info->mtd); 108 onenand_release(&info->mtd);
117 release_mem_region(res->start, size); 109 release_mem_region(res->start, size);
118 iounmap(info->onenand.base); 110 iounmap(info->onenand.base);
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
index 1fcb41adab07..a916dec29215 100644
--- a/drivers/mtd/onenand/omap2.c
+++ b/drivers/mtd/onenand/omap2.c
@@ -67,9 +67,7 @@ struct omap2_onenand {
67 struct regulator *regulator; 67 struct regulator *regulator;
68}; 68};
69 69
70#ifdef CONFIG_MTD_PARTITIONS
71static const char *part_probes[] = { "cmdlinepart", NULL, }; 70static const char *part_probes[] = { "cmdlinepart", NULL, };
72#endif
73 71
74static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data) 72static void omap2_onenand_dma_cb(int lch, u16 ch_status, void *data)
75{ 73{
@@ -755,15 +753,13 @@ static int __devinit omap2_onenand_probe(struct platform_device *pdev)
755 if ((r = onenand_scan(&c->mtd, 1)) < 0) 753 if ((r = onenand_scan(&c->mtd, 1)) < 0)
756 goto err_release_regulator; 754 goto err_release_regulator;
757 755
758#ifdef CONFIG_MTD_PARTITIONS
759 r = parse_mtd_partitions(&c->mtd, part_probes, &c->parts, 0); 756 r = parse_mtd_partitions(&c->mtd, part_probes, &c->parts, 0);
760 if (r > 0) 757 if (r > 0)
761 r = add_mtd_partitions(&c->mtd, c->parts, r); 758 r = mtd_device_register(&c->mtd, c->parts, r);
762 else if (pdata->parts != NULL) 759 else if (pdata->parts != NULL)
763 r = add_mtd_partitions(&c->mtd, pdata->parts, pdata->nr_parts); 760 r = mtd_device_register(&c->mtd, pdata->parts, pdata->nr_parts);
764 else 761 else
765#endif 762 r = mtd_device_register(&c->mtd, NULL, 0);
766 r = add_mtd_device(&c->mtd);
767 if (r) 763 if (r)
768 goto err_release_onenand; 764 goto err_release_onenand;
769 765
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 56a8b2005bda..ac9e959802a7 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -65,11 +65,11 @@ MODULE_PARM_DESC(otp, "Corresponding behaviour of OneNAND in OTP"
65 " : 2 -> 1st Block lock" 65 " : 2 -> 1st Block lock"
66 " : 3 -> BOTH OTP Block and 1st Block lock"); 66 " : 3 -> BOTH OTP Block and 1st Block lock");
67 67
68/** 68/*
69 * onenand_oob_128 - oob info for Flex-Onenand with 4KB page 69 * flexonenand_oob_128 - oob info for Flex-Onenand with 4KB page
70 * For now, we expose only 64 out of 80 ecc bytes 70 * For now, we expose only 64 out of 80 ecc bytes
71 */ 71 */
72static struct nand_ecclayout onenand_oob_128 = { 72static struct nand_ecclayout flexonenand_oob_128 = {
73 .eccbytes = 64, 73 .eccbytes = 64,
74 .eccpos = { 74 .eccpos = {
75 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 75 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
@@ -86,6 +86,35 @@ static struct nand_ecclayout onenand_oob_128 = {
86 } 86 }
87}; 87};
88 88
89/*
90 * onenand_oob_128 - oob info for OneNAND with 4KB page
91 *
92 * Based on specification:
93 * 4Gb M-die OneNAND Flash (KFM4G16Q4M, KFN8G16Q4M). Rev. 1.3, Apr. 2010
94 *
95 * For eccpos we expose only 64 bytes out of 72 (see struct nand_ecclayout)
96 *
97 * oobfree uses the spare area fields marked as
98 * "Managed by internal ECC logic for Logical Sector Number area"
99 */
100static struct nand_ecclayout onenand_oob_128 = {
101 .eccbytes = 64,
102 .eccpos = {
103 7, 8, 9, 10, 11, 12, 13, 14, 15,
104 23, 24, 25, 26, 27, 28, 29, 30, 31,
105 39, 40, 41, 42, 43, 44, 45, 46, 47,
106 55, 56, 57, 58, 59, 60, 61, 62, 63,
107 71, 72, 73, 74, 75, 76, 77, 78, 79,
108 87, 88, 89, 90, 91, 92, 93, 94, 95,
109 103, 104, 105, 106, 107, 108, 109, 110, 111,
110 119
111 },
112 .oobfree = {
113 {2, 3}, {18, 3}, {34, 3}, {50, 3},
114 {66, 3}, {82, 3}, {98, 3}, {114, 3}
115 }
116};
117
89/** 118/**
90 * onenand_oob_64 - oob info for large (2KB) page 119 * onenand_oob_64 - oob info for large (2KB) page
91 */ 120 */
@@ -2424,7 +2453,7 @@ static int onenand_block_by_block_erase(struct mtd_info *mtd,
2424 len -= block_size; 2453 len -= block_size;
2425 addr += block_size; 2454 addr += block_size;
2426 2455
2427 if (addr == region_end) { 2456 if (region && addr == region_end) {
2428 if (!len) 2457 if (!len)
2429 break; 2458 break;
2430 region++; 2459 region++;
@@ -4018,8 +4047,13 @@ int onenand_scan(struct mtd_info *mtd, int maxchips)
4018 */ 4047 */
4019 switch (mtd->oobsize) { 4048 switch (mtd->oobsize) {
4020 case 128: 4049 case 128:
4021 this->ecclayout = &onenand_oob_128; 4050 if (FLEXONENAND(this)) {
4022 mtd->subpage_sft = 0; 4051 this->ecclayout = &flexonenand_oob_128;
4052 mtd->subpage_sft = 0;
4053 } else {
4054 this->ecclayout = &onenand_oob_128;
4055 mtd->subpage_sft = 2;
4056 }
4023 break; 4057 break;
4024 case 64: 4058 case 64:
4025 this->ecclayout = &onenand_oob_64; 4059 this->ecclayout = &onenand_oob_64;
@@ -4108,12 +4142,8 @@ void onenand_release(struct mtd_info *mtd)
4108{ 4142{
4109 struct onenand_chip *this = mtd->priv; 4143 struct onenand_chip *this = mtd->priv;
4110 4144
4111#ifdef CONFIG_MTD_PARTITIONS
4112 /* Deregister partitions */ 4145 /* Deregister partitions */
4113 del_mtd_partitions (mtd); 4146 mtd_device_unregister(mtd);
4114#endif
4115 /* Deregister the device */
4116 del_mtd_device (mtd);
4117 4147
4118 /* Free bad block table memory, if allocated */ 4148 /* Free bad block table memory, if allocated */
4119 if (this->bbm) { 4149 if (this->bbm) {
diff --git a/drivers/mtd/onenand/onenand_sim.c b/drivers/mtd/onenand/onenand_sim.c
index 5ef3bd547772..85399e3accda 100644
--- a/drivers/mtd/onenand/onenand_sim.c
+++ b/drivers/mtd/onenand/onenand_sim.c
@@ -539,7 +539,8 @@ static int __init onenand_sim_init(void)
539 return -ENXIO; 539 return -ENXIO;
540 } 540 }
541 541
542 add_mtd_partitions(&info->mtd, info->parts, ARRAY_SIZE(os_partitions)); 542 mtd_device_register(&info->mtd, info->parts,
543 ARRAY_SIZE(os_partitions));
543 544
544 return 0; 545 return 0;
545} 546}
diff --git a/drivers/mtd/onenand/samsung.c b/drivers/mtd/onenand/samsung.c
index a4c74a9ba430..3306b5b3c736 100644
--- a/drivers/mtd/onenand/samsung.c
+++ b/drivers/mtd/onenand/samsung.c
@@ -147,9 +147,7 @@ struct s3c_onenand {
147 struct resource *dma_res; 147 struct resource *dma_res;
148 unsigned long phys_base; 148 unsigned long phys_base;
149 struct completion complete; 149 struct completion complete;
150#ifdef CONFIG_MTD_PARTITIONS
151 struct mtd_partition *parts; 150 struct mtd_partition *parts;
152#endif
153}; 151};
154 152
155#define CMD_MAP_00(dev, addr) (dev->cmd_map(MAP_00, ((addr) << 1))) 153#define CMD_MAP_00(dev, addr) (dev->cmd_map(MAP_00, ((addr) << 1)))
@@ -159,9 +157,7 @@ struct s3c_onenand {
159 157
160static struct s3c_onenand *onenand; 158static struct s3c_onenand *onenand;
161 159
162#ifdef CONFIG_MTD_PARTITIONS
163static const char *part_probes[] = { "cmdlinepart", NULL, }; 160static const char *part_probes[] = { "cmdlinepart", NULL, };
164#endif
165 161
166static inline int s3c_read_reg(int offset) 162static inline int s3c_read_reg(int offset)
167{ 163{
@@ -1021,15 +1017,13 @@ static int s3c_onenand_probe(struct platform_device *pdev)
1021 if (s3c_read_reg(MEM_CFG_OFFSET) & ONENAND_SYS_CFG1_SYNC_READ) 1017 if (s3c_read_reg(MEM_CFG_OFFSET) & ONENAND_SYS_CFG1_SYNC_READ)
1022 dev_info(&onenand->pdev->dev, "OneNAND Sync. Burst Read enabled\n"); 1018 dev_info(&onenand->pdev->dev, "OneNAND Sync. Burst Read enabled\n");
1023 1019
1024#ifdef CONFIG_MTD_PARTITIONS
1025 err = parse_mtd_partitions(mtd, part_probes, &onenand->parts, 0); 1020 err = parse_mtd_partitions(mtd, part_probes, &onenand->parts, 0);
1026 if (err > 0) 1021 if (err > 0)
1027 add_mtd_partitions(mtd, onenand->parts, err); 1022 mtd_device_register(mtd, onenand->parts, err);
1028 else if (err <= 0 && pdata && pdata->parts) 1023 else if (err <= 0 && pdata && pdata->parts)
1029 add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts); 1024 mtd_device_register(mtd, pdata->parts, pdata->nr_parts);
1030 else 1025 else
1031#endif 1026 err = mtd_device_register(mtd, NULL, 0);
1032 err = add_mtd_device(mtd);
1033 1027
1034 platform_set_drvdata(pdev, mtd); 1028 platform_set_drvdata(pdev, mtd);
1035 1029
diff --git a/drivers/mtd/ubi/gluebi.c b/drivers/mtd/ubi/gluebi.c
index 9aa81584c8a2..941bc3c05d6e 100644
--- a/drivers/mtd/ubi/gluebi.c
+++ b/drivers/mtd/ubi/gluebi.c
@@ -365,7 +365,7 @@ static int gluebi_create(struct ubi_device_info *di,
365 vi->vol_id); 365 vi->vol_id);
366 mutex_unlock(&devices_mutex); 366 mutex_unlock(&devices_mutex);
367 367
368 if (add_mtd_device(mtd)) { 368 if (mtd_device_register(mtd, NULL, 0)) {
369 err_msg("cannot add MTD device"); 369 err_msg("cannot add MTD device");
370 kfree(mtd->name); 370 kfree(mtd->name);
371 kfree(gluebi); 371 kfree(gluebi);
@@ -407,7 +407,7 @@ static int gluebi_remove(struct ubi_volume_info *vi)
407 return err; 407 return err;
408 408
409 mtd = &gluebi->mtd; 409 mtd = &gluebi->mtd;
410 err = del_mtd_device(mtd); 410 err = mtd_device_unregister(mtd);
411 if (err) { 411 if (err) {
412 err_msg("cannot remove fake MTD device %d, UBI device %d, " 412 err_msg("cannot remove fake MTD device %d, UBI device %d, "
413 "volume %d, error %d", mtd->index, gluebi->ubi_num, 413 "volume %d, error %d", mtd->index, gluebi->ubi_num,
@@ -524,7 +524,7 @@ static void __exit ubi_gluebi_exit(void)
524 int err; 524 int err;
525 struct mtd_info *mtd = &gluebi->mtd; 525 struct mtd_info *mtd = &gluebi->mtd;
526 526
527 err = del_mtd_device(mtd); 527 err = mtd_device_unregister(mtd);
528 if (err) 528 if (err)
529 err_msg("error %d while removing gluebi MTD device %d, " 529 err_msg("error %d while removing gluebi MTD device %d, "
530 "UBI device %d, volume %d - ignoring", err, 530 "UBI device %d, volume %d - ignoring", err,
diff --git a/drivers/net/sfc/mtd.c b/drivers/net/sfc/mtd.c
index e646bfce2d84..b6304486f244 100644
--- a/drivers/net/sfc/mtd.c
+++ b/drivers/net/sfc/mtd.c
@@ -216,7 +216,7 @@ static void efx_mtd_remove_partition(struct efx_mtd_partition *part)
216 int rc; 216 int rc;
217 217
218 for (;;) { 218 for (;;) {
219 rc = del_mtd_device(&part->mtd); 219 rc = mtd_device_unregister(&part->mtd);
220 if (rc != -EBUSY) 220 if (rc != -EBUSY)
221 break; 221 break;
222 ssleep(1); 222 ssleep(1);
@@ -268,7 +268,7 @@ static int efx_mtd_probe_device(struct efx_nic *efx, struct efx_mtd *efx_mtd)
268 part->mtd.write = efx_mtd->ops->write; 268 part->mtd.write = efx_mtd->ops->write;
269 part->mtd.sync = efx_mtd_sync; 269 part->mtd.sync = efx_mtd_sync;
270 270
271 if (add_mtd_device(&part->mtd)) 271 if (mtd_device_register(&part->mtd, NULL, 0))
272 goto fail; 272 goto fail;
273 } 273 }
274 274
@@ -280,7 +280,7 @@ fail:
280 --part; 280 --part;
281 efx_mtd_remove_partition(part); 281 efx_mtd_remove_partition(part);
282 } 282 }
283 /* add_mtd_device() returns 1 if the MTD table is full */ 283 /* mtd_device_register() returns 1 if the MTD table is full */
284 return -ENOMEM; 284 return -ENOMEM;
285} 285}
286 286
diff --git a/fs/jffs2/dir.c b/fs/jffs2/dir.c
index 05f73328b28b..9a1e86fc1362 100644
--- a/fs/jffs2/dir.c
+++ b/fs/jffs2/dir.c
@@ -75,7 +75,6 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
75 struct nameidata *nd) 75 struct nameidata *nd)
76{ 76{
77 struct jffs2_inode_info *dir_f; 77 struct jffs2_inode_info *dir_f;
78 struct jffs2_sb_info *c;
79 struct jffs2_full_dirent *fd = NULL, *fd_list; 78 struct jffs2_full_dirent *fd = NULL, *fd_list;
80 uint32_t ino = 0; 79 uint32_t ino = 0;
81 struct inode *inode = NULL; 80 struct inode *inode = NULL;
@@ -86,7 +85,6 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
86 return ERR_PTR(-ENAMETOOLONG); 85 return ERR_PTR(-ENAMETOOLONG);
87 86
88 dir_f = JFFS2_INODE_INFO(dir_i); 87 dir_f = JFFS2_INODE_INFO(dir_i);
89 c = JFFS2_SB_INFO(dir_i->i_sb);
90 88
91 mutex_lock(&dir_f->sem); 89 mutex_lock(&dir_f->sem);
92 90
@@ -119,7 +117,6 @@ static struct dentry *jffs2_lookup(struct inode *dir_i, struct dentry *target,
119static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir) 117static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
120{ 118{
121 struct jffs2_inode_info *f; 119 struct jffs2_inode_info *f;
122 struct jffs2_sb_info *c;
123 struct inode *inode = filp->f_path.dentry->d_inode; 120 struct inode *inode = filp->f_path.dentry->d_inode;
124 struct jffs2_full_dirent *fd; 121 struct jffs2_full_dirent *fd;
125 unsigned long offset, curofs; 122 unsigned long offset, curofs;
@@ -127,7 +124,6 @@ static int jffs2_readdir(struct file *filp, void *dirent, filldir_t filldir)
127 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_path.dentry->d_inode->i_ino)); 124 D1(printk(KERN_DEBUG "jffs2_readdir() for dir_i #%lu\n", filp->f_path.dentry->d_inode->i_ino));
128 125
129 f = JFFS2_INODE_INFO(inode); 126 f = JFFS2_INODE_INFO(inode);
130 c = JFFS2_SB_INFO(inode->i_sb);
131 127
132 offset = filp->f_pos; 128 offset = filp->f_pos;
133 129
diff --git a/fs/jffs2/scan.c b/fs/jffs2/scan.c
index b632dddcb482..8d8cd3419d02 100644
--- a/fs/jffs2/scan.c
+++ b/fs/jffs2/scan.c
@@ -94,7 +94,7 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
94 uint32_t buf_size = 0; 94 uint32_t buf_size = 0;
95 struct jffs2_summary *s = NULL; /* summary info collected by the scan process */ 95 struct jffs2_summary *s = NULL; /* summary info collected by the scan process */
96#ifndef __ECOS 96#ifndef __ECOS
97 size_t pointlen; 97 size_t pointlen, try_size;
98 98
99 if (c->mtd->point) { 99 if (c->mtd->point) {
100 ret = c->mtd->point(c->mtd, 0, c->mtd->size, &pointlen, 100 ret = c->mtd->point(c->mtd, 0, c->mtd->size, &pointlen,
@@ -113,18 +113,21 @@ int jffs2_scan_medium(struct jffs2_sb_info *c)
113 /* For NAND it's quicker to read a whole eraseblock at a time, 113 /* For NAND it's quicker to read a whole eraseblock at a time,
114 apparently */ 114 apparently */
115 if (jffs2_cleanmarker_oob(c)) 115 if (jffs2_cleanmarker_oob(c))
116 buf_size = c->sector_size; 116 try_size = c->sector_size;
117 else 117 else
118 buf_size = PAGE_SIZE; 118 try_size = PAGE_SIZE;
119 119
120 /* Respect kmalloc limitations */ 120 D1(printk(KERN_DEBUG "Trying to allocate readbuf of %zu "
121 if (buf_size > 128*1024) 121 "bytes\n", try_size));
122 buf_size = 128*1024;
123 122
124 D1(printk(KERN_DEBUG "Allocating readbuf of %d bytes\n", buf_size)); 123 flashbuf = mtd_kmalloc_up_to(c->mtd, &try_size);
125 flashbuf = kmalloc(buf_size, GFP_KERNEL);
126 if (!flashbuf) 124 if (!flashbuf)
127 return -ENOMEM; 125 return -ENOMEM;
126
127 D1(printk(KERN_DEBUG "Allocated readbuf of %zu bytes\n",
128 try_size));
129
130 buf_size = (uint32_t)try_size;
128 } 131 }
129 132
130 if (jffs2_sum_active()) { 133 if (jffs2_sum_active()) {
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 9d5306bad117..2541fb848daa 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -322,9 +322,12 @@ static inline uint32_t mtd_mod_by_ws(uint64_t sz, struct mtd_info *mtd)
322 322
323 /* Kernel-side ioctl definitions */ 323 /* Kernel-side ioctl definitions */
324 324
325extern int add_mtd_device(struct mtd_info *mtd); 325struct mtd_partition;
326extern int del_mtd_device (struct mtd_info *mtd);
327 326
327extern int mtd_device_register(struct mtd_info *master,
328 const struct mtd_partition *parts,
329 int nr_parts);
330extern int mtd_device_unregister(struct mtd_info *master);
328extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num); 331extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
329extern int __get_mtd_device(struct mtd_info *mtd); 332extern int __get_mtd_device(struct mtd_info *mtd);
330extern void __put_mtd_device(struct mtd_info *mtd); 333extern void __put_mtd_device(struct mtd_info *mtd);
@@ -348,15 +351,9 @@ int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
348int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs, 351int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
349 unsigned long count, loff_t from, size_t *retlen); 352 unsigned long count, loff_t from, size_t *retlen);
350 353
351#ifdef CONFIG_MTD_PARTITIONS 354void *mtd_kmalloc_up_to(const struct mtd_info *mtd, size_t *size);
355
352void mtd_erase_callback(struct erase_info *instr); 356void mtd_erase_callback(struct erase_info *instr);
353#else
354static inline void mtd_erase_callback(struct erase_info *instr)
355{
356 if (instr->callback)
357 instr->callback(instr);
358}
359#endif
360 357
361/* 358/*
362 * Debugging macro and defines 359 * Debugging macro and defines
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index d44192740f6f..c2b9ac4fbc4a 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -237,9 +237,9 @@ typedef enum {
237 * If passed additionally to NAND_USE_FLASH_BBT then BBT code will not touch 237 * If passed additionally to NAND_USE_FLASH_BBT then BBT code will not touch
238 * the OOB area. 238 * the OOB area.
239 */ 239 */
240#define NAND_USE_FLASH_BBT_NO_OOB 0x00100000 240#define NAND_USE_FLASH_BBT_NO_OOB 0x00800000
241/* Create an empty BBT with no vendor information if the BBT is available */ 241/* Create an empty BBT with no vendor information if the BBT is available */
242#define NAND_CREATE_EMPTY_BBT 0x00200000 242#define NAND_CREATE_EMPTY_BBT 0x01000000
243 243
244/* Options set by nand scan */ 244/* Options set by nand scan */
245/* Nand scan has allocated controller struct */ 245/* Nand scan has allocated controller struct */
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index 4a0a8ba90a72..3a6f0372fc96 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -16,7 +16,7 @@
16 * Partition definition structure: 16 * Partition definition structure:
17 * 17 *
18 * An array of struct partition is passed along with a MTD object to 18 * An array of struct partition is passed along with a MTD object to
19 * add_mtd_partitions() to create them. 19 * mtd_device_register() to create them.
20 * 20 *
21 * For each partition, these fields are available: 21 * For each partition, these fields are available:
22 * name: string that will be used to label the partition's MTD device. 22 * name: string that will be used to label the partition's MTD device.
@@ -49,9 +49,6 @@ struct mtd_partition {
49 49
50struct mtd_info; 50struct mtd_info;
51 51
52int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
53int del_mtd_partitions(struct mtd_info *);
54
55/* 52/*
56 * Functions dealing with the various ways of partitioning the space 53 * Functions dealing with the various ways of partitioning the space
57 */ 54 */
@@ -73,14 +70,17 @@ extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
73struct device; 70struct device;
74struct device_node; 71struct device_node;
75 72
73#ifdef CONFIG_MTD_OF_PARTS
76int __devinit of_mtd_parse_partitions(struct device *dev, 74int __devinit of_mtd_parse_partitions(struct device *dev,
77 struct device_node *node, 75 struct device_node *node,
78 struct mtd_partition **pparts); 76 struct mtd_partition **pparts);
79
80#ifdef CONFIG_MTD_PARTITIONS
81static inline int mtd_has_partitions(void) { return 1; }
82#else 77#else
83static inline int mtd_has_partitions(void) { return 0; } 78static inline int of_mtd_parse_partitions(struct device *dev,
79 struct device_node *node,
80 struct mtd_partition **pparts)
81{
82 return 0;
83}
84#endif 84#endif
85 85
86#ifdef CONFIG_MTD_CMDLINE_PARTS 86#ifdef CONFIG_MTD_CMDLINE_PARTS
diff --git a/include/linux/mtd/physmap.h b/include/linux/mtd/physmap.h
index 49b959029417..d40bfa1d9c91 100644
--- a/include/linux/mtd/physmap.h
+++ b/include/linux/mtd/physmap.h
@@ -37,8 +37,6 @@ struct physmap_flash_data {
37void physmap_configure(unsigned long addr, unsigned long size, 37void physmap_configure(unsigned long addr, unsigned long size,
38 int bankwidth, void (*set_vpp)(struct map_info *, int) ); 38 int bankwidth, void (*set_vpp)(struct map_info *, int) );
39 39
40#ifdef CONFIG_MTD_PARTITIONS
41
42/* 40/*
43 * Machines that wish to do flash partition may want to call this function in 41 * Machines that wish to do flash partition may want to call this function in
44 * their setup routine. 42 * their setup routine.
@@ -50,6 +48,4 @@ void physmap_configure(unsigned long addr, unsigned long size,
50 */ 48 */
51void physmap_set_partitions(struct mtd_partition *parts, int num_parts); 49void physmap_set_partitions(struct mtd_partition *parts, int num_parts);
52 50
53#endif /* defined(CONFIG_MTD_PARTITIONS) */
54
55#endif /* __LINUX_MTD_PHYSMAP__ */ 51#endif /* __LINUX_MTD_PHYSMAP__ */