Skip to content

Commit c14827e

Browse files
Phil Elwellpopcornmix
Phil Elwell
authored andcommitted
bcm2708: Allow option card devices to be configured via DT
If the kernel is built with Device Tree support, and if a DT blob is provided for the kernel at boot time, then the platform devices for option cards are not created. This avoids both the need to blacklist unwanted devices, and the need to update the board support code with each new device.
1 parent 10c8bd7 commit c14827e

File tree

6 files changed

+80
-64
lines changed

6 files changed

+80
-64
lines changed

arch/arm/mach-bcm2708/bcm2708.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <linux/module.h>
3636
#include <linux/of_platform.h>
3737
#include <linux/spi/spi.h>
38+
#include <linux/gpio/machine.h>
3839
#include <linux/w1-gpio.h>
3940

4041
#include <linux/version.h>
@@ -93,6 +94,8 @@ static unsigned reboot_part = 0;
9394
static unsigned w1_gpio_pin = W1_GPIO;
9495
static unsigned w1_gpio_pullup = W1_PULLUP;
9596

97+
static unsigned use_dt = 0;
98+
9699
static void __init bcm2708_init_led(void);
97100

98101
void __init bcm2708_init_irq(void)
@@ -514,7 +517,6 @@ static struct platform_device bcm2708_alsa_devices[] = {
514517
},
515518
};
516519

517-
#ifndef CONFIG_OF
518520
static struct resource bcm2708_spi_resources[] = {
519521
{
520522
.start = SPI0_BASE,
@@ -538,7 +540,6 @@ static struct platform_device bcm2708_spi_device = {
538540
.dma_mask = &bcm2708_spi_dmamask,
539541
.coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
540542
};
541-
#endif
542543

543544
#ifdef CONFIG_BCM2708_SPIDEV
544545
static struct spi_board_info bcm2708_spi_devices[] = {
@@ -560,7 +561,6 @@ static struct spi_board_info bcm2708_spi_devices[] = {
560561
};
561562
#endif
562563

563-
#ifndef CONFIG_OF
564564
static struct resource bcm2708_bsc0_resources[] = {
565565
{
566566
.start = BSC0_BASE,
@@ -599,7 +599,6 @@ static struct platform_device bcm2708_bsc1_device = {
599599
.num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
600600
.resource = bcm2708_bsc1_resources,
601601
};
602-
#endif
603602

604603
static struct platform_device bcm2835_hwmon_device = {
605604
.name = "bcm2835_hwmon",
@@ -609,7 +608,7 @@ static struct platform_device bcm2835_thermal_device = {
609608
.name = "bcm2835_thermal",
610609
};
611610

612-
#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
611+
#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
613612
static struct resource bcm2708_i2s_resources[] = {
614613
{
615614
.start = I2S_BASE,
@@ -731,14 +730,14 @@ int __init bcm_register_device(struct platform_device *pdev)
731730
}
732731

733732
/*
734-
* Use this macro for platform devices that are present in the Device Tree.
735-
* This way the device is only added on non-DT builds.
733+
* Use these macros for platform and i2c devices that are present in the
734+
* Device Tree. This way the devices are only added on non-DT systems.
736735
*/
737-
#ifdef CONFIG_OF
738-
#define bcm_register_device_dt(pdev)
739-
#else
740-
#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
741-
#endif
736+
#define bcm_register_device_dt(pdev) \
737+
if (!use_dt) bcm_register_device(pdev)
738+
739+
#define i2c_register_board_info_dt(busnum, info, n) \
740+
if (!use_dt) i2c_register_board_info(busnum, info, n)
742741

743742
int calc_rsts(int partition)
744743
{
@@ -814,7 +813,9 @@ static void __init bcm2708_dt_init(void)
814813
ret = of_platform_populate(NULL, of_default_bus_match_table, NULL, NULL);
815814
if (ret) {
816815
pr_err("of_platform_populate failed: %d\n", ret);
817-
BUG();
816+
/* Proceed as if CONFIG_OF was not defined */
817+
} else {
818+
use_dt = 1;
818819
}
819820
}
820821
#else
@@ -842,7 +843,7 @@ void __init bcm2708_init(void)
842843
#if defined(CONFIG_W1_MASTER_GPIO) || defined(CONFIG_W1_MASTER_GPIO_MODULE)
843844
w1_gpio_pdata.pin = w1_gpio_pin;
844845
w1_gpio_pdata.ext_pullup_enable_pin = w1_gpio_pullup;
845-
platform_device_register(&w1_device);
846+
bcm_register_device_dt(&w1_device);
846847
#endif
847848
bcm_register_device(&bcm2708_systemtimer_device);
848849
bcm_register_device(&bcm2708_fb_device);
@@ -857,46 +858,45 @@ void __init bcm2708_init(void)
857858
for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
858859
bcm_register_device(&bcm2708_alsa_devices[i]);
859860

861+
bcm_register_device(&bcm2835_hwmon_device);
862+
bcm_register_device(&bcm2835_thermal_device);
863+
860864
bcm_register_device_dt(&bcm2708_spi_device);
861865
bcm_register_device_dt(&bcm2708_bsc0_device);
862866
bcm_register_device_dt(&bcm2708_bsc1_device);
863867

864-
bcm_register_device(&bcm2835_hwmon_device);
865-
bcm_register_device(&bcm2835_thermal_device);
866-
867-
#ifdef CONFIG_SND_BCM2708_SOC_I2S_MODULE
868-
bcm_register_device(&bcm2708_i2s_device);
868+
#if defined(CONFIG_SND_BCM2708_SOC_I2S) || defined(CONFIG_SND_BCM2708_SOC_I2S_MODULE)
869+
bcm_register_device_dt(&bcm2708_i2s_device);
869870
#endif
870871

871872
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DAC_MODULE)
872-
bcm_register_device(&snd_hifiberry_dac_device);
873-
bcm_register_device(&snd_pcm5102a_codec_device);
873+
bcm_register_device_dt(&snd_hifiberry_dac_device);
874+
bcm_register_device_dt(&snd_pcm5102a_codec_device);
874875
#endif
875876

876877
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DACPLUS_MODULE)
877-
bcm_register_device(&snd_rpi_hifiberry_dacplus_device);
878-
i2c_register_board_info(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
878+
bcm_register_device_dt(&snd_rpi_hifiberry_dacplus_device);
879+
i2c_register_board_info_dt(1, snd_pcm512x_hbdacplus_i2c_devices, ARRAY_SIZE(snd_pcm512x_hbdacplus_i2c_devices));
879880
#endif
880881

881882
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_DIGI_MODULE)
882-
bcm_register_device(&snd_hifiberry_digi_device);
883-
i2c_register_board_info(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
883+
bcm_register_device_dt(&snd_hifiberry_digi_device);
884+
i2c_register_board_info_dt(1, snd_wm8804_i2c_devices, ARRAY_SIZE(snd_wm8804_i2c_devices));
884885
#endif
885886

886887
#if defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP) || defined(CONFIG_SND_BCM2708_SOC_HIFIBERRY_AMP_MODULE)
887-
bcm_register_device(&snd_hifiberry_amp_device);
888-
i2c_register_board_info(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
888+
bcm_register_device_dt(&snd_hifiberry_amp_device);
889+
i2c_register_board_info_dt(1, snd_tas5713_i2c_devices, ARRAY_SIZE(snd_tas5713_i2c_devices));
889890
#endif
890891

891-
892892
#if defined(CONFIG_SND_BCM2708_SOC_RPI_DAC) || defined(CONFIG_SND_BCM2708_SOC_RPI_DAC_MODULE)
893-
bcm_register_device(&snd_rpi_dac_device);
894-
bcm_register_device(&snd_pcm1794a_codec_device);
893+
bcm_register_device_dt(&snd_rpi_dac_device);
894+
bcm_register_device_dt(&snd_pcm1794a_codec_device);
895895
#endif
896896

897897
#if defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC) || defined(CONFIG_SND_BCM2708_SOC_IQAUDIO_DAC_MODULE)
898-
bcm_register_device(&snd_rpi_iqaudio_dac_device);
899-
i2c_register_board_info(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
898+
bcm_register_device_dt(&snd_rpi_iqaudio_dac_device);
899+
i2c_register_board_info_dt(1, snd_pcm512x_i2c_devices, ARRAY_SIZE(snd_pcm512x_i2c_devices));
900900
#endif
901901

902902

@@ -1040,9 +1040,9 @@ static struct platform_device bcm2708_led_device = {
10401040

10411041
static void __init bcm2708_init_led(void)
10421042
{
1043-
bcm2708_leds[0].gpio = disk_led_gpio;
1044-
bcm2708_leds[0].active_low = disk_led_active_low;
1045-
platform_device_register(&bcm2708_led_device);
1043+
bcm2708_leds[0].gpio = disk_led_gpio;
1044+
bcm2708_leds[0].active_low = disk_led_active_low;
1045+
bcm_register_device_dt(&bcm2708_led_device);
10461046
}
10471047
#else
10481048
static inline void bcm2708_init_led(void)

drivers/dma/bcm2708-dmaengine.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include <linux/io.h>
4343
#include <linux/spinlock.h>
4444

45-
#ifndef CONFIG_OF
45+
#ifndef CONFIG_ARCH_BCM2835
4646

4747
/* dma manager */
4848
#include <mach/dma.h>
@@ -710,7 +710,7 @@ static int bcm2835_dma_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
710710
}
711711
}
712712

713-
#ifdef CONFIG_OF
713+
#ifdef CONFIG_ARCH_BCM2835
714714
static int bcm2835_dma_chan_init(struct bcm2835_dmadev *d, int chan_id, int irq)
715715
{
716716
struct bcm2835_chan *c;
@@ -773,7 +773,7 @@ static const struct of_device_id bcm2835_dma_of_match[] = {
773773
};
774774
MODULE_DEVICE_TABLE(of, bcm2835_dma_of_match);
775775

776-
#ifdef CONFIG_OF
776+
#ifdef CONFIG_ARCH_BCM2835
777777
static struct dma_chan *bcm2835_dma_xlate(struct of_phandle_args *spec,
778778
struct of_dma *ofdma)
779779
{
@@ -806,7 +806,7 @@ static int bcm2835_dma_device_slave_caps(struct dma_chan *dchan,
806806
static int bcm2835_dma_probe(struct platform_device *pdev)
807807
{
808808
struct bcm2835_dmadev *od;
809-
#ifdef CONFIG_OF
809+
#ifdef CONFIG_ARCH_BCM2835
810810
struct resource *res;
811811
void __iomem *base;
812812
uint32_t chans_available;
@@ -819,10 +819,10 @@ static int bcm2835_dma_probe(struct platform_device *pdev)
819819
if (!pdev->dev.dma_mask)
820820
pdev->dev.dma_mask = &pdev->dev.coherent_dma_mask;
821821

822-
/* If CONFIG_OF is selected, device tree is used */
822+
/* If CONFIG_ARCH_BCM2835 is selected, device tree is used */
823823
/* hence the difference between probing */
824824

825-
#ifndef CONFIG_OF
825+
#ifndef CONFIG_ARCH_BCM2835
826826

827827
rc = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
828828
if (rc)
@@ -976,7 +976,7 @@ static int bcm2835_dma_remove(struct platform_device *pdev)
976976
return 0;
977977
}
978978

979-
#ifndef CONFIG_OF
979+
#ifndef CONFIG_ARCH_BCM2835
980980

981981

982982
static struct platform_driver bcm2835_dma_driver = {

drivers/mmc/host/bcm2835-mmc.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
#include "sdhci.h"
4343

4444

45-
#ifndef CONFIG_OF
45+
#ifndef CONFIG_ARCH_BCM2835
4646
#define BCM2835_CLOCK_FREQ 250000000
4747
#endif
4848

@@ -662,7 +662,7 @@ void bcm2835_mmc_send_command(struct bcm2835_host *host, struct mmc_command *cmd
662662
}
663663

664664
timeout = jiffies;
665-
#ifdef CONFIG_OF
665+
#ifdef CONFIG_ARCH_BCM2835
666666
if (!cmd->data && cmd->busy_timeout > 9000)
667667
timeout += DIV_ROUND_UP(cmd->busy_timeout, 1000) * HZ + HZ;
668668
else
@@ -957,7 +957,7 @@ static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
957957
struct bcm2835_host *host = dev_id;
958958
u32 intmask, mask, unexpected = 0;
959959
int max_loops = 16;
960-
#ifndef CONFIG_OF
960+
#ifndef CONFIG_ARCH_BCM2835
961961
int cardint = 0;
962962
#endif
963963

@@ -988,7 +988,7 @@ static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
988988
mmc_hostname(host->mmc));
989989

990990
if (intmask & SDHCI_INT_CARD_INT) {
991-
#ifndef CONFIG_OF
991+
#ifndef CONFIG_ARCH_BCM2835
992992
cardint = 1;
993993
#else
994994
bcm2835_mmc_enable_sdio_irq_nolock(host, false);
@@ -1021,15 +1021,15 @@ static irqreturn_t bcm2835_mmc_irq(int irq, void *dev_id)
10211021
bcm2835_mmc_dumpregs(host);
10221022
}
10231023

1024-
#ifndef CONFIG_OF
1024+
#ifndef CONFIG_ARCH_BCM2835
10251025
if (cardint)
10261026
mmc_signal_sdio_irq(host->mmc);
10271027
#endif
10281028

10291029
return result;
10301030
}
10311031

1032-
#ifdef CONFIG_OF
1032+
#ifdef CONFIG_ARCH_BCM2835
10331033
static irqreturn_t bcm2835_mmc_thread_irq(int irq, void *dev_id)
10341034
{
10351035
struct bcm2835_host *host = dev_id;
@@ -1278,7 +1278,7 @@ int bcm2835_mmc_add_host(struct bcm2835_host *host)
12781278

12791279
/* SDHCI_QUIRK_DATA_TIMEOUT_USES_SDCLK */
12801280
host->timeout_clk = mmc->f_max / 1000;
1281-
#ifdef CONFIG_OF
1281+
#ifdef CONFIG_ARCH_BCM2835
12821282
mmc->max_busy_timeout = (1 << 27) / host->timeout_clk;
12831283
#endif
12841284
/* host controller capabilities */
@@ -1335,7 +1335,7 @@ int bcm2835_mmc_add_host(struct bcm2835_host *host)
13351335
init_waitqueue_head(&host->buf_ready_int);
13361336

13371337
bcm2835_mmc_init(host, 0);
1338-
#ifndef CONFIG_OF
1338+
#ifndef CONFIG_ARCH_BCM2835
13391339
ret = request_irq(host->irq, bcm2835_mmc_irq, 0 /*IRQF_SHARED*/,
13401340
mmc_hostname(mmc), host);
13411341
#else
@@ -1364,7 +1364,7 @@ int bcm2835_mmc_add_host(struct bcm2835_host *host)
13641364
static int bcm2835_mmc_probe(struct platform_device *pdev)
13651365
{
13661366
struct device *dev = &pdev->dev;
1367-
#ifdef CONFIG_OF
1367+
#ifdef CONFIG_ARCH_BCM2835
13681368
struct device_node *node = dev->of_node;
13691369
struct clk *clk;
13701370
#endif
@@ -1373,7 +1373,7 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
13731373

13741374
int ret;
13751375
struct mmc_host *mmc;
1376-
#if !defined(CONFIG_OF) && !defined(FORCE_PIO)
1376+
#if !defined(CONFIG_ARCH_BCM2835) && !defined(FORCE_PIO)
13771377
dma_cap_mask_t mask;
13781378
#endif
13791379

@@ -1398,7 +1398,7 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
13981398

13991399
host->phys_addr = iomem->start + BCM2835_VCMMU_SHIFT;
14001400

1401-
#ifndef CONFIG_OF
1401+
#ifndef CONFIG_ARCH_BCM2835
14021402
#ifndef FORCE_PIO
14031403
dma_cap_zero(mask);
14041404
/* we don't care about the channel, any would work */
@@ -1448,7 +1448,7 @@ static int bcm2835_mmc_probe(struct platform_device *pdev)
14481448
}
14491449

14501450

1451-
#ifndef CONFIG_OF
1451+
#ifndef CONFIG_ARCH_BCM2835
14521452
mmc->caps |= MMC_CAP_4_BIT_DATA;
14531453
#else
14541454
mmc_of_parse(mmc);

drivers/of/fdt.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,8 +1083,12 @@ static struct debugfs_blob_wrapper flat_dt_blob;
10831083

10841084
static int __init of_flat_dt_debugfs_export_fdt(void)
10851085
{
1086-
struct dentry *d = debugfs_create_dir("device-tree", NULL);
1086+
struct dentry *d;
10871087

1088+
if (!initial_boot_params)
1089+
return -ENOENT;
1090+
1091+
d = debugfs_create_dir("device-tree", NULL);
10881092
if (!d)
10891093
return -ENOENT;
10901094

0 commit comments

Comments
 (0)