mtd: nand: add Broadcom NAND controller support
Subsystems (4)
cover mtd: nand: add Broadcom NAND controller support
Hi,
This adds (long in coming) support for the Broadcom BCM7xxx Set-Top Box NAND controller. This controller has been used in a variety of Broadcom SoCs.
There are a few more features I'd like add in the near future, mostly to support more SoCs, but this is the base set, which should only need relatively minor additions to support chips like BCM63138, BCM3384, and Cygnus/iProc. Particularly, we may need to straighten out some endianness issues for the data path on iProc, and interrupt enabling/acking on iProc, BCM63xxx, BCM3xxx, and others.
TODO: add this to the DTS(I) files for BCM7445.
Happy reviewing! (Speaking of which, I need to catch up on reviewing everybody else's MTD submissions...)
Brian
Brian Norris (3):
mtd: nand: add common DT init code
Documentation: devicetree: add binding doc for Broadcom NAND
controller
mtd: nand: add NAND driver for Broadcom STB NAND controller
.../devicetree/bindings/mtd/brcmstb_nand.txt | 109 + drivers/mtd/nand/Kconfig | 8 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/brcmstb_nand.c | 2182 ++++++++++++++++++++ drivers/mtd/nand/nand_base.c | 41 + include/linux/mtd/nand.h | 5 + 6 files changed, 2346 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/brcmstb_nand.txt create mode 100644 drivers/mtd/nand/brcmstb_nand.c
Signature · 6 lines
1.9.1 -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 1/3 mtd: nand: add common DT init code
These are already-documented common bindings for NAND chips. Let's handle them in nand_base.
If NAND controller drivers need to act on this data before bringing up the NAND chip (e.g., fill out ECC callback functions, change HW modes, etc.), then they can do so between calling nand_scan_ident() and nand_scan_tail().
--- drivers/mtd/nand/nand_base.c | 41 +++++++++++++++++++++++++++++++++++++++++ include/linux/mtd/nand.h | 5 +++++ 2 files changed, 46 insertions(+)
drivers/mtd/nand/nand_base.c +41 -0
@@ -48,6 +48,7 @@#include <linux/leds.h> #include <linux/io.h> #include <linux/mtd/partitions.h> +#include <linux/of_mtd.h> /* Define default oob placement schemes for large and small page devices */ static struct nand_ecclayout nand_oob_8 = {
@@ -3779,6 +3780,39 @@ ident_done:return type; } +static int nand_dt_init (struct mtd_info *mtd,struct nand_chip *chip, +struct device_node *dn) +{ +int ecc_mode, ecc_strength, ecc_step; + +if (of_get_nand_bus_width (dn) ==16 ) + chip->options |=NAND_BUSWIDTH_16 ; + +if (of_get_nand_on_flash_bbt (dn)) + chip->bbt_options |=NAND_BBT_USE_FLASH ; + + ecc_mode =of_get_nand_ecc_mode (dn); + ecc_strength =of_get_nand_ecc_strength (dn); + ecc_step =of_get_nand_ecc_step_size (dn); + +if ((ecc_step >=0 && !(ecc_strength >=0 )) || + (!(ecc_step >=0 ) && ecc_strength >=0 )) { +pr_err ("must set both strength and step size in DT\n" ); +return -EINVAL ; + } + +if (ecc_mode >=0 ) + chip->ecc.mode = ecc_mode; + +if (ecc_strength >=0 ) + chip->ecc.strength = ecc_strength; + +if (ecc_step >0 ) + chip->ecc.size = ecc_step; + +return 0 ; +} +/** * nand_scan_ident - [NAND Interface] Scan for the NAND device * @mtd: MTD device structure
@@ -3796,6 +3830,13 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,int i, nand_maf_id, nand_dev_id;struct nand_chip *chip = mtd->priv;struct nand_flash_dev *type; +int ret; + +if (chip->dn) { + ret =nand_dt_init (mtd, chip, chip->dn); +if (ret) +return ret; + }/* Set the default functions */ nand_set_defaults (chip, chip->options &NAND_BUSWIDTH_16 );
include/linux/mtd/nand.h +5 -0
@@ -26,6 +26,8 @@struct mtd_info ;struct nand_flash_dev ; +struct device_node ; +/* Scan and identify a NAND device */ extern int nand_scan (struct mtd_info *mtd,int max_chips);/*
@@ -542,6 +544,7 @@ struct nand_buffers {* flash device * @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the * flash device. +* @dn: [BOARDSPECIFIC] device node describing this instance * @read_byte: [REPLACEABLE] read one byte from the chip * @read_word: [REPLACEABLE] read one word from the chip * @write_byte: [REPLACEABLE] write a single byte to the chip on the
@@ -644,6 +647,8 @@ struct nand_chip {void __iomem *IO_ADDR_R ;void __iomem *IO_ADDR_W ; +struct device_node *dn; +uint8_t (*read_byte)(struct mtd_info *mtd);u16 (*read_word)(struct mtd_info *mtd);void (*write_byte)(struct mtd_info *mtd,uint8_t byte);
Signature · 1 line
1.9.1
PATCH 2/3 Documentation: devicetree: add binding doc for Broadcom NAND controller
In reply to Brian Norris--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +109 -0
@@ -0,0 +1,109 @@ +* Broadcom STB NAND Controller + +The Broadcom Set-Top Box NAND controller supports low-level access to raw NAND +flash chips. It has a memory-mapped register interface for both control +registers and for its data input/output buffer. On some SoCs, this controller is +paired with a custom DMA engine (inventively named "Flash DMA") which supports +basic PROGRAM and READ functions, among other features. + +This controller was originally designed for STB SoCs (BCM7xxx) but is now +available on a variety of Broadcom SoCs, including some BCM3xxx, BCM63xx, and +iProc/Cygnus. Its history includes several similar (but not fully register +compatible) versions. + +Required properties: +- compatible : should contain "brcm,brcmnand" and an appropriate version + compatibility string, like "brcm,brcmnand-v7.0" + Possible values: + brcm,brcmnand-v4.0 + brcm,brcmnand-v5.0 + brcm,brcmnand-v6.0 + brcm,brcmnand-v7.0 + brcm,brcmnand-v7.1 + brcm,brcmnand +- reg : the register start and length for NAND register region. + (optional) Flash DMA register range (if present) + (optional) NAND flash cache range (if at non-standard offset) +- reg-names : a list of the names corresponding to the previous register + ranges. Should contain "nand" and (optionally) + "flash-dma" and/or "nand-cache". +- interrupts : The NAND CTLRDY interrupt and (if Flash DMA is available) + FLASH_DMA_DONE +- interrupt-names : May be "nand_ctlrdy" or "flash_dma_done" +- interrupt-parent : See standard interrupt bindings +- #address-cells : <1> - subnodes give the chip-select number +- #size-cells : <0> + +Optional properties: +- brcm,nand-has-wp : Some versions of this IP include a write-protect + (WP) control bit. It is always available on >= + v7.0. Use this property to describe the rare + earlier versions of this core that include WP + +* NAND chip-select + +Each controller (compatible: "brcm,brcmnand") may contain one or more subnodes +to represent enabled chip-selects which (may) contain NAND flash chips. Their +properties are as follows. + +Required properties: +- compatible : should contain "brcm,nandcs" +- reg : a single integer representing the chip-select + number (e.g., 0, 1, 2, etc.) +- #address-cells : see partition.txt +- #size-cells : see partition.txt +- nand-ecc-strength : see nand.txt +- nand-ecc-step-size : must be 512 or 1024. See nand.txt + +Optional properties: +- nand-on-flash-bbt : boolean, to enable the on-flash BBT for this + chip-select. See nand.txt +- brcm,nand-oob-sector-size : integer, to denote the spare area sector size + expected for the ECC layout in use. This size, in + addition to the strength and step-size, + determines how the hardware BCH engine will lay + out the parity bytes it stores on the flash. + This property can be automatically determined by + the flash geometry (particularly the NAND page + and OOB size) in many cases, but when booting + from NAND, the boot controller has only a limited + number of available options for its default ECC + layout. + +Each nandcs device node may optionally contain sub-nodes describing the flash +partition mapping. See partition.txt for more detail. + +Example: + +nand@f0442800 { + compatible = "brcm,brcmnand-v7.0", "brcm,brcmnand"; + reg = <0xF0442800 0x600>, + <0xF0443000 0x100>; + reg-names = "nand", "flash-dma"; + interrupt-parent = <&hif_intr2_intc>; + interrupts = <24>, <4>; + + #address-cells = <1>; + #size-cells = <0>; + + nandcs@1 { + compatible = "brcm,nandcs"; + reg = <1>; // Chip select 1 + nand-on-flash-bbt; + nand-ecc-strength = <12>; + nand-ecc-step-size = <512>; + + // Partitions + #address-cells = <1>; // <2>, for 64-bit offset + #size-cells = <1>; // <2>, for 64-bit length + flash0.rootfs@0 { + reg = <0 0x10000000>; + }; + flash0@0 { + reg = <0 0>; // MTDPART_SIZ_FULL + }; + flash0.kernel@10000000 { + reg = <0x10000000 0x400000>; + }; + }; +};
Signature · 1 line
1.9.1
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
Quoted 1 line · Brian Norris
Signed-off-by Brian Norris <[email protected]>
Quoted 121 lines
--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/brcmstb_nand.txtDocumentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +109
-0@@ -0,0 +1,109 @@ +* Broadcom STB NAND Controller + +The Broadcom Set-Top Box NAND controller supports low-level access to raw NAND +flash chips. It has a memory-mapped register interface for both control +registers and for its data input/output buffer. On some SoCs, this controller is +paired with a custom DMA engine (inventively named "Flash DMA") which supports +basic PROGRAM and READ functions, among other features. + +This controller was originally designed for STB SoCs (BCM7xxx) but is now +available on a variety of Broadcom SoCs, including some BCM3xxx, BCM63xx, and +iProc/Cygnus. Its history includes several similar (but not fully register +compatible) versions. + +Required properties: +- compatible : should contain "brcm,brcmnand" and an appropriate version + compatibility string, like "brcm,brcmnand-v7.0" + Possible values: + brcm,brcmnand-v4.0 + brcm,brcmnand-v5.0 + brcm,brcmnand-v6.0 + brcm,brcmnand-v7.0 + brcm,brcmnand-v7.1 + brcm,brcmnand +- reg : the register start and length for NAND register region. + (optional) Flash DMA register range (if present) + (optional) NAND flash cache range (if at non-standard offset) +- reg-names : a list of the names corresponding to the previous register + ranges. Should contain "nand" and (optionally) + "flash-dma" and/or "nand-cache". +- interrupts : The NAND CTLRDY interrupt and (if Flash DMA is available) + FLASH_DMA_DONE +- interrupt-names : May be "nand_ctlrdy" or "flash_dma_done" +- interrupt-parent : See standard interrupt bindings +- #address-cells : <1> - subnodes give the chip-select number +- #size-cells : <0> + +Optional properties: +- brcm,nand-has-wp : Some versions of this IP include a write-protect + (WP) control bit. It is always available on >= + v7.0. Use this property to describe the rare + earlier versions of this core that include WP + +* NAND chip-select + +Each controller (compatible: "brcm,brcmnand") may contain one or more subnodes +to represent enabled chip-selects which (may) contain NAND flash chips. Their +properties are as follows. + +Required properties: +- compatible : should contain "brcm,nandcs" +- reg : a single integer representing the chip-select + number (e.g., 0, 1, 2, etc.) +- #address-cells : see partition.txt +- #size-cells : see partition.txt +- nand-ecc-strength : see nand.txt +- nand-ecc-step-size : must be 512 or 1024. See nand.txt + +Optional properties: +- nand-on-flash-bbt : boolean, to enable the on-flash BBT for this + chip-select. See nand.txt +- brcm,nand-oob-sector-size : integer, to denote the spare area sector size + expected for the ECC layout in use. This size, in + addition to the strength and step-size, + determines how the hardware BCH engine will lay + out the parity bytes it stores on the flash. + This property can be automatically determined by + the flash geometry (particularly the NAND page + and OOB size) in many cases, but when booting + from NAND, the boot controller has only a limited + number of available options for its default ECC + layout. + +Each nandcs device node may optionally contain sub-nodes describing the flash +partition mapping. See partition.txt for more detail. + +Example: + +nand@f0442800 { + compatible = "brcm,brcmnand-v7.0", "brcm,brcmnand"; + reg = <0xF0442800 0x600>, + <0xF0443000 0x100>; + reg-names = "nand", "flash-dma"; + interrupt-parent = <&hif_intr2_intc>; + interrupts = <24>, <4>; + + #address-cells = <1>; + #size-cells = <0>; + + nandcs@1 { + compatible = "brcm,nandcs"; + reg = <1>; // Chip select 1 + nand-on-flash-bbt; + nand-ecc-strength = <12>; + nand-ecc-step-size = <512>; + + // Partitions + #address-cells = <1>; // <2>, for 64-bit offset + #size-cells = <1>; // <2>, for 64-bit length + flash0.rootfs@0 { + reg = <0 0x10000000>; + }; + flash0@0 { + reg = <0 0>; // MTDPART_SIZ_FULL + }; + flash0.kernel@10000000 { + reg = <0x10000000 0x400000>; + }; + }; +};
Signature · 1 line
Florian
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
In reply to Brian NorrisHi Brian,
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Quoted 10 lines · Brian Norris
Signed-off-by Brian Norris <[email protected]>--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+)create mode 100644
Documentation/devicetree/bindings/mtd/brcmstb_nand.txtDocumentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +0
-1--- /dev/null
Could you change the binding document with the vendor prefix to match all the other drivers we have been submitting? ie. "brcm,brcmnand.txt"
Regards,
Scott
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
Quoted 7 lines · Scott Branden
Quoted 6 lines · Brian Norris
Signed-off-by Brian Norris <[email protected]>--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Quoted 8 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Quoted 4 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +0
-1--- /dev/nullCould you change the binding document with the vendor prefix to match all the other drivers we have been submitting? ie. "brcm,brcmnand.txt"
$ find Documentation/devicetree/ -name 'broadcom*' Documentation/devicetree/bindings/net/broadcom-systemport.txt Documentation/devicetree/bindings/net/broadcom-bcm87xx.txt Documentation/devicetree/bindings/net/broadcom-mdio-unimac.txt Documentation/devicetree/bindings/net/broadcom-bcmgenet.txt Documentation/devicetree/bindings/net/broadcom-sf2.txt
$ find Documentation/devicetree/ -name 'brcm[^,]*' Documentation/devicetree/bindings/arm/brcm-brcmstb.txt
$ find Documentation/devicetree/ -name 'brcm,*' Documentation/devicetree/bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt Documentation/devicetree/bindings/interrupt-controller/brcm,l2-intc.txt Documentation/devicetree/bindings/interrupt-controller/brcm,bcm7120-l2-intc.txt Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt Documentation/devicetree/bindings/i2c/brcm,iproc-i2c.txt Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt Documentation/devicetree/bindings/spi/brcm,bcm2835-spi.txt Documentation/devicetree/bindings/rng/brcm,bcm2835.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt Documentation/devicetree/bindings/bus/brcm,gisb-arb.txt Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt Documentation/devicetree/bindings/arm/bcm/brcm,bcm11351-cpu-method Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt Documentation/devicetree/bindings/timer/brcm,bcm2835-system-timer.txt
$ find Documentation/devicetree/bindings -name '*.txt' | grep -v ','| wc -l 1227 $ find Documentation/devicetree/bindings -name '*.txt' | grep ','| wc -l 352
So, what's the standard? Company prefix? Long name? Commas? Hyphens?
Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
Quoted 44 lines · Brian Norris
Quoted 7 lines · Scott Branden
Quoted 6 lines · Brian Norris
Signed-off-by Brian Norris <[email protected]>--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+)create mode 100644
Documentation/devicetree/bindings/mtd/brcmstb_nand.txtQuoted 8 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Quoted 4 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +0
-1--- /dev/nullCould you change the binding document with the vendor prefix to match all the other drivers we have been submitting? ie. "brcm,brcmnand.txt"
$ find Documentation/devicetree/ -name 'broadcom*' Documentation/devicetree/bindings/net/broadcom-systemport.txt Documentation/devicetree/bindings/net/broadcom-bcm87xx.txt Documentation/devicetree/bindings/net/broadcom-mdio-unimac.txt Documentation/devicetree/bindings/net/broadcom-bcmgenet.txt Documentation/devicetree/bindings/net/broadcom-sf2.txt$ find Documentation/devicetree/ -name 'brcm[^,]*' Documentation/devicetree/bindings/arm/brcm-brcmstb.txt$ find Documentation/devicetree/ -name 'brcm,*' Documentation/devicetree/bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt Documentation/devicetree/bindings/interrupt-controller/brcm,l2-intc.txt Documentation/devicetree/bindings/interrupt-controller/brcm,bcm7120-l2-intc.txt Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt Documentation/devicetree/bindings/i2c/brcm,iproc-i2c.txt Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt Documentation/devicetree/bindings/spi/brcm,bcm2835-spi.txt Documentation/devicetree/bindings/rng/brcm,bcm2835.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt Documentation/devicetree/bindings/bus/brcm,gisb-arb.txt Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt Documentation/devicetree/bindings/arm/bcm/brcm,bcm11351-cpu-method Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt Documentation/devicetree/bindings/timer/brcm,bcm2835-system-timer.txt
Quoted 6 lines
$ find Documentation/devicetree/bindings -name '*.txt' | grep -v ','| wc -l 1227 $ find Documentation/devicetree/bindings -name '*.txt' | grep ','| wc -l 352So, what's the standard? Company prefix? Long name? Commas? Hyphens?
The problem with devicetree binding is there is no standard for much of anything. Some others use the vendor prefix for all their binding documentation. We can try to do the same?
Quoted 3 lines
Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
Quoted 51 lines · Scott Branden
Quoted 49 lines · Brian Norris
Quoted 7 lines · Scott Branden
Quoted 6 lines · Brian Norris
Signed-off-by Brian Norris <[email protected]>--- .../devicetree/bindings/mtd/brcmstb_nand.txt | 109 +++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/brcmstb_nand.txtQuoted 8 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt
Quoted 4 lines
Documentation/devicetree/bindings/mtd/brcmstb_nand.txt new file +0
-1--- /dev/nullCould you change the binding document with the vendor prefix to match all the other drivers we have been submitting? ie. "brcm,brcmnand.txt"
$ find Documentation/devicetree/ -name 'broadcom*' Documentation/devicetree/bindings/net/broadcom-systemport.txt Documentation/devicetree/bindings/net/broadcom-bcm87xx.txt Documentation/devicetree/bindings/net/broadcom-mdio-unimac.txt Documentation/devicetree/bindings/net/broadcom-bcmgenet.txt Documentation/devicetree/bindings/net/broadcom-sf2.txt$ find Documentation/devicetree/ -name 'brcm[^,]*' Documentation/devicetree/bindings/arm/brcm-brcmstb.txt$ find Documentation/devicetree/ -name 'brcm,*' Documentation/devicetree/bindings/interrupt-controller/brcm,bcm2835-armctrl-ic.txt Documentation/devicetree/bindings/interrupt-controller/brcm,l2-intc.txt Documentation/devicetree/bindings/interrupt-controller/brcm,bcm7120-l2-intc.txt Documentation/devicetree/bindings/net/wireless/brcm,bcm43xx-fmac.txt Documentation/devicetree/bindings/i2c/brcm,iproc-i2c.txt Documentation/devicetree/bindings/i2c/brcm,bcm2835-i2c.txt Documentation/devicetree/bindings/spi/brcm,bcm2835-spi.txt Documentation/devicetree/bindings/rng/brcm,bcm2835.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm2835-gpio.txt Documentation/devicetree/bindings/pinctrl/brcm,bcm11351-pinctrl.txt Documentation/devicetree/bindings/bus/brcm,gisb-arb.txt Documentation/devicetree/bindings/watchdog/brcm,bcm2835-pm-wdog.txt Documentation/devicetree/bindings/arm/bcm/brcm,bcm11351-cpu-method Documentation/devicetree/bindings/mmc/brcm,bcm2835-sdhci.txt Documentation/devicetree/bindings/timer/brcm,bcm2835-system-timer.txt$ find Documentation/devicetree/bindings -name '*.txt' | grep -v ','| wc -l 1227 $ find Documentation/devicetree/bindings -name '*.txt' | grep ','| wc -l 352
Quoted 5 lines
Quoted 1 line
So, what's the standard? Company prefix? Long name? Commas? Hyphens?
The problem with devicetree binding is there is no standard for much of anything. Some others use the vendor prefix for all their binding documentation. We can try to do the same?
Ok, but we already have 3 versions for Broadcom. I can use 'brcm,' if that helps...
Brian
Re: [PATCH 2/3] Documentation: devicetree: add binding doc for Broadcom NAND controller
Hi Brian,
Quoted 6 lines · Brian Norris
Quoted 5 lines · Scott Branden
Quoted 2 lines · Brian Norris
On Mon, Mar 16, 2015 at 04:07:51PM -0700, Scott Branden wrote:
So, what's the standard? Company prefix? Long name? Commas? Hyphens?
Quoted 6 lines
Quoted 3 lines
The problem with devicetree binding is there is no standard for much of anything. Some others use the vendor prefix for all their binding documentation. We can try to do the same?
Ok, but we already have 3 versions for Broadcom. I can use 'brcm,' if that helps...
Yes, it helps if we try standardizing on the brcm vendor prefix in Documentation/devicetree/bindings/vendor-prefixes.txt. If you sift through the bindings directory you will find some of the other vendors have done the same.
Also, of note.
In Documentation/devicetree/bindings/submitting-patches.txt it states the Documentation should be the first patch in the series. Perhaps this helps the devicetree maintainer in reviewing bindings?
Scott
Quoted 3 lines
Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH 3/3 mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian NorrisThis core originated in Set-Top Box chips (BCM7xxx) but is used in a variety of other Broadcom chips, including some BCM63xxx, BCM33xx, and iProc/Cygnus. It's been used only on ARM and MIPS SoCs, so restrict it to those architectures.
There are multiple revisions of this core throughout the years, and almost every version broke register compatibility in some small way, but with some effort, this driver is able to support v4.0, v5.0, v6.x, v7.0, and v7.1. It's been tested on v5.0, v6.0, v7.0, and v7.1 recently, so there hopefully are no more lurking inconsistencies.
--- drivers/mtd/nand/Kconfig | 8 + drivers/mtd/nand/Makefile | 1 + drivers/mtd/nand/brcmstb_nand.c | 2182 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 2191 insertions(+) create mode 100644 drivers/mtd/nand/brcmstb_nand.c
drivers/mtd/nand/Kconfig +8 -0
@@ -394,6 +394,14 @@ config MTD_NAND_GPMI_NAND block, such as SD card. So pay attention to it when you enable the GPMI. +config MTD_NAND_BRCMSTB + tristate "Broadcom STB NAND controller" + depends on ARM || MIPS + help + Enables the Broadcom NAND controller driver. The controller was + originally designed for Set-Top Box but is used on various BCM7xxx, + BCM3xxx, BCM63xxx, iProc/Cygnus and more. + config MTD_NAND_BCM47XXNFLASH tristate "Support for NAND flash on BCM4706 BCMA bus" depends on BCMA_NFLASH
drivers/mtd/nand/Makefile +1 -0
@@ -52,5 +52,6 @@ obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/ obj-$(CONFIG_MTD_NAND_SUNXI) += sunxi_nand.o obj-$(CONFIG_MTD_NAND_HISI504) += hisi504_nand.o +obj-$(CONFIG_MTD_NAND_BRCMSTB) += brcmstb_nand.o nand-objs := nand_base.o nand_bbt.o nand_timings.o
drivers/mtd/nand/brcmstb_nand.c new file +2182 -0
2,182 lines not on this page · raw message
Signature · 1 line
1.9.1
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Only a license nit.
Brian Norris schreef op vr 06-03-2015 om 17:18 [-0800]:
Quoted 5 lines
drivers/mtd/nand/brcmstb_nand.c new file +2
-0@@ -0,0 +1,2182 @@ +/* +* Copyright © 2010-2015 Broadcom Corporation
drivers/mtd/nand/brcmstb_nand.c line 12
Quoted 10 lines
drivers/mtd/nand/brcmstb_nand.c new file +10
-0+* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/
This states the license is GPL v2.
drivers/mtd/nand/brcmstb_nand.c line 2178
Quoted 1 line
drivers/mtd/nand/brcmstb_nand.c new file +1
-0+MODULE_LICENSE ("GPL" );
So you probably want
MODULE_LICENSE("GPL v2");
here.
Paul Bolle
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 22 lines · Paul Bolle
Only a license nit.
Brian Norris schreef op vr 06-03-2015 om 17:18 [-0800]:
Quoted 5 lines
drivers/mtd/nand/brcmstb_nand.c new file +2
-0@@ -0,0 +1,2182 @@ +/* +* Copyright © 2010-2015 Broadcom Corporation drivers/mtd/nand/brcmstb_nand.c line 12
Quoted 10 lines
drivers/mtd/nand/brcmstb_nand.c new file +10
-0+* +* 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. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ This states the license is GPL v2.
Quoted 6 lines
drivers/mtd/nand/brcmstb_nand.c line 2178
Quoted 1 line
drivers/mtd/nand/brcmstb_nand.c new file +1
-0+MODULE_LICENSE ("GPL" );So you probably want
MODULE_LICENSE("GPL v2");here.
Thanks. Fixed.
Brian
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian Norrisdrivers/mtd/nand/brcmstb_nand.c line 2033
Quoted 5 lines · Brian Norris
drivers/mtd/nand/brcmstb_nand.c new file +5
-0+/* NAND register range */ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + ctrl->nand_base =devm_ioremap_resource (dev, res); +if (!ctrl->nand_base) +return -ENODEV ;
This is what I got during my first test:brcmstb_nand 11315e0.nand: can't request region for resource [mem 0x011315e0-0x011325df]
Unable to handle kernel paging request at virtual address fffffff0
(not sure why yet).
Hint: devm_ioremap_resource does never return NULL
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 7 lines · Rafał Miłecki
drivers/mtd/nand/brcmstb_nand.c line 2033
Quoted 5 lines · Brian Norris
drivers/mtd/nand/brcmstb_nand.c new file +5
-0+/* NAND register range */ + res =platform_get_resource (pdev,IORESOURCE_MEM ,0 ); + ctrl->nand_base =devm_ioremap_resource (dev, res); +if (!ctrl->nand_base) +return -ENODEV ;
Quoted 7 lines
This is what I got during my first test:
brcmstb_nand11315e0.nand: can't request region for resource [mem 0x011315e0-0x011325df]Unable to handle kernel paging request at virtual address fffffff0(not sure why yet).
Hint:
devm_ioremap_resourcedoes never return NULL
Thanks, fixed in 3 places.
I expect you've figured out your problem here by now.
Brian
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian NorrisQuoted 10 lines · Brian Norris
This core originated in Set-Top Box chips (BCM7xxx) but is used in a variety of other Broadcom chips, including some BCM63xxx, BCM33xx, and iProc/Cygnus. It's been used only on ARM and MIPS SoCs, so restrict it to those architectures.
There are multiple revisions of this core throughout the years, and almost every version broke register compatibility in some small way, but with some effort, this driver is able to support v4.0, v5.0, v6.x, v7.0, and v7.1. It's been tested on v5.0, v6.0, v7.0, and v7.1 recently, so there hopefully are no more lurking inconsistencies.
Unfortunately, it seems I can't make this driver work with my BCM4708 based router. This is a SoC with 6.01 controller.
Sometimes I get this:
[ 0.478443] brcmstb_nand 18028000.nand: timeout waiting for command 255 (9) [ 0.485385] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.588393] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.595326] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.698392] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.705322] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.711051] nand: second ID read did not match 20,20 against 20,00 [ 0.717197] nand: No NAND device found
Other time:
[ 0.478441] brcmstb_nand 18028000.nand: timeout waiting for command 255 (9) [ 0.485385] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.588396] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.595327] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.698393] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.705321] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.808394] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.815326] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.918392] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.925322] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.931047] nand: No NAND device found
(Btw. I guess you could use 0x%x instead of %d for printing commands).
It seems that brcmnand_ctlrdy_irq never fires on my device. Just like controller was never generating any IRQ.
I started comparing your driver with OpenWrt's bcm_nand.c (which should be very similar to Broadcom's SDK NAND driver for ARM). Below are few things I've noticed.
1) In bcm_nand.c IRQ handler also doesn't seem to be fired (or very rarely).
2) In brcmnand_waitfunc you seem to be always waiting for an interrupt. This is different from OpenWrt's driver and Broadcom's reference code. In bcm_nand.c in bcmnand_wait_cmd we first check BIT(31) of IRQ STATUS (0x6c / 0x14 / BRCMNAND_INTFC_STATUS). If it's set, we assume command was already completed.
3) In bcm_nand.c in IRQ waiting function bcmnand_wait_interrupt we ack/enable/disable NANDC_IRQ_CONTROLLER_RDY (nand_ctlrdy) IRQ. I don't see that in your code, not sure if it's important.
4) It seems bcm_nand.c also uses some extra register 0x500 and its bit 0x1 (we call it NANDC_IDM_IO_CTRL_RDY). It this bit it set, we don't ever care about NANDC_IRQ_CONTROLLER_RDY (nand_ctlrdy) IRQ.
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 38 lines · Rafał Miłecki
Quoted 10 lines · Brian Norris
This core originated in Set-Top Box chips (BCM7xxx) but is used in a variety of other Broadcom chips, including some BCM63xxx, BCM33xx, and iProc/Cygnus. It's been used only on ARM and MIPS SoCs, so restrict it to those architectures.
There are multiple revisions of this core throughout the years, and almost every version broke register compatibility in some small way, but with some effort, this driver is able to support v4.0, v5.0, v6.x, v7.0, and v7.1. It's been tested on v5.0, v6.0, v7.0, and v7.1 recently, so there hopefully are no more lurking inconsistencies.
Unfortunately, it seems I can't make this driver work with my BCM4708 based router. This is a SoC with 6.01 controller.
Sometimes I get this:
[ 0.478443] brcmstb_nand 18028000.nand: timeout waiting for command 255 (9) [ 0.485385] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.588393] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.595326] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.698392] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.705322] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.711051] nand: second ID read did not match 20,20 against 20,00 [ 0.717197] nand: No NAND device foundOther time:
[ 0.478441] brcmstb_nand 18028000.nand: timeout waiting for command 255 (9) [ 0.485385] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.588396] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.595327] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.698393] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.705321] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.808394] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.815326] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.918392] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 0.925322] brcmstb_nand 18028000.nand: intfc status f0000000 [ 0.931047] nand: No NAND device found
Quoted 4 lines
(Btw. I guess you could use 0x%x instead of %d for printing commands).
It seems that
brcmnand_ctlrdy_irqnever fires on my device. Just like controller was never generating any IRQ.
Oh, damn, I was doing sth stupid. I copied example from Documentation which has "brcm,nandcs" with reg = <1>;. That was wrong of course. after changing chip from 1 to 0 I got:
[ 1.688413] brcmstb_nand 18028000.nand: timeout waiting for command 255 (9) [ 1.695355] brcmstb_nand 18028000.nand: intfc status f0000000 [ 1.808384] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 1.815320] brcmstb_nand 18028000.nand: intfc status f0000000 [ 1.928385] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 1.935312] brcmstb_nand 18028000.nand: intfc status f0000000 [ 2.048460] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 2.055392] brcmstb_nand 18028000.nand: intfc status f0000000 [ 2.168386] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 2.175315] brcmstb_nand 18028000.nand: intfc status f0000000 [ 2.185640] nand: device found, Manufacturer ID: 0x92, Chip ID: 0xf1 [ 2.191967] nand: Eon NAND 128MiB 3,3V 8-bit [ 2.196221] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64 [ 2.203784] brcmstb_nand 18028000.nand: detected 128MiB total,
128KiB blocks, 2KiB pages, 16B OOB, 8-bit, BCH-8
So there is still problem with lacking IRQ (and timeouts), but at least communication with chip looks OK in general.
Of course the lost of log is also spammed in these "timeout waiting" and driver is unusable.
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Rafał MiłeckiQuoted 9 lines · Rafał Miłecki
It seems that
brcmnand_ctlrdy_irqnever fires on my device. Just like controller was never generating any IRQ.I started comparing your driver with OpenWrt's
bcm_nand.c(which should be very similar to Broadcom's SDK NAND driver for ARM). Below are few things I've noticed.1) In
bcm_nand.cIRQ handler also doesn't seem to be fired (or very rarely).
Oh, wait, I was wrong there. So in bcm_nand.c IRQ handler fires very often, just not during the early phase (RESET, READID), when we don't use IRQs. During standard read/program/etc IRQ is commonly used.
So maybe all we're missing in case of brcmstb_nand.c is enabling/acking/disabling IRQ?
It seem that my controller 6.01 has:
1) Following IRQs:DIREC_READ_MISSERASE_COMPLETECOPYBACK_COMPLETEPROGRAM_COMPLETECONTROLLER_RDYRDBSY_RDYECC_UNCORRECTABLEECC_CORRECTABLE
2) Registers for reading/acking above IRQs:0xf00 DIREC_READ_MISS0xf04 ERASE_COMPLETE0xf08 COPYBACK_COMPLETE0xf0c PROGRAM_COMPLETE0xf10 CONTROLLER_RDY0xf14 RDBSY_RDY0xf18 ECC_UNCORRECTABLE0xf1c ECC_CORRECTABLE
(if 0x1 is set, it means IRQ was raised, writing 0x1 ack-es it)
3) Register 0x408 for enabling/disabling IRQs:0x00000004 DIREC_READ_MISS0x00000008 ERASE_COMPLETE0x00000010 COPYBACK_COMPLETE0x00000020 PROGRAM_COMPLETE0x00000040 CONTROLLER_RDY0x00000080 RDBSY_RDY0x00000100 ECC_UNCORRECTABLE0x00000200 ECC_CORRECTABLE
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 9 lines · Rafał Miłecki
Quoted 8 lines · Rafał Miłecki
It seems that
brcmnand_ctlrdy_irqnever fires on my device. Just like controller was never generating any IRQ.I started comparing your driver with OpenWrt's
bcm_nand.c(which should be very similar to Broadcom's SDK NAND driver for ARM). Below are few things I've noticed.
Quoted 8 lines
Quoted 1 line
1) In
bcm_nand.cIRQ handler also doesn't seem to be fired (or very rarely).Oh, wait, I was wrong there. So in
bcm_nand.cIRQ handler fires very often, just not during the early phase (RESET, READID), when we don't use IRQs. During standard read/program/etc IRQ is commonly used.So maybe all we're missing in case of
brcmstb_nand.cis enabling/acking/disabling IRQ?
Yes, that's likely the main problem.
Quoted 11 lines
It seem that my controller 6.01 has:
1) Following IRQs:
DIREC_READ_MISSERASE_COMPLETECOPYBACK_COMPLETEPROGRAM_COMPLETECONTROLLER_RDYRDBSY_RDYECC_UNCORRECTABLEECC_CORRECTABLE
Right, that's the standard set of NAND interrupts. This driver only uses CONTROLLER_RDY, BTW.
Quoted 11 lines
2) Registers for reading/acking above IRQs:
0xf00DIREC_READ_MISS0xf04ERASE_COMPLETE0xf08COPYBACK_COMPLETE0xf0cPROGRAM_COMPLETE0xf10CONTROLLER_RDY0xf14RDBSY_RDY0xf18ECC_UNCORRECTABLE0xf1cECC_CORRECTABLE
(if0x1is set, it means IRQ was raised, writing0x1ack-es it)
Quoted 9 lines
3) Register
0x408for enabling/disabling IRQs:0x00000004DIREC_READ_MISS0x00000008ERASE_COMPLETE0x00000010COPYBACK_COMPLETE0x00000020PROGRAM_COMPLETE0x00000040CONTROLLER_RDY0x00000080RDBSY_RDY0x00000100ECC_UNCORRECTABLE0x00000200ECC_CORRECTABLE
(2) and (3) look pretty similar to the Cygnus chips. We should probably end up using the same solution for both. Several related to the Cygnus project are on CC.
One problem for Cygnus is that some of the other bits in their register 0x408 deal with non-interrupt-related functionality (endianness and clocks), so it might not make the cleanest design to handle this with an irqchip driver.
Brian
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 57 lines · Brian Norris
Quoted 9 lines · Rafał Miłecki
Quoted 8 lines · Rafał Miłecki
It seems that
brcmnand_ctlrdy_irqnever fires on my device. Just like controller was never generating any IRQ.I started comparing your driver with OpenWrt's
bcm_nand.c(which should be very similar to Broadcom's SDK NAND driver for ARM). Below are few things I've noticed.Quoted 8 lines
Quoted 1 line
1) In
bcm_nand.cIRQ handler also doesn't seem to be fired (or very rarely).Oh, wait, I was wrong there. So in
bcm_nand.cIRQ handler fires very often, just not during the early phase (RESET, READID), when we don't use IRQs. During standard read/program/etc IRQ is commonly used.So maybe all we're missing in case of
brcmstb_nand.cis enabling/acking/disabling IRQ?Yes, that's likely the main problem.
Quoted 11 lines
It seem that my controller 6.01 has:
1) Following IRQs:
DIREC_READ_MISSERASE_COMPLETECOPYBACK_COMPLETEPROGRAM_COMPLETECONTROLLER_RDYRDBSY_RDYECC_UNCORRECTABLEECC_CORRECTABLERight, that's the standard set of NAND interrupts. This driver only uses
CONTROLLER_RDY, BTW.Quoted 11 lines
2) Registers for reading/acking above IRQs:
0xf00DIREC_READ_MISS0xf04ERASE_COMPLETE0xf08COPYBACK_COMPLETE0xf0cPROGRAM_COMPLETE0xf10CONTROLLER_RDY0xf14RDBSY_RDY0xf18ECC_UNCORRECTABLE0xf1cECC_CORRECTABLE
(if0x1is set, it means IRQ was raised, writing0x1ack-es it)Quoted 9 lines
3) Register
0x408for enabling/disabling IRQs:0x00000004DIREC_READ_MISS0x00000008ERASE_COMPLETE0x00000010COPYBACK_COMPLETE0x00000020PROGRAM_COMPLETE0x00000040CONTROLLER_RDY0x00000080RDBSY_RDY0x00000100ECC_UNCORRECTABLE0x00000200ECC_CORRECTABLE
Quoted 8 lines
(2) and (3) look pretty similar to the Cygnus chips. We should probably end up using the same solution for both. Several related to the Cygnus project are on CC.
One problem for Cygnus is that some of the other bits in their register
0x408deal with non-interrupt-related functionality (endianness and clocks), so it might not make the cleanest design to handle this with an irqchip driver.
It's not just similar, but it's identical to Cygnus.
The register offset to read/ack the IRQ are the same. and Cygnus also uses a standard alone register to enable/disable IRQ (and their bit field is the same). Based on the link from Rafal, this chip also have the same issue with APB endianess control, clock control, interrupt control all stuffed in the same register:
#define NANDC_IDM_AXI_BIG_ENDIAN IDMREG_BIT_FIELD(0x408, 28, 1) #define NANDC_IDM_APB_LITTLE_ENDIAN IDMREG_BIT_FIELD(0x408, 24, 1) #define NANDC_IDM_TM IDMREG_BIT_FIELD(0x408, 16, 5) #define NANDC_IDM_IRQ_CORRECABLE_EN IDMREG_BIT_FIELD(0x408, 9, 1) #define NANDC_IDM_IRQ_UNCORRECABLE_EN IDMREG_BIT_FIELD(0x408, 8, 1) #define NANDC_IDM_IRQ_RDYBSY_RDY_EN IDMREG_BIT_FIELD(0x408, 7, 1) #define NANDC_IDM_IRQ_CONTROLLER_RDY_EN IDMREG_BIT_FIELD(0x408, 6, 1) #define NANDC_IDM_IRQ_PRPOGRAM_COMP_EN IDMREG_BIT_FIELD(0x408, 5, 1) #define NANDC_IDM_IRQ_COPYBK_COMP_EN IDMREG_BIT_FIELD(0x408, 4, 1) #define NANDC_IDM_IRQ_ERASE_COMP_EN IDMREG_BIT_FIELD(0x408, 3, 1) #define NANDC_IDM_IRQ_READ_MISS_EN IDMREG_BIT_FIELD(0x408, 2, 1) #define NANDC_IDM_IRQ_N_EN(n) IDMREG_BIT_FIELD(0x408, 2+(n), 1) #define NANDC_IDM_CLOCK_EN IDMREG_BIT_FIELD(0x408, 0, 1)
Quoted 3 lines
Brian
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian NorrisQuoted 6 lines · Brian Norris
drivers/mtd/nand/brcmstb_nand.c new file +6
-0+static int brcmnand_waitfunc (struct mtd_info *mtd,struct nand_chip *this) +{ +struct nand_chip *chip = mtd->priv; +struct brcmnand_host *host = chip->priv; +struct brcmnand_controller *ctrl = host->ctrl; +unsigned long timeo =msecs_to_jiffies (100 );
drivers/mtd/nand/brcmstb_nand.c line 1014
Quoted 10 lines
drivers/mtd/nand/brcmstb_nand.c new file +10
-0+ +dev_dbg (ctrl->dev,"wait on native cmd %d\n" , ctrl->cmd_pending); +if (ctrl->cmd_pending && +wait_for_completion_timeout (&ctrl->done, timeo) <=0 ) { +unsigned long cmd =brcmnand_read_reg (ctrl,BRCMNAND_CMD_START ) + >>brcmnand_cmd_shift (ctrl); + +dev_err_ratelimited (ctrl->dev, +"timeout waiting for command %u (%ld)\n" , + host->last_cmd, cmd);
I think that using host->last_cmd in the above message is really misleading. Please consider following:
[ 2.061139] [brcmnand_cmdfunc:1151] command:0x90 native_cmd:0x07 [ 2.067123] brcmstb_nand 18028000.nand: send native cmd 7 addr_lo 0x40 [ 2.168395] brcmstb_nand 18028000.nand: timeout waiting for command 144 (7) [ 2.175321] brcmstb_nand 18028000.nand: intfc status f0000000 [ 2.181051] nand: device found, Manufacturer ID: 0x92, Chip ID: 0xf1 [ 2.187370] nand: Eon NAND 128MiB 3,3V 8-bit [ 2.191632] nand: 128 MiB, SLC, erase size: 128 KiB, page size: 2048, OOB size: 64 [ 2.199192] brcmstb_nand 18028000.nand: detected 128MiB total, 128KiB blocks, 2KiB pages, 16B OOB, 8-bit, BCH-8 [ 2.199192] [ 2.210724] Scanning device for bad blocks [ 2.214812] brcmstb_nand 18028000.nand: send native cmd 1 addr_lo 0x0 [ 2.318394] brcmstb_nand 18028000.nand: timeout waiting for command 144 (1)
As you can see, first there was a brcmnand_cmdfunc call with 0x90 (NAND_CMD_READID). It was translated into internal command 0x07 (CMD_DEVICE_ID_READ).
Then there was a call to brcmnand_read_by_pio which resulted in sending internal command 0x01 (CMD_PAGE_READ). This one overwrote previous command. So the timeout wasn't about 144 (0x90) anymore.
I suggest replacing that with something like
"timeout waiting for internal command 0x%02x\n", cmd
--
To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian NorrisQuoted 5 lines · Brian Norris
This core originated in Set-Top Box chips (BCM7xxx) but is used in a variety of other Broadcom chips, including some BCM63xxx, BCM33xx, and iProc/Cygnus. It's been used only on ARM and MIPS SoCs, so restrict it to those architectures.
Quoted 8 lines
There are multiple revisions of this core throughout the years, and almost every version broke register compatibility in some small way, but with some effort, this driver is able to support v4.0, v5.0, v6.x, v7.0, and v7.1. It's been tested on v5.0, v6.0, v7.0, and v7.1 recently, so there hopefully are no more lurking inconsistencies.
Signed-off-by Brian Norris <[email protected]>---
Looks good to me, just one nitpick below:
[snip]
drivers/mtd/nand/brcmstb_nand.c line 374
Quoted 11 lines
drivers/mtd/nand/brcmstb_nand.c new file +11
-0+static int brcmnand_revision_init (struct brcmnand_controller *ctrl) +{ +static const unsigned int block_sizes_v6[] = {8 ,16 ,128 ,256 ,512 ,1024 ,2048 ,0 }; +static const unsigned int block_sizes_v4[] = {16 ,128 ,8 ,512 ,256 ,1024 ,2048 ,0 }; +static const unsigned int page_sizes[] = {512 ,2048 ,4096 ,8192 ,0 }; + + ctrl->nand_version =nand_readreg (ctrl,0 ) &0xffff ; + +/* Only support v4.0+? */ +if (ctrl->nand_version <0x0400 ) +return -ENODEV ;
It could be nice to have an informative error message here that this is either:
- an unknown controller revision (> 7.1)
- an older controller revision
- a check against the compatible property, just in case?
[snip]
drivers/mtd/nand/brcmstb_nand.c line 398
Quoted 7 lines
drivers/mtd/nand/brcmstb_nand.c new file +7
-0+ ctrl->cs_offsets = brcmnand_cs_offsets_v71; + }else { + ctrl->cs_offsets = brcmnand_cs_offsets; + +/* pre-v5.0 has a different CS0 offset layout */ +if (ctrl->nand_version <=0x0500 ) + ctrl->cs0_offsets = brcmnand_cs_offsets_cs0;
Based on this check, should the comment should be "pre-v5.0 and v5.0 have a different CS0 offset layout"?
Signature · 5 lines
Florian -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
Quoted 16 lines · Florian Fainelli
drivers/mtd/nand/brcmstb_nand.c line 374
Quoted 11 lines · Brian Norris
drivers/mtd/nand/brcmstb_nand.c new file +11
-0+static int brcmnand_revision_init (struct brcmnand_controller *ctrl) +{ +static const unsigned int block_sizes_v6[] = {8 ,16 ,128 ,256 ,512 ,1024 ,2048 ,0 }; +static const unsigned int block_sizes_v4[] = {16 ,128 ,8 ,512 ,256 ,1024 ,2048 ,0 }; +static const unsigned int page_sizes[] = {512 ,2048 ,4096 ,8192 ,0 }; + + ctrl->nand_version =nand_readreg (ctrl,0 ) &0xffff ; + +/* Only support v4.0+? */ +if (ctrl->nand_version <0x0400 ) +return -ENODEV ;It could be nice to have an informative error message here that this is either:
Quoted 3 lines
- an unknown controller revision (> 7.1)
- an older controller revision
- a check against the compatible property, just in case?
I'll add a message that the revision is not supported. The DT binding should catch this too, so this check is just an extra safeguard.
Quoted 12 lines
[snip]
drivers/mtd/nand/brcmstb_nand.c line 398
Quoted 7 lines
drivers/mtd/nand/brcmstb_nand.c new file +7
-0+ ctrl->cs_offsets = brcmnand_cs_offsets_v71; + }else { + ctrl->cs_offsets = brcmnand_cs_offsets; + +/* pre-v5.0 has a different CS0 offset layout */ +if (ctrl->nand_version <=0x0500 ) + ctrl->cs0_offsets = brcmnand_cs_offsets_cs0;Based on this check, should the comment should be "pre-v5.0 and v5.0 have a different CS0 offset layout"?
Yes. Fixed.
Brian
Re: [PATCH 3/3] mtd: nand: add NAND driver for Broadcom STB NAND controller
In reply to Brian Norris[snip]
drivers/mtd/nand/brcmstb_nand.c line 1321
Quoted 8 lines
drivers/mtd/nand/brcmstb_nand.c new file +8
-0+static int brcmnand_dma_trans (struct brcmnand_host *host,u64 addr,u32 *buf, +u32 len,u8 dma_cmd) +{ +struct brcmnand_controller *ctrl = host->ctrl; +dma_addr_t buf_pa; +int dir = dma_cmd ==CMD_PAGE_READ ?DMA_FROM_DEVICE :DMA_TO_DEVICE ; + + buf_pa =dma_map_single (ctrl->dev, buf, len, dir);
We are missing a dma_mapping_error() check here.
Signature · 1 line
Florian
Hi Brian,
Thanks for your work on this. It looks amazing, nice piece of code :)
Quoted 9 lines · Brian Norris
This adds (long in coming) support for the Broadcom BCM7xxx Set-Top Box NAND controller. This controller has been used in a variety of Broadcom SoCs.
There are a few more features I'd like add in the near future, mostly to support more SoCs, but this is the base set, which should only need relatively minor additions to support chips like BCM63138, BCM3384, and Cygnus/iProc. Particularly, we may need to straighten out some endianness issues for the data path on iProc, and interrupt enabling/acking on iProc, BCM63xxx, BCM3xxx, and others.
After applying workaround for not working IRQ, it seems I have some problem with endianess on my BCM4708 (SoC with 6.01 controller).
Let me start with dumps of "nvram" MTD partition.
1) Dumping with Netgear's original firmware:
# hexdump -C -n 16 mtdblock1.bin 00000000 46 4c 53 48 40 79 00 00 84 01 00 00 47 01 1c 08 |[email protected]...| 2) Dumping with OpenWrt and its bcm_nand.c: root@OpenWrt:/# hexdump -C -n 16 /dev/mtdblock1 00000000 46 4c 53 48 38 79 00 00 cb 01 00 00 47 01 1c 08 |FLSH8y......G...|
This makes me feel that bcm_nand.c driver is OK. Unfortunately when using brcmstb_nand.c my bcm47xxpart partition driver didn't detect any partition at all. This means I couldn't use any /dev/mtdblockX, not even user space as it wasn't mounted.
So since I didn't have user space, I decided to add some debugging to bcm47xxpart itself. There is what I got:
1) OpenWrt and its bcm_nand.c:
[bcm47xxpart_parse] 0x80000 46 4c 53 48 38 79 00 00 cb 01 00 00 47 01 1c 08
2) OpenWrt and brcmstb_nand.c:
[bcm47xxpart_parse] 0x80000 48 53 4c 46 00 00 79 38 00 00 01 cb 08 1c 01 47
So obviously data returned by brcmstb_nand.c seems to be all endianess-flipped. Could you take a loo at this?
Quoted 1 line · Rafał Miłecki
Thanks for your work on this. It looks amazing, nice piece of code :)
Thanks :) And thanks for testing this. I believe I suggested to you that I'd be releasing this "soon" several months ago. Better late than never, I guess?
Quoted 34 lines · Brian Norris
Quoted 9 lines
This adds (long in coming) support for the Broadcom BCM7xxx Set-Top Box NAND controller. This controller has been used in a variety of Broadcom SoCs.
There are a few more features I'd like add in the near future, mostly to support more SoCs, but this is the base set, which should only need relatively minor additions to support chips like BCM63138, BCM3384, and Cygnus/iProc. Particularly, we may need to straighten out some endianness issues for the data path on iProc, and interrupt enabling/acking on iProc, BCM63xxx, BCM3xxx, and others.
After applying workaround for not working IRQ, it seems I have some problem with endianess on my BCM4708 (SoC with 6.01 controller).
Let me start with dumps of "nvram" MTD partition.
1) Dumping with Netgear's original firmware:# hexdump -C -n 16 mtdblock1.bin 00000000 46 4c 53 48 40 79 00 00 84 01 00 00 47 01 1c 08 |[email protected]...| 2) Dumping with OpenWrt and its bcm_nand.c: root@OpenWrt:/# hexdump -C -n 16 /dev/mtdblock1 00000000 46 4c 53 48 38 79 00 00 cb 01 00 00 47 01 1c 08 |FLSH8y......G...|This makes me feel that
bcm_nand.cdriver is OK. Unfortunately when usingbrcmstb_nand.cmy bcm47xxpart partition driver didn't detect any partition at all. This means I couldn't use any/dev/mtdblockX, not even user space as it wasn't mounted.So since I didn't have user space, I decided to add some debugging to bcm47xxpart itself. There is what I got:
1) OpenWrt and itsbcm_nand.c:
[bcm47xxpart_parse]0x8000046 4c 53 48 38 79 00 00 cb 01 00 00 47 01 1c 08
2) OpenWrt andbrcmstb_nand.c:
[bcm47xxpart_parse]0x8000048 53 4c 46 00 00 79 38 00 00 01 cb 08 1c 01 47
Quoted 2 lines
So obviously data returned by
brcmstb_nand.cseems to be all endianess-flipped. Could you take a loo at this?
I'll take a look at all your comments/questions when I get back into the office, but a few pointers:
1. IRQs are a touchy subject; for platforms I've supported, I've found it best if the NAND interrupt bits are handled in an irqchip driver. Particularly, that's one of the use cases for drivers/irqchip/irq-brcmstb-l2.c. If you can arrange the NAND enable/ack registers to act as a second-level interrupt controller, that should hopefully solve your problems.
But if BCM4708's NAND interrupt registers can't be shaped into a sane irqchip driver, then we can probably handle them in a per-SoC extension of the driver. I have code already that supports another chip in this way, so I can point you that way if the first suggestion doesn't work out.
2. Endianness is a known issue with at least one other platform. On many chips (spanning MIPS LE, MIPS BE, and ARM LE), NAND has been integrated such that data can just be read/programmed in the native endianness through the FLASH_CACHE registers (as this driver does), but there are a few (on ARM, LE) that require a be32_to_cpu()/cpu_to_be32() swap. I'm considering supporting DT properties like one of the following:
brcm,nand-cache-be
brcm,nand-cache-big-endian
brcm,nand-cache-reverse-endian
You might also check (though I might actually be better equipped for this) if there is a separate register that can tell the NAND data bus to automatically endian-swap data into the native endianness. I know a lot of the buses and peripherals in BCG, at least, are designed such that either (1) they can work naturally in the CPU's native endianness or else (2) they can be configured to swap endianness into either format.
But if such a register does not exist, then we'll definitely have to do something like the DT property above.
Do the bad block markers look OK without extra endian swapping? I'm wondering whether the swapping will have to occur on both the FLASH_CACHE and SPARE_AREA registers.
3. I was told that there were only 2 or 3 chips that were released with a v6.1 NAND controller, and BCM4708 wasn't one of them. Apparently I was told wrong... I'll have to see if there are any other quirks we should be accounting for.
Brian
Quoted 18 lines · Brian Norris
2. Endianness is a known issue with at least one other platform. On many chips (spanning MIPS LE, MIPS BE, and ARM LE), NAND has been integrated such that data can just be read/programmed in the native endianness through the
FLASH_CACHEregisters (as this driver does), but there are a few (on ARM, LE) that require a be32_to_cpu()/cpu_to_be32() swap. I'm considering supporting DT properties like one of the following:brcm,nand-cache-be
brcm,nand-cache-big-endian
brcm,nand-cache-reverse-endianYou might also check (though I might actually be better equipped for this) if there is a separate register that can tell the NAND data bus to automatically endian-swap data into the native endianness. I know a lot of the buses and peripherals in BCG, at least, are designed such that either (1) they can work naturally in the CPU's native endianness or else (2) they can be configured to swap endianness into either format.
Quoted 2 lines
But if such a register does not exist, then we'll definitely have to do something like the DT property above.
It seems there is such a magic register. Please take a look at bcm_nand.c:
https://dev.openwrt.org/browser/trunk/target/linux/bcm53xx/patches-3.18/420-mtd-bcm5301x_nand.patch
There are multiple places (data, OOB, reads, writes) with:
/* Set controller to Little Endian mode for copying */ bcmnand_reg_awrite(ctrl, NANDC_IDM_APB_LITTLE_ENDIAN, 1);
/* Return to Big Endian mode for commands etc */ bcmnand_reg_awrite(ctrl, NANDC_IDM_APB_LITTLE_ENDIAN, 0);
That register is 0x408, but it's in "agent" core (AKA wrapper), so it's separated mapping. I'm not sure what address is it right now, as we read them from the EROM.
Quoted 3 lines
Do the bad block markers look OK without extra endian swapping? I'm wondering whether the swapping will have to occur on both the
FLASH_CACHEandSPARE_AREAregisters.
I don't know, I didn't try nand-on-flash-bbt.
Signature · 1 line
Rafał
Quoted 19 lines · Rafał Miłecki
Quoted 18 lines · Brian Norris
2. Endianness is a known issue with at least one other platform. On many chips (spanning MIPS LE, MIPS BE, and ARM LE), NAND has been integrated such that data can just be read/programmed in the native endianness through the
FLASH_CACHEregisters (as this driver does), but there are a few (on ARM, LE) that require a be32_to_cpu()/cpu_to_be32() swap. I'm considering supporting DT properties like one of the following:brcm,nand-cache-be
brcm,nand-cache-big-endian
brcm,nand-cache-reverse-endianYou might also check (though I might actually be better equipped for this) if there is a separate register that can tell the NAND data bus to automatically endian-swap data into the native endianness. I know a lot of the buses and peripherals in BCG, at least, are designed such that either (1) they can work naturally in the CPU's native endianness or else (2) they can be configured to swap endianness into either format.
Quoted 7 lines
Quoted 2 lines
But if such a register does not exist, then we'll definitely have to do something like the DT property above.
It seems there is such a magic register. Please take a look at
bcm_nand.c:
https://dev.openwrt.org/browser/trunk/target/linux/bcm53xx/patches-3.18/420-mtd-bcm5301x_nand.patchThere are multiple places (data, OOB, reads, writes) with:
So you do data and OOB in little endian? At least that seems consistent.
Quoted 11 lines
/* Set controller to Little Endian mode for copying */
bcmnand_reg_awrite(ctrl, NANDC_IDM_APB_LITTLE_ENDIAN, 1);/* Return to Big Endian mode for commands etc */
bcmnand_reg_awrite(ctrl, NANDC_IDM_APB_LITTLE_ENDIAN, 0);That register is
0x408, but it's in "agent" core (AKA wrapper), so it's separated mapping. I'm not sure what address is it right now, as we read them from the EROM.
Quoted 5 lines
Quoted 3 lines
Do the bad block markers look OK without extra endian swapping? I'm wondering whether the swapping will have to occur on both the
FLASH_CACHEandSPARE_AREAregisters.I don't know, I didn't try nand-on-flash-bbt.
You don't have to use on-flash BBT to notice. Without a flash-based BBT, you should just be scanning for bad block markers on *every* boot. Do you read factory-marked bad block markers correctly? Or maybe you see no factory bad blocks?
Note that this is sometimes hard to tell, if the factory just programmed the entire page + OOB to 0x00; then you obviously don't have to worry about endianness. But if they programmed a word of 0xffffff00, then you definitely do need to care!
Brian
Quoted 4 lines · Brian Norris
3. I was told that there were only 2 or 3 chips that were released with a v6.1 NAND controller, and BCM4708 wasn't one of them. Apparently I was told wrong... I'll have to see if there are any other quirks we should be accounting for.
Please note I'm speaking about 6.01, not 6.10. Maybe it make a difference?
Buffalo WZR-600DHP2 (BCM47081)
[ 0.325732] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 4.838105] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02
Buffalo WZR-1750DHP (BCM4708)
[ 0.326823] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 6.674288] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02
Netgear R6250 V1 (BCM4708)
[ 0.326248] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 8.721335] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02
Netgear R8000 (BCM4709)
[ 0.241961] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x00 [ 1.990330] bcm_nand bcma0:18: NAND Controller rev 6.01
Signature · 5 lines
Rafał -- To unsubscribe from this list: send the line "unsubscribe devicetree" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 16 lines · Rafał Miłecki
Quoted 4 lines · Brian Norris
3. I was told that there were only 2 or 3 chips that were released with a v6.1 NAND controller, and BCM4708 wasn't one of them. Apparently I was told wrong... I'll have to see if there are any other quirks we should be accounting for.
Please note I'm speaking about 6.01, not 6.10. Maybe it make a difference?
Buffalo WZR-600DHP2 (BCM47081)
[ 0.325732] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 4.838105] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02Buffalo WZR-1750DHP (BCM4708)
[ 0.326823] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 6.674288] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02
Quoted 7 lines
Netgear R6250 V1 (BCM4708)
[ 0.326248] [brcmnand_revision_init:371] ctrl->nand_version:0x0601 [ 8.721335] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x02Netgear R8000 (BCM4709)
[ 0.241961] bcma: bus0: Found chip with id 53010, rev 0x00 and package 0x00 [ 1.990330] bcm_nand bcma0:18: NAND Controller rev 6.01
We've never had a MINOR number larger than 4 or 5, I think, so I haven't actually bothered with two digits past the decimal. It's 8 bits of MAJOR and 8 bits of MINOR, but we just call it 6.1 in all our documentation.
0x0601 == v6.10x0701 == v7.1
I suppose if we ever have to care (e.g., we get past 7.9), we'd probably call it 7.10 (0x070a). Kinda like kernel versioning (and not like Ubuntu versioning).
Brian
A message that is not in the archive (sent off-list or not yet received): CALj_zD5rW3Se27Rh0pL6QTMNGOrrmrvAVLvW3BCuF8RujYQE=g@mail.gmail.com
(Your HTML mail will likely get blocked by a lot of filters)
Hi Anatol,
Quoted 9 lines · Anatol Pomazau
Hi Brian
Thanks for the patch series. I am going to test it on a Broadcom dev board.
Do you plan to add a patch for
bcm-cygnus.dtsisimilar to what is done here https://github.com/Broadcom/cygnus-linux/commit/1de02697829c3a2ce48a1bc29a8535e4961999ca?
Not yet. As I note below, this does not work as-is on Cygnus. I wanted to get the initial code out there, as this already supports some chips. There as still some additions necessary to get iProc/Cygnus and BCM53xxx chips working (WIP).
The code you link to is a hacked version from Ray. His changes have not been integrated yet.
Quoted 9 lines
On Fri, Mar 6, 2015 at 5:18 PM, Brian Norris <[email protected]> wrote:
Hi,This adds (long in coming) support for the Broadcom BCM7xxx Set-Top Box NAND
controller. This controller has been used in a variety of Broadcom SoCs.
Quoted 11 lines
There are a few more features I'd like add in the near future, mostly to
support more SoCs, but this is the base set, which should only need relatively
minor additions to support chips like BCM63138, BCM3384, and Cygnus/ iProc.
Particularly, we may need to straighten out some endianness issues for the data
path on iProc, and interrupt enabling/acking on iProc, BCM63xxx, BCM3xxx, and
others.
^^^ Note the previous 2 sentences.
Quoted 7 lines
TODO: add this to the DTS(I) files for BCM7445.
Happy reviewing! (Speaking of which, I need to catch up on reviewing everybody
else's MTD submissions...)Brian
Brian