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