* [PATCH v5 0/1] thermal: thermal-generic-adc: add temp sensor function
@ 2025-04-30 5:58 Svyatoslav Ryhel
2025-04-30 5:58 ` [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel Svyatoslav Ryhel
0 siblings, 1 reply; 5+ messages in thread
From: Svyatoslav Ryhel @ 2025-04-30 5:58 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Jonathan Cameron, Svyatoslav Ryhel
Cc: linux-pm, devicetree, linux-kernel
To avoid duplicating sensor functionality and conversion tables, this
design allows converting an ADC IIO channel's output directly into a
temperature IIO channel. This is particularly useful for devices where
hwmon isn't suitable or where temperature data must be accessible through
IIO.
One such device is, for example, the MAX17040 fuel gauge.
---
Changes on switching from v4 to v5:
- switched back to IIO_CHAN_INFO_PROCESSED
- dropped schema commit
- applied Jonathan Cameron code improvement suggestions
Changes on switching from v3 to v4:
- switch to use of RAW and SCALED channels to provide more accurate data
Changes on switching from v2 to v3:
- rephrased commit headers
Changes on switching from v1 to v2:
- documented #iio-channel-cells property
- switched to IIO_CHAN_INFO_PROCESSED
---
Svyatoslav Ryhel (1):
thermal: thermal-generic-adc: add temperature sensor channel
drivers/thermal/thermal-generic-adc.c | 55 ++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
--
2.48.1
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel
2025-04-30 5:58 [PATCH v5 0/1] thermal: thermal-generic-adc: add temp sensor function Svyatoslav Ryhel
@ 2025-04-30 5:58 ` Svyatoslav Ryhel
2025-05-02 9:19 ` Jonathan Cameron
2025-05-05 8:56 ` Daniel Lezcano
0 siblings, 2 replies; 5+ messages in thread
From: Svyatoslav Ryhel @ 2025-04-30 5:58 UTC (permalink / raw)
To: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
Jonathan Cameron, Svyatoslav Ryhel
Cc: linux-pm, devicetree, linux-kernel
To avoid duplicating sensor functionality and conversion tables, this
design allows converting an ADC IIO channel's output directly into a
temperature IIO channel. This is particularly useful for devices where
hwmon isn't suitable or where temperature data must be accessible through
IIO.
One such device is, for example, the MAX17040 fuel gauge.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/thermal/thermal-generic-adc.c | 55 ++++++++++++++++++++++++++-
1 file changed, 54 insertions(+), 1 deletion(-)
diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
index ee3d0aa31406..7c844589b153 100644
--- a/drivers/thermal/thermal-generic-adc.c
+++ b/drivers/thermal/thermal-generic-adc.c
@@ -7,6 +7,7 @@
* Author: Laxman Dewangan <ldewangan@nvidia.com>
*/
#include <linux/iio/consumer.h>
+#include <linux/iio/iio.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/platform_device.h>
@@ -73,6 +74,58 @@ static const struct thermal_zone_device_ops gadc_thermal_ops = {
.get_temp = gadc_thermal_get_temp,
};
+static const struct iio_chan_spec gadc_thermal_iio_channels[] = {
+ {
+ .type = IIO_TEMP,
+ .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
+ }
+};
+
+static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
+ struct iio_chan_spec const *chan,
+ int *val, int *val2, long mask)
+{
+ struct gadc_thermal_info *gtinfo = iio_priv(indio_dev);
+ int ret;
+
+ switch (mask) {
+ case IIO_CHAN_INFO_PROCESSED:
+ ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
+ if (ret)
+ return ret;
+
+ return IIO_VAL_INT;
+
+ default:
+ return -EINVAL;
+ }
+}
+
+static const struct iio_info gadc_thermal_iio_info = {
+ .read_raw = gadc_thermal_read_raw,
+};
+
+static int gadc_iio_register(struct device *dev, struct gadc_thermal_info *gti)
+{
+ struct gadc_thermal_info *gtinfo;
+ struct iio_dev *indio_dev;
+
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*gtinfo));
+ if (!indio_dev)
+ return -ENOMEM;
+
+ gtinfo = iio_priv(indio_dev);
+ memcpy(gtinfo, gti, sizeof(*gtinfo));
+
+ indio_dev->name = dev_name(dev);
+ indio_dev->info = &gadc_thermal_iio_info;
+ indio_dev->modes = INDIO_DIRECT_MODE;
+ indio_dev->channels = gadc_thermal_iio_channels;
+ indio_dev->num_channels = ARRAY_SIZE(gadc_thermal_iio_channels);
+
+ return devm_iio_device_register(dev, indio_dev);
+}
+
static int gadc_thermal_read_linear_lookup_table(struct device *dev,
struct gadc_thermal_info *gti)
{
@@ -153,7 +206,7 @@ static int gadc_thermal_probe(struct platform_device *pdev)
devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
- return 0;
+ return gadc_iio_register(&pdev->dev, gti);
}
static const struct of_device_id of_adc_thermal_match[] = {
--
2.48.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel
2025-04-30 5:58 ` [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel Svyatoslav Ryhel
@ 2025-05-02 9:19 ` Jonathan Cameron
2025-05-05 8:56 ` Daniel Lezcano
1 sibling, 0 replies; 5+ messages in thread
From: Jonathan Cameron @ 2025-05-02 9:19 UTC (permalink / raw)
To: Svyatoslav Ryhel
Cc: Rafael J. Wysocki, Daniel Lezcano, Zhang Rui, Lukasz Luba,
linux-pm, devicetree, linux-kernel, linux-iio
On Wed, 30 Apr 2025 08:58:07 +0300
Svyatoslav Ryhel <clamor95@gmail.com> wrote:
> To avoid duplicating sensor functionality and conversion tables, this
> design allows converting an ADC IIO channel's output directly into a
> temperature IIO channel. This is particularly useful for devices where
> hwmon isn't suitable or where temperature data must be accessible through
> IIO.
>
> One such device is, for example, the MAX17040 fuel gauge.
>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
Looks good to me.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
+CC linux-iio for info and maybe some more eyes.
> ---
> drivers/thermal/thermal-generic-adc.c | 55 ++++++++++++++++++++++++++-
> 1 file changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
> index ee3d0aa31406..7c844589b153 100644
> --- a/drivers/thermal/thermal-generic-adc.c
> +++ b/drivers/thermal/thermal-generic-adc.c
> @@ -7,6 +7,7 @@
> * Author: Laxman Dewangan <ldewangan@nvidia.com>
> */
> #include <linux/iio/consumer.h>
> +#include <linux/iio/iio.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> @@ -73,6 +74,58 @@ static const struct thermal_zone_device_ops gadc_thermal_ops = {
> .get_temp = gadc_thermal_get_temp,
> };
>
> +static const struct iio_chan_spec gadc_thermal_iio_channels[] = {
> + {
> + .type = IIO_TEMP,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + }
> +};
> +
> +static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + struct gadc_thermal_info *gtinfo = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_PROCESSED:
> + ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> +
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info gadc_thermal_iio_info = {
> + .read_raw = gadc_thermal_read_raw,
> +};
> +
> +static int gadc_iio_register(struct device *dev, struct gadc_thermal_info *gti)
> +{
> + struct gadc_thermal_info *gtinfo;
> + struct iio_dev *indio_dev;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*gtinfo));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + gtinfo = iio_priv(indio_dev);
> + memcpy(gtinfo, gti, sizeof(*gtinfo));
> +
> + indio_dev->name = dev_name(dev);
> + indio_dev->info = &gadc_thermal_iio_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = gadc_thermal_iio_channels;
> + indio_dev->num_channels = ARRAY_SIZE(gadc_thermal_iio_channels);
> +
> + return devm_iio_device_register(dev, indio_dev);
> +}
> +
> static int gadc_thermal_read_linear_lookup_table(struct device *dev,
> struct gadc_thermal_info *gti)
> {
> @@ -153,7 +206,7 @@ static int gadc_thermal_probe(struct platform_device *pdev)
>
> devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
>
> - return 0;
> + return gadc_iio_register(&pdev->dev, gti);
> }
>
> static const struct of_device_id of_adc_thermal_match[] = {
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel
2025-04-30 5:58 ` [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel Svyatoslav Ryhel
2025-05-02 9:19 ` Jonathan Cameron
@ 2025-05-05 8:56 ` Daniel Lezcano
2025-08-24 9:15 ` Svyatoslav Ryhel
1 sibling, 1 reply; 5+ messages in thread
From: Daniel Lezcano @ 2025-05-05 8:56 UTC (permalink / raw)
To: Svyatoslav Ryhel
Cc: Rafael J. Wysocki, Zhang Rui, Lukasz Luba, Jonathan Cameron,
linux-pm, devicetree, linux-kernel
On Wed, Apr 30, 2025 at 08:58:07AM +0300, Svyatoslav Ryhel wrote:
> To avoid duplicating sensor functionality and conversion tables, this
> design allows converting an ADC IIO channel's output directly into a
> temperature IIO channel. This is particularly useful for devices where
> hwmon isn't suitable or where temperature data must be accessible through
> IIO.
>
> One such device is, for example, the MAX17040 fuel gauge.
>
> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> ---
> drivers/thermal/thermal-generic-adc.c | 55 ++++++++++++++++++++++++++-
> 1 file changed, 54 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
> index ee3d0aa31406..7c844589b153 100644
> --- a/drivers/thermal/thermal-generic-adc.c
> +++ b/drivers/thermal/thermal-generic-adc.c
> @@ -7,6 +7,7 @@
> * Author: Laxman Dewangan <ldewangan@nvidia.com>
> */
> #include <linux/iio/consumer.h>
> +#include <linux/iio/iio.h>
> #include <linux/kernel.h>
> #include <linux/module.h>
> #include <linux/platform_device.h>
> @@ -73,6 +74,58 @@ static const struct thermal_zone_device_ops gadc_thermal_ops = {
> .get_temp = gadc_thermal_get_temp,
> };
>
> +static const struct iio_chan_spec gadc_thermal_iio_channels[] = {
> + {
> + .type = IIO_TEMP,
> + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> + }
> +};
> +
> +static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
> + struct iio_chan_spec const *chan,
> + int *val, int *val2, long mask)
> +{
> + struct gadc_thermal_info *gtinfo = iio_priv(indio_dev);
> + int ret;
> +
> + switch (mask) {
> + case IIO_CHAN_INFO_PROCESSED:
> + ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
> + if (ret)
> + return ret;
> +
> + return IIO_VAL_INT;
> +
> + default:
> + return -EINVAL;
> + }
> +}
> +
> +static const struct iio_info gadc_thermal_iio_info = {
> + .read_raw = gadc_thermal_read_raw,
> +};
> +
> +static int gadc_iio_register(struct device *dev, struct gadc_thermal_info *gti)
> +{
> + struct gadc_thermal_info *gtinfo;
> + struct iio_dev *indio_dev;
> +
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*gtinfo));
> + if (!indio_dev)
> + return -ENOMEM;
> +
> + gtinfo = iio_priv(indio_dev);
> + memcpy(gtinfo, gti, sizeof(*gtinfo));
Why copy the structure ?
Copying the thermal zone device pointer should be enough, no ?
> + indio_dev->name = dev_name(dev);
> + indio_dev->info = &gadc_thermal_iio_info;
> + indio_dev->modes = INDIO_DIRECT_MODE;
> + indio_dev->channels = gadc_thermal_iio_channels;
> + indio_dev->num_channels = ARRAY_SIZE(gadc_thermal_iio_channels);
> +
> + return devm_iio_device_register(dev, indio_dev);
> +}
> +
> static int gadc_thermal_read_linear_lookup_table(struct device *dev,
> struct gadc_thermal_info *gti)
> {
> @@ -153,7 +206,7 @@ static int gadc_thermal_probe(struct platform_device *pdev)
>
> devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
>
> - return 0;
> + return gadc_iio_register(&pdev->dev, gti);
> }
>
> static const struct of_device_id of_adc_thermal_match[] = {
> --
> 2.48.1
>
--
<http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
<http://twitter.com/#!/linaroorg> Twitter |
<http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel
2025-05-05 8:56 ` Daniel Lezcano
@ 2025-08-24 9:15 ` Svyatoslav Ryhel
0 siblings, 0 replies; 5+ messages in thread
From: Svyatoslav Ryhel @ 2025-08-24 9:15 UTC (permalink / raw)
To: Daniel Lezcano
Cc: Rafael J. Wysocki, Zhang Rui, Lukasz Luba, Jonathan Cameron,
linux-pm, devicetree, linux-kernel
пн, 5 трав. 2025 р. о 11:56 Daniel Lezcano <daniel.lezcano@linaro.org> пише:
>
> On Wed, Apr 30, 2025 at 08:58:07AM +0300, Svyatoslav Ryhel wrote:
> > To avoid duplicating sensor functionality and conversion tables, this
> > design allows converting an ADC IIO channel's output directly into a
> > temperature IIO channel. This is particularly useful for devices where
> > hwmon isn't suitable or where temperature data must be accessible through
> > IIO.
> >
> > One such device is, for example, the MAX17040 fuel gauge.
> >
> > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
> > ---
> > drivers/thermal/thermal-generic-adc.c | 55 ++++++++++++++++++++++++++-
> > 1 file changed, 54 insertions(+), 1 deletion(-)
> >
> > diff --git a/drivers/thermal/thermal-generic-adc.c b/drivers/thermal/thermal-generic-adc.c
> > index ee3d0aa31406..7c844589b153 100644
> > --- a/drivers/thermal/thermal-generic-adc.c
> > +++ b/drivers/thermal/thermal-generic-adc.c
> > @@ -7,6 +7,7 @@
> > * Author: Laxman Dewangan <ldewangan@nvidia.com>
> > */
> > #include <linux/iio/consumer.h>
> > +#include <linux/iio/iio.h>
> > #include <linux/kernel.h>
> > #include <linux/module.h>
> > #include <linux/platform_device.h>
> > @@ -73,6 +74,58 @@ static const struct thermal_zone_device_ops gadc_thermal_ops = {
> > .get_temp = gadc_thermal_get_temp,
> > };
> >
> > +static const struct iio_chan_spec gadc_thermal_iio_channels[] = {
> > + {
> > + .type = IIO_TEMP,
> > + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
> > + }
> > +};
> > +
> > +static int gadc_thermal_read_raw(struct iio_dev *indio_dev,
> > + struct iio_chan_spec const *chan,
> > + int *val, int *val2, long mask)
> > +{
> > + struct gadc_thermal_info *gtinfo = iio_priv(indio_dev);
> > + int ret;
> > +
> > + switch (mask) {
> > + case IIO_CHAN_INFO_PROCESSED:
> > + ret = gadc_thermal_get_temp(gtinfo->tz_dev, val);
> > + if (ret)
> > + return ret;
> > +
> > + return IIO_VAL_INT;
> > +
> > + default:
> > + return -EINVAL;
> > + }
> > +}
> > +
> > +static const struct iio_info gadc_thermal_iio_info = {
> > + .read_raw = gadc_thermal_read_raw,
> > +};
> > +
> > +static int gadc_iio_register(struct device *dev, struct gadc_thermal_info *gti)
> > +{
> > + struct gadc_thermal_info *gtinfo;
> > + struct iio_dev *indio_dev;
> > +
> > + indio_dev = devm_iio_device_alloc(dev, sizeof(*gtinfo));
> > + if (!indio_dev)
> > + return -ENOMEM;
> > +
> > + gtinfo = iio_priv(indio_dev);
> > + memcpy(gtinfo, gti, sizeof(*gtinfo));
>
> Why copy the structure ?
>
> Copying the thermal zone device pointer should be enough, no ?
>
iio_device_alloc created its own copy of struct gadc_thermal_info
hence memcpy is used to fill struct gadc_thermal_info allocated by iio
using struct gadc_thermal_info from gadc, or how do you propose to
handle this? Maybe you could provide a code example for better
understanding.
> > + indio_dev->name = dev_name(dev);
> > + indio_dev->info = &gadc_thermal_iio_info;
> > + indio_dev->modes = INDIO_DIRECT_MODE;
> > + indio_dev->channels = gadc_thermal_iio_channels;
> > + indio_dev->num_channels = ARRAY_SIZE(gadc_thermal_iio_channels);
> > +
> > + return devm_iio_device_register(dev, indio_dev);
> > +}
> > +
> > static int gadc_thermal_read_linear_lookup_table(struct device *dev,
> > struct gadc_thermal_info *gti)
> > {
> > @@ -153,7 +206,7 @@ static int gadc_thermal_probe(struct platform_device *pdev)
> >
> > devm_thermal_add_hwmon_sysfs(dev, gti->tz_dev);
> >
> > - return 0;
> > + return gadc_iio_register(&pdev->dev, gti);
> > }
> >
> > static const struct of_device_id of_adc_thermal_match[] = {
> > --
> > 2.48.1
> >
>
> --
>
> <http://www.linaro.org/> Linaro.org │ Open source software for ARM SoCs
>
> Follow Linaro: <http://www.facebook.com/pages/Linaro> Facebook |
> <http://twitter.com/#!/linaroorg> Twitter |
> <http://www.linaro.org/linaro-blog/> Blog
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-08-24 9:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-30 5:58 [PATCH v5 0/1] thermal: thermal-generic-adc: add temp sensor function Svyatoslav Ryhel
2025-04-30 5:58 ` [PATCH v5 1/1] thermal: thermal-generic-adc: add temperature sensor channel Svyatoslav Ryhel
2025-05-02 9:19 ` Jonathan Cameron
2025-05-05 8:56 ` Daniel Lezcano
2025-08-24 9:15 ` Svyatoslav Ryhel
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).