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