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
7 In order to describe a single slave device that has no chip select line
8 the 'num-chipselects' property has to be <0> and the 'cs-gpios' property
9 doesn't need to be set.
11 Signed-off-by: Torsten Fleischer <torfl6749@gmail.com>
12 Signed-off-by: Mark Brown <broonie@kernel.org>
14 Documentation/devicetree/bindings/spi/spi-gpio.txt | 6 ++++--
15 drivers/spi/spi-gpio.c | 21 +++++++++++++++------
16 2 files changed, 19 insertions(+), 8 deletions(-)
18 --- a/Documentation/devicetree/bindings/spi/spi-gpio.txt
19 +++ b/Documentation/devicetree/bindings/spi/spi-gpio.txt
20 @@ -8,8 +8,10 @@ Required properties:
21 - gpio-sck: GPIO spec for the SCK line to use
22 - gpio-miso: GPIO spec for the MISO line to use
23 - gpio-mosi: GPIO spec for the MOSI line to use
24 - - cs-gpios: GPIOs to use for chipselect lines
25 - - num-chipselects: number of chipselect lines
26 + - cs-gpios: GPIOs to use for chipselect lines.
27 + Not needed if num-chipselects = <0>.
28 + - num-chipselects: Number of chipselect lines. Should be <0> if a single device
29 + with no chip select is connected.
33 --- a/drivers/spi/spi-gpio.c
34 +++ b/drivers/spi/spi-gpio.c
35 @@ -425,6 +425,7 @@ static int spi_gpio_probe(struct platfor
36 struct spi_gpio_platform_data *pdata;
41 status = spi_gpio_probe_dt(pdev);
43 @@ -434,16 +435,21 @@ static int spi_gpio_probe(struct platfor
45 pdata = dev_get_platdata(&pdev->dev);
46 #ifdef GENERIC_BITBANG
47 - if (!pdata || !pdata->num_chipselect)
48 + if (!pdata || (!use_of && !pdata->num_chipselect))
52 + if (use_of && !SPI_N_CHIPSEL)
55 + num_devices = SPI_N_CHIPSEL;
57 status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags);
61 master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
62 - (sizeof(int) * SPI_N_CHIPSEL));
63 + (sizeof(int) * num_devices));
67 @@ -458,7 +464,7 @@ static int spi_gpio_probe(struct platfor
68 master->bits_per_word_mask = SPI_BPW_RANGE_MASK(1, 32);
69 master->flags = master_flags;
70 master->bus_num = pdev->id;
71 - master->num_chipselect = SPI_N_CHIPSEL;
72 + master->num_chipselect = num_devices;
73 master->setup = spi_gpio_setup;
74 master->cleanup = spi_gpio_cleanup;
76 @@ -473,9 +479,12 @@ static int spi_gpio_probe(struct platfor
77 * property of the node.
80 - for (i = 0; i < SPI_N_CHIPSEL; i++)
81 - spi_gpio->cs_gpios[i] =
82 - of_get_named_gpio(np, "cs-gpios", i);
84 + spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT;
86 + for (i = 0; i < SPI_N_CHIPSEL; i++)
87 + spi_gpio->cs_gpios[i] =
88 + of_get_named_gpio(np, "cs-gpios", i);