ARM: tegra: dalmore: add coefficient for trend calculation.
[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, 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 };
243
244 static struct max77665_muic_platform_data max77665_muic = {
245         .irq_base = MAX77665_TEGRA_IRQ_BASE,
246 };
247
248 static struct max77665_platform_data pluto_max77665_pdata = {
249         .irq_base = MAX77665_TEGRA_IRQ_BASE,
250         .irq_flag = IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
251         .muic_platform_data = {
252                 .pdata = &max77665_muic,
253                 .size = sizeof(max77665_muic),
254                 },
255         .charger_platform_data = {
256                 .pdata = &max77665_charger,
257                 .size = sizeof(max77665_charger),
258                 },
259         .flash_platform_data = {
260                 .pdata = &pluto_max77665_flash_pdata,
261                 .size = sizeof(pluto_max77665_flash_pdata),
262                 },
263         .haptic_platform_data = {
264                 .pdata = &max77665_haptic_pdata,
265                 .size = sizeof(max77665_haptic_pdata),
266                 },
267 };
268
269 static struct i2c_board_info pluto_i2c_board_info_max77665[] = {
270         {
271                 I2C_BOARD_INFO("max77665", 0x66),
272                 .platform_data = &pluto_max77665_pdata,
273         },
274 };
275
276 /* isl29029 support is provided by isl29028*/
277 static struct i2c_board_info pluto_i2c1_isl_board_info[] = {
278         {
279                 I2C_BOARD_INFO("isl29028", 0x44),
280         }
281 };
282
283 static struct balanced_throttle tj_throttle = {
284         .throt_tab_size = 19,
285         .throt_tab = {
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
308 static int __init pluto_throttle_init(void)
309 {
310         if (machine_is_tegra_pluto())
311                 balanced_throttle_register(&tj_throttle, "pluto-nct");
312         return 0;
313 }
314 module_init(pluto_throttle_init);
315
316 static struct nct1008_platform_data pluto_nct1008_pdata = {
317         .supported_hwrev = true,
318         .ext_range = true,
319         .conv_rate = 0x08,
320         .offset = 0,
321         .shutdown_ext_limit = 85, /* C */
322         .shutdown_local_limit = 120, /* C */
323
324         .passive_delay = 2000,
325
326         .num_trips = 1,
327         .trips = {
328                 /* Thermal Throttling */
329                 [0] = {
330                         .cdev_type = "pluto-nct",
331                         .trip_temp = 75000,
332                         .trip_type = THERMAL_TRIP_PASSIVE,
333                         .state = THERMAL_NO_LIMIT,
334                         .hysteresis = 0,
335                 },
336         },
337 };
338
339 static struct i2c_board_info pluto_i2c4_nct1008_board_info[] = {
340         {
341                 I2C_BOARD_INFO("nct1008", 0x4C),
342                 .platform_data = &pluto_nct1008_pdata,
343                 .irq = -1,
344         }
345 };
346
347 #define VI_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _ioreset) \
348         {                                                       \
349                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
350                 .func           = TEGRA_MUX_##_mux,             \
351                 .pupd           = TEGRA_PUPD_##_pupd,           \
352                 .tristate       = TEGRA_TRI_##_tri,             \
353                 .io             = TEGRA_PIN_##_io,              \
354                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
355                 .od             = TEGRA_PIN_OD_DEFAULT,         \
356                 .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
357 }
358
359 static int pluto_focuser_power_on(struct ad5816_power_rail *pw)
360 {
361         int err;
362
363         if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
364                 return -EFAULT;
365
366         err = regulator_enable(pw->vdd_i2c);
367         if (unlikely(err))
368                 goto ad5816_vdd_i2c_fail;
369
370         err = regulator_enable(pw->vdd);
371         if (unlikely(err))
372                 goto ad5816_vdd_fail;
373
374         return 0;
375
376 ad5816_vdd_fail:
377         regulator_disable(pw->vdd_i2c);
378
379 ad5816_vdd_i2c_fail:
380         pr_err("%s FAILED\n", __func__);
381
382         return -ENODEV;
383 }
384
385 static int pluto_focuser_power_off(struct ad5816_power_rail *pw)
386 {
387         if (unlikely(WARN_ON(!pw || !pw->vdd || !pw->vdd_i2c)))
388                 return -EFAULT;
389
390         regulator_disable(pw->vdd);
391         regulator_disable(pw->vdd_i2c);
392
393         return 0;
394 }
395
396 static struct tegra_pingroup_config mclk_disable =
397         VI_PINMUX(CAM_MCLK, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
398
399 static struct tegra_pingroup_config mclk_enable =
400         VI_PINMUX(CAM_MCLK, VI_ALT3, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
401
402 static struct tegra_pingroup_config pbb0_disable =
403         VI_PINMUX(GPIO_PBB0, VI, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
404
405 static struct tegra_pingroup_config pbb0_enable =
406         VI_PINMUX(GPIO_PBB0, VI_ALT3, NORMAL, NORMAL, OUTPUT, DEFAULT, DEFAULT);
407
408 /*
409  * more regulators need to be allocated to activate the sensor devices.
410  * pluto_vcmvdd: this is a workaround due to the focuser device(AD5816) will
411  *               hook up the i2c bus if it is not powered up.
412  * pluto_i2cvdd: by default, the power supply on the i2c bus is OFF. So it
413  *               should be turned on every time any sensor device is activated.
414 */
415 static struct regulator *pluto_vcmvdd;
416 static struct regulator *pluto_i2cvdd;
417
418 static int pluto_get_extra_regulators(void)
419 {
420         if (!pluto_vcmvdd) {
421                 pluto_vcmvdd = regulator_get(NULL, "vdd_af_cam1");
422                 if (WARN_ON(IS_ERR(pluto_vcmvdd))) {
423                         pr_err("%s: can't get regulator vdd_af_cam1: %ld\n",
424                                 __func__, PTR_ERR(pluto_vcmvdd));
425                         pluto_vcmvdd = NULL;
426                         return -ENODEV;
427                 }
428         }
429
430         if (!pluto_i2cvdd) {
431                 pluto_i2cvdd = regulator_get(NULL, "vddio_cam_mb");
432                 if (unlikely(WARN_ON(IS_ERR(pluto_i2cvdd)))) {
433                         pr_err("%s: can't get regulator vddio_cam_mb: %ld\n",
434                                 __func__, PTR_ERR(pluto_i2cvdd));
435                         pluto_i2cvdd = NULL;
436                         return -ENODEV;
437                 }
438         }
439
440         return 0;
441 }
442
443 static int pluto_imx091_power_on(struct nvc_regulator *vreg)
444 {
445         int err;
446
447         if (unlikely(WARN_ON(!vreg)))
448                 return -EFAULT;
449
450         if (pluto_get_extra_regulators())
451                 goto imx091_poweron_fail;
452
453         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
454         usleep_range(10, 20);
455
456         err = regulator_enable(vreg[IMX091_VREG_AVDD].vreg);
457         if (unlikely(err))
458                 goto imx091_avdd_fail;
459
460         err = regulator_enable(vreg[IMX091_VREG_DVDD].vreg);
461         if (unlikely(err))
462                 goto imx091_dvdd_fail;
463
464         err = regulator_enable(vreg[IMX091_VREG_IOVDD].vreg);
465         if (unlikely(err))
466                 goto imx091_iovdd_fail;
467
468         usleep_range(1, 2);
469         gpio_set_value(CAM1_POWER_DWN_GPIO, 1);
470
471         tegra_pinmux_config_table(&mclk_enable, 1);
472         err = regulator_enable(pluto_i2cvdd);
473         if (unlikely(err))
474                 goto imx091_i2c_fail;
475
476         err = regulator_enable(pluto_vcmvdd);
477         if (unlikely(err))
478                 goto imx091_vcm_fail;
479         usleep_range(300, 310);
480
481         return 0;
482
483 imx091_vcm_fail:
484         regulator_disable(pluto_i2cvdd);
485
486 imx091_i2c_fail:
487         tegra_pinmux_config_table(&mclk_disable, 1);
488         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
489         regulator_disable(vreg[IMX091_VREG_IOVDD].vreg);
490
491 imx091_iovdd_fail:
492         regulator_disable(vreg[IMX091_VREG_DVDD].vreg);
493
494 imx091_dvdd_fail:
495         regulator_disable(vreg[IMX091_VREG_AVDD].vreg);
496
497 imx091_avdd_fail:
498 imx091_poweron_fail:
499         pr_err("%s FAILED\n", __func__);
500         return -ENODEV;
501 }
502
503 static int pluto_imx091_power_off(struct nvc_regulator *vreg)
504 {
505         if (unlikely(WARN_ON(!vreg)))
506                 return -EFAULT;
507
508         usleep_range(1, 2);
509         tegra_pinmux_config_table(&mclk_disable, 1);
510         gpio_set_value(CAM1_POWER_DWN_GPIO, 0);
511         usleep_range(1, 2);
512
513         regulator_disable(vreg[IMX091_VREG_IOVDD].vreg);
514         regulator_disable(vreg[IMX091_VREG_DVDD].vreg);
515         regulator_disable(vreg[IMX091_VREG_AVDD].vreg);
516         regulator_disable(pluto_i2cvdd);
517         regulator_disable(pluto_vcmvdd);
518
519         return 0;
520 }
521
522 static struct nvc_imager_cap imx091_cap = {
523         .identifier             = "IMX091",
524         .sensor_nvc_interface   = 3,
525         .pixel_types[0]         = 0x100,
526         .orientation            = 0,
527         .direction              = 0,
528         .initial_clock_rate_khz = 6000,
529         .clock_profiles[0] = {
530                 .external_clock_khz     = 24000,
531                 .clock_multiplier       = 10416667, /* value / 1,000,000 */
532         },
533         .clock_profiles[1] = {
534                 .external_clock_khz     = 0,
535                 .clock_multiplier       = 0,
536         },
537         .h_sync_edge            = 0,
538         .v_sync_edge            = 0,
539         .mclk_on_vgp0           = 0,
540         .csi_port               = 0,
541         .data_lanes             = 4,
542         .virtual_channel_id     = 0,
543         .discontinuous_clk_mode = 1,
544         .cil_threshold_settle   = 0x0,
545         .min_blank_time_width   = 16,
546         .min_blank_time_height  = 16,
547         .preferred_mode_index   = 0,
548         .focuser_guid           = NVC_FOCUS_GUID(0),
549         .torch_guid             = NVC_TORCH_GUID(0),
550         .cap_version            = NVC_IMAGER_CAPABILITIES_VERSION2,
551 };
552
553 static unsigned imx091_estates[] = {200, 100, 2};
554
555 static struct imx091_platform_data imx091_pdata = {
556         .num                    = 0,
557         .sync                   = 0,
558         .dev_name               = "camera",
559         .gpio_count             = ARRAY_SIZE(imx091_gpio_pdata),
560         .gpio                   = imx091_gpio_pdata,
561         .flash_cap              = {
562                 .sdo_trigger_enabled = 1,
563                 .adjustable_flash_timing = 1,
564         },
565         .cap                    = &imx091_cap,
566         .edpc_config    = {
567                 .states = imx091_estates,
568                 .num_states = ARRAY_SIZE(imx091_estates),
569                 .e0_index = 0,
570                 .priority = EDP_MAX_PRIO - 1,
571                 },
572         .power_on               = pluto_imx091_power_on,
573         .power_off              = pluto_imx091_power_off,
574 };
575
576 static int pluto_imx132_power_on(struct imx132_power_rail *pw)
577 {
578         int err;
579
580         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd)))
581                 return -EFAULT;
582
583         if (pluto_get_extra_regulators())
584                 goto pluto_imx132_poweron_fail;
585
586         gpio_set_value(CAM2_POWER_DWN_GPIO, 0);
587
588         tegra_pinmux_config_table(&pbb0_enable, 1);
589
590         err = regulator_enable(pluto_i2cvdd);
591         if (unlikely(err))
592                 goto imx132_i2c_fail;
593
594         err = regulator_enable(pluto_vcmvdd);
595         if (unlikely(err))
596                 goto imx132_vcm_fail;
597
598         err = regulator_enable(pw->avdd);
599         if (unlikely(err))
600                 goto imx132_avdd_fail;
601
602         err = regulator_enable(pw->dvdd);
603         if (unlikely(err))
604                 goto imx132_dvdd_fail;
605
606         err = regulator_enable(pw->iovdd);
607         if (unlikely(err))
608                 goto imx132_iovdd_fail;
609
610         usleep_range(1, 2);
611
612         gpio_set_value(CAM2_POWER_DWN_GPIO, 1);
613
614         return 0;
615
616 imx132_iovdd_fail:
617         regulator_disable(pw->dvdd);
618
619 imx132_dvdd_fail:
620         regulator_disable(pw->avdd);
621
622 imx132_avdd_fail:
623         regulator_disable(pluto_vcmvdd);
624
625 imx132_vcm_fail:
626         regulator_disable(pluto_i2cvdd);
627
628 imx132_i2c_fail:
629         tegra_pinmux_config_table(&pbb0_disable, 1);
630
631 pluto_imx132_poweron_fail:
632         pr_err("%s failed.\n", __func__);
633         return -ENODEV;
634 }
635
636 static int pluto_imx132_power_off(struct imx132_power_rail *pw)
637 {
638         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd ||
639                         !pluto_i2cvdd || !pluto_vcmvdd)))
640                 return -EFAULT;
641
642         gpio_set_value(CAM2_POWER_DWN_GPIO, 0);
643
644         usleep_range(1, 2);
645
646         regulator_disable(pw->iovdd);
647         regulator_disable(pw->dvdd);
648         regulator_disable(pw->avdd);
649
650         tegra_pinmux_config_table(&pbb0_disable, 1);
651
652         regulator_disable(pluto_vcmvdd);
653         regulator_disable(pluto_i2cvdd);
654
655         return 0;
656 }
657
658 struct imx132_platform_data pluto_imx132_data = {
659         .power_on = pluto_imx132_power_on,
660         .power_off = pluto_imx132_power_off,
661 };
662
663 static struct ad5816_platform_data pluto_ad5816_pdata = {
664         .cfg            = 0,
665         .num            = 0,
666         .sync           = 0,
667         .dev_name       = "focuser",
668         .power_on       = pluto_focuser_power_on,
669         .power_off      = pluto_focuser_power_off,
670 };
671
672 static struct i2c_board_info pluto_i2c_board_info_e1625[] = {
673         {
674                 I2C_BOARD_INFO("imx091", 0x10),
675                 .platform_data = &imx091_pdata,
676         },
677         {
678                 I2C_BOARD_INFO("imx132", 0x36),
679                 .platform_data = &pluto_imx132_data,
680         },
681         {
682                 I2C_BOARD_INFO("ad5816", 0x0E),
683                 .platform_data = &pluto_ad5816_pdata,
684         },
685 };
686
687 static int pluto_camera_init(void)
688 {
689         pr_debug("%s: ++\n", __func__);
690
691         tegra_pinmux_config_table(&mclk_disable, 1);
692         tegra_pinmux_config_table(&pbb0_disable, 1);
693
694         i2c_register_board_info(2, pluto_i2c_board_info_e1625,
695                 ARRAY_SIZE(pluto_i2c_board_info_e1625));
696
697         return 0;
698 }
699
700 /* MPU board file definition */
701 static struct mpu_platform_data mpu_gyro_data = {
702         .int_config     = 0x00,
703         .level_shifter  = 0,
704         .orientation    = MPU_GYRO_ORIENTATION,
705         .sec_slave_type = SECONDARY_SLAVE_TYPE_COMPASS,
706         .sec_slave_id   = COMPASS_ID_AK8963,
707         .secondary_i2c_addr     = MPU_COMPASS_ADDR,
708         .secondary_orientation  = MPU_COMPASS_ORIENTATION,
709         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
710                            0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
711 };
712
713 static struct i2c_board_info __initdata inv_mpu_i2c0_board_info[] = {
714         {
715                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
716                 .platform_data = &mpu_gyro_data,
717         },
718 };
719
720 static void mpuirq_init(void)
721 {
722         int ret = 0;
723         int i = 0;
724
725         pr_info("*** MPU START *** mpuirq_init...\n");
726
727         /* MPU-IRQ assignment */
728         ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
729         if (ret < 0) {
730                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
731                 return;
732         }
733
734         ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
735         if (ret < 0) {
736                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
737                 gpio_free(MPU_GYRO_IRQ_GPIO);
738                 return;
739         }
740         pr_info("*** MPU END *** mpuirq_init...\n");
741
742         inv_mpu_i2c0_board_info[i++].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
743 #if MPU_COMPASS_IRQ_GPIO
744         inv_mpu_i2c0_board_info[i++].irq = gpio_to_irq(MPU_COMPASS_IRQ_GPIO);
745 #endif
746         i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c0_board_info,
747                 ARRAY_SIZE(inv_mpu_i2c0_board_info));
748 }
749
750 static int pluto_nct1008_init(void)
751 {
752         int nct1008_port = -1;
753         int ret = 0;
754
755         if (board_info.board_id == BOARD_E1580 ||
756             board_info.board_id == BOARD_E1575) {
757                 nct1008_port = TEGRA_GPIO_PX6;
758         } else {
759                 nct1008_port = TEGRA_GPIO_PX6;
760                 pr_err("Warning: nct alert port assumed TEGRA_GPIO_PX6 for unknown pluto board id E%d\n",
761                        board_info.board_id);
762         }
763
764         if (nct1008_port >= 0) {
765                 struct nct1008_platform_data *data = &pluto_nct1008_pdata;
766 #ifdef CONFIG_TEGRA_EDP_LIMITS
767                 const struct tegra_edp_limits *cpu_edp_limits;
768                 int cpu_edp_limits_size;
769                 int i;
770                 int trip;
771                 struct nct_trip_temp *trip_state;
772
773                 /* edp capping */
774                 tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
775
776                 if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
777                         BUG();
778
779                 for (i = 0; i < cpu_edp_limits_size-1; i++) {
780                         trip = data->num_trips;
781                         trip_state = &data->trips[trip];
782
783                         trip_state->cdev_type = "edp";
784                         trip_state->trip_temp =
785                                         cpu_edp_limits[i].temperature * 1000;
786                         trip_state->trip_type = THERMAL_TRIP_ACTIVE;
787                         trip_state->state = i + 1;
788                         trip_state->hysteresis = 1000;
789
790                         data->num_trips++;
791
792                         if (data->num_trips >= NCT_MAX_TRIPS)
793                                 BUG();
794                 }
795 #endif
796                 nct1008_add_cdev_trips(data, tegra_core_edp_get_cdev());
797                 nct1008_add_cdev_trips(data, tegra_dvfs_get_cpu_dfll_cdev());
798                 nct1008_add_cdev_trips(data, tegra_dvfs_get_core_cdev());
799
800                 pluto_i2c4_nct1008_board_info[0].irq =
801                                 gpio_to_irq(nct1008_port);
802                 pr_info("%s: pluto nct1008 irq %d", __func__, pluto_i2c4_nct1008_board_info[0].irq);
803
804                 ret = gpio_request(nct1008_port, "temp_alert");
805                 if (ret < 0)
806                         return ret;
807
808                 ret = gpio_direction_input(nct1008_port);
809                 if (ret < 0) {
810                         pr_info("%s: calling gpio_free(nct1008_port)", __func__);
811                         gpio_free(nct1008_port);
812                 }
813         }
814
815         /* pluto has thermal sensor on GEN1-I2C i.e. instance 0 */
816         i2c_register_board_info(0, pluto_i2c4_nct1008_board_info,
817                 ARRAY_SIZE(pluto_i2c4_nct1008_board_info));
818
819         return ret;
820 }
821
822 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
823 static int tegra_skin_match(struct thermal_zone_device *thz, void *data)
824 {
825         return strcmp((char *)data, thz->type) == 0;
826 }
827
828 static int tegra_skin_get_temp(void *data, long *temp)
829 {
830         struct thermal_zone_device *thz;
831
832         thz = thermal_zone_device_find(data, tegra_skin_match);
833
834         if (!thz || thz->ops->get_temp(thz, temp))
835                 *temp = 25000;
836
837         return 0;
838 }
839
840 static struct therm_est_data skin_data = {
841         .cdev_type = "pluto-skin",
842         .toffset = 9793,
843         .polling_period = 1100,
844         .ndevs = 2,
845         .tc1 = 5,
846         .tc2 = 1,
847         .devs = {
848                         {
849                                 .dev_data = "nct_ext",
850                                 .get_temp = tegra_skin_get_temp,
851                                 .coeffs = {
852                                         2, 1, 1, 1,
853                                         1, 1, 1, 1,
854                                         1, 1, 1, 0,
855                                         1, 1, 0, 0,
856                                         0, 0, -1, -7
857                                 },
858                         },
859                         {
860                                 .dev_data = "nct_int",
861                                 .get_temp = tegra_skin_get_temp,
862                                 .coeffs = {
863                                         -11, -7, -5, -3,
864                                         -3, -2, -1, 0,
865                                         0, 0, 1, 1,
866                                         1, 2, 2, 3,
867                                         4, 6, 11, 18
868                                 },
869                         },
870         },
871         .trip_temp = 43000,
872         .passive_delay = 5000,
873 };
874
875 static struct balanced_throttle skin_throttle = {
876         .throt_tab_size = 19,
877         .throt_tab = {
878                 {      0, 1000 },
879                 {  51000, 1000 },
880                 { 102000, 1000 },
881                 { 204000, 1000 },
882                 { 252000, 1000 },
883                 { 288000, 1000 },
884                 { 372000, 1000 },
885                 { 468000, 1000 },
886                 { 510000, 1000 },
887                 { 612000, 1000 },
888                 { 714000, 1050 },
889                 { 816000, 1050 },
890                 { 918000, 1050 },
891                 {1020000, 1100 },
892                 {1122000, 1100 },
893                 {1224000, 1100 },
894                 {1326000, 1100 },
895                 {1428000, 1100 },
896                 {1530000, 1100 },
897         },
898 };
899
900 static int __init pluto_skin_init(void)
901 {
902         if (machine_is_tegra_pluto()) {
903                 balanced_throttle_register(&skin_throttle, "pluto-skin");
904                 tegra_skin_therm_est_device.dev.platform_data = &skin_data;
905                 platform_device_register(&tegra_skin_therm_est_device);
906         }
907
908         return 0;
909 }
910 late_initcall(pluto_skin_init);
911 #endif
912
913 void __init max77665_init(void)
914 {
915         int err;
916
917         err = gpio_request(MAX77665_CHARGER_INT, "CHARGER_INT");
918         if (err < 0) {
919                 pr_err("%s: gpio_request failed %d\n", __func__, err);
920                 goto fail_init_irq;
921         }
922
923         err = gpio_direction_input(MAX77665_CHARGER_INT);
924         if (err < 0) {
925                 pr_err("%s: gpio_direction_input failed %d\n", __func__, err);
926                 goto fail_init_irq;
927         }
928
929         pluto_i2c_board_info_max77665[0].irq =
930                                 gpio_to_irq(MAX77665_CHARGER_INT);
931 fail_init_irq:
932         err = i2c_register_board_info(4, pluto_i2c_board_info_max77665,
933                 ARRAY_SIZE(pluto_i2c_board_info_max77665));
934         if (err)
935                 pr_err("%s: max77665 device register failed.\n", __func__);
936
937         return;
938 }
939
940 int __init pluto_sensors_init(void)
941 {
942         int err;
943
944         tegra_get_board_info(&board_info);
945
946         pr_debug("%s: ++\n", __func__);
947         pluto_camera_init();
948
949         err = pluto_nct1008_init();
950         if (err)
951                 return err;
952
953         err = i2c_register_board_info(0, pluto_i2c1_isl_board_info,
954                                 ARRAY_SIZE(pluto_i2c1_isl_board_info));
955         if (err)
956                 pr_err("%s: isl board register failed.\n", __func__);
957
958         mpuirq_init();
959         max77665_init();
960         pluto_i2c_board_info_max77665[0].irq = gpio_to_irq(TEGRA_GPIO_PJ0);
961
962         err = i2c_register_board_info(0, max17042_device,
963                                 ARRAY_SIZE(max17042_device));
964         if (err)
965                 pr_err("%s: max17042 device register failed.\n", __func__);
966
967
968         return 0;
969 }