[PATCH] usb: core: support interface node for simple USB devices

Catalin Popescu
2025-01-22T13:47:41Z

A simple usb device has a single configuration and a single interface
and is considered as a "combined node" when defined in the devicetree.
If available, its interface node is simply ignored which is a problem
whenever the interface node has subnodes. To prevent that from happening
first check for any subnode and ignore the interface node only if no
subnode was found.

Example: FTDI chip FT234XD that has only one UART interface which is
being used as a serdev by other driver.

device@1 {
compatible = "usb403,6015";
reg = <1>;

#address-cells = <2>;
#size-cells = <0>;

interface@0 {
compatible = "usbif403,6015.config1.0";
reg = <0 1>;

bluetooth {
compatible = "nxp,88w8987-bt";
};
};
};

Signed-off-by: Catalin Popescu <catalin.popescu@leica-geosystems.com>
---
drivers/usb/core/message.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
index d2b2787be409..f4a9d1831f6a 100644
--- a/drivers/usb/core/message.c
+++ b/drivers/usb/core/message.c
@@ -2102,6 +2102,7 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
struct usb_interface_cache *intfc;
struct usb_interface *intf;
struct usb_host_interface *alt;
+ struct device_node *np;
u8 ifnum;

cp->interface[i] = intf = new_interfaces[i];
@@ -2126,12 +2127,11 @@ int usb_set_configuration(struct usb_device *dev, int configuration)
intf->cur_altsetting = alt;
usb_enable_interface(dev, intf, true);
intf->dev.parent = &dev->dev;
- if (usb_of_has_combined_node(dev)) {
+ np = usb_of_get_interface_node(dev, configuration, ifnum);
+ if (!of_get_child_count(np) && usb_of_has_combined_node(dev))
device_set_of_node_from_dev(&intf->dev, &dev->dev);
- } else {
- intf->dev.of_node = usb_of_get_interface_node(dev,
- configuration, ifnum);
- }
+ else
+ intf->dev.of_node = np;
ACPI_COMPANION_SET(&intf->dev, ACPI_COMPANION(&dev->dev));
intf->dev.driver = NULL;
intf->dev.bus = &usb_bus_type;

base-commit: f066b5a6c7a06adfb666b7652cc99b4ff264f4ed
--
2.34.1