Skip to content

USB class: support multiple USB host controllers#100703

Merged
fabiobaltieri merged 1 commit intozephyrproject-rtos:mainfrom
josuah:usbh_multi_uhc
Feb 18, 2026
Merged

USB class: support multiple USB host controllers#100703
fabiobaltieri merged 1 commit intozephyrproject-rtos:mainfrom
josuah:usbh_multi_uhc

Conversation

@josuah
Copy link
Copy Markdown
Contributor

@josuah josuah commented Dec 8, 2025

Dependencies:

Do not bind an USB host controller context during init.
Instead only use the c_data->udev = udev; assignment that happens in probe() to give the class the USB context.

This means that class can be used by a controller or another depending on which side the USB device is connected, and this shares resources between the ports.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 8, 2025

@carlescufi carlescufi mentioned this pull request Jan 22, 2026
18 tasks
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 7, 2026

This pull request has been marked as stale because it has been open (more than) 60 days with no activity. Remove the stale label or add a comment saying that you would like to have the label removed otherwise this pull request will automatically be closed in 14 days. Note, that you can always re-open a closed pull request at any time.

@github-actions github-actions Bot added the Stale label Feb 7, 2026
@josuah josuah removed the Stale label Feb 7, 2026
@josuah josuah force-pushed the usbh_multi_uhc branch 2 times, most recently from 551f7e3 to 423c266 Compare February 7, 2026 02:03
@josuah josuah marked this pull request as ready for review February 7, 2026 02:06
Comment thread subsys/usb/host/usbh_class.c
@zephyrbot zephyrbot added area: USB Universal Serial Bus area: Tests Issues related to a particular existing or missing test labels Feb 7, 2026
Comment thread include/zephyr/usb/usbh.h
/** Host initialization handler, before any device is connected */
int (*init)(struct usbh_class_data *const c_data,
struct usbh_context *const uhs_ctx);
int (*init)(struct usbh_class_data *const c_data);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only bind to a controller after probing.

Something like c_data->uhs_ctx = udev->ctx; is missed here

c_node->state = USBH_CLASS_STATE_BOUND;
c_data->udev = udev;
c_data->iface = iface;

Also, c_data->uhs_ctx seems to be redundant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to remove the redundacy by removing the uhs_ctx field, available from udev->ctx.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need a helper to get the host support context, like

diff --git a/subsys/usb/host/usbh_class.h b/subsys/usb/host/usbh_class.h
index 0b3d673c058..eb005b0922e 100644
--- a/subsys/usb/host/usbh_class.h
+++ b/subsys/usb/host/usbh_class.h
@@ -60,4 +60,13 @@ void usbh_class_probe_device(struct usb_device *const udev);
  */
 void usbh_class_remove_all(struct usb_device *const udev);
 
+static inline struct usbh_context *usbh_class_get_ctx(struct usbh_class_data *const c_data)
+{
+	if (c_data->udev != NULL) {
+		return c_data->udev->ctx;
+	}
+
+	return NULL;
+}
+
 #endif /* ZEPHYR_INCLUDE_USBH_CLASS_H */

Copy link
Copy Markdown
Contributor Author

@josuah josuah Feb 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added and rebased on top of latest main.

Edit: that was not the intent to add it now, so removed it in order to keep it for later.

Comment thread tests/subsys/usb/host/src/class.c
jfischer-no
jfischer-no previously approved these changes Feb 16, 2026
Only bind to a controller after probing. Wait that a class is matching and
assigned to a device to assign a host controller to a class. This allows
a class to be used by any of the controller in place.
Remove the `c_data->uhs_ctx` field, not used anywhere, in favor of using
`c_data->udev->ctx`.

Signed-off-by: Josuah Demangeon <me@josuah.net>
@sonarqubecloud
Copy link
Copy Markdown

@fabiobaltieri fabiobaltieri merged commit 4360894 into zephyrproject-rtos:main Feb 18, 2026
28 checks passed
@josuah josuah deleted the usbh_multi_uhc branch March 31, 2026 18:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: Tests Issues related to a particular existing or missing test area: USB Universal Serial Bus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants