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