diff options
author | Jonghwa Lee <jonghwa3.lee@samsung.com> | 2014-08-20 09:28:13 +0900 |
---|---|---|
committer | Chanho Park <chanho61.park@samsung.com> | 2014-11-18 12:00:53 +0900 |
commit | 44bc8b47ca4b4763b48f74f35e0fcfaea6a8dfe9 (patch) | |
tree | ae7b9e0c882395185c23dc369aeff5950755b94b | |
parent | 7fa9b68a0ae602287dbbe161f89b4adf23d5a53d (diff) | |
download | linux-3.10-44bc8b47ca4b4763b48f74f35e0fcfaea6a8dfe9.tar.gz linux-3.10-44bc8b47ca4b4763b48f74f35e0fcfaea6a8dfe9.tar.bz2 linux-3.10-44bc8b47ca4b4763b48f74f35e0fcfaea6a8dfe9.zip |
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.
Change-Id: Ie5b8948ca0cb567854905e0e9ea903ff7cdc1f4c
Signed-off-by: Jonghwa Lee <jonghwa3.lee@samsung.com>
-rw-r--r-- | Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt | 3 | ||||
-rw-r--r-- | drivers/hwmon/Kconfig | 1 | ||||
-rw-r--r-- | drivers/hwmon/ntc_thermistor.c | 25 |
3 files changed, 29 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt index c6f66674f19..bdae6df488e 100644 --- a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt +++ b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt @@ -16,6 +16,9 @@ Requires node properties: - "io-channels" Channel node of ADC to be used for conversion. +Optional node properties: +- "#thermal-sensor-cells" Used to expose itself to thermal fw. + Read more about iio bindings at Documentation/devicetree/bindings/iio/iio-bindings.txt diff --git a/drivers/hwmon/Kconfig b/drivers/hwmon/Kconfig index a8b0c7c62e3..5399c3252b9 100644 --- a/drivers/hwmon/Kconfig +++ b/drivers/hwmon/Kconfig @@ -945,6 +945,7 @@ config SENSORS_NCT6775 config SENSORS_NTC_THERMISTOR tristate "NTC thermistor support" depends on !OF || IIO=n || IIO + depends on THERMAL || !THERMAL_OF help This driver supports NTC thermistors sensor reading and its interpretation. The driver can also monitor the temperature and diff --git a/drivers/hwmon/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c index c64d3d497c5..1eccf1069f5 100644 --- a/drivers/hwmon/ntc_thermistor.c +++ b/drivers/hwmon/ntc_thermistor.c @@ -38,6 +38,7 @@ #include <linux/hwmon.h> #include <linux/hwmon-sysfs.h> +#include <linux/thermal.h> struct ntc_compensation { int temp_c; @@ -140,6 +141,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) @@ -372,6 +374,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) { @@ -502,6 +518,13 @@ static int ntc_thermistor_probe(struct platform_device *pdev) dev_info(&pdev->dev, "Thermistor type: %s successfully probed.\n", pdev->name); + data->tz = thermal_zone_of_sensor_register(data->dev, 0, data->dev, + ntc_read_temp, NULL); + 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); @@ -519,6 +542,8 @@ static int ntc_thermistor_remove(struct platform_device *pdev) ntc_iio_channel_release(pdata); platform_set_drvdata(pdev, NULL); + thermal_zone_of_sensor_unregister(data->dev, data->tz); + return 0; } |