Merge tag 'scsi-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb...
[pandora-kernel.git] / drivers / hwmon / ntc_thermistor.c
index bd41072..112e4d4 100644 (file)
@@ -38,6 +38,7 @@
 
 #include <linux/hwmon.h>
 #include <linux/hwmon-sysfs.h>
+#include <linux/thermal.h>
 
 struct ntc_compensation {
        int             temp_c;
@@ -182,6 +183,7 @@ struct ntc_data {
        struct device *dev;
        int n_comp;
        char name[PLATFORM_NAME_SIZE];
+       struct thermal_zone_device *tz;
 };
 
 #if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
@@ -428,6 +430,20 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
        return -EINVAL;
 }
 
+static int ntc_read_temp(void *dev, long *temp)
+{
+       struct ntc_data *data = dev_get_drvdata(dev);
+       int ohm;
+
+       ohm = ntc_thermistor_get_ohm(data);
+       if (ohm < 0)
+               return ohm;
+
+       *temp = get_temp_mc(data, ohm);
+
+       return 0;
+}
+
 static ssize_t ntc_show_name(struct device *dev,
                struct device_attribute *attr, char *buf)
 {
@@ -470,6 +486,10 @@ static const struct attribute_group ntc_attr_group = {
        .attrs = ntc_attributes,
 };
 
+static const struct thermal_zone_of_device_ops ntc_of_thermal_ops = {
+       .get_temp = ntc_read_temp,
+};
+
 static int ntc_thermistor_probe(struct platform_device *pdev)
 {
        const struct of_device_id *of_id =
@@ -562,6 +582,13 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
        dev_info(&pdev->dev, "Thermistor type: %s successfully probed.\n",
                                                                pdev_id->name);
 
+       data->tz = thermal_zone_of_sensor_register(data->dev, 0, data->dev,
+                                                  &ntc_of_thermal_ops);
+       if (IS_ERR(data->tz)) {
+               dev_dbg(&pdev->dev, "Failed to register to thermal fw.\n");
+               data->tz = NULL;
+       }
+
        return 0;
 err_after_sysfs:
        sysfs_remove_group(&data->dev->kobj, &ntc_attr_group);
@@ -578,13 +605,14 @@ static int ntc_thermistor_remove(struct platform_device *pdev)
        sysfs_remove_group(&data->dev->kobj, &ntc_attr_group);
        ntc_iio_channel_release(pdata);
 
+       thermal_zone_of_sensor_unregister(data->dev, data->tz);
+
        return 0;
 }
 
 static struct platform_driver ntc_thermistor_driver = {
        .driver = {
                .name = "ntc-thermistor",
-               .owner = THIS_MODULE,
                .of_match_table = of_match_ptr(ntc_match),
        },
        .probe = ntc_thermistor_probe,