arm: tegra: cardhu: add support for PM315
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
index e85e4ca..d90802d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * arch/arm/mach-tegra/board-cardhu-sensors.c
  *
- * Copyright (c) 2010-2011, NVIDIA CORPORATION, All rights reserved.
+ * Copyright (c) 2010-2012, NVIDIA CORPORATION, All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions are
 #include <linux/i2c/pca954x.h>
 #include <linux/i2c/pca953x.h>
 #include <linux/nct1008.h>
+#include <linux/gpio.h>
+
+#include <mach/gpio-tegra.h>
 #include <mach/fb.h>
-#include <mach/gpio.h>
 #include <media/ov5650.h>
+#include <media/ov5640.h>
 #include <media/ov14810.h>
 #include <media/ov2710.h>
 #include <media/tps61050.h>
 #include <generated/mach-types.h>
-#include "gpio-names.h"
 #include "board.h"
 #include <linux/mpu.h>
 #include <media/sh532u.h>
+#include <media/ad5816.h>
 #include <linux/bq27x00.h>
-#include <mach/gpio.h>
 #include <mach/edp.h>
-#include <mach/thermal.h>
+#include <linux/therm_est.h>
 
 #include "gpio-names.h"
 #include "board-cardhu.h"
 #include "cpu-tegra.h"
+#include "devices.h"
 
 static struct regulator *cardhu_1v8_cam1 = NULL;
 static struct regulator *cardhu_1v8_cam2 = NULL;
@@ -85,25 +88,22 @@ static int cardhu_camera_init(void)
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
-               tegra_gpio_enable(CAM1_POWER_DWN_GPIO);
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
                ret = gpio_request(CAM1_POWER_DWN_GPIO, "camera_power_en");
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
                                __func__, "CAM1_POWER_DWN_GPIO");
-                               tegra_gpio_enable(CAM3_POWER_DWN_GPIO);
                ret = gpio_request(CAM3_POWER_DWN_GPIO, "cam3_power_en");
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
                                __func__, "CAM3_POWER_DWN_GPIO");
 
-               tegra_gpio_enable(CAM2_POWER_DWN_GPIO);
                ret = gpio_request(CAM2_POWER_DWN_GPIO, "camera2_power_en");
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
                                __func__, "CAM2_POWER_DWN_GPIO");
 
-               tegra_gpio_enable(OV5650_RESETN_GPIO);
                ret = gpio_request(OV5650_RESETN_GPIO, "camera_reset");
                if (ret < 0)
                        pr_err("%s: gpio_request failed for gpio %s\n",
@@ -123,7 +123,6 @@ static int cardhu_camera_init(void)
        }
 
        /* To select the CSIB MUX either for cam2 or cam3 */
-       tegra_gpio_enable(CAMERA_CSI_MUX_SEL_GPIO);
        ret = gpio_request(CAMERA_CSI_MUX_SEL_GPIO, "camera_csi_sel");
        if (ret < 0)
                pr_err("%s: gpio_request failed for gpio %s\n",
@@ -134,15 +133,17 @@ static int cardhu_camera_init(void)
        return 0;
 }
 
-static int cardhu_left_ov5650_power_on(void)
+static int cardhu_left_ov5650_power_on(struct device *dev)
 {
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
 
                if (cardhu_vdd_2v8_cam1 == NULL) {
-                       cardhu_vdd_2v8_cam1 = regulator_get(NULL, "vdd_2v8_cam1");
+                       cardhu_vdd_2v8_cam1 =
+                               regulator_get(dev, "vdd_2v8_cam1");
                        if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam1))) {
                                pr_err("%s: couldn't get regulator vdd_2v8_cam1: %ld\n",
                                        __func__, PTR_ERR(cardhu_vdd_2v8_cam1));
@@ -155,7 +156,7 @@ static int cardhu_left_ov5650_power_on(void)
 
        /* Enable VDD_1V8_Cam1 */
        if (cardhu_1v8_cam1 == NULL) {
-               cardhu_1v8_cam1 = regulator_get(NULL, "vdd_1v8_cam1");
+               cardhu_1v8_cam1 = regulator_get(dev, "vdd_1v8_cam1");
                if (WARN_ON(IS_ERR(cardhu_1v8_cam1))) {
                        pr_err("%s: couldn't get regulator vdd_1v8_cam1: %ld\n",
                                __func__, PTR_ERR(cardhu_1v8_cam1));
@@ -166,7 +167,8 @@ static int cardhu_left_ov5650_power_on(void)
 
        mdelay(5);
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                mdelay(20);
                gpio_direction_output(OV5650_RESETN_GPIO, 0);
@@ -196,12 +198,13 @@ reg_alloc_fail:
 
 }
 
-static int cardhu_left_ov5650_power_off(void)
+static int cardhu_left_ov5650_power_off(struct device *dev)
 {
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
@@ -275,7 +278,7 @@ static struct i2c_board_info cardhu_i2c_board_info_e1214[] = {
 };
 #endif
 
-static int cardhu_right_ov5650_power_on(void)
+static int cardhu_right_ov5650_power_on(struct device *dev)
 {
        /* CSI-B and front sensor are muxed on cardhu */
        gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
@@ -283,14 +286,16 @@ static int cardhu_right_ov5650_power_on(void)
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
 
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
                mdelay(10);
 
                if (cardhu_vdd_2v8_cam2 == NULL) {
-                       cardhu_vdd_2v8_cam2 = regulator_get(NULL, "vdd_2v8_cam2");
+                       cardhu_vdd_2v8_cam2 =
+                               regulator_get(dev, "vdd_2v8_cam2");
                        if (WARN_ON(IS_ERR(cardhu_vdd_2v8_cam2))) {
                                pr_err("%s: couldn't get regulator vdd_2v8_cam2: %ld\n",
                                        __func__, PTR_ERR(cardhu_vdd_2v8_cam2));
@@ -303,7 +308,7 @@ static int cardhu_right_ov5650_power_on(void)
 
        /* Enable VDD_1V8_Cam2 */
        if (cardhu_1v8_cam2 == NULL) {
-               cardhu_1v8_cam2 = regulator_get(NULL, "vdd_1v8_cam2");
+               cardhu_1v8_cam2 = regulator_get(dev, "vdd_1v8_cam2");
                if (WARN_ON(IS_ERR(cardhu_1v8_cam2))) {
                        pr_err("%s: couldn't get regulator vdd_1v8_cam2: %ld\n",
                                __func__, PTR_ERR(cardhu_1v8_cam2));
@@ -336,15 +341,16 @@ reg_alloc_fail:
 
 }
 
-static int cardhu_right_ov5650_power_off(void)
+static int cardhu_right_ov5650_power_off(struct device *dev)
 {
        /* CSI-B and front sensor are muxed on cardhu */
        gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 0);
 
        /* Boards E1198 and E1291 are of Cardhu personality
-        * and donot have TCA6416 exp for camera */
+        * and do not have TCA6416 for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
@@ -365,8 +371,8 @@ static void cardhu_ov5650_synchronize_sensors(void)
                mdelay(50);
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                mdelay(50);
-       }
-       else if (board_info.board_id == BOARD_E1291) {
+       } else if ((board_info.board_id == BOARD_E1291) ||
+                       (board_info.board_id == BOARD_PM315)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
                mdelay(50);
@@ -384,7 +390,92 @@ struct ov5650_platform_data cardhu_right_ov5650_data = {
        .synchronize_sensors = cardhu_ov5650_synchronize_sensors,
 };
 
-static int cardhu_ov2710_power_on(void)
+static int cardhu_ov2710_power_on(struct device *dev)
+{
+       /* CSI-B and front sensor are muxed on cardhu */
+       gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
+
+       /* Enable VDD_1V8_Cam3 */
+       if (cardhu_1v8_cam3 == NULL) {
+               cardhu_1v8_cam3 = regulator_get(dev, "vdd_1v8_cam3");
+               if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
+                       pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
+                               __func__, PTR_ERR(cardhu_1v8_cam3));
+                       goto reg_alloc_fail;
+               }
+       }
+       regulator_enable(cardhu_1v8_cam3);
+
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and do not have TCA6416 for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
+               if (cardhu_vdd_cam3 == NULL) {
+                       cardhu_vdd_cam3 = regulator_get(dev, "vdd_cam3");
+                       if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
+                               pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
+                                       __func__, PTR_ERR(cardhu_vdd_cam3));
+                               goto reg_alloc_fail;
+                       }
+               }
+               regulator_enable(cardhu_vdd_cam3);
+
+               mdelay(5);
+
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
+               gpio_direction_output(CAM3_POWER_DWN_GPIO, 0);
+               mdelay(10);
+
+       }
+
+       mdelay(20);
+
+       return 0;
+
+reg_alloc_fail:
+       if (cardhu_1v8_cam3) {
+               regulator_put(cardhu_1v8_cam3);
+               cardhu_1v8_cam3 = NULL;
+       }
+       if (cardhu_vdd_cam3) {
+               regulator_put(cardhu_vdd_cam3);
+               cardhu_vdd_cam3 = NULL;
+       }
+
+       return -ENODEV;
+}
+
+static int cardhu_ov2710_power_off(struct device *dev)
+{
+       /* CSI-B and front sensor are muxed on cardhu */
+       gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
+
+       /* Boards E1198 and E1291 are of Cardhu personality
+        * and donot have TCA6416 exp for camera */
+       if ((board_info.board_id == BOARD_E1198) ||
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
+               gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
+               gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
+               if (cardhu_vdd_cam3)
+                       regulator_disable(cardhu_vdd_cam3);
+       }
+
+       if (cardhu_1v8_cam3)
+               regulator_disable(cardhu_1v8_cam3);
+
+       return 0;
+}
+
+struct ov2710_platform_data cardhu_ov2710_data = {
+       .power_on = cardhu_ov2710_power_on,
+       .power_off = cardhu_ov2710_power_off,
+};
+
+static int cardhu_ov5640_power_on(struct device *dev)
 {
        /* CSI-B and front sensor are muxed on cardhu */
        gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
@@ -392,7 +483,8 @@ static int cardhu_ov2710_power_on(void)
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
 
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
@@ -400,7 +492,7 @@ static int cardhu_ov2710_power_on(void)
                mdelay(10);
 
                if (cardhu_vdd_cam3 == NULL) {
-                       cardhu_vdd_cam3 = regulator_get(NULL, "vdd_cam3");
+                       cardhu_vdd_cam3 = regulator_get(dev, "vdd_cam3");
                        if (WARN_ON(IS_ERR(cardhu_vdd_cam3))) {
                                pr_err("%s: couldn't get regulator vdd_cam3: %ld\n",
                                        __func__, PTR_ERR(cardhu_vdd_cam3));
@@ -412,7 +504,7 @@ static int cardhu_ov2710_power_on(void)
 
        /* Enable VDD_1V8_Cam3 */
        if (cardhu_1v8_cam3 == NULL) {
-               cardhu_1v8_cam3 = regulator_get(NULL, "vdd_1v8_cam3");
+               cardhu_1v8_cam3 = regulator_get(dev, "vdd_1v8_cam3");
                if (WARN_ON(IS_ERR(cardhu_1v8_cam3))) {
                        pr_err("%s: couldn't get regulator vdd_1v8_cam3: %ld\n",
                                __func__, PTR_ERR(cardhu_1v8_cam3));
@@ -437,7 +529,7 @@ reg_alloc_fail:
        return -ENODEV;
 }
 
-static int cardhu_ov2710_power_off(void)
+static int cardhu_ov5640_power_off(struct device *dev)
 {
        /* CSI-B and front sensor are muxed on cardhu */
        gpio_direction_output(CAMERA_CSI_MUX_SEL_GPIO, 1);
@@ -445,7 +537,8 @@ static int cardhu_ov2710_power_off(void)
        /* Boards E1198 and E1291 are of Cardhu personality
         * and donot have TCA6416 exp for camera */
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291)) {
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315)) {
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 1);
                gpio_direction_output(CAM3_POWER_DWN_GPIO, 1);
@@ -459,9 +552,9 @@ static int cardhu_ov2710_power_off(void)
        return 0;
 }
 
-struct ov2710_platform_data cardhu_ov2710_data = {
-       .power_on = cardhu_ov2710_power_on,
-       .power_off = cardhu_ov2710_power_off,
+struct ov5640_platform_data cardhu_ov5640_data = {
+       .power_on = cardhu_ov5640_power_on,
+       .power_off = cardhu_ov5640_power_off,
 };
 
 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
@@ -471,34 +564,104 @@ static const struct i2c_board_info cardhu_i2c3_board_info[] = {
        },
 };
 
+
+static struct nvc_gpio_pdata sh532u_gpio_pdata[] = {
+       { SH532U_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
+};
+
 static struct sh532u_platform_data sh532u_left_pdata = {
+       .cfg            = NVC_CFG_NODEV,
        .num            = 1,
        .sync           = 2,
        .dev_name       = "focuser",
-       .gpio_reset     = TEGRA_GPIO_PBB0,
+       .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
+       .gpio           = sh532u_gpio_pdata,
 };
 
 static struct sh532u_platform_data sh532u_right_pdata = {
+       .cfg            = NVC_CFG_NODEV,
        .num            = 2,
        .sync           = 1,
        .dev_name       = "focuser",
-       .gpio_reset     = TEGRA_GPIO_PBB0,
+       .gpio_count     = ARRAY_SIZE(sh532u_gpio_pdata),
+       .gpio           = sh532u_gpio_pdata,
+};
+
+static struct nvc_gpio_pdata pm269_sh532u_left_gpio_pdata[] = {
+       { SH532U_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
 };
 
 static struct sh532u_platform_data pm269_sh532u_left_pdata = {
+       .cfg            = 0,
        .num            = 1,
        .sync           = 2,
        .dev_name       = "focuser",
-       .gpio_reset     = CAM1_RST_L_GPIO,
+       .gpio_count     = ARRAY_SIZE(pm269_sh532u_left_gpio_pdata),
+       .gpio           = pm269_sh532u_left_gpio_pdata,
+};
+
+static struct nvc_gpio_pdata pm269_sh532u_right_gpio_pdata[] = {
+       { SH532U_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
 };
 
 static struct sh532u_platform_data pm269_sh532u_right_pdata = {
+       .cfg            = 0,
+       .num            = 2,
+       .sync           = 1,
+       .dev_name       = "focuser",
+       .gpio_count     = ARRAY_SIZE(pm269_sh532u_right_gpio_pdata),
+       .gpio           = pm269_sh532u_right_gpio_pdata,
+};
+
+static struct nvc_gpio_pdata ad5816_gpio_pdata[] = {
+       { AD5816_GPIO_RESET, TEGRA_GPIO_PBB0, false, 0, },
+};
+
+static struct ad5816_platform_data ad5816_left_pdata = {
+       .cfg            = 0,
+       .num            = 1,
+       .sync           = 2,
+       .dev_name       = "focuser",
+       .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
+       .gpio           = ad5816_gpio_pdata,
+};
+
+static struct ad5816_platform_data ad5816_right_pdata = {
+       .cfg            = 0,
        .num            = 2,
        .sync           = 1,
        .dev_name       = "focuser",
-       .gpio_reset     = CAM2_RST_L_GPIO,
+       .gpio_count     = ARRAY_SIZE(ad5816_gpio_pdata),
+       .gpio           = ad5816_gpio_pdata,
 };
 
+static struct nvc_gpio_pdata pm269_ad5816_left_gpio_pdata[] = {
+       { AD5816_GPIO_RESET, CAM1_RST_L_GPIO, false, 0, },
+};
+
+static struct ad5816_platform_data pm269_ad5816_left_pdata = {
+       .cfg            = NVC_CFG_NODEV,
+       .num            = 1,
+       .sync           = 2,
+       .dev_name       = "focuser",
+       .gpio_count     = ARRAY_SIZE(pm269_ad5816_left_gpio_pdata),
+       .gpio           = pm269_ad5816_left_gpio_pdata,
+};
+
+static struct nvc_gpio_pdata pm269_ad5816_right_gpio_pdata[] = {
+       { AD5816_GPIO_RESET, CAM2_RST_L_GPIO, false, 0, },
+};
+
+static struct ad5816_platform_data pm269_ad5816_right_pdata = {
+       .cfg            = NVC_CFG_NODEV,
+       .num            = 2,
+       .sync           = 1,
+       .dev_name       = "focuser",
+       .gpio_count     = ARRAY_SIZE(pm269_ad5816_right_gpio_pdata),
+       .gpio           = pm269_ad5816_right_gpio_pdata,
+};
+
+
 static struct nvc_torch_pin_state cardhu_tps61050_pinstate = {
        .mask           = 0x0008, /*VGP3*/
        .values         = 0x0008,
@@ -525,6 +688,10 @@ static struct i2c_board_info cardhu_i2c6_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &sh532u_left_pdata,
        },
+       {
+               I2C_BOARD_INFO("ad5816", 0x0E),
+               .platform_data = &ad5816_left_pdata,
+       },
 };
 
 static struct i2c_board_info cardhu_i2c7_board_info[] = {
@@ -536,6 +703,10 @@ static struct i2c_board_info cardhu_i2c7_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &sh532u_right_pdata,
        },
+       {
+               I2C_BOARD_INFO("ad5816", 0x0E),
+               .platform_data = &ad5816_right_pdata,
+       },
 };
 
 static struct i2c_board_info pm269_i2c6_board_info[] = {
@@ -547,6 +718,10 @@ static struct i2c_board_info pm269_i2c6_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &pm269_sh532u_left_pdata,
        },
+       {
+               I2C_BOARD_INFO("ad5816", 0x0E),
+               .platform_data = &pm269_ad5816_left_pdata,
+       },
 };
 
 static struct i2c_board_info pm269_i2c7_board_info[] = {
@@ -558,6 +733,10 @@ static struct i2c_board_info pm269_i2c7_board_info[] = {
                I2C_BOARD_INFO("sh532u", 0x72),
                .platform_data = &pm269_sh532u_right_pdata,
        },
+       {
+               I2C_BOARD_INFO("ad5816", 0x0E),
+               .platform_data = &pm269_ad5816_right_pdata,
+       },
 };
 
 static struct i2c_board_info cardhu_i2c8_board_info[] = {
@@ -565,73 +744,46 @@ static struct i2c_board_info cardhu_i2c8_board_info[] = {
                I2C_BOARD_INFO("ov2710", 0x36),
                .platform_data = &cardhu_ov2710_data,
        },
+       {
+               I2C_BOARD_INFO("ov5640", 0x3C),
+               .platform_data = &cardhu_ov5640_data,
+       },
 };
 
-static int nct_get_temp(void *_data, long *temp)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_get_temp(data, temp);
-}
-
-static int nct_get_temp_low(void *_data, long *temp)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_get_temp_low(data, temp);
-}
-
-static int nct_set_limits(void *_data,
-                       long lo_limit_milli,
-                       long hi_limit_milli)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_set_limits(data,
-                                       lo_limit_milli,
-                                       hi_limit_milli);
-}
-
-static int nct_set_alert(void *_data,
-                               void (*alert_func)(void *),
-                               void *alert_data)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_set_alert(data, alert_func, alert_data);
-}
-
-static int nct_set_shutdown_temp(void *_data, long shutdown_temp)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_set_shutdown_temp(data, shutdown_temp);
-}
-
-static void nct1008_probe_callback(struct nct1008_data *data)
-{
-       struct tegra_thermal_device *thermal_device;
-
-       thermal_device = kzalloc(sizeof(struct tegra_thermal_device),
-                                       GFP_KERNEL);
-       if (!thermal_device) {
-               pr_err("unable to allocate thermal device\n");
-               return;
-       }
-
-       thermal_device->name = "nct1008";
-       thermal_device->data = data;
-       thermal_device->offset = TDIODE_OFFSET;
-       thermal_device->get_temp = nct_get_temp;
-       thermal_device->get_temp_low = nct_get_temp_low;
-       thermal_device->set_limits = nct_set_limits;
-       thermal_device->set_alert = nct_set_alert;
-       thermal_device->set_shutdown_temp = nct_set_shutdown_temp;
-
-       tegra_thermal_set_device(thermal_device);
-}
+static struct balanced_throttle tj_throttle = {
+       .throt_tab_size = 10,
+       .throt_tab = {
+               {      0, 1000 },
+               { 640000, 1000 },
+               { 640000, 1000 },
+               { 640000, 1000 },
+               { 640000, 1000 },
+               { 640000, 1000 },
+               { 760000, 1000 },
+               { 760000, 1050 },
+               {1000000, 1050 },
+               {1000000, 1100 },
+       },
+};
 
 static struct nct1008_platform_data cardhu_nct1008_pdata = {
        .supported_hwrev = true,
        .ext_range = true,
        .conv_rate = 0x08,
        .offset = 8, /* 4 * 2C. Bug 844025 - 1C for device accuracies */
-       .probe_callback = nct1008_probe_callback,
+       .shutdown_ext_limit = 90, /* C */
+       .shutdown_local_limit = 100, /* C */
+
+       /* Thermal Throttling */
+       .passive = {
+               .create_cdev = (struct thermal_cooling_device *(*)(void *))
+                               balanced_throttle_register,
+               .cdev_data = &tj_throttle,
+               .trip_temp = 85000,
+               .tc1 = 0,
+               .tc2 = 1,
+               .passive_delay = 2000,
+       }
 };
 
 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
@@ -658,7 +810,8 @@ static int cardhu_nct1008_init(void)
                (board_info.board_id == BOARD_E1257) ||
                (board_info.board_id == BOARD_PM269) ||
                (board_info.board_id == BOARD_PM305) ||
-               (board_info.board_id == BOARD_PM311)) {
+               (board_info.board_id == BOARD_PM311) ||
+               (board_info.board_id == BOARD_PM315)) {
                nct1008_port = TEGRA_GPIO_PCC2;
        } else if ((board_info.board_id == BOARD_E1186) ||
                (board_info.board_id == BOARD_E1187) ||
@@ -668,8 +821,31 @@ static int cardhu_nct1008_init(void)
        }
 
        if (nct1008_port >= 0) {
+#ifdef CONFIG_TEGRA_EDP_LIMITS
+               const struct tegra_edp_limits *cpu_edp_limits;
+               int cpu_edp_limits_size;
+               int i;
+
+               /* edp capping */
+               tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
+
+               if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
+                       BUG();
+
+               for (i = 0; i < cpu_edp_limits_size-1; i++) {
+                       cardhu_nct1008_pdata.active[i].create_cdev =
+                               (struct thermal_cooling_device *(*)(void *))
+                                       edp_cooling_device_create;
+                       cardhu_nct1008_pdata.active[i].cdev_data = (void *)i;
+                       cardhu_nct1008_pdata.active[i].trip_temp =
+                               cpu_edp_limits[i].temperature * 1000;
+                       cardhu_nct1008_pdata.active[i].hysteresis = 1000;
+               }
+               cardhu_nct1008_pdata.active[i].create_cdev = NULL;
+#endif
+
                /* FIXME: enable irq when throttling is supported */
-               cardhu_i2c4_nct1008_board_info[0].irq = TEGRA_GPIO_TO_IRQ(nct1008_port);
+               cardhu_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
 
                ret = gpio_request(nct1008_port, "temp_alert");
                if (ret < 0)
@@ -678,13 +854,93 @@ static int cardhu_nct1008_init(void)
                ret = gpio_direction_input(nct1008_port);
                if (ret < 0)
                        gpio_free(nct1008_port);
-               else
-                       tegra_gpio_enable(nct1008_port);
        }
 
+       i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
+               ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
+
        return ret;
 }
 
+#ifdef CONFIG_TEGRA_SKIN_THROTTLE
+static int tegra_skin_match(struct thermal_zone_device *thz, void *data)
+{
+       return strcmp((char *)data, thz->type) == 0;
+}
+
+static int tegra_skin_get_temp(void *data, long *temp)
+{
+       struct thermal_zone_device *thz;
+
+       thz = thermal_zone_device_find(data, tegra_skin_match);
+
+       if (!thz || thz->ops->get_temp(thz, temp))
+               *temp = 25000;
+
+       return 0;
+}
+
+static struct therm_est_data skin_data = {
+       .toffset = 9793,
+       .polling_period = 1100,
+       .ndevs = 2,
+       .devs = {
+                       {
+                               .dev_data = "nct_ext",
+                               .get_temp = tegra_skin_get_temp,
+                               .coeffs = {
+                                       2, 1, 1, 1,
+                                       1, 1, 1, 1,
+                                       1, 1, 1, 0,
+                                       1, 1, 0, 0,
+                                       0, 0, -1, -7
+                               },
+                       },
+                       {
+                               .dev_data = "nct_int",
+                               .get_temp = tegra_skin_get_temp,
+                               .coeffs = {
+                                       -11, -7, -5, -3,
+                                       -3, -2, -1, 0,
+                                       0, 0, 1, 1,
+                                       1, 2, 2, 3,
+                                       4, 6, 11, 18
+                               },
+                       },
+       },
+       .trip_temp = 43000,
+       .tc1 = 1,
+       .tc2 = 15,
+       .passive_delay = 15000,
+};
+
+static struct balanced_throttle skin_throttle = {
+       .throt_tab_size = 6,
+       .throt_tab = {
+               { 640000, 1200 },
+               { 640000, 1200 },
+               { 760000, 1200 },
+               { 760000, 1200 },
+               {1000000, 1200 },
+               {1000000, 1200 },
+       },
+};
+
+static int __init cardhu_skin_init(void)
+{
+       struct thermal_cooling_device *skin_cdev;
+
+       skin_cdev = balanced_throttle_register(&skin_throttle);
+
+       skin_data.cdev = skin_cdev;
+       tegra_skin_therm_est_device.dev.platform_data = &skin_data;
+       platform_device_register(&tegra_skin_therm_est_device);
+
+       return 0;
+}
+late_initcall(cardhu_skin_init);
+#endif
+
 #if defined(CONFIG_GPIO_PCA953X)
 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
        .gpio_base      = PMU_TCA6416_GPIO_BASE,
@@ -745,55 +1001,88 @@ static int __init cam_tca6416_init(void)
 }
 #endif
 
-#ifdef CONFIG_MPU_SENSORS_MPU3050
-#define SENSOR_MPU_NAME "mpu3050"
-static struct mpu3050_platform_data mpu3050_data = {
-       .int_config  = 0x10,
-       .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for MPU on cardhu */
-       .level_shifter = 0,
-
-       .accel = {
-       .get_slave_descr = get_accel_slave_descr,
-       .adapt_num   = 2,
-       .bus         = EXT_SLAVE_BUS_SECONDARY,
-       .address     = 0x0F,
-       .orientation = { 0, -1, 0, -1, 0, 0, 0, 0, -1 },  /* Orientation matrix for Kionix on cardhu */
-       },
+/* MPU board file definition   */
+static struct mpu_platform_data mpu_gyro_data = {
+       .int_config     = 0x10,
+       .level_shifter  = 0,
+       .orientation    = MPU_GYRO_ORIENTATION, /* Located in board_[platformname].h    */
+       .sec_slave_type = SECONDARY_SLAVE_TYPE_ACCEL,
+       .sec_slave_id   = ACCEL_ID_KXTF9,
+       .secondary_i2c_addr     = MPU_ACCEL_ADDR,
+       .secondary_read_reg     = 0x06,
+       .secondary_orientation  = MPU_ACCEL_ORIENTATION,
+       .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
+                          0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
+};
 
-       .compass = {
-       .get_slave_descr = get_compass_slave_descr,
-       .adapt_num   = 2,
-       .bus         = EXT_SLAVE_BUS_PRIMARY,
-       .address     = 0x0C,
-       .orientation = { 1, 0, 0, 0, -1, 0, 0, 0, -1 },  /* Orientation matrix for AKM on cardhu */
-       },
+static struct mpu_platform_data mpu_compass_data = {
+       .orientation    = MPU_COMPASS_ORIENTATION,
+       .sec_slave_type = SECONDARY_SLAVE_TYPE_NONE,
 };
 
-static struct i2c_board_info __initdata mpu3050_i2c0_boardinfo[] = {
+static struct i2c_board_info __initdata inv_mpu_i2c2_board_info[] = {
+       {
+               I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
+               .platform_data = &mpu_gyro_data,
+       },
        {
-               I2C_BOARD_INFO(SENSOR_MPU_NAME, 0x68),
-               .irq = TEGRA_GPIO_TO_IRQ(TEGRA_GPIO_PX1),
-               .platform_data = &mpu3050_data,
+               I2C_BOARD_INFO(MPU_ACCEL_NAME, MPU_ACCEL_ADDR),
+       },
+       {
+               I2C_BOARD_INFO(MPU_COMPASS_NAME, MPU_COMPASS_ADDR),
+               .platform_data = &mpu_compass_data,
        },
 };
 
-static void cardhu_mpuirq_init(void)
+static void mpuirq_init(void)
 {
-       struct board_info board_info;
-       tegra_get_board_info(&board_info);
-       if (board_info.board_id != BOARD_E1291)
+       int ret = 0;
+       int i = 0;
+
+       pr_info("*** MPU START *** mpuirq_init...\n");
+
+#if    MPU_ACCEL_IRQ_GPIO
+       /* ACCEL-IRQ assignment */
+       ret = gpio_request(MPU_ACCEL_IRQ_GPIO, MPU_ACCEL_NAME);
+       if (ret < 0) {
+               pr_err("%s: gpio_request failed %d\n", __func__, ret);
                return;
+       }
 
-       pr_info("*** MPU START *** cardhu_mpuirq_init...\n");
-       tegra_gpio_enable(TEGRA_GPIO_PX1);
-       gpio_request(TEGRA_GPIO_PX1, SENSOR_MPU_NAME);
-       gpio_direction_input(TEGRA_GPIO_PX1);
-       pr_info("*** MPU END *** cardhu_mpuirq_init...\n");
+       ret = gpio_direction_input(MPU_ACCEL_IRQ_GPIO);
+       if (ret < 0) {
+               pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
+               gpio_free(MPU_ACCEL_IRQ_GPIO);
+               return;
+       }
+#endif
 
-       i2c_register_board_info(2, mpu3050_i2c0_boardinfo,
-               ARRAY_SIZE(mpu3050_i2c0_boardinfo));
-}
+       /* MPU-IRQ assignment */
+       ret = gpio_request(MPU_GYRO_IRQ_GPIO, MPU_GYRO_NAME);
+       if (ret < 0) {
+               pr_err("%s: gpio_request failed %d\n", __func__, ret);
+               return;
+       }
+
+       ret = gpio_direction_input(MPU_GYRO_IRQ_GPIO);
+       if (ret < 0) {
+               pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
+               gpio_free(MPU_GYRO_IRQ_GPIO);
+               return;
+       }
+       pr_info("*** MPU END *** mpuirq_init...\n");
+
+       inv_mpu_i2c2_board_info[i++].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
+#if MPU_ACCEL_IRQ_GPIO
+       inv_mpu_i2c2_board_info[i].irq = gpio_to_irq(MPU_ACCEL_IRQ_GPIO);
 #endif
+       i++;
+#if MPU_COMPASS_IRQ_GPIO
+       inv_mpu_i2c2_board_info[i++].irq = gpio_to_irq(MPU_COMPAS_IRQ_GPIO);
+#endif
+       i2c_register_board_info(MPU_GYRO_BUS_NUM, inv_mpu_i2c2_board_info,
+               ARRAY_SIZE(inv_mpu_i2c2_board_info));
+}
 
 static struct i2c_board_info cardhu_i2c2_isl_board_info[] = {
        {
@@ -863,7 +1152,7 @@ int __init cardhu_sensors_init(void)
        if (board_info.sku == BOARD_SKU_B11)
                i2c_register_board_info(2, cardhu_i2c2_ltr_board_info,
                        ARRAY_SIZE(cardhu_i2c2_ltr_board_info));
-       else
+       else if (board_info.board_id != BOARD_PM315)
                i2c_register_board_info(2, cardhu_i2c2_isl_board_info,
                        ARRAY_SIZE(cardhu_i2c2_isl_board_info));
 
@@ -874,9 +1163,7 @@ int __init cardhu_sensors_init(void)
        i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
                ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
 
-#ifdef CONFIG_MPU_SENSORS_MPU3050
-       cardhu_mpuirq_init();
-#endif
+       mpuirq_init();
        return 0;
 }
 
@@ -921,19 +1208,20 @@ int __init cardhu_ov5650_late_init(void)
                return 0;
 
        if ((board_info.board_id == BOARD_E1198) ||
-               (board_info.board_id == BOARD_E1291))
+               (board_info.board_id == BOARD_E1291) ||
+               (board_info.board_id == BOARD_PM315))
                return 0;
 
-       printk("%s: \n", __func__);
+       printk(KERN_INFO "%s:\n", __func__);
        for (i = 0; i < ARRAY_SIZE(ov5650_gpio_keys); i++) {
                ret = gpio_request(ov5650_gpio_keys[i].gpio,
                        ov5650_gpio_keys[i].name);
                if (ret < 0) {
-                       printk("%s: gpio_request failed for gpio #%d\n",
+                       printk(KERN_INFO "%s: gpio_request failed for gpio #%d\n",
                                __func__, i);
                        goto fail;
                }
-               printk("%s: enable - %d\n", __func__, i);
+               printk(KERN_INFO "%s: enable - %d\n", __func__, i);
                gpio_direction_output(ov5650_gpio_keys[i].gpio,
                        ov5650_gpio_keys[i].enabled);
                gpio_export(ov5650_gpio_keys[i].gpio, false);