diff mbox series

[1/3] power: supply: max17040: Correct voltage reading

Message ID BN6PR04MB0660DA4AED9364441DA33094A3A60@BN6PR04MB0660.namprd04.prod.outlook.com (mailing list archive)
State Not Applicable, archived
Headers show
Series power: supply: Improve max17040 support | expand

Commit Message

Jonathan Bakker May 4, 2020, 10:12 p.m. UTC
According to the datasheet available at (1), the bottom four
bits are always zero and the actual voltage is 1.25x this value
in mV.  Since the kernel API specifies that voltages should be in
uV, it should report 1250x the shifted value.

1) https://datasheets.maximintegrated.com/en/ds/MAX17040-MAX17041.pdf

Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
---
 drivers/power/supply/max17040_battery.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Sebastian Reichel May 10, 2020, 8:09 p.m. UTC | #1
Hi,

On Mon, May 04, 2020 at 03:12:58PM -0700, Jonathan Bakker wrote:
> According to the datasheet available at (1), the bottom four
> bits are always zero and the actual voltage is 1.25x this value
> in mV.  Since the kernel API specifies that voltages should be in
> uV, it should report 1250x the shifted value.
> 
> 1) https://datasheets.maximintegrated.com/en/ds/MAX17040-MAX17041.pdf
> 
> Signed-off-by: Jonathan Bakker <xc-racer2@live.ca>
> ---

Thanks, queued.

-- Sebastian

>  drivers/power/supply/max17040_battery.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
> index 8a1f0ee493aa..48aa44665e2f 100644
> --- a/drivers/power/supply/max17040_battery.c
> +++ b/drivers/power/supply/max17040_battery.c
> @@ -126,7 +126,7 @@ static void max17040_get_vcell(struct i2c_client *client)
>  
>  	vcell = max17040_read_reg(client, MAX17040_VCELL);
>  
> -	chip->vcell = vcell;
> +	chip->vcell = (vcell >> 4) * 1250;
>  }
>  
>  static void max17040_get_soc(struct i2c_client *client)
> -- 
> 2.20.1
>
diff mbox series

Patch

diff --git a/drivers/power/supply/max17040_battery.c b/drivers/power/supply/max17040_battery.c
index 8a1f0ee493aa..48aa44665e2f 100644
--- a/drivers/power/supply/max17040_battery.c
+++ b/drivers/power/supply/max17040_battery.c
@@ -126,7 +126,7 @@  static void max17040_get_vcell(struct i2c_client *client)
 
 	vcell = max17040_read_reg(client, MAX17040_VCELL);
 
-	chip->vcell = vcell;
+	chip->vcell = (vcell >> 4) * 1250;
 }
 
 static void max17040_get_soc(struct i2c_client *client)