]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - arch/arm/mach-tegra/board-ardbeg-sensors.c
9915bf07152d4c2ba59abcf16c94ce80eb135c19
[sojka/nv-tegra/linux-3.10.git] / arch / arm / mach-tegra / board-ardbeg-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-ardbeg-sensors.c
3  *
4  * Copyright (c) 2013-2015, 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
16 #include <linux/i2c.h>
17 #include <linux/gpio.h>
18 #include <linux/mpu.h>
19 #include <linux/delay.h>
20 #include <linux/err.h>
21 #include <linux/nct1008.h>
22 #include <linux/pid_thermal_gov.h>
23 #include <linux/tegra-fuse.h>
24 #include <linux/of_platform.h>
25 #include <mach/edp.h>
26 #include <mach/pinmux-t12.h>
27 #include <mach/pinmux.h>
28 #include <mach/io_dpd.h>
29 #include <media/camera.h>
30 #include <media/ar0330.h>
31 #include <media/ar0261.h>
32 #include <media/ar1335.h>
33 #include <media/imx135.h>
34 #include <media/imx179.h>
35 #include <media/dw9718.h>
36 #include <media/as364x.h>
37 #include <media/ov5693.h>
38 #include <media/ov7695.h>
39 #include <media/mt9m114.h>
40 #include <media/ad5823.h>
41 #include <media/max77387.h>
42
43 #include <media/ov4689.h>
44 #include <linux/platform_device.h>
45 #include <media/soc_camera.h>
46 #include <media/soc_camera_platform.h>
47 #include <media/tegra_v4l2_camera.h>
48 #include <linux/generic_adc_thermal.h>
49
50 #include "cpu-tegra.h"
51 #include "devices.h"
52 #include "board.h"
53 #include "board-common.h"
54 #include "board-ardbeg.h"
55 #include "tegra-board-id.h"
56
57 #if defined(ARCH_TEGRA_12x_SOC)
58 static struct i2c_board_info ardbeg_i2c_board_info_cm32181[] = {
59         {
60                 I2C_BOARD_INFO("cm32181", 0x48),
61         },
62 };
63 #endif
64
65 /* MPU board file definition    */
66 static struct mpu_platform_data mpu9250_gyro_data = {
67         .int_config     = 0x10,
68         .level_shifter  = 0,
69         /* Located in board_[platformname].h */
70         .orientation    = MPU_GYRO_ORIENTATION,
71         .sec_slave_type = SECONDARY_SLAVE_TYPE_NONE,
72         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
73                         0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
74 };
75
76 static struct mpu_platform_data mpu9250_gyro_data_e1762 = {
77         .int_config     = 0x10,
78         .level_shifter  = 0,
79         /* Located in board_[platformname].h */
80         .orientation    = MPU_GYRO_ORIENTATION_E1762,
81         .sec_slave_type = SECONDARY_SLAVE_TYPE_NONE,
82         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
83                         0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
84 };
85
86 static struct mpu_platform_data mpu_compass_data = {
87         .orientation    = MPU_COMPASS_ORIENTATION,
88         .config         = NVI_CONFIG_BOOT_MPU,
89 };
90
91 static struct mpu_platform_data mpu_bmp_pdata = {
92         .config         = NVI_CONFIG_BOOT_MPU,
93 };
94
95 static struct i2c_board_info __initdata inv_mpu9250_i2c0_board_info[] = {
96         {
97                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
98                 .platform_data = &mpu9250_gyro_data,
99         },
100         {
101                 /* The actual BMP180 address is 0x77 but because this conflicts
102                  * with another device, this address is hacked so Linux will
103                  * call the driver.  The conflict is technically okay since the
104                  * BMP180 is behind the MPU.  Also, the BMP180 driver uses a
105                  * hard-coded address of 0x77 since it can't be changed anyway.
106                  */
107                 I2C_BOARD_INFO(MPU_BMP_NAME, MPU_BMP_ADDR),
108                 .platform_data = &mpu_bmp_pdata,
109         },
110         {
111                 I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
112                 .platform_data = &mpu_compass_data,
113         },
114 };
115
116 static void mpuirq_init(void)
117 {
118         int ret = 0;
119         unsigned gyro_irq_gpio = MPU_GYRO_IRQ_GPIO;
120         unsigned gyro_bus_num = MPU_GYRO_BUS_NUM;
121         char *gyro_name = MPU_GYRO_NAME;
122         struct board_info board_info;
123
124         pr_info("*** MPU START *** mpuirq_init...\n");
125
126         tegra_get_board_info(&board_info);
127
128         ret = gpio_request(gyro_irq_gpio, gyro_name);
129         if (ret < 0) {
130                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
131                 return;
132         }
133
134         ret = gpio_direction_input(gyro_irq_gpio);
135         if (ret < 0) {
136                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
137                 gpio_free(gyro_irq_gpio);
138                 return;
139         }
140         pr_info("*** MPU END *** mpuirq_init...\n");
141
142         /* TN8 with diferent Compass address from ardbeg */
143         if (of_machine_is_compatible("nvidia,tn8"))
144                 inv_mpu9250_i2c0_board_info[2].addr = MPU_COMPASS_ADDR_TN8;
145
146         if (board_info.board_id == BOARD_E1762)
147                 inv_mpu9250_i2c0_board_info[0].platform_data =
148                                         &mpu9250_gyro_data_e1762;
149         inv_mpu9250_i2c0_board_info[0].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
150         i2c_register_board_info(gyro_bus_num, inv_mpu9250_i2c0_board_info,
151                 ARRAY_SIZE(inv_mpu9250_i2c0_board_info));
152 }
153
154 /*
155  * Soc Camera platform driver for testing
156  */
157 #if IS_ENABLED(CONFIG_SOC_CAMERA_PLATFORM)
158 static int ardbeg_soc_camera_add(struct soc_camera_device *icd);
159 static void ardbeg_soc_camera_del(struct soc_camera_device *icd);
160
161 static int ardbeg_soc_camera_set_capture(struct soc_camera_platform_info *info,
162                 int enable)
163 {
164         /* TODO: probably add clk opertaion here */
165         return 0; /* camera sensor always enabled */
166 }
167
168 static struct soc_camera_platform_info ardbeg_soc_camera_info = {
169         .format_name = "RGB4",
170         .format_depth = 32,
171         .format = {
172                 .code = V4L2_MBUS_FMT_RGBA8888_4X8_LE,
173                 .colorspace = V4L2_COLORSPACE_SRGB,
174                 .field = V4L2_FIELD_NONE,
175                 .width = 1280,
176                 .height = 720,
177         },
178         .set_capture = ardbeg_soc_camera_set_capture,
179 };
180
181 static struct tegra_camera_platform_data ardbeg_camera_platform_data = {
182         .flip_v                 = 0,
183         .flip_h                 = 0,
184         .port                   = TEGRA_CAMERA_PORT_CSI_A,
185         .lanes                  = 4,
186         .continuous_clk         = 0,
187 };
188
189 static struct soc_camera_link ardbeg_soc_camera_link = {
190         .bus_id         = 1, /* This must match the .id of tegra_vi01_device */
191         .add_device     = ardbeg_soc_camera_add,
192         .del_device     = ardbeg_soc_camera_del,
193         .module_name    = "soc_camera_platform",
194         .priv           = &ardbeg_camera_platform_data,
195         .dev_priv       = &ardbeg_soc_camera_info,
196 };
197
198 static struct platform_device *ardbeg_pdev;
199
200 static void ardbeg_soc_camera_release(struct device *dev)
201 {
202         soc_camera_platform_release(&ardbeg_pdev);
203 }
204
205 static int ardbeg_soc_camera_add(struct soc_camera_device *icd)
206 {
207         return soc_camera_platform_add(icd, &ardbeg_pdev,
208                         &ardbeg_soc_camera_link,
209                         ardbeg_soc_camera_release, 0);
210 }
211
212 static void ardbeg_soc_camera_del(struct soc_camera_device *icd)
213 {
214         soc_camera_platform_del(icd, ardbeg_pdev, &ardbeg_soc_camera_link);
215 }
216
217 static struct platform_device ardbeg_soc_camera_device = {
218         .name   = "soc-camera-pdrv",
219         .id     = 1,
220         .dev    = {
221                 .platform_data = &ardbeg_soc_camera_link,
222         },
223 };
224 #endif
225
226 #if IS_ENABLED(CONFIG_SOC_CAMERA_IMX135)
227 static int ardbeg_imx135_power(struct device *dev, int enable)
228 {
229         return 0;
230 }
231
232 struct imx135_platform_data ardbeg_imx135_data;
233
234 static struct i2c_board_info ardbeg_imx135_camera_i2c_device = {
235         I2C_BOARD_INFO("imx135_v4l2", 0x10),
236         .platform_data = &ardbeg_imx135_data,
237 };
238
239 static struct tegra_camera_platform_data ardbeg_imx135_camera_platform_data = {
240         .flip_v                 = 0,
241         .flip_h                 = 0,
242         .port                   = TEGRA_CAMERA_PORT_CSI_A,
243         .lanes                  = 4,
244         .continuous_clk         = 0,
245 };
246
247 static struct soc_camera_link imx135_iclink = {
248         .bus_id         = 0, /* This must match the .id of tegra_vi01_device */
249         .board_info     = &ardbeg_imx135_camera_i2c_device,
250         .module_name    = "imx135_v4l2",
251         .i2c_adapter_id = 2,
252         .power          = ardbeg_imx135_power,
253         .priv           = &ardbeg_imx135_camera_platform_data,
254 };
255
256 static struct platform_device ardbeg_imx135_soc_camera_device = {
257         .name   = "soc-camera-pdrv",
258         .id     = 0,
259         .dev    = {
260                 .platform_data = &imx135_iclink,
261         },
262 };
263 #endif
264
265 #if IS_ENABLED(CONFIG_SOC_CAMERA_AR0261)
266 static int ardbeg_ar0261_power(struct device *dev, int enable)
267 {
268         return 0;
269 }
270
271 struct ar0261_platform_data ardbeg_ar0261_data;
272
273 static struct i2c_board_info ardbeg_ar0261_camera_i2c_device = {
274         I2C_BOARD_INFO("ar0261_v4l2", 0x36),
275         .platform_data = &ardbeg_ar0261_data,
276 };
277
278 static struct tegra_camera_platform_data ardbeg_ar0261_camera_platform_data = {
279         .flip_v                 = 0,
280         .flip_h                 = 0,
281         .port                   = TEGRA_CAMERA_PORT_CSI_C,
282         .lanes                  = 1,
283         .continuous_clk         = 0,
284 };
285
286 static struct soc_camera_link ar0261_iclink = {
287         .bus_id         = 1, /* This must match the .id of tegra_vi01_device */
288         .board_info     = &ardbeg_ar0261_camera_i2c_device,
289         .module_name    = "ar0261_v4l2",
290         .i2c_adapter_id = 2,
291         .power          = ardbeg_ar0261_power,
292         .priv           = &ardbeg_ar0261_camera_platform_data,
293 };
294
295 static struct platform_device ardbeg_ar0261_soc_camera_device = {
296         .name   = "soc-camera-pdrv",
297         .id     = 1,
298         .dev    = {
299                 .platform_data = &ar0261_iclink,
300         },
301 };
302 #endif
303
304 static struct regulator *ardbeg_vcmvdd;
305
306 static int ardbeg_get_extra_regulators(void)
307 {
308         if (!ardbeg_vcmvdd) {
309                 ardbeg_vcmvdd = regulator_get(NULL, "avdd_af1_cam");
310                 if (WARN_ON(IS_ERR(ardbeg_vcmvdd))) {
311                         pr_err("%s: can't get regulator avdd_af1_cam: %ld\n",
312                                         __func__, PTR_ERR(ardbeg_vcmvdd));
313                         regulator_put(ardbeg_vcmvdd);
314                         ardbeg_vcmvdd = NULL;
315                         return -ENODEV;
316                 }
317         }
318
319         return 0;
320 }
321
322 static struct tegra_io_dpd csia_io = {
323         .name                   = "CSIA",
324         .io_dpd_reg_index       = 0,
325         .io_dpd_bit             = 0,
326 };
327
328 static struct tegra_io_dpd csib_io = {
329         .name                   = "CSIB",
330         .io_dpd_reg_index       = 0,
331         .io_dpd_bit             = 1,
332 };
333
334 static struct tegra_io_dpd csie_io = {
335         .name                   = "CSIE",
336         .io_dpd_reg_index       = 1,
337         .io_dpd_bit             = 12,
338 };
339
340 static int ardbeg_ar0330_front_power_on(struct ar0330_power_rail *pw)
341 {
342         int err;
343
344         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd)))
345                 return -EFAULT;
346
347         /* disable CSIE IOs DPD mode to turn on front camera for ardbeg */
348         tegra_io_dpd_disable(&csie_io);
349
350         gpio_set_value(CAM2_PWDN, 0);
351
352         err = regulator_enable(pw->iovdd);
353         if (unlikely(err))
354                 goto ar0330_front_iovdd_fail;
355
356         usleep_range(1000, 1100);
357         err = regulator_enable(pw->avdd);
358         if (unlikely(err))
359                 goto ar0330_front_avdd_fail;
360
361         usleep_range(1, 2);
362         gpio_set_value(CAM2_PWDN, 1);
363
364         return 0;
365 ar0330_front_avdd_fail:
366         regulator_disable(pw->iovdd);
367
368 ar0330_front_iovdd_fail:
369         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
370         tegra_io_dpd_enable(&csie_io);
371         pr_err("%s failed.\n", __func__);
372         return -ENODEV;
373 }
374
375 static int ardbeg_ar0330_front_power_off(struct ar0330_power_rail *pw)
376 {
377         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd))) {
378                 /* put CSIE IOs into DPD mode to
379                  * save additional power for ardbeg
380                  */
381                 tegra_io_dpd_enable(&csie_io);
382                 return -EFAULT;
383         }
384
385         gpio_set_value(CAM2_PWDN, 0);
386
387         usleep_range(1, 2);
388
389         regulator_disable(pw->iovdd);
390         regulator_disable(pw->avdd);
391         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
392         tegra_io_dpd_enable(&csie_io);
393         return 0;
394 }
395
396 struct ar0330_platform_data ardbeg_ar0330_front_data = {
397         .power_on = ardbeg_ar0330_front_power_on,
398         .power_off = ardbeg_ar0330_front_power_off,
399         .dev_name       = "ar0330.1",
400         .mclk_name = "mclk2",
401 };
402
403 static int ardbeg_ar0330_power_on(struct ar0330_power_rail *pw)
404 {
405         int err;
406
407         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd)))
408                 return -EFAULT;
409
410         /* disable CSIE IOs DPD mode to turn on front camera for ardbeg */
411         tegra_io_dpd_disable(&csia_io);
412         tegra_io_dpd_disable(&csib_io);
413
414         gpio_set_value(CAM1_PWDN, 0);
415
416         err = regulator_enable(pw->iovdd);
417         if (unlikely(err))
418                 goto ar0330_iovdd_fail;
419
420         usleep_range(1000, 1100);
421         err = regulator_enable(pw->avdd);
422         if (unlikely(err))
423                 goto ar0330_avdd_fail;
424
425         usleep_range(1, 2);
426         gpio_set_value(CAM1_PWDN, 1);
427
428         return 0;
429 ar0330_avdd_fail:
430         regulator_disable(pw->iovdd);
431
432 ar0330_iovdd_fail:
433         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
434         tegra_io_dpd_enable(&csia_io);
435         tegra_io_dpd_enable(&csib_io);
436         pr_err("%s failed.\n", __func__);
437         return -ENODEV;
438 }
439
440 static int ardbeg_ar0330_power_off(struct ar0330_power_rail *pw)
441 {
442         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd))) {
443                 /* put CSIE IOs into DPD mode to
444                  * save additional power for ardbeg
445                  */
446                 tegra_io_dpd_enable(&csia_io);
447                 tegra_io_dpd_enable(&csib_io);
448                 return -EFAULT;
449         }
450
451         gpio_set_value(CAM1_PWDN, 0);
452
453         usleep_range(1, 2);
454
455         regulator_disable(pw->iovdd);
456         regulator_disable(pw->avdd);
457         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
458         tegra_io_dpd_enable(&csia_io);
459         tegra_io_dpd_enable(&csib_io);
460         return 0;
461 }
462
463 struct ar0330_platform_data ardbeg_ar0330_data = {
464         .power_on = ardbeg_ar0330_power_on,
465         .power_off = ardbeg_ar0330_power_off,
466         .dev_name       = "ar0330",
467 };
468
469 static int ardbeg_ov4689_power_on(struct ov4689_power_rail *pw)
470 {
471         pr_info("%s: ++\n", __func__);
472         /* disable CSIA/B IOs DPD mode to turn on camera for ardbeg */
473         tegra_io_dpd_disable(&csia_io);
474         tegra_io_dpd_disable(&csib_io);
475
476         gpio_set_value(TEGRA_GPIO_PBB5, 0);
477         usleep_range(10, 20);
478         gpio_set_value(TEGRA_GPIO_PBB5, 1);
479         usleep_range(820, 1000);
480
481         return 1;
482 }
483
484 static int ardbeg_ov4689_power_off(struct ov4689_power_rail *pw)
485 {
486         pr_info("%s: ++\n", __func__);
487
488         gpio_set_value(TEGRA_GPIO_PBB5, 0);
489
490         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
491         tegra_io_dpd_enable(&csia_io);
492         tegra_io_dpd_enable(&csib_io);
493
494         return 0;
495 }
496
497 static int ardbeg_ar0261_power_on(struct ar0261_power_rail *pw)
498 {
499         int err;
500
501         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd)))
502                 return -EFAULT;
503
504         /* disable CSIE IOs DPD mode to turn on front camera for ardbeg */
505         tegra_io_dpd_disable(&csie_io);
506
507         if (ardbeg_get_extra_regulators())
508                 goto ardbeg_ar0261_poweron_fail;
509
510         gpio_set_value(CAM_RSTN, 0);
511         gpio_set_value(CAM_AF_PWDN, 1);
512
513
514         err = regulator_enable(ardbeg_vcmvdd);
515         if (unlikely(err))
516                 goto ar0261_vcm_fail;
517
518         err = regulator_enable(pw->dvdd);
519         if (unlikely(err))
520                 goto ar0261_dvdd_fail;
521
522         err = regulator_enable(pw->avdd);
523         if (unlikely(err))
524                 goto ar0261_avdd_fail;
525
526         err = regulator_enable(pw->iovdd);
527         if (unlikely(err))
528                 goto ar0261_iovdd_fail;
529
530         usleep_range(1, 2);
531         gpio_set_value(CAM2_PWDN, 1);
532
533         gpio_set_value(CAM_RSTN, 1);
534
535         return 0;
536 ar0261_iovdd_fail:
537         regulator_disable(pw->dvdd);
538
539 ar0261_dvdd_fail:
540         regulator_disable(pw->avdd);
541
542 ar0261_avdd_fail:
543         regulator_disable(ardbeg_vcmvdd);
544
545 ar0261_vcm_fail:
546         pr_err("%s vcmvdd failed.\n", __func__);
547         return -ENODEV;
548
549 ardbeg_ar0261_poweron_fail:
550         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
551         tegra_io_dpd_enable(&csie_io);
552         pr_err("%s failed.\n", __func__);
553         return -ENODEV;
554 }
555
556 static int ardbeg_ar0261_power_off(struct ar0261_power_rail *pw)
557 {
558         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd || !pw->dvdd ||
559                                         !ardbeg_vcmvdd))) {
560                 /* put CSIE IOs into DPD mode to
561                  * save additional power for ardbeg
562                  */
563                 tegra_io_dpd_enable(&csie_io);
564                 return -EFAULT;
565         }
566
567         gpio_set_value(CAM_RSTN, 0);
568
569         usleep_range(1, 2);
570
571         regulator_disable(pw->iovdd);
572         regulator_disable(pw->dvdd);
573         regulator_disable(pw->avdd);
574         regulator_disable(ardbeg_vcmvdd);
575         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
576         tegra_io_dpd_enable(&csie_io);
577         return 0;
578 }
579
580 struct ar0261_platform_data ardbeg_ar0261_data = {
581         .power_on = ardbeg_ar0261_power_on,
582         .power_off = ardbeg_ar0261_power_off,
583         .mclk_name = "mclk2",
584 };
585
586 static int ardbeg_imx135_get_extra_regulators(struct imx135_power_rail *pw)
587 {
588         if (!pw->ext_reg1) {
589                 pw->ext_reg1 = regulator_get(NULL, "imx135_reg1");
590                 if (WARN_ON(IS_ERR(pw->ext_reg1))) {
591                         pr_err("%s: can't get regulator imx135_reg1: %ld\n",
592                                 __func__, PTR_ERR(pw->ext_reg1));
593                         pw->ext_reg1 = NULL;
594                         return -ENODEV;
595                 }
596         }
597
598         if (!pw->ext_reg2) {
599                 pw->ext_reg2 = regulator_get(NULL, "imx135_reg2");
600                 if (WARN_ON(IS_ERR(pw->ext_reg2))) {
601                         pr_err("%s: can't get regulator imx135_reg2: %ld\n",
602                                 __func__, PTR_ERR(pw->ext_reg2));
603                         pw->ext_reg2 = NULL;
604                         return -ENODEV;
605                 }
606         }
607
608         return 0;
609 }
610
611 static int ardbeg_imx135_power_on(struct imx135_power_rail *pw)
612 {
613         int err;
614
615         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd)))
616                 return -EFAULT;
617
618         /* disable CSIA/B IOs DPD mode to turn on camera for ardbeg */
619         tegra_io_dpd_disable(&csia_io);
620         tegra_io_dpd_disable(&csib_io);
621
622         if (ardbeg_imx135_get_extra_regulators(pw))
623                 goto imx135_poweron_fail;
624
625         err = regulator_enable(pw->ext_reg1);
626         if (unlikely(err))
627                 goto imx135_ext_reg1_fail;
628
629         err = regulator_enable(pw->ext_reg2);
630         if (unlikely(err))
631                 goto imx135_ext_reg2_fail;
632
633
634         gpio_set_value(CAM_AF_PWDN, 1);
635         gpio_set_value(CAM1_PWDN, 0);
636         usleep_range(10, 20);
637
638         err = regulator_enable(pw->avdd);
639         if (err)
640                 goto imx135_avdd_fail;
641
642         err = regulator_enable(pw->iovdd);
643         if (err)
644                 goto imx135_iovdd_fail;
645
646         usleep_range(1, 2);
647         gpio_set_value(CAM1_PWDN, 1);
648
649         usleep_range(300, 310);
650
651         return 1;
652
653
654 imx135_iovdd_fail:
655         regulator_disable(pw->avdd);
656
657 imx135_avdd_fail:
658         if (pw->ext_reg2)
659                 regulator_disable(pw->ext_reg2);
660
661 imx135_ext_reg2_fail:
662         if (pw->ext_reg1)
663                 regulator_disable(pw->ext_reg1);
664         gpio_set_value(CAM_AF_PWDN, 0);
665
666 imx135_ext_reg1_fail:
667 imx135_poweron_fail:
668         tegra_io_dpd_enable(&csia_io);
669         tegra_io_dpd_enable(&csib_io);
670         pr_err("%s failed.\n", __func__);
671         return -ENODEV;
672 }
673
674 static int ardbeg_imx135_power_off(struct imx135_power_rail *pw)
675 {
676         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd))) {
677                 tegra_io_dpd_enable(&csia_io);
678                 tegra_io_dpd_enable(&csib_io);
679                 return -EFAULT;
680         }
681
682         regulator_disable(pw->iovdd);
683         regulator_disable(pw->avdd);
684
685         regulator_disable(pw->ext_reg1);
686         regulator_disable(pw->ext_reg2);
687
688         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
689         tegra_io_dpd_enable(&csia_io);
690         tegra_io_dpd_enable(&csib_io);
691         return 0;
692 }
693
694 static int ardbeg_ar1335_power_on(struct ar1335_power_rail *pw)
695 {
696         int err;
697
698         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd)))
699                 return -EFAULT;
700
701         /* disable CSIA/B IOs DPD mode to turn on camera for ardbeg */
702         tegra_io_dpd_disable(&csia_io);
703         tegra_io_dpd_disable(&csib_io);
704
705         gpio_set_value(CAM_RSTN, 0);
706         usleep_range(10, 20);
707
708         err = regulator_enable(pw->avdd);
709         if (err)
710                 goto ar1335_avdd_fail;
711
712         err = regulator_enable(pw->iovdd);
713         if (err)
714                 goto ar1335_iovdd_fail;
715
716         err = regulator_enable(pw->dvdd);
717         if (err)
718                 goto ar1335_dvdd_fail;
719
720         usleep_range(1, 2);
721         gpio_set_value(CAM_RSTN, 1);
722
723         usleep_range(300, 310);
724
725         return 0;
726
727 ar1335_dvdd_fail:
728         regulator_disable(pw->iovdd);
729
730 ar1335_iovdd_fail:
731         regulator_disable(pw->avdd);
732
733 ar1335_avdd_fail:
734         tegra_io_dpd_enable(&csia_io);
735         tegra_io_dpd_enable(&csib_io);
736         pr_err("%s failed.\n", __func__);
737         return -ENODEV;
738 }
739
740 static int ardbeg_ar1335_power_off(struct ar1335_power_rail *pw)
741 {
742         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd))) {
743                 tegra_io_dpd_enable(&csia_io);
744                 tegra_io_dpd_enable(&csib_io);
745                 return -EFAULT;
746         }
747
748         regulator_disable(pw->iovdd);
749         regulator_disable(pw->avdd);
750         regulator_disable(pw->dvdd);
751
752         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
753         tegra_io_dpd_enable(&csia_io);
754         tegra_io_dpd_enable(&csib_io);
755         return 0;
756 }
757
758 static int ardbeg_imx179_power_on(struct imx179_power_rail *pw)
759 {
760         int err;
761
762         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd)))
763                 return -EFAULT;
764
765         /* disable CSIA/B IOs DPD mode to turn on camera for ardbeg */
766         tegra_io_dpd_disable(&csia_io);
767         tegra_io_dpd_disable(&csib_io);
768
769         gpio_set_value(CAM_AF_PWDN, 1);
770         gpio_set_value(CAM_RSTN, 0);
771         gpio_set_value(CAM1_PWDN, 0);
772         usleep_range(10, 20);
773
774         err = regulator_enable(pw->avdd);
775         if (err)
776                 goto imx179_avdd_fail;
777
778         err = regulator_enable(pw->iovdd);
779         if (err)
780                 goto imx179_iovdd_fail;
781
782         err = regulator_enable(pw->dvdd);
783         if (err)
784                 goto imx179_dvdd_fail;
785
786         usleep_range(1, 2);
787         gpio_set_value(CAM_RSTN, 1);
788
789         usleep_range(300, 310);
790
791         return 1;
792
793
794 imx179_dvdd_fail:
795         regulator_disable(pw->iovdd);
796
797 imx179_iovdd_fail:
798         regulator_disable(pw->avdd);
799
800 imx179_avdd_fail:
801         tegra_io_dpd_enable(&csia_io);
802         tegra_io_dpd_enable(&csib_io);
803         pr_err("%s failed.\n", __func__);
804         return -ENODEV;
805 }
806
807 static int ardbeg_imx179_power_off(struct imx179_power_rail *pw)
808 {
809         if (unlikely(WARN_ON(!pw || !pw->iovdd || !pw->avdd))) {
810                 tegra_io_dpd_enable(&csia_io);
811                 tegra_io_dpd_enable(&csib_io);
812                 return -EFAULT;
813         }
814
815         regulator_disable(pw->dvdd);
816         regulator_disable(pw->iovdd);
817         regulator_disable(pw->avdd);
818
819         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
820         tegra_io_dpd_enable(&csia_io);
821         tegra_io_dpd_enable(&csib_io);
822         return 0;
823 }
824
825 struct ar1335_platform_data ardbeg_ar1335_data = {
826         .flash_cap = {
827                 .enable = 1,
828                 .edge_trig_en = 1,
829                 .start_edge = 0,
830                 .repeat = 1,
831                 .delay_frm = 0,
832         },
833         .power_on = ardbeg_ar1335_power_on,
834         .power_off = ardbeg_ar1335_power_off,
835 };
836
837 struct imx135_platform_data ardbeg_imx135_data = {
838         .flash_cap = {
839                 .enable = 1,
840                 .edge_trig_en = 1,
841                 .start_edge = 0,
842                 .repeat = 1,
843                 .delay_frm = 0,
844         },
845         .ext_reg = true,
846         .power_on = ardbeg_imx135_power_on,
847         .power_off = ardbeg_imx135_power_off,
848 };
849
850 struct imx179_platform_data ardbeg_imx179_data = {
851         .flash_cap = {
852                 .enable = 1,
853                 .edge_trig_en = 1,
854                 .start_edge = 0,
855                 .repeat = 1,
856                 .delay_frm = 0,
857         },
858         .power_on = ardbeg_imx179_power_on,
859         .power_off = ardbeg_imx179_power_off,
860 };
861
862 struct ov4689_platform_data ardbeg_ov4689_data = {
863         .flash_cap = {
864                 .enable = 0,
865                 .edge_trig_en = 1,
866                 .start_edge = 0,
867                 .repeat = 1,
868                 .delay_frm = 0,
869         },
870         .power_on = ardbeg_ov4689_power_on,
871         .power_off = ardbeg_ov4689_power_off,
872 };
873
874 static int ardbeg_dw9718_power_on(struct dw9718_power_rail *pw)
875 {
876         int err;
877         pr_info("%s\n", __func__);
878
879         if (unlikely(!pw || !pw->vdd || !pw->vdd_i2c || !pw->vana))
880                 return -EFAULT;
881
882         err = regulator_enable(pw->vdd);
883         if (unlikely(err))
884                 goto dw9718_vdd_fail;
885
886         err = regulator_enable(pw->vdd_i2c);
887         if (unlikely(err))
888                 goto dw9718_i2c_fail;
889
890         err = regulator_enable(pw->vana);
891         if (unlikely(err))
892                 goto dw9718_ana_fail;
893
894         usleep_range(1000, 1020);
895
896         /* return 1 to skip the in-driver power_on sequence */
897         pr_debug("%s --\n", __func__);
898         return 1;
899
900 dw9718_ana_fail:
901         regulator_disable(pw->vdd_i2c);
902
903 dw9718_i2c_fail:
904         regulator_disable(pw->vdd);
905
906 dw9718_vdd_fail:
907         pr_err("%s FAILED\n", __func__);
908         return -ENODEV;
909 }
910
911 static int ardbeg_dw9718_power_off(struct dw9718_power_rail *pw)
912 {
913         pr_info("%s\n", __func__);
914
915         if (unlikely(!pw || !pw->vdd || !pw->vdd_i2c || !pw->vana))
916                 return -EFAULT;
917
918         regulator_disable(pw->vdd);
919         regulator_disable(pw->vdd_i2c);
920         regulator_disable(pw->vana);
921
922         return 1;
923 }
924
925 static u16 dw9718_devid;
926 static int ardbeg_dw9718_detect(void *buf, size_t size)
927 {
928         dw9718_devid = 0x9718;
929         return 0;
930 }
931
932 static struct nvc_focus_cap dw9718_cap = {
933         .settle_time = 30,
934         .slew_rate = 0x3A200C,
935         .focus_macro = 450,
936         .focus_infinity = 200,
937         .focus_hyper = 200,
938 };
939
940 static struct dw9718_platform_data ardbeg_dw9718_data = {
941         .cfg = NVC_CFG_NODEV,
942         .num = 0,
943         .sync = 0,
944         .dev_name = "focuser",
945         .cap = &dw9718_cap,
946         .power_on = ardbeg_dw9718_power_on,
947         .power_off = ardbeg_dw9718_power_off,
948         .detect = ardbeg_dw9718_detect,
949 };
950
951 static struct as364x_platform_data ardbeg_as3648_data = {
952         .config         = {
953                 .led_mask       = 3,
954                 .max_total_current_mA = 1000,
955                 .max_peak_current_mA = 600,
956                 .max_torch_current_mA = 600,
957                 .vin_low_v_run_mV = 3070,
958                 .strobe_type = 1,
959                 },
960         .pinstate       = {
961                 .mask   = 1 << (CAM_FLASH_STROBE - TEGRA_GPIO_PBB0),
962                 .values = 1 << (CAM_FLASH_STROBE - TEGRA_GPIO_PBB0)
963                 },
964         .dev_name       = "torch",
965         .type           = AS3648,
966         .gpio_strobe    = CAM_FLASH_STROBE,
967 };
968
969 static int ardbeg_ov7695_power_on(struct ov7695_power_rail *pw)
970 {
971         int err;
972
973         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd)))
974                 return -EFAULT;
975
976         /* disable CSIE IOs DPD mode to turn on front camera for ardbeg */
977         tegra_io_dpd_disable(&csie_io);
978
979         gpio_set_value(CAM2_PWDN, 0);
980         usleep_range(1000, 1020);
981
982         err = regulator_enable(pw->avdd);
983         if (unlikely(err))
984                 goto ov7695_avdd_fail;
985         usleep_range(300, 320);
986
987         err = regulator_enable(pw->iovdd);
988         if (unlikely(err))
989                 goto ov7695_iovdd_fail;
990         usleep_range(1000, 1020);
991
992         gpio_set_value(CAM2_PWDN, 1);
993         usleep_range(1000, 1020);
994
995         return 0;
996
997 ov7695_iovdd_fail:
998         regulator_disable(pw->avdd);
999
1000 ov7695_avdd_fail:
1001         gpio_set_value(CAM_RSTN, 0);
1002         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
1003         tegra_io_dpd_enable(&csie_io);
1004         return -ENODEV;
1005 }
1006
1007 static int ardbeg_ov7695_power_off(struct ov7695_power_rail *pw)
1008 {
1009         if (unlikely(WARN_ON(!pw || !pw->avdd || !pw->iovdd))) {
1010                 /* put CSIE IOs into DPD mode to
1011                  * save additional power for ardbeg
1012                  */
1013                 tegra_io_dpd_enable(&csie_io);
1014                 return -EFAULT;
1015         }
1016         usleep_range(100, 120);
1017
1018         gpio_set_value(CAM2_PWDN, 0);
1019         usleep_range(100, 120);
1020
1021         regulator_disable(pw->iovdd);
1022         usleep_range(100, 120);
1023
1024         regulator_disable(pw->avdd);
1025
1026         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
1027         tegra_io_dpd_enable(&csie_io);
1028         return 0;
1029 }
1030
1031 struct ov7695_platform_data ardbeg_ov7695_pdata = {
1032         .power_on = ardbeg_ov7695_power_on,
1033         .power_off = ardbeg_ov7695_power_off,
1034         .mclk_name = "mclk2",
1035 };
1036
1037 static int ardbeg_mt9m114_power_on(struct mt9m114_power_rail *pw)
1038 {
1039         int err;
1040         if (unlikely(!pw || !pw->avdd || !pw->iovdd))
1041                 return -EFAULT;
1042
1043         /* disable CSIE IOs DPD mode to turn on front camera for ardbeg */
1044         tegra_io_dpd_disable(&csie_io);
1045
1046         gpio_set_value(CAM_RSTN, 0);
1047         gpio_set_value(CAM2_PWDN, 1);
1048         usleep_range(1000, 1020);
1049
1050         err = regulator_enable(pw->iovdd);
1051         if (unlikely(err))
1052                 goto mt9m114_iovdd_fail;
1053
1054         err = regulator_enable(pw->avdd);
1055         if (unlikely(err))
1056                 goto mt9m114_avdd_fail;
1057
1058         usleep_range(1000, 1020);
1059         gpio_set_value(CAM_RSTN, 1);
1060         gpio_set_value(CAM2_PWDN, 0);
1061         usleep_range(1000, 1020);
1062
1063         /* return 1 to skip the in-driver power_on swquence */
1064         return 1;
1065
1066 mt9m114_avdd_fail:
1067         regulator_disable(pw->iovdd);
1068
1069 mt9m114_iovdd_fail:
1070         gpio_set_value(CAM_RSTN, 0);
1071         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
1072         tegra_io_dpd_enable(&csie_io);
1073         return -ENODEV;
1074 }
1075
1076 static int ardbeg_mt9m114_power_off(struct mt9m114_power_rail *pw)
1077 {
1078         if (unlikely(!pw || !pw->avdd || !pw->iovdd)) {
1079                 /* put CSIE IOs into DPD mode to
1080                  * save additional power for ardbeg
1081                  */
1082                 tegra_io_dpd_enable(&csie_io);
1083                 return -EFAULT;
1084         }
1085
1086         usleep_range(100, 120);
1087         gpio_set_value(CAM_RSTN, 0);
1088         usleep_range(100, 120);
1089         regulator_disable(pw->avdd);
1090         usleep_range(100, 120);
1091         regulator_disable(pw->iovdd);
1092
1093         /* put CSIE IOs into DPD mode to save additional power for ardbeg */
1094         tegra_io_dpd_enable(&csie_io);
1095         return 1;
1096 }
1097
1098 struct mt9m114_platform_data ardbeg_mt9m114_pdata = {
1099         .power_on = ardbeg_mt9m114_power_on,
1100         .power_off = ardbeg_mt9m114_power_off,
1101         .mclk_name = "mclk2",
1102 };
1103
1104
1105 static int ardbeg_ov5693_power_on(struct ov5693_power_rail *pw)
1106 {
1107         int err;
1108
1109         if (unlikely(WARN_ON(!pw || !pw->dovdd || !pw->avdd)))
1110                 return -EFAULT;
1111
1112         /* disable CSIA/B IOs DPD mode to turn on camera for ardbeg */
1113         tegra_io_dpd_disable(&csia_io);
1114         tegra_io_dpd_disable(&csib_io);
1115
1116         if (ardbeg_get_extra_regulators())
1117                 goto ov5693_poweron_fail;
1118
1119         gpio_set_value(CAM1_PWDN, 0);
1120         usleep_range(10, 20);
1121
1122         err = regulator_enable(pw->avdd);
1123         if (err)
1124                 goto ov5693_avdd_fail;
1125
1126         err = regulator_enable(pw->dovdd);
1127         if (err)
1128                 goto ov5693_iovdd_fail;
1129
1130         udelay(2);
1131         gpio_set_value(CAM1_PWDN, 1);
1132
1133         err = regulator_enable(ardbeg_vcmvdd);
1134         if (unlikely(err))
1135                 goto ov5693_vcmvdd_fail;
1136
1137         usleep_range(1000, 1110);
1138
1139         return 0;
1140
1141 ov5693_vcmvdd_fail:
1142         regulator_disable(pw->dovdd);
1143
1144 ov5693_iovdd_fail:
1145         regulator_disable(pw->avdd);
1146
1147 ov5693_avdd_fail:
1148         gpio_set_value(CAM1_PWDN, 0);
1149
1150 ov5693_poweron_fail:
1151         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
1152         tegra_io_dpd_enable(&csia_io);
1153         tegra_io_dpd_enable(&csib_io);
1154         pr_err("%s FAILED\n", __func__);
1155         return -ENODEV;
1156 }
1157
1158 static int ardbeg_ov5693_power_off(struct ov5693_power_rail *pw)
1159 {
1160         if (unlikely(WARN_ON(!pw || !pw->dovdd || !pw->avdd))) {
1161                 /* put CSIA/B IOs into DPD mode to
1162                  * save additional power for ardbeg
1163                  */
1164                 tegra_io_dpd_enable(&csia_io);
1165                 tegra_io_dpd_enable(&csib_io);
1166                 return -EFAULT;
1167         }
1168
1169         usleep_range(21, 25);
1170         gpio_set_value(CAM1_PWDN, 0);
1171         udelay(2);
1172
1173         regulator_disable(ardbeg_vcmvdd);
1174         regulator_disable(pw->dovdd);
1175         regulator_disable(pw->avdd);
1176
1177         /* put CSIA/B IOs into DPD mode to save additional power for ardbeg */
1178         tegra_io_dpd_enable(&csia_io);
1179         tegra_io_dpd_enable(&csib_io);
1180         return 0;
1181 }
1182
1183 static struct nvc_gpio_pdata ov5693_gpio_pdata[] = {
1184         { OV5693_GPIO_TYPE_PWRDN, CAM1_PWDN, true, 0, },
1185 };
1186
1187 #define NV_GUID(a, b, c, d, e, f, g, h) \
1188         ((u64) ((((a)&0xffULL) << 56ULL) | (((b)&0xffULL) << 48ULL) | \
1189         (((c)&0xffULL) << 40ULL) | (((d)&0xffULL) << 32ULL) | \
1190         (((e)&0xffULL) << 24ULL) | (((f)&0xffULL) << 16ULL) | \
1191         (((g)&0xffULL) << 8ULL) | (((h)&0xffULL))))
1192
1193 static struct nvc_imager_cap ov5693_cap = {
1194         .identifier                             = "OV5693",
1195         .sensor_nvc_interface   = 3,
1196         .pixel_types[0]                 = 0x101,
1197         .orientation                    = 0,
1198         .direction                              = 0,
1199         .initial_clock_rate_khz = 6000,
1200         .clock_profiles[0] = {
1201                 .external_clock_khz     = 24000,
1202                 .clock_multiplier       = 8000000, /* value * 1000000 */
1203         },
1204         .clock_profiles[1] = {
1205                 .external_clock_khz     = 0,
1206                 .clock_multiplier       = 0,
1207         },
1208         .h_sync_edge                    = 0,
1209         .v_sync_edge                    = 0,
1210         .mclk_on_vgp0                   = 0,
1211         .csi_port                               = 0,
1212         .data_lanes                             = 2,
1213         .virtual_channel_id             = 0,
1214         .discontinuous_clk_mode = 1,
1215         .cil_threshold_settle   = 0,
1216         .min_blank_time_width   = 16,
1217         .min_blank_time_height  = 16,
1218         .preferred_mode_index   = 0,
1219         .focuser_guid                   =
1220                 NV_GUID('f', '_', 'A', 'D', '5', '8', '2', '3'),
1221         .torch_guid                             =
1222                 NV_GUID('l', '_', 'N', 'V', 'C', 'A', 'M', '0'),
1223         .cap_version                    = NVC_IMAGER_CAPABILITIES_VERSION2,
1224         .flash_control_enabled  = 0,
1225         .adjustable_flash_timing        = 0,
1226         .is_hdr                                 = 1,
1227 };
1228
1229
1230 static struct ov5693_platform_data ardbeg_ov5693_pdata = {
1231         .gpio_count     = ARRAY_SIZE(ov5693_gpio_pdata),
1232         .gpio           = ov5693_gpio_pdata,
1233         .power_on       = ardbeg_ov5693_power_on,
1234         .power_off      = ardbeg_ov5693_power_off,
1235         .dev_name       = "ov5693",
1236         .cap            = &ov5693_cap,
1237         .mclk_name      = "mclk",
1238         .regulators = {
1239                         .avdd = "avdd_ov5693",
1240                         .dvdd = "dvdd",
1241                         .dovdd = "dovdd",
1242         },
1243         .has_eeprom = 1,
1244 };
1245
1246 static int ardbeg_ov5693_front_power_on(struct ov5693_power_rail *pw)
1247 {
1248         int err;
1249
1250         if (unlikely(WARN_ON(!pw || !pw->dovdd || !pw->avdd)))
1251                 return -EFAULT;
1252
1253         if (ardbeg_get_extra_regulators())
1254                 goto ov5693_front_poweron_fail;
1255
1256         gpio_set_value(CAM2_PWDN, 0);
1257         gpio_set_value(CAM_RSTN, 0);
1258         usleep_range(10, 20);
1259
1260         err = regulator_enable(pw->avdd);
1261         if (err)
1262                 goto ov5693_front_avdd_fail;
1263
1264         err = regulator_enable(pw->dovdd);
1265         if (err)
1266                 goto ov5693_front_iovdd_fail;
1267
1268         udelay(2);
1269         gpio_set_value(CAM2_PWDN, 1);
1270         gpio_set_value(CAM_RSTN, 1);
1271
1272         err = regulator_enable(ardbeg_vcmvdd);
1273         if (unlikely(err))
1274                 goto ov5693_front_vcmvdd_fail;
1275
1276         usleep_range(1000, 1110);
1277
1278         return 0;
1279
1280 ov5693_front_vcmvdd_fail:
1281         regulator_disable(pw->dovdd);
1282
1283 ov5693_front_iovdd_fail:
1284         regulator_disable(pw->avdd);
1285
1286 ov5693_front_avdd_fail:
1287         gpio_set_value(CAM2_PWDN, 0);
1288         gpio_set_value(CAM_RSTN, 0);
1289
1290 ov5693_front_poweron_fail:
1291         pr_err("%s FAILED\n", __func__);
1292         return -ENODEV;
1293 }
1294
1295 static int ardbeg_ov5693_front_power_off(struct ov5693_power_rail *pw)
1296 {
1297         if (unlikely(WARN_ON(!pw || !pw->dovdd || !pw->avdd))) {
1298                 return -EFAULT;
1299         }
1300
1301         usleep_range(21, 25);
1302         gpio_set_value(CAM2_PWDN, 0);
1303         gpio_set_value(CAM_RSTN, 0);
1304         udelay(2);
1305
1306         regulator_disable(ardbeg_vcmvdd);
1307         regulator_disable(pw->dovdd);
1308         regulator_disable(pw->avdd);
1309
1310         return 0;
1311 }
1312
1313 static struct nvc_gpio_pdata ov5693_front_gpio_pdata[] = {
1314         { OV5693_GPIO_TYPE_PWRDN, CAM2_PWDN, true, 0, },
1315         { OV5693_GPIO_TYPE_PWRDN, CAM_RSTN, true, 0, },
1316 };
1317
1318 static struct nvc_imager_cap ov5693_front_cap = {
1319         .identifier                             = "OV5693.1",
1320         .sensor_nvc_interface   = 4,
1321         .pixel_types[0]                 = 0x101,
1322         .orientation                    = 0,
1323         .direction                              = 1,
1324         .initial_clock_rate_khz = 6000,
1325         .clock_profiles[0] = {
1326                 .external_clock_khz     = 24000,
1327                 .clock_multiplier       = 8000000, /* value * 1000000 */
1328         },
1329         .clock_profiles[1] = {
1330                 .external_clock_khz     = 0,
1331                 .clock_multiplier       = 0,
1332         },
1333         .h_sync_edge                    = 0,
1334         .v_sync_edge                    = 0,
1335         .mclk_on_vgp0                   = 0,
1336         .csi_port                               = 1,
1337         .data_lanes                             = 2,
1338         .virtual_channel_id             = 0,
1339         .discontinuous_clk_mode = 1,
1340         .cil_threshold_settle   = 0,
1341         .min_blank_time_width   = 16,
1342         .min_blank_time_height  = 16,
1343         .preferred_mode_index   = 0,
1344         .focuser_guid                   = 0,
1345         .torch_guid                             = 0,
1346         .cap_version                    = NVC_IMAGER_CAPABILITIES_VERSION2,
1347         .flash_control_enabled  = 0,
1348         .adjustable_flash_timing        = 0,
1349         .is_hdr                                 = 1,
1350 };
1351
1352 static struct ov5693_platform_data ardbeg_ov5693_front_pdata = {
1353         .gpio_count     = ARRAY_SIZE(ov5693_front_gpio_pdata),
1354         .gpio           = ov5693_front_gpio_pdata,
1355         .power_on       = ardbeg_ov5693_front_power_on,
1356         .power_off      = ardbeg_ov5693_front_power_off,
1357         .dev_name       = "ov5693.1",
1358         .mclk_name      = "mclk2",
1359         .cap            = &ov5693_front_cap,
1360         .regulators = {
1361                         .avdd = "vana",
1362                         .dvdd = "vdig",
1363                         .dovdd = "vif",
1364         },
1365         .has_eeprom = 0,
1366 };
1367
1368 static int ardbeg_ad5823_power_on(struct ad5823_platform_data *pdata)
1369 {
1370         int err = 0;
1371
1372         pr_info("%s\n", __func__);
1373         gpio_set_value_cansleep(pdata->gpio, 1);
1374         pdata->pwr_dev = AD5823_PWR_DEV_ON;
1375
1376         return err;
1377 }
1378
1379 static int ardbeg_ad5823_power_off(struct ad5823_platform_data *pdata)
1380 {
1381         pr_info("%s\n", __func__);
1382         gpio_set_value_cansleep(pdata->gpio, 0);
1383         pdata->pwr_dev = AD5823_PWR_DEV_OFF;
1384
1385         return 0;
1386 }
1387
1388 static struct ad5823_platform_data ardbeg_ad5823_pdata = {
1389         .gpio = CAM_AF_PWDN,
1390         .power_on       = ardbeg_ad5823_power_on,
1391         .power_off      = ardbeg_ad5823_power_off,
1392 };
1393
1394 static struct camera_data_blob ardbeg_camera_lut[] = {
1395         {"ardbeg_imx135_pdata", &ardbeg_imx135_data},
1396         {"ardbeg_dw9718_pdata", &ardbeg_dw9718_data},
1397         {"ardbeg_ar0261_pdata", &ardbeg_ar0261_data},
1398         {"ardbeg_mt9m114_pdata", &ardbeg_mt9m114_pdata},
1399         {"ardbeg_ov5693_pdata", &ardbeg_ov5693_pdata},
1400         {"ardbeg_ad5823_pdata", &ardbeg_ad5823_pdata},
1401         {"ardbeg_as3648_pdata", &ardbeg_as3648_data},
1402         {"ardbeg_ov7695_pdata", &ardbeg_ov7695_pdata},
1403         {"ardbeg_ov5693f_pdata", &ardbeg_ov5693_front_pdata},
1404         {"ardbeg_ar0330_pdata", &ardbeg_ar0330_data},
1405         {"ardbeg_ar0330_front_pdata", &ardbeg_ar0330_front_data},
1406         {"ardbeg_ov4689_pdata", &ardbeg_ov4689_data},
1407         {"ardbeg_ar1335_pdata", &ardbeg_ar1335_data},
1408         {},
1409 };
1410
1411 void __init ardbeg_camera_auxdata(void *data)
1412 {
1413         struct of_dev_auxdata *aux_lut = data;
1414         while (aux_lut && aux_lut->compatible) {
1415                 if (!strcmp(aux_lut->compatible, "nvidia,tegra124-camera")) {
1416                         pr_info("%s: update camera lookup table.\n", __func__);
1417                         aux_lut->platform_data = ardbeg_camera_lut;
1418                 }
1419                 aux_lut++;
1420         }
1421 }
1422
1423 static int ardbeg_camera_init(void)
1424 {
1425         struct board_info board_info;
1426
1427         pr_debug("%s: ++\n", __func__);
1428         tegra_get_board_info(&board_info);
1429
1430         /* put CSIA/B/C/D/E IOs into DPD mode to
1431          * save additional power for ardbeg
1432          */
1433         tegra_io_dpd_enable(&csia_io);
1434         tegra_io_dpd_enable(&csib_io);
1435         tegra_io_dpd_enable(&csie_io);
1436
1437 #if IS_ENABLED(CONFIG_SOC_CAMERA_PLATFORM)
1438         platform_device_register(&ardbeg_soc_camera_device);
1439 #endif
1440
1441 #if IS_ENABLED(CONFIG_SOC_CAMERA_IMX135)
1442         platform_device_register(&ardbeg_imx135_soc_camera_device);
1443 #endif
1444
1445 #if IS_ENABLED(CONFIG_SOC_CAMERA_AR0261)
1446         platform_device_register(&ardbeg_ar0261_soc_camera_device);
1447 #endif
1448         return 0;
1449 }
1450
1451 static struct pid_thermal_gov_params cpu_pid_params = {
1452         .max_err_temp = 4000,
1453         .max_err_gain = 1000,
1454
1455         .gain_p = 1000,
1456         .gain_d = 0,
1457
1458         .up_compensation = 15,
1459         .down_compensation = 15,
1460 };
1461
1462 static struct thermal_zone_params cpu_tzp = {
1463         .governor_name = "pid_thermal_gov",
1464         .governor_params = &cpu_pid_params,
1465 };
1466
1467 static struct thermal_zone_params board_tzp = {
1468         .governor_name = "pid_thermal_gov"
1469 };
1470
1471 static struct throttle_table cpu_throttle_table[] = {
1472         /* CPU_THROT_LOW cannot be used by other than CPU */
1473         /*      CPU,    GPU,  C2BUS,  C3BUS,   SCLK,    EMC   */
1474         { { 2295000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1475         { { 2269500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1476         { { 2244000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1477         { { 2218500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1478         { { 2193000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1479         { { 2167500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1480         { { 2142000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1481         { { 2116500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1482         { { 2091000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1483         { { 2065500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1484         { { 2040000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1485         { { 2014500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1486         { { 1989000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1487         { { 1963500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1488         { { 1938000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1489         { { 1912500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1490         { { 1887000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1491         { { 1861500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1492         { { 1836000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1493         { { 1810500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1494         { { 1785000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1495         { { 1759500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1496         { { 1734000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1497         { { 1708500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1498         { { 1683000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1499         { { 1657500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1500         { { 1632000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1501         { { 1606500, 790000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1502         { { 1581000, 776000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1503         { { 1555500, 762000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1504         { { 1530000, 749000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1505         { { 1504500, 735000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1506         { { 1479000, 721000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1507         { { 1453500, 707000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1508         { { 1428000, 693000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1509         { { 1402500, 679000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1510         { { 1377000, 666000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1511         { { 1351500, 652000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1512         { { 1326000, 638000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1513         { { 1300500, 624000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1514         { { 1275000, 610000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1515         { { 1249500, 596000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1516         { { 1224000, 582000, NO_CAP, NO_CAP, NO_CAP, 792000 } },
1517         { { 1198500, 569000, NO_CAP, NO_CAP, NO_CAP, 792000 } },
1518         { { 1173000, 555000, NO_CAP, NO_CAP, 360000, 792000 } },
1519         { { 1147500, 541000, NO_CAP, NO_CAP, 360000, 792000 } },
1520         { { 1122000, 527000, NO_CAP, 684000, 360000, 792000 } },
1521         { { 1096500, 513000, 444000, 684000, 360000, 792000 } },
1522         { { 1071000, 499000, 444000, 684000, 360000, 792000 } },
1523         { { 1045500, 486000, 444000, 684000, 360000, 792000 } },
1524         { { 1020000, 472000, 444000, 684000, 324000, 792000 } },
1525         { {  994500, 458000, 444000, 684000, 324000, 792000 } },
1526         { {  969000, 444000, 444000, 600000, 324000, 792000 } },
1527         { {  943500, 430000, 444000, 600000, 324000, 792000 } },
1528         { {  918000, 416000, 396000, 600000, 324000, 792000 } },
1529         { {  892500, 402000, 396000, 600000, 324000, 792000 } },
1530         { {  867000, 389000, 396000, 600000, 324000, 792000 } },
1531         { {  841500, 375000, 396000, 600000, 288000, 792000 } },
1532         { {  816000, 361000, 396000, 600000, 288000, 792000 } },
1533         { {  790500, 347000, 396000, 600000, 288000, 792000 } },
1534         { {  765000, 333000, 396000, 504000, 288000, 792000 } },
1535         { {  739500, 319000, 348000, 504000, 288000, 792000 } },
1536         { {  714000, 306000, 348000, 504000, 288000, 624000 } },
1537         { {  688500, 292000, 348000, 504000, 288000, 624000 } },
1538         { {  663000, 278000, 348000, 504000, 288000, 624000 } },
1539         { {  637500, 264000, 348000, 504000, 288000, 624000 } },
1540         { {  612000, 250000, 348000, 504000, 252000, 624000 } },
1541         { {  586500, 236000, 348000, 504000, 252000, 624000 } },
1542         { {  561000, 222000, 348000, 420000, 252000, 624000 } },
1543         { {  535500, 209000, 288000, 420000, 252000, 624000 } },
1544         { {  510000, 195000, 288000, 420000, 252000, 624000 } },
1545         { {  484500, 181000, 288000, 420000, 252000, 624000 } },
1546         { {  459000, 167000, 288000, 420000, 252000, 624000 } },
1547         { {  433500, 153000, 288000, 420000, 252000, 396000 } },
1548         { {  408000, 139000, 288000, 420000, 252000, 396000 } },
1549         { {  382500, 126000, 288000, 420000, 252000, 396000 } },
1550         { {  357000, 112000, 288000, 420000, 252000, 396000 } },
1551         { {  331500,  98000, 288000, 420000, 252000, 396000 } },
1552         { {  306000,  84000, 288000, 420000, 252000, 396000 } },
1553         { {  280500,  84000, 288000, 420000, 252000, 396000 } },
1554         { {  255000,  84000, 288000, 420000, 252000, 396000 } },
1555         { {  229500,  84000, 288000, 420000, 252000, 396000 } },
1556         { {  204000,  84000, 288000, 420000, 252000, 396000 } },
1557 };
1558
1559 static struct balanced_throttle cpu_throttle = {
1560         .throt_tab_size = ARRAY_SIZE(cpu_throttle_table),
1561         .throt_tab = cpu_throttle_table,
1562 };
1563
1564 static struct throttle_table gpu_throttle_table[] = {
1565         /* CPU_THROT_LOW cannot be used by other than CPU */
1566         /*      CPU,    GPU,  C2BUS,  C3BUS,   SCLK,    EMC   */
1567         { { 2295000, 782800, 480000, 756000, 384000, 924000 } },
1568         { { 2269500, 772200, 480000, 756000, 384000, 924000 } },
1569         { { 2244000, 761600, 480000, 756000, 384000, 924000 } },
1570         { { 2218500, 751100, 480000, 756000, 384000, 924000 } },
1571         { { 2193000, 740500, 480000, 756000, 384000, 924000 } },
1572         { { 2167500, 729900, 480000, 756000, 384000, 924000 } },
1573         { { 2142000, 719300, 480000, 756000, 384000, 924000 } },
1574         { { 2116500, 708700, 480000, 756000, 384000, 924000 } },
1575         { { 2091000, 698100, 480000, 756000, 384000, 924000 } },
1576         { { 2065500, 687500, 480000, 756000, 384000, 924000 } },
1577         { { 2040000, 676900, 480000, 756000, 384000, 924000 } },
1578         { { 2014500, 666000, 480000, 756000, 384000, 924000 } },
1579         { { 1989000, 656000, 480000, 756000, 384000, 924000 } },
1580         { { 1963500, 645000, 480000, 756000, 384000, 924000 } },
1581         { { 1938000, 635000, 480000, 756000, 384000, 924000 } },
1582         { { 1912500, 624000, 480000, 756000, 384000, 924000 } },
1583         { { 1887000, 613000, 480000, 756000, 384000, 924000 } },
1584         { { 1861500, 603000, 480000, 756000, 384000, 924000 } },
1585         { { 1836000, 592000, 480000, 756000, 384000, 924000 } },
1586         { { 1810500, 582000, 480000, 756000, 384000, 924000 } },
1587         { { 1785000, 571000, 480000, 756000, 384000, 924000 } },
1588         { { 1759500, 560000, 480000, 756000, 384000, 924000 } },
1589         { { 1734000, 550000, 480000, 756000, 384000, 924000 } },
1590         { { 1708500, 539000, 480000, 756000, 384000, 924000 } },
1591         { { 1683000, 529000, 480000, 756000, 384000, 924000 } },
1592         { { 1657500, 518000, 480000, 756000, 384000, 924000 } },
1593         { { 1632000, 508000, 480000, 756000, 384000, 924000 } },
1594         { { 1606500, 497000, 480000, 756000, 384000, 924000 } },
1595         { { 1581000, 486000, 480000, 756000, 384000, 924000 } },
1596         { { 1555500, 476000, 480000, 756000, 384000, 924000 } },
1597         { { 1530000, 465000, 480000, 756000, 384000, 924000 } },
1598         { { 1504500, 455000, 480000, 756000, 384000, 924000 } },
1599         { { 1479000, 444000, 480000, 756000, 384000, 924000 } },
1600         { { 1453500, 433000, 480000, 756000, 384000, 924000 } },
1601         { { 1428000, 423000, 480000, 756000, 384000, 924000 } },
1602         { { 1402500, 412000, 480000, 756000, 384000, 924000 } },
1603         { { 1377000, 402000, 480000, 756000, 384000, 924000 } },
1604         { { 1351500, 391000, 480000, 756000, 384000, 924000 } },
1605         { { 1326000, 380000, 480000, 756000, 384000, 924000 } },
1606         { { 1300500, 370000, 480000, 756000, 384000, 924000 } },
1607         { { 1275000, 359000, 480000, 756000, 384000, 924000 } },
1608         { { 1249500, 349000, 480000, 756000, 384000, 924000 } },
1609         { { 1224000, 338000, 480000, 756000, 384000, 792000 } },
1610         { { 1198500, 328000, 480000, 756000, 384000, 792000 } },
1611         { { 1173000, 317000, 480000, 756000, 360000, 792000 } },
1612         { { 1147500, 306000, 480000, 756000, 360000, 792000 } },
1613         { { 1122000, 296000, 480000, 684000, 360000, 792000 } },
1614         { { 1096500, 285000, 444000, 684000, 360000, 792000 } },
1615         { { 1071000, 275000, 444000, 684000, 360000, 792000 } },
1616         { { 1045500, 264000, 444000, 684000, 360000, 792000 } },
1617         { { 1020000, 253000, 444000, 684000, 324000, 792000 } },
1618         { {  994500, 243000, 444000, 684000, 324000, 792000 } },
1619         { {  969000, 232000, 444000, 600000, 324000, 792000 } },
1620         { {  943500, 222000, 444000, 600000, 324000, 792000 } },
1621         { {  918000, 211000, 396000, 600000, 324000, 792000 } },
1622         { {  892500, 200000, 396000, 600000, 324000, 792000 } },
1623         { {  867000, 190000, 396000, 600000, 324000, 792000 } },
1624         { {  841500, 179000, 396000, 600000, 288000, 792000 } },
1625         { {  816000, 169000, 396000, 600000, 288000, 792000 } },
1626         { {  790500, 158000, 396000, 600000, 288000, 792000 } },
1627         { {  765000, 148000, 396000, 504000, 288000, 792000 } },
1628         { {  739500, 137000, 348000, 504000, 288000, 792000 } },
1629         { {  714000, 126000, 348000, 504000, 288000, 624000 } },
1630         { {  688500, 116000, 348000, 504000, 288000, 624000 } },
1631         { {  663000, 105000, 348000, 504000, 288000, 624000 } },
1632         { {  637500,  95000, 348000, 504000, 288000, 624000 } },
1633         { {  612000,  84000, 348000, 504000, 252000, 624000 } },
1634         { {  586500,  84000, 348000, 504000, 252000, 624000 } },
1635         { {  561000,  84000, 348000, 420000, 252000, 624000 } },
1636         { {  535500,  84000, 288000, 420000, 252000, 624000 } },
1637         { {  510000,  84000, 288000, 420000, 252000, 624000 } },
1638         { {  484500,  84000, 288000, 420000, 252000, 624000 } },
1639         { {  459000,  84000, 288000, 420000, 252000, 624000 } },
1640         { {  433500,  84000, 288000, 420000, 252000, 396000 } },
1641         { {  408000,  84000, 288000, 420000, 252000, 396000 } },
1642         { {  382500,  84000, 288000, 420000, 252000, 396000 } },
1643         { {  357000,  84000, 288000, 420000, 252000, 396000 } },
1644         { {  331500,  84000, 288000, 420000, 252000, 396000 } },
1645         { {  306000,  84000, 288000, 420000, 252000, 396000 } },
1646         { {  280500,  84000, 288000, 420000, 252000, 396000 } },
1647         { {  255000,  84000, 288000, 420000, 252000, 396000 } },
1648         { {  229500,  84000, 288000, 420000, 252000, 396000 } },
1649         { {  204000,  84000, 288000, 420000, 252000, 396000 } },
1650 };
1651
1652 static struct balanced_throttle gpu_throttle = {
1653         .throt_tab_size = ARRAY_SIZE(gpu_throttle_table),
1654         .throt_tab = gpu_throttle_table,
1655 };
1656
1657 /* throttle table that sets all clocks to approximately 50% of their max */
1658 static struct throttle_table emergency_throttle_table[] = {
1659         /*      CPU,    GPU,  C2BUS,  C3BUS,   SCLK,    EMC   */
1660         { { 1122000, 391000, 288000, 420000, 252000, 396000 } },
1661 };
1662
1663 static struct balanced_throttle emergency_throttle = {
1664         .throt_tab_size = ARRAY_SIZE(emergency_throttle_table),
1665         .throt_tab = emergency_throttle_table,
1666 };
1667
1668 static int __init ardbeg_balanced_throttle_init(void)
1669 {
1670         if (of_machine_is_compatible("nvidia,ardbeg") ||
1671                 of_machine_is_compatible("nvidia,norrin") ||
1672                 of_machine_is_compatible("nvidia,bowmore") ||
1673                 of_machine_is_compatible("nvidia,tn8")) {
1674
1675                 if (!balanced_throttle_register(&cpu_throttle, "cpu-balanced"))
1676                         pr_err("balanced_throttle_register 'cpu-balanced' FAILED.\n");
1677                 if (!balanced_throttle_register(&gpu_throttle, "gpu-balanced"))
1678                         pr_err("balanced_throttle_register 'gpu-balanced' FAILED.\n");
1679                 if (!balanced_throttle_register(&emergency_throttle,
1680                                                                 "emergency-balanced"))
1681                         pr_err("balanced_throttle_register 'emergency-balanced' FAILED\n");
1682         }
1683
1684         return 0;
1685 }
1686 late_initcall(ardbeg_balanced_throttle_init);
1687
1688 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
1689 static struct thermal_trip_info skin_trips[] = {
1690         {
1691                 .cdev_type = "skin-balanced",
1692                 .trip_temp = 43000,
1693                 .trip_type = THERMAL_TRIP_PASSIVE,
1694                 .upper = THERMAL_NO_LIMIT,
1695                 .lower = THERMAL_NO_LIMIT,
1696                 .hysteresis = 0,
1697         }
1698 };
1699
1700 static struct therm_est_subdevice skin_devs[] = {
1701         {
1702                 .dev_data = "Tdiode_tegra",
1703                 .coeffs = {
1704                         2, 1, 1, 1,
1705                         1, 1, 1, 1,
1706                         1, 1, 1, 0,
1707                         1, 1, 0, 0,
1708                         0, 0, -1, -7
1709                 },
1710         },
1711         {
1712                 .dev_data = "Tboard_tegra",
1713                 .coeffs = {
1714                         -11, -7, -5, -3,
1715                         -3, -2, -1, 0,
1716                         0, 0, 1, 1,
1717                         1, 2, 2, 3,
1718                         4, 6, 11, 18
1719                 },
1720         },
1721 };
1722
1723 static struct therm_est_subdevice tn8ffd_skin_devs[] = {
1724         {
1725                 .dev_data = "Tdiode",
1726                 .coeffs = {
1727                         3, 0, 0, 0,
1728                         1, 0, -1, 0,
1729                         1, 0, 0, 1,
1730                         1, 0, 0, 0,
1731                         0, 1, 2, 2
1732                 },
1733         },
1734         {
1735                 .dev_data = "Tboard",
1736                 .coeffs = {
1737                         1, 1, 2, 8,
1738                         6, -8, -13, -9,
1739                         -9, -8, -17, -18,
1740                         -18, -16, 2, 17,
1741                         15, 27, 42, 60
1742                 },
1743         },
1744 };
1745
1746 static struct therm_est_subdevice tn8ffd_t132_skin_devs[] = {
1747         {
1748                 .dev_data = "Tdiode",
1749                 .coeffs = {
1750                         -1, -1, 0, -1,
1751                         0, -1, -1, 0,
1752                         0, 0, 1, 1,
1753                         1, 1, 2, 2,
1754                         2, 2, 3, 5
1755                 },
1756         },
1757         {
1758                 .dev_data = "Tboard",
1759                 .coeffs = {
1760                         -3, -1, 1, 1,
1761                         2, 1, 2, 1,
1762                         -1, -1, 0, 2,
1763                         3, 4, 5, 3,
1764                         3, 4, 6, 36
1765                 },
1766         },
1767 };
1768
1769 static struct pid_thermal_gov_params skin_pid_params = {
1770         .max_err_temp = 4000,
1771         .max_err_gain = 1000,
1772
1773         .gain_p = 1000,
1774         .gain_d = 0,
1775
1776         .up_compensation = 15,
1777         .down_compensation = 15,
1778 };
1779
1780 static struct thermal_zone_params skin_tzp = {
1781         .governor_name = "pid_thermal_gov",
1782         .governor_params = &skin_pid_params,
1783 };
1784
1785 static struct therm_est_data skin_data = {
1786         .num_trips = ARRAY_SIZE(skin_trips),
1787         .trips = skin_trips,
1788         .polling_period = 1100,
1789         .passive_delay = 15000,
1790         .tc1 = 10,
1791         .tc2 = 1,
1792         .tzp = &skin_tzp,
1793         .use_activator = 1,
1794 };
1795
1796 static struct throttle_table skin_throttle_table[] = {
1797         /* CPU_THROT_LOW cannot be used by other than CPU */
1798         /*      CPU,    GPU,  C2BUS,  C3BUS,   SCLK,    EMC   */
1799         { { 2295000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1800         { { 2269500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1801         { { 2244000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1802         { { 2218500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1803         { { 2193000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1804         { { 2167500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1805         { { 2142000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1806         { { 2116500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1807         { { 2091000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1808         { { 2065500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1809         { { 2040000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1810         { { 2014500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1811         { { 1989000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1812         { { 1963500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1813         { { 1938000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1814         { { 1912500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1815         { { 1887000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1816         { { 1861500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1817         { { 1836000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1818         { { 1810500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1819         { { 1785000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1820         { { 1759500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1821         { { 1734000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1822         { { 1708500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1823         { { 1683000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1824         { { 1657500, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1825         { { 1632000, NO_CAP, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1826         { { 1606500, 790000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1827         { { 1581000, 776000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1828         { { 1555500, 762000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1829         { { 1530000, 749000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1830         { { 1504500, 735000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1831         { { 1479000, 721000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1832         { { 1453500, 707000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1833         { { 1428000, 693000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1834         { { 1402500, 679000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1835         { { 1377000, 666000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1836         { { 1351500, 652000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1837         { { 1326000, 638000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1838         { { 1300500, 624000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1839         { { 1275000, 610000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1840         { { 1249500, 596000, NO_CAP, NO_CAP, NO_CAP, NO_CAP } },
1841         { { 1224000, 582000, NO_CAP, NO_CAP, NO_CAP, 792000 } },
1842         { { 1198500, 569000, NO_CAP, NO_CAP, NO_CAP, 792000 } },
1843         { { 1173000, 555000, NO_CAP, NO_CAP, 360000, 792000 } },
1844         { { 1147500, 541000, NO_CAP, NO_CAP, 360000, 792000 } },
1845         { { 1122000, 527000, NO_CAP, 684000, 360000, 792000 } },
1846         { { 1096500, 513000, 444000, 684000, 360000, 792000 } },
1847         { { 1071000, 499000, 444000, 684000, 360000, 792000 } },
1848         { { 1045500, 486000, 444000, 684000, 360000, 792000 } },
1849         { { 1020000, 472000, 444000, 684000, 324000, 792000 } },
1850         { {  994500, 458000, 444000, 684000, 324000, 792000 } },
1851         { {  969000, 444000, 444000, 600000, 324000, 792000 } },
1852         { {  943500, 430000, 444000, 600000, 324000, 792000 } },
1853         { {  918000, 416000, 396000, 600000, 324000, 792000 } },
1854         { {  892500, 402000, 396000, 600000, 324000, 792000 } },
1855         { {  867000, 389000, 396000, 600000, 324000, 792000 } },
1856         { {  841500, 375000, 396000, 600000, 288000, 792000 } },
1857         { {  816000, 361000, 396000, 600000, 288000, 792000 } },
1858         { {  790500, 347000, 396000, 600000, 288000, 792000 } },
1859         { {  765000, 333000, 396000, 504000, 288000, 792000 } },
1860         { {  739500, 319000, 348000, 504000, 288000, 792000 } },
1861         { {  714000, 306000, 348000, 504000, 288000, 624000 } },
1862         { {  688500, 292000, 348000, 504000, 288000, 624000 } },
1863         { {  663000, 278000, 348000, 504000, 288000, 624000 } },
1864         { {  637500, 264000, 348000, 504000, 288000, 624000 } },
1865         { {  612000, 250000, 348000, 504000, 252000, 624000 } },
1866         { {  586500, 236000, 348000, 504000, 252000, 624000 } },
1867         { {  561000, 222000, 348000, 420000, 252000, 624000 } },
1868         { {  535500, 209000, 288000, 420000, 252000, 624000 } },
1869         { {  510000, 195000, 288000, 420000, 252000, 624000 } },
1870         { {  484500, 181000, 288000, 420000, 252000, 624000 } },
1871         { {  459000, 167000, 288000, 420000, 252000, 624000 } },
1872         { {  433500, 153000, 288000, 420000, 252000, 396000 } },
1873         { {  408000, 139000, 288000, 420000, 252000, 396000 } },
1874         { {  382500, 126000, 288000, 420000, 252000, 396000 } },
1875         { {  357000, 112000, 288000, 420000, 252000, 396000 } },
1876         { {  331500,  98000, 288000, 420000, 252000, 396000 } },
1877         { {  306000,  84000, 288000, 420000, 252000, 396000 } },
1878         { {  280500,  84000, 288000, 420000, 252000, 396000 } },
1879         { {  255000,  84000, 288000, 420000, 252000, 396000 } },
1880         { {  229500,  84000, 288000, 420000, 252000, 396000 } },
1881         { {  204000,  84000, 288000, 420000, 252000, 396000 } },
1882 };
1883
1884 static struct balanced_throttle skin_throttle = {
1885         .throt_tab_size = ARRAY_SIZE(skin_throttle_table),
1886         .throt_tab = skin_throttle_table,
1887 };
1888
1889 static int __init ardbeg_skin_init(void)
1890 {
1891         struct board_info board_info;
1892
1893         if (of_machine_is_compatible("nvidia,ardbeg") ||
1894                 of_machine_is_compatible("nvidia,norrin") ||
1895                 of_machine_is_compatible("nvidia,bowmore") ||
1896                 of_machine_is_compatible("nvidia,tn8")) {
1897
1898                 tegra_get_board_info(&board_info);
1899
1900                 if (board_info.board_id == BOARD_P1761 &&
1901                                 board_info.fab == BOARD_FAB_D) {
1902                         skin_data.ndevs = ARRAY_SIZE(tn8ffd_t132_skin_devs);
1903                         skin_data.devs = tn8ffd_t132_skin_devs;
1904                         skin_data.toffset = 708;
1905                 } else if (board_info.board_id == BOARD_P1761 ||
1906                                 board_info.board_id == BOARD_E1784 ||
1907                                 board_info.board_id == BOARD_E1971 ||
1908                                 board_info.board_id == BOARD_E1991 ||
1909                                 board_info.board_id == BOARD_E1922) {
1910                         skin_data.ndevs = ARRAY_SIZE(tn8ffd_skin_devs);
1911                         skin_data.devs = tn8ffd_skin_devs;
1912                         skin_data.toffset = 4034;
1913                 } else {
1914                         skin_data.ndevs = ARRAY_SIZE(skin_devs);
1915                         skin_data.devs = skin_devs;
1916                         skin_data.toffset = 9793;
1917                 }
1918
1919                 tegra_skin_therm_est_device.dev.platform_data = &skin_data;
1920                 platform_device_register(&tegra_skin_therm_est_device);
1921
1922                 if (!balanced_throttle_register(&skin_throttle, "skin-balanced"))
1923                         pr_err("balanced_throttle_register 'skin-balanced' FAILED.\n");
1924         }
1925
1926         return 0;
1927 }
1928 late_initcall(ardbeg_skin_init);
1929 #endif
1930
1931 static struct nct1008_platform_data ardbeg_nct72_pdata = {
1932         .loc_name = "tegra",
1933         .supported_hwrev = true,
1934         .conv_rate = 0x06, /* 4Hz conversion rate */
1935         .offset = 0,
1936         .extended_range = true,
1937
1938         .sensors = {
1939                 [LOC] = {
1940                         .tzp = &board_tzp,
1941                         .shutdown_limit = 120, /* C */
1942                         .passive_delay = 1000,
1943                         .num_trips = 1,
1944                         .trips = {
1945                                 {
1946                                         .cdev_type = "therm_est_activ",
1947                                         .trip_temp = 40000,
1948                                         .trip_type = THERMAL_TRIP_ACTIVE,
1949                                         .hysteresis = 1000,
1950                                         .upper = THERMAL_NO_LIMIT,
1951                                         .lower = THERMAL_NO_LIMIT,
1952                                         .mask = 1,
1953                                 },
1954                         },
1955                 },
1956                 [EXT] = {
1957                         .tzp = &cpu_tzp,
1958                         .shutdown_limit = 95, /* C */
1959                         .passive_delay = 1000,
1960                         .num_trips = 2,
1961                         .trips = {
1962                                 {
1963                                         .cdev_type = "shutdown_warning",
1964                                         .trip_temp = 93000,
1965                                         .trip_type = THERMAL_TRIP_PASSIVE,
1966                                         .upper = THERMAL_NO_LIMIT,
1967                                         .lower = THERMAL_NO_LIMIT,
1968                                         .mask = 0,
1969                                 },
1970                                 {
1971                                         .cdev_type = "cpu-balanced",
1972                                         .trip_temp = 83000,
1973                                         .trip_type = THERMAL_TRIP_PASSIVE,
1974                                         .upper = THERMAL_NO_LIMIT,
1975                                         .lower = THERMAL_NO_LIMIT,
1976                                         .hysteresis = 1000,
1977                                         .mask = 1,
1978                                 },
1979                         }
1980                 }
1981         }
1982 };
1983
1984 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
1985 static struct nct1008_platform_data ardbeg_nct72_tskin_pdata = {
1986         .loc_name = "skin",
1987
1988         .supported_hwrev = true,
1989         .conv_rate = 0x06, /* 4Hz conversion rate */
1990         .offset = 0,
1991         .extended_range = true,
1992
1993         .sensors = {
1994                 [LOC] = {
1995                         .shutdown_limit = 95, /* C */
1996                         .num_trips = 0,
1997                         .tzp = NULL,
1998                 },
1999                 [EXT] = {
2000                         .shutdown_limit = 85, /* C */
2001                         .passive_delay = 10000,
2002                         .polling_delay = 1000,
2003                         .tzp = &skin_tzp,
2004                         .num_trips = 1,
2005                         .trips = {
2006                                 {
2007                                         .cdev_type = "skin-balanced",
2008                                         .trip_temp = 50000,
2009                                         .trip_type = THERMAL_TRIP_PASSIVE,
2010                                         .upper = THERMAL_NO_LIMIT,
2011                                         .lower = THERMAL_NO_LIMIT,
2012                                         .mask = 1,
2013                                 },
2014                         },
2015                 }
2016         }
2017 };
2018 #endif
2019
2020 static struct i2c_board_info ardbeg_i2c_nct72_board_info[] = {
2021         {
2022                 I2C_BOARD_INFO("nct72", 0x4c),
2023                 .platform_data = &ardbeg_nct72_pdata,
2024                 .irq = -1,
2025         },
2026 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
2027         {
2028                 I2C_BOARD_INFO("nct72", 0x4d),
2029                 .platform_data = &ardbeg_nct72_tskin_pdata,
2030                 .irq = -1,
2031         }
2032 #endif
2033 };
2034
2035 static int ardbeg_nct72_init(void)
2036 {
2037         int nct72_port = TEGRA_GPIO_PI6;
2038         int ret = 0;
2039         int i;
2040         struct thermal_trip_info *trip_state;
2041         struct board_info board_info;
2042
2043         tegra_get_board_info(&board_info);
2044         /* raise NCT's thresholds if soctherm CP,FT fuses are ok */
2045         if ((tegra_fuse_calib_base_get_cp(NULL, NULL) >= 0) &&
2046             (tegra_fuse_calib_base_get_ft(NULL, NULL) >= 0)) {
2047                 ardbeg_nct72_pdata.sensors[EXT].shutdown_limit += 20;
2048                 for (i = 0; i < ardbeg_nct72_pdata.sensors[EXT].num_trips;
2049                          i++) {
2050                         trip_state = &ardbeg_nct72_pdata.sensors[EXT].trips[i];
2051                         if (!strncmp(trip_state->cdev_type, "cpu-balanced",
2052                                         THERMAL_NAME_LENGTH)) {
2053                                 trip_state->cdev_type = "_none_";
2054                                 break;
2055                         }
2056                 }
2057         } else {
2058                 tegra_platform_edp_init(
2059                         ardbeg_nct72_pdata.sensors[EXT].trips,
2060                         &ardbeg_nct72_pdata.sensors[EXT].num_trips,
2061                                         12000); /* edp temperature margin */
2062                 tegra_add_cpu_vmax_trips(
2063                         ardbeg_nct72_pdata.sensors[EXT].trips,
2064                         &ardbeg_nct72_pdata.sensors[EXT].num_trips);
2065                 tegra_add_tgpu_trips(
2066                         ardbeg_nct72_pdata.sensors[EXT].trips,
2067                         &ardbeg_nct72_pdata.sensors[EXT].num_trips);
2068                 tegra_add_vc_trips(
2069                         ardbeg_nct72_pdata.sensors[EXT].trips,
2070                         &ardbeg_nct72_pdata.sensors[EXT].num_trips);
2071                 tegra_add_core_vmax_trips(
2072                         ardbeg_nct72_pdata.sensors[EXT].trips,
2073                         &ardbeg_nct72_pdata.sensors[EXT].num_trips);
2074         }
2075
2076         /* vmin trips are bound to soctherm on norrin */
2077         if (!(board_info.board_id == BOARD_PM374) &&
2078                 !(board_info.board_id == BOARD_PM375))
2079                 tegra_add_all_vmin_trips(ardbeg_nct72_pdata.sensors[EXT].trips,
2080                         &ardbeg_nct72_pdata.sensors[EXT].num_trips);
2081
2082         ardbeg_i2c_nct72_board_info[0].irq = gpio_to_irq(nct72_port);
2083
2084         ret = gpio_request(nct72_port, "temp_alert");
2085         if (ret < 0)
2086                 return ret;
2087
2088         ret = gpio_direction_input(nct72_port);
2089         if (ret < 0) {
2090                 pr_info("%s: calling gpio_free(nct72_port)", __func__);
2091                 gpio_free(nct72_port);
2092         }
2093
2094         /* norrin has thermal sensor on GEN1-I2C i.e. instance 0 */
2095         if (board_info.board_id == BOARD_PM374)
2096                 i2c_register_board_info(0, ardbeg_i2c_nct72_board_info,
2097                                         1); /* only register device[0] */
2098         /* ardbeg has thermal sensor on GEN2-I2C i.e. instance 1 */
2099         else if (board_info.board_id == BOARD_PM358 ||
2100                         board_info.board_id == BOARD_PM359 ||
2101                         board_info.board_id == BOARD_PM370 ||
2102                         board_info.board_id == BOARD_PM363)
2103                 i2c_register_board_info(1, ardbeg_i2c_nct72_board_info,
2104                 ARRAY_SIZE(ardbeg_i2c_nct72_board_info));
2105         else if (board_info.board_id == BOARD_PM375 ||
2106                         board_info.board_id == BOARD_PM377) {
2107                 ardbeg_nct72_pdata.sensors[EXT].shutdown_limit = 105;
2108                 ardbeg_nct72_pdata.sensors[LOC].shutdown_limit = 100;
2109                 i2c_register_board_info(0, ardbeg_i2c_nct72_board_info,
2110                                         1); /* only register device[0] */
2111         }
2112         else
2113                 i2c_register_board_info(1, ardbeg_i2c_nct72_board_info,
2114                         ARRAY_SIZE(ardbeg_i2c_nct72_board_info));
2115
2116         return ret;
2117 }
2118
2119 struct ntc_thermistor_adc_table {
2120         int temp; /* degree C */
2121         int adc;
2122 };
2123
2124 static struct ntc_thermistor_adc_table tn8_thermistor_table[] = {
2125         { -40, 2578 }, { -39, 2577 }, { -38, 2576 }, { -37, 2575 },
2126         { -36, 2574 }, { -35, 2573 }, { -34, 2572 }, { -33, 2571 },
2127         { -32, 2569 }, { -31, 2568 }, { -30, 2567 }, { -29, 2565 },
2128         { -28, 2563 }, { -27, 2561 }, { -26, 2559 }, { -25, 2557 },
2129         { -24, 2555 }, { -23, 2553 }, { -22, 2550 }, { -21, 2548 },
2130         { -20, 2545 }, { -19, 2542 }, { -18, 2539 }, { -17, 2536 },
2131         { -16, 2532 }, { -15, 2529 }, { -14, 2525 }, { -13, 2521 },
2132         { -12, 2517 }, { -11, 2512 }, { -10, 2507 }, {  -9, 2502 },
2133         {  -8, 2497 }, {  -7, 2492 }, {  -6, 2486 }, {  -5, 2480 },
2134         {  -4, 2473 }, {  -3, 2467 }, {  -2, 2460 }, {  -1, 2452 },
2135         {   0, 2445 }, {   1, 2437 }, {   2, 2428 }, {   3, 2419 },
2136         {   4, 2410 }, {   5, 2401 }, {   6, 2391 }, {   7, 2380 },
2137         {   8, 2369 }, {   9, 2358 }, {  10, 2346 }, {  11, 2334 },
2138         {  12, 2322 }, {  13, 2308 }, {  14, 2295 }, {  15, 2281 },
2139         {  16, 2266 }, {  17, 2251 }, {  18, 2236 }, {  19, 2219 },
2140         {  20, 2203 }, {  21, 2186 }, {  22, 2168 }, {  23, 2150 },
2141         {  24, 2131 }, {  25, 2112 }, {  26, 2092 }, {  27, 2072 },
2142         {  28, 2052 }, {  29, 2030 }, {  30, 2009 }, {  31, 1987 },
2143         {  32, 1964 }, {  33, 1941 }, {  34, 1918 }, {  35, 1894 },
2144         {  36, 1870 }, {  37, 1845 }, {  38, 1820 }, {  39, 1795 },
2145         {  40, 1769 }, {  41, 1743 }, {  42, 1717 }, {  43, 1691 },
2146         {  44, 1664 }, {  45, 1637 }, {  46, 1610 }, {  47, 1583 },
2147         {  48, 1555 }, {  49, 1528 }, {  50, 1500 }, {  51, 1472 },
2148         {  52, 1445 }, {  53, 1417 }, {  54, 1390 }, {  55, 1362 },
2149         {  56, 1334 }, {  57, 1307 }, {  58, 1280 }, {  59, 1253 },
2150         {  60, 1226 }, {  61, 1199 }, {  62, 1172 }, {  63, 1146 },
2151         {  64, 1120 }, {  65, 1094 }, {  66, 1069 }, {  67, 1044 },
2152         {  68, 1019 }, {  69,  994 }, {  70,  970 }, {  71,  946 },
2153         {  72,  922 }, {  73,  899 }, {  74,  877 }, {  75,  854 },
2154         {  76,  832 }, {  77,  811 }, {  78,  789 }, {  79,  769 },
2155         {  80,  748 }, {  81,  729 }, {  82,  709 }, {  83,  690 },
2156         {  84,  671 }, {  85,  653 }, {  86,  635 }, {  87,  618 },
2157         {  88,  601 }, {  89,  584 }, {  90,  568 }, {  91,  552 },
2158         {  92,  537 }, {  93,  522 }, {  94,  507 }, {  95,  493 },
2159         {  96,  479 }, {  97,  465 }, {  98,  452 }, {  99,  439 },
2160         { 100,  427 }, { 101,  415 }, { 102,  403 }, { 103,  391 },
2161         { 104,  380 }, { 105,  369 }, { 106,  359 }, { 107,  349 },
2162         { 108,  339 }, { 109,  329 }, { 110,  320 }, { 111,  310 },
2163         { 112,  302 }, { 113,  293 }, { 114,  285 }, { 115,  277 },
2164         { 116,  269 }, { 117,  261 }, { 118,  254 }, { 119,  247 },
2165         { 120,  240 }, { 121,  233 }, { 122,  226 }, { 123,  220 },
2166         { 124,  214 }, { 125,  208 },
2167 };
2168
2169 static struct ntc_thermistor_adc_table *thermistor_table;
2170 static int thermistor_table_size;
2171
2172 static int gadc_thermal_thermistor_adc_to_temp(
2173                 struct gadc_thermal_platform_data *pdata, int val, int val2)
2174 {
2175         int temp = 0, adc_hi, adc_lo;
2176         int i;
2177
2178         for (i = 0; i < thermistor_table_size; i++)
2179                 if (val >= thermistor_table[i].adc)
2180                         break;
2181
2182         if (i == 0) {
2183                 temp = thermistor_table[i].temp * 1000;
2184         } else if (i >= (thermistor_table_size - 1)) {
2185                 temp = thermistor_table[thermistor_table_size - 1].temp * 1000;
2186         } else {
2187                 adc_hi = thermistor_table[i - 1].adc;
2188                 adc_lo = thermistor_table[i].adc;
2189                 temp = thermistor_table[i].temp * 1000;
2190                 temp -= ((val - adc_lo) * 1000 / (adc_hi - adc_lo));
2191         }
2192
2193         return temp;
2194 };
2195
2196 #define TDIODE_PRECISION_MULTIPLIER     1000000000LL
2197 #define TDIODE_MIN_TEMP                 -25000LL
2198 #define TDIODE_MAX_TEMP                 125000LL
2199
2200 static int gadc_thermal_tdiode_adc_to_temp(
2201                 struct gadc_thermal_platform_data *pdata, int val, int val2)
2202 {
2203         /*
2204          * Series resistance cancellation using multi-current ADC measurement.
2205          * diode temp = ((adc2 - k * adc1) - (b2 - k * b1)) / (m2 - k * m1)
2206          * - adc1 : ADC raw with current source 400uA
2207          * - m1, b1 : calculated with current source 400uA
2208          * - adc2 : ADC raw with current source 800uA
2209          * - m2, b2 : calculated with current source 800uA
2210          * - k : 2 (= 800uA / 400uA)
2211          */
2212         const s64 m1 = -0.00571005 * TDIODE_PRECISION_MULTIPLIER;
2213         const s64 b1 = 2524.29891 * TDIODE_PRECISION_MULTIPLIER;
2214         const s64 m2 = -0.005519811 * TDIODE_PRECISION_MULTIPLIER;
2215         const s64 b2 = 2579.354349 * TDIODE_PRECISION_MULTIPLIER;
2216         s64 temp = TDIODE_PRECISION_MULTIPLIER;
2217
2218         temp *= (s64)((val2) - 2 * (val));
2219         temp -= (b2 - 2 * b1);
2220         temp = div64_s64(temp, (m2 - 2 * m1));
2221         temp = min_t(s64, max_t(s64, temp, TDIODE_MIN_TEMP), TDIODE_MAX_TEMP);
2222         return temp;
2223 };
2224
2225 static struct gadc_thermal_platform_data gadc_thermal_thermistor_pdata = {
2226         .iio_channel_name = "thermistor",
2227         .tz_name = "Tboard",
2228         .temp_offset = 0,
2229         .adc_to_temp = gadc_thermal_thermistor_adc_to_temp,
2230
2231         .polling_delay = 15000,
2232         .num_trips = 1,
2233         .trips = {
2234                 {
2235                         .cdev_type = "therm_est_activ",
2236                         .trip_temp = 40000,
2237                         .trip_type = THERMAL_TRIP_ACTIVE,
2238                         .hysteresis = 1000,
2239                         .upper = THERMAL_NO_LIMIT,
2240                         .lower = THERMAL_NO_LIMIT,
2241                         .mask = 1,
2242                 },
2243         },
2244         .tzp = &board_tzp,
2245 };
2246
2247 static struct gadc_thermal_platform_data gadc_thermal_tdiode_pdata = {
2248         .iio_channel_name = "tdiode",
2249         .tz_name = "Tdiode",
2250         .temp_offset = 0,
2251         .dual_mode = true,
2252         .adc_to_temp = gadc_thermal_tdiode_adc_to_temp,
2253 };
2254
2255 static struct platform_device gadc_thermal_thermistor = {
2256         .name   = "generic-adc-thermal",
2257         .id     = 1,
2258         .dev    = {
2259                 .platform_data = &gadc_thermal_thermistor_pdata,
2260         },
2261 };
2262
2263 static struct platform_device gadc_thermal_tdiode = {
2264         .name   = "generic-adc-thermal",
2265         .id     = 2,
2266         .dev    = {
2267                 .platform_data = &gadc_thermal_tdiode_pdata,
2268         },
2269 };
2270
2271 static struct platform_device *gadc_thermal_devices[] = {
2272         &gadc_thermal_thermistor,
2273         &gadc_thermal_tdiode,
2274 };
2275
2276 int __init ardbeg_sensors_init(void)
2277 {
2278         struct board_info board_info;
2279         tegra_get_board_info(&board_info);
2280         /* PM363 and PM359 don't have mpu 9250 mounted */
2281         /* TN8 sensors use Device Tree */
2282         if (board_info.board_id != BOARD_PM363 &&
2283                 board_info.board_id != BOARD_PM359 &&
2284                 !of_machine_is_compatible("nvidia,tn8") &&
2285                 !of_machine_is_compatible("nvidia,bowmore") &&
2286                 board_info.board_id != BOARD_PM375 &&
2287                 board_info.board_id != BOARD_PM377)
2288                 mpuirq_init();
2289         ardbeg_camera_init();
2290
2291         if (board_info.board_id == BOARD_P1761 ||
2292                 board_info.board_id == BOARD_E1784 ||
2293                 board_info.board_id == BOARD_E1971 ||
2294                 board_info.board_id == BOARD_E1991 ||
2295                 board_info.board_id == BOARD_E1922) {
2296                 platform_add_devices(gadc_thermal_devices,
2297                                 ARRAY_SIZE(gadc_thermal_devices));
2298                 thermistor_table = &tn8_thermistor_table[0];
2299                 thermistor_table_size = ARRAY_SIZE(tn8_thermistor_table);
2300         } else
2301                 ardbeg_nct72_init();
2302
2303 #if defined(ARCH_TEGRA_12x_SOC)
2304         /* TN8 and PM359 don't have ALS CM32181 */
2305         if (!of_machine_is_compatible("nvidia,tn8") &&
2306             board_info.board_id != BOARD_PM359 &&
2307             board_info.board_id != BOARD_PM375 &&
2308             board_info.board_id != BOARD_PM377)
2309                 i2c_register_board_info(0, ardbeg_i2c_board_info_cm32181,
2310                         ARRAY_SIZE(ardbeg_i2c_board_info_cm32181));
2311 #endif
2312         return 0;
2313 }