drivers/usb/dwc3/core.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc3/core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc3/core.c- Extension
.c- Size
- 73416 bytes
- Lines
- 2870
- 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.
- 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/clk.hlinux/version.hlinux/module.hlinux/kernel.hlinux/slab.hlinux/spinlock.hlinux/platform_device.hlinux/pm_runtime.hlinux/interrupt.hlinux/ioport.hlinux/io.hlinux/list.hlinux/delay.hlinux/dma-mapping.hlinux/of.hlinux/of_graph.hlinux/acpi.hlinux/pci.hlinux/pinctrl/consumer.hlinux/pinctrl/devinfo.hlinux/reset.hlinux/bitfield.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/usb/of.hlinux/usb/otg.hcore.hgadget.hglue.hio.hdebug.h../host/xhci-ext-caps.h
Detected Declarations
function Copyrightfunction dwc3_enable_susphyfunction dwc3_set_prtcapfunction __dwc3_set_modefunction DWC3_VER_IS_PRIORfunction dwc3_set_modefunction dwc3_core_fifo_spacefunction dwc3_core_soft_resetfunction dwc3_frame_length_adjustmentfunction dwc3_ref_clk_periodfunction dwc3_free_one_event_bufferfunction ERR_PTRfunction dwc3_free_event_buffersfunction dwc3_alloc_event_buffersfunction dwc3_event_buffers_setupfunction dwc3_event_buffers_cleanupfunction dwc3_core_num_epsfunction dwc3_cache_hwparamsfunction dwc3_config_soc_busfunction dwc3_core_ulpi_initfunction dwc3_ss_phy_setupfunction dwc3_hs_phy_setupfunction dwc3_ulpi_setupfunction dwc3_phy_setupfunction dwc3_phy_initfunction dwc3_phy_exitfunction dwc3_phy_power_onfunction dwc3_phy_power_offfunction dwc3_clk_enablefunction dwc3_clk_disablefunction dwc3_core_exitfunction dwc3_core_is_validfunction dwc3_core_setup_global_controlfunction dwc3_set_incr_burst_typefunction dwc3_set_power_down_clk_scalefunction dwc3_config_thresholdfunction dwc3_core_initfunction dwc3_core_get_phyfunction dwc3_core_init_modefunction dwc3_core_exit_modefunction dwc3_get_software_propertiesfunction dwc3_get_propertiesfunction dwc3_has_imodfunction dwc3_check_paramsfunction dwc3_get_clocksfunction dwc3_get_num_portsfunction dwc3_vbus_draw_workfunction dwc3_core_probe
Annotated Snippet
if (IS_ENABLED(CONFIG_USB_DWC3_HOST)) {
dev_err(dev,
"Controller does not support host mode.\n");
return -EINVAL;
}
mode = USB_DR_MODE_PERIPHERAL;
break;
case DWC3_GHWPARAMS0_MODE_HOST:
if (IS_ENABLED(CONFIG_USB_DWC3_GADGET)) {
dev_err(dev,
"Controller does not support device mode.\n");
return -EINVAL;
}
mode = USB_DR_MODE_HOST;
break;
default:
if (IS_ENABLED(CONFIG_USB_DWC3_HOST))
mode = USB_DR_MODE_HOST;
else if (IS_ENABLED(CONFIG_USB_DWC3_GADGET))
mode = USB_DR_MODE_PERIPHERAL;
/*
* DWC_usb31 and DWC_usb3 v3.30a and higher do not support OTG
* mode. If the controller supports DRD but the dr_mode is not
* specified or set to OTG, then set the mode to peripheral.
*/
if (mode == USB_DR_MODE_OTG && !dwc->edev &&
(!IS_ENABLED(CONFIG_USB_ROLE_SWITCH) ||
!device_property_read_bool(dwc->dev, "usb-role-switch")) &&
!DWC3_VER_IS_PRIOR(DWC3, 330A))
mode = USB_DR_MODE_PERIPHERAL;
}
if (mode != dwc->dr_mode) {
dev_warn(dev,
"Configuration mismatch. dr_mode forced to %s\n",
mode == USB_DR_MODE_HOST ? "host" : "gadget");
dwc->dr_mode = mode;
}
return 0;
}
void dwc3_enable_susphy(struct dwc3 *dwc, bool enable)
{
u32 reg;
int i;
for (i = 0; i < dwc->num_usb3_ports; i++) {
reg = dwc3_readl(dwc, DWC3_GUSB3PIPECTL(i));
if (enable && !dwc->dis_u3_susphy_quirk)
reg |= DWC3_GUSB3PIPECTL_SUSPHY;
else
reg &= ~DWC3_GUSB3PIPECTL_SUSPHY;
dwc3_writel(dwc, DWC3_GUSB3PIPECTL(i), reg);
}
for (i = 0; i < dwc->num_usb2_ports; i++) {
reg = dwc3_readl(dwc, DWC3_GUSB2PHYCFG(i));
if (enable && !dwc->dis_u2_susphy_quirk)
reg |= DWC3_GUSB2PHYCFG_SUSPHY;
else
reg &= ~DWC3_GUSB2PHYCFG_SUSPHY;
dwc3_writel(dwc, DWC3_GUSB2PHYCFG(i), reg);
}
}
EXPORT_SYMBOL_GPL(dwc3_enable_susphy);
void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy)
{
unsigned int hw_mode;
u32 reg;
reg = dwc3_readl(dwc, DWC3_GCTL);
/*
* For DRD controllers, GUSB3PIPECTL.SUSPENDENABLE and
* GUSB2PHYCFG.SUSPHY should be cleared during mode switching,
* and they can be set after core initialization.
*/
hw_mode = DWC3_GHWPARAMS0_MODE(dwc->hwparams.hwparams0);
if (hw_mode == DWC3_GHWPARAMS0_MODE_DRD && !ignore_susphy) {
if (DWC3_GCTL_PRTCAP(reg) != mode)
dwc3_enable_susphy(dwc, false);
}
reg &= ~(DWC3_GCTL_PRTCAPDIR(DWC3_GCTL_PRTCAP_OTG));
Annotation
- Immediate include surface: `linux/clk.h`, `linux/version.h`, `linux/module.h`, `linux/kernel.h`, `linux/slab.h`, `linux/spinlock.h`, `linux/platform_device.h`, `linux/pm_runtime.h`.
- Detected declarations: `function Copyright`, `function dwc3_enable_susphy`, `function dwc3_set_prtcap`, `function __dwc3_set_mode`, `function DWC3_VER_IS_PRIOR`, `function dwc3_set_mode`, `function dwc3_core_fifo_space`, `function dwc3_core_soft_reset`, `function dwc3_frame_length_adjustment`, `function dwc3_ref_clk_period`.
- 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.
- 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.