Skip to content

Commit 1d3db2d

Browse files
macromorgansre
authored andcommitted
power: supply: axp20x_battery: Use scaled iio_read_channel
Change iio_read_channel_processed to iio_read_channel_processed_scale where appropriate. Signed-off-by: Chris Morgan <macromorgan@hotmail.com> Link: https://lore.kernel.org/r/20241023184800.109376-3-macroalpha82@gmail.com Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent 9fdd97d commit 1d3db2d

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

drivers/power/supply/axp20x_battery.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,18 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
354354
if (ret)
355355
return ret;
356356

357+
/* IIO framework gives mA but Power Supply framework gives uA */
357358
if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
358-
ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
359+
ret = iio_read_channel_processed_scale(axp20x_batt->batt_chrg_i,
360+
&val->intval, 1000);
359361
} else {
360-
ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
362+
ret = iio_read_channel_processed_scale(axp20x_batt->batt_dischrg_i,
363+
&val1, 1000);
361364
val->intval = -val1;
362365
}
363366
if (ret)
364367
return ret;
365368

366-
/* IIO framework gives mA but Power Supply framework gives uA */
367-
val->intval *= 1000;
368369
break;
369370

370371
case POWER_SUPPLY_PROP_CAPACITY:
@@ -406,13 +407,12 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
406407
break;
407408

408409
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
409-
ret = iio_read_channel_processed(axp20x_batt->batt_v,
410-
&val->intval);
410+
/* IIO framework gives mV but Power Supply framework gives uV */
411+
ret = iio_read_channel_processed_scale(axp20x_batt->batt_v,
412+
&val->intval, 1000);
411413
if (ret)
412414
return ret;
413415

414-
/* IIO framework gives mV but Power Supply framework gives uV */
415-
val->intval *= 1000;
416416
break;
417417

418418
default:
@@ -519,13 +519,15 @@ static int axp717_battery_get_prop(struct power_supply *psy,
519519
* The offset of this value is currently unknown and is
520520
* not documented in the datasheet. Based on
521521
* observation it's assumed to be somewhere around
522-
* 450ma. I will leave the value raw for now.
522+
* 450ma. I will leave the value raw for now. Note that
523+
* IIO framework gives mA but Power Supply framework
524+
* gives uA.
523525
*/
524-
ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
526+
ret = iio_read_channel_processed_scale(axp20x_batt->batt_chrg_i,
527+
&val->intval, 1000);
525528
if (ret)
526529
return ret;
527-
/* IIO framework gives mA but Power Supply framework gives uA */
528-
val->intval *= 1000;
530+
529531
return 0;
530532

531533
case POWER_SUPPLY_PROP_CAPACITY:
@@ -564,13 +566,12 @@ static int axp717_battery_get_prop(struct power_supply *psy,
564566
return 0;
565567

566568
case POWER_SUPPLY_PROP_VOLTAGE_NOW:
567-
ret = iio_read_channel_processed(axp20x_batt->batt_v,
568-
&val->intval);
569+
/* IIO framework gives mV but Power Supply framework gives uV */
570+
ret = iio_read_channel_processed_scale(axp20x_batt->batt_v,
571+
&val->intval, 1000);
569572
if (ret)
570573
return ret;
571574

572-
/* IIO framework gives mV but Power Supply framework gives uV */
573-
val->intval *= 1000;
574575
return 0;
575576

576577
case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:

0 commit comments

Comments
 (0)