Merge pull request #580 from wigyori/cc-libpcap
[15.05/openwrt.git] / target / linux / brcm2708 / patches-3.18 / 0052-spi-bcm2708-add-device-tree-support.patch
1 From 5de6baef9b5d9e3a84e0c3752cfb7eaef2eb1a0f Mon Sep 17 00:00:00 2001
2 From: notro <notro@tronnes.org>
3 Date: Sun, 27 Jul 2014 20:12:58 +0200
4 Subject: [PATCH 052/114] spi: bcm2708: add device tree support
5
6 Add DT support to driver and add to .dtsi file.
7 Setup pins and spidev in .dts file.
8 SPI is disabled by default.
9
10 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
11
12 BCM2708: don't register SPI controller when using DT
13
14 The device for the SPI controller is in the Device Tree.
15 Only register the device when not using DT.
16
17 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
18
19 spi: bcm2835: make driver available on ARCH_BCM2708
20
21 Make this driver available on ARCH_BCM2708
22
23 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
24
25 bcm2708: Remove the prohibition on mixing SPIDEV and DT
26 ---
27  arch/arm/boot/dts/bcm2708-rpi-b.dts | 32 ++++++++++++++++++++++++++++++++
28  arch/arm/boot/dts/bcm2708.dtsi      | 18 ++++++++++++++++++
29  arch/arm/mach-bcm2708/bcm2708.c     | 19 ++++++++++++++++---
30  drivers/spi/Kconfig                 |  2 +-
31  drivers/spi/spi-bcm2708.c           |  8 ++++++++
32  5 files changed, 75 insertions(+), 4 deletions(-)
33
34 --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
35 +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
36 @@ -5,4 +5,36 @@
37  / {
38         compatible = "brcm,bcm2708";
39         model = "Raspberry Pi";
40 +
41 +       aliases {
42 +               spi0 = &spi0;
43 +       };
44 +};
45 +
46 +&gpio {
47 +       spi0_pins: spi0_pins {
48 +               brcm,pins = <7 8 9 10 11>;
49 +               brcm,function = <4>; /* alt0 */
50 +       };
51 +};
52 +
53 +&spi0 {
54 +       pinctrl-names = "default";
55 +       pinctrl-0 = <&spi0_pins>;
56 +
57 +       spidev@0{
58 +               compatible = "spidev";
59 +               reg = <0>;      /* CE0 */
60 +               #address-cells = <1>;
61 +               #size-cells = <0>;
62 +               spi-max-frequency = <500000>;
63 +       };
64 +
65 +       spidev@1{
66 +               compatible = "spidev";
67 +               reg = <1>;      /* CE1 */
68 +               #address-cells = <1>;
69 +               #size-cells = <0>;
70 +               spi-max-frequency = <500000>;
71 +       };
72  };
73 --- a/arch/arm/boot/dts/bcm2708.dtsi
74 +++ b/arch/arm/boot/dts/bcm2708.dtsi
75 @@ -38,11 +38,29 @@
76                         interrupt-controller;
77                         #interrupt-cells = <2>;
78                 };
79 +
80 +               spi0: spi@7e204000 {
81 +                       compatible = "brcm,bcm2708-spi";
82 +                       reg = <0x7e204000 0x1000>;
83 +                       interrupts = <2 22>;
84 +                       clocks = <&clk_spi>;
85 +                       #address-cells = <1>;
86 +                       #size-cells = <0>;
87 +                       status = "disabled";
88 +               };
89         };
90  
91         clocks {
92                 compatible = "simple-bus";
93                 #address-cells = <1>;
94                 #size-cells = <0>;
95 +
96 +               clk_spi: clock@2 {
97 +                       compatible = "fixed-clock";
98 +                       reg = <2>;
99 +                       #clock-cells = <0>;
100 +                       clock-output-names = "spi";
101 +                       clock-frequency = <250000000>;
102 +               };
103         };
104  };
105 --- a/arch/arm/mach-bcm2708/bcm2708.c
106 +++ b/arch/arm/mach-bcm2708/bcm2708.c
107 @@ -486,6 +486,7 @@ static struct platform_device bcm2708_al
108                },
109  };
110  
111 +#ifndef CONFIG_OF
112  static struct resource bcm2708_spi_resources[] = {
113         {
114                 .start = SPI0_BASE,
115 @@ -509,6 +510,7 @@ static struct platform_device bcm2708_sp
116                 .dma_mask = &bcm2708_spi_dmamask,
117                 .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
118  };
119 +#endif
120  
121  #ifdef CONFIG_BCM2708_SPIDEV
122  static struct spi_board_info bcm2708_spi_devices[] = {
123 @@ -670,6 +672,16 @@ int __init bcm_register_device(struct pl
124         return ret;
125  }
126  
127 +/*
128 + * Use this macro for platform devices that are present in the Device Tree.
129 + * This way the device is only added on non-DT builds.
130 + */
131 +#ifdef CONFIG_OF
132 +#define bcm_register_device_dt(pdev)
133 +#else
134 +#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
135 +#endif
136 +
137  int calc_rsts(int partition)
138  {
139         return PM_PASSWORD |
140 @@ -784,7 +796,7 @@ void __init bcm2708_init(void)
141         for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
142                 bcm_register_device(&bcm2708_alsa_devices[i]);
143  
144 -       bcm_register_device(&bcm2708_spi_device);
145 +       bcm_register_device_dt(&bcm2708_spi_device);
146         bcm_register_device(&bcm2708_bsc0_device);
147         bcm_register_device(&bcm2708_bsc1_device);
148  
149 @@ -824,8 +836,9 @@ void __init bcm2708_init(void)
150         system_serial_low = serial;
151  
152  #ifdef CONFIG_BCM2708_SPIDEV
153 -       spi_register_board_info(bcm2708_spi_devices,
154 -                       ARRAY_SIZE(bcm2708_spi_devices));
155 +       if (!use_dt)
156 +           spi_register_board_info(bcm2708_spi_devices,
157 +                                   ARRAY_SIZE(bcm2708_spi_devices));
158  #endif
159  }
160  
161 --- a/drivers/spi/Kconfig
162 +++ b/drivers/spi/Kconfig
163 @@ -77,7 +77,7 @@ config SPI_ATMEL
164  
165  config SPI_BCM2835
166         tristate "BCM2835 SPI controller"
167 -       depends on ARCH_BCM2835 || COMPILE_TEST
168 +       depends on ARCH_BCM2835 || ARCH_BCM2708 || COMPILE_TEST
169         help
170           This selects a driver for the Broadcom BCM2835 SPI master.
171  
172 --- a/drivers/spi/spi-bcm2708.c
173 +++ b/drivers/spi/spi-bcm2708.c
174 @@ -512,6 +512,7 @@ static int bcm2708_spi_probe(struct plat
175         master->setup = bcm2708_spi_setup;
176         master->transfer = bcm2708_spi_transfer;
177         master->cleanup = bcm2708_spi_cleanup;
178 +       master->dev.of_node = pdev->dev.of_node;
179         platform_set_drvdata(pdev, master);
180  
181         bs = spi_master_get_devdata(master);
182 @@ -596,10 +597,17 @@ static int bcm2708_spi_remove(struct pla
183         return 0;
184  }
185  
186 +static const struct of_device_id bcm2708_spi_match[] = {
187 +       { .compatible = "brcm,bcm2708-spi", },
188 +       {}
189 +};
190 +MODULE_DEVICE_TABLE(of, bcm2708_spi_match);
191 +
192  static struct platform_driver bcm2708_spi_driver = {
193         .driver         = {
194                 .name   = DRV_NAME,
195                 .owner  = THIS_MODULE,
196 +               .of_match_table = bcm2708_spi_match,
197         },
198         .probe          = bcm2708_spi_probe,
199         .remove         = bcm2708_spi_remove,