linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] spi: dw: support 4-16 bits per word
@ 2018-08-08  7:14 Simon Goldschmidt
  2018-08-08  9:45 ` Andy Shevchenko
  2018-08-17  7:01 ` [PATCH v2] " Simon Goldschmidt
  0 siblings, 2 replies; 14+ messages in thread
From: Simon Goldschmidt @ 2018-08-08  7:14 UTC (permalink / raw)
  To: Mark Brown, linux-spi, linux-kernel

The spi-dw driver currently only supports 8 or 16 bits per word.

Since the hardware supports 4-16 bits per word, adapt the driver
to also support this.

Tested on socfpga cyclone5 with a 9-bit SPI display.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---
 drivers/spi/spi-dw.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c
index f693bfe95ab9..2ecbb6b19cea 100644
--- a/drivers/spi/spi-dw.c
+++ b/drivers/spi/spi-dw.c
@@ -307,14 +307,14 @@ static int dw_spi_transfer_one(struct spi_controller *master,
 		dws->current_freq = transfer->speed_hz;
 		spi_set_clk(dws, chip->clk_div);
 	}
-	if (transfer->bits_per_word == 8) {
+	if ((transfer->bits_per_word < 4) || (transfer->bits_per_word > 16))
+		return -EINVAL;
+	if (transfer->bits_per_word <= 8) {
 		dws->n_bytes = 1;
 		dws->dma_width = 1;
-	} else if (transfer->bits_per_word == 16) {
+	} else {
 		dws->n_bytes = 2;
 		dws->dma_width = 2;
-	} else {
-		return -EINVAL;
 	}
 	/* Default SPI mode is SCPOL = 0, SCPH = 0 */
 	cr0 = (transfer->bits_per_word - 1)
@@ -493,7 +493,7 @@ int dw_spi_add_host(struct device *dev, struct dw_spi *dws)
 	}
 
 	master->mode_bits = SPI_CPOL | SPI_CPHA | SPI_LOOP;
-	master->bits_per_word_mask = SPI_BPW_MASK(8) | SPI_BPW_MASK(16);
+	master->bits_per_word_mask =  SPI_BPW_RANGE_MASK(4, 16);
 	master->bus_num = dws->bus_num;
 	master->num_chipselect = dws->num_cs;
 	master->setup = dw_spi_setup;
-- 
2.17.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2018-09-06 13:37 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-08-08  7:14 [PATCH] spi: dw: support 4-16 bits per word Simon Goldschmidt
2018-08-08  9:45 ` Andy Shevchenko
2018-08-08 11:58   ` Simon Goldschmidt
2018-08-08 12:26     ` Andy Shevchenko
2018-08-17  7:01 ` [PATCH v2] " Simon Goldschmidt
2018-08-17 11:17   ` Andy Shevchenko
2018-08-17 16:32   ` Trent Piepho
2018-08-18  8:37     ` Simon Goldschmidt
2018-09-04 19:49   ` [PATCH v3] " Simon Goldschmidt
2018-09-06 11:09     ` Mark Brown
2018-09-06 11:23       ` Simon Goldschmidt
2018-09-06 13:23         ` Mark Brown
2018-09-06 13:37           ` Simon Goldschmidt
2018-09-06 11:10     ` Applied "spi: dw: support 4-16 bits per word" to the spi tree Mark Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).