drivers/usb/core/phy.c
Source file repositories/reference/linux-study-clean/drivers/usb/core/phy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/core/phy.c- Extension
.c- Size
- 8541 bytes
- Lines
- 372
- 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/list.hlinux/phy/phy.hlinux/of.hphy.h
Detected Declarations
struct usb_phy_roothubfunction usb_phy_roothub_add_phy_by_namefunction usb_phy_roothub_add_phyfunction usb_phy_roothub_initfunction list_for_each_entryfunction usb_phy_roothub_exitfunction list_for_each_entryfunction usb_phy_roothub_set_modefunction list_for_each_entryfunction usb_phy_roothub_calibratefunction list_for_each_entryfunction usb_phy_roothub_notify_connectfunction list_for_each_entryfunction usb_phy_roothub_notify_disconnectfunction list_for_each_entryfunction usb_phy_roothub_power_onfunction list_for_each_entryfunction usb_phy_roothub_power_offfunction usb_phy_roothub_suspendfunction usb_phy_roothub_resumeexport usb_phy_roothub_allocexport usb_phy_roothub_alloc_usb3_phyexport usb_phy_roothub_initexport usb_phy_roothub_exitexport usb_phy_roothub_set_modeexport usb_phy_roothub_calibrateexport usb_phy_roothub_notify_connectexport usb_phy_roothub_notify_disconnectexport usb_phy_roothub_power_onexport usb_phy_roothub_power_offexport usb_phy_roothub_suspendexport usb_phy_roothub_resume
Annotated Snippet
struct usb_phy_roothub {
struct phy *phy;
struct list_head list;
};
/* Allocate the roothub_entry by specific name of phy */
static int usb_phy_roothub_add_phy_by_name(struct device *dev, const char *name,
struct list_head *list)
{
struct usb_phy_roothub *roothub_entry;
struct phy *phy;
phy = devm_of_phy_get(dev, dev->of_node, name);
if (IS_ERR(phy))
return PTR_ERR(phy);
roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
if (!roothub_entry)
return -ENOMEM;
INIT_LIST_HEAD(&roothub_entry->list);
roothub_entry->phy = phy;
list_add_tail(&roothub_entry->list, list);
return 0;
}
static int usb_phy_roothub_add_phy(struct device *dev, int index,
struct list_head *list)
{
struct usb_phy_roothub *roothub_entry;
struct phy *phy;
phy = devm_of_phy_get_by_index(dev, dev->of_node, index);
if (IS_ERR(phy)) {
if (PTR_ERR(phy) == -ENODEV)
return 0;
else
return PTR_ERR(phy);
}
roothub_entry = devm_kzalloc(dev, sizeof(*roothub_entry), GFP_KERNEL);
if (!roothub_entry)
return -ENOMEM;
INIT_LIST_HEAD(&roothub_entry->list);
roothub_entry->phy = phy;
list_add_tail(&roothub_entry->list, list);
return 0;
}
struct usb_phy_roothub *usb_phy_roothub_alloc(struct device *dev)
{
struct usb_phy_roothub *phy_roothub;
int i, num_phys, err;
if (!IS_ENABLED(CONFIG_GENERIC_PHY))
return NULL;
num_phys = of_count_phandle_with_args(dev->of_node, "phys",
"#phy-cells");
if (num_phys <= 0)
return NULL;
phy_roothub = devm_kzalloc(dev, sizeof(*phy_roothub), GFP_KERNEL);
if (!phy_roothub)
return ERR_PTR(-ENOMEM);
INIT_LIST_HEAD(&phy_roothub->list);
if (!usb_phy_roothub_add_phy_by_name(dev, "usb2-phy", &phy_roothub->list))
return phy_roothub;
for (i = 0; i < num_phys; i++) {
err = usb_phy_roothub_add_phy(dev, i, &phy_roothub->list);
if (err)
return ERR_PTR(err);
}
return phy_roothub;
}
EXPORT_SYMBOL_GPL(usb_phy_roothub_alloc);
/**
* usb_phy_roothub_alloc_usb3_phy - alloc the roothub
Annotation
- Immediate include surface: `linux/device.h`, `linux/list.h`, `linux/phy/phy.h`, `linux/of.h`, `phy.h`.
- Detected declarations: `struct usb_phy_roothub`, `function usb_phy_roothub_add_phy_by_name`, `function usb_phy_roothub_add_phy`, `function usb_phy_roothub_init`, `function list_for_each_entry`, `function usb_phy_roothub_exit`, `function list_for_each_entry`, `function usb_phy_roothub_set_mode`, `function list_for_each_entry`, `function usb_phy_roothub_calibrate`.
- 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.