Skip to content

Commit 92beafb

Browse files
evgeny-bogerjic23
authored andcommitted
iio: adc: axp20x_adc: fix charging current reporting on AXP22x
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 addition bit in register width. Tested on custom A40i+AXP221s board with external ammeter as a reference. Fixes: 0e34d5d ("iio: adc: add support for X-Powers AXP20X and AXP22X PMICs ADCs") Signed-off-by: Evgeny Boger <[email protected]> Acked-by: Chen-Yu Tsai <[email protected]> Link: https://lore.kernel.org/r/[email protected] Cc: <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent fde272e commit 92beafb

File tree

1 file changed

+3
-15
lines changed

1 file changed

+3
-15
lines changed

drivers/iio/adc/axp20x_adc.c

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -251,19 +251,8 @@ static int axp22x_adc_raw(struct iio_dev *indio_dev,
251251
struct iio_chan_spec const *chan, int *val)
252252
{
253253
struct axp20x_adc_iio *info = iio_priv(indio_dev);
254-
int size;
255254

256-
/*
257-
* N.B.: Unlike the Chinese datasheets tell, the charging current is
258-
* stored on 12 bits, not 13 bits. Only discharging current is on 13
259-
* bits.
260-
*/
261-
if (chan->type == IIO_CURRENT && chan->channel == AXP22X_BATT_DISCHRG_I)
262-
size = 13;
263-
else
264-
size = 12;
265-
266-
*val = axp20x_read_variable_width(info->regmap, chan->address, size);
255+
*val = axp20x_read_variable_width(info->regmap, chan->address, 12);
267256
if (*val < 0)
268257
return *val;
269258

@@ -386,9 +375,8 @@ static int axp22x_adc_scale(struct iio_chan_spec const *chan, int *val,
386375
return IIO_VAL_INT_PLUS_MICRO;
387376

388377
case IIO_CURRENT:
389-
*val = 0;
390-
*val2 = 500000;
391-
return IIO_VAL_INT_PLUS_MICRO;
378+
*val = 1;
379+
return IIO_VAL_INT;
392380

393381
case IIO_TEMP:
394382
*val = 100;

0 commit comments

Comments
 (0)