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