brcm2708: update to v3.18
[openwrt/staging/wigyori.git] / target / linux / brcm2708 / patches-3.18 / 0053-i2c-bcm2708-add-device-tree-support.patch
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
6 Add DT support to driver and add to .dtsi file.
7 Setup pins in .dts file.
8 i2c is disabled by default.
9
10 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
11
12 bcm2708: don't register i2c controllers when using DT
13
14 The devices for the i2c controllers are in the Device Tree.
15 Only register devices when not using DT.
16
17 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
18
19 i2c: bcm2835: make driver available on ARCH_BCM2708
20
21 Make this driver available on ARCH_BCM2708
22
23 Signed-off-by: Noralf Tronnes <notro@tronnes.org>
24 ---
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(-)
31
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
36 @@ -8,6 +8,8 @@
37
38 aliases {
39 spi0 = &spi0;
40 + i2c0 = &i2c0;
41 + i2c1 = &i2c1;
42 };
43 };
44
45 @@ -16,6 +18,16 @@
46 brcm,pins = <7 8 9 10 11>;
47 brcm,function = <4>; /* alt0 */
48 };
49 +
50 + i2c0_pins: i2c0 {
51 + brcm,pins = <0 1>;
52 + brcm,function = <4>;
53 + };
54 +
55 + i2c1_pins: i2c1 {
56 + brcm,pins = <2 3>;
57 + brcm,function = <4>;
58 + };
59 };
60
61 &spi0 {
62 @@ -38,3 +50,15 @@
63 spi-max-frequency = <500000>;
64 };
65 };
66 +
67 +&i2c0 {
68 + pinctrl-names = "default";
69 + pinctrl-0 = <&i2c0_pins>;
70 + clock-frequency = <100000>;
71 +};
72 +
73 +&i2c1 {
74 + pinctrl-names = "default";
75 + pinctrl-0 = <&i2c1_pins>;
76 + clock-frequency = <100000>;
77 +};
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
82 @@ -48,6 +48,26 @@
83 #size-cells = <0>;
84 status = "disabled";
85 };
86 +
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>;
93 + #size-cells = <0>;
94 + status = "disabled";
95 + };
96 +
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>;
103 + #size-cells = <0>;
104 + status = "disabled";
105 + };
106 };
107
108 clocks {
109 @@ -55,6 +75,13 @@
110 #address-cells = <1>;
111 #size-cells = <0>;
112
113 + clk_i2c: i2c {
114 + compatible = "fixed-clock";
115 + reg = <1>;
116 + #clock-cells = <0>;
117 + clock-frequency = <250000000>;
118 + };
119 +
120 clk_spi: clock@2 {
121 compatible = "fixed-clock";
122 reg = <2>;
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[] = {
128 };
129 #endif
130
131 +#ifndef CONFIG_OF
132 static struct resource bcm2708_bsc0_resources[] = {
133 {
134 .start = BSC0_BASE,
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,
138 };
139 +#endif
140
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]);
145
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);
151
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
159
160 config I2C_BCM2835
161 tristate "Broadcom BCM2835 I2C controller"
162 - depends on ARCH_BCM2835
163 + depends on ARCH_BCM2835 || ARCH_BCM2708
164 help
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
171 @@ -26,6 +26,7 @@
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;
181 u32 cdiv;
182
183 + if (pdev->dev.of_node) {
184 + u32 bus_clk_rate;
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");
188 + return -EINVAL;
189 + }
190 + if (!of_property_read_u32(pdev->dev.of_node,
191 + "clock-frequency", &bus_clk_rate))
192 + baudrate = bus_clk_rate;
193 + else
194 + dev_warn(&pdev->dev,
195 + "Could not read clock-frequency property\n");
196 + }
197 +
198 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
199 if (!regs) {
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;
203 adap->nr = pdev->id;
204 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
205 + adap->dev.of_node = pdev->dev.of_node;
206
207 switch (pdev->id) {
208 case 0:
209 @@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct platform_device *pdev)
210 return 0;
211 }
212
213 +static const struct of_device_id bcm2708_i2c_of_match[] = {
214 + { .compatible = "brcm,bcm2708-i2c" },
215 + {},
216 +};
217 +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
218 +
219 static struct platform_driver bcm2708_i2c_driver = {
220 .driver = {
221 .name = DRV_NAME,
222 .owner = THIS_MODULE,
223 + .of_match_table = bcm2708_i2c_of_match,
224 },
225 .probe = bcm2708_i2c_probe,
226 .remove = bcm2708_i2c_remove,
227 --
228 1.8.3.2
229