Skip to contentSkip to conversation

spi: dw: revisit FIFO size detection again

PATCH Superseded Andy Shevchenko 2 participants 4 messages Feb 24, 2015 – Feb 25, 2015 1 message not in the archive SPI

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: dw: revisit FIFO size detection again

The commit d297933cc7fc (spi: dw: Fix detecting FIFO depth) tries to fix the logic of the FIFO detection based on the description on the comments. However, there is a slight difference between numbers in TX Level and TX FIFO size.

So, by specification the FIFO size would be in a range 2-256 bytes. From TX Level prospective it means we can set threshold in the range 0-(FIFO size - 1) bytes. Hence there are currently two issues:
a) FIFO size 2 bytes is actually skipped since TX Level is 1 bit and could be

     either 0 or 1 byte;

b) FIFO size is incorrectly decreased by 1 which already done by meaning of TX Level register.

This patch fixes it eventually right.

Fixes d297933cc7fc (spi: dw: Fix detecting FIFO depth)
Cc Axel Lin <[email protected]>

---

Shame on me I somehow missed this when tested mentioned patch.

 drivers/spi/spi-dw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +2 -2
index 0257dd1..ba9773d 100644
@@ -494,14 +494,14 @@ static void spi_hw_init(struct device *dev, struct dw_spi *dws)
 	if (!dws->fifo_len) {
 		u32 fifo;
 
-		for (fifo = 2; fifo <= 256; fifo++) {
+		for (fifo = 1; fifo <= 256; fifo++) {
 			dw_writew(dws, DW_SPI_TXFLTR, fifo);
 			if (fifo != dw_readw(dws, DW_SPI_TXFLTR))
 				break;
 		}
 		dw_writew(dws, DW_SPI_TXFLTR, 0);
 
-		dws->fifo_len = (fifo == 2) ? 0 : fifo - 1;
+		dws->fifo_len = (fifo == 1) ? 0 : fifo;
 		dev_dbg(dev, "Detected FIFO size: %u bytes\n", dws->fifo_len);
 	}
 }
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Reviewed-by on v1 1/1
#1 lore raw

2015-02-25 2:43 GMT+08:00 Andy Shevchenko <[email protected]>:

Quoted 12 lines

The commit d297933cc7fc (spi: dw: Fix detecting FIFO depth) tries to fix the logic of the FIFO detection based on the description on the comments. However, there is a slight difference between numbers in TX Level and TX FIFO size.

So, by specification the FIFO size would be in a range 2-256 bytes. From TX Level prospective it means we can set threshold in the range 0-(FIFO size - 1) bytes. Hence there are currently two issues:
a) FIFO size 2 bytes is actually skipped since TX Level is 1 bit and could be

     either 0 or 1 byte;

b) FIFO size is incorrectly decreased by 1 which already done by meaning of TX Level register.

Quoted 6 lines

This patch fixes it eventually right.

Fixes d297933cc7fc (spi: dw: Fix detecting FIFO depth)
Cc Axel Lin <[email protected]>
#2 lore raw
In reply to Andy Shevchenko

2015-02-25 2:43 GMT+08:00 Andy Shevchenko <[email protected]>:

Quoted 30 lines

The commit d297933cc7fc (spi: dw: Fix detecting FIFO depth) tries to fix the logic of the FIFO detection based on the description on the comments. However, there is a slight difference between numbers in TX Level and TX FIFO size.

So, by specification the FIFO size would be in a range 2-256 bytes. From TX Level prospective it means we can set threshold in the range 0-(FIFO size - 1) bytes. Hence there are currently two issues:
a) FIFO size 2 bytes is actually skipped since TX Level is 1 bit and could be

     either 0 or 1 byte;

b) FIFO size is incorrectly decreased by 1 which already done by meaning of TX Level register.

This patch fixes it eventually right.

Fixes d297933cc7fc (spi: dw: Fix detecting FIFO depth)
Cc Axel Lin <[email protected]>

---

Shame on me I somehow missed this when tested mentioned patch.

 drivers/spi/spi-dw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +0 -0
index 0257dd1..ba9773d 100644

drivers/spi/spi-dw.c static void spi_hw_init(struct device *dev, struct dw_spi *dws) · line 497

Quoted 5 lines
drivers/spi/spi-dw.c +1 -1
@@ -494,14 +494,14 @@ static void spi_hw_init(struct device *dev, struct dw_spi *dws)
        if (!dws->fifo_len) {
                u32 fifo;
 
-               for (fifo = 2; fifo <= 256; fifo++) {
+               for (fifo = 1; fifo <= 256; fifo++) {

I think the upper bound of the for loop should be 255 (FIFO size - 1) for (fifo = 1; fifo <= 255; fifo++) {
so if writting 255 to DW_SPI_TXFLTR success, fifo_len is 256.

no need to test writing 256 to DW_SPI_TXFLTR.

A message that is not in the archive (sent off-list or not yet received): CAFRkauBykVRaS9nEKTw-opYoe6z50eA=qwg74nBB1y9tzMm4gg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

#4 lore raw
Quoted 34 lines · Axel Lin

2015-02-25 2:43 GMT+08:00 Andy Shevchenko <andriy.shevchenko-VuQAYsv1563Yd54FQh9/[email protected]>:

Quoted 33 lines

The commit d297933cc7fc (spi: dw: Fix detecting FIFO depth) tries to fix the logic of the FIFO detection based on the description on the comments. However, there is a slight difference between numbers in TX Level and TX FIFO size.

So, by specification the FIFO size would be in a range 2-256 bytes. From TX Level prospective it means we can set threshold in the range 0-(FIFO size - 1) bytes. Hence there are currently two issues:
a) FIFO size 2 bytes is actually skipped since TX Level is 1 bit and could be

     either 0 or 1 byte;

b) FIFO size is incorrectly decreased by 1 which already done by meaning of TX Level register.

This patch fixes it eventually right.

Fixes d297933cc7fc (spi: dw: Fix detecting FIFO depth)
Cc Axel Lin <[email protected]>

---

Shame on me I somehow missed this when tested mentioned patch.

 drivers/spi/spi-dw.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/spi/spi-dw.c +0 -0
index 0257dd1..ba9773d 100644
@@ -494,14 +494,14 @@ static void spi_hw_init(struct device *dev, struct dw_spi *dws)
        if (!dws->fifo_len) {
                u32 fifo;
 
Quoted 8 lines

drivers/spi/spi-dw.c static void spi_hw_init(struct device *dev, struct dw_spi *dws) · line 497

Quoted 2 lines
drivers/spi/spi-dw.c +1 -1
-               for (fifo = 2; fifo <= 256; fifo++) {
+               for (fifo = 1; fifo <= 256; fifo++) {

I think the upper bound of the for loop should be 255 (FIFO size - 1) for (fifo = 1; fifo <= 255; fifo++) {
so if writting 255 to DW_SPI_TXFLTR success, fifo_len is 256.

no need to test writing 256 to DW_SPI_TXFLTR.

Yes, I even just retested carefully.
I will change to < 256 and keep your Reviewed-by tag in v2, hope it's okay.

Signature · 7 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html