arm: tegra: cardhu: sh532u board support
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-sensors.c
3  *
4  * Copyright (c) 2010-2011, NVIDIA CORPORATION, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * Neither the name of NVIDIA CORPORATION nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
23  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
24  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
27  * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #include <linux/i2c.h>
35 #include <linux/delay.h>
36 #include <linux/regulator/consumer.h>
37 #include <linux/i2c/pca954x.h>
38 #include <linux/i2c/pca953x.h>
39 #include <linux/nct1008.h>
40 #include <mach/fb.h>
41 #include <mach/gpio.h>
42 #include <media/ov5650.h>
43 #include <media/ov14810.h>
44 #include <media/ov2710.h>
45 #include <media/tps61050.h>
46 #include <generated/mach-types.h>
47 #include "gpio-names.h"
48 #include "board.h"
49 #include <linux/mpu.h>
50 #include <media/sh532u.h>
51 #include <linux/bq27x00.h>
52 #include <mach/gpio.h>
53 #include <mach/edp.h>
54
55 #include "gpio-names.h"
56 #include "board-cardhu.h"
57 #include "cpu-tegra.h"
58
59 static struct regulator *cardhu_1v8_cam1 = NULL;
60 static struct regulator *cardhu_1v8_cam2 = NULL;
61 static struct regulator *cardhu_1v8_cam3 = NULL;
62 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
63 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
64 static struct regulator *cardhu_vdd_cam3 = NULL;
65
66 static struct board_info board_info;
67
68 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
69         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
70         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
71         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
72         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
73 };
74
75 static struct pca954x_platform_data cardhu_pca954x_data = {
76         .modes    = cardhu_pca954x_modes,
77         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
78 };
79
80 static int cardhu_camera_init(void)
81 {
82         int ret;
83
84         /* Boards E1198 and E1291 are of Cardhu personality
85          * and donot have TCA6416 exp for camera */
86         if ((board_info.board_id == BOARD_E1198) ||
87                 (board_info.board_id == BOARD_E1291)) {
88                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
89                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
90                 if (ret < 0)
91                         pr_err("%s: gpio_request failed for gpio %s\n",
92                                 __func__, "CAM1_POWER_DWN_GPIO");
93                                 tegra_gpio_enable(CAM3_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                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
100                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
101                 if (ret < 0)
102                         pr_err("%s: gpio_request failed for gpio %s\n",
103                                 __func__, "CAM2_POWER_DWN_GPIO");
104
105                 tegra_gpio_enable(OV5650_RESETN_GPIO);
106                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
107                 if (ret < 0)
108                         pr_err("%s: gpio_request failed for gpio %s\n",
109                                 __func__, "OV5650_RESETN_GPIO");
110
111                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
112                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
113                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
114                 mdelay(10);
115
116                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
117                 mdelay(5);
118                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
119                 mdelay(5);
120                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
121                 mdelay(5);
122         }
123
124         /* To select the CSIB MUX either for cam2 or cam3 */
125         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
126         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
127         if (ret < 0)
128                 pr_err("%s: gpio_request failed for gpio %s\n",
129                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
130         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
131         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
132
133         return 0;
134 }
135
136 static int cardhu_left_ov5650_power_on(void)
137 {
138         /* Boards E1198 and E1291 are of Cardhu personality
139          * and donot have TCA6416 exp for camera */
140         if ((board_info.board_id == BOARD_E1198) ||
141                 (board_info.board_id == BOARD_E1291)) {
142
143                 if (cardhu_vdd_2v8_cam1 == NULL) {
144                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
145                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
146                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
147                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
148                                 goto reg_alloc_fail;
149                         }
150                 }
151                 regulator_enable(cardhu_vdd_2v8_cam1);
152                 mdelay(5);
153         }
154
155         /* Enable VDD_1V8_Cam1 */
156         if (cardhu_1v8_cam1 == NULL) {
157                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
158                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
159                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
160                                 __func__, PTR_ERR(cardhu_1v8_cam1));
161                         goto reg_alloc_fail;
162                 }
163         }
164         regulator_enable(cardhu_1v8_cam1);
165
166         mdelay(5);
167         if ((board_info.board_id == BOARD_E1198) ||
168                 (board_info.board_id == BOARD_E1291)) {
169                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
170                 mdelay(20);
171                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
172                 mdelay(100);
173                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
174         }
175
176         if (board_info.board_id == BOARD_PM269) {
177                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
178                 mdelay(100);
179                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
180         }
181
182         return 0;
183
184 reg_alloc_fail:
185         if (cardhu_1v8_cam1) {
186                 regulator_put(cardhu_1v8_cam1);
187                 cardhu_1v8_cam1 = NULL;
188         }
189         if (cardhu_vdd_2v8_cam1) {
190                 regulator_put(cardhu_vdd_2v8_cam1);
191                 cardhu_vdd_2v8_cam1 = NULL;
192         }
193
194         return -ENODEV;
195
196 }
197
198 static int cardhu_left_ov5650_power_off(void)
199 {
200         /* Boards E1198 and E1291 are of Cardhu personality
201          * and donot have TCA6416 exp for camera */
202         if ((board_info.board_id == BOARD_E1198) ||
203                 (board_info.board_id == BOARD_E1291)) {
204                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
205                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
206                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
207         }
208         if (cardhu_1v8_cam1)
209                 regulator_disable(cardhu_1v8_cam1);
210         if (cardhu_vdd_2v8_cam1)
211                 regulator_disable(cardhu_vdd_2v8_cam1);
212
213         return 0;
214 }
215
216 struct ov5650_platform_data cardhu_left_ov5650_data = {
217         .power_on = cardhu_left_ov5650_power_on,
218         .power_off = cardhu_left_ov5650_power_off,
219 };
220
221 #ifdef CONFIG_VIDEO_OV14810
222 static int cardhu_ov14810_power_on(void)
223 {
224         if (board_info.board_id == BOARD_E1198) {
225                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
226                 mdelay(20);
227                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
228                 mdelay(100);
229                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
230         }
231
232         return 0;
233 }
234
235 static int cardhu_ov14810_power_off(void)
236 {
237         if (board_info.board_id == BOARD_E1198) {
238                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
239                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
240                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
241         }
242
243         return 0;
244 }
245
246 struct ov14810_platform_data cardhu_ov14810_data = {
247         .power_on = cardhu_ov14810_power_on,
248         .power_off = cardhu_ov14810_power_off,
249 };
250
251 struct ov14810_platform_data cardhu_ov14810uC_data = {
252         .power_on = NULL,
253         .power_off = NULL,
254 };
255
256 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
257         .power_on = NULL,
258         .power_off = NULL,
259 };
260
261 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
262         {
263                 I2C_BOARD_INFO("ov14810", 0x36),
264                 .platform_data = &cardhu_ov14810_data,
265         },
266         {
267                 I2C_BOARD_INFO("ov14810uC", 0x67),
268                 .platform_data = &cardhu_ov14810uC_data,
269         },
270         {
271                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
272                 .platform_data = &cardhu_ov14810SlaveDev_data,
273         }
274 };
275 #endif
276
277 static int cardhu_right_ov5650_power_on(void)
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         /* Boards E1198 and E1291 are of Cardhu personality
338          * and donot have TCA6416 exp for camera */
339         if ((board_info.board_id == BOARD_E1198) ||
340                 (board_info.board_id == BOARD_E1291)) {
341                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
342                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
343                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
344         }
345
346         if (cardhu_1v8_cam2)
347                 regulator_disable(cardhu_1v8_cam2);
348         if (cardhu_vdd_2v8_cam2)
349                 regulator_disable(cardhu_vdd_2v8_cam2);
350
351         return 0;
352 }
353
354 static void cardhu_ov5650_synchronize_sensors(void)
355 {
356         if (board_info.board_id == BOARD_E1198) {
357                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
358                 mdelay(50);
359                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
360                 mdelay(50);
361         }
362         else if (board_info.board_id == BOARD_E1291) {
363                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
364                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
365                 mdelay(50);
366                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
367                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
368                 mdelay(50);
369         }
370         else
371                 pr_err("%s: UnSupported BoardId\n", __func__);
372 }
373
374 struct ov5650_platform_data cardhu_right_ov5650_data = {
375         .power_on = cardhu_right_ov5650_power_on,
376         .power_off = cardhu_right_ov5650_power_off,
377         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
378 };
379
380 static int cardhu_ov2710_power_on(void)
381 {
382         /* CSI-B and front sensor are muxed on verbier */
383         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
384
385         /* Boards E1198 and E1291 are of Cardhu personality
386          * and donot have TCA6416 exp for camera */
387         if ((board_info.board_id == BOARD_E1198) ||
388                 (board_info.board_id == BOARD_E1291)) {
389
390                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
391                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
392                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
393                 mdelay(10);
394
395                 if (cardhu_vdd_cam3 == NULL) {
396                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
397                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
398                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
399                                         __func__, PTR_ERR(cardhu_vdd_cam3));
400                                 goto reg_alloc_fail;
401                         }
402                 }
403                 regulator_enable(cardhu_vdd_cam3);
404         }
405
406         /* Enable VDD_1V8_Cam3 */
407         if (cardhu_1v8_cam3 == NULL) {
408                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
409                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
410                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
411                                 __func__, PTR_ERR(cardhu_1v8_cam3));
412                         goto reg_alloc_fail;
413                 }
414         }
415         regulator_enable(cardhu_1v8_cam3);
416         mdelay(5);
417
418         return 0;
419
420 reg_alloc_fail:
421         if (cardhu_1v8_cam3) {
422                 regulator_put(cardhu_1v8_cam3);
423                 cardhu_1v8_cam3 = NULL;
424         }
425         if (cardhu_vdd_cam3) {
426                 regulator_put(cardhu_vdd_cam3);
427                 cardhu_vdd_cam3 = NULL;
428         }
429
430         return -ENODEV;
431 }
432
433 static int cardhu_ov2710_power_off(void)
434 {
435         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
436
437         /* Boards E1198 and E1291 are of Cardhu personality
438          * and donot have TCA6416 exp for camera */
439         if ((board_info.board_id == BOARD_E1198) ||
440                 (board_info.board_id == BOARD_E1291)) {
441                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
442                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
443                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
444         }
445
446         if (cardhu_1v8_cam3)
447                 regulator_disable(cardhu_1v8_cam3);
448         if (cardhu_vdd_cam3)
449                 regulator_disable(cardhu_vdd_cam3);
450
451         return 0;
452 }
453
454 struct ov2710_platform_data cardhu_ov2710_data = {
455         .power_on = cardhu_ov2710_power_on,
456         .power_off = cardhu_ov2710_power_off,
457 };
458
459 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
460         {
461                 I2C_BOARD_INFO("pca9546", 0x70),
462                 .platform_data = &cardhu_pca954x_data,
463         },
464 };
465
466 static struct sh532u_platform_data sh532u_left_pdata = {
467         .num            = 1,
468         .sync           = 2,
469         .dev_name       = "focuser",
470         .gpio_reset     = TEGRA_GPIO_PBB0,
471 };
472
473 static struct sh532u_platform_data sh532u_right_pdata = {
474         .num            = 2,
475         .sync           = 1,
476         .dev_name       = "focuser",
477         .gpio_reset     = TEGRA_GPIO_PBB0,
478 };
479
480 static bool cardhu_tps61050_pm_flag = 0;
481
482 static struct tps61050_pin_state cardhu_tps61050_pinstate = {
483         .mask           = 0x0008, /*VGP3*/
484         .values         = 0x0008,
485 };
486
487 static int cardhu_tps61050_pm(int pwr)
488 {
489         switch (pwr) {
490         case TPS61050_PWR_OFF:
491                 if (cardhu_tps61050_pm_flag && cardhu_1v8_cam1) {
492                         regulator_disable(cardhu_1v8_cam1);
493                         cardhu_tps61050_pm_flag = 0;
494                 }
495                 return 0;
496
497         case TPS61050_PWR_STDBY:
498         case TPS61050_PWR_COMM:
499         case TPS61050_PWR_ON:
500                 if (!cardhu_tps61050_pm_flag) {
501                         if (cardhu_1v8_cam1 == NULL) {
502                                 cardhu_1v8_cam1 =
503                                         regulator_get(NULL, "vdd_1v8_cam1");
504                                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
505                                         pr_err("%s: err: %ld\n",
506                                                 __func__,
507                                                 PTR_ERR(cardhu_1v8_cam1));
508                                         regulator_put(cardhu_1v8_cam1);
509                                         cardhu_1v8_cam1 = NULL;
510                                 }
511                         }
512                         regulator_enable(cardhu_1v8_cam1);
513                         cardhu_tps61050_pm_flag = 1;
514                         mdelay(5);
515                 }
516                 return 0;
517
518         default:
519                 return -1;
520         }
521 }
522
523 static struct tps61050_platform_data cardhu_tps61050_data = {
524         .cfg            = 0,
525         .num            = 1,
526         .max_amp_torch  = CAMERA_FLASH_MAX_TORCH_AMP,
527         .max_amp_flash  = CAMERA_FLASH_MAX_FLASH_AMP,
528         .pinstate       = &cardhu_tps61050_pinstate,
529         .init           = NULL,
530         .exit           = NULL,
531         .pm             = cardhu_tps61050_pm,
532         .gpio_envm      = NULL,
533         .gpio_sync      = NULL,
534 };
535
536 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
537         {
538                 I2C_BOARD_INFO("tps61050", 0x33),
539                 .platform_data = &cardhu_tps61050_data,
540         },
541 };
542
543 static struct i2c_board_info cardhu_i2c6_board_info[] = {
544         {
545                 I2C_BOARD_INFO("ov5650L", 0x36),
546                 .platform_data = &cardhu_left_ov5650_data,
547         },
548         {
549                 I2C_BOARD_INFO("sh532u", 0x72),
550                 .platform_data = &sh532u_left_pdata,
551         },
552 };
553
554 static struct i2c_board_info cardhu_i2c7_board_info[] = {
555         {
556                 I2C_BOARD_INFO("ov5650R", 0x36),
557                 .platform_data = &cardhu_right_ov5650_data,
558         },
559         {
560                 I2C_BOARD_INFO("sh532u", 0x72),
561                 .platform_data = &sh532u_right_pdata,
562         },
563 };
564
565 static struct i2c_board_info cardhu_i2c8_board_info[] = {
566         {
567                 I2C_BOARD_INFO("ov2710", 0x36),
568                 .platform_data = &cardhu_ov2710_data,
569         },
570 };
571
572 static struct nct1008_platform_data cardhu_nct1008_pdata = {
573         .supported_hwrev = true,
574         .ext_range = true,
575         .conv_rate = 0x08,
576         .hysteresis = 5,
577         .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
578         .shutdown_ext_limit = 90,
579         .shutdown_local_limit = 90,
580         .throttling_ext_limit = 85,
581         .alarm_fn = tegra_throttling_enable,
582 };
583
584 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
585         {
586                 I2C_BOARD_INFO("bq27510", 0x55),
587         },
588 };
589
590 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
591         {
592                 I2C_BOARD_INFO("nct1008", 0x4C),
593                 .platform_data = &cardhu_nct1008_pdata,
594                 .irq = -1,
595         }
596 };
597
598
599 static int cardhu_nct1008_init(void)
600 {
601         int nct1008_port = -1;
602         int ret;
603 #ifdef CONFIG_TEGRA_EDP_LIMITS
604         const struct tegra_edp_limits *z;
605         int zones_sz;
606         int i;
607         bool throttle_ok = false;
608 #endif
609
610         if ((board_info.board_id == BOARD_E1198) ||
611                 (board_info.board_id == BOARD_E1291) ||
612                 (board_info.board_id == BOARD_E1257) ||
613                 (board_info.board_id == BOARD_PM269) ||
614                 (board_info.board_id == BOARD_PM305) ||
615                 (board_info.board_id == BOARD_PM311)) {
616                 nct1008_port = TEGRA_GPIO_PCC2;
617         } else if ((board_info.board_id == BOARD_E1186) ||
618                 (board_info.board_id == BOARD_E1187) ||
619                 (board_info.board_id == BOARD_E1256)) {
620                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
621                 /* nct1008_port = TEGRA_GPIO_PH7; */
622         }
623
624         if (nct1008_port >= 0) {
625                 /* FIXME: enable irq when throttling is supported */
626                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
627
628                 ret = gpio_request(nct1008_port, "temp_alert");
629                 if (ret < 0)
630                         return ret;
631
632                 ret = gpio_direction_input(nct1008_port);
633                 if (ret < 0)
634                         gpio_free(nct1008_port);
635                 else
636                         tegra_gpio_enable(nct1008_port);
637         }
638
639 #ifdef CONFIG_TEGRA_EDP_LIMITS
640         tegra_get_cpu_edp_limits(&z, &zones_sz);
641         zones_sz = min(zones_sz, MAX_ZONES);
642         for (i = 0; i < zones_sz; i++) {
643                 cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
644                 if (cardhu_nct1008_pdata.thermal_zones[i] ==
645                     cardhu_nct1008_pdata.throttling_ext_limit) {
646                         throttle_ok = true;
647                 }
648         }
649
650         if (throttle_ok != true)
651                 pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
652                         " as it is NOT one of the EDP points\n",
653                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
654         else
655                 pr_info("%s: Throttling limit %dC OK\n",
656                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
657
658         cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
659 #endif
660         return ret;
661 }
662
663 #if defined(CONFIG_GPIO_PCA953X)
664 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
665         .gpio_base      = PMU_TCA6416_GPIO_BASE,
666 };
667
668 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
669         {
670                 I2C_BOARD_INFO("tca6416", 0x20),
671                 .platform_data = &cardhu_pmu_tca6416_data,
672         },
673 };
674
675 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
676         .gpio_base      = CAM_TCA6416_GPIO_BASE,
677 };
678
679 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
680         {
681                 I2C_BOARD_INFO("tca6416", 0x20),
682                 .platform_data = &cardhu_cam_tca6416_data,
683         },
684 };
685
686 static int __init pmu_tca6416_init(void)
687 {
688         if ((board_info.board_id == BOARD_E1198) ||
689                 (board_info.board_id == BOARD_E1291))
690                         return 0;
691
692         pr_info("Registering pmu pca6416\n");
693         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
694                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
695         return 0;
696 }
697
698 static int __init cam_tca6416_init(void)
699 {
700         /* Boards E1198 and E1291 are of Cardhu personality
701          * and donot have TCA6416 exp for camera */
702         if ((board_info.board_id == BOARD_E1198) ||
703                 (board_info.board_id == BOARD_E1291))
704                 return 0;
705
706         pr_info("Registering cam pca6416\n");
707         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
708                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
709         return 0;
710 }
711 #else
712 static int __init pmu_tca6416_init(void)
713 {
714         return 0;
715 }
716
717 static int __init cam_tca6416_init(void)
718 {
719         return 0;
720 }
721 #endif
722
723 #ifdef CONFIG_MPU_SENSORS_MPU3050
724 #define SENSOR_MPU_NAME "mpu3050"
725 static struct mpu3050_platform_data mpu3050_data = {
726         .int_config  = 0x10,
727         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
728         .level_shifter = 0,
729
730         .accel = {
731         .get_slave_descr = get_accel_slave_descr,
732         .adapt_num   = 2,
733         .bus         = EXT_SLAVE_BUS_SECONDARY,
734         .address     = 0x0F,
735         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
736         },
737
738         .compass = {
739         .get_slave_descr = get_compass_slave_descr,
740         .adapt_num   = 2,
741         .bus         = EXT_SLAVE_BUS_PRIMARY,
742         .address     = 0x0C,
743         .orientation = { 1, 0, 0, 0, 1, 0, 0, 0, 1 },  /* Orientation matrix for AKM on cardhu */
744         },
745 };
746
747 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
748         {
749                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
750                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
751                 .platform_data = &mpu3050_data,
752         },
753 };
754
755 static void cardhu_mpuirq_init(void)
756 {
757         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
758         tegra_gpio_enable(TEGRA_GPIO_PX1);
759         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
760         gpio_direction_input(TEGRA_GPIO_PX1);
761         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
762
763         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
764                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
765 }
766 #endif
767
768
769 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
770         {
771                 I2C_BOARD_INFO("isl29028", 0x44),
772         }
773 };
774
775 int __init cardhu_sensors_init(void)
776 {
777         int err;
778
779         tegra_get_board_info(&board_info);
780
781         cardhu_camera_init();
782         cam_tca6416_init();
783
784         i2c_register_board_info(2, cardhu_i2c3_board_info,
785                 ARRAY_SIZE(cardhu_i2c3_board_info));
786
787         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
788                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
789
790 #ifdef CONFIG_VIDEO_OV14810
791         /* This is disabled by default; To enable this change Kconfig;
792          * there should be some way to detect dynamically which board
793          * is connected (E1211/E1214), till that time sensor selection
794          * logic is static;
795          * e1214 corresponds to ov14810 sensor */
796         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
797                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
798 #else
799         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
800          * Front camera is on BUS2 */
801         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
802                 ARRAY_SIZE(cardhu_i2c6_board_info));
803
804         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
805                 ARRAY_SIZE(cardhu_i2c7_board_info));
806
807         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
808                 ARRAY_SIZE(cardhu_i2c8_board_info));
809
810 #endif
811         pmu_tca6416_init();
812
813         if (board_info.board_id == BOARD_E1291)
814                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
815                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
816
817         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
818                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
819
820         err = cardhu_nct1008_init();
821         if (err)
822                 return err;
823
824         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
825                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
826
827 #ifdef CONFIG_MPU_SENSORS_MPU3050
828         cardhu_mpuirq_init();
829 #endif
830         return 0;
831 }
832
833 #if defined(CONFIG_GPIO_PCA953X)
834 struct ov5650_gpios {
835         const char *name;
836         int gpio;
837         int enabled;
838 };
839
840 #define OV5650_GPIO(_name, _gpio, _enabled)             \
841         {                                               \
842                 .name = _name,                          \
843                 .gpio = _gpio,                          \
844                 .enabled = _enabled,                    \
845         }
846
847 static struct ov5650_gpios ov5650_gpio_keys[] = {
848         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
849         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
850         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
851         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
852         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
853         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
854         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
855         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
856         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
857         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
858         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
859         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
860         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
861         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
862         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
863 };
864
865 int __init cardhu_ov5650_late_init(void)
866 {
867         int ret;
868         int i;
869
870         if (!machine_is_cardhu())
871                 return 0;
872
873         if ((board_info.board_id == BOARD_E1198) ||
874                 (board_info.board_id == BOARD_E1291))
875                 return 0;
876
877         printk("%s: \n", __func__);
878         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
879                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
880                         ov5650_gpio_keys[i].name);
881                 if (ret < 0) {
882                         printk("%s: gpio_request failed for gpio #%d\n",
883                                 __func__, i);
884                         goto fail;
885                 }
886                 printk("%s: enable - %d\n", __func__, i);
887                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
888                         ov5650_gpio_keys[i].enabled);
889                 gpio_export(ov5650_gpio_keys[i].gpio, false);
890         }
891
892         return 0;
893
894 fail:
895         while (i--)
896                 gpio_free(ov5650_gpio_keys[i].gpio);
897         return ret;
898 }
899
900 late_initcall(cardhu_ov5650_late_init);
901 #endif