ARM: tegra: cardhu: add AC present interrupt gpio
[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
36 #include <mach/gpio.h>
37
38 #include "gpio-names.h"
39 #include "board-cardhu.h"
40
41 static struct regulator *cardhu_1v8_cam1 = NULL;
42 static struct regulator *cardhu_1v8_cam2 = NULL;
43 static struct regulator *cardhu_1v8_cam3 = NULL;
44 static struct regulator *cardhu_avdd_dsi_csi = 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 #ifdef CONFIG_I2C_MUX_PCA954x
52 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
53         { .adap_id = PCA954x_I2C_BUS0, },
54         { .adap_id = PCA954x_I2C_BUS1, },
55         { .adap_id = PCA954x_I2C_BUS2, },
56         { .adap_id = PCA954x_I2C_BUS3, },
57 };
58
59 static struct pca954x_platform_data cardhu_pca954x_data = {
60         .modes    = cardhu_pca954x_modes,
61         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
62 };
63 #endif
64
65 static int cardhu_camera_init(void)
66 {
67         int ret;
68
69         /* Boards E1198 and E1291 are of Cardhu personality
70          * and donot have TCA6416 exp for camera */
71         if ((board_info.board_id == BOARD_E1198) ||
72                 (board_info.board_id == BOARD_E1291)) {
73                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
74                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
75                 if (ret < 0)
76                         pr_err("%s: gpio_request failed for gpio %s\n",
77                                 __func__, "CAM1_POWER_DWN_GPIO");
78                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
79                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
80                 if (ret < 0)
81                         pr_err("%s: gpio_request failed for gpio %s\n",
82                                 __func__, "CAM3_POWER_DWN_GPIO");
83
84                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
85                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
86                 if (ret < 0)
87                         pr_err("%s: gpio_request failed for gpio %s\n",
88                                 __func__, "CAM2_POWER_DWN_GPIO");
89
90                 tegra_gpio_enable(OV5650_RESETN_GPIO);
91                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
92                 if (ret < 0)
93                         pr_err("%s: gpio_request failed for gpio %s\n",
94                                 __func__, "OV5650_RESETN_GPIO");
95
96                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
97                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
98                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
99                 mdelay(10);
100
101                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
102                 mdelay(5);
103                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
104                 mdelay(5);
105                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
106                 mdelay(5);
107         }
108
109         /* To select the CSIB MUX either for cam2 or cam3 */
110         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
111         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
112         if (ret < 0)
113                 pr_err("%s: gpio_request failed for gpio %s\n",
114                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
115         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
116         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
117
118         return 0;
119 }
120
121 static int cardhu_left_ov5650_power_on(void)
122 {
123         /* Boards E1198 and E1291 are of Cardhu personality
124          * and donot have TCA6416 exp for camera */
125         if ((board_info.board_id == BOARD_E1198) ||
126                 (board_info.board_id == BOARD_E1291)) {
127
128                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
129                 mdelay(10);
130
131                 if (cardhu_vdd_2v8_cam1 == NULL) {
132                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
133                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
134                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
135                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
136                                 goto reg_alloc_fail;
137                         }
138                 }
139                 regulator_enable(cardhu_vdd_2v8_cam1);
140                 mdelay(5);
141         }
142
143         /* Enable VDD_1V8_Cam1 */
144         if (cardhu_1v8_cam1 == NULL) {
145                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
146                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
147                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
148                                 __func__, PTR_ERR(cardhu_1v8_cam1));
149                         goto reg_alloc_fail;
150                 }
151         }
152         regulator_enable(cardhu_1v8_cam1);
153
154         /* Enable AVDD_CSI_DSI */
155         if (cardhu_avdd_dsi_csi == NULL) {
156                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
157                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
158                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
159                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
160                         goto reg_alloc_fail;
161                 }
162         }
163         regulator_enable(cardhu_avdd_dsi_csi);
164
165         mdelay(5);
166         return 0;
167
168 reg_alloc_fail:
169         if (cardhu_1v8_cam1) {
170                 regulator_put(cardhu_1v8_cam1);
171                 cardhu_1v8_cam1 = NULL;
172         }
173         if (cardhu_avdd_dsi_csi) {
174                 regulator_put(cardhu_avdd_dsi_csi);
175                 cardhu_avdd_dsi_csi = NULL;
176         }
177         if (cardhu_vdd_2v8_cam1) {
178                 regulator_put(cardhu_vdd_2v8_cam1);
179                 cardhu_vdd_2v8_cam1 = NULL;
180         }
181
182         return -ENODEV;
183
184 }
185
186 static int cardhu_left_ov5650_power_off(void)
187 {
188         /* Boards E1198 and E1291 are of Cardhu personality
189          * and donot have TCA6416 exp for camera */
190         if ((board_info.board_id == BOARD_E1198) ||
191                 (board_info.board_id == BOARD_E1291)) {
192                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
193                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
194                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
195         }
196         if (cardhu_1v8_cam1)
197                 regulator_disable(cardhu_1v8_cam1);
198         if (cardhu_avdd_dsi_csi)
199                 regulator_disable(cardhu_avdd_dsi_csi);
200         if (cardhu_vdd_2v8_cam1)
201                 regulator_disable(cardhu_vdd_2v8_cam1);
202
203         return 0;
204 }
205
206 struct ov5650_platform_data cardhu_left_ov5650_data = {
207         .power_on = cardhu_left_ov5650_power_on,
208         .power_off = cardhu_left_ov5650_power_off,
209 };
210
211 static int cardhu_right_ov5650_power_on(void)
212 {
213         /* Boards E1198 and E1291 are of Cardhu personality
214          * and donot have TCA6416 exp for camera */
215         if ((board_info.board_id == BOARD_E1198) ||
216                 (board_info.board_id == BOARD_E1291)) {
217
218                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
219                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
220                 mdelay(10);
221
222                 if (cardhu_vdd_2v8_cam2 == NULL) {
223                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
224                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
225                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
226                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
227                                 goto reg_alloc_fail;
228                         }
229                 }
230                 regulator_enable(cardhu_vdd_2v8_cam2);
231                 mdelay(5);
232         }
233
234         /* Enable VDD_1V8_Cam2 */
235         if (cardhu_1v8_cam2 == NULL) {
236                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
237                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
238                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
239                                 __func__, PTR_ERR(cardhu_1v8_cam2));
240                         goto reg_alloc_fail;
241                 }
242         }
243         regulator_enable(cardhu_1v8_cam2);
244
245         /* Enable AVDD_CSI_DSI */
246         if (cardhu_avdd_dsi_csi == NULL) {
247                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
248                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
249                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
250                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
251                         goto reg_alloc_fail;
252                 }
253         }
254         regulator_enable(cardhu_avdd_dsi_csi);
255
256         mdelay(5);
257         return 0;
258
259 reg_alloc_fail:
260         if (cardhu_1v8_cam2) {
261                 regulator_put(cardhu_1v8_cam2);
262                 cardhu_1v8_cam2 = NULL;
263         }
264         if (cardhu_avdd_dsi_csi) {
265                 regulator_put(cardhu_avdd_dsi_csi);
266                 cardhu_avdd_dsi_csi = NULL;
267         }
268         if (cardhu_vdd_2v8_cam2) {
269                 regulator_put(cardhu_vdd_2v8_cam2);
270                 cardhu_vdd_2v8_cam2 = NULL;
271         }
272
273         return -ENODEV;
274
275 }
276
277 static int cardhu_right_ov5650_power_off(void)
278 {
279         /* Boards E1198 and E1291 are of Cardhu personality
280          * and donot have TCA6416 exp for camera */
281         if ((board_info.board_id == BOARD_E1198) ||
282                 (board_info.board_id == BOARD_E1291)) {
283                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
284                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
285         }
286
287         if (cardhu_1v8_cam2)
288                 regulator_disable(cardhu_1v8_cam2);
289         if (cardhu_avdd_dsi_csi)
290                 regulator_disable(cardhu_avdd_dsi_csi);
291         if (cardhu_vdd_2v8_cam2)
292                 regulator_disable(cardhu_vdd_2v8_cam2);
293
294         return 0;
295 }
296
297
298 struct ov5650_platform_data cardhu_right_ov5650_data = {
299         .power_on = cardhu_right_ov5650_power_on,
300         .power_off = cardhu_right_ov5650_power_off,
301 };
302
303 static int cardhu_ov2710_power_on(void)
304 {
305         /* CSI-B and front sensor are muxed on verbier */
306         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
307
308         /* Boards E1198 and E1291 are of Cardhu personality
309          * and donot have TCA6416 exp for camera */
310         if ((board_info.board_id == BOARD_E1198) ||
311                 (board_info.board_id == BOARD_E1291)) {
312
313                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
314                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
315                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
316                 mdelay(10);
317
318                 if (cardhu_vdd_cam3 == NULL) {
319                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
320                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
321                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
322                                         __func__, PTR_ERR(cardhu_vdd_cam3));
323                                 goto reg_alloc_fail;
324                         }
325                 }
326                 regulator_enable(cardhu_vdd_cam3);
327         }
328
329         /* Enable VDD_1V8_Cam3 */
330         if (cardhu_1v8_cam3 == NULL) {
331                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
332                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
333                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
334                                 __func__, PTR_ERR(cardhu_1v8_cam3));
335                         goto reg_alloc_fail;
336                 }
337         }
338         regulator_enable(cardhu_1v8_cam3);
339
340         /* Enable AVDD_CSI_DSI */
341         if (cardhu_avdd_dsi_csi == NULL) {
342                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
343                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
344                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
345                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
346                         goto reg_alloc_fail;
347                 }
348         }
349         regulator_enable(cardhu_avdd_dsi_csi);
350         mdelay(5);
351
352         return 0;
353
354 reg_alloc_fail:
355         if (cardhu_1v8_cam3) {
356                 regulator_put(cardhu_1v8_cam3);
357                 cardhu_1v8_cam3 = NULL;
358         }
359         if (cardhu_avdd_dsi_csi) {
360                 regulator_put(cardhu_avdd_dsi_csi);
361                 cardhu_avdd_dsi_csi = NULL;
362         }
363         if (cardhu_vdd_cam3) {
364                 regulator_put(cardhu_vdd_cam3);
365                 cardhu_vdd_cam3 = NULL;
366         }
367
368         return -ENODEV;
369 }
370
371 static int cardhu_ov2710_power_off(void)
372 {
373         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
374
375         /* Boards E1198 and E1291 are of Cardhu personality
376          * and donot have TCA6416 exp for camera */
377         if ((board_info.board_id == BOARD_E1198) ||
378                 (board_info.board_id == BOARD_E1291)) {
379                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
380                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
381                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
382         }
383
384         if (cardhu_1v8_cam3)
385                 regulator_disable(cardhu_1v8_cam3);
386         if (cardhu_avdd_dsi_csi)
387                 regulator_disable(cardhu_avdd_dsi_csi);
388         if (cardhu_vdd_cam3)
389                 regulator_disable(cardhu_vdd_cam3);
390
391         return 0;
392 }
393
394 struct ov2710_platform_data cardhu_ov2710_data = {
395         .power_on = cardhu_ov2710_power_on,
396         .power_off = cardhu_ov2710_power_off,
397 };
398
399 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
400 #ifdef CONFIG_I2C_MUX_PCA954x
401         {
402                 I2C_BOARD_INFO("pca9546", 0x70),
403                 .platform_data = &cardhu_pca954x_data,
404         },
405 #endif
406 };
407 static struct i2c_board_info cardhu_i2c6_board_info[] = {
408         {
409                 I2C_BOARD_INFO("ov5650L", 0x36),
410                 .platform_data = &cardhu_left_ov5650_data,
411         },
412         {
413                 I2C_BOARD_INFO("sh532u", 0x72),
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         if (ARRAY_SIZE(cardhu_i2c3_board_info))
644                 i2c_register_board_info(3, cardhu_i2c3_board_info,
645                         ARRAY_SIZE(cardhu_i2c3_board_info));
646
647 #ifdef CONFIG_SENSORS_MPU3050
648         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
649                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
650 #endif
651
652         return 0;
653 }
654
655 #if defined(CONFIG_GPIO_PCA953X)
656 struct ov5650_gpios {
657         const char *name;
658         int gpio;
659         int enabled;
660 };
661
662 #define OV5650_GPIO(_name, _gpio, _enabled)             \
663         {                                               \
664                 .name = _name,                          \
665                 .gpio = _gpio,                          \
666                 .enabled = _enabled,                    \
667         }
668
669 static struct ov5650_gpios ov5650_gpio_keys[] = {
670         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
671         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
672         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 1),
673         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
674         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
675         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
676         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 1),
677         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
678         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
679         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
680         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 1),
681         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
682         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
683         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
684         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
685 };
686
687 int __init cardhu_ov5650_late_init(void)
688 {
689         int ret;
690         int i;
691
692         printk("%s: \n", __func__);
693         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
694                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
695                         ov5650_gpio_keys[i].name);
696                 if (ret < 0) {
697                         printk("%s: gpio_request failed for gpio #%d\n",
698                                 __func__, i);
699                         goto fail;
700                 }
701                 printk("%s: enable - %d\n", __func__, i);
702                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
703                         ov5650_gpio_keys[i].enabled);
704                 gpio_export(ov5650_gpio_keys[i].gpio, false);
705         }
706
707         return 0;
708
709 fail:
710         while (i--)
711                 gpio_free(ov5650_gpio_keys[i].gpio);
712         return ret;
713 }
714
715 late_initcall(cardhu_ov5650_late_init);
716 #endif