2c3f0b2c3e6d68998aab94452b51fb62e06902d5
[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/ov14810.h>
44 #include <media/ov2710.h>
45 #include <media/tps61050.h>
46 #include <generated/mach-types.h>
47 #include "gpio-names.h"
48 #include "board.h"
49 #include <linux/mpu.h>
50 #include <media/sh532u.h>
51 #include <linux/bq27x00.h>
52 #include <mach/gpio.h>
53 #include <mach/edp.h>
54
55 #include "gpio-names.h"
56 #include "board-cardhu.h"
57 #include "cpu-tegra.h"
58
59 static struct regulator *cardhu_1v8_cam1 = NULL;
60 static struct regulator *cardhu_1v8_cam2 = NULL;
61 static struct regulator *cardhu_1v8_cam3 = NULL;
62 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
63 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
64 static struct regulator *cardhu_vdd_cam3 = NULL;
65
66 static struct board_info board_info;
67
68 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
69         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
70         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
71         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
72         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
73 };
74
75 static struct pca954x_platform_data cardhu_pca954x_data = {
76         .modes    = cardhu_pca954x_modes,
77         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
78 };
79
80 static int cardhu_camera_init(void)
81 {
82         int ret;
83
84         /* Boards E1198 and E1291 are of Cardhu personality
85          * and donot have TCA6416 exp for camera */
86         if ((board_info.board_id == BOARD_E1198) ||
87                 (board_info.board_id == BOARD_E1291)) {
88                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
89                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
90                 if (ret < 0)
91                         pr_err("%s: gpio_request failed for gpio %s\n",
92                                 __func__, "CAM1_POWER_DWN_GPIO");
93                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
94                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
95                 if (ret < 0)
96                         pr_err("%s: gpio_request failed for gpio %s\n",
97                                 __func__, "CAM3_POWER_DWN_GPIO");
98
99                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
100                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
101                 if (ret < 0)
102                         pr_err("%s: gpio_request failed for gpio %s\n",
103                                 __func__, "CAM2_POWER_DWN_GPIO");
104
105                 tegra_gpio_enable(OV5650_RESETN_GPIO);
106                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
107                 if (ret < 0)
108                         pr_err("%s: gpio_request failed for gpio %s\n",
109                                 __func__, "OV5650_RESETN_GPIO");
110
111                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
112                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
113                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
114                 mdelay(10);
115
116                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
117                 mdelay(5);
118                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
119                 mdelay(5);
120                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
121                 mdelay(5);
122         }
123
124         /* To select the CSIB MUX either for cam2 or cam3 */
125         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
126         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
127         if (ret < 0)
128                 pr_err("%s: gpio_request failed for gpio %s\n",
129                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
130         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
131         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
132
133         return 0;
134 }
135
136 static int cardhu_left_ov5650_power_on(void)
137 {
138         /* Boards E1198 and E1291 are of Cardhu personality
139          * and donot have TCA6416 exp for camera */
140         if ((board_info.board_id == BOARD_E1198) ||
141                 (board_info.board_id == BOARD_E1291)) {
142
143                 if (cardhu_vdd_2v8_cam1 == NULL) {
144                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
145                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
146                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
147                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
148                                 goto reg_alloc_fail;
149                         }
150                 }
151                 regulator_enable(cardhu_vdd_2v8_cam1);
152                 mdelay(5);
153         }
154
155         /* Enable VDD_1V8_Cam1 */
156         if (cardhu_1v8_cam1 == NULL) {
157                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
158                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
159                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
160                                 __func__, PTR_ERR(cardhu_1v8_cam1));
161                         goto reg_alloc_fail;
162                 }
163         }
164         regulator_enable(cardhu_1v8_cam1);
165
166         mdelay(5);
167         if ((board_info.board_id == BOARD_E1198) ||
168                 (board_info.board_id == BOARD_E1291)) {
169                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
170                 mdelay(20);
171                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
172                 mdelay(100);
173                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
174         }
175
176         if (board_info.board_id == BOARD_PM269) {
177                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
178                 mdelay(100);
179                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
180         }
181
182         return 0;
183
184 reg_alloc_fail:
185         if (cardhu_1v8_cam1) {
186                 regulator_put(cardhu_1v8_cam1);
187                 cardhu_1v8_cam1 = NULL;
188         }
189         if (cardhu_vdd_2v8_cam1) {
190                 regulator_put(cardhu_vdd_2v8_cam1);
191                 cardhu_vdd_2v8_cam1 = NULL;
192         }
193
194         return -ENODEV;
195
196 }
197
198 static int cardhu_left_ov5650_power_off(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                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
205                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
206                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
207         }
208         if (cardhu_1v8_cam1)
209                 regulator_disable(cardhu_1v8_cam1);
210         if (cardhu_vdd_2v8_cam1)
211                 regulator_disable(cardhu_vdd_2v8_cam1);
212
213         return 0;
214 }
215
216 struct ov5650_platform_data cardhu_left_ov5650_data = {
217         .power_on = cardhu_left_ov5650_power_on,
218         .power_off = cardhu_left_ov5650_power_off,
219 };
220
221 #ifdef CONFIG_VIDEO_OV14810
222 static int cardhu_ov14810_power_on(void)
223 {
224         if (board_info.board_id == BOARD_E1198) {
225                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
226                 mdelay(20);
227                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
228                 mdelay(100);
229                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
230         }
231
232         return 0;
233 }
234
235 static int cardhu_ov14810_power_off(void)
236 {
237         if (board_info.board_id == BOARD_E1198) {
238                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
239                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
240                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
241         }
242
243         return 0;
244 }
245
246 struct ov14810_platform_data cardhu_ov14810_data = {
247         .power_on = cardhu_ov14810_power_on,
248         .power_off = cardhu_ov14810_power_off,
249 };
250
251 struct ov14810_platform_data cardhu_ov14810uC_data = {
252         .power_on = NULL,
253         .power_off = NULL,
254 };
255
256 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
257         .power_on = NULL,
258         .power_off = NULL,
259 };
260
261 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
262         {
263                 I2C_BOARD_INFO("ov14810", 0x36),
264                 .platform_data = &cardhu_ov14810_data,
265         },
266         {
267                 I2C_BOARD_INFO("ov14810uC", 0x67),
268                 .platform_data = &cardhu_ov14810uC_data,
269         },
270         {
271                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
272                 .platform_data = &cardhu_ov14810SlaveDev_data,
273         }
274 };
275 #endif
276
277 static int cardhu_right_ov5650_power_on(void)
278 {
279         /* Boards E1198 and E1291 are of Cardhu personality
280          * and donot have TCA6416 exp for camera */
281         if ((board_info.board_id == BOARD_E1198) ||
282                 (board_info.board_id == BOARD_E1291)) {
283
284                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
285                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
286                 mdelay(10);
287
288                 if (cardhu_vdd_2v8_cam2 == NULL) {
289                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
290                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
291                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
292                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
293                                 goto reg_alloc_fail;
294                         }
295                 }
296                 regulator_enable(cardhu_vdd_2v8_cam2);
297                 mdelay(5);
298         }
299
300         /* Enable VDD_1V8_Cam2 */
301         if (cardhu_1v8_cam2 == NULL) {
302                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
303                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
304                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
305                                 __func__, PTR_ERR(cardhu_1v8_cam2));
306                         goto reg_alloc_fail;
307                 }
308         }
309         regulator_enable(cardhu_1v8_cam2);
310
311         mdelay(5);
312
313         if (board_info.board_id == BOARD_PM269) {
314                 gpio_direction_output(CAM2_RST_L_GPIO, 0);
315                 mdelay(100);
316                 gpio_direction_output(CAM2_RST_L_GPIO, 1);
317         }
318
319         return 0;
320
321 reg_alloc_fail:
322         if (cardhu_1v8_cam2) {
323                 regulator_put(cardhu_1v8_cam2);
324                 cardhu_1v8_cam2 = NULL;
325         }
326         if (cardhu_vdd_2v8_cam2) {
327                 regulator_put(cardhu_vdd_2v8_cam2);
328                 cardhu_vdd_2v8_cam2 = NULL;
329         }
330
331         return -ENODEV;
332
333 }
334
335 static int cardhu_right_ov5650_power_off(void)
336 {
337         /* Boards E1198 and E1291 are of Cardhu personality
338          * and donot have TCA6416 exp for camera */
339         if ((board_info.board_id == BOARD_E1198) ||
340                 (board_info.board_id == BOARD_E1291)) {
341                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
342                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
343                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
344         }
345
346         if (cardhu_1v8_cam2)
347                 regulator_disable(cardhu_1v8_cam2);
348         if (cardhu_vdd_2v8_cam2)
349                 regulator_disable(cardhu_vdd_2v8_cam2);
350
351         return 0;
352 }
353
354 static void cardhu_ov5650_synchronize_sensors(void)
355 {
356         if (board_info.board_id == BOARD_E1198) {
357                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
358                 mdelay(50);
359                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
360                 mdelay(50);
361         }
362         else if (board_info.board_id == BOARD_E1291) {
363                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
364                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
365                 mdelay(50);
366                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
367                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
368                 mdelay(50);
369         }
370         else
371                 pr_err("%s: UnSupported BoardId\n", __func__);
372 }
373
374 struct ov5650_platform_data cardhu_right_ov5650_data = {
375         .power_on = cardhu_right_ov5650_power_on,
376         .power_off = cardhu_right_ov5650_power_off,
377         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
378 };
379
380 static int cardhu_ov2710_power_on(void)
381 {
382         /* CSI-B and front sensor are muxed on verbier */
383         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
384
385         /* Boards E1198 and E1291 are of Cardhu personality
386          * and donot have TCA6416 exp for camera */
387         if ((board_info.board_id == BOARD_E1198) ||
388                 (board_info.board_id == BOARD_E1291)) {
389
390                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
391                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
392                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
393                 mdelay(10);
394
395                 if (cardhu_vdd_cam3 == NULL) {
396                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
397                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
398                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
399                                         __func__, PTR_ERR(cardhu_vdd_cam3));
400                                 goto reg_alloc_fail;
401                         }
402                 }
403                 regulator_enable(cardhu_vdd_cam3);
404         }
405
406         /* Enable VDD_1V8_Cam3 */
407         if (cardhu_1v8_cam3 == NULL) {
408                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
409                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
410                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
411                                 __func__, PTR_ERR(cardhu_1v8_cam3));
412                         goto reg_alloc_fail;
413                 }
414         }
415         regulator_enable(cardhu_1v8_cam3);
416         mdelay(5);
417
418         return 0;
419
420 reg_alloc_fail:
421         if (cardhu_1v8_cam3) {
422                 regulator_put(cardhu_1v8_cam3);
423                 cardhu_1v8_cam3 = NULL;
424         }
425         if (cardhu_vdd_cam3) {
426                 regulator_put(cardhu_vdd_cam3);
427                 cardhu_vdd_cam3 = NULL;
428         }
429
430         return -ENODEV;
431 }
432
433 static int cardhu_ov2710_power_off(void)
434 {
435         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
436
437         /* Boards E1198 and E1291 are of Cardhu personality
438          * and donot have TCA6416 exp for camera */
439         if ((board_info.board_id == BOARD_E1198) ||
440                 (board_info.board_id == BOARD_E1291)) {
441                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
442                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
443                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
444         }
445
446         if (cardhu_1v8_cam3)
447                 regulator_disable(cardhu_1v8_cam3);
448         if (cardhu_vdd_cam3)
449                 regulator_disable(cardhu_vdd_cam3);
450
451         return 0;
452 }
453
454 struct ov2710_platform_data cardhu_ov2710_data = {
455         .power_on = cardhu_ov2710_power_on,
456         .power_off = cardhu_ov2710_power_off,
457 };
458
459 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
460         {
461                 I2C_BOARD_INFO("pca9546", 0x70),
462                 .platform_data = &cardhu_pca954x_data,
463         },
464 };
465
466 static int sh532u_power_control(void *cdata, int is_enable, int which) {
467         static struct regulator *vdd_2v8_cam1_af = NULL;
468         static struct regulator *vdd_2v8_cam2_af = NULL;
469
470         struct regulator *vdd_2v8_camx_af = (1 == which) ? vdd_2v8_cam1_af : vdd_2v8_cam2_af;
471         char *vdd_2v8_camx_tag = (1 == which) ? "vdd_2v8_cam1_af" : "vdd_2v8_cam2_af";
472
473         if (vdd_2v8_camx_af == NULL) {
474                 vdd_2v8_camx_af = regulator_get(NULL, vdd_2v8_camx_tag);
475                 if (WARN_ON(IS_ERR_OR_NULL(vdd_2v8_camx_af))) {
476                         pr_err("%s: couldn't get regulator %s:"
477                                 " %ld\n", __func__, vdd_2v8_camx_tag, PTR_ERR(vdd_2v8_camx_af));
478                         vdd_2v8_camx_af = NULL;
479                         return -ENODEV;
480                 }
481         }
482         if (is_enable) {
483                 regulator_enable(vdd_2v8_camx_af);
484                 mdelay(20);
485         } else
486                 regulator_disable(vdd_2v8_camx_af);
487
488         return 0;
489 }
490
491 static int sh532u_left_init(void *cdata) {
492         return sh532u_power_control(cdata, true, 1);
493 }
494 static int sh532u_left_deinit(void *cdata) {
495         return sh532u_power_control(cdata, false, 1);
496 }
497
498 static int sh532u_right_init(void *cdata) {
499         return sh532u_power_control(cdata, true, 2);
500 }
501 static int sh532u_right_deinit(void *cdata) {
502         return sh532u_power_control(cdata, false, 2);
503 }
504
505 struct sh532u_platform_data sh532u_left_pdata = {
506         .board_init = sh532u_left_init,
507         .board_deinit = sh532u_left_deinit,
508 };
509
510 struct sh532u_platform_data sh532u_right_pdata = {
511         .board_init = sh532u_right_init,
512         .board_deinit = sh532u_right_deinit,
513 };
514
515 static bool cardhu_tps61050_pm_flag = 0;
516
517 static struct tps61050_pin_state cardhu_tps61050_pinstate = {
518         .mask           = 0x0008, /*VGP3*/
519         .values         = 0x0008,
520 };
521
522 static int cardhu_tps61050_pm(int pwr)
523 {
524         switch (pwr) {
525         case TPS61050_PWR_OFF:
526                 if (cardhu_tps61050_pm_flag && cardhu_1v8_cam1) {
527                         regulator_disable(cardhu_1v8_cam1);
528                         cardhu_tps61050_pm_flag = 0;
529                 }
530                 return 0;
531
532         case TPS61050_PWR_STDBY:
533         case TPS61050_PWR_COMM:
534         case TPS61050_PWR_ON:
535                 if (!cardhu_tps61050_pm_flag) {
536                         if (cardhu_1v8_cam1 == NULL) {
537                                 cardhu_1v8_cam1 =
538                                         regulator_get(NULL, "vdd_1v8_cam1");
539                                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
540                                         pr_err("%s: err: %ld\n",
541                                                 __func__,
542                                                 PTR_ERR(cardhu_1v8_cam1));
543                                         regulator_put(cardhu_1v8_cam1);
544                                         cardhu_1v8_cam1 = NULL;
545                                 }
546                         }
547                         regulator_enable(cardhu_1v8_cam1);
548                         cardhu_tps61050_pm_flag = 1;
549                         mdelay(5);
550                 }
551                 return 0;
552
553         default:
554                 return -1;
555         }
556 }
557
558 static struct tps61050_platform_data cardhu_tps61050_data = {
559         .cfg            = 0,
560         .num            = 1,
561         .max_amp_torch  = CAMERA_FLASH_MAX_TORCH_AMP,
562         .max_amp_flash  = CAMERA_FLASH_MAX_FLASH_AMP,
563         .pinstate       = &cardhu_tps61050_pinstate,
564         .init           = NULL,
565         .exit           = NULL,
566         .pm             = cardhu_tps61050_pm,
567         .gpio_envm      = NULL,
568         .gpio_sync      = NULL,
569 };
570
571 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
572         {
573                 I2C_BOARD_INFO("tps61050", 0x33),
574                 .platform_data = &cardhu_tps61050_data,
575         },
576 };
577
578 static struct i2c_board_info cardhu_i2c6_board_info[] = {
579         {
580                 I2C_BOARD_INFO("ov5650L", 0x36),
581                 .platform_data = &cardhu_left_ov5650_data,
582         },
583         {
584                 I2C_BOARD_INFO("sh532uL", 0x72),
585                 .platform_data = &sh532u_left_pdata,
586         },
587 };
588
589 static struct i2c_board_info cardhu_i2c7_board_info[] = {
590         {
591                 I2C_BOARD_INFO("ov5650R", 0x36),
592                 .platform_data = &cardhu_right_ov5650_data,
593         },
594         {
595                 I2C_BOARD_INFO("sh532uR", 0x72),
596                 .platform_data = &sh532u_right_pdata,
597         },
598 };
599
600 static struct i2c_board_info cardhu_i2c8_board_info[] = {
601         {
602                 I2C_BOARD_INFO("ov2710", 0x36),
603                 .platform_data = &cardhu_ov2710_data,
604         },
605 };
606
607 static struct nct1008_platform_data cardhu_nct1008_pdata = {
608         .supported_hwrev = true,
609         .ext_range = true,
610         .conv_rate = 0x08,
611         .hysteresis = 5,
612         .shutdown_ext_limit = 90,
613         .shutdown_local_limit = 90,
614         .throttling_ext_limit = 75,
615         .alarm_fn = tegra_throttling_enable,
616 };
617
618 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
619         {
620                 I2C_BOARD_INFO("bq27510", 0x55),
621         },
622 };
623
624 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
625         {
626                 I2C_BOARD_INFO("nct1008", 0x4C),
627                 .platform_data = &cardhu_nct1008_pdata,
628                 .irq = -1,
629         }
630 };
631
632
633 static int cardhu_nct1008_init(void)
634 {
635         int nct1008_port = -1;
636         int ret;
637         struct nct1008_platform_data *pdata;
638 #ifdef CONFIG_TEGRA_EDP_LIMITS
639         const struct tegra_edp_limits *z;
640         int zones_sz;
641         int i;
642         bool throttle_ok = false;
643 #endif
644
645         if ((board_info.board_id == BOARD_E1198) ||
646                 (board_info.board_id == BOARD_E1291) ||
647                 (board_info.board_id == BOARD_E1257) ||
648                 (board_info.board_id == BOARD_PM269) ||
649                 (board_info.board_id == BOARD_PM305) ||
650                 (board_info.board_id == BOARD_PM311)) {
651                 nct1008_port = TEGRA_GPIO_PCC2;
652         } else if ((board_info.board_id == BOARD_E1186) ||
653                 (board_info.board_id == BOARD_E1187) ||
654                 (board_info.board_id == BOARD_E1256)) {
655                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
656                 /* nct1008_port = TEGRA_GPIO_PH7; */
657         }
658
659         if (nct1008_port >= 0) {
660                 /* FIXME: enable irq when throttling is supported */
661                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
662
663                 ret = gpio_request(nct1008_port, "temp_alert");
664                 if (ret < 0)
665                         return ret;
666
667                 ret = gpio_direction_input(nct1008_port);
668                 if (ret < 0)
669                         gpio_free(nct1008_port);
670                 else
671                         tegra_gpio_enable(nct1008_port);
672         }
673
674         /* Temperature guardband: bug 844025 */
675         if (board_info.board_id == BOARD_PM269) {
676                 /* T30S DSC */
677                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
678                 pdata->offset = 41; /* 4 * 10.25C */
679         } else {
680                 /* T30 MID */
681                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
682                 pdata->offset = 43; /* 4 * 10.75C */
683         }
684
685 #ifdef CONFIG_TEGRA_EDP_LIMITS
686         tegra_get_cpu_edp_limits(&z, &zones_sz);
687         zones_sz = min(zones_sz, MAX_ZONES);
688         for (i = 0; i < zones_sz; i++) {
689                 cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
690                 if (cardhu_nct1008_pdata.thermal_zones[i] ==
691                     cardhu_nct1008_pdata.throttling_ext_limit) {
692                         throttle_ok = true;
693                 }
694         }
695
696         if (throttle_ok != true)
697                 pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
698                         " as it is NOT one of the EDP points\n",
699                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
700         else
701                 pr_info("%s: Throttling limit %dC OK\n",
702                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
703
704         cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
705 #endif
706         return ret;
707 }
708
709 #if defined(CONFIG_GPIO_PCA953X)
710 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
711         .gpio_base      = PMU_TCA6416_GPIO_BASE,
712 };
713
714 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
715         {
716                 I2C_BOARD_INFO("tca6416", 0x20),
717                 .platform_data = &cardhu_pmu_tca6416_data,
718         },
719 };
720
721 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
722         .gpio_base      = CAM_TCA6416_GPIO_BASE,
723 };
724
725 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
726         {
727                 I2C_BOARD_INFO("tca6416", 0x20),
728                 .platform_data = &cardhu_cam_tca6416_data,
729         },
730 };
731
732 static int __init pmu_tca6416_init(void)
733 {
734         if ((board_info.board_id == BOARD_E1198) ||
735                 (board_info.board_id == BOARD_E1291))
736                         return 0;
737
738         pr_info("Registering pmu pca6416\n");
739         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
740                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
741         return 0;
742 }
743
744 static int __init cam_tca6416_init(void)
745 {
746         /* Boards E1198 and E1291 are of Cardhu personality
747          * and donot have TCA6416 exp for camera */
748         if ((board_info.board_id == BOARD_E1198) ||
749                 (board_info.board_id == BOARD_E1291))
750                 return 0;
751
752         pr_info("Registering cam pca6416\n");
753         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
754                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
755         return 0;
756 }
757 #else
758 static int __init pmu_tca6416_init(void)
759 {
760         return 0;
761 }
762
763 static int __init cam_tca6416_init(void)
764 {
765         return 0;
766 }
767 #endif
768
769 #ifdef CONFIG_MPU_SENSORS_MPU3050
770 #define SENSOR_MPU_NAME "mpu3050"
771 static struct mpu3050_platform_data mpu3050_data = {
772         .int_config  = 0x10,
773         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
774         .level_shifter = 0,
775
776         .accel = {
777         .get_slave_descr = get_accel_slave_descr,
778         .adapt_num   = 2,
779         .bus         = EXT_SLAVE_BUS_SECONDARY,
780         .address     = 0x0F,
781         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
782         },
783
784         .compass = {
785         .get_slave_descr = get_compass_slave_descr,
786         .adapt_num   = 2,
787         .bus         = EXT_SLAVE_BUS_PRIMARY,
788         .address     = 0x0C,
789         .orientation = { 1, 0, 0, 0, 1, 0, 0, 0, 1 },  /* Orientation matrix for AKM on cardhu */
790         },
791 };
792
793 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
794         {
795                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
796                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
797                 .platform_data = &mpu3050_data,
798         },
799 };
800
801 static void cardhu_mpuirq_init(void)
802 {
803         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
804         tegra_gpio_enable(TEGRA_GPIO_PX1);
805         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
806         gpio_direction_input(TEGRA_GPIO_PX1);
807         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
808
809         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
810                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
811 }
812 #endif
813
814
815 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
816         {
817                 I2C_BOARD_INFO("isl29028", 0x44),
818         }
819 };
820
821 int __init cardhu_sensors_init(void)
822 {
823         int err;
824
825         tegra_get_board_info(&board_info);
826
827         cardhu_camera_init();
828         cam_tca6416_init();
829
830         i2c_register_board_info(2, cardhu_i2c3_board_info,
831                 ARRAY_SIZE(cardhu_i2c3_board_info));
832
833         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
834                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
835
836 #ifdef CONFIG_VIDEO_OV14810
837         /* This is disabled by default; To enable this change Kconfig;
838          * there should be some way to detect dynamically which board
839          * is connected (E1211/E1214), till that time sensor selection
840          * logic is static;
841          * e1214 corresponds to ov14810 sensor */
842         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
843                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
844 #else
845         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
846          * Front camera is on BUS2 */
847         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
848                 ARRAY_SIZE(cardhu_i2c6_board_info));
849
850         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
851                 ARRAY_SIZE(cardhu_i2c7_board_info));
852
853         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
854                 ARRAY_SIZE(cardhu_i2c8_board_info));
855
856 #endif
857         pmu_tca6416_init();
858
859         if (board_info.board_id == BOARD_E1291)
860                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
861                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
862
863         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
864                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
865
866         err = cardhu_nct1008_init();
867         if (err)
868                 return err;
869
870         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
871                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
872
873 #ifdef CONFIG_MPU_SENSORS_MPU3050
874         cardhu_mpuirq_init();
875 #endif
876         return 0;
877 }
878
879 #if defined(CONFIG_GPIO_PCA953X)
880 struct ov5650_gpios {
881         const char *name;
882         int gpio;
883         int enabled;
884 };
885
886 #define OV5650_GPIO(_name, _gpio, _enabled)             \
887         {                                               \
888                 .name = _name,                          \
889                 .gpio = _gpio,                          \
890                 .enabled = _enabled,                    \
891         }
892
893 static struct ov5650_gpios ov5650_gpio_keys[] = {
894         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
895         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
896         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
897         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
898         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
899         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
900         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
901         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
902         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
903         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
904         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
905         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
906         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
907         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
908         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
909 };
910
911 int __init cardhu_ov5650_late_init(void)
912 {
913         int ret;
914         int i;
915
916         if ((board_info.board_id == BOARD_E1198) ||
917                 (board_info.board_id == BOARD_E1291))
918                 return 0;
919
920         printk("%s: \n", __func__);
921         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
922                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
923                         ov5650_gpio_keys[i].name);
924                 if (ret < 0) {
925                         printk("%s: gpio_request failed for gpio #%d\n",
926                                 __func__, i);
927                         goto fail;
928                 }
929                 printk("%s: enable - %d\n", __func__, i);
930                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
931                         ov5650_gpio_keys[i].enabled);
932                 gpio_export(ov5650_gpio_keys[i].gpio, false);
933         }
934
935         return 0;
936
937 fail:
938         while (i--)
939                 gpio_free(ov5650_gpio_keys[i].gpio);
940         return ret;
941 }
942
943 late_initcall(cardhu_ov5650_late_init);
944 #endif