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
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.
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(-)
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
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>
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;
37 +static unsigned use_dt = 0;
39 static void __init bcm2708_init_led(void);
41 void __init bcm2708_init_irq(void)
42 @@ -514,7 +517,6 @@ static struct platform_device bcm2708_alsa_devices[] = {
47 static struct resource bcm2708_spi_resources[] = {
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)},
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[] = {
63 static struct resource bcm2708_bsc0_resources[] = {
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,
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",
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[] = {
83 @@ -731,14 +730,14 @@ int __init bcm_register_device(struct platform_device *pdev)
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.
93 -#define bcm_register_device_dt(pdev)
95 -#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
97 +#define bcm_register_device_dt(pdev) \
98 + if (!use_dt) bcm_register_device(pdev)
100 +#define i2c_register_board_info_dt(busnum, info, n) \
101 + if (!use_dt) i2c_register_board_info(busnum, info, n)
103 int calc_rsts(int partition)
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);
108 pr_err("of_platform_populate failed: %d\n", ret);
110 + /* Proceed as if CONFIG_OF was not defined */
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);
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]);
129 + bcm_register_device(&bcm2835_hwmon_device);
130 + bcm_register_device(&bcm2835_thermal_device);
132 bcm_register_device_dt(&bcm2708_spi_device);
133 bcm_register_device_dt(&bcm2708_bsc0_device);
134 bcm_register_device_dt(&bcm2708_bsc1_device);
136 - bcm_register_device(&bcm2835_hwmon_device);
137 - bcm_register_device(&bcm2835_thermal_device);
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);
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);
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));
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));
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));
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);
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));
189 @@ -1041,9 +1041,9 @@ static struct platform_device bcm2708_led_device = {
191 static void __init bcm2708_init_led(void)
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);
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
207 #include <linux/io.h>
208 #include <linux/spinlock.h>
211 +#ifndef CONFIG_ARCH_BCM2835
214 #include <mach/dma.h>
215 @@ -721,7 +721,7 @@ static int bcm2835_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
220 +#ifdef CONFIG_ARCH_BCM2835
221 static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
223 struct bcm2835_chan *c;
224 @@ -784,7 +784,7 @@ static const struct of_device_id bcm2835_dma_of_match[] = {
226 MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
229 +#ifdef CONFIG_ARCH_BCM2835
230 static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
231 struct of_dma *ofdma)
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)
236 struct bcm2835_dmadev *od;
238 +#ifdef CONFIG_ARCH_BCM2835
239 struct resource *res;
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;
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 */
251 +#ifndef CONFIG_ARCH_BCM2835
253 rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
255 @@ -987,7 +987,7 @@ static int bcm2835_dma_remove(struct platform_device *pdev)
260 +#ifndef CONFIG_ARCH_BCM2835
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
273 +#ifndef CONFIG_ARCH_BCM2835
274 #define BCM2835_CLOCK_FREQ 250000000
277 @@ -662,7 +662,7 @@ void bcm2835_mmc_send_command(struct bcm2835_host *host, struct mmc_command *cmd
282 +#ifdef CONFIG_ARCH_BCM2835
283 if (!cmd->data && cmd->busy_timeout > 9000)
284 timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
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;
291 +#ifndef CONFIG_ARCH_BCM2835
295 @@ -993,7 +993,7 @@ static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
296 mmc_hostname(host->mmc));
298 if (intmask & SDHCI_INT_CARD_INT) {
300 +#ifndef CONFIG_ARCH_BCM2835
303 bcm2835_mmc_enable_sdio_irq_nolock(host, false);
304 @@ -1026,7 +1026,7 @@ out:
305 bcm2835_mmc_dumpregs(host);
309 +#ifndef CONFIG_ARCH_BCM2835
311 mmc_signal_sdio_irq(host->mmc);
313 @@ -1034,7 +1034,7 @@ out:
318 +#ifdef CONFIG_ARCH_BCM2835
319 static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
321 struct bcm2835_host *host = dev_id;
322 @@ -1288,7 +1288,7 @@ int bcm2835_mmc_add_host(struct bcm2835_host *host)
324 /* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
325 host->timeout_clk = mmc->f_max / 1000;
327 +#ifdef CONFIG_ARCH_BCM2835
328 mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
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);
334 bcm2835_mmc_init(host, 0);
336 +#ifndef CONFIG_ARCH_BCM2835
337 ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
338 mmc_hostname(mmc), host);
340 @@ -1374,7 +1374,7 @@ untasklet:
341 static int bcm2835_mmc_probe(struct platform_device *pdev)
343 struct device *dev = &pdev->dev;
345 +#ifdef CONFIG_ARCH_BCM2835
346 struct device_node *node = dev->of_node;
349 @@ -1383,7 +1383,7 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
352 struct mmc_host *mmc;
353 -#if !defined(CONFIG_OF) && !defined(FORCE_PIO)
354 +#if !defined(CONFIG_ARCH_BCM2835) && !defined(FORCE_PIO)
358 @@ -1408,7 +1408,7 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
360 host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
363 +#ifndef CONFIG_ARCH_BCM2835
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)
372 +#ifndef CONFIG_ARCH_BCM2835
373 mmc->caps |= MMC_CAP_4_BIT_DATA;
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;
382 static int __init of_flat_dt_debugfs_export_fdt(void)
384 - struct dentry *d = debugfs_create_dir("device-tree", NULL);
387 + if (!initial_boot_params)
390 + d = debugfs_create_dir("device-tree", NULL);
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;
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));
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));
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));
425 /* Setup the frame format */
426 format = BCM2708_I2S_CHEN;
427 @@ -981,12 +985,19 @@ static int bcm2708_i2s_remove(struct platform_device *pdev)
431 +static const struct of_device_id bcm2708_i2s_of_match[] = {
432 + { .compatible = "brcm,bcm2708-i2s", },
435 +MODULE_DEVICE_TABLE(of, bcm2708_i2s_of_match);
437 static struct platform_driver bcm2708_i2s_driver = {
438 .probe = bcm2708_i2s_probe,
439 .remove = bcm2708_i2s_remove,
441 .name = "bcm2708-i2s",
442 .owner = THIS_MODULE,
443 + .of_match_table = bcm2708_i2s_of_match,
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", },
455 +MODULE_DEVICE_TABLE(of, bcm2835_i2s_of_match);
457 static struct platform_driver bcm2835_i2s_driver = {
458 .probe = bcm2835_i2s_probe,