0053-i2c-bcm2708-add-device-tree-support.patch 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. From 772f3f8c0c321b2817d35f48d553db023ead2d90 Mon Sep 17 00:00:00 2001
  2. From: notro <notro@tronnes.org>
  3. Date: Tue, 29 Jul 2014 11:04:49 +0200
  4. Subject: [PATCH 053/114] i2c: bcm2708: add device tree support
  5. Add DT support to driver and add to .dtsi file.
  6. Setup pins in .dts file.
  7. i2c is disabled by default.
  8. Signed-off-by: Noralf Tronnes <notro@tronnes.org>
  9. bcm2708: don't register i2c controllers when using DT
  10. The devices for the i2c controllers are in the Device Tree.
  11. Only register devices when not using DT.
  12. Signed-off-by: Noralf Tronnes <notro@tronnes.org>
  13. i2c: 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. ---
  17. arch/arm/boot/dts/bcm2708-rpi-b.dts | 24 ++++++++++++++++++++++++
  18. arch/arm/boot/dts/bcm2708.dtsi | 27 +++++++++++++++++++++++++++
  19. arch/arm/mach-bcm2708/bcm2708.c | 6 ++++--
  20. drivers/i2c/busses/Kconfig | 2 +-
  21. drivers/i2c/busses/i2c-bcm2708.c | 24 ++++++++++++++++++++++++
  22. 5 files changed, 80 insertions(+), 3 deletions(-)
  23. --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
  24. +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
  25. @@ -8,6 +8,8 @@
  26. aliases {
  27. spi0 = &spi0;
  28. + i2c0 = &i2c0;
  29. + i2c1 = &i2c1;
  30. };
  31. };
  32. @@ -16,6 +18,16 @@
  33. brcm,pins = <7 8 9 10 11>;
  34. brcm,function = <4>; /* alt0 */
  35. };
  36. +
  37. + i2c0_pins: i2c0 {
  38. + brcm,pins = <0 1>;
  39. + brcm,function = <4>;
  40. + };
  41. +
  42. + i2c1_pins: i2c1 {
  43. + brcm,pins = <2 3>;
  44. + brcm,function = <4>;
  45. + };
  46. };
  47. &spi0 {
  48. @@ -38,3 +50,15 @@
  49. spi-max-frequency = <500000>;
  50. };
  51. };
  52. +
  53. +&i2c0 {
  54. + pinctrl-names = "default";
  55. + pinctrl-0 = <&i2c0_pins>;
  56. + clock-frequency = <100000>;
  57. +};
  58. +
  59. +&i2c1 {
  60. + pinctrl-names = "default";
  61. + pinctrl-0 = <&i2c1_pins>;
  62. + clock-frequency = <100000>;
  63. +};
  64. --- a/arch/arm/boot/dts/bcm2708.dtsi
  65. +++ b/arch/arm/boot/dts/bcm2708.dtsi
  66. @@ -48,6 +48,26 @@
  67. #size-cells = <0>;
  68. status = "disabled";
  69. };
  70. +
  71. + i2c0: i2c@7e205000 {
  72. + compatible = "brcm,bcm2708-i2c";
  73. + reg = <0x7e205000 0x1000>;
  74. + interrupts = <2 21>;
  75. + clocks = <&clk_i2c>;
  76. + #address-cells = <1>;
  77. + #size-cells = <0>;
  78. + status = "disabled";
  79. + };
  80. +
  81. + i2c1: i2c@7e804000 {
  82. + compatible = "brcm,bcm2708-i2c";
  83. + reg = <0x7e804000 0x1000>;
  84. + interrupts = <2 21>;
  85. + clocks = <&clk_i2c>;
  86. + #address-cells = <1>;
  87. + #size-cells = <0>;
  88. + status = "disabled";
  89. + };
  90. };
  91. clocks {
  92. @@ -55,6 +75,13 @@
  93. #address-cells = <1>;
  94. #size-cells = <0>;
  95. + clk_i2c: i2c {
  96. + compatible = "fixed-clock";
  97. + reg = <1>;
  98. + #clock-cells = <0>;
  99. + clock-frequency = <250000000>;
  100. + };
  101. +
  102. clk_spi: clock@2 {
  103. compatible = "fixed-clock";
  104. reg = <2>;
  105. --- a/arch/arm/mach-bcm2708/bcm2708.c
  106. +++ b/arch/arm/mach-bcm2708/bcm2708.c
  107. @@ -532,6 +532,7 @@ static struct spi_board_info bcm2708_spi
  108. };
  109. #endif
  110. +#ifndef CONFIG_OF
  111. static struct resource bcm2708_bsc0_resources[] = {
  112. {
  113. .start = BSC0_BASE,
  114. @@ -570,6 +571,7 @@ static struct platform_device bcm2708_bs
  115. .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
  116. .resource = bcm2708_bsc1_resources,
  117. };
  118. +#endif
  119. static struct platform_device bcm2835_hwmon_device = {
  120. .name = "bcm2835_hwmon",
  121. @@ -797,8 +799,8 @@ void __init bcm2708_init(void)
  122. bcm_register_device(&bcm2708_alsa_devices[i]);
  123. bcm_register_device_dt(&bcm2708_spi_device);
  124. - bcm_register_device(&bcm2708_bsc0_device);
  125. - bcm_register_device(&bcm2708_bsc1_device);
  126. + bcm_register_device_dt(&bcm2708_bsc0_device);
  127. + bcm_register_device_dt(&bcm2708_bsc1_device);
  128. bcm_register_device(&bcm2835_hwmon_device);
  129. bcm_register_device(&bcm2835_thermal_device);
  130. --- a/drivers/i2c/busses/Kconfig
  131. +++ b/drivers/i2c/busses/Kconfig
  132. @@ -362,7 +362,7 @@ config I2C_AXXIA
  133. config I2C_BCM2835
  134. tristate "Broadcom BCM2835 I2C controller"
  135. - depends on ARCH_BCM2835
  136. + depends on ARCH_BCM2835 || ARCH_BCM2708
  137. help
  138. If you say yes to this option, support will be included for the
  139. BCM2835 I2C controller.
  140. --- a/drivers/i2c/busses/i2c-bcm2708.c
  141. +++ b/drivers/i2c/busses/i2c-bcm2708.c
  142. @@ -26,6 +26,7 @@
  143. #include <linux/spinlock.h>
  144. #include <linux/clk.h>
  145. #include <linux/err.h>
  146. +#include <linux/of.h>
  147. #include <linux/platform_device.h>
  148. #include <linux/io.h>
  149. #include <linux/slab.h>
  150. @@ -303,6 +304,21 @@ static int bcm2708_i2c_probe(struct plat
  151. unsigned long bus_hz;
  152. u32 cdiv;
  153. + if (pdev->dev.of_node) {
  154. + u32 bus_clk_rate;
  155. + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
  156. + if (pdev->id < 0) {
  157. + dev_err(&pdev->dev, "alias is missing\n");
  158. + return -EINVAL;
  159. + }
  160. + if (!of_property_read_u32(pdev->dev.of_node,
  161. + "clock-frequency", &bus_clk_rate))
  162. + baudrate = bus_clk_rate;
  163. + else
  164. + dev_warn(&pdev->dev,
  165. + "Could not read clock-frequency property\n");
  166. + }
  167. +
  168. regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  169. if (!regs) {
  170. dev_err(&pdev->dev, "could not get IO memory\n");
  171. @@ -336,6 +352,7 @@ static int bcm2708_i2c_probe(struct plat
  172. adap->dev.parent = &pdev->dev;
  173. adap->nr = pdev->id;
  174. strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
  175. + adap->dev.of_node = pdev->dev.of_node;
  176. switch (pdev->id) {
  177. case 0:
  178. @@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct pla
  179. return 0;
  180. }
  181. +static const struct of_device_id bcm2708_i2c_of_match[] = {
  182. + { .compatible = "brcm,bcm2708-i2c" },
  183. + {},
  184. +};
  185. +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
  186. +
  187. static struct platform_driver bcm2708_i2c_driver = {
  188. .driver = {
  189. .name = DRV_NAME,
  190. .owner = THIS_MODULE,
  191. + .of_match_table = bcm2708_i2c_of_match,
  192. },
  193. .probe = bcm2708_i2c_probe,
  194. .remove = bcm2708_i2c_remove,