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