Ventana: KBC: Removing the KBC usage on ventana
[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
175         if (board_info.board_id == BOARD_PM269) {
176                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
177                 mdelay(100);
178                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
179         }
180
181         return 0;
182
183 reg_alloc_fail:
184         if (cardhu_1v8_cam1) {
185                 regulator_put(cardhu_1v8_cam1);
186                 cardhu_1v8_cam1 = NULL;
187         }
188         if (cardhu_vdd_2v8_cam1) {
189                 regulator_put(cardhu_vdd_2v8_cam1);
190                 cardhu_vdd_2v8_cam1 = NULL;
191         }
192
193         return -ENODEV;
194
195 }
196
197 static int cardhu_left_ov5650_power_off(void)
198 {
199         /* Boards E1198 and E1291 are of Cardhu personality
200          * and donot have TCA6416 exp for camera */
201         if ((board_info.board_id == BOARD_E1198) ||
202                 (board_info.board_id == BOARD_E1291)) {
203                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
204                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
205                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
206         }
207         if (cardhu_1v8_cam1)
208                 regulator_disable(cardhu_1v8_cam1);
209         if (cardhu_vdd_2v8_cam1)
210                 regulator_disable(cardhu_vdd_2v8_cam1);
211
212         return 0;
213 }
214
215 struct ov5650_platform_data cardhu_left_ov5650_data = {
216         .power_on = cardhu_left_ov5650_power_on,
217         .power_off = cardhu_left_ov5650_power_off,
218 };
219
220 static int cardhu_right_ov5650_power_on(void)
221 {
222         /* Boards E1198 and E1291 are of Cardhu personality
223          * and donot have TCA6416 exp for camera */
224         if ((board_info.board_id == BOARD_E1198) ||
225                 (board_info.board_id == BOARD_E1291)) {
226
227                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
228                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
229                 mdelay(10);
230
231                 if (cardhu_vdd_2v8_cam2 == NULL) {
232                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
233                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
234                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
235                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
236                                 goto reg_alloc_fail;
237                         }
238                 }
239                 regulator_enable(cardhu_vdd_2v8_cam2);
240                 mdelay(5);
241         }
242
243         /* Enable VDD_1V8_Cam2 */
244         if (cardhu_1v8_cam2 == NULL) {
245                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
246                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
247                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
248                                 __func__, PTR_ERR(cardhu_1v8_cam2));
249                         goto reg_alloc_fail;
250                 }
251         }
252         regulator_enable(cardhu_1v8_cam2);
253
254         mdelay(5);
255
256         if (board_info.board_id == BOARD_PM269) {
257                 gpio_direction_output(CAM2_RST_L_GPIO, 0);
258                 mdelay(100);
259                 gpio_direction_output(CAM2_RST_L_GPIO, 1);
260         }
261
262         return 0;
263
264 reg_alloc_fail:
265         if (cardhu_1v8_cam2) {
266                 regulator_put(cardhu_1v8_cam2);
267                 cardhu_1v8_cam2 = NULL;
268         }
269         if (cardhu_vdd_2v8_cam2) {
270                 regulator_put(cardhu_vdd_2v8_cam2);
271                 cardhu_vdd_2v8_cam2 = NULL;
272         }
273
274         return -ENODEV;
275
276 }
277
278 static int cardhu_right_ov5650_power_off(void)
279 {
280         /* Boards E1198 and E1291 are of Cardhu personality
281          * and donot have TCA6416 exp for camera */
282         if ((board_info.board_id == BOARD_E1198) ||
283                 (board_info.board_id == BOARD_E1291)) {
284                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
285                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
286                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
287         }
288
289         if (cardhu_1v8_cam2)
290                 regulator_disable(cardhu_1v8_cam2);
291         if (cardhu_vdd_2v8_cam2)
292                 regulator_disable(cardhu_vdd_2v8_cam2);
293
294         return 0;
295 }
296
297 static void cardhu_ov5650_synchronize_sensors(void)
298 {
299         if (board_info.board_id == BOARD_E1198) {
300                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
301                 mdelay(50);
302                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
303                 mdelay(50);
304         }
305         else if (board_info.board_id == BOARD_E1291) {
306                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
307                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
308                 mdelay(50);
309                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
310                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
311                 mdelay(50);
312         }
313         else
314                 pr_err("%s: UnSupported BoardId\n", __func__);
315 }
316
317 struct ov5650_platform_data cardhu_right_ov5650_data = {
318         .power_on = cardhu_right_ov5650_power_on,
319         .power_off = cardhu_right_ov5650_power_off,
320         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
321 };
322
323 static int cardhu_ov2710_power_on(void)
324 {
325         /* CSI-B and front sensor are muxed on verbier */
326         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
327
328         /* Boards E1198 and E1291 are of Cardhu personality
329          * and donot have TCA6416 exp for camera */
330         if ((board_info.board_id == BOARD_E1198) ||
331                 (board_info.board_id == BOARD_E1291)) {
332
333                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
334                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
335                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
336                 mdelay(10);
337
338                 if (cardhu_vdd_cam3 == NULL) {
339                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
340                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
341                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
342                                         __func__, PTR_ERR(cardhu_vdd_cam3));
343                                 goto reg_alloc_fail;
344                         }
345                 }
346                 regulator_enable(cardhu_vdd_cam3);
347         }
348
349         /* Enable VDD_1V8_Cam3 */
350         if (cardhu_1v8_cam3 == NULL) {
351                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
352                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
353                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
354                                 __func__, PTR_ERR(cardhu_1v8_cam3));
355                         goto reg_alloc_fail;
356                 }
357         }
358         regulator_enable(cardhu_1v8_cam3);
359         mdelay(5);
360
361         return 0;
362
363 reg_alloc_fail:
364         if (cardhu_1v8_cam3) {
365                 regulator_put(cardhu_1v8_cam3);
366                 cardhu_1v8_cam3 = NULL;
367         }
368         if (cardhu_vdd_cam3) {
369                 regulator_put(cardhu_vdd_cam3);
370                 cardhu_vdd_cam3 = NULL;
371         }
372
373         return -ENODEV;
374 }
375
376 static int cardhu_ov2710_power_off(void)
377 {
378         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
379
380         /* Boards E1198 and E1291 are of Cardhu personality
381          * and donot have TCA6416 exp for camera */
382         if ((board_info.board_id == BOARD_E1198) ||
383                 (board_info.board_id == BOARD_E1291)) {
384                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
385                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
386                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
387         }
388
389         if (cardhu_1v8_cam3)
390                 regulator_disable(cardhu_1v8_cam3);
391         if (cardhu_vdd_cam3)
392                 regulator_disable(cardhu_vdd_cam3);
393
394         return 0;
395 }
396
397 struct ov2710_platform_data cardhu_ov2710_data = {
398         .power_on = cardhu_ov2710_power_on,
399         .power_off = cardhu_ov2710_power_off,
400 };
401
402 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
403         {
404                 I2C_BOARD_INFO("pca9546", 0x70),
405                 .platform_data = &cardhu_pca954x_data,
406         },
407 };
408
409 static int sh532u_power_control(void *cdata, int is_enable, int which) {
410         static struct regulator *vdd_2v8_cam1_af = NULL;
411         static struct regulator *vdd_2v8_cam2_af = NULL;
412
413         struct regulator *vdd_2v8_camx_af = (1 == which) ? vdd_2v8_cam1_af : vdd_2v8_cam2_af;
414         char *vdd_2v8_camx_tag = (1 == which) ? "vdd_2v8_cam1_af" : "vdd_2v8_cam2_af";
415
416         if (vdd_2v8_camx_af == NULL) {
417                 vdd_2v8_camx_af = regulator_get(NULL, vdd_2v8_camx_tag);
418                 if (WARN_ON(IS_ERR_OR_NULL(vdd_2v8_camx_af))) {
419                         pr_err("%s: couldn't get regulator %s:"
420                                 " %ld\n", __func__, vdd_2v8_camx_tag, PTR_ERR(vdd_2v8_camx_af));
421                         vdd_2v8_camx_af = NULL;
422                         return -ENODEV;
423                 }
424         }
425         if (is_enable) {
426                 regulator_enable(vdd_2v8_camx_af);
427                 mdelay(20);
428         } else
429                 regulator_disable(vdd_2v8_camx_af);
430
431         return 0;
432 }
433
434 static int sh532u_left_init(void *cdata) {
435         return sh532u_power_control(cdata, true, 1);
436 }
437 static int sh532u_left_deinit(void *cdata) {
438         return sh532u_power_control(cdata, false, 1);
439 }
440
441 static int sh532u_right_init(void *cdata) {
442         return sh532u_power_control(cdata, true, 2);
443 }
444 static int sh532u_right_deinit(void *cdata) {
445         return sh532u_power_control(cdata, false, 2);
446 }
447
448 struct sh532u_platform_data sh532u_left_pdata = {
449         .board_init = sh532u_left_init,
450         .board_deinit = sh532u_left_deinit,
451 };
452
453 struct sh532u_platform_data sh532u_right_pdata = {
454         .board_init = sh532u_right_init,
455         .board_deinit = sh532u_right_deinit,
456 };
457
458 static bool cardhu_tps61050_pm_flag = 0;
459
460 static struct tps61050_pin_state cardhu_tps61050_pinstate = {
461         .mask           = 0x0008, /*VGP3*/
462         .values         = 0x0008,
463 };
464
465 static int cardhu_tps61050_pm(int pwr)
466 {
467         switch (pwr) {
468         case TPS61050_PWR_OFF:
469                 if (cardhu_tps61050_pm_flag && cardhu_1v8_cam1) {
470                         regulator_disable(cardhu_1v8_cam1);
471                         cardhu_tps61050_pm_flag = 0;
472                 }
473                 return 0;
474
475         case TPS61050_PWR_STDBY:
476         case TPS61050_PWR_COMM:
477         case TPS61050_PWR_ON:
478                 if (!cardhu_tps61050_pm_flag) {
479                         if (cardhu_1v8_cam1 == NULL) {
480                                 cardhu_1v8_cam1 =
481                                         regulator_get(NULL, "vdd_1v8_cam1");
482                                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
483                                         pr_err("%s: err: %ld\n",
484                                                 __func__,
485                                                 PTR_ERR(cardhu_1v8_cam1));
486                                         regulator_put(cardhu_1v8_cam1);
487                                         cardhu_1v8_cam1 = NULL;
488                                 }
489                         }
490                         regulator_enable(cardhu_1v8_cam1);
491                         cardhu_tps61050_pm_flag = 1;
492                         mdelay(5);
493                 }
494                 return 0;
495
496         default:
497                 return -1;
498         }
499 }
500
501 static struct tps61050_platform_data cardhu_tps61050_data = {
502         .cfg            = 0,
503         .num            = 1,
504         .max_amp_torch  = CAMERA_FLASH_MAX_TORCH_AMP,
505         .max_amp_flash  = CAMERA_FLASH_MAX_FLASH_AMP,
506         .pinstate       = &cardhu_tps61050_pinstate,
507         .init           = NULL,
508         .exit           = NULL,
509         .pm             = cardhu_tps61050_pm,
510         .gpio_envm      = NULL,
511         .gpio_sync      = NULL,
512 };
513
514 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
515         {
516                 I2C_BOARD_INFO("tps61050", 0x33),
517                 .platform_data = &cardhu_tps61050_data,
518         },
519 };
520
521 static struct i2c_board_info cardhu_i2c6_board_info[] = {
522         {
523                 I2C_BOARD_INFO("ov5650L", 0x36),
524                 .platform_data = &cardhu_left_ov5650_data,
525         },
526         {
527                 I2C_BOARD_INFO("sh532uL", 0x72),
528                 .platform_data = &sh532u_left_pdata,
529         },
530 };
531
532 static struct i2c_board_info cardhu_i2c7_board_info[] = {
533         {
534                 I2C_BOARD_INFO("ov5650R", 0x36),
535                 .platform_data = &cardhu_right_ov5650_data,
536         },
537         {
538                 I2C_BOARD_INFO("sh532uR", 0x72),
539                 .platform_data = &sh532u_right_pdata,
540         },
541 };
542
543 static struct i2c_board_info cardhu_i2c8_board_info[] = {
544         {
545                 I2C_BOARD_INFO("ov2710", 0x36),
546                 .platform_data = &cardhu_ov2710_data,
547         },
548 };
549
550 static struct nct1008_platform_data cardhu_nct1008_pdata = {
551         .supported_hwrev = true,
552         .ext_range = true,
553         .conv_rate = 0x08,
554         .hysteresis = 5,
555         .shutdown_ext_limit = 90,
556         .shutdown_local_limit = 90,
557         .throttling_ext_limit = 75,
558         .alarm_fn = tegra_throttling_enable,
559 };
560
561 static struct bq27x00_platform_data cardhu_bq27510_pdata = {
562         .ac_persent_gpio = AC_PRESENT_GPIO,
563 };
564
565 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
566         {
567                 I2C_BOARD_INFO("bq27510", 0x55),
568                 .irq = AC_PRESENT_INT,
569                 .platform_data = &cardhu_bq27510_pdata,
570         },
571 };
572
573 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
574         {
575                 I2C_BOARD_INFO("nct1008", 0x4C),
576                 .platform_data = &cardhu_nct1008_pdata,
577                 .irq = -1,
578         }
579 };
580
581
582 static int cardhu_nct1008_init(void)
583 {
584         int nct1008_port = -1;
585         int ret;
586         struct nct1008_platform_data *pdata;
587 #ifdef CONFIG_TEGRA_EDP_LIMITS
588         const struct tegra_edp_limits *z;
589         int zones_sz;
590         int i;
591         bool throttle_ok = false;
592 #endif
593
594         if ((board_info.board_id == BOARD_E1198) ||
595                 (board_info.board_id == BOARD_E1291) ||
596                 (board_info.board_id == BOARD_PM269) ||
597                 (board_info.board_id == BOARD_PM305)) {
598                 nct1008_port = TEGRA_GPIO_PCC2;
599         } else if ((board_info.board_id == BOARD_E1186) ||
600                 (board_info.board_id == BOARD_E1187) ||
601                 (board_info.board_id == BOARD_E1256)) {
602                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
603                 /* nct1008_port = TEGRA_GPIO_PH7; */
604         }
605
606         if (nct1008_port >= 0) {
607                 /* FIXME: enable irq when throttling is supported */
608                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
609
610                 ret = gpio_request(nct1008_port, "temp_alert");
611                 if (ret < 0)
612                         return ret;
613
614                 ret = gpio_direction_input(nct1008_port);
615                 if (ret < 0)
616                         gpio_free(nct1008_port);
617                 else
618                         tegra_gpio_enable(nct1008_port);
619         }
620
621         /* Temperature guardband: bug 844025 */
622         if (board_info.board_id == BOARD_PM269) {
623                 /* T30S DSC */
624                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
625                 pdata->offset = 41; /* 4 * 10.25C */
626         } else {
627                 /* T30 MID */
628                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
629                 pdata->offset = 43; /* 4 * 10.75C */
630         }
631
632 #ifdef CONFIG_TEGRA_EDP_LIMITS
633         tegra_get_cpu_edp_limits(&z, &zones_sz);
634         zones_sz = min(zones_sz, MAX_ZONES);
635         for (i = 0; i < zones_sz; i++) {
636                 cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
637                 if (cardhu_nct1008_pdata.thermal_zones[i] ==
638                     cardhu_nct1008_pdata.throttling_ext_limit) {
639                         throttle_ok = true;
640                 }
641         }
642
643         if (throttle_ok != true)
644                 pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
645                         " as it is NOT one of the EDP points\n",
646                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
647         else
648                 pr_info("%s: Throttling limit %dC OK\n",
649                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
650
651         cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
652 #endif
653         return ret;
654 }
655
656 #if defined(CONFIG_GPIO_PCA953X)
657 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
658         .gpio_base      = PMU_TCA6416_GPIO_BASE,
659 };
660
661 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
662         {
663                 I2C_BOARD_INFO("tca6416", 0x20),
664                 .platform_data = &cardhu_pmu_tca6416_data,
665         },
666 };
667
668 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
669         .gpio_base      = CAM_TCA6416_GPIO_BASE,
670 };
671
672 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
673         {
674                 I2C_BOARD_INFO("tca6416", 0x20),
675                 .platform_data = &cardhu_cam_tca6416_data,
676         },
677 };
678
679 static int __init pmu_tca6416_init(void)
680 {
681         if ((board_info.board_id == BOARD_E1198) ||
682                 (board_info.board_id == BOARD_E1291))
683                         return 0;
684
685         pr_info("Registering pmu pca6416\n");
686         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
687                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
688         return 0;
689 }
690
691 static int __init cam_tca6416_init(void)
692 {
693         /* Boards E1198 and E1291 are of Cardhu personality
694          * and donot have TCA6416 exp for camera */
695         if ((board_info.board_id == BOARD_E1198) ||
696                 (board_info.board_id == BOARD_E1291))
697                 return 0;
698
699         pr_info("Registering cam pca6416\n");
700         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
701                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
702         return 0;
703 }
704 #else
705 static int __init pmu_tca6416_init(void)
706 {
707         return 0;
708 }
709
710 static int __init cam_tca6416_init(void)
711 {
712         return 0;
713 }
714 #endif
715
716 #ifdef CONFIG_MPU_SENSORS_MPU3050
717 #define SENSOR_MPU_NAME "mpu3050"
718 static struct mpu3050_platform_data mpu3050_data = {
719         .int_config  = 0x10,
720         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
721         .level_shifter = 0,
722
723         .accel = {
724         .get_slave_descr = get_accel_slave_descr,
725         .adapt_num   = 2,
726         .bus         = EXT_SLAVE_BUS_SECONDARY,
727         .address     = 0x0F,
728         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
729         },
730
731         .compass = {
732         .get_slave_descr = get_compass_slave_descr,
733         .adapt_num   = 2,
734         .bus         = EXT_SLAVE_BUS_PRIMARY,
735         .address     = 0x0C,
736         .orientation = { 1, 0, 0, 0, 1, 0, 0, 0, 1 },  /* Orientation matrix for AKM on cardhu */
737         },
738 };
739
740 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
741         {
742                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
743                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
744                 .platform_data = &mpu3050_data,
745         },
746 };
747
748 static void cardhu_mpuirq_init(void)
749 {
750         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
751         tegra_gpio_enable(TEGRA_GPIO_PX1);
752         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
753         gpio_direction_input(TEGRA_GPIO_PX1);
754         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
755
756         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
757                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
758 }
759 #endif
760
761
762 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
763         {
764                 I2C_BOARD_INFO("isl29028", 0x44),
765         }
766 };
767
768 int __init cardhu_sensors_init(void)
769 {
770         int err;
771
772         tegra_get_board_info(&board_info);
773
774         cardhu_camera_init();
775         cam_tca6416_init();
776
777         i2c_register_board_info(2, cardhu_i2c3_board_info,
778                 ARRAY_SIZE(cardhu_i2c3_board_info));
779
780         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
781                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
782
783         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
784          * Front camera is on BUS2 */
785         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
786                 ARRAY_SIZE(cardhu_i2c6_board_info));
787
788         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
789                 ARRAY_SIZE(cardhu_i2c7_board_info));
790
791         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
792                 ARRAY_SIZE(cardhu_i2c8_board_info));
793
794         pmu_tca6416_init();
795
796         if (board_info.board_id == BOARD_E1291)
797                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
798                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
799
800         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
801                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
802
803         err = cardhu_nct1008_init();
804         if (err)
805                 return err;
806
807         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
808                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
809
810 #ifdef CONFIG_MPU_SENSORS_MPU3050
811         cardhu_mpuirq_init();
812 #endif
813         return 0;
814 }
815
816 #if defined(CONFIG_GPIO_PCA953X)
817 struct ov5650_gpios {
818         const char *name;
819         int gpio;
820         int enabled;
821 };
822
823 #define OV5650_GPIO(_name, _gpio, _enabled)             \
824         {                                               \
825                 .name = _name,                          \
826                 .gpio = _gpio,                          \
827                 .enabled = _enabled,                    \
828         }
829
830 static struct ov5650_gpios ov5650_gpio_keys[] = {
831         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
832         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
833         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
834         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
835         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
836         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
837         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
838         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
839         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
840         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
841         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
842         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
843         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
844         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
845         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
846 };
847
848 int __init cardhu_ov5650_late_init(void)
849 {
850         int ret;
851         int i;
852
853         if ((board_info.board_id == BOARD_E1198) ||
854                 (board_info.board_id == BOARD_E1291))
855                 return 0;
856
857         printk("%s: \n", __func__);
858         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
859                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
860                         ov5650_gpio_keys[i].name);
861                 if (ret < 0) {
862                         printk("%s: gpio_request failed for gpio #%d\n",
863                                 __func__, i);
864                         goto fail;
865                 }
866                 printk("%s: enable - %d\n", __func__, i);
867                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
868                         ov5650_gpio_keys[i].enabled);
869                 gpio_export(ov5650_gpio_keys[i].gpio, false);
870         }
871
872         return 0;
873
874 fail:
875         while (i--)
876                 gpio_free(ov5650_gpio_keys[i].gpio);
877         return ret;
878 }
879
880 late_initcall(cardhu_ov5650_late_init);
881 #endif