Skip to contentSkip to conversation

MTD: LPC32xx MLC NAND driver

PATCH Superseded Roland Stigge 3 participants 7 messages Jun 27, 2012 – Jun 30, 2012

Subsystems (4)

v10 of 11 Superseded Latest is v11 →

lore
Share & tools
lore
#0 lore raw

PATCH v10 1/1 MTD: LPC32xx MLC NAND driver

This patch adds a driver for the MLC NAND controller of the LPC32xx SoC.

---
Applies to l2-mtd

Changes since v9:
* Adjusted to API change in l2-mtd (write function returns int now)

Changes since v8:
* Use of_get_named_gpio() instead of of_get_named_gpio_flags()
* probe() returns -EPROBE_DEFER if wp_gpio is deferred from of_get_named_gpio()

Changes since v7:
* Cleanup: Use mtd nand default functions for single byte read and write operations
* Support more chips by removing fixed page size and calculating mlc subpages from chip data

Changes since v6:
* Kconfig: select amba dma driver
* Make wp_gpio optional by ignoring gpio if property is missing

Changes since v5:
* Renamed: lpc32xx_nand_mlc.c -> lpc32xx_mlc.c

Changes since v4:
* This patch erroneously changed Kconfig of the _other_ NAND (SLC) driver from "bool" to "tristate". Moved this fix to the actual SLC driver patch.

Changes since v3:
* Dropped superfluous error handling of dmaengine_submit()
* Added unmapping of dma sg buffers

Changes since v2:
* Adjusted to mtd API changes

Changes since v1:
* Factored out dmaengine_slave_config() to dma_setup() function in probe()
* Fixed dma data direction and dma transfer direction differences
* Removed dma_sync_sg_for_cpu() - not necessary due to unmap
* Removed dma_set_mask()

Thanks to Alexandre Pereira da Silva, Artem Bityutskiy and Russell King for reviewing, testing and improvements!

 .../devicetree/bindings/mtd/lpc32xx-mlc.txt        |   50 ++
 drivers/mtd/nand/Kconfig                           |   12 +
 drivers/mtd/nand/Makefile                          |    1 +
 drivers/mtd/nand/lpc32xx_mlc.c                     |  929 ++++++++++++++++++++
 4 files changed, 992 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/mtd/lpc32xx-mlc.txt
 create mode 100644 drivers/mtd/nand/lpc32xx_mlc.c
Documentation/devicetree/bindings/mtd/lpc32xx-mlc.txt new file +50 -0
new file mode 100644
index 0000000..d0a3725
@@ -0,0 +1,50 @@
+NXP LPC32xx SoC NAND MLC controller
+
+Required properties:
+- compatible: "nxp,lpc3220-mlc"
+- reg: Address and size of the controller
+- interrupts: The NAND interrupt specification
+- gpios: GPIO specification for NAND write protect
+
+The following required properties are very controller specific. See the LPC32xx
+User Manual 7.5.14 MLC NAND Timing Register (the values here are specified in
+Hz, to make them independent of actual clock speed and to provide for good
+accuracy:)
+- nxp,tcea_delay: TCEA_DELAY
+- nxp,busy_delay: BUSY_DELAY
+- nxp,nand_ta: NAND_TA
+- nxp,rd_high: RD_HIGH
+- nxp,rd_low: RD_LOW
+- nxp,wr_high: WR_HIGH
+- nxp,wr_low: WR_LOW
+
+Optional subnodes:
+- Partitions, see Documentation/devicetree/bindings/mtd/partition.txt
+
+Example:
+
+	mlc: flash at 200A8000 {
+		compatible = "nxp,lpc3220-mlc";
+		reg = <0x200A8000 0x11000>;
+		interrupts = <11 0>;
+		#address-cells = <1>;
+		#size-cells = <1>;
+
+		nxp,tcea-delay = <333333333>;
+		nxp,busy-delay = <10000000>;
+		nxp,nand-ta = <18181818>;
+		nxp,rd-high = <31250000>;
+		nxp,rd-low = <45454545>;
+		nxp,wr-high = <40000000>;
+		nxp,wr-low = <83333333>;
+		gpios = <&gpio 5 19 1>; /* GPO_P3 19, active low */
+
+		mtd0 at 00000000 {
+			label = "boot";
+			reg = <0x00000000 0x00064000>;
+			read-only;
+		};
+
+		...
+
+	};
drivers/mtd/nand/Kconfig +12 -0
index de69978..50bf667 100644
@@ -425,6 +425,18 @@ config MTD_NAND_SLC_LPC32XX
 	  Please check the actual NAND chip connected and its support
 	  by the SLC NAND controller.
 
+config MTD_NAND_MLC_LPC32XX
+       tristate "NXP LPC32xx MLC Controller"
+       depends on ARCH_LPC32XX
+       select AMBA_PL08X
+       help
+         Uses the LPC32XX MLC (i.e. for Multi Level Cell chips) NAND
+         controller. This is the default for the WORK92105 controller
+         board.
+
+         Please check the actual NAND chip connected and its support
+         by the MLC NAND controller.
+
 config MTD_NAND_CM_X270
 	tristate "Support for NAND Flash on CM-X270 modules"
 	depends on MACH_ARMCORE
drivers/mtd/nand/Makefile +1 -0
index d29a893..ddee818 100644
@@ -41,6 +41,7 @@ obj-$(CONFIG_MTD_NAND_FSL_ELBC)		+= fsl_elbc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_IFC)		+= fsl_ifc_nand.o
 obj-$(CONFIG_MTD_NAND_FSL_UPM)		+= fsl_upm.o
 obj-$(CONFIG_MTD_NAND_SLC_LPC32XX)      += lpc32xx_slc.o
+obj-$(CONFIG_MTD_NAND_MLC_LPC32XX)      += lpc32xx_mlc.o
 obj-$(CONFIG_MTD_NAND_SH_FLCTL)		+= sh_flctl.o
 obj-$(CONFIG_MTD_NAND_MXC)		+= mxc_nand.o
 obj-$(CONFIG_MTD_NAND_SOCRATES)		+= socrates_nand.o
drivers/mtd/nand/lpc32xx_mlc.c new file +929 -0

929 lines not on this page · raw message

Signature · 1 line
1.7.10.4
#1 lore raw
Quoted 5 lines · Roland Stigge

This patch adds a driver for the MLC NAND controller of the LPC32xx SoC.

---

Aiaiai complains like this about your patch, please, take a look:

--------------------------------------------------------------------------------

Successfully built configuration "arm-lpc32xx_defconfig,arm,arm-unknown-linux-gnueabi-", results:

after_patching.log renamed from before_patching.log +0 -0
@@ @@
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe':
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set but not used [-Wunused-but-set-variable]
+drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

--------------------------------------------------------------------------------

checkpatch.pl has some complaints:

--------------------------------------------------------------------------------

checkpatch.pl results for patch "[PATCH] MTD: LPC32xx MLC NAND driver"

ERROR:INITIALISED_STATIC: do not initialise statics to 0 or NULL #339: FILE: drivers/mtd/nand/lpc32xx_mlc.c:224:
+static int use_dma = 0;

total: 1 errors, 0 warnings, 1004 lines checked

--------------------------------------------------------------------------------

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#2 lore raw
Quoted 16 lines · Artem Bityutskiy
Quoted 5 lines · Roland Stigge

This patch adds a driver for the MLC NAND controller of the LPC32xx SoC.

---

Aiaiai complains like this about your patch, please, take a look:

--------------------------------------------------------------------------------

Successfully built configuration "arm-lpc32xx_defconfig,arm,arm-unknown-linux-gnueabi-", results:

after_patching.log renamed from before_patching.log +0 -0

@@ @@

after_patching.log

Quoted 3 lines
after_patching.log renamed from before_patching.log +3 -0
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe':
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set but not used [-Wunused-but-set-variable]
+drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

This build fine here, with gcc 4.5.3

Which gcc version is he using?

Quoted 19 lines

--------------------------------------------------------------------------------

checkpatch.pl has some complaints:

--------------------------------------------------------------------------------

checkpatch.pl results for patch "[PATCH] MTD: LPC32xx MLC NAND driver"

ERROR:INITIALISED_STATIC: do not initialise statics to 0 or NULL #339: FILE: drivers/mtd/nand/lpc32xx_mlc.c:224:
+static int use_dma = 0;

total: 1 errors, 0 warnings, 1004 lines checked

--------------------------------------------------------------------------------

--
Best Regards,
Artem Bityutskiy

#3 lore raw
Quoted 3 lines · Alexandre Pereira da Silva

Review

Quoted 3 lines

@@ @@

(quoted diff) +2 -0
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe':
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set but not used [-Wunused-but-set-variable]

gcc 4.6, aiaiai uses W=1 when building.

Quoted 1 line
Quoted 1 line

+drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

This is sparse, not gcc.

Signature · 2 lines
Best Regards,
Artem Bityutskiy
#4 lore raw
Quoted 10 lines · Artem Bityutskiy
Quoted 3 lines · Alexandre Pereira da Silva

Review

Quoted 3 lines

@@ @@

(quoted diff) +2 -0
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe':
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set but not used [-Wunused-but-set-variable]

gcc 4.6, aiaiai uses W=1 when building.

Quoted 1 line
Quoted 1 line

+drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

This is sparse, not gcc.

Does the oob area need to be ecc protected? If not I suggest to just remove the read_oob and write_oob and let this to nand_base. I think this is too much overhead to read 6 bytes.

#5 lore raw
In reply to Artem Bityutskiy

Hi Artem!

Thanks for the notes!

Quoted 9 lines · Artem Bityutskiy

Successfully built configuration "arm-lpc32xx_defconfig,arm,arm-unknown-linux-gnueabi-", results:

--- before_patching.log +++ after_patching.log @@ @@

(quoted diff) +2 -0
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe': 
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set

but not used [-Wunused-but-set-variable] +drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

This is because sparse doesn't understand this local variable:

uint8_t buf[mtd->writesize];

(but gcc does).

Are you sure we need to support sparse?

The above construction is quite convenient for this case and I'd prefer this to allocating another buffer dynamically.

Thanks in advance,

Roland

#6 lore raw
Quoted 17 lines · Roland Stigge

Hi Artem!

Thanks for the notes!

Quoted 9 lines · Artem Bityutskiy

Successfully built configuration "arm-lpc32xx_defconfig,arm,arm-unknown-linux-gnueabi-", results:

--- before_patching.log +++ after_patching.log @@ @@

(quoted diff) +2 -0
+drivers/mtd/nand/lpc32xx_mlc.c: In function 'lpc32xx_nand_probe': 
+drivers/mtd/nand/lpc32xx_mlc.c:679:10: warning: variable 'sr' set

but not used [-Wunused-but-set-variable] +drivers/mtd/nand/lpc32xx_mlc.c:561:24: error: bad constant expression [sparse]

This is because sparse doesn't understand this local variable:

Quoted 1 line

uint8_t buf[mtd->writesize];

mtd->writesize is typically 2048KiB (or even larger, there are MLCs with 4 and 8 KiB NAND page size). You cannot allocate that much on the stack, linux kernel stack size is very small - only 8KiB, and there are people who use even 4KiB stacks. So this have to be fixed.

Quoted 2 lines

The above construction is quite convenient for this case and I'd prefer this to allocating another buffer dynamically.

Yes, in userspaces it is, but unfortunately in the kernel we cannot afford allocating that much on the stack.

Signature · 9 lines
Best Regards,
Artem Bityutskiy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: This is a digitally signed message part
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20120630/af484b3c/attachment.sig>