drivers/usb/misc/onboard_usb_dev_pdevs.c
Source file repositories/reference/linux-study-clean/drivers/usb/misc/onboard_usb_dev_pdevs.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/misc/onboard_usb_dev_pdevs.c- Extension
.c- Size
- 4467 bytes
- Lines
- 145
- 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.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/device.hlinux/export.hlinux/kernel.hlinux/list.hlinux/of.hlinux/of_platform.hlinux/platform_device.hlinux/usb.hlinux/usb/hcd.hlinux/usb/of.hlinux/usb/onboard_dev.honboard_usb_dev.h
Detected Declarations
struct pdev_list_entryfunction of_is_onboard_usb_devfunction devicefunction onboard_dev_destroy_pdevsfunction list_for_each_entry_safeexport onboard_dev_create_pdevsexport onboard_dev_destroy_pdevs
Annotated Snippet
struct pdev_list_entry {
struct platform_device *pdev;
struct list_head node;
};
static bool of_is_onboard_usb_dev(struct device_node *np)
{
return !!of_match_node(onboard_dev_match, np);
}
/**
* onboard_dev_create_pdevs -- create platform devices for onboard USB devices
* @parent_hub : parent hub to scan for connected onboard devices
* @pdev_list : list of onboard platform devices owned by the parent hub
*
* Creates a platform device for each supported onboard device that is connected
* to the given parent hub. The platform device is in charge of initializing the
* device (enable regulators, take the device out of reset, ...). For onboard
* hubs, it can optionally control whether the device remains powered during
* system suspend or not.
*
* To keep track of the platform devices they are added to a list that is owned
* by the parent hub.
*
* Some background about the logic in this function, which can be a bit hard
* to follow:
*
* Root hubs don't have dedicated device tree nodes, but use the node of their
* HCD. The primary and secondary HCD are usually represented by a single DT
* node. That means the root hubs of the primary and secondary HCD share the
* same device tree node (the HCD node). As a result this function can be called
* twice with the same DT node for root hubs. We only want to create a single
* platform device for each physical onboard device, hence for root hubs the
* loop is only executed for the root hub of the primary HCD. Since the function
* scans through all child nodes it still creates pdevs for onboard devices
* connected to the root hub of the secondary HCD if needed.
*
* Further there must be only one platform device for onboard hubs with a peer
* hub (the hub is a single physical device). To achieve this two measures are
* taken: pdevs for onboard hubs with a peer are only created when the function
* is called on behalf of the parent hub that is connected to the primary HCD
* (directly or through other hubs). For onboard hubs connected to root hubs
* the function processes the nodes of both peers. A platform device is only
* created if the peer hub doesn't have one already.
*/
void onboard_dev_create_pdevs(struct usb_device *parent_hub, struct list_head *pdev_list)
{
int i;
struct usb_hcd *hcd = bus_to_hcd(parent_hub->bus);
struct device_node *np, *npc;
struct platform_device *pdev;
struct pdev_list_entry *pdle;
if (!parent_hub->dev.of_node)
return;
if (!parent_hub->parent && !usb_hcd_is_primary_hcd(hcd))
return;
for (i = 1; i <= parent_hub->maxchild; i++) {
np = usb_of_get_device_node(parent_hub, i);
if (!np)
continue;
if (!of_is_onboard_usb_dev(np))
goto node_put;
npc = of_parse_phandle(np, "peer-hub", 0);
if (npc) {
if (!usb_hcd_is_primary_hcd(hcd)) {
of_node_put(npc);
goto node_put;
}
pdev = of_find_device_by_node(npc);
of_node_put(npc);
if (pdev) {
put_device(&pdev->dev);
goto node_put;
}
}
pdev = of_platform_device_create(np, NULL, &parent_hub->dev);
if (!pdev) {
dev_err(&parent_hub->dev,
"failed to create platform device for onboard dev '%pOF'\n", np);
goto node_put;
}
Annotation
- Immediate include surface: `linux/device.h`, `linux/export.h`, `linux/kernel.h`, `linux/list.h`, `linux/of.h`, `linux/of_platform.h`, `linux/platform_device.h`, `linux/usb.h`.
- Detected declarations: `struct pdev_list_entry`, `function of_is_onboard_usb_dev`, `function device`, `function onboard_dev_destroy_pdevs`, `function list_for_each_entry_safe`, `export onboard_dev_create_pdevs`, `export onboard_dev_destroy_pdevs`.
- 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.