diff mbox

spi/dw_spi: add a FIFO depth detection

Message ID 20100121105139.3d0fbd42@feng-desktop (mailing list archive)
State Accepted
Headers show

Commit Message

Feng Tang Jan. 21, 2010, 2:51 a.m. UTC
None
diff mbox

Patch

diff --git a/drivers/spi/dw_spi.c b/drivers/spi/dw_spi.c
index 4e2774c..0e76a6e 100644
--- a/drivers/spi/dw_spi.c
+++ b/drivers/spi/dw_spi.c
@@ -990,6 +990,22 @@  static void spi_hw_init(struct dw_spi *dws)
 	spi_mask_intr(dws, 0xff);
 	spi_enable_chip(dws, 1);
 	flush(dws);
+
+	/*
+	 * Try to detect the FIFO depth if not set by interface driver,
+	 * the depth could be from 2 to 256 from HW spec
+	 */
+	if (!dws->fifo_len) {
+		u32 fifo;
+		for (fifo = 2; fifo <= 257; fifo++) {
+			dw_writew(dws, txfltr, fifo);
+			if (fifo != dw_readw(dws, txfltr))
+				break;
+		}
+
+		dws->fifo_len = (fifo == 257) ? 0 : fifo;
+		dw_writew(dws, txfltr, 0);
+	}
 }
 
 int __devinit dw_spi_add_host(struct dw_spi *dws)