Skip to contentSkip to conversation

usb: typec: ucsi: Support for DisplayPort alt mode

PATCH In review Heikki Krogerus 1 participant 1 message Apr 23, 2019

Subsystems (2)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

PATCH v4 5/7 usb: typec: ucsi: Support for DisplayPort alt mode

This makes it possible to bind a driver to a DisplayPort alt mode adapter devices.

The driver attempts to cope with the limitations of UCSI by "emulating" behaviour and attempting to guess things when ever possible in order to satisfy the requirements the standard DisplayPort alt mode driver has.

---
 drivers/usb/typec/ucsi/Makefile      |  15 +-
 drivers/usb/typec/ucsi/displayport.c | 315 +++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.c        |  21 +-
 drivers/usb/typec/ucsi/ucsi.h        |  21 ++
 4 files changed, 364 insertions(+), 8 deletions(-)
 create mode 100644 drivers/usb/typec/ucsi/displayport.c
drivers/usb/typec/ucsi/Makefile +9 -6
index 2f4900b26210..b35e15a1f02c 100644
@@ -1,12 +1,15 @@
 # SPDX-License-Identifier: GPL-2.0
-CFLAGS_trace.o			:= -I$(src)
+CFLAGS_trace.o				:= -I$(src)
 
-obj-$(CONFIG_TYPEC_UCSI)	+= typec_ucsi.o
+obj-$(CONFIG_TYPEC_UCSI)		+= typec_ucsi.o
 
-typec_ucsi-y			:= ucsi.o
+typec_ucsi-y				:= ucsi.o
 
-typec_ucsi-$(CONFIG_TRACING)	+= trace.o
+typec_ucsi-$(CONFIG_TRACING)		+= trace.o
 
-obj-$(CONFIG_UCSI_ACPI)		+= ucsi_acpi.o
+ifneq ($(CONFIG_TYPEC_DP_ALTMODE),)
+	typec_ucsi-y			+= displayport.o
+endif
 
-obj-$(CONFIG_UCSI_CCG)		+= ucsi_ccg.o
+obj-$(CONFIG_UCSI_ACPI)			+= ucsi_acpi.o
+obj-$(CONFIG_UCSI_CCG)			+= ucsi_ccg.o
drivers/usb/typec/ucsi/displayport.c new file +315 -0

315 lines not on this page · raw message

drivers/usb/typec/ucsi/ucsi.c +19 -2
index fcb9434f218a..b4fb2e05d2e5 100644
@@ -12,7 +12,7 @@
 #include <linux/module.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
-#include <linux/usb/typec_altmode.h>
+#include <linux/usb/typec_dp.h>
 
 #include "ucsi.h"
 #include "trace.h"
@@ -264,9 +264,12 @@ static int ucsi_register_altmode(struct ucsi_connector *con,
 				 u8 recipient)
 {
 	struct typec_altmode *alt;
+	bool override;
 	int ret;
 	int i;
 
+	override = !!(con->ucsi->cap.features & UCSI_CAP_ALT_MODE_OVERRIDE);
+
 	switch (recipient) {
 	case UCSI_RECIPIENT_CON:
 		i = ucsi_next_altmode(con->port_altmode);
@@ -278,7 +281,15 @@ static int ucsi_register_altmode(struct ucsi_connector *con,
 		desc->mode = ucsi_altmode_next_mode(con->port_altmode,
 						    desc->svid);
 
-		alt = typec_port_register_altmode(con->port, desc);
+		switch (desc->svid) {
+		case USB_TYPEC_DP_SID:
+			alt = ucsi_register_displayport(con, override, i, desc);
+			break;
+		default:
+			alt = typec_port_register_altmode(con->port, desc);
+			break;
+		}
+
 		if (IS_ERR(alt)) {
 			ret = PTR_ERR(alt);
 			goto err;
@@ -376,6 +387,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)
 
 static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
 {
+	const struct typec_altmode *pdev;
 	struct typec_altmode **adev;
 	int i = 0;
 
@@ -391,6 +403,11 @@ static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
 	}
 
 	while (adev[i]) {
+		if (recipient == UCSI_RECIPIENT_SOP &&
+		    adev[i]->svid == USB_TYPEC_DP_SID) {
+			pdev = typec_altmode_get_partner(adev[i]);
+			ucsi_displayport_remove_partner((void *)pdev);
+		}
 		typec_unregister_altmode(adev[i]);
 		adev[i++] = NULL;
 	}
drivers/usb/typec/ucsi/ucsi.h +21 -0
index 6cafa6b4a60a..1e2981aef629 100644
@@ -431,4 +431,25 @@ int ucsi_send_command(struct ucsi *ucsi, struct ucsi_control *ctrl,
 
 void ucsi_altmode_update_active(struct ucsi_connector *con);
 
+#if IS_ENABLED(CONFIG_TYPEC_DP_ALTMODE)
+struct typec_altmode *
+ucsi_register_displayport(struct ucsi_connector *con,
+			  bool override, int offset,
+			  struct typec_altmode_desc *desc);
+
+void ucsi_displayport_remove_partner(struct typec_altmode *adev);
+
+#else
+static inline struct typec_altmode *
+ucsi_register_displayport(struct ucsi_connector *con,
+			  bool override, int offset,
+			  struct typec_altmode_desc *desc)
+{
+	return NULL;
+}
+
+static inline void
+ucsi_displayport_remove_partner(struct typec_altmode *adev) { }
+#endif /* CONFIG_TYPEC_DP_ALTMODE */
+
 #endif /* __DRIVER_USB_TYPEC_UCSI_H */