104-spi-spi-ath79-support-multiple-internal-chip-select-.patch 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. From: Felix Fietkau <nbd@nbd.name>
  2. Date: Fri, 9 Dec 2016 20:09:16 +0100
  3. Subject: [PATCH] spi: spi-ath79: support multiple internal chip select
  4. lines
  5. Several devices with multiple flash chips use the internal chip select
  6. lines. Don't assume that chip select 1 and above are GPIO lines.
  7. Signed-off-by: Felix Fietkau <nbd@nbd.name>
  8. ---
  9. --- a/drivers/spi/spi-ath79.c
  10. +++ b/drivers/spi/spi-ath79.c
  11. @@ -78,14 +78,16 @@ static void ath79_spi_chipselect(struct
  12. ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
  13. }
  14. - if (spi->chip_select) {
  15. + if (gpio_is_valid(spi->cs_gpio)) {
  16. /* SPI is normally active-low */
  17. gpio_set_value(spi->cs_gpio, cs_high);
  18. } else {
  19. + u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
  20. +
  21. if (cs_high)
  22. - sp->ioc_base |= AR71XX_SPI_IOC_CS0;
  23. + sp->ioc_base |= cs_bit;
  24. else
  25. - sp->ioc_base &= ~AR71XX_SPI_IOC_CS0;
  26. + sp->ioc_base &= ~cs_bit;
  27. ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
  28. }
  29. @@ -118,11 +120,8 @@ static int ath79_spi_setup_cs(struct spi
  30. struct ath79_spi *sp = ath79_spidev_to_sp(spi);
  31. int status;
  32. - if (spi->chip_select && !gpio_is_valid(spi->cs_gpio))
  33. - return -EINVAL;
  34. -
  35. status = 0;
  36. - if (spi->chip_select) {
  37. + if (gpio_is_valid(spi->cs_gpio)) {
  38. unsigned long flags;
  39. flags = GPIOF_DIR_OUT;
  40. @@ -134,10 +133,12 @@ static int ath79_spi_setup_cs(struct spi
  41. status = gpio_request_one(spi->cs_gpio, flags,
  42. dev_name(&spi->dev));
  43. } else {
  44. + u32 cs_bit = AR71XX_SPI_IOC_CS(spi->chip_select);
  45. +
  46. if (spi->mode & SPI_CS_HIGH)
  47. - sp->ioc_base &= ~AR71XX_SPI_IOC_CS0;
  48. + sp->ioc_base &= ~cs_bit;
  49. else
  50. - sp->ioc_base |= AR71XX_SPI_IOC_CS0;
  51. + sp->ioc_base |= cs_bit;
  52. ath79_spi_wr(sp, AR71XX_SPI_REG_IOC, sp->ioc_base);
  53. }
  54. @@ -147,7 +148,7 @@ static int ath79_spi_setup_cs(struct spi
  55. static void ath79_spi_cleanup_cs(struct spi_device *spi)
  56. {
  57. - if (spi->chip_select) {
  58. + if (gpio_is_valid(spi->cs_gpio)) {
  59. gpio_free(spi->cs_gpio);
  60. }
  61. }