kernel: remove kernel module checks/dependencies for 3.14
[oweals/openwrt.git] / target / linux / brcm63xx / patches-3.18 / 001-spi-spi-gpio-Add-dt-support-for-a-single-device-with.patch
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
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.
10
11 Signed-off-by: Torsten Fleischer <torfl6749@gmail.com>
12 Signed-off-by: Mark Brown <broonie@kernel.org>
13 ---
14  Documentation/devicetree/bindings/spi/spi-gpio.txt |  6 ++++--
15  drivers/spi/spi-gpio.c                             | 21 +++++++++++++++------
16  2 files changed, 19 insertions(+), 8 deletions(-)
17
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.
30  
31  Example:
32  
33 --- a/drivers/spi/spi-gpio.c
34 +++ b/drivers/spi/spi-gpio.c
35 @@ -424,6 +424,7 @@ static int spi_gpio_probe(struct platfor
36         struct spi_gpio_platform_data   *pdata;
37         u16 master_flags = 0;
38         bool use_of = 0;
39 +       int num_devices;
40  
41         status = spi_gpio_probe_dt(pdev);
42         if (status < 0)
43 @@ -433,16 +434,21 @@ static int spi_gpio_probe(struct platfor
44  
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))
49                 return -ENODEV;
50  #endif
51  
52 +       if (use_of && !SPI_N_CHIPSEL)
53 +               num_devices = 1;
54 +       else
55 +               num_devices = SPI_N_CHIPSEL;
56 +
57         status = spi_gpio_request(pdata, dev_name(&pdev->dev), &master_flags);
58         if (status < 0)
59                 return status;
60  
61         master = spi_alloc_master(&pdev->dev, sizeof(*spi_gpio) +
62 -                                       (sizeof(int) * SPI_N_CHIPSEL));
63 +                                       (sizeof(int) * num_devices));
64         if (!master) {
65                 status = -ENOMEM;
66                 goto gpio_free;
67 @@ -457,7 +463,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;
75  #ifdef CONFIG_OF
76 @@ -472,9 +478,12 @@ static int spi_gpio_probe(struct platfor
77                  * property of the node.
78                  */
79  
80 -               for (i = 0; i < SPI_N_CHIPSEL; i++)
81 -                       spi_gpio->cs_gpios[i] =
82 -                               of_get_named_gpio(np, "cs-gpios", i);
83 +               if (!SPI_N_CHIPSEL)
84 +                       spi_gpio->cs_gpios[0] = SPI_GPIO_NO_CHIPSELECT;
85 +               else
86 +                       for (i = 0; i < SPI_N_CHIPSEL; i++)
87 +                               spi_gpio->cs_gpios[i] =
88 +                                       of_get_named_gpio(np, "cs-gpios", i);
89         }
90  #endif
91