drivers: nct: shutdown and thermal register
Joshua Primero [Tue, 28 Aug 2012 21:38:51 +0000 (14:38 -0700)]
Shutdown temperature in platform data now used. Also,
cleaned up some unused platform data parameters.

Also, have nct driver register with thermal framework
itself.

Change-Id: Ic97aa3968b945033c83d2809b63c571b05bb89eb
Signed-off-by: Joshua Primero <jprimero@nvidia.com>
Reviewed-on: http://git-master/r/132879
(cherry picked from commit e361239aab1a9c393a4a6ccfb8ac78f066adbffb)
Signed-off-by: Gaurav Batra <gbatra@nvidia.com>
Reviewed-on: http://git-master/r/130285
Reviewed-by: Automatic_Commit_Validation_User
Reviewed-by: Diwakar Tundlam <dtundlam@nvidia.com>
Tested-by: Diwakar Tundlam <dtundlam@nvidia.com>

drivers/misc/nct1008.c
include/linux/nct1008.h

index 5e35413..56b437d 100644 (file)
@@ -30,6 +30,7 @@
 #include <linux/device.h>
 #include <linux/nct1008.h>
 #include <linux/delay.h>
+#include <linux/thermal.h>
 #include <linux/regulator/consumer.h>
 
 /* Register Addresses */
@@ -598,13 +599,15 @@ static int __devinit nct1008_configure_sensor(struct nct1008_data* data)
                goto error;
 
        /* External temperature h/w shutdown limit */
-       value = temperature_to_value(pdata->ext_range, NCT1008_MAX_TEMP);
+       value = temperature_to_value(pdata->ext_range,
+                                       pdata->shutdown_ext_limit);
        err = i2c_smbus_write_byte_data(client, EXT_THERM_LIMIT_WR, value);
        if (err)
                goto error;
 
        /* Local temperature h/w shutdown limit */
-       value = temperature_to_value(pdata->ext_range, NCT1008_MAX_TEMP);
+       value = temperature_to_value(pdata->ext_range,
+                                       pdata->shutdown_local_limit);
        err = i2c_smbus_write_byte_data(client, LOCAL_THERM_LIMIT_WR, value);
        if (err)
                goto error;
@@ -724,12 +727,6 @@ int nct1008_thermal_get_temps(struct nct1008_data *data, long *etemp, long *item
        return nct1008_get_temp(&data->client->dev, etemp, itemp);
 }
 
-int nct1008_thermal_get_temp_low(struct nct1008_data *data, long *temp)
-{
-       *temp = 0;
-       return 0;
-}
-
 int nct1008_thermal_set_limits(struct nct1008_data *data,
                                long lo_limit_milli,
                                long hi_limit_milli)
@@ -778,32 +775,48 @@ int nct1008_thermal_set_alert(struct nct1008_data *data,
        return 0;
 }
 
-int nct1008_thermal_set_shutdown_temp(struct nct1008_data *data,
-                                       long shutdown_temp_milli)
+#ifdef CONFIG_THERMAL
+static int nct1008_zone_get_temp(struct thermal_zone_device *thz,
+                                       unsigned long *temp)
 {
+       struct nct1008_data *data = thz->devdata;
        struct i2c_client *client = data->client;
        struct nct1008_platform_data *pdata = client->dev.platform_data;
-       int err;
+       s8 temp_local;
+       long temp_local_milli;
        u8 value;
-       long shutdown_temp;
 
-       shutdown_temp = MILLICELSIUS_TO_CELSIUS(shutdown_temp_milli);
+       /* Read Local Temp */
+       value = i2c_smbus_read_byte_data(client, LOCAL_TEMP_RD);
+       if (value < 0)
+               return -1;
+       temp_local = value_to_temperature(pdata->ext_range, value);
+       temp_local_milli = CELSIUS_TO_MILLICELSIUS(temp_local);
 
-       /* External temperature h/w shutdown limit */
-       value = temperature_to_value(pdata->ext_range, shutdown_temp);
-       err = i2c_smbus_write_byte_data(client, EXT_THERM_LIMIT_WR, value);
-       if (err)
-               return err;
+       *temp = temp_local_milli;
 
-       /* Local temperature h/w shutdown limit */
-       value = temperature_to_value(pdata->ext_range, shutdown_temp);
-       err = i2c_smbus_write_byte_data(client, LOCAL_THERM_LIMIT_WR, value);
-       if (err)
-               return err;
+       return 0;
+}
 
+static int nct1008_bind(struct thermal_zone_device *thz,
+                               struct thermal_cooling_device *cdev)
+{
        return 0;
 }
 
+static int nct1008_unbind(struct thermal_zone_device *thz,
+                               struct thermal_cooling_device *cdev)
+{
+       return 0;
+}
+
+static struct thermal_zone_device_ops nct_ops = {
+       .get_temp = nct1008_zone_get_temp,
+       .bind = nct1008_bind,
+       .unbind = nct1008_unbind,
+};
+#endif
+
 /*
  * Manufacturer(OnSemi) recommended sequence for
  * Extended Range mode is as follows
@@ -866,6 +879,17 @@ static int __devinit nct1008_probe(struct i2c_client *client,
        if (err < 0)
                err = 0; /* without debugfs we may continue */
 
+#ifdef CONFIG_THERMAL
+       thermal_zone_device_register("nct_int",
+                               0,
+                               data,
+                               &nct_ops,
+                               0,
+                               1,
+                               2000,
+                               0);
+#endif
+
        /* notify callback that probe is done */
        if (data->plat_data.probe_callback)
                data->plat_data.probe_callback(data);
index 69515a6..e64793f 100644 (file)
@@ -39,13 +39,8 @@ struct nct1008_platform_data {
        bool ext_range;
        u8 conv_rate;
        u8 offset;
-       u8 hysteresis;
        s8 shutdown_ext_limit;
        s8 shutdown_local_limit;
-       s8 throttling_ext_limit;
-       s8 thermal_zones[MAX_ZONES];
-       u8 thermal_zones_sz;
-       void (*alarm_fn)(bool raised);
        void (*probe_callback)(struct nct1008_data *);
 };
 
@@ -57,10 +52,7 @@ struct nct1008_data {
        struct mutex mutex;
        struct dentry *dent;
        u8 config;
-       s8 *limits;
-       u8 limits_sz;
        enum nct1008_chip chip;
-       void (*alarm_fn)(bool raised);
        struct regulator *nct_reg;
        long current_lo_limit;
        long current_hi_limit;
@@ -74,15 +66,12 @@ struct nct1008_data {
 int nct1008_thermal_get_temp(struct nct1008_data *data, long *temp);
 int nct1008_thermal_get_temps(struct nct1008_data *data, long *etemp,
                                long *itemp);
-int nct1008_thermal_get_temp_low(struct nct1008_data *data, long *temp);
 int nct1008_thermal_set_limits(struct nct1008_data *data,
                                long lo_limit_milli,
                                long hi_limit_milli);
 int nct1008_thermal_set_alert(struct nct1008_data *data,
                                void (*alert_func)(void *),
                                void *alert_data);
-int nct1008_thermal_set_shutdown_temp(struct nct1008_data *data,
-                                       long shutdown_temp);
 #else
 static inline int nct1008_thermal_get_temp(struct nct1008_data *data,
                                                long *temp)
@@ -90,9 +79,6 @@ static inline int nct1008_thermal_get_temp(struct nct1008_data *data,
 static inline int nct1008_thermal_get_temps(struct nct1008_data *data,
                                                long *etemp, long *itemp)
 { return -EINVAL; }
-static inline int nct1008_thermal_get_temp_low(struct nct1008_data *data,
-                                               long *temp)
-{ return -EINVAL; }
 static inline int nct1008_thermal_set_limits(struct nct1008_data *data,
                                long lo_limit_milli,
                                long hi_limit_milli)
@@ -101,9 +87,6 @@ static inline int nct1008_thermal_set_alert(struct nct1008_data *data,
                                void (*alert_func)(void *),
                                void *alert_data)
 { return -EINVAL; }
-static inline int nct1008_thermal_set_shutdown_temp(struct nct1008_data *data,
-                                       long shutdown_temp)
-{ return -EINVAL; }
 #endif
 
 #endif /* _LINUX_NCT1008_H */