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