diff mbox series

[3/4] usb: typec: tps6598x: Add the extcon USB chargers

Message ID 20200914164639.1487650-4-angus@akkea.ca
State New
Headers show
Series RFC: USB C extcon patchset for the tps6598x | expand

Commit Message

Angus Ainslie Sept. 14, 2020, 4:46 p.m. UTC
Notify extcon devcies that the charge current has changed

Signed-off-by: Angus Ainslie <angus@akkea.ca>
---
 drivers/usb/typec/tps6598x.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/typec/tps6598x.c b/drivers/usb/typec/tps6598x.c
index 3b06d43c810d..d5aa58c9da0a 100644
--- a/drivers/usb/typec/tps6598x.c
+++ b/drivers/usb/typec/tps6598x.c
@@ -240,17 +240,25 @@  static void tps6589x_set_extcon_state(struct tps6598x *tps,
 			    EXTCON_PROP_USB_VBUS_SRC,
 			    val);
 
+	extcon_set_state(tps->edev, EXTCON_CHG_USB_SDP, 0);
+	extcon_set_state(tps->edev, EXTCON_CHG_USB_DCP, 0);
+	extcon_set_state(tps->edev, EXTCON_CHG_USB_CDP, 0);
+	extcon_set_state(tps->edev, EXTCON_CHG_USB_SLOW, 0);
+	extcon_set_state(tps->edev, EXTCON_CHG_USB_FAST, 0);
+
 	switch (TPS_POWER_STATUS_PWROPMODE(pwr_status)) {
 	case TYPEC_PWR_MODE_USB:
-		max_current = 500;
+		max_current = val.intval = 500;
 		extcon_set_state(tps->edev, EXTCON_CHG_USB_SDP, state);
 		extcon_set_state(tps->edev, EXTCON_CHG_USB_SLOW, state);
 		break;
 	case TYPEC_PWR_MODE_1_5A:
-		max_current = 1500;
+		max_current = val.intval = 1500;
+		extcon_set_state(tps->edev, EXTCON_CHG_USB_CDP, state);
 		break;
 	case TYPEC_PWR_MODE_3_0A:
-		max_current = 3000;
+		max_current = val.intval = 3000;
+		extcon_set_state(tps->edev, EXTCON_CHG_USB_CDP, state);
 		break;
 	case TYPEC_PWR_MODE_PD:
 		max_current = 500;
@@ -265,10 +273,14 @@  static void tps6589x_set_extcon_state(struct tps6598x *tps,
 			    EXTCON_PROP_USB_VBUS_CURRENT,
 			    val);
 
-	extcon_sync(tps->edev, EXTCON_USB);
-	extcon_sync(tps->edev, EXTCON_USB_HOST);
 	extcon_sync(tps->edev, EXTCON_CHG_USB_SDP);
+	extcon_sync(tps->edev, EXTCON_CHG_USB_CDP);
+	extcon_sync(tps->edev, EXTCON_CHG_USB_DCP);
 	extcon_sync(tps->edev, EXTCON_CHG_USB_SLOW);
+	extcon_sync(tps->edev, EXTCON_CHG_USB_FAST);
+	/* do these last for extcon notifiers */
+	extcon_sync(tps->edev, EXTCON_USB);
+	extcon_sync(tps->edev, EXTCON_USB_HOST);
 }
 #endif
 
@@ -562,6 +574,8 @@  static const unsigned int tps6598x_extcon_cable[] = {
 	EXTCON_USB,
 	EXTCON_USB_HOST,
 	EXTCON_CHG_USB_SDP,
+	EXTCON_CHG_USB_CDP,
+	EXTCON_CHG_USB_DCP,
 	EXTCON_CHG_USB_SLOW,
 	EXTCON_CHG_USB_FAST,
 	EXTCON_NONE,