[PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling

Sebastian Reichel posted 11 patches 3 years, 1 month ago
There is a newer version of this series
[PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
Posted by Sebastian Reichel 3 years, 1 month ago
power-supply properties are reported in µV, µA and µW.
The IIO API provides mV, mA, mW, so the values need to
be multiplied by 1000.

Signed-off-by: Sebastian Reichel <sre@kernel.org>
---
 drivers/power/supply/generic-adc-battery.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
index 917bd2a6cc52..535972a332b3 100644
--- a/drivers/power/supply/generic-adc-battery.c
+++ b/drivers/power/supply/generic-adc-battery.c
@@ -136,6 +136,9 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
 			result);
 	if (ret < 0)
 		pr_err("read channel error\n");
+	else
+		*result *= 1000;
+
 	return ret;
 }
 
-- 
2.39.2

Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
Posted by Matti Vaittinen 3 years ago
On 3/10/23 00:50, Sebastian Reichel wrote:
> power-supply properties are reported in µV, µA and µW.
> The IIO API provides mV, mA, mW, so the values need to
> be multiplied by 1000.
> 
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

As Linus wrote, Fixes-tag would be good. With that remark:
Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com>

> ---
>   drivers/power/supply/generic-adc-battery.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/drivers/power/supply/generic-adc-battery.c b/drivers/power/supply/generic-adc-battery.c
> index 917bd2a6cc52..535972a332b3 100644
> --- a/drivers/power/supply/generic-adc-battery.c
> +++ b/drivers/power/supply/generic-adc-battery.c
> @@ -136,6 +136,9 @@ static int read_channel(struct gab *adc_bat, enum power_supply_property psp,
>   			result);
>   	if (ret < 0)
>   		pr_err("read channel error\n");
> +	else
> +		*result *= 1000;
> +
>   	return ret;
>   }
>   

-- 
Matti Vaittinen
Linux kernel developer at ROHM Semiconductors
Oulu Finland

~~ When things go utterly wrong vim users can always type :help! ~~

Re: [PATCHv1 04/11] power: supply: generic-adc-battery: fix unit scaling
Posted by Linus Walleij 3 years, 1 month ago
On Thu, Mar 9, 2023 at 11:50 PM Sebastian Reichel <sre@kernel.org> wrote:

> power-supply properties are reported in µV, µA and µW.
> The IIO API provides mV, mA, mW, so the values need to
> be multiplied by 1000.
>
> Signed-off-by: Sebastian Reichel <sre@kernel.org>

Fixes: tag?
Cc: stable@vger.kernel.org

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

This code can not have seen much testing.

Yours,
Linus Walleij