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