arm: tegra: cardhu: Support for PM311
[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 i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
562         {
563                 I2C_BOARD_INFO("bq27510", 0x55),
564         },
565 };
566
567 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
568         {
569                 I2C_BOARD_INFO("nct1008", 0x4C),
570                 .platform_data = &cardhu_nct1008_pdata,
571                 .irq = -1,
572         }
573 };
574
575
576 static int cardhu_nct1008_init(void)
577 {
578         int nct1008_port = -1;
579         int ret;
580         struct nct1008_platform_data *pdata;
581 #ifdef CONFIG_TEGRA_EDP_LIMITS
582         const struct tegra_edp_limits *z;
583         int zones_sz;
584         int i;
585         bool throttle_ok = false;
586 #endif
587
588         if ((board_info.board_id == BOARD_E1198) ||
589                 (board_info.board_id == BOARD_E1291) ||
590                 (board_info.board_id == BOARD_PM269) ||
591                 (board_info.board_id == BOARD_PM305) ||
592                 (board_info.board_id == BOARD_PM311)) {
593                 nct1008_port = TEGRA_GPIO_PCC2;
594         } else if ((board_info.board_id == BOARD_E1186) ||
595                 (board_info.board_id == BOARD_E1187) ||
596                 (board_info.board_id == BOARD_E1256)) {
597                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
598                 /* nct1008_port = TEGRA_GPIO_PH7; */
599         }
600
601         if (nct1008_port >= 0) {
602                 /* FIXME: enable irq when throttling is supported */
603                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
604
605                 ret = gpio_request(nct1008_port, "temp_alert");
606                 if (ret < 0)
607                         return ret;
608
609                 ret = gpio_direction_input(nct1008_port);
610                 if (ret < 0)
611                         gpio_free(nct1008_port);
612                 else
613                         tegra_gpio_enable(nct1008_port);
614         }
615
616         /* Temperature guardband: bug 844025 */
617         if (board_info.board_id == BOARD_PM269) {
618                 /* T30S DSC */
619                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
620                 pdata->offset = 41; /* 4 * 10.25C */
621         } else {
622                 /* T30 MID */
623                 pdata = cardhu_i2c4_nct1008_board_info[0].platform_data;
624                 pdata->offset = 43; /* 4 * 10.75C */
625         }
626
627 #ifdef CONFIG_TEGRA_EDP_LIMITS
628         tegra_get_cpu_edp_limits(&z, &zones_sz);
629         zones_sz = min(zones_sz, MAX_ZONES);
630         for (i = 0; i < zones_sz; i++) {
631                 cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
632                 if (cardhu_nct1008_pdata.thermal_zones[i] ==
633                     cardhu_nct1008_pdata.throttling_ext_limit) {
634                         throttle_ok = true;
635                 }
636         }
637
638         if (throttle_ok != true)
639                 pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
640                         " as it is NOT one of the EDP points\n",
641                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
642         else
643                 pr_info("%s: Throttling limit %dC OK\n",
644                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
645
646         cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
647 #endif
648         return ret;
649 }
650
651 #if defined(CONFIG_GPIO_PCA953X)
652 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
653         .gpio_base      = PMU_TCA6416_GPIO_BASE,
654 };
655
656 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
657         {
658                 I2C_BOARD_INFO("tca6416", 0x20),
659                 .platform_data = &cardhu_pmu_tca6416_data,
660         },
661 };
662
663 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
664         .gpio_base      = CAM_TCA6416_GPIO_BASE,
665 };
666
667 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
668         {
669                 I2C_BOARD_INFO("tca6416", 0x20),
670                 .platform_data = &cardhu_cam_tca6416_data,
671         },
672 };
673
674 static int __init pmu_tca6416_init(void)
675 {
676         if ((board_info.board_id == BOARD_E1198) ||
677                 (board_info.board_id == BOARD_E1291))
678                         return 0;
679
680         pr_info("Registering pmu pca6416\n");
681         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
682                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
683         return 0;
684 }
685
686 static int __init cam_tca6416_init(void)
687 {
688         /* Boards E1198 and E1291 are of Cardhu personality
689          * and donot have TCA6416 exp for camera */
690         if ((board_info.board_id == BOARD_E1198) ||
691                 (board_info.board_id == BOARD_E1291))
692                 return 0;
693
694         pr_info("Registering cam pca6416\n");
695         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
696                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
697         return 0;
698 }
699 #else
700 static int __init pmu_tca6416_init(void)
701 {
702         return 0;
703 }
704
705 static int __init cam_tca6416_init(void)
706 {
707         return 0;
708 }
709 #endif
710
711 #ifdef CONFIG_SENSORS_MPU3050
712 #define SENSOR_MPU_NAME "mpu3050"
713 static struct mpu3050_platform_data mpu3050_data = {
714         .int_config  = 0x10,
715         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
716         .level_shifter = 0,
717
718         .accel = {
719         .get_slave_descr = get_accel_slave_descr,
720         .adapt_num   = 2,
721         .bus         = EXT_SLAVE_BUS_SECONDARY,
722         .address     = 0x0F,
723         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
724         },
725
726         .compass = {
727         .get_slave_descr = get_compass_slave_descr,
728         .adapt_num   = 2,
729         .bus         = EXT_SLAVE_BUS_PRIMARY,
730         .address     = 0x0C,
731         .orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 },  /* Orientation matrix for AKM on cardhu */
732         },
733 };
734
735 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
736         {
737                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
738                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
739                 .platform_data = &mpu3050_data,
740         },
741 };
742
743 static void cardhu_mpuirq_init(void)
744 {
745         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
746         tegra_gpio_enable(TEGRA_GPIO_PX1);
747         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
748         gpio_direction_input(TEGRA_GPIO_PX1);
749         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
750 }
751 #endif
752
753
754 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
755         {
756                 I2C_BOARD_INFO("isl29028", 0x44),
757         }
758 };
759
760 int __init cardhu_sensors_init(void)
761 {
762         int err;
763
764         tegra_get_board_info(&board_info);
765
766         cardhu_camera_init();
767         cam_tca6416_init();
768
769         i2c_register_board_info(2, cardhu_i2c3_board_info,
770                 ARRAY_SIZE(cardhu_i2c3_board_info));
771
772         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
773                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
774
775         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
776          * Front camera is on BUS2 */
777         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
778                 ARRAY_SIZE(cardhu_i2c6_board_info));
779
780         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
781                 ARRAY_SIZE(cardhu_i2c7_board_info));
782
783         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
784                 ARRAY_SIZE(cardhu_i2c8_board_info));
785
786         pmu_tca6416_init();
787
788         if (board_info.board_id == BOARD_E1291)
789                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
790                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
791
792         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
793                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
794
795         err = cardhu_nct1008_init();
796         if (err)
797                 return err;
798
799         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
800                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
801
802 #ifdef CONFIG_SENSORS_MPU3050
803         cardhu_mpuirq_init();
804 #endif
805
806 #ifdef CONFIG_SENSORS_MPU3050
807         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
808                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
809 #endif
810
811         return 0;
812 }
813
814 #if defined(CONFIG_GPIO_PCA953X)
815 struct ov5650_gpios {
816         const char *name;
817         int gpio;
818         int enabled;
819 };
820
821 #define OV5650_GPIO(_name, _gpio, _enabled)             \
822         {                                               \
823                 .name = _name,                          \
824                 .gpio = _gpio,                          \
825                 .enabled = _enabled,                    \
826         }
827
828 static struct ov5650_gpios ov5650_gpio_keys[] = {
829         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
830         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
831         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
832         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
833         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
834         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
835         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
836         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
837         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
838         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
839         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
840         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
841         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
842         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
843         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
844 };
845
846 int __init cardhu_ov5650_late_init(void)
847 {
848         int ret;
849         int i;
850
851         if ((board_info.board_id == BOARD_E1198) ||
852                 (board_info.board_id == BOARD_E1291))
853                 return 0;
854
855         printk("%s: \n", __func__);
856         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
857                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
858                         ov5650_gpio_keys[i].name);
859                 if (ret < 0) {
860                         printk("%s: gpio_request failed for gpio #%d\n",
861                                 __func__, i);
862                         goto fail;
863                 }
864                 printk("%s: enable - %d\n", __func__, i);
865                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
866                         ov5650_gpio_keys[i].enabled);
867                 gpio_export(ov5650_gpio_keys[i].gpio, false);
868         }
869
870         return 0;
871
872 fail:
873         while (i--)
874                 gpio_free(ov5650_gpio_keys[i].gpio);
875         return ret;
876 }
877
878 late_initcall(cardhu_ov5650_late_init);
879 #endif