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