001-spi-spi-gpio-Add-dt-support-for-a-single-device-with.patch 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. From d1d81802522ade84128a2c66c0d500e372474dca Mon Sep 17 00:00:00 2001
  2. From: Torsten Fleischer <torfl6749@gmail.com>
  3. Date: Mon, 3 Nov 2014 17:17:55 +0100
  4. Subject: [PATCH] spi: spi-gpio: Add dt support for a single device with no
  5. chip select
  6. In order to describe a single slave device that has no chip select line
  7. the 'num-chipselects' property has to be <0> and the 'cs-gpios' property
  8. doesn't need to be set.
  9. Signed-off-by: Torsten Fleischer <torfl6749@gmail.com>
  10. Signed-off-by: Mark Brown <broonie@kernel.org>
  11. ---
  12. Documentation/devicetree/bindings/spi/spi-gpio.txt | 6 ++++--
  13. drivers/spi/spi-gpio.c | 21 +++++++++++++++------
  14. 2 files changed, 19 insertions(+), 8 deletions(-)
  15. --- a/Documentation/devicetree/bindings/spi/spi-gpio.txt
  16. +++ b/Documentation/devicetree/bindings/spi/spi-gpio.txt
  17. @@ -8,8 +8,10 @@ Required properties:
  18. - gpio-sck: GPIO spec for the SCK line to use
  19. - gpio-miso: GPIO spec for the MISO line to use
  20. - gpio-mosi: GPIO spec for the MOSI line to use
  21. - - cs-gpios: GPIOs to use for chipselect lines
  22. - - num-chipselects: number of chipselect lines
  23. + - cs-gpios: GPIOs to use for chipselect lines.
  24. + Not needed if num-chipselects = <0>.
  25. + - num-chipselects: Number of chipselect lines. Should be <0> if a single device
  26. + with no chip select is connected.
  27. Example:
  28. --- a/drivers/spi/spi-gpio.c
  29. +++ b/drivers/spi/spi-gpio.c
  30. @@ -424,6 +424,7 @@ static int spi_gpio_probe(struct platfor
  31. struct spi_gpio_platform_data *pdata;
  32. u16 master_flags = 0;
  33. bool use_of = 0;
  34. + int num_devices;
  35. status = spi_gpio_probe_dt(pdev);
  36. if (status < 0)
  37. @@ -433,16 +434,21 @@ static int spi_gpio_probe(struct platfor
  38. pdata = dev_get_platdata(&pdev->dev);
  39. #ifdef GENERIC_BITBANG
  40. - if (!pdata || !pdata->num_chipselect)
  41. + if (!pdata || (!use_of && !pdata->num_chipselect))
  42. return -ENODEV;
  43. #endif
  44. + if (use_of && !SPI_N_CHIPSEL)
  45. + num_devices = 1;
  46. + else
  47. + num_devices = SPI_N_CHIPSEL;
  48. +
  49. status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags);
  50. if (status < 0)
  51. return status;
  52. master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
  53. - (sizeof(int) * SPI_N_CHIPSEL));
  54. + (sizeof(int) * num_devices));
  55. if (!master) {
  56. status = -ENOMEM;
  57. goto gpio_free;
  58. @@ -457,7 +463,7 @@ static int spi_gpio_probe(struct platfor
  59. master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
  60. master->flags = master_flags;
  61. master->bus_num = pdev->id;
  62. - master->num_chipselect = SPI_N_CHIPSEL;
  63. + master->num_chipselect = num_devices;
  64. master->setup = spi_gpio_setup;
  65. master->cleanup = spi_gpio_cleanup;
  66. #ifdef CONFIG_OF
  67. @@ -472,9 +478,12 @@ static int spi_gpio_probe(struct platfor
  68. * property of the node.
  69. */
  70. - for (i = 0; i < SPI_N_CHIPSEL; i++)
  71. - spi_gpio->cs_gpios[i] =
  72. - of_get_named_gpio(np, "cs-gpios", i);
  73. + if (!SPI_N_CHIPSEL)
  74. + spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT;
  75. + else
  76. + for (i = 0; i < SPI_N_CHIPSEL; i++)
  77. + spi_gpio->cs_gpios[i] =
  78. + of_get_named_gpio(np, "cs-gpios", i);
  79. }
  80. #endif