Skip to contentSkip to conversation

power: supply: sc27xx: Add POWER_SUPPLY_PROP_CHARGE_NOW attribute

PATCH In review Baolin Wang 2 participants 2 messages Feb 14, 2020 – Mar 8, 2020

Subsystems (2)
lore
Share & tools
lore

Baolin Wang

author maintainer
#0 lore raw

PATCH 1/1 power: supply: sc27xx: Add POWER_SUPPLY_PROP_CHARGE_NOW attribute

Add the POWER_SUPPLY_PROP_CHARGE_NOW attribute to allow user to get current battery capacity (uAh) to do measurement.

---
 drivers/power/supply/sc27xx_fuel_gauge.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/power/supply/sc27xx_fuel_gauge.c +12 -0
index 469c83f..a7c8a84 100644
@@ -614,6 +614,17 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 		val->intval = data->total_cap * 1000;
 		break;
 
+	case POWER_SUPPLY_PROP_CHARGE_NOW:
+		ret = sc27xx_fgu_get_clbcnt(data, &value);
+		if (ret)
+			goto error;
+
+		value = DIV_ROUND_CLOSEST(value * 10,
+					  36 * SC27XX_FGU_SAMPLE_HZ);
+		val->intval = sc27xx_fgu_adc_to_current(data, value);
+
+		break;
+
 	default:
 		ret = -EINVAL;
 		break;
@@ -682,6 +693,7 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
 	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CALIBRATE,
+	POWER_SUPPLY_PROP_CHARGE_NOW
 };
 
 static const struct power_supply_desc sc27xx_fgu_desc = {
Signature · 1 line
1.7.9.5
#1 lore raw

Hi,

Quoted 5 lines · Baolin Wang

Add the POWER_SUPPLY_PROP_CHARGE_NOW attribute to allow user to get current battery capacity (uAh) to do measurement.

---

Thanks, queued to power-supply's for-next branch.

-- Sebastian

Quoted 36 lines
 drivers/power/supply/sc27xx_fuel_gauge.c |   12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/power/supply/sc27xx_fuel_gauge.c +12 -0
index 469c83f..a7c8a84 100644
@@ -614,6 +614,17 @@ static int sc27xx_fgu_get_property(struct power_supply *psy,
 		val->intval = data->total_cap * 1000;
 		break;
 
+	case POWER_SUPPLY_PROP_CHARGE_NOW:
+		ret = sc27xx_fgu_get_clbcnt(data, &value);
+		if (ret)
+			goto error;
+
+		value = DIV_ROUND_CLOSEST(value * 10,
+					  36 * SC27XX_FGU_SAMPLE_HZ);
+		val->intval = sc27xx_fgu_adc_to_current(data, value);
+
+		break;
+
 	default:
 		ret = -EINVAL;
 		break;
@@ -682,6 +693,7 @@ static int sc27xx_fgu_property_is_writeable(struct power_supply *psy,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
 	POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN,
 	POWER_SUPPLY_PROP_CALIBRATE,
+	POWER_SUPPLY_PROP_CHARGE_NOW
 };
 
 static const struct power_supply_desc sc27xx_fgu_desc = {
Signature · 1 line
1.7.9.5