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 diff --git a/arch/arm/boot/dts/bcm2708-rpi-b.dts b/arch/arm/boot/dts/bcm2708-rpi-b.dts
33 index 30107fb..5893122 100644
34 --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
35 +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
46 brcm,pins = <7 8 9 10 11>;
47 brcm,function = <4>; /* alt0 */
52 + brcm,function = <4>;
57 + brcm,function = <4>;
63 spi-max-frequency = <500000>;
68 + pinctrl-names = "default";
69 + pinctrl-0 = <&i2c0_pins>;
70 + clock-frequency = <100000>;
74 + pinctrl-names = "default";
75 + pinctrl-0 = <&i2c1_pins>;
76 + clock-frequency = <100000>;
78 diff --git a/arch/arm/boot/dts/bcm2708.dtsi b/arch/arm/boot/dts/bcm2708.dtsi
79 index e90bf4c..2ca6d63 100644
80 --- a/arch/arm/boot/dts/bcm2708.dtsi
81 +++ b/arch/arm/boot/dts/bcm2708.dtsi
87 + i2c0: i2c@7e205000 {
88 + compatible = "brcm,bcm2708-i2c";
89 + reg = <0x7e205000 0x1000>;
90 + interrupts = <2 21>;
91 + clocks = <&clk_i2c>;
92 + #address-cells = <1>;
94 + status = "disabled";
97 + i2c1: i2c@7e804000 {
98 + compatible = "brcm,bcm2708-i2c";
99 + reg = <0x7e804000 0x1000>;
100 + interrupts = <2 21>;
101 + clocks = <&clk_i2c>;
102 + #address-cells = <1>;
104 + status = "disabled";
110 #address-cells = <1>;
114 + compatible = "fixed-clock";
116 + #clock-cells = <0>;
117 + clock-frequency = <250000000>;
121 compatible = "fixed-clock";
123 diff --git a/arch/arm/mach-bcm2708/bcm2708.c b/arch/arm/mach-bcm2708/bcm2708.c
124 index a2069f8..b45f327 100644
125 --- a/arch/arm/mach-bcm2708/bcm2708.c
126 +++ b/arch/arm/mach-bcm2708/bcm2708.c
127 @@ -532,6 +532,7 @@ static struct spi_board_info bcm2708_spi_devices[] = {
132 static struct resource bcm2708_bsc0_resources[] = {
135 @@ -570,6 +571,7 @@ static struct platform_device bcm2708_bsc1_device = {
136 .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
137 .resource = bcm2708_bsc1_resources,
141 static struct platform_device bcm2835_hwmon_device = {
142 .name = "bcm2835_hwmon",
143 @@ -797,8 +799,8 @@ void __init bcm2708_init(void)
144 bcm_register_device(&bcm2708_alsa_devices[i]);
146 bcm_register_device_dt(&bcm2708_spi_device);
147 - bcm_register_device(&bcm2708_bsc0_device);
148 - bcm_register_device(&bcm2708_bsc1_device);
149 + bcm_register_device_dt(&bcm2708_bsc0_device);
150 + bcm_register_device_dt(&bcm2708_bsc1_device);
152 bcm_register_device(&bcm2835_hwmon_device);
153 bcm_register_device(&bcm2835_thermal_device);
154 diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig
155 index 3d3db41..d30a986 100644
156 --- a/drivers/i2c/busses/Kconfig
157 +++ b/drivers/i2c/busses/Kconfig
158 @@ -361,7 +361,7 @@ config I2C_AXXIA
161 tristate "Broadcom BCM2835 I2C controller"
162 - depends on ARCH_BCM2835
163 + depends on ARCH_BCM2835 || ARCH_BCM2708
165 If you say yes to this option, support will be included for the
166 BCM2835 I2C controller.
167 diff --git a/drivers/i2c/busses/i2c-bcm2708.c b/drivers/i2c/busses/i2c-bcm2708.c
168 index 7d385a3..526129b 100644
169 --- a/drivers/i2c/busses/i2c-bcm2708.c
170 +++ b/drivers/i2c/busses/i2c-bcm2708.c
172 #include <linux/spinlock.h>
173 #include <linux/clk.h>
174 #include <linux/err.h>
175 +#include <linux/of.h>
176 #include <linux/platform_device.h>
177 #include <linux/io.h>
178 #include <linux/slab.h>
179 @@ -303,6 +304,21 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
180 unsigned long bus_hz;
183 + if (pdev->dev.of_node) {
185 + pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
186 + if (pdev->id < 0) {
187 + dev_err(&pdev->dev, "alias is missing\n");
190 + if (!of_property_read_u32(pdev->dev.of_node,
191 + "clock-frequency", &bus_clk_rate))
192 + baudrate = bus_clk_rate;
194 + dev_warn(&pdev->dev,
195 + "Could not read clock-frequency property\n");
198 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
200 dev_err(&pdev->dev, "could not get IO memory\n");
201 @@ -336,6 +352,7 @@ static int bcm2708_i2c_probe(struct platform_device *pdev)
202 adap->dev.parent = &pdev->dev;
204 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
205 + adap->dev.of_node = pdev->dev.of_node;
209 @@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct platform_device *pdev)
213 +static const struct of_device_id bcm2708_i2c_of_match[] = {
214 + { .compatible = "brcm,bcm2708-i2c" },
217 +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
219 static struct platform_driver bcm2708_i2c_driver = {
222 .owner = THIS_MODULE,
223 + .of_match_table = bcm2708_i2c_of_match,
225 .probe = bcm2708_i2c_probe,
226 .remove = bcm2708_i2c_remove,