0063-bcm2708-Allow-option-card-devices-to-be-configured-v.patch 14 KB

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