1 From e3e8ae5998017712471c53db877bd01dd297ad01 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 099/203] spi-bcm2835: Support pin groups other than 7-11
6 The spi-bcm2835 driver automatically uses GPIO chip-selects due to
7 some unreliability of the native ones. In doing so it chooses the
8 same pins as the native chip-selects would use, but the existing
9 code always uses pins 7 and 8, wherever the SPI function is mapped.
11 Search the pinctrl group assigned to the driver for pins that
12 correspond to native chip-selects, and use those for GPIO chip-
15 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
17 drivers/spi/spi-bcm2835.c | 45 +++++++++++++++++++++++++++++++++++++--------
18 1 file changed, 37 insertions(+), 8 deletions(-)
20 --- a/drivers/spi/spi-bcm2835.c
21 +++ b/drivers/spi/spi-bcm2835.c
22 @@ -376,6 +376,8 @@ static int bcm2835_spi_setup(struct spi_
25 struct gpio_chip *chip;
26 + struct device_node *pins;
29 * sanity checking the native-chipselects
31 @@ -392,15 +394,42 @@ static int bcm2835_spi_setup(struct spi_
32 "setup: only two native chip-selects are supported\n");
35 - /* now translate native cs to GPIO */
37 - /* get the gpio chip for the base */
38 - chip = gpiochip_find("pinctrl-bcm2835", chip_match_name);
41 + /* now translate native cs to GPIO */
42 + /* first look for chip select pins in the devices pin groups */
43 + for (pingroup_index = 0;
44 + (pins = of_parse_phandle(spi->master->dev.of_node,
46 + pingroup_index)) != 0;
51 + of_property_read_u32_index(pins,
56 + if (((spi->chip_select == 0) &&
57 + ((pin == 8) || (pin == 36) || (pin == 46))) ||
58 + ((spi->chip_select == 1) &&
59 + ((pin == 7) || (pin == 35)))) {
66 + /* if that fails, assume GPIOs 7-11 are used */
67 + if (!gpio_is_valid(spi->cs_gpio) ) {
68 + /* get the gpio chip for the base */
69 + chip = gpiochip_find("pinctrl-bcm2835", chip_match_name);
73 - /* and calculate the real CS */
74 - spi->cs_gpio = chip->base + 8 - spi->chip_select;
75 + /* and calculate the real CS */
76 + spi->cs_gpio = chip->base + 8 - spi->chip_select;
79 /* and set up the "mode" and level */
80 dev_info(&spi->dev, "setting up native-CS%i as GPIO %i\n",