ARM: tegra: cardhu: remove avdd_dsi_csi regulator code
[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) 2011, NVIDIA, All Rights Reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include <linux/i2c.h>
22 #include <linux/delay.h>
23 #include <linux/regulator/consumer.h>
24 #include <linux/i2c/pca954x.h>
25 #include <linux/i2c/pca953x.h>
26 #include <linux/nct1008.h>
27 #include <mach/fb.h>
28 #include <mach/gpio.h>
29 #include <media/ov5650.h>
30 #include <media/ov2710.h>
31 #include <generated/mach-types.h>
32 #include "gpio-names.h"
33 #include "board.h"
34 #include <linux/mpu.h>
35 #include <media/sh532u.h>
36
37 #include <mach/gpio.h>
38
39 #include "gpio-names.h"
40 #include "board-cardhu.h"
41
42 static struct regulator *cardhu_1v8_cam1 = NULL;
43 static struct regulator *cardhu_1v8_cam2 = NULL;
44 static struct regulator *cardhu_1v8_cam3 = NULL;
45 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
46 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
47 static struct regulator *cardhu_vdd_cam3 = NULL;
48
49 static struct board_info board_info;
50
51 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
52         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
53         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
54         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
55         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
56 };
57
58 static struct pca954x_platform_data cardhu_pca954x_data = {
59         .modes    = cardhu_pca954x_modes,
60         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
61 };
62
63 static int cardhu_camera_init(void)
64 {
65         int ret;
66
67         /* Boards E1198 and E1291 are of Cardhu personality
68          * and donot have TCA6416 exp for camera */
69         if ((board_info.board_id == BOARD_E1198) ||
70                 (board_info.board_id == BOARD_E1291)) {
71                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
72                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
73                 if (ret < 0)
74                         pr_err("%s: gpio_request failed for gpio %s\n",
75                                 __func__, "CAM1_POWER_DWN_GPIO");
76                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
77                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
78                 if (ret < 0)
79                         pr_err("%s: gpio_request failed for gpio %s\n",
80                                 __func__, "CAM3_POWER_DWN_GPIO");
81
82                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
83                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
84                 if (ret < 0)
85                         pr_err("%s: gpio_request failed for gpio %s\n",
86                                 __func__, "CAM2_POWER_DWN_GPIO");
87
88                 tegra_gpio_enable(OV5650_RESETN_GPIO);
89                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
90                 if (ret < 0)
91                         pr_err("%s: gpio_request failed for gpio %s\n",
92                                 __func__, "OV5650_RESETN_GPIO");
93
94                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
95                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
96                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
97                 mdelay(10);
98
99                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
100                 mdelay(5);
101                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
102                 mdelay(5);
103                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
104                 mdelay(5);
105         }
106
107         /* To select the CSIB MUX either for cam2 or cam3 */
108         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
109         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
110         if (ret < 0)
111                 pr_err("%s: gpio_request failed for gpio %s\n",
112                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
113         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
114         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
115
116         return 0;
117 }
118
119 static int cardhu_left_ov5650_power_on(void)
120 {
121         /* Boards E1198 and E1291 are of Cardhu personality
122          * and donot have TCA6416 exp for camera */
123         if ((board_info.board_id == BOARD_E1198) ||
124                 (board_info.board_id == BOARD_E1291)) {
125
126                 if (cardhu_vdd_2v8_cam1 == NULL) {
127                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
128                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
129                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
130                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
131                                 goto reg_alloc_fail;
132                         }
133                 }
134                 regulator_enable(cardhu_vdd_2v8_cam1);
135                 mdelay(5);
136         }
137
138         /* Enable VDD_1V8_Cam1 */
139         if (cardhu_1v8_cam1 == NULL) {
140                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
141                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
142                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
143                                 __func__, PTR_ERR(cardhu_1v8_cam1));
144                         goto reg_alloc_fail;
145                 }
146         }
147         regulator_enable(cardhu_1v8_cam1);
148
149         mdelay(5);
150         if ((board_info.board_id == BOARD_E1198) ||
151                 (board_info.board_id == BOARD_E1291)) {
152                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
153                 mdelay(20);
154                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
155                 mdelay(100);
156                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
157         }
158         return 0;
159
160 reg_alloc_fail:
161         if (cardhu_1v8_cam1) {
162                 regulator_put(cardhu_1v8_cam1);
163                 cardhu_1v8_cam1 = NULL;
164         }
165         if (cardhu_vdd_2v8_cam1) {
166                 regulator_put(cardhu_vdd_2v8_cam1);
167                 cardhu_vdd_2v8_cam1 = NULL;
168         }
169
170         return -ENODEV;
171
172 }
173
174 static int cardhu_left_ov5650_power_off(void)
175 {
176         /* Boards E1198 and E1291 are of Cardhu personality
177          * and donot have TCA6416 exp for camera */
178         if ((board_info.board_id == BOARD_E1198) ||
179                 (board_info.board_id == BOARD_E1291)) {
180                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
181                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
182                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
183         }
184         if (cardhu_1v8_cam1)
185                 regulator_disable(cardhu_1v8_cam1);
186         if (cardhu_vdd_2v8_cam1)
187                 regulator_disable(cardhu_vdd_2v8_cam1);
188
189         return 0;
190 }
191
192 struct ov5650_platform_data cardhu_left_ov5650_data = {
193         .power_on = cardhu_left_ov5650_power_on,
194         .power_off = cardhu_left_ov5650_power_off,
195 };
196
197 static int cardhu_right_ov5650_power_on(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
204                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
205                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
206                 mdelay(10);
207
208                 if (cardhu_vdd_2v8_cam2 == NULL) {
209                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
210                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
211                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
212                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
213                                 goto reg_alloc_fail;
214                         }
215                 }
216                 regulator_enable(cardhu_vdd_2v8_cam2);
217                 mdelay(5);
218         }
219
220         /* Enable VDD_1V8_Cam2 */
221         if (cardhu_1v8_cam2 == NULL) {
222                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
223                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
224                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
225                                 __func__, PTR_ERR(cardhu_1v8_cam2));
226                         goto reg_alloc_fail;
227                 }
228         }
229         regulator_enable(cardhu_1v8_cam2);
230
231         mdelay(5);
232         return 0;
233
234 reg_alloc_fail:
235         if (cardhu_1v8_cam2) {
236                 regulator_put(cardhu_1v8_cam2);
237                 cardhu_1v8_cam2 = NULL;
238         }
239         if (cardhu_vdd_2v8_cam2) {
240                 regulator_put(cardhu_vdd_2v8_cam2);
241                 cardhu_vdd_2v8_cam2 = NULL;
242         }
243
244         return -ENODEV;
245
246 }
247
248 static int cardhu_right_ov5650_power_off(void)
249 {
250         /* Boards E1198 and E1291 are of Cardhu personality
251          * and donot have TCA6416 exp for camera */
252         if ((board_info.board_id == BOARD_E1198) ||
253                 (board_info.board_id == BOARD_E1291)) {
254                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
255                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
256         }
257
258         if (cardhu_1v8_cam2)
259                 regulator_disable(cardhu_1v8_cam2);
260         if (cardhu_vdd_2v8_cam2)
261                 regulator_disable(cardhu_vdd_2v8_cam2);
262
263         return 0;
264 }
265
266
267 struct ov5650_platform_data cardhu_right_ov5650_data = {
268         .power_on = cardhu_right_ov5650_power_on,
269         .power_off = cardhu_right_ov5650_power_off,
270 };
271
272 static int cardhu_ov2710_power_on(void)
273 {
274         /* CSI-B and front sensor are muxed on verbier */
275         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
276
277         /* Boards E1198 and E1291 are of Cardhu personality
278          * and donot have TCA6416 exp for camera */
279         if ((board_info.board_id == BOARD_E1198) ||
280                 (board_info.board_id == BOARD_E1291)) {
281
282                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
283                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
284                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
285                 mdelay(10);
286
287                 if (cardhu_vdd_cam3 == NULL) {
288                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
289                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
290                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
291                                         __func__, PTR_ERR(cardhu_vdd_cam3));
292                                 goto reg_alloc_fail;
293                         }
294                 }
295                 regulator_enable(cardhu_vdd_cam3);
296         }
297
298         /* Enable VDD_1V8_Cam3 */
299         if (cardhu_1v8_cam3 == NULL) {
300                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
301                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
302                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
303                                 __func__, PTR_ERR(cardhu_1v8_cam3));
304                         goto reg_alloc_fail;
305                 }
306         }
307         regulator_enable(cardhu_1v8_cam3);
308         mdelay(5);
309
310         return 0;
311
312 reg_alloc_fail:
313         if (cardhu_1v8_cam3) {
314                 regulator_put(cardhu_1v8_cam3);
315                 cardhu_1v8_cam3 = NULL;
316         }
317         if (cardhu_vdd_cam3) {
318                 regulator_put(cardhu_vdd_cam3);
319                 cardhu_vdd_cam3 = NULL;
320         }
321
322         return -ENODEV;
323 }
324
325 static int cardhu_ov2710_power_off(void)
326 {
327         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
328
329         /* Boards E1198 and E1291 are of Cardhu personality
330          * and donot have TCA6416 exp for camera */
331         if ((board_info.board_id == BOARD_E1198) ||
332                 (board_info.board_id == BOARD_E1291)) {
333                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
334                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
335                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
336         }
337
338         if (cardhu_1v8_cam3)
339                 regulator_disable(cardhu_1v8_cam3);
340         if (cardhu_vdd_cam3)
341                 regulator_disable(cardhu_vdd_cam3);
342
343         return 0;
344 }
345
346 struct ov2710_platform_data cardhu_ov2710_data = {
347         .power_on = cardhu_ov2710_power_on,
348         .power_off = cardhu_ov2710_power_off,
349 };
350
351 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
352         {
353                 I2C_BOARD_INFO("pca9546", 0x70),
354                 .platform_data = &cardhu_pca954x_data,
355         },
356 };
357
358 static int sh532u_power_control(void *cdata, int is_enable) {
359         static struct regulator *vdd_2v8_cam1_af = NULL;
360         if (vdd_2v8_cam1_af == NULL) {
361                 vdd_2v8_cam1_af = regulator_get(NULL, "vdd_2v8_cam1_af");
362                 if (WARN_ON(IS_ERR_OR_NULL(vdd_2v8_cam1_af))) {
363                         pr_err("%s: couldn't get regulator vdd_2v8_cam1_af:"
364                                 " %ld\n", __func__, PTR_ERR(vdd_2v8_cam1_af));
365                         return -ENODEV;
366                 }
367         }
368         if (is_enable) {
369                 regulator_enable(vdd_2v8_cam1_af);
370                 mdelay(20);
371         } else
372                 regulator_disable(vdd_2v8_cam1_af);
373         return 0;
374 }
375 static int sh532u_init(void *cdata) {
376         return sh532u_power_control(cdata, true);
377 }
378 static int sh532u_deinit(void *cdata) {
379         return sh532u_power_control(cdata, false);
380 }
381
382 struct sh532u_platform_data sh532u_pdata = {
383         .board_init = sh532u_init,
384         .board_deinit = sh532u_deinit,
385 };
386 static struct i2c_board_info cardhu_i2c6_board_info[] = {
387         {
388                 I2C_BOARD_INFO("ov5650L", 0x36),
389                 .platform_data = &cardhu_left_ov5650_data,
390         },
391         {
392                 I2C_BOARD_INFO("sh532u", 0x72),
393                 .platform_data = &sh532u_pdata,
394         },
395 };
396
397 static struct i2c_board_info cardhu_i2c7_board_info[] = {
398         {
399                 I2C_BOARD_INFO("ov5650R", 0x36),
400                 .platform_data = &cardhu_right_ov5650_data,
401         },
402 };
403
404 static struct i2c_board_info cardhu_i2c8_board_info[] = {
405         {
406                 I2C_BOARD_INFO("ov2710", 0x36),
407                 .platform_data = &cardhu_ov2710_data,
408         },
409 };
410
411 static struct nct1008_platform_data cardhu_nct1008_pdata = {
412         .supported_hwrev = true,
413         .ext_range = false,
414         .conv_rate = 0x08,
415         .offset = 0,
416         .hysteresis = 5,
417         .shutdown_ext_limit = 75,
418         .shutdown_local_limit = 75,
419         .throttling_ext_limit = 60,
420         .alarm_fn = NULL,
421 };
422
423 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
424         {
425                 I2C_BOARD_INFO("bq27510", 0x55),
426                 .irq = AC_PRESENT_GPIO,
427         },
428 };
429
430 static struct i2c_board_info cardhu_i2c4_board_info[] = {
431         {
432                 I2C_BOARD_INFO("nct1008", 0x4C),
433                 .platform_data = &cardhu_nct1008_pdata,
434                 .irq = -1,
435         }
436 };
437
438 static int cardhu_nct1008_init(void)
439 {
440         int nct1008_port = -1;
441         int ret;
442
443         if ((board_info.board_id == BOARD_E1198) ||
444                 (board_info.board_id == BOARD_E1291)) {
445                 nct1008_port = TEGRA_GPIO_PCC2;
446         } else if ((board_info.board_id == BOARD_E1186) ||
447                 (board_info.board_id == BOARD_E1187)) {
448                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
449                 /* nct1008_port = TEGRA_GPIO_PH7; */
450         }
451
452         if (nct1008_port >= 0) {
453                 /* FIXME: enable irq when throttling is supported */
454                 /* cardhu_i2c4_board_info[0].irq = */
455                 /* TEGRA_GPIO_TO_IRQ(nct1008_port); */
456
457                 ret = gpio_request(nct1008_port, "temp_alert");
458                 if (ret < 0)
459                         return ret;
460
461                 ret = gpio_direction_input(nct1008_port);
462                 if (ret < 0)
463                         gpio_free(nct1008_port);
464                 else
465                         tegra_gpio_enable(nct1008_port);
466
467         }
468         return ret;
469 }
470
471 #if defined(CONFIG_GPIO_PCA953X)
472 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
473         .gpio_base      = PMU_TCA6416_GPIO_BASE,
474 };
475
476 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
477         {
478                 I2C_BOARD_INFO("tca6416", 0x20),
479                 .platform_data = &cardhu_pmu_tca6416_data,
480         },
481 };
482
483 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
484         .gpio_base      = CAM_TCA6416_GPIO_BASE,
485 };
486
487 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
488         {
489                 I2C_BOARD_INFO("tca6416", 0x20),
490                 .platform_data = &cardhu_cam_tca6416_data,
491         },
492 };
493
494 static int __init pmu_tca6416_init(void)
495 {
496         if ((board_info.board_id == BOARD_E1198) ||
497                 (board_info.board_id == BOARD_E1291))
498                         return 0;
499
500         pr_info("Registering pmu pca6416\n");
501         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
502                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
503         return 0;
504 }
505
506 static int __init cam_tca6416_init(void)
507 {
508         /* Boards E1198 and E1291 are of Cardhu personality
509          * and donot have TCA6416 exp for camera */
510         if ((board_info.board_id == BOARD_E1198) ||
511                 (board_info.board_id == BOARD_E1291))
512                 return 0;
513
514         pr_info("Registering cam pca6416\n");
515         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
516                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
517         return 0;
518 }
519 #else
520 static int __init pmu_tca6416_init(void)
521 {
522         return 0;
523 }
524
525 static int __init cam_tca6416_init(void)
526 {
527         return 0;
528 }
529 #endif
530
531 #ifdef CONFIG_SENSORS_MPU3050
532 #define SENSOR_MPU_NAME "mpu3050"
533 static struct mpu3050_platform_data mpu3050_data = {
534         .int_config  = 0x10,
535         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
536         .level_shifter = 0,
537
538         .accel = {
539         .get_slave_descr = get_accel_slave_descr,
540         .adapt_num   = 2,
541         .bus         = EXT_SLAVE_BUS_SECONDARY,
542         .address     = 0x0F,
543         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
544         },
545
546         .compass = {
547         .get_slave_descr = get_compass_slave_descr,
548         .adapt_num   = 2,
549         .bus         = EXT_SLAVE_BUS_PRIMARY,
550         .address     = 0x0C,
551         .orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 },  /* Orientation matrix for AKM on cardhu */
552         },
553 };
554
555 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
556         {
557                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
558                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
559                 .platform_data = &mpu3050_data,
560         },
561 };
562
563 static void cardhu_mpuirq_init(void)
564 {
565         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
566         tegra_gpio_enable(TEGRA_GPIO_PX1);
567         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
568         gpio_direction_input(TEGRA_GPIO_PX1);
569         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
570 }
571 #endif
572
573
574 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
575         {
576                 I2C_BOARD_INFO("isl29028", 0x44),
577         }
578 };
579
580 int __init cardhu_sensors_init(void)
581 {
582         int err;
583
584         tegra_get_board_info(&board_info);
585
586         cardhu_camera_init();
587         cam_tca6416_init();
588
589         i2c_register_board_info(2, cardhu_i2c3_board_info,
590                 ARRAY_SIZE(cardhu_i2c3_board_info));
591
592         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
593          * Front camera is on BUS2 */
594         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
595                 ARRAY_SIZE(cardhu_i2c6_board_info));
596
597         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
598                 ARRAY_SIZE(cardhu_i2c7_board_info));
599
600         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
601                 ARRAY_SIZE(cardhu_i2c8_board_info));
602
603         pmu_tca6416_init();
604
605         i2c_register_board_info(4, cardhu_i2c4_board_info,
606                 ARRAY_SIZE(cardhu_i2c4_board_info));
607
608         if (board_info.board_id == BOARD_E1291)
609                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
610                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
611
612         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
613                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
614
615         err = cardhu_nct1008_init();
616         if (err)
617                 return err;
618
619 #ifdef CONFIG_SENSORS_MPU3050
620         cardhu_mpuirq_init();
621 #endif
622
623 #ifdef CONFIG_SENSORS_MPU3050
624         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
625                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
626 #endif
627
628         return 0;
629 }
630
631 #if defined(CONFIG_GPIO_PCA953X)
632 struct ov5650_gpios {
633         const char *name;
634         int gpio;
635         int enabled;
636 };
637
638 #define OV5650_GPIO(_name, _gpio, _enabled)             \
639         {                                               \
640                 .name = _name,                          \
641                 .gpio = _gpio,                          \
642                 .enabled = _enabled,                    \
643         }
644
645 static struct ov5650_gpios ov5650_gpio_keys[] = {
646         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
647         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
648         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 1),
649         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
650         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
651         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
652         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 1),
653         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
654         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
655         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
656         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 1),
657         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
658         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
659         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
660         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
661 };
662
663 int __init cardhu_ov5650_late_init(void)
664 {
665         int ret;
666         int i;
667
668         printk("%s: \n", __func__);
669         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
670                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
671                         ov5650_gpio_keys[i].name);
672                 if (ret < 0) {
673                         printk("%s: gpio_request failed for gpio #%d\n",
674                                 __func__, i);
675                         goto fail;
676                 }
677                 printk("%s: enable - %d\n", __func__, i);
678                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
679                         ov5650_gpio_keys[i].enabled);
680                 gpio_export(ov5650_gpio_keys[i].gpio, false);
681         }
682
683         return 0;
684
685 fail:
686         while (i--)
687                 gpio_free(ov5650_gpio_keys[i].gpio);
688         return ret;
689 }
690
691 late_initcall(cardhu_ov5650_late_init);
692 #endif