arm: tegra: pluto: enable charger interrupt
[linux-3.10.git] / arch / arm / mach-tegra / board-pluto-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-pluto-sensors.c
3  *
4  * Copyright (c) 2012-2013, NVIDIA CORPORATION.  All rights reserved.
5
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 #include <linux/i2c.h>
19 #include <linux/delay.h>
20 #include <linux/regulator/consumer.h>
21 #include <linux/gpio.h>
22 #include <linux/mpu.h>
23 #include <linux/max77665-charger.h>
24 #include <linux/mfd/max77665.h>
25 #include <linux/input/max77665-haptic.h>
26 #include <linux/power/max17042_battery.h>
27 #include <linux/nct1008.h>
28 #include <linux/interrupt.h>
29 #include <mach/edp.h>
30 #include <linux/edp.h>
31 #include <mach/gpio-tegra.h>
32 #include <mach/pinmux-t11.h>
33 #include <mach/pinmux.h>
34 #include <media/max77665-flash.h>
35 #include <media/imx091.h>
36 #include <media/imx132.h>
37 #include <media/ad5816.h>
38 #include <asm/mach-types.h>
39
40 #include "gpio-names.h"
41 #include "board.h"
42 #include "board-common.h"
43 #include "board-pluto.h"
44 #include "cpu-tegra.h"
45 #include "devices.h"
46 #include "tegra-board-id.h"
47 #include "dvfs.h"
48
49 #define NTC_10K_TGAIN   0xE6A2
50 #define NTC_10K_TOFF    0x2694
51 #define MAX77665_CHARGER_INT    TEGRA_GPIO_PJ2
52
53 static struct nvc_gpio_pdata imx091_gpio_pdata[] = {
54         {IMX091_GPIO_RESET, CAM_RSTN, true, false},
55         {IMX091_GPIO_PWDN, CAM1_POWER_DWN_GPIO, true, false},
56         {IMX091_GPIO_GP1, CAM_GPIO1, true, false}
57 };
58
59 static struct board_info board_info;
60 static struct max17042_config_data conf_data = {
61         .valrt_thresh = 0xff00,
62         .talrt_thresh = 0xff00,
63         .soc_alrt_thresh = 0xff00,
64         .shdntimer = 0xe000,
65         .design_cap = 0x07d0,
66         .at_rate = 0x0000,
67         .tgain = NTC_10K_TGAIN,
68         .toff = NTC_10K_TOFF,
69         .vempty = 0xACDA,
70         .qrtbl00 = 0x5C80,
71         .qrtbl10 = 0x438C,
72         .qrtbl20 = 0x1198,
73         .qrtbl30 = 0x0E19,
74         .full_soc_thresh = 0x5A00,
75         .rcomp0 = 0x0077,
76         .tcompc0 = 0x1F2A,
77         .ichgt_term = 0x0320,
78         .temp_nom = 0x1400,
79         .temp_lim = 0x2305,
80         .filter_cfg = 0x87A4,
81         .config = 0x2210,
82         .learn_cfg = 0x2606,
83         .misc_cfg = 0x0810,
84         .fullcap =  0x07d0,
85         .fullcapnom = 0x07d0,
86         .lavg_empty = 0x1000,
87         .dqacc = 0x01f4,
88         .dpacc = 0x3200,
89         .fctc = 0x05e0,
90         .kempty0 = 0x0600,
91         .cell_technology = POWER_SUPPLY_TECHNOLOGY_LION,
92         .cell_char_tbl = {
93                 /* Data to be written from 0x80h */
94                 0x9180, 0xA4C0, 0xB6A0, 0xB760, 0xB980, 0xBB30,
95                 0xBBC0, 0xBC50, 0xBD50, 0xBE50, 0xBF80, 0xC290,
96                 0xC470, 0xC7D0, 0xCC40, 0xCFB0,
97                 /* Data to be written from 0x90h */
98                 0x00C0, 0x0200, 0x1C10, 0x0B00, 0x0900, 0x1F00,
99                 0x1F00, 0x23C0, 0x1990, 0x19F0, 0x09A0, 0x0CE0,
100                 0x0BE0, 0x07D0, 0x0990, 0x0990,
101                 /* Data to be written from 0xA0h */
102                 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
103                 0x0100, 0x0100, 0x0100, 0x0100, 0x0100, 0x0100,
104                 0x0100, 0x0100, 0x0100, 0x0100,
105         },
106 };
107
108 static unsigned int bat_depl_states[] = {
109         900, 800, 700, 600, 500, 400, 300, 200, 100, 0
110 };
111
112 static struct edp_client bat_depl_client = {
113         .states = bat_depl_states,
114         .num_states = ARRAY_SIZE(bat_depl_states),
115         .e0_index = 0,
116         .priority = EDP_MAX_PRIO
117 };
118
119 static struct max17042_platform_data max17042_pdata = {
120         .config_data = &conf_data,
121         .init_data  = NULL,
122         .num_init_data = 0,
123         .enable_por_init = 1, /* Use POR init from Maxim appnote */
124         .enable_current_sense = 1,
125         .r_sns = 0,
126         .edp_client = &bat_depl_client
127 };
128
129 static struct i2c_board_info max17042_device[] = {
130         {
131                 I2C_BOARD_INFO("max17042", 0x36),
132                 .platform_data = &max17042_pdata,
133         },
134 };
135
136 static struct nvc_torch_lumi_level_v1 pluto_max77665_lumi_tbl[] = {
137         {0, 100000},
138         {1, 201690},
139         {2, 298080},
140         {3, 387700},
141         {4, 479050},
142         {5, 562000},
143         {6, 652560},
144         {7, 732150},
145         {8, 816050},
146         {9, 896710},
147         {10, 976890},
148         {11, 1070160},
149         {12, 1151000},
150         {13, 1227790},
151         {14, 1287690},
152         {15, 1375060},
153 };
154
155 static unsigned max77665_f_estates[] = {1000, 800, 600, 400, 200, 100, 0};
156
157 static struct max77665_f_platform_data pluto_max77665_flash_pdata = {
158         .config         = {
159                 .led_mask               = 3,
160                 /* set to true only when using the torch strobe input
161                  * to trigger the flash.
162                  */
163                 .flash_on_torch         = false,
164                 /* use ONE-SHOOT flash mode - flash triggered at the
165                  * raising edge of strobe or strobe signal.
166                  */
167                 .flash_mode             = 1,
168                 /* .flash_on_torch         = true, */
169                 .max_total_current_mA   = 1000,
170                 .max_peak_current_mA    = 600,
171                 .led_config[0] = {
172                         .flash_torch_ratio = 18100,
173                         .granularity = 1000,
174                         .flash_levels = ARRAY_SIZE(pluto_max77665_lumi_tbl),
175                         .lumi_levels = pluto_max77665_lumi_tbl,
176                         },
177                 .led_config[1] = {
178                         .flash_torch_ratio = 18100,
179                         .granularity = 1000,
180                         .flash_levels = ARRAY_SIZE(pluto_max77665_lumi_tbl),
181                         .lumi_levels = pluto_max77665_lumi_tbl,
182                         },
183                 },
184         .pinstate       = {
185                 .mask   = 1 << (CAM_FLASH_STROBE - TEGRA_GPIO_PBB0),
186                 .values = 1 << (CAM_FLASH_STROBE - TEGRA_GPIO_PBB0),
187                 },
188         .dev_name       = "torch",
189         .gpio_strobe    = CAM_FLASH_STROBE,
190         .edpc_config    = {
191                 .states = max77665_f_estates,
192                 .num_states = ARRAY_SIZE(max77665_f_estates),
193                 .e0_index = 3,
194                 .priority = EDP_MAX_PRIO - 2,
195                 },
196 };
197
198 static struct max77665_haptic_platform_data max77665_haptic_pdata = {
199         .pwm_channel_id = 2,
200         .pwm_period = 50,
201         .type = MAX77665_HAPTIC_LRA,
202         .mode = MAX77665_INTERNAL_MODE,
203         .internal_mode_pattern = 0,
204         .pattern_cycle = 10,
205         .pattern_signal_period = 0xD0,
206         .pwm_divisor = MAX77665_PWM_DIVISOR_128,
207         .feedback_duty_cycle = 12,
208         .invert = MAX77665_INVERT_OFF,
209         .cont_mode = MAX77665_CONT_MODE,
210         .motor_startup_val = 0,
211         .scf_val = 2,
212         .edp_states = {90, 0},
213 };
214
215 static struct max77665_charger_cable maxim_cable[] = {
216         {
217                 .name           = "USB",
218         },
219         {
220                 .name           = "USB-Host",
221         },
222         {
223                 .name           = "TA",
224         },
225         {
226                 .name           = "Fast-charger",
227         },
228         {
229                 .name           = "Slow-charger",
230         },
231         {
232                 .name           = "Charge-downstream",
233         },
234 };
235
236 static struct max77665_charger_plat_data max77665_charger = {
237         .fast_chg_cc = 1500, /* fast charger current*/
238         .term_volt = 3700, /* charger termination voltage */
239         .curr_lim = 1500, /* input current limit */
240         .num_cables = MAX_CABLES,
241         .cables = maxim_cable,
242         .irq_base = MAX77665_TEGRA_IRQ_BASE,
243         .update_status = max17042_update_status,
244 };
245
246 static struct max77665_muic_platform_data max77665_muic = {
247         .irq_base = 0,
248 };
249
250 static struct max77665_platform_data pluto_max77665_pdata = {
251         .irq_base = MAX77665_TEGRA_IRQ_BASE,
252         .irq_flag = IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
253         .muic_platform_data = {
254                 .pdata = &max77665_muic,
255                 .size = sizeof(max77665_muic),
256                 },
257         .charger_platform_data = {
258                 .pdata = &max77665_charger,
259                 .size = sizeof(max77665_charger),
260                 },
261         .flash_platform_data = {
262                 .pdata = &pluto_max77665_flash_pdata,
263                 .size = sizeof(pluto_max77665_flash_pdata),
264                 },
265         .haptic_platform_data = {
266                 .pdata = &max77665_haptic_pdata,
267                 .size = sizeof(max77665_haptic_pdata),
268                 },
269 };
270
271 static struct i2c_board_info pluto_i2c_board_info_max77665[] = {
272         {
273                 I2C_BOARD_INFO("max77665", 0x66),
274                 .platform_data = &pluto_max77665_pdata,
275         },
276 };
277
278 /* isl29029 support is provided by isl29028*/
279 static struct i2c_board_info pluto_i2c1_isl_board_info[] = {
280         {
281                 I2C_BOARD_INFO("isl29028", 0x44),
282         }
283 };
284
285 static struct throttle_table tj_throttle_table[] = {
286         {      0, 1000 },
287         {  51000, 1000 },
288         { 102000, 1000 },
289         { 204000, 1000 },
290         { 252000, 1000 },
291         { 288000, 1000 },
292         { 372000, 1000 },
293         { 468000, 1000 },
294         { 510000, 1000 },
295         { 612000, 1000 },
296         { 714000, 1050 },
297         { 816000, 1050 },
298         { 918000, 1050 },
299         {1020000, 1100 },
300         {1122000, 1100 },
301         {1224000, 1100 },
302         {1326000, 1100 },
303         {1428000, 1100 },
304         {1530000, 1100 },
305 };
306
307 static struct balanced_throttle tj_throttle = {
308         .throt_tab_size = ARRAY_SIZE(tj_throttle_table),
309         .throt_tab = tj_throttle_table,
310 };
311
312 static int __init pluto_throttle_init(void)
313 {
314         if (machine_is_tegra_pluto())
315                 balanced_throttle_register(&tj_throttle, "pluto-nct");
316         return 0;
317 }
318 module_init(pluto_throttle_init);
319
320 static struct nct1008_platform_data pluto_nct1008_pdata = {
321         .supported_hwrev = true,
322         .ext_range = true,
323         .conv_rate = 0x08,
324         .offset = 0,
325         .shutdown_ext_limit = 85, /* C */
326         .shutdown_local_limit = 120, /* C */
327
328         .passive_delay = 2000,
329
330         .num_trips = 1,
331         .trips = {
332                 /* Thermal Throttling */
333                 [0] = {
334                         .cdev_type = "pluto-nct",
335                         .trip_temp = 75000,
336                         .trip_type = THERMAL_TRIP_PASSIVE,
337                         .state = THERMAL_NO_LIMIT,
338                         .hysteresis = 0,
339                 },
340         },
341 };
342
343 static struct i2c_board_info pluto_i2c4_nct1008_board_info[] = {
344         {
345                 I2C_BOARD_INFO("nct1008", 0x4C),
346                 .platform_data = &pluto_nct1008_pdata,
347                 .irq = -1,
348         }
349 };
350
351 #define VI_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _ioreset) \
352         {                                                       \
353                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
354                 .func           = TEGRA_MUX_##_mux,             \
355                 .pupd           = TEGRA_PUPD_##_pupd,           \
356                 .tristate       = TEGRA_TRI_##_tri,             \
357                 .io             = TEGRA_PIN_##_io,              \
358                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
359                 .od             = TEGRA_PIN_OD_DEFAULT,         \
360                 .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
361 }
362
363 static int pluto_focuser_power_on(struct ad5816_power_rail *pw)
364 {
365         int err;
366
367         if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
368                 return -EFAULT;
369
370         err = regulator_enable(pw->vdd_i2c);
371         if (unlikely(err))
372                 goto ad5816_vdd_i2c_fail;
373
374         err = regulator_enable(pw->vdd);
375         if (unlikely(err))
376                 goto ad5816_vdd_fail;
377
378         return 0;
379
380 ad5816_vdd_fail:
381         regulator_disable(pw->vdd_i2c);
382
383 ad5816_vdd_i2c_fail:
384         pr_err("%s FAILED\n", __func__);
385
386         return -ENODEV;
387 }
388
389 static int pluto_focuser_power_off(struct ad5816_power_rail *pw)
390 {
391         if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
392                 return -EFAULT;
393
394         regulator_disable(pw->vdd);
395         regulator_disable(pw->vdd_i2c);
396
397         return 0;
398 }
399
400 static struct tegra_pingroup_config mclk_disable =
401         VI_PINMUX(CAM_MCLK, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
402
403 static struct tegra_pingroup_config mclk_enable =
404         VI_PINMUX(CAM_MCLK, VI_ALT3, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
405
406 static struct tegra_pingroup_config pbb0_disable =
407         VI_PINMUX(GPIO_PBB0, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
408
409 static struct tegra_pingroup_config pbb0_enable =
410         VI_PINMUX(GPIO_PBB0, VI_ALT3, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
411
412 /*
413  * more regulators need to be allocated to activate the sensor devices.
414  * pluto_vcmvdd: this is a workaround due to the focuser device(AD5816) will
415  *               hook up the i2c bus if it is not powered up.
416  * pluto_i2cvdd: by default, the power supply on the i2c bus is OFF. So it
417  *               should be turned on every time any sensor device is activated.
418 */
419 static struct regulator *pluto_vcmvdd;
420 static struct regulator *pluto_i2cvdd;
421
422 static int pluto_get_extra_regulators(void)
423 {
424         if (!pluto_vcmvdd) {
425                 pluto_vcmvdd = regulator_get(NULL, "vdd_af_cam1");
426                 if (WARN_ON(IS_ERR(pluto_vcmvdd))) {
427                         pr_err("%s: can't get regulator vdd_af_cam1: %ld\n",
428                                 __func__, PTR_ERR(pluto_vcmvdd));
429                         pluto_vcmvdd = NULL;
430                         return -ENODEV;
431                 }
432         }
433
434         if (!pluto_i2cvdd) {
435                 pluto_i2cvdd = regulator_get(NULL, "vddio_cam_mb");
436                 if (unlikely(WARN_ON(IS_ERR(pluto_i2cvdd)))) {
437                         pr_err("%s: can't get regulator vddio_cam_mb: %ld\n",
438                                 __func__, PTR_ERR(pluto_i2cvdd));
439                         pluto_i2cvdd = NULL;
440                         return -ENODEV;
441                 }
442         }
443
444         return 0;
445 }
446
447 static int pluto_imx091_power_on(struct nvc_regulator *vreg)
448 {
449         int err;
450
451         if (unlikely(WARN_ON(!vreg)))
452                 return -EFAULT;
453
454         if (pluto_get_extra_regulators())
455                 goto imx091_poweron_fail;
456
457         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
458         usleep_range(10, 20);
459
460         err = regulator_enable(vreg[IMX091_VREG_AVDD].vreg);
461         if (unlikely(err))
462                 goto imx091_avdd_fail;
463
464         err = regulator_enable(vreg[IMX091_VREG_DVDD].vreg);
465         if (unlikely(err))
466                 goto imx091_dvdd_fail;
467
468         err = regulator_enable(vreg[IMX091_VREG_IOVDD].vreg);
469         if (unlikely(err))
470                 goto imx091_iovdd_fail;
471
472         usleep_range(1, 2);
473         gpio_set_value(CAM1_POWER_DWN_GPIO, 1);
474
475         tegra_pinmux_config_table(&mclk_enable, 1);
476         err = regulator_enable(pluto_i2cvdd);
477         if (unlikely(err))
478                 goto imx091_i2c_fail;
479
480         err = regulator_enable(pluto_vcmvdd);
481         if (unlikely(err))
482                 goto imx091_vcm_fail;
483         usleep_range(300, 310);
484
485         return 0;
486
487 imx091_vcm_fail:
488         regulator_disable(pluto_i2cvdd);
489
490 imx091_i2c_fail:
491         tegra_pinmux_config_table(&mclk_disable, 1);
492         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
493         regulator_disable(vreg[IMX091_VREG_IOVDD].vreg);
494
495 imx091_iovdd_fail:
496         regulator_disable(vreg[IMX091_VREG_DVDD].vreg);
497
498 imx091_dvdd_fail:
499         regulator_disable(vreg[IMX091_VREG_AVDD].vreg);
500
501 imx091_avdd_fail:
502 imx091_poweron_fail:
503         pr_err("%s FAILED\n", __func__);
504         return -ENODEV;
505 }
506
507 static int pluto_imx091_power_off(struct nvc_regulator *vreg)
508 {
509         if (unlikely(WARN_ON(!vreg)))
510                 return -EFAULT;
511
512         usleep_range(1, 2);
513         tegra_pinmux_config_table(&mclk_disable, 1);
514         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
515         usleep_range(1, 2);
516
517         regulator_disable(vreg[IMX091_VREG_IOVDD].vreg);
518         regulator_disable(vreg[IMX091_VREG_DVDD].vreg);
519         regulator_disable(vreg[IMX091_VREG_AVDD].vreg);
520         regulator_disable(pluto_i2cvdd);
521         regulator_disable(pluto_vcmvdd);
522
523         return 0;
524 }
525
526 static struct nvc_imager_cap imx091_cap = {
527         .identifier             = "IMX091",
528         .sensor_nvc_interface   = 3,
529         .pixel_types[0]         = 0x100,
530         .orientation            = 0,
531         .direction              = 0,
532         .initial_clock_rate_khz = 6000,
533         .clock_profiles[0] = {
534                 .external_clock_khz     = 24000,
535                 .clock_multiplier       = 10416667, /* value / 1,000,000 */
536         },
537         .clock_profiles[1] = {
538                 .external_clock_khz     = 0,
539                 .clock_multiplier       = 0,
540         },
541         .h_sync_edge            = 0,
542         .v_sync_edge            = 0,
543         .mclk_on_vgp0           = 0,
544         .csi_port               = 0,
545         .data_lanes             = 4,
546         .virtual_channel_id     = 0,
547         .discontinuous_clk_mode = 1,
548         .cil_threshold_settle   = 0x0,
549         .min_blank_time_width   = 16,
550         .min_blank_time_height  = 16,
551         .preferred_mode_index   = 0,
552         .focuser_guid           = NVC_FOCUS_GUID(0),
553         .torch_guid             = NVC_TORCH_GUID(0),
554         .cap_version            = NVC_IMAGER_CAPABILITIES_VERSION2,
555 };
556
557 static unsigned imx091_estates[] = {200, 100, 2};
558
559 static struct imx091_platform_data imx091_pdata = {
560         .num                    = 0,
561         .sync                   = 0,
562         .dev_name               = "camera",
563         .gpio_count             = ARRAY_SIZE(imx091_gpio_pdata),
564         .gpio                   = imx091_gpio_pdata,
565         .flash_cap              = {
566                 .sdo_trigger_enabled = 1,
567                 .adjustable_flash_timing = 1,
568         },
569         .cap                    = &imx091_cap,
570         .edpc_config    = {
571                 .states = imx091_estates,
572                 .num_states = ARRAY_SIZE(imx091_estates),
573                 .e0_index = 0,
574                 .priority = EDP_MAX_PRIO - 1,
575                 },
576         .power_on               = pluto_imx091_power_on,
577         .power_off              = pluto_imx091_power_off,
578 };
579
580 static int pluto_imx132_power_on(struct imx132_power_rail *pw)
581 {
582         int err;
583
584         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd)))
585                 return -EFAULT;
586
587         if (pluto_get_extra_regulators())
588                 goto pluto_imx132_poweron_fail;
589
590         gpio_set_value(CAM2_POWER_DWN_GPIO, 0);
591
592         tegra_pinmux_config_table(&pbb0_enable, 1);
593
594         err = regulator_enable(pluto_i2cvdd);
595         if (unlikely(err))
596                 goto imx132_i2c_fail;
597
598         err = regulator_enable(pluto_vcmvdd);
599         if (unlikely(err))
600                 goto imx132_vcm_fail;
601
602         err = regulator_enable(pw->avdd);
603         if (unlikely(err))
604                 goto imx132_avdd_fail;
605
606         err = regulator_enable(pw->dvdd);
607         if (unlikely(err))
608                 goto imx132_dvdd_fail;
609
610         err = regulator_enable(pw->iovdd);
611         if (unlikely(err))
612                 goto imx132_iovdd_fail;
613
614         usleep_range(1, 2);
615
616         gpio_set_value(CAM2_POWER_DWN_GPIO, 1);
617
618         return 0;
619
620 imx132_iovdd_fail:
621         regulator_disable(pw->dvdd);
622
623 imx132_dvdd_fail:
624         regulator_disable(pw->avdd);
625
626 imx132_avdd_fail:
627         regulator_disable(pluto_vcmvdd);
628
629 imx132_vcm_fail:
630         regulator_disable(pluto_i2cvdd);
631
632 imx132_i2c_fail:
633         tegra_pinmux_config_table(&pbb0_disable, 1);
634
635 pluto_imx132_poweron_fail:
636         pr_err("%s failed.\n", __func__);
637         return -ENODEV;
638 }
639
640 static int pluto_imx132_power_off(struct imx132_power_rail *pw)
641 {
642         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd ||
643                         !pluto_i2cvdd || !pluto_vcmvdd)))
644                 return -EFAULT;
645
646         gpio_set_value(CAM2_POWER_DWN_GPIO, 0);
647
648         usleep_range(1, 2);
649
650         regulator_disable(pw->iovdd);
651         regulator_disable(pw->dvdd);
652         regulator_disable(pw->avdd);
653
654         tegra_pinmux_config_table(&pbb0_disable, 1);
655
656         regulator_disable(pluto_vcmvdd);
657         regulator_disable(pluto_i2cvdd);
658
659         return 0;
660 }
661
662 struct imx132_platform_data pluto_imx132_data = {
663         .power_on = pluto_imx132_power_on,
664         .power_off = pluto_imx132_power_off,
665 };
666
667 static struct ad5816_platform_data pluto_ad5816_pdata = {
668         .cfg            = 0,
669         .num            = 0,
670         .sync           = 0,
671         .dev_name       = "focuser",
672         .power_on       = pluto_focuser_power_on,
673         .power_off      = pluto_focuser_power_off,
674 };
675
676 static struct i2c_board_info pluto_i2c_board_info_e1625[] = {
677         {
678                 I2C_BOARD_INFO("imx091", 0x10),
679                 .platform_data = &imx091_pdata,
680         },
681         {
682                 I2C_BOARD_INFO("imx132", 0x36),
683                 .platform_data = &pluto_imx132_data,
684         },
685         {
686                 I2C_BOARD_INFO("ad5816", 0x0E),
687                 .platform_data = &pluto_ad5816_pdata,
688         },
689 };
690
691 static int pluto_camera_init(void)
692 {
693         pr_debug("%s: ++\n", __func__);
694
695         tegra_pinmux_config_table(&mclk_disable, 1);
696         tegra_pinmux_config_table(&pbb0_disable, 1);
697
698         i2c_register_board_info(2, pluto_i2c_board_info_e1625,
699                 ARRAY_SIZE(pluto_i2c_board_info_e1625));
700
701         return 0;
702 }
703
704 /* MPU board file definition */
705 static struct mpu_platform_data mpu_gyro_data = {
706         .int_config     = 0x00,
707         .level_shifter  = 0,
708         .orientation    = MPU_GYRO_ORIENTATION,
709         .sec_slave_type = SECONDARY_SLAVE_TYPE_COMPASS,
710         .sec_slave_id   = COMPASS_ID_AK8963,
711         .secondary_i2c_addr     = MPU_COMPASS_ADDR,
712         .secondary_orientation  = MPU_COMPASS_ORIENTATION,
713         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
714                            0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
715 };
716
717 static struct i2c_board_info __initdata inv_mpu_i2c0_board_info[] = {
718         {
719                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
720                 .platform_data = &mpu_gyro_data,
721         },
722 };
723
724 static void mpuirq_init(void)
725 {
726         int ret = 0;
727         int i = 0;
728
729         pr_info("*** MPU START *** mpuirq_init...\n");
730
731         /* MPU-IRQ assignment */
732         ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
733         if (ret < 0) {
734                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
735                 return;
736         }
737
738         ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
739         if (ret < 0) {
740                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
741                 gpio_free(MPU_GYRO_IRQ_GPIO);
742                 return;
743         }
744         pr_info("*** MPU END *** mpuirq_init...\n");
745
746         inv_mpu_i2c0_board_info[i++].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
747 #if MPU_COMPASS_IRQ_GPIO
748         inv_mpu_i2c0_board_info[i++].irq = gpio_to_irq(MPU_COMPASS_IRQ_GPIO);
749 #endif
750         i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c0_board_info,
751                 ARRAY_SIZE(inv_mpu_i2c0_board_info));
752 }
753
754 static int pluto_nct1008_init(void)
755 {
756         int nct1008_port = -1;
757         int ret = 0;
758
759         if (board_info.board_id == BOARD_E1580 ||
760             board_info.board_id == BOARD_E1575) {
761                 nct1008_port = TEGRA_GPIO_PX6;
762         } else {
763                 nct1008_port = TEGRA_GPIO_PX6;
764                 pr_err("Warning: nct alert port assumed TEGRA_GPIO_PX6 for unknown pluto board id E%d\n",
765                        board_info.board_id);
766         }
767
768         if (nct1008_port >= 0) {
769                 struct nct1008_platform_data *data = &pluto_nct1008_pdata;
770 #ifdef CONFIG_TEGRA_EDP_LIMITS
771                 const struct tegra_edp_limits *cpu_edp_limits;
772                 int cpu_edp_limits_size;
773                 int i;
774                 int trip;
775                 struct nct_trip_temp *trip_state;
776
777                 /* edp capping */
778                 tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
779
780                 if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
781                         BUG();
782
783                 for (i = 0; i < cpu_edp_limits_size-1; i++) {
784                         trip = data->num_trips;
785                         trip_state = &data->trips[trip];
786
787                         trip_state->cdev_type = "edp";
788                         trip_state->trip_temp =
789                                         cpu_edp_limits[i].temperature * 1000;
790                         trip_state->trip_type = THERMAL_TRIP_ACTIVE;
791                         trip_state->state = i + 1;
792                         trip_state->hysteresis = 1000;
793
794                         data->num_trips++;
795
796                         if (data->num_trips >= NCT_MAX_TRIPS)
797                                 BUG();
798                 }
799 #endif
800                 nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
801                 nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
802                 nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_pll_cdev());
803                 nct1008_add_cdev_trips(data, tegra_dvfs_get_core_cdev());
804
805                 pluto_i2c4_nct1008_board_info[0].irq =
806                                 gpio_to_irq(nct1008_port);
807                 pr_info("%s: pluto nct1008 irq %d", __func__, pluto_i2c4_nct1008_board_info[0].irq);
808
809                 ret = gpio_request(nct1008_port, "temp_alert");
810                 if (ret < 0)
811                         return ret;
812
813                 ret = gpio_direction_input(nct1008_port);
814                 if (ret < 0) {
815                         pr_info("%s: calling gpio_free(nct1008_port)", __func__);
816                         gpio_free(nct1008_port);
817                 }
818         }
819
820         /* pluto has thermal sensor on GEN1-I2C i.e. instance 0 */
821         i2c_register_board_info(0, pluto_i2c4_nct1008_board_info,
822                 ARRAY_SIZE(pluto_i2c4_nct1008_board_info));
823
824         return ret;
825 }
826
827 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
828 static int tegra_skin_match(struct thermal_zone_device *thz, void *data)
829 {
830         return strcmp((char *)data, thz->type) == 0;
831 }
832
833 static int tegra_skin_get_temp(void *data, long *temp)
834 {
835         struct thermal_zone_device *thz;
836
837         thz = thermal_zone_device_find(data, tegra_skin_match);
838
839         if (!thz || thz->ops->get_temp(thz, temp))
840                 *temp = 25000;
841
842         return 0;
843 }
844
845 static struct therm_est_data skin_data = {
846         .cdev_type = "skin-balanced",
847         .toffset = 9793,
848         .polling_period = 1100,
849         .ndevs = 2,
850         .tc1 = 5,
851         .tc2 = 1,
852         .devs = {
853                         {
854                                 .dev_data = "nct_ext",
855                                 .get_temp = tegra_skin_get_temp,
856                                 .coeffs = {
857                                         2, 1, 1, 1,
858                                         1, 1, 1, 1,
859                                         1, 1, 1, 0,
860                                         1, 1, 0, 0,
861                                         0, 0, -1, -7
862                                 },
863                         },
864                         {
865                                 .dev_data = "nct_int",
866                                 .get_temp = tegra_skin_get_temp,
867                                 .coeffs = {
868                                         -11, -7, -5, -3,
869                                         -3, -2, -1, 0,
870                                         0, 0, 1, 1,
871                                         1, 2, 2, 3,
872                                         4, 6, 11, 18
873                                 },
874                         },
875         },
876         .trip_temp = 43000,
877         .passive_delay = 5000,
878 };
879
880 static struct throttle_table skin_throttle_table[] = {
881         {      0, 1000 },
882         {  51000, 1000 },
883         { 102000, 1000 },
884         { 204000, 1000 },
885         { 252000, 1000 },
886         { 288000, 1000 },
887         { 372000, 1000 },
888         { 468000, 1000 },
889         { 510000, 1000 },
890         { 612000, 1000 },
891         { 714000, 1050 },
892         { 816000, 1050 },
893         { 918000, 1050 },
894         {1020000, 1100 },
895         {1122000, 1100 },
896         {1224000, 1100 },
897         {1326000, 1100 },
898         {1428000, 1100 },
899         {1530000, 1100 },
900 };
901
902 static struct balanced_throttle skin_throttle = {
903         .throt_tab_size = ARRAY_SIZE(skin_throttle_table),
904         .throt_tab = skin_throttle_table,
905 };
906
907 static int __init pluto_skin_init(void)
908 {
909         if (machine_is_tegra_pluto()) {
910                 balanced_throttle_register(&skin_throttle, "skin-balanced");
911                 tegra_skin_therm_est_device.dev.platform_data = &skin_data;
912                 platform_device_register(&tegra_skin_therm_est_device);
913         }
914
915         return 0;
916 }
917 late_initcall(pluto_skin_init);
918 #endif
919
920 void __init max77665_init(void)
921 {
922         int err;
923
924         err = gpio_request(MAX77665_CHARGER_INT, "CHARGER_INT");
925         if (err < 0) {
926                 pr_err("%s: gpio_request failed %d\n", __func__, err);
927                 goto fail_init_irq;
928         }
929
930         err = gpio_direction_input(MAX77665_CHARGER_INT);
931         if (err < 0) {
932                 pr_err("%s: gpio_direction_input failed %d\n", __func__, err);
933                 goto fail_init_irq;
934         }
935
936         pluto_i2c_board_info_max77665[0].irq =
937                                 gpio_to_irq(MAX77665_CHARGER_INT);
938 fail_init_irq:
939         err = i2c_register_board_info(4, pluto_i2c_board_info_max77665,
940                 ARRAY_SIZE(pluto_i2c_board_info_max77665));
941         if (err)
942                 pr_err("%s: max77665 device register failed.\n", __func__);
943
944         return;
945 }
946
947 int __init pluto_sensors_init(void)
948 {
949         int err;
950
951         tegra_get_board_info(&board_info);
952
953         pr_debug("%s: ++\n", __func__);
954         pluto_camera_init();
955
956         err = pluto_nct1008_init();
957         if (err)
958                 return err;
959
960         err = i2c_register_board_info(0, pluto_i2c1_isl_board_info,
961                                 ARRAY_SIZE(pluto_i2c1_isl_board_info));
962         if (err)
963                 pr_err("%s: isl board register failed.\n", __func__);
964
965         mpuirq_init();
966         max77665_init();
967         pluto_i2c_board_info_max77665[0].irq = gpio_to_irq(TEGRA_GPIO_PJ0);
968
969         err = i2c_register_board_info(0, max17042_device,
970                                 ARRAY_SIZE(max17042_device));
971         if (err)
972                 pr_err("%s: max17042 device register failed.\n", __func__);
973
974
975         return 0;
976 }