mtd: nand: vf610_nfc: Freescale NFC for VF610
Subsystems (3)
v11 cover mtd: nand: vf610_nfc: Freescale NFC for VF610
In this 11th revision the driver now rereads the OOB area in case hardware ECC fails. This allows to count the flipped bits accross the whole page reliably. Also the device tree bindings have been
updated: NAND chips can be specified using sub-nodes, the ECC properties are part of those chip nodes. Note however that the driver currently only supports one NAND chip. The driver has been verified again using the MTD tests.
More information and the full test log of earlier patchset version can be found in the cover letter of the last revision v6:
http://thread.gmane.org/gmane.linux.kernel/1979868
Changes since v10:
- Rebased onto l2-mtd/master
- Use children nodes for NAND chips in device tree bindings
- Support exactly one NAND chip using the new device tree bindings
- Reread page OOB on ECC error in order to reliable determine the amount of bit flips on a erased page
- Use ECC strength/2 as the only bit flip threshold
- Rely on endianness aware word read to read the ECC status
- Introduce vf610_nfc_variant which reflects the variant according to the device tree compatible string
- Use variant to determine chip select implementation
- Use enum for alternate buffer indication
- Renamed page_sz variable in struct vf610_nfc as well as in the function vf610_nfc_command to more specific names
- Some smaller code cleanup (altered ECC_SRAM_ADDR, introduce OOB_MAX)
Changes since v9:
- Remove inline of vf610_nfc_done
- Add __iomem to src argument of vf610_nfc_memcpy
- Handle return value of mtd_device_parse_register correctly
- Count bits in OOB too (only non-ECC bits)
- Return bitflips in ecc.read_page callback vf610_nfc_read_page
- Fall-through ALT_BUF_ONFI
- Use BIT macros
Changes since v8:
- Fix 16-Bit NAND flash support by splitting up initialization (introduce vf610_nfc_preinit_controller)
- Updated comments in initialziation functions
Changes since v7:
- vf610-twr.dts: Moved NFC pinmux into the existing iomuxc node and sort new nfc node behind the existing iomuxc node as well.
- vf610-twr.dts/vf-colibri.dtsi: Dropped _1 suffixes
Changes since v6:
- Rebased ontop of l2-mtd/master (v4.2-rc1 based)
- Removed HAVE_NAND_VF610_NFC and use depends on. This made "[PATCH v6 4/6] ARM: vf610: enable NAND Flash Controller" unnecessary
Changes since v5:
- Removed fsl,mpc5125-nfc compatible string
- Removed readl/writel_relaxed
- Change interface of vf610_nfc_transfer_size to match other accessors
Changes since v4:
- Rebased ontop of l2-mtd/master (v4.1-rc4 based)
- Eliminate unnecessary page read (NAND_CMD_SEQIN) since the driver does not support sub-page writes anyway (improves write performance)
- Support ONFI by enabling READID command with offset and parameter page reads (CMD_PARAM)
- Change to dedicated read_page/write_page function, enables raw writes
- Use __LITTLE_ENDIAN to distingush between LE/BE relevant statements
- Eliminated vf610_nfc_probe_dt in favor of common DT init code
- Use wait_for_completion_timeout
- Some style fixes (spaces, etc.)
Changes since v3:
- Make the driver selectable when COMPILE_TEST is set
- Fix compile error due to superfluous ECC_STATUS configuration in initial patch (without ECC correction ECC_STATUS does not need to be configured)
- Remove custom BBT pattern and switch to in-band BBT in the initial patch
- Include two bug fixes, for details see the corresponding U-Boot patches:
http://thread.gmane.org/gmane.comp.boot-loaders.u-boot/215802
Changes since v2:
- Updated binding documentation
Changes since v1:
- Nest nfc_config struct within the main nfc struct
- Use assigned clock binding to specify NFC clock
- Rebased ontop of MSCM IR patchset (driver parts have been merged)
- Split out arch Kconfig in a separate config
- Fix module license
- Updated MAINTAINERS
Changes since RFC (Bill Pringlemeir):
- Renamed driver from fsl_nfc to vf610_nfc
- Use readl/writel for all register in accessor functions
- Optimized field accessor functions
- Implemented PM (suspend/resume) functions
- Implemented basic support for ECC strength/ECC step size from dt
- Improved performance of count_written_bits by using hweight32
- Support ECC with 60-bytes to correct up to 32 bit errors
- Changed to in-band BBT (NAND_BBT_NO_OOB) which also allows ECC modes which uses up to 60 bytes on 64 byte OOB
- Removed custom (downstream) BBT pattern since BBT table won't be compatible anyway (due to the change above)
mtd_speedtest of this 11th revision on a Colibri VF61:
[ 2321.921612] ================================================= [ 2321.927459] mtd_speedtest: MTD device: 3 [ 2321.936619] mtd_speedtest: MTD device size 104857600, eraseblock size 131072, page size 2048, count of eraseblocks 800, pages per eraseblock 64, OOB size 64 [ 2321.954428] mtd_test: scanning for bad eraseblocks [ 2321.959626] mtd_test: block 142 is bad [ 2321.966038] mtd_test: scanned 800 eraseblocks, 1 are bad [ 2322.370120] mtd_speedtest: testing eraseblock write speed [ 2344.047677] mtd_speedtest: eraseblock write speed is 4718 KiB/s [ 2344.053687] mtd_speedtest: testing eraseblock read speed [ 2351.890573] mtd_speedtest: eraseblock read speed is 13059 KiB/s [ 2352.315120] mtd_speedtest: testing page write speed [ 2374.882015] mtd_speedtest: page write speed is 4533 KiB/s [ 2374.887526] mtd_speedtest: testing page read speed [ 2382.886572] mtd_speedtest: page read speed is 12791 KiB/s [ 2383.290314] mtd_speedtest: testing 2 page write speed [ 2405.362236] mtd_speedtest: 2 page write speed is 4634 KiB/s [ 2405.367925] mtd_speedtest: testing 2 page read speed [ 2413.299551] mtd_speedtest: 2 page read speed is 12901 KiB/s [ 2413.305228] mtd_speedtest: Testing erase speed [ 2413.707595] mtd_speedtest: erase speed is 257612 KiB/s [ 2413.712796] mtd_speedtest: Testing 2x multi-block erase speed [ 2414.110127] mtd_speedtest: 2x multi-block erase speed is 260897 KiB/s [ 2414.116656] mtd_speedtest: Testing 4x multi-block erase speed [ 2414.510316] mtd_speedtest: 4x multi-block erase speed is 264268 KiB/s [ 2414.516838] mtd_speedtest: Testing 8x multi-block erase speed [ 2414.908075] mtd_speedtest: 8x multi-block erase speed is 265641 KiB/s [ 2414.914607] mtd_speedtest: Testing 16x multi-block erase speed [ 2415.306958] mtd_speedtest: 16x multi-block erase speed is 264268 KiB/s [ 2415.313586] mtd_speedtest: Testing 32x multi-block erase speed [ 2415.702660] mtd_speedtest: 32x multi-block erase speed is 267028 KiB/s [ 2415.709270] mtd_speedtest: Testing 64x multi-block erase speed [ 2416.098225] mtd_speedtest: 64x multi-block erase speed is 266333 KiB/s [ 2416.104833] mtd_speedtest: finished [ 2416.108379] =================================================
Stefan Agner (5):
mtd: nand: vf610_nfc: Freescale NFC for VF610, MPC5125 and others
mtd: nand: vf610_nfc: add hardware BCH-ECC support
mtd: nand: vf610_nfc: add device tree bindings
ARM: dts: vf610twr: add NAND flash controller peripherial
ARM: dts: vf-colibri: enable NAND flash controller
.../devicetree/bindings/mtd/vf610-nfc.txt | 59 ++ MAINTAINERS | 6 + arch/arm/boot/dts/vf-colibri.dtsi | 39 + arch/arm/boot/dts/vf610-twr.dts | 47 ++ arch/arm/boot/dts/vfxxx.dtsi | 10 + drivers/mtd/nand/Kconfig | 11 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/vf610_nfc.c | 890 +++++++++++++++++++++ 8 files changed, 1063 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/vf610-nfc.txt create mode 100644 drivers/mtd/nand/vf610_nfc.c
Signature · 1 line
2.5.0
PATCH v11 1/5 mtd: nand: vf610_nfc: Freescale NFC for VF610, MPC5125 and others
This driver supports Freescale NFC (NAND flash controller) found on Vybrid (VF610), MPC5125, MCF54418 and Kinetis K70. The driver has been tested using 8-bit and 16-bit NAND interface on the ARM based Vybrid SoC VF500 and VF610 platform.
parameter page reading.
Limitations:
- Untested on MPC5125 and M54418.
- DMA and pipelining not used.
- 2K pages or less.
- No chip select, one NAND chip per controller.
- No hardware ECC.
Some paths have been hand-optimized and evaluated by measurements made using mtd_speedtest.ko on a 100MB MTD partition.
Colibri VF50
eb write % eb read % page write % page read %
rel/opt 5175 11537 4560 11039 opt 5164 -0.21 11420 -1.01 4737 +3.88 10918 -1.10 none 5113 -1.20 11352 -1.60 4490 -1.54 10865 -1.58
Colibri VF61
eb write % eb read % page write % page read %
rel/opt 5766 13096 5459 12846 opt 5883 +2.03 13064 -0.24 5561 +1.87 12802 -0.34 none 5701 -1.13 12980 -0.89 5488 +0.53 12735 -0.86
rel = using readl_relaxed/writel_relaxed in optimized paths opt = hand-optimized by combining multiple accesses into one read/write
The measurements have not been statistically verfied, hence use them with care. The author came to the conclusion that using the relaxed variants of readl/writel are not worth the additional code.
--- MAINTAINERS | 6 + drivers/mtd/nand/Kconfig | 9 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/vf610_nfc.c | 690 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 706 insertions(+) create mode 100644 drivers/mtd/nand/vf610_nfc.c
MAINTAINERS +6 -0
@@ -10835,6 +10835,12 @@ S: Maintained F: Documentation/fb/uvesafb.txt F: drivers/video/fbdev/uvesafb.* +VF610 NAND DRIVER +M: Stefan Agner <[email protected]> +L: linux-mtd at lists.infradead.org +S: Supported +F: drivers/mtd/nand/vf610_nfc.c + VFAT/FAT/MSDOS FILESYSTEM M: OGAWA Hirofumi <[email protected]> S: Maintained
drivers/mtd/nand/Kconfig +9 -0
@@ -460,6 +460,15 @@ config MTD_NAND_MPC5121_NFC This enables the driver for the NAND flash controller on the MPC5121 SoC. +config MTD_NAND_VF610_NFC + tristate "Support for Freescale NFC for VF610/MPC5125" + depends on (SOC_VF610 || COMPILE_TEST) + help + Enables support for NAND Flash Controller on some Freescale + processors like the VF610, MPC5125, MCF54418 or Kinetis K70. + The driver supports a maximum 2k page size. The driver + currently does not support hardware ECC. + config MTD_NAND_MXC tristate "MXC NAND support" depends on ARCH_MXC
drivers/mtd/nand/Makefile +1 -0
@@ -45,6 +45,7 @@ obj-$(CONFIG_MTD_NAND_SOCRATES) += socrates_nand.o obj-$(CONFIG_MTD_NAND_TXX9NDFMC) += txx9ndfmc.o obj-$(CONFIG_MTD_NAND_NUC900) += nuc900_nand.o obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mpc5121_nfc.o +obj-$(CONFIG_MTD_NAND_VF610_NFC) += vf610_nfc.o obj-$(CONFIG_MTD_NAND_RICOH) += r852.o obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/
drivers/mtd/nand/vf610_nfc.c new file +690 -0
690 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH v11 2/5 mtd: nand: vf610_nfc: add hardware BCH-ECC support
In reply to Stefan AgnerThis adds hardware ECC support using the BCH encoder in the NFC IP. The ECC encoder supports up to 32-bit correction by using 60 error correction bytes. There is no sub-page ECC step, ECC is calculated always accross the whole page (up to 2k pages).
Limitations:
- HW ECC: Only 2K page with 64+ OOB.
- HW ECC: Only 24 and 32-bit error correction implemented.
Raw writes have been tested using the generic nand_write_page_raw implementation. However, raw reads are currently not possible because the controller need to know whether we are going to use the ECC mode already at NAND_CMD_READ0 command time. At this point we do not have the information whether it is a raw read or a regular read at driver level...
--- drivers/mtd/nand/Kconfig | 6 +- drivers/mtd/nand/vf610_nfc.c | 204 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 206 insertions(+), 4 deletions(-)
drivers/mtd/nand/Kconfig +4 -2
@@ -466,8 +466,10 @@ config MTD_NAND_VF610_NFC help Enables support for NAND Flash Controller on some Freescale processors like the VF610, MPC5125, MCF54418 or Kinetis K70. - The driver supports a maximum 2k page size. The driver - currently does not support hardware ECC. + The driver supports a maximum 2k page size. With 2k pages and + 64 bytes or more of OOB, hardware ECC with up to 32-bit error + correction is supported. Hardware ECC is only enabled through + device tree. config MTD_NAND_MXC tristate "MXC NAND support"
drivers/mtd/nand/vf610_nfc.c +202 -2
291 lines not on this page · raw message
Signature · 1 line
2.5.0
Re: [PATCH v11 2/5] mtd: nand: vf610_nfc: add hardware BCH-ECC support
Quoted 24 lines · Stefan Agner
drivers/mtd/nand/vf610_nfc.c +24
-0+static inline int vf610_nfc_correct_data (struct mtd_info *mtd,uint8_t *dat, +uint8_t *oob,int page) +{ +struct vf610_nfc *nfc =mtd_to_nfc (mtd); +u32 ecc_status_off =NFC_MAIN_AREA (0 ) +ECC_SRAM_ADDR +ECC_STATUS ; +u8 ecc_status; +u8 ecc_count; +int flips; +int flips_threshold = nfc->chip.ecc.strength /2 ; + + ecc_status =vf610_nfc_read (nfc, ecc_status_off) &0xff ; + ecc_count = ecc_status &ECC_STATUS_ERR_COUNT ; + +if (!(ecc_status &ECC_STATUS_MASK )) +return ecc_count; + +/* Read OOB without ECC unit enabled */ +vf610_nfc_command (mtd,NAND_CMD_READOOB ,0 , page); +vf610_nfc_read_buf (mtd, oob, mtd->oobsize); + +/* +* On an erased page, bit count (including OOB) should be zero or +* at least less then half of the ECC strength. +*/
drivers/mtd/nand/vf610_nfc.c static void vf610_nfc_select_chip(struct mtd_info *mtd, int chip) · line 594
Quoted 10 lines
drivers/mtd/nand/vf610_nfc.c +10
-0+ flips =count_written_bits (dat, nfc->chip.ecc.size, flips_threshold); + flips +=count_written_bits (oob, mtd->oobsize, flips_threshold); + +if (unlikely (flips > flips_threshold)) +return -EINVAL ; + +/* Erased page. */ +memset (dat,0xff , nfc->chip.ecc.size); +memset (oob,0xff , mtd->oobsize); +return 0 ;
I guess I should return the amount of bitflips here. Will send out a v12 today.
--
Stefan
PATCH v11 3/5 mtd: nand: vf610_nfc: add device tree bindings
In reply to Stefan Agner--- .../devicetree/bindings/mtd/vf610-nfc.txt | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/vf610-nfc.txt
Documentation/devicetree/bindings/mtd/vf610-nfc.txt new file +59 -0
@@ -0,0 +1,59 @@ +Freescale's NAND flash controller (NFC) + +This variant of the Freescale NAND flash controller (NFC) can be found on +Vybrid (vf610), MPC5125, MCF54418 and Kinetis K70. + +Required properties: +- compatible: Should be set to "fsl,vf610-nfc". +- reg: address range of the NFC. +- interrupts: interrupt of the NFC. +- #address-cells: shall be set to 1. Encode the nand CS. +- #size-cells : shall be set to 0. +- assigned-clocks: main clock from the SoC, for Vybrid <&clks VF610_CLK_NFC>; +- assigned-clock-rates: The NAND bus timing is derived from this clock + rate and should not exceed maximum timing for any NAND memory chip + in a board stuffing. Typical NAND memory timings derived from this + clock are found in the SoC hardware reference manual. Furthermore, + there might be restrictions on maximum rates when using hardware ECC. + +- #address-cells, #size-cells : Must be present if the device has sub-nodes + representing partitions. + +Required children nodes: +Children nodes represent the available nand chips. Currently the driver can +only handle one NAND chip. + +Required properties: +- compatible: Should be set to "fsl,vf610-nfc-cs". +- nand-bus-width: see nand.txt +- nand-ecc-mode: see nand.txt + +Required properties for hardware ECC: +- nand-ecc-strength: supported strengths are 24 and 32 bit (see nand.txt) +- nand-ecc-step-size: step size equals page size, currently only 2k pages are + supported +- nand-on-flash-bbt: see nand.txt + +Example: + + nfc: nand at 400e0000 { + compatible = "fsl,vf610-nfc"; + #address-cells = <1>; + #size-cells = <1>; + reg = <0x400e0000 0x4000>; + interrupts = <GIC_SPI 83 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks VF610_CLK_NFC>; + clock-names = "nfc"; + assigned-clocks = <&clks VF610_CLK_NFC>; + assigned-clock-rates = <33000000>; + + nand at 0 { + compatible = "fsl,vf610-nfc-nandcs"; + reg = <0>; + nand-bus-width = <8>; + nand-ecc-mode = "hw"; + nand-ecc-strength = <32>; + nand-ecc-step-size = <2048>; + nand-on-flash-bbt; + }; + };
Signature · 1 line
2.5.0
PATCH v11 4/5 ARM: dts: vf610twr: add NAND flash controller peripherial
In reply to Stefan AgnerThis adds the NAND flash controller (NFC) peripherial. The driver supports the SLC NAND chips found on Freescale's Vybrid Tower System Module. The Micron NAND chip on the module needs 4-bit ECC per 512 byte page. Use 24-bit ECC per 2k page, which is supported by the driver.
--- arch/arm/boot/dts/vf610-twr.dts | 47 +++++++++++++++++++++++++++++++++++++++++ arch/arm/boot/dts/vfxxx.dtsi | 10 +++++++++ 2 files changed, 57 insertions(+)
arch/arm/boot/dts/vf610-twr.dts +47 -0
@@ -237,6 +237,33 @@ >; }; + pinctrl_nfc: nfcgrp { + fsl,pins = < + VF610_PAD_PTD31__NF_IO15 0x28df + VF610_PAD_PTD30__NF_IO14 0x28df + VF610_PAD_PTD29__NF_IO13 0x28df + VF610_PAD_PTD28__NF_IO12 0x28df + VF610_PAD_PTD27__NF_IO11 0x28df + VF610_PAD_PTD26__NF_IO10 0x28df + VF610_PAD_PTD25__NF_IO9 0x28df + VF610_PAD_PTD24__NF_IO8 0x28df + VF610_PAD_PTD23__NF_IO7 0x28df + VF610_PAD_PTD22__NF_IO6 0x28df + VF610_PAD_PTD21__NF_IO5 0x28df + VF610_PAD_PTD20__NF_IO4 0x28df + VF610_PAD_PTD19__NF_IO3 0x28df + VF610_PAD_PTD18__NF_IO2 0x28df + VF610_PAD_PTD17__NF_IO1 0x28df + VF610_PAD_PTD16__NF_IO0 0x28df + VF610_PAD_PTB24__NF_WE_B 0x28c2 + VF610_PAD_PTB25__NF_CE0_B 0x28c2 + VF610_PAD_PTB27__NF_RE_B 0x28c2 + VF610_PAD_PTC26__NF_RB_B 0x283d + VF610_PAD_PTC27__NF_ALE 0x28c2 + VF610_PAD_PTC28__NF_CLE 0x28c2 + >; + }; + pinctrl_pwm0: pwm0grp { fsl,pins = < VF610_PAD_PTB0__FTM0_CH0 0x1582
@@ -274,6 +301,26 @@ }; }; +&nfc { + assigned-clocks = <&clks VF610_CLK_NFC>; + assigned-clock-rates = <33000000>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_nfc>; + status = "okay"; + + nand at 0 { + compatible = "fsl,vf610-nfc-nandcs"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + nand-bus-width = <16>; + nand-ecc-mode = "hw"; + nand-ecc-strength = <24>; + nand-ecc-step-size = <2048>; + nand-on-flash-bbt; + }; +}; + &pwm0 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_pwm0>;
arch/arm/boot/dts/vfxxx.dtsi +10 -0
@@ -520,6 +520,16 @@ status = "disabled"; }; + nfc: nand at 400e0000 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "fsl,vf610-nfc"; + reg = <0x400e0000 0x4000>; + interrupts = <83 IRQ_TYPE_LEVEL_HIGH>; + clocks = <&clks VF610_CLK_NFC>; + clock-names = "nfc"; + status = "disabled"; + }; }; }; };
Signature · 1 line
2.5.0
PATCH v11 5/5 ARM: dts: vf-colibri: enable NAND flash controller
In reply to Stefan AgnerEnable NAND access by adding pinmux and NAND flash controller node to device tree. The NAND chips currently used on the Colibri VF61 requires 8-bit ECC per 512 byte page, hence specify 32-bit ECC strength per 2k page size.
--- arch/arm/boot/dts/vf-colibri.dtsi | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+)
arch/arm/boot/dts/vf-colibri.dtsi +39 -0
@@ -52,6 +52,26 @@ pinctrl-0 = <&pinctrl_i2c0>; }; +&nfc { + assigned-clocks = <&clks VF610_CLK_NFC>; + assigned-clock-rates = <33000000>; + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_nfc>; + status = "okay"; + + nand at 0 { + compatible = "fsl,vf610-nfc-nandcs"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + nand-bus-width = <8>; + nand-ecc-mode = "hw"; + nand-ecc-strength = <32>; + nand-ecc-step-size = <2048>; + nand-on-flash-bbt; + }; +}; + &pwm0 { pinctrl-names = "default"; pinctrl-0 = <&pinctrl_pwm0>;
@@ -156,6 +176,25 @@ >; }; + pinctrl_nfc: nfcgrp { + fsl,pins = < + VF610_PAD_PTD23__NF_IO7 0x28df + VF610_PAD_PTD22__NF_IO6 0x28df + VF610_PAD_PTD21__NF_IO5 0x28df + VF610_PAD_PTD20__NF_IO4 0x28df + VF610_PAD_PTD19__NF_IO3 0x28df + VF610_PAD_PTD18__NF_IO2 0x28df + VF610_PAD_PTD17__NF_IO1 0x28df + VF610_PAD_PTD16__NF_IO0 0x28df + VF610_PAD_PTB24__NF_WE_B 0x28c2 + VF610_PAD_PTB25__NF_CE0_B 0x28c2 + VF610_PAD_PTB27__NF_RE_B 0x28c2 + VF610_PAD_PTC26__NF_RB_B 0x283d + VF610_PAD_PTC27__NF_ALE 0x28c2 + VF610_PAD_PTC28__NF_CLE 0x28c2 + >; + }; + pinctrl_pwm0: pwm0grp { fsl,pins = < VF610_PAD_PTB0__FTM0_CH0 0x1182
Signature · 1 line
2.5.0