Armada 370/XP NAND support
Subsystems (6)
v4 cover Armada 370/XP NAND support
Another version of the Armada 370/XP SoCs v3 patchset, addressing all the feedback provided by Brian Norris.
Please see Documentation/mtd/nand/pxa3xx-nand.txt for specific details about the controller and the driver.
Just as the last version, the bad block factory initial detection issue is not addressed by this patchset, but support for it will be added in a near future once we decide the proper roadmap. See here the discussion about it:
http://permalink.gmane.org/gmane.linux.drivers.mtd/49401
As usual patches 1-4, adding the clock infrastructure have already been merged and will be dropped once this series can be based on v3.13-rc1. I'm including them just for completeness.
Based in l2-mtd's master branch. Also, I've pushed a branch to our github in case anyone wants to test it:
https://github.com/MISL-EBU-System-SW/mainline-public/tree/l2-mtd/upstream-nand-v4
As per Jason Cooper's suggestion I'm Ccing devicetree mailing list, to get a review on the small binding changes this patchset contains. If the devicetree people wants us to just Cc you on the relevant patches, just let us know.
Of course, there's some room for improvements in this driver, and I'll probably continue working on it. However, for now I'd like to focus in adding the strict minimum amount of changes required to support the new SoC family and pospone any improvements.
Thanks!
* Changes from v3 (feedback from Brian Norris)
* Add binding documentation for the nand-flash-bbt DT property.
* Expand in the documentation and in a comment the reason for setting the NAND_BBT_NO_OOB_BBM option.
* Reworked the 'is_ready' completion handler. We still have two completions, but we've dropped the atomic_t type as now the variable is no longer accesed from interruption context.
* Fixed the ecc.read_page() which lacked the max_bitflip return.
* Reworked the ECC strength and size setting. This is important to allow the MTD layer to properly report on bitflip threshold situation.
* Dropped an unused fifo_size state variable
* Use '0' instead of the wrong '-1' when the extended command type doesn't matter or extended semantics are not supposed to be used.
* Changes from v2 (some minor fixes as per Huang's good feedback)
* Add some more details to the commit log in patch "mtd: nand: pxa3xx: Early variant detection"
* Add an empty line between variable declaration and function body
in patch "mtd: nand: pxa3xx: Use chip->cmdfunc instead of the internal".
* Fix a build break caused by incomplete variable replacement:
"mtd: nand: pxa3xx: Replace host->page_size by mtd->writesize"
* Changes from v1
Aside from several changes based in Brian's feedback, the main changes from v1 are:
* The controller's clock source is now fully modeled, see patche 1 to 4. Of course, none of those patches should be taken through the mtd subsystem, but I'm adding them here for completeness.
* The chip's cmdfunc() is now independently implemented in each SoC variant. The rationale behind this decision is that 'chunked' I/O is the only tested mode on the Armada370 variant, while the old 'vanilla' I/O is the only tested mode on the PXA variant.
So it's safer to have an implementation for each variant.
* Added support for BCH-8, in other words: 8-bits of correction in a 512-byte region. This is obtained by using a data chunk size of 1024B, thus doubling the ECC BCH strength, as per this ECC engine mechanism.
* The ECC layout in use, which must be set according to the page size and desired ECC strength is now strictly chosen to match only the tested combinations.
Ezequiel Garcia (31):
clk: mvebu: Add Core Divider clock
ARM: mvebu: Add Core Divider clock device-tree binding
ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
ARM: mvebu: Add the core-divider clock to Armada 370/XP
mtd: nand: pxa3xx: devicetree binding update
mtd: nand: pxa3xx: Add documentation about the controller
mtd: nand: pxa3xx: Make config menu show supported platforms
mtd: nand: pxa3xx: Prevent sub-page writes
mtd: nand: pxa3xx: read_page() returns max_bitflips
mtd: nand: pxa3xx: Early variant detection
mtd: nand: pxa3xx: Use chip->cmdfunc instead of the internal
mtd: nand: pxa3xx: Split FIFO size from to-be-read FIFO count
mtd: nand: pxa3xx: Replace host->page_size by mtd->writesize
mtd: nand: pxa3xx: Add a nice comment to pxa3xx_set_datasize()
mtd: nand: pxa3xx: Use a completion to signal device ready
mtd: nand: pxa3xx: Use waitfunc() to wait for the device to be ready
mtd: nand: pxa3xx: Add bad block handling
mtd: nand: pxa3xx: Add driver-specific ECC BCH support
mtd: nand: pxa3xx: Clear cmd buffer #3 (NDCB3) on command start
mtd: nand: pxa3xx: Add helper function to set page address
mtd: nand: pxa3xx: Remove READ0 switch/case falltrough
mtd: nand: pxa3xx: Split prepare_command_pool() in two stages
mtd: nand: pxa3xx: Move the data buffer clean to
prepare_start_command()
mtd: nand: pxa3xx: Fix SEQIN column address set
mtd: nand: pxa3xx: Add a read/write buffers markers
mtd: nand: pxa3xx: Introduce multiple page I/O support
mtd: nand: pxa3xx: Add multiple chunk write support
mtd: nand: pxa3xx: Add ECC BCH correctable errors detection
ARM: mvebu: Add support for NAND controller in Armada 370/XP
ARM: mvebu: Enable NAND controller in Armada XP GP board
ARM: mvebu: Enable NAND controller in Armada 370 Mirabox
.../bindings/clock/mvebu-corediv-clock.txt | 19 + .../devicetree/bindings/mtd/pxa3xx-nand.txt | 6 +- Documentation/mtd/nand/pxa3xx-nand.txt | 113 ++++ arch/arm/boot/dts/armada-370-mirabox.dts | 21 + arch/arm/boot/dts/armada-370-xp.dtsi | 26 + arch/arm/boot/dts/armada-xp-gp.dts | 8 + drivers/clk/mvebu/Kconfig | 5 + drivers/clk/mvebu/Makefile | 1 + drivers/clk/mvebu/clk-corediv.c | 223 +++++++ drivers/mtd/nand/Kconfig | 4 +- drivers/mtd/nand/pxa3xx_nand.c | 678 ++++++++++++++++----- include/linux/platform_data/mtd-nand-pxa3xx.h | 3 + 12 files changed, 965 insertions(+), 142 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt create mode 100644 Documentation/mtd/nand/pxa3xx-nand.txt create mode 100644 drivers/clk/mvebu/clk-corediv.c
Signature · 1 line
1.8.1.5
PATCH v4 1/31 clk: mvebu: Add Core Divider clock
This commit introduces a new group of clocks present in Armada 370/XP SoCs (called "Core Divider" clocks) and add a provider for them. The only clock supported for now is the NAND clock (ndclk), but the infrastructure to add the rest is already set.
--- drivers/clk/mvebu/Kconfig | 5 + drivers/clk/mvebu/Makefile | 1 + drivers/clk/mvebu/clk-corediv.c | 223 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 229 insertions(+) create mode 100644 drivers/clk/mvebu/clk-corediv.c
drivers/clk/mvebu/Kconfig +5 -0
@@ -4,15 +4,20 @@ config MVEBU_CLK_COMMON config MVEBU_CLK_CPU bool +config MVEBU_CLK_COREDIV + bool + config ARMADA_370_CLK bool select MVEBU_CLK_COMMON select MVEBU_CLK_CPU + select MVEBU_CLK_COREDIV config ARMADA_XP_CLK bool select MVEBU_CLK_COMMON select MVEBU_CLK_CPU + select MVEBU_CLK_COREDIV config DOVE_CLK bool
drivers/clk/mvebu/Makefile +1 -0
@@ -1,5 +1,6 @@ obj-$(CONFIG_MVEBU_CLK_COMMON) += common.o obj-$(CONFIG_MVEBU_CLK_CPU) += clk-cpu.o +obj-$(CONFIG_MVEBU_CLK_COREDIV) += clk-corediv.o obj-$(CONFIG_ARMADA_370_CLK) += armada-370.o obj-$(CONFIG_ARMADA_XP_CLK) += armada-xp.o
drivers/clk/mvebu/clk-corediv.c new file +223 -0
223 lines not on this page · raw message
Signature · 1 line
1.8.1.5
PATCH v4 2/31 ARM: mvebu: Add Core Divider clock device-tree binding
In reply to Ezequiel GarciaThe Armada 370/XP SoCs have a Core Divider clock providing several clocks. For now, only the NAND clock is supported.
--- .../devicetree/bindings/clock/mvebu-corediv-clock.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt
Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt new file +19 -0
@@ -0,0 +1,19 @@ +* Core Divider Clock bindings for Marvell MVEBU SoCs + +The following is a list of provided IDs and clock names on Armada 370/XP: + 0 = nand (NAND clock) + +Required properties: +- compatible : must be "marvell,armada-370-corediv-clock" +- reg : must be the register address of Core Divider control register +- #clock-cells : from common clock binding; shall be set to 1 +- clocks : must be set to the parent's phandle + +Example: + +corediv_clk: corediv-clocks at 18740 { + compatible = "marvell,armada-370-corediv-clock"; + reg = <0x18740 0xc>; + #clock-cells = <1>; + clocks = <&pll>; +};
Signature · 1 line
1.8.1.5
PATCH v4 3/31 ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
In reply to Ezequiel GarciaArmada 370/XP SoCs have a 2 GHz fixed PLL that is used to feed other clocks. This commit adds a DT representation of this clock through a fixed-clock compatible node.
--- arch/arm/boot/dts/armada-370-xp.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +9 -0
@@ -252,4 +252,13 @@ }; }; + + clocks { + /* 2 GHz fixed main PLL */ + mainpll: mainpll { + compatible = "fixed-clock"; + #clock-cells = <0>; + clock-frequency = <2000000000>; + }; + }; };
Signature · 1 line
1.8.1.5
PATCH v4 4/31 ARM: mvebu: Add the core-divider clock to Armada 370/XP
In reply to Ezequiel GarciaThe Armada 370/XP SoC has a clock provider called "Core Divider", that is derived from a fixed 2 GHz PLL clock.
--- arch/arm/boot/dts/armada-370-xp.dtsi | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +8 -0
@@ -137,6 +137,14 @@ status = "disabled"; }; + coredivclk: corediv-clock at 18740 { + compatible = "marvell,armada-370-corediv-clock"; + reg = <0x18740 0xc>; + #clock-cells = <1>; + clocks = <&mainpll>; + clock-output-names = "nand"; + }; + timer at 20300 { reg = <0x20300 0x30>, <0x21040 0x30>; interrupts = <37>, <38>, <39>, <40>, <5>, <6>;
Signature · 1 line
1.8.1.5
PATCH v4 5/31 mtd: nand: pxa3xx: devicetree binding update
In reply to Ezequiel GarciaSince the driver supports the new compatible string, the binding documentation must be updated to reflect it.
--- Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt +3 -1
@@ -2,7 +2,9 @@ PXA3xx NAND DT bindings Required properties: - - compatible: Should be "marvell,pxa3xx-nand" + - compatible: Should be set to one of the following: + marvell,pxa3xx-nand + marvell,armada370-nand - reg: The register base for the controller - interrupts: The interrupt to map - #address-cells: Set to <1> if the node includes partitions
Signature · 1 line
1.8.1.5
PATCH v4 5/31 mtd: nand: pxa3xx: devicetree binding update
Quoted 7 lines · Ezequiel Garcia
Since the driver supports the new compatible string, the binding documentation must be updated to reflect it.
Signed-off-by Ezequiel Garcia <[email protected]>--- Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
Thanks for adding this, but please remember to update the Subject string in the future. Both this patch and the next one are changing the Documentation/ portion of the tree, not drivers/.
And,
thx,
Jason.
Quoted 18 lines
Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt +3
-1@@ -2,7 +2,9 @@ PXA3xx NAND DT bindings Required properties: - - compatible: Should be "marvell,pxa3xx-nand" + - compatible: Should be set to one of the following: + marvell,pxa3xx-nand + marvell,armada370-nand - reg: The register base for the controller - interrupts: The interrupt to map - #address-cells: Set to <1> if the node includes partitionsSignature · 1 line
1.8.1.5
PATCH v4 5/31 mtd: nand: pxa3xx: devicetree binding update
Quoted 4 lines · Jason Cooper
Quoted 3 lines · Ezequiel Garcia
Since the driver supports the new compatible string, the binding documentation must be updated to reflect it.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Ezequiel Garcia <[email protected]>--- Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Thanks for adding this, but please remember to update the Subject string in the future. Both this patch and the next one are changing the
Documentation/portion of the tree, notdrivers/.
Come again?
You mean "[PATCH] Documentation: mtd: nand: Do this"
In that case: sorry, I do it differently on purpose, it looks better to me (focus the affected driver), but maybe I'm wrong.
Quoted 4 lines
And,
Acked-by Jason Cooper <[email protected]>
Thanks!
Quoted 22 lines
thx,
Jason.
Quoted 18 lines
Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt +3
-1@@ -2,7 +2,9 @@ PXA3xx NAND DT bindings Required properties: - - compatible: Should be "marvell,pxa3xx-nand" + - compatible: Should be set to one of the following: + marvell,pxa3xx-nand + marvell,armada370-nand - reg: The register base for the controller - interrupts: The interrupt to map - #address-cells: Set to <1> if the node includes partitionsSignature · 1 line
1.8.1.5
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 5/31 mtd: nand: pxa3xx: devicetree binding update
Quoted 15 lines · Ezequiel Garcia
Quoted 4 lines · Jason Cooper
Quoted 3 lines · Ezequiel Garcia
Since the driver supports the new compatible string, the binding documentation must be updated to reflect it.
Quoted 9 lines
Quoted 4 lines
Signed-off-by Ezequiel Garcia <[email protected]>--- Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)Thanks for adding this, but please remember to update the Subject string in the future. Both this patch and the next one are changing the
Documentation/portion of the tree, notdrivers/.
Quoted 6 lines
Come again?
You mean "[PATCH] Documentation: mtd: nand: Do this"
In that case: sorry, I do it differently on purpose, it looks better to me (focus the affected driver), but maybe I'm wrong.
but it makes it more difficult for devicetree binding reviewers to find the patch in the series. Perhaps having 'binding' in the Subject is sufficient. We'll see how things unfold over the next few days.
thx,
Jason.
PATCH v4 6/31 mtd: nand: pxa3xx: Add documentation about the controller
In reply to Ezequiel GarciaGiven there's no public specification to this date, and in order to capture some important details and singularities about the controller let's document them once and for good.
--- Documentation/mtd/nand/pxa3xx-nand.txt | 113 +++++++++++++++++++++++++++++++++ drivers/mtd/nand/pxa3xx_nand.c | 2 + 2 files changed, 115 insertions(+) create mode 100644 Documentation/mtd/nand/pxa3xx-nand.txt
Documentation/mtd/nand/pxa3xx-nand.txt new file +113 -0
@@ -0,0 +1,113 @@ + +About this document +=================== + +Some notes about Marvell's NAND controller available in PXA and Armada 370/XP +SoC (aka NFCv1 and NFCv2), with an emphasis on the latter. + +NFCv2 controller background +=========================== + +The controller has a 2176 bytes FIFO buffer. Therefore, in order to support +larger pages, I/O operations on 4 KiB and 8 KiB pages is done with a set of +chunked transfers. + +For instance, if we choose a 2048 data chunk and set "BCH" ECC (see below) +we'll have this layout in the pages: + + ------------------------------------------------------------------------------ + | 2048B data | 32B spare | 30B ECC || 2048B data | 32B spare | 30B ECC | ... | + ------------------------------------------------------------------------------ + +The driver reads the data and spare portions independently and builds an internal +buffer with this layout (in the 4 KiB page case): + + ------------------------------------------ + | 4096B data | 64B spare | + ------------------------------------------ + +Also, for the READOOB command the driver disables the ECC and reads a 'spare + ECC' +OOB, one per chunk read. + + ------------------------------------------------------------------- + | 4096B data | 32B spare | 30B ECC | 32B spare | 30B ECC | + ------------------------------------------------------------------- + +So, in order to achieve reading (for instance), we issue several READ0 commands +(with some additional controller-specific magic) and read two chunks of 2080B +(2048 data + 32 spare) each. +The driver accomodates this data to expose the NAND core a contiguous buffer +(4096 data + spare) or (4096 + spare + ECC + spare + ECC). + +ECC +=== + +The controller has built-in hardware ECC capabilities. In addition it is +configurable between two modes: 1) Hamming, 2) BCH. + +Note that the actual BCH mode: BCH-4 or BCH-8 will depend on the way +the controller is configured to transfer the data. + +In the BCH mode the ECC code will be calculated for each transfered chunk +and expected to be located (when reading/programming) right after the spare +bytes as the figure above shows. + +So, repeating the above scheme, a 2048B data chunk will be followed by 32B +spare, and then the ECC controller will read/write the ECC code (30B in +this case): + + ------------------------------------ + | 2048B data | 32B spare | 30B ECC | + ------------------------------------ + +If the ECC mode is 'BCH' then the ECC is *always* 30 bytes long. +If the ECC mode is 'Hamming' the ECC is 6 bytes long, for each 512B block. +So in Hamming mode, a 2048B page will have a 24B ECC. + +Despite all of the above, the controller requires the driver to only read or +write in multiples of 8-bytes, because the data buffer is 64-bits. + +OOB +=== + +Because of the above scheme, and because the "spare" OOB is really located in +the middle of a page, spare OOB cannot be read or write independently of the +data area. In other words, in order to read the OOB (aka READOOB), the entire +page (aka READ0) has to be read. + +In the same sense, in order to write to the spare OOB the driver has to write +an *entire* page. + +Factory bad blocks handling +=========================== + +Given the ECC BCH requires to layout the device's pages in a splitted +data/OOB/data/OOB way, the controller has a view of the flash page that's +different from the specified (aka the manufacturer's) view. In other words, + +Factory view: + + ----------------------------------------------- + | Data |x OOB | + ----------------------------------------------- + +Driver's view: + + ----------------------------------------------- + | Data | OOB | Data x | OOB | + ----------------------------------------------- + +It can be seen from the above, that the factory bad block marker must be +searched within the 'data' region, and not in the usual OOB region. + +In addition, this means under regular usage the driver will write such +position (since it belongs to the data region) and every used block is +likely to be marked as bad. + +For this reason, marking the block as bad in the OOB is explicitly +disabled by using the NAND_BBT_NO_OOB_BBM option in the driver. The rationale +for this is that there's no point in marking a block as bad, because good +blocks are also 'marked as bad' (in the OOB BBM sense) under normal usage. + +Instead, the drive relies in the bad block table alone, and should only perform +the bad block scan on the very first time (when the device hasn't been used).
drivers/mtd/nand/pxa3xx_nand.c +2 -0
@@ -7,6 +7,8 @@* This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. +* +* See Documentation/mtd/nand/pxa3xx-nand.txt for more details. */ #include <linux/kernel.h>
Signature · 1 line
1.8.1.5
PATCH v4 6/31 mtd: nand: pxa3xx: Add documentation about the controller
Quoted 3 lines · Ezequiel Garcia
Given there's no public specification to this date, and in order to capture some important details and singularities about the controller let's document them once and for good.
Made a few small tweaks for spelling and such (see the following diff) and pushed patches 5 through 14 to l2-mtd.git/next.
Thanks,
Brian
Documentation/mtd/nand/pxa3xx-nand.txt +3 -3
@@ -36,7 +36,7 @@ OOB, one per chunk read. So, in order to achieve reading (for instance), we issue several READ0 commands (with some additional controller-specific magic) and read two chunks of 2080B (2048 data + 32 spare) each. -The driver accomodates this data to expose the NAND core a contiguous buffer +The driver accommodates this data to expose the NAND core a contiguous buffer (4096 data + spare) or (4096 + spare + ECC + spare + ECC). ECC
@@ -81,7 +81,7 @@ an *entire* page. Factory bad blocks handling =========================== -Given the ECC BCH requires to layout the device's pages in a splitted +Given the ECC BCH requires to layout the device's pages in a split data/OOB/data/OOB way, the controller has a view of the flash page that's different from the specified (aka the manufacturer's) view. In other words,
@@ -109,5 +109,5 @@ disabled by using the NAND_BBT_NO_OOB_BBM option in the driver. The rationale for this is that there's no point in marking a block as bad, because good blocks are also 'marked as bad' (in the OOB BBM sense) under normal usage. -Instead, the drive relies in the bad block table alone, and should only perform +Instead, the driver relies on the bad block table alone, and should only perform the bad block scan on the very first time (when the device hasn't been used).
PATCH v4 6/31 mtd: nand: pxa3xx: Add documentation about the controller
Quoted 8 lines · Brian Norris
Quoted 3 lines · Ezequiel Garcia
Given there's no public specification to this date, and in order to capture some important details and singularities about the controller let's document them once and for good.
Made a few small tweaks for spelling and such (see the following diff) and pushed patches 5 through 14 to l2-mtd.git/next.
The below diff looks ok. I had to rework a few patches after the completion patch rework, and I'm running some tests.
I'll submit the series as soon as the tests are done.
Quoted 32 lines
Thanks,
BrianDocumentation/mtd/nand/pxa3xx-nand.txt +3
-3@@ -36,7 +36,7 @@ OOB, one per chunk read. So, in order to achieve reading (for instance), we issue several READ0 commands (with some additional controller-specific magic) and read two chunks of 2080B (2048 data + 32 spare) each. -The driver accomodates this data to expose the NAND core a contiguous buffer +The driver accommodates this data to expose the NAND core a contiguous buffer (4096 data + spare) or (4096 + spare + ECC + spare + ECC). ECC@@ -81,7 +81,7 @@ an *entire* page. Factory bad blocks handling =========================== -Given the ECC BCH requires to layout the device's pages in a splitted +Given the ECC BCH requires to layout the device's pages in a split data/OOB/data/OOB way, the controller has a view of the flash page that's different from the specified (aka the manufacturer's) view. In other words,@@ -109,5 +109,5 @@ disabled by using the NAND_BBT_NO_OOB_BBM option in the driver. The rationale for this is that there's no point in marking a block as bad, because good blocks are also 'marked as bad' (in the OOB BBM sense) under normal usage. -Instead, the drive relies in the bad block table alone, and should only perform +Instead, the driver relies on the bad block table alone, and should only perform the bad block scan on the very first time (when the device hasn't been used).
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 7/31 mtd: nand: pxa3xx: Make config menu show supported platforms
In reply to Ezequiel GarciaSince we have now support for the NFCv2 controller found on Armada 370/XP platforms.
--- drivers/mtd/nand/Kconfig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/mtd/nand/Kconfig +2 -2
@@ -326,11 +326,11 @@ config MTD_NAND_ATMEL on Atmel AT91 and AVR32 processors. config MTD_NAND_PXA3xx - tristate "Support for NAND flash devices on PXA3xx" + tristate "NAND support on PXA3xx and Armada 370/XP" depends on PXA3xx || ARCH_MMP || PLAT_ORION help This enables the driver for the NAND flash device found on - PXA3xx processors + PXA3xx processors (NFCv1) and also on Armada 370/XP (NFCv2). config MTD_NAND_SLC_LPC32XX tristate "NXP LPC32xx SLC Controller"
Signature · 1 line
1.8.1.5
PATCH v4 8/31 mtd: nand: pxa3xx: Prevent sub-page writes
In reply to Ezequiel GarciaThe current driver doesn't support sub-page writing, so report that to the NAND core.
--- drivers/mtd/nand/pxa3xx_nand.c | 1 + 1 file changed, 1 insertion(+)
drivers/mtd/nand/pxa3xx_nand.c +1 -0
@@ -1145,6 +1145,7 @@ static int alloc_nand_resource(struct platform_device *pdev) chip->read_byte = pxa3xx_nand_read_byte; chip->read_buf = pxa3xx_nand_read_buf; chip->write_buf = pxa3xx_nand_write_buf; + chip->options |=NAND_NO_SUBPAGE_WRITE ; }spin_lock_init (&chip->controller->lock);
Signature · 1 line
1.8.1.5
PATCH v4 9/31 mtd: nand: pxa3xx: read_page() returns max_bitflips
In reply to Ezequiel GarciaAs per the ecc.read_page() prototype, we must return the maximum number of bitflips that were corrected on any one region covering an ecc step.
--- drivers/mtd/nand/pxa3xx_nand.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/mtd/nand/pxa3xx_nand.c +3 -1
@@ -751,6 +751,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, {struct pxa3xx_nand_host *host = mtd->priv;struct pxa3xx_nand_info *info = host->info_data; +int max_bitflips =0 ; chip->read_buf (mtd, buf, mtd->writesize); chip->read_buf (mtd, chip->oob_poi, mtd->oobsize);
@@ -758,6 +759,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd,if (info->retcode ==ERR_SBERR ) {switch (info->use_ecc) {case 1 : + max_bitflips =1 ; mtd->ecc_stats.corrected++;break ;case 0 :
@@ -776,7 +778,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, mtd->ecc_stats.failed++; } -return 0 ; +return max_bitflips; }static uint8_t pxa3xx_nand_read_byte (struct mtd_info *mtd)
Signature · 1 line
1.8.1.5
PATCH v4 10/31 mtd: nand: pxa3xx: Early variant detection
In reply to Ezequiel GarciaIn order to customize early settings depending on the detected SoC variant, move the detection to be before the nand_chip struct filling.
In a follow-up patch, this change is needed to detect the variant *before* the call to alloc_nand_resource(), which allows to set a different cmdfunc() for each variant.
--- drivers/mtd/nand/pxa3xx_nand.c | 48 +++++++++++++++++++++--------------------- 1 file changed, 24 insertions(+), 24 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +24 -24
@@ -258,6 +258,29 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = {/* convert nano-seconds to nand flash controller clock cycles */ #define ns2cycle (ns, clk) (int)((ns) * (clk / 1000000) / 1000) +static struct of_device_id pxa3xx_nand_dt_ids[] = { + { + .compatible ="marvell,pxa3xx-nand" , + .data = (void *)PXA3XX_NAND_VARIANT_PXA , + }, + { + .compatible ="marvell,armada370-nand" , + .data = (void *)PXA3XX_NAND_VARIANT_ARMADA370 , + }, + {} +}; +MODULE_DEVICE_TABLE (of, pxa3xx_nand_dt_ids); + +static enum pxa3xx_nand_variant +pxa3xx_nand_get_variant (struct platform_device *pdev) +{ +const struct of_device_id *of_id = +of_match_device (pxa3xx_nand_dt_ids, &pdev->dev); +if (!of_id) +return PXA3XX_NAND_VARIANT_PXA ; +return (enum pxa3xx_nand_variant )of_id->data; +} +static void pxa3xx_nand_set_timing (struct pxa3xx_nand_host *host,const struct pxa3xx_nand_timing *t) {
@@ -1125,6 +1148,7 @@ static int alloc_nand_resource(struct platform_device *pdev)return -ENOMEM ; info->pdev = pdev; + info->variant =pxa3xx_nand_get_variant (pdev);for (cs =0 ; cs < pdata->num_cs; cs++) { mtd = (struct mtd_info *)((unsigned int )&info[1 ] + (sizeof (*mtd) +sizeof (*host)) * cs);
@@ -1260,29 +1284,6 @@ static int pxa3xx_nand_remove(struct platform_device *pdev)return 0 ; } -static struct of_device_id pxa3xx_nand_dt_ids[] = { - { - .compatible ="marvell,pxa3xx-nand" , - .data = (void *)PXA3XX_NAND_VARIANT_PXA , - }, - { - .compatible ="marvell,armada370-nand" , - .data = (void *)PXA3XX_NAND_VARIANT_ARMADA370 , - }, - {} -}; -MODULE_DEVICE_TABLE (of, pxa3xx_nand_dt_ids); - -static enum pxa3xx_nand_variant -pxa3xx_nand_get_variant (struct platform_device *pdev) -{ -const struct of_device_id *of_id = -of_match_device (pxa3xx_nand_dt_ids, &pdev->dev); -if (!of_id) -return PXA3XX_NAND_VARIANT_PXA ; -return (enum pxa3xx_nand_variant )of_id->data; -} -static int pxa3xx_nand_probe_dt (struct platform_device *pdev) {struct pxa3xx_nand_platform_data *pdata;
@@ -1339,7 +1340,6 @@ static int pxa3xx_nand_probe(struct platform_device *pdev) } info =platform_get_drvdata (pdev); - info->variant =pxa3xx_nand_get_variant (pdev); probe_success =0 ;for (cs =0 ; cs < pdata->num_cs; cs++) {struct mtd_info *mtd = info->host[cs]->mtd;
Signature · 1 line
1.8.1.5
PATCH v4 11/31 mtd: nand: pxa3xx: Use chip->cmdfunc instead of the internal
In reply to Ezequiel GarciaWhenever possible, it's always better to use the generic chip->cmdfunc instead of the internal pxa3xx_nand_cmdfunc().
In this particular case, this will allow to have multiple cmdfunc() implementations for different SoC variants.
--- drivers/mtd/nand/pxa3xx_nand.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/mtd/nand/pxa3xx_nand.c +5 -1
@@ -1015,14 +1015,18 @@ static void pxa3xx_nand_free_buff(struct pxa3xx_nand_info *info)static int pxa3xx_nand_sensing (struct pxa3xx_nand_info *info) {struct mtd_info *mtd; +struct nand_chip *chip;int ret; + mtd = info->host[info->cs]->mtd; + chip = mtd->priv; +/* use the common timing to make a try */ ret =pxa3xx_nand_config_flash (info, &builtin_flash_types[0 ]);if (ret)return ret; -pxa3xx_nand_cmdfunc (mtd,NAND_CMD_RESET ,0 ,0 ); + chip->cmdfunc (mtd,NAND_CMD_RESET ,0 ,0 );if (info->is_ready)return 0 ;
Signature · 1 line
1.8.1.5
PATCH v4 12/31 mtd: nand: pxa3xx: Split FIFO size from to-be-read FIFO count
In reply to Ezequiel GarciaIntroduce a fifo_size field to represent the size of the controller's FIFO buffer, and use it to distinguish that size from the amount of data bytes to be read from the FIFO.
This is important to support devices with pages larger than the controller's internal FIFO, that need to read the pages in FIFO-sized chunks.
In particular, the current code is at least confusing, for it mixes all the different sizes involved: FIFO size, page size and data size.
This commit starts the cleaning by removing the info->page_size field that is not currently used. The host->page_size field should also be removed and use always mtd->writesize instead. Follow up commits will clean this up.
--- drivers/mtd/nand/pxa3xx_nand.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +7 -5
@@ -201,8 +201,8 @@ struct pxa3xx_nand_info {int use_spare;/* use spare ? */ int is_ready; -unsigned int page_size;/* page size of attached chip */ -unsigned int data_size;/* data size in FIFO */ +unsigned int fifo_size;/* max. data size in the FIFO */ +unsigned int data_size;/* data to be read from FIFO */ unsigned int oob_size;int retcode;
@@ -307,16 +307,15 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_host *host,static void pxa3xx_set_datasize (struct pxa3xx_nand_info *info) { -struct pxa3xx_nand_host *host = info->host[info->cs];int oob_enable = info->reg_ndcr &NDCR_SPARE_EN ; - info->data_size = host->page_size; + info->data_size = info->fifo_size;if (!oob_enable) { info->oob_size =0 ;return ; } -switch (host->page_size) { +switch (info->fifo_size) {case 2048 : info->oob_size = (info->use_ecc) ?40 :64 ;break ;
@@ -933,9 +932,12 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)uint32_t ndcr =nand_readl (info,NDCR );if (ndcr &NDCR_PAGE_SZ ) { +/* Controller's FIFO size */ + info->fifo_size =2048 ; host->page_size =2048 ; host->read_id_bytes =4 ; }else { + info->fifo_size =512 ; host->page_size =512 ; host->read_id_bytes =2 ; }
Signature · 1 line
1.8.1.5
PATCH v4 13/31 mtd: nand: pxa3xx: Replace host->page_size by mtd->writesize
In reply to Ezequiel GarciaThere's no need to privately store the device page size as it's available in mtd structure field mtd->writesize. Also, this removes the hardcoded page size value, leaving the auto-detected value only.
--- drivers/mtd/nand/pxa3xx_nand.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +3 -7
@@ -151,7 +151,6 @@ struct pxa3xx_nand_host {void *info_data;/* page size of attached chip */ -unsigned int page_size;int use_ecc;int cs;
@@ -614,12 +613,12 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, info->buf_start += mtd->writesize;/* Second command setting for large pages */ -if (host->page_size >=PAGE_CHUNK_SIZE ) +if (mtd->writesize >=PAGE_CHUNK_SIZE ) info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 );case NAND_CMD_SEQIN :/* small page addr setting */ -if (unlikely (host->page_size <PAGE_CHUNK_SIZE )) { +if (unlikely (mtd->writesize <PAGE_CHUNK_SIZE )) { info->ndcb1 = ((page_addr &0xFFFFFF ) <<8 ) | (column &0xFF );
@@ -895,7 +894,6 @@ static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info, }/* calculate flash information */ - host->page_size = f->page_size; host->read_id_bytes = (f->page_size ==2048 ) ?4 :2 ;/* calculate addressing information */
@@ -934,11 +932,9 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)if (ndcr &NDCR_PAGE_SZ ) {/* Controller's FIFO size */ info->fifo_size =2048 ; - host->page_size =2048 ; host->read_id_bytes =4 ; }else { info->fifo_size =512 ; - host->page_size =512 ; host->read_id_bytes =2 ; }
@@ -1106,7 +1102,7 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd) def = pxa3xx_flash_ids; KEEP_CONFIG: chip->ecc.mode =NAND_ECC_HW ; - chip->ecc.size = host->page_size; + chip->ecc.size = info->fifo_size; chip->ecc.strength =1 ;if (info->reg_ndcr &NDCR_DWIDTH_M )
Signature · 1 line
1.8.1.5
PATCH v4 14/31 mtd: nand: pxa3xx: Add a nice comment to pxa3xx_set_datasize()
In reply to Ezequiel GarciaAdd a comment clarifying the use of pxa3xx_set_datasize() which is only applicable on data read/write commands (i.e. commands with a data cycle, such as READID, READ0, STATUS, etc.)
--- drivers/mtd/nand/pxa3xx_nand.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/nand/pxa3xx_nand.c +5 -0
@@ -304,6 +304,11 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_host *host,nand_writel (info,NDTR1CS0 , ndtr1); } +/* +* Set the data and OOB size, depending on the selected +* spare and ECC configuration. +* Only applicable to READ0, READOOB and PAGEPROG commands. +*/ static void pxa3xx_set_datasize (struct pxa3xx_nand_info *info) {int oob_enable = info->reg_ndcr &NDCR_SPARE_EN ;
Signature · 1 line
1.8.1.5
PATCH v4 15/31 mtd: nand: pxa3xx: Use a completion to signal device ready
In reply to Ezequiel GarciaThe expected behavior of the waitfunc() NAND chip call is to wait for the device to be READY (this is a standard chip line). However, the current implementation does almost nothing, which opens the possibility of issuing a command to a non-ready device.
Fix this by adding a new completion to wait for the ready event to arrive.
--- drivers/mtd/nand/pxa3xx_nand.c | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +23 -12
@@ -37,6 +37,7 @@#include <linux/platform_data/mtd-nand-pxa3xx.h> +#define NAND_DEV_READY_TIMEOUT 50#define CHIP_DELAY_TIMEOUT (2 * HZ/10)#define NAND_STOP_DELAY (2 * HZ/50)#define PAGE_CHUNK_SIZE (2048)
@@ -168,7 +169,7 @@ struct pxa3xx_nand_info {struct clk *clk;void __iomem *mmio_base;unsigned long mmio_phys; -struct completion cmd_complete; +struct completion cmd_complete, dev_ready;unsigned int buf_start;unsigned int buf_count;
@@ -480,7 +481,7 @@ static void start_data_dma(struct pxa3xx_nand_info *info)static irqreturn_t pxa3xx_nand_irq (int irq,void *devid) {struct pxa3xx_nand_info *info = devid; -unsigned int status, is_completed =0 ; +unsigned int status, is_completed =0 , is_ready =0 ;unsigned int ready, cmd_done;if (info->cs ==0 ) {
@@ -516,8 +517,8 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid) is_completed =1 ; }if (status & ready) { - info->is_ready =1 ; info->state =STATE_READY ; + is_ready =1 ; }if (status &NDSR_WRCMDREQ ) {
@@ -546,6 +547,8 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid)nand_writel (info,NDSR , status);if (is_completed)complete (&info->cmd_complete); +if (is_ready) +complete (&info->dev_ready); NORMAL_IRQ_EXIT:return IRQ_HANDLED ; }
@@ -576,7 +579,6 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, info->oob_size =0 ; info->use_ecc =0 ; info->use_spare =1 ; - info->is_ready =0 ; info->retcode =ERR_NONE ;if (info->cs !=0 ) info->ndcb0 =NDCB0_CSEL ;
@@ -749,6 +751,8 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, exec_cmd =prepare_command_pool (info, command, column, page_addr);if (exec_cmd) {init_completion (&info->cmd_complete); +init_completion (&info->dev_ready); + info->is_ready =0 ;pxa3xx_nand_start (info); ret = wait_for_completion_timeout(&info->cmd_complete,
@@ -863,21 +867,28 @@ static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) {struct pxa3xx_nand_host *host = mtd->priv;struct pxa3xx_nand_info *info = host->info_data; +int ret; + +/* Need to wait? */ +if (!info->is_ready) { + ret =wait_for_completion_timeout (&info->dev_ready, +CHIP_DELAY_TIMEOUT ); +if (!ret) { +dev_err (&info->pdev->dev,"Ready time out!!!\n" ); +return NAND_STATUS_FAIL ; + } + info->is_ready =1 ; + }/* pxa3xx_nand_send_command has waited for command complete */ if (this->state ==FL_WRITING || this->state ==FL_ERASING ) {if (info->retcode ==ERR_NONE )return 0 ; -else { -/* -* any error make it return 0x01 which will tell -* the caller the erase and write fail -*/ -return 0x01 ; - } +else +return NAND_STATUS_FAIL ; } -return 0 ; +return NAND_STATUS_READY ; } static int pxa3xx_nand_config_flash(struct pxa3xx_nand_info *info,
Signature · 1 line
1.8.1.5
PATCH v4 15/31 mtd: nand: pxa3xx: Use a completion to signal device ready
Quoted 7 lines · Ezequiel Garcia
drivers/mtd/nand/pxa3xx_nand.c +1
-0@@ -863,21 +867,28 @@ static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) {struct pxa3xx_nand_host *host = mtd->priv;struct pxa3xx_nand_info *info = host->info_data; +int ret;
drivers/mtd/nand/pxa3xx_nand.c static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) · line 880
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c +10
-0+ +/* Need to wait? */ +if (!info->is_ready) { + ret =wait_for_completion_timeout (&info->dev_ready, +CHIP_DELAY_TIMEOUT ); +if (!ret) { +dev_err (&info->pdev->dev,"Ready time out!!!\n" ); +return NAND_STATUS_FAIL ; + } + info->is_ready =1 ;
Shouldn't the is_ready=1 line to be above the if (!ret) condition? I think you want to set is_ready=1 in either case (success or timeout). With this code, any timeout will cause subsequent waitfunc()'s to block, even if they are never going to catch an interrupt.
I think this kind of mistake is easier to make now, since the 'is_ready' field isn't properly descriptive any more. It doesn't represent "is the device ready"; it represents "is there a pending command on which I need to wait". (I don't care if you change the name; I'm just pointing this out.)
drivers/mtd/nand/pxa3xx_nand.c static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) · line 882
Quoted 2 lines
drivers/mtd/nand/pxa3xx_nand.c +1
-0+ }
I think all the other patches up to this one are good. I may push them to l2-mtd.git now, unless you object.
Brian
PATCH v4 15/31 mtd: nand: pxa3xx: Use a completion to signal device ready
Brian,
Quoted 15 lines · Brian Norris
Quoted 14 lines · Ezequiel Garcia
drivers/mtd/nand/pxa3xx_nand.c +8
-0@@ -863,21 +867,28 @@ static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) {struct pxa3xx_nand_host *host = mtd->priv;struct pxa3xx_nand_info *info = host->info_data; +int ret; + +/* Need to wait? */ +if (!info->is_ready) { + ret =wait_for_completion_timeout (&info->dev_ready, +CHIP_DELAY_TIMEOUT ); +if (!ret) { +dev_err (&info->pdev->dev,"Ready time out!!!\n" );
Quoted 9 lines
drivers/mtd/nand/pxa3xx_nand.c static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) · line 880
Quoted 3 lines
drivers/mtd/nand/pxa3xx_nand.c +3
-0+return NAND_STATUS_FAIL ; + } + info->is_ready =1 ;Shouldn't the is_ready=1 line to be above the if (!ret) condition? I think you want to set is_ready=1 in either case (success or timeout). With this code, any timeout will cause subsequent waitfunc()'s to block, even if they are never going to catch an interrupt.
Yes, good catch!
Quoted 6 lines
I think this kind of mistake is easier to make now, since the '
is_ready' field isn't properly descriptive any more. It doesn't represent "is the device ready"; it represents "is there a pending command on which I need to wait". (I don't care if you change the name; I'm just pointing this out.)
Yes, I agree. Maybe, "need_wait" or something like that would fit better. Let me submit a new patch for this one.
Quoted 6 lines
drivers/mtd/nand/pxa3xx_nand.c static int pxa3xx_nand_waitfunc(struct mtd_info *mtd, struct nand_chip *this) · line 882
Quoted 2 lines
drivers/mtd/nand/pxa3xx_nand.c +1
-0+ }I think all the other patches up to this one are good. I may push them to l2-mtd.git now, unless you object.
Great, thanks a lot for reviewing and for all the feedback!
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 16/31 mtd: nand: pxa3xx: Use waitfunc() to wait for the device to be ready
In reply to Ezequiel GarciaIn pxa3xx_nand_sensing() instead of simply using info->is_ready after issuing a command, the correct way of checking is to wait for the device to be ready through the chip's waitfunc().
--- drivers/mtd/nand/pxa3xx_nand.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +4 -3
@@ -1041,10 +1041,11 @@ static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)return ret; chip->cmdfunc (mtd,NAND_CMD_RESET ,0 ,0 ); -if (info->is_ready) -return 0 ; + ret = chip->waitfunc (mtd, chip); +if (ret &NAND_STATUS_FAIL ) +return -ENODEV ; -return -ENODEV ; +return 0 ; }static int pxa3xx_nand_scan (struct mtd_info *mtd)
Signature · 1 line
1.8.1.5
PATCH v4 17/31 mtd: nand: pxa3xx: Add bad block handling
In reply to Ezequiel GarciaAdd support for flash-based bad block table using Marvell's custom in-flash bad block table layout. The support is enabled a 'flash_bbt' platform data or device tree parameter.
While at it, update the binding document to reflect this driver supports the property.
--- .../devicetree/bindings/mtd/pxa3xx-nand.txt | 2 ++ drivers/mtd/nand/pxa3xx_nand.c | 37 ++++++++++++++++++++++ include/linux/platform_data/mtd-nand-pxa3xx.h | 3 ++ 3 files changed, 42 insertions(+)
Documentation/devicetree/bindings/mtd/pxa3xx-nand.txt +2 -0
@@ -15,6 +15,8 @@ Optional properties: - marvell,nand-keep-config: Set to keep the NAND controller config as set by the bootloader - num-cs: Number of chipselect lines to usw + - nand-on-flash-bbt: boolean to enable on flash bbt option if + not present false Example:
drivers/mtd/nand/pxa3xx_nand.c +37 -0
@@ -26,6 +26,7 @@#include <linux/slab.h> #include <linux/of.h> #include <linux/of_device.h> +#include <linux/of_mtd.h> #if defined(CONFIG_ARCH_PXA ) || defined(CONFIG_ARCH_MMP )#define ARCH_HAS_DMA
@@ -241,6 +242,29 @@ static struct pxa3xx_nand_flash builtin_flash_types[] = { { "256MiB 16-bit", 0xba20, 64, 2048, 16, 16, 2048, &timing[3] }, }; +static u8 bbt_pattern[] = {'M' ,'V' ,'B' ,'b' ,'t' ,'0' }; +static u8 bbt_mirror_pattern[] = {'1' ,'t' ,'b' ,'B' ,'V' ,'M' }; + +static struct nand_bbt_descr bbt_main_descr = { + .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE + |NAND_BBT_2BIT |NAND_BBT_VERSION , + .offs =8 , + .len =6 , + .veroffs =14 , + .maxblocks =8 ,/* Last 8 blocks in each chip */ + .pattern = bbt_pattern +}; + +static struct nand_bbt_descr bbt_mirror_descr = { + .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE + |NAND_BBT_2BIT |NAND_BBT_VERSION , + .offs =8 , + .len =6 , + .veroffs =14 , + .maxblocks =8 ,/* Last 8 blocks in each chip */ + .pattern = bbt_mirror_pattern +}; +/* Define a default flash type setting serve as flash detecting only */ #define DEFAULT_FLASH_TYPE (&builtin_flash_types[0])
@@ -1127,6 +1151,18 @@ KEEP_CONFIG:if (nand_scan_ident (mtd,1 , def))return -ENODEV ; + +if (pdata->flash_bbt) { +/* +* We'll use a bad block table stored in-flash and don't +* allow writing the bad block marker to the flash. +*/ + chip->bbt_options |=NAND_BBT_USE_FLASH | +NAND_BBT_NO_OOB_BBM ; + chip->bbt_td = &bbt_main_descr; + chip->bbt_md = &bbt_mirror_descr; + } +/* calculate addressing information */ if (mtd->writesize >=2048 ) host->col_addr_cycles =2 ;
@@ -1322,6 +1358,7 @@ static int pxa3xx_nand_probe_dt(struct platform_device *pdev)if (of_get_property (np,"marvell,nand-keep-config" ,NULL )) pdata->keep_config =1 ;of_property_read_u32 (np,"num-cs" , &pdata->num_cs); + pdata->flash_bbt =of_get_nand_on_flash_bbt (np); pdev->dev.platform_data = pdata;
include/linux/platform_data/mtd-nand-pxa3xx.h +3 -0
@@ -55,6 +55,9 @@ struct pxa3xx_nand_platform_data {/* indicate how many chip selects will be used */ int num_cs; +/* use an flash-based bad block table */ +bool flash_bbt; +const struct mtd_partition *parts[NUM_CHIP_SELECT ];unsigned int nr_parts[NUM_CHIP_SELECT ];
Signature · 1 line
1.8.1.5
PATCH v4 18/31 mtd: nand: pxa3xx: Add driver-specific ECC BCH support
In reply to Ezequiel GarciaThis commit adds the BCH ECC support available in NFCv2 controller. Depending on the detected required strength the respective ECC layout is selected.
This commit adds an empty ECC layout, since support to access large pages is first required. Once that support is added, a proper ECC layout will be added as well.
--- drivers/mtd/nand/pxa3xx_nand.c | 86 +++++++++++++++++++++++++++++++++--------- 1 file changed, 69 insertions(+), 17 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +69 -17
@@ -58,6 +58,7 @@#define NDPCR (0x18)/* Page Count Register */ #define NDBDR0 (0x1C)/* Bad Block Register 0 */ #define NDBDR1 (0x20)/* Bad Block Register 1 */ +#define NDECCCTRL (0x28)/* ECC control */ #define NDDB (0x40)/* Data Buffer */ #define NDCB0 (0x48)/* Command Buffer0 */ #define NDCB1 (0x4C)/* Command Buffer1 */
@@ -198,6 +199,7 @@ struct pxa3xx_nand_info {int cs;int use_ecc;/* use HW ECC ? */ +int ecc_bch;/* using BCH ECC? */ int use_dma;/* use DMA ? */ int use_spare;/* use spare ? */ int is_ready;
@@ -205,6 +207,8 @@ struct pxa3xx_nand_info {unsigned int fifo_size;/* max. data size in the FIFO */ unsigned int data_size;/* data to be read from FIFO */ unsigned int oob_size; +unsigned int spare_size; +unsigned int ecc_size;int retcode;/* cached register value */
@@ -339,19 +343,12 @@ static void pxa3xx_set_datasize(struct pxa3xx_nand_info *info)int oob_enable = info->reg_ndcr &NDCR_SPARE_EN ; info->data_size = info->fifo_size; -if (!oob_enable) { - info->oob_size =0 ; +if (!oob_enable)return ; - } -switch (info->fifo_size) { -case 2048 : - info->oob_size = (info->use_ecc) ?40 :64 ; -break ; -case 512 : - info->oob_size = (info->use_ecc) ?8 :16 ; -break ; - } + info->oob_size = info->spare_size; +if (!info->use_ecc) + info->oob_size += info->ecc_size; }/**
@@ -366,10 +363,15 @@ static void pxa3xx_nand_start(struct pxa3xx_nand_info *info) ndcr = info->reg_ndcr; -if (info->use_ecc) +if (info->use_ecc) { ndcr |=NDCR_ECC_EN ; -else +if (info->ecc_bch) +nand_writel (info,NDECCCTRL ,0x1 ); + }else { ndcr &= ~NDCR_ECC_EN ; +if (info->ecc_bch) +nand_writel (info,NDECCCTRL ,0x0 ); + }if (info->use_dma) ndcr |=NDCR_DMA_EN ;
@@ -1072,6 +1074,41 @@ static int pxa3xx_nand_sensing(struct pxa3xx_nand_info *info)return 0 ; } +static int pxa_ecc_init (struct pxa3xx_nand_info *info, +struct nand_ecc_ctrl *ecc, +int strength,int page_size) +{ +/* +* We don't use strength here as the PXA variant +* is used with non-ONFI compliant devices. +*/ +if (page_size ==2048 ) { + info->spare_size =40 ; + info->ecc_size =24 ; + ecc->mode =NAND_ECC_HW ; + ecc->size =2048 ; + ecc->strength =1 ; +return 1 ; + + }else if (page_size ==512 ) { + info->spare_size =8 ; + info->ecc_size =8 ; + ecc->mode =NAND_ECC_HW ; + ecc->size =512 ; + ecc->strength =1 ; +return 1 ; + } +return 0 ; +} + +static int armada370_ecc_init (struct pxa3xx_nand_info *info, +struct nand_ecc_ctrl *ecc, +int strength,int page_size) +{ +/* Unimplemented yet */ +return 0 ; +} +static int pxa3xx_nand_scan (struct mtd_info *mtd) {struct pxa3xx_nand_host *host = mtd->priv;
@@ -1142,13 +1179,13 @@ static int pxa3xx_nand_scan(struct mtd_info *mtd) pxa3xx_flash_ids[1 ].name =NULL ; def = pxa3xx_flash_ids; KEEP_CONFIG: - chip->ecc.mode =NAND_ECC_HW ; - chip->ecc.size = info->fifo_size; - chip->ecc.strength =1 ; -if (info->reg_ndcr &NDCR_DWIDTH_M ) chip->options |=NAND_BUSWIDTH_16 ; +/* Device detection must be done with ECC disabled */ +if (info->variant ==PXA3XX_NAND_VARIANT_ARMADA370 ) +nand_writel (info,NDECCCTRL ,0x0 ); +if (nand_scan_ident (mtd,1 , def))return -ENODEV ;
@@ -1163,6 +1200,21 @@ KEEP_CONFIG: chip->bbt_md = &bbt_mirror_descr; } +if (info->variant ==PXA3XX_NAND_VARIANT_ARMADA370 ) + ret =armada370_ecc_init (info, &chip->ecc, + chip->ecc_strength_ds, + mtd->writesize); +else + ret =pxa_ecc_init (info, &chip->ecc, + chip->ecc_strength_ds, + mtd->writesize); +if (!ret) { +dev_err (&info->pdev->dev, +"ECC strength %d at page size %d is not supported\n" , + chip->ecc_strength_ds, mtd->writesize); +return -ENODEV ; + } +/* calculate addressing information */ if (mtd->writesize >=2048 ) host->col_addr_cycles =2 ;
Signature · 1 line
1.8.1.5
PATCH v4 19/31 mtd: nand: pxa3xx: Clear cmd buffer #3 (NDCB3) on command start
In reply to Ezequiel GarciaCommand buffer #3 is not properly cleared and it keeps the last set value. Fix this by clearing when a command is setup.
--- drivers/mtd/nand/pxa3xx_nand.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mtd/nand/pxa3xx_nand.c +1 -1
@@ -606,6 +606,7 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, info->use_ecc =0 ; info->use_spare =1 ; info->retcode =ERR_NONE ; + info->ndcb3 =0 ;if (info->cs !=0 ) info->ndcb0 =NDCB0_CSEL ;else
@@ -627,7 +628,6 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,default : info->ndcb1 =0 ; info->ndcb2 =0 ; - info->ndcb3 =0 ;break ; }
Signature · 1 line
1.8.1.5
PATCH v4 20/31 mtd: nand: pxa3xx: Add helper function to set page address
In reply to Ezequiel GarciaLet's simplify the code by first introducing a helper function to set the page address, as done by the READ0, READOOB and SEQIN commands.
--- drivers/mtd/nand/pxa3xx_nand.c | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +21 -15
@@ -587,6 +587,26 @@ static inline int is_buf_blank(uint8_t *buf, size_t len)return 1 ; } +static void set_command_address (struct pxa3xx_nand_info *info, +unsigned int page_size,uint16_t column,int page_addr) +{ +/* small page addr setting */ +if (page_size <PAGE_CHUNK_SIZE ) { + info->ndcb1 = ((page_addr &0xFFFFFF ) <<8 ) + | (column &0xFF ); + + info->ndcb2 =0 ; + }else { + info->ndcb1 = ((page_addr &0xFFFF ) <<16 ) + | (column &0xFFFF ); + +if (page_addr &0xFF0000 ) + info->ndcb2 = (page_addr &0xFF0000 ) >>16 ; +else + info->ndcb2 =0 ; + } +} +static int prepare_command_pool (struct pxa3xx_nand_info *info,int command,uint16_t column,int page_addr) {
@@ -650,22 +670,8 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 );case NAND_CMD_SEQIN : -/* small page addr setting */ -if (unlikely (mtd->writesize <PAGE_CHUNK_SIZE )) { - info->ndcb1 = ((page_addr &0xFFFFFF ) <<8 ) - | (column &0xFF ); - - info->ndcb2 =0 ; - }else { - info->ndcb1 = ((page_addr &0xFFFF ) <<16 ) - | (column &0xFFFF ); - -if (page_addr &0xFF0000 ) - info->ndcb2 = (page_addr &0xFF0000 ) >>16 ; -else - info->ndcb2 =0 ; - } +set_command_address (info, mtd->writesize, column, page_addr); info->buf_count = mtd->writesize + mtd->oobsize;memset (info->data_buff,0xFF , info->buf_count);
Signature · 1 line
1.8.1.5
PATCH v4 21/31 mtd: nand: pxa3xx: Remove READ0 switch/case falltrough
In reply to Ezequiel GarciaREAD0 and READOOB command preparation has a falltrough to SEQIN case, where the command address is specified.
This is certainly confusing and makes the code less readable with no added value. Let's remove it.
--- drivers/mtd/nand/pxa3xx_nand.c | 5 +++++ 1 file changed, 5 insertions(+)
drivers/mtd/nand/pxa3xx_nand.c +5 -0
@@ -669,6 +669,11 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,if (mtd->writesize >=PAGE_CHUNK_SIZE ) info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 ); +set_command_address (info, mtd->writesize, column, page_addr); + info->buf_count = mtd->writesize + mtd->oobsize; +memset (info->data_buff,0xFF , info->buf_count); +break ; +case NAND_CMD_SEQIN :set_command_address (info, mtd->writesize, column, page_addr);
Signature · 1 line
1.8.1.5
PATCH v4 22/31 mtd: nand: pxa3xx: Split prepare_command_pool() in two stages
In reply to Ezequiel GarciaThis commit splits the prepare_command_pool() function into two
stages: prepare_start_command() / prepare_set_command().
This is a preparation patch without any functionality changes, and is meant to allow support for multiple page reading/writing operations.
--- drivers/mtd/nand/pxa3xx_nand.c | 44 ++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 19 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +25 -19
@@ -607,18 +607,8 @@ static void set_command_address(struct pxa3xx_nand_info *info, } } -static int prepare_command_pool (struct pxa3xx_nand_info *info,int command, -uint16_t column,int page_addr) +static void prepare_start_command (struct pxa3xx_nand_info *info,int command) { -int addr_cycle, exec_cmd; -struct pxa3xx_nand_host *host; -struct mtd_info *mtd; - - host = info->host[info->cs]; - mtd = host->mtd; - addr_cycle =0 ; - exec_cmd =1 ; -/* reset data and oob column point to handle data */ info->buf_start =0 ; info->buf_count =0 ;
@@ -627,10 +617,6 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command, info->use_spare =1 ; info->retcode =ERR_NONE ; info->ndcb3 =0 ; -if (info->cs !=0 ) - info->ndcb0 =NDCB0_CSEL ; -else - info->ndcb0 =0 ;switch (command) {case NAND_CMD_READ0 :
@@ -642,14 +628,32 @@ static int prepare_command_pool(struct pxa3xx_nand_info *info, int command,case NAND_CMD_PARAM : info->use_spare =0 ;break ; -case NAND_CMD_SEQIN : - exec_cmd =0 ; -break ;default : info->ndcb1 =0 ; info->ndcb2 =0 ;break ; } +} + +static int prepare_set_command (struct pxa3xx_nand_info *info,int command, +uint16_t column,int page_addr) +{ +int addr_cycle, exec_cmd; +struct pxa3xx_nand_host *host; +struct mtd_info *mtd; + + host = info->host[info->cs]; + mtd = host->mtd; + addr_cycle =0 ; + exec_cmd =1 ; + +if (info->cs !=0 ) + info->ndcb0 =NDCB0_CSEL ; +else + info->ndcb0 =0 ; + +if (command ==NAND_CMD_SEQIN ) + exec_cmd =0 ; addr_cycle =NDCB0_ADDR_CYC (host->row_addr_cycles + host->col_addr_cycles);
@@ -784,8 +788,10 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,nand_writel (info,NDTR1CS0 , info->ndtr1cs0); } +prepare_start_command (info, command); + info->state =STATE_PREPARED ; - exec_cmd =prepare_command_pool (info, command, column, page_addr); + exec_cmd =prepare_set_command (info, command, column, page_addr);if (exec_cmd) {init_completion (&info->cmd_complete);init_completion (&info->dev_ready);
Signature · 1 line
1.8.1.5
PATCH v4 23/31 mtd: nand: pxa3xx: Move the data buffer clean to prepare_start_command()
In reply to Ezequiel GarciaTo allow future support of multiple page reading/writing, move the data buffer clean out of prepare_set_command().
This is done to prevent the data buffer from being cleaned on every command preparation, when a multiple command sequence is implemented to read/write pages larger than the FIFO size (2 KiB).
--- drivers/mtd/nand/pxa3xx_nand.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +16 -5
@@ -609,6 +609,9 @@ static void set_command_address(struct pxa3xx_nand_info *info,static void prepare_start_command (struct pxa3xx_nand_info *info,int command) { +struct pxa3xx_nand_host *host = info->host[info->cs]; +struct mtd_info *mtd = host->mtd; +/* reset data and oob column point to handle data */ info->buf_start =0 ; info->buf_count =0 ;
@@ -633,6 +636,19 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command) info->ndcb2 =0 ;break ; } + +/* +* If we are about to isse a read command, or about to set +* the write address, then clean the data buffer. +*/ +if (command ==NAND_CMD_READ0 || + command ==NAND_CMD_READOOB || + command ==NAND_CMD_SEQIN ) { + + info->buf_count = mtd->writesize + mtd->oobsize; +memset (info->data_buff,0xFF , info->buf_count); + } + } static int prepare_set_command(struct pxa3xx_nand_info *info, int command,
@@ -674,16 +690,11 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command, info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 );set_command_address (info, mtd->writesize, column, page_addr); - info->buf_count = mtd->writesize + mtd->oobsize; -memset (info->data_buff,0xFF , info->buf_count);break ;case NAND_CMD_SEQIN :set_command_address (info, mtd->writesize, column, page_addr); - info->buf_count = mtd->writesize + mtd->oobsize; -memset (info->data_buff,0xFF , info->buf_count); -break ;case NAND_CMD_PAGEPROG :
Signature · 1 line
1.8.1.5
PATCH v4 24/31 mtd: nand: pxa3xx: Fix SEQIN column address set
In reply to Ezequiel GarciaThis commit adds support page programming with a non-zero "column" address setting. This is important to support OOB writing, through command sequences such as:
cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, ofs); write_buf(mtd, oob_buf, 6); cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
--- drivers/mtd/nand/pxa3xx_nand.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/mtd/nand/pxa3xx_nand.c +2 -1
@@ -694,7 +694,8 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command,case NAND_CMD_SEQIN : -set_command_address (info, mtd->writesize, column, page_addr); + info->buf_start = column; +set_command_address (info, mtd->writesize,0 , page_addr);break ;case NAND_CMD_PAGEPROG :
Signature · 1 line
1.8.1.5
PATCH v4 25/31 mtd: nand: pxa3xx: Add a read/write buffers markers
In reply to Ezequiel GarciaIn preparation to support multiple (aka chunked, aka splitted) page I/O, this commit adds 'data_buff_pos' and 'oob_buff_pos' fields to keep track of where the next read (or write) should be done.
This will allow multiple calls to handle_data_pio() to continue the read (or write) operation.
--- drivers/mtd/nand/pxa3xx_nand.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +29 -11
@@ -176,6 +176,8 @@ struct pxa3xx_nand_info {unsigned int buf_start;unsigned int buf_count;unsigned int buf_size; +unsigned int data_buff_pos; +unsigned int oob_buff_pos;/* DMA information */ int drcmr_dat;
@@ -338,11 +340,12 @@ static void pxa3xx_nand_set_timing(struct pxa3xx_nand_host *host,* spare and ECC configuration. * Only applicable to READ0, READOOB and PAGEPROG commands. */ -static void pxa3xx_set_datasize (struct pxa3xx_nand_info *info) +static void pxa3xx_set_datasize (struct pxa3xx_nand_info *info, +struct mtd_info *mtd) {int oob_enable = info->reg_ndcr &NDCR_SPARE_EN ; - info->data_size = info->fifo_size; + info->data_size = mtd->writesize;if (!oob_enable)return ;
@@ -430,26 +433,39 @@ static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)static void handle_data_pio (struct pxa3xx_nand_info *info) { +unsigned int do_bytes =min (info->data_size, info->fifo_size); +switch (info->state) {case STATE_PIO_WRITING : -__raw_writesl (info->mmio_base +NDDB , info->data_buff, -DIV_ROUND_UP (info->data_size,4 )); +__raw_writesl (info->mmio_base +NDDB , + info->data_buff + info->data_buff_pos, +DIV_ROUND_UP (do_bytes,4 )); +if (info->oob_size >0 ) -__raw_writesl (info->mmio_base +NDDB , info->oob_buff, -DIV_ROUND_UP (info->oob_size,4 )); +__raw_writesl (info->mmio_base +NDDB , + info->oob_buff + info->oob_buff_pos, +DIV_ROUND_UP (info->oob_size,4 ));break ;case STATE_PIO_READING : -__raw_readsl (info->mmio_base +NDDB , info->data_buff, -DIV_ROUND_UP (info->data_size,4 )); +__raw_readsl (info->mmio_base +NDDB , + info->data_buff + info->data_buff_pos, +DIV_ROUND_UP (do_bytes,4 )); +if (info->oob_size >0 ) -__raw_readsl (info->mmio_base +NDDB , info->oob_buff, -DIV_ROUND_UP (info->oob_size,4 )); +__raw_readsl (info->mmio_base +NDDB , + info->oob_buff + info->oob_buff_pos, +DIV_ROUND_UP (info->oob_size,4 ));break ;default :dev_err (&info->pdev->dev,"%s: invalid state %d\n" , __func__, info->state);BUG (); } + +/* Update buffer pointers for multi-page read/write */ + info->data_buff_pos += do_bytes; + info->oob_buff_pos += info->oob_size; + info->data_size -= do_bytes; }#ifdef ARCH_HAS_DMA
@@ -616,6 +632,8 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command) info->buf_start =0 ; info->buf_count =0 ; info->oob_size =0 ; + info->data_buff_pos =0 ; + info->oob_buff_pos =0 ; info->use_ecc =0 ; info->use_spare =1 ; info->retcode =ERR_NONE ;
@@ -626,7 +644,7 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command)case NAND_CMD_PAGEPROG : info->use_ecc =1 ;case NAND_CMD_READOOB : -pxa3xx_set_datasize (info); +pxa3xx_set_datasize (info, mtd);break ;case NAND_CMD_PARAM : info->use_spare =0 ;
Signature · 1 line
1.8.1.5
PATCH v4 26/31 mtd: nand: pxa3xx: Introduce multiple page I/O support
In reply to Ezequiel GarciaAs preparation work to fully support large pages, this commit adds the initial infrastructure to support splitted (aka chunked) I/O operation. This commit adds support for read, and follow-up patches will add write support.
When a read (aka READ0) command is issued, the driver loops issuing the same command until all the requested data is transfered, changing the 'extended' command field as needed.
For instance, if the driver is required to read a 4 KiB page, using a chunk size of 2 KiB, the transaction is splitted in:
1. Monolithic read, first 2 KiB page chunk is read
2. Last naked read, second and last 2KiB page chunk is read
If ECC is enabled it is calculated on each chunk transfered and added at a controller-fixed location after the data chunk that must be spare area.
--- drivers/mtd/nand/pxa3xx_nand.c | 182 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 172 insertions(+), 10 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +172 -10
@@ -103,6 +103,8 @@#define NDCB0_ST_ROW_EN (0x1 << 26)#define NDCB0_AUTO_RS (0x1 << 25)#define NDCB0_CSEL (0x1 << 24) +#define NDCB0_EXT_CMD_TYPE_MASK (0x7 << 29) +#define NDCB0_EXT_CMD_TYPE (x) (((x) << 29) & NDCB0_EXT_CMD_TYPE_MASK)#define NDCB0_CMD_TYPE_MASK (0x7 << 21)#define NDCB0_CMD_TYPE (x) (((x) << 21) & NDCB0_CMD_TYPE_MASK)#define NDCB0_NC (0x1 << 20)
@@ -113,6 +115,14 @@#define NDCB0_CMD1_MASK (0xff)#define NDCB0_ADDR_CYC_SHIFT (16) +#define EXT_CMD_TYPE_DISPATCH 6/* Command dispatch */ +#define EXT_CMD_TYPE_NAKED_RW 5/* Naked read or Naked write */ +#define EXT_CMD_TYPE_READ 4/* Read */ +#define EXT_CMD_TYPE_DISP_WR 4/* Command dispatch with write */ +#define EXT_CMD_TYPE_FINAL 3/* Final command */ +#define EXT_CMD_TYPE_LAST_RW 1/* Last naked read/write */ +#define EXT_CMD_TYPE_MONO 0/* Monolithic read/write */ +/* macros for registers read/write */ #define nand_writel (info, off, val) \ __raw_writel((val), (info)->mmio_base + (off))
@@ -206,8 +216,8 @@ struct pxa3xx_nand_info {int use_spare;/* use spare ? */ int is_ready; -unsigned int fifo_size;/* max. data size in the FIFO */ unsigned int data_size;/* data to be read from FIFO */ +unsigned int chunk_size;/* split commands chunk size */ unsigned int oob_size;unsigned int spare_size;unsigned int ecc_size;
@@ -271,6 +281,31 @@ static struct nand_bbt_descr bbt_mirror_descr = { .pattern = bbt_mirror_pattern }; +static struct nand_ecclayout ecc_layout_4KB_bch4bit = { + .eccbytes =64 , + .eccpos = { +32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 , +40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 , +48 ,49 ,50 ,51 ,52 ,53 ,54 ,55 , +56 ,57 ,58 ,59 ,60 ,61 ,62 ,63 , +96 ,97 ,98 ,99 ,100 ,101 ,102 ,103 , +104 ,105 ,106 ,107 ,108 ,109 ,110 ,111 , +112 ,113 ,114 ,115 ,116 ,117 ,118 ,119 , +120 ,121 ,122 ,123 ,124 ,125 ,126 ,127 }, +/* Bootrom looks in bytes 0 & 5 for bad blocks */ + .oobfree = { {6 ,26 }, {64 ,32 } } +}; + +static struct nand_ecclayout ecc_layout_4KB_bch8bit = { + .eccbytes =128 , + .eccpos = { +32 ,33 ,34 ,35 ,36 ,37 ,38 ,39 , +40 ,41 ,42 ,43 ,44 ,45 ,46 ,47 , +48 ,49 ,50 ,51 ,52 ,53 ,54 ,55 , +56 ,57 ,58 ,59 ,60 ,61 ,62 ,63 }, + .oobfree = { } +}; +/* Define a default flash type setting serve as flash detecting only */ #define DEFAULT_FLASH_TYPE (&builtin_flash_types[0])
@@ -433,7 +468,7 @@ static void disable_int(struct pxa3xx_nand_info *info, uint32_t int_mask)static void handle_data_pio (struct pxa3xx_nand_info *info) { -unsigned int do_bytes =min (info->data_size, info->fifo_size); +unsigned int do_bytes =min (info->data_size, info->chunk_size);switch (info->state) {case STATE_PIO_WRITING :
@@ -670,7 +705,7 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command) }static int prepare_set_command (struct pxa3xx_nand_info *info,int command, -uint16_t column,int page_addr) +int ext_cmd_type,uint16_t column,int page_addr) {int addr_cycle, exec_cmd;struct pxa3xx_nand_host *host;
@@ -703,9 +738,20 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command,if (command ==NAND_CMD_READOOB ) info->buf_start += mtd->writesize; -/* Second command setting for large pages */ -if (mtd->writesize >=PAGE_CHUNK_SIZE ) +/* +* Multiple page read needs an 'extended command type' field, +* which is either naked-read or last-read according to the +* state. +*/ +if (mtd->writesize ==PAGE_CHUNK_SIZE ) { info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 ); + }else if (mtd->writesize >PAGE_CHUNK_SIZE ) { + info->ndcb0 |=NDCB0_DBC | (NAND_CMD_READSTART <<8 ) + |NDCB0_LEN_OVRD + |NDCB0_EXT_CMD_TYPE (ext_cmd_type); + info->ndcb3 = info->chunk_size + + info->oob_size; + }set_command_address (info, mtd->writesize, column, page_addr);break ;
@@ -821,7 +867,8 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command,prepare_start_command (info, command); info->state =STATE_PREPARED ; - exec_cmd =prepare_set_command (info, command, column, page_addr); + exec_cmd =prepare_set_command (info, command,0 , column, page_addr); +if (exec_cmd) {init_completion (&info->cmd_complete);init_completion (&info->dev_ready);
@@ -839,6 +886,93 @@ static void pxa3xx_nand_cmdfunc(struct mtd_info *mtd, unsigned command, info->state =STATE_IDLE ; } +static void armada370_nand_cmdfunc (struct mtd_info *mtd, +const unsigned command, +int column,int page_addr) +{ +struct pxa3xx_nand_host *host = mtd->priv; +struct pxa3xx_nand_info *info = host->info_data; +int ret, exec_cmd, ext_cmd_type; + +/* +* if this is a x16 device then convert the input +* "byte" address into a "word" address appropriate +* for indexing a word-oriented device +*/ +if (info->reg_ndcr &NDCR_DWIDTH_M ) + column /=2 ; + +/* +* There may be different NAND chip hooked to +* different chip select, so check whether +* chip select has been changed, if yes, reset the timing +*/ +if (info->cs != host->cs) { + info->cs = host->cs; +nand_writel (info,NDTR0CS0 , info->ndtr0cs0); +nand_writel (info,NDTR1CS0 , info->ndtr1cs0); + } + +/* Select the extended command for the first command */ +switch (command) { +case NAND_CMD_READ0 : +case NAND_CMD_READOOB : + ext_cmd_type =EXT_CMD_TYPE_MONO ; +break ; +default : + ext_cmd_type =0 ; + } + +prepare_start_command (info, command); + +/* +* Prepare the "is ready" completion before starting a command +* transaction sequence. If the command is not executed the +* completion will be completed, see below. +* +* We can do that inside the loop because the command variable +* is invariant and thus so is the exec_cmd. +*/ + info->is_ready =0 ; +init_completion (&info->dev_ready); +do { + info->state =STATE_PREPARED ; + exec_cmd =prepare_set_command (info, command, ext_cmd_type, + column, page_addr); +if (!exec_cmd) { + info->is_ready =1 ; +complete (&info->dev_ready); +break ; + } + +init_completion (&info->cmd_complete); +pxa3xx_nand_start (info); + + ret =wait_for_completion_timeout (&info->cmd_complete, +CHIP_DELAY_TIMEOUT ); +if (!ret) { +dev_err (&info->pdev->dev,"Wait time out!!!\n" ); +/* Stop State Machine for next command cycle */ +pxa3xx_nand_stop (info); +break ; + } + +/* Check if the sequence is complete */ +if (info->data_size ==0 ) +break ; + +if (command ==NAND_CMD_READ0 || command ==NAND_CMD_READOOB ) { +/* Last read: issue a 'last naked read' */ +if (info->data_size == info->chunk_size) + ext_cmd_type =EXT_CMD_TYPE_LAST_RW ; +else + ext_cmd_type =EXT_CMD_TYPE_NAKED_RW ; + } + }while (1 ); + + info->state =STATE_IDLE ; +} +static int pxa3xx_nand_write_page_hwecc (struct mtd_info *mtd,struct nand_chip *chip,const uint8_t *buf,int oob_required) {
@@ -1020,13 +1154,14 @@ static int pxa3xx_nand_detect_config(struct pxa3xx_nand_info *info)if (ndcr &NDCR_PAGE_SZ ) {/* Controller's FIFO size */ - info->fifo_size =2048 ; + info->chunk_size =2048 ; host->read_id_bytes =4 ; }else { - info->fifo_size =512 ; + info->chunk_size =512 ; host->read_id_bytes =2 ; } +/* Set an initial chunk size */ info->reg_ndcr = ndcr & ~NDCR_INT_MASK ; info->ndtr0cs0 =nand_readl (info,NDTR0CS0 ); info->ndtr1cs0 =nand_readl (info,NDTR1CS0 );
@@ -1130,6 +1265,7 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,* is used with non-ONFI compliant devices. */ if (page_size ==2048 ) { + info->chunk_size =2048 ; info->spare_size =40 ; info->ecc_size =24 ; ecc->mode =NAND_ECC_HW ;
@@ -1138,6 +1274,7 @@ static int pxa_ecc_init(struct pxa3xx_nand_info *info,return 1 ; }else if (page_size ==512 ) { + info->chunk_size =512 ; info->spare_size =8 ; info->ecc_size =8 ; ecc->mode =NAND_ECC_HW ;
@@ -1152,7 +1289,28 @@ static int armada370_ecc_init(struct pxa3xx_nand_info *info,struct nand_ecc_ctrl *ecc, int strength, int page_size) { - /* Unimplemented yet */ + if (strength == 4 && page_size == 4096) { + info->ecc_bch = 1; + info->chunk_size =2048 ; + info->spare_size =32 ; + info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch4bit; + ecc->strength =16 ; +return 1 ; + + } else if (strength == 8 && page_size == 4096) { + info->ecc_bch =1 ; + info->chunk_size =1024 ; + info->spare_size =0 ; + info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch8bit; + ecc->strength =16 ; +return 1 ; + }return 0 ; }
@@ -1320,12 +1478,16 @@ static int alloc_nand_resource(struct platform_device *pdev) chip->controller = &info->controller; chip->waitfunc = pxa3xx_nand_waitfunc; chip->select_chip = pxa3xx_nand_select_chip; - chip->cmdfunc = pxa3xx_nand_cmdfunc; chip->read_word = pxa3xx_nand_read_word; chip->read_byte = pxa3xx_nand_read_byte; chip->read_buf = pxa3xx_nand_read_buf; chip->write_buf = pxa3xx_nand_write_buf; chip->options |=NAND_NO_SUBPAGE_WRITE ; + +if (info->variant ==PXA3XX_NAND_VARIANT_ARMADA370 ) + chip->cmdfunc = armada370_nand_cmdfunc; +else + chip->cmdfunc = pxa3xx_nand_cmdfunc; }spin_lock_init (&chip->controller->lock);
Signature · 1 line
1.8.1.5
PATCH v4 26/31 mtd: nand: pxa3xx: Introduce multiple page I/O support
Hello,
I have a concern about the ECC mode and strength determination.
On Thu, Nov 07, 2013 at 12:17:30PM -0300, Ezequiel Garcia wrote:
[..]
Quoted 20 lines
drivers/mtd/nand/pxa3xx_nand.c +15
-1@@ -1152,7 +1289,28 @@ static int armada370_ecc_init(struct pxa3xx_nand_info *info,struct nand_ecc_ctrl *ecc, int strength, int page_size) { -/* Unimplemented yet */ + if (strength == 4 && page_size == 4096) { + info->ecc_bch = 1; + info->chunk_size =2048 ; + info->spare_size =32 ; + info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch4bit; + ecc->strength =16 ; +return 1 ; + + } else if (strength == 8 && page_size == 4096) { + info->ecc_bch =1 ; + info->chunk_size =1024 ; + info->spare_size =0 ;
drivers/mtd/nand/pxa3xx_nand.c static int armada370_ecc_init(struct pxa3xx_nand_info *info, · line 1316
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c +7
-0+ info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch8bit; + ecc->strength =16 ; +return 1 ; + }return 0 ; }
The above shows I tried to be very careful (aka paranoid) in the ECC mode determination. Please note that what I call "ECC mode", is determined by the chunk->size value only.
As the included documentation explains this controller supports two different BCH ECC strength: 16-over-1024, or 16-over-2048. Setting the chunk size to either 1024 or 2048 is what determines which of the above will actually take effect.
In past mails, we've refered to these two as BCH4 or BCH8, but this is not really accurate (as Brian has pointed out) so I droped that terms in favor of the real thing: 16 correctable bits over 1024 data bytes, or 16 correctable bits over 2048 data bytes.
In turn, such BCH mode setting affects heavily the page layout, because after each transfered chunk (which is either 1024+spare or 2048+spare) the controller reads and writes a 30B ECC region.
In other words, the kernel cannot arbitrarily change this setting, or the image won't be readable/writeable any longer.
For this reason, I'm starting to think the above method of picking the "ECC mode" based solely on the page size or the strength is slightly fragile (future developers might come and "improve" the driver breaking images).
Besides: what if a user wants the kernel to use a "higher" than required strength?
In conclusion: I'm starting to think a better (and long-term safer) approach is to set the ECC mode in the DT. I know this sucks, but from my point of view the flash device contains an image that "must" be read/write with a given ECC mode, and this ECC mode is by no means discoverable.
Now, let's suppose we want to set this in the DT: what property would we use? "marvell,nand-ecc-opt = 16-2048"? (a bit odd, no?).
What do you think?
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 26/31 mtd: nand: pxa3xx: Introduce multiple page I/O support
Hi,
I haven't taken a look at all your changes yet, but I'll get this comment off my chest while it's still fresh :)
Quoted 63 lines · Ezequiel Garcia
Hello,
I have a concern about the ECC mode and strength determination.
On Thu, Nov 07, 2013 at 12:17:30PM -0300, Ezequiel Garcia wrote:
[..]Quoted 20 lines
drivers/mtd/nand/pxa3xx_nand.c +15
-1@@ -1152,7 +1289,28 @@ static int armada370_ecc_init(struct pxa3xx_nand_info *info,struct nand_ecc_ctrl *ecc, int strength, int page_size) { -/* Unimplemented yet */ + if (strength == 4 && page_size == 4096) { + info->ecc_bch = 1; + info->chunk_size =2048 ; + info->spare_size =32 ; + info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch4bit; + ecc->strength =16 ; +return 1 ; + + } else if (strength == 8 && page_size == 4096) { + info->ecc_bch =1 ; + info->chunk_size =1024 ; + info->spare_size =0 ;drivers/mtd/nand/pxa3xx_nand.c static int armada370_ecc_init(struct pxa3xx_nand_info *info, · line 1316
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c +7
-0+ info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch8bit; + ecc->strength =16 ; +return 1 ; + }return 0 ; }The above shows I tried to be very careful (aka paranoid) in the ECC mode determination. Please note that what I call "ECC mode", is determined by the
chunk->sizevalue only.As the included documentation explains this controller supports two different BCH ECC strength: 16-over-1024, or 16-over-2048. Setting the chunk size to either 1024 or 2048 is what determines which of the above will actually take effect.
In past mails, we've refered to these two as BCH4 or BCH8, but this is not really accurate (as Brian has pointed out) so I droped that terms in favor of the real thing: 16 correctable bits over 1024 data bytes, or 16 correctable bits over 2048 data bytes.
In turn, such BCH mode setting affects heavily the page layout, because after each transfered chunk (which is either 1024+spare or 2048+spare) the controller reads and writes a 30B ECC region.
In other words, the kernel cannot arbitrarily change this setting, or the image won't be readable/writeable any longer.
For this reason, I'm starting to think the above method of picking the "ECC mode" based solely on the page size or the strength is slightly fragile (future developers might come and "improve" the driver breaking images).
Quoted 8 lines
Besides: what if a user wants the kernel to use a "higher" than required strength?
In conclusion: I'm starting to think a better (and long-term safer) approach is to set the ECC mode in the DT. I know this sucks, but from my point of view the flash device contains an image that "must" be read/write with a given ECC mode, and this ECC mode is by no means discoverable.
I think that's the way to go, in general. We can get by with "implementation defined behavior" (i.e., make the driver do what makes sense) for now, but to avoid breakage in the future, the bootloader needs to specify what ECC configuration is required -- via DT. But your current patch is still probably fine without it, since you're supporting new hardware.
Quoted 4 lines
Now, let's suppose we want to set this in the DT: what property would we use? "marvell,nand-ecc-opt = 16-2048"? (a bit odd, no?).
What do you think?
If ECC is purely determined by the chunk size, then why not just:
marvell,nand-chunk-size = 2048;
(with a value of 2048, 1024, or 512?)
Brian
PATCH v4 26/31 mtd: nand: pxa3xx: Introduce multiple page I/O support
Quoted 73 lines · Brian Norris
Quoted 63 lines · Ezequiel Garcia
Hello,
I have a concern about the ECC mode and strength determination.
On Thu, Nov 07, 2013 at 12:17:30PM -0300, Ezequiel Garcia wrote:
[..]Quoted 20 lines
drivers/mtd/nand/pxa3xx_nand.c +15
-1@@ -1152,7 +1289,28 @@ static int armada370_ecc_init(struct pxa3xx_nand_info *info,struct nand_ecc_ctrl *ecc, int strength, int page_size) { -/* Unimplemented yet */ + if (strength == 4 && page_size == 4096) { + info->ecc_bch = 1; + info->chunk_size =2048 ; + info->spare_size =32 ; + info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch4bit; + ecc->strength =16 ; +return 1 ; + + } else if (strength == 8 && page_size == 4096) { + info->ecc_bch =1 ; + info->chunk_size =1024 ; + info->spare_size =0 ;drivers/mtd/nand/pxa3xx_nand.c static int armada370_ecc_init(struct pxa3xx_nand_info *info, · line 1316
Quoted 10 lines
drivers/mtd/nand/pxa3xx_nand.c +7
-0+ info->ecc_size =32 ; + ecc->mode =NAND_ECC_HW ; + ecc->size = info->chunk_size; + ecc->layout = &ecc_layout_4KB_bch8bit; + ecc->strength =16 ; +return 1 ; + }return 0 ; }The above shows I tried to be very careful (aka paranoid) in the ECC mode determination. Please note that what I call "ECC mode", is determined by the
chunk->sizevalue only.As the included documentation explains this controller supports two different BCH ECC strength: 16-over-1024, or 16-over-2048. Setting the chunk size to either 1024 or 2048 is what determines which of the above will actually take effect.
In past mails, we've refered to these two as BCH4 or BCH8, but this is not really accurate (as Brian has pointed out) so I droped that terms in favor of the real thing: 16 correctable bits over 1024 data bytes, or 16 correctable bits over 2048 data bytes.
In turn, such BCH mode setting affects heavily the page layout, because after each transfered chunk (which is either 1024+spare or 2048+spare) the controller reads and writes a 30B ECC region.
In other words, the kernel cannot arbitrarily change this setting, or the image won't be readable/writeable any longer.
For this reason, I'm starting to think the above method of picking the "ECC mode" based solely on the page size or the strength is slightly fragile (future developers might come and "improve" the driver breaking images).
Quoted 8 lines
Besides: what if a user wants the kernel to use a "higher" than required strength?
In conclusion: I'm starting to think a better (and long-term safer) approach is to set the ECC mode in the DT. I know this sucks, but from my point of view the flash device contains an image that "must" be read/write with a given ECC mode, and this ECC mode is by no means discoverable.
Quoted 7 lines
I think that's the way to go, in general. We can get by with "implementation defined behavior" (i.e., make the driver do what makes sense) for now, but to avoid breakage in the future, the bootloader needs to specify what ECC configuration is required -- via DT. But your current patch is still probably fine without it, since you're supporting new hardware.
That sounds good. The ECC mode is currently "selected" in the driver to be the one that "makes sense". In follow up patches we'll add a proper DT binding, so this ECC mode can be set by the user.
The latter is an improvement over the former (adding more flexibility), so there won't be any regressions.
Just to confirm: I consider this patchset to be OK as it is, and I expect it to either get merged or receive some request for changes.
Oh, and by the way: we __really__ need someone to test for regressions on PXA.
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 26/31 mtd: nand: pxa3xx: Introduce multiple page I/O support
In reply to Brian NorrisQuoted 2 lines · Brian Norris
I haven't taken a look at all your changes yet, but I'll get this
Any comments on the v4?
I don't think there are any open issues to reply, but maybe my memory is failing, so feel free to refresh it :-)
I'll re-submit the series as soon as v3.13-rc1 is out.
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
PATCH v4 27/31 mtd: nand: pxa3xx: Add multiple chunk write support
In reply to Ezequiel GarciaThis commit adds write support for large pages (4 KiB, 8 KiB). Such support is implemented by issuing a multiple command sequence, transfering a set of 2 KiB chunks per transaction.
The splitted command sequence requires to send the SEQIN command independently of the PAGEPROG command and therefore it's set as an execution command.
Since PAGEPROG enables ECC, each 2 KiB chunk of data is written together with ECC code at a controller-fixed location within the flash page.
Currently, only devices with a 4 KiB page size has been tested.
--- drivers/mtd/nand/pxa3xx_nand.c | 81 +++++++++++++++++++++++++++++++++++++----- 1 file changed, 73 insertions(+), 8 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +73 -8
@@ -760,6 +760,20 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command, info->buf_start = column;set_command_address (info, mtd->writesize,0 , page_addr); + +/* +* Multiple page programming needs to execute the initial +* SEQIN command that sets the page address. +*/ +if (mtd->writesize >PAGE_CHUNK_SIZE ) { + info->ndcb0 |=NDCB0_CMD_TYPE (0x1 ) + |NDCB0_EXT_CMD_TYPE (ext_cmd_type) + | addr_cycle + | command; +/* No data transfer in this case */ + info->data_size =0 ; + exec_cmd =1 ; + }break ;case NAND_CMD_PAGEPROG :
@@ -769,13 +783,40 @@ static int prepare_set_command(struct pxa3xx_nand_info *info, int command,break ; } - info->ndcb0 |=NDCB0_CMD_TYPE (0x1 ) - |NDCB0_AUTO_RS - |NDCB0_ST_ROW_EN - |NDCB0_DBC - | (NAND_CMD_PAGEPROG <<8 ) - |NAND_CMD_SEQIN - | addr_cycle; +/* Second command setting for large pages */ +if (mtd->writesize >PAGE_CHUNK_SIZE ) { +/* +* Multiple page write uses the 'extended command' +* field. This can be used to issue a command dispatch +* or a naked-write depending on the current stage. +*/ + info->ndcb0 |=NDCB0_CMD_TYPE (0x1 ) + |NDCB0_LEN_OVRD + |NDCB0_EXT_CMD_TYPE (ext_cmd_type); + info->ndcb3 = info->chunk_size + + info->oob_size; + +/* +* This is the command dispatch that completes a chunked +* page program operation. +*/ +if (info->data_size ==0 ) { + info->ndcb0 =NDCB0_CMD_TYPE (0x1 ) + |NDCB0_EXT_CMD_TYPE (ext_cmd_type) + | command; + info->ndcb1 =0 ; + info->ndcb2 =0 ; + info->ndcb3 =0 ; + } + }else { + info->ndcb0 |=NDCB0_CMD_TYPE (0x1 ) + |NDCB0_AUTO_RS + |NDCB0_ST_ROW_EN + |NDCB0_DBC + | (NAND_CMD_PAGEPROG <<8 ) + |NAND_CMD_SEQIN + | addr_cycle; + }break ;case NAND_CMD_PARAM :
@@ -919,8 +960,15 @@ static void armada370_nand_cmdfunc(struct mtd_info *mtd,case NAND_CMD_READOOB : ext_cmd_type =EXT_CMD_TYPE_MONO ;break ; +case NAND_CMD_SEQIN : + ext_cmd_type =EXT_CMD_TYPE_DISPATCH ; +break ; +case NAND_CMD_PAGEPROG : + ext_cmd_type =EXT_CMD_TYPE_NAKED_RW ; +break ;default : ext_cmd_type =0 ; +break ; }prepare_start_command (info, command);
@@ -958,7 +1006,16 @@ static void armada370_nand_cmdfunc(struct mtd_info *mtd, }/* Check if the sequence is complete */ -if (info->data_size ==0 ) +if (info->data_size ==0 && command !=NAND_CMD_PAGEPROG ) +break ; + +/* +* After a splitted program command sequence has issued +* the command dispatch, the command sequence is complete. +*/ +if (info->data_size ==0 && + command ==NAND_CMD_PAGEPROG && + ext_cmd_type ==EXT_CMD_TYPE_DISPATCH )break ;if (command ==NAND_CMD_READ0 || command ==NAND_CMD_READOOB ) {
@@ -967,6 +1024,14 @@ static void armada370_nand_cmdfunc(struct mtd_info *mtd, ext_cmd_type =EXT_CMD_TYPE_LAST_RW ; else ext_cmd_type =EXT_CMD_TYPE_NAKED_RW ; + +/* +* If a splitted program command has no more data to transfer, +* the command dispatch must be issued to complete. +*/ + }else if (command ==NAND_CMD_PAGEPROG && + info->data_size ==0 ) { + ext_cmd_type =EXT_CMD_TYPE_DISPATCH ; } }while (1 );
Signature · 1 line
1.8.1.5
PATCH v4 28/31 mtd: nand: pxa3xx: Add ECC BCH correctable errors detection
In reply to Ezequiel GarciaThis commit extends the ECC correctable error detection to include ECC BCH errors. The number of BCH correctable errors can be any up to 16, and the actual value is exposed in the NDSR register.
Therefore, we change some symbol names to refer to correctable or uncorrectable (instead of single-bit or double-bit as it was in the Hamming case) and while at it, cleanup the detection code slightly.
--- drivers/mtd/nand/pxa3xx_nand.c | 57 ++++++++++++++++++++++++++---------------- 1 file changed, 35 insertions(+), 22 deletions(-)
drivers/mtd/nand/pxa3xx_nand.c +35 -22
@@ -85,6 +85,9 @@#define NDCR_INT_MASK (0xFFF)#define NDSR_MASK (0xfff) +#define NDSR_ERR_CNT_OFF (16) +#define NDSR_ERR_CNT_MASK (0x1f) +#define NDSR_ERR_CNT (sr) ((sr >> NDSR_ERR_CNT_OFF) & NDSR_ERR_CNT_MASK)#define NDSR_RDY (0x1 << 12)#define NDSR_FLASH_RDY (0x1 << 11)#define NDSR_CS0_PAGED (0x1 << 10)
@@ -93,8 +96,8 @@#define NDSR_CS1_CMDD (0x1 << 7)#define NDSR_CS0_BBD (0x1 << 6)#define NDSR_CS1_BBD (0x1 << 5) -#define NDSR_DBERR (0x1 << 4) -#define NDSR_SBERR (0x1 << 3) +#define NDSR_UNCORERR (0x1 << 4) +#define NDSR_CORERR (0x1 << 3)#define NDSR_WRDREQ (0x1 << 2)#define NDSR_RDDREQ (0x1 << 1)#define NDSR_WRCMDREQ (0x1)
@@ -135,9 +138,9 @@ enum {ERR_NONE =0 ,ERR_DMABUSERR =-1 ,ERR_SENDCMD =-2 , -ERR_DBERR =-3 , +ERR_UNCORERR =-3 ,ERR_BBERR =-4 , - ERR_SBERR = -5, + ERR_CORERR = -5, }; enum {
@@ -221,6 +224,8 @@ struct pxa3xx_nand_info {unsigned int oob_size;unsigned int spare_size;unsigned int ecc_size; +unsigned int ecc_err_cnt; +unsigned int max_bitflips;int retcode;/* cached register value */
@@ -571,10 +576,25 @@ static irqreturn_t pxa3xx_nand_irq(int irq, void *devid) status =nand_readl (info,NDSR ); -if (status &NDSR_DBERR ) - info->retcode =ERR_DBERR ; -if (status &NDSR_SBERR ) - info->retcode =ERR_SBERR ; +if (status &NDSR_UNCORERR ) + info->retcode =ERR_UNCORERR ; +if (status &NDSR_CORERR ) { + info->retcode =ERR_CORERR ; +if (info->variant ==PXA3XX_NAND_VARIANT_ARMADA370 && + info->ecc_bch) + info->ecc_err_cnt =NDSR_ERR_CNT (status); +else + info->ecc_err_cnt =1 ; + +/* +* Each chunk composing a page is corrected independently, +* and we need to store maximum number of corrected bitflips +* to return it to the MTD layer in ecc.read_page(). +*/ + info->max_bitflips = max_t(unsigned int, + info->max_bitflips, + info->ecc_err_cnt); + }if (status & (NDSR_RDDREQ |NDSR_WRDREQ )) {/* whether use dma to transfer data */ if (info->use_dma) {
@@ -672,6 +692,7 @@ static void prepare_start_command(struct pxa3xx_nand_info *info, int command) info->use_ecc =0 ; info->use_spare =1 ; info->retcode =ERR_NONE ; + info->ecc_err_cnt =0 ; info->ndcb3 =0 ;switch (command) {
@@ -1053,26 +1074,18 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, {struct pxa3xx_nand_host *host = mtd->priv;struct pxa3xx_nand_info *info = host->info_data; -int max_bitflips =0 ; chip->read_buf (mtd, buf, mtd->writesize); chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); -if (info->retcode ==ERR_SBERR ) { -switch (info->use_ecc) { -case 1 : - max_bitflips =1 ; - mtd->ecc_stats.corrected++; -break ; -case 0 : -default : -break ; - } - }else if (info->retcode ==ERR_DBERR ) { +if (info->retcode ==ERR_CORERR && info->use_ecc) { + mtd->ecc_stats.corrected += info->ecc_err_cnt; + + }else if (info->retcode ==ERR_UNCORERR ) {/* * for blank page (all 0xff), HW will calculate its ECC as * 0, which is different from the ECC information within -* OOB, ignore such double bit errors +* OOB, ignore such ucorrectable errors */ if (is_buf_blank (buf, mtd->writesize)) info->retcode =ERR_NONE ;
@@ -1080,7 +1093,7 @@ static int pxa3xx_nand_read_page_hwecc(struct mtd_info *mtd, mtd->ecc_stats.failed++; } -return max_bitflips; +return info->max_bitflips; }static uint8_t pxa3xx_nand_read_byte (struct mtd_info *mtd)
Signature · 1 line
1.8.1.5
PATCH v4 29/31 ARM: mvebu: Add support for NAND controller in Armada 370/XP
In reply to Ezequiel GarciaThe Armada 370 and Armada XP SoC have a NAND controller (aka NFCv2). This commit adds support for it in Armada 370 and Armada XP SoC common devicetree.
--- arch/arm/boot/dts/armada-370-xp.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/arm/boot/dts/armada-370-xp.dtsi +9 -0
@@ -258,6 +258,15 @@ status = "disabled"; }; + nand at d0000 { + compatible = "marvell,armada370-nand"; + reg = <0xd0000 0x54>; + #address-cells = <1>; + #size-cells = <1>; + interrupts = <113>; + clocks = <&coredivclk 0>; + status = "disabled"; + }; }; };
Signature · 1 line
1.8.1.5
PATCH v4 29/31 ARM: mvebu: Add support for NAND controller in Armada 370/XP
Quoted 8 lines · Ezequiel Garcia
The Armada 370 and Armada XP SoC have a NAND controller (aka NFCv2). This commit adds support for it in Armada 370 and Armada XP SoC common devicetree.
Signed-off-by Ezequiel Garcia <[email protected]>--- arch/arm/boot/dts/armada-370-xp.dtsi | 9 +++++++++ 1 file changed, 9 insertions(+)
Patches 29 (this one), 30 and 31 applied to mvebu/dt
I'll be working on the core-divider clock issue over the next couple of days.
thx,
Jason.
PATCH v4 30/31 ARM: mvebu: Enable NAND controller in Armada XP GP board
In reply to Ezequiel GarciaThe Armada XP GP board has a NAND flash, so enable it in the devicetree.
In order to skip the driver's custom device detection and use only ONFI detection, the "marvell,keep-config" parameter is used.
This is needed because we haven't support for setting the timings parameters yet and must rely in bootloader's.
--- arch/arm/boot/dts/armada-xp-gp.dts | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/arm/boot/dts/armada-xp-gp.dts +8 -0
@@ -175,6 +175,14 @@ spi-max-frequency = <108000000>; }; }; + + nand at d0000 { + status = "okay"; + num-cs = <1>; + marvell,nand-keep-config; + marvell,nand-enable-arbiter; + nand-on-flash-bbt; + }; }; }; };
Signature · 1 line
1.8.1.5
PATCH v4 31/31 ARM: mvebu: Enable NAND controller in Armada 370 Mirabox
In reply to Ezequiel GarciaThe Armada 370 Mirabox has a NAND flash, so enable it in the devicetree and add the partitions as prepared in the factory images.
In order to skip the driver's custom device detection and use only ONFI detection, the "marvell,keep-config" parameter is used.
This is needed because we have no support for setting the timings parameters yet.
--- arch/arm/boot/dts/armada-370-mirabox.dts | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm/boot/dts/armada-370-mirabox.dts +21 -0
@@ -139,6 +139,27 @@ reg = <0x25>; }; }; + + nand at d0000 { + status = "okay"; + num-cs = <1>; + marvell,nand-keep-config; + marvell,nand-enable-arbiter; + nand-on-flash-bbt; + + partition at 0 { + label = "U-Boot"; + reg = <0 0x400000>; + }; + partition at 400000 { + label = "Linux"; + reg = <0x400000 0x400000>; + }; + partition at 800000 { + label = "Filesystem"; + reg = <0x800000 0x3f800000>; + }; + }; }; }; };
Signature · 1 line
1.8.1.5
v4 cover Armada 370/XP NAND support
In reply to Ezequiel GarciaBrian,
If at all possible I would like the feedback not to stall, so the discussion (which is pretty complex) is still fresh in everybody's mind (specially mine!).
Thanks!
Quoted 144 lines · Ezequiel Garcia
Another version of the Armada 370/XP SoCs v3 patchset, addressing all the feedback provided by Brian Norris.
Please see
Documentation/mtd/nand/pxa3xx-nand.txtfor specific details about the controller and the driver.Just as the last version, the bad block factory initial detection issue is not addressed by this patchset, but support for it will be added in a near future once we decide the proper roadmap. See here the discussion about it:
http://permalink.gmane.org/gmane.linux.drivers.mtd/49401
As usual patches 1-4, adding the clock infrastructure have already been merged and will be dropped once this series can be based on v3.13-rc1. I'm including them just for completeness.
Based in l2-mtd's master branch. Also, I've pushed a branch to our github in case anyone wants to test it:
https://github.com/MISL-EBU-System-SW/mainline-public/tree/l2-mtd/upstream-nand-v4
As per Jason Cooper's suggestion I'm Ccing devicetree mailing list, to get a review on the small binding changes this patchset contains. If the devicetree people wants us to just Cc you on the relevant patches, just let us know.
Of course, there's some room for improvements in this driver, and I'll probably continue working on it. However, for now I'd like to focus in adding the strict minimum amount of changes required to support the new SoC family and pospone any improvements.
Thanks!
* Changes from v3 (feedback from Brian Norris)
* Add binding documentation for the nand-flash-bbt DT property.
* Expand in the documentation and in a comment the reason for setting the
NAND_BBT_NO_OOB_BBMoption.* Reworked the '
is_ready' completion handler. We still have two completions, but we've dropped theatomic_ttype as now the variable is no longer accesed from interruption context.* Fixed the
ecc.read_page()which lacked themax_bitflipreturn.* Reworked the ECC strength and size setting. This is important to allow the MTD layer to properly report on bitflip threshold situation.
* Dropped an unused
fifo_sizestate variable* Use '0' instead of the wrong '-1' when the extended command type doesn't matter or extended semantics are not supposed to be used.
* Changes from v2 (some minor fixes as per Huang's good feedback)
* Add some more details to the commit log in patch "mtd: nand: pxa3xx: Early variant detection"
* Add an empty line between variable declaration and function body
in patch "mtd: nand: pxa3xx: Use chip->cmdfunc instead of the internal".* Fix a build break caused by incomplete variable replacement:
"mtd: nand: pxa3xx: Replace host->page_size by mtd->writesize"* Changes from v1
Aside from several changes based in Brian's feedback, the main changes from v1 are:
* The controller's clock source is now fully modeled, see patche 1 to 4. Of course, none of those patches should be taken through the mtd subsystem, but I'm adding them here for completeness.
* The chip's
cmdfunc()is now independently implemented in each SoC variant. The rationale behind this decision is that 'chunked' I/O is the only tested mode on the Armada370 variant, while the old 'vanilla' I/O is the only tested mode on the PXA variant.So it's safer to have an implementation for each variant.
* Added support for BCH-8, in other words: 8-bits of correction in a 512-byte region. This is obtained by using a data chunk size of 1024B, thus doubling the ECC BCH strength, as per this ECC engine mechanism.
* The ECC layout in use, which must be set according to the page size and desired ECC strength is now strictly chosen to match only the tested combinations.
Ezequiel Garcia (31):
clk: mvebu: Add Core Divider clock
ARM: mvebu: Add Core Divider clock device-tree binding
ARM: mvebu: Add a 2 GHz fixed-clock Armada 370/XP
ARM: mvebu: Add the core-divider clock to Armada 370/XP
mtd: nand: pxa3xx: devicetree binding update
mtd: nand: pxa3xx: Add documentation about the controller
mtd: nand: pxa3xx: Make config menu show supported platforms
mtd: nand: pxa3xx: Prevent sub-page writes
mtd: nand: pxa3xx:read_page()returnsmax_bitflips
mtd: nand: pxa3xx: Early variant detection
mtd: nand: pxa3xx: Usechip->cmdfuncinstead of the internal
mtd: nand: pxa3xx: Split FIFO size from to-be-read FIFO count
mtd: nand: pxa3xx: Replacehost->page_sizebymtd->writesize
mtd: nand: pxa3xx: Add a nice comment topxa3xx_set_datasize()
mtd: nand: pxa3xx: Use a completion to signal device ready
mtd: nand: pxa3xx: Usewaitfunc()to wait for the device to be ready
mtd: nand: pxa3xx: Add bad block handling
mtd: nand: pxa3xx: Add driver-specific ECC BCH support
mtd: nand: pxa3xx: Clear cmd buffer #3 (NDCB3) on command start
mtd: nand: pxa3xx: Add helper function to set page address
mtd: nand: pxa3xx: Remove READ0 switch/case falltrough
mtd: nand: pxa3xx: Splitprepare_command_pool()in two stages
mtd: nand: pxa3xx: Move the data buffer clean to
prepare_start_command()
mtd: nand: pxa3xx: Fix SEQIN column address set
mtd: nand: pxa3xx: Add a read/write buffers markers
mtd: nand: pxa3xx: Introduce multiple page I/O support
mtd: nand: pxa3xx: Add multiple chunk write support
mtd: nand: pxa3xx: Add ECC BCH correctable errors detection
ARM: mvebu: Add support for NAND controller in Armada 370/XP
ARM: mvebu: Enable NAND controller in Armada XP GP board
ARM: mvebu: Enable NAND controller in Armada 370 Mirabox.../bindings/clock/mvebu-corediv-clock.txt | 19 + .../devicetree/bindings/mtd/pxa3xx-nand.txt | 6 +- Documentation/mtd/nand/pxa3xx-nand.txt | 113 ++++ arch/arm/boot/dts/armada-370-mirabox.dts | 21 + arch/arm/boot/dts/armada-370-xp.dtsi | 26 + arch/arm/boot/dts/armada-xp-gp.dts | 8 + drivers/clk/mvebu/Kconfig | 5 + drivers/clk/mvebu/Makefile | 1 + drivers/clk/mvebu/clk-corediv.c | 223 +++++++ drivers/mtd/nand/Kconfig | 4 +- drivers/mtd/nand/pxa3xx_nand.c | 678 ++++++++++++++++----- include/linux/platform_data/mtd-nand-pxa3xx.h | 3 + 12 files changed, 965 insertions(+), 142 deletions(-) create mode 100644 Documentation/devicetree/bindings/clock/mvebu-corediv-clock.txt create mode 100644 Documentation/mtd/nand/pxa3xx-nand.txt create mode 100644 drivers/clk/mvebu/clk-corediv.cSignature · 1 line
1.8.1.5
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com
v4 cover Armada 370/XP NAND support
In reply to Ezequiel GarciaHello,
Quoted 22 lines · Ezequiel Garcia
Another version of the Armada 370/XP SoCs v3 patchset, addressing all the feedback provided by Brian Norris.
Please see
Documentation/mtd/nand/pxa3xx-nand.txtfor specific details about the controller and the driver.Just as the last version, the bad block factory initial detection issue is not addressed by this patchset, but support for it will be added in a near future once we decide the proper roadmap. See here the discussion about it:
http://permalink.gmane.org/gmane.linux.drivers.mtd/49401
As usual patches 1-4, adding the clock infrastructure have already been merged and will be dropped once this series can be based on v3.13-rc1. I'm including them just for completeness.
Based in l2-mtd's master branch. Also, I've pushed a branch to our github in case anyone wants to test it:
https://github.com/MISL-EBU-System-SW/mainline-public/tree/l2-mtd/upstream-nand-v4
Quoted 9 lines
As per Jason Cooper's suggestion I'm Ccing devicetree mailing list, to get a review on the small binding changes this patchset contains. If the devicetree people wants us to just Cc you on the relevant patches, just let us know.
Of course, there's some room for improvements in this driver, and I'll probably continue working on it. However, for now I'd like to focus in adding the strict minimum amount of changes required to support the new SoC family and pospone any improvements.
After some powering issues, I could boot my PXA3xx board (CM-X300 from Compulab) and I've tested this patchset on it. In other words: no regression on PXA! both DMA and non-DMA works.
Daniel: feel free to confirm my check, but it's no longer required, in case you are too busy at the moment. I'll be able to test your dmaengine work on this board, so feel free to Cc me on it.
Big thanks to Compulab for sending me the board, and specially to Igor and Nikita!
Signature · 3 lines
Ezequiel Garc?a, Free Electrons Embedded Linux, Kernel and Android Engineering http://free-electrons.com