Re: [PATCH] usb: typec: hd3ss3220: Add sysfs attribute for USB role state

From: Heikki Krogerus

Date: Mon Mar 02 2026 - 05:46:33 EST


The HD3SS3220 driver correctly detects USB Type-C cable attach/detach
events and propagates the role to the USB controller. However, there is
no way for userspace to query the current role state (device/host/none).

This becomes problematic when using udev rules to trigger scripts on
role changes. The driver generates kobject change events, but the event
itself doesn't contain the role information. Userspace needs to read
the current state to determine the appropriate action.

Add a 'usb_role' sysfs attribute that exposes the current USB role as
a string ("device", "host", or "none"). Also ensure sysfs_notify() and
kobject_uevent() are called when the role changes, enabling userspace
applications to poll() on the sysfs file or receive udev events.

This is useful for systems that need to:
- Start/stop USB gadget functions based on cable connection
- Switch between host and device modes dynamically
- Monitor USB Type-C port state from userspace
You use the "data_role" sysfs attribute file for this.

--
heikki