diff options
Diffstat (limited to 'arch/arm/mach-tegra/p852/board-p852-i2c.c')
-rw-r--r-- | arch/arm/mach-tegra/p852/board-p852-i2c.c | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/p852/board-p852-i2c.c b/arch/arm/mach-tegra/p852/board-p852-i2c.c new file mode 100644 index 00000000000..041ec252b6c --- /dev/null +++ b/arch/arm/mach-tegra/p852/board-p852-i2c.c | |||
@@ -0,0 +1,180 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-tegra/board-p852-i2c.c | ||
3 | * | ||
4 | * Copyright (c) 2010-2011, NVIDIA Corporation. | ||
5 | * | ||
6 | * This software is licensed under the terms of the GNU General Public | ||
7 | * License version 2, as published by the Free Software Foundation, and | ||
8 | * may be copied, distributed, and modified under those terms. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | */ | ||
16 | |||
17 | #include <linux/resource.h> | ||
18 | #include <linux/platform_device.h> | ||
19 | #include <linux/delay.h> | ||
20 | #include <linux/gpio.h> | ||
21 | |||
22 | #include <asm/mach-types.h> | ||
23 | #include <mach/irqs.h> | ||
24 | #include <mach/iomap.h> | ||
25 | #include <linux/i2c.h> | ||
26 | #include <mach/pinmux.h> | ||
27 | #include <asm/mach-types.h> | ||
28 | |||
29 | #include "board-p852.h" | ||
30 | |||
31 | static struct resource i2c_resource1[] = { | ||
32 | [0] = { | ||
33 | .start = INT_I2C, | ||
34 | .end = INT_I2C, | ||
35 | .flags = IORESOURCE_IRQ, | ||
36 | }, | ||
37 | [1] = { | ||
38 | .start = TEGRA_I2C_BASE, | ||
39 | .end = TEGRA_I2C_BASE + TEGRA_I2C_SIZE - 1, | ||
40 | .flags = IORESOURCE_MEM, | ||
41 | }, | ||
42 | }; | ||
43 | |||
44 | static struct resource i2c_resource2[] = { | ||
45 | [0] = { | ||
46 | .start = INT_I2C2, | ||
47 | .end = INT_I2C2, | ||
48 | .flags = IORESOURCE_IRQ, | ||
49 | }, | ||
50 | [1] = { | ||
51 | .start = TEGRA_I2C2_BASE, | ||
52 | .end = TEGRA_I2C2_BASE + TEGRA_I2C2_SIZE - 1, | ||
53 | .flags = IORESOURCE_MEM, | ||
54 | }, | ||
55 | }; | ||
56 | |||
57 | static struct resource i2c_resource3[] = { | ||
58 | [0] = { | ||
59 | .start = INT_I2C3, | ||
60 | .end = INT_I2C3, | ||
61 | .flags = IORESOURCE_IRQ, | ||
62 | }, | ||
63 | [1] = { | ||
64 | .start = TEGRA_I2C3_BASE, | ||
65 | .end = TEGRA_I2C3_BASE + TEGRA_I2C3_SIZE - 1, | ||
66 | .flags = IORESOURCE_MEM, | ||
67 | }, | ||
68 | }; | ||
69 | |||
70 | static struct resource i2c_resource4[] = { | ||
71 | [0] = { | ||
72 | .start = INT_DVC, | ||
73 | .end = INT_DVC, | ||
74 | .flags = IORESOURCE_IRQ, | ||
75 | }, | ||
76 | [1] = { | ||
77 | .start = TEGRA_DVC_BASE, | ||
78 | .end = TEGRA_DVC_BASE + TEGRA_DVC_SIZE - 1, | ||
79 | .flags = IORESOURCE_MEM, | ||
80 | }, | ||
81 | }; | ||
82 | |||
83 | static const struct tegra_pingroup_config i2c2_ddc = { | ||
84 | .pingroup = TEGRA_PINGROUP_DDC, | ||
85 | .func = TEGRA_MUX_I2C2, | ||
86 | }; | ||
87 | |||
88 | static const struct tegra_pingroup_config i2c_i2cp = { | ||
89 | .pingroup = TEGRA_PINGROUP_I2CP, | ||
90 | .func = TEGRA_MUX_I2C, | ||
91 | }; | ||
92 | |||
93 | static struct tegra_i2c_platform_data p852_i2c1_platform_data = { | ||
94 | .adapter_nr = 0, | ||
95 | .bus_count = 1, | ||
96 | .bus_clk_rate = {400000}, | ||
97 | }; | ||
98 | |||
99 | static struct tegra_i2c_platform_data p852_i2c2_platform_data = { | ||
100 | .adapter_nr = 1, | ||
101 | .bus_count = 1, | ||
102 | .bus_clk_rate = {100000}, | ||
103 | .bus_mux = {&i2c2_ddc}, | ||
104 | .bus_mux_len = {1}, | ||
105 | }; | ||
106 | |||
107 | static struct tegra_i2c_platform_data p852_i2c3_platform_data = { | ||
108 | .adapter_nr = 2, | ||
109 | .bus_count = 1, | ||
110 | .bus_clk_rate = {400000}, | ||
111 | }; | ||
112 | |||
113 | static struct tegra_i2c_platform_data p852_dvc_platform_data = { | ||
114 | .adapter_nr = 3, | ||
115 | .bus_count = 1, | ||
116 | .bus_clk_rate = {100000}, | ||
117 | .bus_mux = {&i2c_i2cp}, | ||
118 | .bus_mux_len = {1}, | ||
119 | .is_dvc = true, | ||
120 | }; | ||
121 | |||
122 | struct platform_device tegra_i2c_device[] = { | ||
123 | { | ||
124 | .name = "tegra-i2c", | ||
125 | .id = 0, | ||
126 | .resource = i2c_resource1, | ||
127 | .num_resources = ARRAY_SIZE(i2c_resource1), | ||
128 | .dev = { | ||
129 | .platform_data = &p852_i2c1_platform_data, | ||
130 | }, | ||
131 | }, | ||
132 | { | ||
133 | .name = "tegra-i2c", | ||
134 | .id = 1, | ||
135 | .resource = i2c_resource2, | ||
136 | .num_resources = ARRAY_SIZE(i2c_resource2), | ||
137 | .dev = { | ||
138 | .platform_data = &p852_i2c2_platform_data, | ||
139 | }, | ||
140 | }, | ||
141 | { | ||
142 | .name = "tegra-i2c", | ||
143 | .id = 2, | ||
144 | .resource = i2c_resource3, | ||
145 | .num_resources = ARRAY_SIZE(i2c_resource3), | ||
146 | .dev = { | ||
147 | .platform_data = &p852_i2c3_platform_data, | ||
148 | }, | ||
149 | }, | ||
150 | { | ||
151 | .name = "tegra-i2c", | ||
152 | .id = 3, | ||
153 | .resource = i2c_resource4, | ||
154 | .num_resources = ARRAY_SIZE(i2c_resource4), | ||
155 | .dev = { | ||
156 | .platform_data = &p852_dvc_platform_data, | ||
157 | }, | ||
158 | } | ||
159 | }; | ||
160 | |||
161 | void __init p852_i2c_set_default_clock(int adapter, unsigned long clock) | ||
162 | { | ||
163 | if (adapter >= 0 && adapter < ARRAY_SIZE(tegra_i2c_device)) | ||
164 | ((struct tegra_i2c_platform_data *)tegra_i2c_device[adapter]. | ||
165 | dev.platform_data)->bus_clk_rate[0] = clock; | ||
166 | } | ||
167 | |||
168 | void __init p852_i2c_init(void) | ||
169 | { | ||
170 | int i; | ||
171 | unsigned int i2c_config = 0; | ||
172 | if (p852_sku_peripherals & P852_SKU_I2C_ENABLE) { | ||
173 | for (i = 0; i < P852_MAX_I2C; i++) { | ||
174 | i2c_config = | ||
175 | (p852_i2c_peripherals >> (P852_I2C_SHIFT * i)); | ||
176 | if (i2c_config & P852_I2C_ENABLE) | ||
177 | platform_device_register(&tegra_i2c_device[i]); | ||
178 | } | ||
179 | } | ||
180 | } | ||