Hi Heikki, On Tue, Aug 22, 2023 at 6:32 AM Heikki Krogerus <heikki.krogerus@xxxxxxxxxxxxxxx> wrote: > > Hi Benson, > > RFC for now. I can't test these properly. If you guys could take over > this, I would much appreciated. I hope this is at least close to your > proposal. > > With this (or something like it) you should be able to get > notification about USB connections and disconnections to your port > driver by implementing the new "attach" and "deattach" callbacks in > struct typec_partner_desc. The typec partner devices will also have > symlinks to the enumerated USB devices and vise versa. > > I took a little shortcut and did not implement a proper device list. > Instead there is now only a member for the USB2 device and a member > for the USB3 device in struct typec_port, so with this only USB is > supported. But the API does not deal with struct usb_device, so > extending this to support other devices (TBT, Displayport, etc.) by > adding the actual device list should be fairly easy. > > thanks, > > Heikki Krogerus (2): > usb: typec: Link enumerated USB devices with Type-C partner > usb: Inform the USB Type-C class about enumerated devices > > drivers/usb/core/hub.c | 4 ++ > drivers/usb/core/hub.h | 3 + > drivers/usb/core/port.c | 19 +++++- > drivers/usb/typec/class.c | 108 +++++++++++++++++++++++++++++--- > drivers/usb/typec/class.h | 16 +++++ > drivers/usb/typec/port-mapper.c | 9 ++- > include/linux/usb/typec.h | 37 +++++++++++ > 7 files changed, 184 insertions(+), 12 deletions(-) > > -- > 2.40.1 > Tested-by: Benson Leung <bleung@xxxxxxxxxxxx> I picked these two changes back to my Brya/Redrix Chromebook which has the PLD changes to link subsystems. First I plugged in a USB-C to USB-A receptacle adapter with a USB3 thumbdrive into port0, and went to the port0-partner path. redrix-rev3 /sys/class/typec/port0-partner # ls -lh total 0 lrwxrwxrwx. 1 root root 0 Aug 22 17:16 2-1 -> ../../../../../../../0000:00:0d.0/usb2/2-1 -r--r--r--. 1 root root 4.0K Aug 22 17:14 accessory_mode lrwxrwxrwx. 1 root root 0 Aug 22 17:14 device -> ../../port0 drwxr-xr-x. 2 root root 0 Aug 22 17:14 identity drwxr-xr-x. 2 root root 0 Aug 22 17:14 power lrwxrwxrwx. 1 root root 0 Aug 22 17:14 subsystem -> ../../../../../../../../../class/typec -r--r--r--. 1 root root 4.0K Aug 22 17:14 supports_usb_power_delivery -r--r--r--. 1 root root 4.0K Aug 22 17:14 type -rw-r--r--. 1 root root 4.0K Aug 22 17:14 uevent -r--r--r--. 1 root root 4.0K Aug 22 17:14 usb_power_delivery_revision 2-1 symlink appears, which is the SuperSpeed usb device associated with the thumbdrive. Unplugging the USB3 thumbdrive without unplugging the C-to-A adapter, and then plugging in a USB2.0 security key: redrix-rev3 /sys/class/typec/port0-partner # ls -lh total 0 lrwxrwxrwx. 1 root root 0 Aug 22 17:19 3-1 -> ../../../../../../../0000:00:14.0/usb3/3-1 -r--r--r--. 1 root root 4.0K Aug 22 17:14 accessory_mode lrwxrwxrwx. 1 root root 0 Aug 22 17:14 device -> ../../port0 drwxr-xr-x. 2 root root 0 Aug 22 17:14 identity drwxr-xr-x. 2 root root 0 Aug 22 17:14 power lrwxrwxrwx. 1 root root 0 Aug 22 17:14 subsystem -> ../../../../../../../../../class/typec -r--r--r--. 1 root root 4.0K Aug 22 17:14 supports_usb_power_delivery -r--r--r--. 1 root root 4.0K Aug 22 17:14 type -rw-r--r--. 1 root root 4.0K Aug 22 17:14 uevent -r--r--r--. 1 root root 4.0K Aug 22 17:14 usb_power_delivery_revision 2-1 node disappears. 3-1 appears Unplugging the adapter, plugging in a USB4 hub: redrix-rev3 /sys/class/typec/port0-partner # ls -lh total 0 lrwxrwxrwx. 1 root root 0 Aug 22 17:21 2-1 -> ../../../../../../../0000:00:0d.0/usb2/2-1 lrwxrwxrwx. 1 root root 0 Aug 22 17:21 3-1 -> ../../../../../../../0000:00:14.0/usb3/3-1 -r--r--r--. 1 root root 4.0K Aug 22 17:21 accessory_mode lrwxrwxrwx. 1 root root 0 Aug 22 17:21 device -> ../../port0 drwxr-xr-x. 2 root root 0 Aug 22 17:21 identity -r--r--r--. 1 root root 4.0K Aug 22 17:21 number_of_alternate_modes drwxr-xr-x. 5 root root 0 Aug 22 17:21 pd0 drwxr-xr-x. 4 root root 0 Aug 22 17:21 port0-partner.0 drwxr-xr-x. 2 root root 0 Aug 22 17:21 power lrwxrwxrwx. 1 root root 0 Aug 22 17:21 subsystem -> ../../../../../../../../../class/typec -r--r--r--. 1 root root 4.0K Aug 22 17:21 supports_usb_power_delivery -r--r--r--. 1 root root 4.0K Aug 22 17:21 type -rw-r--r--. 1 root root 4.0K Aug 22 17:21 uevent lrwxrwxrwx. 1 root root 0 Aug 22 17:21 usb_power_delivery -> pd0 -r--r--r--. 1 root root 4.0K Aug 22 17:21 usb_power_delivery_revision Both 2-1 and 3-1 are linked. Thanks so much for this, Heikki! I can look a little closer at the attach and deattach callbacks in our typec port driver in a little while. Benson -- Benson Leung Staff Software Engineer Chrome OS Kernel Google Inc. bleung@xxxxxxxxxx Chromium OS Project bleung@xxxxxxxxxxxx