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