0052-spi-bcm2708-add-device-tree-support.patch 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  1. From 5de6baef9b5d9e3a84e0c3752cfb7eaef2eb1a0f Mon Sep 17 00:00:00 2001
  2. From: notro <notro@tronnes.org>
  3. Date: Sun, 27 Jul 2014 20:12:58 +0200
  4. Subject: [PATCH 052/114] spi: bcm2708: add device tree support
  5. Add DT support to driver and add to .dtsi file.
  6. Setup pins and spidev in .dts file.
  7. SPI is disabled by default.
  8. Signed-off-by: Noralf Tronnes <notro@tronnes.org>
  9. BCM2708: don't register SPI controller when using DT
  10. The device for the SPI controller is in the Device Tree.
  11. Only register the device when not using DT.
  12. Signed-off-by: Noralf Tronnes <notro@tronnes.org>
  13. spi: bcm2835: make driver available on ARCH_BCM2708
  14. Make this driver available on ARCH_BCM2708
  15. Signed-off-by: Noralf Tronnes <notro@tronnes.org>
  16. bcm2708: Remove the prohibition on mixing SPIDEV and DT
  17. ---
  18. arch/arm/boot/dts/bcm2708-rpi-b.dts | 32 ++++++++++++++++++++++++++++++++
  19. arch/arm/boot/dts/bcm2708.dtsi | 18 ++++++++++++++++++
  20. arch/arm/mach-bcm2708/bcm2708.c | 19 ++++++++++++++++---
  21. drivers/spi/Kconfig | 2 +-
  22. drivers/spi/spi-bcm2708.c | 8 ++++++++
  23. 5 files changed, 75 insertions(+), 4 deletions(-)
  24. --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
  25. +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
  26. @@ -5,4 +5,36 @@
  27. / {
  28. compatible = "brcm,bcm2708";
  29. model = "Raspberry Pi";
  30. +
  31. + aliases {
  32. + spi0 = &spi0;
  33. + };
  34. +};
  35. +
  36. +&gpio {
  37. + spi0_pins: spi0_pins {
  38. + brcm,pins = <7 8 9 10 11>;
  39. + brcm,function = <4>; /* alt0 */
  40. + };
  41. +};
  42. +
  43. +&spi0 {
  44. + pinctrl-names = "default";
  45. + pinctrl-0 = <&spi0_pins>;
  46. +
  47. + spidev@0{
  48. + compatible = "spidev";
  49. + reg = <0>; /* CE0 */
  50. + #address-cells = <1>;
  51. + #size-cells = <0>;
  52. + spi-max-frequency = <500000>;
  53. + };
  54. +
  55. + spidev@1{
  56. + compatible = "spidev";
  57. + reg = <1>; /* CE1 */
  58. + #address-cells = <1>;
  59. + #size-cells = <0>;
  60. + spi-max-frequency = <500000>;
  61. + };
  62. };
  63. --- a/arch/arm/boot/dts/bcm2708.dtsi
  64. +++ b/arch/arm/boot/dts/bcm2708.dtsi
  65. @@ -38,11 +38,29 @@
  66. interrupt-controller;
  67. #interrupt-cells = <2>;
  68. };
  69. +
  70. + spi0: spi@7e204000 {
  71. + compatible = "brcm,bcm2708-spi";
  72. + reg = <0x7e204000 0x1000>;
  73. + interrupts = <2 22>;
  74. + clocks = <&clk_spi>;
  75. + #address-cells = <1>;
  76. + #size-cells = <0>;
  77. + status = "disabled";
  78. + };
  79. };
  80. clocks {
  81. compatible = "simple-bus";
  82. #address-cells = <1>;
  83. #size-cells = <0>;
  84. +
  85. + clk_spi: clock@2 {
  86. + compatible = "fixed-clock";
  87. + reg = <2>;
  88. + #clock-cells = <0>;
  89. + clock-output-names = "spi";
  90. + clock-frequency = <250000000>;
  91. + };
  92. };
  93. };
  94. --- a/arch/arm/mach-bcm2708/bcm2708.c
  95. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  96. @@ -486,6 +486,7 @@ static struct platform_device bcm2708_al
  97. },
  98. };
  99. +#ifndef CONFIG_OF
  100. static struct resource bcm2708_spi_resources[] = {
  101. {
  102. .start = SPI0_BASE,
  103. @@ -509,6 +510,7 @@ static struct platform_device bcm2708_sp
  104. .dma_mask = &bcm2708_spi_dmamask,
  105. .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON)},
  106. };
  107. +#endif
  108. #ifdef CONFIG_BCM2708_SPIDEV
  109. static struct spi_board_info bcm2708_spi_devices[] = {
  110. @@ -670,6 +672,16 @@ int __init bcm_register_device(struct pl
  111. return ret;
  112. }
  113. +/*
  114. + * Use this macro for platform devices that are present in the Device Tree.
  115. + * This way the device is only added on non-DT builds.
  116. + */
  117. +#ifdef CONFIG_OF
  118. +#define bcm_register_device_dt(pdev)
  119. +#else
  120. +#define bcm_register_device_dt(pdev) bcm_register_device(pdev)
  121. +#endif
  122. +
  123. int calc_rsts(int partition)
  124. {
  125. return PM_PASSWORD |
  126. @@ -784,7 +796,7 @@ void __init bcm2708_init(void)
  127. for (i = 0; i < ARRAY_SIZE(bcm2708_alsa_devices); i++)
  128. bcm_register_device(&bcm2708_alsa_devices[i]);
  129. - bcm_register_device(&bcm2708_spi_device);
  130. + bcm_register_device_dt(&bcm2708_spi_device);
  131. bcm_register_device(&bcm2708_bsc0_device);
  132. bcm_register_device(&bcm2708_bsc1_device);
  133. @@ -824,8 +836,9 @@ void __init bcm2708_init(void)
  134. system_serial_low = serial;
  135. #ifdef CONFIG_BCM2708_SPIDEV
  136. - spi_register_board_info(bcm2708_spi_devices,
  137. - ARRAY_SIZE(bcm2708_spi_devices));
  138. + if (!use_dt)
  139. + spi_register_board_info(bcm2708_spi_devices,
  140. + ARRAY_SIZE(bcm2708_spi_devices));
  141. #endif
  142. }
  143. --- a/drivers/spi/Kconfig
  144. +++ b/drivers/spi/Kconfig
  145. @@ -77,7 +77,7 @@ config SPI_ATMEL
  146. config SPI_BCM2835
  147. tristate "BCM2835 SPI controller"
  148. - depends on ARCH_BCM2835 || COMPILE_TEST
  149. + depends on ARCH_BCM2835 || ARCH_BCM2708 || COMPILE_TEST
  150. help
  151. This selects a driver for the Broadcom BCM2835 SPI master.
  152. --- a/drivers/spi/spi-bcm2708.c
  153. +++ b/drivers/spi/spi-bcm2708.c
  154. @@ -512,6 +512,7 @@ static int bcm2708_spi_probe(struct plat
  155. master->setup = bcm2708_spi_setup;
  156. master->transfer = bcm2708_spi_transfer;
  157. master->cleanup = bcm2708_spi_cleanup;
  158. + master->dev.of_node = pdev->dev.of_node;
  159. platform_set_drvdata(pdev, master);
  160. bs = spi_master_get_devdata(master);
  161. @@ -596,10 +597,17 @@ static int bcm2708_spi_remove(struct pla
  162. return 0;
  163. }
  164. +static const struct of_device_id bcm2708_spi_match[] = {
  165. + { .compatible = "brcm,bcm2708-spi", },
  166. + {}
  167. +};
  168. +MODULE_DEVICE_TABLE(of, bcm2708_spi_match);
  169. +
  170. static struct platform_driver bcm2708_spi_driver = {
  171. .driver = {
  172. .name = DRV_NAME,
  173. .owner = THIS_MODULE,
  174. + .of_match_table = bcm2708_spi_match,
  175. },
  176. .probe = bcm2708_spi_probe,
  177. .remove = bcm2708_spi_remove,