arm: tegra: cardhu: add support for PM315
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
index b08d04d..d90802d 100644 (file)
@@ -53,7 +53,6 @@
 #include <media/ad5816.h>
 #include <linux/bq27x00.h>
 #include <mach/edp.h>
-#include <mach/thermal.h>
 #include <linux/therm_est.h>
 
 #include "gpio-names.h"
@@ -89,7 +88,8 @@ 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)) {
+               (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",
@@ -138,7 +138,8 @@ 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 =
@@ -166,7 +167,8 @@ static int cardhu_left_ov5650_power_on(struct device *dev)
 
        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);
@@ -201,7 +203,8 @@ 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);
@@ -283,7 +286,8 @@ static int cardhu_right_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)) {
 
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
@@ -345,7 +349,8 @@ static int cardhu_right_ov5650_power_off(struct device *dev)
        /* 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_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);
@@ -366,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);
@@ -404,7 +409,8 @@ static int cardhu_ov2710_power_on(struct device *dev)
        /* 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_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))) {
@@ -449,7 +455,8 @@ static int cardhu_ov2710_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);
@@ -476,7 +483,8 @@ static int cardhu_ov5640_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)) {
 
                gpio_direction_output(CAM1_POWER_DWN_GPIO, 0);
                gpio_direction_output(CAM2_POWER_DWN_GPIO, 0);
@@ -529,7 +537,8 @@ static int cardhu_ov5640_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);
@@ -741,59 +750,40 @@ static struct i2c_board_info cardhu_i2c8_board_info[] = {
        },
 };
 
-static int nct_get_temp(void *_data, long *temp)
-{
-       struct nct1008_data *data = _data;
-       return nct1008_thermal_get_temp(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 void nct1008_probe_callback(struct nct1008_data *data)
-{
-       struct tegra_thermal_device *ext_nct;
-
-       ext_nct = kzalloc(sizeof(struct tegra_thermal_device),
-                                       GFP_KERNEL);
-       if (!ext_nct) {
-               pr_err("unable to allocate thermal device\n");
-               return;
-       }
-
-       ext_nct->name = "nct_ext";
-       ext_nct->id = THERMAL_DEVICE_ID_NCT_EXT;
-       ext_nct->data = data;
-       ext_nct->get_temp = nct_get_temp;
-       ext_nct->set_limits = nct_set_limits;
-       ext_nct->set_alert = nct_set_alert;
-
-       tegra_thermal_device_register(ext_nct);
-}
+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 */
-       .shutdown_ext_limit = 90,
-       .shutdown_local_limit = 100,
-       .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[] = {
@@ -820,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) ||
@@ -830,6 +821,29 @@ 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 = gpio_to_irq(nct1008_port);
 
@@ -842,6 +856,9 @@ static int cardhu_nct1008_init(void)
                        gpio_free(nct1008_port);
        }
 
+       i2c_register_board_info(4, cardhu_i2c4_nct1008_board_info,
+               ARRAY_SIZE(cardhu_i2c4_nct1008_board_info));
+
        return ret;
 }
 
@@ -1135,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));
 
@@ -1191,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);