aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJonghwa Lee <jonghwa3.lee@samsung.com>2014-09-17 01:54:37 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-09-22 14:14:52 -0400
commitc08860ffe5c0e986e208e8217dae8191c0b40b24 (patch)
treed70f8173ba1e25887539527015acce344bbc0085 /drivers/hwmon
parent9b993e36611bd8029b81637ad53a262fa7882af1 (diff)
hwmon: (ntc_thermistor) Add ntc thermistor to thermal subsystem as a sensor.
To get more comprehensive and integrated thermal management, it adds ntc thermistor to thermal framework as a thermal sensor. It's governed thermal susbsystem only if it is described in DT node. Otherwise, it just notifies temperature to userspace via sysfs as it used to be. Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/Kconfig1
-rw-r--r--drivers/hwmon/ntc_thermistor.c25
2 files changed, 26 insertions, 0 deletions
diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig
index 4289a4fa1a03..f790b41283d0 100644
--- a/drivers/hwmon/Kconfig
+++ b/drivers/hwmon/Kconfig
@@ -1077,6 +1077,7 @@ config SENSORS_PC87427
1077config SENSORS_NTC_THERMISTOR 1077config SENSORS_NTC_THERMISTOR
1078 tristate "NTC thermistor support from Murata" 1078 tristate "NTC thermistor support from Murata"
1079 depends on !OF || IIO=n || IIO 1079 depends on !OF || IIO=n || IIO
1080 depends on THERMAL || !THERMAL_OF
1080 help 1081 help
1081 This driver supports NTC thermistors sensor reading and its 1082 This driver supports NTC thermistors sensor reading and its
1082 interpretation. The driver can also monitor the temperature and 1083 interpretation. The driver can also monitor the temperature and
diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index bd410722cd4b..4ff89b2482e4 100644
--- a/drivers/hwmon/ntc_thermistor.c
+++ b/drivers/hwmon/ntc_thermistor.c
@@ -38,6 +38,7 @@
38 38
39#include <linux/hwmon.h> 39#include <linux/hwmon.h>
40#include <linux/hwmon-sysfs.h> 40#include <linux/hwmon-sysfs.h>
41#include <linux/thermal.h>
41 42
42struct ntc_compensation { 43struct ntc_compensation {
43 int temp_c; 44 int temp_c;
@@ -182,6 +183,7 @@ struct ntc_data {
182 struct device *dev; 183 struct device *dev;
183 int n_comp; 184 int n_comp;
184 char name[PLATFORM_NAME_SIZE]; 185 char name[PLATFORM_NAME_SIZE];
186 struct thermal_zone_device *tz;
185}; 187};
186 188
187#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO) 189#if defined(CONFIG_OF) && IS_ENABLED(CONFIG_IIO)
@@ -428,6 +430,20 @@ static int ntc_thermistor_get_ohm(struct ntc_data *data)
428 return -EINVAL; 430 return -EINVAL;
429} 431}
430 432
433static int ntc_read_temp(void *dev, long *temp)
434{
435 struct ntc_data *data = dev_get_drvdata(dev);
436 int ohm;
437
438 ohm = ntc_thermistor_get_ohm(data);
439 if (ohm < 0)
440 return ohm;
441
442 *temp = get_temp_mc(data, ohm);
443
444 return 0;
445}
446
431static ssize_t ntc_show_name(struct device *dev, 447static ssize_t ntc_show_name(struct device *dev,
432 struct device_attribute *attr, char *buf) 448 struct device_attribute *attr, char *buf)
433{ 449{
@@ -562,6 +578,13 @@ static int ntc_thermistor_probe(struct platform_device *pdev)
562 dev_info(&pdev->dev, "Thermistor type: %s successfully probed.\n", 578 dev_info(&pdev->dev, "Thermistor type: %s successfully probed.\n",
563 pdev_id->name); 579 pdev_id->name);
564 580
581 data->tz = thermal_zone_of_sensor_register(data->dev, 0, data->dev,
582 ntc_read_temp, NULL);
583 if (IS_ERR(data->tz)) {
584 dev_dbg(&pdev->dev, "Failed to register to thermal fw.\n");
585 data->tz = NULL;
586 }
587
565 return 0; 588 return 0;
566err_after_sysfs: 589err_after_sysfs:
567 sysfs_remove_group(&data->dev->kobj, &ntc_attr_group); 590 sysfs_remove_group(&data->dev->kobj, &ntc_attr_group);
@@ -578,6 +601,8 @@ static int ntc_thermistor_remove(struct platform_device *pdev)
578 sysfs_remove_group(&data->dev->kobj, &ntc_attr_group); 601 sysfs_remove_group(&data->dev->kobj, &ntc_attr_group);
579 ntc_iio_channel_release(pdata); 602 ntc_iio_channel_release(pdata);
580 603
604 thermal_zone_of_sensor_unregister(data->dev, data->tz);
605
581 return 0; 606 return 0;
582} 607}
583 608