ARM: tegra: thermal: Edp into cooling device
[linux-2.6.git] / arch / arm / mach-tegra / tegra3_thermal.c
index 6322eb3..32c817c 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * arch/arm/mach-tegra/tegra3_thermal.c
  *
- * Copyright (C) 2010-2011 NVIDIA Corporation.
+ * Copyright (C) 2010-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
 #include <linux/seq_file.h>
 #include <linux/uaccess.h>
 #include <linux/thermal.h>
+#include <linux/module.h>
 #include <mach/thermal.h>
-#include <mach/edp.h>
 #include <linux/slab.h>
+#include <linux/suspend.h>
 
 #include "clock.h"
 #include "cpu-tegra.h"
 #include "dvfs.h"
 
-#define MAX_ZONES (16)
+static struct tegra_thermal_data *therm;
+static struct tegra_skin_data *skin_therm;
+static LIST_HEAD(tegra_therm_list);
+static DEFINE_MUTEX(tegra_therm_mutex);
 
-struct tegra_thermal {
-       struct tegra_thermal_device *device;
-       long temp_shutdown_tj;
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       long temp_throttle_tj;
-       struct thermal_zone_device *thz;
-       int tc1;
-       int tc2;
-       long passive_delay;
-#endif
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-       int edp_thermal_zone_val;
-       long edp_offset;
-       long hysteresis_edp;
-#endif
-       struct mutex mutex;
-};
+static struct balanced_throttle *throttle_list;
+static int throttle_list_size;
 
-static struct tegra_thermal thermal_state = {
-       .device = NULL,
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-       .edp_thermal_zone_val = -1,
-#endif
-};
+#define MAX_TEMP (120000)
 
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-static inline long edp2tj(struct tegra_thermal *thermal,
-                               long edp_temp)
-{
-       return edp_temp + thermal->edp_offset;
-}
+#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 inline long tj2edp(struct tegra_thermal *thermal,
-                               long temp_tj)
-{
-       return temp_tj - thermal->edp_offset;
-}
+#ifdef CONFIG_DEBUG_FS
+static struct dentry *thermal_debugfs_root;
 #endif
 
 static inline long dev2tj(struct tegra_thermal_device *dev,
@@ -86,55 +67,124 @@ static inline long tj2dev(struct tegra_thermal_device *dev,
        return tj_temp - dev->offset;
 }
 
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
+static int tegra_thermal_get_temp_unlocked(long *tj_temp, bool offsetted)
+{
+       struct tegra_thermal_device *dev = NULL;
+       int ret = 0;
 
-static int tegra_thermal_zone_bind(struct thermal_zone_device *thermal,
-                               struct thermal_cooling_device *cdevice) {
-       /* Support only Thermal Throttling (1 trip) for now */
-       return thermal_zone_bind_cooling_device(thermal, 0, cdevice);
+       list_for_each_entry(dev, &tegra_therm_list, node)
+               if (dev->id == therm->throttle_edp_device_id)
+                       break;
+
+       if (dev) {
+               dev->get_temp(dev->data, tj_temp);
+               if (offsetted)
+                       *tj_temp = dev2tj(dev, *tj_temp);
+       } else {
+               *tj_temp = 0xdeadbeef;
+               ret = -1;
+       }
+
+       return ret;
 }
 
-static int tegra_thermal_zone_unbind(struct thermal_zone_device *thermal,
+static int tegra_thermal_zone_bind(struct thermal_zone_device *thz,
+                               struct thermal_cooling_device *cdevice)
+{
+       int i, j, trip=0, trip_size, index;
+       struct tegra_cooling_device *tegra_cdev = cdevice->devdata;
+       struct tegra_thermal_device *device = thz->devdata;
+
+       for (i=0; therm->binds[i].tdev_id; i++) {
+               if(device->id == therm->binds[i].tdev_id) {
+                       trip_size = therm->binds[i].get_trip_size();
+                       index = tegra_cdev->id & 0xffff;
+
+                       if (therm->binds[i].cdev_id  == (tegra_cdev->id & 0xffff0000)) {
+                               for (j=0; j < trip_size; j++) {
+                                       thermal_zone_bind_cooling_device(
+                                                       thz,
+                                                       trip + index,
+                                                       cdevice);
+                               }
+                       }
+
+                       trip += trip_size;
+               }
+       }
+
+       return 0;
+}
+
+static int tegra_thermal_zone_unbind(struct thermal_zone_device *thz,
                                struct thermal_cooling_device *cdevice) {
-       /* Support only Thermal Throttling (1 trip) for now */
-       return thermal_zone_unbind_cooling_device(thermal, 0, cdevice);
+       int i, trip = 0;
+       struct tegra_cooling_device *tegra_cdev = cdevice->devdata;
+       struct tegra_thermal_device *device = thz->devdata;
+
+       for (i=0; therm->binds[i].tdev_id; i++) {
+               if(device->id == therm->binds[i].tdev_id) {
+                       if (tegra_cdev->id == therm->binds[i].cdev_id)
+                               thermal_zone_unbind_cooling_device(thz, trip, cdevice);
+                       trip += therm->binds[i].get_trip_size();
+               }
+       }
+
+       return 0;
 }
 
 static int tegra_thermal_zone_get_temp(struct thermal_zone_device *thz,
                                        unsigned long *temp)
 {
-       struct tegra_thermal *thermal = thz->devdata;
-       thermal->device->get_temp(thermal->device->data, temp);
+       struct tegra_thermal_device *device = thz->devdata;
+
+       if (!tegra_thermal_suspend)
+               device->get_temp(device->data, temp);
 
        return 0;
 }
 
 static int tegra_thermal_zone_get_trip_type(
-                       struct thermal_zone_device *thermal,
+                       struct thermal_zone_device *thz,
                        int trip,
                        enum thermal_trip_type *type) {
+       int i, trip_count = 0;
+       struct tegra_thermal_device *device = thz->devdata;
+
+       for (i=0; therm->binds[i].tdev_id; i++) {
+               if(device->id == therm->binds[i].tdev_id) {
+                       trip_count += therm->binds[i].get_trip_size();
+                       if (trip < trip_count) {
+                               *type = therm->binds[i].type;
+                               return 0;
+                       }
+               }
+       }
 
-       /* Support only Thermal Throttling (1 trip) for now */
-       if (trip != 0)
-               return -EINVAL;
-
-       *type = THERMAL_TRIP_PASSIVE;
-
-       return 0;
+       return -EINVAL;
 }
 
 static int tegra_thermal_zone_get_trip_temp(struct thermal_zone_device *thz,
                                        int trip,
                                        unsigned long *temp) {
-       struct tegra_thermal *thermal = thz->devdata;
-
-       /* Support only Thermal Throttling (1 trip) for now */
-       if (trip != 0)
-               return -EINVAL;
-
-       *temp = tj2dev(thermal->device, thermal->temp_throttle_tj);
+       int i, j, trip_size, trip_count = 0;
+       struct tegra_thermal_device *device = thz->devdata;
+
+       for (i=0; therm->binds[i].tdev_id; i++) {
+               if(device->id == therm->binds[i].tdev_id) {
+                       trip_size = therm->binds[i].get_trip_size();
+                       for (j=0; j < trip_size; j++) {
+                               if (trip == trip_count) {
+                                       *temp = therm->binds[i].get_trip_temp(
+                                                       &therm->binds[i], j);
+                                       return 0;
+                               }
+                               trip_count++;
+                       }
+               }
+       }
 
-       return 0;
+       return -EINVAL;
 }
 
 static struct thermal_zone_device_ops tegra_thermal_zone_ops = {
@@ -144,14 +194,30 @@ static struct thermal_zone_device_ops tegra_thermal_zone_ops = {
        .get_trip_type = tegra_thermal_zone_get_trip_type,
        .get_trip_temp = tegra_thermal_zone_get_trip_temp,
 };
-#endif
 
-/* Make sure this function remains stateless */
-void tegra_thermal_alert(void *data)
+static int tegra_thermal_pm_notify(struct notifier_block *nb,
+                               unsigned long event, void *data)
+{
+       switch (event) {
+       case PM_SUSPEND_PREPARE:
+               tegra_thermal_suspend = true;
+               break;
+       case PM_POST_SUSPEND:
+               tegra_thermal_suspend = false;
+               break;
+       }
+
+       return NOTIFY_OK;
+};
+
+static struct notifier_block tegra_thermal_nb = {
+       .notifier_call = tegra_thermal_pm_notify,
+};
+
+static void tegra_thermal_alert(void *data)
 {
-       struct tegra_thermal *thermal = data;
-       int err;
-       long temp_dev, temp_tj;
+       struct tegra_thermal_device *device = data;
+       long temp_tj;
        long lo_limit_throttle_tj, hi_limit_throttle_tj;
        long lo_limit_edp_tj = 0, hi_limit_edp_tj = 0;
        long temp_low_dev, temp_low_tj;
@@ -162,61 +228,46 @@ void tegra_thermal_alert(void *data)
        int i;
 #endif
 
-       if (thermal != &thermal_state)
-               BUG();
+       mutex_lock(&tegra_therm_mutex);
 
-       mutex_lock(&thermal_state.mutex);
-
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       if (thermal->thz) {
-               if (!thermal->thz->passive)
-                       thermal_zone_device_update(thermal->thz);
-       }
-#endif
-
-       err = thermal->device->get_temp(thermal->device->data, &temp_dev);
-       if (err) {
-               pr_err("%s: get temp fail(%d)", __func__, err);
-               goto done;
-       }
+       if (device->thz)
+               if ((!device->thz->passive) && (!tegra_thermal_suspend))
+                       thermal_zone_device_update(device->thz);
 
        /* Convert all temps to tj and then do all work/logic in terms of
           tj in order to avoid confusion */
-       temp_tj = dev2tj(thermal->device, temp_dev);
-       thermal->device->get_temp_low(thermal->device, &temp_low_dev);
-       temp_low_tj = dev2tj(thermal->device, temp_low_dev);
+       if (tegra_thermal_get_temp_unlocked(&temp_tj, true))
+               goto done;
+
+       device->get_temp_low(device, &temp_low_dev);
+       temp_low_tj = dev2tj(device, temp_low_dev);
 
        lo_limit_throttle_tj = temp_low_tj;
-       hi_limit_throttle_tj = thermal->temp_shutdown_tj;
+       hi_limit_throttle_tj = dev2tj(device, MAX_TEMP);
 
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       hi_limit_throttle_tj = thermal->temp_throttle_tj;
+       hi_limit_throttle_tj = dev2tj(device, therm->temp_throttle);
 
-       if (temp_tj > thermal->temp_throttle_tj) {
-               lo_limit_throttle_tj = thermal->temp_throttle_tj;
-               hi_limit_throttle_tj = thermal->temp_shutdown_tj;
+       if (temp_tj > dev2tj(device, therm->temp_throttle)) {
+               lo_limit_throttle_tj = dev2tj(device, therm->temp_throttle);
+               hi_limit_throttle_tj = dev2tj(device, MAX_TEMP);
        }
-#endif
 
 #ifdef CONFIG_TEGRA_EDP_LIMITS
+#define EDP_TEMP_TJ(_index) (z[_index].temperature * 1000 + therm->edp_offset)
        tegra_get_cpu_edp_limits(&z, &zones_sz);
-
-/* edp table based off of tdiode measurements */
-#define EDP_TEMP_TJ(_index)    edp2tj(thermal, z[_index].temperature * 1000)
-
        if (temp_tj < EDP_TEMP_TJ(0)) {
                lo_limit_edp_tj = temp_low_tj;
                hi_limit_edp_tj = EDP_TEMP_TJ(0);
        } else if (temp_tj >= EDP_TEMP_TJ(zones_sz-1)) {
                lo_limit_edp_tj = EDP_TEMP_TJ(zones_sz-1) -
-                                       thermal->hysteresis_edp;
-               hi_limit_edp_tj = thermal->temp_shutdown_tj;
+                                       therm->hysteresis_edp;
+               hi_limit_edp_tj = dev2tj(device, MAX_TEMP);
        } else {
                for (i = 0; (i + 1) < zones_sz; i++) {
                        if ((temp_tj >= EDP_TEMP_TJ(i)) &&
                                (temp_tj < EDP_TEMP_TJ(i+1))) {
                                lo_limit_edp_tj = EDP_TEMP_TJ(i) -
-                                                       thermal->hysteresis_edp;
+                                                       therm->hysteresis_edp;
                                hi_limit_edp_tj = EDP_TEMP_TJ(i+1);
                                break;
                        }
@@ -225,271 +276,295 @@ void tegra_thermal_alert(void *data)
 #undef EDP_TEMP_TJ
 #else
        lo_limit_edp_tj = temp_low_tj;
-       hi_limit_edp_tj = thermal->temp_shutdown_tj;
+       hi_limit_edp_tj = dev2tj(device, MAX_TEMP);
 #endif
 
        /* Get smallest window size */
        lo_limit_tj = max(lo_limit_throttle_tj, lo_limit_edp_tj);
        hi_limit_tj = min(hi_limit_throttle_tj, hi_limit_edp_tj);
 
-       thermal->device->set_limits(thermal->device->data,
-                                       tj2dev(thermal->device, lo_limit_tj),
-                                       tj2dev(thermal->device, hi_limit_tj));
-
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-       /* inform edp governor */
-       if (thermal->edp_thermal_zone_val != temp_tj)
-               tegra_edp_update_thermal_zone(tj2edp(thermal, temp_tj)/1000);
-
-       thermal->edp_thermal_zone_val = temp_tj;
-#endif
+       device->set_limits(device->data,
+                               tj2dev(device, lo_limit_tj),
+                               tj2dev(device, hi_limit_tj));
+}
 
 done:
-       mutex_unlock(&thermal_state.mutex);
+       mutex_unlock(&tegra_therm_mutex);
 }
 
-int tegra_thermal_set_device(struct tegra_thermal_device *device)
+#ifdef CONFIG_TEGRA_SKIN_THROTTLE
+static void tegra_skin_thermal_alert(void *data)
 {
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       struct thermal_zone_device *thz;
-#endif
-
-       /* only support one device */
-       if (thermal_state.device)
-               return -EINVAL;
-
-       thermal_state.device = device;
+       struct tegra_thermal_device *dev = data;
 
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       thz = thermal_zone_device_register(thermal_state.device->name,
-                                       1, /* trips */
-                                       &thermal_state,
-                                       &tegra_thermal_zone_ops,
-                                       thermal_state.tc1, /* dT/dt */
-                                       thermal_state.tc2, /* throttle */
-                                       thermal_state.passive_delay,
-                                       0); /* polling delay */
+       if (!dev->thz->passive)
+               thermal_zone_device_update(dev->thz);
+}
 
-       if (IS_ERR(thz)) {
-               thz = NULL;
-               return -ENODEV;
+static int tegra_skin_device_register(struct tegra_thermal_device *device)
+{
+       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;
+               }
        }
 
-       thermal_state.thz = thz;
-#endif
-       thermal_state.device->set_alert(thermal_state.device->data,
-                                       tegra_thermal_alert,
-                                       &thermal_state);
-
-       thermal_state.device->set_shutdown_temp(thermal_state.device->data,
-                               tj2dev(device, thermal_state.temp_shutdown_tj));
-
-       /* initialize limits */
-       tegra_thermal_alert(&thermal_state);
+       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);
+       }
 
        return 0;
 }
+#endif
 
-int __init tegra_thermal_init(struct tegra_thermal_data *data)
+static int passive_get_trip_temp(void *data, long trip)
 {
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       thermal_state.tc1 = data->tc1;
-       thermal_state.tc2 = data->tc2;
-       thermal_state.passive_delay = data->passive_delay;
-       thermal_state.temp_throttle_tj = data->temp_throttle +
-                                               data->temp_offset;
-#endif
-       mutex_init(&thermal_state.mutex);
-#ifdef CONFIG_TEGRA_EDP_LIMITS
-       thermal_state.edp_offset = data->edp_offset;
-       thermal_state.hysteresis_edp = data->hysteresis_edp;
-#endif
-       thermal_state.temp_shutdown_tj = data->temp_shutdown +
-                                               data->temp_offset;
+       struct tegra_thermal_bind *bind = data;
+       return bind->passive.trip_temp;
+}
 
-       return 0;
+static int passive_get_trip_size(void)
+{
+       return 1;
 }
 
-int tegra_thermal_exit(void)
+int tegra_thermal_device_register(struct tegra_thermal_device *device)
 {
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       if (thermal_state.thz)
-               thermal_zone_device_unregister(thermal_state.thz);
-#endif
+       struct tegra_thermal_device *dev;
+       struct thermal_zone_device *thz;
+       int i, t1 = 0, t2 = 0, pdelay = 0, trips=0;
 
-       return 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;
+               }
+       }
 
-#ifdef CONFIG_DEBUG_FS
+       for (i=0; therm->binds[i].tdev_id; i++) {
+               if(device->id == therm->binds[i].tdev_id) {
+                       switch(therm->binds[i].type) {
+                       case THERMAL_TRIP_PASSIVE:
+                               /* only one passive type allowed for now */
+                               if (pdelay)
+                                       return -EINVAL;
+
+                               /* These should be set only for ACTIVE types */
+                               if (therm->binds[i].get_trip_temp ||
+                                       therm->binds[i].get_trip_size)
+                                       return -EINVAL;
+
+                               t1 = therm->binds[i].passive.tc1;
+                               t2 = therm->binds[i].passive.tc2;
+                               pdelay = therm->binds[i].passive.passive_delay;
+
+                               therm->binds[i].get_trip_temp = passive_get_trip_temp;
+                               therm->binds[i].get_trip_size = passive_get_trip_size;
+                               break;
+                       }
 
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-static int tegra_thermal_throttle_temp_tj_set(void *data, u64 val)
-{
-       mutex_lock(&thermal_state.mutex);
-       thermal_state.temp_throttle_tj = val;
-       mutex_unlock(&thermal_state.mutex);
+                       trips += therm->binds[i].get_trip_size();
+               }
+       }
 
-       tegra_thermal_alert(&thermal_state);
+       if (trips) {
+               thz = thermal_zone_device_register(
+                                       device->name,
+                                       trips, /* trips */
+                                       device,
+                                       &tegra_thermal_zone_ops,
+                                       t1, /* dT/dt */
+                                       t2, /* throttle */
+                                       pdelay,
+                                       0); /* polling delay */
+               if (IS_ERR_OR_NULL(thz))
+                       return -ENODEV;
 
-       return 0;
-}
+               device->thz = thz;
+       }
 
-static int tegra_thermal_throttle_temp_tj_get(void *data, u64 *val)
-{
-       *val = (u64)thermal_state.temp_throttle_tj;
-       return 0;
-}
+       list_add(&device->node, &tegra_therm_list);
+       mutex_unlock(&tegra_therm_mutex);
 
-DEFINE_SIMPLE_ATTRIBUTE(throttle_temp_tj_fops,
-                       tegra_thermal_throttle_temp_tj_get,
-                       tegra_thermal_throttle_temp_tj_set,
-                       "%llu\n");
+#ifdef CONFIG_TEGRA_SKIN_THROTTLE
+       if (device->id == skin_therm->skin_device_id) {
+               if (create_thz)
+                       device->set_alert(device->data,
+                               tegra_skin_thermal_alert,
+                               device);
+               device->set_limits(device->data, 0, skin_therm->temp_throttle_skin);
+       }
 #endif
 
-static int tegra_thermal_shutdown_temp_tj_set(void *data, u64 val)
-{
-       thermal_state.temp_shutdown_tj = val;
+       if (device->id == therm->throttle_edp_device_id) {
+               device->set_alert(device->data, tegra_thermal_alert, device);
 
-       if (thermal_state.device)
-               thermal_state.device->set_shutdown_temp(
-                               thermal_state.device->data,
-                               tj2dev(thermal_state.device,
-                                       thermal_state.temp_shutdown_tj));
+               /* initialize limits */
+               tegra_thermal_alert(device);
+       }
 
-       tegra_thermal_alert(&thermal_state);
+#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;
 }
 
-static int tegra_thermal_shutdown_temp_tj_get(void *data, u64 *val)
+/* This needs to be inialized later hand */
+static int __init throttle_list_init(void)
 {
-       *val = (u64)thermal_state.temp_shutdown_tj;
+       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);
 
-DEFINE_SIMPLE_ATTRIBUTE(shutdown_temp_tj_fops,
-                       tegra_thermal_shutdown_temp_tj_get,
-                       tegra_thermal_shutdown_temp_tj_set,
-                       "%llu\n");
-
-
-static int tegra_thermal_temp_tj_get(void *data, u64 *val)
+int __init tegra_thermal_init(struct tegra_thermal_data *data,
+                               struct tegra_skin_data *skin_data,
+                               struct balanced_throttle *tlist,
+                               int tlist_size)
 {
-       long temp_tj, temp_dev;
-
-       if (thermal_state.device) {
-               thermal_state.device->get_temp(thermal_state.device->data,
-                                               &temp_dev);
+       therm = data;
+       skin_therm = skin_data;
+#ifdef CONFIG_DEBUG_FS
+       thermal_debugfs_root = debugfs_create_dir("tegra_thermal", 0);
+#endif
 
-               /* Convert all temps to tj and then do all work/logic in
-                  terms of tj in order to avoid confusion */
-               temp_tj = dev2tj(thermal_state.device, temp_dev);
-       } else {
-               temp_tj = -1;
+#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
 
-       *val = (u64)temp_tj;
-
-       return 0;
-}
+       throttle_list = tlist;
+       throttle_list_size = tlist_size;
 
-DEFINE_SIMPLE_ATTRIBUTE(temp_tj_fops,
-                       tegra_thermal_temp_tj_get,
-                       NULL,
-                       "%llu\n");
+       register_pm_notifier(&tegra_thermal_nb);
 
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-static int tegra_thermal_tc1_set(void *data, u64 val)
-{
-       thermal_state.thz->tc1 = val;
        return 0;
 }
 
-static int tegra_thermal_tc1_get(void *data, u64 *val)
+int tegra_thermal_exit(void)
 {
-       *val = (u64)thermal_state.thz->tc1;
-       return 0;
-}
-
-DEFINE_SIMPLE_ATTRIBUTE(tc1_fops,
-                       tegra_thermal_tc1_get,
-                       tegra_thermal_tc1_set,
-                       "%llu\n");
+       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);
 
-static int tegra_thermal_tc2_set(void *data, u64 val)
-{
-       thermal_state.thz->tc2 = val;
        return 0;
 }
 
-static int tegra_thermal_tc2_get(void *data, u64 *val)
+#ifdef CONFIG_DEBUG_FS
+static int tegra_thermal_temp_tj_get(void *data, u64 *val)
 {
-       *val = (u64)thermal_state.thz->tc2;
-       return 0;
-}
+       long temp_tj;
 
-DEFINE_SIMPLE_ATTRIBUTE(tc2_fops,
-                       tegra_thermal_tc2_get,
-                       tegra_thermal_tc2_set,
-                       "%llu\n");
+       mutex_lock(&tegra_therm_mutex);
+       if (tegra_thermal_get_temp_unlocked(&temp_tj, false))
+               temp_tj = -1;
+       mutex_unlock(&tegra_therm_mutex);
 
-static int tegra_thermal_passive_delay_set(void *data, u64 val)
-{
-       thermal_state.thz->passive_delay = val;
-       return 0;
-}
+       *val = (u64)temp_tj;
 
-static int tegra_thermal_passive_delay_get(void *data, u64 *val)
-{
-       *val = (u64)thermal_state.thz->passive_delay;
        return 0;
 }
 
-DEFINE_SIMPLE_ATTRIBUTE(passive_delay_fops,
-                       tegra_thermal_passive_delay_get,
-                       tegra_thermal_passive_delay_set,
+DEFINE_SIMPLE_ATTRIBUTE(temp_tj_fops,
+                       tegra_thermal_temp_tj_get,
+                       NULL,
                        "%llu\n");
-#endif
-
-
-static struct dentry *thermal_debugfs_root;
 
-static int __init tegra_thermal_debug_init(void)
+static int __init temp_tj_debug_init(void)
 {
-       thermal_debugfs_root = debugfs_create_dir("tegra_thermal", 0);
-
-       if (!debugfs_create_file("shutdown_temp_tj", 0644, thermal_debugfs_root,
-                                NULL, &shutdown_temp_tj_fops))
-               goto err_out;
-
-       if (!debugfs_create_file("temp_tj", 0644, thermal_debugfs_root,
-                                NULL, &temp_tj_fops))
-               goto err_out;
-
-#ifdef CONFIG_TEGRA_THERMAL_THROTTLE
-       if (!debugfs_create_file("throttle_temp_tj", 0644, thermal_debugfs_root,
-                                NULL, &throttle_temp_tj_fops))
-               goto err_out;
-
-       if (!debugfs_create_file("tc1", 0644, thermal_debugfs_root,
-                                NULL, &tc1_fops))
-               goto err_out;
-
-       if (!debugfs_create_file("tc2", 0644, thermal_debugfs_root,
-                                NULL, &tc2_fops))
-               goto err_out;
-
-       if (!debugfs_create_file("passive_delay", 0644, thermal_debugfs_root,
-                                NULL, &passive_delay_fops))
-               goto err_out;
-#endif
-
+       debugfs_create_file("temp_tj", 0644, thermal_debugfs_root,
+               NULL, &temp_tj_fops);
        return 0;
-
-err_out:
-       debugfs_remove_recursive(thermal_debugfs_root);
-       return -ENOMEM;
 }
-
-late_initcall(tegra_thermal_debug_init);
+late_initcall(temp_tj_debug_init);
+
+#define THERM_DEBUGFS(_name) \
+       static int tegra_thermal_##_name##_set(void *data, u64 val) \
+       { \
+               struct tegra_thermal_device *dev; \
+               mutex_lock(&tegra_therm_mutex); \
+               list_for_each_entry(dev, &tegra_therm_list, node) \
+                       if (dev->id == therm->throttle_edp_device_id) \
+                               break; \
+               if (dev) \
+                       dev->thz->_name = val; \
+               mutex_unlock(&tegra_therm_mutex); \
+               return 0; \
+       } \
+       static int tegra_thermal_##_name##_get(void *data, u64 *val) \
+       { \
+               struct tegra_thermal_device *dev; \
+               mutex_lock(&tegra_therm_mutex); \
+               list_for_each_entry(dev, &tegra_therm_list, node) \
+                       if (dev->id == therm->throttle_edp_device_id) \
+                               break; \
+               if (dev) \
+                       *val = (u64)dev->thz->_name; \
+               mutex_unlock(&tegra_therm_mutex); \
+               return 0; \
+       } \
+       DEFINE_SIMPLE_ATTRIBUTE(_name##_fops, \
+                       tegra_thermal_##_name##_get, \
+                       tegra_thermal_##_name##_set, \
+                       "%llu\n"); \
+       static int __init _name##_debug_init(void) \
+       { \
+               debugfs_create_file(#_name, 0644, thermal_debugfs_root, \
+                       NULL, &_name##_fops); \
+               return 0; \
+       } \
+       late_initcall(_name##_debug_init);
+
+
+THERM_DEBUGFS(tc1);
+THERM_DEBUGFS(tc2);
+THERM_DEBUGFS(passive_delay);
 #endif