diff mbox series

[11/14] power: supply: bq25890: show measured VBUS

Message ID 32ec8cef47cb49e02542916ae15972ba2e619e5a.1585838679.git.mirq-linux@rere.qmqm.pl
State New
Headers show
Series power: supply: bq25890: fix and extend | expand

Commit Message

Michał Mirosław April 2, 2020, 2:58 p.m. UTC
Export VBUS measurement via INPUT_VOLTAGE_NOW property.

Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
 drivers/power/supply/bq25890_charger.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
diff mbox series

Patch

diff --git a/drivers/power/supply/bq25890_charger.c b/drivers/power/supply/bq25890_charger.c
index 250468f3ff18..d23274d13263 100644
--- a/drivers/power/supply/bq25890_charger.c
+++ b/drivers/power/supply/bq25890_charger.c
@@ -506,6 +506,24 @@  static int bq25890_power_supply_get_property(struct power_supply *psy,
 		val->intval = bq25890_find_val(ret, TBL_IILIM);
 		break;
 
+	case POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW:
+		ret = bq25890_field_read(bq, F_VBUS_GD); /* is VBUS connected? */
+		if (ret < 0)
+			return ret;
+
+		if (!ret) {
+			val->intval = 0;
+			break;
+		}
+
+		ret = bq25890_field_read(bq, F_VBUSV); /* read measured value */
+		if (ret < 0)
+			return ret;
+
+		/* converted_val = 2.6V + ADC_val * 100mV */
+		val->intval = 2600000 + ret * 100000;
+		break;
+
 	case POWER_SUPPLY_PROP_VOLTAGE_NOW:
 		ret = bq25890_field_read(bq, F_SYSV); /* read measured value */
 		if (ret < 0)
@@ -705,6 +723,7 @@  static const enum power_supply_property bq25890_power_supply_props[] = {
 	POWER_SUPPLY_PROP_PRECHARGE_CURRENT,
 	POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT,
 	POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
+	POWER_SUPPLY_PROP_INPUT_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_VOLTAGE_NOW,
 	POWER_SUPPLY_PROP_CURRENT_NOW,
 };