spi: spi-mem: Add driver for NXP FlexSPI controller
Subsystems (5)
v7 cover spi: spi-mem: Add driver for NXP FlexSPI controller
- Add driver for NXP FlexSPI host controller
FlexSPI is a flexsible SPI host controller [1], Chapter 30 page 1475,
which supports two SPI channels and up to 4 external devices.
Each channel supports Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional data lines) i.e. FlexSPI acts as an interface to external devices, maximum 4, each with up to 8 bidirectional data lines.
- Tested this driver with mtd_debug(Erase/Write/Read) utility and JFFS2 filesystem mounting and booting on NXP LX2160ARDB[2] and LX2160AQDS targets. LX2160ARDB is having two NOR slave device connected on single bus A i.e. A0 and A1 (CS0 and CS1).
LX2160AQDS is having two NOR slave device connected on separate buses one flash on A0 and second on B1 i.e. (CS0 and CS3).
Verified this driver on following SPI NOR flashes:
Micron, mt35xu512aba, [Read - 1 bit mode]
Cypress, s25fl512s, [Read - 1/2/4 bit mode]
[1] https://www.nxp.com/docs/en/reference-manual/IMXRT1050RM.pdf
[2] https://patchwork.kernel.org/project/linux-arm-kernel/list/?submitter=182097
Yogesh Narayan Gaur (5):
spi: spi-mem: Add driver for NXP FlexSPI controller
dt-bindings: spi: add binding file for NXP FlexSPI controller
arm64: dts: lx2160a: add FlexSPI node property
arm64: defconfig: enable NXP FlexSPI driver
MAINTAINERS: add maintainers for the NXP FlexSPI driver
Changes for v7:
- Rebase on top of SPI tree
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git/
branch: for-next
- Incorporated review comments for
patch 'spi: spi-mem: Add driver for NXP FlexSPI controller'.
Changes for v6:
- Rebase on top of v5.0-rc1.
- Incorporated review comments for
patch 'spi: spi-mem: Add driver for NXP FlexSPI controller'.
- Updated s-b tag in all patches.
Changes for v5:
- Rebase on top of v4.20-rc2
- Incorporated review comments for
patch 'spi: spi-mem: Add driver for NXP FlexSPI controller'.
Changes for v4:
- Incorporated review comments for
patch 'spi: spi-mem: Add driver for NXP FlexSPI controller'.
- Incorporated binding file review comments.
Changes for v3:
- Incorporated review comments for
patch 'spi: spi-mem: Add driver for NXP FlexSPI controller'.
Changes for v2:
- Incorporated Boris review comments and drop below patches as per the comments.
- Patch 'spi: add slave device size in spi_device struct'
- Patch 'spi: add flags for octal I/O data transfer'
- Incorporated DTS and Binding file review comments of Shawn Guo and Rob Herring.
.../devicetree/bindings/spi/spi-nxp-fspi.txt | 39 + MAINTAINERS | 7 + .../boot/dts/freescale/fsl-lx2160a-rdb.dts | 22 + .../arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 13 + arch/arm64/configs/defconfig | 1 + drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-nxp-fspi.c | 1105 +++++++++++++++++ 8 files changed, 1198 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt create mode 100644 drivers/spi/spi-nxp-fspi.c
Signature · 1 line
2.17.1
PATCH v7 1/5 spi: spi-mem: Add driver for NXP FlexSPI controller
- Add driver for NXP FlexSPI host controller
(0) What is the FlexSPI controller?
FlexSPI is a flexsible SPI host controller which supports two SPI channels and up to 4 external devices. Each channel supports Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional data lines) i.e. FlexSPI acts as an interface to external devices, maximum 4, each with up to 8 bidirectional data lines.
It uses new SPI memory interface of the SPI framework to issue flash memory operations to up to four connected flash devices (2 buses with 2 CS each).
(1) Tested this driver with the mtd_debug and JFFS2 filesystem utility on NXP LX2160ARDB and LX2160AQDS targets.
LX2160ARDB is having two NOR slave device connected on single bus A i.e. A0 and A1 (CS0 and CS1).
LX2160AQDS is having two NOR slave device connected on separate buses one flash on A0 and second on B1 i.e. (CS0 and CS3). Verified this driver on following SPI NOR flashes:
Micron, mt35xu512ab, [Read - 1 bit mode]
Cypress, s25fl512s, [Read - 1/2/4 bit mode]---
Changes for v7:
- Add func pointer for '.get_name' for struct spi_controller_mem_ops
- Add input address range check as per controller memory mapped space
- Update _fill_txfifo/_read_rxfifo funcs as per Frieder review comments Changes for v6:
- Rebase on top of v5.0-rc1
- Updated as per Frieder review comments and perform code cleanup
- Updated _fill_txfifo/_read_rxfifo func write/read logic Changes for v5:
- Rebase on top of v4.20-rc2
- Modified fspi_readl_poll_tout() as per review comments
- Arrange header file in alphabetical order
- Removed usage of read()/write() function callback pointer
- Add support for 1 and 2 byte address length
- Change Frieder e-mail to new e-mail address
Changes for v4:
- Incorporate Boris review comments
* Use readl_poll_timeout() instead of busy looping.
* Re-define register masking as per comment.
* Drop fspi_devtype enum.
Changes for v3:
- Added endianness flag in platform specific structure instead of DTS.
- Modified nxp_fspi_read_ahb(), removed remapping code.
- Added Boris and Frieder as Author and provided reference of spi-fsl-qspi.c Changes for v2:
- Incorporated Boris review comments.
- Remove dependency of driver over connected flash device size.
- Modified the logic to select requested CS.
- Remove SPI-Octal Macros.
drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-nxp-fspi.c | 1105 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1116 insertions(+) create mode 100644 drivers/spi/spi-nxp-fspi.c
drivers/spi/Kconfig +10 -0
@@ -279,6 +279,16 @@ config SPI_FSL_QUADSPI This controller does not support generic SPI messages. It only supports the high-level SPI memory interface. +config SPI_NXP_FLEXSPI + tristate "NXP Flex SPI controller" + depends on ARCH_LAYERSCAPE || HAS_IOMEM + help + This enables support for the Flex SPI controller in master mode. + Up to four slave devices can be connected on two buses with two + chipselects each. + This controller does not support generic SPI messages and only + supports the high-level SPI memory interface. + config SPI_GPIO tristate "GPIO-based bitbanging SPI Master" depends on GPIOLIB || COMPILE_TEST
drivers/spi/Makefile +1 -0
@@ -64,6 +64,7 @@ obj-$(CONFIG_SPI_MXIC) += spi-mxic.o obj-$(CONFIG_SPI_MXS) += spi-mxs.o obj-$(CONFIG_SPI_NPCM_PSPI) += spi-npcm-pspi.o obj-$(CONFIG_SPI_NUC900) += spi-nuc900.o +obj-$(CONFIG_SPI_NXP_FLEXSPI) += spi-nxp-fspi.o obj-$(CONFIG_SPI_OC_TINY) += spi-oc-tiny.o spi-octeon-objs := spi-cavium.o spi-cavium-octeon.o obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o
drivers/spi/spi-nxp-fspi.c new file +1105 -0
1,105 lines not on this page · raw message
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.17.1
Hi Yogesh,
Quoted 61 lines · Yogesh Narayan Gaur
- Add driver for NXP FlexSPI host controller
(0) What is the FlexSPI controller?
FlexSPI is a flexsible SPI host controller which supports two SPI channels and up to 4 external devices. Each channel supports Single/Dual/Quad/Octal mode data transfer (1/2/4/8 bidirectional data lines) i.e. FlexSPI acts as an interface to external devices, maximum 4, each with up to 8 bidirectional data lines.It uses new SPI memory interface of the SPI framework to issue flash memory operations to up to four connected flash devices (2 buses with 2 CS each).
(1) Tested this driver with the
mtd_debugand JFFS2 filesystem utility on NXP LX2160ARDB and LX2160AQDS targets.
LX2160ARDB is having two NOR slave device connected on single bus A i.e. A0 and A1 (CS0 and CS1).
LX2160AQDS is having two NOR slave device connected on separate buses one flash on A0 and second on B1 i.e. (CS0 and CS3). Verified this driver on following SPI NOR flashes:Micron, mt35xu512ab, [Read - 1 bit mode] Cypress, s25fl512s, [Read - 1/2/4 bit mode]Signed-off-by Yogesh Narayan Gaur <[email protected]>---
Changes for v7:
- Add func pointer for '.get_name' for structspi_controller_mem_ops
- Add input address range check as per controller memory mapped space
- Update _fill_txfifo/_read_rxfifo funcs as per Frieder review comments Changes for v6:
- Rebase on top of v5.0-rc1
- Updated as per Frieder review comments and perform code cleanup
- Updated _fill_txfifo/_read_rxfifo func write/read logic Changes for v5:
- Rebase on top of v4.20-rc2
- Modifiedfspi_readl_poll_tout()as per review comments
- Arrange header file in alphabetical order
- Removed usage of read()/write() function callback pointer
- Add support for 1 and 2 byte address length
- Change Frieder e-mail to new e-mail address
Changes for v4:
- Incorporate Boris review comments
* Usereadl_poll_timeout()instead of busy looping.
* Re-define register masking as per comment.
* Dropfspi_devtypeenum.
Changes for v3:
- Added endianness flag in platform specific structure instead of DTS.
- Modifiednxp_fspi_read_ahb(), removed remapping code.
- Added Boris and Frieder as Author and provided reference ofspi-fsl-qspi.cChanges for v2:
- Incorporated Boris review comments.
- Remove dependency of driver over connected flash device size.
- Modified the logic to select requested CS.
- Remove SPI-Octal Macros.drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-nxp-fspi.c | 1105 ++++++++++++++++++++++++++++++++++++ 3 files changed, 1116 insertions(+)create mode 100644
drivers/spi/spi-nxp-fspi.c
[...]
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c new file +13
-0+ +static bool nxp_fspi_supports_op (struct spi_mem *mem, +const struct spi_mem_op *op) +{ +struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->master); +int ret; + + ret =nxp_fspi_check_buswidth (f, op->cmd.buswidth); + +if (op->addr.nbytes) + ret |=nxp_fspi_check_buswidth (f, op->addr.buswidth); + +if (op->dummy.nbytes)
drivers/spi/spi-nxp-fspi.c line 413
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+ ret |=nxp_fspi_check_buswidth (f, op->dummy.buswidth); + +if (op->data.nbytes) + ret |=nxp_fspi_check_buswidth (f, op->data.buswidth); + +if (ret) +return false; + +/* +* The number of address bytes should be equal to and less than 4bytes.
Nitpick: use "or" instead of "and", add a space between "4" and "bytes".
Quoted 30 lines
drivers/spi/spi-nxp-fspi.c new file +30
-0+*/ +if (op->addr.nbytes >4 ) +return false; + +/* +* If requested address value is greater than controller assigned +* memory mapped space, return error as it didn't fit in the range +* of assigned address space. +*/ +if (op->addr.val >= f->memmap_phy_size) +return false; + +/* Max 64 dummy clock cycles supported */ +if (op->dummy.buswidth && + (op->dummy.nbytes *8 / op->dummy.buswidth >64 )) +return false; + +/* Max data length, check controller limits and alignment */ +if (op->data.dir ==SPI_MEM_DATA_IN && + (op->data.nbytes > f->devtype_data->ahb_buf_size || + (op->data.nbytes > f->devtype_data->rxfifo -4 && + !IS_ALIGNED (op->data.nbytes,8 )))) +return false; + +if (op->data.dir ==SPI_MEM_DATA_OUT && + op->data.nbytes > f->devtype_data->txfifo) +return false; + +return true; +}
[...]
Quoted 15 lines
drivers/spi/spi-nxp-fspi.c new file +15
-0+static void nxp_fspi_fill_txfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, ret; + +/* clear the TX FIFO. */ +fspi_writel (f,FSPI_IPTXFCR_CLR , base +FSPI_IPTXFCR ); + +/* +* Default value of water mark level is 8 bytes, hence in single +* write request controller can write max 8 bytes of data. +*/ + +for (i =0 ; i <ALIGN_DOWN (op->data.nbytes,8 ); i +=8 ) {
drivers/spi/spi-nxp-fspi.c line 676
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* Wait for TXFIFO empty */ + ret =fspi_readl_poll_tout (f, f->iobase +FSPI_INTR , +FSPI_INTR_IPTXWE ,0 , +POLL_TOUT , true); +WARN_ON (ret); + +fspi_writel (f, *(u32 *) ((u8 *)op->data.buf.out + i), + base +FSPI_TFDR ); +fspi_writel (f, *(u32 *) ((u8 *)op->data.buf.out + i +4 ), + base +FSPI_TFDR +4 );
Nitpick: Add a "u8 *buf = (u8 *)op->data.buf.out" to the top of the function and use it here...
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+fspi_writel (f,FSPI_INTR_IPTXWE , base +FSPI_INTR ); + } + +if (i < op->data.nbytes) {
drivers/spi/spi-nxp-fspi.c line 690
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+u32 data =0 ; +int j; +/* Wait for TXFIFO empty */ + ret =fspi_readl_poll_tout (f, f->iobase +FSPI_INTR , +FSPI_INTR_IPTXWE ,0 , +POLL_TOUT , true); +WARN_ON (ret); + +for (j =0 ; j <ALIGN (op->data.nbytes - i,4 ); j +=4 ) { +memcpy (&data, op->data.buf.out + i + j,4 );
...and also here.
Quoted 38 lines
drivers/spi/spi-nxp-fspi.c new file +38
-0+fspi_writel (f, data, base +FSPI_TFDR + j); + } +fspi_writel (f,FSPI_INTR_IPTXWE , base +FSPI_INTR ); + } +} + +static void nxp_fspi_read_rxfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, ret; +int len = op->data.nbytes; +u8 *buf = (u8 *) op->data.buf.in; + +/* +* Default value of water mark level is 8 bytes, hence in single +* read request controller can read max 8 bytes of data. +*/ +for (i =0 ; i <ALIGN_DOWN (len,8 ); i +=8 ) { +/* Wait for RXFIFO available */ + ret =fspi_readl_poll_tout (f, f->iobase +FSPI_INTR , +FSPI_INTR_IPRXWA ,0 , +POLL_TOUT , true); +WARN_ON (ret); + + *(u32 *)(buf + i) =fspi_readl (f, base +FSPI_RFDR ); + *(u32 *)(buf + i +4 ) =fspi_readl (f, base +FSPI_RFDR +4 ); +/* move the FIFO pointer */ +fspi_writel (f,FSPI_INTR_IPRXWA , base +FSPI_INTR ); + } + +if (i < len) { +u32 tmp; +int size, j; + + buf = op->data.buf.in + i; +/* Wait for RXFIFO available */ + ret = fspi_readl_poll_tout(f, f->iobase + FSPI_INTR,
drivers/spi/spi-nxp-fspi.c line 738
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+FSPI_INTR_IPRXWA ,0 , + POLL_TOUT, true); +WARN_ON (ret); + + len = op->data.nbytes - i; +for (j =0 ; j < (ALIGN (len,4 ))/4 ; j++, buf += size) { + tmp =fspi_readl (f, base +FSPI_RFDR + j *4 ); + size =min (len,4 ); +memcpy (buf, &tmp, size); + }
In the second iteration of this loop, the calculation of size seems wrong, as len has not changed.
Maybe this could work?:
len = op->data.nbytes - i;
for (j = 0; j < op->data.nbytes - i; j += 4) {
tmp = fspi_readl(f, base + FSPI_RFDR + j);
size = min(len, 4);
memcpy(buf + j, &tmp, size);
len -= size;
}When this is fixed and tested you can add:
Thanks,
Frieder
PATCH v7 2/5 dt-bindings: spi: add binding file for NXP FlexSPI controller
In reply to Yogesh Narayan GaurAdd binding file for NXP FlexSPI controller
---
Changes for v7:
- None
Changes for v6:
- None
Changes for v5:
- None
Changes for v4:
- Incorporated Rob review comments.
Changes for v3:
- Removed node property 'big-endian'.
Changes for v2:
- Incorporated Rob review comments.
.../devicetree/bindings/spi/spi-nxp-fspi.txt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +39 -0
@@ -0,0 +1,39 @@ +* NXP Flex Serial Peripheral Interface (FSPI) + +Required properties: + - compatible : Should be "nxp,lx2160a-fspi" + - reg : First contains the register location and length, + Second contains the memory mapping address and length + - reg-names : Should contain the resource reg names: + - fspi_base: configuration register address space + - fspi_mmap: memory mapped address space + - interrupts : Should contain the interrupt for the device + +Required SPI slave node properties: + - reg : There are two buses (A and B) with two chip selects each. + This encodes to which bus and CS the flash is connected: + - <0>: Bus A, CS 0 + - <1>: Bus A, CS 1 + - <2>: Bus B, CS 0 + - <3>: Bus B, CS 1 + +Example showing the usage of two SPI NOR slave devices on bus A: + +fspi0: spi@20c0000 { + compatible = "nxp,lx2160a-fspi"; + reg = <0x0 0x20c0000 0x0 0x10000>, <0x0 0x20000000 0x0 0x10000000>; + reg-names = "fspi_base", "fspi_mmap"; + interrupts = <0 25 0x4>; /* Level high type */ + clocks = <&clockgen 4 3>, <&clockgen 4 3>; + clock-names = "fspi_en", "fspi"; + + mt35xu512aba0: flash@0 { + reg = <0>; + .... + }; + + mt35xu512aba1: flash@1 { + reg = <1>; + .... + }; +};
Signature · 1 line
2.17.1
PATCH v7 3/5 arm64: dts: lx2160a: add FlexSPI node property
In reply to Yogesh Narayan GaurAdd fspi node property for LX2160A SoC for FlexSPI driver. Property added for the FlexSPI controller and for the connected slave device for the LX2160ARDB target.
This is having two SPI-NOR flash device, mt35xu512aba, connected at CS0 and CS1.
---
Changes for v7:
- None
Changes for v6:
- None
Changes for v5:
- None
Changes for v4:
- Incorporated Rob review comments.
Changes for v3:
- None.
Changes for v2:
- Incorporated Shawn review comments.
.../boot/dts/freescale/fsl-lx2160a-rdb.dts | 22 +++++++++++++++++++ .../arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 13 +++++++++++ 2 files changed, 35 insertions(+)
arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts +22 -0
@@ -50,6 +50,28 @@ status = "okay"; }; +&fspi { + status = "okay"; + + mt35xu512aba0: flash@0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "spansion,m25p80"; + m25p,fast-read; + spi-max-frequency = <50000000>; + reg = <0>; + }; + + mt35xu512aba1: flash@1 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "spansion,m25p80"; + m25p,fast-read; + spi-max-frequency = <50000000>; + reg = <1>; + }; +}; + &i2c0 { status = "okay";
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +13 -0
@@ -762,5 +762,18 @@ <GIC_SPI 209 IRQ_TYPE_LEVEL_HIGH>; dma-coherent; }; + + fspi: spi@20c0000 { + compatible = "nxp,lx2160a-fspi"; + #address-cells = <1>; + #size-cells = <0>; + reg = <0x0 0x20c0000 0x0 0x10000>, + <0x0 0x20000000 0x0 0x10000000>; + reg-names = "fspi_base", "fspi_mmap"; + interrupts = <0 25 0x4>; /* Level high type */ + clocks = <&clockgen 4 3>, <&clockgen 4 3>; + clock-names = "fspi_en", "fspi"; + status = "disabled"; + }; }; };
Signature · 1 line
2.17.1
PATCH v7 4/5 arm64: defconfig: enable NXP FlexSPI driver
In reply to Yogesh Narayan GaurEnable driver support of NXP FlexSPI controller.
---
Changes for v7:
- None
Changes for v6:
- None
Changes for v5:
- None
Changes for v4:
- None
Changes for v3:
- None
Changes for v2:
- None
arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -362,6 +362,7 @@ CONFIG_SPI_ROCKCHIP=y CONFIG_SPI_QUP=y CONFIG_SPI_S3C64XX=y CONFIG_SPI_SPIDEV=m +CONFIG_SPI_NXP_FLEXSPI=y CONFIG_SPMI=y CONFIG_PINCTRL_SINGLE=y CONFIG_PINCTRL_MAX77620=y
Signature · 1 line
2.17.1
PATCH v7 5/5 MAINTAINERS: add maintainers for the NXP FlexSPI driver
In reply to Yogesh Narayan GaurAdd maintainers for the NXP FlexSPI driver
---
Changes for v7:
- None
Changes for v6:
- None
Changes for v5:
- Add maintainers for binding file
Changes for v4:
- None
Changes for v3:
- None
Changes for v2:
- None
MAINTAINERS | 7 +++++++ 1 file changed, 7 insertions(+)
MAINTAINERS +7 -0
@@ -10927,6 +10927,13 @@ F: lib/objagg.c F: lib/test_objagg.c F: include/linux/objagg.h +NXP FSPI DRIVER +M: Yogesh Gaur <[email protected]> +L: [email protected] +S: Maintained +F: drivers/spi/spi-nxp-fspi.c +F: Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt + OBJTOOL M: Josh Poimboeuf <[email protected]> M: Peter Zijlstra <[email protected]>
Signature · 1 line
2.17.1