linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH RESEND v2] hwmon: ntc_thermistor: Add ntc thermistor to thermal subsystem as a sensor.
@ 2014-09-17  2:41 Jonghwa Lee
  2014-09-17  4:09 ` Guenter Roeck
  0 siblings, 1 reply; 3+ messages in thread
From: Jonghwa Lee @ 2014-09-17  2:41 UTC (permalink / raw)
  To: linux-kernel, lm-sensors; +Cc: jdelvare, linux, Jonghwa Lee

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>
---
Updates in v2
 - Remove NULL pointer checking already done by thermal_zone_of_sensor_unregister().

 .../devicetree/bindings/hwmon/ntc_thermistor.txt   |    3 +++
 drivers/hwmon/ntc_thermistor.c                     |   25 ++++++++++++++++++++
 2 files changed, 28 insertions(+)

diff --git a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
index 2391e5c..fcca8e7 100644
--- a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
+++ b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
@@ -25,6 +25,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/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
index bd41072..4ff89b2 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;
@@ -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)
 {
@@ -562,6 +578,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_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);
@@ -578,6 +601,8 @@ 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;
 }
 
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND v2] hwmon: ntc_thermistor: Add ntc thermistor to thermal subsystem as a sensor.
  2014-09-17  2:41 [PATCH RESEND v2] hwmon: ntc_thermistor: Add ntc thermistor to thermal subsystem as a sensor Jonghwa Lee
@ 2014-09-17  4:09 ` Guenter Roeck
  2014-09-17  4:15   ` jonghwa3.lee
  0 siblings, 1 reply; 3+ messages in thread
From: Guenter Roeck @ 2014-09-17  4:09 UTC (permalink / raw)
  To: Jonghwa Lee, linux-kernel, lm-sensors; +Cc: jdelvare

On 09/16/2014 07:41 PM, Jonghwa Lee wrote:
> 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>
> ---

As has been pointed out, with

CONFIG_OF=y
CONFIG_THERMAL=m
CONFIG_SENSORS_NTC_THERMISTOR=y

this patch results in

drivers/built-in.o: In function `ntc_thermistor_probe':
ntc_thermistor.c:(.text+0xfff52): undefined reference to `thermal_zone_of_sensor_register'
drivers/built-in.o: In function `ntc_thermistor_remove':
ntc_thermistor.c:(.text+0xfffc5): undefined reference to `thermal_zone_of_sensor_unregister'
make: *** [vmlinux] Error 1

Resending the patch without changes does not fix the problem.
Please submit a fixed version.

Thanks,
Guenter


> Updates in v2
>   - Remove NULL pointer checking already done by thermal_zone_of_sensor_unregister().
>
>   .../devicetree/bindings/hwmon/ntc_thermistor.txt   |    3 +++
>   drivers/hwmon/ntc_thermistor.c                     |   25 ++++++++++++++++++++
>   2 files changed, 28 insertions(+)
>
> diff --git a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
> index 2391e5c..fcca8e7 100644
> --- a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
> +++ b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
> @@ -25,6 +25,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/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
> index bd41072..4ff89b2 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;
> @@ -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)
>   {
> @@ -562,6 +578,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_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);
> @@ -578,6 +601,8 @@ 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;
>   }
>
>


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH RESEND v2] hwmon: ntc_thermistor: Add ntc thermistor to thermal subsystem as a sensor.
  2014-09-17  4:09 ` Guenter Roeck
@ 2014-09-17  4:15   ` jonghwa3.lee
  0 siblings, 0 replies; 3+ messages in thread
From: jonghwa3.lee @ 2014-09-17  4:15 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-kernel, lm-sensors, jdelvare

On 2014년 09월 17일 13:09, Guenter Roeck wrote:

> On 09/16/2014 07:41 PM, Jonghwa Lee wrote:
>> 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>
>> ---
> 
> As has been pointed out, with
> 
> CONFIG_OF=y
> CONFIG_THERMAL=m
> CONFIG_SENSORS_NTC_THERMISTOR=y
> 
> this patch results in
> 
> drivers/built-in.o: In function `ntc_thermistor_probe':
> ntc_thermistor.c:(.text+0xfff52): undefined reference to
> `thermal_zone_of_sensor_register'
> drivers/built-in.o: In function `ntc_thermistor_remove':
> ntc_thermistor.c:(.text+0xfffc5): undefined reference to
> `thermal_zone_of_sensor_unregister'
> make: *** [vmlinux] Error 1
> 
> Resending the patch without changes does not fix the problem.
> Please submit a fixed version.
> 


Sorry, I think I lost the thread, I didn't notice you commented before.
Anyway I'll fix it resend it.

Thanks,
Jonghwa

> Thanks,
> Guenter
> 
> 
>> Updates in v2
>>   - Remove NULL pointer checking already done by
>> thermal_zone_of_sensor_unregister().
>>
>>   .../devicetree/bindings/hwmon/ntc_thermistor.txt   |    3 +++
>>   drivers/hwmon/ntc_thermistor.c                     |   25 ++++++++++++++++++++
>>   2 files changed, 28 insertions(+)
>>
>> diff --git a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
>> b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
>> index 2391e5c..fcca8e7 100644
>> --- a/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
>> +++ b/Documentation/devicetree/bindings/hwmon/ntc_thermistor.txt
>> @@ -25,6 +25,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/ntc_thermistor.c b/drivers/hwmon/ntc_thermistor.c
>> index bd41072..4ff89b2 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;
>> @@ -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)
>>   {
>> @@ -562,6 +578,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_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);
>> @@ -578,6 +601,8 @@ 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;
>>   }
>>
>>
> 
> 



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2014-09-17  4:15 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-09-17  2:41 [PATCH RESEND v2] hwmon: ntc_thermistor: Add ntc thermistor to thermal subsystem as a sensor Jonghwa Lee
2014-09-17  4:09 ` Guenter Roeck
2014-09-17  4:15   ` jonghwa3.lee

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).