aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/powerpc/dts-bindings/fsl/upm-nand.txt39
-rw-r--r--arch/arm/mach-davinci/include/mach/nand.h80
-rw-r--r--arch/arm/mach-pxa/include/mach/pxa3xx_nand.h3
-rw-r--r--arch/blackfin/kernel/process.c2
-rw-r--r--arch/mips/include/asm/txx9/ndfmc.h30
-rw-r--r--arch/mips/include/asm/txx9/rbtx4939.h9
-rw-r--r--arch/mips/include/asm/txx9/tx4938.h1
-rw-r--r--arch/mips/include/asm/txx9/tx4939.h2
-rw-r--r--arch/mips/txx9/generic/setup.c21
-rw-r--r--arch/mips/txx9/generic/setup_tx4938.c21
-rw-r--r--arch/mips/txx9/generic/setup_tx4939.c17
-rw-r--r--arch/mips/txx9/rbtx4938/setup.c2
-rw-r--r--arch/mips/txx9/rbtx4939/setup.c161
-rw-r--r--arch/powerpc/boot/dts/tqm8548-bigflash.dts7
-rw-r--r--arch/powerpc/boot/dts/tqm8548.dts7
-rw-r--r--arch/powerpc/sysdev/fsl_lbc.c2
-rw-r--r--drivers/mtd/Makefile2
-rw-r--r--drivers/mtd/ar7part.c6
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0001.c8
-rw-r--r--drivers/mtd/chips/cfi_cmdset_0002.c11
-rw-r--r--drivers/mtd/chips/jedec_probe.c16
-rw-r--r--drivers/mtd/chips/map_ram.c17
-rw-r--r--drivers/mtd/chips/map_rom.c17
-rw-r--r--drivers/mtd/cmdlinepart.c6
-rw-r--r--drivers/mtd/devices/doc2000.c1
-rw-r--r--drivers/mtd/devices/doc2001.c1
-rw-r--r--drivers/mtd/devices/doc2001plus.c1
-rw-r--r--drivers/mtd/devices/docecc.c1
-rw-r--r--drivers/mtd/devices/m25p80.c19
-rw-r--r--drivers/mtd/devices/mtd_dataflash.c18
-rw-r--r--drivers/mtd/devices/mtdram.c14
-rw-r--r--drivers/mtd/inftlmount.c1
-rw-r--r--drivers/mtd/internal.h17
-rw-r--r--drivers/mtd/maps/Kconfig12
-rw-r--r--drivers/mtd/maps/Makefile2
-rw-r--r--drivers/mtd/maps/omap_nor.c2
-rw-r--r--drivers/mtd/maps/physmap.c1
-rw-r--r--drivers/mtd/maps/physmap_of.c1
-rw-r--r--drivers/mtd/maps/plat-ram.c1
-rw-r--r--drivers/mtd/maps/rbtx4939-flash.c208
-rw-r--r--drivers/mtd/maps/sa1100-flash.c2
-rw-r--r--drivers/mtd/maps/sharpsl-flash.c116
-rw-r--r--drivers/mtd/mtd_blkdevs.c4
-rw-r--r--drivers/mtd/mtdbdi.c43
-rw-r--r--drivers/mtd/mtdchar.c111
-rw-r--r--drivers/mtd/mtdconcat.c47
-rw-r--r--drivers/mtd/mtdcore.c208
-rw-r--r--drivers/mtd/mtdoops.c16
-rw-r--r--drivers/mtd/mtdpart.c31
-rw-r--r--drivers/mtd/nand/Kconfig21
-rw-r--r--drivers/mtd/nand/Makefile3
-rw-r--r--drivers/mtd/nand/bf5xx_nand.c18
-rw-r--r--drivers/mtd/nand/cafe_nand.c1
-rw-r--r--drivers/mtd/nand/davinci_nand.c570
-rw-r--r--drivers/mtd/nand/fsl_upm.c119
-rw-r--r--drivers/mtd/nand/mxc_nand.c1
-rw-r--r--drivers/mtd/nand/nand_base.c125
-rw-r--r--drivers/mtd/nand/plat_nand.c2
-rw-r--r--drivers/mtd/nand/pxa3xx_nand.c119
-rw-r--r--drivers/mtd/nand/sh_flctl.c18
-rw-r--r--drivers/mtd/nand/socrates_nand.c325
-rw-r--r--drivers/mtd/nand/txx9ndfmc.c428
-rw-r--r--drivers/mtd/nftlcore.c3
-rw-r--r--drivers/mtd/ofpart.c7
-rw-r--r--drivers/mtd/onenand/omap2.c6
-rw-r--r--drivers/mtd/onenand/onenand_base.c145
-rw-r--r--fs/jffs2/acl.c4
-rw-r--r--fs/jffs2/malloc.c6
-rw-r--r--fs/romfs/Kconfig48
-rw-r--r--fs/romfs/Makefile9
-rw-r--r--fs/romfs/inode.c665
-rw-r--r--fs/romfs/internal.h47
-rw-r--r--fs/romfs/mmap-nommu.c75
-rw-r--r--fs/romfs/storage.c261
-rw-r--r--fs/romfs/super.c648
-rw-r--r--include/linux/mtd/mtd.h21
-rw-r--r--include/linux/mtd/nand.h4
-rw-r--r--include/linux/mtd/partitions.h12
78 files changed, 4080 insertions, 996 deletions
diff --git a/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt b/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt
index 84a04d5eb8e6..a48b2cadc7f0 100644
--- a/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt
+++ b/Documentation/powerpc/dts-bindings/fsl/upm-nand.txt
@@ -5,9 +5,21 @@ Required properties:
5- reg : should specify localbus chip select and size used for the chip. 5- reg : should specify localbus chip select and size used for the chip.
6- fsl,upm-addr-offset : UPM pattern offset for the address latch. 6- fsl,upm-addr-offset : UPM pattern offset for the address latch.
7- fsl,upm-cmd-offset : UPM pattern offset for the command latch. 7- fsl,upm-cmd-offset : UPM pattern offset for the command latch.
8- gpios : may specify optional GPIO connected to the Ready-Not-Busy pin.
9 8
10Example: 9Optional properties:
10- fsl,upm-wait-flags : add chip-dependent short delays after running the
11 UPM pattern (0x1), after writing a data byte (0x2) or after
12 writing out a buffer (0x4).
13- fsl,upm-addr-line-cs-offsets : address offsets for multi-chip support.
14 The corresponding address lines are used to select the chip.
15- gpios : may specify optional GPIOs connected to the Ready-Not-Busy pins
16 (R/B#). For multi-chip devices, "n" GPIO definitions are required
17 according to the number of chips.
18- chip-delay : chip dependent delay for transfering data from array to
19 read registers (tR). Required if property "gpios" is not used
20 (R/B# pins not connected).
21
22Examples:
11 23
12upm@1,0 { 24upm@1,0 {
13 compatible = "fsl,upm-nand"; 25 compatible = "fsl,upm-nand";
@@ -26,3 +38,26 @@ upm@1,0 {
26 }; 38 };
27 }; 39 };
28}; 40};
41
42upm@3,0 {
43 #address-cells = <0>;
44 #size-cells = <0>;
45 compatible = "tqc,tqm8548-upm-nand", "fsl,upm-nand";
46 reg = <3 0x0 0x800>;
47 fsl,upm-addr-offset = <0x10>;
48 fsl,upm-cmd-offset = <0x08>;
49 /* Multi-chip NAND device */
50 fsl,upm-addr-line-cs-offsets = <0x0 0x200>;
51 fsl,upm-wait-flags = <0x5>;
52 chip-delay = <25>; // in micro-seconds
53
54 nand@0 {
55 #address-cells = <1>;
56 #size-cells = <1>;
57
58 partition@0 {
59 label = "fs";
60 reg = <0x00000000 0x10000000>;
61 };
62 };
63};
diff --git a/arch/arm/mach-davinci/include/mach/nand.h b/arch/arm/mach-davinci/include/mach/nand.h
new file mode 100644
index 000000000000..aa482841270b
--- /dev/null
+++ b/arch/arm/mach-davinci/include/mach/nand.h
@@ -0,0 +1,80 @@
1/*
2 * mach-davinci/nand.h
3 *
4 * Copyright © 2006 Texas Instruments.
5 *
6 * Ported to 2.6.23 Copyright © 2008 by
7 * Sander Huijsen <Shuijsen@optelecom-nkf.com>
8 * Troy Kisky <troy.kisky@boundarydevices.com>
9 * Dirk Behme <Dirk.Behme@gmail.com>
10 *
11 * --------------------------------------------------------------------------
12 *
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 */
27
28#ifndef __ARCH_ARM_DAVINCI_NAND_H
29#define __ARCH_ARM_DAVINCI_NAND_H
30
31#include <linux/mtd/nand.h>
32
33#define NRCSR_OFFSET 0x00
34#define AWCCR_OFFSET 0x04
35#define A1CR_OFFSET 0x10
36#define NANDFCR_OFFSET 0x60
37#define NANDFSR_OFFSET 0x64
38#define NANDF1ECC_OFFSET 0x70
39
40/* 4-bit ECC syndrome registers */
41#define NAND_4BIT_ECC_LOAD_OFFSET 0xbc
42#define NAND_4BIT_ECC1_OFFSET 0xc0
43#define NAND_4BIT_ECC2_OFFSET 0xc4
44#define NAND_4BIT_ECC3_OFFSET 0xc8
45#define NAND_4BIT_ECC4_OFFSET 0xcc
46#define NAND_ERR_ADD1_OFFSET 0xd0
47#define NAND_ERR_ADD2_OFFSET 0xd4
48#define NAND_ERR_ERRVAL1_OFFSET 0xd8
49#define NAND_ERR_ERRVAL2_OFFSET 0xdc
50
51/* NOTE: boards don't need to use these address bits
52 * for ALE/CLE unless they support booting from NAND.
53 * They're used unless platform data overrides them.
54 */
55#define MASK_ALE 0x08
56#define MASK_CLE 0x10
57
58struct davinci_nand_pdata { /* platform_data */
59 uint32_t mask_ale;
60 uint32_t mask_cle;
61
62 /* for packages using two chipselects */
63 uint32_t mask_chipsel;
64
65 /* board's default static partition info */
66 struct mtd_partition *parts;
67 unsigned nr_parts;
68
69 /* none == NAND_ECC_NONE (strongly *not* advised!!)
70 * soft == NAND_ECC_SOFT
71 * 1-bit == NAND_ECC_HW
72 * 4-bit == NAND_ECC_HW_SYNDROME (not on all chips)
73 */
74 nand_ecc_modes_t ecc_mode;
75
76 /* e.g. NAND_BUSWIDTH_16 or NAND_USE_FLASH_BBT */
77 unsigned options;
78};
79
80#endif /* __ARCH_ARM_DAVINCI_NAND_H */
diff --git a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
index eb35fca9aea5..3478eae32d8a 100644
--- a/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
+++ b/arch/arm/mach-pxa/include/mach/pxa3xx_nand.h
@@ -49,6 +49,9 @@ struct pxa3xx_nand_platform_data {
49 */ 49 */
50 int enable_arbiter; 50 int enable_arbiter;
51 51
52 /* allow platform code to keep OBM/bootloader defined NFC config */
53 int keep_config;
54
52 const struct mtd_partition *parts; 55 const struct mtd_partition *parts;
53 unsigned int nr_parts; 56 unsigned int nr_parts;
54 57
diff --git a/arch/blackfin/kernel/process.c b/arch/blackfin/kernel/process.c
index f49427293ca1..e040e03335ea 100644
--- a/arch/blackfin/kernel/process.c
+++ b/arch/blackfin/kernel/process.c
@@ -337,7 +337,7 @@ int _access_ok(unsigned long addr, unsigned long size)
337 if (addr >= memory_mtd_end && (addr + size) <= physical_mem_end) 337 if (addr >= memory_mtd_end && (addr + size) <= physical_mem_end)
338 return 1; 338 return 1;
339 339
340#ifdef CONFIG_ROMFS_MTD_FS 340#ifdef CONFIG_ROMFS_ON_MTD
341 /* For XIP, allow user space to use pointers within the ROMFS. */ 341 /* For XIP, allow user space to use pointers within the ROMFS. */
342 if (addr >= memory_mtd_start && (addr + size) <= memory_mtd_end) 342 if (addr >= memory_mtd_start && (addr + size) <= memory_mtd_end)
343 return 1; 343 return 1;
diff --git a/arch/mips/include/asm/txx9/ndfmc.h b/arch/mips/include/asm/txx9/ndfmc.h
new file mode 100644
index 000000000000..fa67f3df78fc
--- /dev/null
+++ b/arch/mips/include/asm/txx9/ndfmc.h
@@ -0,0 +1,30 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License version 2 as
4 * published by the Free Software Foundation.
5 *
6 * (C) Copyright TOSHIBA CORPORATION 2007
7 */
8#ifndef __ASM_TXX9_NDFMC_H
9#define __ASM_TXX9_NDFMC_H
10
11#define NDFMC_PLAT_FLAG_USE_BSPRT 0x01
12#define NDFMC_PLAT_FLAG_NO_RSTR 0x02
13#define NDFMC_PLAT_FLAG_HOLDADD 0x04
14#define NDFMC_PLAT_FLAG_DUMMYWRITE 0x08
15
16struct txx9ndfmc_platform_data {
17 unsigned int shift;
18 unsigned int gbus_clock;
19 unsigned int hold; /* hold time in nanosecond */
20 unsigned int spw; /* strobe pulse width in nanosecond */
21 unsigned int flags;
22 unsigned char ch_mask; /* available channel bitmask */
23 unsigned char wp_mask; /* write-protect bitmask */
24 unsigned char wide_mask; /* 16bit-nand bitmask */
25};
26
27void txx9_ndfmc_init(unsigned long baseaddr,
28 const struct txx9ndfmc_platform_data *plat_data);
29
30#endif /* __ASM_TXX9_NDFMC_H */
diff --git a/arch/mips/include/asm/txx9/rbtx4939.h b/arch/mips/include/asm/txx9/rbtx4939.h
index 1acf428c0b4f..e517899794a8 100644
--- a/arch/mips/include/asm/txx9/rbtx4939.h
+++ b/arch/mips/include/asm/txx9/rbtx4939.h
@@ -130,4 +130,13 @@
130void rbtx4939_prom_init(void); 130void rbtx4939_prom_init(void);
131void rbtx4939_irq_setup(void); 131void rbtx4939_irq_setup(void);
132 132
133struct mtd_partition;
134struct map_info;
135struct rbtx4939_flash_data {
136 unsigned int width;
137 unsigned int nr_parts;
138 struct mtd_partition *parts;
139 void (*map_init)(struct map_info *map);
140};
141
133#endif /* __ASM_TXX9_RBTX4939_H */ 142#endif /* __ASM_TXX9_RBTX4939_H */
diff --git a/arch/mips/include/asm/txx9/tx4938.h b/arch/mips/include/asm/txx9/tx4938.h
index 0b068154054c..cd8bc2021755 100644
--- a/arch/mips/include/asm/txx9/tx4938.h
+++ b/arch/mips/include/asm/txx9/tx4938.h
@@ -291,6 +291,7 @@ int tx4938_pcic1_map_irq(const struct pci_dev *dev, u8 slot);
291void tx4938_setup_pcierr_irq(void); 291void tx4938_setup_pcierr_irq(void);
292void tx4938_irq_init(void); 292void tx4938_irq_init(void);
293void tx4938_mtd_init(int ch); 293void tx4938_mtd_init(int ch);
294void tx4938_ndfmc_init(unsigned int hold, unsigned int spw);
294 295
295struct tx4938ide_platform_info { 296struct tx4938ide_platform_info {
296 /* 297 /*
diff --git a/arch/mips/include/asm/txx9/tx4939.h b/arch/mips/include/asm/txx9/tx4939.h
index 964ef7ede268..f02c50b3abfb 100644
--- a/arch/mips/include/asm/txx9/tx4939.h
+++ b/arch/mips/include/asm/txx9/tx4939.h
@@ -542,5 +542,7 @@ int tx4939_irq(void);
542void tx4939_mtd_init(int ch); 542void tx4939_mtd_init(int ch);
543void tx4939_ata_init(void); 543void tx4939_ata_init(void);
544void tx4939_rtc_init(void); 544void tx4939_rtc_init(void);
545void tx4939_ndfmc_init(unsigned int hold, unsigned int spw,
546 unsigned char ch_mask, unsigned char wide_mask);
545 547
546#endif /* __ASM_TXX9_TX4939_H */ 548#endif /* __ASM_TXX9_TX4939_H */
diff --git a/arch/mips/txx9/generic/setup.c b/arch/mips/txx9/generic/setup.c
index a13a08b8c9ec..8a266c6a3f58 100644
--- a/arch/mips/txx9/generic/setup.c
+++ b/arch/mips/txx9/generic/setup.c
@@ -32,6 +32,7 @@
32#include <asm/txx9/generic.h> 32#include <asm/txx9/generic.h>
33#include <asm/txx9/pci.h> 33#include <asm/txx9/pci.h>
34#include <asm/txx9tmr.h> 34#include <asm/txx9tmr.h>
35#include <asm/txx9/ndfmc.h>
35#ifdef CONFIG_CPU_TX49XX 36#ifdef CONFIG_CPU_TX49XX
36#include <asm/txx9/tx4938.h> 37#include <asm/txx9/tx4938.h>
37#endif 38#endif
@@ -691,6 +692,26 @@ void __init txx9_physmap_flash_init(int no, unsigned long addr,
691#endif 692#endif
692} 693}
693 694
695void __init txx9_ndfmc_init(unsigned long baseaddr,
696 const struct txx9ndfmc_platform_data *pdata)
697{
698#if defined(CONFIG_MTD_NAND_TXX9NDFMC) || \
699 defined(CONFIG_MTD_NAND_TXX9NDFMC_MODULE)
700 struct resource res = {
701 .start = baseaddr,
702 .end = baseaddr + 0x1000 - 1,
703 .flags = IORESOURCE_MEM,
704 };
705 struct platform_device *pdev = platform_device_alloc("txx9ndfmc", -1);
706
707 if (!pdev ||
708 platform_device_add_resources(pdev, &res, 1) ||
709 platform_device_add_data(pdev, pdata, sizeof(*pdata)) ||
710 platform_device_add(pdev))
711 platform_device_put(pdev);
712#endif
713}
714
694#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE) 715#if defined(CONFIG_LEDS_GPIO) || defined(CONFIG_LEDS_GPIO_MODULE)
695static DEFINE_SPINLOCK(txx9_iocled_lock); 716static DEFINE_SPINLOCK(txx9_iocled_lock);
696 717
diff --git a/arch/mips/txx9/generic/setup_tx4938.c b/arch/mips/txx9/generic/setup_tx4938.c
index 25819ff1c350..f0844f891f0b 100644
--- a/arch/mips/txx9/generic/setup_tx4938.c
+++ b/arch/mips/txx9/generic/setup_tx4938.c
@@ -23,6 +23,7 @@
23#include <asm/txx9tmr.h> 23#include <asm/txx9tmr.h>
24#include <asm/txx9pio.h> 24#include <asm/txx9pio.h>
25#include <asm/txx9/generic.h> 25#include <asm/txx9/generic.h>
26#include <asm/txx9/ndfmc.h>
26#include <asm/txx9/tx4938.h> 27#include <asm/txx9/tx4938.h>
27 28
28static void __init tx4938_wdr_init(void) 29static void __init tx4938_wdr_init(void)
@@ -382,6 +383,26 @@ void __init tx4938_ata_init(unsigned int irq, unsigned int shift, int tune)
382 platform_device_put(pdev); 383 platform_device_put(pdev);
383} 384}
384 385
386void __init tx4938_ndfmc_init(unsigned int hold, unsigned int spw)
387{
388 struct txx9ndfmc_platform_data plat_data = {
389 .shift = 1,
390 .gbus_clock = txx9_gbus_clock,
391 .hold = hold,
392 .spw = spw,
393 .ch_mask = 1,
394 };
395 unsigned long baseaddr = TX4938_NDFMC_REG & 0xfffffffffULL;
396
397#ifdef __BIG_ENDIAN
398 baseaddr += 4;
399#endif
400 if ((__raw_readq(&tx4938_ccfgptr->pcfg) &
401 (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) ==
402 TX4938_PCFG_NDF_SEL)
403 txx9_ndfmc_init(baseaddr, &plat_data);
404}
405
385static void __init tx4938_stop_unused_modules(void) 406static void __init tx4938_stop_unused_modules(void)
386{ 407{
387 __u64 pcfg, rst = 0, ckd = 0; 408 __u64 pcfg, rst = 0, ckd = 0;
diff --git a/arch/mips/txx9/generic/setup_tx4939.c b/arch/mips/txx9/generic/setup_tx4939.c
index 55440967b3a8..7a25b573e9b0 100644
--- a/arch/mips/txx9/generic/setup_tx4939.c
+++ b/arch/mips/txx9/generic/setup_tx4939.c
@@ -27,6 +27,7 @@
27#include <asm/txx9irq.h> 27#include <asm/txx9irq.h>
28#include <asm/txx9tmr.h> 28#include <asm/txx9tmr.h>
29#include <asm/txx9/generic.h> 29#include <asm/txx9/generic.h>
30#include <asm/txx9/ndfmc.h>
30#include <asm/txx9/tx4939.h> 31#include <asm/txx9/tx4939.h>
31 32
32static void __init tx4939_wdr_init(void) 33static void __init tx4939_wdr_init(void)
@@ -457,6 +458,22 @@ void __init tx4939_rtc_init(void)
457 platform_device_register(&rtc_dev); 458 platform_device_register(&rtc_dev);
458} 459}
459 460
461void __init tx4939_ndfmc_init(unsigned int hold, unsigned int spw,
462 unsigned char ch_mask, unsigned char wide_mask)
463{
464 struct txx9ndfmc_platform_data plat_data = {
465 .shift = 1,
466 .gbus_clock = txx9_gbus_clock,
467 .hold = hold,
468 .spw = spw,
469 .flags = NDFMC_PLAT_FLAG_NO_RSTR | NDFMC_PLAT_FLAG_HOLDADD |
470 NDFMC_PLAT_FLAG_DUMMYWRITE,
471 .ch_mask = ch_mask,
472 .wide_mask = wide_mask,
473 };
474 txx9_ndfmc_init(TX4939_NDFMC_REG & 0xfffffffffULL, &plat_data);
475}
476
460static void __init tx4939_stop_unused_modules(void) 477static void __init tx4939_stop_unused_modules(void)
461{ 478{
462 __u64 pcfg, rst = 0, ckd = 0; 479 __u64 pcfg, rst = 0, ckd = 0;
diff --git a/arch/mips/txx9/rbtx4938/setup.c b/arch/mips/txx9/rbtx4938/setup.c
index 547ff2920bf0..65d13df8878a 100644
--- a/arch/mips/txx9/rbtx4938/setup.c
+++ b/arch/mips/txx9/rbtx4938/setup.c
@@ -352,6 +352,8 @@ static void __init rbtx4938_device_init(void)
352 rbtx4938_ne_init(); 352 rbtx4938_ne_init();
353 tx4938_wdt_init(); 353 tx4938_wdt_init();
354 rbtx4938_mtd_init(); 354 rbtx4938_mtd_init();
355 /* TC58DVM82A1FT: tDH=10ns, tWP=tRP=tREADID=35ns */
356 tx4938_ndfmc_init(10, 35);
355 tx4938_ata_init(RBTX4938_IRQ_IOC_ATA, 0, 1); 357 tx4938_ata_init(RBTX4938_IRQ_IOC_ATA, 0, 1);
356 txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL); 358 txx9_iocled_init(RBTX4938_LED_ADDR - IO_BASE, -1, 8, 1, "green", NULL);
357} 359}
diff --git a/arch/mips/txx9/rbtx4939/setup.c b/arch/mips/txx9/rbtx4939/setup.c
index 656603b85b71..011e1e332f47 100644
--- a/arch/mips/txx9/rbtx4939/setup.c
+++ b/arch/mips/txx9/rbtx4939/setup.c
@@ -16,6 +16,9 @@
16#include <linux/leds.h> 16#include <linux/leds.h>
17#include <linux/interrupt.h> 17#include <linux/interrupt.h>
18#include <linux/smc91x.h> 18#include <linux/smc91x.h>
19#include <linux/mtd/mtd.h>
20#include <linux/mtd/partitions.h>
21#include <linux/mtd/map.h>
19#include <asm/reboot.h> 22#include <asm/reboot.h>
20#include <asm/txx9/generic.h> 23#include <asm/txx9/generic.h>
21#include <asm/txx9/pci.h> 24#include <asm/txx9/pci.h>
@@ -282,6 +285,159 @@ static void rbtx4939_7segled_putc(unsigned int pos, unsigned char val)
282 __rbtx4939_7segled_putc(pos, val); 285 __rbtx4939_7segled_putc(pos, val);
283} 286}
284 287
288#if defined(CONFIG_MTD_RBTX4939) || defined(CONFIG_MTD_RBTX4939_MODULE)
289/* special mapping for boot rom */
290static unsigned long rbtx4939_flash_fixup_ofs(unsigned long ofs)
291{
292 u8 bdipsw = readb(rbtx4939_bdipsw_addr) & 0x0f;
293 unsigned char shift;
294
295 if (bdipsw & 8) {
296 /* BOOT Mode: USER ROM1 / USER ROM2 */
297 shift = bdipsw & 3;
298 /* rotate A[23:22] */
299 return (ofs & ~0xc00000) | ((((ofs >> 22) + shift) & 3) << 22);
300 }
301#ifdef __BIG_ENDIAN
302 if (bdipsw == 0)
303 /* BOOT Mode: Monitor ROM */
304 ofs ^= 0x400000; /* swap A[22] */
305#endif
306 return ofs;
307}
308
309static map_word rbtx4939_flash_read16(struct map_info *map, unsigned long ofs)
310{
311 map_word r;
312
313 ofs = rbtx4939_flash_fixup_ofs(ofs);
314 r.x[0] = __raw_readw(map->virt + ofs);
315 return r;
316}
317
318static void rbtx4939_flash_write16(struct map_info *map, const map_word datum,
319 unsigned long ofs)
320{
321 ofs = rbtx4939_flash_fixup_ofs(ofs);
322 __raw_writew(datum.x[0], map->virt + ofs);
323 mb(); /* see inline_map_write() in mtd/map.h */
324}
325
326static void rbtx4939_flash_copy_from(struct map_info *map, void *to,
327 unsigned long from, ssize_t len)
328{
329 u8 bdipsw = readb(rbtx4939_bdipsw_addr) & 0x0f;
330 unsigned char shift;
331 ssize_t curlen;
332
333 from += (unsigned long)map->virt;
334 if (bdipsw & 8) {
335 /* BOOT Mode: USER ROM1 / USER ROM2 */
336 shift = bdipsw & 3;
337 while (len) {
338 curlen = min_t(unsigned long, len,
339 0x400000 - (from & (0x400000 - 1)));
340 memcpy(to,
341 (void *)((from & ~0xc00000) |
342 ((((from >> 22) + shift) & 3) << 22)),
343 curlen);
344 len -= curlen;
345 from += curlen;
346 to += curlen;
347 }
348 return;
349 }
350#ifdef __BIG_ENDIAN
351 if (bdipsw == 0) {
352 /* BOOT Mode: Monitor ROM */
353 while (len) {
354 curlen = min_t(unsigned long, len,
355 0x400000 - (from & (0x400000 - 1)));
356 memcpy(to, (void *)(from ^ 0x400000), curlen);
357 len -= curlen;
358 from += curlen;
359 to += curlen;
360 }
361 return;
362 }
363#endif
364 memcpy(to, (void *)from, len);
365}
366
367static void rbtx4939_flash_map_init(struct map_info *map)
368{
369 map->read = rbtx4939_flash_read16;
370 map->write = rbtx4939_flash_write16;
371 map->copy_from = rbtx4939_flash_copy_from;
372}
373
374static void __init rbtx4939_mtd_init(void)
375{
376 static struct {
377 struct platform_device dev;
378 struct resource res;
379 struct rbtx4939_flash_data data;
380 } pdevs[4];
381 int i;
382 static char names[4][8];
383 static struct mtd_partition parts[4];
384 struct rbtx4939_flash_data *boot_pdata = &pdevs[0].data;
385 u8 bdipsw = readb(rbtx4939_bdipsw_addr) & 0x0f;
386
387 if (bdipsw & 8) {
388 /* BOOT Mode: USER ROM1 / USER ROM2 */
389 boot_pdata->nr_parts = 4;
390 for (i = 0; i < boot_pdata->nr_parts; i++) {
391 sprintf(names[i], "img%d", 4 - i);
392 parts[i].name = names[i];
393 parts[i].size = 0x400000;
394 parts[i].offset = MTDPART_OFS_NXTBLK;
395 }
396 } else if (bdipsw == 0) {
397 /* BOOT Mode: Monitor ROM */
398 boot_pdata->nr_parts = 2;
399 strcpy(names[0], "big");
400 strcpy(names[1], "little");
401 for (i = 0; i < boot_pdata->nr_parts; i++) {
402 parts[i].name = names[i];
403 parts[i].size = 0x400000;
404 parts[i].offset = MTDPART_OFS_NXTBLK;
405 }
406 } else {
407 /* BOOT Mode: ROM Emulator */
408 boot_pdata->nr_parts = 2;
409 parts[0].name = "boot";
410 parts[0].offset = 0xc00000;
411 parts[0].size = 0x400000;
412 parts[1].name = "user";
413 parts[1].offset = 0;
414 parts[1].size = 0xc00000;
415 }
416 boot_pdata->parts = parts;
417 boot_pdata->map_init = rbtx4939_flash_map_init;
418
419 for (i = 0; i < ARRAY_SIZE(pdevs); i++) {
420 struct resource *r = &pdevs[i].res;
421 struct platform_device *dev = &pdevs[i].dev;
422
423 r->start = 0x1f000000 - i * 0x1000000;
424 r->end = r->start + 0x1000000 - 1;
425 r->flags = IORESOURCE_MEM;
426 pdevs[i].data.width = 2;
427 dev->num_resources = 1;
428 dev->resource = r;
429 dev->id = i;
430 dev->name = "rbtx4939-flash";
431 dev->dev.platform_data = &pdevs[i].data;
432 platform_device_register(dev);
433 }
434}
435#else
436static void __init rbtx4939_mtd_init(void)
437{
438}
439#endif
440
285static void __init rbtx4939_arch_init(void) 441static void __init rbtx4939_arch_init(void)
286{ 442{
287 rbtx4939_pci_setup(); 443 rbtx4939_pci_setup();
@@ -333,6 +489,11 @@ static void __init rbtx4939_device_init(void)
333 platform_device_add_data(pdev, &smc_pdata, sizeof(smc_pdata)) || 489 platform_device_add_data(pdev, &smc_pdata, sizeof(smc_pdata)) ||
334 platform_device_add(pdev)) 490 platform_device_add(pdev))
335 platform_device_put(pdev); 491 platform_device_put(pdev);
492 rbtx4939_mtd_init();
493 /* TC58DVM82A1FT: tDH=10ns, tWP=tRP=tREADID=35ns */
494 tx4939_ndfmc_init(10, 35,
495 (1 << 1) | (1 << 2),
496 (1 << 2)); /* ch1:8bit, ch2:16bit */
336 rbtx4939_led_setup(); 497 rbtx4939_led_setup();
337 tx4939_wdt_init(); 498 tx4939_wdt_init();
338 tx4939_ata_init(); 499 tx4939_ata_init();
diff --git a/arch/powerpc/boot/dts/tqm8548-bigflash.dts b/arch/powerpc/boot/dts/tqm8548-bigflash.dts
index 28b1a95257cd..19aa72301c83 100644
--- a/arch/powerpc/boot/dts/tqm8548-bigflash.dts
+++ b/arch/powerpc/boot/dts/tqm8548-bigflash.dts
@@ -397,10 +397,13 @@
397 upm@3,0 { 397 upm@3,0 {
398 #address-cells = <0>; 398 #address-cells = <0>;
399 #size-cells = <0>; 399 #size-cells = <0>;
400 compatible = "fsl,upm-nand"; 400 compatible = "tqc,tqm8548-upm-nand", "fsl,upm-nand";
401 reg = <3 0x0 0x800>; 401 reg = <3 0x0 0x800>;
402 fsl,upm-addr-offset = <0x10>; 402 fsl,upm-addr-offset = <0x10>;
403 fsl,upm-cmd-offset = <0x08>; 403 fsl,upm-cmd-offset = <0x08>;
404 /* Micron MT29F8G08FAB multi-chip device */
405 fsl,upm-addr-line-cs-offsets = <0x0 0x200>;
406 fsl,upm-wait-flags = <0x5>;
404 chip-delay = <25>; // in micro-seconds 407 chip-delay = <25>; // in micro-seconds
405 408
406 nand@0 { 409 nand@0 {
@@ -409,7 +412,7 @@
409 412
410 partition@0 { 413 partition@0 {
411 label = "fs"; 414 label = "fs";
412 reg = <0x00000000 0x01000000>; 415 reg = <0x00000000 0x10000000>;
413 }; 416 };
414 }; 417 };
415 }; 418 };
diff --git a/arch/powerpc/boot/dts/tqm8548.dts b/arch/powerpc/boot/dts/tqm8548.dts
index 826fb622cd3c..49145a04fc6c 100644
--- a/arch/powerpc/boot/dts/tqm8548.dts
+++ b/arch/powerpc/boot/dts/tqm8548.dts
@@ -397,10 +397,13 @@
397 upm@3,0 { 397 upm@3,0 {
398 #address-cells = <0>; 398 #address-cells = <0>;
399 #size-cells = <0>; 399 #size-cells = <0>;
400 compatible = "fsl,upm-nand"; 400 compatible = "tqc,tqm8548-upm-nand", "fsl,upm-nand";
401 reg = <3 0x0 0x800>; 401 reg = <3 0x0 0x800>;
402 fsl,upm-addr-offset = <0x10>; 402 fsl,upm-addr-offset = <0x10>;
403 fsl,upm-cmd-offset = <0x08>; 403 fsl,upm-cmd-offset = <0x08>;
404 /* Micron MT29F8G08FAB multi-chip device */
405 fsl,upm-addr-line-cs-offsets = <0x0 0x200>;
406 fsl,upm-wait-flags = <0x5>;
404 chip-delay = <25>; // in micro-seconds 407 chip-delay = <25>; // in micro-seconds
405 408
406 nand@0 { 409 nand@0 {
@@ -409,7 +412,7 @@
409 412
410 partition@0 { 413 partition@0 {
411 label = "fs"; 414 label = "fs";
412 reg = <0x00000000 0x01000000>; 415 reg = <0x00000000 0x10000000>;
413 }; 416 };
414 }; 417 };
415 }; 418 };
diff --git a/arch/powerpc/sysdev/fsl_lbc.c b/arch/powerpc/sysdev/fsl_lbc.c
index 0494ee55920f..dceb8d1a843d 100644
--- a/arch/powerpc/sysdev/fsl_lbc.c
+++ b/arch/powerpc/sysdev/fsl_lbc.c
@@ -150,7 +150,7 @@ int fsl_upm_run_pattern(struct fsl_upm *upm, void __iomem *io_base, u32 mar)
150 150
151 spin_lock_irqsave(&fsl_lbc_lock, flags); 151 spin_lock_irqsave(&fsl_lbc_lock, flags);
152 152
153 out_be32(&fsl_lbc_regs->mar, mar << (32 - upm->width)); 153 out_be32(&fsl_lbc_regs->mar, mar);
154 154
155 switch (upm->width) { 155 switch (upm->width) {
156 case 8: 156 case 8:
diff --git a/drivers/mtd/Makefile b/drivers/mtd/Makefile
index 4521b1ecce45..82d1e4de475b 100644
--- a/drivers/mtd/Makefile
+++ b/drivers/mtd/Makefile
@@ -4,7 +4,7 @@
4 4
5# Core functionality. 5# Core functionality.
6obj-$(CONFIG_MTD) += mtd.o 6obj-$(CONFIG_MTD) += mtd.o
7mtd-y := mtdcore.o mtdsuper.o 7mtd-y := mtdcore.o mtdsuper.o mtdbdi.o
8mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o 8mtd-$(CONFIG_MTD_PARTITIONS) += mtdpart.o
9 9
10obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o 10obj-$(CONFIG_MTD_CONCAT) += mtdconcat.o
diff --git a/drivers/mtd/ar7part.c b/drivers/mtd/ar7part.c
index ecf170b55c32..6697a1ec72d0 100644
--- a/drivers/mtd/ar7part.c
+++ b/drivers/mtd/ar7part.c
@@ -44,8 +44,6 @@ struct ar7_bin_rec {
44 unsigned int address; 44 unsigned int address;
45}; 45};
46 46
47static struct mtd_partition ar7_parts[AR7_PARTS];
48
49static int create_mtd_partitions(struct mtd_info *master, 47static int create_mtd_partitions(struct mtd_info *master,
50 struct mtd_partition **pparts, 48 struct mtd_partition **pparts,
51 unsigned long origin) 49 unsigned long origin)
@@ -57,7 +55,11 @@ static int create_mtd_partitions(struct mtd_info *master,
57 unsigned int root_offset = ROOT_OFFSET; 55 unsigned int root_offset = ROOT_OFFSET;
58 56
59 int retries = 10; 57 int retries = 10;
58 struct mtd_partition *ar7_parts;
60 59
60 ar7_parts = kzalloc(sizeof(*ar7_parts) * AR7_PARTS, GFP_KERNEL);
61 if (!ar7_parts)
62 return -ENOMEM;
61 ar7_parts[0].name = "loader"; 63 ar7_parts[0].name = "loader";
62 ar7_parts[0].offset = 0; 64 ar7_parts[0].offset = 0;
63 ar7_parts[0].size = master->erasesize; 65 ar7_parts[0].size = master->erasesize;
diff --git a/drivers/mtd/chips/cfi_cmdset_0001.c b/drivers/mtd/chips/cfi_cmdset_0001.c
index f5ab6fa1057b..c240454fd113 100644
--- a/drivers/mtd/chips/cfi_cmdset_0001.c
+++ b/drivers/mtd/chips/cfi_cmdset_0001.c
@@ -1236,10 +1236,14 @@ static int inval_cache_and_wait_for_operation(
1236 remove_wait_queue(&chip->wq, &wait); 1236 remove_wait_queue(&chip->wq, &wait);
1237 spin_lock(chip->mutex); 1237 spin_lock(chip->mutex);
1238 } 1238 }
1239 if (chip->erase_suspended || chip->write_suspended) { 1239 if (chip->erase_suspended && chip_state == FL_ERASING) {
1240 /* Suspend has occured while sleep: reset timeout */ 1240 /* Erase suspend occured while sleep: reset timeout */
1241 timeo = reset_timeo; 1241 timeo = reset_timeo;
1242 chip->erase_suspended = 0; 1242 chip->erase_suspended = 0;
1243 }
1244 if (chip->write_suspended && chip_state == FL_WRITING) {
1245 /* Write suspend occured while sleep: reset timeout */
1246 timeo = reset_timeo;
1243 chip->write_suspended = 0; 1247 chip->write_suspended = 0;
1244 } 1248 }
1245 } 1249 }
diff --git a/drivers/mtd/chips/cfi_cmdset_0002.c b/drivers/mtd/chips/cfi_cmdset_0002.c
index 94bb61e19047..61ea833e0908 100644
--- a/drivers/mtd/chips/cfi_cmdset_0002.c
+++ b/drivers/mtd/chips/cfi_cmdset_0002.c
@@ -282,6 +282,16 @@ static void fixup_s29gl032n_sectors(struct mtd_info *mtd, void *param)
282 } 282 }
283} 283}
284 284
285static void fixup_M29W128G_write_buffer(struct mtd_info *mtd, void *param)
286{
287 struct map_info *map = mtd->priv;
288 struct cfi_private *cfi = map->fldrv_priv;
289 if (cfi->cfiq->BufWriteTimeoutTyp) {
290 pr_warning("Don't use write buffer on ST flash M29W128G\n");
291 cfi->cfiq->BufWriteTimeoutTyp = 0;
292 }
293}
294
285static struct cfi_fixup cfi_fixup_table[] = { 295static struct cfi_fixup cfi_fixup_table[] = {
286 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL }, 296 { CFI_MFR_ATMEL, CFI_ID_ANY, fixup_convert_atmel_pri, NULL },
287#ifdef AMD_BOOTLOC_BUG 297#ifdef AMD_BOOTLOC_BUG
@@ -298,6 +308,7 @@ static struct cfi_fixup cfi_fixup_table[] = {
298 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors, NULL, }, 308 { CFI_MFR_AMD, 0x1301, fixup_s29gl064n_sectors, NULL, },
299 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors, NULL, }, 309 { CFI_MFR_AMD, 0x1a00, fixup_s29gl032n_sectors, NULL, },
300 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors, NULL, }, 310 { CFI_MFR_AMD, 0x1a01, fixup_s29gl032n_sectors, NULL, },
311 { CFI_MFR_ST, 0x227E, fixup_M29W128G_write_buffer, NULL, },
301#if !FORCE_WORD_WRITE 312#if !FORCE_WORD_WRITE
302 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, }, 313 { CFI_MFR_ANY, CFI_ID_ANY, fixup_use_write_buffers, NULL, },
303#endif 314#endif
diff --git a/drivers/mtd/chips/jedec_probe.c b/drivers/mtd/chips/jedec_probe.c
index 2f3f2f719ba4..e824b9b9b056 100644
--- a/drivers/mtd/chips/jedec_probe.c
+++ b/drivers/mtd/chips/jedec_probe.c
@@ -159,6 +159,7 @@
159#define SST39LF800 0x2781 159#define SST39LF800 0x2781
160#define SST39LF160 0x2782 160#define SST39LF160 0x2782
161#define SST39VF1601 0x234b 161#define SST39VF1601 0x234b
162#define SST39VF3201 0x235b
162#define SST39LF512 0x00D4 163#define SST39LF512 0x00D4
163#define SST39LF010 0x00D5 164#define SST39LF010 0x00D5
164#define SST39LF020 0x00D6 165#define SST39LF020 0x00D6
@@ -1490,6 +1491,21 @@ static const struct amd_flash_info jedec_table[] = {
1490 ERASEINFO(0x1000,256) 1491 ERASEINFO(0x1000,256)
1491 } 1492 }
1492 }, { 1493 }, {
1494 .mfr_id = MANUFACTURER_SST, /* should be CFI */
1495 .dev_id = SST39VF3201,
1496 .name = "SST 39VF3201",
1497 .devtypes = CFI_DEVICETYPE_X16,
1498 .uaddr = MTD_UADDR_0xAAAA_0x5555,
1499 .dev_size = SIZE_4MiB,
1500 .cmd_set = P_ID_AMD_STD,
1501 .nr_regions = 4,
1502 .regions = {
1503 ERASEINFO(0x1000,256),
1504 ERASEINFO(0x1000,256),
1505 ERASEINFO(0x1000,256),
1506 ERASEINFO(0x1000,256)
1507 }
1508 }, {
1493 .mfr_id = MANUFACTURER_SST, 1509 .mfr_id = MANUFACTURER_SST,
1494 .dev_id = SST36VF3203, 1510 .dev_id = SST36VF3203,
1495 .name = "SST 36VF3203", 1511 .name = "SST 36VF3203",
diff --git a/drivers/mtd/chips/map_ram.c b/drivers/mtd/chips/map_ram.c
index 072dd8abf33a..6bdc50c727e7 100644
--- a/drivers/mtd/chips/map_ram.c
+++ b/drivers/mtd/chips/map_ram.c
@@ -21,6 +21,8 @@ static int mapram_write (struct mtd_info *, loff_t, size_t, size_t *, const u_ch
21static int mapram_erase (struct mtd_info *, struct erase_info *); 21static int mapram_erase (struct mtd_info *, struct erase_info *);
22static void mapram_nop (struct mtd_info *); 22static void mapram_nop (struct mtd_info *);
23static struct mtd_info *map_ram_probe(struct map_info *map); 23static struct mtd_info *map_ram_probe(struct map_info *map);
24static unsigned long mapram_unmapped_area(struct mtd_info *, unsigned long,
25 unsigned long, unsigned long);
24 26
25 27
26static struct mtd_chip_driver mapram_chipdrv = { 28static struct mtd_chip_driver mapram_chipdrv = {
@@ -64,6 +66,7 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
64 mtd->type = MTD_RAM; 66 mtd->type = MTD_RAM;
65 mtd->size = map->size; 67 mtd->size = map->size;
66 mtd->erase = mapram_erase; 68 mtd->erase = mapram_erase;
69 mtd->get_unmapped_area = mapram_unmapped_area;
67 mtd->read = mapram_read; 70 mtd->read = mapram_read;
68 mtd->write = mapram_write; 71 mtd->write = mapram_write;
69 mtd->sync = mapram_nop; 72 mtd->sync = mapram_nop;
@@ -79,6 +82,20 @@ static struct mtd_info *map_ram_probe(struct map_info *map)
79} 82}
80 83
81 84
85/*
86 * Allow NOMMU mmap() to directly map the device (if not NULL)
87 * - return the address to which the offset maps
88 * - return -ENOSYS to indicate refusal to do the mapping
89 */
90static unsigned long mapram_unmapped_area(struct mtd_info *mtd,
91 unsigned long len,
92 unsigned long offset,
93 unsigned long flags)
94{
95 struct map_info *map = mtd->priv;
96 return (unsigned long) map->virt + offset;
97}
98
82static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) 99static int mapram_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
83{ 100{
84 struct map_info *map = mtd->priv; 101 struct map_info *map = mtd->priv;
diff --git a/drivers/mtd/chips/map_rom.c b/drivers/mtd/chips/map_rom.c
index c76d6e5f47ee..076090a67b90 100644
--- a/drivers/mtd/chips/map_rom.c
+++ b/drivers/mtd/chips/map_rom.c
@@ -20,6 +20,8 @@ static int maprom_write (struct mtd_info *, loff_t, size_t, size_t *, const u_ch
20static void maprom_nop (struct mtd_info *); 20static void maprom_nop (struct mtd_info *);
21static struct mtd_info *map_rom_probe(struct map_info *map); 21static struct mtd_info *map_rom_probe(struct map_info *map);
22static int maprom_erase (struct mtd_info *mtd, struct erase_info *info); 22static int maprom_erase (struct mtd_info *mtd, struct erase_info *info);
23static unsigned long maprom_unmapped_area(struct mtd_info *, unsigned long,
24 unsigned long, unsigned long);
23 25
24static struct mtd_chip_driver maprom_chipdrv = { 26static struct mtd_chip_driver maprom_chipdrv = {
25 .probe = map_rom_probe, 27 .probe = map_rom_probe,
@@ -40,6 +42,7 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
40 mtd->name = map->name; 42 mtd->name = map->name;
41 mtd->type = MTD_ROM; 43 mtd->type = MTD_ROM;
42 mtd->size = map->size; 44 mtd->size = map->size;
45 mtd->get_unmapped_area = maprom_unmapped_area;
43 mtd->read = maprom_read; 46 mtd->read = maprom_read;
44 mtd->write = maprom_write; 47 mtd->write = maprom_write;
45 mtd->sync = maprom_nop; 48 mtd->sync = maprom_nop;
@@ -53,6 +56,20 @@ static struct mtd_info *map_rom_probe(struct map_info *map)
53} 56}
54 57
55 58
59/*
60 * Allow NOMMU mmap() to directly map the device (if not NULL)
61 * - return the address to which the offset maps
62 * - return -ENOSYS to indicate refusal to do the mapping
63 */
64static unsigned long maprom_unmapped_area(struct mtd_info *mtd,
65 unsigned long len,
66 unsigned long offset,
67 unsigned long flags)
68{
69 struct map_info *map = mtd->priv;
70 return (unsigned long) map->virt + offset;
71}
72
56static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) 73static int maprom_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf)
57{ 74{
58 struct map_info *map = mtd->priv; 75 struct map_info *map = mtd->priv;
diff --git a/drivers/mtd/cmdlinepart.c b/drivers/mtd/cmdlinepart.c
index 50a340388e74..5011fa73f918 100644
--- a/drivers/mtd/cmdlinepart.c
+++ b/drivers/mtd/cmdlinepart.c
@@ -335,7 +335,11 @@ static int parse_cmdline_partitions(struct mtd_info *master,
335 } 335 }
336 offset += part->parts[i].size; 336 offset += part->parts[i].size;
337 } 337 }
338 *pparts = part->parts; 338 *pparts = kmemdup(part->parts,
339 sizeof(*part->parts) * part->num_parts,
340 GFP_KERNEL);
341 if (!*pparts)
342 return -ENOMEM;
339 return part->num_parts; 343 return part->num_parts;
340 } 344 }
341 } 345 }
diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
index 50de839c77a9..5bf5f460e132 100644
--- a/drivers/mtd/devices/doc2000.c
+++ b/drivers/mtd/devices/doc2000.c
@@ -10,7 +10,6 @@
10#include <asm/errno.h> 10#include <asm/errno.h>
11#include <asm/io.h> 11#include <asm/io.h>
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13#include <linux/miscdevice.h>
14#include <linux/delay.h> 13#include <linux/delay.h>
15#include <linux/slab.h> 14#include <linux/slab.h>
16#include <linux/sched.h> 15#include <linux/sched.h>
diff --git a/drivers/mtd/devices/doc2001.c b/drivers/mtd/devices/doc2001.c
index e32c568c1145..0990f7803628 100644
--- a/drivers/mtd/devices/doc2001.c
+++ b/drivers/mtd/devices/doc2001.c
@@ -10,7 +10,6 @@
10#include <asm/errno.h> 10#include <asm/errno.h>
11#include <asm/io.h> 11#include <asm/io.h>
12#include <asm/uaccess.h> 12#include <asm/uaccess.h>
13#include <linux/miscdevice.h>
14#include <linux/delay.h> 13#include <linux/delay.h>
15#include <linux/slab.h> 14#include <linux/slab.h>
16#include <linux/init.h> 15#include <linux/init.h>
diff --git a/drivers/mtd/devices/doc2001plus.c b/drivers/mtd/devices/doc2001plus.c
index d853f891b586..719b2915dc3a 100644
--- a/drivers/mtd/devices/doc2001plus.c
+++ b/drivers/mtd/devices/doc2001plus.c
@@ -14,7 +14,6 @@
14#include <asm/errno.h> 14#include <asm/errno.h>
15#include <asm/io.h> 15#include <asm/io.h>
16#include <asm/uaccess.h> 16#include <asm/uaccess.h>
17#include <linux/miscdevice.h>
18#include <linux/delay.h> 17#include <linux/delay.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
20#include <linux/init.h> 19#include <linux/init.h>
diff --git a/drivers/mtd/devices/docecc.c b/drivers/mtd/devices/docecc.c
index 874e51b110a2..a19cda52da5c 100644
--- a/drivers/mtd/devices/docecc.c
+++ b/drivers/mtd/devices/docecc.c
@@ -26,7 +26,6 @@
26#include <asm/errno.h> 26#include <asm/errno.h>
27#include <asm/io.h> 27#include <asm/io.h>
28#include <asm/uaccess.h> 28#include <asm/uaccess.h>
29#include <linux/miscdevice.h>
30#include <linux/delay.h> 29#include <linux/delay.h>
31#include <linux/slab.h> 30#include <linux/slab.h>
32#include <linux/init.h> 31#include <linux/init.h>
diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index 7c3fc766dcf1..8185b1f3e5e6 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -65,12 +65,6 @@
65#define FAST_READ_DUMMY_BYTE 0 65#define FAST_READ_DUMMY_BYTE 0
66#endif 66#endif
67 67
68#ifdef CONFIG_MTD_PARTITIONS
69#define mtd_has_partitions() (1)
70#else
71#define mtd_has_partitions() (0)
72#endif
73
74/****************************************************************************/ 68/****************************************************************************/
75 69
76struct m25p { 70struct m25p {
@@ -678,6 +672,8 @@ static int __devinit m25p_probe(struct spi_device *spi)
678 flash->mtd.erasesize = info->sector_size; 672 flash->mtd.erasesize = info->sector_size;
679 } 673 }
680 674
675 flash->mtd.dev.parent = &spi->dev;
676
681 dev_info(&spi->dev, "%s (%lld Kbytes)\n", info->name, 677 dev_info(&spi->dev, "%s (%lld Kbytes)\n", info->name,
682 (long long)flash->mtd.size >> 10); 678 (long long)flash->mtd.size >> 10);
683 679
@@ -708,12 +704,13 @@ static int __devinit m25p_probe(struct spi_device *spi)
708 struct mtd_partition *parts = NULL; 704 struct mtd_partition *parts = NULL;
709 int nr_parts = 0; 705 int nr_parts = 0;
710 706
711#ifdef CONFIG_MTD_CMDLINE_PARTS 707 if (mtd_has_cmdlinepart()) {
712 static const char *part_probes[] = { "cmdlinepart", NULL, }; 708 static const char *part_probes[]
709 = { "cmdlinepart", NULL, };
713 710
714 nr_parts = parse_mtd_partitions(&flash->mtd, 711 nr_parts = parse_mtd_partitions(&flash->mtd,
715 part_probes, &parts, 0); 712 part_probes, &parts, 0);
716#endif 713 }
717 714
718 if (nr_parts <= 0 && data && data->parts) { 715 if (nr_parts <= 0 && data && data->parts) {
719 parts = data->parts; 716 parts = data->parts;
diff --git a/drivers/mtd/devices/mtd_dataflash.c b/drivers/mtd/devices/mtd_dataflash.c
index 6d9f810565c8..62dee54af0a5 100644
--- a/drivers/mtd/devices/mtd_dataflash.c
+++ b/drivers/mtd/devices/mtd_dataflash.c
@@ -98,12 +98,6 @@ struct dataflash {
98 struct mtd_info mtd; 98 struct mtd_info mtd;
99}; 99};
100 100
101#ifdef CONFIG_MTD_PARTITIONS
102#define mtd_has_partitions() (1)
103#else
104#define mtd_has_partitions() (0)
105#endif
106
107/* ......................................................................... */ 101/* ......................................................................... */
108 102
109/* 103/*
@@ -670,6 +664,8 @@ add_dataflash_otp(struct spi_device *spi, char *name,
670 device->write = dataflash_write; 664 device->write = dataflash_write;
671 device->priv = priv; 665 device->priv = priv;
672 666
667 device->dev.parent = &spi->dev;
668
673 if (revision >= 'c') 669 if (revision >= 'c')
674 otp_tag = otp_setup(device, revision); 670 otp_tag = otp_setup(device, revision);
675 671
@@ -682,11 +678,13 @@ add_dataflash_otp(struct spi_device *spi, char *name,
682 struct mtd_partition *parts; 678 struct mtd_partition *parts;
683 int nr_parts = 0; 679 int nr_parts = 0;
684 680
685#ifdef CONFIG_MTD_CMDLINE_PARTS 681 if (mtd_has_cmdlinepart()) {
686 static const char *part_probes[] = { "cmdlinepart", NULL, }; 682 static const char *part_probes[]
683 = { "cmdlinepart", NULL, };
687 684
688 nr_parts = parse_mtd_partitions(device, part_probes, &parts, 0); 685 nr_parts = parse_mtd_partitions(device,
689#endif 686 part_probes, &parts, 0);
687 }
690 688
691 if (nr_parts <= 0 && pdata && pdata->parts) { 689 if (nr_parts <= 0 && pdata && pdata->parts) {
692 parts = pdata->parts; 690 parts = pdata->parts;
diff --git a/drivers/mtd/devices/mtdram.c b/drivers/mtd/devices/mtdram.c
index 3aaca88847d3..fce5ff7589aa 100644
--- a/drivers/mtd/devices/mtdram.c
+++ b/drivers/mtd/devices/mtdram.c
@@ -65,6 +65,19 @@ static void ram_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
65{ 65{
66} 66}
67 67
68/*
69 * Allow NOMMU mmap() to directly map the device (if not NULL)
70 * - return the address to which the offset maps
71 * - return -ENOSYS to indicate refusal to do the mapping
72 */
73static unsigned long ram_get_unmapped_area(struct mtd_info *mtd,
74 unsigned long len,
75 unsigned long offset,
76 unsigned long flags)
77{
78 return (unsigned long) mtd->priv + offset;
79}
80
68static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, 81static int ram_read(struct mtd_info *mtd, loff_t from, size_t len,
69 size_t *retlen, u_char *buf) 82 size_t *retlen, u_char *buf)
70{ 83{
@@ -116,6 +129,7 @@ int mtdram_init_device(struct mtd_info *mtd, void *mapped_address,
116 mtd->erase = ram_erase; 129 mtd->erase = ram_erase;
117 mtd->point = ram_point; 130 mtd->point = ram_point;
118 mtd->unpoint = ram_unpoint; 131 mtd->unpoint = ram_unpoint;
132 mtd->get_unmapped_area = ram_get_unmapped_area;
119 mtd->read = ram_read; 133 mtd->read = ram_read;
120 mtd->write = ram_write; 134 mtd->write = ram_write;
121 135
diff --git a/drivers/mtd/inftlmount.c b/drivers/mtd/inftlmount.c
index f751dd97c549..32e82aef3e53 100644
--- a/drivers/mtd/inftlmount.c
+++ b/drivers/mtd/inftlmount.c
@@ -28,7 +28,6 @@
28#include <asm/errno.h> 28#include <asm/errno.h>
29#include <asm/io.h> 29#include <asm/io.h>
30#include <asm/uaccess.h> 30#include <asm/uaccess.h>
31#include <linux/miscdevice.h>
32#include <linux/delay.h> 31#include <linux/delay.h>
33#include <linux/slab.h> 32#include <linux/slab.h>
34#include <linux/init.h> 33#include <linux/init.h>
diff --git a/drivers/mtd/internal.h b/drivers/mtd/internal.h
new file mode 100644
index 000000000000..c658fe7216b5
--- /dev/null
+++ b/drivers/mtd/internal.h
@@ -0,0 +1,17 @@
1/* Internal MTD definitions
2 *
3 * Copyright © 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12/*
13 * mtdbdi.c
14 */
15extern struct backing_dev_info mtd_bdi_unmappable;
16extern struct backing_dev_info mtd_bdi_ro_mappable;
17extern struct backing_dev_info mtd_bdi_rw_mappable;
diff --git a/drivers/mtd/maps/Kconfig b/drivers/mtd/maps/Kconfig
index 729f899a5cd5..82923bd2d9c5 100644
--- a/drivers/mtd/maps/Kconfig
+++ b/drivers/mtd/maps/Kconfig
@@ -529,12 +529,6 @@ config MTD_DMV182
529 help 529 help
530 Map driver for Dy-4 SVME/DMV-182 board. 530 Map driver for Dy-4 SVME/DMV-182 board.
531 531
532config MTD_SHARP_SL
533 tristate "ROM mapped on Sharp SL Series"
534 depends on ARCH_PXA
535 help
536 This enables access to the flash chip on the Sharp SL Series of PDAs.
537
538config MTD_INTEL_VR_NOR 532config MTD_INTEL_VR_NOR
539 tristate "NOR flash on Intel Vermilion Range Expansion Bus CS0" 533 tristate "NOR flash on Intel Vermilion Range Expansion Bus CS0"
540 depends on PCI 534 depends on PCI
@@ -542,6 +536,12 @@ config MTD_INTEL_VR_NOR
542 Map driver for a NOR flash bank located on the Expansion Bus of the 536 Map driver for a NOR flash bank located on the Expansion Bus of the
543 Intel Vermilion Range chipset. 537 Intel Vermilion Range chipset.
544 538
539config MTD_RBTX4939
540 tristate "Map driver for RBTX4939 board"
541 depends on TOSHIBA_RBTX4939 && MTD_CFI && MTD_COMPLEX_MAPPINGS
542 help
543 Map driver for NOR flash chips on RBTX4939 board.
544
545config MTD_PLATRAM 545config MTD_PLATRAM
546 tristate "Map driver for platform device RAM (mtd-ram)" 546 tristate "Map driver for platform device RAM (mtd-ram)"
547 select MTD_RAM 547 select MTD_RAM
diff --git a/drivers/mtd/maps/Makefile b/drivers/mtd/maps/Makefile
index 26b28a7a90b5..2dbc1bec8488 100644
--- a/drivers/mtd/maps/Makefile
+++ b/drivers/mtd/maps/Makefile
@@ -56,9 +56,9 @@ obj-$(CONFIG_MTD_IXP4XX) += ixp4xx.o
56obj-$(CONFIG_MTD_IXP2000) += ixp2000.o 56obj-$(CONFIG_MTD_IXP2000) += ixp2000.o
57obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o 57obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o
58obj-$(CONFIG_MTD_DMV182) += dmv182.o 58obj-$(CONFIG_MTD_DMV182) += dmv182.o
59obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o
60obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o 59obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o
61obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o 60obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
62obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o 61obj-$(CONFIG_MTD_INTEL_VR_NOR) += intel_vr_nor.o
63obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o 62obj-$(CONFIG_MTD_BFIN_ASYNC) += bfin-async-flash.o
63obj-$(CONFIG_MTD_RBTX4939) += rbtx4939-flash.o
64obj-$(CONFIG_MTD_VMU) += vmu-flash.o 64obj-$(CONFIG_MTD_VMU) += vmu-flash.o
diff --git a/drivers/mtd/maps/omap_nor.c b/drivers/mtd/maps/omap_nor.c
index 7e50e9b1b781..a24478102b11 100644
--- a/drivers/mtd/maps/omap_nor.c
+++ b/drivers/mtd/maps/omap_nor.c
@@ -115,6 +115,8 @@ static int __init omapflash_probe(struct platform_device *pdev)
115 } 115 }
116 info->mtd->owner = THIS_MODULE; 116 info->mtd->owner = THIS_MODULE;
117 117
118 info->mtd->dev.parent = &pdev->dev;
119
118#ifdef CONFIG_MTD_PARTITIONS 120#ifdef CONFIG_MTD_PARTITIONS
119 err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0); 121 err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0);
120 if (err > 0) 122 if (err > 0)
diff --git a/drivers/mtd/maps/physmap.c b/drivers/mtd/maps/physmap.c
index 229718222db7..29a901157352 100644
--- a/drivers/mtd/maps/physmap.c
+++ b/drivers/mtd/maps/physmap.c
@@ -147,6 +147,7 @@ static int physmap_flash_probe(struct platform_device *dev)
147 devices_found++; 147 devices_found++;
148 } 148 }
149 info->mtd[i]->owner = THIS_MODULE; 149 info->mtd[i]->owner = THIS_MODULE;
150 info->mtd[i]->dev.parent = &dev->dev;
150 } 151 }
151 152
152 if (devices_found == 1) { 153 if (devices_found == 1) {
diff --git a/drivers/mtd/maps/physmap_of.c b/drivers/mtd/maps/physmap_of.c
index fbf0ca939d72..c83a60fada53 100644
--- a/drivers/mtd/maps/physmap_of.c
+++ b/drivers/mtd/maps/physmap_of.c
@@ -219,6 +219,7 @@ static int __devinit of_flash_probe(struct of_device *dev,
219 goto err_out; 219 goto err_out;
220 } 220 }
221 info->mtd->owner = THIS_MODULE; 221 info->mtd->owner = THIS_MODULE;
222 info->mtd->dev.parent = &dev->dev;
222 223
223#ifdef CONFIG_MTD_PARTITIONS 224#ifdef CONFIG_MTD_PARTITIONS
224 /* First look for RedBoot table or partitions on the command 225 /* First look for RedBoot table or partitions on the command
diff --git a/drivers/mtd/maps/plat-ram.c b/drivers/mtd/maps/plat-ram.c
index e7dd9c8a965e..49c9ece76477 100644
--- a/drivers/mtd/maps/plat-ram.c
+++ b/drivers/mtd/maps/plat-ram.c
@@ -224,6 +224,7 @@ static int platram_probe(struct platform_device *pdev)
224 } 224 }
225 225
226 info->mtd->owner = THIS_MODULE; 226 info->mtd->owner = THIS_MODULE;
227 info->mtd->dev.parent = &pdev->dev;
227 228
228 platram_setrw(info, PLATRAM_RW); 229 platram_setrw(info, PLATRAM_RW);
229 230
diff --git a/drivers/mtd/maps/rbtx4939-flash.c b/drivers/mtd/maps/rbtx4939-flash.c
new file mode 100644
index 000000000000..d39f0adac846
--- /dev/null
+++ b/drivers/mtd/maps/rbtx4939-flash.c
@@ -0,0 +1,208 @@
1/*
2 * rbtx4939-flash (based on physmap.c)
3 *
4 * This is a simplified physmap driver with map_init callback function.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * Copyright (C) 2009 Atsushi Nemoto <anemo@mba.ocn.ne.jp>
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/kernel.h>
16#include <linux/init.h>
17#include <linux/slab.h>
18#include <linux/device.h>
19#include <linux/platform_device.h>
20#include <linux/mtd/mtd.h>
21#include <linux/mtd/map.h>
22#include <linux/mtd/partitions.h>
23#include <asm/txx9/rbtx4939.h>
24
25struct rbtx4939_flash_info {
26 struct mtd_info *mtd;
27 struct map_info map;
28#ifdef CONFIG_MTD_PARTITIONS
29 int nr_parts;
30 struct mtd_partition *parts;
31#endif
32};
33
34static int rbtx4939_flash_remove(struct platform_device *dev)
35{
36 struct rbtx4939_flash_info *info;
37
38 info = platform_get_drvdata(dev);
39 if (!info)
40 return 0;
41 platform_set_drvdata(dev, NULL);
42
43 if (info->mtd) {
44#ifdef CONFIG_MTD_PARTITIONS
45 struct rbtx4939_flash_data *pdata = dev->dev.platform_data;
46
47 if (info->nr_parts) {
48 del_mtd_partitions(info->mtd);
49 kfree(info->parts);
50 } else if (pdata->nr_parts)
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);
58 }
59 return 0;
60}
61
62static const char *rom_probe_types[] = { "cfi_probe", "jedec_probe", NULL };
63#ifdef CONFIG_MTD_PARTITIONS
64static const char *part_probe_types[] = { "cmdlinepart", NULL };
65#endif
66
67static int rbtx4939_flash_probe(struct platform_device *dev)
68{
69 struct rbtx4939_flash_data *pdata;
70 struct rbtx4939_flash_info *info;
71 struct resource *res;
72 const char **probe_type;
73 int err = 0;
74 unsigned long size;
75
76 pdata = dev->dev.platform_data;
77 if (!pdata)
78 return -ENODEV;
79
80 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
81 if (!res)
82 return -ENODEV;
83 info = devm_kzalloc(&dev->dev, sizeof(struct rbtx4939_flash_info),
84 GFP_KERNEL);
85 if (!info)
86 return -ENOMEM;
87
88 platform_set_drvdata(dev, info);
89
90 size = resource_size(res);
91 pr_notice("rbtx4939 platform flash device: %pR\n", res);
92
93 if (!devm_request_mem_region(&dev->dev, res->start, size,
94 dev_name(&dev->dev)))
95 return -EBUSY;
96
97 info->map.name = dev_name(&dev->dev);
98 info->map.phys = res->start;
99 info->map.size = size;
100 info->map.bankwidth = pdata->width;
101
102 info->map.virt = devm_ioremap(&dev->dev, info->map.phys, size);
103 if (!info->map.virt)
104 return -EBUSY;
105
106 if (pdata->map_init)
107 (*pdata->map_init)(&info->map);
108 else
109 simple_map_init(&info->map);
110
111 probe_type = rom_probe_types;
112 for (; !info->mtd && *probe_type; probe_type++)
113 info->mtd = do_map_probe(*probe_type, &info->map);
114 if (!info->mtd) {
115 dev_err(&dev->dev, "map_probe failed\n");
116 err = -ENXIO;
117 goto err_out;
118 }
119 info->mtd->owner = THIS_MODULE;
120 if (err)
121 goto err_out;
122
123#ifdef CONFIG_MTD_PARTITIONS
124 err = parse_mtd_partitions(info->mtd, part_probe_types,
125 &info->parts, 0);
126 if (err > 0) {
127 add_mtd_partitions(info->mtd, info->parts, err);
128 info->nr_parts = err;
129 return 0;
130 }
131
132 if (pdata->nr_parts) {
133 pr_notice("Using rbtx4939 partition information\n");
134 add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts);
135 return 0;
136 }
137#endif
138
139 add_mtd_device(info->mtd);
140 return 0;
141
142err_out:
143 rbtx4939_flash_remove(dev);
144 return err;
145}
146
147#ifdef CONFIG_PM
148static int rbtx4939_flash_suspend(struct platform_device *dev,
149 pm_message_t state)
150{
151 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
152
153 if (info->mtd->suspend)
154 return info->mtd->suspend(info->mtd);
155 return 0;
156}
157
158static int rbtx4939_flash_resume(struct platform_device *dev)
159{
160 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
161
162 if (info->mtd->resume)
163 info->mtd->resume(info->mtd);
164 return 0;
165}
166
167static void rbtx4939_flash_shutdown(struct platform_device *dev)
168{
169 struct rbtx4939_flash_info *info = platform_get_drvdata(dev);
170
171 if (info->mtd->suspend && info->mtd->resume)
172 if (info->mtd->suspend(info->mtd) == 0)
173 info->mtd->resume(info->mtd);
174}
175#else
176#define rbtx4939_flash_suspend NULL
177#define rbtx4939_flash_resume NULL
178#define rbtx4939_flash_shutdown NULL
179#endif
180
181static struct platform_driver rbtx4939_flash_driver = {
182 .probe = rbtx4939_flash_probe,
183 .remove = rbtx4939_flash_remove,
184 .suspend = rbtx4939_flash_suspend,
185 .resume = rbtx4939_flash_resume,
186 .shutdown = rbtx4939_flash_shutdown,
187 .driver = {
188 .name = "rbtx4939-flash",
189 .owner = THIS_MODULE,
190 },
191};
192
193static int __init rbtx4939_flash_init(void)
194{
195 return platform_driver_register(&rbtx4939_flash_driver);
196}
197
198static void __exit rbtx4939_flash_exit(void)
199{
200 platform_driver_unregister(&rbtx4939_flash_driver);
201}
202
203module_init(rbtx4939_flash_init);
204module_exit(rbtx4939_flash_exit);
205
206MODULE_LICENSE("GPL");
207MODULE_DESCRIPTION("RBTX4939 MTD map driver");
208MODULE_ALIAS("platform:rbtx4939-flash");
diff --git a/drivers/mtd/maps/sa1100-flash.c b/drivers/mtd/maps/sa1100-flash.c
index 8f57b6f40aa2..05e9362dc7f0 100644
--- a/drivers/mtd/maps/sa1100-flash.c
+++ b/drivers/mtd/maps/sa1100-flash.c
@@ -351,7 +351,7 @@ sa1100_setup_mtd(struct platform_device *pdev, struct flash_platform_data *plat)
351 351
352static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL }; 352static const char *part_probes[] = { "cmdlinepart", "RedBoot", NULL };
353 353
354static int __init sa1100_mtd_probe(struct platform_device *pdev) 354static int __devinit sa1100_mtd_probe(struct platform_device *pdev)
355{ 355{
356 struct flash_platform_data *plat = pdev->dev.platform_data; 356 struct flash_platform_data *plat = pdev->dev.platform_data;
357 struct mtd_partition *parts; 357 struct mtd_partition *parts;
diff --git a/drivers/mtd/maps/sharpsl-flash.c b/drivers/mtd/maps/sharpsl-flash.c
deleted file mode 100644
index b392f096c706..000000000000
--- a/drivers/mtd/maps/sharpsl-flash.c
+++ /dev/null
@@ -1,116 +0,0 @@
1/*
2 * sharpsl-flash.c
3 *
4 * Copyright (C) 2001 Lineo Japan, Inc.
5 * Copyright (C) 2002 SHARP
6 *
7 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp
8 * Handle mapping of the flash on the RPX Lite and CLLF boards
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 */
21
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/kernel.h>
25#include <linux/mtd/mtd.h>
26#include <linux/mtd/map.h>
27#include <linux/mtd/partitions.h>
28#include <asm/io.h>
29#include <asm/mach-types.h>
30
31#define WINDOW_ADDR 0x00000000
32#define WINDOW_SIZE 0x00800000
33#define BANK_WIDTH 2
34
35static struct mtd_info *mymtd;
36
37struct map_info sharpsl_map = {
38 .name = "sharpsl-flash",
39 .size = WINDOW_SIZE,
40 .bankwidth = BANK_WIDTH,
41 .phys = WINDOW_ADDR
42};
43
44static struct mtd_partition sharpsl_partitions[1] = {
45 {
46 name: "Boot PROM Filesystem",
47 }
48};
49
50static int __init init_sharpsl(void)
51{
52 struct mtd_partition *parts;
53 int nb_parts = 0;
54 char *part_type = "static";
55
56 printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n",
57 WINDOW_SIZE, WINDOW_ADDR);
58 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
59 if (!sharpsl_map.virt) {
60 printk("Failed to ioremap\n");
61 return -EIO;
62 }
63
64 simple_map_init(&sharpsl_map);
65
66 mymtd = do_map_probe("map_rom", &sharpsl_map);
67 if (!mymtd) {
68 iounmap(sharpsl_map.virt);
69 return -ENXIO;
70 }
71
72 mymtd->owner = THIS_MODULE;
73
74 if (machine_is_corgi() || machine_is_shepherd() || machine_is_husky()
75 || machine_is_poodle()) {
76 sharpsl_partitions[0].size=0x006d0000;
77 sharpsl_partitions[0].offset=0x00120000;
78 } else if (machine_is_tosa()) {
79 sharpsl_partitions[0].size=0x006a0000;
80 sharpsl_partitions[0].offset=0x00160000;
81 } else if (machine_is_spitz() || machine_is_akita() || machine_is_borzoi()) {
82 sharpsl_partitions[0].size=0x006b0000;
83 sharpsl_partitions[0].offset=0x00140000;
84 } else {
85 map_destroy(mymtd);
86 iounmap(sharpsl_map.virt);
87 return -ENODEV;
88 }
89
90 parts = sharpsl_partitions;
91 nb_parts = ARRAY_SIZE(sharpsl_partitions);
92
93 printk(KERN_NOTICE "Using %s partition definition\n", part_type);
94 add_mtd_partitions(mymtd, parts, nb_parts);
95
96 return 0;
97}
98
99static void __exit cleanup_sharpsl(void)
100{
101 if (mymtd) {
102 del_mtd_partitions(mymtd);
103 map_destroy(mymtd);
104 }
105 if (sharpsl_map.virt) {
106 iounmap(sharpsl_map.virt);
107 sharpsl_map.virt = 0;
108 }
109}
110
111module_init(init_sharpsl);
112module_exit(cleanup_sharpsl);
113
114MODULE_LICENSE("GPL");
115MODULE_AUTHOR("SHARP (Original: Arnold Christensen <AKC@pel.dk>)");
116MODULE_DESCRIPTION("MTD map driver for SHARP SL series");
diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c
index 1409f01406f6..a49a9c8f2cb1 100644
--- a/drivers/mtd/mtd_blkdevs.c
+++ b/drivers/mtd/mtd_blkdevs.c
@@ -286,6 +286,7 @@ int add_mtd_blktrans_dev(struct mtd_blktrans_dev *new)
286 gd->private_data = new; 286 gd->private_data = new;
287 new->blkcore_priv = gd; 287 new->blkcore_priv = gd;
288 gd->queue = tr->blkcore_priv->rq; 288 gd->queue = tr->blkcore_priv->rq;
289 gd->driverfs_dev = new->mtd->dev.parent;
289 290
290 if (new->readonly) 291 if (new->readonly)
291 set_disk_ro(gd, 1); 292 set_disk_ro(gd, 1);
@@ -382,11 +383,12 @@ int register_mtd_blktrans(struct mtd_blktrans_ops *tr)
382 tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr, 383 tr->blkcore_priv->thread = kthread_run(mtd_blktrans_thread, tr,
383 "%sd", tr->name); 384 "%sd", tr->name);
384 if (IS_ERR(tr->blkcore_priv->thread)) { 385 if (IS_ERR(tr->blkcore_priv->thread)) {
386 int ret = PTR_ERR(tr->blkcore_priv->thread);
385 blk_cleanup_queue(tr->blkcore_priv->rq); 387 blk_cleanup_queue(tr->blkcore_priv->rq);
386 unregister_blkdev(tr->major, tr->name); 388 unregister_blkdev(tr->major, tr->name);
387 kfree(tr->blkcore_priv); 389 kfree(tr->blkcore_priv);
388 mutex_unlock(&mtd_table_mutex); 390 mutex_unlock(&mtd_table_mutex);
389 return PTR_ERR(tr->blkcore_priv->thread); 391 return ret;
390 } 392 }
391 393
392 INIT_LIST_HEAD(&tr->devs); 394 INIT_LIST_HEAD(&tr->devs);
diff --git a/drivers/mtd/mtdbdi.c b/drivers/mtd/mtdbdi.c
new file mode 100644
index 000000000000..5ca5aed0b225
--- /dev/null
+++ b/drivers/mtd/mtdbdi.c
@@ -0,0 +1,43 @@
1/* MTD backing device capabilities
2 *
3 * Copyright © 2006 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/backing-dev.h>
13#include <linux/mtd/mtd.h>
14#include "internal.h"
15
16/*
17 * backing device capabilities for non-mappable devices (such as NAND flash)
18 * - permits private mappings, copies are taken of the data
19 */
20struct backing_dev_info mtd_bdi_unmappable = {
21 .capabilities = BDI_CAP_MAP_COPY,
22};
23
24/*
25 * backing device capabilities for R/O mappable devices (such as ROM)
26 * - permits private mappings, copies are taken of the data
27 * - permits non-writable shared mappings
28 */
29struct backing_dev_info mtd_bdi_ro_mappable = {
30 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
31 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP),
32};
33
34/*
35 * backing device capabilities for writable mappable devices (such as RAM)
36 * - permits private mappings, copies are taken of the data
37 * - permits non-writable shared mappings
38 */
39struct backing_dev_info mtd_bdi_rw_mappable = {
40 .capabilities = (BDI_CAP_MAP_COPY | BDI_CAP_MAP_DIRECT |
41 BDI_CAP_EXEC_MAP | BDI_CAP_READ_MAP |
42 BDI_CAP_WRITE_MAP),
43};
diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
index e9ec59e9a566..763d3f0a1f42 100644
--- a/drivers/mtd/mtdchar.c
+++ b/drivers/mtd/mtdchar.c
@@ -13,39 +13,13 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/smp_lock.h> 15#include <linux/smp_lock.h>
16#include <linux/backing-dev.h>
16 17
17#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
18#include <linux/mtd/compatmac.h> 19#include <linux/mtd/compatmac.h>
19 20
20#include <asm/uaccess.h> 21#include <asm/uaccess.h>
21 22
22static struct class *mtd_class;
23
24static void mtd_notify_add(struct mtd_info* mtd)
25{
26 if (!mtd)
27 return;
28
29 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2),
30 NULL, "mtd%d", mtd->index);
31
32 device_create(mtd_class, NULL, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1),
33 NULL, "mtd%dro", mtd->index);
34}
35
36static void mtd_notify_remove(struct mtd_info* mtd)
37{
38 if (!mtd)
39 return;
40
41 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2));
42 device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1));
43}
44
45static struct mtd_notifier notifier = {
46 .add = mtd_notify_add,
47 .remove = mtd_notify_remove,
48};
49 23
50/* 24/*
51 * Data structure to hold the pointer to the mtd device as well 25 * Data structure to hold the pointer to the mtd device as well
@@ -107,12 +81,15 @@ static int mtd_open(struct inode *inode, struct file *file)
107 goto out; 81 goto out;
108 } 82 }
109 83
110 if (MTD_ABSENT == mtd->type) { 84 if (mtd->type == MTD_ABSENT) {
111 put_mtd_device(mtd); 85 put_mtd_device(mtd);
112 ret = -ENODEV; 86 ret = -ENODEV;
113 goto out; 87 goto out;
114 } 88 }
115 89
90 if (mtd->backing_dev_info)
91 file->f_mapping->backing_dev_info = mtd->backing_dev_info;
92
116 /* You can't open it RW if it's not a writeable device */ 93 /* You can't open it RW if it's not a writeable device */
117 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) { 94 if ((file->f_mode & FMODE_WRITE) && !(mtd->flags & MTD_WRITEABLE)) {
118 put_mtd_device(mtd); 95 put_mtd_device(mtd);
@@ -781,6 +758,59 @@ static int mtd_ioctl(struct inode *inode, struct file *file,
781 return ret; 758 return ret;
782} /* memory_ioctl */ 759} /* memory_ioctl */
783 760
761/*
762 * try to determine where a shared mapping can be made
763 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
764 * mappings)
765 */
766#ifndef CONFIG_MMU
767static unsigned long mtd_get_unmapped_area(struct file *file,
768 unsigned long addr,
769 unsigned long len,
770 unsigned long pgoff,
771 unsigned long flags)
772{
773 struct mtd_file_info *mfi = file->private_data;
774 struct mtd_info *mtd = mfi->mtd;
775
776 if (mtd->get_unmapped_area) {
777 unsigned long offset;
778
779 if (addr != 0)
780 return (unsigned long) -EINVAL;
781
782 if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
783 return (unsigned long) -EINVAL;
784
785 offset = pgoff << PAGE_SHIFT;
786 if (offset > mtd->size - len)
787 return (unsigned long) -EINVAL;
788
789 return mtd->get_unmapped_area(mtd, len, offset, flags);
790 }
791
792 /* can't map directly */
793 return (unsigned long) -ENOSYS;
794}
795#endif
796
797/*
798 * set up a mapping for shared memory segments
799 */
800static int mtd_mmap(struct file *file, struct vm_area_struct *vma)
801{
802#ifdef CONFIG_MMU
803 struct mtd_file_info *mfi = file->private_data;
804 struct mtd_info *mtd = mfi->mtd;
805
806 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM)
807 return 0;
808 return -ENOSYS;
809#else
810 return vma->vm_flags & VM_SHARED ? 0 : -ENOSYS;
811#endif
812}
813
784static const struct file_operations mtd_fops = { 814static const struct file_operations mtd_fops = {
785 .owner = THIS_MODULE, 815 .owner = THIS_MODULE,
786 .llseek = mtd_lseek, 816 .llseek = mtd_lseek,
@@ -789,39 +819,36 @@ static const struct file_operations mtd_fops = {
789 .ioctl = mtd_ioctl, 819 .ioctl = mtd_ioctl,
790 .open = mtd_open, 820 .open = mtd_open,
791 .release = mtd_close, 821 .release = mtd_close,
822 .mmap = mtd_mmap,
823#ifndef CONFIG_MMU
824 .get_unmapped_area = mtd_get_unmapped_area,
825#endif
792}; 826};
793 827
794static int __init init_mtdchar(void) 828static int __init init_mtdchar(void)
795{ 829{
796 if (register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops)) { 830 int status;
831
832 status = register_chrdev(MTD_CHAR_MAJOR, "mtd", &mtd_fops);
833 if (status < 0) {
797 printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n", 834 printk(KERN_NOTICE "Can't allocate major number %d for Memory Technology Devices.\n",
798 MTD_CHAR_MAJOR); 835 MTD_CHAR_MAJOR);
799 return -EAGAIN;
800 } 836 }
801 837
802 mtd_class = class_create(THIS_MODULE, "mtd"); 838 return status;
803
804 if (IS_ERR(mtd_class)) {
805 printk(KERN_ERR "Error creating mtd class.\n");
806 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
807 return PTR_ERR(mtd_class);
808 }
809
810 register_mtd_user(&notifier);
811 return 0;
812} 839}
813 840
814static void __exit cleanup_mtdchar(void) 841static void __exit cleanup_mtdchar(void)
815{ 842{
816 unregister_mtd_user(&notifier);
817 class_destroy(mtd_class);
818 unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); 843 unregister_chrdev(MTD_CHAR_MAJOR, "mtd");
819} 844}
820 845
821module_init(init_mtdchar); 846module_init(init_mtdchar);
822module_exit(cleanup_mtdchar); 847module_exit(cleanup_mtdchar);
823 848
849MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
824 850
825MODULE_LICENSE("GPL"); 851MODULE_LICENSE("GPL");
826MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 852MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
827MODULE_DESCRIPTION("Direct character-device access to MTD devices"); 853MODULE_DESCRIPTION("Direct character-device access to MTD devices");
854MODULE_ALIAS_CHARDEV_MAJOR(MTD_CHAR_MAJOR);
diff --git a/drivers/mtd/mtdconcat.c b/drivers/mtd/mtdconcat.c
index 3dbb1b38db66..792b547786b8 100644
--- a/drivers/mtd/mtdconcat.c
+++ b/drivers/mtd/mtdconcat.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <linux/sched.h> 14#include <linux/sched.h>
15#include <linux/types.h> 15#include <linux/types.h>
16#include <linux/backing-dev.h>
16 17
17#include <linux/mtd/mtd.h> 18#include <linux/mtd/mtd.h>
18#include <linux/mtd/concat.h> 19#include <linux/mtd/concat.h>
@@ -684,6 +685,40 @@ static int concat_block_markbad(struct mtd_info *mtd, loff_t ofs)
684} 685}
685 686
686/* 687/*
688 * try to support NOMMU mmaps on concatenated devices
689 * - we don't support subdev spanning as we can't guarantee it'll work
690 */
691static unsigned long concat_get_unmapped_area(struct mtd_info *mtd,
692 unsigned long len,
693 unsigned long offset,
694 unsigned long flags)
695{
696 struct mtd_concat *concat = CONCAT(mtd);
697 int i;
698
699 for (i = 0; i < concat->num_subdev; i++) {
700 struct mtd_info *subdev = concat->subdev[i];
701
702 if (offset >= subdev->size) {
703 offset -= subdev->size;
704 continue;
705 }
706
707 /* we've found the subdev over which the mapping will reside */
708 if (offset + len > subdev->size)
709 return (unsigned long) -EINVAL;
710
711 if (subdev->get_unmapped_area)
712 return subdev->get_unmapped_area(subdev, len, offset,
713 flags);
714
715 break;
716 }
717
718 return (unsigned long) -ENOSYS;
719}
720
721/*
687 * This function constructs a virtual MTD device by concatenating 722 * This function constructs a virtual MTD device by concatenating
688 * num_devs MTD devices. A pointer to the new device object is 723 * num_devs MTD devices. A pointer to the new device object is
689 * stored to *new_dev upon success. This function does _not_ 724 * stored to *new_dev upon success. This function does _not_
@@ -740,6 +775,8 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
740 775
741 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks; 776 concat->mtd.ecc_stats.badblocks = subdev[0]->ecc_stats.badblocks;
742 777
778 concat->mtd.backing_dev_info = subdev[0]->backing_dev_info;
779
743 concat->subdev[0] = subdev[0]; 780 concat->subdev[0] = subdev[0];
744 781
745 for (i = 1; i < num_devs; i++) { 782 for (i = 1; i < num_devs; i++) {
@@ -766,6 +803,15 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
766 concat->mtd.flags |= 803 concat->mtd.flags |=
767 subdev[i]->flags & MTD_WRITEABLE; 804 subdev[i]->flags & MTD_WRITEABLE;
768 } 805 }
806
807 /* only permit direct mapping if the BDIs are all the same
808 * - copy-mapping is still permitted
809 */
810 if (concat->mtd.backing_dev_info !=
811 subdev[i]->backing_dev_info)
812 concat->mtd.backing_dev_info =
813 &default_backing_dev_info;
814
769 concat->mtd.size += subdev[i]->size; 815 concat->mtd.size += subdev[i]->size;
770 concat->mtd.ecc_stats.badblocks += 816 concat->mtd.ecc_stats.badblocks +=
771 subdev[i]->ecc_stats.badblocks; 817 subdev[i]->ecc_stats.badblocks;
@@ -796,6 +842,7 @@ struct mtd_info *mtd_concat_create(struct mtd_info *subdev[], /* subdevices to c
796 concat->mtd.unlock = concat_unlock; 842 concat->mtd.unlock = concat_unlock;
797 concat->mtd.suspend = concat_suspend; 843 concat->mtd.suspend = concat_suspend;
798 concat->mtd.resume = concat_resume; 844 concat->mtd.resume = concat_resume;
845 concat->mtd.get_unmapped_area = concat_get_unmapped_area;
799 846
800 /* 847 /*
801 * Combine the erase block size info of the subdevices: 848 * Combine the erase block size info of the subdevices:
diff --git a/drivers/mtd/mtdcore.c b/drivers/mtd/mtdcore.c
index 76fe0a1e7a5e..fdd6ae859397 100644
--- a/drivers/mtd/mtdcore.c
+++ b/drivers/mtd/mtdcore.c
@@ -19,9 +19,13 @@
19#include <linux/proc_fs.h> 19#include <linux/proc_fs.h>
20 20
21#include <linux/mtd/mtd.h> 21#include <linux/mtd/mtd.h>
22#include "internal.h"
22 23
23#include "mtdcore.h" 24#include "mtdcore.h"
24 25
26
27static struct class *mtd_class;
28
25/* These are exported solely for the purpose of mtd_blkdevs.c. You 29/* These are exported solely for the purpose of mtd_blkdevs.c. You
26 should not use them for _anything_ else */ 30 should not use them for _anything_ else */
27DEFINE_MUTEX(mtd_table_mutex); 31DEFINE_MUTEX(mtd_table_mutex);
@@ -32,6 +36,160 @@ EXPORT_SYMBOL_GPL(mtd_table);
32 36
33static LIST_HEAD(mtd_notifiers); 37static LIST_HEAD(mtd_notifiers);
34 38
39
40#if defined(CONFIG_MTD_CHAR) || defined(CONFIG_MTD_CHAR_MODULE)
41#define MTD_DEVT(index) MKDEV(MTD_CHAR_MAJOR, (index)*2)
42#else
43#define MTD_DEVT(index) 0
44#endif
45
46/* REVISIT once MTD uses the driver model better, whoever allocates
47 * the mtd_info will probably want to use the release() hook...
48 */
49static void mtd_release(struct device *dev)
50{
51 struct mtd_info *mtd = dev_to_mtd(dev);
52
53 /* remove /dev/mtdXro node if needed */
54 if (MTD_DEVT(mtd->index))
55 device_destroy(mtd_class, MTD_DEVT(mtd->index) + 1);
56}
57
58static ssize_t mtd_type_show(struct device *dev,
59 struct device_attribute *attr, char *buf)
60{
61 struct mtd_info *mtd = dev_to_mtd(dev);
62 char *type;
63
64 switch (mtd->type) {
65 case MTD_ABSENT:
66 type = "absent";
67 break;
68 case MTD_RAM:
69 type = "ram";
70 break;
71 case MTD_ROM:
72 type = "rom";
73 break;
74 case MTD_NORFLASH:
75 type = "nor";
76 break;
77 case MTD_NANDFLASH:
78 type = "nand";
79 break;
80 case MTD_DATAFLASH:
81 type = "dataflash";
82 break;
83 case MTD_UBIVOLUME:
84 type = "ubi";
85 break;
86 default:
87 type = "unknown";
88 }
89
90 return snprintf(buf, PAGE_SIZE, "%s\n", type);
91}
92static DEVICE_ATTR(type, S_IRUGO, mtd_type_show, NULL);
93
94static ssize_t mtd_flags_show(struct device *dev,
95 struct device_attribute *attr, char *buf)
96{
97 struct mtd_info *mtd = dev_to_mtd(dev);
98
99 return snprintf(buf, PAGE_SIZE, "0x%lx\n", (unsigned long)mtd->flags);
100
101}
102static DEVICE_ATTR(flags, S_IRUGO, mtd_flags_show, NULL);
103
104static ssize_t mtd_size_show(struct device *dev,
105 struct device_attribute *attr, char *buf)
106{
107 struct mtd_info *mtd = dev_to_mtd(dev);
108
109 return snprintf(buf, PAGE_SIZE, "%llu\n",
110 (unsigned long long)mtd->size);
111
112}
113static DEVICE_ATTR(size, S_IRUGO, mtd_size_show, NULL);
114
115static ssize_t mtd_erasesize_show(struct device *dev,
116 struct device_attribute *attr, char *buf)
117{
118 struct mtd_info *mtd = dev_to_mtd(dev);
119
120 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->erasesize);
121
122}
123static DEVICE_ATTR(erasesize, S_IRUGO, mtd_erasesize_show, NULL);
124
125static ssize_t mtd_writesize_show(struct device *dev,
126 struct device_attribute *attr, char *buf)
127{
128 struct mtd_info *mtd = dev_to_mtd(dev);
129
130 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->writesize);
131
132}
133static DEVICE_ATTR(writesize, S_IRUGO, mtd_writesize_show, NULL);
134
135static ssize_t mtd_oobsize_show(struct device *dev,
136 struct device_attribute *attr, char *buf)
137{
138 struct mtd_info *mtd = dev_to_mtd(dev);
139
140 return snprintf(buf, PAGE_SIZE, "%lu\n", (unsigned long)mtd->oobsize);
141
142}
143static DEVICE_ATTR(oobsize, S_IRUGO, mtd_oobsize_show, NULL);
144
145static ssize_t mtd_numeraseregions_show(struct device *dev,
146 struct device_attribute *attr, char *buf)
147{
148 struct mtd_info *mtd = dev_to_mtd(dev);
149
150 return snprintf(buf, PAGE_SIZE, "%u\n", mtd->numeraseregions);
151
152}
153static DEVICE_ATTR(numeraseregions, S_IRUGO, mtd_numeraseregions_show,
154 NULL);
155
156static ssize_t mtd_name_show(struct device *dev,
157 struct device_attribute *attr, char *buf)
158{
159 struct mtd_info *mtd = dev_to_mtd(dev);
160
161 return snprintf(buf, PAGE_SIZE, "%s\n", mtd->name);
162
163}
164static DEVICE_ATTR(name, S_IRUGO, mtd_name_show, NULL);
165
166static struct attribute *mtd_attrs[] = {
167 &dev_attr_type.attr,
168 &dev_attr_flags.attr,
169 &dev_attr_size.attr,
170 &dev_attr_erasesize.attr,
171 &dev_attr_writesize.attr,
172 &dev_attr_oobsize.attr,
173 &dev_attr_numeraseregions.attr,
174 &dev_attr_name.attr,
175 NULL,
176};
177
178struct attribute_group mtd_group = {
179 .attrs = mtd_attrs,
180};
181
182struct attribute_group *mtd_groups[] = {
183 &mtd_group,
184 NULL,
185};
186
187static struct device_type mtd_devtype = {
188 .name = "mtd",
189 .groups = mtd_groups,
190 .release = mtd_release,
191};
192
35/** 193/**
36 * add_mtd_device - register an MTD device 194 * add_mtd_device - register an MTD device
37 * @mtd: pointer to new MTD device info structure 195 * @mtd: pointer to new MTD device info structure
@@ -40,12 +198,27 @@ static LIST_HEAD(mtd_notifiers);
40 * notify each currently active MTD 'user' of its arrival. Returns 198 * notify each currently active MTD 'user' of its arrival. Returns
41 * zero on success or 1 on failure, which currently will only happen 199 * zero on success or 1 on failure, which currently will only happen
42 * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16) 200 * if the number of present devices exceeds MAX_MTD_DEVICES (i.e. 16)
201 * or there's a sysfs error.
43 */ 202 */
44 203
45int add_mtd_device(struct mtd_info *mtd) 204int add_mtd_device(struct mtd_info *mtd)
46{ 205{
47 int i; 206 int i;
48 207
208 if (!mtd->backing_dev_info) {
209 switch (mtd->type) {
210 case MTD_RAM:
211 mtd->backing_dev_info = &mtd_bdi_rw_mappable;
212 break;
213 case MTD_ROM:
214 mtd->backing_dev_info = &mtd_bdi_ro_mappable;
215 break;
216 default:
217 mtd->backing_dev_info = &mtd_bdi_unmappable;
218 break;
219 }
220 }
221
49 BUG_ON(mtd->writesize == 0); 222 BUG_ON(mtd->writesize == 0);
50 mutex_lock(&mtd_table_mutex); 223 mutex_lock(&mtd_table_mutex);
51 224
@@ -80,6 +253,23 @@ int add_mtd_device(struct mtd_info *mtd)
80 mtd->name); 253 mtd->name);
81 } 254 }
82 255
256 /* Caller should have set dev.parent to match the
257 * physical device.
258 */
259 mtd->dev.type = &mtd_devtype;
260 mtd->dev.class = mtd_class;
261 mtd->dev.devt = MTD_DEVT(i);
262 dev_set_name(&mtd->dev, "mtd%d", i);
263 if (device_register(&mtd->dev) != 0) {
264 mtd_table[i] = NULL;
265 break;
266 }
267
268 if (MTD_DEVT(i))
269 device_create(mtd_class, mtd->dev.parent,
270 MTD_DEVT(i) + 1,
271 NULL, "mtd%dro", i);
272
83 DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name); 273 DEBUG(0, "mtd: Giving out device %d to %s\n",i, mtd->name);
84 /* No need to get a refcount on the module containing 274 /* No need to get a refcount on the module containing
85 the notifier, since we hold the mtd_table_mutex */ 275 the notifier, since we hold the mtd_table_mutex */
@@ -124,6 +314,8 @@ int del_mtd_device (struct mtd_info *mtd)
124 } else { 314 } else {
125 struct mtd_notifier *not; 315 struct mtd_notifier *not;
126 316
317 device_unregister(&mtd->dev);
318
127 /* No need to get a refcount on the module containing 319 /* No need to get a refcount on the module containing
128 the notifier, since we hold the mtd_table_mutex */ 320 the notifier, since we hold the mtd_table_mutex */
129 list_for_each_entry(not, &mtd_notifiers, list) 321 list_for_each_entry(not, &mtd_notifiers, list)
@@ -393,28 +585,38 @@ done:
393 return ((count < begin+len-off) ? count : begin+len-off); 585 return ((count < begin+len-off) ? count : begin+len-off);
394} 586}
395 587
588#endif /* CONFIG_PROC_FS */
589
396/*====================================================================*/ 590/*====================================================================*/
397/* Init code */ 591/* Init code */
398 592
399static int __init init_mtd(void) 593static int __init init_mtd(void)
400{ 594{
595 mtd_class = class_create(THIS_MODULE, "mtd");
596
597 if (IS_ERR(mtd_class)) {
598 pr_err("Error creating mtd class.\n");
599 return PTR_ERR(mtd_class);
600 }
601#ifdef CONFIG_PROC_FS
401 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL ))) 602 if ((proc_mtd = create_proc_entry( "mtd", 0, NULL )))
402 proc_mtd->read_proc = mtd_read_proc; 603 proc_mtd->read_proc = mtd_read_proc;
604#endif /* CONFIG_PROC_FS */
403 return 0; 605 return 0;
404} 606}
405 607
406static void __exit cleanup_mtd(void) 608static void __exit cleanup_mtd(void)
407{ 609{
610#ifdef CONFIG_PROC_FS
408 if (proc_mtd) 611 if (proc_mtd)
409 remove_proc_entry( "mtd", NULL); 612 remove_proc_entry( "mtd", NULL);
613#endif /* CONFIG_PROC_FS */
614 class_destroy(mtd_class);
410} 615}
411 616
412module_init(init_mtd); 617module_init(init_mtd);
413module_exit(cleanup_mtd); 618module_exit(cleanup_mtd);
414 619
415#endif /* CONFIG_PROC_FS */
416
417
418MODULE_LICENSE("GPL"); 620MODULE_LICENSE("GPL");
419MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>"); 621MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>");
420MODULE_DESCRIPTION("Core MTD registration and access routines"); 622MODULE_DESCRIPTION("Core MTD registration and access routines");
diff --git a/drivers/mtd/mtdoops.c b/drivers/mtd/mtdoops.c
index 1a6b3beabe8d..1060337c06df 100644
--- a/drivers/mtd/mtdoops.c
+++ b/drivers/mtd/mtdoops.c
@@ -44,6 +44,7 @@ static struct mtdoops_context {
44 int oops_pages; 44 int oops_pages;
45 int nextpage; 45 int nextpage;
46 int nextcount; 46 int nextcount;
47 char *name;
47 48
48 void *oops_buf; 49 void *oops_buf;
49 50
@@ -273,6 +274,9 @@ static void mtdoops_notify_add(struct mtd_info *mtd)
273{ 274{
274 struct mtdoops_context *cxt = &oops_cxt; 275 struct mtdoops_context *cxt = &oops_cxt;
275 276
277 if (cxt->name && !strcmp(mtd->name, cxt->name))
278 cxt->mtd_index = mtd->index;
279
276 if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0) 280 if ((mtd->index != cxt->mtd_index) || cxt->mtd_index < 0)
277 return; 281 return;
278 282
@@ -357,8 +361,10 @@ mtdoops_console_write(struct console *co, const char *s, unsigned int count)
357 spin_lock_irqsave(&cxt->writecount_lock, flags); 361 spin_lock_irqsave(&cxt->writecount_lock, flags);
358 362
359 /* Check ready status didn't change whilst waiting for the lock */ 363 /* Check ready status didn't change whilst waiting for the lock */
360 if (!cxt->ready) 364 if (!cxt->ready) {
365 spin_unlock_irqrestore(&cxt->writecount_lock, flags);
361 return; 366 return;
367 }
362 368
363 if (cxt->writecount == 0) { 369 if (cxt->writecount == 0) {
364 u32 *stamp = cxt->oops_buf; 370 u32 *stamp = cxt->oops_buf;
@@ -383,8 +389,12 @@ static int __init mtdoops_console_setup(struct console *co, char *options)
383{ 389{
384 struct mtdoops_context *cxt = co->data; 390 struct mtdoops_context *cxt = co->data;
385 391
386 if (cxt->mtd_index != -1) 392 if (cxt->mtd_index != -1 || cxt->name)
387 return -EBUSY; 393 return -EBUSY;
394 if (options) {
395 cxt->name = kstrdup(options, GFP_KERNEL);
396 return 0;
397 }
388 if (co->index == -1) 398 if (co->index == -1)
389 return -EINVAL; 399 return -EINVAL;
390 400
@@ -412,6 +422,7 @@ static int __init mtdoops_console_init(void)
412 422
413 cxt->mtd_index = -1; 423 cxt->mtd_index = -1;
414 cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE); 424 cxt->oops_buf = vmalloc(OOPS_PAGE_SIZE);
425 spin_lock_init(&cxt->writecount_lock);
415 426
416 if (!cxt->oops_buf) { 427 if (!cxt->oops_buf) {
417 printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n"); 428 printk(KERN_ERR "Failed to allocate mtdoops buffer workspace\n");
@@ -432,6 +443,7 @@ static void __exit mtdoops_console_exit(void)
432 443
433 unregister_mtd_user(&mtdoops_notifier); 444 unregister_mtd_user(&mtdoops_notifier);
434 unregister_console(&mtdoops_console); 445 unregister_console(&mtdoops_console);
446 kfree(cxt->name);
435 vfree(cxt->oops_buf); 447 vfree(cxt->oops_buf);
436} 448}
437 449
diff --git a/drivers/mtd/mtdpart.c b/drivers/mtd/mtdpart.c
index 144e6b613a77..29675edb44b4 100644
--- a/drivers/mtd/mtdpart.c
+++ b/drivers/mtd/mtdpart.c
@@ -48,8 +48,11 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
48 size_t *retlen, u_char *buf) 48 size_t *retlen, u_char *buf)
49{ 49{
50 struct mtd_part *part = PART(mtd); 50 struct mtd_part *part = PART(mtd);
51 struct mtd_ecc_stats stats;
51 int res; 52 int res;
52 53
54 stats = part->master->ecc_stats;
55
53 if (from >= mtd->size) 56 if (from >= mtd->size)
54 len = 0; 57 len = 0;
55 else if (from + len > mtd->size) 58 else if (from + len > mtd->size)
@@ -58,9 +61,9 @@ static int part_read(struct mtd_info *mtd, loff_t from, size_t len,
58 len, retlen, buf); 61 len, retlen, buf);
59 if (unlikely(res)) { 62 if (unlikely(res)) {
60 if (res == -EUCLEAN) 63 if (res == -EUCLEAN)
61 mtd->ecc_stats.corrected++; 64 mtd->ecc_stats.corrected += part->master->ecc_stats.corrected - stats.corrected;
62 if (res == -EBADMSG) 65 if (res == -EBADMSG)
63 mtd->ecc_stats.failed++; 66 mtd->ecc_stats.failed += part->master->ecc_stats.failed - stats.failed;
64 } 67 }
65 return res; 68 return res;
66} 69}
@@ -84,6 +87,18 @@ static void part_unpoint(struct mtd_info *mtd, loff_t from, size_t len)
84 part->master->unpoint(part->master, from + part->offset, len); 87 part->master->unpoint(part->master, from + part->offset, len);
85} 88}
86 89
90static unsigned long part_get_unmapped_area(struct mtd_info *mtd,
91 unsigned long len,
92 unsigned long offset,
93 unsigned long flags)
94{
95 struct mtd_part *part = PART(mtd);
96
97 offset += part->offset;
98 return part->master->get_unmapped_area(part->master, len, offset,
99 flags);
100}
101
87static int part_read_oob(struct mtd_info *mtd, loff_t from, 102static int part_read_oob(struct mtd_info *mtd, loff_t from,
88 struct mtd_oob_ops *ops) 103 struct mtd_oob_ops *ops)
89{ 104{
@@ -342,6 +357,12 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
342 357
343 slave->mtd.name = part->name; 358 slave->mtd.name = part->name;
344 slave->mtd.owner = master->owner; 359 slave->mtd.owner = master->owner;
360 slave->mtd.backing_dev_info = master->backing_dev_info;
361
362 /* NOTE: we don't arrange MTDs as a tree; it'd be error-prone
363 * to have the same data be in two different partitions.
364 */
365 slave->mtd.dev.parent = master->dev.parent;
345 366
346 slave->mtd.read = part_read; 367 slave->mtd.read = part_read;
347 slave->mtd.write = part_write; 368 slave->mtd.write = part_write;
@@ -354,6 +375,8 @@ static struct mtd_part *add_one_partition(struct mtd_info *master,
354 slave->mtd.unpoint = part_unpoint; 375 slave->mtd.unpoint = part_unpoint;
355 } 376 }
356 377
378 if (master->get_unmapped_area)
379 slave->mtd.get_unmapped_area = part_get_unmapped_area;
357 if (master->read_oob) 380 if (master->read_oob)
358 slave->mtd.read_oob = part_read_oob; 381 slave->mtd.read_oob = part_read_oob;
359 if (master->write_oob) 382 if (master->write_oob)
@@ -493,7 +516,9 @@ out_register:
493 * This function, given a master MTD object and a partition table, creates 516 * This function, given a master MTD object and a partition table, creates
494 * and registers slave MTD objects which are bound to the master according to 517 * and registers slave MTD objects which are bound to the master according to
495 * the partition definitions. 518 * the partition definitions.
496 * (Q: should we register the master MTD object as well?) 519 *
520 * We don't register the master, or expect the caller to have done so,
521 * for reasons of data integrity.
497 */ 522 */
498 523
499int add_mtd_partitions(struct mtd_info *master, 524int add_mtd_partitions(struct mtd_info *master,
diff --git a/drivers/mtd/nand/Kconfig b/drivers/mtd/nand/Kconfig
index 2ff88791cebc..890936d0275e 100644
--- a/drivers/mtd/nand/Kconfig
+++ b/drivers/mtd/nand/Kconfig
@@ -334,7 +334,7 @@ config MTD_NAND_ATMEL_ECC_NONE
334endchoice 334endchoice
335 335
336config MTD_NAND_PXA3xx 336config MTD_NAND_PXA3xx
337 bool "Support for NAND flash devices on PXA3xx" 337 tristate "Support for NAND flash devices on PXA3xx"
338 depends on MTD_NAND && PXA3xx 338 depends on MTD_NAND && PXA3xx
339 help 339 help
340 This enables the driver for the NAND flash device found on 340 This enables the driver for the NAND flash device found on
@@ -427,4 +427,23 @@ config MTD_NAND_SH_FLCTL
427 Several Renesas SuperH CPU has FLCTL. This option enables support 427 Several Renesas SuperH CPU has FLCTL. This option enables support
428 for NAND Flash using FLCTL. This driver support SH7723. 428 for NAND Flash using FLCTL. This driver support SH7723.
429 429
430config MTD_NAND_DAVINCI
431 tristate "Support NAND on DaVinci SoC"
432 depends on ARCH_DAVINCI
433 help
434 Enable the driver for NAND flash chips on Texas Instruments
435 DaVinci processors.
436
437config MTD_NAND_TXX9NDFMC
438 tristate "NAND Flash support for TXx9 SoC"
439 depends on SOC_TX4938 || SOC_TX4939
440 help
441 This enables the NAND flash controller on the TXx9 SoCs.
442
443config MTD_NAND_SOCRATES
444 tristate "Support for NAND on Socrates board"
445 depends on MTD_NAND && SOCRATES
446 help
447 Enables support for NAND Flash chips wired onto Socrates board.
448
430endif # MTD_NAND 449endif # MTD_NAND
diff --git a/drivers/mtd/nand/Makefile b/drivers/mtd/nand/Makefile
index b661586afbfc..d33860ac42c3 100644
--- a/drivers/mtd/nand/Makefile
+++ b/drivers/mtd/nand/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o
14obj-$(CONFIG_MTD_NAND_BF5XX) += bf5xx_nand.o 14obj-$(CONFIG_MTD_NAND_BF5XX) += bf5xx_nand.o
15obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o 15obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o
16obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o 16obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o
17obj-$(CONFIG_MTD_NAND_DAVINCI) += davinci_nand.o
17obj-$(CONFIG_MTD_NAND_DISKONCHIP) += diskonchip.o 18obj-$(CONFIG_MTD_NAND_DISKONCHIP) += diskonchip.o
18obj-$(CONFIG_MTD_NAND_H1900) += h1910.o 19obj-$(CONFIG_MTD_NAND_H1900) += h1910.o
19obj-$(CONFIG_MTD_NAND_RTC_FROM4) += rtc_from4.o 20obj-$(CONFIG_MTD_NAND_RTC_FROM4) += rtc_from4.o
@@ -36,5 +37,7 @@ obj-$(CONFIG_MTD_NAND_FSL_ELBC) += fsl_elbc_nand.o
36obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o 37obj-$(CONFIG_MTD_NAND_FSL_UPM) += fsl_upm.o
37obj-$(CONFIG_MTD_NAND_SH_FLCTL) += sh_flctl.o 38obj-$(CONFIG_MTD_NAND_SH_FLCTL) += sh_flctl.o
38obj-$(CONFIG_MTD_NAND_MXC) += mxc_nand.o 39obj-$(CONFIG_MTD_NAND_MXC) += mxc_nand.o
40obj-$(CONFIG_MTD_NAND_SOCRATES) += socrates_nand.o
41obj-$(CONFIG_MTD_NAND_TXX9NDFMC) += txx9ndfmc.o
39 42
40nand-objs := nand_base.o nand_bbt.o 43nand-objs := nand_base.o nand_bbt.o
diff --git a/drivers/mtd/nand/bf5xx_nand.c b/drivers/mtd/nand/bf5xx_nand.c
index 9af2a2cc1153..4c2a67ca801e 100644
--- a/drivers/mtd/nand/bf5xx_nand.c
+++ b/drivers/mtd/nand/bf5xx_nand.c
@@ -552,7 +552,6 @@ static void bf5xx_nand_dma_write_buf(struct mtd_info *mtd,
552static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info) 552static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
553{ 553{
554 int ret; 554 int ret;
555 unsigned short val;
556 555
557 /* Do not use dma */ 556 /* Do not use dma */
558 if (!hardware_ecc) 557 if (!hardware_ecc)
@@ -560,13 +559,6 @@ static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
560 559
561 init_completion(&info->dma_completion); 560 init_completion(&info->dma_completion);
562 561
563#ifdef CONFIG_BF54x
564 /* Setup DMAC1 channel mux for NFC which shared with SDH */
565 val = bfin_read_DMAC1_PERIMUX();
566 val &= 0xFFFE;
567 bfin_write_DMAC1_PERIMUX(val);
568 SSYNC();
569#endif
570 /* Request NFC DMA channel */ 562 /* Request NFC DMA channel */
571 ret = request_dma(CH_NFC, "BF5XX NFC driver"); 563 ret = request_dma(CH_NFC, "BF5XX NFC driver");
572 if (ret < 0) { 564 if (ret < 0) {
@@ -574,7 +566,13 @@ static int bf5xx_nand_dma_init(struct bf5xx_nand_info *info)
574 return ret; 566 return ret;
575 } 567 }
576 568
577 set_dma_callback(CH_NFC, (void *) bf5xx_nand_dma_irq, (void *) info); 569#ifdef CONFIG_BF54x
570 /* Setup DMAC1 channel mux for NFC which shared with SDH */
571 bfin_write_DMAC1_PERIMUX(bfin_read_DMAC1_PERIMUX() & ~1);
572 SSYNC();
573#endif
574
575 set_dma_callback(CH_NFC, bf5xx_nand_dma_irq, info);
578 576
579 /* Turn off the DMA channel first */ 577 /* Turn off the DMA channel first */
580 disable_dma(CH_NFC); 578 disable_dma(CH_NFC);
@@ -632,7 +630,7 @@ static int bf5xx_nand_hw_init(struct bf5xx_nand_info *info)
632/* 630/*
633 * Device management interface 631 * Device management interface
634 */ 632 */
635static int bf5xx_nand_add_partition(struct bf5xx_nand_info *info) 633static int __devinit bf5xx_nand_add_partition(struct bf5xx_nand_info *info)
636{ 634{
637 struct mtd_info *mtd = &info->mtd; 635 struct mtd_info *mtd = &info->mtd;
638 636
diff --git a/drivers/mtd/nand/cafe_nand.c b/drivers/mtd/nand/cafe_nand.c
index 22a6b2e50e91..7c5b257ce8e4 100644
--- a/drivers/mtd/nand/cafe_nand.c
+++ b/drivers/mtd/nand/cafe_nand.c
@@ -654,6 +654,7 @@ static int __devinit cafe_nand_probe(struct pci_dev *pdev,
654 } 654 }
655 cafe = (void *)(&mtd[1]); 655 cafe = (void *)(&mtd[1]);
656 656
657 mtd->dev.parent = &pdev->dev;
657 mtd->priv = cafe; 658 mtd->priv = cafe;
658 mtd->owner = THIS_MODULE; 659 mtd->owner = THIS_MODULE;
659 660
diff --git a/drivers/mtd/nand/davinci_nand.c b/drivers/mtd/nand/davinci_nand.c
new file mode 100644
index 000000000000..0119220de7d0
--- /dev/null
+++ b/drivers/mtd/nand/davinci_nand.c
@@ -0,0 +1,570 @@
1/*
2 * davinci_nand.c - NAND Flash Driver for DaVinci family chips
3 *
4 * Copyright © 2006 Texas Instruments.
5 *
6 * Port to 2.6.23 Copyright © 2008 by:
7 * Sander Huijsen <Shuijsen@optelecom-nkf.com>
8 * Troy Kisky <troy.kisky@boundarydevices.com>
9 * Dirk Behme <Dirk.Behme@gmail.com>
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 */
25
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/module.h>
29#include <linux/platform_device.h>
30#include <linux/err.h>
31#include <linux/clk.h>
32#include <linux/io.h>
33#include <linux/mtd/nand.h>
34#include <linux/mtd/partitions.h>
35
36#include <mach/nand.h>
37
38#include <asm/mach-types.h>
39
40
41/*
42 * This is a device driver for the NAND flash controller found on the
43 * various DaVinci family chips. It handles up to four SoC chipselects,
44 * and some flavors of secondary chipselect (e.g. based on A12) as used
45 * with multichip packages.
46 *
47 * The 1-bit ECC hardware is supported, but not yet the newer 4-bit ECC
48 * available on chips like the DM355 and OMAP-L137 and needed with the
49 * more error-prone MLC NAND chips.
50 *
51 * This driver assumes EM_WAIT connects all the NAND devices' RDY/nBUSY
52 * outputs in a "wire-AND" configuration, with no per-chip signals.
53 */
54struct davinci_nand_info {
55 struct mtd_info mtd;
56 struct nand_chip chip;
57
58 struct device *dev;
59 struct clk *clk;
60 bool partitioned;
61
62 void __iomem *base;
63 void __iomem *vaddr;
64
65 uint32_t ioaddr;
66 uint32_t current_cs;
67
68 uint32_t mask_chipsel;
69 uint32_t mask_ale;
70 uint32_t mask_cle;
71
72 uint32_t core_chipsel;
73};
74
75static DEFINE_SPINLOCK(davinci_nand_lock);
76
77#define to_davinci_nand(m) container_of(m, struct davinci_nand_info, mtd)
78
79
80static inline unsigned int davinci_nand_readl(struct davinci_nand_info *info,
81 int offset)
82{
83 return __raw_readl(info->base + offset);
84}
85
86static inline void davinci_nand_writel(struct davinci_nand_info *info,
87 int offset, unsigned long value)
88{
89 __raw_writel(value, info->base + offset);
90}
91
92/*----------------------------------------------------------------------*/
93
94/*
95 * Access to hardware control lines: ALE, CLE, secondary chipselect.
96 */
97
98static void nand_davinci_hwcontrol(struct mtd_info *mtd, int cmd,
99 unsigned int ctrl)
100{
101 struct davinci_nand_info *info = to_davinci_nand(mtd);
102 uint32_t addr = info->current_cs;
103 struct nand_chip *nand = mtd->priv;
104
105 /* Did the control lines change? */
106 if (ctrl & NAND_CTRL_CHANGE) {
107 if ((ctrl & NAND_CTRL_CLE) == NAND_CTRL_CLE)
108 addr |= info->mask_cle;
109 else if ((ctrl & NAND_CTRL_ALE) == NAND_CTRL_ALE)
110 addr |= info->mask_ale;
111
112 nand->IO_ADDR_W = (void __iomem __force *)addr;
113 }
114
115 if (cmd != NAND_CMD_NONE)
116 iowrite8(cmd, nand->IO_ADDR_W);
117}
118
119static void nand_davinci_select_chip(struct mtd_info *mtd, int chip)
120{
121 struct davinci_nand_info *info = to_davinci_nand(mtd);
122 uint32_t addr = info->ioaddr;
123
124 /* maybe kick in a second chipselect */
125 if (chip > 0)
126 addr |= info->mask_chipsel;
127 info->current_cs = addr;
128
129 info->chip.IO_ADDR_W = (void __iomem __force *)addr;
130 info->chip.IO_ADDR_R = info->chip.IO_ADDR_W;
131}
132
133/*----------------------------------------------------------------------*/
134
135/*
136 * 1-bit hardware ECC ... context maintained for each core chipselect
137 */
138
139static inline uint32_t nand_davinci_readecc_1bit(struct mtd_info *mtd)
140{
141 struct davinci_nand_info *info = to_davinci_nand(mtd);
142
143 return davinci_nand_readl(info, NANDF1ECC_OFFSET
144 + 4 * info->core_chipsel);
145}
146
147static void nand_davinci_hwctl_1bit(struct mtd_info *mtd, int mode)
148{
149 struct davinci_nand_info *info;
150 uint32_t nandcfr;
151 unsigned long flags;
152
153 info = to_davinci_nand(mtd);
154
155 /* Reset ECC hardware */
156 nand_davinci_readecc_1bit(mtd);
157
158 spin_lock_irqsave(&davinci_nand_lock, flags);
159
160 /* Restart ECC hardware */
161 nandcfr = davinci_nand_readl(info, NANDFCR_OFFSET);
162 nandcfr |= BIT(8 + info->core_chipsel);
163 davinci_nand_writel(info, NANDFCR_OFFSET, nandcfr);
164
165 spin_unlock_irqrestore(&davinci_nand_lock, flags);
166}
167
168/*
169 * Read hardware ECC value and pack into three bytes
170 */
171static int nand_davinci_calculate_1bit(struct mtd_info *mtd,
172 const u_char *dat, u_char *ecc_code)
173{
174 unsigned int ecc_val = nand_davinci_readecc_1bit(mtd);
175 unsigned int ecc24 = (ecc_val & 0x0fff) | ((ecc_val & 0x0fff0000) >> 4);
176
177 /* invert so that erased block ecc is correct */
178 ecc24 = ~ecc24;
179 ecc_code[0] = (u_char)(ecc24);
180 ecc_code[1] = (u_char)(ecc24 >> 8);
181 ecc_code[2] = (u_char)(ecc24 >> 16);
182
183 return 0;
184}
185
186static int nand_davinci_correct_1bit(struct mtd_info *mtd, u_char *dat,
187 u_char *read_ecc, u_char *calc_ecc)
188{
189 struct nand_chip *chip = mtd->priv;
190 uint32_t eccNand = read_ecc[0] | (read_ecc[1] << 8) |
191 (read_ecc[2] << 16);
192 uint32_t eccCalc = calc_ecc[0] | (calc_ecc[1] << 8) |
193 (calc_ecc[2] << 16);
194 uint32_t diff = eccCalc ^ eccNand;
195
196 if (diff) {
197 if ((((diff >> 12) ^ diff) & 0xfff) == 0xfff) {
198 /* Correctable error */
199 if ((diff >> (12 + 3)) < chip->ecc.size) {
200 dat[diff >> (12 + 3)] ^= BIT((diff >> 12) & 7);
201 return 1;
202 } else {
203 return -1;
204 }
205 } else if (!(diff & (diff - 1))) {
206 /* Single bit ECC error in the ECC itself,
207 * nothing to fix */
208 return 1;
209 } else {
210 /* Uncorrectable error */
211 return -1;
212 }
213
214 }
215 return 0;
216}
217
218/*----------------------------------------------------------------------*/
219
220/*
221 * NOTE: NAND boot requires ALE == EM_A[1], CLE == EM_A[2], so that's
222 * how these chips are normally wired. This translates to both 8 and 16
223 * bit busses using ALE == BIT(3) in byte addresses, and CLE == BIT(4).
224 *
225 * For now we assume that configuration, or any other one which ignores
226 * the two LSBs for NAND access ... so we can issue 32-bit reads/writes
227 * and have that transparently morphed into multiple NAND operations.
228 */
229static void nand_davinci_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
230{
231 struct nand_chip *chip = mtd->priv;
232
233 if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0)
234 ioread32_rep(chip->IO_ADDR_R, buf, len >> 2);
235 else if ((0x01 & ((unsigned)buf)) == 0 && (0x01 & len) == 0)
236 ioread16_rep(chip->IO_ADDR_R, buf, len >> 1);
237 else
238 ioread8_rep(chip->IO_ADDR_R, buf, len);
239}
240
241static void nand_davinci_write_buf(struct mtd_info *mtd,
242 const uint8_t *buf, int len)
243{
244 struct nand_chip *chip = mtd->priv;
245
246 if ((0x03 & ((unsigned)buf)) == 0 && (0x03 & len) == 0)
247 iowrite32_rep(chip->IO_ADDR_R, buf, len >> 2);
248 else if ((0x01 & ((unsigned)buf)) == 0 && (0x01 & len) == 0)
249 iowrite16_rep(chip->IO_ADDR_R, buf, len >> 1);
250 else
251 iowrite8_rep(chip->IO_ADDR_R, buf, len);
252}
253
254/*
255 * Check hardware register for wait status. Returns 1 if device is ready,
256 * 0 if it is still busy.
257 */
258static int nand_davinci_dev_ready(struct mtd_info *mtd)
259{
260 struct davinci_nand_info *info = to_davinci_nand(mtd);
261
262 return davinci_nand_readl(info, NANDFSR_OFFSET) & BIT(0);
263}
264
265static void __init nand_dm6446evm_flash_init(struct davinci_nand_info *info)
266{
267 uint32_t regval, a1cr;
268
269 /*
270 * NAND FLASH timings @ PLL1 == 459 MHz
271 * - AEMIF.CLK freq = PLL1/6 = 459/6 = 76.5 MHz
272 * - AEMIF.CLK period = 1/76.5 MHz = 13.1 ns
273 */
274 regval = 0
275 | (0 << 31) /* selectStrobe */
276 | (0 << 30) /* extWait (never with NAND) */
277 | (1 << 26) /* writeSetup 10 ns */
278 | (3 << 20) /* writeStrobe 40 ns */
279 | (1 << 17) /* writeHold 10 ns */
280 | (0 << 13) /* readSetup 10 ns */
281 | (3 << 7) /* readStrobe 60 ns */
282 | (0 << 4) /* readHold 10 ns */
283 | (3 << 2) /* turnAround ?? ns */
284 | (0 << 0) /* asyncSize 8-bit bus */
285 ;
286 a1cr = davinci_nand_readl(info, A1CR_OFFSET);
287 if (a1cr != regval) {
288 dev_dbg(info->dev, "Warning: NAND config: Set A1CR " \
289 "reg to 0x%08x, was 0x%08x, should be done by " \
290 "bootloader.\n", regval, a1cr);
291 davinci_nand_writel(info, A1CR_OFFSET, regval);
292 }
293}
294
295/*----------------------------------------------------------------------*/
296
297static int __init nand_davinci_probe(struct platform_device *pdev)
298{
299 struct davinci_nand_pdata *pdata = pdev->dev.platform_data;
300 struct davinci_nand_info *info;
301 struct resource *res1;
302 struct resource *res2;
303 void __iomem *vaddr;
304 void __iomem *base;
305 int ret;
306 uint32_t val;
307 nand_ecc_modes_t ecc_mode;
308
309 /* which external chipselect will we be managing? */
310 if (pdev->id < 0 || pdev->id > 3)
311 return -ENODEV;
312
313 info = kzalloc(sizeof(*info), GFP_KERNEL);
314 if (!info) {
315 dev_err(&pdev->dev, "unable to allocate memory\n");
316 ret = -ENOMEM;
317 goto err_nomem;
318 }
319
320 platform_set_drvdata(pdev, info);
321
322 res1 = platform_get_resource(pdev, IORESOURCE_MEM, 0);
323 res2 = platform_get_resource(pdev, IORESOURCE_MEM, 1);
324 if (!res1 || !res2) {
325 dev_err(&pdev->dev, "resource missing\n");
326 ret = -EINVAL;
327 goto err_nomem;
328 }
329
330 vaddr = ioremap(res1->start, res1->end - res1->start);
331 base = ioremap(res2->start, res2->end - res2->start);
332 if (!vaddr || !base) {
333 dev_err(&pdev->dev, "ioremap failed\n");
334 ret = -EINVAL;
335 goto err_ioremap;
336 }
337
338 info->dev = &pdev->dev;
339 info->base = base;
340 info->vaddr = vaddr;
341
342 info->mtd.priv = &info->chip;
343 info->mtd.name = dev_name(&pdev->dev);
344 info->mtd.owner = THIS_MODULE;
345
346 info->mtd.dev.parent = &pdev->dev;
347
348 info->chip.IO_ADDR_R = vaddr;
349 info->chip.IO_ADDR_W = vaddr;
350 info->chip.chip_delay = 0;
351 info->chip.select_chip = nand_davinci_select_chip;
352
353 /* options such as NAND_USE_FLASH_BBT or 16-bit widths */
354 info->chip.options = pdata ? pdata->options : 0;
355
356 info->ioaddr = (uint32_t __force) vaddr;
357
358 info->current_cs = info->ioaddr;
359 info->core_chipsel = pdev->id;
360 info->mask_chipsel = pdata->mask_chipsel;
361
362 /* use nandboot-capable ALE/CLE masks by default */
363 if (pdata && pdata->mask_ale)
364 info->mask_ale = pdata->mask_cle;
365 else
366 info->mask_ale = MASK_ALE;
367 if (pdata && pdata->mask_cle)
368 info->mask_cle = pdata->mask_cle;
369 else
370 info->mask_cle = MASK_CLE;
371
372 /* Set address of hardware control function */
373 info->chip.cmd_ctrl = nand_davinci_hwcontrol;
374 info->chip.dev_ready = nand_davinci_dev_ready;
375
376 /* Speed up buffer I/O */
377 info->chip.read_buf = nand_davinci_read_buf;
378 info->chip.write_buf = nand_davinci_write_buf;
379
380 /* use board-specific ECC config; else, the best available */
381 if (pdata)
382 ecc_mode = pdata->ecc_mode;
383 else
384 ecc_mode = NAND_ECC_HW;
385
386 switch (ecc_mode) {
387 case NAND_ECC_NONE:
388 case NAND_ECC_SOFT:
389 break;
390 case NAND_ECC_HW:
391 info->chip.ecc.calculate = nand_davinci_calculate_1bit;
392 info->chip.ecc.correct = nand_davinci_correct_1bit;
393 info->chip.ecc.hwctl = nand_davinci_hwctl_1bit;
394 info->chip.ecc.size = 512;
395 info->chip.ecc.bytes = 3;
396 break;
397 case NAND_ECC_HW_SYNDROME:
398 /* FIXME implement */
399 info->chip.ecc.size = 512;
400 info->chip.ecc.bytes = 10;
401
402 dev_warn(&pdev->dev, "4-bit ECC nyet supported\n");
403 /* FALL THROUGH */
404 default:
405 ret = -EINVAL;
406 goto err_ecc;
407 }
408 info->chip.ecc.mode = ecc_mode;
409
410 info->clk = clk_get(&pdev->dev, "AEMIFCLK");
411 if (IS_ERR(info->clk)) {
412 ret = PTR_ERR(info->clk);
413 dev_dbg(&pdev->dev, "unable to get AEMIFCLK, err %d\n", ret);
414 goto err_clk;
415 }
416
417 ret = clk_enable(info->clk);
418 if (ret < 0) {
419 dev_dbg(&pdev->dev, "unable to enable AEMIFCLK, err %d\n", ret);
420 goto err_clk_enable;
421 }
422
423 /* EMIF timings should normally be set by the boot loader,
424 * especially after boot-from-NAND. The *only* reason to
425 * have this special casing for the DM6446 EVM is to work
426 * with boot-from-NOR ... with CS0 manually re-jumpered
427 * (after startup) so it addresses the NAND flash, not NOR.
428 * Even for dev boards, that's unusually rude...
429 */
430 if (machine_is_davinci_evm())
431 nand_dm6446evm_flash_init(info);
432
433 spin_lock_irq(&davinci_nand_lock);
434
435 /* put CSxNAND into NAND mode */
436 val = davinci_nand_readl(info, NANDFCR_OFFSET);
437 val |= BIT(info->core_chipsel);
438 davinci_nand_writel(info, NANDFCR_OFFSET, val);
439
440 spin_unlock_irq(&davinci_nand_lock);
441
442 /* Scan to find existence of the device(s) */
443 ret = nand_scan(&info->mtd, pdata->mask_chipsel ? 2 : 1);
444 if (ret < 0) {
445 dev_dbg(&pdev->dev, "no NAND chip(s) found\n");
446 goto err_scan;
447 }
448
449 if (mtd_has_partitions()) {
450 struct mtd_partition *mtd_parts = NULL;
451 int mtd_parts_nb = 0;
452
453 if (mtd_has_cmdlinepart()) {
454 static const char *probes[] __initconst =
455 { "cmdlinepart", NULL };
456
457 const char *master_name;
458
459 /* Set info->mtd.name = 0 temporarily */
460 master_name = info->mtd.name;
461 info->mtd.name = (char *)0;
462
463 /* info->mtd.name == 0, means: don't bother checking
464 <mtd-id> */
465 mtd_parts_nb = parse_mtd_partitions(&info->mtd, probes,
466 &mtd_parts, 0);
467
468 /* Restore info->mtd.name */
469 info->mtd.name = master_name;
470 }
471
472 if (mtd_parts_nb <= 0 && pdata) {
473 mtd_parts = pdata->parts;
474 mtd_parts_nb = pdata->nr_parts;
475 }
476
477 /* Register any partitions */
478 if (mtd_parts_nb > 0) {
479 ret = add_mtd_partitions(&info->mtd,
480 mtd_parts, mtd_parts_nb);
481 if (ret == 0)
482 info->partitioned = true;
483 }
484
485 } else if (pdata && pdata->nr_parts) {
486 dev_warn(&pdev->dev, "ignoring %d default partitions on %s\n",
487 pdata->nr_parts, info->mtd.name);
488 }
489
490 /* If there's no partition info, just package the whole chip
491 * as a single MTD device.
492 */
493 if (!info->partitioned)
494 ret = add_mtd_device(&info->mtd) ? -ENODEV : 0;
495
496 if (ret < 0)
497 goto err_scan;
498
499 val = davinci_nand_readl(info, NRCSR_OFFSET);
500 dev_info(&pdev->dev, "controller rev. %d.%d\n",
501 (val >> 8) & 0xff, val & 0xff);
502
503 return 0;
504
505err_scan:
506 clk_disable(info->clk);
507
508err_clk_enable:
509 clk_put(info->clk);
510
511err_ecc:
512err_clk:
513err_ioremap:
514 if (base)
515 iounmap(base);
516 if (vaddr)
517 iounmap(vaddr);
518
519err_nomem:
520 kfree(info);
521 return ret;
522}
523
524static int __exit nand_davinci_remove(struct platform_device *pdev)
525{
526 struct davinci_nand_info *info = platform_get_drvdata(pdev);
527 int status;
528
529 if (mtd_has_partitions() && info->partitioned)
530 status = del_mtd_partitions(&info->mtd);
531 else
532 status = del_mtd_device(&info->mtd);
533
534 iounmap(info->base);
535 iounmap(info->vaddr);
536
537 nand_release(&info->mtd);
538
539 clk_disable(info->clk);
540 clk_put(info->clk);
541
542 kfree(info);
543
544 return 0;
545}
546
547static struct platform_driver nand_davinci_driver = {
548 .remove = __exit_p(nand_davinci_remove),
549 .driver = {
550 .name = "davinci_nand",
551 },
552};
553MODULE_ALIAS("platform:davinci_nand");
554
555static int __init nand_davinci_init(void)
556{
557 return platform_driver_probe(&nand_davinci_driver, nand_davinci_probe);
558}
559module_init(nand_davinci_init);
560
561static void __exit nand_davinci_exit(void)
562{
563 platform_driver_unregister(&nand_davinci_driver);
564}
565module_exit(nand_davinci_exit);
566
567MODULE_LICENSE("GPL");
568MODULE_AUTHOR("Texas Instruments");
569MODULE_DESCRIPTION("Davinci NAND flash driver");
570
diff --git a/drivers/mtd/nand/fsl_upm.c b/drivers/mtd/nand/fsl_upm.c
index 7815a404a632..d120cd8d7267 100644
--- a/drivers/mtd/nand/fsl_upm.c
+++ b/drivers/mtd/nand/fsl_upm.c
@@ -23,6 +23,10 @@
23#include <linux/io.h> 23#include <linux/io.h>
24#include <asm/fsl_lbc.h> 24#include <asm/fsl_lbc.h>
25 25
26#define FSL_UPM_WAIT_RUN_PATTERN 0x1
27#define FSL_UPM_WAIT_WRITE_BYTE 0x2
28#define FSL_UPM_WAIT_WRITE_BUFFER 0x4
29
26struct fsl_upm_nand { 30struct fsl_upm_nand {
27 struct device *dev; 31 struct device *dev;
28 struct mtd_info mtd; 32 struct mtd_info mtd;
@@ -36,8 +40,12 @@ struct fsl_upm_nand {
36 uint8_t upm_addr_offset; 40 uint8_t upm_addr_offset;
37 uint8_t upm_cmd_offset; 41 uint8_t upm_cmd_offset;
38 void __iomem *io_base; 42 void __iomem *io_base;
39 int rnb_gpio; 43 int rnb_gpio[NAND_MAX_CHIPS];
44 uint32_t mchip_offsets[NAND_MAX_CHIPS];
45 uint32_t mchip_count;
46 uint32_t mchip_number;
40 int chip_delay; 47 int chip_delay;
48 uint32_t wait_flags;
41}; 49};
42 50
43#define to_fsl_upm_nand(mtd) container_of(mtd, struct fsl_upm_nand, mtd) 51#define to_fsl_upm_nand(mtd) container_of(mtd, struct fsl_upm_nand, mtd)
@@ -46,7 +54,7 @@ static int fun_chip_ready(struct mtd_info *mtd)
46{ 54{
47 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd); 55 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
48 56
49 if (gpio_get_value(fun->rnb_gpio)) 57 if (gpio_get_value(fun->rnb_gpio[fun->mchip_number]))
50 return 1; 58 return 1;
51 59
52 dev_vdbg(fun->dev, "busy\n"); 60 dev_vdbg(fun->dev, "busy\n");
@@ -55,9 +63,9 @@ static int fun_chip_ready(struct mtd_info *mtd)
55 63
56static void fun_wait_rnb(struct fsl_upm_nand *fun) 64static void fun_wait_rnb(struct fsl_upm_nand *fun)
57{ 65{
58 int cnt = 1000000; 66 if (fun->rnb_gpio[fun->mchip_number] >= 0) {
67 int cnt = 1000000;
59 68
60 if (fun->rnb_gpio >= 0) {
61 while (--cnt && !fun_chip_ready(&fun->mtd)) 69 while (--cnt && !fun_chip_ready(&fun->mtd))
62 cpu_relax(); 70 cpu_relax();
63 if (!cnt) 71 if (!cnt)
@@ -69,7 +77,9 @@ static void fun_wait_rnb(struct fsl_upm_nand *fun)
69 77
70static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl) 78static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
71{ 79{
80 struct nand_chip *chip = mtd->priv;
72 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd); 81 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
82 u32 mar;
73 83
74 if (!(ctrl & fun->last_ctrl)) { 84 if (!(ctrl & fun->last_ctrl)) {
75 fsl_upm_end_pattern(&fun->upm); 85 fsl_upm_end_pattern(&fun->upm);
@@ -87,9 +97,28 @@ static void fun_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
87 fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset); 97 fsl_upm_start_pattern(&fun->upm, fun->upm_cmd_offset);
88 } 98 }
89 99
90 fsl_upm_run_pattern(&fun->upm, fun->io_base, cmd); 100 mar = (cmd << (32 - fun->upm.width)) |
101 fun->mchip_offsets[fun->mchip_number];
102 fsl_upm_run_pattern(&fun->upm, chip->IO_ADDR_R, mar);
103
104 if (fun->wait_flags & FSL_UPM_WAIT_RUN_PATTERN)
105 fun_wait_rnb(fun);
106}
107
108static void fun_select_chip(struct mtd_info *mtd, int mchip_nr)
109{
110 struct nand_chip *chip = mtd->priv;
111 struct fsl_upm_nand *fun = to_fsl_upm_nand(mtd);
91 112
92 fun_wait_rnb(fun); 113 if (mchip_nr == -1) {
114 chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE);
115 } else if (mchip_nr >= 0) {
116 fun->mchip_number = mchip_nr;
117 chip->IO_ADDR_R = fun->io_base + fun->mchip_offsets[mchip_nr];
118 chip->IO_ADDR_W = chip->IO_ADDR_R;
119 } else {
120 BUG();
121 }
93} 122}
94 123
95static uint8_t fun_read_byte(struct mtd_info *mtd) 124static uint8_t fun_read_byte(struct mtd_info *mtd)
@@ -115,8 +144,11 @@ static void fun_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len)
115 144
116 for (i = 0; i < len; i++) { 145 for (i = 0; i < len; i++) {
117 out_8(fun->chip.IO_ADDR_W, buf[i]); 146 out_8(fun->chip.IO_ADDR_W, buf[i]);
118 fun_wait_rnb(fun); 147 if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BYTE)
148 fun_wait_rnb(fun);
119 } 149 }
150 if (fun->wait_flags & FSL_UPM_WAIT_WRITE_BUFFER)
151 fun_wait_rnb(fun);
120} 152}
121 153
122static int __devinit fun_chip_init(struct fsl_upm_nand *fun, 154static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
@@ -137,8 +169,10 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
137 fun->chip.read_buf = fun_read_buf; 169 fun->chip.read_buf = fun_read_buf;
138 fun->chip.write_buf = fun_write_buf; 170 fun->chip.write_buf = fun_write_buf;
139 fun->chip.ecc.mode = NAND_ECC_SOFT; 171 fun->chip.ecc.mode = NAND_ECC_SOFT;
172 if (fun->mchip_count > 1)
173 fun->chip.select_chip = fun_select_chip;
140 174
141 if (fun->rnb_gpio >= 0) 175 if (fun->rnb_gpio[0] >= 0)
142 fun->chip.dev_ready = fun_chip_ready; 176 fun->chip.dev_ready = fun_chip_ready;
143 177
144 fun->mtd.priv = &fun->chip; 178 fun->mtd.priv = &fun->chip;
@@ -155,7 +189,7 @@ static int __devinit fun_chip_init(struct fsl_upm_nand *fun,
155 goto err; 189 goto err;
156 } 190 }
157 191
158 ret = nand_scan(&fun->mtd, 1); 192 ret = nand_scan(&fun->mtd, fun->mchip_count);
159 if (ret) 193 if (ret)
160 goto err; 194 goto err;
161 195
@@ -185,8 +219,10 @@ static int __devinit fun_probe(struct of_device *ofdev,
185 struct fsl_upm_nand *fun; 219 struct fsl_upm_nand *fun;
186 struct resource io_res; 220 struct resource io_res;
187 const uint32_t *prop; 221 const uint32_t *prop;
222 int rnb_gpio;
188 int ret; 223 int ret;
189 int size; 224 int size;
225 int i;
190 226
191 fun = kzalloc(sizeof(*fun), GFP_KERNEL); 227 fun = kzalloc(sizeof(*fun), GFP_KERNEL);
192 if (!fun) 228 if (!fun)
@@ -208,7 +244,7 @@ static int __devinit fun_probe(struct of_device *ofdev,
208 if (!prop || size != sizeof(uint32_t)) { 244 if (!prop || size != sizeof(uint32_t)) {
209 dev_err(&ofdev->dev, "can't get UPM address offset\n"); 245 dev_err(&ofdev->dev, "can't get UPM address offset\n");
210 ret = -EINVAL; 246 ret = -EINVAL;
211 goto err2; 247 goto err1;
212 } 248 }
213 fun->upm_addr_offset = *prop; 249 fun->upm_addr_offset = *prop;
214 250
@@ -216,21 +252,40 @@ static int __devinit fun_probe(struct of_device *ofdev,
216 if (!prop || size != sizeof(uint32_t)) { 252 if (!prop || size != sizeof(uint32_t)) {
217 dev_err(&ofdev->dev, "can't get UPM command offset\n"); 253 dev_err(&ofdev->dev, "can't get UPM command offset\n");
218 ret = -EINVAL; 254 ret = -EINVAL;
219 goto err2; 255 goto err1;
220 } 256 }
221 fun->upm_cmd_offset = *prop; 257 fun->upm_cmd_offset = *prop;
222 258
223 fun->rnb_gpio = of_get_gpio(ofdev->node, 0); 259 prop = of_get_property(ofdev->node,
224 if (fun->rnb_gpio >= 0) { 260 "fsl,upm-addr-line-cs-offsets", &size);
225 ret = gpio_request(fun->rnb_gpio, dev_name(&ofdev->dev)); 261 if (prop && (size / sizeof(uint32_t)) > 0) {
226 if (ret) { 262 fun->mchip_count = size / sizeof(uint32_t);
227 dev_err(&ofdev->dev, "can't request RNB gpio\n"); 263 if (fun->mchip_count >= NAND_MAX_CHIPS) {
264 dev_err(&ofdev->dev, "too much multiple chips\n");
265 goto err1;
266 }
267 for (i = 0; i < fun->mchip_count; i++)
268 fun->mchip_offsets[i] = prop[i];
269 } else {
270 fun->mchip_count = 1;
271 }
272
273 for (i = 0; i < fun->mchip_count; i++) {
274 fun->rnb_gpio[i] = -1;
275 rnb_gpio = of_get_gpio(ofdev->node, i);
276 if (rnb_gpio >= 0) {
277 ret = gpio_request(rnb_gpio, dev_name(&ofdev->dev));
278 if (ret) {
279 dev_err(&ofdev->dev,
280 "can't request RNB gpio #%d\n", i);
281 goto err2;
282 }
283 gpio_direction_input(rnb_gpio);
284 fun->rnb_gpio[i] = rnb_gpio;
285 } else if (rnb_gpio == -EINVAL) {
286 dev_err(&ofdev->dev, "RNB gpio #%d is invalid\n", i);
228 goto err2; 287 goto err2;
229 } 288 }
230 gpio_direction_input(fun->rnb_gpio);
231 } else if (fun->rnb_gpio == -EINVAL) {
232 dev_err(&ofdev->dev, "specified RNB gpio is invalid\n");
233 goto err2;
234 } 289 }
235 290
236 prop = of_get_property(ofdev->node, "chip-delay", NULL); 291 prop = of_get_property(ofdev->node, "chip-delay", NULL);
@@ -239,8 +294,15 @@ static int __devinit fun_probe(struct of_device *ofdev,
239 else 294 else
240 fun->chip_delay = 50; 295 fun->chip_delay = 50;
241 296
297 prop = of_get_property(ofdev->node, "fsl,upm-wait-flags", &size);
298 if (prop && size == sizeof(uint32_t))
299 fun->wait_flags = *prop;
300 else
301 fun->wait_flags = FSL_UPM_WAIT_RUN_PATTERN |
302 FSL_UPM_WAIT_WRITE_BYTE;
303
242 fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start, 304 fun->io_base = devm_ioremap_nocache(&ofdev->dev, io_res.start,
243 io_res.end - io_res.start + 1); 305 io_res.end - io_res.start + 1);
244 if (!fun->io_base) { 306 if (!fun->io_base) {
245 ret = -ENOMEM; 307 ret = -ENOMEM;
246 goto err2; 308 goto err2;
@@ -257,8 +319,11 @@ static int __devinit fun_probe(struct of_device *ofdev,
257 319
258 return 0; 320 return 0;
259err2: 321err2:
260 if (fun->rnb_gpio >= 0) 322 for (i = 0; i < fun->mchip_count; i++) {
261 gpio_free(fun->rnb_gpio); 323 if (fun->rnb_gpio[i] < 0)
324 break;
325 gpio_free(fun->rnb_gpio[i]);
326 }
262err1: 327err1:
263 kfree(fun); 328 kfree(fun);
264 329
@@ -268,12 +333,16 @@ err1:
268static int __devexit fun_remove(struct of_device *ofdev) 333static int __devexit fun_remove(struct of_device *ofdev)
269{ 334{
270 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev); 335 struct fsl_upm_nand *fun = dev_get_drvdata(&ofdev->dev);
336 int i;
271 337
272 nand_release(&fun->mtd); 338 nand_release(&fun->mtd);
273 kfree(fun->mtd.name); 339 kfree(fun->mtd.name);
274 340
275 if (fun->rnb_gpio >= 0) 341 for (i = 0; i < fun->mchip_count; i++) {
276 gpio_free(fun->rnb_gpio); 342 if (fun->rnb_gpio[i] < 0)
343 break;
344 gpio_free(fun->rnb_gpio[i]);
345 }
277 346
278 kfree(fun); 347 kfree(fun);
279 348
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c
index bad048aca89a..f3548d048014 100644
--- a/drivers/mtd/nand/mxc_nand.c
+++ b/drivers/mtd/nand/mxc_nand.c
@@ -866,6 +866,7 @@ static int __init mxcnd_probe(struct platform_device *pdev)
866 mtd = &host->mtd; 866 mtd = &host->mtd;
867 mtd->priv = this; 867 mtd->priv = this;
868 mtd->owner = THIS_MODULE; 868 mtd->owner = THIS_MODULE;
869 mtd->dev.parent = &pdev->dev;
869 870
870 /* 50 us command delay time */ 871 /* 50 us command delay time */
871 this->chip_delay = 5; 872 this->chip_delay = 5;
diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index 5f71371eb1b0..3d7ed432fa41 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -82,6 +82,20 @@ static struct nand_ecclayout nand_oob_64 = {
82 .length = 38}} 82 .length = 38}}
83}; 83};
84 84
85static struct nand_ecclayout nand_oob_128 = {
86 .eccbytes = 48,
87 .eccpos = {
88 80, 81, 82, 83, 84, 85, 86, 87,
89 88, 89, 90, 91, 92, 93, 94, 95,
90 96, 97, 98, 99, 100, 101, 102, 103,
91 104, 105, 106, 107, 108, 109, 110, 111,
92 112, 113, 114, 115, 116, 117, 118, 119,
93 120, 121, 122, 123, 124, 125, 126, 127},
94 .oobfree = {
95 {.offset = 2,
96 .length = 78}}
97};
98
85static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd, 99static int nand_get_device(struct nand_chip *chip, struct mtd_info *mtd,
86 int new_state); 100 int new_state);
87 101
@@ -748,6 +762,8 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)
748 * @mtd: mtd info structure 762 * @mtd: mtd info structure
749 * @chip: nand chip info structure 763 * @chip: nand chip info structure
750 * @buf: buffer to store read data 764 * @buf: buffer to store read data
765 *
766 * Not for syndrome calculating ecc controllers, which use a special oob layout
751 */ 767 */
752static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 768static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
753 uint8_t *buf) 769 uint8_t *buf)
@@ -758,6 +774,47 @@ static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
758} 774}
759 775
760/** 776/**
777 * nand_read_page_raw_syndrome - [Intern] read raw page data without ecc
778 * @mtd: mtd info structure
779 * @chip: nand chip info structure
780 * @buf: buffer to store read data
781 *
782 * We need a special oob layout and handling even when OOB isn't used.
783 */
784static int nand_read_page_raw_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
785 uint8_t *buf)
786{
787 int eccsize = chip->ecc.size;
788 int eccbytes = chip->ecc.bytes;
789 uint8_t *oob = chip->oob_poi;
790 int steps, size;
791
792 for (steps = chip->ecc.steps; steps > 0; steps--) {
793 chip->read_buf(mtd, buf, eccsize);
794 buf += eccsize;
795
796 if (chip->ecc.prepad) {
797 chip->read_buf(mtd, oob, chip->ecc.prepad);
798 oob += chip->ecc.prepad;
799 }
800
801 chip->read_buf(mtd, oob, eccbytes);
802 oob += eccbytes;
803
804 if (chip->ecc.postpad) {
805 chip->read_buf(mtd, oob, chip->ecc.postpad);
806 oob += chip->ecc.postpad;
807 }
808 }
809
810 size = mtd->oobsize - (oob - chip->oob_poi);
811 if (size)
812 chip->read_buf(mtd, oob, size);
813
814 return 0;
815}
816
817/**
761 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function 818 * nand_read_page_swecc - [REPLACABLE] software ecc based page read function
762 * @mtd: mtd info structure 819 * @mtd: mtd info structure
763 * @chip: nand chip info structure 820 * @chip: nand chip info structure
@@ -1482,6 +1539,8 @@ static int nand_read_oob(struct mtd_info *mtd, loff_t from,
1482 * @mtd: mtd info structure 1539 * @mtd: mtd info structure
1483 * @chip: nand chip info structure 1540 * @chip: nand chip info structure
1484 * @buf: data buffer 1541 * @buf: data buffer
1542 *
1543 * Not for syndrome calculating ecc controllers, which use a special oob layout
1485 */ 1544 */
1486static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, 1545static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1487 const uint8_t *buf) 1546 const uint8_t *buf)
@@ -1491,6 +1550,44 @@ static void nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
1491} 1550}
1492 1551
1493/** 1552/**
1553 * nand_write_page_raw_syndrome - [Intern] raw page write function
1554 * @mtd: mtd info structure
1555 * @chip: nand chip info structure
1556 * @buf: data buffer
1557 *
1558 * We need a special oob layout and handling even when ECC isn't checked.
1559 */
1560static void nand_write_page_raw_syndrome(struct mtd_info *mtd, struct nand_chip *chip,
1561 const uint8_t *buf)
1562{
1563 int eccsize = chip->ecc.size;
1564 int eccbytes = chip->ecc.bytes;
1565 uint8_t *oob = chip->oob_poi;
1566 int steps, size;
1567
1568 for (steps = chip->ecc.steps; steps > 0; steps--) {
1569 chip->write_buf(mtd, buf, eccsize);
1570 buf += eccsize;
1571
1572 if (chip->ecc.prepad) {
1573 chip->write_buf(mtd, oob, chip->ecc.prepad);
1574 oob += chip->ecc.prepad;
1575 }
1576
1577 chip->read_buf(mtd, oob, eccbytes);
1578 oob += eccbytes;
1579
1580 if (chip->ecc.postpad) {
1581 chip->write_buf(mtd, oob, chip->ecc.postpad);
1582 oob += chip->ecc.postpad;
1583 }
1584 }
1585
1586 size = mtd->oobsize - (oob - chip->oob_poi);
1587 if (size)
1588 chip->write_buf(mtd, oob, size);
1589}
1590/**
1494 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function 1591 * nand_write_page_swecc - [REPLACABLE] software ecc based page write function
1495 * @mtd: mtd info structure 1592 * @mtd: mtd info structure
1496 * @chip: nand chip info structure 1593 * @chip: nand chip info structure
@@ -1863,7 +1960,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1863 } 1960 }
1864 1961
1865 if (unlikely(ops->ooboffs >= len)) { 1962 if (unlikely(ops->ooboffs >= len)) {
1866 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1963 DEBUG(MTD_DEBUG_LEVEL0, "nand_do_write_oob: "
1867 "Attempt to start write outside oob\n"); 1964 "Attempt to start write outside oob\n");
1868 return -EINVAL; 1965 return -EINVAL;
1869 } 1966 }
@@ -1873,7 +1970,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
1873 ops->ooboffs + ops->ooblen > 1970 ops->ooboffs + ops->ooblen >
1874 ((mtd->size >> chip->page_shift) - 1971 ((mtd->size >> chip->page_shift) -
1875 (to >> chip->page_shift)) * len)) { 1972 (to >> chip->page_shift)) * len)) {
1876 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 1973 DEBUG(MTD_DEBUG_LEVEL0, "nand_do_write_oob: "
1877 "Attempt write beyond end of device\n"); 1974 "Attempt write beyond end of device\n");
1878 return -EINVAL; 1975 return -EINVAL;
1879 } 1976 }
@@ -1929,8 +2026,8 @@ static int nand_write_oob(struct mtd_info *mtd, loff_t to,
1929 2026
1930 /* Do not allow writes past end of device */ 2027 /* Do not allow writes past end of device */
1931 if (ops->datbuf && (to + ops->len) > mtd->size) { 2028 if (ops->datbuf && (to + ops->len) > mtd->size) {
1932 DEBUG(MTD_DEBUG_LEVEL0, "nand_read_oob: " 2029 DEBUG(MTD_DEBUG_LEVEL0, "nand_write_oob: "
1933 "Attempt read beyond end of device\n"); 2030 "Attempt write beyond end of device\n");
1934 return -EINVAL; 2031 return -EINVAL;
1935 } 2032 }
1936 2033
@@ -2555,6 +2652,9 @@ int nand_scan_tail(struct mtd_info *mtd)
2555 case 64: 2652 case 64:
2556 chip->ecc.layout = &nand_oob_64; 2653 chip->ecc.layout = &nand_oob_64;
2557 break; 2654 break;
2655 case 128:
2656 chip->ecc.layout = &nand_oob_128;
2657 break;
2558 default: 2658 default:
2559 printk(KERN_WARNING "No oob scheme defined for " 2659 printk(KERN_WARNING "No oob scheme defined for "
2560 "oobsize %d\n", mtd->oobsize); 2660 "oobsize %d\n", mtd->oobsize);
@@ -2569,10 +2669,6 @@ int nand_scan_tail(struct mtd_info *mtd)
2569 * check ECC mode, default to software if 3byte/512byte hardware ECC is 2669 * check ECC mode, default to software if 3byte/512byte hardware ECC is
2570 * selected and we have 256 byte pagesize fallback to software ECC 2670 * selected and we have 256 byte pagesize fallback to software ECC
2571 */ 2671 */
2572 if (!chip->ecc.read_page_raw)
2573 chip->ecc.read_page_raw = nand_read_page_raw;
2574 if (!chip->ecc.write_page_raw)
2575 chip->ecc.write_page_raw = nand_write_page_raw;
2576 2672
2577 switch (chip->ecc.mode) { 2673 switch (chip->ecc.mode) {
2578 case NAND_ECC_HW: 2674 case NAND_ECC_HW:
@@ -2581,6 +2677,10 @@ int nand_scan_tail(struct mtd_info *mtd)
2581 chip->ecc.read_page = nand_read_page_hwecc; 2677 chip->ecc.read_page = nand_read_page_hwecc;
2582 if (!chip->ecc.write_page) 2678 if (!chip->ecc.write_page)
2583 chip->ecc.write_page = nand_write_page_hwecc; 2679 chip->ecc.write_page = nand_write_page_hwecc;
2680 if (!chip->ecc.read_page_raw)
2681 chip->ecc.read_page_raw = nand_read_page_raw;
2682 if (!chip->ecc.write_page_raw)
2683 chip->ecc.write_page_raw = nand_write_page_raw;
2584 if (!chip->ecc.read_oob) 2684 if (!chip->ecc.read_oob)
2585 chip->ecc.read_oob = nand_read_oob_std; 2685 chip->ecc.read_oob = nand_read_oob_std;
2586 if (!chip->ecc.write_oob) 2686 if (!chip->ecc.write_oob)
@@ -2602,6 +2702,10 @@ int nand_scan_tail(struct mtd_info *mtd)
2602 chip->ecc.read_page = nand_read_page_syndrome; 2702 chip->ecc.read_page = nand_read_page_syndrome;
2603 if (!chip->ecc.write_page) 2703 if (!chip->ecc.write_page)
2604 chip->ecc.write_page = nand_write_page_syndrome; 2704 chip->ecc.write_page = nand_write_page_syndrome;
2705 if (!chip->ecc.read_page_raw)
2706 chip->ecc.read_page_raw = nand_read_page_raw_syndrome;
2707 if (!chip->ecc.write_page_raw)
2708 chip->ecc.write_page_raw = nand_write_page_raw_syndrome;
2605 if (!chip->ecc.read_oob) 2709 if (!chip->ecc.read_oob)
2606 chip->ecc.read_oob = nand_read_oob_syndrome; 2710 chip->ecc.read_oob = nand_read_oob_syndrome;
2607 if (!chip->ecc.write_oob) 2711 if (!chip->ecc.write_oob)
@@ -2620,6 +2724,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2620 chip->ecc.read_page = nand_read_page_swecc; 2724 chip->ecc.read_page = nand_read_page_swecc;
2621 chip->ecc.read_subpage = nand_read_subpage; 2725 chip->ecc.read_subpage = nand_read_subpage;
2622 chip->ecc.write_page = nand_write_page_swecc; 2726 chip->ecc.write_page = nand_write_page_swecc;
2727 chip->ecc.read_page_raw = nand_read_page_raw;
2728 chip->ecc.write_page_raw = nand_write_page_raw;
2623 chip->ecc.read_oob = nand_read_oob_std; 2729 chip->ecc.read_oob = nand_read_oob_std;
2624 chip->ecc.write_oob = nand_write_oob_std; 2730 chip->ecc.write_oob = nand_write_oob_std;
2625 chip->ecc.size = 256; 2731 chip->ecc.size = 256;
@@ -2632,6 +2738,8 @@ int nand_scan_tail(struct mtd_info *mtd)
2632 chip->ecc.read_page = nand_read_page_raw; 2738 chip->ecc.read_page = nand_read_page_raw;
2633 chip->ecc.write_page = nand_write_page_raw; 2739 chip->ecc.write_page = nand_write_page_raw;
2634 chip->ecc.read_oob = nand_read_oob_std; 2740 chip->ecc.read_oob = nand_read_oob_std;
2741 chip->ecc.read_page_raw = nand_read_page_raw;
2742 chip->ecc.write_page_raw = nand_write_page_raw;
2635 chip->ecc.write_oob = nand_write_oob_std; 2743 chip->ecc.write_oob = nand_write_oob_std;
2636 chip->ecc.size = mtd->writesize; 2744 chip->ecc.size = mtd->writesize;
2637 chip->ecc.bytes = 0; 2745 chip->ecc.bytes = 0;
@@ -2676,6 +2784,7 @@ int nand_scan_tail(struct mtd_info *mtd)
2676 break; 2784 break;
2677 case 4: 2785 case 4:
2678 case 8: 2786 case 8:
2787 case 16:
2679 mtd->subpage_sft = 2; 2788 mtd->subpage_sft = 2;
2680 break; 2789 break;
2681 } 2790 }
diff --git a/drivers/mtd/nand/plat_nand.c b/drivers/mtd/nand/plat_nand.c
index 75f9f4874ecf..86e1d08eee00 100644
--- a/drivers/mtd/nand/plat_nand.c
+++ b/drivers/mtd/nand/plat_nand.c
@@ -30,7 +30,7 @@ struct plat_nand_data {
30/* 30/*
31 * Probe for the NAND device. 31 * Probe for the NAND device.
32 */ 32 */
33static int __init plat_nand_probe(struct platform_device *pdev) 33static int __devinit plat_nand_probe(struct platform_device *pdev)
34{ 34{
35 struct platform_nand_data *pdata = pdev->dev.platform_data; 35 struct platform_nand_data *pdata = pdev->dev.platform_data;
36 struct plat_nand_data *data; 36 struct plat_nand_data *data;
diff --git a/drivers/mtd/nand/pxa3xx_nand.c b/drivers/mtd/nand/pxa3xx_nand.c
index 61b69cc40009..30a8ce6d3e69 100644
--- a/drivers/mtd/nand/pxa3xx_nand.c
+++ b/drivers/mtd/nand/pxa3xx_nand.c
@@ -170,7 +170,13 @@ static int use_dma = 1;
170module_param(use_dma, bool, 0444); 170module_param(use_dma, bool, 0444);
171MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW"); 171MODULE_PARM_DESC(use_dma, "enable DMA for data transfering to/from NAND HW");
172 172
173#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN 173/*
174 * Default NAND flash controller configuration setup by the
175 * bootloader. This configuration is used only when pdata->keep_config is set
176 */
177static struct pxa3xx_nand_timing default_timing;
178static struct pxa3xx_nand_flash default_flash;
179
174static struct pxa3xx_nand_cmdset smallpage_cmdset = { 180static struct pxa3xx_nand_cmdset smallpage_cmdset = {
175 .read1 = 0x0000, 181 .read1 = 0x0000,
176 .read2 = 0x0050, 182 .read2 = 0x0050,
@@ -197,6 +203,7 @@ static struct pxa3xx_nand_cmdset largepage_cmdset = {
197 .lock_status = 0x007A, 203 .lock_status = 0x007A,
198}; 204};
199 205
206#ifdef CONFIG_MTD_NAND_PXA3xx_BUILTIN
200static struct pxa3xx_nand_timing samsung512MbX16_timing = { 207static struct pxa3xx_nand_timing samsung512MbX16_timing = {
201 .tCH = 10, 208 .tCH = 10,
202 .tCS = 0, 209 .tCS = 0,
@@ -296,9 +303,23 @@ static struct pxa3xx_nand_flash *builtin_flash_types[] = {
296#define NDTR1_tWHR(c) (min((c), 15) << 4) 303#define NDTR1_tWHR(c) (min((c), 15) << 4)
297#define NDTR1_tAR(c) (min((c), 15) << 0) 304#define NDTR1_tAR(c) (min((c), 15) << 0)
298 305
306#define tCH_NDTR0(r) (((r) >> 19) & 0x7)
307#define tCS_NDTR0(r) (((r) >> 16) & 0x7)
308#define tWH_NDTR0(r) (((r) >> 11) & 0x7)
309#define tWP_NDTR0(r) (((r) >> 8) & 0x7)
310#define tRH_NDTR0(r) (((r) >> 3) & 0x7)
311#define tRP_NDTR0(r) (((r) >> 0) & 0x7)
312
313#define tR_NDTR1(r) (((r) >> 16) & 0xffff)
314#define tWHR_NDTR1(r) (((r) >> 4) & 0xf)
315#define tAR_NDTR1(r) (((r) >> 0) & 0xf)
316
299/* convert nano-seconds to nand flash controller clock cycles */ 317/* convert nano-seconds to nand flash controller clock cycles */
300#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1) 318#define ns2cycle(ns, clk) (int)(((ns) * (clk / 1000000) / 1000) - 1)
301 319
320/* convert nand flash controller clock cycles to nano-seconds */
321#define cycle2ns(c, clk) ((((c) + 1) * 1000000 + clk / 500) / (clk / 1000))
322
302static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info, 323static void pxa3xx_nand_set_timing(struct pxa3xx_nand_info *info,
303 const struct pxa3xx_nand_timing *t) 324 const struct pxa3xx_nand_timing *t)
304{ 325{
@@ -920,6 +941,82 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
920 return 0; 941 return 0;
921} 942}
922 943
944static void pxa3xx_nand_detect_timing(struct pxa3xx_nand_info *info,
945 struct pxa3xx_nand_timing *t)
946{
947 unsigned long nand_clk = clk_get_rate(info->clk);
948 uint32_t ndtr0 = nand_readl(info, NDTR0CS0);
949 uint32_t ndtr1 = nand_readl(info, NDTR1CS0);
950
951 t->tCH = cycle2ns(tCH_NDTR0(ndtr0), nand_clk);
952 t->tCS = cycle2ns(tCS_NDTR0(ndtr0), nand_clk);
953 t->tWH = cycle2ns(tWH_NDTR0(ndtr0), nand_clk);
954 t->tWP = cycle2ns(tWP_NDTR0(ndtr0), nand_clk);
955 t->tRH = cycle2ns(tRH_NDTR0(ndtr0), nand_clk);
956 t->tRP = cycle2ns(tRP_NDTR0(ndtr0), nand_clk);
957
958 t->tR = cycle2ns(tR_NDTR1(ndtr1), nand_clk);
959 t->tWHR = cycle2ns(tWHR_NDTR1(ndtr1), nand_clk);
960 t->tAR = cycle2ns(tAR_NDTR1(ndtr1), nand_clk);
961}
962
963static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)
964{
965 uint32_t ndcr = nand_readl(info, NDCR);
966 struct nand_flash_dev *type = NULL;
967 uint32_t id = -1;
968 int i;
969
970 default_flash.page_per_block = ndcr & NDCR_PG_PER_BLK ? 64 : 32;
971 default_flash.page_size = ndcr & NDCR_PAGE_SZ ? 2048 : 512;
972 default_flash.flash_width = ndcr & NDCR_DWIDTH_M ? 16 : 8;
973 default_flash.dfc_width = ndcr & NDCR_DWIDTH_C ? 16 : 8;
974
975 if (default_flash.page_size == 2048)
976 default_flash.cmdset = &largepage_cmdset;
977 else
978 default_flash.cmdset = &smallpage_cmdset;
979
980 /* set info fields needed to __readid */
981 info->flash_info = &default_flash;
982 info->read_id_bytes = (default_flash.page_size == 2048) ? 4 : 2;
983 info->reg_ndcr = ndcr;
984
985 if (__readid(info, &id))
986 return -ENODEV;
987
988 /* Lookup the flash id */
989 id = (id >> 8) & 0xff; /* device id is byte 2 */
990 for (i = 0; nand_flash_ids[i].name != NULL; i++) {
991 if (id == nand_flash_ids[i].id) {
992 type = &nand_flash_ids[i];
993 break;
994 }
995 }
996
997 if (!type)
998 return -ENODEV;
999
1000 /* fill the missing flash information */
1001 i = __ffs(default_flash.page_per_block * default_flash.page_size);
1002 default_flash.num_blocks = type->chipsize << (20 - i);
1003
1004 info->oob_size = (default_flash.page_size == 2048) ? 64 : 16;
1005
1006 /* calculate addressing information */
1007 info->col_addr_cycles = (default_flash.page_size == 2048) ? 2 : 1;
1008
1009 if (default_flash.num_blocks * default_flash.page_per_block > 65536)
1010 info->row_addr_cycles = 3;
1011 else
1012 info->row_addr_cycles = 2;
1013
1014 pxa3xx_nand_detect_timing(info, &default_timing);
1015 default_flash.timing = &default_timing;
1016
1017 return 0;
1018}
1019
923static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info, 1020static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
924 const struct pxa3xx_nand_platform_data *pdata) 1021 const struct pxa3xx_nand_platform_data *pdata)
925{ 1022{
@@ -927,6 +1024,10 @@ static int pxa3xx_nand_detect_flash(struct pxa3xx_nand_info *info,
927 uint32_t id = -1; 1024 uint32_t id = -1;
928 int i; 1025 int i;
929 1026
1027 if (pdata->keep_config)
1028 if (pxa3xx_nand_detect_config(info) == 0)
1029 return 0;
1030
930 for (i = 0; i<pdata->num_flash; ++i) { 1031 for (i = 0; i<pdata->num_flash; ++i) {
931 f = pdata->flash + i; 1032 f = pdata->flash + i;
932 1033
@@ -1078,6 +1179,7 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1078 1179
1079 this = &info->nand_chip; 1180 this = &info->nand_chip;
1080 mtd->priv = info; 1181 mtd->priv = info;
1182 mtd->owner = THIS_MODULE;
1081 1183
1082 info->clk = clk_get(&pdev->dev, NULL); 1184 info->clk = clk_get(&pdev->dev, NULL);
1083 if (IS_ERR(info->clk)) { 1185 if (IS_ERR(info->clk)) {
@@ -1117,14 +1219,14 @@ static int pxa3xx_nand_probe(struct platform_device *pdev)
1117 goto fail_put_clk; 1219 goto fail_put_clk;
1118 } 1220 }
1119 1221
1120 r = request_mem_region(r->start, r->end - r->start + 1, pdev->name); 1222 r = request_mem_region(r->start, resource_size(r), pdev->name);
1121 if (r == NULL) { 1223 if (r == NULL) {
1122 dev_err(&pdev->dev, "failed to request memory resource\n"); 1224 dev_err(&pdev->dev, "failed to request memory resource\n");
1123 ret = -EBUSY; 1225 ret = -EBUSY;
1124 goto fail_put_clk; 1226 goto fail_put_clk;
1125 } 1227 }
1126 1228
1127 info->mmio_base = ioremap(r->start, r->end - r->start + 1); 1229 info->mmio_base = ioremap(r->start, resource_size(r));
1128 if (info->mmio_base == NULL) { 1230 if (info->mmio_base == NULL) {
1129 dev_err(&pdev->dev, "ioremap() failed\n"); 1231 dev_err(&pdev->dev, "ioremap() failed\n");
1130 ret = -ENODEV; 1232 ret = -ENODEV;
@@ -1173,7 +1275,7 @@ fail_free_buf:
1173fail_free_io: 1275fail_free_io:
1174 iounmap(info->mmio_base); 1276 iounmap(info->mmio_base);
1175fail_free_res: 1277fail_free_res:
1176 release_mem_region(r->start, r->end - r->start + 1); 1278 release_mem_region(r->start, resource_size(r));
1177fail_put_clk: 1279fail_put_clk:
1178 clk_disable(info->clk); 1280 clk_disable(info->clk);
1179 clk_put(info->clk); 1281 clk_put(info->clk);
@@ -1186,6 +1288,7 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1186{ 1288{
1187 struct mtd_info *mtd = platform_get_drvdata(pdev); 1289 struct mtd_info *mtd = platform_get_drvdata(pdev);
1188 struct pxa3xx_nand_info *info = mtd->priv; 1290 struct pxa3xx_nand_info *info = mtd->priv;
1291 struct resource *r;
1189 1292
1190 platform_set_drvdata(pdev, NULL); 1293 platform_set_drvdata(pdev, NULL);
1191 1294
@@ -1198,6 +1301,14 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)
1198 info->data_buff, info->data_buff_phys); 1301 info->data_buff, info->data_buff_phys);
1199 } else 1302 } else
1200 kfree(info->data_buff); 1303 kfree(info->data_buff);
1304
1305 iounmap(info->mmio_base);
1306 r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1307 release_mem_region(r->start, resource_size(r));
1308
1309 clk_disable(info->clk);
1310 clk_put(info->clk);
1311
1201 kfree(mtd); 1312 kfree(mtd);
1202 return 0; 1313 return 0;
1203} 1314}
diff --git a/drivers/mtd/nand/sh_flctl.c b/drivers/mtd/nand/sh_flctl.c
index 821acb08ff1c..2bc896623e2d 100644
--- a/drivers/mtd/nand/sh_flctl.c
+++ b/drivers/mtd/nand/sh_flctl.c
@@ -58,7 +58,7 @@ static struct nand_bbt_descr flctl_4secc_smallpage = {
58}; 58};
59 59
60static struct nand_bbt_descr flctl_4secc_largepage = { 60static struct nand_bbt_descr flctl_4secc_largepage = {
61 .options = 0, 61 .options = NAND_BBT_SCAN2NDPAGE,
62 .offs = 58, 62 .offs = 58,
63 .len = 2, 63 .len = 2,
64 .pattern = scan_ff_pattern, 64 .pattern = scan_ff_pattern,
@@ -149,7 +149,7 @@ static void wait_wfifo_ready(struct sh_flctl *flctl)
149 printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n"); 149 printk(KERN_ERR "wait_wfifo_ready(): Timeout occured \n");
150} 150}
151 151
152static int wait_recfifo_ready(struct sh_flctl *flctl) 152static int wait_recfifo_ready(struct sh_flctl *flctl, int sector_number)
153{ 153{
154 uint32_t timeout = LOOP_TIMEOUT_MAX; 154 uint32_t timeout = LOOP_TIMEOUT_MAX;
155 int checked[4]; 155 int checked[4];
@@ -183,7 +183,12 @@ static int wait_recfifo_ready(struct sh_flctl *flctl)
183 uint8_t org; 183 uint8_t org;
184 int index; 184 int index;
185 185
186 index = data >> 16; 186 if (flctl->page_size)
187 index = (512 * sector_number) +
188 (data >> 16);
189 else
190 index = data >> 16;
191
187 org = flctl->done_buff[index]; 192 org = flctl->done_buff[index];
188 flctl->done_buff[index] = org ^ (data & 0xFF); 193 flctl->done_buff[index] = org ^ (data & 0xFF);
189 checked[i] = 1; 194 checked[i] = 1;
@@ -238,14 +243,14 @@ static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
238 } 243 }
239} 244}
240 245
241static int read_ecfiforeg(struct sh_flctl *flctl, uint8_t *buff) 246static int read_ecfiforeg(struct sh_flctl *flctl, uint8_t *buff, int sector)
242{ 247{
243 int i; 248 int i;
244 unsigned long *ecc_buf = (unsigned long *)buff; 249 unsigned long *ecc_buf = (unsigned long *)buff;
245 void *fifo_addr = (void *)FLECFIFO(flctl); 250 void *fifo_addr = (void *)FLECFIFO(flctl);
246 251
247 for (i = 0; i < 4; i++) { 252 for (i = 0; i < 4; i++) {
248 if (wait_recfifo_ready(flctl)) 253 if (wait_recfifo_ready(flctl , sector))
249 return 1; 254 return 1;
250 ecc_buf[i] = readl(fifo_addr); 255 ecc_buf[i] = readl(fifo_addr);
251 ecc_buf[i] = be32_to_cpu(ecc_buf[i]); 256 ecc_buf[i] = be32_to_cpu(ecc_buf[i]);
@@ -384,7 +389,8 @@ static void execmd_read_page_sector(struct mtd_info *mtd, int page_addr)
384 read_fiforeg(flctl, 512, 512 * sector); 389 read_fiforeg(flctl, 512, 512 * sector);
385 390
386 ret = read_ecfiforeg(flctl, 391 ret = read_ecfiforeg(flctl,
387 &flctl->done_buff[mtd->writesize + 16 * sector]); 392 &flctl->done_buff[mtd->writesize + 16 * sector],
393 sector);
388 394
389 if (ret) 395 if (ret)
390 flctl->hwecc_cant_correct[sector] = 1; 396 flctl->hwecc_cant_correct[sector] = 1;
diff --git a/drivers/mtd/nand/socrates_nand.c b/drivers/mtd/nand/socrates_nand.c
new file mode 100644
index 000000000000..a4519a7bd683
--- /dev/null
+++ b/drivers/mtd/nand/socrates_nand.c
@@ -0,0 +1,325 @@
1/*
2 * drivers/mtd/nand/socrates_nand.c
3 *
4 * Copyright © 2008 Ilya Yanok, Emcraft Systems
5 *
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 *
11 */
12
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/mtd/mtd.h>
16#include <linux/mtd/nand.h>
17#include <linux/mtd/partitions.h>
18#include <linux/of_platform.h>
19#include <linux/io.h>
20
21#define FPGA_NAND_CMD_MASK (0x7 << 28)
22#define FPGA_NAND_CMD_COMMAND (0x0 << 28)
23#define FPGA_NAND_CMD_ADDR (0x1 << 28)
24#define FPGA_NAND_CMD_READ (0x2 << 28)
25#define FPGA_NAND_CMD_WRITE (0x3 << 28)
26#define FPGA_NAND_BUSY (0x1 << 15)
27#define FPGA_NAND_ENABLE (0x1 << 31)
28#define FPGA_NAND_DATA_SHIFT 16
29
30struct socrates_nand_host {
31 struct nand_chip nand_chip;
32 struct mtd_info mtd;
33 void __iomem *io_base;
34 struct device *dev;
35};
36
37/**
38 * socrates_nand_write_buf - write buffer to chip
39 * @mtd: MTD device structure
40 * @buf: data buffer
41 * @len: number of bytes to write
42 */
43static void socrates_nand_write_buf(struct mtd_info *mtd,
44 const uint8_t *buf, int len)
45{
46 int i;
47 struct nand_chip *this = mtd->priv;
48 struct socrates_nand_host *host = this->priv;
49
50 for (i = 0; i < len; i++) {
51 out_be32(host->io_base, FPGA_NAND_ENABLE |
52 FPGA_NAND_CMD_WRITE |
53 (buf[i] << FPGA_NAND_DATA_SHIFT));
54 }
55}
56
57/**
58 * socrates_nand_read_buf - read chip data into buffer
59 * @mtd: MTD device structure
60 * @buf: buffer to store date
61 * @len: number of bytes to read
62 */
63static void socrates_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
64{
65 int i;
66 struct nand_chip *this = mtd->priv;
67 struct socrates_nand_host *host = this->priv;
68 uint32_t val;
69
70 val = FPGA_NAND_ENABLE | FPGA_NAND_CMD_READ;
71
72 out_be32(host->io_base, val);
73 for (i = 0; i < len; i++) {
74 buf[i] = (in_be32(host->io_base) >>
75 FPGA_NAND_DATA_SHIFT) & 0xff;
76 }
77}
78
79/**
80 * socrates_nand_read_byte - read one byte from the chip
81 * @mtd: MTD device structure
82 */
83static uint8_t socrates_nand_read_byte(struct mtd_info *mtd)
84{
85 uint8_t byte;
86 socrates_nand_read_buf(mtd, &byte, sizeof(byte));
87 return byte;
88}
89
90/**
91 * socrates_nand_read_word - read one word from the chip
92 * @mtd: MTD device structure
93 */
94static uint16_t socrates_nand_read_word(struct mtd_info *mtd)
95{
96 uint16_t word;
97 socrates_nand_read_buf(mtd, (uint8_t *)&word, sizeof(word));
98 return word;
99}
100
101/**
102 * socrates_nand_verify_buf - Verify chip data against buffer
103 * @mtd: MTD device structure
104 * @buf: buffer containing the data to compare
105 * @len: number of bytes to compare
106 */
107static int socrates_nand_verify_buf(struct mtd_info *mtd, const u8 *buf,
108 int len)
109{
110 int i;
111
112 for (i = 0; i < len; i++) {
113 if (buf[i] != socrates_nand_read_byte(mtd))
114 return -EFAULT;
115 }
116 return 0;
117}
118
119/*
120 * Hardware specific access to control-lines
121 */
122static void socrates_nand_cmd_ctrl(struct mtd_info *mtd, int cmd,
123 unsigned int ctrl)
124{
125 struct nand_chip *nand_chip = mtd->priv;
126 struct socrates_nand_host *host = nand_chip->priv;
127 uint32_t val;
128
129 if (cmd == NAND_CMD_NONE)
130 return;
131
132 if (ctrl & NAND_CLE)
133 val = FPGA_NAND_CMD_COMMAND;
134 else
135 val = FPGA_NAND_CMD_ADDR;
136
137 if (ctrl & NAND_NCE)
138 val |= FPGA_NAND_ENABLE;
139
140 val |= (cmd & 0xff) << FPGA_NAND_DATA_SHIFT;
141
142 out_be32(host->io_base, val);
143}
144
145/*
146 * Read the Device Ready pin.
147 */
148static int socrates_nand_device_ready(struct mtd_info *mtd)
149{
150 struct nand_chip *nand_chip = mtd->priv;
151 struct socrates_nand_host *host = nand_chip->priv;
152
153 if (in_be32(host->io_base) & FPGA_NAND_BUSY)
154 return 0; /* busy */
155 return 1;
156}
157
158#ifdef CONFIG_MTD_PARTITIONS
159static const char *part_probes[] = { "cmdlinepart", NULL };
160#endif
161
162/*
163 * Probe for the NAND device.
164 */
165static int __devinit socrates_nand_probe(struct of_device *ofdev,
166 const struct of_device_id *ofid)
167{
168 struct socrates_nand_host *host;
169 struct mtd_info *mtd;
170 struct nand_chip *nand_chip;
171 int res;
172
173#ifdef CONFIG_MTD_PARTITIONS
174 struct mtd_partition *partitions = NULL;
175 int num_partitions = 0;
176#endif
177
178 /* Allocate memory for the device structure (and zero it) */
179 host = kzalloc(sizeof(struct socrates_nand_host), GFP_KERNEL);
180 if (!host) {
181 printk(KERN_ERR
182 "socrates_nand: failed to allocate device structure.\n");
183 return -ENOMEM;
184 }
185
186 host->io_base = of_iomap(ofdev->node, 0);
187 if (host->io_base == NULL) {
188 printk(KERN_ERR "socrates_nand: ioremap failed\n");
189 kfree(host);
190 return -EIO;
191 }
192
193 mtd = &host->mtd;
194 nand_chip = &host->nand_chip;
195 host->dev = &ofdev->dev;
196
197 nand_chip->priv = host; /* link the private data structures */
198 mtd->priv = nand_chip;
199 mtd->name = "socrates_nand";
200 mtd->owner = THIS_MODULE;
201 mtd->dev.parent = &ofdev->dev;
202
203 /*should never be accessed directly */
204 nand_chip->IO_ADDR_R = (void *)0xdeadbeef;
205 nand_chip->IO_ADDR_W = (void *)0xdeadbeef;
206
207 nand_chip->cmd_ctrl = socrates_nand_cmd_ctrl;
208 nand_chip->read_byte = socrates_nand_read_byte;
209 nand_chip->read_word = socrates_nand_read_word;
210 nand_chip->write_buf = socrates_nand_write_buf;
211 nand_chip->read_buf = socrates_nand_read_buf;
212 nand_chip->verify_buf = socrates_nand_verify_buf;
213 nand_chip->dev_ready = socrates_nand_device_ready;
214
215 nand_chip->ecc.mode = NAND_ECC_SOFT; /* enable ECC */
216
217 /* TODO: I have no idea what real delay is. */
218 nand_chip->chip_delay = 20; /* 20us command delay time */
219
220 dev_set_drvdata(&ofdev->dev, host);
221
222 /* first scan to find the device and get the page size */
223 if (nand_scan_ident(mtd, 1)) {
224 res = -ENXIO;
225 goto out;
226 }
227
228 /* second phase scan */
229 if (nand_scan_tail(mtd)) {
230 res = -ENXIO;
231 goto out;
232 }
233
234#ifdef CONFIG_MTD_PARTITIONS
235#ifdef CONFIG_MTD_CMDLINE_PARTS
236 num_partitions = parse_mtd_partitions(mtd, part_probes,
237 &partitions, 0);
238 if (num_partitions < 0) {
239 res = num_partitions;
240 goto release;
241 }
242#endif
243
244#ifdef CONFIG_MTD_OF_PARTS
245 if (num_partitions == 0) {
246 num_partitions = of_mtd_parse_partitions(&ofdev->dev,
247 ofdev->node,
248 &partitions);
249 if (num_partitions < 0) {
250 res = num_partitions;
251 goto release;
252 }
253 }
254#endif
255 if (partitions && (num_partitions > 0))
256 res = add_mtd_partitions(mtd, partitions, num_partitions);
257 else
258#endif
259 res = add_mtd_device(mtd);
260
261 if (!res)
262 return res;
263
264#ifdef CONFIG_MTD_PARTITIONS
265release:
266#endif
267 nand_release(mtd);
268
269out:
270 dev_set_drvdata(&ofdev->dev, NULL);
271 iounmap(host->io_base);
272 kfree(host);
273 return res;
274}
275
276/*
277 * Remove a NAND device.
278 */
279static int __devexit socrates_nand_remove(struct of_device *ofdev)
280{
281 struct socrates_nand_host *host = dev_get_drvdata(&ofdev->dev);
282 struct mtd_info *mtd = &host->mtd;
283
284 nand_release(mtd);
285
286 dev_set_drvdata(&ofdev->dev, NULL);
287 iounmap(host->io_base);
288 kfree(host);
289
290 return 0;
291}
292
293static struct of_device_id socrates_nand_match[] =
294{
295 {
296 .compatible = "abb,socrates-nand",
297 },
298 {},
299};
300
301MODULE_DEVICE_TABLE(of, socrates_nand_match);
302
303static struct of_platform_driver socrates_nand_driver = {
304 .name = "socrates_nand",
305 .match_table = socrates_nand_match,
306 .probe = socrates_nand_probe,
307 .remove = __devexit_p(socrates_nand_remove),
308};
309
310static int __init socrates_nand_init(void)
311{
312 return of_register_platform_driver(&socrates_nand_driver);
313}
314
315static void __exit socrates_nand_exit(void)
316{
317 of_unregister_platform_driver(&socrates_nand_driver);
318}
319
320module_init(socrates_nand_init);
321module_exit(socrates_nand_exit);
322
323MODULE_LICENSE("GPL");
324MODULE_AUTHOR("Ilya Yanok");
325MODULE_DESCRIPTION("NAND driver for Socrates board");
diff --git a/drivers/mtd/nand/txx9ndfmc.c b/drivers/mtd/nand/txx9ndfmc.c
new file mode 100644
index 000000000000..812479264896
--- /dev/null
+++ b/drivers/mtd/nand/txx9ndfmc.c
@@ -0,0 +1,428 @@
1/*
2 * TXx9 NAND flash memory controller driver
3 * Based on RBTX49xx patch from CELF patch archive.
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * (C) Copyright TOSHIBA CORPORATION 2004-2007
10 * All Rights Reserved.
11 */
12#include <linux/init.h>
13#include <linux/slab.h>
14#include <linux/module.h>
15#include <linux/platform_device.h>
16#include <linux/delay.h>
17#include <linux/mtd/mtd.h>
18#include <linux/mtd/nand.h>
19#include <linux/mtd/nand_ecc.h>
20#include <linux/mtd/partitions.h>
21#include <linux/io.h>
22#include <asm/txx9/ndfmc.h>
23
24/* TXX9 NDFMC Registers */
25#define TXX9_NDFDTR 0x00
26#define TXX9_NDFMCR 0x04
27#define TXX9_NDFSR 0x08
28#define TXX9_NDFISR 0x0c
29#define TXX9_NDFIMR 0x10
30#define TXX9_NDFSPR 0x14
31#define TXX9_NDFRSTR 0x18 /* not TX4939 */
32
33/* NDFMCR : NDFMC Mode Control */
34#define TXX9_NDFMCR_WE 0x80
35#define TXX9_NDFMCR_ECC_ALL 0x60
36#define TXX9_NDFMCR_ECC_RESET 0x60
37#define TXX9_NDFMCR_ECC_READ 0x40
38#define TXX9_NDFMCR_ECC_ON 0x20
39#define TXX9_NDFMCR_ECC_OFF 0x00
40#define TXX9_NDFMCR_CE 0x10
41#define TXX9_NDFMCR_BSPRT 0x04 /* TX4925/TX4926 only */
42#define TXX9_NDFMCR_ALE 0x02
43#define TXX9_NDFMCR_CLE 0x01
44/* TX4939 only */
45#define TXX9_NDFMCR_X16 0x0400
46#define TXX9_NDFMCR_DMAREQ_MASK 0x0300
47#define TXX9_NDFMCR_DMAREQ_NODMA 0x0000
48#define TXX9_NDFMCR_DMAREQ_128 0x0100
49#define TXX9_NDFMCR_DMAREQ_256 0x0200
50#define TXX9_NDFMCR_DMAREQ_512 0x0300
51#define TXX9_NDFMCR_CS_MASK 0x0c
52#define TXX9_NDFMCR_CS(ch) ((ch) << 2)
53
54/* NDFMCR : NDFMC Status */
55#define TXX9_NDFSR_BUSY 0x80
56/* TX4939 only */
57#define TXX9_NDFSR_DMARUN 0x40
58
59/* NDFMCR : NDFMC Reset */
60#define TXX9_NDFRSTR_RST 0x01
61
62struct txx9ndfmc_priv {
63 struct platform_device *dev;
64 struct nand_chip chip;
65 struct mtd_info mtd;
66 int cs;
67 char mtdname[BUS_ID_SIZE + 2];
68};
69
70#define MAX_TXX9NDFMC_DEV 4
71struct txx9ndfmc_drvdata {
72 struct mtd_info *mtds[MAX_TXX9NDFMC_DEV];
73 void __iomem *base;
74 unsigned char hold; /* in gbusclock */
75 unsigned char spw; /* in gbusclock */
76 struct nand_hw_control hw_control;
77#ifdef CONFIG_MTD_PARTITIONS
78 struct mtd_partition *parts[MAX_TXX9NDFMC_DEV];
79#endif
80};
81
82static struct platform_device *mtd_to_platdev(struct mtd_info *mtd)
83{
84 struct nand_chip *chip = mtd->priv;
85 struct txx9ndfmc_priv *txx9_priv = chip->priv;
86 return txx9_priv->dev;
87}
88
89static void __iomem *ndregaddr(struct platform_device *dev, unsigned int reg)
90{
91 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev);
92 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
93
94 return drvdata->base + (reg << plat->shift);
95}
96
97static u32 txx9ndfmc_read(struct platform_device *dev, unsigned int reg)
98{
99 return __raw_readl(ndregaddr(dev, reg));
100}
101
102static void txx9ndfmc_write(struct platform_device *dev,
103 u32 val, unsigned int reg)
104{
105 __raw_writel(val, ndregaddr(dev, reg));
106}
107
108static uint8_t txx9ndfmc_read_byte(struct mtd_info *mtd)
109{
110 struct platform_device *dev = mtd_to_platdev(mtd);
111
112 return txx9ndfmc_read(dev, TXX9_NDFDTR);
113}
114
115static void txx9ndfmc_write_buf(struct mtd_info *mtd, const uint8_t *buf,
116 int len)
117{
118 struct platform_device *dev = mtd_to_platdev(mtd);
119 void __iomem *ndfdtr = ndregaddr(dev, TXX9_NDFDTR);
120 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR);
121
122 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_WE, TXX9_NDFMCR);
123 while (len--)
124 __raw_writel(*buf++, ndfdtr);
125 txx9ndfmc_write(dev, mcr, TXX9_NDFMCR);
126}
127
128static void txx9ndfmc_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
129{
130 struct platform_device *dev = mtd_to_platdev(mtd);
131 void __iomem *ndfdtr = ndregaddr(dev, TXX9_NDFDTR);
132
133 while (len--)
134 *buf++ = __raw_readl(ndfdtr);
135}
136
137static int txx9ndfmc_verify_buf(struct mtd_info *mtd, const uint8_t *buf,
138 int len)
139{
140 struct platform_device *dev = mtd_to_platdev(mtd);
141 void __iomem *ndfdtr = ndregaddr(dev, TXX9_NDFDTR);
142
143 while (len--)
144 if (*buf++ != (uint8_t)__raw_readl(ndfdtr))
145 return -EFAULT;
146 return 0;
147}
148
149static void txx9ndfmc_cmd_ctrl(struct mtd_info *mtd, int cmd,
150 unsigned int ctrl)
151{
152 struct nand_chip *chip = mtd->priv;
153 struct txx9ndfmc_priv *txx9_priv = chip->priv;
154 struct platform_device *dev = txx9_priv->dev;
155 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
156
157 if (ctrl & NAND_CTRL_CHANGE) {
158 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR);
159
160 mcr &= ~(TXX9_NDFMCR_CLE | TXX9_NDFMCR_ALE | TXX9_NDFMCR_CE);
161 mcr |= ctrl & NAND_CLE ? TXX9_NDFMCR_CLE : 0;
162 mcr |= ctrl & NAND_ALE ? TXX9_NDFMCR_ALE : 0;
163 /* TXX9_NDFMCR_CE bit is 0:high 1:low */
164 mcr |= ctrl & NAND_NCE ? TXX9_NDFMCR_CE : 0;
165 if (txx9_priv->cs >= 0 && (ctrl & NAND_NCE)) {
166 mcr &= ~TXX9_NDFMCR_CS_MASK;
167 mcr |= TXX9_NDFMCR_CS(txx9_priv->cs);
168 }
169 txx9ndfmc_write(dev, mcr, TXX9_NDFMCR);
170 }
171 if (cmd != NAND_CMD_NONE)
172 txx9ndfmc_write(dev, cmd & 0xff, TXX9_NDFDTR);
173 if (plat->flags & NDFMC_PLAT_FLAG_DUMMYWRITE) {
174 /* dummy write to update external latch */
175 if ((ctrl & NAND_CTRL_CHANGE) && cmd == NAND_CMD_NONE)
176 txx9ndfmc_write(dev, 0, TXX9_NDFDTR);
177 }
178 mmiowb();
179}
180
181static int txx9ndfmc_dev_ready(struct mtd_info *mtd)
182{
183 struct platform_device *dev = mtd_to_platdev(mtd);
184
185 return !(txx9ndfmc_read(dev, TXX9_NDFSR) & TXX9_NDFSR_BUSY);
186}
187
188static int txx9ndfmc_calculate_ecc(struct mtd_info *mtd, const uint8_t *dat,
189 uint8_t *ecc_code)
190{
191 struct platform_device *dev = mtd_to_platdev(mtd);
192 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR);
193
194 mcr &= ~TXX9_NDFMCR_ECC_ALL;
195 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_OFF, TXX9_NDFMCR);
196 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_READ, TXX9_NDFMCR);
197 ecc_code[1] = txx9ndfmc_read(dev, TXX9_NDFDTR);
198 ecc_code[0] = txx9ndfmc_read(dev, TXX9_NDFDTR);
199 ecc_code[2] = txx9ndfmc_read(dev, TXX9_NDFDTR);
200 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_OFF, TXX9_NDFMCR);
201 return 0;
202}
203
204static void txx9ndfmc_enable_hwecc(struct mtd_info *mtd, int mode)
205{
206 struct platform_device *dev = mtd_to_platdev(mtd);
207 u32 mcr = txx9ndfmc_read(dev, TXX9_NDFMCR);
208
209 mcr &= ~TXX9_NDFMCR_ECC_ALL;
210 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_RESET, TXX9_NDFMCR);
211 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_OFF, TXX9_NDFMCR);
212 txx9ndfmc_write(dev, mcr | TXX9_NDFMCR_ECC_ON, TXX9_NDFMCR);
213}
214
215static void txx9ndfmc_initialize(struct platform_device *dev)
216{
217 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
218 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev);
219 int tmout = 100;
220
221 if (plat->flags & NDFMC_PLAT_FLAG_NO_RSTR)
222 ; /* no NDFRSTR. Write to NDFSPR resets the NDFMC. */
223 else {
224 /* reset NDFMC */
225 txx9ndfmc_write(dev,
226 txx9ndfmc_read(dev, TXX9_NDFRSTR) |
227 TXX9_NDFRSTR_RST,
228 TXX9_NDFRSTR);
229 while (txx9ndfmc_read(dev, TXX9_NDFRSTR) & TXX9_NDFRSTR_RST) {
230 if (--tmout == 0) {
231 dev_err(&dev->dev, "reset failed.\n");
232 break;
233 }
234 udelay(1);
235 }
236 }
237 /* setup Hold Time, Strobe Pulse Width */
238 txx9ndfmc_write(dev, (drvdata->hold << 4) | drvdata->spw, TXX9_NDFSPR);
239 txx9ndfmc_write(dev,
240 (plat->flags & NDFMC_PLAT_FLAG_USE_BSPRT) ?
241 TXX9_NDFMCR_BSPRT : 0, TXX9_NDFMCR);
242}
243
244#define TXX9NDFMC_NS_TO_CYC(gbusclk, ns) \
245 DIV_ROUND_UP((ns) * DIV_ROUND_UP(gbusclk, 1000), 1000000)
246
247static int __init txx9ndfmc_probe(struct platform_device *dev)
248{
249 struct txx9ndfmc_platform_data *plat = dev->dev.platform_data;
250#ifdef CONFIG_MTD_PARTITIONS
251 static const char *probes[] = { "cmdlinepart", NULL };
252#endif
253 int hold, spw;
254 int i;
255 struct txx9ndfmc_drvdata *drvdata;
256 unsigned long gbusclk = plat->gbus_clock;
257 struct resource *res;
258
259 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
260 if (!res)
261 return -ENODEV;
262 drvdata = devm_kzalloc(&dev->dev, sizeof(*drvdata), GFP_KERNEL);
263 if (!drvdata)
264 return -ENOMEM;
265 if (!devm_request_mem_region(&dev->dev, res->start,
266 resource_size(res), dev_name(&dev->dev)))
267 return -EBUSY;
268 drvdata->base = devm_ioremap(&dev->dev, res->start,
269 resource_size(res));
270 if (!drvdata->base)
271 return -EBUSY;
272
273 hold = plat->hold ?: 20; /* tDH */
274 spw = plat->spw ?: 90; /* max(tREADID, tWP, tRP) */
275
276 hold = TXX9NDFMC_NS_TO_CYC(gbusclk, hold);
277 spw = TXX9NDFMC_NS_TO_CYC(gbusclk, spw);
278 if (plat->flags & NDFMC_PLAT_FLAG_HOLDADD)
279 hold -= 2; /* actual hold time : (HOLD + 2) BUSCLK */
280 spw -= 1; /* actual wait time : (SPW + 1) BUSCLK */
281 hold = clamp(hold, 1, 15);
282 drvdata->hold = hold;
283 spw = clamp(spw, 1, 15);
284 drvdata->spw = spw;
285 dev_info(&dev->dev, "CLK:%ldMHz HOLD:%d SPW:%d\n",
286 (gbusclk + 500000) / 1000000, hold, spw);
287
288 spin_lock_init(&drvdata->hw_control.lock);
289 init_waitqueue_head(&drvdata->hw_control.wq);
290
291 platform_set_drvdata(dev, drvdata);
292 txx9ndfmc_initialize(dev);
293
294 for (i = 0; i < MAX_TXX9NDFMC_DEV; i++) {
295 struct txx9ndfmc_priv *txx9_priv;
296 struct nand_chip *chip;
297 struct mtd_info *mtd;
298#ifdef CONFIG_MTD_PARTITIONS
299 int nr_parts;
300#endif
301
302 if (!(plat->ch_mask & (1 << i)))
303 continue;
304 txx9_priv = kzalloc(sizeof(struct txx9ndfmc_priv),
305 GFP_KERNEL);
306 if (!txx9_priv) {
307 dev_err(&dev->dev, "Unable to allocate "
308 "TXx9 NDFMC MTD device structure.\n");
309 continue;
310 }
311 chip = &txx9_priv->chip;
312 mtd = &txx9_priv->mtd;
313 mtd->owner = THIS_MODULE;
314
315 mtd->priv = chip;
316
317 chip->read_byte = txx9ndfmc_read_byte;
318 chip->read_buf = txx9ndfmc_read_buf;
319 chip->write_buf = txx9ndfmc_write_buf;
320 chip->verify_buf = txx9ndfmc_verify_buf;
321 chip->cmd_ctrl = txx9ndfmc_cmd_ctrl;
322 chip->dev_ready = txx9ndfmc_dev_ready;
323 chip->ecc.calculate = txx9ndfmc_calculate_ecc;
324 chip->ecc.correct = nand_correct_data;
325 chip->ecc.hwctl = txx9ndfmc_enable_hwecc;
326 chip->ecc.mode = NAND_ECC_HW;
327 chip->ecc.size = 256;
328 chip->ecc.bytes = 3;
329 chip->chip_delay = 100;
330 chip->controller = &drvdata->hw_control;
331
332 chip->priv = txx9_priv;
333 txx9_priv->dev = dev;
334
335 if (plat->ch_mask != 1) {
336 txx9_priv->cs = i;
337 sprintf(txx9_priv->mtdname, "%s.%u",
338 dev_name(&dev->dev), i);
339 } else {
340 txx9_priv->cs = -1;
341 strcpy(txx9_priv->mtdname, dev_name(&dev->dev));
342 }
343 if (plat->wide_mask & (1 << i))
344 chip->options |= NAND_BUSWIDTH_16;
345
346 if (nand_scan(mtd, 1)) {
347 kfree(txx9_priv);
348 continue;
349 }
350 mtd->name = txx9_priv->mtdname;
351
352#ifdef CONFIG_MTD_PARTITIONS
353 nr_parts = parse_mtd_partitions(mtd, probes,
354 &drvdata->parts[i], 0);
355 if (nr_parts > 0)
356 add_mtd_partitions(mtd, drvdata->parts[i], nr_parts);
357#endif
358 add_mtd_device(mtd);
359 drvdata->mtds[i] = mtd;
360 }
361
362 return 0;
363}
364
365static int __exit txx9ndfmc_remove(struct platform_device *dev)
366{
367 struct txx9ndfmc_drvdata *drvdata = platform_get_drvdata(dev);
368 int i;
369
370 platform_set_drvdata(dev, NULL);
371 if (!drvdata)
372 return 0;
373 for (i = 0; i < MAX_TXX9NDFMC_DEV; i++) {
374 struct mtd_info *mtd = drvdata->mtds[i];
375 struct nand_chip *chip;
376 struct txx9ndfmc_priv *txx9_priv;
377
378 if (!mtd)
379 continue;
380 chip = mtd->priv;
381 txx9_priv = chip->priv;
382
383#ifdef CONFIG_MTD_PARTITIONS
384 del_mtd_partitions(mtd);
385 kfree(drvdata->parts[i]);
386#endif
387 del_mtd_device(mtd);
388 kfree(txx9_priv);
389 }
390 return 0;
391}
392
393#ifdef CONFIG_PM
394static int txx9ndfmc_resume(struct platform_device *dev)
395{
396 if (platform_get_drvdata(dev))
397 txx9ndfmc_initialize(dev);
398 return 0;
399}
400#else
401#define txx9ndfmc_resume NULL
402#endif
403
404static struct platform_driver txx9ndfmc_driver = {
405 .remove = __exit_p(txx9ndfmc_remove),
406 .resume = txx9ndfmc_resume,
407 .driver = {
408 .name = "txx9ndfmc",
409 .owner = THIS_MODULE,
410 },
411};
412
413static int __init txx9ndfmc_init(void)
414{
415 return platform_driver_probe(&txx9ndfmc_driver, txx9ndfmc_probe);
416}
417
418static void __exit txx9ndfmc_exit(void)
419{
420 platform_driver_unregister(&txx9ndfmc_driver);
421}
422
423module_init(txx9ndfmc_init);
424module_exit(txx9ndfmc_exit);
425
426MODULE_LICENSE("GPL");
427MODULE_DESCRIPTION("TXx9 SoC NAND flash controller driver");
428MODULE_ALIAS("platform:txx9ndfmc");
diff --git a/drivers/mtd/nftlcore.c b/drivers/mtd/nftlcore.c
index d1c4546513f7..e3f8495a94c2 100644
--- a/drivers/mtd/nftlcore.c
+++ b/drivers/mtd/nftlcore.c
@@ -15,11 +15,11 @@
15#include <asm/errno.h> 15#include <asm/errno.h>
16#include <asm/io.h> 16#include <asm/io.h>
17#include <asm/uaccess.h> 17#include <asm/uaccess.h>
18#include <linux/miscdevice.h>
19#include <linux/delay.h> 18#include <linux/delay.h>
20#include <linux/slab.h> 19#include <linux/slab.h>
21#include <linux/init.h> 20#include <linux/init.h>
22#include <linux/hdreg.h> 21#include <linux/hdreg.h>
22#include <linux/blkdev.h>
23 23
24#include <linux/kmod.h> 24#include <linux/kmod.h>
25#include <linux/mtd/mtd.h> 25#include <linux/mtd/mtd.h>
@@ -818,3 +818,4 @@ module_exit(cleanup_nftl);
818MODULE_LICENSE("GPL"); 818MODULE_LICENSE("GPL");
819MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>, Fabrice Bellard <fabrice.bellard@netgem.com> et al."); 819MODULE_AUTHOR("David Woodhouse <dwmw2@infradead.org>, Fabrice Bellard <fabrice.bellard@netgem.com> et al.");
820MODULE_DESCRIPTION("Support code for NAND Flash Translation Layer, used on M-Systems DiskOnChip 2000 and Millennium"); 820MODULE_DESCRIPTION("Support code for NAND Flash Translation Layer, used on M-Systems DiskOnChip 2000 and Millennium");
821MODULE_ALIAS_BLOCKDEV_MAJOR(NFTL_MAJOR);
diff --git a/drivers/mtd/ofpart.c b/drivers/mtd/ofpart.c
index 9e45b3f39c0e..3e164f0c9295 100644
--- a/drivers/mtd/ofpart.c
+++ b/drivers/mtd/ofpart.c
@@ -46,6 +46,13 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
46 const u32 *reg; 46 const u32 *reg;
47 int len; 47 int len;
48 48
49 /* check if this is a partition node */
50 partname = of_get_property(pp, "name", &len);
51 if (strcmp(partname, "partition") != 0) {
52 nr_parts--;
53 continue;
54 }
55
49 reg = of_get_property(pp, "reg", &len); 56 reg = of_get_property(pp, "reg", &len);
50 if (!reg || (len != 2 * sizeof(u32))) { 57 if (!reg || (len != 2 * sizeof(u32))) {
51 of_node_put(pp); 58 of_node_put(pp);
diff --git a/drivers/mtd/onenand/omap2.c b/drivers/mtd/onenand/omap2.c
index 77a4f1446156..f2e9de1414df 100644
--- a/drivers/mtd/onenand/omap2.c
+++ b/drivers/mtd/onenand/omap2.c
@@ -294,6 +294,10 @@ static int omap3_onenand_read_bufferram(struct mtd_info *mtd, int area,
294 if (bram_offset & 3 || (size_t)buf & 3 || count < 384) 294 if (bram_offset & 3 || (size_t)buf & 3 || count < 384)
295 goto out_copy; 295 goto out_copy;
296 296
297 /* panic_write() may be in an interrupt context */
298 if (in_interrupt())
299 goto out_copy;
300
297 if (buf >= high_memory) { 301 if (buf >= high_memory) {
298 struct page *p1; 302 struct page *p1;
299 303
@@ -672,6 +676,8 @@ static int __devinit omap2_onenand_probe(struct platform_device *pdev)
672 c->mtd.priv = &c->onenand; 676 c->mtd.priv = &c->onenand;
673 c->mtd.owner = THIS_MODULE; 677 c->mtd.owner = THIS_MODULE;
674 678
679 c->mtd.dev.parent = &pdev->dev;
680
675 if (c->dma_channel >= 0) { 681 if (c->dma_channel >= 0) {
676 struct onenand_chip *this = &c->onenand; 682 struct onenand_chip *this = &c->onenand;
677 683
diff --git a/drivers/mtd/onenand/onenand_base.c b/drivers/mtd/onenand/onenand_base.c
index 529af271db17..30d6999e5f9f 100644
--- a/drivers/mtd/onenand/onenand_base.c
+++ b/drivers/mtd/onenand/onenand_base.c
@@ -1455,7 +1455,8 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1455 struct mtd_oob_ops *ops) 1455 struct mtd_oob_ops *ops)
1456{ 1456{
1457 struct onenand_chip *this = mtd->priv; 1457 struct onenand_chip *this = mtd->priv;
1458 int written = 0, column, thislen, subpage; 1458 int written = 0, column, thislen = 0, subpage = 0;
1459 int prev = 0, prevlen = 0, prev_subpage = 0, first = 1;
1459 int oobwritten = 0, oobcolumn, thisooblen, oobsize; 1460 int oobwritten = 0, oobcolumn, thisooblen, oobsize;
1460 size_t len = ops->len; 1461 size_t len = ops->len;
1461 size_t ooblen = ops->ooblen; 1462 size_t ooblen = ops->ooblen;
@@ -1482,6 +1483,10 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1482 return -EINVAL; 1483 return -EINVAL;
1483 } 1484 }
1484 1485
1486 /* Check zero length */
1487 if (!len)
1488 return 0;
1489
1485 if (ops->mode == MTD_OOB_AUTO) 1490 if (ops->mode == MTD_OOB_AUTO)
1486 oobsize = this->ecclayout->oobavail; 1491 oobsize = this->ecclayout->oobavail;
1487 else 1492 else
@@ -1492,79 +1497,121 @@ static int onenand_write_ops_nolock(struct mtd_info *mtd, loff_t to,
1492 column = to & (mtd->writesize - 1); 1497 column = to & (mtd->writesize - 1);
1493 1498
1494 /* Loop until all data write */ 1499 /* Loop until all data write */
1495 while (written < len) { 1500 while (1) {
1496 u_char *wbuf = (u_char *) buf; 1501 if (written < len) {
1502 u_char *wbuf = (u_char *) buf;
1497 1503
1498 thislen = min_t(int, mtd->writesize - column, len - written); 1504 thislen = min_t(int, mtd->writesize - column, len - written);
1499 thisooblen = min_t(int, oobsize - oobcolumn, ooblen - oobwritten); 1505 thisooblen = min_t(int, oobsize - oobcolumn, ooblen - oobwritten);
1500 1506
1501 cond_resched(); 1507 cond_resched();
1502 1508
1503 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen); 1509 this->command(mtd, ONENAND_CMD_BUFFERRAM, to, thislen);
1504 1510
1505 /* Partial page write */ 1511 /* Partial page write */
1506 subpage = thislen < mtd->writesize; 1512 subpage = thislen < mtd->writesize;
1507 if (subpage) { 1513 if (subpage) {
1508 memset(this->page_buf, 0xff, mtd->writesize); 1514 memset(this->page_buf, 0xff, mtd->writesize);
1509 memcpy(this->page_buf + column, buf, thislen); 1515 memcpy(this->page_buf + column, buf, thislen);
1510 wbuf = this->page_buf; 1516 wbuf = this->page_buf;
1511 } 1517 }
1512 1518
1513 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize); 1519 this->write_bufferram(mtd, ONENAND_DATARAM, wbuf, 0, mtd->writesize);
1514 1520
1515 if (oob) { 1521 if (oob) {
1516 oobbuf = this->oob_buf; 1522 oobbuf = this->oob_buf;
1517 1523
1518 /* We send data to spare ram with oobsize 1524 /* We send data to spare ram with oobsize
1519 * to prevent byte access */ 1525 * to prevent byte access */
1520 memset(oobbuf, 0xff, mtd->oobsize); 1526 memset(oobbuf, 0xff, mtd->oobsize);
1521 if (ops->mode == MTD_OOB_AUTO) 1527 if (ops->mode == MTD_OOB_AUTO)
1522 onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen); 1528 onenand_fill_auto_oob(mtd, oobbuf, oob, oobcolumn, thisooblen);
1523 else 1529 else
1524 memcpy(oobbuf + oobcolumn, oob, thisooblen); 1530 memcpy(oobbuf + oobcolumn, oob, thisooblen);
1525 1531
1526 oobwritten += thisooblen; 1532 oobwritten += thisooblen;
1527 oob += thisooblen; 1533 oob += thisooblen;
1528 oobcolumn = 0; 1534 oobcolumn = 0;
1535 } else
1536 oobbuf = (u_char *) ffchars;
1537
1538 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize);
1529 } else 1539 } else
1530 oobbuf = (u_char *) ffchars; 1540 ONENAND_SET_NEXT_BUFFERRAM(this);
1531 1541
1532 this->write_bufferram(mtd, ONENAND_SPARERAM, oobbuf, 0, mtd->oobsize); 1542 /*
1543 * 2 PLANE, MLC, and Flex-OneNAND doesn't support
1544 * write-while-programe feature.
1545 */
1546 if (!ONENAND_IS_2PLANE(this) && !first) {
1547 ONENAND_SET_PREV_BUFFERRAM(this);
1533 1548
1534 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize); 1549 ret = this->wait(mtd, FL_WRITING);
1535 1550
1536 ret = this->wait(mtd, FL_WRITING); 1551 /* In partial page write we don't update bufferram */
1552 onenand_update_bufferram(mtd, prev, !ret && !prev_subpage);
1553 if (ret) {
1554 written -= prevlen;
1555 printk(KERN_ERR "onenand_write_ops_nolock: write filaed %d\n", ret);
1556 break;
1557 }
1537 1558
1538 /* In partial page write we don't update bufferram */ 1559 if (written == len) {
1539 onenand_update_bufferram(mtd, to, !ret && !subpage); 1560 /* Only check verify write turn on */
1540 if (ONENAND_IS_2PLANE(this)) { 1561 ret = onenand_verify(mtd, buf - len, to - len, len);
1541 ONENAND_SET_BUFFERRAM1(this); 1562 if (ret)
1542 onenand_update_bufferram(mtd, to + this->writesize, !ret && !subpage); 1563 printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret);
1543 } 1564 break;
1565 }
1544 1566
1545 if (ret) { 1567 ONENAND_SET_NEXT_BUFFERRAM(this);
1546 printk(KERN_ERR "onenand_write_ops_nolock: write filaed %d\n", ret);
1547 break;
1548 } 1568 }
1549 1569
1550 /* Only check verify write turn on */ 1570 this->command(mtd, ONENAND_CMD_PROG, to, mtd->writesize);
1551 ret = onenand_verify(mtd, buf, to, thislen);
1552 if (ret) {
1553 printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret);
1554 break;
1555 }
1556 1571
1557 written += thislen; 1572 /*
1573 * 2 PLANE, MLC, and Flex-OneNAND wait here
1574 */
1575 if (ONENAND_IS_2PLANE(this)) {
1576 ret = this->wait(mtd, FL_WRITING);
1558 1577
1559 if (written == len) 1578 /* In partial page write we don't update bufferram */
1560 break; 1579 onenand_update_bufferram(mtd, to, !ret && !subpage);
1580 if (ret) {
1581 printk(KERN_ERR "onenand_write_ops_nolock: write filaed %d\n", ret);
1582 break;
1583 }
1584
1585 /* Only check verify write turn on */
1586 ret = onenand_verify(mtd, buf, to, thislen);
1587 if (ret) {
1588 printk(KERN_ERR "onenand_write_ops_nolock: verify failed %d\n", ret);
1589 break;
1590 }
1591
1592 written += thislen;
1593
1594 if (written == len)
1595 break;
1596
1597 } else
1598 written += thislen;
1561 1599
1562 column = 0; 1600 column = 0;
1601 prev_subpage = subpage;
1602 prev = to;
1603 prevlen = thislen;
1563 to += thislen; 1604 to += thislen;
1564 buf += thislen; 1605 buf += thislen;
1606 first = 0;
1565 } 1607 }
1566 1608
1609 /* In error case, clear all bufferrams */
1610 if (written != len)
1611 onenand_invalidate_bufferram(mtd, 0, -1);
1612
1567 ops->retlen = written; 1613 ops->retlen = written;
1614 ops->oobretlen = oobwritten;
1568 1615
1569 return ret; 1616 return ret;
1570} 1617}
diff --git a/fs/jffs2/acl.c b/fs/jffs2/acl.c
index 77ccf8cb0823..043740dde20c 100644
--- a/fs/jffs2/acl.c
+++ b/fs/jffs2/acl.c
@@ -38,12 +38,12 @@ static int jffs2_acl_count(size_t size)
38 size_t s; 38 size_t s;
39 39
40 size -= sizeof(struct jffs2_acl_header); 40 size -= sizeof(struct jffs2_acl_header);
41 s = size - 4 * sizeof(struct jffs2_acl_entry_short); 41 if (size < 4 * sizeof(struct jffs2_acl_entry_short)) {
42 if (s < 0) {
43 if (size % sizeof(struct jffs2_acl_entry_short)) 42 if (size % sizeof(struct jffs2_acl_entry_short))
44 return -1; 43 return -1;
45 return size / sizeof(struct jffs2_acl_entry_short); 44 return size / sizeof(struct jffs2_acl_entry_short);
46 } else { 45 } else {
46 s = size - 4 * sizeof(struct jffs2_acl_entry_short);
47 if (s % sizeof(struct jffs2_acl_entry)) 47 if (s % sizeof(struct jffs2_acl_entry))
48 return -1; 48 return -1;
49 return s / sizeof(struct jffs2_acl_entry) + 4; 49 return s / sizeof(struct jffs2_acl_entry) + 4;
diff --git a/fs/jffs2/malloc.c b/fs/jffs2/malloc.c
index f9211252b5f1..9eff2bdae8a7 100644
--- a/fs/jffs2/malloc.c
+++ b/fs/jffs2/malloc.c
@@ -284,10 +284,9 @@ void jffs2_free_inode_cache(struct jffs2_inode_cache *x)
284struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void) 284struct jffs2_xattr_datum *jffs2_alloc_xattr_datum(void)
285{ 285{
286 struct jffs2_xattr_datum *xd; 286 struct jffs2_xattr_datum *xd;
287 xd = kmem_cache_alloc(xattr_datum_cache, GFP_KERNEL); 287 xd = kmem_cache_zalloc(xattr_datum_cache, GFP_KERNEL);
288 dbg_memalloc("%p\n", xd); 288 dbg_memalloc("%p\n", xd);
289 289
290 memset(xd, 0, sizeof(struct jffs2_xattr_datum));
291 xd->class = RAWNODE_CLASS_XATTR_DATUM; 290 xd->class = RAWNODE_CLASS_XATTR_DATUM;
292 xd->node = (void *)xd; 291 xd->node = (void *)xd;
293 INIT_LIST_HEAD(&xd->xindex); 292 INIT_LIST_HEAD(&xd->xindex);
@@ -303,10 +302,9 @@ void jffs2_free_xattr_datum(struct jffs2_xattr_datum *xd)
303struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void) 302struct jffs2_xattr_ref *jffs2_alloc_xattr_ref(void)
304{ 303{
305 struct jffs2_xattr_ref *ref; 304 struct jffs2_xattr_ref *ref;
306 ref = kmem_cache_alloc(xattr_ref_cache, GFP_KERNEL); 305 ref = kmem_cache_zalloc(xattr_ref_cache, GFP_KERNEL);
307 dbg_memalloc("%p\n", ref); 306 dbg_memalloc("%p\n", ref);
308 307
309 memset(ref, 0, sizeof(struct jffs2_xattr_ref));
310 ref->class = RAWNODE_CLASS_XATTR_REF; 308 ref->class = RAWNODE_CLASS_XATTR_REF;
311 ref->node = (void *)ref; 309 ref->node = (void *)ref;
312 return ref; 310 return ref;
diff --git a/fs/romfs/Kconfig b/fs/romfs/Kconfig
index 1a17020f9faf..ce2d6bcc6266 100644
--- a/fs/romfs/Kconfig
+++ b/fs/romfs/Kconfig
@@ -1,6 +1,6 @@
1config ROMFS_FS 1config ROMFS_FS
2 tristate "ROM file system support" 2 tristate "ROM file system support"
3 depends on BLOCK 3 depends on BLOCK || MTD
4 ---help--- 4 ---help---
5 This is a very small read-only file system mainly intended for 5 This is a very small read-only file system mainly intended for
6 initial ram disks of installation disks, but it could be used for 6 initial ram disks of installation disks, but it could be used for
@@ -14,3 +14,49 @@ config ROMFS_FS
14 14
15 If you don't know whether you need it, then you don't need it: 15 If you don't know whether you need it, then you don't need it:
16 answer N. 16 answer N.
17
18#
19# Select the backing stores to be supported
20#
21choice
22 prompt "RomFS backing stores"
23 depends on ROMFS_FS
24 default ROMFS_BACKED_BY_BLOCK
25 help
26 Select the backing stores to be supported.
27
28config ROMFS_BACKED_BY_BLOCK
29 bool "Block device-backed ROM file system support"
30 depends on BLOCK
31 help
32 This permits ROMFS to use block devices buffered through the page
33 cache as the medium from which to retrieve data. It does not allow
34 direct mapping of the medium.
35
36 If unsure, answer Y.
37
38config ROMFS_BACKED_BY_MTD
39 bool "MTD-backed ROM file system support"
40 depends on MTD=y || (ROMFS_FS=m && MTD)
41 help
42 This permits ROMFS to use MTD based devices directly, without the
43 intercession of the block layer (which may have been disabled). It
44 also allows direct mapping of MTD devices through romfs files under
45 NOMMU conditions if the underlying device is directly addressable by
46 the CPU.
47
48 If unsure, answer Y.
49
50config ROMFS_BACKED_BY_BOTH
51 bool "Both the above"
52 depends on BLOCK && (MTD=y || (ROMFS_FS=m && MTD))
53endchoice
54
55
56config ROMFS_ON_BLOCK
57 bool
58 default y if ROMFS_BACKED_BY_BLOCK || ROMFS_BACKED_BY_BOTH
59
60config ROMFS_ON_MTD
61 bool
62 default y if ROMFS_BACKED_BY_MTD || ROMFS_BACKED_BY_BOTH
diff --git a/fs/romfs/Makefile b/fs/romfs/Makefile
index c95b21cf49a3..420beb7d495c 100644
--- a/fs/romfs/Makefile
+++ b/fs/romfs/Makefile
@@ -1,7 +1,12 @@
1# 1#
2# Makefile for the linux romfs filesystem routines. 2# Makefile for the linux RomFS filesystem routines.
3# 3#
4 4
5obj-$(CONFIG_ROMFS_FS) += romfs.o 5obj-$(CONFIG_ROMFS_FS) += romfs.o
6 6
7romfs-objs := inode.o 7romfs-y := storage.o super.o
8
9ifneq ($(CONFIG_MMU),y)
10romfs-$(CONFIG_ROMFS_ON_MTD) += mmap-nommu.o
11endif
12
diff --git a/fs/romfs/inode.c b/fs/romfs/inode.c
deleted file mode 100644
index 98a232f7196b..000000000000
--- a/fs/romfs/inode.c
+++ /dev/null
@@ -1,665 +0,0 @@
1/*
2 * ROMFS file system, Linux implementation
3 *
4 * Copyright (C) 1997-1999 Janos Farkas <chexum@shadow.banki.hu>
5 *
6 * Using parts of the minix filesystem
7 * Copyright (C) 1991, 1992 Linus Torvalds
8 *
9 * and parts of the affs filesystem additionally
10 * Copyright (C) 1993 Ray Burr
11 * Copyright (C) 1996 Hans-Joachim Widmaier
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version
16 * 2 of the License, or (at your option) any later version.
17 *
18 * Changes
19 * Changed for 2.1.19 modules
20 * Jan 1997 Initial release
21 * Jun 1997 2.1.43+ changes
22 * Proper page locking in readpage
23 * Changed to work with 2.1.45+ fs
24 * Jul 1997 Fixed follow_link
25 * 2.1.47
26 * lookup shouldn't return -ENOENT
27 * from Horst von Brand:
28 * fail on wrong checksum
29 * double unlock_super was possible
30 * correct namelen for statfs
31 * spotted by Bill Hawes:
32 * readlink shouldn't iput()
33 * Jun 1998 2.1.106 from Avery Pennarun: glibc scandir()
34 * exposed a problem in readdir
35 * 2.1.107 code-freeze spellchecker run
36 * Aug 1998 2.1.118+ VFS changes
37 * Sep 1998 2.1.122 another VFS change (follow_link)
38 * Apr 1999 2.2.7 no more EBADF checking in
39 * lookup/readdir, use ERR_PTR
40 * Jun 1999 2.3.6 d_alloc_root use changed
41 * 2.3.9 clean up usage of ENOENT/negative
42 * dentries in lookup
43 * clean up page flags setting
44 * (error, uptodate, locking) in
45 * in readpage
46 * use init_special_inode for
47 * fifos/sockets (and streamline) in
48 * read_inode, fix _ops table order
49 * Aug 1999 2.3.16 __initfunc() => __init change
50 * Oct 1999 2.3.24 page->owner hack obsoleted
51 * Nov 1999 2.3.27 2.3.25+ page->offset => index change
52 */
53
54/* todo:
55 * - see Documentation/filesystems/romfs.txt
56 * - use allocated, not stack memory for file names?
57 * - considering write access...
58 * - network (tftp) files?
59 * - merge back some _op tables
60 */
61
62/*
63 * Sorry about some optimizations and for some goto's. I just wanted
64 * to squeeze some more bytes out of this code.. :)
65 */
66
67#include <linux/module.h>
68#include <linux/types.h>
69#include <linux/errno.h>
70#include <linux/slab.h>
71#include <linux/romfs_fs.h>
72#include <linux/fs.h>
73#include <linux/init.h>
74#include <linux/pagemap.h>
75#include <linux/smp_lock.h>
76#include <linux/buffer_head.h>
77#include <linux/vfs.h>
78
79#include <asm/uaccess.h>
80
81struct romfs_inode_info {
82 unsigned long i_metasize; /* size of non-data area */
83 unsigned long i_dataoffset; /* from the start of fs */
84 struct inode vfs_inode;
85};
86
87static struct inode *romfs_iget(struct super_block *, unsigned long);
88
89/* instead of private superblock data */
90static inline unsigned long romfs_maxsize(struct super_block *sb)
91{
92 return (unsigned long)sb->s_fs_info;
93}
94
95static inline struct romfs_inode_info *ROMFS_I(struct inode *inode)
96{
97 return container_of(inode, struct romfs_inode_info, vfs_inode);
98}
99
100static __u32
101romfs_checksum(void *data, int size)
102{
103 __u32 sum;
104 __be32 *ptr;
105
106 sum = 0; ptr = data;
107 size>>=2;
108 while (size>0) {
109 sum += be32_to_cpu(*ptr++);
110 size--;
111 }
112 return sum;
113}
114
115static const struct super_operations romfs_ops;
116
117static int romfs_fill_super(struct super_block *s, void *data, int silent)
118{
119 struct buffer_head *bh;
120 struct romfs_super_block *rsb;
121 struct inode *root;
122 int sz, ret = -EINVAL;
123
124 /* I would parse the options here, but there are none.. :) */
125
126 sb_set_blocksize(s, ROMBSIZE);
127 s->s_maxbytes = 0xFFFFFFFF;
128
129 bh = sb_bread(s, 0);
130 if (!bh) {
131 /* XXX merge with other printk? */
132 printk ("romfs: unable to read superblock\n");
133 goto outnobh;
134 }
135
136 rsb = (struct romfs_super_block *)bh->b_data;
137 sz = be32_to_cpu(rsb->size);
138 if (rsb->word0 != ROMSB_WORD0 || rsb->word1 != ROMSB_WORD1
139 || sz < ROMFH_SIZE) {
140 if (!silent)
141 printk ("VFS: Can't find a romfs filesystem on dev "
142 "%s.\n", s->s_id);
143 goto out;
144 }
145 if (romfs_checksum(rsb, min_t(int, sz, 512))) {
146 printk ("romfs: bad initial checksum on dev "
147 "%s.\n", s->s_id);
148 goto out;
149 }
150
151 s->s_magic = ROMFS_MAGIC;
152 s->s_fs_info = (void *)(long)sz;
153
154 s->s_flags |= MS_RDONLY;
155
156 /* Find the start of the fs */
157 sz = (ROMFH_SIZE +
158 strnlen(rsb->name, ROMFS_MAXFN) + 1 + ROMFH_PAD)
159 & ROMFH_MASK;
160
161 s->s_op = &romfs_ops;
162 root = romfs_iget(s, sz);
163 if (IS_ERR(root)) {
164 ret = PTR_ERR(root);
165 goto out;
166 }
167
168 ret = -ENOMEM;
169 s->s_root = d_alloc_root(root);
170 if (!s->s_root)
171 goto outiput;
172
173 brelse(bh);
174 return 0;
175
176outiput:
177 iput(root);
178out:
179 brelse(bh);
180outnobh:
181 return ret;
182}
183
184/* That's simple too. */
185
186static int
187romfs_statfs(struct dentry *dentry, struct kstatfs *buf)
188{
189 buf->f_type = ROMFS_MAGIC;
190 buf->f_bsize = ROMBSIZE;
191 buf->f_bfree = buf->f_bavail = buf->f_ffree;
192 buf->f_blocks = (romfs_maxsize(dentry->d_sb)+ROMBSIZE-1)>>ROMBSBITS;
193 buf->f_namelen = ROMFS_MAXFN;
194 return 0;
195}
196
197/* some helper routines */
198
199static int
200romfs_strnlen(struct inode *i, unsigned long offset, unsigned long count)
201{
202 struct buffer_head *bh;
203 unsigned long avail, maxsize, res;
204
205 maxsize = romfs_maxsize(i->i_sb);
206 if (offset >= maxsize)
207 return -1;
208
209 /* strnlen is almost always valid */
210 if (count > maxsize || offset+count > maxsize)
211 count = maxsize-offset;
212
213 bh = sb_bread(i->i_sb, offset>>ROMBSBITS);
214 if (!bh)
215 return -1; /* error */
216
217 avail = ROMBSIZE - (offset & ROMBMASK);
218 maxsize = min_t(unsigned long, count, avail);
219 res = strnlen(((char *)bh->b_data)+(offset&ROMBMASK), maxsize);
220 brelse(bh);
221
222 if (res < maxsize)
223 return res; /* found all of it */
224
225 while (res < count) {
226 offset += maxsize;
227
228 bh = sb_bread(i->i_sb, offset>>ROMBSBITS);
229 if (!bh)
230 return -1;
231 maxsize = min_t(unsigned long, count - res, ROMBSIZE);
232 avail = strnlen(bh->b_data, maxsize);
233 res += avail;
234 brelse(bh);
235 if (avail < maxsize)
236 return res;
237 }
238 return res;
239}
240
241static int
242romfs_copyfrom(struct inode *i, void *dest, unsigned long offset, unsigned long count)
243{
244 struct buffer_head *bh;
245 unsigned long avail, maxsize, res;
246
247 maxsize = romfs_maxsize(i->i_sb);
248 if (offset >= maxsize || count > maxsize || offset+count>maxsize)
249 return -1;
250
251 bh = sb_bread(i->i_sb, offset>>ROMBSBITS);
252 if (!bh)
253 return -1; /* error */
254
255 avail = ROMBSIZE - (offset & ROMBMASK);
256 maxsize = min_t(unsigned long, count, avail);
257 memcpy(dest, ((char *)bh->b_data) + (offset & ROMBMASK), maxsize);
258 brelse(bh);
259
260 res = maxsize; /* all of it */
261
262 while (res < count) {
263 offset += maxsize;
264 dest += maxsize;
265
266 bh = sb_bread(i->i_sb, offset>>ROMBSBITS);
267 if (!bh)
268 return -1;
269 maxsize = min_t(unsigned long, count - res, ROMBSIZE);
270 memcpy(dest, bh->b_data, maxsize);
271 brelse(bh);
272 res += maxsize;
273 }
274 return res;
275}
276
277static unsigned char romfs_dtype_table[] = {
278 DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_SOCK, DT_FIFO
279};
280
281static int
282romfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
283{
284 struct inode *i = filp->f_path.dentry->d_inode;
285 struct romfs_inode ri;
286 unsigned long offset, maxoff;
287 int j, ino, nextfh;
288 int stored = 0;
289 char fsname[ROMFS_MAXFN]; /* XXX dynamic? */
290
291 lock_kernel();
292
293 maxoff = romfs_maxsize(i->i_sb);
294
295 offset = filp->f_pos;
296 if (!offset) {
297 offset = i->i_ino & ROMFH_MASK;
298 if (romfs_copyfrom(i, &ri, offset, ROMFH_SIZE) <= 0)
299 goto out;
300 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
301 }
302
303 /* Not really failsafe, but we are read-only... */
304 for(;;) {
305 if (!offset || offset >= maxoff) {
306 offset = maxoff;
307 filp->f_pos = offset;
308 goto out;
309 }
310 filp->f_pos = offset;
311
312 /* Fetch inode info */
313 if (romfs_copyfrom(i, &ri, offset, ROMFH_SIZE) <= 0)
314 goto out;
315
316 j = romfs_strnlen(i, offset+ROMFH_SIZE, sizeof(fsname)-1);
317 if (j < 0)
318 goto out;
319
320 fsname[j]=0;
321 romfs_copyfrom(i, fsname, offset+ROMFH_SIZE, j);
322
323 ino = offset;
324 nextfh = be32_to_cpu(ri.next);
325 if ((nextfh & ROMFH_TYPE) == ROMFH_HRD)
326 ino = be32_to_cpu(ri.spec);
327 if (filldir(dirent, fsname, j, offset, ino,
328 romfs_dtype_table[nextfh & ROMFH_TYPE]) < 0) {
329 goto out;
330 }
331 stored++;
332 offset = nextfh & ROMFH_MASK;
333 }
334out:
335 unlock_kernel();
336 return stored;
337}
338
339static struct dentry *
340romfs_lookup(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
341{
342 unsigned long offset, maxoff;
343 long res;
344 int fslen;
345 struct inode *inode = NULL;
346 char fsname[ROMFS_MAXFN]; /* XXX dynamic? */
347 struct romfs_inode ri;
348 const char *name; /* got from dentry */
349 int len;
350
351 res = -EACCES; /* placeholder for "no data here" */
352 offset = dir->i_ino & ROMFH_MASK;
353 lock_kernel();
354 if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0)
355 goto error;
356
357 maxoff = romfs_maxsize(dir->i_sb);
358 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
359
360 /* OK, now find the file whose name is in "dentry" in the
361 * directory specified by "dir". */
362
363 name = dentry->d_name.name;
364 len = dentry->d_name.len;
365
366 for(;;) {
367 if (!offset || offset >= maxoff)
368 goto success; /* negative success */
369 if (romfs_copyfrom(dir, &ri, offset, ROMFH_SIZE) <= 0)
370 goto error;
371
372 /* try to match the first 16 bytes of name */
373 fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, ROMFH_SIZE);
374 if (len < ROMFH_SIZE) {
375 if (len == fslen) {
376 /* both are shorter, and same size */
377 romfs_copyfrom(dir, fsname, offset+ROMFH_SIZE, len+1);
378 if (strncmp (name, fsname, len) == 0)
379 break;
380 }
381 } else if (fslen >= ROMFH_SIZE) {
382 /* both are longer; XXX optimize max size */
383 fslen = romfs_strnlen(dir, offset+ROMFH_SIZE, sizeof(fsname)-1);
384 if (len == fslen) {
385 romfs_copyfrom(dir, fsname, offset+ROMFH_SIZE, len+1);
386 if (strncmp(name, fsname, len) == 0)
387 break;
388 }
389 }
390 /* next entry */
391 offset = be32_to_cpu(ri.next) & ROMFH_MASK;
392 }
393
394 /* Hard link handling */
395 if ((be32_to_cpu(ri.next) & ROMFH_TYPE) == ROMFH_HRD)
396 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
397
398 inode = romfs_iget(dir->i_sb, offset);
399 if (IS_ERR(inode)) {
400 res = PTR_ERR(inode);
401 goto error;
402 }
403
404success:
405 d_add(dentry, inode);
406 res = 0;
407error:
408 unlock_kernel();
409 return ERR_PTR(res);
410}
411
412/*
413 * Ok, we do readpage, to be able to execute programs. Unfortunately,
414 * we can't use bmap, since we may have looser alignments.
415 */
416
417static int
418romfs_readpage(struct file *file, struct page * page)
419{
420 struct inode *inode = page->mapping->host;
421 loff_t offset, size;
422 unsigned long filled;
423 void *buf;
424 int result = -EIO;
425
426 page_cache_get(page);
427 lock_kernel();
428 buf = kmap(page);
429 if (!buf)
430 goto err_out;
431
432 /* 32 bit warning -- but not for us :) */
433 offset = page_offset(page);
434 size = i_size_read(inode);
435 filled = 0;
436 result = 0;
437 if (offset < size) {
438 unsigned long readlen;
439
440 size -= offset;
441 readlen = size > PAGE_SIZE ? PAGE_SIZE : size;
442
443 filled = romfs_copyfrom(inode, buf, ROMFS_I(inode)->i_dataoffset+offset, readlen);
444
445 if (filled != readlen) {
446 SetPageError(page);
447 filled = 0;
448 result = -EIO;
449 }
450 }
451
452 if (filled < PAGE_SIZE)
453 memset(buf + filled, 0, PAGE_SIZE-filled);
454
455 if (!result)
456 SetPageUptodate(page);
457 flush_dcache_page(page);
458
459 unlock_page(page);
460
461 kunmap(page);
462err_out:
463 page_cache_release(page);
464 unlock_kernel();
465
466 return result;
467}
468
469/* Mapping from our types to the kernel */
470
471static const struct address_space_operations romfs_aops = {
472 .readpage = romfs_readpage
473};
474
475static const struct file_operations romfs_dir_operations = {
476 .read = generic_read_dir,
477 .readdir = romfs_readdir,
478};
479
480static const struct inode_operations romfs_dir_inode_operations = {
481 .lookup = romfs_lookup,
482};
483
484static mode_t romfs_modemap[] =
485{
486 0, S_IFDIR+0644, S_IFREG+0644, S_IFLNK+0777,
487 S_IFBLK+0600, S_IFCHR+0600, S_IFSOCK+0644, S_IFIFO+0644
488};
489
490static struct inode *
491romfs_iget(struct super_block *sb, unsigned long ino)
492{
493 int nextfh, ret;
494 struct romfs_inode ri;
495 struct inode *i;
496
497 ino &= ROMFH_MASK;
498 i = iget_locked(sb, ino);
499 if (!i)
500 return ERR_PTR(-ENOMEM);
501 if (!(i->i_state & I_NEW))
502 return i;
503
504 i->i_mode = 0;
505
506 /* Loop for finding the real hard link */
507 for(;;) {
508 if (romfs_copyfrom(i, &ri, ino, ROMFH_SIZE) <= 0) {
509 printk(KERN_ERR "romfs: read error for inode 0x%lx\n",
510 ino);
511 iget_failed(i);
512 return ERR_PTR(-EIO);
513 }
514 /* XXX: do romfs_checksum here too (with name) */
515
516 nextfh = be32_to_cpu(ri.next);
517 if ((nextfh & ROMFH_TYPE) != ROMFH_HRD)
518 break;
519
520 ino = be32_to_cpu(ri.spec) & ROMFH_MASK;
521 }
522
523 i->i_nlink = 1; /* Hard to decide.. */
524 i->i_size = be32_to_cpu(ri.size);
525 i->i_mtime.tv_sec = i->i_atime.tv_sec = i->i_ctime.tv_sec = 0;
526 i->i_mtime.tv_nsec = i->i_atime.tv_nsec = i->i_ctime.tv_nsec = 0;
527
528 /* Precalculate the data offset */
529 ret = romfs_strnlen(i, ino + ROMFH_SIZE, ROMFS_MAXFN);
530 if (ret >= 0)
531 ino = (ROMFH_SIZE + ret + 1 + ROMFH_PAD) & ROMFH_MASK;
532 else
533 ino = 0;
534
535 ROMFS_I(i)->i_metasize = ino;
536 ROMFS_I(i)->i_dataoffset = ino+(i->i_ino&ROMFH_MASK);
537
538 /* Compute permissions */
539 ino = romfs_modemap[nextfh & ROMFH_TYPE];
540 /* only "normal" files have ops */
541 switch (nextfh & ROMFH_TYPE) {
542 case 1:
543 i->i_size = ROMFS_I(i)->i_metasize;
544 i->i_op = &romfs_dir_inode_operations;
545 i->i_fop = &romfs_dir_operations;
546 if (nextfh & ROMFH_EXEC)
547 ino |= S_IXUGO;
548 i->i_mode = ino;
549 break;
550 case 2:
551 i->i_fop = &generic_ro_fops;
552 i->i_data.a_ops = &romfs_aops;
553 if (nextfh & ROMFH_EXEC)
554 ino |= S_IXUGO;
555 i->i_mode = ino;
556 break;
557 case 3:
558 i->i_op = &page_symlink_inode_operations;
559 i->i_data.a_ops = &romfs_aops;
560 i->i_mode = ino | S_IRWXUGO;
561 break;
562 default:
563 /* depending on MBZ for sock/fifos */
564 nextfh = be32_to_cpu(ri.spec);
565 init_special_inode(i, ino,
566 MKDEV(nextfh>>16,nextfh&0xffff));
567 }
568 unlock_new_inode(i);
569 return i;
570}
571
572static struct kmem_cache * romfs_inode_cachep;
573
574static struct inode *romfs_alloc_inode(struct super_block *sb)
575{
576 struct romfs_inode_info *ei;
577 ei = kmem_cache_alloc(romfs_inode_cachep, GFP_KERNEL);
578 if (!ei)
579 return NULL;
580 return &ei->vfs_inode;
581}
582
583static void romfs_destroy_inode(struct inode *inode)
584{
585 kmem_cache_free(romfs_inode_cachep, ROMFS_I(inode));
586}
587
588static void init_once(void *foo)
589{
590 struct romfs_inode_info *ei = foo;
591
592 inode_init_once(&ei->vfs_inode);
593}
594
595static int init_inodecache(void)
596{
597 romfs_inode_cachep = kmem_cache_create("romfs_inode_cache",
598 sizeof(struct romfs_inode_info),
599 0, (SLAB_RECLAIM_ACCOUNT|
600 SLAB_MEM_SPREAD),
601 init_once);
602 if (romfs_inode_cachep == NULL)
603 return -ENOMEM;
604 return 0;
605}
606
607static void destroy_inodecache(void)
608{
609 kmem_cache_destroy(romfs_inode_cachep);
610}
611
612static int romfs_remount(struct super_block *sb, int *flags, char *data)
613{
614 *flags |= MS_RDONLY;
615 return 0;
616}
617
618static const struct super_operations romfs_ops = {
619 .alloc_inode = romfs_alloc_inode,
620 .destroy_inode = romfs_destroy_inode,
621 .statfs = romfs_statfs,
622 .remount_fs = romfs_remount,
623};
624
625static int romfs_get_sb(struct file_system_type *fs_type,
626 int flags, const char *dev_name, void *data, struct vfsmount *mnt)
627{
628 return get_sb_bdev(fs_type, flags, dev_name, data, romfs_fill_super,
629 mnt);
630}
631
632static struct file_system_type romfs_fs_type = {
633 .owner = THIS_MODULE,
634 .name = "romfs",
635 .get_sb = romfs_get_sb,
636 .kill_sb = kill_block_super,
637 .fs_flags = FS_REQUIRES_DEV,
638};
639
640static int __init init_romfs_fs(void)
641{
642 int err = init_inodecache();
643 if (err)
644 goto out1;
645 err = register_filesystem(&romfs_fs_type);
646 if (err)
647 goto out;
648 return 0;
649out:
650 destroy_inodecache();
651out1:
652 return err;
653}
654
655static void __exit exit_romfs_fs(void)
656{
657 unregister_filesystem(&romfs_fs_type);
658 destroy_inodecache();
659}
660
661/* Yes, works even as a module... :) */
662
663module_init(init_romfs_fs)
664module_exit(exit_romfs_fs)
665MODULE_LICENSE("GPL");
diff --git a/fs/romfs/internal.h b/fs/romfs/internal.h
new file mode 100644
index 000000000000..06044a9dc62d
--- /dev/null
+++ b/fs/romfs/internal.h
@@ -0,0 +1,47 @@
1/* RomFS internal definitions
2 *
3 * Copyright © 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/romfs_fs.h>
13
14struct romfs_inode_info {
15 struct inode vfs_inode;
16 unsigned long i_metasize; /* size of non-data area */
17 unsigned long i_dataoffset; /* from the start of fs */
18};
19
20static inline size_t romfs_maxsize(struct super_block *sb)
21{
22 return (size_t) (unsigned long) sb->s_fs_info;
23}
24
25static inline struct romfs_inode_info *ROMFS_I(struct inode *inode)
26{
27 return container_of(inode, struct romfs_inode_info, vfs_inode);
28}
29
30/*
31 * mmap-nommu.c
32 */
33#if !defined(CONFIG_MMU) && defined(CONFIG_ROMFS_ON_MTD)
34extern const struct file_operations romfs_ro_fops;
35#else
36#define romfs_ro_fops generic_ro_fops
37#endif
38
39/*
40 * storage.c
41 */
42extern int romfs_dev_read(struct super_block *sb, unsigned long pos,
43 void *buf, size_t buflen);
44extern ssize_t romfs_dev_strnlen(struct super_block *sb,
45 unsigned long pos, size_t maxlen);
46extern int romfs_dev_strncmp(struct super_block *sb, unsigned long pos,
47 const char *str, size_t size);
diff --git a/fs/romfs/mmap-nommu.c b/fs/romfs/mmap-nommu.c
new file mode 100644
index 000000000000..f0511e816967
--- /dev/null
+++ b/fs/romfs/mmap-nommu.c
@@ -0,0 +1,75 @@
1/* NOMMU mmap support for RomFS on MTD devices
2 *
3 * Copyright © 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/mm.h>
13#include <linux/mtd/super.h>
14#include "internal.h"
15
16/*
17 * try to determine where a shared mapping can be made
18 * - only supported for NOMMU at the moment (MMU can't doesn't copy private
19 * mappings)
20 * - attempts to map through to the underlying MTD device
21 */
22static unsigned long romfs_get_unmapped_area(struct file *file,
23 unsigned long addr,
24 unsigned long len,
25 unsigned long pgoff,
26 unsigned long flags)
27{
28 struct inode *inode = file->f_mapping->host;
29 struct mtd_info *mtd = inode->i_sb->s_mtd;
30 unsigned long isize, offset;
31
32 if (!mtd)
33 goto cant_map_directly;
34
35 isize = i_size_read(inode);
36 offset = pgoff << PAGE_SHIFT;
37 if (offset > isize || len > isize || offset > isize - len)
38 return (unsigned long) -EINVAL;
39
40 /* we need to call down to the MTD layer to do the actual mapping */
41 if (mtd->get_unmapped_area) {
42 if (addr != 0)
43 return (unsigned long) -EINVAL;
44
45 if (len > mtd->size || pgoff >= (mtd->size >> PAGE_SHIFT))
46 return (unsigned long) -EINVAL;
47
48 offset += ROMFS_I(inode)->i_dataoffset;
49 if (offset > mtd->size - len)
50 return (unsigned long) -EINVAL;
51
52 return mtd->get_unmapped_area(mtd, len, offset, flags);
53 }
54
55cant_map_directly:
56 return (unsigned long) -ENOSYS;
57}
58
59/*
60 * permit a R/O mapping to be made directly through onto an MTD device if
61 * possible
62 */
63static int romfs_mmap(struct file *file, struct vm_area_struct *vma)
64{
65 return vma->vm_flags & (VM_SHARED | VM_MAYSHARE) ? 0 : -ENOSYS;
66}
67
68const struct file_operations romfs_ro_fops = {
69 .llseek = generic_file_llseek,
70 .read = do_sync_read,
71 .aio_read = generic_file_aio_read,
72 .splice_read = generic_file_splice_read,
73 .mmap = romfs_mmap,
74 .get_unmapped_area = romfs_get_unmapped_area,
75};
diff --git a/fs/romfs/storage.c b/fs/romfs/storage.c
new file mode 100644
index 000000000000..7e3e1e12a081
--- /dev/null
+++ b/fs/romfs/storage.c
@@ -0,0 +1,261 @@
1/* RomFS storage access routines
2 *
3 * Copyright © 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version
9 * 2 of the License, or (at your option) any later version.
10 */
11
12#include <linux/fs.h>
13#include <linux/mtd/super.h>
14#include <linux/buffer_head.h>
15#include "internal.h"
16
17#if !defined(CONFIG_ROMFS_ON_MTD) && !defined(CONFIG_ROMFS_ON_BLOCK)
18#error no ROMFS backing store interface configured
19#endif
20
21#ifdef CONFIG_ROMFS_ON_MTD
22#define ROMFS_MTD_READ(sb, ...) ((sb)->s_mtd->read((sb)->s_mtd, ##__VA_ARGS__))
23
24/*
25 * read data from an romfs image on an MTD device
26 */
27static int romfs_mtd_read(struct super_block *sb, unsigned long pos,
28 void *buf, size_t buflen)
29{
30 size_t rlen;
31 int ret;
32
33 ret = ROMFS_MTD_READ(sb, pos, buflen, &rlen, buf);
34 return (ret < 0 || rlen != buflen) ? -EIO : 0;
35}
36
37/*
38 * determine the length of a string in a romfs image on an MTD device
39 */
40static ssize_t romfs_mtd_strnlen(struct super_block *sb,
41 unsigned long pos, size_t maxlen)
42{
43 ssize_t n = 0;
44 size_t segment;
45 u_char buf[16], *p;
46 size_t len;
47 int ret;
48
49 /* scan the string up to 16 bytes at a time */
50 while (maxlen > 0) {
51 segment = min_t(size_t, maxlen, 16);
52 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
53 if (ret < 0)
54 return ret;
55 p = memchr(buf, 0, len);
56 if (p)
57 return n + (p - buf);
58 maxlen -= len;
59 pos += len;
60 n += len;
61 }
62
63 return n;
64}
65
66/*
67 * compare a string to one in a romfs image on MTD
68 * - return 1 if matched, 0 if differ, -ve if error
69 */
70static int romfs_mtd_strncmp(struct super_block *sb, unsigned long pos,
71 const char *str, size_t size)
72{
73 u_char buf[16];
74 size_t len, segment;
75 int ret;
76
77 /* scan the string up to 16 bytes at a time */
78 while (size > 0) {
79 segment = min_t(size_t, size, 16);
80 ret = ROMFS_MTD_READ(sb, pos, segment, &len, buf);
81 if (ret < 0)
82 return ret;
83 if (memcmp(buf, str, len) != 0)
84 return 0;
85 size -= len;
86 pos += len;
87 str += len;
88 }
89
90 return 1;
91}
92#endif /* CONFIG_ROMFS_ON_MTD */
93
94#ifdef CONFIG_ROMFS_ON_BLOCK
95/*
96 * read data from an romfs image on a block device
97 */
98static int romfs_blk_read(struct super_block *sb, unsigned long pos,
99 void *buf, size_t buflen)
100{
101 struct buffer_head *bh;
102 unsigned long offset;
103 size_t segment;
104
105 /* copy the string up to blocksize bytes at a time */
106 while (buflen > 0) {
107 offset = pos & (ROMBSIZE - 1);
108 segment = min_t(size_t, buflen, ROMBSIZE - offset);
109 bh = sb_bread(sb, pos >> ROMBSBITS);
110 if (!bh)
111 return -EIO;
112 memcpy(buf, bh->b_data + offset, segment);
113 brelse(bh);
114 buflen -= segment;
115 pos += segment;
116 }
117
118 return 0;
119}
120
121/*
122 * determine the length of a string in romfs on a block device
123 */
124static ssize_t romfs_blk_strnlen(struct super_block *sb,
125 unsigned long pos, size_t limit)
126{
127 struct buffer_head *bh;
128 unsigned long offset;
129 ssize_t n = 0;
130 size_t segment;
131 u_char *buf, *p;
132
133 /* scan the string up to blocksize bytes at a time */
134 while (limit > 0) {
135 offset = pos & (ROMBSIZE - 1);
136 segment = min_t(size_t, limit, ROMBSIZE - offset);
137 bh = sb_bread(sb, pos >> ROMBSBITS);
138 if (!bh)
139 return -EIO;
140 buf = bh->b_data + offset;
141 p = memchr(buf, 0, segment);
142 brelse(bh);
143 if (p)
144 return n + (p - buf);
145 limit -= segment;
146 pos += segment;
147 n += segment;
148 }
149
150 return n;
151}
152
153/*
154 * compare a string to one in a romfs image on a block device
155 * - return 1 if matched, 0 if differ, -ve if error
156 */
157static int romfs_blk_strncmp(struct super_block *sb, unsigned long pos,
158 const char *str, size_t size)
159{
160 struct buffer_head *bh;
161 unsigned long offset;
162 size_t segment;
163 bool x;
164
165 /* scan the string up to 16 bytes at a time */
166 while (size > 0) {
167 offset = pos & (ROMBSIZE - 1);
168 segment = min_t(size_t, size, ROMBSIZE - offset);
169 bh = sb_bread(sb, pos >> ROMBSBITS);
170 if (!bh)
171 return -EIO;
172 x = (memcmp(bh->b_data + offset, str, segment) != 0);
173 brelse(bh);
174 if (x)
175 return 0;
176 size -= segment;
177 pos += segment;
178 str += segment;
179 }
180
181 return 1;
182}
183#endif /* CONFIG_ROMFS_ON_BLOCK */
184
185/*
186 * read data from the romfs image
187 */
188int romfs_dev_read(struct super_block *sb, unsigned long pos,
189 void *buf, size_t buflen)
190{
191 size_t limit;
192
193 limit = romfs_maxsize(sb);
194 if (pos >= limit)
195 return -EIO;
196 if (buflen > limit - pos)
197 buflen = limit - pos;
198
199#ifdef CONFIG_ROMFS_ON_MTD
200 if (sb->s_mtd)
201 return romfs_mtd_read(sb, pos, buf, buflen);
202#endif
203#ifdef CONFIG_ROMFS_ON_BLOCK
204 if (sb->s_bdev)
205 return romfs_blk_read(sb, pos, buf, buflen);
206#endif
207 return -EIO;
208}
209
210/*
211 * determine the length of a string in romfs
212 */
213ssize_t romfs_dev_strnlen(struct super_block *sb,
214 unsigned long pos, size_t maxlen)
215{
216 size_t limit;
217
218 limit = romfs_maxsize(sb);
219 if (pos >= limit)
220 return -EIO;
221 if (maxlen > limit - pos)
222 maxlen = limit - pos;
223
224#ifdef CONFIG_ROMFS_ON_MTD
225 if (sb->s_mtd)
226 return romfs_mtd_strnlen(sb, pos, limit);
227#endif
228#ifdef CONFIG_ROMFS_ON_BLOCK
229 if (sb->s_bdev)
230 return romfs_blk_strnlen(sb, pos, limit);
231#endif
232 return -EIO;
233}
234
235/*
236 * compare a string to one in romfs
237 * - return 1 if matched, 0 if differ, -ve if error
238 */
239int romfs_dev_strncmp(struct super_block *sb, unsigned long pos,
240 const char *str, size_t size)
241{
242 size_t limit;
243
244 limit = romfs_maxsize(sb);
245 if (pos >= limit)
246 return -EIO;
247 if (size > ROMFS_MAXFN)
248 return -ENAMETOOLONG;
249 if (size > limit - pos)
250 return -EIO;
251
252#ifdef CONFIG_ROMFS_ON_MTD
253 if (sb->s_mtd)
254 return romfs_mtd_strncmp(sb, pos, str, size);
255#endif
256#ifdef CONFIG_ROMFS_ON_BLOCK
257 if (sb->s_bdev)
258 return romfs_blk_strncmp(sb, pos, str, size);
259#endif
260 return -EIO;
261}
diff --git a/fs/romfs/super.c b/fs/romfs/super.c
new file mode 100644
index 000000000000..1e548a4975ba
--- /dev/null
+++ b/fs/romfs/super.c
@@ -0,0 +1,648 @@
1/* Block- or MTD-based romfs
2 *
3 * Copyright © 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
5 *
6 * Derived from: ROMFS file system, Linux implementation
7 *
8 * Copyright © 1997-1999 Janos Farkas <chexum@shadow.banki.hu>
9 *
10 * Using parts of the minix filesystem
11 * Copyright © 1991, 1992 Linus Torvalds
12 *
13 * and parts of the affs filesystem additionally
14 * Copyright © 1993 Ray Burr
15 * Copyright © 1996 Hans-Joachim Widmaier
16 *
17 * Changes
18 * Changed for 2.1.19 modules
19 * Jan 1997 Initial release
20 * Jun 1997 2.1.43+ changes
21 * Proper page locking in readpage
22 * Changed to work with 2.1.45+ fs
23 * Jul 1997 Fixed follow_link
24 * 2.1.47
25 * lookup shouldn't return -ENOENT
26 * from Horst von Brand:
27 * fail on wrong checksum
28 * double unlock_super was possible
29 * correct namelen for statfs
30 * spotted by Bill Hawes:
31 * readlink shouldn't iput()
32 * Jun 1998 2.1.106 from Avery Pennarun: glibc scandir()
33 * exposed a problem in readdir
34 * 2.1.107 code-freeze spellchecker run
35 * Aug 1998 2.1.118+ VFS changes
36 * Sep 1998 2.1.122 another VFS change (follow_link)
37 * Apr 1999 2.2.7 no more EBADF checking in
38 * lookup/readdir, use ERR_PTR
39 * Jun 1999 2.3.6 d_alloc_root use changed
40 * 2.3.9 clean up usage of ENOENT/negative
41 * dentries in lookup
42 * clean up page flags setting
43 * (error, uptodate, locking) in
44 * in readpage
45 * use init_special_inode for
46 * fifos/sockets (and streamline) in
47 * read_inode, fix _ops table order
48 * Aug 1999 2.3.16 __initfunc() => __init change
49 * Oct 1999 2.3.24 page->owner hack obsoleted
50 * Nov 1999 2.3.27 2.3.25+ page->offset => index change
51 *
52 *
53 * This program is free software; you can redistribute it and/or
54 * modify it under the terms of the GNU General Public Licence
55 * as published by the Free Software Foundation; either version
56 * 2 of the Licence, or (at your option) any later version.
57 */
58
59#include <linux/module.h>
60#include <linux/string.h>
61#include <linux/fs.h>
62#include <linux/time.h>
63#include <linux/slab.h>
64#include <linux/init.h>
65#include <linux/blkdev.h>
66#include <linux/parser.h>
67#include <linux/mount.h>
68#include <linux/namei.h>
69#include <linux/statfs.h>
70#include <linux/mtd/super.h>
71#include <linux/ctype.h>
72#include <linux/highmem.h>
73#include <linux/pagemap.h>
74#include <linux/uaccess.h>
75#include "internal.h"
76
77static struct kmem_cache *romfs_inode_cachep;
78
79static const umode_t romfs_modemap[8] = {
80 0, /* hard link */
81 S_IFDIR | 0644, /* directory */
82 S_IFREG | 0644, /* regular file */
83 S_IFLNK | 0777, /* symlink */
84 S_IFBLK | 0600, /* blockdev */
85 S_IFCHR | 0600, /* chardev */
86 S_IFSOCK | 0644, /* socket */
87 S_IFIFO | 0644 /* FIFO */
88};
89
90static const unsigned char romfs_dtype_table[] = {
91 DT_UNKNOWN, DT_DIR, DT_REG, DT_LNK, DT_BLK, DT_CHR, DT_SOCK, DT_FIFO
92};
93
94static struct inode *romfs_iget(struct super_block *sb, unsigned long pos);
95
96/*
97 * read a page worth of data from the image
98 */
99static int romfs_readpage(struct file *file, struct page *page)
100{
101 struct inode *inode = page->mapping->host;
102 loff_t offset, size;
103 unsigned long fillsize, pos;
104 void *buf;
105 int ret;
106
107 buf = kmap(page);
108 if (!buf)
109 return -ENOMEM;
110
111 /* 32 bit warning -- but not for us :) */
112 offset = page_offset(page);
113 size = i_size_read(inode);
114 fillsize = 0;
115 ret = 0;
116 if (offset < size) {
117 size -= offset;
118 fillsize = size > PAGE_SIZE ? PAGE_SIZE : size;
119
120 pos = ROMFS_I(inode)->i_dataoffset + offset;
121
122 ret = romfs_dev_read(inode->i_sb, pos, buf, fillsize);
123 if (ret < 0) {
124 SetPageError(page);
125 fillsize = 0;
126 ret = -EIO;
127 }
128 }
129
130 if (fillsize < PAGE_SIZE)
131 memset(buf + fillsize, 0, PAGE_SIZE - fillsize);
132 if (ret == 0)
133 SetPageUptodate(page);
134
135 flush_dcache_page(page);
136 kunmap(page);
137 unlock_page(page);
138 return ret;
139}
140
141static const struct address_space_operations romfs_aops = {
142 .readpage = romfs_readpage
143};
144
145/*
146 * read the entries from a directory
147 */
148static int romfs_readdir(struct file *filp, void *dirent, filldir_t filldir)
149{
150 struct inode *i = filp->f_dentry->d_inode;
151 struct romfs_inode ri;
152 unsigned long offset, maxoff;
153 int j, ino, nextfh;
154 int stored = 0;
155 char fsname[ROMFS_MAXFN]; /* XXX dynamic? */
156 int ret;
157
158 maxoff = romfs_maxsize(i->i_sb);
159
160 offset = filp->f_pos;
161 if (!offset) {
162 offset = i->i_ino & ROMFH_MASK;
163 ret = romfs_dev_read(i->i_sb, offset, &ri, ROMFH_SIZE);
164 if (ret < 0)
165 goto out;
166 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
167 }
168
169 /* Not really failsafe, but we are read-only... */
170 for (;;) {
171 if (!offset || offset >= maxoff) {
172 offset = maxoff;
173 filp->f_pos = offset;
174 goto out;
175 }
176 filp->f_pos = offset;
177
178 /* Fetch inode info */
179 ret = romfs_dev_read(i->i_sb, offset, &ri, ROMFH_SIZE);
180 if (ret < 0)
181 goto out;
182
183 j = romfs_dev_strnlen(i->i_sb, offset + ROMFH_SIZE,
184 sizeof(fsname) - 1);
185 if (j < 0)
186 goto out;
187
188 ret = romfs_dev_read(i->i_sb, offset + ROMFH_SIZE, fsname, j);
189 if (ret < 0)
190 goto out;
191 fsname[j] = '\0';
192
193 ino = offset;
194 nextfh = be32_to_cpu(ri.next);
195 if ((nextfh & ROMFH_TYPE) == ROMFH_HRD)
196 ino = be32_to_cpu(ri.spec);
197 if (filldir(dirent, fsname, j, offset, ino,
198 romfs_dtype_table[nextfh & ROMFH_TYPE]) < 0)
199 goto out;
200
201 stored++;
202 offset = nextfh & ROMFH_MASK;
203 }
204
205out:
206 return stored;
207}
208
209/*
210 * look up an entry in a directory
211 */
212static struct dentry *romfs_lookup(struct inode *dir, struct dentry *dentry,
213 struct nameidata *nd)
214{
215 unsigned long offset, maxoff;
216 struct inode *inode;
217 struct romfs_inode ri;
218 const char *name; /* got from dentry */
219 int len, ret;
220
221 offset = dir->i_ino & ROMFH_MASK;
222 ret = romfs_dev_read(dir->i_sb, offset, &ri, ROMFH_SIZE);
223 if (ret < 0)
224 goto error;
225
226 /* search all the file entries in the list starting from the one
227 * pointed to by the directory's special data */
228 maxoff = romfs_maxsize(dir->i_sb);
229 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
230
231 name = dentry->d_name.name;
232 len = dentry->d_name.len;
233
234 for (;;) {
235 if (!offset || offset >= maxoff)
236 goto out0;
237
238 ret = romfs_dev_read(dir->i_sb, offset, &ri, sizeof(ri));
239 if (ret < 0)
240 goto error;
241
242 /* try to match the first 16 bytes of name */
243 ret = romfs_dev_strncmp(dir->i_sb, offset + ROMFH_SIZE, name,
244 len);
245 if (ret < 0)
246 goto error;
247 if (ret == 1)
248 break;
249
250 /* next entry */
251 offset = be32_to_cpu(ri.next) & ROMFH_MASK;
252 }
253
254 /* Hard link handling */
255 if ((be32_to_cpu(ri.next) & ROMFH_TYPE) == ROMFH_HRD)
256 offset = be32_to_cpu(ri.spec) & ROMFH_MASK;
257
258 inode = romfs_iget(dir->i_sb, offset);
259 if (IS_ERR(inode)) {
260 ret = PTR_ERR(inode);
261 goto error;
262 }
263 goto outi;
264
265 /*
266 * it's a bit funky, _lookup needs to return an error code
267 * (negative) or a NULL, both as a dentry. ENOENT should not
268 * be returned, instead we need to create a negative dentry by
269 * d_add(dentry, NULL); and return 0 as no error.
270 * (Although as I see, it only matters on writable file
271 * systems).
272 */
273out0:
274 inode = NULL;
275outi:
276 d_add(dentry, inode);
277 ret = 0;
278error:
279 return ERR_PTR(ret);
280}
281
282static const struct file_operations romfs_dir_operations = {
283 .read = generic_read_dir,
284 .readdir = romfs_readdir,
285};
286
287static struct inode_operations romfs_dir_inode_operations = {
288 .lookup = romfs_lookup,
289};
290
291/*
292 * get a romfs inode based on its position in the image (which doubles as the
293 * inode number)
294 */
295static struct inode *romfs_iget(struct super_block *sb, unsigned long pos)
296{
297 struct romfs_inode_info *inode;
298 struct romfs_inode ri;
299 struct inode *i;
300 unsigned long nlen;
301 unsigned nextfh, ret;
302 umode_t mode;
303
304 /* we might have to traverse a chain of "hard link" file entries to get
305 * to the actual file */
306 for (;;) {
307 ret = romfs_dev_read(sb, pos, &ri, sizeof(ri));
308 if (ret < 0)
309 goto error;
310
311 /* XXX: do romfs_checksum here too (with name) */
312
313 nextfh = be32_to_cpu(ri.next);
314 if ((nextfh & ROMFH_TYPE) != ROMFH_HRD)
315 break;
316
317 pos = be32_to_cpu(ri.spec) & ROMFH_MASK;
318 }
319
320 /* determine the length of the filename */
321 nlen = romfs_dev_strnlen(sb, pos + ROMFH_SIZE, ROMFS_MAXFN);
322 if (IS_ERR_VALUE(nlen))
323 goto eio;
324
325 /* get an inode for this image position */
326 i = iget_locked(sb, pos);
327 if (!i)
328 return ERR_PTR(-ENOMEM);
329
330 if (!(i->i_state & I_NEW))
331 return i;
332
333 /* precalculate the data offset */
334 inode = ROMFS_I(i);
335 inode->i_metasize = (ROMFH_SIZE + nlen + 1 + ROMFH_PAD) & ROMFH_MASK;
336 inode->i_dataoffset = pos + inode->i_metasize;
337
338 i->i_nlink = 1; /* Hard to decide.. */
339 i->i_size = be32_to_cpu(ri.size);
340 i->i_mtime.tv_sec = i->i_atime.tv_sec = i->i_ctime.tv_sec = 0;
341 i->i_mtime.tv_nsec = i->i_atime.tv_nsec = i->i_ctime.tv_nsec = 0;
342
343 /* set up mode and ops */
344 mode = romfs_modemap[nextfh & ROMFH_TYPE];
345
346 switch (nextfh & ROMFH_TYPE) {
347 case ROMFH_DIR:
348 i->i_size = ROMFS_I(i)->i_metasize;
349 i->i_op = &romfs_dir_inode_operations;
350 i->i_fop = &romfs_dir_operations;
351 if (nextfh & ROMFH_EXEC)
352 mode |= S_IXUGO;
353 break;
354 case ROMFH_REG:
355 i->i_fop = &romfs_ro_fops;
356 i->i_data.a_ops = &romfs_aops;
357 if (i->i_sb->s_mtd)
358 i->i_data.backing_dev_info =
359 i->i_sb->s_mtd->backing_dev_info;
360 if (nextfh & ROMFH_EXEC)
361 mode |= S_IXUGO;
362 break;
363 case ROMFH_SYM:
364 i->i_op = &page_symlink_inode_operations;
365 i->i_data.a_ops = &romfs_aops;
366 mode |= S_IRWXUGO;
367 break;
368 default:
369 /* depending on MBZ for sock/fifos */
370 nextfh = be32_to_cpu(ri.spec);
371 init_special_inode(i, mode, MKDEV(nextfh >> 16,
372 nextfh & 0xffff));
373 break;
374 }
375
376 i->i_mode = mode;
377
378 unlock_new_inode(i);
379 return i;
380
381eio:
382 ret = -EIO;
383error:
384 printk(KERN_ERR "ROMFS: read error for inode 0x%lx\n", pos);
385 return ERR_PTR(ret);
386}
387
388/*
389 * allocate a new inode
390 */
391static struct inode *romfs_alloc_inode(struct super_block *sb)
392{
393 struct romfs_inode_info *inode;
394 inode = kmem_cache_alloc(romfs_inode_cachep, GFP_KERNEL);
395 return inode ? &inode->vfs_inode : NULL;
396}
397
398/*
399 * return a spent inode to the slab cache
400 */
401static void romfs_destroy_inode(struct inode *inode)
402{
403 kmem_cache_free(romfs_inode_cachep, ROMFS_I(inode));
404}
405
406/*
407 * get filesystem statistics
408 */
409static int romfs_statfs(struct dentry *dentry, struct kstatfs *buf)
410{
411 buf->f_type = ROMFS_MAGIC;
412 buf->f_namelen = ROMFS_MAXFN;
413 buf->f_bsize = ROMBSIZE;
414 buf->f_bfree = buf->f_bavail = buf->f_ffree;
415 buf->f_blocks =
416 (romfs_maxsize(dentry->d_sb) + ROMBSIZE - 1) >> ROMBSBITS;
417 return 0;
418}
419
420/*
421 * remounting must involve read-only
422 */
423static int romfs_remount(struct super_block *sb, int *flags, char *data)
424{
425 *flags |= MS_RDONLY;
426 return 0;
427}
428
429static const struct super_operations romfs_super_ops = {
430 .alloc_inode = romfs_alloc_inode,
431 .destroy_inode = romfs_destroy_inode,
432 .statfs = romfs_statfs,
433 .remount_fs = romfs_remount,
434};
435
436/*
437 * checksum check on part of a romfs filesystem
438 */
439static __u32 romfs_checksum(const void *data, int size)
440{
441 const __be32 *ptr = data;
442 __u32 sum;
443
444 sum = 0;
445 size >>= 2;
446 while (size > 0) {
447 sum += be32_to_cpu(*ptr++);
448 size--;
449 }
450 return sum;
451}
452
453/*
454 * fill in the superblock
455 */
456static int romfs_fill_super(struct super_block *sb, void *data, int silent)
457{
458 struct romfs_super_block *rsb;
459 struct inode *root;
460 unsigned long pos, img_size;
461 const char *storage;
462 size_t len;
463 int ret;
464
465#ifdef CONFIG_BLOCK
466 if (!sb->s_mtd) {
467 sb_set_blocksize(sb, ROMBSIZE);
468 } else {
469 sb->s_blocksize = ROMBSIZE;
470 sb->s_blocksize_bits = blksize_bits(ROMBSIZE);
471 }
472#endif
473
474 sb->s_maxbytes = 0xFFFFFFFF;
475 sb->s_magic = ROMFS_MAGIC;
476 sb->s_flags |= MS_RDONLY | MS_NOATIME;
477 sb->s_op = &romfs_super_ops;
478
479 /* read the image superblock and check it */
480 rsb = kmalloc(512, GFP_KERNEL);
481 if (!rsb)
482 return -ENOMEM;
483
484 sb->s_fs_info = (void *) 512;
485 ret = romfs_dev_read(sb, 0, rsb, 512);
486 if (ret < 0)
487 goto error_rsb;
488
489 img_size = be32_to_cpu(rsb->size);
490
491 if (sb->s_mtd && img_size > sb->s_mtd->size)
492 goto error_rsb_inval;
493
494 sb->s_fs_info = (void *) img_size;
495
496 if (rsb->word0 != ROMSB_WORD0 || rsb->word1 != ROMSB_WORD1 ||
497 img_size < ROMFH_SIZE) {
498 if (!silent)
499 printk(KERN_WARNING "VFS:"
500 " Can't find a romfs filesystem on dev %s.\n",
501 sb->s_id);
502 goto error_rsb_inval;
503 }
504
505 if (romfs_checksum(rsb, min_t(size_t, img_size, 512))) {
506 printk(KERN_ERR "ROMFS: bad initial checksum on dev %s.\n",
507 sb->s_id);
508 goto error_rsb_inval;
509 }
510
511 storage = sb->s_mtd ? "MTD" : "the block layer";
512
513 len = strnlen(rsb->name, ROMFS_MAXFN);
514 if (!silent)
515 printk(KERN_NOTICE "ROMFS: Mounting image '%*.*s' through %s\n",
516 (unsigned) len, (unsigned) len, rsb->name, storage);
517
518 kfree(rsb);
519 rsb = NULL;
520
521 /* find the root directory */
522 pos = (ROMFH_SIZE + len + 1 + ROMFH_PAD) & ROMFH_MASK;
523
524 root = romfs_iget(sb, pos);
525 if (!root)
526 goto error;
527
528 sb->s_root = d_alloc_root(root);
529 if (!sb->s_root)
530 goto error_i;
531
532 return 0;
533
534error_i:
535 iput(root);
536error:
537 return -EINVAL;
538error_rsb_inval:
539 ret = -EINVAL;
540error_rsb:
541 return ret;
542}
543
544/*
545 * get a superblock for mounting
546 */
547static int romfs_get_sb(struct file_system_type *fs_type,
548 int flags, const char *dev_name,
549 void *data, struct vfsmount *mnt)
550{
551 int ret = -EINVAL;
552
553#ifdef CONFIG_ROMFS_ON_MTD
554 ret = get_sb_mtd(fs_type, flags, dev_name, data, romfs_fill_super,
555 mnt);
556#endif
557#ifdef CONFIG_ROMFS_ON_BLOCK
558 if (ret == -EINVAL)
559 ret = get_sb_bdev(fs_type, flags, dev_name, data,
560 romfs_fill_super, mnt);
561#endif
562 return ret;
563}
564
565/*
566 * destroy a romfs superblock in the appropriate manner
567 */
568static void romfs_kill_sb(struct super_block *sb)
569{
570#ifdef CONFIG_ROMFS_ON_MTD
571 if (sb->s_mtd) {
572 kill_mtd_super(sb);
573 return;
574 }
575#endif
576#ifdef CONFIG_ROMFS_ON_BLOCK
577 if (sb->s_bdev) {
578 kill_block_super(sb);
579 return;
580 }
581#endif
582}
583
584static struct file_system_type romfs_fs_type = {
585 .owner = THIS_MODULE,
586 .name = "romfs",
587 .get_sb = romfs_get_sb,
588 .kill_sb = romfs_kill_sb,
589 .fs_flags = FS_REQUIRES_DEV,
590};
591
592/*
593 * inode storage initialiser
594 */
595static void romfs_i_init_once(void *_inode)
596{
597 struct romfs_inode_info *inode = _inode;
598
599 inode_init_once(&inode->vfs_inode);
600}
601
602/*
603 * romfs module initialisation
604 */
605static int __init init_romfs_fs(void)
606{
607 int ret;
608
609 printk(KERN_INFO "ROMFS MTD (C) 2007 Red Hat, Inc.\n");
610
611 romfs_inode_cachep =
612 kmem_cache_create("romfs_i",
613 sizeof(struct romfs_inode_info), 0,
614 SLAB_RECLAIM_ACCOUNT | SLAB_MEM_SPREAD,
615 romfs_i_init_once);
616
617 if (!romfs_inode_cachep) {
618 printk(KERN_ERR
619 "ROMFS error: Failed to initialise inode cache\n");
620 return -ENOMEM;
621 }
622 ret = register_filesystem(&romfs_fs_type);
623 if (ret) {
624 printk(KERN_ERR "ROMFS error: Failed to register filesystem\n");
625 goto error_register;
626 }
627 return 0;
628
629error_register:
630 kmem_cache_destroy(romfs_inode_cachep);
631 return ret;
632}
633
634/*
635 * romfs module removal
636 */
637static void __exit exit_romfs_fs(void)
638{
639 unregister_filesystem(&romfs_fs_type);
640 kmem_cache_destroy(romfs_inode_cachep);
641}
642
643module_init(init_romfs_fs);
644module_exit(exit_romfs_fs);
645
646MODULE_DESCRIPTION("Direct-MTD Capable RomFS");
647MODULE_AUTHOR("Red Hat, Inc.");
648MODULE_LICENSE("GPL"); /* Actually dual-licensed, but it doesn't matter for */
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index 3aa5d77c2cdb..5675b63a0631 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/uio.h> 12#include <linux/uio.h>
13#include <linux/notifier.h> 13#include <linux/notifier.h>
14#include <linux/device.h>
14 15
15#include <linux/mtd/compatmac.h> 16#include <linux/mtd/compatmac.h>
16#include <mtd/mtd-abi.h> 17#include <mtd/mtd-abi.h>
@@ -162,6 +163,20 @@ struct mtd_info {
162 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */ 163 /* We probably shouldn't allow XIP if the unpoint isn't a NULL */
163 void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len); 164 void (*unpoint) (struct mtd_info *mtd, loff_t from, size_t len);
164 165
166 /* Allow NOMMU mmap() to directly map the device (if not NULL)
167 * - return the address to which the offset maps
168 * - return -ENOSYS to indicate refusal to do the mapping
169 */
170 unsigned long (*get_unmapped_area) (struct mtd_info *mtd,
171 unsigned long len,
172 unsigned long offset,
173 unsigned long flags);
174
175 /* Backing device capabilities for this device
176 * - provides mmap capabilities
177 */
178 struct backing_dev_info *backing_dev_info;
179
165 180
166 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 181 int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
167 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf); 182 int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
@@ -223,6 +238,7 @@ struct mtd_info {
223 void *priv; 238 void *priv;
224 239
225 struct module *owner; 240 struct module *owner;
241 struct device dev;
226 int usecount; 242 int usecount;
227 243
228 /* If the driver is something smart, like UBI, it may need to maintain 244 /* If the driver is something smart, like UBI, it may need to maintain
@@ -233,6 +249,11 @@ struct mtd_info {
233 void (*put_device) (struct mtd_info *mtd); 249 void (*put_device) (struct mtd_info *mtd);
234}; 250};
235 251
252static inline struct mtd_info *dev_to_mtd(struct device *dev)
253{
254 return dev ? container_of(dev, struct mtd_info, dev) : NULL;
255}
256
236static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd) 257static inline uint32_t mtd_div_by_eb(uint64_t sz, struct mtd_info *mtd)
237{ 258{
238 if (mtd->erasesize_shift) 259 if (mtd->erasesize_shift)
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index db5b63da2a7e..7efb9be34662 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -43,8 +43,8 @@ extern void nand_wait_ready(struct mtd_info *mtd);
43 * is supported now. If you add a chip with bigger oobsize/page 43 * is supported now. If you add a chip with bigger oobsize/page
44 * adjust this accordingly. 44 * adjust this accordingly.
45 */ 45 */
46#define NAND_MAX_OOBSIZE 64 46#define NAND_MAX_OOBSIZE 128
47#define NAND_MAX_PAGESIZE 2048 47#define NAND_MAX_PAGESIZE 4096
48 48
49/* 49/*
50 * Constants for hardware specific CLE/ALE/NCE function 50 * Constants for hardware specific CLE/ALE/NCE function
diff --git a/include/linux/mtd/partitions.h b/include/linux/mtd/partitions.h
index a45dd831b3f8..7535a74083b9 100644
--- a/include/linux/mtd/partitions.h
+++ b/include/linux/mtd/partitions.h
@@ -76,4 +76,16 @@ int __devinit of_mtd_parse_partitions(struct device *dev,
76 struct device_node *node, 76 struct device_node *node,
77 struct mtd_partition **pparts); 77 struct mtd_partition **pparts);
78 78
79#ifdef CONFIG_MTD_PARTITIONS
80static inline int mtd_has_partitions(void) { return 1; }
81#else
82static inline int mtd_has_partitions(void) { return 0; }
83#endif
84
85#ifdef CONFIG_MTD_CMDLINE_PARTS
86static inline int mtd_has_cmdlinepart(void) { return 1; }
87#else
88static inline int mtd_has_cmdlinepart(void) { return 0; }
89#endif
90
79#endif 91#endif