Skip to contentSkip to conversation

usb: typec: ucsi: Support for DisplayPort alt mode

PATCH New Heikki Krogerus 1 participant 1 message Feb 1, 2019

Subsystems (2)
lore
Share & tools
lore

Heikki Krogerus

author maintainer
#0 lore raw

PATCH 5/5 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 | 301 +++++++++++++++++++++++++++
 drivers/usb/typec/ucsi/ucsi.c        |  22 +-
 drivers/usb/typec/ucsi/ucsi.h        |  21 ++
 4 files changed, 351 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 +301 -0

301 lines not on this page · raw message

drivers/usb/typec/ucsi/ucsi.c +20 -2
index 5190f8dd4548..760d69eaa029 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"
@@ -288,9 +288,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);
@@ -302,7 +305,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;
@@ -398,6 +409,7 @@ static int ucsi_register_altmodes(struct ucsi_connector *con, u8 recipient)
 static void ucsi_unregister_altmodes(struct ucsi_connector *con, u8 recipient)
 {
 	struct typec_altmode **adev;
+	struct typec_altmode *alt;
 	int i = 0;
 
 	switch (recipient) {
@@ -412,6 +424,12 @@ 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) {
+			alt = typec_match_altmode(con->port_altmode, -1,
+						  USB_TYPEC_DP_SID, 1);
+			ucsi_displayport_remove_partner(alt);
+		}
 		typec_unregister_altmode(adev[i]);
 		adev[i++] = NULL;
 	}
drivers/usb/typec/ucsi/ucsi.h +21 -0
index c416bae4b5ca..036ebf256cdd 100644
@@ -406,4 +406,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 */