NXP SPIFI driver for LPC18xx/43xx familiy
Subsystems (3)
v2 cover NXP SPIFI driver for LPC18xx/43xx familiy
This patch set adds a SPI-NOR driver for the NXP SPI Flash (SPIFI) controller that can be found on newer NXP MCUs. For example on the LPC18xx and LPC43xx familiy.
NXP SPIFI is a specialized SPI interface for serial Flash devices. It supports one Flash device with 1-, 2- and 4-bits width in SPI mode 0 or 3. The controller operates in either command or memory mode. In memory mode the Flash is made accessible for the CPU as normal memory.
This version address the comments from Ezequiel Garcia.
See: http://marc.info/?l=linux-arm-kernel&m=143300098616001&w=2
Changes since v1:
- use readb_poll_timeout instead of open coding
- cache current mode (memory/command)
- depend on HAS_IOMEM
- removed stray white space
- removed leftover debug print
Support for LPC18xx/43xx can found in linux-next now.
Patch against l2-mtd.git master branch.
Joachim Eastwood (2):
mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)
doc: dt: add documentation for nxp,lpc1773-spifi
.../devicetree/bindings/mtd/nxp-spifi.txt | 56 +++ drivers/mtd/spi-nor/Kconfig | 11 + drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 491 +++++++++++++++++++++ 4 files changed, 559 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/nxp-spifi.txt create mode 100644 drivers/mtd/spi-nor/nxp-spifi.c
Signature · 1 line
1.8.0
PATCH v2 1/2 mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)
Add SPI-NOR driver for the SPI Flash Interface (SPIFI) controller that is found newer NXP MCU devices.
The controller supports serial SPI Flash devices with 1-, 2- and 4-bit width in either SPI mode 0 or 3. The controller can operate in either command or memory mode. In memory mode the Flash is exposed as normal memory and can be directly accessed by the CPU.
--- drivers/mtd/spi-nor/Kconfig | 11 + drivers/mtd/spi-nor/Makefile | 1 + drivers/mtd/spi-nor/nxp-spifi.c | 491 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 503 insertions(+) create mode 100644 drivers/mtd/spi-nor/nxp-spifi.c
drivers/mtd/spi-nor/Kconfig +11 -0
@@ -28,4 +28,15 @@ config SPI_FSL_QUADSPI This enables support for the Quad SPI controller in master mode. We only connect the NOR to this controller now. +config SPI_NXP_SPIFI + tristate "NXP SPI Flash Interface (SPIFI)" + depends on OF && (ARCH_LPC18XX || COMPILE_TEST) + depends on HAS_IOMEM + help + Enable support for the NXP LPC SPI Flash Interface controller. + + SPIFI is a specialized controller for connecting serial SPI + Flash. Enable this option if you have a device with a SPIFI + controller and want to access the Flash as a mtd device. + endif # MTD_SPI_NOR
drivers/mtd/spi-nor/Makefile +1 -0
@@ -1,2 +1,3 @@ obj-$(CONFIG_MTD_SPI_NOR) += spi-nor.o obj-$(CONFIG_SPI_FSL_QUADSPI) += fsl-quadspi.o +obj-$(CONFIG_SPI_NXP_SPIFI) += nxp-spifi.o
drivers/mtd/spi-nor/nxp-spifi.c new file +491 -0
491 lines not on this page · raw message
Signature · 1 line
1.8.0
PATCH v2 1/2 mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)
Joachim,
I tested the driver and found an issue with it.
Quoted 18 lines · Joachim Eastwood
drivers/mtd/spi-nor/nxp-spifi.c new file +18
-0+ + spifi->mtd.priv = &spifi->nor; + spifi->nor.mtd = &spifi->mtd; + spifi->nor.dev = spifi->dev; + spifi->nor.priv = spifi; + spifi->nor.read = nxp_spifi_read; + spifi->nor.write = nxp_spifi_write; + spifi->nor.erase = nxp_spifi_erase; + spifi->nor.read_reg = nxp_spifi_read_reg; + spifi->nor.write_reg = nxp_spifi_write_reg; + + ret =of_modalias_node (np, modalias,sizeof (modalias)); +if (ret <0 ) { +dev_err (spifi->dev,"unable to get device modalias\n" ); +return ret; + } + +/*
drivers/mtd/spi-nor/nxp-spifi.c line 363
Quoted 10 lines
drivers/mtd/spi-nor/nxp-spifi.c new file +10
-0+* The first read on a hard reset isn't reliable so do a +* dummy read of the id before calling spi_nor_scan(). +* The reason for this problem is unknown. +* +* The official NXP spifilib uses more or less the same +* workaround that is applied here by reading the device +* id multiple times. +*/ +nxp_spifi_dummy_id_read (&spifi->nor); +
Actually, I think there's an issue here. See how m25p80 deals with modalias:
[..]
else if (!strcmp(spi->modalias, "spi-nor"))
flash_name = NULL; /* auto-detect */
else
flash_name = spi->modalias;
ret = spi_nor_scan(nor, flash_name, mode);
if (ret)
return ret;I think the "auto-detect" quirk is really needed, or you are will otherwise fail to probe with the generic "jedec,spi-nor" compatible string.
Notice that the binding specifies the chip-specific compatible as optional (it says _May_):
- compatible : May include a device-specific string consisting of the manufacturer and name of the chip.
Quoted 5 lines
drivers/mtd/spi-nor/nxp-spifi.c new file +5
-0+ ret =spi_nor_scan (&spifi->nor, modalias, flash_read); +if (ret) { +dev_err (spifi->dev,"device scan failed\n" ); +return ret; + }
Signature · 2 lines
Ezequiel Garcia, VanguardiaSur www.vanguardiasur.com.ar
PATCH v2 1/2 mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)
Quoted 47 lines · Ezequiel Garcia
Joachim,
I tested the driver and found an issue with it.
Quoted 18 lines · Joachim Eastwood
drivers/mtd/spi-nor/nxp-spifi.c new file +18
-0+ + spifi->mtd.priv = &spifi->nor; + spifi->nor.mtd = &spifi->mtd; + spifi->nor.dev = spifi->dev; + spifi->nor.priv = spifi; + spifi->nor.read = nxp_spifi_read; + spifi->nor.write = nxp_spifi_write; + spifi->nor.erase = nxp_spifi_erase; + spifi->nor.read_reg = nxp_spifi_read_reg; + spifi->nor.write_reg = nxp_spifi_write_reg; + + ret =of_modalias_node (np, modalias,sizeof (modalias)); +if (ret <0 ) { +dev_err (spifi->dev,"unable to get device modalias\n" ); +return ret; + } + +/* drivers/mtd/spi-nor/nxp-spifi.c line 363
Quoted 10 lines
drivers/mtd/spi-nor/nxp-spifi.c new file +10
-0+* The first read on a hard reset isn't reliable so do a +* dummy read of the id before calling spi_nor_scan(). +* The reason for this problem is unknown. +* +* The official NXP spifilib uses more or less the same +* workaround that is applied here by reading the device +* id multiple times. +*/ +nxp_spifi_dummy_id_read (&spifi->nor); +Actually, I think there's an issue here. See how m25p80 deals with modalias:
[..] else if (!strcmp(spi->modalias, "spi-nor")) flash_name = NULL; /* auto-detect */ else flash_name = spi->modalias; ret = spi_nor_scan(nor, flash_name, mode); if (ret) return ret;
Quoted 3 lines
I think the "auto-detect" quirk is really needed, or you are will otherwise fail to probe with the generic "jedec,spi-nor" compatible string.
I see.
Seem easy enough to fix. I'll send out new version after doing some more tests here.
Note that this code was copied from fsl-quadspi so I assume it has the same problem.
Thanks for testing and catching the issue, Ezequiel.
regards,
Joachim Eastwood
PATCH v2 1/2 mtd: spi-nor: add driver for NXP SPI Flash Interface (SPIFI)
Quoted 4 lines · Joachim Eastwood
Quoted 3 lines · Ezequiel Garcia
I think the "auto-detect" quirk is really needed, or you are will otherwise fail to probe with the generic "jedec,spi-nor" compatible string.
[...]
Quoted 2 lines
Note that this code was copied from fsl-quadspi so I assume it has the same problem.
Yes, fsl-quadspi gets this a bit wrong, I think. But spi_nor_scan() didn't have a notion of "NULL means autodetect" when it was first written. The framework is still evolving a bit.
I have a simple patch for fsl-quadspi to fix this up now, but I don't have the HW. Maybe I'll send with a RFT.
Brian
PATCH v2 2/2 doc: dt: add documentation for nxp,lpc1773-spifi
In reply to Joachim EastwoodAdd device tree binding documentation for the SPI Flash Interface (SPIFI) found on NXP LPC18xx and LPC43xx devies.
--- .../devicetree/bindings/mtd/nxp-spifi.txt | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 Documentation/devicetree/bindings/mtd/nxp-spifi.txt
Documentation/devicetree/bindings/mtd/nxp-spifi.txt new file +56 -0
@@ -0,0 +1,56 @@ +* NXP SPI Flash Interface (SPIFI) + +NXP SPIFI is a specialized SPI interface for serial Flash devices. +It supports one Flash device with 1-, 2- and 4-bits width in SPI +mode 0 or 3. The controller operates in either command or memory +mode. In memory mode the Flash is accessible from the CPU as +normal memory. + +Required properties: + - compatible : Should be "nxp,lpc1773-spifi" + - reg : the first contains the register location and length, + the second contains the memory mapping address and length + - reg-names: Should contain the reg names "spifi" and "flash" + - interrupts : Should contain the interrupt for the device + - clocks : The clocks needed by the SPIFI controller + - clock-names : Should contain the clock names "spifi" and "reg" + +Optional properties: + - resets : phandle + reset specifier + +The SPI Flash must be a child of the SPIFI node and can contain +the following properties. + - spi-cpol : Controller only supports mode 0 and 3 so either + both spi-cpol and spi-cpha should be present or + none of them + - spi-cpha : See above + - spi-rx-bus-width : Used to select how many pins that are used + for input on the controller + +See bindings/spi/spi-bus.txt for more information. + +Example: +spifi: spifi at 40003000 { + compatible = "nxp,lpc1773-spifi"; + reg = <0x40003000 0x1000>, <0x14000000 0x4000000>; + reg-names = "spifi", "flash"; + interrupts = <30>; + clocks = <&ccu1 CLK_SPIFI>, <&ccu1 CLK_CPU_SPIFI>; + clock-names = "spifi", "reg"; + resets = <&rgu 53>; + + flash at 0 { + compatible = "spansion,s25fl016k", "jedec,spi-nor"; + spi-cpol; + spi-cpha; + spi-rx-bus-width = <4>; + #address-cells = <1>; + #size-cells = <1>; + + partition at 0 { + label = "data"; + reg = <0 0x200000>; + }; + }; +}; +
Signature · 1 line
1.8.0