drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
Source file repositories/reference/linux-study-clean/drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/phy/broadcom/phy-bcm-ns2-usbdrd.c- Extension
.c- Size
- 10980 bytes
- Lines
- 417
- Domain
- Driver Families
- Bucket
- drivers/phy
- 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.
- 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/delay.hlinux/extcon-provider.hlinux/gpio.hlinux/gpio/consumer.hlinux/init.hlinux/interrupt.hlinux/io.hlinux/iopoll.hlinux/irq.hlinux/mfd/syscon.hlinux/module.hlinux/of.hlinux/of_address.hlinux/phy/phy.hlinux/platform_device.hlinux/regmap.hlinux/slab.hlinux/workqueue.h
Detected Declarations
struct ns2_phy_datastruct ns2_phy_driverstruct ns2_phy_datafunction pll_lock_statfunction ns2_drd_phy_initfunction ns2_drd_phy_powerofffunction ns2_drd_phy_poweronfunction connect_changefunction extcon_workfunction gpio_irq_handlerfunction ns2_drd_phy_probe
Annotated Snippet
struct ns2_phy_driver {
void __iomem *icfgdrd_regs;
void __iomem *idmdrd_rst_ctrl;
void __iomem *crmu_usb2_ctrl;
void __iomem *usb2h_strap_reg;
struct ns2_phy_data *data;
struct extcon_dev *edev;
struct gpio_desc *vbus_gpiod;
struct gpio_desc *id_gpiod;
int id_irq;
int vbus_irq;
unsigned long debounce_jiffies;
struct delayed_work wq_extcon;
};
struct ns2_phy_data {
struct ns2_phy_driver *driver;
struct phy *phy;
int new_state;
};
static const unsigned int usb_extcon_cable[] = {
EXTCON_USB,
EXTCON_USB_HOST,
EXTCON_NONE,
};
static inline int pll_lock_stat(u32 usb_reg, int reg_mask,
struct ns2_phy_driver *driver)
{
u32 val;
return readl_poll_timeout_atomic(driver->icfgdrd_regs + usb_reg,
val, (val & reg_mask), 1,
PLL_LOCK_RETRY);
}
static int ns2_drd_phy_init(struct phy *phy)
{
struct ns2_phy_data *data = phy_get_drvdata(phy);
struct ns2_phy_driver *driver = data->driver;
u32 val;
val = readl(driver->icfgdrd_regs + ICFG_FSM_CTRL);
if (data->new_state == EVT_HOST) {
val &= ~DRD_DEVICE_MODE;
val |= DRD_HOST_MODE;
} else {
val &= ~DRD_HOST_MODE;
val |= DRD_DEVICE_MODE;
}
writel(val, driver->icfgdrd_regs + ICFG_FSM_CTRL);
return 0;
}
static int ns2_drd_phy_poweroff(struct phy *phy)
{
struct ns2_phy_data *data = phy_get_drvdata(phy);
struct ns2_phy_driver *driver = data->driver;
u32 val;
val = readl(driver->crmu_usb2_ctrl);
val &= ~AFE_CORERDY_VDDC;
writel(val, driver->crmu_usb2_ctrl);
val = readl(driver->crmu_usb2_ctrl);
val &= ~DRD_DEV_MODE;
writel(val, driver->crmu_usb2_ctrl);
/* Disable Host and Device Mode */
val = readl(driver->icfgdrd_regs + ICFG_FSM_CTRL);
val &= ~(DRD_HOST_MODE | DRD_DEVICE_MODE | ICFG_OFF_MODE);
writel(val, driver->icfgdrd_regs + ICFG_FSM_CTRL);
return 0;
}
static int ns2_drd_phy_poweron(struct phy *phy)
{
struct ns2_phy_data *data = phy_get_drvdata(phy);
struct ns2_phy_driver *driver = data->driver;
u32 extcon_event = data->new_state;
int ret;
u32 val;
if (extcon_event == EVT_DEVICE) {
writel(DRD_DEV_VAL, driver->icfgdrd_regs + ICFG_DRD_P0CTL);
Annotation
- Immediate include surface: `linux/delay.h`, `linux/extcon-provider.h`, `linux/gpio.h`, `linux/gpio/consumer.h`, `linux/init.h`, `linux/interrupt.h`, `linux/io.h`, `linux/iopoll.h`.
- Detected declarations: `struct ns2_phy_data`, `struct ns2_phy_driver`, `struct ns2_phy_data`, `function pll_lock_stat`, `function ns2_drd_phy_init`, `function ns2_drd_phy_poweroff`, `function ns2_drd_phy_poweron`, `function connect_change`, `function extcon_work`, `function gpio_irq_handler`.
- Atlas domain: Driver Families / drivers/phy.
- Implementation status: source implementation candidate.
- 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.