drivers/usb/phy/phy.c
Source file repositories/reference/linux-study-clean/drivers/usb/phy/phy.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/phy/phy.c- Extension
.c- Size
- 19112 bytes
- Lines
- 749
- 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/kernel.hlinux/export.hlinux/err.hlinux/device.hlinux/module.hlinux/slab.hlinux/of.hlinux/usb/phy.h
Detected Declarations
struct phy_devmfunction list_for_each_entryfunction list_for_each_entryfunction list_for_each_entryfunction usb_phy_set_default_currentfunction usb_phy_get_charger_typefunction usb_phy_ueventfunction __usb_phy_get_charger_typefunction usb_phy_get_charger_typefunction usb_phy_set_charger_currentfunction usb_phy_get_charger_currentfunction usb_phy_set_charger_statefunction devm_usb_phy_releasefunction devm_usb_phy_release2function usb_charger_initfunction usb_add_extconfunction usb_get_phyfunction usb_put_phyfunction usb_get_phyfunction usb_add_phyfunction list_for_each_entryfunction usb_add_phy_devfunction usb_remove_phyfunction usb_phy_set_eventexport usb_phy_set_charger_currentexport usb_phy_get_charger_currentexport usb_phy_set_charger_stateexport devm_usb_get_phyexport usb_get_phyexport devm_usb_get_phy_by_nodeexport devm_usb_get_phy_by_phandleexport usb_put_phyexport usb_add_phyexport usb_add_phy_devexport usb_remove_phyexport usb_phy_set_event
Annotated Snippet
struct phy_devm {
struct usb_phy *phy;
struct notifier_block *nb;
};
static const char *const usb_chger_type[] = {
[UNKNOWN_TYPE] = "USB_CHARGER_UNKNOWN_TYPE",
[SDP_TYPE] = "USB_CHARGER_SDP_TYPE",
[CDP_TYPE] = "USB_CHARGER_CDP_TYPE",
[DCP_TYPE] = "USB_CHARGER_DCP_TYPE",
[ACA_TYPE] = "USB_CHARGER_ACA_TYPE",
};
static const char *const usb_chger_state[] = {
[USB_CHARGER_DEFAULT] = "USB_CHARGER_DEFAULT",
[USB_CHARGER_PRESENT] = "USB_CHARGER_PRESENT",
[USB_CHARGER_ABSENT] = "USB_CHARGER_ABSENT",
};
static struct usb_phy *__usb_find_phy(struct list_head *list,
enum usb_phy_type type)
{
struct usb_phy *phy = NULL;
list_for_each_entry(phy, list, head) {
if (phy->type != type)
continue;
return phy;
}
return ERR_PTR(-ENODEV);
}
static struct usb_phy *__of_usb_find_phy(struct device_node *node)
{
struct usb_phy *phy;
if (!of_device_is_available(node))
return ERR_PTR(-ENODEV);
list_for_each_entry(phy, &phy_list, head) {
if (node != phy->dev->of_node)
continue;
return phy;
}
return ERR_PTR(-EPROBE_DEFER);
}
static struct usb_phy *__device_to_usb_phy(const struct device *dev)
{
struct usb_phy *usb_phy;
list_for_each_entry(usb_phy, &phy_list, head) {
if (usb_phy->dev == dev)
return usb_phy;
}
return NULL;
}
static void usb_phy_set_default_current(struct usb_phy *usb_phy)
{
usb_phy->chg_cur.sdp_min = DEFAULT_SDP_CUR_MIN;
usb_phy->chg_cur.sdp_max = DEFAULT_SDP_CUR_MAX;
usb_phy->chg_cur.dcp_min = DEFAULT_DCP_CUR_MIN;
usb_phy->chg_cur.dcp_max = DEFAULT_DCP_CUR_MAX;
usb_phy->chg_cur.cdp_min = DEFAULT_CDP_CUR_MIN;
usb_phy->chg_cur.cdp_max = DEFAULT_CDP_CUR_MAX;
usb_phy->chg_cur.aca_min = DEFAULT_ACA_CUR_MIN;
usb_phy->chg_cur.aca_max = DEFAULT_ACA_CUR_MAX;
}
/**
* usb_phy_notify_charger_work - notify the USB charger state
* @work: the charger work to notify the USB charger state
*
* This work can be issued when USB charger state has been changed or
* USB charger current has been changed, then we can notify the current
* what can be drawn to power user and the charger state to userspace.
*
* If we get the charger type from extcon subsystem, we can notify the
* charger state to power user automatically by usb_phy_get_charger_type()
* issuing from extcon subsystem.
*
* If we get the charger type from ->charger_detect() instead of extcon
* subsystem, the usb phy driver should issue usb_phy_set_charger_state()
* to set charger state when the charger state has been changed.
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/export.h`, `linux/err.h`, `linux/device.h`, `linux/module.h`, `linux/slab.h`, `linux/of.h`, `linux/usb/phy.h`.
- Detected declarations: `struct phy_devm`, `function list_for_each_entry`, `function list_for_each_entry`, `function list_for_each_entry`, `function usb_phy_set_default_current`, `function usb_phy_get_charger_type`, `function usb_phy_uevent`, `function __usb_phy_get_charger_type`, `function usb_phy_get_charger_type`, `function usb_phy_set_charger_current`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.