Skip to contentSkip to conversation

Add ti qspi controller

PATCH Superseded Sourav Poddar 3 participants 15 messages Jul 29, 2013 – Jul 30, 2013

Subsystems (2)

v6 of 10 Superseded Latest is v10 →

lore
Share & tools
lore
#0 lore raw

v6 cover Add ti qspi controller

This patch series add support for ti qspi controller. Adapted this series on top of Mark brown series[1]:

[1]: https://patchwork.kernel.org/patch/2834694/

And some other cleanups.

Sourav Poddar (2):
drivers: spi: Add qspi flash controller
driver: spi: Add quad spi read support

 Documentation/devicetree/bindings/spi/ti_qspi.txt |   22 +
 drivers/spi/Kconfig                               |    8 +
 drivers/spi/Makefile                              |    1 +
 drivers/spi/spi-ti-qspi.c                         |  532 +++++++++++++++++++++
 4 files changed, 563 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/ti_qspi.txt
 create mode 100644 drivers/spi/spi-ti-qspi.c
#1 lore raw

PATCH v6 1/2 drivers: spi: Add qspi flash controller

The patch add basic support for the quad spi controller.

QSPI is a kind of spi module that allows single, dual and quad read access to external spi devices. The module has a memory mapped interface which provide direct interface for accessing data form external spi devices.

The patch will configure controller clocks, device control register and for defining low level transfer apis which will be used by the spi framework to transfer data to the slave spi device(flash in this case).

Test details:
-------------
Tested this on dra7 board.
Test1: Ran mtd_stesstest for 40000 iterations.
- All iterations went through without failure.
Test2: Use mtd utilities:
- flash_erase to erase the flash device
- nanddump to read data back.
- nandwrite to write to the data flash.
diff between the write and read data shows zero.

---
v5->v6
--------
- Modified read/write api
- Adapt the code to Mark Brown series of moving
runtime PM apis to core.
- Miscellaneous cleanup.

 Documentation/devicetree/bindings/spi/ti_qspi.txt |   22 +
 drivers/spi/Kconfig                               |    8 +
 drivers/spi/Makefile                              |    1 +
 drivers/spi/spi-ti-qspi.c                         |  520 +++++++++++++++++++++
 4 files changed, 551 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/ti_qspi.txt
 create mode 100644 drivers/spi/spi-ti-qspi.c
Documentation/devicetree/bindings/spi/ti_qspi.txt new file +22 -0
new file mode 100644
index 0000000..398ef59
@@ -0,0 +1,22 @@
+TI QSPI controller.
+
+Required properties:
+- compatible : should be "ti,dra7xxx-qspi".
+- reg: Should contain QSPI registers location and length.
+- #address-cells, #size-cells : Must be present if the device has sub-nodes
+- ti,hwmods: Name of the hwmod associated to the QSPI
+
+Recommended properties:
+- spi-max-frequency: Definition as per
+                     Documentation/devicetree/bindings/spi/spi-bus.txt
+
+Example:
+
+qspi: qspi@4b300000 {
+	compatible = "ti,dra7xxx-qspi";
+	reg = <0x4b300000 0x100>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+	spi-max-frequency = <25000000>;
+	ti,hwmods = "qspi";
+};
drivers/spi/Kconfig +8 -0
index 92a9345..1c4e758 100644
@@ -285,6 +285,14 @@ config SPI_OMAP24XX
 	  SPI master controller for OMAP24XX and later Multichannel SPI
 	  (McSPI) modules.
 
+config SPI_TI_QSPI
+	tristate "DRA7xxx QSPI controller support"
+	depends on ARCH_OMAP2PLUS || COMPILE_TEST
+	help
+	  QSPI master controller for DRA7xxx used for flash devices.
+	  This device supports single, dual and quad read support, while
+	  it only supports single write mode.
+
 config SPI_OMAP_100K
 	tristate "OMAP SPI 100K"
 	depends on ARCH_OMAP850 || ARCH_OMAP730
drivers/spi/Makefile +1 -0
index 33f9c09..a174030 100644
@@ -46,6 +46,7 @@ obj-$(CONFIG_SPI_OCTEON)		+= spi-octeon.o
 obj-$(CONFIG_SPI_OMAP_UWIRE)		+= spi-omap-uwire.o
 obj-$(CONFIG_SPI_OMAP_100K)		+= spi-omap-100k.o
 obj-$(CONFIG_SPI_OMAP24XX)		+= spi-omap2-mcspi.o
+obj-$(CONFIG_SPI_TI_QSPI)		+= spi-ti-qspi.o
 obj-$(CONFIG_SPI_ORION)			+= spi-orion.o
 obj-$(CONFIG_SPI_PL022)			+= spi-pl022.o
 obj-$(CONFIG_SPI_PPC4xx)		+= spi-ppc4xx.o
drivers/spi/spi-ti-qspi.c new file +520 -0

520 lines not on this page · raw message

Signature · 1 line
1.7.1
#2 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi,

Quoted 5 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +0 -0
new file mode 100644
index 0000000..51fe95f

[ snip ]

drivers/spi/spi-ti-qspi.c line 49

Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+struct ti_qspi {
+	spinlock_t              lock;           /* IRQ synchronization */
+	struct spi_master	*master;
+	void __iomem            *base;
+	struct device           *dev;
+	struct completion       transfer_complete;
+	struct clk *fclk;
+	struct ti_qspi_regs     ctx_reg;
+	int device_type;

device_type isn't used

drivers/spi/spi-ti-qspi.c line 53

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+	u32 spi_max_frequency;
+	u32 cmd;
+	u32 dc;
+};

you need to make a choice here ? Are you going to tabify the structure or not ? You might also want to reorganize this structure to it looks like below:

struct ti_qspi {
	struct completion	transfer_complete;

	/* IRQ synchronization */
	spinlock_t		lock;

	struct spi_master	*master;
	void __iomem		*base;
	struct clk		*fclk;
	struct device		*dev;

	struct ti_qspi_regs	ctx_reg;

	u32			spi_max_frequency;
	u32			cmd;
	u32			dc;
};

drivers/spi/spi-ti-qspi.c line 107

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+/* Status */
+#define QSPI_WC				(1 << 1)
+#define QSPI_BUSY			(1 << 0)
+#define QSPI_WC_BUSY			(QSPI_WC | QSPI_BUSY)

WC_BUSY isn't used in this file. It looks unnecessary too.

Quoted 1 line

+#define QSPI_XFER_DONE QSPI_WC

so transfer done is word completion ? Why do you need this ? It's not even used in this source file.

drivers/spi/spi-ti-qspi.c line 132

Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+static inline void ti_qspi_read_data(struct ti_qspi *qspi,
+		unsigned long reg, int wlen, u8 **rxbuf)
+{
+	switch (wlen) {
+	case 8:
+		**rxbuf = readb(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

you're incrementing only after printing, do you really need the -1 here?

Also, I would change these into dev_vdbg(), it's quite unlikely someone needs to track all reads to the data register and since you're not printing the writes either, this looks even more like a case for dev_vdbg()

drivers/spi/spi-ti-qspi.c line 137

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+		*rxbuf += 1;
+		break;
+	case 16:
+		**rxbuf = readw(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

%04x and no -1 (also, if you needed to decrement, it would have to be %-2).

drivers/spi/spi-ti-qspi.c line 142

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+		*rxbuf += 2;
+		break;
+	case 32:
+		**rxbuf = readl(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

%04x

drivers/spi/spi-ti-qspi.c line 145

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+		*rxbuf += 4;
+	default:
+		dev_dbg(qspi->dev, "word lenght out of range");

s/lenght/length

drivers/spi/spi-ti-qspi.c line 183

Quoted 12 lines
drivers/spi/spi-ti-qspi.c new file +12 -0
+static int ti_qspi_setup(struct spi_device *spi)
+{
+	struct ti_qspi	*qspi = spi_master_get_devdata(spi->master);
+	struct ti_qspi_regs *ctx_reg = &qspi->ctx_reg;
+	int clk_div = 0, ret;
+	u32 clk_ctrl_reg, clk_rate, clk_mask;
+
+	clk_rate = clk_get_rate(qspi->fclk);
+
+	if (!qspi->spi_max_frequency) {
+		dev_err(qspi->dev, "spi max frequency not defined\n");
+		return -EINVAL;

if you're returning here...

drivers/spi/spi-ti-qspi.c line 184

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	} else {

this else is unneeded

drivers/spi/spi-ti-qspi.c line 195

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -0
+		clk_div = DIV_ROUND_UP(clk_rate, qspi->spi_max_frequency) - 1;
+	}
+
+	dev_dbg(qspi->dev, "%s: hz: %d, clock divider %d\n", __func__,
+			qspi->spi_max_frequency, clk_div);
+
+	ret = pm_runtime_get_sync(qspi->dev);
+	if (ret) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}

after Mark's patch, is this really needed ?

drivers/spi/spi-ti-qspi.c line 205

Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	clk_ctrl_reg = ti_qspi_read(qspi, QSPI_SPI_CLOCK_CNTRL_REG);
+
+	clk_ctrl_reg &= ~QSPI_CLK_EN;
+
+	/* disable SCLK */
+	if (!spi->master->busy)
+		ti_qspi_write(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG);
+	else
+		dev_dbg(qspi->dev, "master busy doing other trasnfers\n");

if master is busy, shouldn't you return -EBUSY at this point ?

drivers/spi/spi-ti-qspi.c line 210

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+
+	if (clk_div < 0) {
+		dev_dbg(qspi->dev, "%s: clock divider < 0, using /1 divider\n",
+				__func__);
+		return -EINVAL;

you do a get_sync without a put_sync() here.

drivers/spi/spi-ti-qspi.c line 216

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	}
+
+	if (clk_div > QSPI_CLK_DIV_MAX) {
+		dev_dbg(qspi->dev, "%s: clock divider >%d , using /%d divider\n",
+			__func__, QSPI_CLK_DIV_MAX, QSPI_CLK_DIV_MAX + 1);
+		return -EINVAL;

no put_sync()

Quoted 33 lines
drivers/spi/spi-ti-qspi.c new file +33 -0
+	}
+
+	/* enable SCLK */
+	clk_mask = QSPI_CLK_EN | clk_div;
+	ti_qspi_write(qspi, clk_mask, QSPI_SPI_CLOCK_CNTRL_REG);
+	ctx_reg->clkctrl = clk_mask;
+
+	pm_runtime_mark_last_busy(qspi->dev);
+	ret = pm_runtime_put_autosuspend(qspi->dev);
+	if (ret < 0) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void ti_qspi_restore_ctx(struct ti_qspi *qspi)
+{
+	struct ti_qspi_regs *ctx_reg = &qspi->ctx_reg;
+
+	ti_qspi_write(qspi, ctx_reg->clkctrl, QSPI_SPI_CLOCK_CNTRL_REG);
+}
+
+static void qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	const u8 *txbuf;
+	int wlen, count;
+
+	count = t->len;
+	txbuf = t->tx_buf;
+	wlen = t->bits_per_word;
+

drivers/spi/spi-ti-qspi.c line 259

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	while (count--) {
+		dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %02x\n",
+			qspi->cmd | QSPI_WR_SNGL, qspi->dc, *txbuf);
+		ti_qspi_write_data(qspi, *txbuf, QSPI_SPI_DATA_REG,
+					wlen, &txbuf);
+		ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG);
+		ti_qspi_write(qspi, qspi->cmd | QSPI_WR_SNGL,
+			QSPI_SPI_CMD_REG);
+		ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
+		wait_for_completion(&qspi->transfer_complete);

you can't wait forever dude, wait_for_completion_timeout() and give it a 2 second timeout, then you can make this and qspi_read_msg() return something so you can notify that the controller didn't transfer anything in case your wait_for_completion_timeout() actually times out.

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	}
+}
+
+static void qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	u8 *rxbuf;
+	int wlen, count;
+
+	count = t->len;
+	rxbuf = t->rx_buf;

drivers/spi/spi-ti-qspi.c line 279

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	wlen = t->bits_per_word;
+
+	while (count--) {
+		dev_dbg(qspi->dev, "rx cmd %08x dc %08x\n",
+			qspi->cmd | QSPI_RD_SNGL, qspi->dc);
+		ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG);
+		ti_qspi_write(qspi, qspi->cmd | QSPI_RD_SNGL,
+			QSPI_SPI_CMD_REG);
+		ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
+		wait_for_completion(&qspi->transfer_complete);

wait_for_completion_timeout()

Quoted 25 lines
drivers/spi/spi-ti-qspi.c new file +25 -0
+		ti_qspi_read_data(qspi, QSPI_SPI_DATA_REG, wlen, &rxbuf);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(rxbuf-1));
+	}
+}
+
+static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	if (t->tx_buf)
+		qspi_write_msg(qspi, t);
+	if (t->rx_buf)
+		qspi_read_msg(qspi, t);
+
+	return 0;
+}
+
+static int ti_qspi_start_transfer_one(struct spi_master *master,
+		struct spi_message *m)
+{
+	struct ti_qspi *qspi = spi_master_get_devdata(master);
+	struct spi_device *spi = m->spi;
+	struct spi_transfer *t;
+	int status = 0, ret;
+	int frame_length;
+
+	/* setup device control reg */

drivers/spi/spi-ti-qspi.c line 314

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	qspi->dc = 0;
+
+	if (spi->mode & SPI_CPHA)
+		qspi->dc |= QSPI_CKPHA(spi->chip_select);
+	if (spi->mode & SPI_CPOL)
+		qspi->dc |= QSPI_CKPOL(spi->chip_select);
+	if (spi->mode & SPI_CS_HIGH)
+		qspi->dc |= QSPI_CSPOL(spi->chip_select);
+
+	frame_length = (m->frame_length << 3) / spi->bits_per_word;

there's another way to optimize this. If you assume bits_per_word to always be power of two you can:

	frame_length = (m->frame_length << 3) >> __ffs(spi->bits_per_word);

but that would need a comment stating that you're assuming bits_per_word to always be a power of two. Not sure if this is a correct assumption.

Quoted 28 lines
drivers/spi/spi-ti-qspi.c new file +28 -0
+	frame_length = clamp(frame_length, 0, QSPI_FRAME_MAX);
+
+	/* setup command reg */
+	qspi->cmd = 0;
+	qspi->cmd |= QSPI_EN_CS(spi->chip_select);
+	qspi->cmd |= QSPI_FLEN(frame_length);
+	qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+	list_for_each_entry(t, &m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+
+		ret = qspi_transfer_msg(qspi, t);
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
+
+		m->actual_length += t->len;
+	}
+
+	m->status = status;
+	spi_finalize_current_message(master);
+
+	ti_qspi_write(qspi, qspi->cmd | QSPI_INVAL, QSPI_SPI_CMD_REG);
+
+	return status;
+}
+

drivers/spi/spi-ti-qspi.c line 353

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+static irqreturn_t ti_qspi_isr(int irq, void *dev_id)
+{
+	struct ti_qspi *qspi = dev_id;
+	u16 mask, stat;
+
+	irqreturn_t ret = IRQ_HANDLED;
+
+	spin_lock(&qspi->lock);
+
+	stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR);

since you're not reading the _RAW register, you don't need the mask below, right ?

drivers/spi/spi-ti-qspi.c line 361

Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8 -0
+	mask = ti_qspi_read(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (!(stat & mask)) {
+		dev_dbg(qspi->dev, "No IRQ triggered\n");
+		ret = IRQ_NONE;
+	}
+
+	ret = IRQ_WAKE_THREAD;

look at this code and tell me when will you *EVER* return IRQ_NONE. Dude you're waking up the IRQ thread even when there are no IRQs to be handled.

drivers/spi/spi-ti-qspi.c line 363

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	spin_unlock(&qspi->lock);

You should, before releasing the lock, mask your IRQs, so that you can get rid of IRQF_ONESHOT. Unmask them before returning from the IRQ thread.

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+	struct  ti_qspi *qspi;
+	struct spi_master *master;
+	struct resource         *r;
+	struct device_node *np = pdev->dev.of_node;

drivers/spi/spi-ti-qspi.c line 419

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	u32 max_freq;
+	int ret = 0, num_cs, irq;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(*qspi));
+	if (!master)
+		return -ENOMEM;
+
+	master->mode_bits = SPI_CPOL | SPI_CPHA;
+
+	master->num_chipselect = 1;

again with the num_chipselect = 1 ? IIRC this controller has 4 chipselects, just read 24.5.1 on your TRM.

drivers/spi/spi-ti-qspi.c line 429

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	master->bus_num = -1;
+	master->flags = SPI_MASTER_HALF_DUPLEX;
+	master->setup = ti_qspi_setup;
+	master->auto_runtime_pm = true;
+	master->transfer_one_message = ti_qspi_start_transfer_one;
+	master->dev.of_node = pdev->dev.of_node;
+	master->bits_per_word_mask = BIT(32 - 1) | BIT(16 - 1) | BIT(8 - 1);
+
+	if (!of_property_read_u32(np, "num-cs", &num_cs))
+		master->num_chipselect = num_cs;

so you reinitialize here num_chipselect, then why do you initialize it above ?

drivers/spi/spi-ti-qspi.c line 441

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -0
+	platform_set_drvdata(pdev, master);
+
+	qspi = spi_master_get_devdata(master);
+	qspi->master = master;
+	qspi->dev = &pdev->dev;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (r == NULL) {
+		ret = -ENODEV;
+		goto free_master;
+	}

you don't need to check the resource when using devm_ioremap_resource().

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq < 0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

drivers/spi/spi-ti-qspi.c line 458

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Signature · 1 line
balbi
#3 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Quoted 10 lines · Felipe Balbi

Hi,

Quoted 5 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +0 -0
new file mode 100644
index 0000000..51fe95f

[ snip ]

Quoted 11 lines

drivers/spi/spi-ti-qspi.c line 49

Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+struct ti_qspi {
+	spinlock_t              lock;           /* IRQ synchronization */
+	struct spi_master	*master;
+	void __iomem            *base;
+	struct device           *dev;
+	struct completion       transfer_complete;
+	struct clk *fclk;
+	struct ti_qspi_regs     ctx_reg;
+	int device_type;

device_type isn't used

My bad. yes, will remove. Was added for some experiments.

Quoted 17 lines

drivers/spi/spi-ti-qspi.c line 53

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+	u32 spi_max_frequency;
+	u32 cmd;
+	u32 dc;
+};

you need to make a choice here ? Are you going to tabify the structure or not ? You might also want to reorganize this structure to it looks like below:

struct ti_qspi {
	struct completion	transfer_complete;

	/* IRQ synchronization */
	spinlock_t		lock;

	struct spi_master	*master;
	void __iomem		*base;
	struct clk		*fclk;
Quoted 9 lines
	struct device		*dev;

	struct ti_qspi_regs	ctx_reg;

	u32			spi_max_frequency;
	u32			cmd;
	u32			dc;
};

hmm..yes will do.

Quoted 6 lines

drivers/spi/spi-ti-qspi.c line 107

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+/* Status */
+#define QSPI_WC				(1<<  1)
+#define QSPI_BUSY			(1<<  0)
+#define QSPI_WC_BUSY			(QSPI_WC | QSPI_BUSY)

WC_BUSY isn't used in this file. It looks unnecessary too.

Yes.

Quoted 4 lines
Quoted 1 line

+#define QSPI_XFER_DONE QSPI_WC

so transfer done is word completion ? Why do you need this ? It's not even used in this source file.

Yes, this was used in ealier versons for polled mode. Will remove.

Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 132

Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+static inline void ti_qspi_read_data(struct ti_qspi *qspi,
+		unsigned long reg, int wlen, u8 **rxbuf)
+{
+	switch (wlen) {
+	case 8:
+		**rxbuf = readb(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

you're incrementing only after printing, do you really need the -1 here?

Quoted 5 lines

Also, I would change these into dev_vdbg(), it's quite unlikely someone needs to track all reads to the data register and since you're not printing the writes either, this looks even more like a case for dev_vdbg()

Ok.will change.

Quoted 8 lines

drivers/spi/spi-ti-qspi.c line 137

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+		*rxbuf += 1;
+		break;
+	case 16:
+		**rxbuf = readw(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

%04x and no -1 (also, if you needed to decrement, it would have to be %-2).

Ok.

Quoted 7 lines

drivers/spi/spi-ti-qspi.c line 142

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+		*rxbuf += 2;
+		break;
+	case 32:
+		**rxbuf = readl(qspi->base + reg);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(*rxbuf-1));

%04x

OK

Quoted 5 lines

drivers/spi/spi-ti-qspi.c line 145

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+		*rxbuf += 4;
+	default:
+		dev_dbg(qspi->dev, "word lenght out of range");

s/lenght/length

hmm..will change.

Quoted 14 lines

drivers/spi/spi-ti-qspi.c line 183

Quoted 12 lines
drivers/spi/spi-ti-qspi.c new file +12 -0
+static int ti_qspi_setup(struct spi_device *spi)
+{
+	struct ti_qspi	*qspi = spi_master_get_devdata(spi->master);
+	struct ti_qspi_regs *ctx_reg =&qspi->ctx_reg;
+	int clk_div = 0, ret;
+	u32 clk_ctrl_reg, clk_rate, clk_mask;
+
+	clk_rate = clk_get_rate(qspi->fclk);
+
+	if (!qspi->spi_max_frequency) {
+		dev_err(qspi->dev, "spi max frequency not defined\n");
+		return -EINVAL;

if you're returning here...

Quoted 3 lines

drivers/spi/spi-ti-qspi.c line 184

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	} else {

this else is unneeded

hmm..true. Will change.

Quoted 13 lines

drivers/spi/spi-ti-qspi.c line 195

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -0
+		clk_div = DIV_ROUND_UP(clk_rate, qspi->spi_max_frequency) - 1;
+	}
+
+	dev_dbg(qspi->dev, "%s: hz: %d, clock divider %d\n", __func__,
+			qspi->spi_max_frequency, clk_div);
+
+	ret = pm_runtime_get_sync(qspi->dev);
+	if (ret) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}

after Mark's patch, is this really needed ?

Quoted 11 lines

drivers/spi/spi-ti-qspi.c line 205

Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	clk_ctrl_reg = ti_qspi_read(qspi, QSPI_SPI_CLOCK_CNTRL_REG);
+
+	clk_ctrl_reg&= ~QSPI_CLK_EN;
+
+	/* disable SCLK */
+	if (!spi->master->busy)
+		ti_qspi_write(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG);
+	else
+		dev_dbg(qspi->dev, "master busy doing other trasnfers\n");

if master is busy, shouldn't you return -EBUSY at this point ?

Yes. will add.

Quoted 7 lines

drivers/spi/spi-ti-qspi.c line 210

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+
+	if (clk_div<  0) {
+		dev_dbg(qspi->dev, "%s: clock divider<  0, using /1 divider\n",
+				__func__);
+		return -EINVAL;

you do a get_sync without a put_sync() here.

Hmm..will add put_sync in error path.

Quoted 8 lines

drivers/spi/spi-ti-qspi.c line 216

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	}
+
+	if (clk_div>  QSPI_CLK_DIV_MAX) {
+		dev_dbg(qspi->dev, "%s: clock divider>%d , using /%d divider\n",
+			__func__, QSPI_CLK_DIV_MAX, QSPI_CLK_DIV_MAX + 1);
+		return -EINVAL;

no put_sync()

Same.

Quoted 39 lines
Quoted 39 lines
drivers/spi/spi-ti-qspi.c new file +39 -0
+	}
+
+	/* enable SCLK */
+	clk_mask = QSPI_CLK_EN | clk_div;
+	ti_qspi_write(qspi, clk_mask, QSPI_SPI_CLOCK_CNTRL_REG);
+	ctx_reg->clkctrl = clk_mask;
+
+	pm_runtime_mark_last_busy(qspi->dev);
+	ret = pm_runtime_put_autosuspend(qspi->dev);
+	if (ret<  0) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}
+
+	return 0;
+}
+
+static void ti_qspi_restore_ctx(struct ti_qspi *qspi)
+{
+	struct ti_qspi_regs *ctx_reg =&qspi->ctx_reg;
+
+	ti_qspi_write(qspi, ctx_reg->clkctrl, QSPI_SPI_CLOCK_CNTRL_REG);
+}
+
+static void qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	const u8 *txbuf;
+	int wlen, count;
+
+	count = t->len;
+	txbuf = t->tx_buf;
+	wlen = t->bits_per_word;
+
+	while (count--) {
+		dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %02x\n",
+			qspi->cmd | QSPI_WR_SNGL, qspi->dc, *txbuf);
+		ti_qspi_write_data(qspi, *txbuf, QSPI_SPI_DATA_REG,
+					wlen,&txbuf);
+		ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG);
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 259

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+		ti_qspi_write(qspi, qspi->cmd | QSPI_WR_SNGL,
+			QSPI_SPI_CMD_REG);
+		ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
+		wait_for_completion(&qspi->transfer_complete);

you can't wait forever dude, wait_for_completion_timeout() and give it a 2 second timeout, then you can make this and qspi_read_msg() return something so you can notify that the controller didn't transfer anything in case your wait_for_completion_timeout() actually times out.

Ok.

Quoted 13 lines
Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13 -0
+	}
+}
+
+static void qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	u8 *rxbuf;
+	int wlen, count;
+
+	count = t->len;
+	rxbuf = t->rx_buf;
+	wlen = t->bits_per_word;
+
+	while (count--) {
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 279

Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+		dev_dbg(qspi->dev, "rx cmd %08x dc %08x\n",
+			qspi->cmd | QSPI_RD_SNGL, qspi->dc);
+		ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG);
+		ti_qspi_write(qspi, qspi->cmd | QSPI_RD_SNGL,
+			QSPI_SPI_CMD_REG);
+		ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
+		wait_for_completion(&qspi->transfer_complete);

wait_for_completion_timeout()

Ok.

Quoted 38 lines
Quoted 25 lines
drivers/spi/spi-ti-qspi.c new file +25 -0
+		ti_qspi_read_data(qspi, QSPI_SPI_DATA_REG, wlen,&rxbuf);
+		dev_dbg(qspi->dev, "rx done, read %02x\n", *(rxbuf-1));
+	}
+}
+
+static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t)
+{
+	if (t->tx_buf)
+		qspi_write_msg(qspi, t);
+	if (t->rx_buf)
+		qspi_read_msg(qspi, t);
+
+	return 0;
+}
+
+static int ti_qspi_start_transfer_one(struct spi_master *master,
+		struct spi_message *m)
+{
+	struct ti_qspi *qspi = spi_master_get_devdata(master);
+	struct spi_device *spi = m->spi;
+	struct spi_transfer *t;
+	int status = 0, ret;
+	int frame_length;
+
+	/* setup device control reg */

drivers/spi/spi-ti-qspi.c

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	qspi->dc = 0;
+
+	if (spi->mode&  SPI_CPHA)
+		qspi->dc |= QSPI_CKPHA(spi->chip_select);
+	if (spi->mode&  SPI_CPOL)
+		qspi->dc |= QSPI_CKPOL(spi->chip_select);
+	if (spi->mode&  SPI_CS_HIGH)
+		qspi->dc |= QSPI_CSPOL(spi->chip_select);
+
+	frame_length = (m->frame_length<<  3) / spi->bits_per_word;

there's another way to optimize this. If you assume bits_per_word to always be power of two you can:

Quoted 5 lines
	frame_length = (m->frame_length<<  3)>>  __ffs(spi->bits_per_word);

but that would need a comment stating that you're assuming bits_per_word to always be a power of two. Not sure if this is a correct assumption.

I dont think it will be a correct assumption, since our controller is flexible to handle anything from 1 to 128 as bits_per_word.

Quoted 32 lines
Quoted 32 lines
drivers/spi/spi-ti-qspi.c new file +32 -0
+	frame_length = clamp(frame_length, 0, QSPI_FRAME_MAX);
+
+	/* setup command reg */
+	qspi->cmd = 0;
+	qspi->cmd |= QSPI_EN_CS(spi->chip_select);
+	qspi->cmd |= QSPI_FLEN(frame_length);
+	qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+	list_for_each_entry(t,&m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+
+		ret = qspi_transfer_msg(qspi, t);
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
+
+		m->actual_length += t->len;
+	}
+
+	m->status = status;
+	spi_finalize_current_message(master);
+
+	ti_qspi_write(qspi, qspi->cmd | QSPI_INVAL, QSPI_SPI_CMD_REG);
+
+	return status;
+}
+
+static irqreturn_t ti_qspi_isr(int irq, void *dev_id)
+{
+	struct ti_qspi *qspi = dev_id;
+	u16 mask, stat;
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 353

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+
+	irqreturn_t ret = IRQ_HANDLED;
+
+	spin_lock(&qspi->lock);
+
+	stat = ti_qspi_read(qspi, QSPI_INTR_STATUS_ENABLED_CLEAR);

since you're not reading the _RAW register, you don't need the mask below, right ?

I think yes, only status register should be sufficient.

Quoted 12 lines

drivers/spi/spi-ti-qspi.c line 361

Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8 -0
+	mask = ti_qspi_read(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (!(stat&  mask)) {
+		dev_dbg(qspi->dev, "No IRQ triggered\n");
+		ret = IRQ_NONE;
+	}
+
+	ret = IRQ_WAKE_THREAD;

look at this code and tell me when will you *EVER* return IRQ_NONE. Dude you're waking up the IRQ thread even when there are no IRQs to be handled.

My bad, should add a return ret before IRQ_NONE.

Quoted 5 lines

drivers/spi/spi-ti-qspi.c line 363

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	spin_unlock(&qspi->lock);

You should, before releasing the lock, mask your IRQs, so that you can get rid of IRQF_ONESHOT. Unmask them before returning from the IRQ thread.

Sorry, did not get you here?
I am reading interrupt status register before and clearing them in the
threaded irq.

Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+	struct  ti_qspi *qspi;
+	struct spi_master *master;
+	struct resource         *r;
+	struct device_node *np = pdev->dev.of_node;
+	u32 max_freq;
+	int ret = 0, num_cs, irq;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(*qspi));
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 419

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	if (!master)
+		return -ENOMEM;
+
+	master->mode_bits = SPI_CPOL | SPI_CPHA;
+
+	master->num_chipselect = 1;

again with the num_chipselect = 1 ? IIRC this controller has 4 chipselects, just read 24.5.1 on your TRM.

this is unnecessary. I intended to configure chip selects through dt)as done below). Will remove.

Quoted 13 lines

drivers/spi/spi-ti-qspi.c line 429

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	master->bus_num = -1;
+	master->flags = SPI_MASTER_HALF_DUPLEX;
+	master->setup = ti_qspi_setup;
+	master->auto_runtime_pm = true;
+	master->transfer_one_message = ti_qspi_start_transfer_one;
+	master->dev.of_node = pdev->dev.of_node;
+	master->bits_per_word_mask = BIT(32 - 1) | BIT(16 - 1) | BIT(8 - 1);
+
+	if (!of_property_read_u32(np, "num-cs",&num_cs))
+		master->num_chipselect = num_cs;

so you reinitialize here num_chipselect, then why do you initialize it above ?

Quoted 13 lines

drivers/spi/spi-ti-qspi.c line 441

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -0
+	platform_set_drvdata(pdev, master);
+
+	qspi = spi_master_get_devdata(master);
+	qspi->master = master;
+	qspi->dev =&pdev->dev;
+
+	r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (r == NULL) {
+		ret = -ENODEV;
+		goto free_master;
+	}

you don't need to check the resource when using devm_ioremap_resource().

Ok.

Quoted 9 lines
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<  0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 458

Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

I should get away with this.

#4 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi,

Quoted 4 lines · Sourav Poddar
Quoted 4 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	frame_length = (m->frame_length<<  3) / spi->bits_per_word;

there's another way to optimize this. If you assume bits_per_word to always be power of two you can:

Quoted 8 lines
Quoted 5 lines
	frame_length = (m->frame_length<<  3)>>  __ffs(spi->bits_per_word);

but that would need a comment stating that you're assuming bits_per_word to always be a power of two. Not sure if this is a correct assumption.

I dont think it will be a correct assumption, since our controller is flexible to
handle anything from 1 to 128 as bits_per_word.

right, but can the framework handle non-power-of-two bits_per_word ?

Quoted 8 lines
Quoted 5 lines

drivers/spi/spi-ti-qspi.c line 363

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	spin_unlock(&qspi->lock);

You should, before releasing the lock, mask your IRQs, so that you can get rid of IRQF_ONESHOT. Unmask them before returning from the IRQ thread.

Sorry, did not get you here?
I am reading interrupt status register before and clearing them in
the threaded irq.

you need to mask the IRQs, clear WC and FIRQ in IRQENABLE register... set them back at the end of the thread handler.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+	struct  ti_qspi *qspi;
+	struct spi_master *master;
+	struct resource         *r;
+	struct device_node *np = pdev->dev.of_node;
+	u32 max_freq;
+	int ret = 0, num_cs, irq;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(*qspi));
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 419

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	if (!master)
+		return -ENOMEM;
+
+	master->mode_bits = SPI_CPOL | SPI_CPHA;
+
+	master->num_chipselect = 1;

again with the num_chipselect = 1 ? IIRC this controller has 4 chipselects, just read 24.5.1 on your TRM.

Quoted 3 lines

this is unnecessary. I intended to configure chip selects through dt)as done below).
Will remove.

which brings me to the point of:

Do you review your own code before sending it out ? Doesn't look like...

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<  0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 458

Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

Signature · 1 line
balbi
#5 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Quoted 9 lines · Felipe Balbi

Hi,

Quoted 6 lines · Sourav Poddar
Quoted 6 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	frame_length = (m->frame_length<<   3) / spi->bits_per_word;

there's another way to optimize this. If you assume bits_per_word to always be power of two you can:

	frame_length = (m->frame_length<<   3)>>   __ffs(spi->bits_per_word);
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines

but that would need a comment stating that you're assuming bits_per_word to always be a power of two. Not sure if this is a correct assumption.

I dont think it will be a correct assumption, since our controller is flexible to
handle anything from 1 to 128 as bits_per_word.

right, but can the framework handle non-power-of-two bits_per_word ?

The only limitation I see is the max bits_per_word, which is 32. Though, I did set "master->bits_per_word_mask" as power of 2 in my probe.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

drivers/spi/spi-ti-qspi.c line 363

Quoted 1 line
drivers/spi/spi-ti-qspi.c new file +1 -0
+	spin_unlock(&qspi->lock);

You should, before releasing the lock, mask your IRQs, so that you can get rid of IRQF_ONESHOT. Unmask them before returning from the IRQ thread.

Sorry, did not get you here?
I am reading interrupt status register before and clearing them in
the threaded irq.

you need to mask the IRQs, clear WC and FIRQ in IRQENABLE register... set them back at the end of the thread handler.

Ok

Quoted 44 lines
Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+	struct  ti_qspi *qspi;
+	struct spi_master *master;
+	struct resource         *r;
+	struct device_node *np = pdev->dev.of_node;
+	u32 max_freq;
+	int ret = 0, num_cs, irq;
+
+	master = spi_alloc_master(&pdev->dev, sizeof(*qspi));
Quoted 9 lines

drivers/spi/spi-ti-qspi.c line 419

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	if (!master)
+		return -ENOMEM;
+
+	master->mode_bits = SPI_CPOL | SPI_CPHA;
+
+	master->num_chipselect = 1;

again with the num_chipselect = 1 ? IIRC this controller has 4 chipselects, just read 24.5.1 on your TRM.

Quoted 3 lines

this is unnecessary. I intended to configure chip selects through dt)as done below).
Will remove.

which brings me to the point of:

Do you review your own code before sending it out ? Doesn't look like...

Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<   0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

drivers/spi/spi-ti-qspi.c line 458

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

#6 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<   0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

drivers/spi/spi-ti-qspi.c line 458

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

won't be prepared in what way ?

Signature · 1 line
balbi
#7 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Quoted 21 lines · Felipe Balbi

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<    0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

drivers/spi/spi-ti-qspi.c line 458

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

won't be prepared in what way ?

Our driver will be down, so the irq might go un-serviced.

------------------------------------------------------------------------------
See everything from the browser to the database with AppDynamics Get end-to-end visibility with application monitoring from AppDynamics Isolate bottlenecks and diagnose root cause in seconds. Start your free trial of AppDynamics Pro today!
http://pubads.g.doubleclick.net/gampad/clk?id=48808831&iu=/4140/ostg.clktrk

#8 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
(quoted diff) +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<    0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

won't be prepared in what way ?

Our driver will be down, so the irq might go un-serviced.

only if you wrote the driver that way. IRQ subsystem doesn't know the state of the device, all it knows is that in case an IRQ fires, it needs to call the registered IRQ handler.

Now the thing is:

Initially you had the flag setup, so I asked why you needed it. I expected you to tell me why you think QSPI's IRQ shouldn't be disabled during suspend and the implications of disabling it.

Instead you just changed your mind and decided to remove the flag.

Because you changed your mind with no explanation, that tells me you haven't fully grasped how that flag works and what it means to set (or not set) it.

My question now is simply: why don't you need that flag ? What are the implications of setting that flag ? How would your driver behave if an IRQ fired while your driver was suspended ? Unless you understand what it does, how can you understand the behavior or the driver ?

cheers

Signature · 1 line
balbi
#9 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi Felipe,

Quoted 45 lines · Felipe Balbi

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
(quoted diff) +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<     0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

won't be prepared in what way ?

Our driver will be down, so the irq might go un-serviced.

only if you wrote the driver that way. IRQ subsystem doesn't know the state of the device, all it knows is that in case an IRQ fires, it needs to call the registered IRQ handler.

Now the thing is:

Initially you had the flag setup, so I asked why you needed it. I expected you to tell me why you think QSPI's IRQ shouldn't be disabled during suspend and the implications of disabling it.

Instead you just changed your mind and decided to remove the flag.

Because you changed your mind with no explanation, that tells me you haven't fully grasped how that flag works and what it means to set (or not set) it.

Quoted 7 lines

My question now is simply: why don't you need that flag ? What are the implications of setting that flag ? How would your driver behave if an IRQ fired while your driver was suspended ? Unless you understand what it does, how can you understand the behavior or the driver ?

cheers

We dont need IRQF_NO_SUSPEND flag in our qspi controller.

Qspi driver need to be prevented from receiving interrupts during system wide suspend/hibernation. "suspend_device_irqs" in kernel/irq/pm.c marks interrupt line in use and sets IRQS_SUSPENDED for them.
If we use "IRQF_NO_SUSPEND", we will bypass setting this IRQS_SUSPENDED flag, which is not. desired

For this, interrupt lines need to
and this function is provided for this purpose.
* It marks all interrupt lines in use, except for the timer ones, as
disabled
* and sets the IRQS_SUSPENDED flag for each of them.

This flag gets used in __disable_irq api(kernel/irq/manage.c) which

#10 lore raw

Re: [PATCHv6 1/2] drivers: spi: Add qspi flash controller

Hi,

Quoted 66 lines · Sourav Poddar

Hi Felipe,

Quoted 45 lines · Felipe Balbi

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 18 lines
Quoted 6 lines
(quoted diff) +6 -0
+	irq = platform_get_irq(pdev, 0);
+	if (irq<     0) {
+		dev_err(&pdev->dev, "no irq resource?\n");
+		return irq;
+	}
+

Review

Quoted 10 lines
(quoted diff) +10 -0
+	spin_lock_init(&qspi->lock);
+
+	qspi->base = devm_ioremap_resource(&pdev->dev, r);
+	if (IS_ERR(qspi->base)) {
+		ret = PTR_ERR(qspi->base);
+		goto free_master;
+	}
+
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,

why do you need IRQF_NO_SUSPEND ?

Quoted 8 lines
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

I should get away with this.

why ? Do you need or do you *not* need it ? And in either case, why ?

I was thinking, this will keep the irqs up even when we are hitting suspend, we will not be prepared to handle it. ?

won't be prepared in what way ?

Our driver will be down, so the irq might go un-serviced.

only if you wrote the driver that way. IRQ subsystem doesn't know the state of the device, all it knows is that in case an IRQ fires, it needs to call the registered IRQ handler.

Now the thing is:

Initially you had the flag setup, so I asked why you needed it. I expected you to tell me why you think QSPI's IRQ shouldn't be disabled during suspend and the implications of disabling it.

Instead you just changed your mind and decided to remove the flag.

Because you changed your mind with no explanation, that tells me you haven't fully grasped how that flag works and what it means to set (or not set) it.

Quoted 7 lines

My question now is simply: why don't you need that flag ? What are the implications of setting that flag ? How would your driver behave if an IRQ fired while your driver was suspended ? Unless you understand what it does, how can you understand the behavior or the driver ?

cheers

We dont need IRQF_NO_SUSPEND flag in our qspi controller.

Qspi driver need to be prevented from receiving interrupts during system wide suspend/hibernation.
"suspend_device_irqs" in kernel/irq/pm.c marks interrupt line in use and sets IRQS_SUSPENDED
for them.
If we use "IRQF_NO_SUSPEND", we will bypass setting this IRQS_SUSPENDED flag, which is not.
desired

Quoted 7 lines

For this, interrupt lines need to
and this function is provided for this purpose.
* It marks all interrupt lines in use, except for the timer ones, as
disabled
* and sets the IRQS_SUSPENDED flag for each of them.

This flag gets used in __disable_irq api(kernel/irq/manage.c) which

some formatting issues in the mail, but good that you looked at the code. Cheers

Signature · 1 line
balbi
#11 lore raw

PATCH v6 2/2 driver: spi: Add quad spi read support

In reply to Sourav Poddar

Since, qspi controller uses quad read.

Configuring the command register, if the transfer of data needs dual or quad lines.

This patch has been done on top of the following patch[1], which is just the basic idea of adding dual/quad support in spi framework. $subject patch will undergo changes with the ongoing discussion in the community.

This patch is posted to demonstrate how patch 1 of the series will support quad read.

[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047

---
 drivers/spi/spi-ti-qspi.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +14 -2
index 51fe95f..8a32b1c 100644
@@ -86,6 +86,7 @@ struct ti_qspi {
 #define QSPI_3_PIN			(1 << 18)
 #define QSPI_RD_SNGL			(1 << 16)
 #define QSPI_WR_SNGL			(2 << 16)
+#define	QSPI_RD_DUAL			(3 << 16)
 #define QSPI_RD_QUAD			(7 << 16)
 #define QSPI_INVAL			(4 << 16)
 #define QSPI_WC_CMD_INT_EN			(1 << 14)
@@ -264,6 +265,7 @@ static void qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
 {
 	u8 *rxbuf;
 	int wlen, count;
+	unsigned cmd = qspi->cmd;
 
 	count = t->len;
 	rxbuf = t->rx_buf;
@@ -273,8 +275,18 @@ static void qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
 		dev_dbg(qspi->dev, "rx cmd %08x dc %08x\n",
 			qspi->cmd | QSPI_RD_SNGL, qspi->dc);
 		ti_qspi_write(qspi, qspi->dc, QSPI_SPI_DC_REG);
-		ti_qspi_write(qspi, qspi->cmd | QSPI_RD_SNGL,
-			QSPI_SPI_CMD_REG);
+		switch (t->bitwidth) {
+		case SPI_BITWIDTH_QUAD:
+			cmd |= QSPI_RD_QUAD;
+			break;
+		case SPI_BITWIDTH_DUAL:
+			cmd |= QSPI_RD_DUAL;
+			break;
+		case SPI_BITWIDTH_SINGLE:
+		default:
+			cmd |= QSPI_RD_SNGL;
+		}
+		ti_qspi_writel(qspi, cmd, QSPI_SPI_CMD_REG);
 		ti_qspi_write(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
 		wait_for_completion(&qspi->transfer_complete);
 		ti_qspi_read_data(qspi, QSPI_SPI_DATA_REG, wlen, &rxbuf);
Signature · 1 line
1.7.1
#12 lore raw

Re: [RFC/PATCH 2/2] driver: spi: Add quad spi read support

Quoted 25 lines · Sourav Poddar

Since, qspi controller uses quad read.

Configuring the command register, if the transfer of data needs dual or quad lines.

This patch has been done on top of the following patch[1], which is just the basic idea of adding dual/quad support in spi framework. $subject patch will undergo changes with the ongoing discussion in the community.

This patch is posted to demonstrate how patch 1 of the series will support quad read.

[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047

---
 drivers/spi/spi-ti-qspi.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +0 -0
index 51fe95f..8a32b1c 100644

drivers/spi/spi-ti-qspi.c struct ti_qspi { · line 90

Quoted 5 lines
drivers/spi/spi-ti-qspi.c +1 -0
@@ -86,6 +86,7 @@ struct ti_qspi {
 #define QSPI_3_PIN			(1 << 18)
 #define QSPI_RD_SNGL			(1 << 16)
 #define QSPI_WR_SNGL			(2 << 16)
+#define	QSPI_RD_DUAL			(3 << 16)
 #define QSPI_RD_QUAD			(7 << 16)

so RD_QUAD is defined in previous patch but not RD_DUAL ? What gives ?

IMHO, just merge this patch with previous and make the entire driver depend on the other patch.

Signature · 1 line
balbi
#13 lore raw

Re: [RFC/PATCH 2/2] driver: spi: Add quad spi read support

Quoted 21 lines · Felipe Balbi
Quoted 20 lines · Sourav Poddar

Since, qspi controller uses quad read.

Configuring the command register, if the transfer of data needs dual or quad lines.

This patch has been done on top of the following patch[1], which is just the basic idea of adding dual/quad support in spi framework. $subject patch will undergo changes with the ongoing discussion in the community.

This patch is posted to demonstrate how patch 1 of the series will support quad read.

[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047

---
  drivers/spi/spi-ti-qspi.c |   16 ++++++++++++++--
  1 files changed, 14 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/spi/spi-ti-qspi.c struct ti_qspi { · line 90

Quoted 10 lines
drivers/spi/spi-ti-qspi.c +1 -0
index 51fe95f..8a32b1c 100644
@@ -86,6 +86,7 @@ struct ti_qspi {
  #define QSPI_3_PIN			(1<<  18)
  #define QSPI_RD_SNGL			(1<<  16)
  #define QSPI_WR_SNGL			(2<<  16)
+#define	QSPI_RD_DUAL			(3<<  16)
  #define QSPI_RD_QUAD			(7<<  16)

so RD_QUAD is defined in previous patch but not RD_DUAL ? What gives ?

I think I will define RD_DUAL in the previous patch...

Quoted 3 lines

IMHO, just merge this patch with previous and make the entire driver depend on the other patch.

but I was thinking of keeping rest of the $subject patch seperate, since the idea of implementing dual/quad read in spi framework is still under discussion. and this patch will change.

So, it would be good if we can get the basic previous patch in, and then when the other discussion is sorted out, we can get this in?

~Sourav

#14 lore raw

Re: [RFC/PATCH 2/2] driver: spi: Add quad spi read support

Quoted 38 lines · Sourav Poddar
Quoted 21 lines · Felipe Balbi
Quoted 20 lines · Sourav Poddar

Since, qspi controller uses quad read.

Configuring the command register, if the transfer of data needs dual or quad lines.

This patch has been done on top of the following patch[1], which is just the basic idea of adding dual/quad support in spi framework. $subject patch will undergo changes with the ongoing discussion in the community.

This patch is posted to demonstrate how patch 1 of the series will support quad read.

[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047

---
 drivers/spi/spi-ti-qspi.c |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)
Quoted 12 lines

drivers/spi/spi-ti-qspi.c struct ti_qspi { · line 90

Quoted 10 lines
drivers/spi/spi-ti-qspi.c +1 -0
index 51fe95f..8a32b1c 100644
@@ -86,6 +86,7 @@ struct ti_qspi {
 #define QSPI_3_PIN			(1<<  18)
 #define QSPI_RD_SNGL			(1<<  16)
 #define QSPI_WR_SNGL			(2<<  16)
+#define	QSPI_RD_DUAL			(3<<  16)
 #define QSPI_RD_QUAD			(7<<  16)

so RD_QUAD is defined in previous patch but not RD_DUAL ? What gives ?

I think I will define RD_DUAL in the previous patch...

Quoted 3 lines

IMHO, just merge this patch with previous and make the entire driver depend on the other patch.

Quoted 8 lines

but I was thinking of keeping rest of the $subject patch seperate, since the idea of implementing dual/quad read in spi framework is still under discussion.
and this patch will change.

So, it would be good if we can get the basic previous patch in, and then when the
other discussion is sorted out, we can get this in?

alright, in that case it makes sense.

Signature · 1 line
balbi