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