ARM: tegra: cardhu: Remove tegra_gpio_enb/disable
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-sensors.c
3  *
4  * Copyright (c) 2010-2012, NVIDIA CORPORATION, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * Neither the name of NVIDIA CORPORATION nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <linux/i2c.h>
35 #include <linux/delay.h>
36 #include <linux/regulator/consumer.h>
37 #include <linux/i2c/pca954x.h>
38 #include <linux/i2c/pca953x.h>
39 #include <linux/nct1008.h>
40 #include <mach/fb.h>
41 #include <mach/gpio.h>
42 #include <media/ov5650.h>
43 #include <media/ov5640.h>
44 #include <media/ov14810.h>
45 #include <media/ov2710.h>
46 #include <media/tps61050.h>
47 #include <generated/mach-types.h>
48 #include "gpio-names.h"
49 #include "board.h"
50 #include <linux/mpu.h>
51 #include <media/sh532u.h>
52 #include <linux/bq27x00.h>
53 #include <mach/gpio.h>
54 #include <mach/edp.h>
55 #include <mach/thermal.h>
56
57 #include "gpio-names.h"
58 #include "board-cardhu.h"
59 #include "cpu-tegra.h"
60
61 static struct regulator *cardhu_1v8_cam1 = NULL;
62 static struct regulator *cardhu_1v8_cam2 = NULL;
63 static struct regulator *cardhu_1v8_cam3 = NULL;
64 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
65 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
66 static struct regulator *cardhu_vdd_cam3 = NULL;
67
68 static struct board_info board_info;
69
70 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
71         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
72         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
73         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
74         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
75 };
76
77 static struct pca954x_platform_data cardhu_pca954x_data = {
78         .modes    = cardhu_pca954x_modes,
79         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
80 };
81
82 static int cardhu_camera_init(void)
83 {
84         int ret;
85
86         /* Boards E1198 and E1291 are of Cardhu personality
87          * and donot have TCA6416 exp for camera */
88         if ((board_info.board_id == BOARD_E1198) ||
89                 (board_info.board_id == BOARD_E1291)) {
90                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
91                 if (ret < 0)
92                         pr_err("%s: gpio_request failed for gpio %s\n",
93                                 __func__, "CAM1_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                 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                 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         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
124         if (ret < 0)
125                 pr_err("%s: gpio_request failed for gpio %s\n",
126                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
127         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
128         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
129
130         return 0;
131 }
132
133 static int cardhu_left_ov5650_power_on(void)
134 {
135         /* Boards E1198 and E1291 are of Cardhu personality
136          * and donot have TCA6416 exp for camera */
137         if ((board_info.board_id == BOARD_E1198) ||
138                 (board_info.board_id == BOARD_E1291)) {
139
140                 if (cardhu_vdd_2v8_cam1 == NULL) {
141                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
142                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
143                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
144                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
145                                 goto reg_alloc_fail;
146                         }
147                 }
148                 regulator_enable(cardhu_vdd_2v8_cam1);
149                 mdelay(5);
150         }
151
152         /* Enable VDD_1V8_Cam1 */
153         if (cardhu_1v8_cam1 == NULL) {
154                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
155                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
156                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
157                                 __func__, PTR_ERR(cardhu_1v8_cam1));
158                         goto reg_alloc_fail;
159                 }
160         }
161         regulator_enable(cardhu_1v8_cam1);
162
163         mdelay(5);
164         if ((board_info.board_id == BOARD_E1198) ||
165                 (board_info.board_id == BOARD_E1291)) {
166                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
167                 mdelay(20);
168                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
169                 mdelay(100);
170                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
171         }
172
173         if (board_info.board_id == BOARD_PM269) {
174                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
175                 mdelay(100);
176                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
177         }
178
179         return 0;
180
181 reg_alloc_fail:
182         if (cardhu_1v8_cam1) {
183                 regulator_put(cardhu_1v8_cam1);
184                 cardhu_1v8_cam1 = NULL;
185         }
186         if (cardhu_vdd_2v8_cam1) {
187                 regulator_put(cardhu_vdd_2v8_cam1);
188                 cardhu_vdd_2v8_cam1 = NULL;
189         }
190
191         return -ENODEV;
192
193 }
194
195 static int cardhu_left_ov5650_power_off(void)
196 {
197         /* Boards E1198 and E1291 are of Cardhu personality
198          * and donot have TCA6416 exp for camera */
199         if ((board_info.board_id == BOARD_E1198) ||
200                 (board_info.board_id == BOARD_E1291)) {
201                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
202                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
203                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
204         }
205         if (cardhu_1v8_cam1)
206                 regulator_disable(cardhu_1v8_cam1);
207         if (cardhu_vdd_2v8_cam1)
208                 regulator_disable(cardhu_vdd_2v8_cam1);
209
210         return 0;
211 }
212
213 struct ov5650_platform_data cardhu_left_ov5650_data = {
214         .power_on = cardhu_left_ov5650_power_on,
215         .power_off = cardhu_left_ov5650_power_off,
216 };
217
218 #ifdef CONFIG_VIDEO_OV14810
219 static int cardhu_ov14810_power_on(void)
220 {
221         if (board_info.board_id == BOARD_E1198) {
222                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
223                 mdelay(20);
224                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
225                 mdelay(100);
226                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
227         }
228
229         return 0;
230 }
231
232 static int cardhu_ov14810_power_off(void)
233 {
234         if (board_info.board_id == BOARD_E1198) {
235                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
236                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
237                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
238         }
239
240         return 0;
241 }
242
243 struct ov14810_platform_data cardhu_ov14810_data = {
244         .power_on = cardhu_ov14810_power_on,
245         .power_off = cardhu_ov14810_power_off,
246 };
247
248 struct ov14810_platform_data cardhu_ov14810uC_data = {
249         .power_on = NULL,
250         .power_off = NULL,
251 };
252
253 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
254         .power_on = NULL,
255         .power_off = NULL,
256 };
257
258 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
259         {
260                 I2C_BOARD_INFO("ov14810", 0x36),
261                 .platform_data = &cardhu_ov14810_data,
262         },
263         {
264                 I2C_BOARD_INFO("ov14810uC", 0x67),
265                 .platform_data = &cardhu_ov14810uC_data,
266         },
267         {
268                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
269                 .platform_data = &cardhu_ov14810SlaveDev_data,
270         }
271 };
272 #endif
273
274 static int cardhu_right_ov5650_power_on(void)
275 {
276         /* CSI-B and front sensor are muxed on cardhu */
277         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
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         /* CSI-B and front sensor are muxed on cardhu */
338         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
339
340         /* Boards E1198 and E1291 are of Cardhu personality
341          * and donot have TCA6416 exp for camera */
342         if ((board_info.board_id == BOARD_E1198) ||
343                 (board_info.board_id == BOARD_E1291)) {
344                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
345                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
346                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
347         }
348
349         if (cardhu_1v8_cam2)
350                 regulator_disable(cardhu_1v8_cam2);
351         if (cardhu_vdd_2v8_cam2)
352                 regulator_disable(cardhu_vdd_2v8_cam2);
353
354         return 0;
355 }
356
357 static void cardhu_ov5650_synchronize_sensors(void)
358 {
359         if (board_info.board_id == BOARD_E1198) {
360                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
361                 mdelay(50);
362                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
363                 mdelay(50);
364         }
365         else if (board_info.board_id == BOARD_E1291) {
366                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
367                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
368                 mdelay(50);
369                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
370                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
371                 mdelay(50);
372         }
373         else
374                 pr_err("%s: UnSupported BoardId\n", __func__);
375 }
376
377 struct ov5650_platform_data cardhu_right_ov5650_data = {
378         .power_on = cardhu_right_ov5650_power_on,
379         .power_off = cardhu_right_ov5650_power_off,
380         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
381 };
382
383 static int cardhu_ov2710_power_on(void)
384 {
385         /* CSI-B and front sensor are muxed on cardhu */
386         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
387
388         /* Boards E1198 and E1291 are of Cardhu personality
389          * and donot have TCA6416 exp for camera */
390         if ((board_info.board_id == BOARD_E1198) ||
391                 (board_info.board_id == BOARD_E1291)) {
392
393                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
394                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
395                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
396                 mdelay(10);
397
398                 if (cardhu_vdd_cam3 == NULL) {
399                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
400                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
401                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
402                                         __func__, PTR_ERR(cardhu_vdd_cam3));
403                                 goto reg_alloc_fail;
404                         }
405                 }
406                 regulator_enable(cardhu_vdd_cam3);
407         }
408
409         /* Enable VDD_1V8_Cam3 */
410         if (cardhu_1v8_cam3 == NULL) {
411                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
412                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
413                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
414                                 __func__, PTR_ERR(cardhu_1v8_cam3));
415                         goto reg_alloc_fail;
416                 }
417         }
418         regulator_enable(cardhu_1v8_cam3);
419         mdelay(5);
420
421         return 0;
422
423 reg_alloc_fail:
424         if (cardhu_1v8_cam3) {
425                 regulator_put(cardhu_1v8_cam3);
426                 cardhu_1v8_cam3 = NULL;
427         }
428         if (cardhu_vdd_cam3) {
429                 regulator_put(cardhu_vdd_cam3);
430                 cardhu_vdd_cam3 = NULL;
431         }
432
433         return -ENODEV;
434 }
435
436 static int cardhu_ov2710_power_off(void)
437 {
438         /* CSI-B and front sensor are muxed on cardhu */
439         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
440
441         /* Boards E1198 and E1291 are of Cardhu personality
442          * and donot have TCA6416 exp for camera */
443         if ((board_info.board_id == BOARD_E1198) ||
444                 (board_info.board_id == BOARD_E1291)) {
445                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
446                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
447                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
448         }
449
450         if (cardhu_1v8_cam3)
451                 regulator_disable(cardhu_1v8_cam3);
452         if (cardhu_vdd_cam3)
453                 regulator_disable(cardhu_vdd_cam3);
454
455         return 0;
456 }
457
458 struct ov2710_platform_data cardhu_ov2710_data = {
459         .power_on = cardhu_ov2710_power_on,
460         .power_off = cardhu_ov2710_power_off,
461 };
462
463 static int cardhu_ov5640_power_on(void)
464 {
465         /* CSI-B and front sensor are muxed on cardhu */
466         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
467
468         /* Boards E1198 and E1291 are of Cardhu personality
469          * and donot have TCA6416 exp for camera */
470         if ((board_info.board_id == BOARD_E1198) ||
471                 (board_info.board_id == BOARD_E1291)) {
472
473                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
474                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
475                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
476                 mdelay(10);
477
478                 if (cardhu_vdd_cam3 == NULL) {
479                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
480                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
481                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
482                                         __func__, PTR_ERR(cardhu_vdd_cam3));
483                                 goto reg_alloc_fail;
484                         }
485                 }
486                 regulator_enable(cardhu_vdd_cam3);
487         }
488
489         /* Enable VDD_1V8_Cam3 */
490         if (cardhu_1v8_cam3 == NULL) {
491                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
492                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
493                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
494                                 __func__, PTR_ERR(cardhu_1v8_cam3));
495                         goto reg_alloc_fail;
496                 }
497         }
498         regulator_enable(cardhu_1v8_cam3);
499         mdelay(5);
500
501         return 0;
502
503 reg_alloc_fail:
504         if (cardhu_1v8_cam3) {
505                 regulator_put(cardhu_1v8_cam3);
506                 cardhu_1v8_cam3 = NULL;
507         }
508         if (cardhu_vdd_cam3) {
509                 regulator_put(cardhu_vdd_cam3);
510                 cardhu_vdd_cam3 = NULL;
511         }
512
513         return -ENODEV;
514 }
515
516 static int cardhu_ov5640_power_off(void)
517 {
518         /* CSI-B and front sensor are muxed on cardhu */
519         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
520
521         /* Boards E1198 and E1291 are of Cardhu personality
522          * and donot have TCA6416 exp for camera */
523         if ((board_info.board_id == BOARD_E1198) ||
524                 (board_info.board_id == BOARD_E1291)) {
525                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
526                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
527                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
528         }
529
530         if (cardhu_1v8_cam3)
531                 regulator_disable(cardhu_1v8_cam3);
532         if (cardhu_vdd_cam3)
533                 regulator_disable(cardhu_vdd_cam3);
534
535         return 0;
536 }
537
538 struct ov5640_platform_data cardhu_ov5640_data = {
539         .power_on = cardhu_ov5640_power_on,
540         .power_off = cardhu_ov5640_power_off,
541 };
542
543 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
544         {
545                 I2C_BOARD_INFO("pca9546", 0x70),
546                 .platform_data = &cardhu_pca954x_data,
547         },
548 };
549
550
551 static struct nvc_gpio_pdata sh532u_gpio_pdata[] = {
552         { SH532U_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
553 };
554
555 static struct sh532u_platform_data sh532u_left_pdata = {
556         .cfg            = NVC_CFG_NODEV,
557         .num            = 1,
558         .sync           = 2,
559         .dev_name       = "focuser",
560         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
561         .gpio           = sh532u_gpio_pdata,
562 };
563
564 static struct sh532u_platform_data sh532u_right_pdata = {
565         .cfg            = NVC_CFG_NODEV,
566         .num            = 2,
567         .sync           = 1,
568         .dev_name       = "focuser",
569         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
570         .gpio           = sh532u_gpio_pdata,
571 };
572
573 static struct nvc_gpio_pdata pm269_sh532u_left_gpio_pdata[] = {
574         { SH532U_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
575 };
576
577 static struct sh532u_platform_data pm269_sh532u_left_pdata = {
578         .cfg            = 0,
579         .num            = 1,
580         .sync           = 2,
581         .dev_name       = "focuser",
582         .gpio_count     = ARRAY_SIZE(pm269_sh532u_left_gpio_pdata),
583         .gpio           = pm269_sh532u_left_gpio_pdata,
584 };
585
586 static struct nvc_gpio_pdata pm269_sh532u_right_gpio_pdata[] = {
587         { SH532U_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
588 };
589
590 static struct sh532u_platform_data pm269_sh532u_right_pdata = {
591         .cfg            = 0,
592         .num            = 2,
593         .sync           = 1,
594         .dev_name       = "focuser",
595         .gpio_count     = ARRAY_SIZE(pm269_sh532u_right_gpio_pdata),
596         .gpio           = pm269_sh532u_right_gpio_pdata,
597 };
598
599
600 static struct nvc_torch_pin_state cardhu_tps61050_pinstate = {
601         .mask           = 0x0008, /*VGP3*/
602         .values         = 0x0008,
603 };
604
605 static struct tps61050_platform_data cardhu_tps61050_pdata = {
606         .dev_name       = "torch",
607         .pinstate       = &cardhu_tps61050_pinstate,
608 };
609
610 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
611         {
612                 I2C_BOARD_INFO("tps61050", 0x33),
613                 .platform_data = &cardhu_tps61050_pdata,
614         },
615 };
616
617 static struct i2c_board_info cardhu_i2c6_board_info[] = {
618         {
619                 I2C_BOARD_INFO("ov5650L", 0x36),
620                 .platform_data = &cardhu_left_ov5650_data,
621         },
622         {
623                 I2C_BOARD_INFO("sh532u", 0x72),
624                 .platform_data = &sh532u_left_pdata,
625         },
626 };
627
628 static struct i2c_board_info cardhu_i2c7_board_info[] = {
629         {
630                 I2C_BOARD_INFO("ov5650R", 0x36),
631                 .platform_data = &cardhu_right_ov5650_data,
632         },
633         {
634                 I2C_BOARD_INFO("sh532u", 0x72),
635                 .platform_data = &sh532u_right_pdata,
636         },
637 };
638
639 static struct i2c_board_info pm269_i2c6_board_info[] = {
640         {
641                 I2C_BOARD_INFO("ov5650L", 0x36),
642                 .platform_data = &cardhu_left_ov5650_data,
643         },
644         {
645                 I2C_BOARD_INFO("sh532u", 0x72),
646                 .platform_data = &pm269_sh532u_left_pdata,
647         },
648 };
649
650 static struct i2c_board_info pm269_i2c7_board_info[] = {
651         {
652                 I2C_BOARD_INFO("ov5650R", 0x36),
653                 .platform_data = &cardhu_right_ov5650_data,
654         },
655         {
656                 I2C_BOARD_INFO("sh532u", 0x72),
657                 .platform_data = &pm269_sh532u_right_pdata,
658         },
659 };
660
661 static struct i2c_board_info cardhu_i2c8_board_info[] = {
662         {
663                 I2C_BOARD_INFO("ov2710", 0x36),
664                 .platform_data = &cardhu_ov2710_data,
665         },
666         {
667                 I2C_BOARD_INFO("ov5640", 0x3C),
668                 .platform_data = &cardhu_ov5640_data,
669         },
670 };
671
672 static int nct_get_temp(void *_data, long *temp)
673 {
674         struct nct1008_data *data = _data;
675         return nct1008_thermal_get_temp(data, temp);
676 }
677
678 static int nct_get_temp_low(void *_data, long *temp)
679 {
680         struct nct1008_data *data = _data;
681         return nct1008_thermal_get_temp_low(data, temp);
682 }
683
684 static int nct_set_limits(void *_data,
685                         long lo_limit_milli,
686                         long hi_limit_milli)
687 {
688         struct nct1008_data *data = _data;
689         return nct1008_thermal_set_limits(data,
690                                         lo_limit_milli,
691                                         hi_limit_milli);
692 }
693
694 static int nct_set_alert(void *_data,
695                                 void (*alert_func)(void *),
696                                 void *alert_data)
697 {
698         struct nct1008_data *data = _data;
699         return nct1008_thermal_set_alert(data, alert_func, alert_data);
700 }
701
702 static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
703 {
704         struct nct1008_data *data = _data;
705         return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
706 }
707
708 static void nct1008_probe_callback(struct nct1008_data *data)
709 {
710         struct tegra_thermal_device *thermal_device;
711
712         thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
713                                         GFP_KERNEL);
714         if (!thermal_device) {
715                 pr_err("unable to allocate thermal device\n");
716                 return;
717         }
718
719         thermal_device->name = "nct1008";
720         thermal_device->data = data;
721         thermal_device->offset = TDIODE_OFFSET;
722         thermal_device->get_temp = nct_get_temp;
723         thermal_device->get_temp_low = nct_get_temp_low;
724         thermal_device->set_limits = nct_set_limits;
725         thermal_device->set_alert = nct_set_alert;
726         thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
727
728         tegra_thermal_set_device(thermal_device);
729 }
730
731 static struct nct1008_platform_data cardhu_nct1008_pdata = {
732         .supported_hwrev = true,
733         .ext_range = true,
734         .conv_rate = 0x08,
735         .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
736         .probe_callback = nct1008_probe_callback,
737 };
738
739 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
740         {
741                 I2C_BOARD_INFO("bq27510", 0x55),
742         },
743 };
744
745 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
746         {
747                 I2C_BOARD_INFO("nct1008", 0x4C),
748                 .platform_data = &cardhu_nct1008_pdata,
749                 .irq = -1,
750         }
751 };
752
753 static int cardhu_nct1008_init(void)
754 {
755         int nct1008_port = -1;
756         int ret = 0;
757
758         if ((board_info.board_id == BOARD_E1198) ||
759                 (board_info.board_id == BOARD_E1291) ||
760                 (board_info.board_id == BOARD_E1257) ||
761                 (board_info.board_id == BOARD_PM269) ||
762                 (board_info.board_id == BOARD_PM305) ||
763                 (board_info.board_id == BOARD_PM311)) {
764                 nct1008_port = TEGRA_GPIO_PCC2;
765         } else if ((board_info.board_id == BOARD_E1186) ||
766                 (board_info.board_id == BOARD_E1187) ||
767                 (board_info.board_id == BOARD_E1256)) {
768                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
769                 /* nct1008_port = TEGRA_GPIO_PH7; */
770         }
771
772         if (nct1008_port >= 0) {
773                 /* FIXME: enable irq when throttling is supported */
774                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
775
776                 ret = gpio_request(nct1008_port, "temp_alert");
777                 if (ret < 0)
778                         return ret;
779
780                 ret = gpio_direction_input(nct1008_port);
781                 if (ret < 0)
782                         gpio_free(nct1008_port);
783         }
784
785         return ret;
786 }
787
788 #if defined(CONFIG_GPIO_PCA953X)
789 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
790         .gpio_base      = PMU_TCA6416_GPIO_BASE,
791 };
792
793 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
794         {
795                 I2C_BOARD_INFO("tca6416", 0x20),
796                 .platform_data = &cardhu_pmu_tca6416_data,
797         },
798 };
799
800 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
801         .gpio_base      = CAM_TCA6416_GPIO_BASE,
802 };
803
804 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
805         {
806                 I2C_BOARD_INFO("tca6416", 0x20),
807                 .platform_data = &cardhu_cam_tca6416_data,
808         },
809 };
810
811 static int __init pmu_tca6416_init(void)
812 {
813         if ((board_info.board_id == BOARD_E1198) ||
814                 (board_info.board_id == BOARD_E1291))
815                         return 0;
816
817         pr_info("Registering pmu pca6416\n");
818         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
819                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
820         return 0;
821 }
822
823 static int __init cam_tca6416_init(void)
824 {
825         /* Boards E1198 and E1291 are of Cardhu personality
826          * and donot have TCA6416 exp for camera */
827         if ((board_info.board_id == BOARD_E1198) ||
828                 (board_info.board_id == BOARD_E1291))
829                 return 0;
830
831         pr_info("Registering cam pca6416\n");
832         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
833                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
834         return 0;
835 }
836 #else
837 static int __init pmu_tca6416_init(void)
838 {
839         return 0;
840 }
841
842 static int __init cam_tca6416_init(void)
843 {
844         return 0;
845 }
846 #endif
847
848 /* MPU board file definition    */
849 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
850 #define MPU_GYRO_NAME           "mpu3050"
851 #endif
852 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU6050)
853 #define MPU_GYRO_NAME           "mpu6050"
854 #endif
855 static struct mpu_platform_data mpu_gyro_data = {
856         .int_config     = 0x10,
857         .level_shifter  = 0,
858         .orientation    = MPU_GYRO_ORIENTATION, /* Located in board_[platformname].h    */
859 };
860
861 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
862 static struct ext_slave_platform_data mpu_accel_data = {
863         .address        = MPU_ACCEL_ADDR,
864         .irq            = 0,
865         .adapt_num      = MPU_ACCEL_BUS_NUM,
866         .bus            = EXT_SLAVE_BUS_SECONDARY,
867         .orientation    = MPU_ACCEL_ORIENTATION,        /* Located in board_[platformname].h    */
868 };
869 #endif
870
871 static struct ext_slave_platform_data mpu_compass_data = {
872         .address        = MPU_COMPASS_ADDR,
873         .irq            = 0,
874         .adapt_num      = MPU_COMPASS_BUS_NUM,
875         .bus            = EXT_SLAVE_BUS_PRIMARY,
876         .orientation    = MPU_COMPASS_ORIENTATION,      /* Located in board_[platformname].h    */
877 };
878
879 static struct i2c_board_info __initdata inv_mpu_i2c2_board_info[] = {
880         {
881                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
882                 .irq = TEGRA_GPIO_TO_IRQ(MPU_GYRO_IRQ_GPIO),
883                 .platform_data = &mpu_gyro_data,
884         },
885 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
886         {
887                 I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR),
888 #if     MPU_ACCEL_IRQ_GPIO
889                 .irq = TEGRA_GPIO_TO_IRQ(MPU_ACCEL_IRQ_GPIO),
890 #endif
891                 .platform_data = &mpu_accel_data,
892         },
893 #endif
894         {
895                 I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
896 #if     MPU_COMPASS_IRQ_GPIO
897                 .irq = TEGRA_GPIO_TO_IRQ(MPU_COMPASS_IRQ_GPIO),
898 #endif
899                 .platform_data = &mpu_compass_data,
900         },
901 };
902
903 static void mpuirq_init(void)
904 {
905         int ret = 0;
906
907         pr_info("*** MPU START *** mpuirq_init...\n");
908
909 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
910 #if     MPU_ACCEL_IRQ_GPIO
911         /* ACCEL-IRQ assignment */
912         ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME);
913         if (ret < 0) {
914                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
915                 return;
916         }
917
918         ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO);
919         if (ret < 0) {
920                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
921                 gpio_free(MPU_ACCEL_IRQ_GPIO);
922                 return;
923         }
924 #endif
925 #endif
926
927         /* MPU-IRQ assignment */
928         ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
929         if (ret < 0) {
930                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
931                 return;
932         }
933
934         ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
935         if (ret < 0) {
936                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
937                 gpio_free(MPU_GYRO_IRQ_GPIO);
938                 return;
939         }
940         pr_info("*** MPU END *** mpuirq_init...\n");
941
942         i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c2_board_info,
943                 ARRAY_SIZE(inv_mpu_i2c2_board_info));
944 }
945
946 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
947         {
948                 I2C_BOARD_INFO("isl29028", 0x44),
949         }
950 };
951
952 static struct i2c_board_info cardhu_i2c2_ltr_board_info[] = {
953         {
954                 I2C_BOARD_INFO("LTR_558ALS", 0x23),
955         }
956 };
957
958 int __init cardhu_sensors_init(void)
959 {
960         int err;
961
962         tegra_get_board_info(&board_info);
963
964         cardhu_camera_init();
965         cam_tca6416_init();
966
967         i2c_register_board_info(2, cardhu_i2c3_board_info,
968                 ARRAY_SIZE(cardhu_i2c3_board_info));
969
970         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
971                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
972
973 #ifdef CONFIG_VIDEO_OV14810
974         /* This is disabled by default; To enable this change Kconfig;
975          * there should be some way to detect dynamically which board
976          * is connected (E1211/E1214), till that time sensor selection
977          * logic is static;
978          * e1214 corresponds to ov14810 sensor */
979         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
980                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
981 #else
982         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
983          * Front camera is on BUS2 */
984         if (board_info.board_id != BOARD_PM269) {
985                 i2c_register_board_info(PCA954x_I2C_BUS0,
986                                         cardhu_i2c6_board_info,
987                                         ARRAY_SIZE(cardhu_i2c6_board_info));
988
989                 i2c_register_board_info(PCA954x_I2C_BUS1,
990                                         cardhu_i2c7_board_info,
991                                         ARRAY_SIZE(cardhu_i2c7_board_info));
992         } else {
993                 i2c_register_board_info(PCA954x_I2C_BUS0,
994                                         pm269_i2c6_board_info,
995                                         ARRAY_SIZE(pm269_i2c6_board_info));
996
997                 i2c_register_board_info(PCA954x_I2C_BUS1,
998                                         pm269_i2c7_board_info,
999                                         ARRAY_SIZE(pm269_i2c7_board_info));
1000         }
1001         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
1002                 ARRAY_SIZE(cardhu_i2c8_board_info));
1003
1004 #endif
1005         pmu_tca6416_init();
1006
1007         if (board_info.board_id == BOARD_E1291)
1008                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
1009                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
1010
1011         if (board_info.sku == BOARD_SKU_B11)
1012                 i2c_register_board_info(2, cardhu_i2c2_ltr_board_info,
1013                         ARRAY_SIZE(cardhu_i2c2_ltr_board_info));
1014         else
1015                 i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
1016                         ARRAY_SIZE(cardhu_i2c2_isl_board_info));
1017
1018         err = cardhu_nct1008_init();
1019         if (err)
1020                 return err;
1021
1022         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
1023                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
1024
1025         mpuirq_init();
1026         return 0;
1027 }
1028
1029 #if defined(CONFIG_GPIO_PCA953X)
1030 struct ov5650_gpios {
1031         const char *name;
1032         int gpio;
1033         int enabled;
1034 };
1035
1036 #define OV5650_GPIO(_name, _gpio, _enabled)             \
1037         {                                               \
1038                 .name = _name,                          \
1039                 .gpio = _gpio,                          \
1040                 .enabled = _enabled,                    \
1041         }
1042
1043 static struct ov5650_gpios ov5650_gpio_keys[] = {
1044         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
1045         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
1046         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
1047         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
1048         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
1049         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
1050         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
1051         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
1052         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
1053         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
1054         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
1055         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
1056         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
1057         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
1058         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
1059 };
1060
1061 int __init cardhu_ov5650_late_init(void)
1062 {
1063         int ret;
1064         int i;
1065
1066         if (!machine_is_cardhu())
1067                 return 0;
1068
1069         if ((board_info.board_id == BOARD_E1198) ||
1070                 (board_info.board_id == BOARD_E1291))
1071                 return 0;
1072
1073         printk("%s: \n", __func__);
1074         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
1075                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
1076                         ov5650_gpio_keys[i].name);
1077                 if (ret < 0) {
1078                         printk("%s: gpio_request failed for gpio #%d\n",
1079                                 __func__, i);
1080                         goto fail;
1081                 }
1082                 printk("%s: enable - %d\n", __func__, i);
1083                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
1084                         ov5650_gpio_keys[i].enabled);
1085                 gpio_export(ov5650_gpio_keys[i].gpio, false);
1086         }
1087
1088         return 0;
1089
1090 fail:
1091         while (i--)
1092                 gpio_free(ov5650_gpio_keys[i].gpio);
1093         return ret;
1094 }
1095
1096 late_initcall(cardhu_ov5650_late_init);
1097 #endif