Battery uevent must be Discharging when input suspended.

When we specify echo 1 > /d/google_charger/input_suspend
to stop charging we expect that the battery uevent to report that the
device is "Discharging" rather than Charging. We ensure this by
modifying sw5100_bms to mark when we disable charge as discharging
rather than not charging when usb is suspended.

Bug: 248085252
Test: Confirm that input suspend results in Discharging
Signed-off-by: Brandon Edens <[email protected]>
Change-Id: I311bb88dcf43b761e3679d2a6abcac9bec0e9fef
diff --git a/sw5100_bms.c b/sw5100_bms.c
index c8b00a6..3e6f6db 100644
--- a/sw5100_bms.c
+++ b/sw5100_bms.c
@@ -114,6 +114,9 @@
 
 #define CHGR_BATTERY_CHARGER_STATUS_MASK	GENMASK(2, 0)
 
+#define CHGR_USB_SUSPEND			0x2954
+#define USBIN_SUSPEND BIT(0)
+
 #define CHGR_FLOAT_VOLTAGE_BASE			3600000
 #define CHGR_CHARGE_CURRENT_STEP		25000
 
@@ -591,6 +594,7 @@
 	int vchrg = 0;
 	int vlimit = bms->chg_term_voltage;
 	u8 pstat, stat1, stat2;
+	u8 suspend;
 
 	rc = sw5100_rd8(bms->pmic_regmap, DCDC_POWER_PATH_STATUS_REG, &pstat);
 	if (rc < 0)
@@ -644,7 +648,14 @@
 		break;
 	/* disabled disconnect */
 	case SW5100_DISABLE_CHARGE:
-		ret = POWER_SUPPLY_STATUS_NOT_CHARGING;
+		rc = sw5100_rd8(bms->pmic_regmap, CHGR_USB_SUSPEND, &suspend);
+		if (rc < 0)
+			return POWER_SUPPLY_STATUS_UNKNOWN;
+		if ((suspend & USBIN_SUSPEND) == USBIN_SUSPEND) {
+			ret = POWER_SUPPLY_STATUS_DISCHARGING;
+		} else {
+			ret = POWER_SUPPLY_STATUS_NOT_CHARGING;
+		}
 		break;
 	default:
 		ret = POWER_SUPPLY_STATUS_UNKNOWN;