arm: tegra: sensors: synchronize cam A and cam B
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-sensors.c
3  *
4  * Copyright (c) 2011, NVIDIA, All Rights Reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include <linux/i2c.h>
22 #include <linux/delay.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/i2c/pca954x.h>
25 #include <linux/i2c/pca953x.h>
26 #include <linux/nct1008.h>
27 #include <mach/fb.h>
28 #include <mach/gpio.h>
29 #include <media/ov5650.h>
30 #include <media/ov2710.h>
31 #include <generated/mach-types.h>
32 #include "gpio-names.h"
33 #include "board.h"
34 #include <linux/mpu.h>
35 #include <media/sh532u.h>
36
37 #include <mach/gpio.h>
38
39 #include "gpio-names.h"
40 #include "board-cardhu.h"
41
42 static struct regulator *cardhu_1v8_cam1 = NULL;
43 static struct regulator *cardhu_1v8_cam2 = NULL;
44 static struct regulator *cardhu_1v8_cam3 = NULL;
45 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
46 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
47 static struct regulator *cardhu_vdd_cam3 = NULL;
48
49 static struct board_info board_info;
50
51 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
52         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
53         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
54         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
55         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
56 };
57
58 static struct pca954x_platform_data cardhu_pca954x_data = {
59         .modes    = cardhu_pca954x_modes,
60         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
61 };
62
63 static int cardhu_camera_init(void)
64 {
65         int ret;
66
67         /* Boards E1198 and E1291 are of Cardhu personality
68          * and donot have TCA6416 exp for camera */
69         if ((board_info.board_id == BOARD_E1198) ||
70                 (board_info.board_id == BOARD_E1291)) {
71                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
72                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
73                 if (ret < 0)
74                         pr_err("%s: gpio_request failed for gpio %s\n",
75                                 __func__, "CAM1_POWER_DWN_GPIO");
76                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
77                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
78                 if (ret < 0)
79                         pr_err("%s: gpio_request failed for gpio %s\n",
80                                 __func__, "CAM3_POWER_DWN_GPIO");
81
82                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
83                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
84                 if (ret < 0)
85                         pr_err("%s: gpio_request failed for gpio %s\n",
86                                 __func__, "CAM2_POWER_DWN_GPIO");
87
88                 tegra_gpio_enable(OV5650_RESETN_GPIO);
89                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
90                 if (ret < 0)
91                         pr_err("%s: gpio_request failed for gpio %s\n",
92                                 __func__, "OV5650_RESETN_GPIO");
93
94                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
95                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
96                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
97                 mdelay(10);
98
99                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
100                 mdelay(5);
101                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
102                 mdelay(5);
103                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
104                 mdelay(5);
105         }
106
107         /* To select the CSIB MUX either for cam2 or cam3 */
108         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
109         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
110         if (ret < 0)
111                 pr_err("%s: gpio_request failed for gpio %s\n",
112                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
113         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
114         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
115
116         return 0;
117 }
118
119 static int cardhu_left_ov5650_power_on(void)
120 {
121         /* Boards E1198 and E1291 are of Cardhu personality
122          * and donot have TCA6416 exp for camera */
123         if ((board_info.board_id == BOARD_E1198) ||
124                 (board_info.board_id == BOARD_E1291)) {
125
126                 if (cardhu_vdd_2v8_cam1 == NULL) {
127                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
128                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
129                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
130                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
131                                 goto reg_alloc_fail;
132                         }
133                 }
134                 regulator_enable(cardhu_vdd_2v8_cam1);
135                 mdelay(5);
136         }
137
138         /* Enable VDD_1V8_Cam1 */
139         if (cardhu_1v8_cam1 == NULL) {
140                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
141                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
142                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
143                                 __func__, PTR_ERR(cardhu_1v8_cam1));
144                         goto reg_alloc_fail;
145                 }
146         }
147         regulator_enable(cardhu_1v8_cam1);
148
149         mdelay(5);
150         if ((board_info.board_id == BOARD_E1198) ||
151                 (board_info.board_id == BOARD_E1291)) {
152                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
153                 mdelay(20);
154                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
155                 mdelay(100);
156                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
157         }
158         return 0;
159
160 reg_alloc_fail:
161         if (cardhu_1v8_cam1) {
162                 regulator_put(cardhu_1v8_cam1);
163                 cardhu_1v8_cam1 = NULL;
164         }
165         if (cardhu_vdd_2v8_cam1) {
166                 regulator_put(cardhu_vdd_2v8_cam1);
167                 cardhu_vdd_2v8_cam1 = NULL;
168         }
169
170         return -ENODEV;
171
172 }
173
174 static int cardhu_left_ov5650_power_off(void)
175 {
176         /* Boards E1198 and E1291 are of Cardhu personality
177          * and donot have TCA6416 exp for camera */
178         if ((board_info.board_id == BOARD_E1198) ||
179                 (board_info.board_id == BOARD_E1291)) {
180                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
181                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
182                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
183         }
184         if (cardhu_1v8_cam1)
185                 regulator_disable(cardhu_1v8_cam1);
186         if (cardhu_vdd_2v8_cam1)
187                 regulator_disable(cardhu_vdd_2v8_cam1);
188
189         return 0;
190 }
191
192 struct ov5650_platform_data cardhu_left_ov5650_data = {
193         .power_on = cardhu_left_ov5650_power_on,
194         .power_off = cardhu_left_ov5650_power_off,
195 };
196
197 static int cardhu_right_ov5650_power_on(void)
198 {
199         /* Boards E1198 and E1291 are of Cardhu personality
200          * and donot have TCA6416 exp for camera */
201         if ((board_info.board_id == BOARD_E1198) ||
202                 (board_info.board_id == BOARD_E1291)) {
203
204                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
205                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
206                 mdelay(10);
207
208                 if (cardhu_vdd_2v8_cam2 == NULL) {
209                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
210                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
211                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
212                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
213                                 goto reg_alloc_fail;
214                         }
215                 }
216                 regulator_enable(cardhu_vdd_2v8_cam2);
217                 mdelay(5);
218         }
219
220         /* Enable VDD_1V8_Cam2 */
221         if (cardhu_1v8_cam2 == NULL) {
222                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
223                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
224                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
225                                 __func__, PTR_ERR(cardhu_1v8_cam2));
226                         goto reg_alloc_fail;
227                 }
228         }
229         regulator_enable(cardhu_1v8_cam2);
230
231         mdelay(5);
232         return 0;
233
234 reg_alloc_fail:
235         if (cardhu_1v8_cam2) {
236                 regulator_put(cardhu_1v8_cam2);
237                 cardhu_1v8_cam2 = NULL;
238         }
239         if (cardhu_vdd_2v8_cam2) {
240                 regulator_put(cardhu_vdd_2v8_cam2);
241                 cardhu_vdd_2v8_cam2 = NULL;
242         }
243
244         return -ENODEV;
245
246 }
247
248 static int cardhu_right_ov5650_power_off(void)
249 {
250         /* Boards E1198 and E1291 are of Cardhu personality
251          * and donot have TCA6416 exp for camera */
252         if ((board_info.board_id == BOARD_E1198) ||
253                 (board_info.board_id == BOARD_E1291)) {
254                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
255                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
256         }
257
258         if (cardhu_1v8_cam2)
259                 regulator_disable(cardhu_1v8_cam2);
260         if (cardhu_vdd_2v8_cam2)
261                 regulator_disable(cardhu_vdd_2v8_cam2);
262
263         return 0;
264 }
265
266 static void cardhu_ov5650_synchronize_sensors(void)
267 {
268         if (board_info.board_id == BOARD_E1198) {
269                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
270                 mdelay(50);
271                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
272                 mdelay(50);
273         }
274         else if (board_info.board_id == BOARD_E1291) {
275                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
276                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
277                 mdelay(50);
278                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
279                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
280                 mdelay(50);
281         }
282         else
283                 pr_err("%s: UnSupported BoardId\n", __func__);
284 }
285
286 struct ov5650_platform_data cardhu_right_ov5650_data = {
287         .power_on = cardhu_right_ov5650_power_on,
288         .power_off = cardhu_right_ov5650_power_off,
289         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
290 };
291
292 static int cardhu_ov2710_power_on(void)
293 {
294         /* CSI-B and front sensor are muxed on verbier */
295         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
296
297         /* Boards E1198 and E1291 are of Cardhu personality
298          * and donot have TCA6416 exp for camera */
299         if ((board_info.board_id == BOARD_E1198) ||
300                 (board_info.board_id == BOARD_E1291)) {
301
302                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
303                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
304                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
305                 mdelay(10);
306
307                 if (cardhu_vdd_cam3 == NULL) {
308                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
309                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
310                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
311                                         __func__, PTR_ERR(cardhu_vdd_cam3));
312                                 goto reg_alloc_fail;
313                         }
314                 }
315                 regulator_enable(cardhu_vdd_cam3);
316         }
317
318         /* Enable VDD_1V8_Cam3 */
319         if (cardhu_1v8_cam3 == NULL) {
320                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
321                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
322                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
323                                 __func__, PTR_ERR(cardhu_1v8_cam3));
324                         goto reg_alloc_fail;
325                 }
326         }
327         regulator_enable(cardhu_1v8_cam3);
328         mdelay(5);
329
330         return 0;
331
332 reg_alloc_fail:
333         if (cardhu_1v8_cam3) {
334                 regulator_put(cardhu_1v8_cam3);
335                 cardhu_1v8_cam3 = NULL;
336         }
337         if (cardhu_vdd_cam3) {
338                 regulator_put(cardhu_vdd_cam3);
339                 cardhu_vdd_cam3 = NULL;
340         }
341
342         return -ENODEV;
343 }
344
345 static int cardhu_ov2710_power_off(void)
346 {
347         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
348
349         /* Boards E1198 and E1291 are of Cardhu personality
350          * and donot have TCA6416 exp for camera */
351         if ((board_info.board_id == BOARD_E1198) ||
352                 (board_info.board_id == BOARD_E1291)) {
353                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
354                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
355                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
356         }
357
358         if (cardhu_1v8_cam3)
359                 regulator_disable(cardhu_1v8_cam3);
360         if (cardhu_vdd_cam3)
361                 regulator_disable(cardhu_vdd_cam3);
362
363         return 0;
364 }
365
366 struct ov2710_platform_data cardhu_ov2710_data = {
367         .power_on = cardhu_ov2710_power_on,
368         .power_off = cardhu_ov2710_power_off,
369 };
370
371 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
372         {
373                 I2C_BOARD_INFO("pca9546", 0x70),
374                 .platform_data = &cardhu_pca954x_data,
375         },
376 };
377
378 static int sh532u_power_control(void *cdata, int is_enable) {
379         static struct regulator *vdd_2v8_cam1_af = NULL;
380         if (vdd_2v8_cam1_af == NULL) {
381                 vdd_2v8_cam1_af = regulator_get(NULL, "vdd_2v8_cam1_af");
382                 if (WARN_ON(IS_ERR_OR_NULL(vdd_2v8_cam1_af))) {
383                         pr_err("%s: couldn't get regulator vdd_2v8_cam1_af:"
384                                 " %ld\n", __func__, PTR_ERR(vdd_2v8_cam1_af));
385                         return -ENODEV;
386                 }
387         }
388         if (is_enable) {
389                 regulator_enable(vdd_2v8_cam1_af);
390                 mdelay(20);
391         } else
392                 regulator_disable(vdd_2v8_cam1_af);
393         return 0;
394 }
395 static int sh532u_init(void *cdata) {
396         return sh532u_power_control(cdata, true);
397 }
398 static int sh532u_deinit(void *cdata) {
399         return sh532u_power_control(cdata, false);
400 }
401
402 struct sh532u_platform_data sh532u_pdata = {
403         .board_init = sh532u_init,
404         .board_deinit = sh532u_deinit,
405 };
406 static struct i2c_board_info cardhu_i2c6_board_info[] = {
407         {
408                 I2C_BOARD_INFO("ov5650L", 0x36),
409                 .platform_data = &cardhu_left_ov5650_data,
410         },
411         {
412                 I2C_BOARD_INFO("sh532u", 0x72),
413                 .platform_data = &sh532u_pdata,
414         },
415 };
416
417 static struct i2c_board_info cardhu_i2c7_board_info[] = {
418         {
419                 I2C_BOARD_INFO("ov5650R", 0x36),
420                 .platform_data = &cardhu_right_ov5650_data,
421         },
422 };
423
424 static struct i2c_board_info cardhu_i2c8_board_info[] = {
425         {
426                 I2C_BOARD_INFO("ov2710", 0x36),
427                 .platform_data = &cardhu_ov2710_data,
428         },
429 };
430
431 static struct nct1008_platform_data cardhu_nct1008_pdata = {
432         .supported_hwrev = true,
433         .ext_range = false,
434         .conv_rate = 0x08,
435         .offset = 0,
436         .hysteresis = 5,
437         .shutdown_ext_limit = 75,
438         .shutdown_local_limit = 75,
439         .throttling_ext_limit = 60,
440         .alarm_fn = NULL,
441 };
442
443 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
444         {
445                 I2C_BOARD_INFO("bq27510", 0x55),
446                 .irq = AC_PRESENT_GPIO,
447         },
448 };
449
450 static struct i2c_board_info cardhu_i2c4_board_info[] = {
451         {
452                 I2C_BOARD_INFO("nct1008", 0x4C),
453                 .platform_data = &cardhu_nct1008_pdata,
454                 .irq = -1,
455         }
456 };
457
458 static int cardhu_nct1008_init(void)
459 {
460         int nct1008_port = -1;
461         int ret;
462
463         if ((board_info.board_id == BOARD_E1198) ||
464                 (board_info.board_id == BOARD_E1291)) {
465                 nct1008_port = TEGRA_GPIO_PCC2;
466         } else if ((board_info.board_id == BOARD_E1186) ||
467                 (board_info.board_id == BOARD_E1187)) {
468                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
469                 /* nct1008_port = TEGRA_GPIO_PH7; */
470         }
471
472         if (nct1008_port >= 0) {
473                 /* FIXME: enable irq when throttling is supported */
474                 /* cardhu_i2c4_board_info[0].irq = */
475                 /* TEGRA_GPIO_TO_IRQ(nct1008_port); */
476
477                 ret = gpio_request(nct1008_port, "temp_alert");
478                 if (ret < 0)
479                         return ret;
480
481                 ret = gpio_direction_input(nct1008_port);
482                 if (ret < 0)
483                         gpio_free(nct1008_port);
484                 else
485                         tegra_gpio_enable(nct1008_port);
486
487         }
488         return ret;
489 }
490
491 #if defined(CONFIG_GPIO_PCA953X)
492 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
493         .gpio_base      = PMU_TCA6416_GPIO_BASE,
494 };
495
496 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
497         {
498                 I2C_BOARD_INFO("tca6416", 0x20),
499                 .platform_data = &cardhu_pmu_tca6416_data,
500         },
501 };
502
503 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
504         .gpio_base      = CAM_TCA6416_GPIO_BASE,
505 };
506
507 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
508         {
509                 I2C_BOARD_INFO("tca6416", 0x20),
510                 .platform_data = &cardhu_cam_tca6416_data,
511         },
512 };
513
514 static int __init pmu_tca6416_init(void)
515 {
516         if ((board_info.board_id == BOARD_E1198) ||
517                 (board_info.board_id == BOARD_E1291))
518                         return 0;
519
520         pr_info("Registering pmu pca6416\n");
521         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
522                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
523         return 0;
524 }
525
526 static int __init cam_tca6416_init(void)
527 {
528         /* Boards E1198 and E1291 are of Cardhu personality
529          * and donot have TCA6416 exp for camera */
530         if ((board_info.board_id == BOARD_E1198) ||
531                 (board_info.board_id == BOARD_E1291))
532                 return 0;
533
534         pr_info("Registering cam pca6416\n");
535         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
536                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
537         return 0;
538 }
539 #else
540 static int __init pmu_tca6416_init(void)
541 {
542         return 0;
543 }
544
545 static int __init cam_tca6416_init(void)
546 {
547         return 0;
548 }
549 #endif
550
551 #ifdef CONFIG_SENSORS_MPU3050
552 #define SENSOR_MPU_NAME "mpu3050"
553 static struct mpu3050_platform_data mpu3050_data = {
554         .int_config  = 0x10,
555         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
556         .level_shifter = 0,
557
558         .accel = {
559         .get_slave_descr = get_accel_slave_descr,
560         .adapt_num   = 2,
561         .bus         = EXT_SLAVE_BUS_SECONDARY,
562         .address     = 0x0F,
563         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
564         },
565
566         .compass = {
567         .get_slave_descr = get_compass_slave_descr,
568         .adapt_num   = 2,
569         .bus         = EXT_SLAVE_BUS_PRIMARY,
570         .address     = 0x0C,
571         .orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 },  /* Orientation matrix for AKM on cardhu */
572         },
573 };
574
575 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
576         {
577                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
578                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
579                 .platform_data = &mpu3050_data,
580         },
581 };
582
583 static void cardhu_mpuirq_init(void)
584 {
585         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
586         tegra_gpio_enable(TEGRA_GPIO_PX1);
587         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
588         gpio_direction_input(TEGRA_GPIO_PX1);
589         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
590 }
591 #endif
592
593
594 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
595         {
596                 I2C_BOARD_INFO("isl29028", 0x44),
597         }
598 };
599
600 int __init cardhu_sensors_init(void)
601 {
602         int err;
603
604         tegra_get_board_info(&board_info);
605
606         cardhu_camera_init();
607         cam_tca6416_init();
608
609         i2c_register_board_info(2, cardhu_i2c3_board_info,
610                 ARRAY_SIZE(cardhu_i2c3_board_info));
611
612         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
613          * Front camera is on BUS2 */
614         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
615                 ARRAY_SIZE(cardhu_i2c6_board_info));
616
617         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
618                 ARRAY_SIZE(cardhu_i2c7_board_info));
619
620         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
621                 ARRAY_SIZE(cardhu_i2c8_board_info));
622
623         pmu_tca6416_init();
624
625         i2c_register_board_info(4, cardhu_i2c4_board_info,
626                 ARRAY_SIZE(cardhu_i2c4_board_info));
627
628         if (board_info.board_id == BOARD_E1291)
629                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
630                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
631
632         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
633                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
634
635         err = cardhu_nct1008_init();
636         if (err)
637                 return err;
638
639 #ifdef CONFIG_SENSORS_MPU3050
640         cardhu_mpuirq_init();
641 #endif
642
643 #ifdef CONFIG_SENSORS_MPU3050
644         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
645                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
646 #endif
647
648         return 0;
649 }
650
651 #if defined(CONFIG_GPIO_PCA953X)
652 struct ov5650_gpios {
653         const char *name;
654         int gpio;
655         int enabled;
656 };
657
658 #define OV5650_GPIO(_name, _gpio, _enabled)             \
659         {                                               \
660                 .name = _name,                          \
661                 .gpio = _gpio,                          \
662                 .enabled = _enabled,                    \
663         }
664
665 static struct ov5650_gpios ov5650_gpio_keys[] = {
666         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
667         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
668         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 1),
669         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
670         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
671         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
672         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 1),
673         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
674         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
675         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
676         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 1),
677         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
678         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
679         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
680         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
681 };
682
683 int __init cardhu_ov5650_late_init(void)
684 {
685         int ret;
686         int i;
687
688         printk("%s: \n", __func__);
689         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
690                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
691                         ov5650_gpio_keys[i].name);
692                 if (ret < 0) {
693                         printk("%s: gpio_request failed for gpio #%d\n",
694                                 __func__, i);
695                         goto fail;
696                 }
697                 printk("%s: enable - %d\n", __func__, i);
698                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
699                         ov5650_gpio_keys[i].enabled);
700                 gpio_export(ov5650_gpio_keys[i].gpio, false);
701         }
702
703         return 0;
704
705 fail:
706         while (i--)
707                 gpio_free(ov5650_gpio_keys[i].gpio);
708         return ret;
709 }
710
711 late_initcall(cardhu_ov5650_late_init);
712 #endif