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