ARM: tegra: thermal: Remove tegra therm dependency
Joshua Primero [Thu, 30 Aug 2012 03:16:22 +0000 (20:16 -0700)]
Removed the use of the Tegra thermal layer. All management
is now done via Linux thermal framework via thermal_zone_devices
and thermal_cooling_zones.

Change-Id: I87de8a7dd8ff8e338d3c18db1518b5acfc18faee
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Reviewed-on: http://git-master/r/132883
(cherry picked from commit cb9e0dbe41d7419d6152f02ea10f13faa7448e81)
Signed-off-by: Gaurav Batra <gbatra@nvidia.com>
Reviewed-on: http://git-master/r/130289
Reviewed-by: Simone Willett <swillett@nvidia.com>
Tested-by: Simone Willett <swillett@nvidia.com>

15 files changed:
arch/arm/mach-tegra/Kconfig
arch/arm/mach-tegra/Makefile
arch/arm/mach-tegra/board-cardhu-sensors.c
arch/arm/mach-tegra/board-cardhu.c
arch/arm/mach-tegra/board-enterprise-sensors.c
arch/arm/mach-tegra/board-enterprise.c
arch/arm/mach-tegra/board-kai-sensors.c
arch/arm/mach-tegra/board-kai.c
arch/arm/mach-tegra/board-ventana-sensors.c
arch/arm/mach-tegra/cpu-tegra.c
arch/arm/mach-tegra/cpu-tegra.h
arch/arm/mach-tegra/include/mach/edp.h
arch/arm/mach-tegra/include/mach/tsensor.h
arch/arm/mach-tegra/tegra3_throttle.c
arch/arm/mach-tegra/tegra3_tsensor.c

index cb24c01..a193687 100644 (file)
@@ -482,17 +482,11 @@ config TEGRA_AVP_KERNEL_ON_SMMU
 config TEGRA_ARB_SEMAPHORE
        bool
 
-config TEGRA_THERMAL
-       bool "Enable Tegra Thermal Framework"
-       depends on ARCH_TEGRA_3x_SOC
-       depends on THERMAL
-       default y
-
 config TEGRA_THERMAL_THROTTLE
        bool "Enable throttling of CPU speed on overtemp"
        depends on TEGRA_SILICON_PLATFORM
        depends on CPU_FREQ
-       depends on TEGRA_THERMAL
+       depends on THERMAL
        default y
        help
          Also requires enabling a temperature sensor such as NCT1008.
@@ -541,7 +535,7 @@ config TEGRA_EDP_LIMITS
        bool "Enforce electrical design limits"
        depends on TEGRA_SILICON_PLATFORM
        depends on CPU_FREQ
-       depends on TEGRA_THERMAL
+       depends on THERMAL
        default y if ARCH_TEGRA_3x_SOC
        default n
        help
index 61c3106..b0c3925 100644 (file)
@@ -120,8 +120,8 @@ obj-$(CONFIG_ARCH_TEGRA_11x_SOC)        += tegra11_soctherm.o
 ifeq ($(CONFIG_TEGRA_THERMAL_THROTTLE),y)
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += tegra2_throttle.o
 obj-$(CONFIG_ARCH_TEGRA_3x_SOC)         += tegra3_throttle.o
+obj-$(CONFIG_ARCH_TEGRA_11x_SOC)        += tegra3_throttle.o
 endif
-obj-$(CONFIG_TEGRA_THERMAL)             += tegra3_thermal.o
 obj-$(CONFIG_TEGRA_IOVMM)               += iovmm.o
 obj-$(CONFIG_TEGRA_IOVMM_GART)          += iovmm-gart.o
 obj-$(CONFIG_TEGRA_IOVMM_SMMU)          += iovmm-smmu.o
index b08d04d..ac6930e 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"
@@ -741,59 +740,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,
+               .tc1 = 1,
+               .passive_delay = 2000,
+       }
 };
 
 static struct i2c_board_info cardhu_i2c4_bq27510_board_info[] = {
@@ -830,6 +810,28 @@ 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].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 +844,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;
 }
 
index 8e09c5e..9ef3c7f 100644 (file)
 #include <mach/tegra_asoc_pdata.h>
 #include <mach/tegra_wm8903_pdata.h>
 #include <mach/usb_phy.h>
-#include <mach/thermal.h>
 #include <mach/pci.h>
 #include <mach/gpio-tegra.h>
 #include <mach/tegra_fiq_debugger.h>
-#include <linux/thermal.h>
 
 #include <asm/hardware/gic.h>
 #include <asm/mach-types.h>
 #include "wdt-recovery.h"
 #include "common.h"
 
-static struct balanced_throttle throttle_list[] = {
-       {
-               .tegra_cdev = {
-                       .id = CDEV_BTHROT_ID_TJ,
-               },
-               .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 tegra_thermal_bind thermal_binds[] = {
-       /* Thermal Throttling */
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NCT_EXT,
-               .cdev_id = CDEV_BTHROT_ID_TJ,
-               .type = THERMAL_TRIP_PASSIVE,
-               .passive = {
-                       .trip_temp = 85000,
-                       .tc1 = 0,
-                       .tc2 = 1,
-                       .passive_delay = 2000,
-               }
-       },
-       /* EDP Capping */
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NCT_EXT,
-               .cdev_id = CDEV_EDPTABLE_ID_EDP,
-               .type = THERMAL_TRIP_ACTIVE,
-               .get_trip_temp = tegra_edp_get_trip_temp,
-               .get_trip_size = tegra_edp_get_trip_size,
-       },
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NULL,
-       },
-};
-
 static struct rfkill_gpio_platform_data cardhu_bt_rfkill_pdata[] = {
        {
                .name           = "bt_rfkill",
@@ -1289,7 +1240,6 @@ late_initcall(cardhu_throttle_list_init);
 
 static void __init tegra_cardhu_init(void)
 {
-       tegra_thermal_init(thermal_binds);
        tegra_clk_init_from_table(cardhu_clk_init_table);
        tegra_enable_pinmux();
        tegra_smmu_init();
index e6a5e11..8238725 100644 (file)
@@ -47,7 +47,6 @@
 #include <media/tps61050.h>
 #include <media/ov9726.h>
 #include <mach/edp.h>
-#include <mach/thermal.h>
 #include <mach/gpio-tegra.h>
 #include <mach/clk.h>
 #include "cpu-tegra.h"
 
 static struct board_info 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 *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->id = THERMAL_DEVICE_ID_NCT_EXT;
-       thermal_device->get_temp = nct_get_temp;
-       thermal_device->set_limits = nct_set_limits;
-       thermal_device->set_alert = nct_set_alert;
-
-       tegra_thermal_device_register(thermal_device);
-}
-
 static struct nct1008_platform_data enterprise_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,
 };
 
 static struct i2c_board_info enterprise_i2c4_nct1008_board_info[] = {
index aac9c49..8b7cbd8 100644 (file)
@@ -61,7 +61,6 @@
 #include <mach/i2s.h>
 #include <mach/tegra_aic326x_pdata.h>
 #include <mach/tegra_asoc_pdata.h>
-#include <mach/thermal.h>
 #include <mach/tegra-bb-power.h>
 #include <mach/gpio-tegra.h>
 #include <mach/tegra_fiq_debugger.h>
 #include "pm.h"
 #include "common.h"
 
-static struct balanced_throttle throttle_list[] = {
-       {
-               .tegra_cdev = {
-                       .id = CDEV_BTHROT_ID_TJ,
-               },
-               .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 },
-               },
-       },
-};
-
-/* All units are in millicelsius */
-static struct tegra_thermal_bind thermal_binds[] = {
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NCT_EXT,
-               .cdev_id = CDEV_BTHROT_ID_TJ,
-               .type = THERMAL_TRIP_PASSIVE,
-               .passive = {
-                       .trip_temp = 85000,
-                       .tc1 = 0,
-                       .tc2 = 1,
-                       .passive_delay = 2000,
-               }
-       },
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NULL,
-       },
-};
-
 /* wl128x BT, FM, GPS connectivity chip */
 struct ti_st_plat_data enterprise_wilink_pdata = {
-       .nshutdown_gpio = TEGRA_GPIO_PE6,
-       .dev_name = BLUETOOTH_UART_DEV_NAME,
-       .flow_cntrl = 1,
-       .baud_rate = 3000000,
+       .nshutdown_gpio = TEGRA_GPIO_PE6,
+       .dev_name = BLUETOOTH_UART_DEV_NAME,
+       .flow_cntrl = 1,
+       .baud_rate = 3000000,
 };
 
 static struct platform_device wl128x_device = {
-       .name           = "kim",
-       .id             = -1,
-       .dev.platform_data = &enterprise_wilink_pdata,
+       .name           = "kim",
+       .id             = -1,
+       .dev.platform_data = &enterprise_wilink_pdata,
 };
 
 static struct platform_device btwilink_device = {
-       .name = "btwilink",
-       .id = -1,
+       .name = "btwilink",
+       .id = -1,
 };
 
 static noinline void __init enterprise_bt_st(void)
 {
-       pr_info("enterprise_bt_st");
+       pr_info("enterprise_bt_st");
 
-       platform_device_register(&wl128x_device);
-       platform_device_register(&btwilink_device);
+       platform_device_register(&wl128x_device);
+       platform_device_register(&btwilink_device);
 }
+
 static struct rfkill_gpio_platform_data enterprise_bt_rfkill_pdata[] = {
        {
                .name           = "bt_rfkill",
@@ -1110,7 +1071,6 @@ static void __init tegra_enterprise_init(void)
        else
                tegra_clk_init_from_table(enterprise_clk_i2s2_table);
 
-       tegra_thermal_init(thermal_binds);
        tegra_clk_init_from_table(enterprise_clk_init_table);
        tegra_enable_pinmux();
        tegra_smmu_init();
index 796b815..062d9c9 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/slab.h>
 #include <linux/gpio.h>
 #include <asm/mach-types.h>
-#include <mach/thermal.h>
 #include <media/ov2710.h>
 
 #include <mach/gpio-tegra.h>
 static struct regulator *kai_1v8_cam3;
 static struct regulator *kai_vdd_cam3;
 
-#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
-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 *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 = "nct72";
-       thermal_device->data = data;
-       thermal_device->id = THERMAL_DEVICE_ID_NCT_EXT;
-       thermal_device->get_temp = nct_get_temp;
-       thermal_device->set_limits = nct_set_limits;
-       thermal_device->set_alert = nct_set_alert;
-
-       tegra_thermal_device_register(thermal_device);
-}
-#endif
-
 static struct nct1008_platform_data kai_nct1008_pdata = {
        .supported_hwrev = true,
        .ext_range = true,
        .conv_rate = 0x09, /* 0x09 corresponds to 32Hz conversion rate */
        .offset = 8, /* 4 * 2C. 1C for device accuracies */
-#ifndef CONFIG_TEGRA_INTERNAL_TSENSOR_EDP_SUPPORT
-       .probe_callback = nct1008_probe_callback,
-#endif
 };
 
 static struct i2c_board_info kai_i2c4_nct1008_board_info[] = {
index 5a0074b..f7dd56a 100644 (file)
@@ -61,7 +61,6 @@
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <mach/usb_phy.h>
-#include <mach/thermal.h>
 #include <mach/gpio-tegra.h>
 #include <mach/tegra_fiq_debugger.h>
 
 #include "wdt-recovery.h"
 #include "common.h"
 
-static struct balanced_throttle throttle_list[] = {
-       {
-               .tegra_cdev = {
-                       .id = CDEV_BTHROT_ID_TJ,
-               },
-               .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 },
-               },
-       },
-};
-
-/* All units are in millicelsius */
-static struct tegra_thermal_bind thermal_binds[] = {
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NCT_EXT,
-               .cdev_id = CDEV_BTHROT_ID_TJ,
-               .type = THERMAL_TRIP_PASSIVE,
-               .passive = {
-                       .trip_temp = 85000,
-                       .tc1 = 0,
-                       .tc2 = 1,
-                       .passive_delay = 2000,
-               }
-       },
-       {
-               .tdev_id = THERMAL_DEVICE_ID_NULL,
-       },
-};
-
 /* wl128x BT, FM, GPS connectivity chip */
 struct ti_st_plat_data kai_wilink_pdata = {
        .nshutdown_gpio = TEGRA_GPIO_PU0,
@@ -863,7 +823,6 @@ late_initcall(kai_throttle_list_init);
 
 static void __init tegra_kai_init(void)
 {
-       tegra_thermal_init(thermal_binds);
        tegra_clk_init_from_table(kai_clk_init_table);
        tegra_enable_pinmux();
        tegra_smmu_init();
index 354082e..6e3dfa6 100644 (file)
@@ -41,6 +41,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/gpio.h>
 #include <linux/module.h>
+#include <linux/thermal.h>
 
 #include <mach/gpio-tegra.h>
 
@@ -206,114 +207,65 @@ static void ventana_nct1008_init(void)
        gpio_direction_input(NCT1008_THERM2_GPIO);
 }
 
-static long ventana_shutdown_temp = 115000;
-static long ventana_throttle_temp = 90000;
-static long ventana_throttle_hysteresis = 3000;
-static struct nct1008_data *nct_data;
-
-static void ventana_thermal_alert(void *vdata)
-{
-       struct nct1008_data *data = vdata;
-       long temp;
-       long lo_limit, hi_limit;
-       bool is_above_throttle;
-
-       nct1008_thermal_get_temp(data, &temp);
-       is_above_throttle = (temp >= ventana_throttle_temp);
-
-       if (is_above_throttle != tegra_is_throttling())
-               tegra_throttling_enable(is_above_throttle);
-
-       if (is_above_throttle) {
-               lo_limit = ventana_throttle_temp - ventana_throttle_hysteresis;
-               hi_limit = ventana_shutdown_temp;
-       } else {
-               lo_limit = 0;
-               hi_limit = ventana_throttle_temp;
-       }
-
-       nct1008_thermal_set_limits(data, lo_limit, hi_limit);
-}
-
-static void nct1008_probe_callback(struct nct1008_data *data)
-{
-       nct_data = data;
-       nct1008_thermal_set_shutdown_temp(data, ventana_shutdown_temp);
-       nct1008_thermal_set_alert(data, ventana_thermal_alert, data);
-       nct1008_thermal_set_limits(data, 0, ventana_throttle_temp);
-}
-
-#ifdef CONFIG_DEBUG_FS
-static int ventana_thermal_get_throttle_temp(void *data, u64 *val)
+#ifdef CONFIG_THERMAL
+static int throttle_get_max_state(struct thermal_cooling_device *cdev,
+                               unsigned long *max_state)
 {
-       *val = (u64)ventana_throttle_temp;
+       *max_state = 1;
        return 0;
 }
 
-static int ventana_thermal_set_throttle_temp(void *data, u64 val)
+static int throttle_get_cur_state(struct thermal_cooling_device *cdev,
+                               unsigned long *cur_state)
 {
-       ventana_throttle_temp = val;
-       if (nct_data)
-               ventana_thermal_alert(nct_data);
-
+       *cur_state = tegra_is_throttling();
        return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(throttle_fops,
-                       ventana_thermal_get_throttle_temp,
-                       ventana_thermal_set_throttle_temp,
-                       "%llu\n");
-
-static int ventana_thermal_get_shutdown_temp(void *data, u64 *val)
+static int throttle_set_cur_state(struct thermal_cooling_device *cdev,
+                               unsigned long cur_state)
 {
-       *val = (u64)ventana_shutdown_temp;
+       if (tegra_is_throttling() != cur_state)
+               tegra_throttling_enable(cur_state);
        return 0;
 }
 
-static int ventana_thermal_set_shutdown_temp(void *data, u64 val)
-{
-       ventana_shutdown_temp = val;
-       if (nct_data)
-               nct1008_thermal_set_shutdown_temp(nct_data,
-                                               ventana_shutdown_temp);
+static struct thermal_cooling_device_ops throttle_cooling_ops = {
+       .get_max_state = throttle_get_max_state,
+       .get_cur_state = throttle_get_cur_state,
+       .set_cur_state = throttle_set_cur_state,
+};
 
-       return 0;
+static struct thermal_cooling_device *throttle_create(void *data)
+{
+       return thermal_cooling_device_register("throttle",
+                                               NULL,
+                                               &throttle_cooling_ops);
 }
-
-DEFINE_SIMPLE_ATTRIBUTE(shutdown_fops,
-                       ventana_thermal_get_shutdown_temp,
-                       ventana_thermal_set_shutdown_temp,
-                       "%llu\n");
-
-
-static int __init ventana_thermal_debug_init(void)
+#else
+static struct thermal_cooling_device *throttle_create(void *data)
 {
-       struct dentry *thermal_debugfs_root;
-
-       thermal_debugfs_root = debugfs_create_dir("thermal", 0);
-
-       if (!debugfs_create_file("throttle", 0644, thermal_debugfs_root,
-                                       NULL, &throttle_fops))
-               return -ENOMEM;
-
-       if (!debugfs_create_file("shutdown", 0644, thermal_debugfs_root,
-                                       NULL, &shutdown_fops))
-               return -ENOMEM;
-
-       return 0;
+       return NULL;
 }
-
-late_initcall(ventana_thermal_debug_init);
-
 #endif
 
-
 static struct nct1008_platform_data ventana_nct1008_pdata = {
        .supported_hwrev = true,
        .ext_range = false,
        .conv_rate = 0x08,
        .offset = 0,
-       .probe_callback = nct1008_probe_callback,
+       .shutdown_local_limit = 125,
+       .shutdown_ext_limit = 115,
+
+       /* Thermal Throttling */
+       .passive = {
+               .create_cdev = throttle_create,
+               .cdev_data = NULL,
+               .trip_temp = 90000,
+               .tc1 = 0,
+               .tc1 = 1,
+               .passive_delay = 2000,
+       },
 };
 
 static struct i2c_board_info ventana_i2c0_board_info[] = {
index 95b9783..3540e49 100644 (file)
@@ -37,7 +37,6 @@
 
 #include <mach/clk.h>
 #include <mach/edp.h>
-#include <mach/thermal.h>
 
 #include "clock.h"
 #include "cpu-tegra.h"
@@ -213,18 +212,6 @@ static unsigned int edp_governor_speed(unsigned int requested_speed)
                return edp_limit;
 }
 
-int tegra_edp_get_trip_temp(void *data, long trip)
-{
-       tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
-       return cpu_edp_limits[trip].temperature * 1000;
-}
-
-int tegra_edp_get_trip_size(void)
-{
-       tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
-       return cpu_edp_limits_size-1;
-}
-
 int tegra_edp_get_max_state(struct thermal_cooling_device *cdev,
                                unsigned long *max_state)
 {
@@ -238,24 +225,21 @@ static int edp_state_mask;
 int tegra_edp_get_cur_state(struct thermal_cooling_device *cdev,
                                unsigned long *cur_state)
 {
-       struct tegra_cooling_device *tegra_cdev = cdev->devdata;
-       int index = tegra_cdev->id && 0xffff;
-       *cur_state = !!((1 << index) & edp_state_mask);
+       int index = (int)cdev->devdata;
+       *cur_state = !!((1 << (index)) & edp_state_mask);
        return 0;
 }
 
 int tegra_edp_set_cur_state(struct thermal_cooling_device *cdev,
                                unsigned long cur_state)
 {
-       struct tegra_cooling_device *tegra_cdev = cdev->devdata;
-       int index, i;
-
+       int index = (int)cdev->devdata;
+       int i;
 
        if (!cpu_edp_limits)
                return -EINVAL;
 
        mutex_lock(&tegra_cpu_lock);
-       index = tegra_cdev->id & 0xffff;
 
        if (cur_state)
                edp_state_mask |= 1 << index;
@@ -287,6 +271,17 @@ static struct thermal_cooling_device_ops tegra_edp_cooling_ops = {
        .set_cur_state = tegra_edp_set_cur_state,
 };
 
+struct thermal_cooling_device *edp_cooling_device_create(int index)
+{
+       if (index >= cpu_edp_limits_size)
+               return ERR_PTR(-EINVAL);
+
+       return thermal_cooling_device_register(
+                               "edp",
+                               (void *)index,
+                               &tegra_edp_cooling_ops);
+}
+
 int tegra_system_edp_alarm(bool alarm)
 {
        int ret = -ENODEV;
@@ -389,16 +384,6 @@ static struct notifier_block tegra_cpu_edp_notifier = {
        .notifier_call = tegra_cpu_edp_notify,
 };
 
-static struct thermal_cooling_device *edp_cdev;
-static struct tegra_cooling_device edp_cooling_devices[] = {
-       { .id = CDEV_EDPTABLE_ID_EDP_0 },
-       { .id = CDEV_EDPTABLE_ID_EDP_1 },
-       { .id = CDEV_EDPTABLE_ID_EDP_2 },
-       { .id = CDEV_EDPTABLE_ID_EDP_3 },
-       { .id = CDEV_EDPTABLE_ID_EDP_4 },
-};
-
-
 static void tegra_cpu_edp_init(bool resume)
 {
        tegra_get_system_edp_limits(&system_edp_limits);
@@ -422,17 +407,6 @@ static void tegra_cpu_edp_init(bool resume)
                register_hotcpu_notifier(&tegra_cpu_edp_notifier);
                pr_info("cpu-tegra: init EDP limit: %u MHz\n", edp_limit/1000);
        }
-
-       if (!edp_cdev) {
-               int i;
-               for (i=0; i<cpu_edp_limits_size-1; i++) {
-                       edp_cdev = thermal_cooling_device_register(
-                               "edp",
-                               &edp_cooling_devices[i],
-                               &tegra_edp_cooling_ops);
-               }
-       }
-
 }
 
 static void tegra_cpu_edp_exit(void)
index 0dda294..6434ed8 100644 (file)
@@ -21,6 +21,8 @@
 #ifndef __MACH_TEGRA_CPU_TEGRA_H
 #define __MACH_TEGRA_CPU_TEGRA_H
 
+#include <linux/fs.h>
+
 unsigned int tegra_getspeed(unsigned int cpu);
 int tegra_update_cpu_speed(unsigned long rate);
 int tegra_cpu_set_speed_cap(unsigned int *speed_cap);
@@ -29,8 +31,26 @@ unsigned int tegra_get_slowest_cpu_n(void);
 unsigned long tegra_cpu_lowest_speed(void);
 unsigned long tegra_cpu_highest_speed(void);
 
+#define MAX_THROT_TABLE_SIZE   (32)
+
+struct throttle_table {
+       unsigned int cpu_freq;
+       int core_cap_level;
+};
+
+struct balanced_throttle {
+       struct thermal_cooling_device *cdev;
+       struct list_head node;
+       int is_throttling;
+       int throttle_index;
+       int throt_tab_size;
+       struct throttle_table throt_tab[MAX_THROT_TABLE_SIZE + 1];
+};
+
 #ifdef CONFIG_TEGRA_THERMAL_THROTTLE
 int tegra_throttle_init(struct mutex *cpu_lock);
+struct thermal_cooling_device *balanced_throttle_register(
+       struct balanced_throttle *bthrot);
 void tegra_throttle_exit(void);
 bool tegra_is_throttling(void);
 unsigned int tegra_throttle_governor_speed(unsigned int requested_speed);
@@ -39,6 +59,9 @@ void tegra_throttling_enable(bool enable);
 #else
 static inline int tegra_throttle_init(struct mutex *cpu_lock)
 { return 0; }
+static inline struct thermal_cooling_device *balanced_throttle_register(
+       struct balanced_throttle *bthrot)
+{ return ERR_PTR(-EINVAL); }
 static inline void tegra_throttle_exit(void)
 {}
 static inline bool tegra_is_throttling(void)
index 1192a29..a074309 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <linux/debugfs.h>
 #include <linux/edp.h>
+#include <linux/thermal.h>
 
 struct tegra_edp_entry {
        char speedo_id;
@@ -43,8 +44,7 @@ struct system_edp_entry {
 };
 
 #ifdef CONFIG_TEGRA_EDP_LIMITS
-int tegra_edp_get_trip_temp(void *, long trip);
-int tegra_edp_get_trip_size(void);
+struct thermal_cooling_device *edp_cooling_device_create(int index);
 void tegra_init_cpu_edp_limits(unsigned int regulator_mA);
 void tegra_init_system_edp_limits(unsigned int power_limit_mW);
 void tegra_get_cpu_edp_limits(const struct tegra_edp_limits **limits, int *size);
@@ -53,14 +53,13 @@ void tegra_get_system_edp_limits(const unsigned int **limits);
 int tegra_system_edp_alarm(bool alarm);
 
 #else
+static inline struct thermal_cooling_device *edp_cooling_device_create(
+       int index)
+{ return NULL; }
 static inline void tegra_init_cpu_edp_limits(int regulator_mA)
 {}
 static inline void tegra_init_system_edp_limits(int power_limit_mW)
 {}
-static inline int tegra_edp_get_trip_temp(void *data, long trip)
-{ return 0; }
-static inline int tegra_edp_get_trip_size(void)
-{ return 0; }
 static inline void tegra_get_cpu_edp_limits(struct tegra_edp_limits **limits,
                                            int *size)
 {}
index 190a385..05cd54e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Tegra tsensor header file
  *
- * Copyright (c) 2011, NVIDIA Corporation.
+ * Copyright (c) 2011-2012, NVIDIA Corporation.
  *
  * This software is licensed under the terms of the GNU General Public
  * License version 2, as published by the Free Software Foundation, and
 #define __MACH_TEGRA_TSENSOR_H
 
 #include <linux/types.h>
+#include <linux/thermal.h>
+
+struct tegra_tsensor_cdev {
+       struct thermal_cooling_device *cdev;
+       long trip_temp;
+       enum thermal_trip_type type;
+       int tc1;
+       int tc2;
+       int passive_delay;
+};
 
-#include <mach/edp.h>
-
-#define MAX_ZONES      16
-
-struct tegra_tsensor_data;
+#define TSENSOR_MAX_ACTIVE (16)
 
 struct tegra_tsensor_platform_data {
-       void (*probe_callback)(struct tegra_tsensor_data *);
+       long shutdown_temp;
+       struct tegra_tsensor_cdev passive;
+       struct tegra_tsensor_cdev active[TSENSOR_MAX_ACTIVE + 1];
 };
 
-int tsensor_thermal_get_temp(struct tegra_tsensor_data *data,
-                               long *milli_temp);
-int tsensor_thermal_get_temp_low(struct tegra_tsensor_data *data,
-                                       long *milli_temp);
-int tsensor_thermal_set_limits(struct tegra_tsensor_data *data,
-                               long lo_limit_milli,
-                               long hi_limit_milli);
-int tsensor_thermal_set_alert(struct tegra_tsensor_data *data,
-                               void (*alert_func)(void *),
-                               void *alert_data);
-int tsensor_thermal_set_shutdown_temp(struct tegra_tsensor_data *data,
-                               long shutdown_temp_milli);
-
 #endif /* __MACH_TEGRA_TSENSOR_H */
 
index 21e2c16..37d729a 100644 (file)
@@ -28,7 +28,6 @@
 #include <linux/uaccess.h>
 #include <linux/thermal.h>
 #include <linux/module.h>
-#include <mach/thermal.h>
 
 #include "clock.h"
 #include "cpu-tegra.h"
@@ -37,6 +36,7 @@
 static struct mutex *cpu_throttle_lock;
 static DEFINE_MUTEX(bthrot_list_lock);
 static LIST_HEAD(bthrot_list);
+static int num_throt;
 
 static unsigned int clip_to_table(unsigned int cpu_freq)
 {
@@ -252,17 +252,8 @@ struct thermal_cooling_device *balanced_throttle_register(
 #ifdef CONFIG_DEBUG_FS
        char name[32];
 #endif
-       struct balanced_throttle *dev;
-
        mutex_lock(&bthrot_list_lock);
-       list_for_each_entry(dev, &bthrot_list, node) {
-               if (dev->tegra_cdev.id == bthrot->tegra_cdev.id) {
-                       mutex_unlock(&bthrot_list_lock);
-                       return ERR_PTR(-EINVAL);
-               }
-       }
-
-
+       num_throt++;
        list_add(&bthrot->node, &bthrot_list);
        mutex_unlock(&bthrot_list_lock);
 
@@ -277,7 +268,7 @@ struct thermal_cooling_device *balanced_throttle_register(
        }
 
 #ifdef CONFIG_DEBUG_FS
-       sprintf(name, "throttle_table%d", bthrot->tegra_cdev.id);
+       sprintf(name, "throttle_table%d", num_throt);
        debugfs_create_file(name,0644, throttle_debugfs_root,
                                bthrot, &table_fops);
 #endif
index 526a355..4ad4271 100644 (file)
@@ -23,9 +23,9 @@
 #include <mach/tsensor.h>
 #include <mach/tegra_fuse.h>
 #include <mach/iomap.h>
-#include <mach/thermal.h>
 #include <mach/tsensor.h>
 
+#include "cpu-tegra.h"
 #include "devices.h"
 #include "tegra3_tsensor.h"
 
 #define PMU_16BIT_SUPPORT_MASK                 0x1
 
 #define TSENSOR_OFFSET (4000 + 5000)
-
-static int tsensor_get_temp(void *vdata, long *milli_temp)
-{
-       struct tegra_tsensor_data *data = vdata;
-       return tsensor_thermal_get_temp(data, milli_temp);
-}
-
-static int tsensor_set_limits(void *vdata,
-                       long lo_limit_milli,
-                       long hi_limit_milli)
-{
-       struct tegra_tsensor_data *data = vdata;
-       return tsensor_thermal_set_limits(data,
-                                       lo_limit_milli,
-                                       hi_limit_milli);
-}
-
-static int tsensor_set_alert(void *vdata,
-                       void (*alert_func)(void *),
-                       void *alert_data)
-{
-       struct tegra_tsensor_data *data = vdata;
-       return tsensor_thermal_set_alert(data, alert_func, alert_data);
-}
-
-static void tegra3_tsensor_probe_callback(struct tegra_tsensor_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 = "tsensor";
-       thermal_device->data = data;
-       thermal_device->id = THERMAL_DEVICE_ID_TSENSOR;
-       thermal_device->get_temp = tsensor_get_temp;
-       thermal_device->set_limits = tsensor_set_limits;
-       thermal_device->set_alert = tsensor_set_alert;
-
-       /* This should not fail */
-       if (tegra_thermal_device_register(thermal_device))
-               BUG();
-}
+#define TDIODE_OFFSET  (9000 + 1000)
+
+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 tegra_tsensor_platform_data tsensor_data = {
-       .probe_callback = tegra3_tsensor_probe_callback,
+       .shutdown_temp = 90 + TDIODE_OFFSET - TSENSOR_OFFSET,
+       .passive = {
+               .trip_temp = 85 + TDIODE_OFFSET - TSENSOR_OFFSET,
+               .tc1 = 0,
+               .tc1 = 1,
+               .passive_delay = 2000,
+       }
 };
 
 void __init tegra3_tsensor_init(struct tegra_tsensor_pmu_data *data)
@@ -164,7 +139,11 @@ void __init tegra3_tsensor_init(struct tegra_tsensor_pmu_data *data)
        val |= (checksum << CHECKSUM_OFFSET);
        writel(val, pMem + 4);
 
+
 labelSkipPowerOff:
+       /* Thermal throttling */
+       tsensor_data.passive.cdev = balanced_throttle_register(&tj_throttle);
+
        /* set platform data for device before register */
        tegra_tsensor_device.dev.platform_data = &tsensor_data;
        platform_device_register(&tegra_tsensor_device);