drivers/usb/core/of.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/of.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/of.c- Extension
.c- Size
- 4906 bytes
- Lines
- 177
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/of.hlinux/of_graph.hlinux/usb/of.h
Detected Declarations
function Copyrightfunction for_each_child_of_nodefunction usb_of_has_combined_nodefunction usb_of_has_devices_or_graphfunction usb_of_get_connect_typefunction usb_of_get_interface_nodefunction for_each_child_of_nodeexport usb_of_get_device_nodeexport usb_of_has_combined_nodeexport usb_of_get_connect_typeexport usb_of_get_interface_node
Annotated Snippet
if (ddesc->bNumConfigurations == 1) {
cdesc = &udev->config->desc;
if (cdesc->bNumInterfaces == 1)
return true;
}
}
return false;
}
EXPORT_SYMBOL_GPL(usb_of_has_combined_node);
static bool usb_of_has_devices_or_graph(const struct usb_device *hub)
{
const struct device_node *np = hub->dev.of_node;
if (of_graph_is_present(np))
return true;
for_each_child_of_node_scoped(np, child)
if (of_property_present(child, "reg"))
return true;
return false;
}
/**
* usb_of_get_connect_type() - get a USB hub's port connect_type
* @hub: hub to which port is for @port1
* @port1: one-based index of port
*
* Get the connect_type of @port1 based on the device node for @hub. If the
* port is described in the OF graph, the connect_type is "hotplug". If the
* @hub has a child device has with a 'reg' property equal to @port1 the
* connect_type is "hard-wired". If there isn't an OF graph or child node at
* all then the connect_type is "unknown". Otherwise, the port is considered
* "unused" because it isn't described at all.
*
* Return: A connect_type for @port1 based on the device node for @hub.
*/
enum usb_port_connect_type usb_of_get_connect_type(struct usb_device *hub, int port1)
{
struct device_node *np, *child, *ep, *remote_np;
enum usb_port_connect_type connect_type;
/* Only set connect_type if binding has ports/hardwired devices. */
if (!usb_of_has_devices_or_graph(hub))
return USB_PORT_CONNECT_TYPE_UNKNOWN;
/* Assume port is unused if there's a graph or a child node. */
connect_type = USB_PORT_NOT_USED;
np = hub->dev.of_node;
/*
* Hotplug ports are connected to an available remote node, e.g.
* usb-a-connector compatible node, in the OF graph.
*/
if (of_graph_is_present(np)) {
ep = of_graph_get_endpoint_by_regs(np, port1, -1);
if (ep) {
remote_np = of_graph_get_remote_port_parent(ep);
of_node_put(ep);
if (of_device_is_available(remote_np))
connect_type = USB_PORT_CONNECT_TYPE_HOT_PLUG;
of_node_put(remote_np);
}
}
/*
* Hard-wired ports are child nodes with a reg property corresponding
* to the port number, i.e. a usb device.
*/
child = usb_of_get_device_node(hub, port1);
if (of_device_is_available(child))
connect_type = USB_PORT_CONNECT_TYPE_HARD_WIRED;
of_node_put(child);
return connect_type;
}
EXPORT_SYMBOL_GPL(usb_of_get_connect_type);
/**
* usb_of_get_interface_node() - get a USB interface node
* @udev: USB device of interface
* @config: configuration value
* @ifnum: interface number
*
* Look up the node of a USB interface given its USB device, configuration
* value and interface number.
*
* Return: A pointer to the node with incremented refcount if found, or
Annotation
- Immediate include surface: `linux/of.h`, `linux/of_graph.h`, `linux/usb/of.h`.
- Detected declarations: `function Copyright`, `function for_each_child_of_node`, `function usb_of_has_combined_node`, `function usb_of_has_devices_or_graph`, `function usb_of_get_connect_type`, `function usb_of_get_interface_node`, `function for_each_child_of_node`, `export usb_of_get_device_node`, `export usb_of_has_combined_node`, `export usb_of_get_connect_type`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.