arm: tegra: pm269: update sh532u config
[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                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
91                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
92                 if (ret < 0)
93                         pr_err("%s: gpio_request failed for gpio %s\n",
94                                 __func__, "CAM1_POWER_DWN_GPIO");
95                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
96                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
97                 if (ret < 0)
98                         pr_err("%s: gpio_request failed for gpio %s\n",
99                                 __func__, "CAM3_POWER_DWN_GPIO");
100
101                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
102                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
103                 if (ret < 0)
104                         pr_err("%s: gpio_request failed for gpio %s\n",
105                                 __func__, "CAM2_POWER_DWN_GPIO");
106
107                 tegra_gpio_enable(OV5650_RESETN_GPIO);
108                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
109                 if (ret < 0)
110                         pr_err("%s: gpio_request failed for gpio %s\n",
111                                 __func__, "OV5650_RESETN_GPIO");
112
113                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
114                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
115                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
116                 mdelay(10);
117
118                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
119                 mdelay(5);
120                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
121                 mdelay(5);
122                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
123                 mdelay(5);
124         }
125
126         /* To select the CSIB MUX either for cam2 or cam3 */
127         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
128         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
129         if (ret < 0)
130                 pr_err("%s: gpio_request failed for gpio %s\n",
131                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
132         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
133         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
134
135         return 0;
136 }
137
138 static int cardhu_left_ov5650_power_on(void)
139 {
140         /* Boards E1198 and E1291 are of Cardhu personality
141          * and donot have TCA6416 exp for camera */
142         if ((board_info.board_id == BOARD_E1198) ||
143                 (board_info.board_id == BOARD_E1291)) {
144
145                 if (cardhu_vdd_2v8_cam1 == NULL) {
146                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
147                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
148                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
149                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
150                                 goto reg_alloc_fail;
151                         }
152                 }
153                 regulator_enable(cardhu_vdd_2v8_cam1);
154                 mdelay(5);
155         }
156
157         /* Enable VDD_1V8_Cam1 */
158         if (cardhu_1v8_cam1 == NULL) {
159                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
160                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
161                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
162                                 __func__, PTR_ERR(cardhu_1v8_cam1));
163                         goto reg_alloc_fail;
164                 }
165         }
166         regulator_enable(cardhu_1v8_cam1);
167
168         mdelay(5);
169         if ((board_info.board_id == BOARD_E1198) ||
170                 (board_info.board_id == BOARD_E1291)) {
171                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
172                 mdelay(20);
173                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
174                 mdelay(100);
175                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
176         }
177
178         if (board_info.board_id == BOARD_PM269) {
179                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
180                 mdelay(100);
181                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
182         }
183
184         return 0;
185
186 reg_alloc_fail:
187         if (cardhu_1v8_cam1) {
188                 regulator_put(cardhu_1v8_cam1);
189                 cardhu_1v8_cam1 = NULL;
190         }
191         if (cardhu_vdd_2v8_cam1) {
192                 regulator_put(cardhu_vdd_2v8_cam1);
193                 cardhu_vdd_2v8_cam1 = NULL;
194         }
195
196         return -ENODEV;
197
198 }
199
200 static int cardhu_left_ov5650_power_off(void)
201 {
202         /* Boards E1198 and E1291 are of Cardhu personality
203          * and donot have TCA6416 exp for camera */
204         if ((board_info.board_id == BOARD_E1198) ||
205                 (board_info.board_id == BOARD_E1291)) {
206                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
207                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
208                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
209         }
210         if (cardhu_1v8_cam1)
211                 regulator_disable(cardhu_1v8_cam1);
212         if (cardhu_vdd_2v8_cam1)
213                 regulator_disable(cardhu_vdd_2v8_cam1);
214
215         return 0;
216 }
217
218 struct ov5650_platform_data cardhu_left_ov5650_data = {
219         .power_on = cardhu_left_ov5650_power_on,
220         .power_off = cardhu_left_ov5650_power_off,
221 };
222
223 #ifdef CONFIG_VIDEO_OV14810
224 static int cardhu_ov14810_power_on(void)
225 {
226         if (board_info.board_id == BOARD_E1198) {
227                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
228                 mdelay(20);
229                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
230                 mdelay(100);
231                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
232         }
233
234         return 0;
235 }
236
237 static int cardhu_ov14810_power_off(void)
238 {
239         if (board_info.board_id == BOARD_E1198) {
240                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
241                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
242                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
243         }
244
245         return 0;
246 }
247
248 struct ov14810_platform_data cardhu_ov14810_data = {
249         .power_on = cardhu_ov14810_power_on,
250         .power_off = cardhu_ov14810_power_off,
251 };
252
253 struct ov14810_platform_data cardhu_ov14810uC_data = {
254         .power_on = NULL,
255         .power_off = NULL,
256 };
257
258 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
259         .power_on = NULL,
260         .power_off = NULL,
261 };
262
263 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
264         {
265                 I2C_BOARD_INFO("ov14810", 0x36),
266                 .platform_data = &cardhu_ov14810_data,
267         },
268         {
269                 I2C_BOARD_INFO("ov14810uC", 0x67),
270                 .platform_data = &cardhu_ov14810uC_data,
271         },
272         {
273                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
274                 .platform_data = &cardhu_ov14810SlaveDev_data,
275         }
276 };
277 #endif
278
279 static int cardhu_right_ov5650_power_on(void)
280 {
281         /* CSI-B and front sensor are muxed on cardhu */
282         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
283
284         /* Boards E1198 and E1291 are of Cardhu personality
285          * and donot have TCA6416 exp for camera */
286         if ((board_info.board_id == BOARD_E1198) ||
287                 (board_info.board_id == BOARD_E1291)) {
288
289                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
290                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
291                 mdelay(10);
292
293                 if (cardhu_vdd_2v8_cam2 == NULL) {
294                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
295                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
296                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
297                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
298                                 goto reg_alloc_fail;
299                         }
300                 }
301                 regulator_enable(cardhu_vdd_2v8_cam2);
302                 mdelay(5);
303         }
304
305         /* Enable VDD_1V8_Cam2 */
306         if (cardhu_1v8_cam2 == NULL) {
307                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
308                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
309                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
310                                 __func__, PTR_ERR(cardhu_1v8_cam2));
311                         goto reg_alloc_fail;
312                 }
313         }
314         regulator_enable(cardhu_1v8_cam2);
315
316         mdelay(5);
317
318         if (board_info.board_id == BOARD_PM269) {
319                 gpio_direction_output(CAM2_RST_L_GPIO, 0);
320                 mdelay(100);
321                 gpio_direction_output(CAM2_RST_L_GPIO, 1);
322         }
323
324         return 0;
325
326 reg_alloc_fail:
327         if (cardhu_1v8_cam2) {
328                 regulator_put(cardhu_1v8_cam2);
329                 cardhu_1v8_cam2 = NULL;
330         }
331         if (cardhu_vdd_2v8_cam2) {
332                 regulator_put(cardhu_vdd_2v8_cam2);
333                 cardhu_vdd_2v8_cam2 = NULL;
334         }
335
336         return -ENODEV;
337
338 }
339
340 static int cardhu_right_ov5650_power_off(void)
341 {
342         /* CSI-B and front sensor are muxed on cardhu */
343         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
344
345         /* Boards E1198 and E1291 are of Cardhu personality
346          * and donot have TCA6416 exp for camera */
347         if ((board_info.board_id == BOARD_E1198) ||
348                 (board_info.board_id == BOARD_E1291)) {
349                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
350                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
351                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
352         }
353
354         if (cardhu_1v8_cam2)
355                 regulator_disable(cardhu_1v8_cam2);
356         if (cardhu_vdd_2v8_cam2)
357                 regulator_disable(cardhu_vdd_2v8_cam2);
358
359         return 0;
360 }
361
362 static void cardhu_ov5650_synchronize_sensors(void)
363 {
364         if (board_info.board_id == BOARD_E1198) {
365                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
366                 mdelay(50);
367                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
368                 mdelay(50);
369         }
370         else if (board_info.board_id == BOARD_E1291) {
371                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
372                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
373                 mdelay(50);
374                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
375                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
376                 mdelay(50);
377         }
378         else
379                 pr_err("%s: UnSupported BoardId\n", __func__);
380 }
381
382 struct ov5650_platform_data cardhu_right_ov5650_data = {
383         .power_on = cardhu_right_ov5650_power_on,
384         .power_off = cardhu_right_ov5650_power_off,
385         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
386 };
387
388 static int cardhu_ov2710_power_on(void)
389 {
390         /* CSI-B and front sensor are muxed on cardhu */
391         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
392
393         /* Boards E1198 and E1291 are of Cardhu personality
394          * and donot have TCA6416 exp for camera */
395         if ((board_info.board_id == BOARD_E1198) ||
396                 (board_info.board_id == BOARD_E1291)) {
397
398                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
399                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
400                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
401                 mdelay(10);
402
403                 if (cardhu_vdd_cam3 == NULL) {
404                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
405                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
406                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
407                                         __func__, PTR_ERR(cardhu_vdd_cam3));
408                                 goto reg_alloc_fail;
409                         }
410                 }
411                 regulator_enable(cardhu_vdd_cam3);
412         }
413
414         /* Enable VDD_1V8_Cam3 */
415         if (cardhu_1v8_cam3 == NULL) {
416                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
417                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
418                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
419                                 __func__, PTR_ERR(cardhu_1v8_cam3));
420                         goto reg_alloc_fail;
421                 }
422         }
423         regulator_enable(cardhu_1v8_cam3);
424         mdelay(5);
425
426         return 0;
427
428 reg_alloc_fail:
429         if (cardhu_1v8_cam3) {
430                 regulator_put(cardhu_1v8_cam3);
431                 cardhu_1v8_cam3 = NULL;
432         }
433         if (cardhu_vdd_cam3) {
434                 regulator_put(cardhu_vdd_cam3);
435                 cardhu_vdd_cam3 = NULL;
436         }
437
438         return -ENODEV;
439 }
440
441 static int cardhu_ov2710_power_off(void)
442 {
443         /* CSI-B and front sensor are muxed on cardhu */
444         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
445
446         /* Boards E1198 and E1291 are of Cardhu personality
447          * and donot have TCA6416 exp for camera */
448         if ((board_info.board_id == BOARD_E1198) ||
449                 (board_info.board_id == BOARD_E1291)) {
450                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
451                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
452                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
453         }
454
455         if (cardhu_1v8_cam3)
456                 regulator_disable(cardhu_1v8_cam3);
457         if (cardhu_vdd_cam3)
458                 regulator_disable(cardhu_vdd_cam3);
459
460         return 0;
461 }
462
463 struct ov2710_platform_data cardhu_ov2710_data = {
464         .power_on = cardhu_ov2710_power_on,
465         .power_off = cardhu_ov2710_power_off,
466 };
467
468 static int cardhu_ov5640_power_on(void)
469 {
470         /* CSI-B and front sensor are muxed on cardhu */
471         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
472
473         /* Boards E1198 and E1291 are of Cardhu personality
474          * and donot have TCA6416 exp for camera */
475         if ((board_info.board_id == BOARD_E1198) ||
476                 (board_info.board_id == BOARD_E1291)) {
477
478                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
479                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
480                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
481                 mdelay(10);
482
483                 if (cardhu_vdd_cam3 == NULL) {
484                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
485                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
486                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
487                                         __func__, PTR_ERR(cardhu_vdd_cam3));
488                                 goto reg_alloc_fail;
489                         }
490                 }
491                 regulator_enable(cardhu_vdd_cam3);
492         }
493
494         /* Enable VDD_1V8_Cam3 */
495         if (cardhu_1v8_cam3 == NULL) {
496                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
497                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
498                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
499                                 __func__, PTR_ERR(cardhu_1v8_cam3));
500                         goto reg_alloc_fail;
501                 }
502         }
503         regulator_enable(cardhu_1v8_cam3);
504         mdelay(5);
505
506         return 0;
507
508 reg_alloc_fail:
509         if (cardhu_1v8_cam3) {
510                 regulator_put(cardhu_1v8_cam3);
511                 cardhu_1v8_cam3 = NULL;
512         }
513         if (cardhu_vdd_cam3) {
514                 regulator_put(cardhu_vdd_cam3);
515                 cardhu_vdd_cam3 = NULL;
516         }
517
518         return -ENODEV;
519 }
520
521 static int cardhu_ov5640_power_off(void)
522 {
523         /* CSI-B and front sensor are muxed on cardhu */
524         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
525
526         /* Boards E1198 and E1291 are of Cardhu personality
527          * and donot have TCA6416 exp for camera */
528         if ((board_info.board_id == BOARD_E1198) ||
529                 (board_info.board_id == BOARD_E1291)) {
530                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
531                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
532                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
533         }
534
535         if (cardhu_1v8_cam3)
536                 regulator_disable(cardhu_1v8_cam3);
537         if (cardhu_vdd_cam3)
538                 regulator_disable(cardhu_vdd_cam3);
539
540         return 0;
541 }
542
543 struct ov5640_platform_data cardhu_ov5640_data = {
544         .power_on = cardhu_ov5640_power_on,
545         .power_off = cardhu_ov5640_power_off,
546 };
547
548 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
549         {
550                 I2C_BOARD_INFO("pca9546", 0x70),
551                 .platform_data = &cardhu_pca954x_data,
552         },
553 };
554
555
556 static struct nvc_gpio_pdata sh532u_gpio_pdata[] = {
557         { SH532U_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
558 };
559
560 static struct sh532u_platform_data sh532u_left_pdata = {
561         .cfg            = NVC_CFG_NODEV,
562         .num            = 1,
563         .sync           = 2,
564         .dev_name       = "focuser",
565         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
566         .gpio           = sh532u_gpio_pdata,
567 };
568
569 static struct sh532u_platform_data sh532u_right_pdata = {
570         .cfg            = NVC_CFG_NODEV,
571         .num            = 2,
572         .sync           = 1,
573         .dev_name       = "focuser",
574         .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
575         .gpio           = sh532u_gpio_pdata,
576 };
577
578 static struct nvc_gpio_pdata pm269_sh532u_left_gpio_pdata[] = {
579         { SH532U_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
580 };
581
582 static struct sh532u_platform_data pm269_sh532u_left_pdata = {
583         .cfg            = 0,
584         .num            = 1,
585         .sync           = 2,
586         .dev_name       = "focuser",
587         .gpio_count     = ARRAY_SIZE(pm269_sh532u_left_gpio_pdata),
588         .gpio           = pm269_sh532u_left_gpio_pdata,
589 };
590
591 static struct nvc_gpio_pdata pm269_sh532u_right_gpio_pdata[] = {
592         { SH532U_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
593 };
594
595 static struct sh532u_platform_data pm269_sh532u_right_pdata = {
596         .cfg            = 0,
597         .num            = 2,
598         .sync           = 1,
599         .dev_name       = "focuser",
600         .gpio_count     = ARRAY_SIZE(pm269_sh532u_right_gpio_pdata),
601         .gpio           = pm269_sh532u_right_gpio_pdata,
602 };
603
604
605 static struct nvc_torch_pin_state cardhu_tps61050_pinstate = {
606         .mask           = 0x0008, /*VGP3*/
607         .values         = 0x0008,
608 };
609
610 static struct tps61050_platform_data cardhu_tps61050_pdata = {
611         .dev_name       = "torch",
612         .pinstate       = &cardhu_tps61050_pinstate,
613 };
614
615 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
616         {
617                 I2C_BOARD_INFO("tps61050", 0x33),
618                 .platform_data = &cardhu_tps61050_pdata,
619         },
620 };
621
622 static struct i2c_board_info cardhu_i2c6_board_info[] = {
623         {
624                 I2C_BOARD_INFO("ov5650L", 0x36),
625                 .platform_data = &cardhu_left_ov5650_data,
626         },
627         {
628                 I2C_BOARD_INFO("sh532u", 0x72),
629                 .platform_data = &sh532u_left_pdata,
630         },
631 };
632
633 static struct i2c_board_info cardhu_i2c7_board_info[] = {
634         {
635                 I2C_BOARD_INFO("ov5650R", 0x36),
636                 .platform_data = &cardhu_right_ov5650_data,
637         },
638         {
639                 I2C_BOARD_INFO("sh532u", 0x72),
640                 .platform_data = &sh532u_right_pdata,
641         },
642 };
643
644 static struct i2c_board_info pm269_i2c6_board_info[] = {
645         {
646                 I2C_BOARD_INFO("ov5650L", 0x36),
647                 .platform_data = &cardhu_left_ov5650_data,
648         },
649         {
650                 I2C_BOARD_INFO("sh532u", 0x72),
651                 .platform_data = &pm269_sh532u_left_pdata,
652         },
653 };
654
655 static struct i2c_board_info pm269_i2c7_board_info[] = {
656         {
657                 I2C_BOARD_INFO("ov5650R", 0x36),
658                 .platform_data = &cardhu_right_ov5650_data,
659         },
660         {
661                 I2C_BOARD_INFO("sh532u", 0x72),
662                 .platform_data = &pm269_sh532u_right_pdata,
663         },
664 };
665
666 static struct i2c_board_info cardhu_i2c8_board_info[] = {
667         {
668                 I2C_BOARD_INFO("ov2710", 0x36),
669                 .platform_data = &cardhu_ov2710_data,
670         },
671         {
672                 I2C_BOARD_INFO("ov5640", 0x3C),
673                 .platform_data = &cardhu_ov5640_data,
674         },
675 };
676
677 static int nct_get_temp(void *_data, long *temp)
678 {
679         struct nct1008_data *data = _data;
680         return nct1008_thermal_get_temp(data, temp);
681 }
682
683 static int nct_get_temp_low(void *_data, long *temp)
684 {
685         struct nct1008_data *data = _data;
686         return nct1008_thermal_get_temp_low(data, temp);
687 }
688
689 static int nct_set_limits(void *_data,
690                         long lo_limit_milli,
691                         long hi_limit_milli)
692 {
693         struct nct1008_data *data = _data;
694         return nct1008_thermal_set_limits(data,
695                                         lo_limit_milli,
696                                         hi_limit_milli);
697 }
698
699 static int nct_set_alert(void *_data,
700                                 void (*alert_func)(void *),
701                                 void *alert_data)
702 {
703         struct nct1008_data *data = _data;
704         return nct1008_thermal_set_alert(data, alert_func, alert_data);
705 }
706
707 static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
708 {
709         struct nct1008_data *data = _data;
710         return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
711 }
712
713 static void nct1008_probe_callback(struct nct1008_data *data)
714 {
715         struct tegra_thermal_device *thermal_device;
716
717         thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
718                                         GFP_KERNEL);
719         if (!thermal_device) {
720                 pr_err("unable to allocate thermal device\n");
721                 return;
722         }
723
724         thermal_device->name = "nct1008";
725         thermal_device->data = data;
726         thermal_device->offset = TDIODE_OFFSET;
727         thermal_device->get_temp = nct_get_temp;
728         thermal_device->get_temp_low = nct_get_temp_low;
729         thermal_device->set_limits = nct_set_limits;
730         thermal_device->set_alert = nct_set_alert;
731         thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
732
733         tegra_thermal_set_device(thermal_device);
734 }
735
736 static struct nct1008_platform_data cardhu_nct1008_pdata = {
737         .supported_hwrev = true,
738         .ext_range = true,
739         .conv_rate = 0x08,
740         .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
741         .probe_callback = nct1008_probe_callback,
742 };
743
744 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
745         {
746                 I2C_BOARD_INFO("bq27510", 0x55),
747         },
748 };
749
750 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
751         {
752                 I2C_BOARD_INFO("nct1008", 0x4C),
753                 .platform_data = &cardhu_nct1008_pdata,
754                 .irq = -1,
755         }
756 };
757
758 static int cardhu_nct1008_init(void)
759 {
760         int nct1008_port = -1;
761         int ret = 0;
762
763         if ((board_info.board_id == BOARD_E1198) ||
764                 (board_info.board_id == BOARD_E1291) ||
765                 (board_info.board_id == BOARD_E1257) ||
766                 (board_info.board_id == BOARD_PM269) ||
767                 (board_info.board_id == BOARD_PM305) ||
768                 (board_info.board_id == BOARD_PM311)) {
769                 nct1008_port = TEGRA_GPIO_PCC2;
770         } else if ((board_info.board_id == BOARD_E1186) ||
771                 (board_info.board_id == BOARD_E1187) ||
772                 (board_info.board_id == BOARD_E1256)) {
773                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
774                 /* nct1008_port = TEGRA_GPIO_PH7; */
775         }
776
777         if (nct1008_port >= 0) {
778                 /* FIXME: enable irq when throttling is supported */
779                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
780
781                 ret = gpio_request(nct1008_port, "temp_alert");
782                 if (ret < 0)
783                         return ret;
784
785                 ret = gpio_direction_input(nct1008_port);
786                 if (ret < 0)
787                         gpio_free(nct1008_port);
788                 else
789                         tegra_gpio_enable(nct1008_port);
790         }
791
792         return ret;
793 }
794
795 #if defined(CONFIG_GPIO_PCA953X)
796 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
797         .gpio_base      = PMU_TCA6416_GPIO_BASE,
798 };
799
800 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
801         {
802                 I2C_BOARD_INFO("tca6416", 0x20),
803                 .platform_data = &cardhu_pmu_tca6416_data,
804         },
805 };
806
807 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
808         .gpio_base      = CAM_TCA6416_GPIO_BASE,
809 };
810
811 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
812         {
813                 I2C_BOARD_INFO("tca6416", 0x20),
814                 .platform_data = &cardhu_cam_tca6416_data,
815         },
816 };
817
818 static int __init pmu_tca6416_init(void)
819 {
820         if ((board_info.board_id == BOARD_E1198) ||
821                 (board_info.board_id == BOARD_E1291))
822                         return 0;
823
824         pr_info("Registering pmu pca6416\n");
825         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
826                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
827         return 0;
828 }
829
830 static int __init cam_tca6416_init(void)
831 {
832         /* Boards E1198 and E1291 are of Cardhu personality
833          * and donot have TCA6416 exp for camera */
834         if ((board_info.board_id == BOARD_E1198) ||
835                 (board_info.board_id == BOARD_E1291))
836                 return 0;
837
838         pr_info("Registering cam pca6416\n");
839         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
840                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
841         return 0;
842 }
843 #else
844 static int __init pmu_tca6416_init(void)
845 {
846         return 0;
847 }
848
849 static int __init cam_tca6416_init(void)
850 {
851         return 0;
852 }
853 #endif
854
855 /* MPU board file definition    */
856 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
857 #define MPU_GYRO_NAME           "mpu3050"
858 #endif
859 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU6050)
860 #define MPU_GYRO_NAME           "mpu6050"
861 #endif
862 static struct mpu_platform_data mpu_gyro_data = {
863         .int_config     = 0x10,
864         .level_shifter  = 0,
865         .orientation    = MPU_GYRO_ORIENTATION, /* Located in board_[platformname].h    */
866 };
867
868 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
869 static struct ext_slave_platform_data mpu_accel_data = {
870         .address        = MPU_ACCEL_ADDR,
871         .irq            = 0,
872         .adapt_num      = MPU_ACCEL_BUS_NUM,
873         .bus            = EXT_SLAVE_BUS_SECONDARY,
874         .orientation    = MPU_ACCEL_ORIENTATION,        /* Located in board_[platformname].h    */
875 };
876 #endif
877
878 static struct ext_slave_platform_data mpu_compass_data = {
879         .address        = MPU_COMPASS_ADDR,
880         .irq            = 0,
881         .adapt_num      = MPU_COMPASS_BUS_NUM,
882         .bus            = EXT_SLAVE_BUS_PRIMARY,
883         .orientation    = MPU_COMPASS_ORIENTATION,      /* Located in board_[platformname].h    */
884 };
885
886 static struct i2c_board_info __initdata inv_mpu_i2c2_board_info[] = {
887         {
888                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
889                 .irq = TEGRA_GPIO_TO_IRQ(MPU_GYRO_IRQ_GPIO),
890                 .platform_data = &mpu_gyro_data,
891         },
892 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
893         {
894                 I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR),
895 #if     MPU_ACCEL_IRQ_GPIO
896                 .irq = TEGRA_GPIO_TO_IRQ(MPU_ACCEL_IRQ_GPIO),
897 #endif
898                 .platform_data = &mpu_accel_data,
899         },
900 #endif
901         {
902                 I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
903 #if     MPU_COMPASS_IRQ_GPIO
904                 .irq = TEGRA_GPIO_TO_IRQ(MPU_COMPASS_IRQ_GPIO),
905 #endif
906                 .platform_data = &mpu_compass_data,
907         },
908 };
909
910 static void mpuirq_init(void)
911 {
912         int ret = 0;
913
914         pr_info("*** MPU START *** mpuirq_init...\n");
915
916 #if (MPU_GYRO_TYPE == MPU_TYPE_MPU3050)
917 #if     MPU_ACCEL_IRQ_GPIO
918         /* ACCEL-IRQ assignment */
919         tegra_gpio_enable(MPU_ACCEL_IRQ_GPIO);
920         ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME);
921         if (ret < 0) {
922                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
923                 return;
924         }
925
926         ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO);
927         if (ret < 0) {
928                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
929                 gpio_free(MPU_ACCEL_IRQ_GPIO);
930                 return;
931         }
932 #endif
933 #endif
934
935         /* MPU-IRQ assignment */
936         tegra_gpio_enable(MPU_GYRO_IRQ_GPIO);
937         ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
938         if (ret < 0) {
939                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
940                 return;
941         }
942
943         ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
944         if (ret < 0) {
945                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
946                 gpio_free(MPU_GYRO_IRQ_GPIO);
947                 return;
948         }
949         pr_info("*** MPU END *** mpuirq_init...\n");
950
951         i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c2_board_info,
952                 ARRAY_SIZE(inv_mpu_i2c2_board_info));
953 }
954
955 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
956         {
957                 I2C_BOARD_INFO("isl29028", 0x44),
958         }
959 };
960
961 static struct i2c_board_info cardhu_i2c2_ltr_board_info[] = {
962         {
963                 I2C_BOARD_INFO("LTR_558ALS", 0x23),
964         }
965 };
966
967 int __init cardhu_sensors_init(void)
968 {
969         int err;
970
971         tegra_get_board_info(&board_info);
972
973         cardhu_camera_init();
974         cam_tca6416_init();
975
976         i2c_register_board_info(2, cardhu_i2c3_board_info,
977                 ARRAY_SIZE(cardhu_i2c3_board_info));
978
979         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
980                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
981
982 #ifdef CONFIG_VIDEO_OV14810
983         /* This is disabled by default; To enable this change Kconfig;
984          * there should be some way to detect dynamically which board
985          * is connected (E1211/E1214), till that time sensor selection
986          * logic is static;
987          * e1214 corresponds to ov14810 sensor */
988         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
989                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
990 #else
991         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
992          * Front camera is on BUS2 */
993         if (board_info.board_id != BOARD_PM269) {
994                 i2c_register_board_info(PCA954x_I2C_BUS0,
995                                         cardhu_i2c6_board_info,
996                                         ARRAY_SIZE(cardhu_i2c6_board_info));
997
998                 i2c_register_board_info(PCA954x_I2C_BUS1,
999                                         cardhu_i2c7_board_info,
1000                                         ARRAY_SIZE(cardhu_i2c7_board_info));
1001         } else {
1002                 i2c_register_board_info(PCA954x_I2C_BUS0,
1003                                         pm269_i2c6_board_info,
1004                                         ARRAY_SIZE(pm269_i2c6_board_info));
1005
1006                 i2c_register_board_info(PCA954x_I2C_BUS1,
1007                                         pm269_i2c7_board_info,
1008                                         ARRAY_SIZE(pm269_i2c7_board_info));
1009         }
1010         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
1011                 ARRAY_SIZE(cardhu_i2c8_board_info));
1012
1013 #endif
1014         pmu_tca6416_init();
1015
1016         if (board_info.board_id == BOARD_E1291)
1017                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
1018                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
1019
1020         if (board_info.sku == BOARD_SKU_B11)
1021                 i2c_register_board_info(2, cardhu_i2c2_ltr_board_info,
1022                         ARRAY_SIZE(cardhu_i2c2_ltr_board_info));
1023         else
1024                 i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
1025                         ARRAY_SIZE(cardhu_i2c2_isl_board_info));
1026
1027         err = cardhu_nct1008_init();
1028         if (err)
1029                 return err;
1030
1031         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
1032                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
1033
1034         mpuirq_init();
1035         return 0;
1036 }
1037
1038 #if defined(CONFIG_GPIO_PCA953X)
1039 struct ov5650_gpios {
1040         const char *name;
1041         int gpio;
1042         int enabled;
1043 };
1044
1045 #define OV5650_GPIO(_name, _gpio, _enabled)             \
1046         {                                               \
1047                 .name = _name,                          \
1048                 .gpio = _gpio,                          \
1049                 .enabled = _enabled,                    \
1050         }
1051
1052 static struct ov5650_gpios ov5650_gpio_keys[] = {
1053         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
1054         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
1055         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
1056         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
1057         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
1058         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
1059         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
1060         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
1061         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
1062         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
1063         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
1064         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
1065         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
1066         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
1067         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
1068 };
1069
1070 int __init cardhu_ov5650_late_init(void)
1071 {
1072         int ret;
1073         int i;
1074
1075         if (!machine_is_cardhu())
1076                 return 0;
1077
1078         if ((board_info.board_id == BOARD_E1198) ||
1079                 (board_info.board_id == BOARD_E1291))
1080                 return 0;
1081
1082         printk("%s: \n", __func__);
1083         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
1084                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
1085                         ov5650_gpio_keys[i].name);
1086                 if (ret < 0) {
1087                         printk("%s: gpio_request failed for gpio #%d\n",
1088                                 __func__, i);
1089                         goto fail;
1090                 }
1091                 printk("%s: enable - %d\n", __func__, i);
1092                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
1093                         ov5650_gpio_keys[i].enabled);
1094                 gpio_export(ov5650_gpio_keys[i].gpio, false);
1095         }
1096
1097         return 0;
1098
1099 fail:
1100         while (i--)
1101                 gpio_free(ov5650_gpio_keys[i].gpio);
1102         return ret;
1103 }
1104
1105 late_initcall(cardhu_ov5650_late_init);
1106 #endif