Skip to contentSkip to conversation

power: supply: bq25890: Document POWER_SUPPLY_PROP_CURRENT_NOW

PATCH In review Marek Vasut 3 participants 10 messages Oct 14, 2022 – Oct 28, 2022 Power supply

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/7 power: supply: bq25890: Document POWER_SUPPLY_PROP_CURRENT_NOW

Document that POWER_SUPPLY_PROP_CURRENT_NOW really does refer to ADC-sampled immediate battery charge current I_BAT , since the meaning is not clear with all the currents which might be measured by charger chips.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Add RB from Hans

---
 drivers/power/supply/bq25890_charger.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/power/supply/bq25890_charger.c +8 -1
index 6020b58c641d2..1298d5720aa4b 100644
@@ -588,7 +588,14 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = 2304000 + ret * 20000;
 		break;
 
-	case POWER_SUPPLY_PROP_CURRENT_NOW:
+	case POWER_SUPPLY_PROP_CURRENT_NOW:	/* I_BAT now */
+		/*
+		 * This is ADC-sampled immediate charge current supplied
+		 * from charger to battery. The property name is confusing,
+		 * for clarification refer to:
+		 * Documentation/ABI/testing/sysfs-class-power
+		 * /sys/class/power_supply/<supply_name>/current_now
+		 */
 		ret = bq25890_field_read(bq, F_ICHGR); /* read measured value */
 		if (ret < 0)
 			return ret;
Signature · 1 line
2.35.1
#1 lore raw

PATCH v2 2/7 power: supply: bq25890: Clean up POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT

Clean up misuse of POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT and POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX and document what exactly each value means.

The POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT content is newly read back from hardware, while POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX is reported as the maximum value set in DT.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Add RB from Hans

---
 drivers/power/supply/bq25890_charger.c | 57 ++++++++++++++++++--------
 1 file changed, 41 insertions(+), 16 deletions(-)
drivers/power/supply/bq25890_charger.c +41 -16
index 1298d5720aa4b..5924b036b1588 100644
@@ -529,22 +529,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
 		break;
 
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:
-		val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
-
-		/* When temperature is too low, charge current is decreased */
-		if (bq->state.ntc_fault == NTC_FAULT_COOL) {
-			ret = bq25890_field_read(bq, F_JEITA_ISET);
-			if (ret < 0)
-				return ret;
-
-			if (ret)
-				val->intval /= 5;
-			else
-				val->intval /= 2;
-		}
-		break;
-
 	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
 		if (!state.online) {
 			val->intval = 0;
@@ -604,6 +588,46 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = ret * -50000;
 		break;
 
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:	/* I_BAT user limit */
+		/*
+		 * This is user-configured constant charge current supplied
+		 * from charger to battery in first phase of charging, when
+		 * battery voltage is below constant charge voltage.
+		 *
+		 * This value reflects the current hardware setting.
+		 *
+		 * The POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX is the
+		 * maximum value of this property.
+		 */
+		ret = bq25890_field_read(bq, F_ICHG);
+		if (ret < 0)
+			return ret;
+		val->intval = bq25890_find_val(ret, TBL_ICHG);
+
+		/* When temperature is too low, charge current is decreased */
+		if (bq->state.ntc_fault == NTC_FAULT_COOL) {
+			ret = bq25890_field_read(bq, F_JEITA_ISET);
+			if (ret < 0)
+				return ret;
+
+			if (ret)
+				val->intval /= 5;
+			else
+				val->intval /= 2;
+		}
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX:	/* I_BAT max */
+		/*
+		 * This is maximum allowed constant charge current supplied
+		 * from charger to battery in first phase of charging, when
+		 * battery voltage is below constant charge voltage.
+		 *
+		 * This value is constant for each battery and set from DT.
+		 */
+		val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
+		break;
+
 	case POWER_SUPPLY_PROP_TEMP:
 		ret = bq25890_field_read(bq, F_TSPCT);
 		if (ret < 0)
@@ -887,6 +911,7 @@ static const enum power_supply_property bq25890_power_supply_props[] = {
 	POWER_SUPPLY_PROP_CHARGE_TYPE,
 	POWER_SUPPLY_PROP_ONLINE,
 	POWER_SUPPLY_PROP_HEALTH,
+	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE,
 	POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX,
Signature · 1 line
2.35.1
#2 lore raw

PATCH v2 3/7 power: supply: bq25890: Clean up POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE

In reply to Marek Vasut

Clean up misuse of POWER_SUPPLY_PROP_VOLTAGE,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
and POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
and document what exactly each value means.

The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE content is newly read back from hardware, while POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is reported as the maximum value set in DT.

The POWER_SUPPLY_PROP_VOLTAGE is newly used to report immediate value of battery voltage V_BAT, which is what this property was intended to report and which has been thus far misused to report the charger chip output voltage V_SYS.

The V_SYS is no longer reported as there is currently no suitable property to report V_SYS. V_SYS reporting will be reinstated in subsequent patch.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Drop the state online check from new POWER_SUPPLY_PROP_VOLTAGE_NOW
since the VBAT can be measured even when discharging

---
 drivers/power/supply/bq25890_charger.c | 72 ++++++++++++++++----------
 1 file changed, 45 insertions(+), 27 deletions(-)
drivers/power/supply/bq25890_charger.c +45 -27
index 5924b036b1588..050eef2571e8e 100644
@@ -529,24 +529,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
 		break;
 
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
-		if (!state.online) {
-			val->intval = 0;
-			break;
-		}
-
-		ret = bq25890_field_read(bq, F_BATV); /* read measured value */
-		if (ret < 0)
-			return ret;
-
-		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
-		val->intval = 2304000 + ret * 20000;
-		break;
-
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
-		val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
-		break;
-
 	case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
 		val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM);
 		break;
@@ -563,15 +545,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = bq25890_find_val(ret, TBL_IINLIM);
 		break;
 
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
-		if (ret < 0)
-			return ret;
-
-		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
-		val->intval = 2304000 + ret * 20000;
-		break;
-
 	case POWER_SUPPLY_PROP_CURRENT_NOW:	/* I_BAT now */
 		/*
 		 * This is ADC-sampled immediate charge current supplied
@@ -628,6 +601,51 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
 		break;
 
+	case POWER_SUPPLY_PROP_VOLTAGE_NOW:	/* V_BAT now */
+		/*
+		 * This is ADC-sampled immediate charge voltage supplied
+		 * from charger to battery. The property name is confusing,
+		 * for clarification refer to:
+		 * Documentation/ABI/testing/sysfs-class-power
+		 * /sys/class/power_supply/<supply_name>/voltage_now
+		 */
+		ret = bq25890_field_read(bq, F_BATV); /* read measured value */
+		if (ret < 0)
+			return ret;
+
+		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
+		val->intval = 2304000 + ret * 20000;
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:	/* V_BAT user limit */
+		/*
+		 * This is user-configured constant charge voltage supplied
+		 * from charger to battery in second phase of charging, when
+		 * battery voltage reached constant charge voltage.
+		 *
+		 * This value reflects the current hardware setting.
+		 *
+		 * The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is the
+		 * maximum value of this property.
+		 */
+		ret = bq25890_field_read(bq, F_VREG);
+		if (ret < 0)
+			return ret;
+
+		val->intval = bq25890_find_val(ret, TBL_VREG);
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:	/* V_BAT max */
+		/*
+		 * This is maximum allowed constant charge voltage supplied
+		 * from charger to battery in second phase of charging, when
+		 * battery voltage reached constant charge voltage.
+		 *
+		 * This value is constant for each battery and set from DT.
+		 */
+		val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
+		break;
+
 	case POWER_SUPPLY_PROP_TEMP:
 		ret = bq25890_field_read(bq, F_TSPCT);
 		if (ret < 0)
Signature · 1 line
2.35.1
Reviewed-by on v2 3/7
#3 lore raw

Re: [PATCH v2 3/7] power: supply: bq25890: Clean up POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE

Hi,

Quoted 19 lines · Marek Vasut

Clean up misuse of POWER_SUPPLY_PROP_VOLTAGE,
POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX
and POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE
and document what exactly each value means.

The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE content is newly read back from hardware, while POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is reported as the maximum value set in DT.

The POWER_SUPPLY_PROP_VOLTAGE is newly used to report immediate value of battery voltage V_BAT, which is what this property was intended to report and which has been thus far misused to report the charger chip output voltage V_SYS.

The V_SYS is no longer reported as there is currently no suitable property to report V_SYS. V_SYS reporting will be reinstated in subsequent patch.

Quoted 9 lines

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Drop the state online check from new POWER_SUPPLY_PROP_VOLTAGE_NOW
since the VBAT can be measured even when discharging

Thanks, patch looks good to me:

Regards,

Hans

Quoted 101 lines
---
 drivers/power/supply/bq25890_charger.c | 72 ++++++++++++++++----------
 1 file changed, 45 insertions(+), 27 deletions(-)
drivers/power/supply/bq25890_charger.c +45 -27
index 5924b036b1588..050eef2571e8e 100644
@@ -529,24 +529,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 			val->intval = POWER_SUPPLY_HEALTH_UNSPEC_FAILURE;
 		break;
 
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
-		if (!state.online) {
-			val->intval = 0;
-			break;
-		}
-
-		ret = bq25890_field_read(bq, F_BATV); /* read measured value */
-		if (ret < 0)
-			return ret;
-
-		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
-		val->intval = 2304000 + ret * 20000;
-		break;
-
-	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:
-		val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
-		break;
-
 	case POWER_SUPPLY_PROP_PRECHARGE_CURRENT:
 		val->intval = bq25890_find_val(bq->init_data.iprechg, TBL_ITERM);
 		break;
@@ -563,15 +545,6 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = bq25890_find_val(ret, TBL_IINLIM);
 		break;
 
-	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
-		ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
-		if (ret < 0)
-			return ret;
-
-		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
-		val->intval = 2304000 + ret * 20000;
-		break;
-
 	case POWER_SUPPLY_PROP_CURRENT_NOW:	/* I_BAT now */
 		/*
 		 * This is ADC-sampled immediate charge current supplied
@@ -628,6 +601,51 @@ static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
 		break;
 
+	case POWER_SUPPLY_PROP_VOLTAGE_NOW:	/* V_BAT now */
+		/*
+		 * This is ADC-sampled immediate charge voltage supplied
+		 * from charger to battery. The property name is confusing,
+		 * for clarification refer to:
+		 * Documentation/ABI/testing/sysfs-class-power
+		 * /sys/class/power_supply/<supply_name>/voltage_now
+		 */
+		ret = bq25890_field_read(bq, F_BATV); /* read measured value */
+		if (ret < 0)
+			return ret;
+
+		/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
+		val->intval = 2304000 + ret * 20000;
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:	/* V_BAT user limit */
+		/*
+		 * This is user-configured constant charge voltage supplied
+		 * from charger to battery in second phase of charging, when
+		 * battery voltage reached constant charge voltage.
+		 *
+		 * This value reflects the current hardware setting.
+		 *
+		 * The POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX is the
+		 * maximum value of this property.
+		 */
+		ret = bq25890_field_read(bq, F_VREG);
+		if (ret < 0)
+			return ret;
+
+		val->intval = bq25890_find_val(ret, TBL_VREG);
+		break;
+
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX:	/* V_BAT max */
+		/*
+		 * This is maximum allowed constant charge voltage supplied
+		 * from charger to battery in second phase of charging, when
+		 * battery voltage reached constant charge voltage.
+		 *
+		 * This value is constant for each battery and set from DT.
+		 */
+		val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
+		break;
+
 	case POWER_SUPPLY_PROP_TEMP:
 		ret = bq25890_field_read(bq, F_TSPCT);
 		if (ret < 0)
#4 lore raw

PATCH v2 4/7 power: supply: bq25890: Add support for setting user charge current and voltage limit

In reply to Marek Vasut

Let user set battery charge current and voltage limit via sysfs. This is useful in case the user space needs to reduce charge current to keep the system within thermal limits. The maximum charge current and voltage are still limited to "ti,charge-current" and "ti,battery-regulation-voltage" values to avoid damaging the hardware in case too high values are set by user space.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Add RB from Hans

---
 drivers/power/supply/bq25890_charger.c | 11 +++++++++++
 1 file changed, 11 insertions(+)
drivers/power/supply/bq25890_charger.c +11 -0
index 050eef2571e8e..95803157ac4af 100644
@@ -667,9 +667,18 @@ static int bq25890_power_supply_set_property(struct power_supply *psy,
 					     const union power_supply_propval *val)
 {
 	struct bq25890_device *bq = power_supply_get_drvdata(psy);
+	int maxval;
 	u8 lval;
 
 	switch (psp) {
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+		maxval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG);
+		lval = bq25890_find_idx(min(val->intval, maxval), TBL_ICHG);
+		return bq25890_field_write(bq, F_ICHG, lval);
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
+		maxval = bq25890_find_val(bq->init_data.vreg, TBL_VREG);
+		lval = bq25890_find_idx(min(val->intval, maxval), TBL_VREG);
+		return bq25890_field_write(bq, F_VREG, lval);
 	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
 		lval = bq25890_find_idx(val->intval, TBL_IINLIM);
 		return bq25890_field_write(bq, F_IINLIM, lval);
@@ -682,6 +691,8 @@ static int bq25890_power_supply_property_is_writeable(struct power_supply *psy,
 						      enum power_supply_property psp)
 {
 	switch (psp) {
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT:
+	case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE:
 	case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT:
 		return true;
 	default:
Signature · 1 line
2.35.1
#5 lore raw

PATCH v2 5/7 power: supply: bq25890: Factor out regulator registration code

In reply to Marek Vasut

Pull the regulator registration code into separate function, so it can be extended to register more regulators later. Currently this is only moving ifdeffery into one place and other preparatory changes. The dev_err_probe() output string is changed to explicitly list vbus regulator failure, so that once more regulators are registered, it would be clear which one failed.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: - Add the missing semicolon past return 0 in bq25890_register_regulator()
in negative REGULATOR macro check branch
- Add RB from Hans

---
 drivers/power/supply/bq25890_charger.c | 51 ++++++++++++++++++--------
 1 file changed, 35 insertions(+), 16 deletions(-)
drivers/power/supply/bq25890_charger.c +35 -16
index 95803157ac4af..dad98b782a2f8 100644
@@ -1110,6 +1110,36 @@ static const struct regulator_desc bq25890_vbus_desc = {
 	.fixed_uV = 5000000,
 	.n_voltages = 1,
 };
+
+static int bq25890_register_regulator(struct bq25890_device *bq)
+{
+	struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev);
+	struct regulator_config cfg = {
+		.dev = bq->dev,
+		.driver_data = bq,
+	};
+	struct regulator_dev *reg;
+
+	if (!IS_ERR_OR_NULL(bq->usb_phy))
+		return 0;
+
+	if (pdata)
+		cfg.init_data = pdata->regulator_init_data;
+
+	reg = devm_regulator_register(bq->dev, &bq25890_vbus_desc, &cfg);
+	if (IS_ERR(reg)) {
+		return dev_err_probe(bq->dev, PTR_ERR(reg),
+				     "registering vbus regulator");
+	}
+
+	return 0;
+}
+#else
+static inline int
+bq25890_register_regulator(struct bq25890_device *bq)
+{
+	return 0;
+}
 #endif
 
 static int bq25890_get_chip_version(struct bq25890_device *bq)
@@ -1305,27 +1335,16 @@ static int bq25890_probe(struct i2c_client *client,
 
 	/* OTG reporting */
 	bq->usb_phy = devm_usb_get_phy(dev, USB_PHY_TYPE_USB2);
+
+	ret = bq25890_register_regulator(bq);
+	if (ret)
+		return ret;
+
 	if (!IS_ERR_OR_NULL(bq->usb_phy)) {
 		INIT_WORK(&bq->usb_work, bq25890_usb_work);
 		bq->usb_nb.notifier_call = bq25890_usb_notifier;
 		usb_register_notifier(bq->usb_phy, &bq->usb_nb);
 	}
-#ifdef CONFIG_REGULATOR
-	else {
-		struct bq25890_platform_data *pdata = dev_get_platdata(dev);
-		struct regulator_config cfg = { };
-		struct regulator_dev *reg;
-
-		cfg.dev = dev;
-		cfg.driver_data = bq;
-		if (pdata)
-			cfg.init_data = pdata->regulator_init_data;
-
-		reg = devm_regulator_register(dev, &bq25890_vbus_desc, &cfg);
-		if (IS_ERR(reg))
-			return dev_err_probe(dev, PTR_ERR(reg), "registering regulator");
-	}
-#endif
 
 	ret = bq25890_power_supply_init(bq);
 	if (ret < 0) {
Signature · 1 line
2.35.1
#6 lore raw

PATCH v2 6/7 power: supply: bq25890: Add get_voltage support to Vbus regulator

In reply to Marek Vasut

The chip is capable of reporting Vbus voltage, add .get_voltage implementation to Vbus regulator to report current Vbus voltage. This requires for the Vbus regulator to be registered always instead of the current state where the regulator is registered only in case USB PHY is not found.

Do not provide Vbus regulator enable/disable ops in case USB PHY is present, as they would race with USB PHY notifier which is also used to toggle OTG boost mode.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Simplify the Vbus regulator registration, quoting Hans:
"
AFAIK if the Vboost regulator is not referenced in dt because it is controller through the usb-phy framework then valid_ops_mask will be empty, so the 2 sets of ops + 2 descs are not necessary I believe.
So I believe this can be simplified to just adding bq25890_vbus_get_voltage to the ops, dropping .fixed_uV and .n_voltages from the desc, and just completely dropping the IS_ERR_OR_NULL(bq->usb_phy) check.
"

---
 drivers/power/supply/bq25890_charger.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/power/supply/bq25890_charger.c +8 -5
index dad98b782a2f8..ad5811304f88a 100644
@@ -1095,10 +1095,18 @@ static int bq25890_vbus_is_enabled(struct regulator_dev *rdev)
 	return bq25890_field_read(bq, F_OTG_CFG);
 }
 
+static int bq25890_vbus_get_voltage(struct regulator_dev *rdev)
+{
+	struct bq25890_device *bq = rdev_get_drvdata(rdev);
+
+	return bq25890_get_vbus_voltage(bq);
+}
+
 static const struct regulator_ops bq25890_vbus_ops = {
 	.enable = bq25890_vbus_enable,
 	.disable = bq25890_vbus_disable,
 	.is_enabled = bq25890_vbus_is_enabled,
+	.get_voltage = bq25890_vbus_get_voltage,
 };
 
 static const struct regulator_desc bq25890_vbus_desc = {
@@ -1107,8 +1115,6 @@ static const struct regulator_desc bq25890_vbus_desc = {
 	.type = REGULATOR_VOLTAGE,
 	.owner = THIS_MODULE,
 	.ops = &bq25890_vbus_ops,
-	.fixed_uV = 5000000,
-	.n_voltages = 1,
 };
 
 static int bq25890_register_regulator(struct bq25890_device *bq)
@@ -1120,9 +1126,6 @@ static int bq25890_register_regulator(struct bq25890_device *bq)
 	};
 	struct regulator_dev *reg;
 
-	if (!IS_ERR_OR_NULL(bq->usb_phy))
-		return 0;
-
 	if (pdata)
 		cfg.init_data = pdata->regulator_init_data;
 
Signature · 1 line
2.35.1
Reviewed-by on v2 6/7
#7 lore raw

Re: [PATCH v2 6/7] power: supply: bq25890: Add get_voltage support to Vbus regulator

Hi,

Quoted 21 lines · Marek Vasut

The chip is capable of reporting Vbus voltage, add .get_voltage implementation to Vbus regulator to report current Vbus voltage. This requires for the Vbus regulator to be registered always instead of the current state where the regulator is registered only in case USB PHY is not found.

Do not provide Vbus regulator enable/disable ops in case USB PHY is present, as they would race with USB PHY notifier which is also used to toggle OTG boost mode.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Simplify the Vbus regulator registration, quoting Hans:
"
AFAIK if the Vboost regulator is not referenced in dt because

Quoted 8 lines

it is controller through the usb-phy framework then valid_ops_mask will be empty, so the 2 sets of ops + 2 descs are not necessary I believe.
So I believe this can be simplified to just adding bq25890_vbus_get_voltage to the ops, dropping .fixed_uV and .n_voltages from the desc, and just completely dropping the IS_ERR_OR_NULL(bq->usb_phy) check.
"

Thanks, patch looks good to me:

Regards,

Hans

Quoted 47 lines
---
 drivers/power/supply/bq25890_charger.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/power/supply/bq25890_charger.c +8 -5
index dad98b782a2f8..ad5811304f88a 100644
@@ -1095,10 +1095,18 @@ static int bq25890_vbus_is_enabled(struct regulator_dev *rdev)
 	return bq25890_field_read(bq, F_OTG_CFG);
 }
 
+static int bq25890_vbus_get_voltage(struct regulator_dev *rdev)
+{
+	struct bq25890_device *bq = rdev_get_drvdata(rdev);
+
+	return bq25890_get_vbus_voltage(bq);
+}
+
 static const struct regulator_ops bq25890_vbus_ops = {
 	.enable = bq25890_vbus_enable,
 	.disable = bq25890_vbus_disable,
 	.is_enabled = bq25890_vbus_is_enabled,
+	.get_voltage = bq25890_vbus_get_voltage,
 };
 
 static const struct regulator_desc bq25890_vbus_desc = {
@@ -1107,8 +1115,6 @@ static const struct regulator_desc bq25890_vbus_desc = {
 	.type = REGULATOR_VOLTAGE,
 	.owner = THIS_MODULE,
 	.ops = &bq25890_vbus_ops,
-	.fixed_uV = 5000000,
-	.n_voltages = 1,
 };
 
 static int bq25890_register_regulator(struct bq25890_device *bq)
@@ -1120,9 +1126,6 @@ static int bq25890_register_regulator(struct bq25890_device *bq)
 	};
 	struct regulator_dev *reg;
 
-	if (!IS_ERR_OR_NULL(bq->usb_phy))
-		return 0;
-
 	if (pdata)
 		cfg.init_data = pdata->regulator_init_data;
 
#8 lore raw

PATCH v2 7/7 power: supply: bq25890: Add Vsys regulator

In reply to Marek Vasut

The chip is capable of reporting Vsys voltage supplied to the system. Add regulator which represents the Vsys supply. This can be used e.g. as a supply for system PMIC input.

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Add RB from Hans

---
 drivers/power/supply/bq25890_charger.c | 32 ++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
drivers/power/supply/bq25890_charger.c +32 -0
index ad5811304f88a..f0362dcb935e9 100644
@@ -1102,6 +1102,20 @@ static int bq25890_vbus_get_voltage(struct regulator_dev *rdev)
 	return bq25890_get_vbus_voltage(bq);
 }
 
+static int bq25890_vsys_get_voltage(struct regulator_dev *rdev)
+{
+	struct bq25890_device *bq = rdev_get_drvdata(rdev);
+	int ret;
+
+	/* Should be some output voltage ? */
+	ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
+	if (ret < 0)
+		return ret;
+
+	/* converted_val = 2.304V + ADC_val * 20mV (table 10.3.15) */
+	return 2304000 + ret * 20000;
+}
+
 static const struct regulator_ops bq25890_vbus_ops = {
 	.enable = bq25890_vbus_enable,
 	.disable = bq25890_vbus_disable,
@@ -1117,6 +1131,18 @@ static const struct regulator_desc bq25890_vbus_desc = {
 	.ops = &bq25890_vbus_ops,
 };
 
+static const struct regulator_ops bq25890_vsys_ops = {
+	.get_voltage = bq25890_vsys_get_voltage,
+};
+
+static const struct regulator_desc bq25890_vsys_desc = {
+	.name = "vsys",
+	.of_match = "vsys",
+	.type = REGULATOR_VOLTAGE,
+	.owner = THIS_MODULE,
+	.ops = &bq25890_vsys_ops,
+};
+
 static int bq25890_register_regulator(struct bq25890_device *bq)
 {
 	struct bq25890_platform_data *pdata = dev_get_platdata(bq->dev);
@@ -1135,6 +1161,12 @@ static int bq25890_register_regulator(struct bq25890_device *bq)
 				     "registering vbus regulator");
 	}
 
+	reg = devm_regulator_register(bq->dev, &bq25890_vsys_desc, &cfg);
+	if (IS_ERR(reg)) {
+		return dev_err_probe(bq->dev, PTR_ERR(reg),
+				     "registering vsys regulator");
+	}
+
 	return 0;
 }
 #else
Signature · 1 line
2.35.1
#9 lore raw
In reply to Marek Vasut

Hi,

Quoted 6 lines · Marek Vasut

Document that POWER_SUPPLY_PROP_CURRENT_NOW really does refer to ADC-sampled immediate battery charge current I_BAT , since the meaning is not clear with all the currents which might be measured by charger chips.

Quoted 9 lines

---
Cc: Andy Shevchenko <[email protected]>
Cc: Hans de Goede <[email protected]>
Cc: Michał Mirosław <[email protected]>
Cc: Sebastian Reichel <[email protected]>
To: [email protected]
---
V2: Add RB from Hans
---

Thanks, I queued the whole series.

-- Sebastian