Skip to contentSkip to conversation

spi: omap3: Fix timeout handling

PATCH Superseded David Dueck 2 participants 2 messages Apr 1, 2015 SPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: omap3: Fix timeout handling

The timeout value is never reset during the transfer. This means that when transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

CC Tom Rini <[email protected]>
CC Jagannadh Teki <jagannadh@[email protected]>
CC Stefan Roese <[email protected]>
CC Andy Pont <[email protected]>
---
 drivers/spi/omap3_spi.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/spi/omap3_spi.c +12 -8
index 651e46e..c1b4b33 100644
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include "omap3_spi.h"
 
-#define SPI_WAIT_TIMEOUT 3000000
+#define SPI_WAIT_TIMEOUT 10
 
 static void spi_reset(struct omap3_spi_slave *ds)
 {
@@ -227,7 +227,7 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
 	int i;
-	int timeout = SPI_WAIT_TIMEOUT;
+	ulong start;
 	int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 
 	/* Enable the channel */
@@ -241,9 +241,10 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 
 	for (i = 0; i < len; i++) {
 		/* wait till TX register is empty (TXS == 1) */
+		start = get_timer(0);
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 			 OMAP3_MCSPI_CHSTAT_TXS)) {
-			if (--timeout <= 0) {
+			if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
 				printf("SPI TXS timed out, status=0x%08x\n",
 				       readl(&ds->regs->channel[ds->slave.cs].chstat));
 				return -1;
@@ -280,7 +281,7 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
 	int i;
-	int timeout = SPI_WAIT_TIMEOUT;
+	ulong start;
 	int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 
 	/* Enable the channel */
@@ -295,10 +296,11 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 	writel(0, &ds->regs->channel[ds->slave.cs].tx);
 
 	for (i = 0; i < len; i++) {
+		start = get_timer(0);
 		/* Wait till RX register contains data (RXS == 1) */
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 			 OMAP3_MCSPI_CHSTAT_RXS)) {
-			if (--timeout <= 0) {
+			if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
 				printf("SPI RXS timed out, status=0x%08x\n",
 				       readl(&ds->regs->channel[ds->slave.cs].chstat));
 				return -1;
@@ -332,7 +334,7 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
 		   const void *txp, void *rxp, unsigned long flags)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
-	int timeout = SPI_WAIT_TIMEOUT;
+	ulong start;
 	int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 	int irqstatus = readl(&ds->regs->irqstatus);
 	int i=0;
@@ -350,9 +352,10 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
 	for (i=0; i < len; i++){
 		/* Write: wait for TX empty (TXS == 1)*/
 		irqstatus |= (1<< (4*(ds->slave.bus)));
+		start = get_timer(0);
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 			 OMAP3_MCSPI_CHSTAT_TXS)) {
-			if (--timeout <= 0) {
+			if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
 				printf("SPI TXS timed out, status=0x%08x\n",
 				       readl(&ds->regs->channel[ds->slave.cs].chstat));
 				return -1;
@@ -368,9 +371,10 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
 			writel(((u8 *)txp)[i], tx);
 
 		/*Read: wait for RX containing data (RXS == 1)*/
+		start = get_timer(0);
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
 			 OMAP3_MCSPI_CHSTAT_RXS)) {
-			if (--timeout <= 0) {
+			if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
 				printf("SPI RXS timed out, status=0x%08x\n",
 				       readl(&ds->regs->channel[ds->slave.cs].chstat));
 				return -1;
Signature · 1 line
2.3.4
#1 lore raw

PATCH 1/1 spi: omap3: Fix timeout handling

Quoted 59 lines · David Dueck

The timeout value is never reset during the transfer. This means that when transferring more data we eventually trigger the timeout.

This was reported on the mailing list:
"Spansion SPI flash read timeout with AM335x"

CC Tom Rini <[email protected]>
CC Jagannadh Teki <jagannadh@[email protected]>
CC Stefan Roese <[email protected]>
CC Andy Pont <[email protected]>
---
 drivers/spi/omap3_spi.c | 20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)
drivers/spi/omap3_spi.c +5 -4
index 651e46e..c1b4b33 100644
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include "omap3_spi.h"
 
-#define SPI_WAIT_TIMEOUT 3000000
+#define SPI_WAIT_TIMEOUT 10
 
 static void spi_reset(struct omap3_spi_slave *ds)
 {
@@ -227,7 +227,7 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 {
        struct omap3_spi_slave *ds = to_omap3_spi(slave);
        int i;
-       int timeout = SPI_WAIT_TIMEOUT;
+       ulong start;
        int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 
        /* Enable the channel */
@@ -241,9 +241,10 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 
        for (i = 0; i < len; i++) {
                /* wait till TX register is empty (TXS == 1) */
+               start = get_timer(0);
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
                         OMAP3_MCSPI_CHSTAT_TXS)) {
-                       if (--timeout <= 0) {
+                       if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
                                printf("SPI TXS timed out, status=0x%08x\n",
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
                                return -1;
@@ -280,7 +281,7 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 {
        struct omap3_spi_slave *ds = to_omap3_spi(slave);
        int i;
-       int timeout = SPI_WAIT_TIMEOUT;
+       ulong start;
        int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
 
        /* Enable the channel */

drivers/spi/omap3_spi.c int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp, · line 303

Quoted 9 lines
drivers/spi/omap3_spi.c +2 -1
@@ -295,10 +296,11 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
        writel(0, &ds->regs->channel[ds->slave.cs].tx);
 
        for (i = 0; i < len; i++) {
+               start = get_timer(0);
                /* Wait till RX register contains data (RXS == 1) */
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
                         OMAP3_MCSPI_CHSTAT_RXS)) {
-                       if (--timeout <= 0) {
+                       if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {

I think this is redundant, please check ie negation to start what about this

start = get_timer(0);
-----

if (get_timer(start) > SPI_WAIT_TIMEOUT) {

Quoted 37 lines
drivers/spi/omap3_spi.c +5 -4
                                printf("SPI RXS timed out, status=0x%08x\n",
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
                                return -1;
@@ -332,7 +334,7 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
                   const void *txp, void *rxp, unsigned long flags)
 {
        struct omap3_spi_slave *ds = to_omap3_spi(slave);
-       int timeout = SPI_WAIT_TIMEOUT;
+       ulong start;
        int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
        int irqstatus = readl(&ds->regs->irqstatus);
        int i=0;
@@ -350,9 +352,10 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
        for (i=0; i < len; i++){
                /* Write: wait for TX empty (TXS == 1)*/
                irqstatus |= (1<< (4*(ds->slave.bus)));
+               start = get_timer(0);
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
                         OMAP3_MCSPI_CHSTAT_TXS)) {
-                       if (--timeout <= 0) {
+                       if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
                                printf("SPI TXS timed out, status=0x%08x\n",
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
                                return -1;
@@ -368,9 +371,10 @@ int omap3_spi_txrx(struct spi_slave *slave, unsigned int len,
                        writel(((u8 *)txp)[i], tx);
 
                /*Read: wait for RX containing data (RXS == 1)*/
+               start = get_timer(0);
                while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
                         OMAP3_MCSPI_CHSTAT_RXS)) {
-                       if (--timeout <= 0) {
+                       if (get_timer(0) - start > SPI_WAIT_TIMEOUT) {
                                printf("SPI RXS timed out, status=0x%08x\n",
                                       readl(&ds->regs->channel[ds->slave.cs].chstat));
                                return -1;
--
Quoted 1 line

2.3.4

thanks!

Signature · 1 line
Jagan.