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