501-spi-a3700-Change-SPI-mode-before-asserting-chip-sele.patch 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From dd7aa8d4b53b3484ba31ba56f3ff1be7deb38530 Mon Sep 17 00:00:00 2001
  2. From: Maxime Chevallier <maxime.chevallier@smile.fr>
  3. Date: Tue, 10 Oct 2017 10:43:18 +0200
  4. Subject: spi: a3700: Change SPI mode before asserting chip-select
  5. The spi device mode should be configured in the controller before the
  6. chip-select is asserted, so that a clock polarity configuration change
  7. is not interpreted as a clock tick by the device.
  8. This patch moves the mode setting to the 'prepare_message' function
  9. instead of the 'transfer_one' function.
  10. By doing so, this patch also removes redundant code in
  11. a3700_spi_clock_set.
  12. This was tested on EspressoBin board, with spidev.
  13. Signed-off-by: Maxime Chevallier <maxime.chevallier@smile.fr>
  14. Signed-off-by: Mark Brown <broonie@kernel.org>
  15. ---
  16. drivers/spi/spi-armada-3700.c | 17 ++++-------------
  17. 1 file changed, 4 insertions(+), 13 deletions(-)
  18. --- a/drivers/spi/spi-armada-3700.c
  19. +++ b/drivers/spi/spi-armada-3700.c
  20. @@ -214,7 +214,7 @@ static void a3700_spi_mode_set(struct a3
  21. }
  22. static void a3700_spi_clock_set(struct a3700_spi *a3700_spi,
  23. - unsigned int speed_hz, u16 mode)
  24. + unsigned int speed_hz)
  25. {
  26. u32 val;
  27. u32 prescale;
  28. @@ -239,17 +239,6 @@ static void a3700_spi_clock_set(struct a
  29. val |= A3700_SPI_CLK_CAPT_EDGE;
  30. spireg_write(a3700_spi, A3700_SPI_IF_TIME_REG, val);
  31. }
  32. -
  33. - val = spireg_read(a3700_spi, A3700_SPI_IF_CFG_REG);
  34. - val &= ~(A3700_SPI_CLK_POL | A3700_SPI_CLK_PHA);
  35. -
  36. - if (mode & SPI_CPOL)
  37. - val |= A3700_SPI_CLK_POL;
  38. -
  39. - if (mode & SPI_CPHA)
  40. - val |= A3700_SPI_CLK_PHA;
  41. -
  42. - spireg_write(a3700_spi, A3700_SPI_IF_CFG_REG, val);
  43. }
  44. static void a3700_spi_bytelen_set(struct a3700_spi *a3700_spi, unsigned int len)
  45. @@ -431,7 +420,7 @@ static void a3700_spi_transfer_setup(str
  46. a3700_spi = spi_master_get_devdata(spi->master);
  47. - a3700_spi_clock_set(a3700_spi, xfer->speed_hz, spi->mode);
  48. + a3700_spi_clock_set(a3700_spi, xfer->speed_hz);
  49. byte_len = xfer->bits_per_word >> 3;
  50. @@ -592,6 +581,8 @@ static int a3700_spi_prepare_message(str
  51. a3700_spi_bytelen_set(a3700_spi, 4);
  52. + a3700_spi_mode_set(a3700_spi, spi->mode);
  53. +
  54. return 0;
  55. }