diff options
author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
---|---|---|
committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-01-22 10:38:37 -0500 |
commit | fcc9d2e5a6c89d22b8b773a64fb4ad21ac318446 (patch) | |
tree | a57612d1888735a2ec7972891b68c1ac5ec8faea /arch/arm/mach-tegra/board-ventana-sensors.c | |
parent | 8dea78da5cee153b8af9c07a2745f6c55057fe12 (diff) |
Diffstat (limited to 'arch/arm/mach-tegra/board-ventana-sensors.c')
-rw-r--r-- | arch/arm/mach-tegra/board-ventana-sensors.c | 585 |
1 files changed, 585 insertions, 0 deletions
diff --git a/arch/arm/mach-tegra/board-ventana-sensors.c b/arch/arm/mach-tegra/board-ventana-sensors.c new file mode 100644 index 00000000000..81184d54599 --- /dev/null +++ b/arch/arm/mach-tegra/board-ventana-sensors.c | |||
@@ -0,0 +1,585 @@ | |||
1 | /* | ||
2 | * arch/arm/mach-tegra/board-ventana-sensors.c | ||
3 | * | ||
4 | * Copyright (c) 2011-2012, NVIDIA CORPORATION, All rights reserved. | ||
5 | * | ||
6 | * Redistribution and use in source and binary forms, with or without | ||
7 | * modification, are permitted provided that the following conditions are | ||
8 | * met: | ||
9 | * | ||
10 | * Redistributions of source code must retain the above copyright notice, | ||
11 | * this list of conditions and the following disclaimer. | ||
12 | * | ||
13 | * Redistributions in binary form must reproduce the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer in the | ||
15 | * documentation and/or other materials provided with the distribution. | ||
16 | * | ||
17 | * Neither the name of NVIDIA CORPORATION nor the names of its contributors | ||
18 | * may be used to endorse or promote products derived from this software | ||
19 | * without specific prior written permission. | ||
20 | * | ||
21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS | ||
22 | * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
23 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A | ||
24 | * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
25 | * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
26 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED | ||
27 | * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
28 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF | ||
29 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | ||
30 | * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | ||
31 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
32 | */ | ||
33 | |||
34 | #include <linux/delay.h> | ||
35 | #include <linux/i2c.h> | ||
36 | #include <linux/mpu.h> | ||
37 | #include <linux/i2c/pca954x.h> | ||
38 | #include <linux/i2c/pca953x.h> | ||
39 | #include <linux/nct1008.h> | ||
40 | #include <linux/err.h> | ||
41 | #include <linux/regulator/consumer.h> | ||
42 | |||
43 | #include <mach/gpio.h> | ||
44 | |||
45 | #include <media/ov5650.h> | ||
46 | #include <media/ov2710.h> | ||
47 | #include <media/sh532u.h> | ||
48 | #include <media/ssl3250a.h> | ||
49 | #include <generated/mach-types.h> | ||
50 | |||
51 | #include "gpio-names.h" | ||
52 | #include "board.h" | ||
53 | #include "board-ventana.h" | ||
54 | #include "cpu-tegra.h" | ||
55 | |||
56 | static struct regulator *cam1_2v8, *cam2_2v8; | ||
57 | |||
58 | /* left ov5650 is CAM2 which is on csi_a */ | ||
59 | static int ventana_left_ov5650_power_on(void) | ||
60 | { | ||
61 | gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0); | ||
62 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1); | ||
63 | regulator_enable(cam2_2v8); | ||
64 | mdelay(5); | ||
65 | gpio_direction_output(CAM2_PWR_DN_GPIO, 0); | ||
66 | mdelay(5); | ||
67 | gpio_direction_output(CAM2_RST_L_GPIO, 0); | ||
68 | mdelay(1); | ||
69 | gpio_direction_output(CAM2_RST_L_GPIO, 1); | ||
70 | mdelay(20); | ||
71 | return 0; | ||
72 | } | ||
73 | |||
74 | static int ventana_left_ov5650_power_off(void) | ||
75 | { | ||
76 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0); | ||
77 | gpio_direction_output(CAM2_RST_L_GPIO, 0); | ||
78 | gpio_direction_output(CAM2_PWR_DN_GPIO, 1); | ||
79 | regulator_disable(cam2_2v8); | ||
80 | return 0; | ||
81 | } | ||
82 | |||
83 | struct ov5650_platform_data ventana_left_ov5650_data = { | ||
84 | .power_on = ventana_left_ov5650_power_on, | ||
85 | .power_off = ventana_left_ov5650_power_off, | ||
86 | }; | ||
87 | |||
88 | /* right ov5650 is CAM1 which is on csi_b */ | ||
89 | static int ventana_right_ov5650_power_on(void) | ||
90 | { | ||
91 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1); | ||
92 | regulator_enable(cam1_2v8); | ||
93 | mdelay(5); | ||
94 | gpio_direction_output(CAM1_PWR_DN_GPIO, 0); | ||
95 | mdelay(5); | ||
96 | gpio_direction_output(CAM1_RST_L_GPIO, 0); | ||
97 | mdelay(1); | ||
98 | gpio_direction_output(CAM1_RST_L_GPIO, 1); | ||
99 | mdelay(20); | ||
100 | return 0; | ||
101 | } | ||
102 | |||
103 | static int ventana_right_ov5650_power_off(void) | ||
104 | { | ||
105 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0); | ||
106 | gpio_direction_output(CAM1_RST_L_GPIO, 0); | ||
107 | gpio_direction_output(CAM1_PWR_DN_GPIO, 1); | ||
108 | regulator_disable(cam1_2v8); | ||
109 | return 0; | ||
110 | } | ||
111 | |||
112 | struct ov5650_platform_data ventana_right_ov5650_data = { | ||
113 | .power_on = ventana_right_ov5650_power_on, | ||
114 | .power_off = ventana_right_ov5650_power_off, | ||
115 | }; | ||
116 | |||
117 | static int ventana_ov2710_power_on(void) | ||
118 | { | ||
119 | gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1); | ||
120 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 1); | ||
121 | mdelay(5); | ||
122 | gpio_direction_output(CAM3_PWR_DN_GPIO, 0); | ||
123 | mdelay(5); | ||
124 | gpio_direction_output(CAM3_RST_L_GPIO, 0); | ||
125 | mdelay(1); | ||
126 | gpio_direction_output(CAM3_RST_L_GPIO, 1); | ||
127 | mdelay(20); | ||
128 | return 0; | ||
129 | } | ||
130 | |||
131 | static int ventana_ov2710_power_off(void) | ||
132 | { | ||
133 | gpio_direction_output(CAM3_RST_L_GPIO, 0); | ||
134 | gpio_direction_output(CAM3_PWR_DN_GPIO, 1); | ||
135 | gpio_direction_output(AVDD_DSI_CSI_ENB_GPIO, 0); | ||
136 | gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0); | ||
137 | return 0; | ||
138 | } | ||
139 | |||
140 | struct ov2710_platform_data ventana_ov2710_data = { | ||
141 | .power_on = ventana_ov2710_power_on, | ||
142 | .power_off = ventana_ov2710_power_off, | ||
143 | }; | ||
144 | |||
145 | |||
146 | static struct sh532u_platform_data sh532u_left_pdata = { | ||
147 | .num = 1, | ||
148 | .sync = 2, | ||
149 | .dev_name = "focuser", | ||
150 | .gpio_reset = CAM2_RST_L_GPIO, | ||
151 | .gpio_en = CAM2_LDO_SHUTDN_L_GPIO, | ||
152 | }; | ||
153 | |||
154 | static struct sh532u_platform_data sh532u_right_pdata = { | ||
155 | .num = 2, | ||
156 | .sync = 1, | ||
157 | .dev_name = "focuser", | ||
158 | .gpio_reset = CAM1_RST_L_GPIO, | ||
159 | .gpio_en = CAM1_LDO_SHUTDN_L_GPIO, | ||
160 | }; | ||
161 | |||
162 | |||
163 | static struct nvc_torch_pin_state ventana_ssl3250a_pinstate = { | ||
164 | .mask = 0x0040, /* VGP6 */ | ||
165 | .values = 0x0040, | ||
166 | }; | ||
167 | |||
168 | static struct ssl3250a_platform_data ventana_ssl3250a_pdata = { | ||
169 | .dev_name = "torch", | ||
170 | .pinstate = &ventana_ssl3250a_pinstate, | ||
171 | .gpio_act = CAMERA_FLASH_ACT_GPIO, | ||
172 | }; | ||
173 | |||
174 | |||
175 | static void ventana_isl29018_init(void) | ||
176 | { | ||
177 | tegra_gpio_enable(ISL29018_IRQ_GPIO); | ||
178 | gpio_request(ISL29018_IRQ_GPIO, "isl29018"); | ||
179 | gpio_direction_input(ISL29018_IRQ_GPIO); | ||
180 | } | ||
181 | |||
182 | #ifdef CONFIG_SENSORS_AK8975 | ||
183 | static void ventana_akm8975_init(void) | ||
184 | { | ||
185 | tegra_gpio_enable(AKM8975_IRQ_GPIO); | ||
186 | gpio_request(AKM8975_IRQ_GPIO, "akm8975"); | ||
187 | gpio_direction_input(AKM8975_IRQ_GPIO); | ||
188 | } | ||
189 | #endif | ||
190 | |||
191 | static void ventana_nct1008_init(void) | ||
192 | { | ||
193 | tegra_gpio_enable(NCT1008_THERM2_GPIO); | ||
194 | gpio_request(NCT1008_THERM2_GPIO, "temp_alert"); | ||
195 | gpio_direction_input(NCT1008_THERM2_GPIO); | ||
196 | } | ||
197 | |||
198 | static struct nct1008_platform_data ventana_nct1008_pdata = { | ||
199 | .supported_hwrev = true, | ||
200 | .ext_range = false, | ||
201 | .conv_rate = 0x08, | ||
202 | .offset = 0, | ||
203 | .hysteresis = 0, | ||
204 | .shutdown_ext_limit = 115, | ||
205 | .shutdown_local_limit = 120, | ||
206 | .throttling_ext_limit = 90, | ||
207 | .alarm_fn = tegra_throttling_enable, | ||
208 | }; | ||
209 | |||
210 | static const struct i2c_board_info ventana_i2c0_board_info[] = { | ||
211 | { | ||
212 | I2C_BOARD_INFO("isl29018", 0x44), | ||
213 | .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PZ2), | ||
214 | }, | ||
215 | }; | ||
216 | |||
217 | static const struct i2c_board_info ventana_i2c2_board_info[] = { | ||
218 | { | ||
219 | I2C_BOARD_INFO("bq20z75", 0x0B), | ||
220 | }, | ||
221 | }; | ||
222 | |||
223 | static struct pca953x_platform_data ventana_tca6416_data = { | ||
224 | .gpio_base = TCA6416_GPIO_BASE, | ||
225 | }; | ||
226 | |||
227 | static struct pca954x_platform_mode ventana_pca9546_modes[] = { | ||
228 | { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = 1 }, /* REAR CAM1 */ | ||
229 | { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = 1 }, /* REAR CAM2 */ | ||
230 | { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = 1 }, /* FRONT CAM3 */ | ||
231 | }; | ||
232 | |||
233 | static struct pca954x_platform_data ventana_pca9546_data = { | ||
234 | .modes = ventana_pca9546_modes, | ||
235 | .num_modes = ARRAY_SIZE(ventana_pca9546_modes), | ||
236 | }; | ||
237 | |||
238 | static const struct i2c_board_info ventana_i2c3_board_info_tca6416[] = { | ||
239 | { | ||
240 | I2C_BOARD_INFO("tca6416", 0x20), | ||
241 | .platform_data = &ventana_tca6416_data, | ||
242 | }, | ||
243 | }; | ||
244 | |||
245 | static const struct i2c_board_info ventana_i2c3_board_info_pca9546[] = { | ||
246 | { | ||
247 | I2C_BOARD_INFO("pca9546", 0x70), | ||
248 | .platform_data = &ventana_pca9546_data, | ||
249 | }, | ||
250 | }; | ||
251 | |||
252 | static const struct i2c_board_info ventana_i2c3_board_info_ssl3250a[] = { | ||
253 | { | ||
254 | I2C_BOARD_INFO("ssl3250a", 0x30), | ||
255 | .platform_data = &ventana_ssl3250a_pdata, | ||
256 | }, | ||
257 | }; | ||
258 | |||
259 | static struct i2c_board_info ventana_i2c4_board_info[] = { | ||
260 | { | ||
261 | I2C_BOARD_INFO("nct1008", 0x4C), | ||
262 | .irq = TEGRA_GPIO_TO_IRQ(NCT1008_THERM2_GPIO), | ||
263 | .platform_data = &ventana_nct1008_pdata, | ||
264 | }, | ||
265 | |||
266 | #ifdef CONFIG_SENSORS_AK8975 | ||
267 | { | ||
268 | I2C_BOARD_INFO("akm8975", 0x0C), | ||
269 | .irq = TEGRA_GPIO_TO_IRQ(AKM8975_IRQ_GPIO), | ||
270 | }, | ||
271 | #endif | ||
272 | }; | ||
273 | |||
274 | static struct i2c_board_info ventana_i2c6_board_info[] = { | ||
275 | { | ||
276 | I2C_BOARD_INFO("ov5650R", 0x36), | ||
277 | .platform_data = &ventana_right_ov5650_data, | ||
278 | }, | ||
279 | { | ||
280 | I2C_BOARD_INFO("sh532u", 0x72), | ||
281 | .platform_data = &sh532u_right_pdata, | ||
282 | }, | ||
283 | }; | ||
284 | |||
285 | static struct i2c_board_info ventana_i2c7_board_info[] = { | ||
286 | { | ||
287 | I2C_BOARD_INFO("ov5650L", 0x36), | ||
288 | .platform_data = &ventana_left_ov5650_data, | ||
289 | }, | ||
290 | { | ||
291 | I2C_BOARD_INFO("sh532u", 0x72), | ||
292 | .platform_data = &sh532u_left_pdata, | ||
293 | }, | ||
294 | }; | ||
295 | |||
296 | static struct i2c_board_info ventana_i2c8_board_info[] = { | ||
297 | { | ||
298 | I2C_BOARD_INFO("ov2710", 0x36), | ||
299 | .platform_data = &ventana_ov2710_data, | ||
300 | }, | ||
301 | }; | ||
302 | |||
303 | /* MPU board file definition */ | ||
304 | #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050) | ||
305 | #define MPU_GYRO_NAME "mpu3050" | ||
306 | #endif | ||
307 | #if (MPU_GYRO_TYPE == MPU_TYPE_MPU6050) | ||
308 | #define MPU_GYRO_NAME "mpu6050" | ||
309 | #endif | ||
310 | static struct mpu_platform_data mpu_gyro_data = { | ||
311 | .int_config = 0x10, | ||
312 | .level_shifter = 0, | ||
313 | .orientation = MPU_GYRO_ORIENTATION, /* Located in board_[platformname].h */ | ||
314 | }; | ||
315 | |||
316 | #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050) | ||
317 | static struct ext_slave_platform_data mpu_accel_data = { | ||
318 | .address = MPU_ACCEL_ADDR, | ||
319 | .irq = 0, | ||
320 | .adapt_num = MPU_ACCEL_BUS_NUM, | ||
321 | .bus = EXT_SLAVE_BUS_SECONDARY, | ||
322 | .orientation = MPU_ACCEL_ORIENTATION, /* Located in board_[platformname].h */ | ||
323 | }; | ||
324 | #endif | ||
325 | |||
326 | static struct ext_slave_platform_data mpu_compass_data = { | ||
327 | .address = MPU_COMPASS_ADDR, | ||
328 | .irq = 0, | ||
329 | .adapt_num = MPU_COMPASS_BUS_NUM, | ||
330 | .bus = EXT_SLAVE_BUS_PRIMARY, | ||
331 | .orientation = MPU_COMPASS_ORIENTATION, /* Located in board_[platformname].h */ | ||
332 | }; | ||
333 | |||
334 | static struct i2c_board_info __initdata inv_mpu_i2c2_board_info[] = { | ||
335 | { | ||
336 | I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR), | ||
337 | .irq = TEGRA_GPIO_TO_IRQ(MPU_GYRO_IRQ_GPIO), | ||
338 | .platform_data = &mpu_gyro_data, | ||
339 | }, | ||
340 | #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050) | ||
341 | { | ||
342 | I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR), | ||
343 | #if MPU_ACCEL_IRQ_GPIO | ||
344 | .irq = TEGRA_GPIO_TO_IRQ(MPU_ACCEL_IRQ_GPIO), | ||
345 | #endif | ||
346 | .platform_data = &mpu_accel_data, | ||
347 | }, | ||
348 | #endif | ||
349 | }; | ||
350 | |||
351 | static struct i2c_board_info __initdata inv_mpu_i2c4_board_info[] = { | ||
352 | { | ||
353 | I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR), | ||
354 | #if MPU_COMPASS_IRQ_GPIO | ||
355 | .irq = TEGRA_GPIO_TO_IRQ(MPU_COMPASS_IRQ_GPIO), | ||
356 | #endif | ||
357 | .platform_data = &mpu_compass_data, | ||
358 | }, | ||
359 | }; | ||
360 | |||
361 | static void mpuirq_init(void) | ||
362 | { | ||
363 | int ret = 0; | ||
364 | |||
365 | pr_info("*** MPU START *** mpuirq_init...\n"); | ||
366 | |||
367 | #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050) | ||
368 | #if MPU_ACCEL_IRQ_GPIO | ||
369 | /* ACCEL-IRQ assignment */ | ||
370 | tegra_gpio_enable(MPU_ACCEL_IRQ_GPIO); | ||
371 | ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME); | ||
372 | if (ret < 0) { | ||
373 | pr_err("%s: gpio_request failed %d\n", __func__, ret); | ||
374 | return; | ||
375 | } | ||
376 | |||
377 | ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO); | ||
378 | if (ret < 0) { | ||
379 | pr_err("%s: gpio_direction_input failed %d\n", __func__, ret); | ||
380 | gpio_free(MPU_ACCEL_IRQ_GPIO); | ||
381 | return; | ||
382 | } | ||
383 | #endif | ||
384 | #endif | ||
385 | |||
386 | /* MPU-IRQ assignment */ | ||
387 | tegra_gpio_enable(MPU_GYRO_IRQ_GPIO); | ||
388 | ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME); | ||
389 | if (ret < 0) { | ||
390 | pr_err("%s: gpio_request failed %d\n", __func__, ret); | ||
391 | return; | ||
392 | } | ||
393 | |||
394 | ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO); | ||
395 | if (ret < 0) { | ||
396 | pr_err("%s: gpio_direction_input failed %d\n", __func__, ret); | ||
397 | gpio_free(MPU_GYRO_IRQ_GPIO); | ||
398 | return; | ||
399 | } | ||
400 | pr_info("*** MPU END *** mpuirq_init...\n"); | ||
401 | |||
402 | i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c2_board_info, | ||
403 | ARRAY_SIZE(inv_mpu_i2c2_board_info)); | ||
404 | i2c_register_board_info(MPU_COMPASS_BUS_NUM, inv_mpu_i2c4_board_info, | ||
405 | ARRAY_SIZE(inv_mpu_i2c4_board_info)); | ||
406 | } | ||
407 | |||
408 | int __init ventana_sensors_init(void) | ||
409 | { | ||
410 | struct board_info BoardInfo; | ||
411 | |||
412 | ventana_isl29018_init(); | ||
413 | #ifdef CONFIG_SENSORS_AK8975 | ||
414 | ventana_akm8975_init(); | ||
415 | #endif | ||
416 | mpuirq_init(); | ||
417 | ventana_nct1008_init(); | ||
418 | |||
419 | i2c_register_board_info(0, ventana_i2c0_board_info, | ||
420 | ARRAY_SIZE(ventana_i2c0_board_info)); | ||
421 | |||
422 | tegra_get_board_info(&BoardInfo); | ||
423 | |||
424 | /* | ||
425 | * battery driver is supported on FAB.D boards and above only, | ||
426 | * since they have the necessary hardware rework | ||
427 | */ | ||
428 | if (BoardInfo.sku > 0) { | ||
429 | i2c_register_board_info(2, ventana_i2c2_board_info, | ||
430 | ARRAY_SIZE(ventana_i2c2_board_info)); | ||
431 | } | ||
432 | |||
433 | i2c_register_board_info(3, ventana_i2c3_board_info_ssl3250a, | ||
434 | ARRAY_SIZE(ventana_i2c3_board_info_ssl3250a)); | ||
435 | |||
436 | i2c_register_board_info(4, ventana_i2c4_board_info, | ||
437 | ARRAY_SIZE(ventana_i2c4_board_info)); | ||
438 | |||
439 | i2c_register_board_info(6, ventana_i2c6_board_info, | ||
440 | ARRAY_SIZE(ventana_i2c6_board_info)); | ||
441 | |||
442 | i2c_register_board_info(7, ventana_i2c7_board_info, | ||
443 | ARRAY_SIZE(ventana_i2c7_board_info)); | ||
444 | |||
445 | i2c_register_board_info(8, ventana_i2c8_board_info, | ||
446 | ARRAY_SIZE(ventana_i2c8_board_info)); | ||
447 | |||
448 | return 0; | ||
449 | } | ||
450 | |||
451 | #ifdef CONFIG_TEGRA_CAMERA | ||
452 | |||
453 | struct tegra_camera_gpios { | ||
454 | const char *name; | ||
455 | int gpio; | ||
456 | bool tegra_internal_gpio; | ||
457 | int enabled; | ||
458 | }; | ||
459 | |||
460 | #define TEGRA_CAMERA_GPIO(_name, _gpio, _tegra_internal_gpio, _enabled) \ | ||
461 | { \ | ||
462 | .name = _name, \ | ||
463 | .gpio = _gpio, \ | ||
464 | .tegra_internal_gpio = _tegra_internal_gpio, \ | ||
465 | .enabled = _enabled, \ | ||
466 | } | ||
467 | |||
468 | static struct tegra_camera_gpios ventana_camera_gpio_keys[] = { | ||
469 | [0] = TEGRA_CAMERA_GPIO("camera_power_en", CAMERA_POWER_GPIO, true, 1), | ||
470 | [1] = TEGRA_CAMERA_GPIO("camera_csi_sel", CAMERA_CSI_MUX_SEL_GPIO, true, 0), | ||
471 | [2] = TEGRA_CAMERA_GPIO("torch_gpio_act", CAMERA_FLASH_ACT_GPIO, true, 0), | ||
472 | |||
473 | [3] = TEGRA_CAMERA_GPIO("en_avdd_csi", AVDD_DSI_CSI_ENB_GPIO, false, 1), | ||
474 | [4] = TEGRA_CAMERA_GPIO("cam_i2c_mux_rst_lo", CAM_I2C_MUX_RST_GPIO, false, 1), | ||
475 | |||
476 | [5] = TEGRA_CAMERA_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, false, 0), | ||
477 | [6] = TEGRA_CAMERA_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, false, 0), | ||
478 | [7] = TEGRA_CAMERA_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, false, 1), | ||
479 | |||
480 | [8] = TEGRA_CAMERA_GPIO("cam3_af_pwdn_lo", CAM3_AF_PWR_DN_L_GPIO, false, 0), | ||
481 | [9] = TEGRA_CAMERA_GPIO("cam3_pwdn", CAM3_PWR_DN_GPIO, false, 0), | ||
482 | [10] = TEGRA_CAMERA_GPIO("cam3_rst_lo", CAM3_RST_L_GPIO, false, 1), | ||
483 | |||
484 | [11] = TEGRA_CAMERA_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, false, 0), | ||
485 | [12] = TEGRA_CAMERA_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, false, 0), | ||
486 | [13] = TEGRA_CAMERA_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, false, 1), | ||
487 | }; | ||
488 | |||
489 | int __init ventana_camera_late_init(void) | ||
490 | { | ||
491 | int ret; | ||
492 | int i; | ||
493 | struct regulator *cam_ldo6 = NULL; | ||
494 | |||
495 | if (!machine_is_ventana()) | ||
496 | return 0; | ||
497 | |||
498 | cam_ldo6 = regulator_get(NULL, "vdd_ldo6"); | ||
499 | if (IS_ERR_OR_NULL(cam_ldo6)) { | ||
500 | pr_err("%s: Couldn't get regulator ldo6\n", __func__); | ||
501 | return PTR_ERR(cam_ldo6); | ||
502 | } | ||
503 | |||
504 | ret = regulator_enable(cam_ldo6); | ||
505 | if (ret){ | ||
506 | pr_err("%s: Failed to enable ldo6\n", __func__); | ||
507 | goto fail_put_regulator_ldo6; | ||
508 | } | ||
509 | |||
510 | i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_tca6416); | ||
511 | |||
512 | for (i = 0; i < ARRAY_SIZE(ventana_camera_gpio_keys); i++) { | ||
513 | |||
514 | if (ventana_camera_gpio_keys[i].tegra_internal_gpio) | ||
515 | tegra_gpio_enable(ventana_camera_gpio_keys[i].gpio); | ||
516 | |||
517 | ret = gpio_request(ventana_camera_gpio_keys[i].gpio, | ||
518 | ventana_camera_gpio_keys[i].name); | ||
519 | if (ret < 0) { | ||
520 | pr_err("%s: gpio_request failed for gpio #%d\n", | ||
521 | __func__, i); | ||
522 | goto fail_free_gpio; | ||
523 | } | ||
524 | |||
525 | gpio_direction_output(ventana_camera_gpio_keys[i].gpio, | ||
526 | ventana_camera_gpio_keys[i].enabled); | ||
527 | |||
528 | gpio_export(ventana_camera_gpio_keys[i].gpio, false); | ||
529 | } | ||
530 | |||
531 | ventana_cam_fixed_voltage_regulator_init(); | ||
532 | |||
533 | cam1_2v8 = regulator_get(NULL, "cam1_2v8"); | ||
534 | if (WARN_ON(IS_ERR(cam1_2v8))) { | ||
535 | pr_err("%s: couldn't get regulator cam1_2v8: %ld\n", | ||
536 | __func__, PTR_ERR(cam1_2v8)); | ||
537 | ret = PTR_ERR(cam1_2v8); | ||
538 | goto fail_free_gpio; | ||
539 | } else { | ||
540 | regulator_enable(cam1_2v8); | ||
541 | } | ||
542 | |||
543 | cam2_2v8 = regulator_get(NULL, "cam2_2v8"); | ||
544 | if (WARN_ON(IS_ERR(cam2_2v8))) { | ||
545 | pr_err("%s: couldn't get regulator cam2_2v8: %ld\n", | ||
546 | __func__, PTR_ERR(cam2_2v8)); | ||
547 | ret = PTR_ERR(cam2_2v8); | ||
548 | goto fail_put_regulator_cam1_2v8; | ||
549 | } else { | ||
550 | regulator_enable(cam2_2v8); | ||
551 | } | ||
552 | |||
553 | i2c_new_device(i2c_get_adapter(3), ventana_i2c3_board_info_pca9546); | ||
554 | |||
555 | ventana_ov2710_power_off(); | ||
556 | ventana_left_ov5650_power_off(); | ||
557 | ventana_right_ov5650_power_off(); | ||
558 | |||
559 | ret = regulator_disable(cam_ldo6); | ||
560 | if (ret){ | ||
561 | pr_err("%s: Failed to disable ldo6\n", __func__); | ||
562 | goto fail_put_regulator_cam2_2v8; | ||
563 | } | ||
564 | |||
565 | regulator_put(cam_ldo6); | ||
566 | return 0; | ||
567 | |||
568 | fail_put_regulator_cam2_2v8: | ||
569 | regulator_put(cam2_2v8); | ||
570 | |||
571 | fail_put_regulator_cam1_2v8: | ||
572 | regulator_put(cam1_2v8); | ||
573 | |||
574 | fail_free_gpio: | ||
575 | while (i--) | ||
576 | gpio_free(ventana_camera_gpio_keys[i].gpio); | ||
577 | |||
578 | fail_put_regulator_ldo6: | ||
579 | regulator_put(cam_ldo6); | ||
580 | return ret; | ||
581 | } | ||
582 | |||
583 | late_initcall(ventana_camera_late_init); | ||
584 | |||
585 | #endif /* CONFIG_TEGRA_CAMERA */ | ||