Skip to contentSkip to conversation

Add support for SPI based DataImage LCD panel

PATCH Superseded Nikita Kiryanov 4 participants 11 messages Oct 9, 2013 – Oct 15, 2013

Subsystems (3)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add support for SPI based DataImage LCD panel

This patch ports the Linux driver for DataImage SCF0403852GGU04 and SCF0403526GGU20 LCD panels into U-Boot. As a preparation step, variable SPI word length support is added to omap3_spi and the generic SPI interface. Finally, the driver is used in cm_t35 board.

The SPI changes were tested with a Beagle I2C/SPI/MDIO Protocol Analyzer, and also with a DataImage SCF0403 lcd as part of the DataImage driver test.

Patch number 3 depends on http://patchwork.ozlabs.org/patch/275283/

Cc Tom Rini <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Igor Grinberg <[email protected]>
Cc Jagannadha Sutradharudu Teki <[email protected]>

Nikita Kiryanov (3):
spi: omap3: add support for more word lengths
lcd: add DataImage SCF0403x LCD panel support
cm_t35: use scf0403 driver

 arch/arm/include/asm/arch-omap3/dss.h |   9 +-
 board/compulab/cm_t35/cm_t35.c        |  12 ++
 board/compulab/common/omap3_display.c |  46 +++++-
 drivers/spi/omap3_spi.c               |  78 +++++++--
 drivers/spi/omap3_spi.h               |  11 +-
 drivers/video/Makefile                |   1 +
 drivers/video/scf0403_lcd.c           | 298 ++++++++++++++++++++++++++++++++++
 include/configs/cm_t35.h              |   3 +
 include/scf0403_lcd.h                 |  22 +++
 include/spi.h                         |  14 ++
 10 files changed, 467 insertions(+), 27 deletions(-)
 create mode 100644 drivers/video/scf0403_lcd.c
 create mode 100644 include/scf0403_lcd.h
Signature · 1 line
1.8.1.2
#1 lore raw

PATCH 1/3 spi: omap3: add support for more word lengths

Current implementation only supports 8 bit word lengths, even though omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length, and implement it in omap3_spi driver to support the full range of possible word lengths.
This implementation is backwards compatible by defaulting to the old behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions, but since they are not used anywhere else, no collateral changes are required.

Cc Tom Rini <[email protected]>
Cc Igor Grinberg <[email protected]>
Cc Jagannadha Sutradharudu Teki <[email protected]>
---
 drivers/spi/omap3_spi.c | 78 ++++++++++++++++++++++++++++++++++++++-----------
 drivers/spi/omap3_spi.h | 11 ++++---
 include/spi.h           | 13 +++++++++
 3 files changed, 81 insertions(+), 21 deletions(-)
drivers/spi/omap3_spi.c +61 -17
index 6bac245..add98e1 100644
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include "omap3_spi.h"
 
-#define WORD_LEN	8
+#define SPI_DEFAULT_WORDLEN 8;
 #define SPI_WAIT_TIMEOUT 3000000;
 
 static void spi_reset(struct omap3_spi_slave *ds)
@@ -128,10 +128,32 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	ds->regs = regs;
 	ds->freq = max_hz;
 	ds->mode = mode;
+	ds->wordlen = SPI_DEFAULT_WORDLEN;
 
 	return &ds->slave;
 }
 
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
+{
+	struct omap3_spi_slave *ds;
+	int chconf;
+
+	if (wordlen < 4 || wordlen > 32) {
+		printf("SPI error: unsupported wordlen %d\n", wordlen);
+		return -1;
+	}
+
+	ds = to_omap3_spi(slave);
+	ds->wordlen = wordlen;
+
+	chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
+	chconf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
+	chconf |= (wordlen - 1) << 7;
+	omap3_spi_write_chconf(ds, chconf);
+
+	return 0;
+}
+
 void spi_free_slave(struct spi_slave *slave)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -185,7 +207,7 @@ int spi_claim_bus(struct spi_slave *slave)
 
 	/* wordlength */
 	conf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
-	conf |= (WORD_LEN - 1) << 7;
+	conf |= (ds->wordlen - 1) << 7;
 
 	/* set chipselect polarity; manage with FORCE */
 	if (!(ds->mode & SPI_CS_HIGH))
@@ -223,7 +245,7 @@ void spi_release_bus(struct spi_slave *slave)
 	spi_reset(ds);
 }
 
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
+int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 		    unsigned long flags)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -250,7 +272,13 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
 			}
 		}
 		/* Write the data */
-		writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
+		unsigned int *tx = &ds->regs->channel[ds->slave.cs].tx;
+		if (ds->wordlen > 16)
+			writel(((u32 *)txp)[i], tx);
+		else if (ds->wordlen > 8)
+			writel(((u16 *)txp)[i], tx);
+		else
+			writel(((u8 *)txp)[i], tx);
 	}
 
         /* wait to finish of transfer */
@@ -268,7 +296,7 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
 	return 0;
 }
 
-int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
+int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 		   unsigned long flags)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -302,7 +330,13 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
 			omap3_spi_set_enable(ds,OMAP3_MCSPI_CHCTRL_DIS);
 
 		/* Read the data */
-		rxp[i] = readl(&ds->regs->channel[ds->slave.cs].rx);
+		unsigned int *rx = &ds->regs->channel[ds->slave.cs].rx;
+		if (ds->wordlen > 16)
+			((u32 *)rxp)[i] = readl(rx);
+		else if (ds->wordlen > 8)
+			((u16 *)rxp)[i] = (u16)readl(rx);
+		else
+			((u8 *)rxp)[i] = (u8)readl(rx);
 	}
 
 	if (flags & SPI_XFER_END) {
@@ -314,8 +348,8 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
 }
 
 /*McSPI Transmit Receive Mode*/
-int omap3_spi_txrx(struct spi_slave *slave,
-		unsigned int len, const u8 *txp, u8 *rxp, unsigned long flags)
+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;
@@ -344,7 +378,13 @@ int omap3_spi_txrx(struct spi_slave *slave,
 			}
 		}
 		/* Write the data */
-		writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
+		unsigned int *tx = &ds->regs->channel[ds->slave.cs].tx;
+		if (ds->wordlen > 16)
+			writel(((u32 *)txp)[i], tx);
+		else if (ds->wordlen > 8)
+			writel(((u16 *)txp)[i], tx);
+		else
+			writel(((u8 *)txp)[i], tx);
 
 		/*Read: wait for RX containing data (RXS == 1)*/
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
@@ -356,7 +396,13 @@ int omap3_spi_txrx(struct spi_slave *slave,
 			}
 		}
 		/* Read the data */
-		rxp[i] = readl(&ds->regs->channel[ds->slave.cs].rx);
+		unsigned int *rx = &ds->regs->channel[ds->slave.cs].rx;
+		if (ds->wordlen > 16)
+			((u32 *)rxp)[i] = readl(rx);
+		else if (ds->wordlen > 8)
+			((u16 *)rxp)[i] = (u16)readl(rx);
+		else
+			((u8 *)rxp)[i] = (u8)readl(rx);
 	}
 	/* Disable the channel */
         omap3_spi_set_enable(ds,OMAP3_MCSPI_CHCTRL_DIS);
@@ -375,14 +421,12 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
 	unsigned int	len;
-	const u8	*txp = dout;
-	u8		*rxp = din;
 	int ret = -1;
 
-	if (bitlen % 8)
+	if (bitlen % ds->wordlen)
 		return -1;
 
-	len = bitlen / 8;
+	len = bitlen / ds->wordlen;
 
 	if (bitlen == 0) {	 /* only change CS */
 		int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
@@ -400,11 +444,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 		ret = 0;
 	} else {
 		if (dout != NULL && din != NULL)
-			ret = omap3_spi_txrx(slave, len, txp, rxp, flags);
+			ret = omap3_spi_txrx(slave, len, dout, din, flags);
 		else if (dout != NULL)
-			ret = omap3_spi_write(slave, len, txp, flags);
+			ret = omap3_spi_write(slave, len, dout, flags);
 		else if (din != NULL)
-			ret = omap3_spi_read(slave, len, rxp, flags);
+			ret = omap3_spi_read(slave, len, din, flags);
 	}
 	return ret;
 }
drivers/spi/omap3_spi.h +7 -4
index 01537b6..aeddb53 100644
@@ -92,6 +92,7 @@ struct omap3_spi_slave {
 	struct mcspi *regs;
 	unsigned int freq;
 	unsigned int mode;
+	unsigned int wordlen;
 };
 
 static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
@@ -99,11 +100,13 @@ static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
 	return container_of(slave, struct omap3_spi_slave, slave);
 }
 
-int omap3_spi_txrx(struct spi_slave *slave, unsigned int len, const u8 *txp,
-			u8 *rxp, unsigned long flags);
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
+int omap3_spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
+
+int omap3_spi_txrx(struct spi_slave *slave, unsigned int len, const void *txp,
+			void *rxp, unsigned long flags);
+int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 		    unsigned long flags);
-int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
+int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 		   unsigned long flags);
 
 #endif /* _OMAP3_SPI_H_ */
include/spi.h +13 -0
index c0dab57..ae318ff 100644
@@ -149,6 +149,19 @@ int spi_claim_bus(struct spi_slave *slave);
 void spi_release_bus(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set the word length for SPI transactions
+ *
+ * Set the word length (number of bits per word) for SPI transactions.
+ * This setting is persistent until changed.
+ *
+ *   slave:	The SPI slave
+ *   wordlen:	The number of bits in a word
+ *
+ *   Returns: 0 on success, -1 on failure.
+ */
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
+
+/*-----------------------------------------------------------------------
  * SPI transfer
  *
  * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
Signature · 1 line
1.8.1.2
#2 lore raw

PATCH 1/3 spi: omap3: add support for more word lengths

drivers/spi/omap3_spi.c line 26

Quoted 12 lines · Nikita Kiryanov
drivers/spi/omap3_spi.c +1 -1
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include "omap3_spi.h"
 
-#define WORD_LEN	8
+#define SPI_DEFAULT_WORDLEN 8;
 #define SPI_WAIT_TIMEOUT 3000000;
 
 static void spi_reset(struct omap3_spi_slave *ds)

This is strictly speaking unrelated to your change, but might be worth getting fixed in a separate submission. I haven't read your patch in the meaning of a review, just happened to spot this nit before skipping to the next message ...

The semicolon in a #define for a constant is certainly wrong. This applies to both your new line as well as the context which already was in place. The code may appear to work, but for sanity and to avoid future problems the defines should get fixed. You might add the separate cleanup patch in front of the new feature should feedback make you send another version of your series, or send a fix individually (and check for other occurances for bonus points).

virtually yours
Gerhard Sittig

Signature · 3 lines
DENX Software Engineering GmbH,     MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr. 5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-0 Fax: +49-8142-66989-80  Email: office at denx.de
#3 lore raw

PATCH 1/3 spi: omap3: add support for more word lengths

In reply to Nikita Kiryanov

Hi Nikita,

Quoted 26 lines · Nikita Kiryanov

Current implementation only supports 8 bit word lengths, even though omap3 can handle anything between 4 and 32.

Update the spi interface to support changing the SPI word length, and implement it in omap3_spi driver to support the full range of possible word lengths.
This implementation is backwards compatible by defaulting to the old behavior of 8 bit word lengths.
Also, it required a change to the omap3_spi non static I/O functions, but since they are not used anywhere else, no collateral changes are required.

Cc Tom Rini <[email protected]>
Cc Igor Grinberg <[email protected]>
Cc Jagannadha Sutradharudu Teki <[email protected]>
---
 drivers/spi/omap3_spi.c | 78 ++++++++++++++++++++++++++++++++++++++-----------
 drivers/spi/omap3_spi.h | 11 ++++---
 include/spi.h           | 13 +++++++++
 3 files changed, 81 insertions(+), 21 deletions(-)
drivers/spi/omap3_spi.c +0 -0
index 6bac245..add98e1 100644

drivers/spi/omap3_spi.c line 23

Quoted 5 lines
drivers/spi/omap3_spi.c +1 -1
@@ -20,7 +20,7 @@
 #include <asm/io.h>
 #include "omap3_spi.h"
 
-#define WORD_LEN	8
+#define SPI_DEFAULT_WORDLEN 8;

As already pointed out, the semicolon should not be there...

drivers/spi/omap3_spi.c line 24

Quoted 1 line
drivers/spi/omap3_spi.c +0 -0
 #define SPI_WAIT_TIMEOUT 3000000;

While at this, can you please, send a separate patch to fix the above semicolon?

drivers/spi/omap3_spi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 131

Quoted 7 lines
drivers/spi/omap3_spi.c +1 -0
 static void spi_reset(struct omap3_spi_slave *ds)
@@ -128,10 +128,32 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
 	ds->regs = regs;
 	ds->freq = max_hz;
 	ds->mode = mode;
+	ds->wordlen = SPI_DEFAULT_WORDLEN;

While we know, OMAP SPI controller supports this, I think many other controllers can also support this feature and thus their drivers can benefit from this option.

Wouldn't it be better to add the wordlen field to the generic slave structure instead of the OMAP specific structure?

Quoted 11 lines
drivers/spi/omap3_spi.c +7 -0
 	return &ds->slave;
 }
 
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
+{
+	struct omap3_spi_slave *ds;
+	int chconf;
+
+	if (wordlen < 4 || wordlen > 32) {
+		printf("SPI error: unsupported wordlen %d\n", wordlen);

drivers/spi/omap3_spi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 152

Quoted 10 lines
drivers/spi/omap3_spi.c +10 -0
+		return -1;
+	}
+
+	ds = to_omap3_spi(slave);
+	ds->wordlen = wordlen;
+
+	chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
+	chconf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
+	chconf |= (wordlen - 1) << 7;
+	omap3_spi_write_chconf(ds, chconf);

I would recommend to update the controller just before the transaction takes place, e.g. in spi_xfer() function, so the spi_set_wordlen() function will only update the slave structure and will not touch the hardware. Thus spi_set_wordlen() can be placed in the generic SPI code.

Quoted 27 lines
drivers/spi/omap3_spi.c +6 -2
+
+	return 0;
+}
+
 void spi_free_slave(struct spi_slave *slave)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -185,7 +207,7 @@ int spi_claim_bus(struct spi_slave *slave)
 
 	/* wordlength */
 	conf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
-	conf |= (WORD_LEN - 1) << 7;
+	conf |= (ds->wordlen - 1) << 7;
 
 	/* set chipselect polarity; manage with FORCE */
 	if (!(ds->mode & SPI_CS_HIGH))
@@ -223,7 +245,7 @@ void spi_release_bus(struct spi_slave *slave)
 	spi_reset(ds);
 }
 
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
+int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 		    unsigned long flags)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -250,7 +272,13 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
 			}

drivers/spi/omap3_spi.c int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp, · line 281

Quoted 10 lines
drivers/spi/omap3_spi.c +7 -1
 		}
 		/* Write the data */
-		writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
+		unsigned int *tx = &ds->regs->channel[ds->slave.cs].tx;
+		if (ds->wordlen > 16)
+			writel(((u32 *)txp)[i], tx);
+		else if (ds->wordlen > 8)
+			writel(((u16 *)txp)[i], tx);
+		else
+			writel(((u8 *)txp)[i], tx);

Can we always have u32 for the txp and use masks ans shifts instead of the ugly castings?

Quoted 14 lines
drivers/spi/omap3_spi.c +1 -1
 	}
 
         /* wait to finish of transfer */
@@ -268,7 +296,7 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
 	return 0;
 }
 
-int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
+int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 		   unsigned long flags)
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -302,7 +330,13 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
 			omap3_spi_set_enable(ds,OMAP3_MCSPI_CHCTRL_DIS);

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

Quoted 10 lines
drivers/spi/omap3_spi.c +7 -1
 
 		/* Read the data */
-		rxp[i] = readl(&ds->regs->channel[ds->slave.cs].rx);
+		unsigned int *rx = &ds->regs->channel[ds->slave.cs].rx;
+		if (ds->wordlen > 16)
+			((u32 *)rxp)[i] = readl(rx);
+		else if (ds->wordlen > 8)
+			((u16 *)rxp)[i] = (u16)readl(rx);
+		else
+			((u8 *)rxp)[i] = (u8)readl(rx);

same here...

Quoted 16 lines
drivers/spi/omap3_spi.c +2 -2
 	}
 
 	if (flags & SPI_XFER_END) {
@@ -314,8 +348,8 @@ int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
 }
 
 /*McSPI Transmit Receive Mode*/
-int omap3_spi_txrx(struct spi_slave *slave,
-		unsigned int len, const u8 *txp, u8 *rxp, unsigned long flags)
+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;
@@ -344,7 +378,13 @@ int omap3_spi_txrx(struct spi_slave *slave,
 			}

drivers/spi/omap3_spi.c int omap3_spi_txrx(struct spi_slave *slave, · line 387

Quoted 10 lines
drivers/spi/omap3_spi.c +7 -1
 		}
 		/* Write the data */
-		writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
+		unsigned int *tx = &ds->regs->channel[ds->slave.cs].tx;
+		if (ds->wordlen > 16)
+			writel(((u32 *)txp)[i], tx);
+		else if (ds->wordlen > 8)
+			writel(((u16 *)txp)[i], tx);
+		else
+			writel(((u8 *)txp)[i], tx);

and here...

Quoted 5 lines
drivers/spi/omap3_spi.c +0 -0
 		/*Read: wait for RX containing data (RXS == 1)*/
 		while (!(readl(&ds->regs->channel[ds->slave.cs].chstat) &
@@ -356,7 +396,13 @@ int omap3_spi_txrx(struct spi_slave *slave,
 			}

drivers/spi/omap3_spi.c int omap3_spi_txrx(struct spi_slave *slave, · line 405

Quoted 10 lines
drivers/spi/omap3_spi.c +7 -1
 		}
 		/* Read the data */
-		rxp[i] = readl(&ds->regs->channel[ds->slave.cs].rx);
+		unsigned int *rx = &ds->regs->channel[ds->slave.cs].rx;
+		if (ds->wordlen > 16)
+			((u32 *)rxp)[i] = readl(rx);
+		else if (ds->wordlen > 8)
+			((u16 *)rxp)[i] = (u16)readl(rx);
+		else
+			((u8 *)rxp)[i] = (u8)readl(rx);

and here...

Quoted 40 lines
drivers/spi/omap3_spi.c +5 -7
 	}
 	/* Disable the channel */
         omap3_spi_set_enable(ds,OMAP3_MCSPI_CHCTRL_DIS);
@@ -375,14 +421,12 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 {
 	struct omap3_spi_slave *ds = to_omap3_spi(slave);
 	unsigned int	len;
-	const u8	*txp = dout;
-	u8		*rxp = din;
 	int ret = -1;
 
-	if (bitlen % 8)
+	if (bitlen % ds->wordlen)
 		return -1;
 
-	len = bitlen / 8;
+	len = bitlen / ds->wordlen;
 
 	if (bitlen == 0) {	 /* only change CS */
 		int chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
@@ -400,11 +444,11 @@ int spi_xfer(struct spi_slave *slave, unsigned int bitlen,
 		ret = 0;
 	} else {
 		if (dout != NULL && din != NULL)
-			ret = omap3_spi_txrx(slave, len, txp, rxp, flags);
+			ret = omap3_spi_txrx(slave, len, dout, din, flags);
 		else if (dout != NULL)
-			ret = omap3_spi_write(slave, len, txp, flags);
+			ret = omap3_spi_write(slave, len, dout, flags);
 		else if (din != NULL)
-			ret = omap3_spi_read(slave, len, rxp, flags);
+			ret = omap3_spi_read(slave, len, din, flags);
 	}
 	return ret;
 }
drivers/spi/omap3_spi.h +0 -0
index 01537b6..aeddb53 100644

drivers/spi/omap3_spi.h struct omap3_spi_slave { · line 95

Quoted 4 lines
drivers/spi/omap3_spi.h +1 -0
@@ -92,6 +92,7 @@ struct omap3_spi_slave {
 	struct mcspi *regs;
 	unsigned int freq;
 	unsigned int mode;
+	unsigned int wordlen;

See above.

Quoted 9 lines
drivers/spi/omap3_spi.h +0 -2
 };
 
 static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
@@ -99,11 +100,13 @@ static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave)
 	return container_of(slave, struct omap3_spi_slave, slave);
 }
 
-int omap3_spi_txrx(struct spi_slave *slave, unsigned int len, const u8 *txp,
-			u8 *rxp, unsigned long flags);

drivers/spi/omap3_spi.h static inline struct omap3_spi_slave *to_omap3_spi(struct spi_slave *slave) · line 110

Quoted 10 lines
drivers/spi/omap3_spi.h +6 -2
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
+int omap3_spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
+
+int omap3_spi_txrx(struct spi_slave *slave, unsigned int len, const void *txp,
+			void *rxp, unsigned long flags);
+int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
 		    unsigned long flags);
-int omap3_spi_read(struct spi_slave *slave, unsigned int len, u8 *rxp,
+int omap3_spi_read(struct spi_slave *slave, unsigned int len, void *rxp,
 		   unsigned long flags);

u32 *?

Quoted 2 lines
drivers/spi/omap3_spi.h +0 -0
 #endif /* _OMAP3_SPI_H_ */

[...]

Quoted 25 lines
include/spi.h +13 -0
index c0dab57..ae318ff 100644
@@ -149,6 +149,19 @@ int spi_claim_bus(struct spi_slave *slave);
 void spi_release_bus(struct spi_slave *slave);
 
 /*-----------------------------------------------------------------------
+ * Set the word length for SPI transactions
+ *
+ * Set the word length (number of bits per word) for SPI transactions.
+ * This setting is persistent until changed.
+ *
+ *   slave:	The SPI slave
+ *   wordlen:	The number of bits in a word
+ *
+ *   Returns: 0 on success, -1 on failure.
+ */
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen);
+
+/*-----------------------------------------------------------------------
  * SPI transfer
  *
  * This writes "bitlen" bits out the SPI MOSI port and simultaneously clocks
Signature · 2 lines
Regards,
Igor.
#4 lore raw

PATCH 1/3 spi: omap3: add support for more word lengths

Quoted 8 lines · Igor Grinberg
Quoted 8 lines
drivers/spi/omap3_spi.c +0 -0
index 6bac245..add98e1 100644
@@ -20,7 +20,7 @@
  #include <asm/io.h>
  #include "omap3_spi.h"
 
Quoted 4 lines

drivers/spi/omap3_spi.c line 23

Quoted 2 lines
drivers/spi/omap3_spi.c +1 -1
-#define WORD_LEN	8
+#define SPI_DEFAULT_WORDLEN 8;

As already pointed out, the semicolon should not be there...

Will fix

Quoted 5 lines

drivers/spi/omap3_spi.c line 24

Quoted 2 lines
drivers/spi/omap3_spi.c +0 -0
  #define SPI_WAIT_TIMEOUT 3000000;

While at this, can you please, send a separate patch to fix the above semicolon?

Will do

Quoted 13 lines

drivers/spi/omap3_spi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 131

Quoted 8 lines
drivers/spi/omap3_spi.c +1 -0
  static void spi_reset(struct omap3_spi_slave *ds)
@@ -128,10 +128,32 @@ struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs,
  	ds->regs = regs;
  	ds->freq = max_hz;
  	ds->mode = mode;
+	ds->wordlen = SPI_DEFAULT_WORDLEN;

While we know, OMAP SPI controller supports this, I think many other controllers can also support this feature and thus their drivers can benefit from this option.

Quoted 2 lines

Wouldn't it be better to add the wordlen field to the generic slave structure instead of the OMAP specific structure?

Makes sense. Will move wordlen to struct spi_slave.

Quoted 19 lines
Quoted 19 lines
drivers/spi/omap3_spi.c +14 -0
  	return &ds->slave;
  }
 
+int spi_set_wordlen(struct spi_slave *slave, unsigned int wordlen)
+{
+	struct omap3_spi_slave *ds;
+	int chconf;
+
+	if (wordlen < 4 || wordlen > 32) {
+		printf("SPI error: unsupported wordlen %d\n", wordlen);
+		return -1;
+	}
+
+	ds = to_omap3_spi(slave);
+	ds->wordlen = wordlen;
+
+	chconf = readl(&ds->regs->channel[ds->slave.cs].chconf);
Quoted 8 lines

drivers/spi/omap3_spi.c struct spi_slave *spi_setup_slave(unsigned int bus, unsigned int cs, · line 152

Quoted 3 lines
drivers/spi/omap3_spi.c +3 -0
+	chconf &= ~OMAP3_MCSPI_CHCONF_WL_MASK;
+	chconf |= (wordlen - 1) << 7;
+	omap3_spi_write_chconf(ds, chconf);

I would recommend to update the controller just before the transaction takes place, e.g. in spi_xfer() function, so the spi_set_wordlen() function will only update the slave structure and will not touch the hardware. Thus spi_set_wordlen() can be placed in the generic SPI code.

Yes that is better. Will do.

Quoted 13 lines
Quoted 13 lines
drivers/spi/omap3_spi.c +3 -2
-int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
+int omap3_spi_write(struct spi_slave *slave, unsigned int len, const void *txp,
  		    unsigned long flags)
  {
  	struct omap3_spi_slave *ds = to_omap3_spi(slave);
@@ -250,7 +272,13 @@ int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp,
  			}
  		}
  		/* Write the data */
-		writel(txp[i], &ds->regs->channel[ds->slave.cs].tx);
+		unsigned int *tx = &ds->regs->channel[ds->slave.cs].tx;
+		if (ds->wordlen > 16)
Quoted 8 lines

drivers/spi/omap3_spi.c int omap3_spi_write(struct spi_slave *slave, unsigned int len, const u8 *txp, · line 281

Quoted 5 lines
drivers/spi/omap3_spi.c +5 -0
+			writel(((u32 *)txp)[i], tx);
+		else if (ds->wordlen > 8)
+			writel(((u16 *)txp)[i], tx);
+		else
+			writel(((u8 *)txp)[i], tx);

Can we always have u32 for the txp and use masks ans shifts instead of the ugly castings?

Working with masks and shifts will basically do the same thing that the casts do, but in a more complicated way. The best way to get rid of the casts will be to store SPI words in u32 arrays to begin with, regardless of the size of SPI word. Unfortunately, this is actually a difficult change:

If we change omap3_spi implementation to work with u32 arrays we also have to change cmd_spi.c, which stores data in byte arrays, and then we will be forced to change all the other U-Boot SPI implementations.

Due to the scope of this change I think it should be done in another patch series.

Signature · 2 lines
Regards,
Nikita.
#5 lore raw

PATCH 2/3 lcd: add DataImage SCF0403x LCD panel support

In reply to Nikita Kiryanov

Add SPI-based driver for DataImage SCF0403852GGU04 and SCF0403526GGU20 LCD panels.

Cc Tom Rini <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Igor Grinberg <[email protected]>
---
 drivers/video/Makefile      |   1 +
 drivers/video/scf0403_lcd.c | 298 ++++++++++++++++++++++++++++++++++++++++++++
 include/scf0403_lcd.h       |  22 ++++
 include/spi.h               |   1 +
 4 files changed, 322 insertions(+)
 create mode 100644 drivers/video/scf0403_lcd.c
 create mode 100644 include/scf0403_lcd.h
drivers/video/Makefile +1 -0
index 6c208c5..e7324d1 100644
@@ -22,6 +22,7 @@ COBJS-$(CONFIG_FSL_DIU_FB) += fsl_diu_fb.o videomodes.o
 COBJS-$(CONFIG_L5F31188) += l5f31188.o
 COBJS-$(CONFIG_MPC8XX_LCD) += mpc8xx_lcd.o
 COBJS-$(CONFIG_PXA_LCD) += pxa_lcd.o
+COBJS-$(CONFIG_SCF0403_LCD) += scf0403_lcd.o
 COBJS-$(CONFIG_S6E8AX0) += s6e8ax0.o
 COBJS-$(CONFIG_S6E63D6) += s6e63d6.o
 COBJS-$(CONFIG_LD9040) += ld9040.o
drivers/video/scf0403_lcd.c new file +298 -0

298 lines not on this page · raw message

include/scf0403_lcd.h new file +22 -0
new file mode 100644
index 0000000..1185d29
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2013, Compulab Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.
+ */
+#ifndef SCF0403_LCD_H_
+#define SCF0403_LCD_H_
+
+int scf0403_init(int reset_gpio);
+
+#endif
include/spi.h +1 -0
index ae318ff..4441527 100644
@@ -27,6 +27,7 @@
 /* SPI transfer flags */
 #define SPI_XFER_BEGIN	0x01			/* Assert CS before transfer */
 #define SPI_XFER_END	0x02			/* Deassert CS after transfer */
+#define SPI_XFER_ONCE	(SPI_XFER_BEGIN | SPI_XFER_END)
 
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
Signature · 1 line
1.8.1.2
#6 lore raw

PATCH 2/3 lcd: add DataImage SCF0403x LCD panel support

On Wed, 9 Oct 2013 17:46:04 +0300
Nikita Kiryanov <[email protected]> wrote:
...

Quoted 12 lines
drivers/video/scf0403_lcd.c new file +6 -0
new file mode 100644
index 0000000..1d1c3ff
@@ -0,0 +1,298 @@
+/*
+ * scf0403.c -- support for DataImage SCF0403 LCD
+ *
+ * Copyright (c) 2013 Adapted from Linux driver:
+ * Copyright (c) 2012 Anders Electronics plc. All Rights Reserved.
+ * Copyright (c) 2012 CompuLab, Ltd

drivers/video/scf0403_lcd.c line 16

Quoted 10 lines
drivers/video/scf0403_lcd.c new file +10 -0
+ *           Dmitry Lifshitz <[email protected]>
+ *           Ilya Ledvich <[email protected]>
+ * Inspired by Alberto Panizzo <[email protected]> &
+ *	Marek Vasut work in l4f00242t03.c
+ *
+ * U-Boot port: Nikita Kiryanov <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.

please use "SPDX-License-Identifier: GPL-2.0" here.
See Licenses/README for more info.

...

drivers/video/scf0403_lcd.c line 225

Quoted 3 lines
drivers/video/scf0403_lcd.c new file +3 -0
+	for (i = 0; i < priv->seq_size; i++) {
+		if (scf0403_spi_transfer(priv->spi, &priv->init_seq[i].cmd) < 0)
+			printf("SPI transfer failed\n");

using puts() for not formatted strings is preferred, please check in other places, too.

Quoted 2 lines
drivers/video/scf0403_lcd.c new file +1 -0
+++ b/include/scf0403_lcd.h
@@ -0,0 +1,22 @@

...

Quoted 3 lines

+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc.

also please use SPDX license identifier here, too.

Thanks,

Anatolij

#7 lore raw

PATCH 2/3 lcd: add DataImage SCF0403x LCD panel support

In reply to Nikita Kiryanov

Hi Nikita,

Quoted 15 lines · Nikita Kiryanov

Add SPI-based driver for DataImage SCF0403852GGU04 and SCF0403526GGU20 LCD panels.

Cc Tom Rini <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Igor Grinberg <[email protected]>
---
 drivers/video/Makefile      |   1 +
 drivers/video/scf0403_lcd.c | 298 ++++++++++++++++++++++++++++++++++++++++++++
 include/scf0403_lcd.h       |  22 ++++
 include/spi.h               |   1 +
 4 files changed, 322 insertions(+)
 create mode 100644 drivers/video/scf0403_lcd.c
 create mode 100644 include/scf0403_lcd.h

[...]

Quoted 6 lines
drivers/video/scf0403_lcd.c new file +0 -0
new file mode 100644
index 0000000..1d1c3ff
@@ -0,0 +1,298 @@

[...]

Quoted 12 lines
drivers/video/scf0403_lcd.c new file +12 -0
+static void scf0403_gpio_reset(unsigned int gpio)
+{
+	if (!gpio_is_valid(gpio))
+		return;
+
+	gpio_set_value(gpio, 1);
+	mdelay(100);
+	gpio_set_value(gpio, 0);
+	mdelay(40);
+	gpio_set_value(gpio, 1);
+	mdelay(100);
+}

[...]

drivers/video/scf0403_lcd.c line 251

Quoted 7 lines
drivers/video/scf0403_lcd.c new file +7 -0
+int scf0403_init(int reset_gpio)
+{
+	int error;
+
+	if (!gpio_is_valid(reset_gpio)) {
+		printf("scf0403 reset_gpio not valid\n");
+		return -1;

The LCD reset pin does not have to be connected to a GPIO. Instead, it can be handled in another manner (e.g. by hardware). So, I don't think you should fail the LCD initialization if some kind of -EINVAL is passed.

Quoted 47 lines
drivers/video/scf0403_lcd.c new file +47 -0
+	}
+
+	priv.reset_gpio = reset_gpio;
+	error = scf0403_request_reset_gpio(reset_gpio);
+	if (error) {
+		printf("Failed requesting reset GPIO%d: %d\n",
+		       reset_gpio, error);
+		return error;
+	}
+
+	priv.spi = spi_setup_slave(3, 0, 1000000, SPI_MODE_0);
+	error = spi_claim_bus(priv.spi);
+	if (error) {
+		gpio_free(priv.reset_gpio);
+		return error;
+	}
+
+	/* reset LCD */
+	scf0403_gpio_reset(reset_gpio);
+
+	error = scf0403_spi_read_rddid(priv.spi, &priv.rddid);
+	if (error) {
+		printf("IDs read failed\n");
+		gpio_free(priv.reset_gpio);
+		spi_release_bus(priv.spi);
+
+		return error;
+	}
+
+	if (priv.rddid == SCF0403852GGU04_ID) {
+		priv.init_seq = scf0403_initseq_sn04;
+		priv.seq_size = ARRAY_SIZE(scf0403_initseq_sn04);
+	} else {
+		priv.init_seq = scf0403_initseq_sn20;
+		priv.seq_size = ARRAY_SIZE(scf0403_initseq_sn20);
+	}
+
+	scf0403_lcd_init(&priv);
+
+	/* Start operation */
+	scf0403_spi_transfer(priv.spi, &scf0403_cmd_dison);
+	mdelay(100);
+	scf0403_spi_transfer(priv.spi, &scf0403_cmd_slpout);
+	spi_release_bus(priv.spi);
+
+	return 0;
+}

[...]

include/spi.h line 30

Quoted 9 lines
include/spi.h +1 -0
index ae318ff..4441527 100644
@@ -27,6 +27,7 @@
 /* SPI transfer flags */
 #define SPI_XFER_BEGIN	0x01			/* Assert CS before transfer */
 #define SPI_XFER_END	0x02			/* Deassert CS after transfer */
+#define SPI_XFER_ONCE	(SPI_XFER_BEGIN | SPI_XFER_END)

This bit does not belong to the patch.

Quoted 4 lines
include/spi.h +0 -0
 /* Header byte that marks the start of the message */
 #define SPI_PREAMBLE_END_BYTE	0xec
 
Signature · 2 lines
Regards,
Igor.
#8 lore raw

PATCH 3/3 cm_t35: use scf0403 driver

In reply to Nikita Kiryanov

Use scf0403 driver to add scf0403x LCD support for cm-t35 and cm-t3730 boards.

Cc Tom Rini <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Igor Grinberg <[email protected]>

---
NOTE: This patch depends on http://patchwork.ozlabs.org/patch/275283/

 arch/arm/include/asm/arch-omap3/dss.h |  9 ++++---
 board/compulab/cm_t35/cm_t35.c        | 12 +++++++++
 board/compulab/common/omap3_display.c | 46 +++++++++++++++++++++++++++++++++--
 include/configs/cm_t35.h              |  3 +++
 4 files changed, 64 insertions(+), 6 deletions(-)
arch/arm/include/asm/arch-omap3/dss.h +5 -4
index ae0babf..8bf6b48 100644
@@ -178,10 +178,11 @@ struct venc_regs {
 #define LCD_INTERFACE_24_BIT	3
 
 /* Polarity */
-#define DSS_IVS	(1 << 12)
-#define DSS_IHS	(1 << 13)
-#define DSS_IPC	(1 << 14)
-#define DSS_IEO	(1 << 15)
+#define DSS_IVS		(1 << 12)
+#define DSS_IHS		(1 << 13)
+#define DSS_IPC		(1 << 14)
+#define DSS_IEO		(1 << 15)
+#define DSS_ONOFF	(1 << 17)
 
 /* GFX format */
 #define GFXFORMAT_BITMAP1		(0x0 << 1)
board/compulab/cm_t35/cm_t35.c +12 -0
index a6d4aba..51dd4a4 100644
@@ -268,6 +268,9 @@ static void cm_t3x_set_common_muxconf(void)
 	/* DVI enable */
 	MUX_VAL(CP(GPMC_NCS3),		(IDIS  | PTU | DIS  | M4));/*GPMC_nCS3*/
 
+	/* DataImage backlight */
+	MUX_VAL(CP(GPMC_NCS7),		(IDIS  | PTU | DIS  | M4));/*GPIO_58*/
+
 	/* CM-T3x Ethernet */
 	MUX_VAL(CP(GPMC_NCS5),		(IDIS | PTU | DIS | M0)); /*GPMC_nCS5*/
 	MUX_VAL(CP(GPMC_CLK),		(IEN  | PTD | DIS | M4)); /*GPIO_59*/
@@ -374,6 +377,15 @@ static void cm_t3x_set_common_muxconf(void)
 	MUX_VAL(CP(MMC1_DAT1),		(IEN  | PTU | EN  | M0)); /*MMC1_DAT1*/
 	MUX_VAL(CP(MMC1_DAT2),		(IEN  | PTU | EN  | M0)); /*MMC1_DAT2*/
 	MUX_VAL(CP(MMC1_DAT3),		(IEN  | PTU | EN  | M0)); /*MMC1_DAT3*/
+
+	/* SPI */
+	MUX_VAL(CP(MCBSP1_CLKR),	(IEN | PTD | DIS | M1)); /*MCSPI4_CLK*/
+	MUX_VAL(CP(MCBSP1_DX),		(IEN | PTD | DIS | M1)); /*MCSPI4_SIMO*/
+	MUX_VAL(CP(MCBSP1_DR),		(IEN | PTD | DIS | M1)); /*MCSPI4_SOMI*/
+	MUX_VAL(CP(MCBSP1_FSX),		(IEN | PTU | EN  | M1)); /*MCSPI4_CS0*/
+
+	/* display controls */
+	MUX_VAL(CP(MCBSP1_FSR),		(IDIS | PTU | DIS | M4)); /*GPIO_157*/
 }
 
 static void cm_t35_set_muxconf(void)
board/compulab/common/omap3_display.c +44 -2

86 lines not on this page · raw message

include/configs/cm_t35.h +3 -0
index 1260367..0a5e81f 100644
@@ -327,5 +327,8 @@
 #define CONFIG_SPLASH_SCREEN
 #define CONFIG_CMD_BMP
 #define CONFIG_BMP_16BPP
+#define CONFIG_SCF0403_LCD
+
+#define CONFIG_OMAP3_SPI
 
 #endif /* __CONFIG_H */
Signature · 1 line
1.8.1.2
#9 lore raw

PATCH 3/3 cm_t35: use scf0403 driver

Quoted 7 lines · On Wed, 9 Oct 2013 17:46:05 +0300 Nikita Kiryanov <[email protected]>…

Use scf0403 driver to add scf0403x LCD support for cm-t35 and cm-t3730 boards.

Cc Tom Rini <[email protected]>
Cc Anatolij Gustschin <[email protected]>
Cc Igor Grinberg <[email protected]>
Quoted 8 lines

---
NOTE: This patch depends on http://patchwork.ozlabs.org/patch/275283/

 arch/arm/include/asm/arch-omap3/dss.h |  9 ++++---
 board/compulab/cm_t35/cm_t35.c        | 12 +++++++++
 board/compulab/common/omap3_display.c | 46 +++++++++++++++++++++++++++++++++--
 include/configs/cm_t35.h              |  3 +++
 4 files changed, 64 insertions(+), 6 deletions(-)