Skip to contentSkip to conversation

Change axp20x power drivers to use iio scaled

PATCH Applied Chris Morgan 2 participants 4 messages Oct 23, 2024 – Nov 11, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Change axp20x power drivers to use iio scaled

From: Chris Morgan <[email protected]>

Simplify the axp20x_battery and axp20x_usb_power to use iio_read_channel_processed_scale() instead of reading the channel and then applying the scaling factor in an additional step.

Chris Morgan (2):
power: supply: axp20x_usb_power: Use scaled iio_read_channel
power: supply: axp20x_battery: Use scaled iio_read_channel

 drivers/power/supply/axp20x_battery.c   | 33 +++++++++++++------------
 drivers/power/supply/axp20x_usb_power.c | 33 +++++++++++--------------
 2 files changed, 32 insertions(+), 34 deletions(-)
Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/2 power: supply: axp20x_usb_power: Use scaled iio_read_channel

From: Chris Morgan <[email protected]>

Change iio_read_channel_processed to iio_read_channel_processed_scale where appropriate.

---
 drivers/power/supply/axp20x_usb_power.c | 33 +++++++++++--------------
 1 file changed, 15 insertions(+), 18 deletions(-)
drivers/power/supply/axp20x_usb_power.c +15 -18
index 2766352ab737..9722912268fe 100644
@@ -220,16 +220,15 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
 		return 0;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 		if (IS_ENABLED(CONFIG_AXP20X_ADC)) {
-			ret = iio_read_channel_processed(power->vbus_v,
-							 &val->intval);
-			if (ret)
-				return ret;
-
 			/*
 			 * IIO framework gives mV but Power Supply framework
 			 * gives uV.
 			 */
-			val->intval *= 1000;
+			ret = iio_read_channel_processed_scale(power->vbus_v,
+							       &val->intval, 1000);
+			if (ret)
+				return ret;
+
 			return 0;
 		}
 
@@ -253,16 +252,15 @@ static int axp20x_usb_power_get_property(struct power_supply *psy,
 		return 0;
 	case POWER_SUPPLY_PROP_CURRENT_NOW:
 		if (IS_ENABLED(CONFIG_AXP20X_ADC)) {
-			ret = iio_read_channel_processed(power->vbus_i,
-							 &val->intval);
-			if (ret)
-				return ret;
-
 			/*
 			 * IIO framework gives mA but Power Supply framework
 			 * gives uA.
 			 */
-			val->intval *= 1000;
+			ret = iio_read_channel_processed_scale(power->vbus_i,
+							       &val->intval, 1000);
+			if (ret)
+				return ret;
+
 			return 0;
 		}
 
@@ -374,16 +372,15 @@ static int axp717_usb_power_get_property(struct power_supply *psy,
 		break;
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 		if (IS_ENABLED(CONFIG_AXP20X_ADC)) {
-			ret = iio_read_channel_processed(power->vbus_v,
-							 &val->intval);
-			if (ret)
-				return ret;
-
 			/*
 			 * IIO framework gives mV but Power Supply framework
 			 * gives uV.
 			 */
-			val->intval *= 1000;
+			ret = iio_read_channel_processed_scale(power->vbus_v,
+							       &val->intval, 1000);
+			if (ret)
+				return ret;
+
 			return 0;
 		}
 
Signature · 1 line
2.43.0
#2 lore raw

PATCH 2/2 power: supply: axp20x_battery: Use scaled iio_read_channel

In reply to Chris Morgan

From: Chris Morgan <[email protected]>

Change iio_read_channel_processed to iio_read_channel_processed_scale where appropriate.

---
 drivers/power/supply/axp20x_battery.c | 33 ++++++++++++++-------------
 1 file changed, 17 insertions(+), 16 deletions(-)
drivers/power/supply/axp20x_battery.c +17 -16
index f71cc90fea12..fa27195f074e 100644
@@ -354,17 +354,18 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
 		if (ret)
 			return ret;
 
+		/* IIO framework gives mA but Power Supply framework gives uA */
 		if (reg & AXP20X_PWR_STATUS_BAT_CHARGING) {
-			ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
+			ret = iio_read_channel_processed_scale(axp20x_batt->batt_chrg_i,
+							       &val->intval, 1000);
 		} else {
-			ret = iio_read_channel_processed(axp20x_batt->batt_dischrg_i, &val1);
+			ret = iio_read_channel_processed_scale(axp20x_batt->batt_dischrg_i,
+							       &val1, 1000);
 			val->intval = -val1;
 		}
 		if (ret)
 			return ret;
 
-		/* IIO framework gives mA but Power Supply framework gives uA */
-		val->intval *= 1000;
 		break;
 
 	case POWER_SUPPLY_PROP_CAPACITY:
@@ -406,13 +407,12 @@ static int axp20x_battery_get_prop(struct power_supply *psy,
 		break;
 
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = iio_read_channel_processed(axp20x_batt->batt_v,
-						 &val->intval);
+		/* IIO framework gives mV but Power Supply framework gives uV */
+		ret = iio_read_channel_processed_scale(axp20x_batt->batt_v,
+						 &val->intval, 1000);
 		if (ret)
 			return ret;
 
-		/* IIO framework gives mV but Power Supply framework gives uV */
-		val->intval *= 1000;
 		break;
 
 	default:
@@ -519,13 +519,15 @@ static int axp717_battery_get_prop(struct power_supply *psy,
 		 * The offset of this value is currently unknown and is
 		 * not documented in the datasheet. Based on
 		 * observation it's assumed to be somewhere around
-		 * 450ma. I will leave the value raw for now.
+		 * 450ma. I will leave the value raw for now. Note that
+		 * IIO framework gives mA but Power Supply framework
+		 * gives uA.
 		 */
-		ret = iio_read_channel_processed(axp20x_batt->batt_chrg_i, &val->intval);
+		ret = iio_read_channel_processed_scale(axp20x_batt->batt_chrg_i,
+						       &val->intval, 1000);
 		if (ret)
 			return ret;
-		/* IIO framework gives mA but Power Supply framework gives uA */
-		val->intval *= 1000;
+
 		return 0;
 
 	case POWER_SUPPLY_PROP_CAPACITY:
@@ -564,13 +566,12 @@ static int axp717_battery_get_prop(struct power_supply *psy,
 		return 0;
 
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = iio_read_channel_processed(axp20x_batt->batt_v,
-						 &val->intval);
+		/* IIO framework gives mV but Power Supply framework gives uV */
+		ret = iio_read_channel_processed_scale(axp20x_batt->batt_v,
+						       &val->intval, 1000);
 		if (ret)
 			return ret;
 
-		/* IIO framework gives mV but Power Supply framework gives uV */
-		val->intval *= 1000;
 		return 0;
 
 	case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
Signature · 1 line
2.43.0
#3 lore raw
In reply to Chris Morgan
Quoted 11 lines · Chris Morgan

From: Chris Morgan <[email protected]>

Simplify the axp20x_battery and axp20x_usb_power to use iio_read_channel_processed_scale() instead of reading the channel and then applying the scaling factor in an additional step.

Chris Morgan (2):
power: supply: axp20x_usb_power: Use scaled iio_read_channel
power: supply: axp20x_battery: Use scaled iio_read_channel

[...]

Applied, thanks!

[1/2] power: supply: axp20x_usb_power: Use scaled iio_read_channel

      commit: 9fdd97d63fe2be2ab890240cce0a5790e0ef9877
[2/2] power: supply: axp20x_battery: Use scaled iio_read_channel
      commit: 1d3db2d99fbaa5020543bd1dc4f365faeffae4ed

Best regards,

Signature · 1 line
Sebastian Reichel <[email protected]>