arm: tegra: power: Tegra Thermal refactoring
[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/ov14810.h>
44 #include <media/ov2710.h>
45 #include <media/tps61050.h>
46 #include <generated/mach-types.h>
47 #include "gpio-names.h"
48 #include "board.h"
49 #include <linux/mpu.h>
50 #include <media/sh532u.h>
51 #include <linux/bq27x00.h>
52 #include <mach/gpio.h>
53 #include <mach/edp.h>
54 #include <mach/thermal.h>
55
56 #include "gpio-names.h"
57 #include "board-cardhu.h"
58 #include "cpu-tegra.h"
59
60 static struct regulator *cardhu_1v8_cam1 = NULL;
61 static struct regulator *cardhu_1v8_cam2 = NULL;
62 static struct regulator *cardhu_1v8_cam3 = NULL;
63 static struct regulator *cardhu_vdd_2v8_cam1 = NULL;
64 static struct regulator *cardhu_vdd_2v8_cam2 = NULL;
65 static struct regulator *cardhu_vdd_cam3 = NULL;
66
67 static struct board_info board_info;
68
69 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
70         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
71         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
72         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
73         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
74 };
75
76 static struct pca954x_platform_data cardhu_pca954x_data = {
77         .modes    = cardhu_pca954x_modes,
78         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
79 };
80
81 static int cardhu_camera_init(void)
82 {
83         int ret;
84
85         /* Boards E1198 and E1291 are of Cardhu personality
86          * and donot have TCA6416 exp for camera */
87         if ((board_info.board_id == BOARD_E1198) ||
88                 (board_info.board_id == BOARD_E1291)) {
89                 tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
90                 ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
91                 if (ret < 0)
92                         pr_err("%s: gpio_request failed for gpio %s\n",
93                                 __func__, "CAM1_POWER_DWN_GPIO");
94                                 tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
95                 ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
96                 if (ret < 0)
97                         pr_err("%s: gpio_request failed for gpio %s\n",
98                                 __func__, "CAM3_POWER_DWN_GPIO");
99
100                 tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
101                 ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
102                 if (ret < 0)
103                         pr_err("%s: gpio_request failed for gpio %s\n",
104                                 __func__, "CAM2_POWER_DWN_GPIO");
105
106                 tegra_gpio_enable(OV5650_RESETN_GPIO);
107                 ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
108                 if (ret < 0)
109                         pr_err("%s: gpio_request failed for gpio %s\n",
110                                 __func__, "OV5650_RESETN_GPIO");
111
112                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
113                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
114                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
115                 mdelay(10);
116
117                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
118                 mdelay(5);
119                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
120                 mdelay(5);
121                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
122                 mdelay(5);
123         }
124
125         /* To select the CSIB MUX either for cam2 or cam3 */
126         tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
127         ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
128         if (ret < 0)
129                 pr_err("%s: gpio_request failed for gpio %s\n",
130                         __func__, "CAMERA_CSI_MUX_SEL_GPIO");
131         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
132         gpio_export(CAMERA_CSI_MUX_SEL_GPIO, false);
133
134         return 0;
135 }
136
137 static int cardhu_left_ov5650_power_on(void)
138 {
139         /* Boards E1198 and E1291 are of Cardhu personality
140          * and donot have TCA6416 exp for camera */
141         if ((board_info.board_id == BOARD_E1198) ||
142                 (board_info.board_id == BOARD_E1291)) {
143
144                 if (cardhu_vdd_2v8_cam1 == NULL) {
145                         cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
146                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
147                                 pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
148                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
149                                 goto reg_alloc_fail;
150                         }
151                 }
152                 regulator_enable(cardhu_vdd_2v8_cam1);
153                 mdelay(5);
154         }
155
156         /* Enable VDD_1V8_Cam1 */
157         if (cardhu_1v8_cam1 == NULL) {
158                 cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
159                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
160                         pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
161                                 __func__, PTR_ERR(cardhu_1v8_cam1));
162                         goto reg_alloc_fail;
163                 }
164         }
165         regulator_enable(cardhu_1v8_cam1);
166
167         mdelay(5);
168         if ((board_info.board_id == BOARD_E1198) ||
169                 (board_info.board_id == BOARD_E1291)) {
170                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
171                 mdelay(20);
172                 gpio_direction_output(OV5650_RESETN_GPIO, 0);
173                 mdelay(100);
174                 gpio_direction_output(OV5650_RESETN_GPIO, 1);
175         }
176
177         if (board_info.board_id == BOARD_PM269) {
178                 gpio_direction_output(CAM1_RST_L_GPIO, 0);
179                 mdelay(100);
180                 gpio_direction_output(CAM1_RST_L_GPIO, 1);
181         }
182
183         return 0;
184
185 reg_alloc_fail:
186         if (cardhu_1v8_cam1) {
187                 regulator_put(cardhu_1v8_cam1);
188                 cardhu_1v8_cam1 = NULL;
189         }
190         if (cardhu_vdd_2v8_cam1) {
191                 regulator_put(cardhu_vdd_2v8_cam1);
192                 cardhu_vdd_2v8_cam1 = NULL;
193         }
194
195         return -ENODEV;
196
197 }
198
199 static int cardhu_left_ov5650_power_off(void)
200 {
201         /* Boards E1198 and E1291 are of Cardhu personality
202          * and donot have TCA6416 exp for camera */
203         if ((board_info.board_id == BOARD_E1198) ||
204                 (board_info.board_id == BOARD_E1291)) {
205                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
206                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
207                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
208         }
209         if (cardhu_1v8_cam1)
210                 regulator_disable(cardhu_1v8_cam1);
211         if (cardhu_vdd_2v8_cam1)
212                 regulator_disable(cardhu_vdd_2v8_cam1);
213
214         return 0;
215 }
216
217 struct ov5650_platform_data cardhu_left_ov5650_data = {
218         .power_on = cardhu_left_ov5650_power_on,
219         .power_off = cardhu_left_ov5650_power_off,
220 };
221
222 #ifdef CONFIG_VIDEO_OV14810
223 static int cardhu_ov14810_power_on(void)
224 {
225         if (board_info.board_id == BOARD_E1198) {
226                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
227                 mdelay(20);
228                 gpio_direction_output(OV14810_RESETN_GPIO, 0);
229                 mdelay(100);
230                 gpio_direction_output(OV14810_RESETN_GPIO, 1);
231         }
232
233         return 0;
234 }
235
236 static int cardhu_ov14810_power_off(void)
237 {
238         if (board_info.board_id == BOARD_E1198) {
239                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
240                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
241                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
242         }
243
244         return 0;
245 }
246
247 struct ov14810_platform_data cardhu_ov14810_data = {
248         .power_on = cardhu_ov14810_power_on,
249         .power_off = cardhu_ov14810_power_off,
250 };
251
252 struct ov14810_platform_data cardhu_ov14810uC_data = {
253         .power_on = NULL,
254         .power_off = NULL,
255 };
256
257 struct ov14810_platform_data cardhu_ov14810SlaveDev_data = {
258         .power_on = NULL,
259         .power_off = NULL,
260 };
261
262 static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
263         {
264                 I2C_BOARD_INFO("ov14810", 0x36),
265                 .platform_data = &cardhu_ov14810_data,
266         },
267         {
268                 I2C_BOARD_INFO("ov14810uC", 0x67),
269                 .platform_data = &cardhu_ov14810uC_data,
270         },
271         {
272                 I2C_BOARD_INFO("ov14810SlaveDev", 0x69),
273                 .platform_data = &cardhu_ov14810SlaveDev_data,
274         }
275 };
276 #endif
277
278 static int cardhu_right_ov5650_power_on(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
285                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
286                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
287                 mdelay(10);
288
289                 if (cardhu_vdd_2v8_cam2 == NULL) {
290                         cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
291                         if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
292                                 pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
293                                         __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
294                                 goto reg_alloc_fail;
295                         }
296                 }
297                 regulator_enable(cardhu_vdd_2v8_cam2);
298                 mdelay(5);
299         }
300
301         /* Enable VDD_1V8_Cam2 */
302         if (cardhu_1v8_cam2 == NULL) {
303                 cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
304                 if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
305                         pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
306                                 __func__, PTR_ERR(cardhu_1v8_cam2));
307                         goto reg_alloc_fail;
308                 }
309         }
310         regulator_enable(cardhu_1v8_cam2);
311
312         mdelay(5);
313
314         if (board_info.board_id == BOARD_PM269) {
315                 gpio_direction_output(CAM2_RST_L_GPIO, 0);
316                 mdelay(100);
317                 gpio_direction_output(CAM2_RST_L_GPIO, 1);
318         }
319
320         return 0;
321
322 reg_alloc_fail:
323         if (cardhu_1v8_cam2) {
324                 regulator_put(cardhu_1v8_cam2);
325                 cardhu_1v8_cam2 = NULL;
326         }
327         if (cardhu_vdd_2v8_cam2) {
328                 regulator_put(cardhu_vdd_2v8_cam2);
329                 cardhu_vdd_2v8_cam2 = NULL;
330         }
331
332         return -ENODEV;
333
334 }
335
336 static int cardhu_right_ov5650_power_off(void)
337 {
338         /* Boards E1198 and E1291 are of Cardhu personality
339          * and donot have TCA6416 exp for camera */
340         if ((board_info.board_id == BOARD_E1198) ||
341                 (board_info.board_id == BOARD_E1291)) {
342                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
343                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
344                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
345         }
346
347         if (cardhu_1v8_cam2)
348                 regulator_disable(cardhu_1v8_cam2);
349         if (cardhu_vdd_2v8_cam2)
350                 regulator_disable(cardhu_vdd_2v8_cam2);
351
352         return 0;
353 }
354
355 static void cardhu_ov5650_synchronize_sensors(void)
356 {
357         if (board_info.board_id == BOARD_E1198) {
358                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
359                 mdelay(50);
360                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
361                 mdelay(50);
362         }
363         else if (board_info.board_id == BOARD_E1291) {
364                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
365                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
366                 mdelay(50);
367                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
368                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
369                 mdelay(50);
370         }
371         else
372                 pr_err("%s: UnSupported BoardId\n", __func__);
373 }
374
375 struct ov5650_platform_data cardhu_right_ov5650_data = {
376         .power_on = cardhu_right_ov5650_power_on,
377         .power_off = cardhu_right_ov5650_power_off,
378         .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
379 };
380
381 static int cardhu_ov2710_power_on(void)
382 {
383         /* CSI-B and front sensor are muxed on verbier */
384         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
385
386         /* Boards E1198 and E1291 are of Cardhu personality
387          * and donot have TCA6416 exp for camera */
388         if ((board_info.board_id == BOARD_E1198) ||
389                 (board_info.board_id == BOARD_E1291)) {
390
391                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
392                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
393                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
394                 mdelay(10);
395
396                 if (cardhu_vdd_cam3 == NULL) {
397                         cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
398                         if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
399                                 pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
400                                         __func__, PTR_ERR(cardhu_vdd_cam3));
401                                 goto reg_alloc_fail;
402                         }
403                 }
404                 regulator_enable(cardhu_vdd_cam3);
405         }
406
407         /* Enable VDD_1V8_Cam3 */
408         if (cardhu_1v8_cam3 == NULL) {
409                 cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
410                 if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
411                         pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
412                                 __func__, PTR_ERR(cardhu_1v8_cam3));
413                         goto reg_alloc_fail;
414                 }
415         }
416         regulator_enable(cardhu_1v8_cam3);
417         mdelay(5);
418
419         return 0;
420
421 reg_alloc_fail:
422         if (cardhu_1v8_cam3) {
423                 regulator_put(cardhu_1v8_cam3);
424                 cardhu_1v8_cam3 = NULL;
425         }
426         if (cardhu_vdd_cam3) {
427                 regulator_put(cardhu_vdd_cam3);
428                 cardhu_vdd_cam3 = NULL;
429         }
430
431         return -ENODEV;
432 }
433
434 static int cardhu_ov2710_power_off(void)
435 {
436         gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
437
438         /* Boards E1198 and E1291 are of Cardhu personality
439          * and donot have TCA6416 exp for camera */
440         if ((board_info.board_id == BOARD_E1198) ||
441                 (board_info.board_id == BOARD_E1291)) {
442                 gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
443                 gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
444                 gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
445         }
446
447         if (cardhu_1v8_cam3)
448                 regulator_disable(cardhu_1v8_cam3);
449         if (cardhu_vdd_cam3)
450                 regulator_disable(cardhu_vdd_cam3);
451
452         return 0;
453 }
454
455 struct ov2710_platform_data cardhu_ov2710_data = {
456         .power_on = cardhu_ov2710_power_on,
457         .power_off = cardhu_ov2710_power_off,
458 };
459
460 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
461         {
462                 I2C_BOARD_INFO("pca9546", 0x70),
463                 .platform_data = &cardhu_pca954x_data,
464         },
465 };
466
467 static struct sh532u_platform_data sh532u_left_pdata = {
468         .num            = 1,
469         .sync           = 2,
470         .dev_name       = "focuser",
471         .gpio_reset     = TEGRA_GPIO_PBB0,
472 };
473
474 static struct sh532u_platform_data sh532u_right_pdata = {
475         .num            = 2,
476         .sync           = 1,
477         .dev_name       = "focuser",
478         .gpio_reset     = TEGRA_GPIO_PBB0,
479 };
480
481 static bool cardhu_tps61050_pm_flag = 0;
482
483 static struct tps61050_pin_state cardhu_tps61050_pinstate = {
484         .mask           = 0x0008, /*VGP3*/
485         .values         = 0x0008,
486 };
487
488 static int cardhu_tps61050_pm(int pwr)
489 {
490         switch (pwr) {
491         case TPS61050_PWR_OFF:
492                 if (cardhu_tps61050_pm_flag && cardhu_1v8_cam1) {
493                         regulator_disable(cardhu_1v8_cam1);
494                         cardhu_tps61050_pm_flag = 0;
495                 }
496                 return 0;
497
498         case TPS61050_PWR_STDBY:
499         case TPS61050_PWR_COMM:
500         case TPS61050_PWR_ON:
501                 if (!cardhu_tps61050_pm_flag) {
502                         if (cardhu_1v8_cam1 == NULL) {
503                                 cardhu_1v8_cam1 =
504                                         regulator_get(NULL, "vdd_1v8_cam1");
505                                 if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
506                                         pr_err("%s: err: %ld\n",
507                                                 __func__,
508                                                 PTR_ERR(cardhu_1v8_cam1));
509                                         regulator_put(cardhu_1v8_cam1);
510                                         cardhu_1v8_cam1 = NULL;
511                                 }
512                         }
513                         regulator_enable(cardhu_1v8_cam1);
514                         cardhu_tps61050_pm_flag = 1;
515                         mdelay(5);
516                 }
517                 return 0;
518
519         default:
520                 return -1;
521         }
522 }
523
524 static struct tps61050_platform_data cardhu_tps61050_data = {
525         .cfg            = 0,
526         .num            = 1,
527         .max_amp_torch  = CAMERA_FLASH_MAX_TORCH_AMP,
528         .max_amp_flash  = CAMERA_FLASH_MAX_FLASH_AMP,
529         .pinstate       = &cardhu_tps61050_pinstate,
530         .init           = NULL,
531         .exit           = NULL,
532         .pm             = cardhu_tps61050_pm,
533         .gpio_envm      = NULL,
534         .gpio_sync      = NULL,
535 };
536
537 static const struct i2c_board_info cardhu_i2c_board_info_tps61050[] = {
538         {
539                 I2C_BOARD_INFO("tps61050", 0x33),
540                 .platform_data = &cardhu_tps61050_data,
541         },
542 };
543
544 static struct i2c_board_info cardhu_i2c6_board_info[] = {
545         {
546                 I2C_BOARD_INFO("ov5650L", 0x36),
547                 .platform_data = &cardhu_left_ov5650_data,
548         },
549         {
550                 I2C_BOARD_INFO("sh532u", 0x72),
551                 .platform_data = &sh532u_left_pdata,
552         },
553 };
554
555 static struct i2c_board_info cardhu_i2c7_board_info[] = {
556         {
557                 I2C_BOARD_INFO("ov5650R", 0x36),
558                 .platform_data = &cardhu_right_ov5650_data,
559         },
560         {
561                 I2C_BOARD_INFO("sh532u", 0x72),
562                 .platform_data = &sh532u_right_pdata,
563         },
564 };
565
566 static struct i2c_board_info cardhu_i2c8_board_info[] = {
567         {
568                 I2C_BOARD_INFO("ov2710", 0x36),
569                 .platform_data = &cardhu_ov2710_data,
570         },
571 };
572
573 #ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
574 static int nct_get_temp(void *_data, long *temp)
575 {
576         struct nct1008_data *data = _data;
577         return nct1008_thermal_get_temp(data, temp);
578 }
579
580 static int nct_set_limits(void *_data,
581                         long lo_limit_milli,
582                         long hi_limit_milli)
583 {
584         struct nct1008_data *data = _data;
585         return nct1008_thermal_set_limits(data,
586                                         lo_limit_milli,
587                                         hi_limit_milli);
588 }
589
590 static int nct_set_alert(void *_data,
591                                 void (*alert_func)(void *),
592                                 void *alert_data)
593 {
594         struct nct1008_data *data = _data;
595         return nct1008_thermal_set_alert(data, alert_func, alert_data);
596 }
597
598 static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
599 {
600         struct nct1008_data *data = _data;
601         return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
602 }
603 static void nct1008_probe_callback(struct nct1008_data *data)
604 {
605         struct tegra_thermal_device *thermal_device;
606
607         thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
608                                         GFP_KERNEL);
609         if (!thermal_device) {
610                 pr_err("unable to allocate thermal device\n");
611                 return;
612         }
613
614         thermal_device->data = data;
615         thermal_device->offset = TDIODE_OFFSET;
616         thermal_device->get_temp = nct_get_temp;
617         thermal_device->set_limits = nct_set_limits;
618         thermal_device->set_alert = nct_set_alert;
619         thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
620
621         tegra_thermal_set_device(thermal_device);
622 }
623 #endif
624
625 static struct nct1008_platform_data cardhu_nct1008_pdata = {
626         .supported_hwrev = true,
627         .ext_range = true,
628         .conv_rate = 0x08,
629         .hysteresis = 5,
630         .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
631         .shutdown_ext_limit = 90,
632         .shutdown_local_limit = 90,
633         .throttling_ext_limit = 85,
634         .alarm_fn = tegra_throttling_enable,
635 #ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
636         .probe_callback = nct1008_probe_callback,
637 #endif
638 };
639
640 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
641         {
642                 I2C_BOARD_INFO("bq27510", 0x55),
643         },
644 };
645
646 static struct i2c_board_info cardhu_i2c4_nct1008_board_info[] = {
647         {
648                 I2C_BOARD_INFO("nct1008", 0x4C),
649                 .platform_data = &cardhu_nct1008_pdata,
650                 .irq = -1,
651         }
652 };
653
654 static int cardhu_nct1008_init(void)
655 {
656         int nct1008_port = -1;
657         int ret;
658 #ifdef CONFIG_TEGRA_EDP_LIMITS
659         const struct tegra_edp_limits *z;
660         int zones_sz;
661         int i;
662         bool throttle_ok = false;
663 #endif
664
665         if ((board_info.board_id == BOARD_E1198) ||
666                 (board_info.board_id == BOARD_E1291) ||
667                 (board_info.board_id == BOARD_E1257) ||
668                 (board_info.board_id == BOARD_PM269) ||
669                 (board_info.board_id == BOARD_PM305) ||
670                 (board_info.board_id == BOARD_PM311)) {
671                 nct1008_port = TEGRA_GPIO_PCC2;
672         } else if ((board_info.board_id == BOARD_E1186) ||
673                 (board_info.board_id == BOARD_E1187) ||
674                 (board_info.board_id == BOARD_E1256)) {
675                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
676                 /* nct1008_port = TEGRA_GPIO_PH7; */
677         }
678
679         if (nct1008_port >= 0) {
680                 /* FIXME: enable irq when throttling is supported */
681                 cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
682
683                 ret = gpio_request(nct1008_port, "temp_alert");
684                 if (ret < 0)
685                         return ret;
686
687                 ret = gpio_direction_input(nct1008_port);
688                 if (ret < 0)
689                         gpio_free(nct1008_port);
690                 else
691                         tegra_gpio_enable(nct1008_port);
692         }
693
694 #ifdef CONFIG_TEGRA_EDP_LIMITS
695         tegra_get_cpu_edp_limits(&z, &zones_sz);
696         zones_sz = min(zones_sz, MAX_ZONES);
697         for (i = 0; i < zones_sz; i++) {
698                 cardhu_nct1008_pdata.thermal_zones[i] = z[i].temperature;
699                 if (cardhu_nct1008_pdata.thermal_zones[i] ==
700                     cardhu_nct1008_pdata.throttling_ext_limit) {
701                         throttle_ok = true;
702                 }
703         }
704
705         if (throttle_ok != true)
706                 pr_warn("%s: WARNING! Throttling limit %dC would be inaccurate"
707                         " as it is NOT one of the EDP points\n",
708                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
709         else
710                 pr_info("%s: Throttling limit %dC OK\n",
711                         __func__, cardhu_nct1008_pdata.throttling_ext_limit);
712
713         cardhu_nct1008_pdata.thermal_zones_sz = zones_sz;
714 #endif
715         return ret;
716 }
717
718 #if defined(CONFIG_GPIO_PCA953X)
719 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
720         .gpio_base      = PMU_TCA6416_GPIO_BASE,
721 };
722
723 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
724         {
725                 I2C_BOARD_INFO("tca6416", 0x20),
726                 .platform_data = &cardhu_pmu_tca6416_data,
727         },
728 };
729
730 static struct pca953x_platform_data cardhu_cam_tca6416_data = {
731         .gpio_base      = CAM_TCA6416_GPIO_BASE,
732 };
733
734 static const struct i2c_board_info cardhu_i2c2_board_info_tca6416[] = {
735         {
736                 I2C_BOARD_INFO("tca6416", 0x20),
737                 .platform_data = &cardhu_cam_tca6416_data,
738         },
739 };
740
741 static int __init pmu_tca6416_init(void)
742 {
743         if ((board_info.board_id == BOARD_E1198) ||
744                 (board_info.board_id == BOARD_E1291))
745                         return 0;
746
747         pr_info("Registering pmu pca6416\n");
748         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
749                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
750         return 0;
751 }
752
753 static int __init cam_tca6416_init(void)
754 {
755         /* Boards E1198 and E1291 are of Cardhu personality
756          * and donot have TCA6416 exp for camera */
757         if ((board_info.board_id == BOARD_E1198) ||
758                 (board_info.board_id == BOARD_E1291))
759                 return 0;
760
761         pr_info("Registering cam pca6416\n");
762         i2c_register_board_info(2, cardhu_i2c2_board_info_tca6416,
763                 ARRAY_SIZE(cardhu_i2c2_board_info_tca6416));
764         return 0;
765 }
766 #else
767 static int __init pmu_tca6416_init(void)
768 {
769         return 0;
770 }
771
772 static int __init cam_tca6416_init(void)
773 {
774         return 0;
775 }
776 #endif
777
778 #ifdef CONFIG_MPU_SENSORS_MPU3050
779 #define SENSOR_MPU_NAME "mpu3050"
780 static struct mpu3050_platform_data mpu3050_data = {
781         .int_config  = 0x10,
782         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
783         .level_shifter = 0,
784
785         .accel = {
786         .get_slave_descr = get_accel_slave_descr,
787         .adapt_num   = 2,
788         .bus         = EXT_SLAVE_BUS_SECONDARY,
789         .address     = 0x0F,
790         .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
791         },
792
793         .compass = {
794         .get_slave_descr = get_compass_slave_descr,
795         .adapt_num   = 2,
796         .bus         = EXT_SLAVE_BUS_PRIMARY,
797         .address     = 0x0C,
798         .orientation = { 1, 0, 0, 0, 1, 0, 0, 0, 1 },  /* Orientation matrix for AKM on cardhu */
799         },
800 };
801
802 static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
803         {
804                 I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
805                 .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
806                 .platform_data = &mpu3050_data,
807         },
808 };
809
810 static void cardhu_mpuirq_init(void)
811 {
812         pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
813         tegra_gpio_enable(TEGRA_GPIO_PX1);
814         gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
815         gpio_direction_input(TEGRA_GPIO_PX1);
816         pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
817
818         i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
819                 ARRAY_SIZE(mpu3050_i2c0_boardinfo));
820 }
821 #endif
822
823
824 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
825         {
826                 I2C_BOARD_INFO("isl29028", 0x44),
827         }
828 };
829
830 int __init cardhu_sensors_init(void)
831 {
832         int err;
833
834         tegra_get_board_info(&board_info);
835
836         cardhu_camera_init();
837         cam_tca6416_init();
838
839         i2c_register_board_info(2, cardhu_i2c3_board_info,
840                 ARRAY_SIZE(cardhu_i2c3_board_info));
841
842         i2c_register_board_info(2, cardhu_i2c_board_info_tps61050,
843                 ARRAY_SIZE(cardhu_i2c_board_info_tps61050));
844
845 #ifdef CONFIG_VIDEO_OV14810
846         /* This is disabled by default; To enable this change Kconfig;
847          * there should be some way to detect dynamically which board
848          * is connected (E1211/E1214), till that time sensor selection
849          * logic is static;
850          * e1214 corresponds to ov14810 sensor */
851         i2c_register_board_info(2, cardhu_i2c_board_info_e1214,
852                 ARRAY_SIZE(cardhu_i2c_board_info_e1214));
853 #else
854         /* Left  camera is on PCA954x's I2C BUS0, Right camera is on BUS1 &
855          * Front camera is on BUS2 */
856         i2c_register_board_info(PCA954x_I2C_BUS0, cardhu_i2c6_board_info,
857                 ARRAY_SIZE(cardhu_i2c6_board_info));
858
859         i2c_register_board_info(PCA954x_I2C_BUS1, cardhu_i2c7_board_info,
860                 ARRAY_SIZE(cardhu_i2c7_board_info));
861
862         i2c_register_board_info(PCA954x_I2C_BUS2, cardhu_i2c8_board_info,
863                 ARRAY_SIZE(cardhu_i2c8_board_info));
864
865 #endif
866         pmu_tca6416_init();
867
868         if (board_info.board_id == BOARD_E1291)
869                 i2c_register_board_info(4, cardhu_i2c4_bq27510_board_info,
870                         ARRAY_SIZE(cardhu_i2c4_bq27510_board_info));
871
872         i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
873                 ARRAY_SIZE(cardhu_i2c2_isl_board_info));
874
875         err = cardhu_nct1008_init();
876         if (err)
877                 return err;
878
879         i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
880                 ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
881
882 #ifdef CONFIG_MPU_SENSORS_MPU3050
883         cardhu_mpuirq_init();
884 #endif
885         return 0;
886 }
887
888 #if defined(CONFIG_GPIO_PCA953X)
889 struct ov5650_gpios {
890         const char *name;
891         int gpio;
892         int enabled;
893 };
894
895 #define OV5650_GPIO(_name, _gpio, _enabled)             \
896         {                                               \
897                 .name = _name,                          \
898                 .gpio = _gpio,                          \
899                 .enabled = _enabled,                    \
900         }
901
902 static struct ov5650_gpios ov5650_gpio_keys[] = {
903         [0] = OV5650_GPIO("cam1_pwdn", CAM1_PWR_DN_GPIO, 0),
904         [1] = OV5650_GPIO("cam1_rst_lo", CAM1_RST_L_GPIO, 1),
905         [2] = OV5650_GPIO("cam1_af_pwdn_lo", CAM1_AF_PWR_DN_L_GPIO, 0),
906         [3] = OV5650_GPIO("cam1_ldo_shdn_lo", CAM1_LDO_SHUTDN_L_GPIO, 1),
907         [4] = OV5650_GPIO("cam2_pwdn", CAM2_PWR_DN_GPIO, 0),
908         [5] = OV5650_GPIO("cam2_rst_lo", CAM2_RST_L_GPIO, 1),
909         [6] = OV5650_GPIO("cam2_af_pwdn_lo", CAM2_AF_PWR_DN_L_GPIO, 0),
910         [7] = OV5650_GPIO("cam2_ldo_shdn_lo", CAM2_LDO_SHUTDN_L_GPIO, 1),
911         [8] = OV5650_GPIO("cam3_pwdn", CAM_FRONT_PWR_DN_GPIO, 0),
912         [9] = OV5650_GPIO("cam3_rst_lo", CAM_FRONT_RST_L_GPIO, 1),
913         [10] = OV5650_GPIO("cam3_af_pwdn_lo", CAM_FRONT_AF_PWR_DN_L_GPIO, 0),
914         [11] = OV5650_GPIO("cam3_ldo_shdn_lo", CAM_FRONT_LDO_SHUTDN_L_GPIO, 1),
915         [12] = OV5650_GPIO("cam_led_exp", CAM_FRONT_LED_EXP, 1),
916         [13] = OV5650_GPIO("cam_led_rear_exp", CAM_SNN_LED_REAR_EXP, 1),
917         [14] = OV5650_GPIO("cam_i2c_mux_rst", CAM_I2C_MUX_RST_EXP, 1),
918 };
919
920 int __init cardhu_ov5650_late_init(void)
921 {
922         int ret;
923         int i;
924
925         if (!machine_is_cardhu())
926                 return 0;
927
928         if ((board_info.board_id == BOARD_E1198) ||
929                 (board_info.board_id == BOARD_E1291))
930                 return 0;
931
932         printk("%s: \n", __func__);
933         for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
934                 ret = gpio_request(ov5650_gpio_keys[i].gpio,
935                         ov5650_gpio_keys[i].name);
936                 if (ret < 0) {
937                         printk("%s: gpio_request failed for gpio #%d\n",
938                                 __func__, i);
939                         goto fail;
940                 }
941                 printk("%s: enable - %d\n", __func__, i);
942                 gpio_direction_output(ov5650_gpio_keys[i].gpio,
943                         ov5650_gpio_keys[i].enabled);
944                 gpio_export(ov5650_gpio_keys[i].gpio, false);
945         }
946
947         return 0;
948
949 fail:
950         while (i--)
951                 gpio_free(ov5650_gpio_keys[i].gpio);
952         return ret;
953 }
954
955 late_initcall(cardhu_ov5650_late_init);
956 #endif