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