aboutsummaryrefslogtreecommitdiffstats
path: root/target/linux/brcm2708/patches-3.18/0053-i2c-bcm2708-add-device-tree-support.patch
blob: 0269052ae349ea1e0380243db7ed94b4f758a171 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
From 772f3f8c0c321b2817d35f48d553db023ead2d90 Mon Sep 17 00:00:00 2001
From: notro <notro@tronnes.org>
Date: Tue, 29 Jul 2014 11:04:49 +0200
Subject: [PATCH 053/114] i2c: bcm2708: add device tree support

Add DT support to driver and add to .dtsi file.
Setup pins in .dts file.
i2c is disabled by default.

Signed-off-by: Noralf Tronnes <notro@tronnes.org>

bcm2708: don't register i2c controllers when using DT

The devices for the i2c controllers are in the Device Tree.
Only register devices when not using DT.

Signed-off-by: Noralf Tronnes <notro@tronnes.org>

i2c: bcm2835: make driver available on ARCH_BCM2708

Make this driver available on ARCH_BCM2708

Signed-off-by: Noralf Tronnes <notro@tronnes.org>
---
 arch/arm/boot/dts/bcm2708-rpi-b.dts | 24 ++++++++++++++++++++++++
 arch/arm/boot/dts/bcm2708.dtsi      | 27 +++++++++++++++++++++++++++
 arch/arm/mach-bcm2708/bcm2708.c     |  6 ++++--
 drivers/i2c/busses/Kconfig          |  2 +-
 drivers/i2c/busses/i2c-bcm2708.c    | 24 ++++++++++++++++++++++++
 5 files changed, 80 insertions(+), 3 deletions(-)

--- a/arch/arm/boot/dts/bcm2708-rpi-b.dts
+++ b/arch/arm/boot/dts/bcm2708-rpi-b.dts
@@ -8,6 +8,8 @@
 
 	aliases {
 		spi0 = &spi0;
+		i2c0 = &i2c0;
+		i2c1 = &i2c1;
 	};
 };
 
@@ -16,6 +18,16 @@
 		brcm,pins = <7 8 9 10 11>;
 		brcm,function = <4>; /* alt0 */
 	};
+
+	i2c0_pins: i2c0 {
+		brcm,pins = <0 1>;
+		brcm,function = <4>;
+	};
+
+	i2c1_pins: i2c1 {
+		brcm,pins = <2 3>;
+		brcm,function = <4>;
+	};
 };
 
 &spi0 {
@@ -38,3 +50,15 @@
 		spi-max-frequency = <500000>;
 	};
 };
+
+&i2c0 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c0_pins>;
+	clock-frequency = <100000>;
+};
+
+&i2c1 {
+	pinctrl-names = "default";
+	pinctrl-0 = <&i2c1_pins>;
+	clock-frequency = <100000>;
+};
--- a/arch/arm/boot/dts/bcm2708.dtsi
+++ b/arch/arm/boot/dts/bcm2708.dtsi
@@ -48,6 +48,26 @@
 			#size-cells = <0>;
 			status = "disabled";
 		};
+
+		i2c0: i2c@7e205000 {
+			compatible = "brcm,bcm2708-i2c";
+			reg = <0x7e205000 0x1000>;
+			interrupts = <2 21>;
+			clocks = <&clk_i2c>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
+
+		i2c1: i2c@7e804000 {
+			compatible = "brcm,bcm2708-i2c";
+			reg = <0x7e804000 0x1000>;
+			interrupts = <2 21>;
+			clocks = <&clk_i2c>;
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "disabled";
+		};
 	};
 
 	clocks {
@@ -55,6 +75,13 @@
 		#address-cells = <1>;
 		#size-cells = <0>;
 
+		clk_i2c: i2c {
+			compatible = "fixed-clock";
+			reg = <1>;
+			#clock-cells = <0>;
+			clock-frequency = <250000000>;
+		};
+
 		clk_spi: clock@2 {
 			compatible = "fixed-clock";
 			reg = <2>;
--- a/arch/arm/mach-bcm2708/bcm2708.c
+++ b/arch/arm/mach-bcm2708/bcm2708.c
@@ -532,6 +532,7 @@ static struct spi_board_info bcm2708_spi
 };
 #endif
 
+#ifndef CONFIG_OF
 static struct resource bcm2708_bsc0_resources[] = {
 	{
 		.start = BSC0_BASE,
@@ -570,6 +571,7 @@ static struct platform_device bcm2708_bs
 	.num_resources = ARRAY_SIZE(bcm2708_bsc1_resources),
 	.resource = bcm2708_bsc1_resources,
 };
+#endif
 
 static struct platform_device bcm2835_hwmon_device = {
 	.name = "bcm2835_hwmon",
@@ -797,8 +799,8 @@ void __init bcm2708_init(void)
 		bcm_register_device(&bcm2708_alsa_devices[i]);
 
 	bcm_register_device_dt(&bcm2708_spi_device);
-	bcm_register_device(&bcm2708_bsc0_device);
-	bcm_register_device(&bcm2708_bsc1_device);
+	bcm_register_device_dt(&bcm2708_bsc0_device);
+	bcm_register_device_dt(&bcm2708_bsc1_device);
 
 	bcm_register_device(&bcm2835_hwmon_device);
 	bcm_register_device(&bcm2835_thermal_device);
--- a/drivers/i2c/busses/Kconfig
+++ b/drivers/i2c/busses/Kconfig
@@ -362,7 +362,7 @@ config I2C_AXXIA
 
 config I2C_BCM2835
 	tristate "Broadcom BCM2835 I2C controller"
-	depends on ARCH_BCM2835
+	depends on ARCH_BCM2835 || ARCH_BCM2708
 	help
 	  If you say yes to this option, support will be included for the
 	  BCM2835 I2C controller.
--- a/drivers/i2c/busses/i2c-bcm2708.c
+++ b/drivers/i2c/busses/i2c-bcm2708.c
@@ -26,6 +26,7 @@
 #include <linux/spinlock.h>
 #include <linux/clk.h>
 #include <linux/err.h>
+#include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/slab.h>
@@ -303,6 +304,21 @@ static int bcm2708_i2c_probe(struct plat
 	unsigned long bus_hz;
 	u32 cdiv;
 
+	if (pdev->dev.of_node) {
+		u32 bus_clk_rate;
+		pdev->id = of_alias_get_id(pdev->dev.of_node, "i2c");
+		if (pdev->id < 0) {
+			dev_err(&pdev->dev, "alias is missing\n");
+			return -EINVAL;
+		}
+		if (!of_property_read_u32(pdev->dev.of_node,
+					"clock-frequency", &bus_clk_rate))
+			baudrate = bus_clk_rate;
+		else
+			dev_warn(&pdev->dev,
+				"Could not read clock-frequency property\n");
+	}
+
 	regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	if (!regs) {
 		dev_err(&pdev->dev, "could not get IO memory\n");
@@ -336,6 +352,7 @@ static int bcm2708_i2c_probe(struct plat
 	adap->dev.parent = &pdev->dev;
 	adap->nr = pdev->id;
 	strlcpy(adap->name, dev_name(&pdev->dev), sizeof(adap->name));
+	adap->dev.of_node = pdev->dev.of_node;
 
 	switch (pdev->id) {
 	case 0:
@@ -416,10 +433,17 @@ static int bcm2708_i2c_remove(struct pla
 	return 0;
 }
 
+static const struct of_device_id bcm2708_i2c_of_match[] = {
+        { .compatible = "brcm,bcm2708-i2c" },
+        {},
+};
+MODULE_DEVICE_TABLE(of, bcm2708_i2c_of_match);
+
 static struct platform_driver bcm2708_i2c_driver = {
 	.driver		= {
 		.name	= DRV_NAME,
 		.owner	= THIS_MODULE,
+		.of_match_table = bcm2708_i2c_of_match,
 	},
 	.probe		= bcm2708_i2c_probe,
 	.remove		= bcm2708_i2c_remove,