* [PATCH] hwmon: iio: Use iio_read_channel_processed_scale for IIO_POWER
@ 2024-06-20 21:20 Sean Anderson
2024-06-21 15:09 ` Guenter Roeck
0 siblings, 1 reply; 2+ messages in thread
From: Sean Anderson @ 2024-06-20 21:20 UTC (permalink / raw)
To: Jean Delvare, Guenter Roeck, linux-hwmon; +Cc: linux-kernel, Sean Anderson
Instead of rescaling power channels after the fact, use the dedicated
scaling API. This should reduce any inaccuracies resulting from the
scaling.
Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
---
drivers/hwmon/iio_hwmon.c | 11 ++++++-----
1 file changed, 6 insertions(+), 5 deletions(-)
diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
index 4c8a80847891..fab32e1e15f2 100644
--- a/drivers/hwmon/iio_hwmon.c
+++ b/drivers/hwmon/iio_hwmon.c
@@ -49,16 +49,17 @@ static ssize_t iio_hwmon_read_val(struct device *dev,
struct iio_channel *chan = &state->channels[sattr->index];
enum iio_chan_type type;
- ret = iio_read_channel_processed(chan, &result);
- if (ret < 0)
- return ret;
-
ret = iio_get_channel_type(chan, &type);
if (ret < 0)
return ret;
if (type == IIO_POWER)
- result *= 1000; /* mili-Watts to micro-Watts conversion */
+ /* mili-Watts to micro-Watts conversion */
+ ret = iio_read_channel_processed_scale(chan, &result, 1000);
+ else
+ ret = iio_read_channel_processed(chan, &result);
+ if (ret < 0)
+ return ret;
return sprintf(buf, "%d\n", result);
}
--
2.35.1.1320.gc452695387.dirty
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] hwmon: iio: Use iio_read_channel_processed_scale for IIO_POWER
2024-06-20 21:20 [PATCH] hwmon: iio: Use iio_read_channel_processed_scale for IIO_POWER Sean Anderson
@ 2024-06-21 15:09 ` Guenter Roeck
0 siblings, 0 replies; 2+ messages in thread
From: Guenter Roeck @ 2024-06-21 15:09 UTC (permalink / raw)
To: Sean Anderson; +Cc: Jean Delvare, linux-hwmon, linux-kernel
On Thu, Jun 20, 2024 at 05:20:05PM -0400, Sean Anderson wrote:
> Instead of rescaling power channels after the fact, use the dedicated
> scaling API. This should reduce any inaccuracies resulting from the
> scaling.
>
> Signed-off-by: Sean Anderson <sean.anderson@linux.dev>
Applied.
Thanks,
Guenter
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-06-21 15:09 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-06-20 21:20 [PATCH] hwmon: iio: Use iio_read_channel_processed_scale for IIO_POWER Sean Anderson
2024-06-21 15:09 ` Guenter Roeck
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox