950-0227-spi-Force-CS_HIGH-if-GPIO-descriptors-are-used.patch 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. From 51a164a0654895d930acb4e3bd096f7bf54c058b Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <[email protected]>
  3. Date: Fri, 17 Apr 2020 10:46:19 +0100
  4. Subject: [PATCH] spi: Force CS_HIGH if GPIO descriptors are used
  5. Commit f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
  6. amended of_spi_parse_dt() to always set SPI_CS_HIGH for SPI slaves whose
  7. Chip Select is defined by a "cs-gpios" devicetree property.
  8. This change breaks drivers whose probe functions set the mode field of
  9. the spi_device because in doing so they clear the SPI_CS_HIGH flag.
  10. Fix by setting SPI_CS_HIGH in spi_setup (under the same conditions as
  11. in of_spi_parse_dt()).
  12. See also: 83b2a8fe43bd ("spi: spidev: Fix CS polarity if GPIO descriptors are used")
  13. Fixes: f3186dd87669 ("spi: Optionally use GPIO descriptors for CS GPIOs")
  14. Signed-off-by: Phil Elwell <[email protected]>
  15. SQUASH: spi: Demote SPI_CS_HIGH warning to KERN_DEBUG
  16. This warning is unavoidable from a client's perspective and
  17. doesn't indicate anything wrong (just surprising).
  18. SQUASH with "spi: use_gpio_descriptor fixup moved to spi_setup"
  19. Signed-off-by: Phil Elwell <[email protected]>
  20. ---
  21. drivers/spi/spi.c | 9 +++++++++
  22. 1 file changed, 9 insertions(+)
  23. --- a/drivers/spi/spi.c
  24. +++ b/drivers/spi/spi.c
  25. @@ -3675,6 +3675,7 @@ static int spi_set_cs_timing(struct spi_
  26. */
  27. int spi_setup(struct spi_device *spi)
  28. {
  29. + struct spi_controller *ctlr = spi->controller;
  30. unsigned bad_bits, ugly_bits;
  31. int status = 0;
  32. @@ -3695,6 +3696,14 @@ int spi_setup(struct spi_device *spi)
  33. (SPI_TX_DUAL | SPI_TX_QUAD | SPI_TX_OCTAL |
  34. SPI_RX_DUAL | SPI_RX_QUAD | SPI_RX_OCTAL)))
  35. return -EINVAL;
  36. +
  37. + if (ctlr->use_gpio_descriptors && ctlr->cs_gpiods &&
  38. + ctlr->cs_gpiods[spi->chip_select] && !(spi->mode & SPI_CS_HIGH)) {
  39. + dev_dbg(&spi->dev,
  40. + "setup: forcing CS_HIGH (use_gpio_descriptors)\n");
  41. + spi->mode |= SPI_CS_HIGH;
  42. + }
  43. +
  44. /*
  45. * Help drivers fail *cleanly* when they need options
  46. * that aren't supported with their current controller.