e9d2c6b09157b1d18d8dada015c4e868167b9205
[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) 2011, NVIDIA, All Rights Reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include <linux/i2c.h>
22 #include <linux/delay.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/i2c/pca954x.h>
25 #include <linux/i2c/pca953x.h>
26 #include <linux/nct1008.h>
27 #include <mach/fb.h>
28 #include <mach/gpio.h>
29 #include <media/ov5650.h>
30 #include <media/ov2710.h>
31 #include <generated/mach-types.h>
32 #include "gpio-names.h"
33 #include "board.h"
34 #include <linux/mpu.h>
35 #include <media/sh532u.h>
36
37 #include <mach/gpio.h>
38
39 #include "gpio-names.h"
40 #include "board-cardhu.h"
41
42 static struct regulator *cardhu_1v8_cam1 = NULL;
43 static struct regulator *cardhu_1v8_cam2 = NULL;
44 static struct regulator *cardhu_1v8_cam3 = NULL;
45 static struct regulator *cardhu_avdd_dsi_csi = NULL;
46 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
47 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
48 static struct regulator *cardhu_vdd_cam3 = NULL;
49
50 static struct board_info board_info;
51
52 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
53         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
54         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
55         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
56         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
57 };
58
59 static struct pca954x_platform_data cardhu_pca954x_data = {
60         .modes    = cardhu_pca954x_modes,
61         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
62 };
63
64 static int cardhu_camera_init(void)
65 {
66         int ret;
67
68         /* Boards E1198 and E1291 are of Cardhu personality
69          * and donot have TCA6416 exp for camera */
70         if ((board_info.board_id == BOARD_E1198) ||
71                 (board_info.board_id == BOARD_E1291)) {
72                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
73                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
74                 if (ret < 0)
75                         pr_err("%s: gpio_request failed for gpio %s\n",
76                                 __func__, "CAM1_POWER_DWN_GPIO");
77                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
78                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
79                 if (ret < 0)
80                         pr_err("%s: gpio_request failed for gpio %s\n",
81                                 __func__, "CAM3_POWER_DWN_GPIO");
82
83                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
84                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
85                 if (ret < 0)
86                         pr_err("%s: gpio_request failed for gpio %s\n",
87                                 __func__, "CAM2_POWER_DWN_GPIO");
88
89                 tegra_gpio_enable(OV5650_RESETN_GPIO);
90                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
91                 if (ret < 0)
92                         pr_err("%s: gpio_request failed for gpio %s\n",
93                                 __func__, "OV5650_RESETN_GPIO");
94
95                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
96                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
97                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
98                 mdelay(10);
99
100                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
101                 mdelay(5);
102                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
103                 mdelay(5);
104                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
105                 mdelay(5);
106         }
107
108         /* To select the CSIB MUX either for cam2 or cam3 */
109         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
110         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
111         if (ret < 0)
112                 pr_err("%s: gpio_request failed for gpio %s\n",
113                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
114         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
115         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
116
117         return 0;
118 }
119
120 static int cardhu_left_ov5650_power_on(void)
121 {
122         /* Boards E1198 and E1291 are of Cardhu personality
123          * and donot have TCA6416 exp for camera */
124         if ((board_info.board_id == BOARD_E1198) ||
125                 (board_info.board_id == BOARD_E1291)) {
126
127                 if (cardhu_vdd_2v8_cam1 == NULL) {
128                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
129                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
130                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
131                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
132                                 goto reg_alloc_fail;
133                         }
134                 }
135                 regulator_enable(cardhu_vdd_2v8_cam1);
136                 mdelay(5);
137         }
138
139         /* Enable VDD_1V8_Cam1 */
140         if (cardhu_1v8_cam1 == NULL) {
141                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
142                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
143                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
144                                 __func__, PTR_ERR(cardhu_1v8_cam1));
145                         goto reg_alloc_fail;
146                 }
147         }
148         regulator_enable(cardhu_1v8_cam1);
149
150         /* Enable AVDD_CSI_DSI */
151         if (cardhu_avdd_dsi_csi == NULL) {
152                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
153                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
154                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
155                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
156                         goto reg_alloc_fail;
157                 }
158         }
159         regulator_enable(cardhu_avdd_dsi_csi);
160
161         mdelay(5);
162         if ((board_info.board_id == BOARD_E1198) ||
163                 (board_info.board_id == BOARD_E1291)) {
164                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
165                 mdelay(20);
166                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
167                 mdelay(100);
168                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
169         }
170         return 0;
171
172 reg_alloc_fail:
173         if (cardhu_1v8_cam1) {
174                 regulator_put(cardhu_1v8_cam1);
175                 cardhu_1v8_cam1 = NULL;
176         }
177         if (cardhu_avdd_dsi_csi) {
178                 regulator_put(cardhu_avdd_dsi_csi);
179                 cardhu_avdd_dsi_csi = 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_avdd_dsi_csi)
203                 regulator_disable(cardhu_avdd_dsi_csi);
204         if (cardhu_vdd_2v8_cam1)
205                 regulator_disable(cardhu_vdd_2v8_cam1);
206
207         return 0;
208 }
209
210 struct ov5650_platform_data cardhu_left_ov5650_data = {
211         .power_on = cardhu_left_ov5650_power_on,
212         .power_off = cardhu_left_ov5650_power_off,
213 };
214
215 static int cardhu_right_ov5650_power_on(void)
216 {
217         /* Boards E1198 and E1291 are of Cardhu personality
218          * and donot have TCA6416 exp for camera */
219         if ((board_info.board_id == BOARD_E1198) ||
220                 (board_info.board_id == BOARD_E1291)) {
221
222                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
223                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
224                 mdelay(10);
225
226                 if (cardhu_vdd_2v8_cam2 == NULL) {
227                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
228                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
229                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
230                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
231                                 goto reg_alloc_fail;
232                         }
233                 }
234                 regulator_enable(cardhu_vdd_2v8_cam2);
235                 mdelay(5);
236         }
237
238         /* Enable VDD_1V8_Cam2 */
239         if (cardhu_1v8_cam2 == NULL) {
240                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
241                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
242                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
243                                 __func__, PTR_ERR(cardhu_1v8_cam2));
244                         goto reg_alloc_fail;
245                 }
246         }
247         regulator_enable(cardhu_1v8_cam2);
248
249         /* Enable AVDD_CSI_DSI */
250         if (cardhu_avdd_dsi_csi == NULL) {
251                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
252                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
253                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
254                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
255                         goto reg_alloc_fail;
256                 }
257         }
258         regulator_enable(cardhu_avdd_dsi_csi);
259
260         mdelay(5);
261         return 0;
262
263 reg_alloc_fail:
264         if (cardhu_1v8_cam2) {
265                 regulator_put(cardhu_1v8_cam2);
266                 cardhu_1v8_cam2 = NULL;
267         }
268         if (cardhu_avdd_dsi_csi) {
269                 regulator_put(cardhu_avdd_dsi_csi);
270                 cardhu_avdd_dsi_csi = NULL;
271         }
272         if (cardhu_vdd_2v8_cam2) {
273                 regulator_put(cardhu_vdd_2v8_cam2);
274                 cardhu_vdd_2v8_cam2 = NULL;
275         }
276
277         return -ENODEV;
278
279 }
280
281 static int cardhu_right_ov5650_power_off(void)
282 {
283         /* Boards E1198 and E1291 are of Cardhu personality
284          * and donot have TCA6416 exp for camera */
285         if ((board_info.board_id == BOARD_E1198) ||
286                 (board_info.board_id == BOARD_E1291)) {
287                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
288                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
289         }
290
291         if (cardhu_1v8_cam2)
292                 regulator_disable(cardhu_1v8_cam2);
293         if (cardhu_avdd_dsi_csi)
294                 regulator_disable(cardhu_avdd_dsi_csi);
295         if (cardhu_vdd_2v8_cam2)
296                 regulator_disable(cardhu_vdd_2v8_cam2);
297
298         return 0;
299 }
300
301
302 struct ov5650_platform_data cardhu_right_ov5650_data = {
303         .power_on = cardhu_right_ov5650_power_on,
304         .power_off = cardhu_right_ov5650_power_off,
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
344         /* Enable AVDD_CSI_DSI */
345         if (cardhu_avdd_dsi_csi == NULL) {
346                 cardhu_avdd_dsi_csi = regulator_get(NULL, "avdd_dsi_csi");
347                 if (WARN_ON(IS_ERR(cardhu_avdd_dsi_csi))) {
348                         pr_err("%s: couldn't get regulator avdd_dsi_csi: %ld\n",
349                                 __func__, PTR_ERR(cardhu_avdd_dsi_csi));
350                         goto reg_alloc_fail;
351                 }
352         }
353         regulator_enable(cardhu_avdd_dsi_csi);
354         mdelay(5);
355
356         return 0;
357
358 reg_alloc_fail:
359         if (cardhu_1v8_cam3) {
360                 regulator_put(cardhu_1v8_cam3);
361                 cardhu_1v8_cam3 = NULL;
362         }
363         if (cardhu_avdd_dsi_csi) {
364                 regulator_put(cardhu_avdd_dsi_csi);
365                 cardhu_avdd_dsi_csi = NULL;
366         }
367         if (cardhu_vdd_cam3) {
368                 regulator_put(cardhu_vdd_cam3);
369                 cardhu_vdd_cam3 = NULL;
370         }
371
372         return -ENODEV;
373 }
374
375 static int cardhu_ov2710_power_off(void)
376 {
377         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
378
379         /* Boards E1198 and E1291 are of Cardhu personality
380          * and donot have TCA6416 exp for camera */
381         if ((board_info.board_id == BOARD_E1198) ||
382                 (board_info.board_id == BOARD_E1291)) {
383                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
384                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
385                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
386         }
387
388         if (cardhu_1v8_cam3)
389                 regulator_disable(cardhu_1v8_cam3);
390         if (cardhu_avdd_dsi_csi)
391                 regulator_disable(cardhu_avdd_dsi_csi);
392         if (cardhu_vdd_cam3)
393                 regulator_disable(cardhu_vdd_cam3);
394
395         return 0;
396 }
397
398 struct ov2710_platform_data cardhu_ov2710_data = {
399         .power_on = cardhu_ov2710_power_on,
400         .power_off = cardhu_ov2710_power_off,
401 };
402
403 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
404         {
405                 I2C_BOARD_INFO("pca9546", 0x70),
406                 .platform_data = &cardhu_pca954x_data,
407         },
408 };
409
410 static int sh532u_power_control(void *cdata, int is_enable) {
411         static struct regulator *vdd_2v8_cam1_af = NULL;
412         if (vdd_2v8_cam1_af == NULL) {
413                 vdd_2v8_cam1_af = regulator_get(NULL, "vdd_2v8_cam1_af");
414                 if (WARN_ON(IS_ERR_OR_NULL(vdd_2v8_cam1_af))) {
415                         pr_err("%s: couldn't get regulator vdd_2v8_cam1_af:"
416                                 " %ld\n", __func__, PTR_ERR(vdd_2v8_cam1_af));
417                         return -ENODEV;
418                 }
419         }
420         if (is_enable) {
421                 regulator_enable(vdd_2v8_cam1_af);
422                 mdelay(20);
423         } else
424                 regulator_disable(vdd_2v8_cam1_af);
425         return 0;
426 }
427 static int sh532u_init(void *cdata) {
428         return sh532u_power_control(cdata, true);
429 }
430 static int sh532u_deinit(void *cdata) {
431         return sh532u_power_control(cdata, false);
432 }
433
434 struct sh532u_platform_data sh532u_pdata = {
435         .board_init = sh532u_init,
436         .board_deinit = sh532u_deinit,
437 };
438 static struct i2c_board_info cardhu_i2c6_board_info[] = {
439         {
440                 I2C_BOARD_INFO("ov5650L", 0x36),
441                 .platform_data = &cardhu_left_ov5650_data,
442         },
443         {
444                 I2C_BOARD_INFO("sh532u", 0x72),
445                 .platform_data = &sh532u_pdata,
446         },
447 };
448
449 static struct i2c_board_info cardhu_i2c7_board_info[] = {
450         {
451                 I2C_BOARD_INFO("ov5650R", 0x36),
452                 .platform_data = &cardhu_right_ov5650_data,
453         },
454 };
455
456 static struct i2c_board_info cardhu_i2c8_board_info[] = {
457         {
458                 I2C_BOARD_INFO("ov2710", 0x36),
459                 .platform_data = &cardhu_ov2710_data,
460         },
461 };
462
463 static struct nct1008_platform_data cardhu_nct1008_pdata = {
464         .supported_hwrev = true,
465         .ext_range = false,
466         .conv_rate = 0x08,
467         .offset = 0,
468         .hysteresis = 5,
469         .shutdown_ext_limit = 75,
470         .shutdown_local_limit = 75,
471         .throttling_ext_limit = 60,
472         .alarm_fn = NULL,
473 };
474
475 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
476         {
477                 I2C_BOARD_INFO("bq27510", 0x55),
478                 .irq = AC_PRESENT_GPIO,
479         },
480 };
481
482 static struct i2c_board_info cardhu_i2c4_board_info[] = {
483         {
484                 I2C_BOARD_INFO("nct1008", 0x4C),
485                 .platform_data = &cardhu_nct1008_pdata,
486                 .irq = -1,
487         }
488 };
489
490 static int cardhu_nct1008_init(void)
491 {
492         int nct1008_port = -1;
493         int ret;
494
495         if ((board_info.board_id == BOARD_E1198) ||
496                 (board_info.board_id == BOARD_E1291)) {
497                 nct1008_port = TEGRA_GPIO_PCC2;
498         } else if ((board_info.board_id == BOARD_E1186) ||
499                 (board_info.board_id == BOARD_E1187)) {
500                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
501                 /* nct1008_port = TEGRA_GPIO_PH7; */
502         }
503
504         if (nct1008_port >= 0) {
505                 /* FIXME: enable irq when throttling is supported */
506                 /* cardhu_i2c4_board_info[0].irq = */
507                 /* TEGRA_GPIO_TO_IRQ(nct1008_port); */
508
509                 ret = gpio_request(nct1008_port, "temp_alert");
510                 if (ret < 0)
511                         return ret;
512
513                 ret = gpio_direction_input(nct1008_port);
514                 if (ret < 0)
515                         gpio_free(nct1008_port);
516                 else
517                         tegra_gpio_enable(nct1008_port);
518
519         }
520         return ret;
521 }
522
523 #if defined(CONFIG_GPIO_PCA953X)
524 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
525         .gpio_base      = PMU_TCA6416_GPIO_BASE,
526 };
527
528 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
529         {
530                 I2C_BOARD_INFO("tca6416", 0x20),
531                 .platform_data = &cardhu_pmu_tca6416_data,
532         },
533 };
534
535 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
536         .gpio_base      = CAM_TCA6416_GPIO_BASE,
537 };
538
539 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
540         {
541                 I2C_BOARD_INFO("tca6416", 0x20),
542                 .platform_data = &cardhu_cam_tca6416_data,
543         },
544 };
545
546 static int __init pmu_tca6416_init(void)
547 {
548         if ((board_info.board_id == BOARD_E1198) ||
549                 (board_info.board_id == BOARD_E1291))
550                         return 0;
551
552         pr_info("Registering pmu pca6416\n");
553         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
554                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
555         return 0;
556 }
557
558 static int __init cam_tca6416_init(void)
559 {
560         /* Boards E1198 and E1291 are of Cardhu personality
561          * and donot have TCA6416 exp for camera */
562         if ((board_info.board_id == BOARD_E1198) ||
563                 (board_info.board_id == BOARD_E1291))
564                 return 0;
565
566         pr_info("Registering cam pca6416\n");
567         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
568                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
569         return 0;
570 }
571 #else
572 static int __init pmu_tca6416_init(void)
573 {
574         return 0;
575 }
576
577 static int __init cam_tca6416_init(void)
578 {
579         return 0;
580 }
581 #endif
582
583 #ifdef CONFIG_SENSORS_MPU3050
584 #define SENSOR_MPU_NAME "mpu3050"
585 static struct mpu3050_platform_data mpu3050_data = {
586         .int_config  = 0x10,
587         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
588         .level_shifter = 0,
589
590         .accel = {
591         .get_slave_descr = get_accel_slave_descr,
592         .adapt_num   = 2,
593         .bus         = EXT_SLAVE_BUS_SECONDARY,
594         .address     = 0x0F,
595         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
596         },
597
598         .compass = {
599         .get_slave_descr = get_compass_slave_descr,
600         .adapt_num   = 2,
601         .bus         = EXT_SLAVE_BUS_PRIMARY,
602         .address     = 0x0C,
603         .orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 },  /* Orientation matrix for AKM on cardhu */
604         },
605 };
606
607 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
608         {
609                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
610                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
611                 .platform_data = &mpu3050_data,
612         },
613 };
614
615 static void cardhu_mpuirq_init(void)
616 {
617         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
618         tegra_gpio_enable(TEGRA_GPIO_PX1);
619         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
620         gpio_direction_input(TEGRA_GPIO_PX1);
621         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
622 }
623 #endif
624
625
626 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
627         {
628                 I2C_BOARD_INFO("isl29028", 0x44),
629         }
630 };
631
632 int __init cardhu_sensors_init(void)
633 {
634         int err;
635
636         tegra_get_board_info(&board_info);
637
638         cardhu_camera_init();
639         cam_tca6416_init();
640
641         i2c_register_board_info(2, cardhu_i2c3_board_info,
642                 ARRAY_SIZE(cardhu_i2c3_board_info));
643
644         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
645          * Front camera is on BUS2 */
646         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
647                 ARRAY_SIZE(cardhu_i2c6_board_info));
648
649         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
650                 ARRAY_SIZE(cardhu_i2c7_board_info));
651
652         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
653                 ARRAY_SIZE(cardhu_i2c8_board_info));
654
655         pmu_tca6416_init();
656
657         i2c_register_board_info(4, cardhu_i2c4_board_info,
658                 ARRAY_SIZE(cardhu_i2c4_board_info));
659
660         if (board_info.board_id == BOARD_E1291)
661                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
662                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
663
664         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
665                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
666
667         err = cardhu_nct1008_init();
668         if (err)
669                 return err;
670
671 #ifdef CONFIG_SENSORS_MPU3050
672         cardhu_mpuirq_init();
673 #endif
674
675 #ifdef CONFIG_SENSORS_MPU3050
676         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
677                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
678 #endif
679
680         return 0;
681 }
682
683 #if defined(CONFIG_GPIO_PCA953X)
684 struct ov5650_gpios {
685         const char *name;
686         int gpio;
687         int enabled;
688 };
689
690 #define OV5650_GPIO(_name, _gpio, _enabled)             \
691         {                                               \
692                 .name = _name,                          \
693                 .gpio = _gpio,                          \
694                 .enabled = _enabled,                    \
695         }
696
697 static struct ov5650_gpios ov5650_gpio_keys[] = {
698         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
699         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
700         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 1),
701         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
702         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
703         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
704         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 1),
705         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
706         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
707         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
708         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 1),
709         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
710         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
711         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
712         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
713 };
714
715 int __init cardhu_ov5650_late_init(void)
716 {
717         int ret;
718         int i;
719
720         printk("%s: \n", __func__);
721         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
722                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
723                         ov5650_gpio_keys[i].name);
724                 if (ret < 0) {
725                         printk("%s: gpio_request failed for gpio #%d\n",
726                                 __func__, i);
727                         goto fail;
728                 }
729                 printk("%s: enable - %d\n", __func__, i);
730                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
731                         ov5650_gpio_keys[i].enabled);
732                 gpio_export(ov5650_gpio_keys[i].gpio, false);
733         }
734
735         return 0;
736
737 fail:
738         while (i--)
739                 gpio_free(ov5650_gpio_keys[i].gpio);
740         return ret;
741 }
742
743 late_initcall(cardhu_ov5650_late_init);
744 #endif