media: video: tegra: pass device as argument in power_on
[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-2012, 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 <linux/gpio.h>
41
42 #include <mach/gpio-tegra.h>
43 #include <mach/fb.h>
44 #include <media/ov5650.h>
45 #include <media/ov5640.h>
46 #include <media/ov14810.h>
47 #include <media/ov2710.h>
48 #include <media/tps61050.h>
49 #include <media/imx091.h>
50 #include <generated/mach-types.h>
51 #include "board.h"
52 #include <linux/mpu.h>
53 #include <media/sh532u.h>
54 #include <media/ad5816.h>
55 #include <linux/bq27x00.h>
56 #include <mach/edp.h>
57 #include <mach/thermal.h>
58 #include <linux/therm_est.h>
59
60 #include "gpio-names.h"
61 #include "board-cardhu.h"
62 #include "cpu-tegra.h"
63 #include "devices.h"
64
65 static struct regulator *cardhu_1v8_cam1 = NULL;
66 static struct regulator *cardhu_1v8_cam2 = NULL;
67 static struct regulator *cardhu_1v8_cam3 = NULL;
68 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
69 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
70 static struct regulator *cardhu_vdd_cam3 = NULL;
71
72 static struct board_info board_info;
73
74 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
75         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
76         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
77         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
78         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
79 };
80
81 static struct pca954x_platform_data cardhu_pca954x_data = {
82         .modes    = cardhu_pca954x_modes,
83         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
84 };
85
86 static int cardhu_camera_init(void)
87 {
88         int ret;
89
90         /* Boards E1198 and E1291 are of Cardhu personality
91          * and donot have TCA6416 exp for camera */
92         if ((board_info.board_id == BOARD_E1198) ||
93                 (board_info.board_id == BOARD_E1291)) {
94                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
95                 if (ret < 0)
96                         pr_err("%s: gpio_request failed for gpio %s\n",
97                                 __func__, "CAM1_POWER_DWN_GPIO");
98                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
99                 if (ret < 0)
100                         pr_err("%s: gpio_request failed for gpio %s\n",
101                                 __func__, "CAM3_POWER_DWN_GPIO");
102
103                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
104                 if (ret < 0)
105                         pr_err("%s: gpio_request failed for gpio %s\n",
106                                 __func__, "CAM2_POWER_DWN_GPIO");
107
108                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
109                 if (ret < 0)
110                         pr_err("%s: gpio_request failed for gpio %s\n",
111                                 __func__, "OV5650_RESETN_GPIO");
112
113                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
114                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
115                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
116                 mdelay(10);
117
118                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
119                 mdelay(5);
120                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
121                 mdelay(5);
122                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
123                 mdelay(5);
124         }
125
126         /* To select the CSIB MUX either for cam2 or cam3 */
127         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
128         if (ret < 0)
129                 pr_err("%s: gpio_request failed for gpio %s\n",
130                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
131         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
132         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
133
134         return 0;
135 }
136
137 static int cardhu_left_ov5650_power_on(struct device *dev)
138 {
139         /* Boards E1198 and E1291 are of Cardhu personality
140          * and donot have TCA6416 exp for camera */
141         if ((board_info.board_id == BOARD_E1198) ||
142                 (board_info.board_id == BOARD_E1291)) {
143
144                 if (cardhu_vdd_2v8_cam1 == NULL) {
145                         cardhu_vdd_2v8_cam1 =
146                                 regulator_get(dev, "vdd_2v8_cam1");
147                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
148                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
149                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
150                                 goto reg_alloc_fail;
151                         }
152                 }
153                 regulator_enable(cardhu_vdd_2v8_cam1);
154                 mdelay(5);
155         }
156
157         /* Enable VDD_1V8_Cam1 */
158         if (cardhu_1v8_cam1 == NULL) {
159                 cardhu_1v8_cam1 = regulator_get(dev, "vdd_1v8_cam1");
160                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
161                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
162                                 __func__, PTR_ERR(cardhu_1v8_cam1));
163                         goto reg_alloc_fail;
164                 }
165         }
166         regulator_enable(cardhu_1v8_cam1);
167
168         mdelay(5);
169         if ((board_info.board_id == BOARD_E1198) ||
170                 (board_info.board_id == BOARD_E1291)) {
171                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
172                 mdelay(20);
173                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
174                 mdelay(100);
175                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
176         }
177
178         if (board_info.board_id == BOARD_PM269) {
179                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
180                 mdelay(100);
181                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
182         }
183
184         return 0;
185
186 reg_alloc_fail:
187         if (cardhu_1v8_cam1) {
188                 regulator_put(cardhu_1v8_cam1);
189                 cardhu_1v8_cam1 = NULL;
190         }
191         if (cardhu_vdd_2v8_cam1) {
192                 regulator_put(cardhu_vdd_2v8_cam1);
193                 cardhu_vdd_2v8_cam1 = NULL;
194         }
195
196         return -ENODEV;
197
198 }
199
200 static int cardhu_left_ov5650_power_off(struct device *dev)
201 {
202         /* Boards E1198 and E1291 are of Cardhu personality
203          * and donot have TCA6416 exp for camera */
204         if ((board_info.board_id == BOARD_E1198) ||
205                 (board_info.board_id == BOARD_E1291)) {
206                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
207                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
208                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
209         }
210         if (cardhu_1v8_cam1)
211                 regulator_disable(cardhu_1v8_cam1);
212         if (cardhu_vdd_2v8_cam1)
213                 regulator_disable(cardhu_vdd_2v8_cam1);
214
215         return 0;
216 }
217
218 struct ov5650_platform_data cardhu_left_ov5650_data = {
219         .power_on = cardhu_left_ov5650_power_on,
220         .power_off = cardhu_left_ov5650_power_off,
221 };
222
223 #ifdef CONFIG_VIDEO_OV14810
224 static int cardhu_ov14810_power_on(void)
225 {
226         if (board_info.board_id == BOARD_E1198) {
227                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
228                 mdelay(20);
229                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
230                 mdelay(100);
231                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
232         }
233
234         return 0;
235 }
236
237 static int cardhu_ov14810_power_off(void)
238 {
239         if (board_info.board_id == BOARD_E1198) {
240                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
241                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
242                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
243         }
244
245         return 0;
246 }
247
248 struct ov14810_platform_data cardhu_ov14810_data = {
249         .power_on = cardhu_ov14810_power_on,
250         .power_off = cardhu_ov14810_power_off,
251 };
252
253 struct ov14810_platform_data cardhu_ov14810uC_data = {
254         .power_on = NULL,
255         .power_off = NULL,
256 };
257
258 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
259         .power_on = NULL,
260         .power_off = NULL,
261 };
262
263 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
264         {
265                 I2C_BOARD_INFO("ov14810", 0x36),
266                 .platform_data = &cardhu_ov14810_data,
267         },
268         {
269                 I2C_BOARD_INFO("ov14810uC", 0x67),
270                 .platform_data = &cardhu_ov14810uC_data,
271         },
272         {
273                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
274                 .platform_data = &cardhu_ov14810SlaveDev_data,
275         }
276 };
277 #endif
278
279 #ifdef CONFIG_VIDEO_IMX091
280 static int cardhu_imx091_power_on(struct device *dev)
281 {
282         /* Boards E1198 and E1291 are of Cardhu personality
283         * and donot have TCA6416 exp for camera */
284         if ((board_info.board_id == BOARD_E1198) ||
285                 (board_info.board_id == BOARD_E1291)) {
286
287                         if (cardhu_vdd_2v8_cam1 == NULL) {
288                                 cardhu_vdd_2v8_cam1 =
289                                         regulator_get(dev, "vdd_2v8_cam1");
290                                 if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
291                                         pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
292                                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
293                                                 goto reg_alloc_fail;
294                                         }
295                         }
296                 regulator_enable(cardhu_vdd_2v8_cam1);
297                 mdelay(5);
298         }
299
300         /* Enable VDD_1V8_Cam1 */
301         if (cardhu_1v8_cam1 == NULL) {
302                         cardhu_1v8_cam1 = regulator_get(dev, "vdd_1v8_cam1");
303                         if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
304                                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
305                                                         __func__, PTR_ERR(cardhu_1v8_cam1));
306                                         goto reg_alloc_fail;
307                         }
308         }
309         regulator_enable(cardhu_1v8_cam1);
310
311         mdelay(5);
312         if ((board_info.board_id == BOARD_E1198) ||
313                         (board_info.board_id == BOARD_E1291)) {
314                         gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
315                         mdelay(20);
316         }
317         return 0;
318
319 reg_alloc_fail:
320         if (cardhu_1v8_cam1) {
321                         regulator_put(cardhu_1v8_cam1);
322                         cardhu_1v8_cam1 = NULL;
323         }
324         if (cardhu_vdd_2v8_cam1) {
325                         regulator_put(cardhu_vdd_2v8_cam1);
326                         cardhu_vdd_2v8_cam1 = NULL;
327         }
328
329         return -ENODEV;
330
331 }
332
333 static int cardhu_imx091_power_off(void)
334 {
335         /* Boards E1198 and E1291 are of Cardhu personality
336          * and donot have TCA6416 exp for camera */
337         if ((board_info.board_id == BOARD_E1198) ||
338                         (board_info.board_id == BOARD_E1291)) {
339                         gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
340         }
341         if (cardhu_1v8_cam1)
342                         regulator_disable(cardhu_1v8_cam1);
343         if (cardhu_vdd_2v8_cam1)
344                         regulator_disable(cardhu_vdd_2v8_cam1);
345
346         return 0;
347 }
348
349 struct imx091_platform_data cardhu_imx091_data = {
350         .power_on = cardhu_imx091_power_on,
351         .power_off = cardhu_imx091_power_off,
352 };
353
354
355 static struct i2c_board_info cardhu_i2c_board_info_e1244[] = {
356         {
357                 I2C_BOARD_INFO("imx091", 0x36),
358                 .platform_data = &cardhu_imx091_data,
359         },
360 };
361 #endif /* CONFIG_VIDEO_IMX091 */
362
363
364
365 static int cardhu_right_ov5650_power_on(struct device *dev)
366 {
367         /* CSI-B and front sensor are muxed on cardhu */
368         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
369
370         /* Boards E1198 and E1291 are of Cardhu personality
371          * and donot have TCA6416 exp for camera */
372         if ((board_info.board_id == BOARD_E1198) ||
373                 (board_info.board_id == BOARD_E1291)) {
374
375                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
376                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
377                 mdelay(10);
378
379                 if (cardhu_vdd_2v8_cam2 == NULL) {
380                         cardhu_vdd_2v8_cam2 =
381                                 regulator_get(dev, "vdd_2v8_cam2");
382                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
383                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
384                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
385                                 goto reg_alloc_fail;
386                         }
387                 }
388                 regulator_enable(cardhu_vdd_2v8_cam2);
389                 mdelay(5);
390         }
391
392         /* Enable VDD_1V8_Cam2 */
393         if (cardhu_1v8_cam2 == NULL) {
394                 cardhu_1v8_cam2 = regulator_get(dev, "vdd_1v8_cam2");
395                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
396                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
397                                 __func__, PTR_ERR(cardhu_1v8_cam2));
398                         goto reg_alloc_fail;
399                 }
400         }
401         regulator_enable(cardhu_1v8_cam2);
402
403         mdelay(5);
404
405         if (board_info.board_id == BOARD_PM269) {
406                 gpio_direction_output(CAM2_RST_L_GPIO, 0);
407                 mdelay(100);
408                 gpio_direction_output(CAM2_RST_L_GPIO, 1);
409         }
410
411         return 0;
412
413 reg_alloc_fail:
414         if (cardhu_1v8_cam2) {
415                 regulator_put(cardhu_1v8_cam2);
416                 cardhu_1v8_cam2 = NULL;
417         }
418         if (cardhu_vdd_2v8_cam2) {
419                 regulator_put(cardhu_vdd_2v8_cam2);
420                 cardhu_vdd_2v8_cam2 = NULL;
421         }
422
423         return -ENODEV;
424
425 }
426
427 static int cardhu_right_ov5650_power_off(struct device *dev)
428 {
429         /* CSI-B and front sensor are muxed on cardhu */
430         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
431
432         /* Boards E1198 and E1291 are of Cardhu personality
433          * and do not have TCA6416 for camera */
434         if ((board_info.board_id == BOARD_E1198) ||
435                 (board_info.board_id == BOARD_E1291)) {
436                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
437                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
438                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
439         }
440
441         if (cardhu_1v8_cam2)
442                 regulator_disable(cardhu_1v8_cam2);
443         if (cardhu_vdd_2v8_cam2)
444                 regulator_disable(cardhu_vdd_2v8_cam2);
445
446         return 0;
447 }
448
449 static void cardhu_ov5650_synchronize_sensors(void)
450 {
451         if (board_info.board_id == BOARD_E1198) {
452                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
453                 mdelay(50);
454                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
455                 mdelay(50);
456         }
457         else if (board_info.board_id == BOARD_E1291) {
458                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
459                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
460                 mdelay(50);
461                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
462                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
463                 mdelay(50);
464         }
465         else
466                 pr_err("%s: UnSupported BoardId\n", __func__);
467 }
468
469 struct ov5650_platform_data cardhu_right_ov5650_data = {
470         .power_on = cardhu_right_ov5650_power_on,
471         .power_off = cardhu_right_ov5650_power_off,
472         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
473 };
474
475 static int cardhu_ov2710_power_on(struct device *dev)
476 {
477         /* CSI-B and front sensor are muxed on cardhu */
478         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
479
480         /* Enable VDD_1V8_Cam3 */
481         if (cardhu_1v8_cam3 == NULL) {
482                 cardhu_1v8_cam3 = regulator_get(dev, "vdd_1v8_cam3");
483                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
484                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
485                                 __func__, PTR_ERR(cardhu_1v8_cam3));
486                         goto reg_alloc_fail;
487                 }
488         }
489         regulator_enable(cardhu_1v8_cam3);
490
491         /* Boards E1198 and E1291 are of Cardhu personality
492          * and do not have TCA6416 for camera */
493         if ((board_info.board_id == BOARD_E1198) ||
494                 (board_info.board_id == BOARD_E1291)) {
495                 if (cardhu_vdd_cam3 == NULL) {
496                         cardhu_vdd_cam3 = regulator_get(dev, "vdd_cam3");
497                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
498                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
499                                         __func__, PTR_ERR(cardhu_vdd_cam3));
500                                 goto reg_alloc_fail;
501                         }
502                 }
503                 regulator_enable(cardhu_vdd_cam3);
504
505                 mdelay(5);
506
507                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
508                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
509                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
510                 mdelay(10);
511
512         }
513
514         mdelay(20);
515
516         return 0;
517
518 reg_alloc_fail:
519         if (cardhu_1v8_cam3) {
520                 regulator_put(cardhu_1v8_cam3);
521                 cardhu_1v8_cam3 = NULL;
522         }
523         if (cardhu_vdd_cam3) {
524                 regulator_put(cardhu_vdd_cam3);
525                 cardhu_vdd_cam3 = NULL;
526         }
527
528         return -ENODEV;
529 }
530
531 static int cardhu_ov2710_power_off(struct device *dev)
532 {
533         /* CSI-B and front sensor are muxed on cardhu */
534         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
535
536         /* Boards E1198 and E1291 are of Cardhu personality
537          * and donot have TCA6416 exp for camera */
538         if ((board_info.board_id == BOARD_E1198) ||
539                 (board_info.board_id == BOARD_E1291)) {
540                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
541                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
542                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
543                 if (cardhu_vdd_cam3)
544                         regulator_disable(cardhu_vdd_cam3);
545         }
546
547         if (cardhu_1v8_cam3)
548                 regulator_disable(cardhu_1v8_cam3);
549
550         return 0;
551 }
552
553 struct ov2710_platform_data cardhu_ov2710_data = {
554         .power_on = cardhu_ov2710_power_on,
555         .power_off = cardhu_ov2710_power_off,
556 };
557
558 static int cardhu_ov5640_power_on(struct device *dev)
559 {
560         /* CSI-B and front sensor are muxed on cardhu */
561         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
562
563         /* Boards E1198 and E1291 are of Cardhu personality
564          * and donot have TCA6416 exp for camera */
565         if ((board_info.board_id == BOARD_E1198) ||
566                 (board_info.board_id == BOARD_E1291)) {
567
568                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
569                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
570                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
571                 mdelay(10);
572
573                 if (cardhu_vdd_cam3 == NULL) {
574                         cardhu_vdd_cam3 = regulator_get(dev, "vdd_cam3");
575                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
576                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
577                                         __func__, PTR_ERR(cardhu_vdd_cam3));
578                                 goto reg_alloc_fail;
579                         }
580                 }
581                 regulator_enable(cardhu_vdd_cam3);
582         }
583
584         /* Enable VDD_1V8_Cam3 */
585         if (cardhu_1v8_cam3 == NULL) {
586                 cardhu_1v8_cam3 = regulator_get(dev, "vdd_1v8_cam3");
587                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
588                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
589                                 __func__, PTR_ERR(cardhu_1v8_cam3));
590                         goto reg_alloc_fail;
591                 }
592         }
593         regulator_enable(cardhu_1v8_cam3);
594         mdelay(5);
595
596         return 0;
597
598 reg_alloc_fail:
599         if (cardhu_1v8_cam3) {
600                 regulator_put(cardhu_1v8_cam3);
601                 cardhu_1v8_cam3 = NULL;
602         }
603         if (cardhu_vdd_cam3) {
604                 regulator_put(cardhu_vdd_cam3);
605                 cardhu_vdd_cam3 = NULL;
606         }
607
608         return -ENODEV;
609 }
610
611 static int cardhu_ov5640_power_off(struct device *dev)
612 {
613         /* CSI-B and front sensor are muxed on cardhu */
614         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
615
616         /* Boards E1198 and E1291 are of Cardhu personality
617          * and donot have TCA6416 exp for camera */
618         if ((board_info.board_id == BOARD_E1198) ||
619                 (board_info.board_id == BOARD_E1291)) {
620                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
621                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
622                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
623         }
624
625         if (cardhu_1v8_cam3)
626                 regulator_disable(cardhu_1v8_cam3);
627         if (cardhu_vdd_cam3)
628                 regulator_disable(cardhu_vdd_cam3);
629
630         return 0;
631 }
632
633 struct ov5640_platform_data cardhu_ov5640_data = {
634         .power_on = cardhu_ov5640_power_on,
635         .power_off = cardhu_ov5640_power_off,
636 };
637
638 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
639         {
640                 I2C_BOARD_INFO("pca9546", 0x70),
641                 .platform_data = &cardhu_pca954x_data,
642         },
643 };
644
645
646 static struct nvc_gpio_pdata sh532u_gpio_pdata[] = {
647         { SH532U_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
648 };
649
650 static struct sh532u_platform_data sh532u_left_pdata = {
651         .cfg            = NVC_CFG_NODEV,
652         .num            = 1,
653         .sync           = 2,
654         .dev_name       = "focuser",
655         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
656         .gpio           = sh532u_gpio_pdata,
657 };
658
659 static struct sh532u_platform_data sh532u_right_pdata = {
660         .cfg            = NVC_CFG_NODEV,
661         .num            = 2,
662         .sync           = 1,
663         .dev_name       = "focuser",
664         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
665         .gpio           = sh532u_gpio_pdata,
666 };
667
668 static struct nvc_gpio_pdata pm269_sh532u_left_gpio_pdata[] = {
669         { SH532U_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
670 };
671
672 static struct sh532u_platform_data pm269_sh532u_left_pdata = {
673         .cfg            = 0,
674         .num            = 1,
675         .sync           = 2,
676         .dev_name       = "focuser",
677         .gpio_count     = ARRAY_SIZE(pm269_sh532u_left_gpio_pdata),
678         .gpio           = pm269_sh532u_left_gpio_pdata,
679 };
680
681 static struct nvc_gpio_pdata pm269_sh532u_right_gpio_pdata[] = {
682         { SH532U_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
683 };
684
685 static struct sh532u_platform_data pm269_sh532u_right_pdata = {
686         .cfg            = 0,
687         .num            = 2,
688         .sync           = 1,
689         .dev_name       = "focuser",
690         .gpio_count     = ARRAY_SIZE(pm269_sh532u_right_gpio_pdata),
691         .gpio           = pm269_sh532u_right_gpio_pdata,
692 };
693
694 static struct nvc_gpio_pdata ad5816_gpio_pdata[] = {
695         { AD5816_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
696 };
697
698 static struct ad5816_platform_data ad5816_left_pdata = {
699         .cfg            = 0,
700         .num            = 1,
701         .sync           = 2,
702         .dev_name       = "focuser",
703         .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
704         .gpio           = ad5816_gpio_pdata,
705 };
706
707 static struct ad5816_platform_data ad5816_right_pdata = {
708         .cfg            = 0,
709         .num            = 2,
710         .sync           = 1,
711         .dev_name       = "focuser",
712         .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
713         .gpio           = ad5816_gpio_pdata,
714 };
715
716 static struct nvc_gpio_pdata pm269_ad5816_left_gpio_pdata[] = {
717         { AD5816_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
718 };
719
720 static struct ad5816_platform_data pm269_ad5816_left_pdata = {
721         .cfg            = NVC_CFG_NODEV,
722         .num            = 1,
723         .sync           = 2,
724         .dev_name       = "focuser",
725         .gpio_count     = ARRAY_SIZE(pm269_ad5816_left_gpio_pdata),
726         .gpio           = pm269_ad5816_left_gpio_pdata,
727 };
728
729 static struct nvc_gpio_pdata pm269_ad5816_right_gpio_pdata[] = {
730         { AD5816_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
731 };
732
733 static struct ad5816_platform_data pm269_ad5816_right_pdata = {
734         .cfg            = NVC_CFG_NODEV,
735         .num            = 2,
736         .sync           = 1,
737         .dev_name       = "focuser",
738         .gpio_count     = ARRAY_SIZE(pm269_ad5816_right_gpio_pdata),
739         .gpio           = pm269_ad5816_right_gpio_pdata,
740 };
741
742
743 static struct nvc_torch_pin_state cardhu_tps61050_pinstate = {
744         .mask           = 0x0008, /*VGP3*/
745         .values         = 0x0008,
746 };
747
748 static struct tps61050_platform_data cardhu_tps61050_pdata = {
749         .dev_name       = "torch",
750         .pinstate       = &cardhu_tps61050_pinstate,
751 };
752
753 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
754         {
755                 I2C_BOARD_INFO("tps61050", 0x33),
756                 .platform_data = &cardhu_tps61050_pdata,
757         },
758 };
759
760 static struct i2c_board_info cardhu_i2c6_board_info[] = {
761         {
762                 I2C_BOARD_INFO("ov5650L", 0x36),
763                 .platform_data = &cardhu_left_ov5650_data,
764         },
765         {
766                 I2C_BOARD_INFO("sh532u", 0x72),
767                 .platform_data = &sh532u_left_pdata,
768         },
769         {
770                 I2C_BOARD_INFO("ad5816", 0x0E),
771                 .platform_data = &ad5816_left_pdata,
772         },
773 };
774
775 static struct i2c_board_info cardhu_i2c7_board_info[] = {
776         {
777                 I2C_BOARD_INFO("ov5650R", 0x36),
778                 .platform_data = &cardhu_right_ov5650_data,
779         },
780         {
781                 I2C_BOARD_INFO("sh532u", 0x72),
782                 .platform_data = &sh532u_right_pdata,
783         },
784         {
785                 I2C_BOARD_INFO("ad5816", 0x0E),
786                 .platform_data = &ad5816_right_pdata,
787         },
788 };
789
790 static struct i2c_board_info pm269_i2c6_board_info[] = {
791         {
792                 I2C_BOARD_INFO("ov5650L", 0x36),
793                 .platform_data = &cardhu_left_ov5650_data,
794         },
795         {
796                 I2C_BOARD_INFO("sh532u", 0x72),
797                 .platform_data = &pm269_sh532u_left_pdata,
798         },
799         {
800                 I2C_BOARD_INFO("ad5816", 0x0E),
801                 .platform_data = &pm269_ad5816_left_pdata,
802         },
803 };
804
805 static struct i2c_board_info pm269_i2c7_board_info[] = {
806         {
807                 I2C_BOARD_INFO("ov5650R", 0x36),
808                 .platform_data = &cardhu_right_ov5650_data,
809         },
810         {
811                 I2C_BOARD_INFO("sh532u", 0x72),
812                 .platform_data = &pm269_sh532u_right_pdata,
813         },
814         {
815                 I2C_BOARD_INFO("ad5816", 0x0E),
816                 .platform_data = &pm269_ad5816_right_pdata,
817         },
818 };
819
820 static struct i2c_board_info cardhu_i2c8_board_info[] = {
821         {
822                 I2C_BOARD_INFO("ov2710", 0x36),
823                 .platform_data = &cardhu_ov2710_data,
824         },
825         {
826                 I2C_BOARD_INFO("ov5640", 0x3C),
827                 .platform_data = &cardhu_ov5640_data,
828         },
829 };
830
831 static int nct_get_temp(void *_data, long *temp)
832 {
833         struct nct1008_data *data = _data;
834         return nct1008_thermal_get_temp(data, temp);
835 }
836
837 static int nct_set_limits(void *_data,
838                         long lo_limit_milli,
839                         long hi_limit_milli)
840 {
841         struct nct1008_data *data = _data;
842         return nct1008_thermal_set_limits(data,
843                                         lo_limit_milli,
844                                         hi_limit_milli);
845 }
846
847 static int nct_set_alert(void *_data,
848                                 void (*alert_func)(void *),
849                                 void *alert_data)
850 {
851         struct nct1008_data *data = _data;
852         return nct1008_thermal_set_alert(data, alert_func, alert_data);
853 }
854
855 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
856 static int nct_get_itemp(void *dev_data, long *temp)
857 {
858         struct nct1008_data *data = dev_data;
859         return nct1008_thermal_get_temps(data, NULL, temp);
860 }
861 #endif
862
863 static void nct1008_probe_callback(struct nct1008_data *data)
864 {
865         struct tegra_thermal_device *ext_nct;
866
867         ext_nct = kzalloc(sizeof(struct tegra_thermal_device),
868                                         GFP_KERNEL);
869         if (!ext_nct) {
870                 pr_err("unable to allocate thermal device\n");
871                 return;
872         }
873
874         ext_nct->name = "nct_ext";
875         ext_nct->id = THERMAL_DEVICE_ID_NCT_EXT;
876         ext_nct->data = data;
877         ext_nct->get_temp = nct_get_temp;
878         ext_nct->set_limits = nct_set_limits;
879         ext_nct->set_alert = nct_set_alert;
880
881         tegra_thermal_device_register(ext_nct);
882
883 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
884         {
885                 struct tegra_thermal_device *int_nct;
886                 int_nct = kzalloc(sizeof(struct tegra_thermal_device),
887                                                 GFP_KERNEL);
888                 if (!int_nct) {
889                         kfree(int_nct);
890                         pr_err("unable to allocate thermal device\n");
891                         return;
892                 }
893
894                 int_nct->name = "nct_int";
895                 int_nct->id = THERMAL_DEVICE_ID_NCT_INT;
896                 int_nct->data = data;
897                 int_nct->get_temp = nct_get_itemp;
898
899                 tegra_thermal_device_register(int_nct);
900         }
901 #endif
902 }
903
904 static struct nct1008_platform_data cardhu_nct1008_pdata = {
905         .supported_hwrev = true,
906         .ext_range = true,
907         .conv_rate = 0x08,
908         .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
909         .probe_callback = nct1008_probe_callback,
910 };
911
912 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
913         {
914                 I2C_BOARD_INFO("bq27510", 0x55),
915         },
916 };
917
918 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
919         {
920                 I2C_BOARD_INFO("nct1008", 0x4C),
921                 .platform_data = &cardhu_nct1008_pdata,
922                 .irq = -1,
923         }
924 };
925
926 static int cardhu_nct1008_init(void)
927 {
928         int nct1008_port = -1;
929         int ret = 0;
930
931         if ((board_info.board_id == BOARD_E1198) ||
932                 (board_info.board_id == BOARD_E1291) ||
933                 (board_info.board_id == BOARD_E1257) ||
934                 (board_info.board_id == BOARD_PM269) ||
935                 (board_info.board_id == BOARD_PM305) ||
936                 (board_info.board_id == BOARD_PM311)) {
937                 nct1008_port = TEGRA_GPIO_PCC2;
938         } else if ((board_info.board_id == BOARD_E1186) ||
939                 (board_info.board_id == BOARD_E1187) ||
940                 (board_info.board_id == BOARD_E1256)) {
941                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
942                 /* nct1008_port = TEGRA_GPIO_PH7; */
943         }
944
945         if (nct1008_port >= 0) {
946                 /* FIXME: enable irq when throttling is supported */
947                 cardhu_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
948
949                 ret = gpio_request(nct1008_port, "temp_alert");
950                 if (ret < 0)
951                         return ret;
952
953                 ret = gpio_direction_input(nct1008_port);
954                 if (ret < 0)
955                         gpio_free(nct1008_port);
956         }
957
958         return ret;
959 }
960
961 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
962 static int tegra_skin_match(struct thermal_zone_device *thz, void *data)
963 {
964         return strcmp((char *)data, thz->type) == 0;
965 }
966
967 static int tegra_skin_get_temp(void *data, long *temp)
968 {
969         struct thermal_zone_device *thz;
970
971         thz = thermal_zone_device_find(data, tegra_skin_match);
972
973         if (!thz || thz->ops->get_temp(thz, temp))
974                 *temp = 25000;
975
976         return 0;
977 }
978
979 static struct therm_est_data skin_data = {
980         .toffset = 9793,
981         .polling_period = 1100,
982         .ndevs = 2,
983         .devs = {
984                         {
985                                 .dev_data = "nct_ext",
986                                 .get_temp = tegra_skin_get_temp,
987                                 .coeffs = {
988                                         2, 1, 1, 1,
989                                         1, 1, 1, 1,
990                                         1, 1, 1, 0,
991                                         1, 1, 0, 0,
992                                         0, 0, -1, -7
993                                 },
994                         },
995                         {
996                                 .dev_data = "nct_int",
997                                 .get_temp = tegra_skin_get_temp,
998                                 .coeffs = {
999                                         -11, -7, -5, -3,
1000                                         -3, -2, -1, 0,
1001                                         0, 0, 1, 1,
1002                                         1, 2, 2, 3,
1003                                         4, 6, 11, 18
1004                                 },
1005                         },
1006         },
1007         .trip_temp = 43000,
1008         .tc1 = 1,
1009         .tc2 = 15,
1010         .passive_delay = 15000,
1011 };
1012
1013 static struct balanced_throttle skin_throttle = {
1014         .throt_tab_size = 6,
1015         .throt_tab = {
1016                 { 640000, 1200 },
1017                 { 640000, 1200 },
1018                 { 760000, 1200 },
1019                 { 760000, 1200 },
1020                 {1000000, 1200 },
1021                 {1000000, 1200 },
1022         },
1023 };
1024
1025 static int __init cardhu_skin_init(void)
1026 {
1027         struct thermal_cooling_device *skin_cdev;
1028
1029         skin_cdev = balanced_throttle_register(&skin_throttle);
1030
1031         skin_data.cdev = skin_cdev;
1032         tegra_skin_therm_est_device.dev.platform_data = &skin_data;
1033         platform_device_register(&tegra_skin_therm_est_device);
1034
1035         return 0;
1036 }
1037 late_initcall(cardhu_skin_init);
1038 #endif
1039
1040 #if defined(CONFIG_GPIO_PCA953X)
1041 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
1042         .gpio_base      = PMU_TCA6416_GPIO_BASE,
1043 };
1044
1045 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
1046         {
1047                 I2C_BOARD_INFO("tca6416", 0x20),
1048                 .platform_data = &cardhu_pmu_tca6416_data,
1049         },
1050 };
1051
1052 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
1053         .gpio_base      = CAM_TCA6416_GPIO_BASE,
1054 };
1055
1056 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
1057         {
1058                 I2C_BOARD_INFO("tca6416", 0x20),
1059                 .platform_data = &cardhu_cam_tca6416_data,
1060         },
1061 };
1062
1063 static int __init pmu_tca6416_init(void)
1064 {
1065         if ((board_info.board_id == BOARD_E1198) ||
1066                 (board_info.board_id == BOARD_E1291))
1067                         return 0;
1068
1069         pr_info("Registering pmu pca6416\n");
1070         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
1071                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
1072         return 0;
1073 }
1074
1075 static int __init cam_tca6416_init(void)
1076 {
1077         /* Boards E1198 and E1291 are of Cardhu personality
1078          * and donot have TCA6416 exp for camera */
1079         if ((board_info.board_id == BOARD_E1198) ||
1080                 (board_info.board_id == BOARD_E1291))
1081                 return 0;
1082
1083         pr_info("Registering cam pca6416\n");
1084         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
1085                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
1086         return 0;
1087 }
1088 #else
1089 static int __init pmu_tca6416_init(void)
1090 {
1091         return 0;
1092 }
1093
1094 static int __init cam_tca6416_init(void)
1095 {
1096         return 0;
1097 }
1098 #endif
1099
1100 /* MPU board file definition    */
1101 static struct mpu_platform_data mpu_gyro_data = {
1102         .int_config     = 0x10,
1103         .level_shifter  = 0,
1104         .orientation    = MPU_GYRO_ORIENTATION, /* Located in board_[platformname].h    */
1105         .sec_slave_type = SECONDARY_SLAVE_TYPE_ACCEL,
1106         .sec_slave_id   = ACCEL_ID_KXTF9,
1107         .secondary_i2c_addr     = MPU_ACCEL_ADDR,
1108         .secondary_read_reg     = 0x06,
1109         .secondary_orientation  = MPU_ACCEL_ORIENTATION,
1110         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
1111                            0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
1112 };
1113
1114 static struct mpu_platform_data mpu_compass_data = {
1115         .orientation    = MPU_COMPASS_ORIENTATION,
1116         .sec_slave_type = SECONDARY_SLAVE_TYPE_NONE,
1117 };
1118
1119 static struct i2c_board_info __initdata inv_mpu_i2c2_board_info[] = {
1120         {
1121                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
1122                 .platform_data = &mpu_gyro_data,
1123         },
1124         {
1125                 I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR),
1126         },
1127         {
1128                 I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
1129                 .platform_data = &mpu_compass_data,
1130         },
1131 };
1132
1133 static void mpuirq_init(void)
1134 {
1135         int ret = 0;
1136         int i = 0;
1137
1138         pr_info("*** MPU START *** mpuirq_init...\n");
1139
1140 #if     MPU_ACCEL_IRQ_GPIO
1141         /* ACCEL-IRQ assignment */
1142         ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME);
1143         if (ret < 0) {
1144                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
1145                 return;
1146         }
1147
1148         ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO);
1149         if (ret < 0) {
1150                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
1151                 gpio_free(MPU_ACCEL_IRQ_GPIO);
1152                 return;
1153         }
1154 #endif
1155
1156         /* MPU-IRQ assignment */
1157         ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
1158         if (ret < 0) {
1159                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
1160                 return;
1161         }
1162
1163         ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
1164         if (ret < 0) {
1165                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
1166                 gpio_free(MPU_GYRO_IRQ_GPIO);
1167                 return;
1168         }
1169         pr_info("*** MPU END *** mpuirq_init...\n");
1170
1171         inv_mpu_i2c2_board_info[i++].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
1172 #if MPU_ACCEL_IRQ_GPIO
1173         inv_mpu_i2c2_board_info[i].irq = gpio_to_irq(MPU_ACCEL_IRQ_GPIO);
1174 #endif
1175         i++;
1176 #if MPU_COMPASS_IRQ_GPIO
1177         inv_mpu_i2c2_board_info[i++].irq = gpio_to_irq(MPU_COMPAS_IRQ_GPIO);
1178 #endif
1179         i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c2_board_info,
1180                 ARRAY_SIZE(inv_mpu_i2c2_board_info));
1181 }
1182
1183 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
1184         {
1185                 I2C_BOARD_INFO("isl29028", 0x44),
1186         }
1187 };
1188
1189 static struct i2c_board_info cardhu_i2c2_ltr_board_info[] = {
1190         {
1191                 I2C_BOARD_INFO("LTR_558ALS", 0x23),
1192         }
1193 };
1194
1195 int __init cardhu_sensors_init(void)
1196 {
1197         int err;
1198
1199         tegra_get_board_info(&board_info);
1200
1201         cardhu_camera_init();
1202         cam_tca6416_init();
1203
1204 #ifdef CONFIG_VIDEO_IMX091
1205         i2c_register_board_info(2, cardhu_i2c_board_info_e1244,
1206                 ARRAY_SIZE(cardhu_i2c_board_info_e1244));
1207 #endif
1208
1209         i2c_register_board_info(2, cardhu_i2c3_board_info,
1210                 ARRAY_SIZE(cardhu_i2c3_board_info));
1211
1212         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
1213                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
1214
1215 #ifdef CONFIG_VIDEO_OV14810
1216         /* This is disabled by default; To enable this change Kconfig;
1217          * there should be some way to detect dynamically which board
1218          * is connected (E1211/E1214), till that time sensor selection
1219          * logic is static;
1220          * e1214 corresponds to ov14810 sensor */
1221         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
1222                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
1223 #else
1224         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
1225          * Front camera is on BUS2 */
1226         if (board_info.board_id != BOARD_PM269) {
1227                 i2c_register_board_info(PCA954x_I2C_BUS0,
1228                                         cardhu_i2c6_board_info,
1229                                         ARRAY_SIZE(cardhu_i2c6_board_info));
1230
1231                 i2c_register_board_info(PCA954x_I2C_BUS1,
1232                                         cardhu_i2c7_board_info,
1233                                         ARRAY_SIZE(cardhu_i2c7_board_info));
1234         } else {
1235                 i2c_register_board_info(PCA954x_I2C_BUS0,
1236                                         pm269_i2c6_board_info,
1237                                         ARRAY_SIZE(pm269_i2c6_board_info));
1238
1239                 i2c_register_board_info(PCA954x_I2C_BUS1,
1240                                         pm269_i2c7_board_info,
1241                                         ARRAY_SIZE(pm269_i2c7_board_info));
1242         }
1243         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
1244                 ARRAY_SIZE(cardhu_i2c8_board_info));
1245
1246 #endif
1247         pmu_tca6416_init();
1248
1249         if (board_info.board_id == BOARD_E1291)
1250                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
1251                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
1252
1253         if (board_info.sku == BOARD_SKU_B11)
1254                 i2c_register_board_info(2, cardhu_i2c2_ltr_board_info,
1255                         ARRAY_SIZE(cardhu_i2c2_ltr_board_info));
1256         else
1257                 i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
1258                         ARRAY_SIZE(cardhu_i2c2_isl_board_info));
1259
1260         err = cardhu_nct1008_init();
1261         if (err)
1262                 return err;
1263
1264         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
1265                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
1266
1267         mpuirq_init();
1268         return 0;
1269 }
1270
1271 #if defined(CONFIG_GPIO_PCA953X)
1272 struct ov5650_gpios {
1273         const char *name;
1274         int gpio;
1275         int enabled;
1276 };
1277
1278 #define OV5650_GPIO(_name, _gpio, _enabled)             \
1279         {                                               \
1280                 .name = _name,                          \
1281                 .gpio = _gpio,                          \
1282                 .enabled = _enabled,                    \
1283         }
1284
1285 static struct ov5650_gpios ov5650_gpio_keys[] = {
1286         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
1287         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
1288         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
1289         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
1290         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
1291         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
1292         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
1293         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
1294         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
1295         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
1296         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
1297         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
1298         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
1299         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
1300         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
1301 };
1302
1303 int __init cardhu_ov5650_late_init(void)
1304 {
1305         int ret;
1306         int i;
1307
1308         if (!machine_is_cardhu())
1309                 return 0;
1310
1311         if ((board_info.board_id == BOARD_E1198) ||
1312                 (board_info.board_id == BOARD_E1291))
1313                 return 0;
1314
1315         printk("%s: \n", __func__);
1316         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
1317                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
1318                         ov5650_gpio_keys[i].name);
1319                 if (ret < 0) {
1320                         printk("%s: gpio_request failed for gpio #%d\n",
1321                                 __func__, i);
1322                         goto fail;
1323                 }
1324                 printk("%s: enable - %d\n", __func__, i);
1325                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
1326                         ov5650_gpio_keys[i].enabled);
1327                 gpio_export(ov5650_gpio_keys[i].gpio, false);
1328         }
1329
1330         return 0;
1331
1332 fail:
1333         while (i--)
1334                 gpio_free(ov5650_gpio_keys[i].gpio);
1335         return ret;
1336 }
1337
1338 late_initcall(cardhu_ov5650_late_init);
1339 #endif