Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

usb: typec: altmodes/displayport: Notify drm subsys of hotplug events

Use the new drm_connector_oob_hotplug_event() functions to let drm/kms
drivers know about DisplayPort over Type-C hotplug events.

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Tested-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Reviewed-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Reviewed-by: Lyude Paul <lyude@redhat.com>
Link: https://lore.kernel.org/r/20210817215201.795062-9-hdegoede@redhat.com

+24
+1
drivers/usb/typec/altmodes/Kconfig
··· 4 4 5 5 config TYPEC_DP_ALTMODE 6 6 tristate "DisplayPort Alternate Mode driver" 7 + depends on DRM 7 8 help 8 9 DisplayPort USB Type-C Alternate Mode allows DisplayPort 9 10 displays and adapters to be attached to the USB Type-C
+23
drivers/usb/typec/altmodes/displayport.c
··· 11 11 #include <linux/delay.h> 12 12 #include <linux/mutex.h> 13 13 #include <linux/module.h> 14 + #include <linux/property.h> 14 15 #include <linux/usb/pd_vdo.h> 15 16 #include <linux/usb/typec_dp.h> 17 + #include <drm/drm_connector.h> 16 18 #include "displayport.h" 17 19 18 20 #define DP_HEADER(_dp, ver, cmd) (VDO((_dp)->alt->svid, 1, ver, cmd) \ ··· 59 57 struct typec_displayport_data data; 60 58 61 59 enum dp_state state; 60 + bool hpd; 62 61 63 62 struct mutex lock; /* device lock */ 64 63 struct work_struct work; 65 64 struct typec_altmode *alt; 66 65 const struct typec_altmode *port; 66 + struct fwnode_handle *connector_fwnode; 67 67 }; 68 68 69 69 static int dp_altmode_notify(struct dp_altmode *dp) ··· 129 125 static int dp_altmode_status_update(struct dp_altmode *dp) 130 126 { 131 127 bool configured = !!DP_CONF_GET_PIN_ASSIGN(dp->data.conf); 128 + bool hpd = !!(dp->data.status & DP_STATUS_HPD_STATE); 132 129 u8 con = DP_STATUS_CONNECTION(dp->data.status); 133 130 int ret = 0; 134 131 ··· 142 137 ret = dp_altmode_configure(dp, con); 143 138 if (!ret) 144 139 dp->state = DP_STATE_CONFIGURE; 140 + } else { 141 + if (dp->hpd != hpd) { 142 + drm_connector_oob_hotplug_event(dp->connector_fwnode); 143 + dp->hpd = hpd; 144 + } 145 145 } 146 146 147 147 return ret; ··· 522 512 int dp_altmode_probe(struct typec_altmode *alt) 523 513 { 524 514 const struct typec_altmode *port = typec_altmode_get_partner(alt); 515 + struct fwnode_handle *fwnode; 525 516 struct dp_altmode *dp; 526 517 int ret; 527 518 ··· 551 540 alt->desc = "DisplayPort"; 552 541 alt->ops = &dp_altmode_ops; 553 542 543 + fwnode = dev_fwnode(alt->dev.parent->parent); /* typec_port fwnode */ 544 + dp->connector_fwnode = fwnode_find_reference(fwnode, "displayport", 0); 545 + if (IS_ERR(dp->connector_fwnode)) 546 + dp->connector_fwnode = NULL; 547 + 554 548 typec_altmode_set_drvdata(alt, dp); 555 549 556 550 dp->state = DP_STATE_ENTER; ··· 571 555 572 556 sysfs_remove_group(&alt->dev.kobj, &dp_altmode_group); 573 557 cancel_work_sync(&dp->work); 558 + 559 + if (dp->connector_fwnode) { 560 + if (dp->hpd) 561 + drm_connector_oob_hotplug_event(dp->connector_fwnode); 562 + 563 + fwnode_handle_put(dp->connector_fwnode); 564 + } 574 565 } 575 566 EXPORT_SYMBOL_GPL(dp_altmode_remove); 576 567