brcm2708: remove CMA_DEBUG
[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 diff --git a/arch/arm/boot/dts/bcm2708-rpi-b.dts b/arch/arm/boot/dts/bcm2708-rpi-b.dts
35 index e319c8e..30107fb 100644
36 --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
37 +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
38 @@ -5,4 +5,36 @@
39  / {
40         compatible = "brcm,bcm2708";
41         model = "Raspberry Pi";
42 +
43 +       aliases {
44 +               spi0 = &spi0;
45 +       };
46 +};
47 +
48 +&gpio {
49 +       spi0_pins: spi0_pins {
50 +               brcm,pins = <7 8 9 10 11>;
51 +               brcm,function = <4>; /* alt0 */
52 +       };
53 +};
54 +
55 +&spi0 {
56 +       pinctrl-names = "default";
57 +       pinctrl-0 = <&spi0_pins>;
58 +
59 +       spidev@0{
60 +               compatible = "spidev";
61 +               reg = <0>;      /* CE0 */
62 +               #address-cells = <1>;
63 +               #size-cells = <0>;
64 +               spi-max-frequency = <500000>;
65 +       };
66 +
67 +       spidev@1{
68 +               compatible = "spidev";
69 +               reg = <1>;      /* CE1 */
70 +               #address-cells = <1>;
71 +               #size-cells = <0>;
72 +               spi-max-frequency = <500000>;
73 +       };
74  };
75 diff --git a/arch/arm/boot/dts/bcm2708.dtsi b/arch/arm/boot/dts/bcm2708.dtsi
76 index b2920c8..e90bf4c 100644
77 --- a/arch/arm/boot/dts/bcm2708.dtsi
78 +++ b/arch/arm/boot/dts/bcm2708.dtsi
79 @@ -38,11 +38,29 @@
80                         interrupt-controller;
81                         #interrupt-cells = <2>;
82                 };
83 +
84 +               spi0: spi@7e204000 {
85 +                       compatible = "brcm,bcm2708-spi";
86 +                       reg = <0x7e204000 0x1000>;
87 +                       interrupts = <2 22>;
88 +                       clocks = <&clk_spi>;
89 +                       #address-cells = <1>;
90 +                       #size-cells = <0>;
91 +                       status = "disabled";
92 +               };
93         };
94  
95         clocks {
96                 compatible = "simple-bus";
97                 #address-cells = <1>;
98                 #size-cells = <0>;
99 +
100 +               clk_spi: clock@2 {
101 +                       compatible = "fixed-clock";
102 +                       reg = <2>;
103 +                       #clock-cells = <0>;
104 +                       clock-output-names = "spi";
105 +                       clock-frequency = <250000000>;
106 +               };
107         };
108  };
109 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
110 index 0e5bd43..a2069f8 100644
111 --- a/arch/arm/mach-bcm2708/bcm2708.c
112 +++ b/arch/arm/mach-bcm2708/bcm2708.c
113 @@ -486,6 +486,7 @@ static struct platform_device bcm2708_alsa_devices[] = {
114                },
115  };
116  
117 +#ifndef CONFIG_OF
118  static struct resource bcm2708_spi_resources[] = {
119         {
120                 .start = SPI0_BASE,
121 @@ -509,6 +510,7 @@ static struct platform_device bcm2708_spi_device = {
122                 .dma_mask = &bcm2708_spi_dmamask,
123                 .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
124  };
125 +#endif
126  
127  #ifdef CONFIG_BCM2708_SPIDEV
128  static struct spi_board_info bcm2708_spi_devices[] = {
129 @@ -670,6 +672,16 @@ int __init bcm_register_device(struct platform_device *pdev)
130         return ret;
131  }
132  
133 +/*
134 + * Use this macro for platform devices that are present in the Device Tree.
135 + * This way the device is only added on non-DT builds.
136 + */
137 +#ifdef CONFIG_OF
138 +#define bcm_register_device_dt(pdev)
139 +#else
140 +#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
141 +#endif
142 +
143  int calc_rsts(int partition)
144  {
145         return PM_PASSWORD |
146 @@ -784,7 +796,7 @@ void __init bcm2708_init(void)
147         for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
148                 bcm_register_device(&bcm2708_alsa_devices[i]);
149  
150 -       bcm_register_device(&bcm2708_spi_device);
151 +       bcm_register_device_dt(&bcm2708_spi_device);
152         bcm_register_device(&bcm2708_bsc0_device);
153         bcm_register_device(&bcm2708_bsc1_device);
154  
155 @@ -824,8 +836,9 @@ void __init bcm2708_init(void)
156         system_serial_low = serial;
157  
158  #ifdef CONFIG_BCM2708_SPIDEV
159 -       spi_register_board_info(bcm2708_spi_devices,
160 -                       ARRAY_SIZE(bcm2708_spi_devices));
161 +       if (!use_dt)
162 +           spi_register_board_info(bcm2708_spi_devices,
163 +                                   ARRAY_SIZE(bcm2708_spi_devices));
164  #endif
165  }
166  
167 diff --git a/drivers/spi/Kconfig b/drivers/spi/Kconfig
168 index 71b4741..a5238ab 100644
169 --- a/drivers/spi/Kconfig
170 +++ b/drivers/spi/Kconfig
171 @@ -77,7 +77,7 @@ config SPI_ATMEL
172  
173  config SPI_BCM2835
174         tristate "BCM2835 SPI controller"
175 -       depends on ARCH_BCM2835 || COMPILE_TEST
176 +       depends on ARCH_BCM2835 || ARCH_BCM2708 || COMPILE_TEST
177         help
178           This selects a driver for the Broadcom BCM2835 SPI master.
179  
180 diff --git a/drivers/spi/spi-bcm2708.c b/drivers/spi/spi-bcm2708.c
181 index 349d21f..041b5e2 100644
182 --- a/drivers/spi/spi-bcm2708.c
183 +++ b/drivers/spi/spi-bcm2708.c
184 @@ -512,6 +512,7 @@ static int bcm2708_spi_probe(struct platform_device *pdev)
185         master->setup = bcm2708_spi_setup;
186         master->transfer = bcm2708_spi_transfer;
187         master->cleanup = bcm2708_spi_cleanup;
188 +       master->dev.of_node = pdev->dev.of_node;
189         platform_set_drvdata(pdev, master);
190  
191         bs = spi_master_get_devdata(master);
192 @@ -596,10 +597,17 @@ static int bcm2708_spi_remove(struct platform_device *pdev)
193         return 0;
194  }
195  
196 +static const struct of_device_id bcm2708_spi_match[] = {
197 +       { .compatible = "brcm,bcm2708-spi", },
198 +       {}
199 +};
200 +MODULE_DEVICE_TABLE(of, bcm2708_spi_match);
201 +
202  static struct platform_driver bcm2708_spi_driver = {
203         .driver         = {
204                 .name   = DRV_NAME,
205                 .owner  = THIS_MODULE,
206 +               .of_match_table = bcm2708_spi_match,
207         },
208         .probe          = bcm2708_spi_probe,
209         .remove         = bcm2708_spi_remove,
210 -- 
211 1.8.3.2
212