From 7e29e37e98bc9514f7072b8ff0fb32e81186c0cd Mon Sep 17 00:00:00 2001
From: Ondrej Jirman <megi@xff.cz>
Date: Thu, 9 Feb 2023 20:33:50 +0100
Subject: [PATCH 349/463] usb: typec: typec-extcon: Allow to force reset on
 each mux change

This may help with some Alt-DP USB adapters.

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

diff --git a/drivers/usb/typec/typec-extcon.c b/drivers/usb/typec/typec-extcon.c
index f617e90b71a09..81fc4114bc598 100644
--- a/drivers/usb/typec/typec-extcon.c
+++ b/drivers/usb/typec/typec-extcon.c
@@ -19,6 +19,10 @@
 #include <linux/usb/typec_mux.h>
 #include <linux/extcon-provider.h>
 
+static bool reset_on_mux;
+module_param(reset_on_mux, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(reset_on_mux, "Set DP=0 on each type-c mux change");
+
 struct typec_extcon {
         struct device *dev;
 
@@ -162,6 +166,17 @@ static int typec_extcon_mux_set(struct typec_mux_dev *mux,
 		dev_dbg(tce->dev, "      ...alt: svid=%04hx mode=%d vdo=%08x active=%u\n",
 			alt->svid, alt->mode, alt->vdo, alt->active);
 
+        mutex_lock(&tce->lock);
+	if (reset_on_mux && alt != NULL && tce->has_alt) {
+		tce->mode = state->mode;
+		tce->has_alt = false;
+		mutex_unlock(&tce->lock);
+
+		typec_extcon_sync_extcon(tce);
+	} else {
+		mutex_unlock(&tce->lock);
+	}
+
         mutex_lock(&tce->lock);
 	tce->mode = state->mode;
 	tce->has_alt = alt != NULL;
-- 
2.46.0

