lantiq: Use the BAR0 base address in the ath PCI fixup code
[openwrt/openwrt.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 --- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
33 +++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
34 @@ -8,6 +8,8 @@
35
36 aliases {
37 spi0 = &spi0;
38 + i2c0 = &i2c0;
39 + i2c1 = &i2c1;
40 };
41 };
42
43 @@ -16,6 +18,16 @@
44 brcm,pins = <7 8 9 10 11>;
45 brcm,function = <4>; /* alt0 */
46 };
47 +
48 + i2c0_pins: i2c0 {
49 + brcm,pins = <0 1>;
50 + brcm,function = <4>;
51 + };
52 +
53 + i2c1_pins: i2c1 {
54 + brcm,pins = <2 3>;
55 + brcm,function = <4>;
56 + };
57 };
58
59 &spi0 {
60 @@ -38,3 +50,15 @@
61 spi-max-frequency = <500000>;
62 };
63 };
64 +
65 +&i2c0 {
66 + pinctrl-names = "default";
67 + pinctrl-0 = <&i2c0_pins>;
68 + clock-frequency = <100000>;
69 +};
70 +
71 +&i2c1 {
72 + pinctrl-names = "default";
73 + pinctrl-0 = <&i2c1_pins>;
74 + clock-frequency = <100000>;
75 +};
76 --- a/arch/arm/boot/dts/bcm2708.dtsi
77 +++ b/arch/arm/boot/dts/bcm2708.dtsi
78 @@ -48,6 +48,26 @@
79 #size-cells = <0>;
80 status = "disabled";
81 };
82 +
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>;
89 + #size-cells = <0>;
90 + status = "disabled";
91 + };
92 +
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>;
99 + #size-cells = <0>;
100 + status = "disabled";
101 + };
102 };
103
104 clocks {
105 @@ -55,6 +75,13 @@
106 #address-cells = <1>;
107 #size-cells = <0>;
108
109 + clk_i2c: i2c {
110 + compatible = "fixed-clock";
111 + reg = <1>;
112 + #clock-cells = <0>;
113 + clock-frequency = <250000000>;
114 + };
115 +
116 clk_spi: clock@2 {
117 compatible = "fixed-clock";
118 reg = <2>;
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
122 };
123 #endif
124
125 +#ifndef CONFIG_OF
126 static struct resource bcm2708_bsc0_resources[] = {
127 {
128 .start = BSC0_BASE,
129 @@ -570,6 +571,7 @@ static struct platform_device bcm2708_bs
130 .num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
131 .resource = bcm2708_bsc1_resources,
132 };
133 +#endif
134
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]);
139
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);
145
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
151
152 config I2C_BCM2835
153 tristate "Broadcom BCM2835 I2C controller"
154 - depends on ARCH_BCM2835
155 + depends on ARCH_BCM2835 || ARCH_BCM2708
156 help
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
161 @@ -26,6 +26,7 @@
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;
171 u32 cdiv;
172
173 + if (pdev->dev.of_node) {
174 + u32 bus_clk_rate;
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");
178 + return -EINVAL;
179 + }
180 + if (!of_property_read_u32(pdev->dev.of_node,
181 + "clock-frequency", &bus_clk_rate))
182 + baudrate = bus_clk_rate;
183 + else
184 + dev_warn(&pdev->dev,
185 + "Could not read clock-frequency property\n");
186 + }
187 +
188 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
189 if (!regs) {
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;
193 adap->nr = pdev->id;
194 strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
195 + adap->dev.of_node = pdev->dev.of_node;
196
197 switch (pdev->id) {
198 case 0:
199 @@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct pla
200 return 0;
201 }
202
203 +static const struct of_device_id bcm2708_i2c_of_match[] = {
204 + { .compatible = "brcm,bcm2708-i2c" },
205 + {},
206 +};
207 +MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
208 +
209 static struct platform_driver bcm2708_i2c_driver = {
210 .driver = {
211 .name = DRV_NAME,
212 .owner = THIS_MODULE,
213 + .of_match_table = bcm2708_i2c_of_match,
214 },
215 .probe = bcm2708_i2c_probe,
216 .remove = bcm2708_i2c_remove,