0012-spi-bcm2835-Support-pin-groups-other-than-7-11.patch 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. From f58037ac49ec4233848397cf67f84afa97a3ab38 Mon Sep 17 00:00:00 2001
  2. From: Phil Elwell <phil@raspberrypi.org>
  3. Date: Wed, 24 Jun 2015 14:10:44 +0100
  4. Subject: [PATCH] spi-bcm2835: Support pin groups other than 7-11
  5. The spi-bcm2835 driver automatically uses GPIO chip-selects due to
  6. some unreliability of the native ones. In doing so it chooses the
  7. same pins as the native chip-selects would use, but the existing
  8. code always uses pins 7 and 8, wherever the SPI function is mapped.
  9. Search the pinctrl group assigned to the driver for pins that
  10. correspond to native chip-selects, and use those for GPIO chip-
  11. selects.
  12. Signed-off-by: Phil Elwell <phil@raspberrypi.org>
  13. ---
  14. drivers/spi/spi-bcm2835.c | 45 +++++++++++++++++++++++++++++++++++++--------
  15. 1 file changed, 37 insertions(+), 8 deletions(-)
  16. --- a/drivers/spi/spi-bcm2835.c
  17. +++ b/drivers/spi/spi-bcm2835.c
  18. @@ -687,6 +687,8 @@ static int bcm2835_spi_setup(struct spi_
  19. {
  20. int err;
  21. struct gpio_chip *chip;
  22. + struct device_node *pins;
  23. + u32 pingroup_index;
  24. /*
  25. * sanity checking the native-chipselects
  26. */
  27. @@ -703,15 +705,42 @@ static int bcm2835_spi_setup(struct spi_
  28. "setup: only two native chip-selects are supported\n");
  29. return -EINVAL;
  30. }
  31. - /* now translate native cs to GPIO */
  32. - /* get the gpio chip for the base */
  33. - chip = gpiochip_find("pinctrl-bcm2835", chip_match_name);
  34. - if (!chip)
  35. - return 0;
  36. + /* now translate native cs to GPIO */
  37. + /* first look for chip select pins in the devices pin groups */
  38. + for (pingroup_index = 0;
  39. + (pins = of_parse_phandle(spi->master->dev.of_node,
  40. + "pinctrl-0",
  41. + pingroup_index)) != 0;
  42. + pingroup_index++) {
  43. + u32 pin;
  44. + u32 pin_index;
  45. + for (pin_index = 0;
  46. + of_property_read_u32_index(pins,
  47. + "brcm,pins",
  48. + pin_index,
  49. + &pin) == 0;
  50. + pin_index++) {
  51. + if (((spi->chip_select == 0) &&
  52. + ((pin == 8) || (pin == 36) || (pin == 46))) ||
  53. + ((spi->chip_select == 1) &&
  54. + ((pin == 7) || (pin == 35)))) {
  55. + spi->cs_gpio = pin;
  56. + break;
  57. + }
  58. + }
  59. + of_node_put(pins);
  60. + }
  61. + /* if that fails, assume GPIOs 7-11 are used */
  62. + if (!gpio_is_valid(spi->cs_gpio) ) {
  63. + /* get the gpio chip for the base */
  64. + chip = gpiochip_find("pinctrl-bcm2835", chip_match_name);
  65. + if (!chip)
  66. + return 0;
  67. - /* and calculate the real CS */
  68. - spi->cs_gpio = chip->base + 8 - spi->chip_select;
  69. + /* and calculate the real CS */
  70. + spi->cs_gpio = chip->base + 8 - spi->chip_select;
  71. + }
  72. /* and set up the "mode" and level */
  73. dev_info(&spi->dev, "setting up native-CS%i as GPIO %i\n",