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
6 Add DT support to driver and add to .dtsi file.
7 Setup pins in .dts file.
8 i2c is disabled by default.
10 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
12 bcm2708: don't register i2c controllers when using DT
14 The devices for the i2c controllers are in the Device Tree.
15 Only register devices when not using DT.
17 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
19 i2c: bcm2835: make driver available on ARCH_BCM2708
21 Make this driver available on ARCH_BCM2708
23 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
25 arch/arm/boot/dts/bcm2708-rpi-b.dts | 24 ++++++++++++++++++++++++
26 arch/arm/boot/dts/bcm2708.dtsi | 27 +++++++++++++++++++++++++++
27 arch/arm/mach-bcm2708/bcm2708.c | 6 ++++--
28 drivers/i2c/busses/Kconfig | 2 +-
29 drivers/i2c/busses/i2c-bcm2708.c | 24 ++++++++++++++++++++++++
30 5 files changed, 80 insertions(+), 3 deletions(-)
32 --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
33 +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
44 brcm,pins = <7 8 9 10 11>;
45 brcm,function = <4>; /* alt0 */
50 + brcm,function = <4>;
55 + brcm,function = <4>;
61 spi-max-frequency = <500000>;
66 + pinctrl-names = "default";
67 + pinctrl-0 = <&i2c0_pins>;
68 + clock-frequency = <100000>;
72 + pinctrl-names = "default";
73 + pinctrl-0 = <&i2c1_pins>;
74 + clock-frequency = <100000>;
76 --- a/arch/arm/boot/dts/bcm2708.dtsi
77 +++ b/arch/arm/boot/dts/bcm2708.dtsi
83 + i2c0: i2c@7e205000 {
84 + compatible = "brcm,bcm2708-i2c";
85 + reg = <0x7e205000 0x1000>;
86 + interrupts = <2 21>;
87 + clocks = <&clk_i2c>;
88 + #address-cells = <1>;
90 + status = "disabled";
93 + i2c1: i2c@7e804000 {
94 + compatible = "brcm,bcm2708-i2c";
95 + reg = <0x7e804000 0x1000>;
96 + interrupts = <2 21>;
97 + clocks = <&clk_i2c>;
98 + #address-cells = <1>;
100 + status = "disabled";
106 #address-cells = <1>;
110 + compatible = "fixed-clock";
112 + #clock-cells = <0>;
113 + clock-frequency = <250000000>;
117 compatible = "fixed-clock";
119 --- a/arch/arm/mach-bcm2708/bcm2708.c
120 +++ b/arch/arm/mach-bcm2708/bcm2708.c
121 @@ -532,6 +532,7 @@ static struct spi_board_info bcm2708_spi
126 static struct resource bcm2708_bsc0_resources[] = {
129 @@ -570,6 +571,7 @@ static struct platform_device bcm2708_bs
130 .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
131 .resource = bcm2708_bsc1_resources,
135 static struct platform_device bcm2835_hwmon_device = {
136 .name = "bcm2835_hwmon",
137 @@ -797,8 +799,8 @@ void __init bcm2708_init(void)
138 bcm_register_device(&bcm2708_alsa_devices[i]);
140 bcm_register_device_dt(&bcm2708_spi_device);
141 - bcm_register_device(&bcm2708_bsc0_device);
142 - bcm_register_device(&bcm2708_bsc1_device);
143 + bcm_register_device_dt(&bcm2708_bsc0_device);
144 + bcm_register_device_dt(&bcm2708_bsc1_device);
146 bcm_register_device(&bcm2835_hwmon_device);
147 bcm_register_device(&bcm2835_thermal_device);
148 --- a/drivers/i2c/busses/Kconfig
149 +++ b/drivers/i2c/busses/Kconfig
150 @@ -362,7 +362,7 @@ config I2C_AXXIA
153 tristate "Broadcom BCM2835 I2C controller"
154 - depends on ARCH_BCM2835
155 + depends on ARCH_BCM2835 || ARCH_BCM2708
157 If you say yes to this option, support will be included for the
158 BCM2835 I2C controller.
159 --- a/drivers/i2c/busses/i2c-bcm2708.c
160 +++ b/drivers/i2c/busses/i2c-bcm2708.c
162 #include <linux/spinlock.h>
163 #include <linux/clk.h>
164 #include <linux/err.h>
165 +#include <linux/of.h>
166 #include <linux/platform_device.h>
167 #include <linux/io.h>
168 #include <linux/slab.h>
169 @@ -303,6 +304,21 @@ static int bcm2708_i2c_probe(struct plat
170 unsigned long bus_hz;
173 + if (pdev->dev.of_node) {
175 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
176 + if (pdev->id < 0) {
177 + dev_err(&pdev->dev, "alias is missing\n");
180 + if (!of_property_read_u32(pdev->dev.of_node,
181 + "clock-frequency", &bus_clk_rate))
182 + baudrate = bus_clk_rate;
184 + dev_warn(&pdev->dev,
185 + "Could not read clock-frequency property\n");
188 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
190 dev_err(&pdev->dev, "could not get IO memory\n");
191 @@ -336,6 +352,7 @@ static int bcm2708_i2c_probe(struct plat
192 adap->dev.parent = &pdev->dev;
194 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
195 + adap->dev.of_node = pdev->dev.of_node;
199 @@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct pla
203 +static const struct of_device_id bcm2708_i2c_of_match[] = {
204 + { .compatible = "brcm,bcm2708-i2c" },
207 +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
209 static struct platform_driver bcm2708_i2c_driver = {
212 .owner = THIS_MODULE,
213 + .of_match_table = bcm2708_i2c_of_match,
215 .probe = bcm2708_i2c_probe,
216 .remove = bcm2708_i2c_remove,