Skip to contentSkip to conversation

MTD: generic FSMC NAND MTD driver

PATCH New Linus Walleij 6 participants 11 messages Sep 12, 2010 – Oct 24, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

---
Changes:
- Merged the local SPEAr FSMC header files into one under include/mtd (I hope this is where MTD includes should go these days?)
- Changed to look up the clock actually using the clockdevice instead of a connection string "fsmc".
- Implemented platform data for U300 (second patch).

Issues:
- The discussed problem with ecc_pos locked to 64 in the userspace contract and the enforcements of bigger ecc fields provoke build warnings. Not really sure on how to proceed with this.
- The SPEAr platform data probably needs fixing, but should be along the lines of the U300. SPEAr clkdev should be prepared I think, remember to name the platform device "fsmc-nand"
- Hardcoding partition tables and ECC layout into the driver is a bit so-so (IMO this should be in platform data only), but I don't know about the other drivers in mtd/.

---
 drivers/mtd/nand/Kconfig     |    7 +
 drivers/mtd/nand/Makefile    |    1 +
 drivers/mtd/nand/fsmc_nand.c |  862 ++++++++++++++++++++++++++++++++++++++++++
 include/mtd/fsmc.h           |  181 +++++++++
 4 files changed, 1051 insertions(+), 0 deletions(-)
 create mode 100644 drivers/mtd/nand/fsmc_nand.c
 create mode 100644 include/mtd/fsmc.h
drivers/mtd/nand/Kconfig +7 -0
index 8b4b67c..81f818a 100644
@@ -531,4 +531,11 @@ config MTD_NAND_JZ4740
 	help
 		Enables support for NAND Flash on JZ4740 SoC based boards.
 
+config MTD_NAND_FSMC
+	tristate "Support for NAND on ST Micros FSMC"
+	depends on PLAT_SPEAR || PLAT_NOMADIK || MACH_U300
+	help
+	  Enables support for NAND Flash chips on the ST Microelectronics
+	  Flexible Static Memory Controller (FSMC)
+
 endif # MTD_NAND
drivers/mtd/nand/Makefile +1 -0
index ac83dcd..8ad6fae 100644
@@ -19,6 +19,7 @@ obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB)	+= ppchameleonevb.o
 obj-$(CONFIG_MTD_NAND_S3C2410)		+= s3c2410.o
 obj-$(CONFIG_MTD_NAND_DAVINCI)		+= davinci_nand.o
 obj-$(CONFIG_MTD_NAND_DISKONCHIP)	+= diskonchip.o
+obj-$(CONFIG_MTD_NAND_FSMC)		+= fsmc_nand.o
 obj-$(CONFIG_MTD_NAND_H1900)		+= h1910.o
 obj-$(CONFIG_MTD_NAND_RTC_FROM4)	+= rtc_from4.o
 obj-$(CONFIG_MTD_NAND_SHARPSL)		+= sharpsl.o
drivers/mtd/nand/fsmc_nand.c new file +862 -0

862 lines not on this page · raw message

include/mtd/fsmc.h new file +181 -0

181 lines not on this page · raw message

Signature · 1 line
1.6.3.3
#1 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

2010/9/13 Linus Walleij <[email protected]>:

Quoted 3 lines

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

David if this one looks OK then can you merge both patches through the MTD tree?

Yours,
Linus Walleij

#2 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

Quoted 8 lines · Linus Walleij

2010/9/13 Linus Walleij <[email protected]>:

Quoted 3 lines

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

David if this one looks OK then can you merge both patches through the MTD tree?

I've pushed both patches to my l2-mtd-2.6.git / master, without signing this off myself.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (????? ????????)
#3 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

2010/9/20 Artem Bityutskiy <[email protected]>:

Quoted 7 lines · Linus Walleij
Quoted 6 lines

2010/9/13 Linus Walleij <[email protected]>:

Quoted 3 lines

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

Quoted 5 lines
Quoted 2 lines

David if this one looks OK then can you merge both patches through the MTD tree?

I've pushed both patches to my l2-mtd-2.6.git / master, without signing this off myself.

Thanks Artem, are you integrating MTD to Linus (Torvalds)?

This git is not part of linux-next right?

Yours,
Linus Walleij

#4 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

Quoted 8 lines · Linus Walleij

2010/9/20 Artem Bityutskiy <[email protected]>:

Quoted 7 lines · Linus Walleij
Quoted 6 lines

2010/9/13 Linus Walleij <[email protected]>:

Quoted 3 lines

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

Quoted 7 lines
Quoted 5 lines
Quoted 2 lines

David if this one looks OK then can you merge both patches through the MTD tree?

I've pushed both patches to my l2-mtd-2.6.git / master, without signing this off myself.

Thanks Artem, are you integrating MTD to Linus (Torvalds)?

Not me, dwmw2 should pick patches from my tree.

Quoted 1 line

This git is not part of linux-next right?

Right.

Signature · 2 lines
Best Regards,
Artem Bityutskiy (????? ????????)
#5 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

In reply to Linus Walleij
Quoted 4 lines · Linus WALLEIJ

This is the same driver submitted by ST Micros SPEAr team but generalized and tested on the ST-Ericsson U300. It probably easily works on the NHK8815 too.

<snip...>

Quoted 5 lines
---
 drivers/mtd/nand/Kconfig     |    7 +
 drivers/mtd/nand/Makefile    |    1 +
 drivers/mtd/nand/fsmc_nand.c |  862 ++++++++++++++++++++++++++++++++++++++++++
 include/mtd/fsmc.h           |  181 +++++++++

Linus,

Just one query, what should be the location of fsmc.h include/mtd/ or include/linux/mtd ??

viresh.

#6 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

Quoted 4 lines · viresh kumar

Just one query, what should be the location of fsmc.h include/mtd/ or include/linux/mtd ??

We use include/mtd/ for headers which are exported to userspace. Looks like this should be include/linux/mtd/

Signature · 1 line
dwmw2
#7 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

2010/10/1 David Woodhouse <[email protected]>:

Quoted 7 lines · viresh kumar
Quoted 3 lines

Just one query, what should be the location of fsmc.h include/mtd/ or include/linux/mtd ??

We use include/mtd/ for headers which are exported to userspace. Looks like this should be include/linux/mtd/

Aha, I'll respin it then.

Yours,
Linus Walleij

#8 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

Quoted 10 lines · Linus Walleij

2010/10/1 David Woodhouse <[email protected]>:

Quoted 7 lines · viresh kumar
Quoted 3 lines

Just one query, what should be the location of fsmc.h include/mtd/ or include/linux/mtd ??

We use include/mtd/ for headers which are exported to userspace. Looks like this should be include/linux/mtd/

Aha, I'll respin it then.

Or perhaps it shouldn't be in a header file at all. Where else does it get used from?

Signature · 1 line
dwmw2
#9 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

In reply to Linus Walleij

Hello David, Linus

Quoted 45 lines
drivers/mtd/nand/fsmc_nand.c new file +45 -0
+#include <linux/mtd/nand_ecc.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/partitions.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <mtd/fsmc.h>
+#include <mtd/mtd-abi.h>
+
+static struct nand_ecclayout fsmc_ecc1_layout = {
+       .eccbytes = 24,
+       .eccpos = {2, 3, 4, 18, 19, 20, 34, 35, 36, 50, 51, 52,
+               66, 67, 68, 82, 83, 84, 98, 99, 100, 114, 115, 116},
+       .oobfree = {
+               {.offset = 8, .length = 8},
+               {.offset = 24, .length = 8},
+               {.offset = 40, .length = 8},
+               {.offset = 56, .length = 8},
+               {.offset = 72, .length = 8},
+               {.offset = 88, .length = 8},
+               {.offset = 104, .length = 8},
+               {.offset = 120, .length = 8}
+       }
+};
+
+static struct nand_ecclayout fsmc_ecc4_lp_layout = {
+       .eccbytes = 104,
+       .eccpos = {  2,   3,   4,   5,   6,   7,   8,
+               9,  10,  11,  12,  13,  14,
+               18,  19,  20,  21,  22,  23,  24,
+               25,  26,  27,  28,  29,  30,
+               34,  35,  36,  37,  38,  39,  40,
+               41,  42,  43,  44,  45,  46,
+               50,  51,  52,  53,  54,  55,  56,
+               57,  58,  59,  60,  61,  62,
+               66,  67,  68,  69,  70,  71,  72,
+               73,  74,  75,  76,  77,  78,
+               82,  83,  84,  85,  86,  87,  88,
+               89,  90,  91,  92,  93,  94,
+               98,  99, 100, 101, 102, 103, 104,
+               105, 106, 107, 108, 109, 110,
+               114, 115, 116, 117, 118, 119, 120,
+               121, 122, 123, 124, 125, 126
+       },
+       .oobfree = {
+               {.offset = 15, .length = 3},

drivers/mtd/nand/fsmc_nand.c line 82

Quoted 10 lines
drivers/mtd/nand/fsmc_nand.c new file +10 -0
+               {.offset = 31, .length = 3},
+               {.offset = 47, .length = 3},
+               {.offset = 63, .length = 3},
+               {.offset = 79, .length = 3},
+               {.offset = 95, .length = 3},
+               {.offset = 111, .length = 3},
+               {.offset = 127, .length = 1}
+       }
+};
+

I just noticed that the above array is based on an earlier patch which increased the array size from 64 to 128.

http://lists.infradead.org/pipermail/linux-arm-kernel/2010-August/024372.html

This patch itself was under the lense of reviewers for a long time. Actually, increasing this array breaks mtd abi as pointed by Artem

Quoting from his mail

Quoted 3 lines

The old interface should remain unchanged in that include/mtd/mtd-abi.h. If an application using the old interface calls any of the ecc ioctls for a nand chip with > 64 bytes ecc it should return an error.

It will, because size of the structure is part of the ioctl number, even. See the corresponding ioctl macro definition.

Quoted 4 lines

I still think the eccpos field should be a pointer, so that it can allocate as much space as is needed for the ecc. This also means that the kernel doesn't need to be changed every time a new NAND chips appears with a bigger ecc size.

Sure, this is the whole point: go ahead and design the new ioctl, and then deprecate the old one. Just invest men/hours into that and we are all right :-)

This means that the patch sent by linus can be added only after a new ioctl is defined and the old one deprecated

include/mtd/fsmc.h line 23

Quoted 7 lines
include/mtd/fsmc.h new file +7 -0
+#define __MTD_FSMC_H
+
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/types.h>
+#include <linux/mtd/partitions.h>
+#include <asm/param.h>

Linus, there is a checkpatch warining here :)

Best Regards
Vipin

#10 lore raw

PATCH 1/2 MTD: generic FSMC NAND MTD driver

In reply to Linus Walleij

drivers/mtd/nand/fsmc_nand.c line 137

Quoted 13 lines · Linus Walleij
drivers/mtd/nand/fsmc_nand.c new file +12 -0
+#define PARTITION(n, off, sz)  {.name = n, .offset = off, .size = sz}
+
+/*
+ * Default partition layout for small page(= 512 bytes) devices
+ * Size for "Root file system" is updated in driver based on actual device size
+ */
+static struct mtd_partition partition_info_16KB_blk[] = {
+       PARTITION("X-loader", 0, 4 * 0x4000),
+       PARTITION("U-Boot", 0x10000, 20 * 0x4000),
+       PARTITION("Kernel", 0x60000, 256 * 0x4000),
+       PARTITION("Root File System", 0x460000, 0),
+}; 

Er, you use a macro just so that you can use order-dependent non-C99 structure initialisation? You realise that this would do the same thing:
#define PARTITION(a,b,c) {a,c,b}

And no, I don't think *that* would be a good idea either :)

Please fix.

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
David.Woodhouse at intel.com                              Intel Corporation