drivers/usb/phy/phy-gpio-vbus-usb.c
Source file repositories/reference/linux-study-clean/drivers/usb/phy/phy-gpio-vbus-usb.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/phy/phy-gpio-vbus-usb.c- Extension
.c- Size
- 10624 bytes
- Lines
- 396
- Domain
- Driver Families
- Bucket
- drivers/usb
- Inferred role
- Driver Families: implementation source
- Status
- source 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.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/kernel.hlinux/platform_device.hlinux/gpio/consumer.hlinux/module.hlinux/slab.hlinux/interrupt.hlinux/usb.hlinux/workqueue.hlinux/regulator/consumer.hlinux/usb/gadget.hlinux/usb/otg.h
Detected Declarations
struct gpio_vbus_datafunction surgesfunction is_vbus_poweredfunction gpio_vbus_workfunction gpio_vbus_irqfunction gpio_vbus_set_peripheralfunction gpio_vbus_set_powerfunction gpio_vbus_set_suspendfunction gpio_vbus_probefunction gpio_vbus_removefunction gpio_vbus_pm_suspendfunction gpio_vbus_pm_resume
Annotated Snippet
struct gpio_vbus_data {
struct gpio_desc *vbus_gpiod;
struct gpio_desc *pullup_gpiod;
struct usb_phy phy;
struct device *dev;
struct regulator *vbus_draw;
int vbus_draw_enabled;
unsigned mA;
struct delayed_work work;
int vbus;
int irq;
};
/*
* This driver relies on "both edges" triggering. VBUS has 100 msec to
* stabilize, so the peripheral controller driver may need to cope with
* some bouncing due to current surges (e.g. charging local capacitance)
* and contact chatter.
*
* REVISIT in desperate straits, toggling between rising and falling
* edges might be workable.
*/
#define VBUS_IRQ_FLAGS \
(IRQF_SHARED | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
/* interface to regulator framework */
static void set_vbus_draw(struct gpio_vbus_data *gpio_vbus, unsigned mA)
{
struct regulator *vbus_draw = gpio_vbus->vbus_draw;
int enabled;
int ret;
if (!vbus_draw)
return;
enabled = gpio_vbus->vbus_draw_enabled;
if (mA) {
regulator_set_current_limit(vbus_draw, 0, 1000 * mA);
if (!enabled) {
ret = regulator_enable(vbus_draw);
if (ret < 0)
return;
gpio_vbus->vbus_draw_enabled = 1;
}
} else {
if (enabled) {
ret = regulator_disable(vbus_draw);
if (ret < 0)
return;
gpio_vbus->vbus_draw_enabled = 0;
}
}
gpio_vbus->mA = mA;
}
static int is_vbus_powered(struct gpio_vbus_data *gpio_vbus)
{
return gpiod_get_value(gpio_vbus->vbus_gpiod);
}
static void gpio_vbus_work(struct work_struct *work)
{
struct gpio_vbus_data *gpio_vbus =
container_of(work, struct gpio_vbus_data, work.work);
int status, vbus;
if (!gpio_vbus->phy.otg->gadget)
return;
vbus = is_vbus_powered(gpio_vbus);
if ((vbus ^ gpio_vbus->vbus) == 0)
return;
gpio_vbus->vbus = vbus;
/* Peripheral controllers which manage the pullup themselves won't have
* a pullup GPIO configured here. If it's configured here, we'll do
* what isp1301_omap::b_peripheral() does and enable the pullup here...
* although that may complicate usb_gadget_{,dis}connect() support.
*/
if (vbus) {
status = USB_EVENT_VBUS;
gpio_vbus->phy.otg->state = OTG_STATE_B_PERIPHERAL;
gpio_vbus->phy.last_event = status;
usb_gadget_vbus_connect(gpio_vbus->phy.otg->gadget);
/* drawing a "unit load" is *always* OK, except for OTG */
set_vbus_draw(gpio_vbus, 100);
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/platform_device.h`, `linux/gpio/consumer.h`, `linux/module.h`, `linux/slab.h`, `linux/interrupt.h`, `linux/usb.h`, `linux/workqueue.h`.
- Detected declarations: `struct gpio_vbus_data`, `function surges`, `function is_vbus_powered`, `function gpio_vbus_work`, `function gpio_vbus_irq`, `function gpio_vbus_set_peripheral`, `function gpio_vbus_set_power`, `function gpio_vbus_set_suspend`, `function gpio_vbus_probe`, `function gpio_vbus_remove`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.