lantiq: Use the BAR0 base address in the ath PCI fixup code
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-3.18 / 0063-bcm2708-Allow-option-card-devices-to-be-configured-v.patch
1 From 37fd085e3449fabd2d976d671ebf2a6c631c9afd Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Mon, 1 Sep 2014 16:35:56 +0100
4 Subject: [PATCH 063/114] bcm2708: Allow option card devices to be configured
5 via DT
6
7 If the kernel is built with Device Tree support, and if a DT blob
8 is provided for the kernel at boot time, then the platform devices
9 for option cards are not created. This avoids both the need to
10 blacklist unwanted devices, and the need to update the board
11 support code with each new device.
12 ---
13 arch/arm/mach-bcm2708/bcm2708.c | 70 ++++++++++++++++++++---------------------
14 drivers/dma/bcm2708-dmaengine.c | 14 ++++-----
15 drivers/mmc/host/bcm2835-mmc.c | 24 +++++++-------
16 drivers/of/fdt.c | 6 +++-
17 sound/soc/bcm/bcm2708-i2s.c | 29 +++++++++++------
18 sound/soc/bcm/bcm2835-i2s.c | 1 +
19 6 files changed, 80 insertions(+), 64 deletions(-)
20
21 --- a/arch/arm/mach-bcm2708/bcm2708.c
22 +++ b/arch/arm/mach-bcm2708/bcm2708.c
23 @@ -35,6 +35,7 @@
24 #include <linux/module.h>
25 #include <linux/of_platform.h>
26 #include <linux/spi/spi.h>
27 +#include <linux/gpio/machine.h>
28 #include <linux/w1-gpio.h>
29
30 #include <linux/version.h>
31 @@ -93,6 +94,8 @@ static unsigned reboot_part = 0;
32 static unsigned w1_gpio_pin = W1_GPIO;
33 static unsigned w1_gpio_pullup = W1_PULLUP;
34
35 +static unsigned use_dt = 0;
36 +
37 static void __init bcm2708_init_led(void);
38
39 void __init bcm2708_init_irq(void)
40 @@ -514,7 +517,6 @@ static struct platform_device bcm2708_al
41 },
42 };
43
44 -#ifndef CONFIG_OF
45 static struct resource bcm2708_spi_resources[] = {
46 {
47 .start = SPI0_BASE,
48 @@ -538,7 +540,6 @@ static struct platform_device bcm2708_sp
49 .dma_mask = &bcm2708_spi_dmamask,
50 .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
51 };
52 -#endif
53
54 #ifdef CONFIG_BCM2708_SPIDEV
55 static struct spi_board_info bcm2708_spi_devices[] = {
56 @@ -560,7 +561,6 @@ static struct spi_board_info bcm2708_spi
57 };
58 #endif
59
60 -#ifndef CONFIG_OF
61 static struct resource bcm2708_bsc0_resources[] = {
62 {
63 .start = BSC0_BASE,
64 @@ -599,7 +599,6 @@ static struct platform_device bcm2708_bs
65 .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
66 .resource = bcm2708_bsc1_resources,
67 };
68 -#endif
69
70 static struct platform_device bcm2835_hwmon_device = {
71 .name = "bcm2835_hwmon",
72 @@ -609,7 +608,7 @@ static struct platform_device bcm2835_th
73 .name = "bcm2835_thermal",
74 };
75
76 -#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
77 +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
78 static struct resource bcm2708_i2s_resources[] = {
79 {
80 .start = I2S_BASE,
81 @@ -731,14 +730,14 @@ int __init bcm_register_device(struct pl
82 }
83
84 /*
85 - * Use this macro for platform devices that are present in the Device Tree.
86 - * This way the device is only added on non-DT builds.
87 + * Use these macros for platform and i2c devices that are present in the
88 + * Device Tree. This way the devices are only added on non-DT systems.
89 */
90 -#ifdef CONFIG_OF
91 -#define bcm_register_device_dt(pdev)
92 -#else
93 -#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
94 -#endif
95 +#define bcm_register_device_dt(pdev) \
96 + if (!use_dt) bcm_register_device(pdev)
97 +
98 +#define i2c_register_board_info_dt(busnum, info, n) \
99 + if (!use_dt) i2c_register_board_info(busnum, info, n)
100
101 int calc_rsts(int partition)
102 {
103 @@ -814,7 +813,9 @@ static void __init bcm2708_dt_init(void)
104 ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
105 if (ret) {
106 pr_err("of_platform_populate failed: %d\n", ret);
107 - BUG();
108 + /* Proceed as if CONFIG_OF was not defined */
109 + } else {
110 + use_dt = 1;
111 }
112 }
113 #else
114 @@ -842,7 +843,7 @@ void __init bcm2708_init(void)
115 #if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
116 w1_gpio_pdata.pin = w1_gpio_pin;
117 w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
118 - platform_device_register(&w1_device);
119 + bcm_register_device_dt(&w1_device);
120 #endif
121 bcm_register_device(&bcm2708_systemtimer_device);
122 bcm_register_device(&bcm2708_fb_device);
123 @@ -857,46 +858,45 @@ void __init bcm2708_init(void)
124 for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
125 bcm_register_device(&bcm2708_alsa_devices[i]);
126
127 + bcm_register_device(&bcm2835_hwmon_device);
128 + bcm_register_device(&bcm2835_thermal_device);
129 +
130 bcm_register_device_dt(&bcm2708_spi_device);
131 bcm_register_device_dt(&bcm2708_bsc0_device);
132 bcm_register_device_dt(&bcm2708_bsc1_device);
133
134 - bcm_register_device(&bcm2835_hwmon_device);
135 - bcm_register_device(&bcm2835_thermal_device);
136 -
137 -#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
138 - bcm_register_device(&bcm2708_i2s_device);
139 +#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
140 + bcm_register_device_dt(&bcm2708_i2s_device);
141 #endif
142
143 #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
144 - bcm_register_device(&snd_hifiberry_dac_device);
145 - bcm_register_device(&snd_pcm5102a_codec_device);
146 + bcm_register_device_dt(&snd_hifiberry_dac_device);
147 + bcm_register_device_dt(&snd_pcm5102a_codec_device);
148 #endif
149
150 #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
151 - bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
152 - i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
153 + bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
154 + i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
155 #endif
156
157 #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
158 - bcm_register_device(&snd_hifiberry_digi_device);
159 - i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
160 + bcm_register_device_dt(&snd_hifiberry_digi_device);
161 + i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
162 #endif
163
164 #if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
165 - bcm_register_device(&snd_hifiberry_amp_device);
166 - i2c_register_board_info(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
167 + bcm_register_device_dt(&snd_hifiberry_amp_device);
168 + i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
169 #endif
170
171 -
172 #if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
173 - bcm_register_device(&snd_rpi_dac_device);
174 - bcm_register_device(&snd_pcm1794a_codec_device);
175 + bcm_register_device_dt(&snd_rpi_dac_device);
176 + bcm_register_device_dt(&snd_pcm1794a_codec_device);
177 #endif
178
179 #if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
180 - bcm_register_device(&snd_rpi_iqaudio_dac_device);
181 - i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
182 + bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
183 + i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
184 #endif
185
186
187 @@ -1041,9 +1041,9 @@ static struct platform_device bcm2708_le
188
189 static void __init bcm2708_init_led(void)
190 {
191 - bcm2708_leds[0].gpio = disk_led_gpio;
192 - bcm2708_leds[0].active_low = disk_led_active_low;
193 - platform_device_register(&bcm2708_led_device);
194 + bcm2708_leds[0].gpio = disk_led_gpio;
195 + bcm2708_leds[0].active_low = disk_led_active_low;
196 + bcm_register_device_dt(&bcm2708_led_device);
197 }
198 #else
199 static inline void bcm2708_init_led(void)
200 --- a/drivers/dma/bcm2708-dmaengine.c
201 +++ b/drivers/dma/bcm2708-dmaengine.c
202 @@ -42,7 +42,7 @@
203 #include <linux/io.h>
204 #include <linux/spinlock.h>
205
206 -#ifndef CONFIG_OF
207 +#ifndef CONFIG_ARCH_BCM2835
208
209 /* dma manager */
210 #include <mach/dma.h>
211 @@ -721,7 +721,7 @@ static int bcm2835_dma_control(struct dm
212 }
213 }
214
215 -#ifdef CONFIG_OF
216 +#ifdef CONFIG_ARCH_BCM2835
217 static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
218 {
219 struct bcm2835_chan *c;
220 @@ -784,7 +784,7 @@ static const struct of_device_id bcm2835
221 };
222 MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
223
224 -#ifdef CONFIG_OF
225 +#ifdef CONFIG_ARCH_BCM2835
226 static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
227 struct of_dma *ofdma)
228 {
229 @@ -817,7 +817,7 @@ static int bcm2835_dma_device_slave_caps
230 static int bcm2835_dma_probe(struct platform_device *pdev)
231 {
232 struct bcm2835_dmadev *od;
233 -#ifdef CONFIG_OF
234 +#ifdef CONFIG_ARCH_BCM2835
235 struct resource *res;
236 void __iomem *base;
237 uint32_t chans_available;
238 @@ -830,10 +830,10 @@ static int bcm2835_dma_probe(struct plat
239 if (!pdev->dev.dma_mask)
240 pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
241
242 - /* If CONFIG_OF is selected, device tree is used */
243 + /* If CONFIG_ARCH_BCM2835 is selected, device tree is used */
244 /* hence the difference between probing */
245
246 -#ifndef CONFIG_OF
247 +#ifndef CONFIG_ARCH_BCM2835
248
249 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
250 if (rc)
251 @@ -987,7 +987,7 @@ static int bcm2835_dma_remove(struct pla
252 return 0;
253 }
254
255 -#ifndef CONFIG_OF
256 +#ifndef CONFIG_ARCH_BCM2835
257
258
259 static struct platform_driver bcm2835_dma_driver = {
260 --- a/drivers/mmc/host/bcm2835-mmc.c
261 +++ b/drivers/mmc/host/bcm2835-mmc.c
262 @@ -42,7 +42,7 @@
263 #include "sdhci.h"
264
265
266 -#ifndef CONFIG_OF
267 +#ifndef CONFIG_ARCH_BCM2835
268 #define BCM2835_CLOCK_FREQ 250000000
269 #endif
270
271 @@ -662,7 +662,7 @@ void bcm2835_mmc_send_command(struct bcm
272 }
273
274 timeout = jiffies;
275 -#ifdef CONFIG_OF
276 +#ifdef CONFIG_ARCH_BCM2835
277 if (!cmd->data && cmd->busy_timeout > 9000)
278 timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
279 else
280 @@ -962,7 +962,7 @@ static irqreturn_t bcm2835_mmc_irq(int i
281 struct bcm2835_host *host = dev_id;
282 u32 intmask, mask, unexpected = 0;
283 int max_loops = 16;
284 -#ifndef CONFIG_OF
285 +#ifndef CONFIG_ARCH_BCM2835
286 int cardint = 0;
287 #endif
288
289 @@ -993,7 +993,7 @@ static irqreturn_t bcm2835_mmc_irq(int i
290 mmc_hostname(host->mmc));
291
292 if (intmask & SDHCI_INT_CARD_INT) {
293 -#ifndef CONFIG_OF
294 +#ifndef CONFIG_ARCH_BCM2835
295 cardint = 1;
296 #else
297 bcm2835_mmc_enable_sdio_irq_nolock(host, false);
298 @@ -1026,7 +1026,7 @@ out:
299 bcm2835_mmc_dumpregs(host);
300 }
301
302 -#ifndef CONFIG_OF
303 +#ifndef CONFIG_ARCH_BCM2835
304 if (cardint)
305 mmc_signal_sdio_irq(host->mmc);
306 #endif
307 @@ -1034,7 +1034,7 @@ out:
308 return result;
309 }
310
311 -#ifdef CONFIG_OF
312 +#ifdef CONFIG_ARCH_BCM2835
313 static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
314 {
315 struct bcm2835_host *host = dev_id;
316 @@ -1288,7 +1288,7 @@ int bcm2835_mmc_add_host(struct bcm2835_
317
318 /* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
319 host->timeout_clk = mmc->f_max / 1000;
320 -#ifdef CONFIG_OF
321 +#ifdef CONFIG_ARCH_BCM2835
322 mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
323 #endif
324 /* host controller capabilities */
325 @@ -1345,7 +1345,7 @@ int bcm2835_mmc_add_host(struct bcm2835_
326 init_waitqueue_head(&host->buf_ready_int);
327
328 bcm2835_mmc_init(host, 0);
329 -#ifndef CONFIG_OF
330 +#ifndef CONFIG_ARCH_BCM2835
331 ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
332 mmc_hostname(mmc), host);
333 #else
334 @@ -1374,7 +1374,7 @@ untasklet:
335 static int bcm2835_mmc_probe(struct platform_device *pdev)
336 {
337 struct device *dev = &pdev->dev;
338 -#ifdef CONFIG_OF
339 +#ifdef CONFIG_ARCH_BCM2835
340 struct device_node *node = dev->of_node;
341 struct clk *clk;
342 #endif
343 @@ -1383,7 +1383,7 @@ static int bcm2835_mmc_probe(struct plat
344
345 int ret;
346 struct mmc_host *mmc;
347 -#if !defined(CONFIG_OF) && !defined(FORCE_PIO)
348 +#if !defined(CONFIG_ARCH_BCM2835) && !defined(FORCE_PIO)
349 dma_cap_mask_t mask;
350 #endif
351
352 @@ -1408,7 +1408,7 @@ static int bcm2835_mmc_probe(struct plat
353
354 host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
355
356 -#ifndef CONFIG_OF
357 +#ifndef CONFIG_ARCH_BCM2835
358 #ifndef FORCE_PIO
359 dma_cap_zero(mask);
360 /* we don't care about the channel, any would work */
361 @@ -1458,7 +1458,7 @@ static int bcm2835_mmc_probe(struct plat
362 }
363
364
365 -#ifndef CONFIG_OF
366 +#ifndef CONFIG_ARCH_BCM2835
367 mmc->caps |= MMC_CAP_4_BIT_DATA;
368 #else
369 mmc_of_parse(mmc);
370 --- a/drivers/of/fdt.c
371 +++ b/drivers/of/fdt.c
372 @@ -1086,8 +1086,12 @@ static struct debugfs_blob_wrapper flat_
373
374 static int __init of_flat_dt_debugfs_export_fdt(void)
375 {
376 - struct dentry *d = debugfs_create_dir("device-tree", NULL);
377 + struct dentry *d;
378
379 + if (!initial_boot_params)
380 + return -ENOENT;
381 +
382 + d = debugfs_create_dir("device-tree", NULL);
383 if (!d)
384 return -ENOENT;
385
386 --- a/sound/soc/bcm/bcm2708-i2s.c
387 +++ b/sound/soc/bcm/bcm2708-i2s.c
388 @@ -493,15 +493,19 @@ static int bcm2708_i2s_hw_params(struct
389 divf = dividend & BCM2708_CLK_DIVF_MASK;
390 }
391
392 - /* Set clock divider */
393 - regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
394 - | BCM2708_CLK_DIVI(divi)
395 - | BCM2708_CLK_DIVF(divf));
396 -
397 - /* Setup clock, but don't start it yet */
398 - regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
399 - | BCM2708_CLK_MASH(mash)
400 - | BCM2708_CLK_SRC(clk_src));
401 + /* Clock should only be set up here if CPU is clock master */
402 + if (((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFS) ||
403 + ((dev->fmt & SND_SOC_DAIFMT_MASTER_MASK) == SND_SOC_DAIFMT_CBS_CFM)) {
404 + /* Set clock divider */
405 + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMDIV_REG, BCM2708_CLK_PASSWD
406 + | BCM2708_CLK_DIVI(divi)
407 + | BCM2708_CLK_DIVF(divf));
408 +
409 + /* Setup clock, but don't start it yet */
410 + regmap_write(dev->clk_regmap, BCM2708_CLK_PCMCTL_REG, BCM2708_CLK_PASSWD
411 + | BCM2708_CLK_MASH(mash)
412 + | BCM2708_CLK_SRC(clk_src));
413 + }
414
415 /* Setup the frame format */
416 format = BCM2708_I2S_CHEN;
417 @@ -981,12 +985,19 @@ static int bcm2708_i2s_remove(struct pla
418 return 0;
419 }
420
421 +static const struct of_device_id bcm2708_i2s_of_match[] = {
422 + { .compatible = "brcm,bcm2708-i2s", },
423 + {},
424 +};
425 +MODULE_DEVICE_TABLE(of, bcm2708_i2s_of_match);
426 +
427 static struct platform_driver bcm2708_i2s_driver = {
428 .probe = bcm2708_i2s_probe,
429 .remove = bcm2708_i2s_remove,
430 .driver = {
431 .name = "bcm2708-i2s",
432 .owner = THIS_MODULE,
433 + .of_match_table = bcm2708_i2s_of_match,
434 },
435 };
436
437 --- a/sound/soc/bcm/bcm2835-i2s.c
438 +++ b/sound/soc/bcm/bcm2835-i2s.c
439 @@ -861,6 +861,7 @@ static const struct of_device_id bcm2835
440 { .compatible = "brcm,bcm2835-i2s", },
441 {},
442 };
443 +MODULE_DEVICE_TABLE(of, bcm2835_i2s_of_match);
444
445 static struct platform_driver bcm2835_i2s_driver = {
446 .probe = bcm2835_i2s_probe,