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