From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Sat, 2 Apr 2022 03:17:34 +0200
Subject: power: supply: ip5xxx: Add boost status property

Boost can be enabled, but actually off. Real status is reported by
POWER_SUPPLY_PROP_PRESENT property.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/power/supply/ip5xxx_power.c | 13 +++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/drivers/power/supply/ip5xxx_power.c b/drivers/power/supply/ip5xxx_power.c
index 6ef7708f45aa..b1f820efa741 100644
--- a/drivers/power/supply/ip5xxx_power.c
+++ b/drivers/power/supply/ip5xxx_power.c
@@ -44,6 +44,8 @@
 #define IP5XXX_GPIO_CTL2		0x53
 #define IP5XXX_GPIO_CTL2A		0x54
 #define IP5XXX_GPIO_CTL3		0x55
+#define IP5XXX_STATUS			0x70
+#define IP5XXX_STATUS_BOOST_ON			BIT(2)
 #define IP5XXX_READ0			0x71
 #define IP5XXX_READ0_CHG_STAT			GENMASK(7, 5)
 #define IP5XXX_READ0_CHG_STAT_IDLE		(0x0 << 5)
@@ -539,6 +541,7 @@ static const struct power_supply_desc ip5xxx_battery_desc = {
 
 static const enum power_supply_property ip5xxx_boost_properties[] = {
 	POWER_SUPPLY_PROP_ONLINE,
+	POWER_SUPPLY_PROP_PRESENT,
 	POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN,
 };
 
@@ -563,6 +566,14 @@ static int ip5xxx_boost_get_property(struct power_supply *psy,
 		val->intval = !!(rval & IP5XXX_SYS_CTL0_BOOST_EN);
 		return 0;
 
+	case POWER_SUPPLY_PROP_PRESENT:
+		ret = ip5xxx_read(ip5xxx, IP5XXX_STATUS, &rval);
+		if (ret)
+			return ret;
+
+		val->intval = !!(rval & IP5XXX_STATUS_BOOST_ON);
+		return 0;
+
 	case POWER_SUPPLY_PROP_VOLTAGE_MIN_DESIGN:
 		ret = ip5xxx_read(ip5xxx, IP5XXX_CHG_CTL1, &rval);
 		if (ret)
@@ -608,7 +619,7 @@ static int ip5xxx_boost_set_property(struct power_supply *psy,
 static int ip5xxx_boost_property_is_writeable(struct power_supply *psy,
 					      enum power_supply_property psp)
 {
-	return true;
+	return psp != POWER_SUPPLY_PROP_PRESENT;
 }
 
 static const struct power_supply_desc ip5xxx_boost_desc = {
-- 
Armbian

