diff options
author | Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com> | 2018-09-04 21:49:44 +0200 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2018-09-06 12:09:37 +0100 |
commit | af060b3f72b801962033f75a2fda25fff992796d (patch) | |
tree | d4c37f8b64d86ef924a7422a0cf278b33c8b3f47 | |
parent | 48c29d0d27fbbb4c78d3c14c50067d7e8919ed95 (diff) | |
download | blackbird-op-linux-af060b3f72b801962033f75a2fda25fff992796d.tar.gz blackbird-op-linux-af060b3f72b801962033f75a2fda25fff992796d.zip |
spi: dw: support 4-16 bits per word
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>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
-rw-r--r-- | drivers/spi/spi-dw.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/drivers/spi/spi-dw.c b/drivers/spi/spi-dw.c index 1736612ee86b..3e205ab60cd4 100644 --- a/drivers/spi/spi-dw.c +++ b/drivers/spi/spi-dw.c @@ -308,15 +308,10 @@ 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) { - dws->n_bytes = 1; - dws->dma_width = 1; - } else if (transfer->bits_per_word == 16) { - dws->n_bytes = 2; - dws->dma_width = 2; - } else { - return -EINVAL; - } + + dws->n_bytes = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + dws->dma_width = DIV_ROUND_UP(transfer->bits_per_word, BITS_PER_BYTE); + /* Default SPI mode is SCPOL = 0, SCPH = 0 */ cr0 = (transfer->bits_per_word - 1) | (chip->type << SPI_FRF_OFFSET) @@ -496,7 +491,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; |