Skip to contentSkip to conversation

spi changes and ti quad spi controller.

PATCH Applied Sourav Poddar 5 participants 26 messages Jul 18, 2013 – Jul 19, 2013

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

cover spi changes and ti quad spi controller.

Add support for calculating message length in spi framework.

Add support for quad spi controller.

Patch 2 of this series had been posted before. Sending along with the series along with ather propsed change.

Sourav Poddar (3):
driver: spi: Modify core to compute the message length
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                         |  550 +++++++++++++++++++++
 drivers/spi/spi.c                                 |    1 +
 include/linux/spi/spi.h                           |    1 +
 6 files changed, 583 insertions(+), 0 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/ti_qspi.txt
 create mode 100644 drivers/spi/spi-ti-qspi.c

------------------------------------------------------------------------------
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

#1 lore raw

PATCH 1/3 driver: spi: Modify core to compute the message length

Make spi core calculate the message length while
populating the other transfer parameters.

Usecase, driver can use it to populate framelength filed in their controller.

---
 drivers/spi/spi.c       |    1 +
 include/linux/spi/spi.h |    1 +
 2 files changed, 2 insertions(+), 0 deletions(-)
drivers/spi/spi.c +1 -0
index 32b7bb1..6a05b3c 100644
@@ -1375,6 +1375,7 @@ static int __spi_async(struct spi_device *spi, struct spi_message *message)
 	 * it is not set for this transfer.
 	 */
 	list_for_each_entry(xfer, &message->transfers, transfer_list) {
+		message->frame_length += xfer->len;
 		if (!xfer->bits_per_word)
 			xfer->bits_per_word = spi->bits_per_word;
 		if (!xfer->speed_hz)
include/linux/spi/spi.h +1 -0
index 6ff26c8..d83841e 100644
@@ -575,6 +575,7 @@ struct spi_message {
 	/* completion is reported through a callback */
 	void			(*complete)(void *context);
 	void			*context;
+	unsigned		frame_length;
 	unsigned		actual_length;
 	int			status;
 
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
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
maintainer Applied
#2 lore raw

Re: [RFC/PATCHv2 1/3] driver: spi: Modify core to compute the message length

Quoted 2 lines · Sourav Poddar

Make spi core calculate the message length while
populating the other transfer parameters.

Applied, thanks.

#3 lore raw

PATCH v4 2/3 drivers: spi: Add qspi flash controller

In reply to Sourav Poddar

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).

---
v3->v4
- Did miscellaneous cleanup
- Added power management support.

 Documentation/devicetree/bindings/spi/ti_qspi.txt |   22 +
 drivers/spi/Kconfig                               |    8 +
 drivers/spi/Makefile                              |    1 +
 drivers/spi/spi-ti-qspi.c                         |  537 +++++++++++++++++++++
 4 files changed, 568 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..e594fdb 100644
@@ -285,6 +285,14 @@ config SPI_OMAP24XX
 	  SPI master controller for OMAP24XX and later Multichannel SPI
 	  (McSPI) modules.
 
+config QSPI_DRA7xxx
+	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..b3b4857 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_QSPI_DRA7xxx)              += 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 +537 -0

537 lines not on this page · raw message

Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
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
#4 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi,

it might be just me, but ...

Quoted 26 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +26 -0
+static inline unsigned long ti_qspi_readl_data(struct ti_qspi *qspi,
+		unsigned long reg, int wlen)
+{
+	switch (wlen) {
+	case 8:
+		return readw(qspi->base + reg);
+		break;
+	case 16:
+		return readb(qspi->base + reg);
+		break;
+	case 32:
+		return readl(qspi->base + reg);
+		break;
+	default:
+		return -EINVAL;
+	}
+}
+
+static inline void ti_qspi_writel_data(struct ti_qspi *qspi,
+		unsigned long val, unsigned long reg, int wlen)
+{
+	switch (wlen) {
+	case 8:
+		writew(val, qspi->base + reg);
+		break;
+	case 16:

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+		writeb(val, qspi->base + reg);
+		break;
+	case 32:
+		writeb(val, qspi->base + reg);
+		break;
+	default:
+		dev_dbg(qspi->dev, "word lenght out of range");
+		break;
+	}
+}

because of these two functions you have the hability to read/write *more* than one byte, and yet ...

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

Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13 -0
+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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4. Same goes for read_data(), below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

You only use writew() if you have exactly 2 bytes to write and writeb() if you have exactly 1 byte to write. 3 bytes we'll be left as an exercise.

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -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 */
+	qspi->dc = 0;

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -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 = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
+				spi->bits_per_word);

this calculation doesn't look correct.

	(m->frame_length * spi->bits_per_word) /
		spi->bits_per_word = m->frame_length

What are you trying to achieve here ? frame_length should be counted in words right ? And we get that value in bytes. So what's the best calculation to convert bytes into words ? If you have 8 bits_per_word you don't need any calculation, but if you have 32 bits_per_word, you _do_ need something.

How will you achieve the number you want ? (hint: 1 byte == 8 bits)

And btw, all of these mistakes pretty much tell me that this driver hasn't been tested. How have you tested this driver ? Is your spansion memory accessed with 8 bits_per_word only ? Is there anyway to use 32 bits_per_word with that device ? That would uncover quite a few mistakes in $subject.

Signature · 1 line
balbi
#5 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi Felipe,

Quoted 44 lines · Felipe Balbi

Hi,

it might be just me, but ...

Quoted 26 lines · Sourav Poddar
drivers/spi/spi-ti-qspi.c new file +26 -0
+static inline unsigned long ti_qspi_readl_data(struct ti_qspi *qspi,
+		unsigned long reg, int wlen)
+{
+	switch (wlen) {
+	case 8:
+		return readw(qspi->base + reg);
+		break;
+	case 16:
+		return readb(qspi->base + reg);
+		break;
+	case 32:
+		return readl(qspi->base + reg);
+		break;
+	default:
+		return -EINVAL;
+	}
+}
+
+static inline void ti_qspi_writel_data(struct ti_qspi *qspi,
+		unsigned long val, unsigned long reg, int wlen)
+{
+	switch (wlen) {
+	case 8:
+		writew(val, qspi->base + reg);
+		break;
+	case 16:

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+		writeb(val, qspi->base + reg);
+		break;
+	case 32:
+		writeb(val, qspi->base + reg);
+		break;
+	default:
+		dev_dbg(qspi->dev, "word lenght out of range");
+		break;
+	}
+}

because of these two functions you have the hability to read/write *more* than one byte, and yet ...

Quoted 15 lines

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

Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13 -0
+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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4.

hmm..got this point. Yes, my mistake, here I agree if wlen is not 8 bits txbuf++ is not valid.

Quoted 4 lines

Same goes for read_data(),
below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

Do you mean 4 words of 8 bits?

Quoted 3 lines

You only use writew() if you have exactly 2 bytes to write and writeb() if you have exactly 1 byte to write. 3 bytes we'll be left as an exercise.

hmm..yes.

Quoted 23 lines
Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -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 */
+	qspi->dc = 0;

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -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 = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
+				spi->bits_per_word);

this calculation doesn't look correct.

Quoted 9 lines
	(m->frame_length * spi->bits_per_word) /
		spi->bits_per_word = m->frame_length

What are you trying to achieve here ? frame_length should be counted in words right ? And we get that value in bytes. So what's the best calculation to convert bytes into words ? If you have 8 bits_per_word you don't need any calculation, but if you have 32 bits_per_word, you _do_ need something.

Yes, just derive this formulae with 8 bits per word in mind. Will change.
It should be (m->frame_length * 8) / spi->bits_per_word

Quoted 4 lines

How will you achieve the number you want ? (hint: 1 byte == 8 bits)

And btw, all of these mistakes pretty much tell me that this driver hasn't been tested. How have you tested this driver ?

After bootup, I checked for deive detting enumerated as /proc/mtd. After which I am using mtdutils(erase, dump and write utilied to check for the communication with the flash device.)

Quoted 2 lines

Is your spansion
memory accessed with 8 bits_per_word only ?

Yes, most of the places is like that and data is sapmled in 8 bits. For some opcodes, we need to send 3 bytes addresses after instruction
to the flash chip.

Quoted 4 lines

Is there anyway to use
32 bits_per_word with that device ? That would uncover quite a few mistakes in $subject.

------------------------------------------------------------------------------
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

#6 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 16 lines · Sourav Poddar
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+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;
Quoted 8 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4.

Quoted 7 lines

hmm..got this point. Yes, my mistake, here I agree if wlen is not 8 bits txbuf++ is not valid.

Quoted 4 lines

Same goes for read_data(),
below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

Do you mean 4 words of 8 bits?

yeah. Say you have wlen = 8 but the transfer length is 8 bytes (64 bits). If you use writeb(), you will do 8 writes, if you use writel() you'll do 2 writes.

Quoted 32 lines
Quoted 23 lines
Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -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 */
+	qspi->dc = 0;

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -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 = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
+				spi->bits_per_word);

this calculation doesn't look correct.

Quoted 9 lines
	(m->frame_length * spi->bits_per_word) /
		spi->bits_per_word = m->frame_length

What are you trying to achieve here ? frame_length should be counted in words right ? And we get that value in bytes. So what's the best calculation to convert bytes into words ? If you have 8 bits_per_word you don't need any calculation, but if you have 32 bits_per_word, you _do_ need something.

Quoted 3 lines

Yes, just derive this formulae with 8 bits per word in mind. Will change.
It should be (m->frame_length * 8) / spi->bits_per_word

right on. To make sure this will execute a little faster (you never know what several different versions of GCC will do), instead of multiplying by 8, left shift by 3.

Quoted 7 lines
Quoted 4 lines

How will you achieve the number you want ? (hint: 1 byte == 8 bits)

And btw, all of these mistakes pretty much tell me that this driver hasn't been tested. How have you tested this driver ?

After bootup, I checked for deive detting enumerated as /proc/mtd. After which I am using mtdutils(erase, dump and write utilied to check for the communication with the flash device.)

alright, make that clear in your commit log.

Signature · 1 line
balbi
#7 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 18 lines · Felipe Balbi
Quoted 17 lines · Sourav Poddar
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+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;
Quoted 8 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4.

hmm..got this point. Yes, my mistake, here I agree if wlen is not 8 bits txbuf++ is not valid.

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

Same goes for read_data(),
below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

Do you mean 4 words of 8 bits?

yeah. Say you have wlen = 8 but the transfer length is 8 bytes (64 bits). If you use writeb(), you will do 8 writes, if you use writel() you'll do 2 writes.

hmm.. I will check this out.
If our wlen is 8, after every 8 bits there will be
an interrupt. Will check that out, how that interrupt
should be tackled if we desired to read 4 bytes in a single writel/readl.

Quoted 32 lines
Quoted 32 lines
Quoted 32 lines
Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -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 */
+	qspi->dc = 0;

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -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 = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
+				spi->bits_per_word);

this calculation doesn't look correct.

	(m->frame_length * spi->bits_per_word) /
		spi->bits_per_word = m->frame_length

What are you trying to achieve here ? frame_length should be counted in words right ? And we get that value in bytes. So what's the best calculation to convert bytes into words ? If you have 8 bits_per_word you don't need any calculation, but if you have 32 bits_per_word, you _do_ need something.

Quoted 7 lines
Quoted 3 lines

Yes, just derive this formulae with 8 bits per word in mind. Will change.
It should be (m->frame_length * 8) / spi->bits_per_word

right on. To make sure this will execute a little faster (you never know what several different versions of GCC will do), instead of multiplying by 8, left shift by 3.

Ok. Will do.

Quoted 9 lines
Quoted 7 lines
Quoted 4 lines

How will you achieve the number you want ? (hint: 1 byte == 8 bits)

And btw, all of these mistakes pretty much tell me that this driver hasn't been tested. How have you tested this driver ?

After bootup, I checked for deive detting enumerated as /proc/mtd. After which I am using mtdutils(erase, dump and write utilied to check for the communication with the flash device.)

alright, make that clear in your commit log.

Ok.

------------------------------------------------------------------------------
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: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Felipe Balbi

Hi Felipe,

Quoted 18 lines · Felipe Balbi
Quoted 17 lines · Sourav Poddar
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+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;
Quoted 8 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4.

hmm..got this point. Yes, my mistake, here I agree if wlen is not 8 bits txbuf++ is not valid.

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

Same goes for read_data(),
below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

Do you mean 4 words of 8 bits?

yeah. Say you have wlen = 8 but the transfer length is 8 bytes (64 bits). If you use writeb(), you will do 8 writes, if you use writel() you'll do 2 writes.

Just some more findings on this, after wlen bits are transferred we need an WC interrupt. So, if I try to pack 4 words of 8bits and use readl/writel, there will be an interrupt after every wlen bits transferred and things will get screwd up.

So, for 8 bits word we need to use readb, for 16 bits word readw.

Quoted 48 lines
Quoted 32 lines
Quoted 23 lines
Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +11 -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 */
+	qspi->dc = 0;

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -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 = DIV_ROUND_UP(m->frame_length * spi->bits_per_word,
+				spi->bits_per_word);

this calculation doesn't look correct.

Quoted 9 lines
	(m->frame_length * spi->bits_per_word) /
		spi->bits_per_word = m->frame_length

What are you trying to achieve here ? frame_length should be counted in words right ? And we get that value in bytes. So what's the best calculation to convert bytes into words ? If you have 8 bits_per_word you don't need any calculation, but if you have 32 bits_per_word, you _do_ need something.

Quoted 3 lines

Yes, just derive this formulae with 8 bits per word in mind. Will change.
It should be (m->frame_length * 8) / spi->bits_per_word

right on. To make sure this will execute a little faster (you never know what several different versions of GCC will do), instead of multiplying by 8, left shift by 3.

Quoted 7 lines
Quoted 4 lines

How will you achieve the number you want ? (hint: 1 byte == 8 bits)

And btw, all of these mistakes pretty much tell me that this driver hasn't been tested. How have you tested this driver ?

After bootup, I checked for deive detting enumerated as /proc/mtd. After which I am using mtdutils(erase, dump and write utilied to check for the communication with the flash device.)

alright, make that clear in your commit log.

#9 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi,

Quoted 28 lines · Sourav Poddar
Quoted 18 lines · Felipe Balbi
Quoted 17 lines · Sourav Poddar
Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+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;
Quoted 8 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+	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_writel_data(qspi, *txbuf++, QSPI_SPI_DATA_REG, wlen);

you always increment by each byte. Here, if you used writel(), you wrote 4 bytes and should increment txbuf by 4.

hmm..got this point. Yes, my mistake, here I agree if wlen is not 8 bits txbuf++ is not valid.

Quoted 9 lines
Quoted 5 lines
Quoted 4 lines

Same goes for read_data(),
below. Another thing. Even though your wlen might be 8 bits, if you write 4 bytes to write, you can save a few CPU cycles by using writel().

Do you mean 4 words of 8 bits?

yeah. Say you have wlen = 8 but the transfer length is 8 bytes (64 bits). If you use writeb(), you will do 8 writes, if you use writel() you'll do 2 writes.

Quoted 5 lines

Just some more findings on this, after wlen bits are transferred we need an WC interrupt.
So, if I try to pack 4 words of 8bits and use readl/writel, there will be an interrupt after every
wlen bits transferred and things will get screwd up.

they will not if you throttle the IRQs or add some knowledge about the FIFO sizes. I mean, there are ways to get this working.

Quoted 1 line

So, for 8 bits word we need to use readb, for 16 bits word readw.

not entirely true...

I mean, you have a 32-bit FIFO, why would underutilize the FIFO by always writing 8-bits ? Write 32 bits, when you get the first word completion, you know you have 8-bits of space in the FIFO, then you can fill those 8 bits with new data. (all of this is assuming word length is 8-bits, clearly if it is more, then you need to change the assumptions).

Another thing which might help, is checking if the HW will even access the other DATA registers even if word length is <= 32 bits. If it does, then you have a total of 128 bits to shift data into, which can save you a lot of time filling up FIFOs and waiting for them to empty.

Signature · 1 line
balbi
maintainer
#10 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Sourav Poddar
Quoted 4 lines · Sourav Poddar

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.

Have you seen the ongoing thread about SPI buses with extra data lines? How does this driver fit in with that?

drivers/spi/Makefile obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o · line 52

Quoted 10 lines
drivers/spi/Makefile +1 -0
@@ -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_QSPI_DRA7xxx)              += 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

Please use SPI_ like the other drivers.

drivers/spi/Makefile

Quoted 13 lines
drivers/spi/Makefile +13 -0
+static int ti_qspi_prepare_xfer(struct spi_master *master)
+{
+	struct ti_qspi *qspi = spi_master_get_devdata(master);
+	int ret;
+
+	ret = pm_runtime_get_sync(qspi->dev);
+	if (ret < 0) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}
+
+	return 0;
+}

This is a very common pattern, it should probably be factored out into the core, probably not even as ops but rather as an actual feature.

Quoted 5 lines
drivers/spi/Makefile +5 -0
+	list_for_each_entry(t, &m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+		qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+		ret = qspi_transfer_msg(qspi, t);

drivers/spi/Makefile

Quoted 10 lines
drivers/spi/Makefile +10 -0
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
+
+		m->actual_length += t->len;
+
+		if (list_is_last(&t->transfer_list, &m->transfers))
+			goto out;
+	}

The use of list_is_last() here is *realy* strange - what's going on there?

Quoted 8 lines
drivers/spi/Makefile +8 -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);

drivers/spi/Makefile

Quoted 10 lines
drivers/spi/Makefile +10 -0
+
+	stat = ti_qspi_readl(qspi, QSPI_SPI_STATUS_REG);
+	mask = ti_qspi_readl(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (stat && mask)
+		ret = IRQ_WAKE_THREAD;
+
+	spin_unlock(&qspi->lock);
+
+	return ret;

According to the above code we might interrupt for masked events... that's a bit worrying isn't it?

drivers/spi/Makefile

Quoted 8 lines
drivers/spi/Makefile +8 -0
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,
+			dev_name(&pdev->dev), qspi);
+	if (ret < 0) {
+		dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
+				irq);
+		goto free_master;
+	}

Standard question about devm_request_threaded_irq() - how can we be certain it's safe to use during removal?

#11 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 9 lines · Mark Brown
Quoted 4 lines · Sourav Poddar

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.

Have you seen the ongoing thread about SPI buses with extra data lines? How does this driver fit in with that?

I have tried using it in my patch3 of this series..

Quoted 12 lines

drivers/spi/Makefile obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o · line 52

Quoted 10 lines
drivers/spi/Makefile +1 -0
@@ -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_QSPI_DRA7xxx)              += 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

Please use SPI_ like the other drivers.

Ok.

Quoted 7 lines
Quoted 7 lines
drivers/spi/Makefile +7 -0
+static int ti_qspi_prepare_xfer(struct spi_master *master)
+{
+	struct ti_qspi *qspi = spi_master_get_devdata(master);
+	int ret;
+
+	ret = pm_runtime_get_sync(qspi->dev);
+	if (ret<  0) {
Quoted 9 lines

drivers/spi/Makefile

Quoted 6 lines
drivers/spi/Makefile +6 -0
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}
+
+	return 0;
+}

This is a very common pattern, it should probably be factored out into the core, probably not even as ops but rather as an actual feature.

May be yes.

Quoted 9 lines
Quoted 9 lines
drivers/spi/Makefile +9 -0
+	list_for_each_entry(t,&m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+		qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+		ret = qspi_transfer_msg(qspi, t);
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
Quoted 9 lines

drivers/spi/Makefile

Quoted 6 lines
drivers/spi/Makefile +6 -0
+
+		m->actual_length += t->len;
+
+		if (list_is_last(&t->transfer_list,&m->transfers))
+			goto out;
+	}

The use of list_is_last() here is *realy* strange - what's going on there?

We are checking if there is any transfer left, if no we are signalling the flash device about the end of transfer.

Quoted 12 lines
Quoted 12 lines
drivers/spi/Makefile +12 -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_readl(qspi, QSPI_SPI_STATUS_REG);
+	mask = ti_qspi_readl(qspi, QSPI_INTR_ENABLE_SET_REG);
+
Quoted 9 lines

drivers/spi/Makefile

Quoted 6 lines
drivers/spi/Makefile +6 -0
+	if (stat&&  mask)
+		ret = IRQ_WAKE_THREAD;
+
+	spin_unlock(&qspi->lock);
+
+	return ret;

According to the above code we might interrupt for masked events... that's a bit worrying isn't it?

Yes, there is WC interrupt enable bit which enables the interrupt. This interrupt
gets disabled by writing to the CLEAR reg in the threaded irq.

Quoted 10 lines

drivers/spi/Makefile

Quoted 8 lines
drivers/spi/Makefile +8 -0
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,
+			dev_name(&pdev->dev), qspi);
+	if (ret<  0) {
+		dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
+				irq);
+		goto free_master;
+	}

Standard question about devm_request_threaded_irq() - how can we be certain it's safe to use during removal?

I am not sure about the exact flow. If we see the api description, it says about irq getting
freed automatically.
Practically, I will check that on removing the driver, cat /proc/interrupts should not show
the required interrupt getting registered.
Though, I see an api also existing "devm_free_irq", which explicitly un allocate your irq requested
through devm_* variants.

------------------------------------------------------------------------------
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

#12 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi,

Quoted 18 lines · Sourav Poddar
Quoted 9 lines
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	list_for_each_entry(t,&m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+		qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+		ret = qspi_transfer_msg(qspi, t);
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
Quoted 9 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+
+		m->actual_length += t->len;
+
+		if (list_is_last(&t->transfer_list,&m->transfers))
+			goto out;
+	}

The use of list_is_last() here is *realy* strange - what's going on there?

Quoted 2 lines

We are checking if there is any transfer left, if no we are signalling the flash device about the end of transfer.

I'll quote your diff below because I wanted to show where your 'out' label lies:

+ list_for_each_entry(t, &m->transfers, transfer_list) {

+               qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+               qspi->cmd |= QSPI_WC_CMD_INT_EN;

+
+ ret = qspi_transfer_msg(qspi, t);
+ if (ret) {
+ dev_dbg(qspi->dev, "transfer message failed\n");
+ return -EINVAL;
+ }
+
+ m->actual_length += t->len;
+
+ if (list_is_last(&t->transfer_list, &m->transfers))
+ goto out;
+ }
+
+out:
+ m->status = status;
+ spi_finalize_current_message(master);

see how it's place right after the closing curly brackets ? In that case, why do you need it ? list_for_each_entry() will do exactly what it
says: iterate over each entry on the entry. When it reaches the last one, the loop will end.

This renders your list_is_last() check useless. In fact, you could've figured that out if you just spent the time to read list_for_each_entry() carefully.

Signature · 1 line
balbi
maintainer
#13 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Sourav Poddar
Quoted 20 lines · Sourav Poddar
Quoted 9 lines · Mark Brown
Quoted 9 lines
drivers/spi/spi-ti-qspi.c new file +9 -0
+	list_for_each_entry(t,&m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+		qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+		ret = qspi_transfer_msg(qspi, t);
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
Quoted 8 lines

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +6 -0
+
+		m->actual_length += t->len;
+
+		if (list_is_last(&t->transfer_list,&m->transfers))
+			goto out;
+	}

The use of list_is_last() here is *realy* strange - what's going on there?

Quoted 2 lines

We are checking if there is any transfer left, if no we are signalling the flash device about the end of transfer.

Please be more specific. How will you ever reach the end of the transfer list in a way which wouldn't cause the for loop to terminate?

Quoted 22 lines
Quoted 13 lines
Quoted 13 lines
drivers/spi/spi-ti-qspi.c new file +13 -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_readl(qspi, QSPI_SPI_STATUS_REG);
+	mask = ti_qspi_readl(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (stat&&  mask)
Quoted 8 lines

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

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+		ret = IRQ_WAKE_THREAD;
+
+	spin_unlock(&qspi->lock);
+
+	return ret;

According to the above code we might interrupt for masked events... that's a bit worrying isn't it?

Quoted 3 lines

Yes, there is WC interrupt enable bit which enables the interrupt. This interrupt
gets disabled by writing to the CLEAR reg in the threaded irq.

So why do we report that we handled the interrupt then? Shouldn't we at least warn if we're getting spurious IRQs?

Quoted 10 lines
Quoted 10 lines

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

Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8 -0
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,
+			dev_name(&pdev->dev), qspi);
+	if (ret<  0) {
+		dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
+				irq);
+		goto free_master;
+	}

Standard question about devm_request_threaded_irq() - how can we be certain it's safe to use during removal?

Quoted 9 lines

I am not sure about the exact flow. If we see the api description, it says about irq getting
freed automatically.
Practically, I will check that on removing the driver, cat /proc/interrupts should not show
the required interrupt getting registered.
Though, I see an api also existing "devm_free_irq", which explicitly un allocate your irq requested
through devm_* variants.

You're missing the point here - how can you be sure that the interrupt can't fire?

Quoted 3 lines
#14 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi,

Quoted 22 lines · Mark Brown
Quoted 21 lines
Quoted 21 lines
Quoted 8 lines
drivers/spi/spi-ti-qspi.c new file +8 -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);

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

Quoted 10 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+
+	stat = ti_qspi_readl(qspi, QSPI_SPI_STATUS_REG);
+	mask = ti_qspi_readl(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (stat&&  mask)
+		ret = IRQ_WAKE_THREAD;
+
+	spin_unlock(&qspi->lock);
+
+	return ret;

According to the above code we might interrupt for masked events... that's a bit worrying isn't it?

Quoted 6 lines
Quoted 3 lines

Yes, there is WC interrupt enable bit which enables the interrupt. This interrupt
gets disabled by writing to the CLEAR reg in the threaded irq.

So why do we report that we handled the interrupt then? Shouldn't we at least warn if we're getting spurious IRQs?

not spurious. OMAP has two sets of IRQ status registers. One is call IRQSTATUS$n (n = 0, 1, ...) and IRQSTATUS_RAW$n.

IRQSTATUS$n will only enable the bits which fired IRQs and aren't masked while IRQSTATUS_RAW$n will also enable the bits which are masked. I could never come up with a use case where we would need to handle IRQs which we decided to mask, but perhaps there might be some cases, I don't know.

Based on that, I believe Sourav is reading IRQSTATUS_RAW$n, then he need to clear the masked bits.

Signature · 1 line
balbi
maintainer
#15 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 8 lines · Felipe Balbi
Quoted 2 lines · Mark Brown

So why do we report that we handled the interrupt then? Shouldn't we at least warn if we're getting spurious IRQs?

not spurious. OMAP has two sets of IRQ status registers. One is call IRQSTATUS$n (n = 0, 1, ...) and IRQSTATUS_RAW$n.

Quoted 8 lines

IRQSTATUS$n will only enable the bits which fired IRQs and aren't masked while IRQSTATUS_RAW$n will also enable the bits which are masked. I could never come up with a use case where we would need to handle IRQs which we decided to mask, but perhaps there might be some cases, I don't know.

Based on that, I believe Sourav is reading IRQSTATUS_RAW$n, then he need to clear the masked bits.

That's not the issue - the issue is that if none of the unmasked interrupts are being asserted we shouldn't be in the interrupt handler in the first place but the driver silently accepts that and reports that it handled the interrupt.

#16 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Hi Mark,

Quoted 13 lines · Mark Brown
Quoted 12 lines · Felipe Balbi
Quoted 2 lines · Mark Brown

So why do we report that we handled the interrupt then? Shouldn't we at least warn if we're getting spurious IRQs?

not spurious. OMAP has two sets of IRQ status registers. One is call IRQSTATUS$n (n = 0, 1, ...) and IRQSTATUS_RAW$n.
IRQSTATUS$n will only enable the bits which fired IRQs and aren't masked while IRQSTATUS_RAW$n will also enable the bits which are masked. I could never come up with a use case where we would need to handle IRQs which we decided to mask, but perhaps there might be some cases, I don't know.
Based on that, I believe Sourav is reading IRQSTATUS_RAW$n, then he need to clear the masked bits.

Quoted 4 lines

That's not the issue - the issue is that if none of the unmasked interrupts are being asserted we shouldn't be in the interrupt handler in the first place but the driver silently accepts that and reports that it handled the interrupt.

I believe this is what you hinted at doing..

there is a QSPI_INTR_STATUS_ENABLED_CLEAR register, which indicated the interrupt
status.
if nothing is set in the above register, I should return IRQ_NONE.

------------------------------------------------------------------------------
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

maintainer
#17 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 4 lines · Sourav Poddar

there is a QSPI_INTR_STATUS_ENABLED_CLEAR register, which indicated the interrupt
status.
if nothing is set in the above register, I should return IRQ_NONE.

Yes, and/or complain in the log.

#18 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Mark Brown

Hi Mark,

Quoted 21 lines · Mark Brown
Quoted 4 lines · Sourav Poddar

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.

Have you seen the ongoing thread about SPI buses with extra data lines? How does this driver fit in with that?

drivers/spi/Makefile obj-$(CONFIG_SPI_OCTEON) += spi-octeon.o · line 52

Quoted 10 lines
drivers/spi/Makefile +1 -0
@@ -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_QSPI_DRA7xxx)              += 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

Please use SPI_ like the other drivers.

Quoted 16 lines

drivers/spi/Makefile

Quoted 13 lines
drivers/spi/Makefile +13 -0
+static int ti_qspi_prepare_xfer(struct spi_master *master)
+{
+	struct ti_qspi *qspi = spi_master_get_devdata(master);
+	int ret;
+
+	ret = pm_runtime_get_sync(qspi->dev);
+	if (ret<  0) {
+		dev_err(qspi->dev, "pm_runtime_get_sync() failed\n");
+		return ret;
+	}
+
+	return 0;
+}

This is a very common pattern, it should probably be factored out into the core, probably not even as ops but rather as an actual feature.

I see, every other driver doing it this way right now.
Is it ok, if I take your above idea as an seperate excercise after this patch.?

Quoted 39 lines
Quoted 5 lines
drivers/spi/Makefile +5 -0
+	list_for_each_entry(t,&m->transfers, transfer_list) {
+		qspi->cmd |= QSPI_WLEN(t->bits_per_word);
+		qspi->cmd |= QSPI_WC_CMD_INT_EN;
+
+		ret = qspi_transfer_msg(qspi, t);

drivers/spi/Makefile

Quoted 10 lines
drivers/spi/Makefile +10 -0
+		if (ret) {
+			dev_dbg(qspi->dev, "transfer message failed\n");
+			return -EINVAL;
+		}
+
+		m->actual_length += t->len;
+
+		if (list_is_last(&t->transfer_list,&m->transfers))
+			goto out;
+	}

The use of list_is_last() here is *realy* strange - what's going on there?

Quoted 8 lines
drivers/spi/Makefile +8 -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);

drivers/spi/Makefile

Quoted 10 lines
drivers/spi/Makefile +10 -0
+
+	stat = ti_qspi_readl(qspi, QSPI_SPI_STATUS_REG);
+	mask = ti_qspi_readl(qspi, QSPI_INTR_ENABLE_SET_REG);
+
+	if (stat&&  mask)
+		ret = IRQ_WAKE_THREAD;
+
+	spin_unlock(&qspi->lock);
+
+	return ret;

According to the above code we might interrupt for masked events... that's a bit worrying isn't it?

Quoted 10 lines

drivers/spi/Makefile

Quoted 8 lines
drivers/spi/Makefile +8 -0
+	ret = devm_request_threaded_irq(&pdev->dev, irq, ti_qspi_isr,
+			ti_qspi_threaded_isr, IRQF_NO_SUSPEND | IRQF_ONESHOT,
+			dev_name(&pdev->dev), qspi);
+	if (ret<  0) {
+		dev_err(&pdev->dev, "Failed to register ISR for IRQ %d\n",
+				irq);
+		goto free_master;
+	}

Standard question about devm_request_threaded_irq() - how can we be certain it's safe to use during removal?

------------------------------------------------------------------------------
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

#19 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Sourav Poddar
Quoted 5 lines · Sourav Poddar

+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

What is ti,hwmods? It's not clear from the description. It also doesn't appear to be used in the driver. At least, I did not find any occurrence of "hwmods" in the driver code.

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

Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2 -0
+static inline unsigned long ti_qspi_readl_data(struct ti_qspi *qspi,
+               unsigned long reg, int wlen)

"readl" means read LONG. That's what the L is for. But this does different widths.

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

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+{
+       switch (wlen) {
+       case 8:
+               return readw(qspi->base + reg);
+               break;

wlen == 8, but readw == 16 bit read?

The break after the return isn't necessary.

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+       case 16:
+               return readb(qspi->base + reg);
+               break;

wlen == 16, but readb == 8 bit read?

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

Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2 -0
+       case 32:
+               return readl(qspi->base + reg);

wlen == 32, readl == 32, this one makes sense, but....

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

Quoted 6 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+static inline void ti_qspi_writel_data(struct ti_qspi *qspi,
+               unsigned long val, unsigned long reg, int wlen)
 
+       case 32:
+               writeb(val, qspi->base + reg);
+               break;

A 32 bit write uses an 8 bit write command, while read is 32 bits??

This doesn't make a lot of sense. If it's actually correct, there should be come kind of comment about it.

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

Quoted 11 lines
drivers/spi/spi-ti-qspi.c new file +10 -0
+
+static int ti_qspi_setup(struct spi_device *spi)
+{
 
+
+       clk_ctrl_reg = ti_qspi_readl(qspi, QSPI_SPI_CLOCK_CNTRL_REG);
+
+       clk_ctrl_reg &= ~QSPI_CLK_EN;
+
+       /* disable SCLK */
+       ti_qspi_writel(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG);

Did you read this from Documentation/spi/spi-summary?
** BUG ALERT: for some reason the first version of ** many spi_master drivers seems to get this wrong. ** When you code setup(), ASSUME that the controller ** is actively processing transfers for another device.

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

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+
+       master->mode_bits = SPI_CPOL | SPI_CPHA;

Does your device support full duplex? It doesn't look like it does. You should set the SPI_MASER_HALF_DUPLEX flag in master->flags.

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+
+       if (!of_property_read_u32(np, "ti,spi-num-cs", &num_cs))
+               master->num_chipselect = num_cs;

You didn't document this property. How is this different than the "num-cs" property already documented in spi-bus bindings?

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+       qspi->base = devm_ioremap_resource(&pdev->dev, r);
+       if (IS_ERR(qspi->base)) {
+               ret = -ENOMEM;

Shouldn't that be ret = PTR_ERR(qspi->base)

------------------------------------------------------------------------------
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

maintainer
#20 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 7 lines · Trent Piepho
Quoted 1 line · Sourav Poddar

+- ti,hwmods: Name of the hwmod associated to the QSPI

What is ti,hwmods? It's not clear from the description. It also doesn't appear to be used in the driver. At least, I did not find any occurrence of "hwmods" in the driver code.

It's a generic thing for all OMAPs which is handled by the core SoC support transparently on TI chips.

#21 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

Quoted 12 lines · Mark Brown
Quoted 7 lines · Trent Piepho
Quoted 1 line · Sourav Poddar

+- ti,hwmods: Name of the hwmod associated to the QSPI

What is ti,hwmods? It's not clear from the description. It also doesn't appear to be used in the driver. At least, I did not find any occurrence of "hwmods" in the driver code.

It's a generic thing for all OMAPs which is handled by the core SoC support transparently on TI chips.

Here are some ancient documentation for the same (pre-device tree) world[1] bindings documentation is available:
Documentation/devicetree/bindings/arm/omap/omap.txt

[1] http://omapedia.org/wiki/HWMOD

Signature · 9 lines
Regards,
Nishanth Menon

------------------------------------------------------------------------------
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
#22 lore raw

Re: [PATCHv4 2/3] drivers: spi: Add qspi flash controller

In reply to Trent Piepho
Quoted 15 lines · Trent Piepho
Quoted 5 lines · Sourav Poddar

+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

What is ti,hwmods? It's not clear from the description. It also doesn't appear to be used in the driver. At least, I did not find any occurrence of "hwmods" in the driver code.

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

Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2 -0
+static inline unsigned long ti_qspi_readl_data(struct ti_qspi *qspi,
+               unsigned long reg, int wlen)

"readl" means read LONG. That's what the L is for. But this does different widths.

Quoted 6 lines

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

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+{
+       switch (wlen) {
+       case 8:
+               return readw(qspi->base + reg);
+               break;

wlen == 8, but readw == 16 bit read?

Yes, I need to change this. should be readb.

Quoted 7 lines

The break after the return isn't necessary.

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+       case 16:
+               return readb(qspi->base + reg);
+               break;

wlen == 16, but readb == 8 bit read?

same here.

Quoted 9 lines

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

Quoted 2 lines
drivers/spi/spi-ti-qspi.c new file +2 -0
+       case 32:
+               return readl(qspi->base + reg);

wlen == 32, readl == 32, this one makes sense, but....

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

Quoted 5 lines
drivers/spi/spi-ti-qspi.c new file +5 -0
+static inline void ti_qspi_writel_data(struct ti_qspi *qspi,
+               unsigned long val, unsigned long reg, int wlen)
+       case 32:
+               writeb(val, qspi->base + reg);
+               break;
Quoted 5 lines

A 32 bit write uses an 8 bit write command, while read is 32 bits??

This doesn't make a lot of sense. If it's actually correct, there should be come kind of comment about it.

Yes, I will change this in the next version.

Quoted 7 lines
Quoted 7 lines
drivers/spi/spi-ti-qspi.c new file +7 -0
+
+static int ti_qspi_setup(struct spi_device *spi)
+{
+
+       clk_ctrl_reg = ti_qspi_readl(qspi, QSPI_SPI_CLOCK_CNTRL_REG);
+
+       clk_ctrl_reg&= ~QSPI_CLK_EN;
Quoted 9 lines

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+
+       /* disable SCLK */
+       ti_qspi_writel(qspi, clk_ctrl_reg, QSPI_SPI_CLOCK_CNTRL_REG);

Did you read this from Documentation/spi/spi-summary?
** BUG ALERT: for some reason the first version of ** many spi_master drivers seems to get this wrong. ** When you code setup(), ASSUME that the controller ** is actively processing transfers for another device.

But I see in this documentation, that setup is usually used for setting up device clock rate, modes etc.
So, what do you recommend here, should we move clk settings to prepare hardware ?

Quoted 7 lines

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

Quoted 4 lines
drivers/spi/spi-ti-qspi.c new file +4 -0
+static int ti_qspi_probe(struct platform_device *pdev)
+{
+
+       master->mode_bits = SPI_CPOL | SPI_CPHA;

Does your device support full duplex? It doesn't look like it does. You should set the SPI_MASER_HALF_DUPLEX flag in master->flags.

hmm. Ok, will add.

Quoted 6 lines

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+
+       if (!of_property_read_u32(np, "ti,spi-num-cs",&num_cs))
+               master->num_chipselect = num_cs;

You didn't document this property. How is this different than the "num-cs" property already documented in spi-bus bindings?

Actually, it is no different. This also means the total number of chipselects. I used it from omap mcspi. I will make this property in accordance with the generic binding.
Will also send a seperate patch for omap mcspi.

Quoted 4 lines

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

Quoted 3 lines
drivers/spi/spi-ti-qspi.c new file +3 -0
+       qspi->base = devm_ioremap_resource(&pdev->dev, r);
+       if (IS_ERR(qspi->base)) {
+               ret = -ENOMEM;

Shouldn't that be ret = PTR_ERR(qspi->base)

hmm.will change.

#23 lore raw

PATCH 3/3 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 as the parent patch goes[1]

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

---
v1->v2
Added support for dual also.

 drivers/spi/spi-ti-qspi.c |   17 +++++++++++++++--
 1 files changed, 15 insertions(+), 2 deletions(-)
drivers/spi/spi-ti-qspi.c +15 -2
index 3cae731..3a5c56d 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)
@@ -280,6 +281,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;
@@ -289,8 +291,19 @@ 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_writel(qspi, qspi->dc, QSPI_SPI_DC_REG);
-		ti_qspi_writel(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_writel(qspi, QSPI_WC_INT_EN, QSPI_INTR_ENABLE_SET_REG);
 		wait_for_completion(&qspi->transfer_complete);
 		*rxbuf++ = ti_qspi_readl_data(qspi, QSPI_SPI_DATA_REG, wlen);
Signature · 9 lines
1.7.1


------------------------------------------------------------------------------
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
maintainer
#24 lore raw

Re: [RFC/PATCHv2 3/3] driver: spi: Add quad spi read support

Quoted 10 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 as the parent patch goes[1]

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

Just as with commit IDs you should include a plain text description of anything you link to so that people reading your e-mail can tell what you're talking about without going on line.

#25 lore raw

Re: [RFC/PATCHv2 3/3] driver: spi: Add quad spi read support

Quoted 6 lines · Mark Brown
Quoted 5 lines · Sourav Poddar

Since, qspi controller uses quad read.

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

Quoted 8 lines
Quoted 5 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 as the parent patch goes[1]

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

Just as with commit IDs you should include a plain text description of anything you link to so that people reading your e-mail can tell what you're talking about without going on line.

Ok, will keep that in mind for future.

Just to give you a brief description here,
Requirement is to have a dual/quad support in spi frameowrk, so that drivers can use multiple lines for data transfers.

What patch[1] tries to does, is
[1]: http://comments.gmane.org/gmane.linux.kernel.spi.devel/14047

is to add to each transfer the bitwidth it supports, so that that bitwidth information
can be parsed in controller driver and can be used for respective read/writes.

A typical usecase on my side is,
I have a spansion flash connected to qspi. Flash device supports quad read with
a certain read opcode(QUAD_READ). So, Whenever the opcode send is QUAD_READ, we will append that information as a bitwidth to the spi transfer. This information will
be parsed by the controller driver and will be used to configure the cmd reg to do
the particular type of reads.

------------------------------------------------------------------------------
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