From 4e782d0f529ea1f1ae6a5c01f21cacc3903395c6 Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Fri, 15 Mar 2024 23:05:10 +0100
Subject: usb: typec: anx7688: Port to Linux 6.9

POWER_SUPPLY_PROP_USB_BC_ENABLED is no longer needed, nor supported
by axp20x driver.

Signed-off-by: Ondrej Jirman <megi@xff.cz>
---
 drivers/usb/typec/anx7688.c | 51 ++++---------------------------------
 1 file changed, 5 insertions(+), 46 deletions(-)

diff --git a/drivers/usb/typec/anx7688.c b/drivers/usb/typec/anx7688.c
index fa1d3496af73..77c154565340 100644
--- a/drivers/usb/typec/anx7688.c
+++ b/drivers/usb/typec/anx7688.c
@@ -636,14 +636,6 @@ static void anx7688_disconnect(struct anx7688 *anx7688)
 	if (ret)
 		dev_err(dev, "failed to offline vbus_in\n");
 
-	val.intval = 1;
-	dev_dbg(dev, "enabling USB BC 1.2 detection\n");
-	ret = power_supply_set_property(anx7688->vbus_in_supply,
-					POWER_SUPPLY_PROP_USB_BC_ENABLED,
-					&val);
-	if (ret)
-		dev_err(dev, "failed to enabled USB BC1.2 detection\n");
-
 	clear_bit(ANX7688_F_CONNECTED, anx7688->flags);
 }
 
@@ -1822,17 +1814,8 @@ static void anx7688_handle_current_update(struct anx7688* anx7688)
 
 	if (current_limit) {
 		/*
-		 * Disable BC1.2 detection, because we'll be setting
-		 * a current limit determined by USB-PD
+		 * Set a current limit determined by USB-PD
 		 */
-		val.intval = 0;
-		dev_dbg(dev, "disabling USB BC 1.2 detection\n");
-		ret = power_supply_set_property(anx7688->vbus_in_supply,
-						POWER_SUPPLY_PROP_USB_BC_ENABLED,
-						&val);
-		if (ret)
-			dev_err(dev, "failed to disable USB BC1.2 detection\n");
-
 		val.intval = current_limit * 1000;
 		dev_dbg(dev, "setting vbus_in current limit to %d mA\n", current_limit);
 		ret = power_supply_set_property(anx7688->vbus_in_supply,
@@ -1846,27 +1829,13 @@ static void anx7688_handle_current_update(struct anx7688* anx7688)
 		 * Use the result of BC1.2 detection performed by PMIC.
 		 */
 		ret = power_supply_get_property(anx7688->vbus_in_supply,
-						POWER_SUPPLY_PROP_USB_BC_ENABLED,
+						POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
 						&val);
 		if (ret)
-			dev_err(dev, "failed to get USB BC1.2 detection status\n");
-
-		if (ret != 0 || val.intval == 0) {
-			/*
-			 * If BC is disabled or we can't get its status,
-			 * set conservative 500mA limit. Otherwise leave
-			 * the limit to BC1.2.
-			 */
-			val.intval = 500 * 1000;
-			dev_dbg(dev, "setting vbus_in current limit to %d mA\n",
+			dev_err(dev, "failed to get vbus_in current limit\n");
+		if (ret == 0)
+			dev_dbg(dev, "vbus_in current limit is %d mA\n",
 				val.intval / 1000);
-			ret = power_supply_set_property(anx7688->vbus_in_supply,
-							POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT,
-							&val);
-			if (ret)
-				dev_err(dev, "failed to set vbus_in current to %d mA\n",
-					val.intval / 1000);
-		}
 	}
 
 	/* Turn on VBUS power path inside PMIC. */
@@ -1932,7 +1901,6 @@ static int anx7688_i2c_probe(struct i2c_client *client)
 	struct anx7688 *anx7688;
 	struct device *dev = &client->dev;
 	struct typec_capability typec_cap = { };
-	union power_supply_propval psy_val;
 	int i, vid_h, vid_l;
 	int irq_cabledet;
 	int ret = 0;
@@ -2087,15 +2055,6 @@ static int anx7688_i2c_probe(struct i2c_client *client)
 
 	// make sure BC1.2 detection in PMIC is enabled
 	anx7688->last_bc_result = -1;
-	psy_val.intval = 1;
-	dev_dbg(dev, "enabling USB BC 1.2 detection\n");
-	ret = power_supply_set_property(anx7688->vbus_in_supply,
-					POWER_SUPPLY_PROP_USB_BC_ENABLED,
-					&psy_val);
-	if (ret) {
-		dev_err(anx7688->dev, "failed to enable BC1.2 detection\n");
-		goto err_cport;
-	}
 
 	ret = devm_request_irq(dev, irq_cabledet, anx7688_irq_plug_handler,
 			       IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING,
-- 
2.35.3

