spi: spi-mem: Add driver for NXP FlexSPI controller
Subsystems (5)
v3 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[3], [Read - 1 bit mode]
Cypress, s25fl512s, [Read - 1/2/4 bit mode]
Support for octal flash commands and other Octal data transfer related framework changes work is in progress.
[1] https://www.nxp.com/docs/en/reference-manual/IMXRT1050RM.pdf
[2] https://patchwork.kernel.org/project/linux-arm-kernel/list/?series=9721
[3] https://patchwork.ozlabs.org/project/linux-mtd/list/?series=63445
Yogesh 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 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 | 42 + MAINTAINERS | 6 + arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts | 22 + arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 12 + arch/arm64/configs/defconfig | 1 + drivers/spi/Kconfig | 10 + drivers/spi/Makefile | 1 + drivers/spi/spi-nxp-fspi.c | 1231 ++++++++++++++++++++ 8 files changed, 1324 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.7.4
PATCH v3 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 v3:
- Added endianness flag in platform specific structure instead of DTS.
- Modified nxp_fspi_read_ahb(), removed remapping code. 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 | 1231 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 1241 insertions(+) create mode 100644 drivers/spi/spi-nxp-fspi.c
drivers/spi/Kconfig +10 -0
@@ -251,6 +251,16 @@ config SPI_FSL_LPSPI help This enables Freescale i.MX LPSPI controllers in master mode. +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
@@ -59,6 +59,7 @@ obj-$(CONFIG_SPI_MPC52xx) += spi-mpc52xx.o obj-$(CONFIG_SPI_MT65XX) += spi-mt65xx.o obj-$(CONFIG_SPI_MXS) += spi-mxs.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 +1230 -0
1,230 lines not on this page · raw message
+MODULE_LICENSE("GPL v2");
Signature · 1 line
2.7.4
Hi Yogesh,
Quoted 20 lines · On Fri, 21 Sep 2018 15:51:59 +0530 Yogesh Gaur <[email protected]>…
drivers/spi/spi-nxp-fspi.c new file +20
-0+/* Registers used by the driver */ +#define FSPI_MCR0 0x00 +#define FSPI_MCR0_AHB_TIMEOUT_SHIFT 24 +#define FSPI_MCR0_AHB_TIMEOUT_MASK (0xFF << FSPI_MCR0_AHB_TIMEOUT_SHIFT) +#define FSPI_MCR0_IP_TIMEOUT_SHIFT 16 +#define FSPI_MCR0_IP_TIMEOUT_MASK (0xFF << FSPI_MCR0_IP_TIMEOUT_SHIFT) +#define FSPI_MCR0_LEARN_EN_SHIFT 15 +#define FSPI_MCR0_LEARN_EN_MASK (1 << FSPI_MCR0_LEARN_EN_SHIFT) +#define FSPI_MCR0_SCRFRUN_EN_SHIFT 14 +#define FSPI_MCR0_SCRFRUN_EN_MASK (1 << FSPI_MCR0_SCRFRUN_EN_SHIFT) +#define FSPI_MCR0_OCTCOMB_EN_SHIFT 13 +#define FSPI_MCR0_OCTCOMB_EN_MASK (1 << FSPI_MCR0_OCTCOMB_EN_SHIFT) +#define FSPI_MCR0_DOZE_EN_SHIFT 12 +#define FSPI_MCR0_DOZE_EN_MASK (1 << FSPI_MCR0_DOZE_EN_SHIFT) +#define FSPI_MCR0_HSEN_SHIFT 11 +#define FSPI_MCR0_HSEN_MASK (1 << FSPI_MCR0_HSEN_SHIFT) +#define FSPI_MCR0_SERCLKDIV_SHIFT 8 +#define FSPI_MCR0_SERCLKDIV_MASK (7 << FSPI_MCR0_SERCLKDIV_SHIFT) +#define FSPI_MCR0_ATDF_EN_SHIFT 7 +#define FSPI_MCR0_ATDF_EN_MASK (1 << FSPI_MCR0_ATDF_EN_SHIFT)
drivers/spi/spi-nxp-fspi.c line 90
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+#define FSPI_MCR0_ARDF_EN_SHIFT 6 +#define FSPI_MCR0_ARDF_EN_MASK (1 << FSPI_MCR0_ARDF_EN_SHIFT) +#define FSPI_MCR0_RXCLKSRC_SHIFT 4 +#define FSPI_MCR0_RXCLKSRC_MASK (3 << FSPI_MCR0_RXCLKSRC_SHIFT) +#define FSPI_MCR0_END_CFG_SHIFT 2 +#define FSPI_MCR0_END_CFG_MASK (3 << FSPI_MCR0_END_CFG_SHIFT) +#define FSPI_MCR0_MDIS_SHIFT 1 +#define FSPI_MCR0_MDIS_MASK (1 << FSPI_MCR0_MDIS_SHIFT) +#define FSPI_MCR0_SWRST_SHIFT 0 +#define FSPI_MCR0_SWRST_MASK (1 << FSPI_MCR0_SWRST_SHIFT)
Do we really need all those _SHIFT/_MASK defs? I mean
#define FSPI_MCR0_SWRST BIT(0)
or
#define FSPI_MCR0_AHB_TIMEOUT(x) ((x) << 24)
#define FSPI_MCR0_AHB_TIMEOUT_MASK GENMASK(31, 24)
are just fine.
drivers/spi/spi-nxp-fspi.c line 422
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+ +enum nxp_fspi_devtype { +NXP_FSPI_LX2160A , +};
I'm pretty sure you don't need this enum if you describe all dev caps in the nxp_fspi_devtype_data struct.
drivers/spi/spi-nxp-fspi.c line 430
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c new file +8
-0+ +struct nxp_fspi_devtype_data { +enum nxp_fspi_devtype devtype; +unsigned int rxfifo; +unsigned int txfifo; +unsigned int ahb_buf_size; +unsigned int quirks; +bool endianness;
How about renaming this variable big_endian and dropping the {L,B}_ENDIAN macros?
Quoted 1 line
+};
[...]
Quoted 25 lines
drivers/spi/spi-nxp-fspi.c new file +25
-0+struct nxp_fspi { +void __iomem *iobase; +void __iomem *ahb_addr; +u32 memmap_phy; +u32 memmap_phy_size; +struct clk *clk, *clk_en; +struct device *dev; +struct completion c; +const struct nxp_fspi_devtype_data *devtype_data; +struct mutex lock; +struct pm_qos_request pm_qos_req; +int selected; +void (*write)(u32 val,void __iomem *addr); +u32 (*read)(void __iomem *addr); +}; + +static void fspi_writel_be (u32 val,void __iomem *addr) +{ +iowrite32be (val, addr); +} + +static void fspi_writel (u32 val,void __iomem *addr) +{ +iowrite32 (val, addr); +}
drivers/spi/spi-nxp-fspi.c line 478
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+ +static u32 fspi_readl_be (void __iomem *addr) +{ +return ioread32be (addr); +} + +static u32 fspi_readl (void __iomem *addr) +{ +return ioread32 (addr); +}
Hm, I'd recommend dropping the ->read/write() hooks and providing the following functions:
static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr)
{
if (f->big_endian)
iowrite32be(val, addr);
else
iowrite32(val, addr);
}static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr)
{
if (f->big_endian)
return ioread32be(addr);
else
return ioread32(addr);
}Quoted 15 lines
drivers/spi/spi-nxp-fspi.c new file +15
-0+ +static irqreturn_t nxp_fspi_irq_handler (int irq,void *dev_id) +{ +struct nxp_fspi *f = dev_id; +u32 reg; + +/* clear interrupt */ + reg = f->read (f->iobase +FSPI_INTR ); + f->write (FSPI_INTR_IPCMDDONE_MASK , f->iobase +FSPI_INTR ); + +if (reg &FSPI_INTR_IPCMDDONE_MASK ) +complete (&f->c); + +return IRQ_HANDLED ; +}
[...]
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+/* +* If the slave device content being changed by Write/Erase, need to +* invalidate the AHB buffer. This can be achieved by doing the reset +* of controller after setting MCR0[SWRESET] bit.
drivers/spi/spi-nxp-fspi.c line 569
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+*/ +static inline void nxp_fspi_invalid (struct nxp_fspi *f) +{ +u32 reg; + + reg = f->read (f->iobase +FSPI_MCR0 ); + f->write (reg |FSPI_MCR0_SWRST_MASK , f->iobase +FSPI_MCR0 ); + +while (f->read (f->iobase +FSPI_MCR0 ) &FSPI_MCR0_SWRST_MASK ) + ;
Did you consider using readl_poll_timeout[_atomic]()?
if (f->big_endian) mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); else mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); ret = readl_poll_timeout(f->iobase + FSPI_MCR0, reg, reg & mask, 0, FSPI_SWRST_TIMEOUT); WARN_ON(ret);
Quoted 1 line
+}
[...]
drivers/spi/spi-nxp-fspi.c line 756
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c new file +6
-0+static void nxp_fspi_read_ahb (struct nxp_fspi *f,const struct spi_mem_op *op) +{ +u32 len = op->data.nbytes; + +/* Read out the data directly from the AHB buffer. */ +memcpy_fromio (op->data.buf.in, (f->ahb_addr + op->addr.val), len);
Don't know if it's supported, but if it is, I recommend using DMA to do this copy, because otherwise you might stall the CPU for quite a long time if the flash is operating in a low-speed mode, and RT maintainers will complain about that at some point ;-).
Quoted 11 lines
drivers/spi/spi-nxp-fspi.c new file +11
-0+} + +static void nxp_fspi_fill_txfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, j; +int size, tmp_size, wm_size; +u32 data =0 ; +u32 *txbuf = (u32 *) op->data.buf.out; +
drivers/spi/spi-nxp-fspi.c line 777
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* clear the TX FIFO. */ + f->write (FSPI_IPTXFCR_CLR_MASK , base +FSPI_IPTXFCR ); + +/* Default value of water mark level is 8 bytes. */ + wm_size =8 ; + size = op->data.nbytes / wm_size; +for (i =0 ; i < size; i++) { +/* Wait for TXFIFO empty */ +while (!(f->read (base +FSPI_INTR ) &FSPI_INTR_IPTXWE_MASK )) + ;
Use readl_poll_timeout(), or even better, provide an helper (fspi_readl_poll_timeout()?) that hides the BE/LE stuff, so that you can reuse it when this pattern occurs.
[...]
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c new file +9
-0+static int nxp_fspi_exec_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->master); +void __iomem *base = f->iobase; +int err =0 ; +unsigned int timeout =1000 ; + +mutex_lock (&f->lock); +
drivers/spi/spi-nxp-fspi.c line 931
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* wait for the controller being ready */ + do { + u32 status; + + status = f->read(base + FSPI_STS0); + if ((status & FSPI_STS0_ARB_IDLE_MASK) && + (status & FSPI_STS0_SEQ_IDLE_MASK)) + break; + udelay(1); + dev_dbg(f->dev, "The controller is busy, 0x%x\n", status);
Same here.
Note that I didn't spend time looking at how the IP works, which explains why I focus on tiny details here. Unfortunately, I won't have time to review the driver in more details, so I'll leave that to someone else, or let Mark decides if he's happy enough with the current version.
Regards,
Boris
Hi Boris,
Quoted 119 lines · Boris Brezillon
Hi Yogesh,
Quoted 20 lines · On Fri, 21 Sep 2018 15:51:59 +0530 Yogesh Gaur <[email protected]>…
drivers/spi/spi-nxp-fspi.c new file +20
-0+/* Registers used by the driver */ +#define FSPI_MCR0 0x00 +#define FSPI_MCR0_AHB_TIMEOUT_SHIFT 24 +#define FSPI_MCR0_AHB_TIMEOUT_MASK (0xFF << FSPI_MCR0_AHB_TIMEOUT_SHIFT) +#define FSPI_MCR0_IP_TIMEOUT_SHIFT 16 +#define FSPI_MCR0_IP_TIMEOUT_MASK (0xFF << FSPI_MCR0_IP_TIMEOUT_SHIFT) +#define FSPI_MCR0_LEARN_EN_SHIFT 15 +#define FSPI_MCR0_LEARN_EN_MASK (1 << FSPI_MCR0_LEARN_EN_SHIFT) +#define FSPI_MCR0_SCRFRUN_EN_SHIFT 14 +#define FSPI_MCR0_SCRFRUN_EN_MASK (1 << FSPI_MCR0_SCRFRUN_EN_SHIFT) +#define FSPI_MCR0_OCTCOMB_EN_SHIFT 13 +#define FSPI_MCR0_OCTCOMB_EN_MASK (1 << FSPI_MCR0_OCTCOMB_EN_SHIFT) +#define FSPI_MCR0_DOZE_EN_SHIFT 12 +#define FSPI_MCR0_DOZE_EN_MASK (1 << FSPI_MCR0_DOZE_EN_SHIFT) +#define FSPI_MCR0_HSEN_SHIFT 11 +#define FSPI_MCR0_HSEN_MASK (1 << FSPI_MCR0_HSEN_SHIFT) +#define FSPI_MCR0_SERCLKDIV_SHIFT 8 +#define FSPI_MCR0_SERCLKDIV_MASK (7 << FSPI_MCR0_SERCLKDIV_SHIFT) +#define FSPI_MCR0_ATDF_EN_SHIFT 7 +#define FSPI_MCR0_ATDF_EN_MASK (1 << FSPI_MCR0_ATDF_EN_SHIFT)drivers/spi/spi-nxp-fspi.c line 90
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+#define FSPI_MCR0_ARDF_EN_SHIFT 6 +#define FSPI_MCR0_ARDF_EN_MASK (1 << FSPI_MCR0_ARDF_EN_SHIFT) +#define FSPI_MCR0_RXCLKSRC_SHIFT 4 +#define FSPI_MCR0_RXCLKSRC_MASK (3 << FSPI_MCR0_RXCLKSRC_SHIFT) +#define FSPI_MCR0_END_CFG_SHIFT 2 +#define FSPI_MCR0_END_CFG_MASK (3 << FSPI_MCR0_END_CFG_SHIFT) +#define FSPI_MCR0_MDIS_SHIFT 1 +#define FSPI_MCR0_MDIS_MASK (1 << FSPI_MCR0_MDIS_SHIFT) +#define FSPI_MCR0_SWRST_SHIFT 0 +#define FSPI_MCR0_SWRST_MASK (1 << FSPI_MCR0_SWRST_SHIFT)Do we really need all those _SHIFT/_MASK defs? I mean
#define
FSPI_MCR0_SWRSTBIT(0)or
#define
FSPI_MCR0_AHB_TIMEOUT(x)((x) << 24)
#defineFSPI_MCR0_AHB_TIMEOUT_MASKGENMASK(31, 24)are just fine.
drivers/spi/spi-nxp-fspi.c line 422
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+ +enum nxp_fspi_devtype { +NXP_FSPI_LX2160A , +};I'm pretty sure you don't need this enum if you describe all dev caps in the
nxp_fspi_devtype_datastruct.drivers/spi/spi-nxp-fspi.c line 430
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c new file +8
-0+ +struct nxp_fspi_devtype_data { +enum nxp_fspi_devtype devtype; +unsigned int rxfifo; +unsigned int txfifo; +unsigned int ahb_buf_size; +unsigned int quirks; +bool endianness;How about renaming this variable
big_endianand dropping the {L,B}_ENDIAN macros?Quoted 1 line
+};
[...]
Quoted 25 lines
drivers/spi/spi-nxp-fspi.c new file +25
-0+struct nxp_fspi { +void __iomem *iobase; +void __iomem *ahb_addr; +u32 memmap_phy; +u32 memmap_phy_size; +struct clk *clk, *clk_en; +struct device *dev; +struct completion c; +const struct nxp_fspi_devtype_data *devtype_data; +struct mutex lock; +struct pm_qos_request pm_qos_req; +int selected; +void (*write)(u32 val,void __iomem *addr); +u32 (*read)(void __iomem *addr); +}; + +static void fspi_writel_be (u32 val,void __iomem *addr) +{ +iowrite32be (val, addr); +} + +static void fspi_writel (u32 val,void __iomem *addr) +{ +iowrite32 (val, addr); +}drivers/spi/spi-nxp-fspi.c line 478
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+ +static u32 fspi_readl_be (void __iomem *addr) +{ +return ioread32be (addr); +} + +static u32 fspi_readl (void __iomem *addr) +{ +return ioread32 (addr); +}Hm, I'd recommend dropping the ->read/write() hooks and providing the following functions:
static void
fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr){ if (f->big_endian) iowrite32be(val, addr); else iowrite32(val, addr); }
Quoted 7 lines
static u32
fspi_readl(struct nxp_fspi *f, void __iomem *addr){ if (f->big_endian) return ioread32be(addr); else return ioread32(addr); }
I introduced the ->read/write() hooks in the QSPI driver because I was told to remove the conditional in the read/write path, but I can't really tell if this really makes any difference.
Regards,
Frieder
Quoted 121 lines
Quoted 16 lines
drivers/spi/spi-nxp-fspi.c new file +15
-0+ +static irqreturn_t nxp_fspi_irq_handler (int irq,void *dev_id) +{ +struct nxp_fspi *f = dev_id; +u32 reg; + +/* clear interrupt */ + reg = f->read (f->iobase +FSPI_INTR ); + f->write (FSPI_INTR_IPCMDDONE_MASK , f->iobase +FSPI_INTR ); + +if (reg &FSPI_INTR_IPCMDDONE_MASK ) +complete (&f->c); + +return IRQ_HANDLED ; +}[...]
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+/* +* If the slave device content being changed by Write/Erase, need to +* invalidate the AHB buffer. This can be achieved by doing the reset +* of controller after setting MCR0[SWRESET] bit. drivers/spi/spi-nxp-fspi.c line 569
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+*/ +static inline void nxp_fspi_invalid (struct nxp_fspi *f) +{ +u32 reg; + + reg = f->read (f->iobase +FSPI_MCR0 ); + f->write (reg |FSPI_MCR0_SWRST_MASK , f->iobase +FSPI_MCR0 ); + +while (f->read (f->iobase +FSPI_MCR0 ) &FSPI_MCR0_SWRST_MASK ) + ;Did you consider using readl_poll_timeout[_atomic]()?
if (f->big_endian) mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); else mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); ret = readl_poll_timeout(f->iobase + FSPI_MCR0, reg, reg & mask, 0, FSPI_SWRST_TIMEOUT); WARN_ON(ret);Quoted 1 line
+}
[...]
drivers/spi/spi-nxp-fspi.c line 756
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c new file +6
-0+static void nxp_fspi_read_ahb (struct nxp_fspi *f,const struct spi_mem_op *op) +{ +u32 len = op->data.nbytes; + +/* Read out the data directly from the AHB buffer. */ +memcpy_fromio (op->data.buf.in, (f->ahb_addr + op->addr.val), len);Don't know if it's supported, but if it is, I recommend using DMA to do this copy, because otherwise you might stall the CPU for quite a long time if the flash is operating in a low-speed mode, and RT maintainers will complain about that at some point ;-).
Quoted 11 lines
drivers/spi/spi-nxp-fspi.c new file +11
-0+} + +static void nxp_fspi_fill_txfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, j; +int size, tmp_size, wm_size; +u32 data =0 ; +u32 *txbuf = (u32 *) op->data.buf.out; +drivers/spi/spi-nxp-fspi.c line 777
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* clear the TX FIFO. */ + f->write (FSPI_IPTXFCR_CLR_MASK , base +FSPI_IPTXFCR ); + +/* Default value of water mark level is 8 bytes. */ + wm_size =8 ; + size = op->data.nbytes / wm_size; +for (i =0 ; i < size; i++) { +/* Wait for TXFIFO empty */ +while (!(f->read (base +FSPI_INTR ) &FSPI_INTR_IPTXWE_MASK )) + ;Use
readl_poll_timeout(), or even better, provide an helper (fspi_readl_poll_timeout()?) that hides the BE/LE stuff, so that you can reuse it when this pattern occurs.[...]
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c new file +9
-0+static int nxp_fspi_exec_op (struct spi_mem *mem,const struct spi_mem_op *op) +{ +struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->master); +void __iomem *base = f->iobase; +int err =0 ; +unsigned int timeout =1000 ; + +mutex_lock (&f->lock); +drivers/spi/spi-nxp-fspi.c line 931
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* wait for the controller being ready */ + do { + u32 status; + + status = f->read(base + FSPI_STS0); + if ((status & FSPI_STS0_ARB_IDLE_MASK) && + (status & FSPI_STS0_SEQ_IDLE_MASK)) + break; + udelay(1); + dev_dbg(f->dev, "The controller is busy, 0x%x\n", status);Same here.
Note that I didn't spend time looking at how the IP works, which explains why I focus on tiny details here. Unfortunately, I won't have time to review the driver in more details, so I'll leave that to someone else, or let Mark decides if he's happy enough with the current version.
Regards,
Boris
Hi Boris,
Quoted 149 lines
-----Original Message-----
From: Frieder Schrempf [mailto:frieder.schrempf at exceet.de]
Sent: Monday, October 1, 2018 11:48 AM
To: Boris Brezillon <[email protected]>; Yogesh Narayan Gaur <[email protected]>
Cc: linux-mtd at lists.infradead.org; marek.vasut at gmail.com; linux- spi at vger.kernel.org; devicetree at vger.kernel.org; robh at kernel.org; mark.rutland at arm.com; shawnguo at kernel.org; linux-arm-
kernel at lists.infradead.org; computersforpeace at gmail.com; linux- kernel at vger.kernel.org
Subject: Re: [PATCH v3 1/5] spi: spi-mem: Add driver for NXP FlexSPI controllerHi Boris,
Quoted 9 lines · Boris Brezillon
Hi Yogesh,
drivers/spi/spi-nxp-fspi.c
Quoted 4 lines · On Fri, 21 Sep 2018 15:51:59 +0530 Yogesh Gaur <[email protected]>…
drivers/spi/spi-nxp-fspi.c new file +4
-0+/* Registers used by the driver */ +#define FSPI_MCR0 0x00 +#define FSPI_MCR0_AHB_TIMEOUT_SHIFT 24 +#define FSPI_MCR0_AHB_TIMEOUT_MASK (0xFF <<
FSPI_MCR0_AHB_TIMEOUT_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_IP_TIMEOUT_SHIFT 16 +#define FSPI_MCR0_IP_TIMEOUT_MASK (0xFF <<
FSPI_MCR0_IP_TIMEOUT_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_LEARN_EN_SHIFT 15 +#define FSPI_MCR0_LEARN_EN_MASK (1 <<
FSPI_MCR0_LEARN_EN_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_SCRFRUN_EN_SHIFT 14 +#define FSPI_MCR0_SCRFRUN_EN_MASK (1 <<
FSPI_MCR0_SCRFRUN_EN_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_OCTCOMB_EN_SHIFT 13 +#define FSPI_MCR0_OCTCOMB_EN_MASK (1 <<
FSPI_MCR0_OCTCOMB_EN_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_DOZE_EN_SHIFT 12 +#define FSPI_MCR0_DOZE_EN_MASK (1 <<
FSPI_MCR0_DOZE_EN_SHIFT)Quoted 4 lines
drivers/spi/spi-nxp-fspi.c
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+#define FSPI_MCR0_HSEN_SHIFT 11 +#define FSPI_MCR0_HSEN_MASK (1 << FSPI_MCR0_HSEN_SHIFT) +#define FSPI_MCR0_SERCLKDIV_SHIFT 8 +#define FSPI_MCR0_SERCLKDIV_MASK (7 <<
FSPI_MCR0_SERCLKDIV_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_ATDF_EN_SHIFT 7 +#define FSPI_MCR0_ATDF_EN_MASK (1 <<
FSPI_MCR0_ATDF_EN_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_ARDF_EN_SHIFT 6 +#define FSPI_MCR0_ARDF_EN_MASK (1 <<
FSPI_MCR0_ARDF_EN_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_RXCLKSRC_SHIFT 4 +#define FSPI_MCR0_RXCLKSRC_MASK (3 <<
FSPI_MCR0_RXCLKSRC_SHIFT)Quoted 2 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_END_CFG_SHIFT 2 +#define FSPI_MCR0_END_CFG_MASK (3 <<
FSPI_MCR0_END_CFG_SHIFT)Quoted 4 lines
drivers/spi/spi-nxp-fspi.c
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+#define FSPI_MCR0_MDIS_SHIFT 1 +#define FSPI_MCR0_MDIS_MASK (1 << FSPI_MCR0_MDIS_SHIFT) +#define FSPI_MCR0_SWRST_SHIFT 0 +#define FSPI_MCR0_SWRST_MASK (1 <<
FSPI_MCR0_SWRST_SHIFT)Quoted 80 lines
Do we really need all those _SHIFT/_MASK defs? I mean
#define
FSPI_MCR0_SWRSTBIT(0)or
#define
FSPI_MCR0_AHB_TIMEOUT(x)((x) << 24)
#defineFSPI_MCR0_AHB_TIMEOUT_MASKGENMASK(31, 24)are just fine.
drivers/spi/spi-nxp-fspi.c line 422
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+ +enum nxp_fspi_devtype { +NXP_FSPI_LX2160A , +};I'm pretty sure you don't need this enum if you describe all dev caps in the
nxp_fspi_devtype_datastruct.drivers/spi/spi-nxp-fspi.c line 430
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c new file +8
-0+ +struct nxp_fspi_devtype_data { +enum nxp_fspi_devtype devtype; +unsigned int rxfifo; +unsigned int txfifo; +unsigned int ahb_buf_size; +unsigned int quirks; +bool endianness;How about renaming this variable
big_endianand dropping the {L,B}_ENDIAN macros?Quoted 1 line
+};
[...]
Quoted 21 lines
drivers/spi/spi-nxp-fspi.c new file +21
-0+struct nxp_fspi { +void __iomem *iobase; +void __iomem *ahb_addr; +u32 memmap_phy; +u32 memmap_phy_size; +struct clk *clk, *clk_en; +struct device *dev; +struct completion c; +const struct nxp_fspi_devtype_data *devtype_data; +struct mutex lock; +struct pm_qos_request pm_qos_req; +int selected; +void (*write)(u32 val,void __iomem *addr); +u32 (*read)(void __iomem *addr); +}; + +static void fspi_writel_be (u32 val,void __iomem *addr) { +iowrite32be (val, addr); +} + +static void fspi_writel (u32 val,void __iomem *addr) {drivers/spi/spi-nxp-fspi.c line 478
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+iowrite32 (val, addr); +} + +static u32 fspi_readl_be (void __iomem *addr) { +return ioread32be (addr); +} + +static u32 fspi_readl (void __iomem *addr) { +return ioread32 (addr); +}Hm, I'd recommend dropping the ->read/write() hooks and providing the following functions:
static void fspi_writel(struct
nxp_fspi*f, u32 val, void__iomem*addr) { if (f->big_endian) iowrite32be(val, addr); else iowrite32(val, addr); }Quoted 6 lines
static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) { if (f->big_endian) return ioread32be(addr); else return ioread32(addr); }
Quoted 4 lines
I introduced the ->read/write() hooks in the QSPI driver because I was told to remove the conditional in the read/write path, but I can't really tell if this really makes any difference.
Yes, I have taken these hooks by looking into the comments received for Frieder's QSPI patch series.
For me this looks more clean and can be decided in the controller initialization sequence which hook would going to be invoked.
Quoted 48 lines
Regards,
FriederQuoted 45 lines
Quoted 15 lines
drivers/spi/spi-nxp-fspi.c new file +14
-0+ +static irqreturn_t nxp_fspi_irq_handler (int irq,void *dev_id) { +struct nxp_fspi *f = dev_id; +u32 reg; + +/* clear interrupt */ + reg = f->read (f->iobase +FSPI_INTR ); + f->write (FSPI_INTR_IPCMDDONE_MASK , f->iobase +FSPI_INTR ); + +if (reg &FSPI_INTR_IPCMDDONE_MASK ) +complete (&f->c); + +return IRQ_HANDLED ; +}[...]
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+/* +* If the slave device content being changed by Write/Erase, need to +* invalidate the AHB buffer. This can be achieved by doing the +reset drivers/spi/spi-nxp-fspi.c line 569
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+* of controller after setting MCR0[SWRESET] bit. +*/ +static inline void nxp_fspi_invalid (struct nxp_fspi *f) { +u32 reg; + + reg = f->read (f->iobase +FSPI_MCR0 ); + f->write (reg |FSPI_MCR0_SWRST_MASK , f->iobase +FSPI_MCR0 ); + +while (f->read (f->iobase +FSPI_MCR0 ) &FSPI_MCR0_SWRST_MASK ) + ;Did you consider using readl_poll_timeout[_atomic]()?
if (f->big_endian) mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); else mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); ret = readl_poll_timeout(f->iobase + FSPI_MCR0, reg, reg & mask, 0, FSPI_SWRST_TIMEOUT); WARN_ON(ret);Quoted 1 line
+}
Ok, would check usage of readl_poll_timeout_atomic() and modify current implementation of doing busy waiting using while() loop.
--
Regards
Yogesh Gaur.
Quoted 75 lines
Quoted 75 lines
[...]
drivers/spi/spi-nxp-fspi.c line 756
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c new file +6
-0+static void nxp_fspi_read_ahb (struct nxp_fspi *f,const struct +spi_mem_op *op) { +u32 len = op->data.nbytes; + +/* Read out the data directly from the AHB buffer. */ +memcpy_fromio (op->data.buf.in, (f->ahb_addr + op->addr.val), len);Don't know if it's supported, but if it is, I recommend using DMA to do this copy, because otherwise you might stall the CPU for quite a long time if the flash is operating in a low-speed mode, and RT maintainers will complain about that at some point ;-).
Quoted 11 lines
drivers/spi/spi-nxp-fspi.c new file +11
-0+} + +static void nxp_fspi_fill_txfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, j; +int size, tmp_size, wm_size; +u32 data =0 ; +u32 *txbuf = (u32 *) op->data.buf.out; +drivers/spi/spi-nxp-fspi.c line 777
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* clear the TX FIFO. */ + f->write (FSPI_IPTXFCR_CLR_MASK , base +FSPI_IPTXFCR ); + +/* Default value of water mark level is 8 bytes. */ + wm_size =8 ; + size = op->data.nbytes / wm_size; +for (i =0 ; i < size; i++) { +/* Wait for TXFIFO empty */ +while (!(f->read (base +FSPI_INTR ) &FSPI_INTR_IPTXWE_MASK )) + ;Use
readl_poll_timeout(), or even better, provide an helper (fspi_readl_poll_timeout()?) that hides the BE/LE stuff, so that you can reuse it when this pattern occurs.[...]
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c new file +9
-0+static int nxp_fspi_exec_op (struct spi_mem *mem,const struct +spi_mem_op *op) { +struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->master); +void __iomem *base = f->iobase; +int err =0 ; +unsigned int timeout =1000 ; + +mutex_lock (&f->lock); +drivers/spi/spi-nxp-fspi.c line 931
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* wait for the controller being ready */ + do { + u32 status; + + status = f->read(base + FSPI_STS0); + if ((status & FSPI_STS0_ARB_IDLE_MASK) && + (status & FSPI_STS0_SEQ_IDLE_MASK)) + break; + udelay(1); + dev_dbg(f->dev, "The controller is busy, 0x%x\n", status);Same here.
Note that I didn't spend time looking at how the IP works, which explains why I focus on tiny details here. Unfortunately, I won't have time to review the driver in more details, so I'll leave that to someone else, or let Mark decides if he's happy enough with the current version.
Regards,
Boris
Quoted 16 lines · On Mon, 1 Oct 2018 09:02:32 +0000 Yogesh Narayan Gaur…
Quoted 16 lines
Quoted 15 lines
static void fspi_writel(struct
nxp_fspi*f, u32 val, void__iomem*addr) { if (f->big_endian) iowrite32be(val, addr); else iowrite32(val, addr); }static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) { if (f->big_endian) return ioread32be(addr); else return ioread32(addr); }
Quoted 8 lines
Quoted 4 lines
I introduced the ->read/write() hooks in the QSPI driver because I was told to remove the conditional in the read/write path, but I can't really tell if this really makes any difference.
Yes, I have taken these hooks by looking into the comments received for Frieder's QSPI patch series. For me this looks more clean and can be decided in the controller initialization sequence which hook would going to be invoked.
Well, depending on your CPU, the indirect branch (caused by the function pointer call) might have an higher cost than the conditional branch. Not sure we care about such micro-optimizations though. Regarding the readability aspect, I still prefer my version, but I guess that's a matter of taste.
Hi Boris,
Quoted 53 lines
-----Original Message-----
From: Boris Brezillon [mailto:boris.brezillon at bootlin.com]
Sent: Saturday, September 29, 2018 9:10 PM
To: Yogesh Narayan Gaur <[email protected]>
Cc: linux-mtd at lists.infradead.org; marek.vasut at gmail.com; linux- spi at vger.kernel.org; devicetree at vger.kernel.org; robh at kernel.org; mark.rutland at arm.com; shawnguo at kernel.org; linux-arm-
kernel at lists.infradead.org; computersforpeace at gmail.com; frieder.schrempf at exceet.de; linux-kernel at vger.kernel.org
Subject: Re: [PATCH v3 1/5] spi: spi-mem: Add driver for NXP FlexSPI controllerHi Yogesh,
drivers/spi/spi-nxp-fspi.c
Quoted 4 lines · On Fri, 21 Sep 2018 15:51:59 +0530 Yogesh Gaur <[email protected]>…
drivers/spi/spi-nxp-fspi.c new file +4
-0+/* Registers used by the driver */ +#define FSPI_MCR0 0x00 +#define FSPI_MCR0_AHB_TIMEOUT_SHIFT 24 +#define FSPI_MCR0_AHB_TIMEOUT_MASK (0xFF <<
FSPI_MCR0_AHB_TIMEOUT_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_IP_TIMEOUT_SHIFT 16 +#define FSPI_MCR0_IP_TIMEOUT_MASK (0xFF <<
FSPI_MCR0_IP_TIMEOUT_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_LEARN_EN_SHIFT 15 +#define FSPI_MCR0_LEARN_EN_MASK (1 <<
FSPI_MCR0_LEARN_EN_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_SCRFRUN_EN_SHIFT 14 +#define FSPI_MCR0_SCRFRUN_EN_MASK (1 <<
FSPI_MCR0_SCRFRUN_EN_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_OCTCOMB_EN_SHIFT 13 +#define FSPI_MCR0_OCTCOMB_EN_MASK (1 <<
FSPI_MCR0_OCTCOMB_EN_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_DOZE_EN_SHIFT 12 +#define FSPI_MCR0_DOZE_EN_MASK (1 <<
FSPI_MCR0_DOZE_EN_SHIFT)drivers/spi/spi-nxp-fspi.c
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+#define FSPI_MCR0_HSEN_SHIFT 11 +#define FSPI_MCR0_HSEN_MASK (1 << FSPI_MCR0_HSEN_SHIFT) +#define FSPI_MCR0_SERCLKDIV_SHIFT 8 +#define FSPI_MCR0_SERCLKDIV_MASK (7 <<
FSPI_MCR0_SERCLKDIV_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_ATDF_EN_SHIFT 7 +#define FSPI_MCR0_ATDF_EN_MASK (1 <<
FSPI_MCR0_ATDF_EN_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_ARDF_EN_SHIFT 6 +#define FSPI_MCR0_ARDF_EN_MASK (1 <<
FSPI_MCR0_ARDF_EN_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_RXCLKSRC_SHIFT 4 +#define FSPI_MCR0_RXCLKSRC_MASK (3 <<
FSPI_MCR0_RXCLKSRC_SHIFT)Review
Quoted 2 lines
(quoted diff) +2
-0+#define FSPI_MCR0_END_CFG_SHIFT 2 +#define FSPI_MCR0_END_CFG_MASK (3 <<
FSPI_MCR0_END_CFG_SHIFT)
Quoted 8 lines
drivers/spi/spi-nxp-fspi.c
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+#define FSPI_MCR0_MDIS_SHIFT 1 +#define FSPI_MCR0_MDIS_MASK (1 << FSPI_MCR0_MDIS_SHIFT) +#define FSPI_MCR0_SWRST_SHIFT 0 +#define FSPI_MCR0_SWRST_MASK (1 <<
FSPI_MCR0_SWRST_SHIFT)Do we really need all those _SHIFT/_MASK defs? I mean
Changes done in next version of the patch series, v4 [1].
Quoted 9 lines
#define
FSPI_MCR0_SWRSTBIT(0)or
#define
FSPI_MCR0_AHB_TIMEOUT(x)((x) << 24)
#defineFSPI_MCR0_AHB_TIMEOUT_MASKGENMASK(31, 24)are just fine.
Quoted 7 lines
drivers/spi/spi-nxp-fspi.c line 422
Quoted 4 lines
drivers/spi/spi-nxp-fspi.c new file +4
-0+ +enum nxp_fspi_devtype { +NXP_FSPI_LX2160A , +};I'm pretty sure you don't need this enum if you describe all dev caps in the
nxp_fspi_devtype_datastruct.
Done, in v4.
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c line 430
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c new file +8
-0+ +struct nxp_fspi_devtype_data { +enum nxp_fspi_devtype devtype; +unsigned int rxfifo; +unsigned int txfifo; +unsigned int ahb_buf_size; +unsigned int quirks; +bool endianness;How about renaming this variable
big_endianand dropping the {L,B}_ENDIAN macros?
Done in v4, default make as little_endian to reduce indirect branch checking.
Quoted 87 lines
Quoted 1 line
+};
[...]
Quoted 21 lines
drivers/spi/spi-nxp-fspi.c new file +21
-0+struct nxp_fspi { +void __iomem *iobase; +void __iomem *ahb_addr; +u32 memmap_phy; +u32 memmap_phy_size; +struct clk *clk, *clk_en; +struct device *dev; +struct completion c; +const struct nxp_fspi_devtype_data *devtype_data; +struct mutex lock; +struct pm_qos_request pm_qos_req; +int selected; +void (*write)(u32 val,void __iomem *addr); +u32 (*read)(void __iomem *addr); +}; + +static void fspi_writel_be (u32 val,void __iomem *addr) { +iowrite32be (val, addr); +} + +static void fspi_writel (u32 val,void __iomem *addr) {drivers/spi/spi-nxp-fspi.c line 478
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+iowrite32 (val, addr); +} + +static u32 fspi_readl_be (void __iomem *addr) { +return ioread32be (addr); +} + +static u32 fspi_readl (void __iomem *addr) { +return ioread32 (addr); +}Hm, I'd recommend dropping the ->read/write() hooks and providing the following functions:
static void fspi_writel(struct nxp_fspi *f, u32 val, void __iomem *addr) { if (f->big_endian) iowrite32be(val, addr); else iowrite32(val, addr); }static u32 fspi_readl(struct nxp_fspi *f, void __iomem *addr) { if (f->big_endian) return ioread32be(addr); else return ioread32(addr); }Quoted 14 lines
drivers/spi/spi-nxp-fspi.c new file +14
-0+ +static irqreturn_t nxp_fspi_irq_handler (int irq,void *dev_id) { +struct nxp_fspi *f = dev_id; +u32 reg; + +/* clear interrupt */ + reg = f->read (f->iobase +FSPI_INTR ); + f->write (FSPI_INTR_IPCMDDONE_MASK , f->iobase +FSPI_INTR ); + +if (reg &FSPI_INTR_IPCMDDONE_MASK ) +complete (&f->c); + +return IRQ_HANDLED ; +}[...]
drivers/spi/spi-nxp-fspi.c line 569
Quoted 13 lines
drivers/spi/spi-nxp-fspi.c new file +13
-0+/* +* If the slave device content being changed by Write/Erase, need to +* invalidate the AHB buffer. This can be achieved by doing the reset +* of controller after setting MCR0[SWRESET] bit. +*/ +static inline void nxp_fspi_invalid (struct nxp_fspi *f) { +u32 reg; + + reg = f->read (f->iobase +FSPI_MCR0 ); + f->write (reg |FSPI_MCR0_SWRST_MASK , f->iobase +FSPI_MCR0 ); + +while (f->read (f->iobase +FSPI_MCR0 ) &FSPI_MCR0_SWRST_MASK ) + ;Did you consider using readl_poll_timeout[_atomic]()?
Quoted 11 lines
if (f->big_endian) mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); else mask = (u32)cpu_to_be32(FSPI_MCR0_SWRST_MASK); ret = readl_poll_timeout(f->iobase + FSPI_MCR0, reg, reg & mask, 0, FSPI_SWRST_TIMEOUT); WARN_ON(ret);Quoted 1 line
+}
Thanks, added readl_poll_timeout() functionality instead of busy looping.
Quoted 14 lines
[...]
drivers/spi/spi-nxp-fspi.c line 756
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c new file +6
-0+static void nxp_fspi_read_ahb (struct nxp_fspi *f,const struct +spi_mem_op *op) { +u32 len = op->data.nbytes; + +/* Read out the data directly from the AHB buffer. */ +memcpy_fromio (op->data.buf.in, (f->ahb_addr + op->addr.val), len);Don't know if it's supported, but if it is, I recommend using DMA to do this copy, because otherwise you might stall the CPU for quite a long time if the flash is operating in a low-speed mode, and RT maintainers will complain about that at some point ;-).
Read using DMA is not supported by the controller in AHB mode, only supported in IP mode. Have to use memcpy_fromio() calls. Maximum data size can be read in single call is 0x800 using AHB read.
--
Regards
Yogesh Gaur.
[1] https://patchwork.ozlabs.org/project/linux-mtd/list/?series=69535
Quoted 58 lines
Quoted 11 lines
drivers/spi/spi-nxp-fspi.c new file +11
-0+} + +static void nxp_fspi_fill_txfifo (struct nxp_fspi *f, +const struct spi_mem_op *op) +{ +void __iomem *base = f->iobase; +int i, j; +int size, tmp_size, wm_size; +u32 data =0 ; +u32 *txbuf = (u32 *) op->data.buf.out; +drivers/spi/spi-nxp-fspi.c line 777
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* clear the TX FIFO. */ + f->write (FSPI_IPTXFCR_CLR_MASK , base +FSPI_IPTXFCR ); + +/* Default value of water mark level is 8 bytes. */ + wm_size =8 ; + size = op->data.nbytes / wm_size; +for (i =0 ; i < size; i++) { +/* Wait for TXFIFO empty */ +while (!(f->read (base +FSPI_INTR ) &FSPI_INTR_IPTXWE_MASK )) + ;Use
readl_poll_timeout(), or even better, provide an helper (fspi_readl_poll_timeout()?) that hides the BE/LE stuff, so that you can reuse it when this pattern occurs.[...]
Quoted 9 lines
drivers/spi/spi-nxp-fspi.c new file +9
-0+static int nxp_fspi_exec_op (struct spi_mem *mem,const struct +spi_mem_op *op) { +struct nxp_fspi *f =spi_controller_get_devdata (mem->spi->master); +void __iomem *base = f->iobase; +int err =0 ; +unsigned int timeout =1000 ; + +mutex_lock (&f->lock); +drivers/spi/spi-nxp-fspi.c line 931
Quoted 10 lines
drivers/spi/spi-nxp-fspi.c new file +10
-0+/* wait for the controller being ready */ + do { + u32 status; + + status = f->read(base + FSPI_STS0); + if ((status & FSPI_STS0_ARB_IDLE_MASK) && + (status & FSPI_STS0_SEQ_IDLE_MASK)) + break; + udelay(1); + dev_dbg(f->dev, "The controller is busy, 0x%x\n", status);Same here.
Note that I didn't spend time looking at how the IP works, which explains why I focus on tiny details here. Unfortunately, I won't have time to review the driver in more details, so I'll leave that to someone else, or let Mark decides if he's happy enough with the current version.
Regards,
Boris
Quoted 12 lines · On Mon, 8 Oct 2018 11:21:13 +0000 Yogesh Narayan Gaur…
Quoted 12 lines
drivers/spi/spi-nxp-fspi.c line 756
Quoted 6 lines
drivers/spi/spi-nxp-fspi.c new file +6
-0+static void nxp_fspi_read_ahb (struct nxp_fspi *f,const struct +spi_mem_op *op) { +u32 len = op->data.nbytes; + +/* Read out the data directly from the AHB buffer. */ +memcpy_fromio (op->data.buf.in, (f->ahb_addr + op->addr.val), len);Don't know if it's supported, but if it is, I recommend using DMA to do this copy, because otherwise you might stall the CPU for quite a long time if the flash is operating in a low-speed mode, and RT maintainers will complain about that at some point ;-).
Quoted 3 lines
Read using DMA is not supported by the controller in AHB mode, only supported in IP mode. Have to use
memcpy_fromio()calls. Maximum data size can be read in single call is0x800using AHB read.
Still, blocking the CPU until the SPI controller has read 0x800 bytes is enough to make you miss a real-time deadline. Don't you have a controller that supports mem2mem transfers (I'm pretty sure a mem2mem DMA transfer would do the trick here)?
Regards,
Boris
PATCH v3 2/5 dt-bindings: spi: add binding file for NXP FlexSPI controller
In reply to Yogesh GaurAdd binding file for NXP FlexSPI controller
---
Changes for v3:
- None
Changes for v2:
- Incorporated Rob review comments.
.../devicetree/bindings/spi/spi-nxp-fspi.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +42 -0
@@ -0,0 +1,42 @@ +* 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 + +Optional properties: + - big-endian : See common-properties.txt. + +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: + +fspi at 0: flexspi at 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"; + + flash at 0: mt35xu512aba at 0 { + reg = <0>; + .... + }; + + flash at 1: mt35xu512aba at 1 { + reg = <1>; + .... + }; +};
Signature · 1 line
2.7.4
Rob Herring
maintainerRe: [PATCH v3 2/5] dt-bindings: spi: add binding file for NXP FlexSPI controller
Quoted 34 lines · Yogesh Gaur
Add binding file for NXP FlexSPI controller
Signed-off-by Yogesh Gaur <[email protected]>---
Changes for v3:
- None
Changes for v2:
- Incorporated Rob review comments..../devicetree/bindings/spi/spi-nxp-fspi.txt | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Documentation/devicetree/bindings/spi/spi-nxp-fspi.txtDocumentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +15
-0@@ -0,0 +1,42 @@ +* 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 + +Optional properties: + - big-endian : See common-properties.txt. + +Required SPI slave node properties:
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt line 25
Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +10
-0+ - 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: + +fspi at 0: flexspi at 20c0000 {
Use standard node names.
spi at ...
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt line 33
Quoted 8 lines
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +8
-0+ 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"; + + flash at 0: mt35xu512aba at 0 {
You've got the label and node name reversed. Drop the '@' in the label. That should be reserved for node names.
Quoted 12 lines
Documentation/devicetree/bindings/spi/spi-nxp-fspi.txt new file +9
-0+ reg = <0>; + .... + }; + + flash at 1: mt35xu512aba at 1 { + reg = <1>; + .... + }; +};Signature · 1 line
2.7.4
PATCH v3 3/5 arm64: dts: lx2160a: add FlexSPI node property
In reply to Yogesh 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 v3:
- None
Changes for v2:
- Incorporated Shawn review comments.
arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts | 22 ++++++++++++++++++++++ arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi | 12 ++++++++++++ 2 files changed, 34 insertions(+)
arch/arm64/boot/dts/freescale/fsl-lx2160a-rdb.dts +22 -0
@@ -32,6 +32,28 @@ status = "okay"; }; +&fspi { + status = "okay"; + + mt35xu512aba0: flash at 0 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "spansion,m25p80"; + m25p,fast-read; + spi-max-frequency = <20000000>; + reg = <0>; + }; + + mt35xu512aba1: flash at 1 { + #address-cells = <1>; + #size-cells = <1>; + compatible = "spansion,m25p80"; + m25p,fast-read; + spi-max-frequency = <20000000>; + reg = <1>; + }; +}; + &i2c0 { status = "okay"; pca9547 at 77 {
arch/arm64/boot/dts/freescale/fsl-lx2160a.dtsi +12 -0
@@ -568,5 +568,17 @@ timeout-sec = <30>; }; + fspi: flexspi at 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.7.4
PATCH v3 4/5 arm64: defconfig: enable NXP FlexSPI driver
In reply to Yogesh GaurEnable driver support of NXP FlexSPI controller.
---
Changes for v3:
- None
Changes for v2:
- None
arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -335,6 +335,7 @@ CONFIG_SPI_QUP=y CONFIG_SPI_ROCKCHIP=y CONFIG_SPI_S3C64XX=y CONFIG_SPI_SPIDEV=m +CONFIG_SPI_NXP_FLEXSPI=y CONFIG_SPMI=y CONFIG_PINCTRL_IPQ8074=y CONFIG_PINCTRL_SINGLE=y
Signature · 1 line
2.7.4
PATCH v3 5/5 MAINTAINERS: add maintainers for the NXP FlexSPI driver
In reply to Yogesh GaurAdd maintainers for the NXP FlexSPI driver
---
Changes for v3:
- None
Changes for v2:
- None
MAINTAINERS | 6 ++++++ 1 file changed, 6 insertions(+)
MAINTAINERS +6 -0
@@ -10228,6 +10228,12 @@ L: linux-nfc at lists.01.org (moderated for non-subscribers) S: Supported F: drivers/nfc/nxp-nci +NXP FSPI DRIVER +M: Yogesh Gaur <[email protected]> +L: linux-spi at vger.kernel.org +S: Maintained +F: drivers/spi/spi-nxp-fspi.c + OBJTOOL M: Josh Poimboeuf <[email protected]> M: Peter Zijlstra <[email protected]>
Signature · 1 line
2.7.4