ARM: tegra: thermal: Refactored thermals
Joshua Primero [Thu, 23 Aug 2012 23:29:11 +0000 (16:29 -0700)]
1) Removed skin thermals from tegra_thermal layer
2) Removed throttle initialization from tegra_thermal layer
3) Simplified thermal device interface
4) Create a therm estimator device as a platform device

Change-Id: Ic8ffd111817f03f7aadc89d6185eb749b274b830
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Reviewed-on: http://git-master/r/130282
Reviewed-by: Rohan Somvanshi <rsomvanshi@nvidia.com>
Tested-by: Rohan Somvanshi <rsomvanshi@nvidia.com>

Rebase-Id: Ra98f7e38d1273b0b75c6e4789f1ea98e3be4bf7c

arch/arm/mach-tegra/devices.c
arch/arm/mach-tegra/devices.h
arch/arm/mach-tegra/include/mach/thermal.h
arch/arm/mach-tegra/tegra3_thermal.c
arch/arm/mach-tegra/tegra3_throttle.c
arch/arm/mach-tegra/tegra3_tsensor.c

index 246383b..ec81eb2 100644 (file)
@@ -1899,6 +1899,17 @@ struct platform_device tegra_kbc_device = {
        },
 };
 
+#if defined(CONFIG_TEGRA_SKIN_THROTTLE)
+struct platform_device tegra_skin_therm_est_device = {
+       .name   = "therm_est",
+       .id     = -1,
+       .num_resources  = 0,
+       .dev = {
+               .platform_data = 0,
+       },
+};
+#endif
+
 #if defined(CONFIG_ARCH_TEGRA_3x_SOC)
 static struct resource tegra_tsensor_resources[]= {
        {
index c4c9e5c..6e434b9 100644 (file)
@@ -136,6 +136,9 @@ extern struct platform_device tegra_uarte_device;
 extern struct platform_device tegra_avp_device;
 extern struct nvhost_device nvavp_device;
 extern struct platform_device tegra_aes_device;
+#if defined(CONFIG_TEGRA_SKIN_THROTTLE)
+extern struct platform_device tegra_skin_therm_est_device;
+#endif
 #if !defined(CONFIG_ARCH_TEGRA_2x_SOC)
 extern struct platform_device tegra_tsensor_device;
 #endif
index 6ff5252..43388d2 100644 (file)
 #include <linux/therm_est.h>
 #include <linux/thermal.h>
 
-#ifndef CONFIG_THERMAL
-#endif
-
 enum thermal_device_id {
-       THERMAL_DEVICE_ID_NULL = 0x0,
-       THERMAL_DEVICE_ID_NCT_EXT = 0x1,
-       THERMAL_DEVICE_ID_NCT_INT = 0x2,
-       THERMAL_DEVICE_ID_TSENSOR = 0x4,
-       THERMAL_DEVICE_ID_THERM_EST_SKIN = 0x8,
+       THERMAL_DEVICE_ID_NULL = 0,
+       THERMAL_DEVICE_ID_NCT_EXT = 1,
+       THERMAL_DEVICE_ID_NCT_INT = 2,
+       THERMAL_DEVICE_ID_TSENSOR = 3,
+       THERMAL_DEVICE_ID_THERM_EST_SKIN = 4,
 };
 
-#define THERMAL_DEVICE_MAX     (4)
+#define THERMAL_DEVICE_MAX     (5)
 
 enum cooling_device_id {
        CDEV_BTHROT_ID_TJ      = 0x00010000,
-       CDEV_BTHROT_ID_SKIN    = 0x00020000,
        CDEV_EDPTABLE_ID_EDP   = 0x00030000,
        CDEV_EDPTABLE_ID_EDP_0 = 0x00030000,
        CDEV_EDPTABLE_ID_EDP_1 = 0x00030001,
@@ -58,30 +54,13 @@ struct tegra_thermal_bind {
        } passive;
 };
 
-struct skin_therm_est_subdevice {
-       enum thermal_device_id id;
-       long coeffs[HIST_LEN];
-};
-
-struct tegra_skin_data {
-       enum thermal_device_id skin_device_id;
-
-       long skin_temp_offset;
-       long skin_period;
-       int skin_devs_size;
-       struct skin_therm_est_subdevice skin_devs[];
-};
-
 struct tegra_thermal_device {
        char *name;
        enum thermal_device_id id;
        void *data;
-       long offset;
        int (*get_temp) (void *, long *);
-       int (*get_temp_low)(void *, long *);
        int (*set_limits) (void *, long, long);
        int (*set_alert)(void *, void (*)(void *), void *);
-       int (*set_shutdown_temp)(void *, long);
        struct thermal_zone_device *thz;
        struct list_head node;
 };
@@ -108,27 +87,27 @@ struct balanced_throttle {
 };
 
 #ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-int balanced_throttle_register(struct balanced_throttle *bthrot);
+struct thermal_cooling_device *balanced_throttle_register(
+       struct balanced_throttle *bthrot);
 #else
-static inline int balanced_throttle_register(struct balanced_throttle *bthrot)
-{ return 0; }
+static inline struct thermal_cooling_device *balanced_throttle_register(
+       struct balanced_throttle *bthrot)
+{ return ERR_PTR(-EINVAL); }
 #endif
 
 #ifdef CONFIG_TEGRA_THERMAL
-int tegra_thermal_init(struct tegra_thermal_bind *thermal_binds,
-                               struct tegra_skin_data *skin_data,
-                               struct balanced_throttle *throttle_list,
-                               int throttle_list_size);
+int tegra_thermal_init(struct tegra_thermal_bind *thermal_binds);
 int tegra_thermal_device_register(struct tegra_thermal_device *device);
+struct tegra_thermal_device *tegra_thermal_get_device(enum thermal_device_id id);
 int tegra_thermal_exit(void);
 #else
-static inline int tegra_thermal_init(struct tegra_thermal_bind *thermal_binds,
-                                       struct tegra_skin_data *skin_data,
-                                       struct balanced_throttle *throttle_list,
-                                       int throttle_list_size)
+static inline int tegra_thermal_init(struct tegra_thermal_bind *thermal_binds)
 { return 0; }
 static inline int tegra_thermal_device_register(struct tegra_thermal_device *device)
 { return 0; }
+static inline struct tegra_thermal_device *tegra_thermal_get_device(
+       enum thermal_device_id id)
+{ return NULL; }
 static inline int tegra_thermal_exit(void)
 { return 0; }
 #endif
index eb319e2..f76723e 100644 (file)
 #include <linux/slab.h>
 #include <linux/suspend.h>
 
-#include "clock.h"
-#include "cpu-tegra.h"
-#include "dvfs.h"
-
 static struct tegra_thermal_bind *thermal_binds;
-static struct tegra_skin_data *skin_therm;
-static LIST_HEAD(tegra_therm_list);
-static DEFINE_MUTEX(tegra_therm_mutex);
 
-static struct balanced_throttle *throttle_list;
-static int throttle_list_size;
+static struct tegra_thermal_device *devices[THERMAL_DEVICE_MAX];
+static bool tegra_thermal_suspend;
 
 #define MAX_TEMP (120000)
 
-#ifdef CONFIG_TEGRA_SKIN_THROTTLE
-static int skin_devs_bitmap;
-static struct therm_est_subdevice *skin_devs[THERMAL_DEVICE_MAX];
-static int skin_devs_count;
-#endif
 static bool tegra_thermal_suspend;
 
 static int tegra_thermal_zone_bind(struct thermal_zone_device *thz,
@@ -153,9 +141,9 @@ static int tegra_thermal_zone_get_trip_temp(struct thermal_zone_device *thz,
 static struct thermal_zone_device_ops tegra_thermal_zone_ops = {
        .bind = tegra_thermal_zone_bind,
        .unbind = tegra_thermal_zone_unbind,
-       .get_temp = tegra_thermal_zone_get_temp,
        .get_trip_type = tegra_thermal_zone_get_trip_type,
        .get_trip_temp = tegra_thermal_zone_get_trip_temp,
+       .get_temp = tegra_thermal_zone_get_temp,
 };
 
 static int tegra_thermal_pm_notify(struct notifier_block *nb,
@@ -183,10 +171,8 @@ static void tegra_thermal_alert(void *data)
        long temp, trip_temp, low_temp = 0, high_temp = MAX_TEMP;
        int count;
 
-       mutex_lock(&tegra_therm_mutex);
-
        if (!device->thz)
-               goto done;
+               return;
 
        if ((!device->thz->passive) && (!tegra_thermal_suspend))
                thermal_zone_device_update(device->thz);
@@ -205,60 +191,15 @@ static void tegra_thermal_alert(void *data)
 
        if (device->set_limits && device->thz->trips)
                device->set_limits(device->data, low_temp, high_temp);
-done:
-       mutex_unlock(&tegra_therm_mutex);
 }
 
-#ifdef CONFIG_TEGRA_SKIN_THROTTLE
-static int tegra_skin_device_register(struct tegra_thermal_device *device)
+struct tegra_thermal_device *tegra_thermal_get_device(enum thermal_device_id id)
 {
-       int i;
-       struct therm_est_subdevice *skin_dev =
-               kzalloc(sizeof(struct therm_est_subdevice), GFP_KERNEL);
-
-       for (i = 0; i < skin_therm->skin_devs_size; i++) {
-               if (skin_therm->skin_devs[i].id == device->id) {
-                       memcpy(skin_dev->coeffs,
-                               skin_therm->skin_devs[i].coeffs,
-                               sizeof(skin_devs[i]->coeffs));
-                       break;
-               }
-       }
-
-       skin_dev->dev_data = device->data;
-       skin_dev->get_temp = device->get_temp;
-
-       skin_devs[skin_devs_count++] = skin_dev;
-
-       /* Create skin thermal device */
-       if (skin_devs_count == skin_therm->skin_devs_size) {
-               struct tegra_thermal_device *thermal_skin_device;
-               struct therm_estimator *skin_estimator;
-
-               skin_estimator = therm_est_register(
-                                       skin_devs,
-                                       skin_devs_count,
-                                       skin_therm->skin_temp_offset,
-                                       skin_therm->skin_period);
-               thermal_skin_device = kzalloc(sizeof(struct tegra_thermal_device),
-                                                       GFP_KERNEL);
-               thermal_skin_device->name = "skin_pred";
-               thermal_skin_device->id = THERMAL_DEVICE_ID_SKIN;
-               thermal_skin_device->data = skin_estimator;
-               thermal_skin_device->get_temp =
-                       (int (*)(void *, long *)) therm_est_get_temp;
-               thermal_skin_device->set_limits =
-                       (int (*)(void *, long, long)) therm_est_set_limits;
-               thermal_skin_device->set_alert =
-                       (int (*)(void *, void (*)(void *), void *))
-                               therm_est_set_alert;
-
-               tegra_thermal_device_register(thermal_skin_device);
-       }
+       if (id < 0 || id >= THERMAL_DEVICE_MAX)
+               return NULL;
 
-       return 0;
+       return devices[id];
 }
-#endif
 
 static int passive_get_trip_temp(void *data, long trip)
 {
@@ -273,17 +214,11 @@ static int passive_get_trip_size(void)
 
 int tegra_thermal_device_register(struct tegra_thermal_device *device)
 {
-       struct tegra_thermal_device *dev;
        struct thermal_zone_device *thz = NULL;
        int i, t1 = 0, t2 = 0, pdelay = 0, trips=0;
 
-       mutex_lock(&tegra_therm_mutex);
-       list_for_each_entry(dev, &tegra_therm_list, node) {
-               if (dev->id == device->id) {
-                       mutex_unlock(&tegra_therm_mutex);
-                       return -EINVAL;
-               }
-       }
+       if (device->id >= THERMAL_DEVICE_MAX || devices[device->id])
+               return -EINVAL;
 
        for (i=0; thermal_binds[i].tdev_id; i++) {
                if(device->id == thermal_binds[i].tdev_id) {
@@ -321,59 +256,27 @@ int tegra_thermal_device_register(struct tegra_thermal_device *device)
                                        t2, /* throttle */
                                        pdelay,
                                        0); /* polling delay */
-               if (IS_ERR_OR_NULL(thz))
+               if (IS_ERR_OR_NULL(thz)) {
                        return -ENODEV;
+               }
 
                device->thz = thz;
        }
 
-       list_add(&device->node, &tegra_therm_list);
-       mutex_unlock(&tegra_therm_mutex);
+       devices[device->id] = device;
 
        if (thz) {
                device->set_alert(device->data, tegra_thermal_alert, device);
                tegra_thermal_alert(device);
        }
 
-#ifdef CONFIG_TEGRA_SKIN_THROTTLE
-       if ((skin_therm->skin_device_id == THERMAL_DEVICE_ID_SKIN) &&
-               device->id && skin_devs_bitmap)
-               tegra_skin_device_register(device);
-#endif
-
        return 0;
 }
 
-/* This needs to be inialized later hand */
-static int __init throttle_list_init(void)
-{
-       int i;
-       for (i = 0; i < throttle_list_size; i++)
-               if (balanced_throttle_register(&throttle_list[i]))
-                       return -ENODEV;
-
-       return 0;
-}
-late_initcall(throttle_list_init);
 
-int __init tegra_thermal_init(struct tegra_thermal_bind *binds,
-                               struct tegra_skin_data *skin_data,
-                               struct balanced_throttle *tlist,
-                               int tlist_size)
+int __init tegra_thermal_init(struct tegra_thermal_bind *binds)
 {
        thermal_binds = binds;
-       skin_therm = skin_data;
-
-#ifdef CONFIG_TEGRA_SKIN_THROTTLE
-       {
-               int i;
-               for (i = 0; i < skin_therm->skin_devs_size; i++)
-                       skin_devs_bitmap |= skin_therm->skin_devs[i].id;
-       }
-#endif
-
-       throttle_list = tlist;
-       throttle_list_size = tlist_size;
 
        register_pm_notifier(&tegra_thermal_nb);
 
@@ -382,13 +285,6 @@ int __init tegra_thermal_init(struct tegra_thermal_bind *binds,
 
 int tegra_thermal_exit(void)
 {
-       struct tegra_thermal_device *dev;
-       mutex_lock(&tegra_therm_mutex);
-       list_for_each_entry(dev, &tegra_therm_list, node) {
-               thermal_zone_device_unregister(dev->thz);
-       }
-       mutex_unlock(&tegra_therm_mutex);
-
        return 0;
 }
 
index 23c02ab..21e2c16 100644 (file)
@@ -246,7 +246,8 @@ static struct dentry *throttle_debugfs_root;
 #endif /* CONFIG_DEBUG_FS */
 
 
-int balanced_throttle_register(struct balanced_throttle *bthrot)
+struct thermal_cooling_device *balanced_throttle_register(
+       struct balanced_throttle *bthrot)
 {
 #ifdef CONFIG_DEBUG_FS
        char name[32];
@@ -257,7 +258,7 @@ int balanced_throttle_register(struct balanced_throttle *bthrot)
        list_for_each_entry(dev, &bthrot_list, node) {
                if (dev->tegra_cdev.id == bthrot->tegra_cdev.id) {
                        mutex_unlock(&bthrot_list_lock);
-                       return -EINVAL;
+                       return ERR_PTR(-EINVAL);
                }
        }
 
@@ -272,7 +273,7 @@ int balanced_throttle_register(struct balanced_throttle *bthrot)
 
        if (IS_ERR(bthrot->cdev)) {
                bthrot->cdev = NULL;
-               return -ENODEV;
+               return ERR_PTR(-ENODEV);
        }
 
 #ifdef CONFIG_DEBUG_FS
@@ -281,7 +282,7 @@ int balanced_throttle_register(struct balanced_throttle *bthrot)
                                bthrot, &table_fops);
 #endif
 
-       return 0;
+       return bthrot->cdev;
 }
 
 int __init tegra_throttle_init(struct mutex *cpu_lock)
index 7a1c122..526a355 100644 (file)
@@ -63,12 +63,6 @@ static int tsensor_get_temp(void *vdata, long *milli_temp)
        return tsensor_thermal_get_temp(data, milli_temp);
 }
 
-static int tsensor_get_temp_low(void *vdata, long *milli_temp)
-{
-       struct tegra_tsensor_data *data = vdata;
-       return tsensor_thermal_get_temp_low(data, milli_temp);
-}
-
 static int tsensor_set_limits(void *vdata,
                        long lo_limit_milli,
                        long hi_limit_milli)
@@ -87,12 +81,6 @@ static int tsensor_set_alert(void *vdata,
        return tsensor_thermal_set_alert(data, alert_func, alert_data);
 }
 
-static int tsensor_set_shutdown_temp(void *vdata, long shutdown_temp_milli)
-{
-       struct tegra_tsensor_data *data = vdata;
-       return tsensor_thermal_set_shutdown_temp(data, shutdown_temp_milli);
-}
-
 static void tegra3_tsensor_probe_callback(struct tegra_tsensor_data *data)
 {
        struct tegra_thermal_device *thermal_device;
@@ -108,12 +96,9 @@ static void tegra3_tsensor_probe_callback(struct tegra_tsensor_data *data)
        thermal_device->name = "tsensor";
        thermal_device->data = data;
        thermal_device->id = THERMAL_DEVICE_ID_TSENSOR;
-       thermal_device->offset = TSENSOR_OFFSET;
        thermal_device->get_temp = tsensor_get_temp;
-       thermal_device->get_temp_low = tsensor_get_temp_low;
        thermal_device->set_limits = tsensor_set_limits;
        thermal_device->set_alert = tsensor_set_alert;
-       thermal_device->set_shutdown_temp = tsensor_set_shutdown_temp;
 
        /* This should not fail */
        if (tegra_thermal_device_register(thermal_device))