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