* [PATCH] iio: adc: axp20x_adc: fix charging current reporting on AXP22x
@ 2021-03-06 23:52 Evgeny Boger
2021-03-07 12:46 ` Jonathan Cameron
0 siblings, 1 reply; 2+ messages in thread
From: Evgeny Boger @ 2021-03-06 23:52 UTC (permalink / raw)
To: linux-iio, linux-kernel
Cc: Evgeny Boger, Jonathan Cameron, Lars-Peter Clausen,
Peter Meerwald-Stadler, Quentin Schulz
Both the charging and discharging currents on AXP22x are stored as
12-bit integers, in accordance with the datasheet.
It's also confirmed by vendor BSP (axp20x_adc.c:axp22_icharge_to_mA).
The scale factor of 0.5 is never mentioned in datasheet, nor in the
vendor source code. I think it was here to compensate for
erroneous additional bit in register width.
Tested on custom A40i+AXP221s board with external ammeter as
a reference.
Signed-off-by: Evgeny Boger <boger@wirenboard.com>
---
drivers/iio/adc/axp20x_adc.c | 14 ++------------
1 file changed, 2 insertions(+), 12 deletions(-)
diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c
index 3e0c0233b431..8db6699c20c3 100644
--- a/drivers/iio/adc/axp20x_adc.c
+++ b/drivers/iio/adc/axp20x_adc.c
@@ -253,17 +253,7 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev,
struct axp20x_adc_iio *info = iio_priv(indio_dev);
int size;
- /*
- * N.B.: Unlike the Chinese datasheets tell, the charging current is
- * stored on 12 bits, not 13 bits. Only discharging current is on 13
- * bits.
- */
- if (chan->type == IIO_CURRENT && chan->channel == AXP22X_BATT_DISCHRG_I)
- size = 13;
- else
- size = 12;
-
- *val = axp20x_read_variable_width(info->regmap, chan->address, size);
+ *val = axp20x_read_variable_width(info->regmap, chan->address, 12);
if (*val < 0)
return *val;
@@ -387,7 +377,7 @@ static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val,
case IIO_CURRENT:
*val = 0;
- *val2 = 500000;
+ *val2 = 1000000;
return IIO_VAL_INT_PLUS_MICRO;
case IIO_TEMP:
--
2.17.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] iio: adc: axp20x_adc: fix charging current reporting on AXP22x
2021-03-06 23:52 [PATCH] iio: adc: axp20x_adc: fix charging current reporting on AXP22x Evgeny Boger
@ 2021-03-07 12:46 ` Jonathan Cameron
0 siblings, 0 replies; 2+ messages in thread
From: Jonathan Cameron @ 2021-03-07 12:46 UTC (permalink / raw)
To: Evgeny Boger
Cc: linux-iio, linux-kernel, Lars-Peter Clausen,
Peter Meerwald-Stadler, Quentin Schulz, Quentin Schulz
On Sun, 7 Mar 2021 02:52:38 +0300
Evgeny Boger <boger@wirenboard.com> wrote:
> Both the charging and discharging currents on AXP22x are stored as
> 12-bit integers, in accordance with the datasheet.
> It's also confirmed by vendor BSP (axp20x_adc.c:axp22_icharge_to_mA).
>
> The scale factor of 0.5 is never mentioned in datasheet, nor in the
> vendor source code. I think it was here to compensate for
> erroneous additional bit in register width.
>
> Tested on custom A40i+AXP221s board with external ammeter as
> a reference.
>
> Signed-off-by: Evgeny Boger <boger@wirenboard.com>
+CC Quentin's bootlin address.
One comment inline,
Jonathan
> ---
> drivers/iio/adc/axp20x_adc.c | 14 ++------------
> 1 file changed, 2 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c
> index 3e0c0233b431..8db6699c20c3 100644
> --- a/drivers/iio/adc/axp20x_adc.c
> +++ b/drivers/iio/adc/axp20x_adc.c
> @@ -253,17 +253,7 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev,
> struct axp20x_adc_iio *info = iio_priv(indio_dev);
> int size;
>
> - /*
> - * N.B.: Unlike the Chinese datasheets tell, the charging current is
> - * stored on 12 bits, not 13 bits. Only discharging current is on 13
> - * bits.
> - */
> - if (chan->type == IIO_CURRENT && chan->channel == AXP22X_BATT_DISCHRG_I)
> - size = 13;
> - else
> - size = 12;
> -
> - *val = axp20x_read_variable_width(info->regmap, chan->address, size);
> + *val = axp20x_read_variable_width(info->regmap, chan->address, 12);
> if (*val < 0)
> return *val;
>
> @@ -387,7 +377,7 @@ static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val,
>
> case IIO_CURRENT:
> *val = 0;
> - *val2 = 500000;
> + *val2 = 1000000;
> return IIO_VAL_INT_PLUS_MICRO;
*val = 1;
return IIO_VAL_INT;
Should work if the scale factor is 1.
Note that we could just have reported the channel as _processed in the first place, but
given we didn't better to keep the ABI the same and just have a noop scale factor.
>
> case IIO_TEMP:
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-03-07 12:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-06 23:52 [PATCH] iio: adc: axp20x_adc: fix charging current reporting on AXP22x Evgeny Boger
2021-03-07 12:46 ` Jonathan Cameron
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.