Skip to contentSkip to conversation

devicetree: Add devicetree bindings documentation for ZynqMP GQSPI

RFC PATCH In review Ranjit Waghmode 5 participants 12 messages May 20, 2015 – May 29, 2015

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/2 devicetree: Add devicetree bindings documentation for ZynqMP GQSPI

Add bindings documentation for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---
 .../devicetree/bindings/spi/spi-zynqmp-qspi.txt    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt new file +26 -0
new file mode 100644
index 0000000..cec6330
@@ -0,0 +1,26 @@
+Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
+-------------------------------------------------------------------
+
+Required properties:
+- compatible		: Should be "xlnx,zynqmp-qspi-1.0".
+- reg			: Physical base address and size of GQSPI registers map.
+- interrupts		: Property with a value describing the interrupt
+			  number.
+- interrupt-parent	: Must be core interrupt controller.
+- clock-names		: List of input clock names - "ref_clk", "pclk"
+			  (See clock bindings for details).
+- clocks		: Clock phandles (see clock bindings for details).
+
+Optional properties:
+- num-cs		: Number of chip selects used.
+
+Example:
+	qspi: spi at ff0f0000 {
+		compatible = "xlnx,zynqmp-qspi-1.0";
+		clock-names = "ref_clk", "pclk";
+		clocks = <&misc_clk &misc_clk>;
+		interrupts = <0 15 4>;
+		interrupt-parent = <&gic>;
+		num-cs = <1>;
+		reg = <0x0 0xff0f0000 0x1000 0x0 0xc0000000 0x8000000>;
+	};

--
2.1.2

#1 lore raw

RFC PATCH 2/2 spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

This patch adds support for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---
 drivers/spi/Kconfig            |    6 +
 drivers/spi/Makefile           |    1 +
 drivers/spi/spi-zynqmp-gqspi.c | 1092 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1099 insertions(+)
 create mode 100644 drivers/spi/spi-zynqmp-gqspi.c
drivers/spi/Kconfig +6 -0
index 72b0590..4406a85 100644
@@ -610,6 +610,12 @@ config SPI_XTENSA_XTFPGA
 	  16 bit words in SPI mode 0, automatically asserting CS on transfer
 	  start and deasserting on end.
 
+config SPI_ZYNQMP_GQSPI
+	tristate "Xilinx ZynqMP GQSPI controller"
+	depends on SPI_MASTER
+	help
+	  Enables Xilinx GQSPI controller driver for Zynq UltraScale+ MPSoC.
+
 config SPI_NUC900
 	tristate "Nuvoton NUC900 series SPI"
 	depends on ARCH_W90X900
drivers/spi/Makefile +1 -0
index d8cbf65..52db832 100644
@@ -89,3 +89,4 @@ obj-$(CONFIG_SPI_TXX9)			+= spi-txx9.o
 obj-$(CONFIG_SPI_XCOMM)		+= spi-xcomm.o
 obj-$(CONFIG_SPI_XILINX)		+= spi-xilinx.o
 obj-$(CONFIG_SPI_XTENSA_XTFPGA)		+= spi-xtensa-xtfpga.o
+obj-$(CONFIG_SPI_ZYNQMP_GQSPI)		+= spi-zynqmp-gqspi.o
drivers/spi/spi-zynqmp-gqspi.c new file +1092 -0

1,092 lines not on this page · raw message

--
2.1.2

#2 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Hi Ranjit,

Quoted 5 lines · Ranjit Waghmode

This patch adds support for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---

[...]

Quoted 11 lines
drivers/spi/spi-zynqmp-gqspi.c new file +11 -0
+/**
+ * zynqmp_gqspi_read:	For GQSPI controller read operation
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @offset:	Offset from where to read
+ */
+static u32 zynqmp_gqspi_read(struct zynqmp_qspi *xqspi, u32 offset)
+{
+	return readl_relaxed(xqspi->regs + offset);
+}
+
+/**

drivers/spi/spi-zynqmp-gqspi.c line 196

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+ * zynqmp_gqspi_write:	For GQSPI controller write operation
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @offset:	Offset where to write
+ * @val:	Value to be written
+ */
+static inline void zynqmp_gqspi_write(struct zynqmp_qspi *xqspi, u32 offset,
+				      u32 val)
+{
+	writel_relaxed(val, (xqspi->regs + offset));
+}

why are you wrapping (readl|writel)_relaxed?

[...]

drivers/spi/spi-zynqmp-gqspi.c line 337

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+/**
+ * zynqmp_qspi_copy_read_data:	Copy data to RX buffer
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @data:	The 32 bit variable where data is stored
+ * @size:	Number of bytes to be copied from data to RX buffer
+ */
+static void zynqmp_qspi_copy_read_data(struct zynqmp_qspi *xqspi,
+				       u32 data, u8 size)
+{
+	memcpy(xqspi->rxbuf, ((u8 *) &data), size);

Is this cast really needed? IIRC, memcpy takes (void *). The outer parentheses for that argument are not needed.

Quoted 9 lines
drivers/spi/spi-zynqmp-gqspi.c new file +9 -0
+	xqspi->rxbuf += size;
+	xqspi->bytes_to_receive -= size;
+}
+
+/**
+ * zynqmp_prepare_transfer_hardware:	Prepares hardware for transfer.
+ * @master:	Pointer to the spi_master structure which provides
+ *		information about the controller.
+ *

drivers/spi/spi-zynqmp-gqspi.c line 356

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+ * This function enables SPI master controller.
+ *
+ * Return:	Always 0
+ */
+static int zynqmp_prepare_transfer_hardware(struct spi_master *master)
+{
+	struct zynqmp_qspi *xqspi = spi_master_get_devdata(master);
+
+	clk_enable(xqspi->refclk);
+	clk_enable(xqspi->pclk);

Did you consider using runtime_pm? Then this would just bit pm_runtime_get_sync(...)

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+	zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK);
+	return 0;
+}
+
+/**
+ * zynqmp_unprepare_transfer_hardware:	Relaxes hardware after transfer
+ * @master:	Pointer to the spi_master structure which provides
+ *		information about the controller.
+ *
+ * This function disables the SPI master controller.

drivers/spi/spi-zynqmp-gqspi.c line 376

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+ *
+ * Return:	Always 0
+ */
+static int zynqmp_unprepare_transfer_hardware(struct spi_master *master)
+{
+	struct zynqmp_qspi *xqspi = spi_master_get_devdata(master);
+
+	zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0);
+	clk_disable(xqspi->refclk);
+	clk_disable(xqspi->pclk);

and this would become pm_runtime_put()

[...]

drivers/spi/spi-zynqmp-gqspi.c line 504

Quoted 13 lines
drivers/spi/spi-zynqmp-gqspi.c new file +13 -0
+/**
+ * zynqmp_qspi_filltxfifo:	Fills the TX FIFO as long as there is room in
+ *				the FIFO or the bytes required to be
+ *				transmitted.
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @size:	Number of bytes to be copied from TX buffer to TX FIFO
+ */
+static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi *xqspi, int size)
+{
+	u32 count = 0;
+
+	while ((xqspi->bytes_to_transfer > 0) && (count < size)) {
+		writel(*((u32 *) xqspi->txbuf), xqspi->regs + GQSPI_TXD_OFST);

Here the writel wrapper is not used. Is there a reason, then it would probably deserve a comment.

[...]

Quoted 25 lines
drivers/spi/spi-zynqmp-gqspi.c new file +25 -0
+/**
+ * zynqmp_process_dma_irq:	Handler for DMA done interrupt of QSPI
+ *				controller
+ * @xqspi:	zynqmp_qspi instance pointer
+ *
+ * This function handles DMA interrupt only.
+ */
+static void zynqmp_process_dma_irq(struct zynqmp_qspi *xqspi)
+{
+	u32 config_reg, genfifoentry;
+
+	dma_unmap_single(xqspi->dev, xqspi->dma_addr,
+				xqspi->dma_rx_bytes, DMA_FROM_DEVICE);
+	xqspi->rxbuf += xqspi->dma_rx_bytes;
+	xqspi->bytes_to_receive -= xqspi->dma_rx_bytes;
+	xqspi->dma_rx_bytes = 0;
+
+	/* Disabling the DMA interrupts */
+	writel(GQSPI_QSPIDMA_DST_I_EN_DONE_MASK,
+			xqspi->regs + GQSPI_QSPIDMA_DST_I_DIS_OFST);
+
+	if (xqspi->bytes_to_receive > 0) {
+		/* Switch to IO mode,for remaining bytes to receive */
+		config_reg = readl(xqspi->regs + GQSPI_CONFIG_OFST);
+		config_reg &= ~GQSPI_CFG_MODE_EN_MASK;

drivers/spi/spi-zynqmp-gqspi.c line 578

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+		writel(config_reg, xqspi->regs + GQSPI_CONFIG_OFST);
+
+		/* Initiate the transfer of remaining bytes */
+		genfifoentry = xqspi->genfifoentry;
+		genfifoentry |= xqspi->bytes_to_receive;
+		writel(genfifoentry,
+				xqspi->regs + GQSPI_GEN_FIFO_OFST);
+
+		/* Dummy generic FIFO entry */
+		writel(0x0, xqspi->regs + GQSPI_GEN_FIFO_OFST);

not using wrapper?

drivers/spi/spi-zynqmp-gqspi.c line 582

Quoted 4 lines
drivers/spi/spi-zynqmp-gqspi.c new file +4 -0
+
+		/* Manual start */
+		zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+			(readl(xqspi->regs + GQSPI_CONFIG_OFST) |

not using wrapper?

Overall:
The usage of those readl/writel wrappers seems inconsistent to me. I usually prefer not wrapping things like that at all but at least it should be consistent.

And I believe the handling of clocks would benefit from using of the runtime_pm framework.

Thanks,
S?ren

maintainer
#3 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Quoted 8 lines · S?ren Brinkmann

drivers/spi/spi-zynqmp-gqspi.c line 193

Quoted 4 lines · Ranjit Waghmode
drivers/spi/spi-zynqmp-gqspi.c new file +3 -0
+static u32 zynqmp_gqspi_read(struct zynqmp_qspi *xqspi, u32 offset)
 
+static inline void zynqmp_gqspi_write(struct zynqmp_qspi *xqspi, u32 offset,
+				      u32 val)

why are you wrapping (readl|writel)_relaxed?

It's very common to wrap the lookup from driver data to the MMIO
address.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150520/ea9b9d27/attachment.sig>

#4 lore raw

RE: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

In reply to Sören Brinkmann

Hi Soren,

Sorry for being late for this reply as this thread is moved a step ahead.

Quoted 5 lines · Ranjit Waghmode

This patch adds support for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---

[...]

Quoted 8 lines
drivers/spi/spi-zynqmp-gqspi.c new file +8 -0
+/**
+ * zynqmp_gqspi_read:	For GQSPI controller read operation
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @offset:	Offset from where to read
+ */
+static u32 zynqmp_gqspi_read(struct zynqmp_qspi *xqspi, u32 offset) {
+	return readl_relaxed(xqspi->regs + offset); }
+

drivers/spi/spi-zynqmp-gqspi.c

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+/**
+ * zynqmp_gqspi_write:	For GQSPI controller write operation
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @offset:	Offset where to write
+ * @val:	Value to be written
+ */
+static inline void zynqmp_gqspi_write(struct zynqmp_qspi *xqspi, u32 offset,
+				      u32 val)
+{
+	writel_relaxed(val, (xqspi->regs + offset)); }

why are you wrapping (readl|writel)_relaxed?

[...]

drivers/spi/spi-zynqmp-gqspi.c line 337

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+/**
+ * zynqmp_qspi_copy_read_data:	Copy data to RX buffer
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @data:	The 32 bit variable where data is stored
+ * @size:	Number of bytes to be copied from data to RX buffer
+ */
+static void zynqmp_qspi_copy_read_data(struct zynqmp_qspi *xqspi,
+				       u32 data, u8 size)
+{
+	memcpy(xqspi->rxbuf, ((u8 *) &data), size);

Is this cast really needed? IIRC, memcpy takes (void *). The outer parentheses for that argument are not needed. [Ranjit] : taken care

Quoted 9 lines
drivers/spi/spi-zynqmp-gqspi.c new file +9 -0
+	xqspi->rxbuf += size;
+	xqspi->bytes_to_receive -= size;
+}
+
+/**
+ * zynqmp_prepare_transfer_hardware:	Prepares hardware for transfer.
+ * @master:	Pointer to the spi_master structure which provides
+ *		information about the controller.
+ *

drivers/spi/spi-zynqmp-gqspi.c line 356

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+ * This function enables SPI master controller.
+ *
+ * Return:	Always 0
+ */
+static int zynqmp_prepare_transfer_hardware(struct spi_master 
+*master) {
+	struct zynqmp_qspi *xqspi = spi_master_get_devdata(master);
+
+	clk_enable(xqspi->refclk);
+	clk_enable(xqspi->pclk);

Did you consider using runtime_pm? Then this would just bit pm_runtime_get_sync(...)

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+	zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, GQSPI_EN_MASK);
+	return 0;
+}
+
+/**
+ * zynqmp_unprepare_transfer_hardware:	Relaxes hardware after transfer
+ * @master:	Pointer to the spi_master structure which provides
+ *		information about the controller.
+ *
+ * This function disables the SPI master controller.

drivers/spi/spi-zynqmp-gqspi.c line 376

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+ *
+ * Return:	Always 0
+ */
+static int zynqmp_unprepare_transfer_hardware(struct spi_master 
+*master) {
+	struct zynqmp_qspi *xqspi = spi_master_get_devdata(master);
+
+	zynqmp_gqspi_write(xqspi, GQSPI_EN_OFST, 0x0);
+	clk_disable(xqspi->refclk);
+	clk_disable(xqspi->pclk);

and this would become pm_runtime_put()

[...]

drivers/spi/spi-zynqmp-gqspi.c line 504

Quoted 13 lines
drivers/spi/spi-zynqmp-gqspi.c new file +13 -0
+/**
+ * zynqmp_qspi_filltxfifo:	Fills the TX FIFO as long as there is room in
+ *				the FIFO or the bytes required to be
+ *				transmitted.
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @size:	Number of bytes to be copied from TX buffer to TX FIFO
+ */
+static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi *xqspi, int 
+size) {
+	u32 count = 0;
+
+	while ((xqspi->bytes_to_transfer > 0) && (count < size)) {
+		writel(*((u32 *) xqspi->txbuf), xqspi->regs + GQSPI_TXD_OFST);

Here the writel wrapper is not used. Is there a reason, then it would probably deserve a comment.

[...]

Quoted 24 lines
drivers/spi/spi-zynqmp-gqspi.c new file +24 -0
+/**
+ * zynqmp_process_dma_irq:	Handler for DMA done interrupt of QSPI
+ *				controller
+ * @xqspi:	zynqmp_qspi instance pointer
+ *
+ * This function handles DMA interrupt only.
+ */
+static void zynqmp_process_dma_irq(struct zynqmp_qspi *xqspi) {
+	u32 config_reg, genfifoentry;
+
+	dma_unmap_single(xqspi->dev, xqspi->dma_addr,
+				xqspi->dma_rx_bytes, DMA_FROM_DEVICE);
+	xqspi->rxbuf += xqspi->dma_rx_bytes;
+	xqspi->bytes_to_receive -= xqspi->dma_rx_bytes;
+	xqspi->dma_rx_bytes = 0;
+
+	/* Disabling the DMA interrupts */
+	writel(GQSPI_QSPIDMA_DST_I_EN_DONE_MASK,
+			xqspi->regs + GQSPI_QSPIDMA_DST_I_DIS_OFST);
+
+	if (xqspi->bytes_to_receive > 0) {
+		/* Switch to IO mode,for remaining bytes to receive */
+		config_reg = readl(xqspi->regs + GQSPI_CONFIG_OFST);
+		config_reg &= ~GQSPI_CFG_MODE_EN_MASK;

drivers/spi/spi-zynqmp-gqspi.c line 578

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+		writel(config_reg, xqspi->regs + GQSPI_CONFIG_OFST);
+
+		/* Initiate the transfer of remaining bytes */
+		genfifoentry = xqspi->genfifoentry;
+		genfifoentry |= xqspi->bytes_to_receive;
+		writel(genfifoentry,
+				xqspi->regs + GQSPI_GEN_FIFO_OFST);
+
+		/* Dummy generic FIFO entry */
+		writel(0x0, xqspi->regs + GQSPI_GEN_FIFO_OFST);

not using wrapper?

drivers/spi/spi-zynqmp-gqspi.c line 582

Quoted 4 lines
drivers/spi/spi-zynqmp-gqspi.c new file +4 -0
+
+		/* Manual start */
+		zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+			(readl(xqspi->regs + GQSPI_CONFIG_OFST) |

not using wrapper?

Overall:
The usage of those readl/writel wrappers seems inconsistent to me. I usually prefer not wrapping things like that at all but at least it should be consistent. [Ranjit]: Removing all inconsistencies by using wrapper function everywhere.

And I believe the handling of clocks would benefit from using of the runtime_pm framework. [Ranjit]: Will add above suggestion and send next version.

Thanks & Regards,
Ranjit Waghmode

maintainer
#5 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

In reply to Ranjit Waghmode

On Wed, May 20, 2015 at 12:57:51PM +0530, Ranjit Waghmode wrote:

This looks pretty good overall but there are a few issues below from a first read through.

drivers/spi/spi-zynqmp-gqspi.c line 205

Quoted 2 lines
drivers/spi/spi-zynqmp-gqspi.c new file +2 -0
+static void zynqmp_gqspi_selectflash(struct zynqmp_qspi *instanceptr,
+				     u8 flashcs, u8 flashbus)

Is this a SPI controller or a flash controller? It looks like it is actually a SPI controller but the above is a bit worrying.

drivers/spi/spi-zynqmp-gqspi.c line 211

Quoted 6 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+{
+	/*
+	 * Bus and CS lines selected here will be updated in the instance and
+	 * used for subsequent GENFIFO entries during transfer.
+	 */
+	/* Choose slave select line */

Coding style - at least a blank linne between the two comment blocks.

drivers/spi/spi-zynqmp-gqspi.c line 223

Quoted 12 lines
drivers/spi/spi-zynqmp-gqspi.c new file +12 -0
+	switch (flashcs) {
+	case GQSPI_SELECT_FLASH_CS_BOTH:
+		instanceptr->genfifocs = GQSPI_GENFIFO_CS_LOWER |
+		    GQSPI_GENFIFO_CS_UPPER;
+		break;
+	case GQSPI_SELECT_FLASH_CS_UPPER:
+		instanceptr->genfifocs = GQSPI_GENFIFO_CS_UPPER;
+		break;
+	case GQSPI_SELECT_FLASH_CS_LOWER:
+	default:
+		instanceptr->genfifocs = GQSPI_GENFIFO_CS_LOWER;
+	}

Why is there a default case here? That's going to men we try to handle any random chip select that gets passed in as pointing to this lower device which doesn't seem right. The fact that this is trying to handle mirroring of the chip select to two devices is also raising alarm bells here...

drivers/spi/spi-zynqmp-gqspi.c line 340

Quoted 13 lines
drivers/spi/spi-zynqmp-gqspi.c new file +13 -0
+/**
+ * zynqmp_qspi_copy_read_data:	Copy data to RX buffer
+ * @xqspi:	Pointer to the zynqmp_qspi structure
+ * @data:	The 32 bit variable where data is stored
+ * @size:	Number of bytes to be copied from data to RX buffer
+ */
+static void zynqmp_qspi_copy_read_data(struct zynqmp_qspi *xqspi,
+				       u32 data, u8 size)
+{
+	memcpy(xqspi->rxbuf, ((u8 *) &data), size);
+	xqspi->rxbuf += size;
+	xqspi->bytes_to_receive -= size;
+}

This looks like there's some type abuse going on and is going to be broken for 64 bit systems - why are we passing pointers around as 32 bit unsigned values?

drivers/spi/spi-zynqmp-gqspi.c line 356

Quoted 6 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+static int zynqmp_prepare_transfer_hardware(struct spi_master *master)
+{
+	struct zynqmp_qspi *xqspi = spi_master_get_devdata(master);
+
+	clk_enable(xqspi->refclk);
+	clk_enable(xqspi->pclk);

Should be checking return codes here.

drivers/spi/spi-zynqmp-gqspi.c line 406

Quoted 8 lines
drivers/spi/spi-zynqmp-gqspi.c new file +7 -0
+static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
+{
 
+	if (is_high) {
+		/* Manually start the generic FIFO command */
+		zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+				zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+				GQSPI_CFG_START_GEN_FIFO_MASK);

No, this is broken - setting the chip select should set the chip select, it shouldn't have any impact on transfers. Transfers should be started in the transfer operations.

drivers/spi/spi-zynqmp-gqspi.c line 458

Quoted 5 lines
drivers/spi/spi-zynqmp-gqspi.c new file +5 -0
+	/* If req_hz == 0, default to lowest speed */
+	while ((baud_rate_val < GQSPI_BAUD_DIV_MAX) &&
+	       (clk_get_rate(xqspi->refclk) /
+		(GQSPI_BAUD_DIV_SHIFT << baud_rate_val)) > req_hz)
+		baud_rate_val++;

It'd be better to factor the clk_get_rate() out of the loop rather than repeatedly calling into the clock API.

drivers/spi/spi-zynqmp-gqspi.c line 490

Quoted 11 lines

+ * Sets the operational mode of QSPI controller for the next QSPI transfer,
+ * baud rate and divisor value to setup the requested qspi clock.
+ *
+ * Return: 0 Always
+ */

drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+static int zynqmp_qspi_setup(struct spi_device *qspi)
+{
+	if (qspi->master->busy)
+		return -EBUSY;
+	return zynqmp_qspi_setup_transfer(qspi, NULL);
+}

The setup() function shouldn't affect the hardwaer but _setup_transfer() does. See spi-summary.

Quoted 6 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+static void zynqmp_qspi_filltxfifo(struct zynqmp_qspi *xqspi, int size)
+{
+	u32 count = 0;
+
+	while ((xqspi->bytes_to_transfer > 0) && (count < size)) {
+		writel(*((u32 *) xqspi->txbuf), xqspi->regs + GQSPI_TXD_OFST);

drivers/spi/spi-zynqmp-gqspi.c line 514

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+		if (xqspi->bytes_to_transfer >= 4) {
+			xqspi->txbuf += 4;
+			xqspi->bytes_to_transfer -= 4;
+		} else {
+			xqspi->txbuf += xqspi->bytes_to_transfer;
+			xqspi->bytes_to_transfer = 0;
+		}
+		count++;
+	}
+}

This doesn't appear to take any account of endianness which is especially alarming in the case where we're dealing with the final word and the casting here looks unsafe. I'd expect to be using endanness annotated pointers with no need for casting.

drivers/spi/spi-zynqmp-gqspi.c line 556

Quoted 7 lines

+ */

drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+static void zynqmp_process_dma_irq(struct zynqmp_qspi *xqspi)
+{
+	u32 config_reg, genfifoentry;
+
+	dma_unmap_single(xqspi->dev, xqspi->dma_addr,
+				xqspi->dma_rx_bytes, DMA_FROM_DEVICE);

Don't manually do DMA mapping, let the core do it. It looks like we need to enhance the core DMA mapping to support partial mapping of transfers here, this case where you're doing the tail of the transfer as PIO is a reasonable one (I'm a bit surprised we haven't run into it before to be honest).

Quoted 5 lines
drivers/spi/spi-zynqmp-gqspi.c new file +5 -0
+static inline u32 zynqmp_qspi_selectspimode(u8 spimode)
+{
+	u32 mask;
+
+	switch (spimode) {

drivers/spi/spi-zynqmp-gqspi.c line 664

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+	case GQSPI_SELECT_MODE_DUALSPI:
+		mask = GQSPI_GENFIFO_MODE_DUALSPI;
+		break;
+	case GQSPI_SELECT_MODE_QUADSPI:
+		mask = GQSPI_GENFIFO_MODE_QUADSPI;
+		break;
+	case GQSPI_SELECT_MODE_SPI:
+	default:
+		mask = GQSPI_GENFIFO_MODE_SPI;
+	}

Again this default case looks buggy.

drivers/spi/spi-zynqmp-gqspi.c line 891

Quoted 10 lines
drivers/spi/spi-zynqmp-gqspi.c new file +10 -0
+static int __maybe_unused zynqmp_qspi_suspend(struct device *dev)
+{
+	struct platform_device *pdev = container_of(dev,
+						    struct platform_device,
+						    dev);
+	struct spi_master *master = platform_get_drvdata(pdev);
+
+	spi_master_suspend(master);
+
+	zynqmp_unprepare_transfer_hardware(master);

Why are you manually unpreparing the hardware here? Obviously if the core has suspended it ought to have done this...

drivers/spi/spi-zynqmp-gqspi.c line 1015

Quoted 5 lines
drivers/spi/spi-zynqmp-gqspi.c new file +5 -0
+	ret = of_property_read_u32(pdev->dev.of_node, "num-cs", &num_cs);
+	if (ret < 0)
+		master->num_chipselect = GQSPI_DEFAULT_NUM_CS;
+	else
+		master->num_chipselect = num_cs;

Why is this selectable from DT? I'm not seeing any code here which
really validates chip select numbers or handles arbatrary chip select
numbers...
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150522/1768a9da/attachment.sig>

#6 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Hi Mark,

Quoted 10 lines · Mark Brown

On Wed, May 20, 2015 at 12:57:51PM +0530, Ranjit Waghmode wrote:

This looks pretty good overall but there are a few issues below from a first read through.

drivers/spi/spi-zynqmp-gqspi.c line 205

Quoted 2 lines
drivers/spi/spi-zynqmp-gqspi.c new file +2 -0
+static void zynqmp_gqspi_selectflash(struct zynqmp_qspi *instanceptr,
+                                  u8 flashcs, u8 flashbus)

Is this a SPI controller or a flash controller? It looks like it is actually a SPI controller but the above is a bit worrying.

It is a Quad SPI controller. SPI NOR flash devices are the most common interface. But we hope to keep this driver generic.
The above function name is probably misleading; it can be renamed.

Quoted 23 lines

drivers/spi/spi-zynqmp-gqspi.c line 211

Quoted 7 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+{
+     /*
+      * Bus and CS lines selected here will be updated in the instance and
+      * used for subsequent GENFIFO entries during transfer.
+      */
+     /* Choose slave select line */

Coding style - at least a blank linne between the two comment blocks.

drivers/spi/spi-zynqmp-gqspi.c line 223

Quoted 12 lines
drivers/spi/spi-zynqmp-gqspi.c new file +12 -0
+     switch (flashcs) {
+     case GQSPI_SELECT_FLASH_CS_BOTH:
+             instanceptr->genfifocs = GQSPI_GENFIFO_CS_LOWER |
+                 GQSPI_GENFIFO_CS_UPPER;
+             break;
+     case GQSPI_SELECT_FLASH_CS_UPPER:
+             instanceptr->genfifocs = GQSPI_GENFIFO_CS_UPPER;
+             break;
+     case GQSPI_SELECT_FLASH_CS_LOWER:
+     default:
+             instanceptr->genfifocs = GQSPI_GENFIFO_CS_LOWER;
+     }
Quoted 5 lines

Why is there a default case here? That's going to men we try to handle any random chip select that gets passed in as pointing to this lower device which doesn't seem right. The fact that this is trying to handle mirroring of the chip select to two devices is also raising alarm bells here...

This SPI controller has two CS lines and two data bus. Two devices can be connected to these and either the upper or the lower or both (Explained below) can be selected.

When two flash devices are used, one of the HW configurations in which they can be connected is called "parallel" mode where they share the same CS but use separate 4 bit data bus each (essentially making it 8 bit bus width).
Another configuration is "stacked" mode where the
same 4 bit data bus is shared and lower or upper CS lines are used to select the flash.

Nevertheless, we will deal with acceptable ways to add such features incrementally or maybe send an RFC separately.
For the current patch (which is intended to support a single device), the above selection of "both" CS wont be necessary. @Ranjit, please remove it.

<snip>

Quoted 9 lines

drivers/spi/spi-zynqmp-gqspi.c line 406

Quoted 8 lines
drivers/spi/spi-zynqmp-gqspi.c new file +7 -0
+static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
+{
 
+     if (is_high) {
+             /* Manually start the generic FIFO command */
+             zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+                             zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+                             GQSPI_CFG_START_GEN_FIFO_MASK);
Quoted 4 lines

No, this is broken - setting the chip select should set the chip select, it shouldn't have any impact on transfers. Transfers should be started in the transfer operations.

This is the only way to assert the CS. It doesn't start transferring any data. The controller has a Generic FIFO. All operations to be performed on the bus have to be given in the form of any entry in this FIFO.
The controller fetches each entry from the FIFO and performs the operations. And that includes asserting and de-asserting CS. There is no dedicated register bit to assert or de-assert the CS.

The GEN FIFO entry has fields such as:
- TX or RX
- CS - lower/upper
- data bus - lower/upper
- bytecount
- bus width - x1 or x2 or x4
etc.

@Ranjit It might be useful to describe the GENFIFO format in the driver at some appropriate place.

Regards,
Harini

maintainer
#7 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Quoted 9 lines · Harini Katakam
Quoted 7 lines · Mark Brown

On Wed, May 20, 2015 at 12:57:51PM +0530, Ranjit Waghmode wrote:

Why is there a default case here? That's going to men we try to handle any random chip select that gets passed in as pointing to this lower device which doesn't seem right. The fact that this is trying to handle mirroring of the chip select to two devices is also raising alarm bells here...

Quoted 6 lines

This SPI controller has two CS lines and two data bus. Two devices can be connected to these and either the upper or the lower or both (Explained below) can be selected.

When two flash devices are used, one of the HW configurations in which they can be connected is called "parallel" mode where they

I know what wiring chip selects in parallel is but that's not the question - the question is about the handling of the default case.

Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
drivers/spi/spi-zynqmp-gqspi.c new file +7 -0
+static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool is_high)
+{
 
+     if (is_high) {
+             /* Manually start the generic FIFO command */
+             zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+                             zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+                             GQSPI_CFG_START_GEN_FIFO_MASK);
Quoted 5 lines
Quoted 3 lines

No, this is broken - setting the chip select should set the chip select, it shouldn't have any impact on transfers. Transfers should be started in the transfer operations.

This is the only way to assert the CS. It doesn't start transferring any data.

OK, then you can't implement a separate set_cs() operation and shouldn't
be trying to do so. This will break in multiple ways when the framework
tries to use the operations separately. You probably need to implement
a single flat transfer() operation.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20150528/5119c1dc/attachment.sig>

#8 lore raw

RE: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Hi Mark,

Quoted 26 lines

-----Original Message-----
From: Mark Brown [mailto:broonie at kernel.org]
Sent: Thursday, May 28, 2015 8:34 PM
To: Harini Katakam
Cc: Ranjit Abhimanyu Waghmode; Rob Herring; Pawel Moll; Mark Rutland; ijc+devicetree at hellion.org.uk; Kumar Gala; Michal Simek; Soren Brinkmann; devicetree at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux- kernel at vger.kernel.org; linux-spi; Punnaiah Choudary Kalluri; ran27jit at gmail.com
Subject: Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Quoted 12 lines · Harini Katakam
Quoted 7 lines · Mark Brown

On Wed, May 20, 2015 at 12:57:51PM +0530, Ranjit Waghmode wrote:

Why is there a default case here? That's going to men we try to handle any random chip select that gets passed in as pointing to this lower device which doesn't seem right. The fact that this is trying to handle mirroring of the chip select to two devices is also raising alarm bells here...

This SPI controller has two CS lines and two data bus. Two devices can be connected to these and either the upper or the lower or both (Explained below) can be selected.

Quoted 5 lines
Quoted 2 lines

When two flash devices are used, one of the HW configurations in which they can be connected is called "parallel" mode where they

I know what wiring chip selects in parallel is but that's not the question - the question is about the handling of the default case.

Yes, we should not handle default case here. We will change this.

Quoted 15 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool

is_high)

Quoted 11 lines
Quoted 11 lines

drivers/spi/spi-zynqmp-gqspi.c line 406

Quoted 7 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+{
 
+     if (is_high) {
+             /* Manually start the generic FIFO command */
+             zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+                             zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+                             GQSPI_CFG_START_GEN_FIFO_MASK);

No, this is broken - setting the chip select should set the chip select, it shouldn't have any impact on transfers. Transfers should be started in the transfer operations.

Quoted 6 lines
Quoted 1 line

This is the only way to assert the CS. It doesn't start transferring any data.

OK, then you can't implement a separate set_cs() operation and shouldn't be trying to do so. This will break in multiple ways when the framework tries to use the operations separately. You probably need to implement a single flat transfer() operation.

As we said it will not start any data transfer. In order to set chip select (chip select only) we need to
1. Frame a control word with following parameters like the chip select that we would like to set and hold time
2. Update the control word to fifo

To have a performance advantage (may be not trivial) we are executing this fifo entry along with the first
Data transfer entry in transfer function so that we can avoid waiting for fifo empty in set_cs function.

We will ensure CS assert by waiting till the fifo empty in set_cs function and justify the what the
Function supposed do.

Regards,
Punnaiah

#9 lore raw

Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Hi Mark,

Quoted 28 lines · Punnaiah Choudary Kalluri

Hi Mark,

Quoted 26 lines

-----Original Message-----
From: Mark Brown [mailto:broonie at kernel.org]
Sent: Thursday, May 28, 2015 8:34 PM
To: Harini Katakam
Cc: Ranjit Abhimanyu Waghmode; Rob Herring; Pawel Moll; Mark Rutland; ijc+devicetree at hellion.org.uk; Kumar Gala; Michal Simek; Soren Brinkmann; devicetree at vger.kernel.org; linux-arm-kernel at lists.infradead.org; linux- kernel at vger.kernel.org; linux-spi; Punnaiah Choudary Kalluri; ran27jit at gmail.com
Subject: Re: [RFC PATCH 2/2] spi: Add support for Zynq Ultrascale+ MPSoC GQSPI controller

Quoted 12 lines · Harini Katakam
Quoted 7 lines · Mark Brown

On Wed, May 20, 2015 at 12:57:51PM +0530, Ranjit Waghmode wrote:

Why is there a default case here? That's going to men we try to handle any random chip select that gets passed in as pointing to this lower device which doesn't seem right. The fact that this is trying to handle mirroring of the chip select to two devices is also raising alarm bells here...

This SPI controller has two CS lines and two data bus. Two devices can be connected to these and either the upper or the lower or both (Explained below) can be selected.

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

When two flash devices are used, one of the HW configurations in which they can be connected is called "parallel" mode where they

I know what wiring chip selects in parallel is but that's not the question - the question is about the handling of the default case.

Yes, we should not handle default case here. We will change this.

Yes, that's right. I was just elaborating the mirroring part.

Quoted 26 lines
Quoted 15 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

+static void zynqmp_qspi_chipselect(struct spi_device *qspi, bool

is_high)

Quoted 11 lines
Quoted 11 lines

drivers/spi/spi-zynqmp-gqspi.c line 406

Quoted 7 lines
drivers/spi/spi-zynqmp-gqspi.c new file +6 -0
+{
 
+     if (is_high) {
+             /* Manually start the generic FIFO command */
+             zynqmp_gqspi_write(xqspi, GQSPI_CONFIG_OFST,
+                             zynqmp_gqspi_read(xqspi, GQSPI_CONFIG_OFST) |
+                             GQSPI_CFG_START_GEN_FIFO_MASK);

No, this is broken - setting the chip select should set the chip select, it shouldn't have any impact on transfers. Transfers should be started in the transfer operations.

Quoted 6 lines
Quoted 1 line

This is the only way to assert the CS. It doesn't start transferring any data.

OK, then you can't implement a separate set_cs() operation and shouldn't be trying to do so. This will break in multiple ways when the framework tries to use the operations separately. You probably need to implement a single flat transfer() operation.

As we said it will not start any data transfer. In order to set chip select (chip select only) we need to
1. Frame a control word with following parameters like the chip select that we would like to set and hold time
2. Update the control word to fifo

Quoted 6 lines

To have a performance advantage (may be not trivial) we are executing this fifo entry along with the first
Data transfer entry in transfer function so that we can avoid waiting for fifo empty in set_cs function.

We will ensure CS assert by waiting till the fifo empty in set_cs function and justify the what the
Function supposed do.

Yes, if we wait for cs assert to be executed (which is just the time controller takes to fetch this command
and execute), this set_cs will be independent as expected. The framework can use it anytime.

Regards,
Harini

#10 lore raw
In reply to Ranjit Waghmode
Quoted 30 lines · Ranjit Waghmode

Add bindings documentation for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---
 .../devicetree/bindings/spi/spi-zynqmp-qspi.txt    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt new file +15 -0
new file mode 100644
index 0000000..cec6330
@@ -0,0 +1,26 @@
+Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
+-------------------------------------------------------------------
+
+Required properties:
+- compatible		: Should be "xlnx,zynqmp-qspi-1.0".
+- reg			: Physical base address and size of GQSPI registers map.
+- interrupts		: Property with a value describing the interrupt
+			  number.
+- interrupt-parent	: Must be core interrupt controller.
+- clock-names		: List of input clock names - "ref_clk", "pclk"
+			  (See clock bindings for details).
+- clocks		: Clock phandles (see clock bindings for details).
+
+Optional properties:
+- num-cs		: Number of chip selects used.

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt new file +10 -0
+
+Example:
+	qspi: spi at ff0f0000 {
+		compatible = "xlnx,zynqmp-qspi-1.0";
+		clock-names = "ref_clk", "pclk";
+		clocks = <&misc_clk &misc_clk>;
+		interrupts = <0 15 4>;
+		interrupt-parent = <&gic>;
+		num-cs = <1>;
+		reg = <0x0 0xff0f0000 0x1000 0x0 0xc0000000 0x8000000>;

I find things a lot easier to read when there is something separating the groups. Could this become:

	reg = <0x0 0xff0f0000 0x1000>, <0x0 0xc0000000 0x8000000>;

?

Thanks,
S?ren

#11 lore raw

Hi Soren,

Quoted 32 lines · Ranjit Waghmode

Add bindings documentation for GQSPI controller driver used by Zynq Ultrascale+ MPSoC

---
 .../devicetree/bindings/spi/spi-zynqmp-qspi.txt    | 26 ++++++++++++++++++++++
 1 file changed, 26 insertions(+)
 create mode 100644 

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt new file +15 -0
new file mode 100644
index 0000000..cec6330
@@ -0,0 +1,26 @@
+Xilinx Zynq UltraScale+ MPSoC GQSPI controller Device Tree Bindings
+-------------------------------------------------------------------
+
+Required properties:
+- compatible		: Should be "xlnx,zynqmp-qspi-1.0".
+- reg			: Physical base address and size of GQSPI registers map.
+- interrupts		: Property with a value describing the interrupt
+			  number.
+- interrupt-parent	: Must be core interrupt controller.
+- clock-names		: List of input clock names - "ref_clk", "pclk"
+			  (See clock bindings for details).
+- clocks		: Clock phandles (see clock bindings for details).
+
+Optional properties:
+- num-cs		: Number of chip selects used.

Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt line 25

Quoted 10 lines
Documentation/devicetree/bindings/spi/spi-zynqmp-qspi.txt new file +10 -0
+
+Example:
+	qspi: spi at ff0f0000 {
+		compatible = "xlnx,zynqmp-qspi-1.0";
+		clock-names = "ref_clk", "pclk";
+		clocks = <&misc_clk &misc_clk>;
+		interrupts = <0 15 4>;
+		interrupt-parent = <&gic>;
+		num-cs = <1>;
+		reg = <0x0 0xff0f0000 0x1000 0x0 0xc0000000 0x8000000>;

I find things a lot easier to read when there is something separating the groups. Could this become:

	reg = <0x0 0xff0f0000 0x1000>, <0x0 0xc0000000 0x8000000>; ?

[Ranjit]: I will try your suggestion and send you in the next version.

Regards,
Ranjit