drivers/usb/dwc3/dwc3-apple.c
Source file repositories/reference/linux-study-clean/drivers/usb/dwc3/dwc3-apple.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/dwc3/dwc3-apple.c- Extension
.c- Size
- 17683 bytes
- Lines
- 524
- 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.
- 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/of.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/reset.hglue.h
Detected Declarations
struct dwc3_appleenum dwc3_apple_statefunction dwc3_apple_writelfunction dwc3_apple_readlfunction dwc3_apple_maskfunction dwc3_apple_setup_ciofunction dwc3_apple_set_ptrcapfunction dwc3_apple_core_probefunction dwc3_apple_core_initfunction dwc3_apple_initfunction dwc3_apple_exitfunction dwc3_usb_role_switch_setfunction dwc3_usb_role_switch_getfunction dwc3_apple_setup_role_switchfunction dwc3_apple_probefunction dwc3_apple_remove
Annotated Snippet
struct dwc3_apple {
struct dwc3 dwc;
struct device *dev;
struct resource *mmio_resource;
void __iomem *apple_regs;
struct reset_control *reset;
struct usb_role_switch *role_sw;
struct mutex lock;
enum dwc3_apple_state state;
};
#define to_dwc3_apple(d) container_of((d), struct dwc3_apple, dwc)
/*
* Apple Silicon dwc3 vendor-specific registers
*
* These registers were identified by tracing XNU's memory access patterns and correlating them with
* debug output over serial to determine their names. We don't exactly know what these do but
* without these USB3 devices sometimes don't work.
*/
#define APPLE_DWC3_REGS_START 0xcd00
#define APPLE_DWC3_REGS_END 0xcdff
#define APPLE_DWC3_CIO_LFPS_OFFSET 0xcd38
#define APPLE_DWC3_CIO_LFPS_OFFSET_VALUE 0xf800f80
#define APPLE_DWC3_CIO_BW_NGT_OFFSET 0xcd3c
#define APPLE_DWC3_CIO_BW_NGT_OFFSET_VALUE 0xfc00fc0
#define APPLE_DWC3_CIO_LINK_TIMER 0xcd40
#define APPLE_DWC3_CIO_PENDING_HP_TIMER GENMASK(23, 16)
#define APPLE_DWC3_CIO_PENDING_HP_TIMER_VALUE 0x14
#define APPLE_DWC3_CIO_PM_LC_TIMER GENMASK(15, 8)
#define APPLE_DWC3_CIO_PM_LC_TIMER_VALUE 0xa
#define APPLE_DWC3_CIO_PM_ENTRY_TIMER GENMASK(7, 0)
#define APPLE_DWC3_CIO_PM_ENTRY_TIMER_VALUE 0x10
static inline void dwc3_apple_writel(struct dwc3_apple *appledwc, u32 offset, u32 value)
{
writel(value, appledwc->apple_regs + offset - APPLE_DWC3_REGS_START);
}
static inline u32 dwc3_apple_readl(struct dwc3_apple *appledwc, u32 offset)
{
return readl(appledwc->apple_regs + offset - APPLE_DWC3_REGS_START);
}
static inline void dwc3_apple_mask(struct dwc3_apple *appledwc, u32 offset, u32 mask, u32 value)
{
u32 reg;
reg = dwc3_apple_readl(appledwc, offset);
reg &= ~mask;
reg |= value;
dwc3_apple_writel(appledwc, offset, reg);
}
static void dwc3_apple_setup_cio(struct dwc3_apple *appledwc)
{
dwc3_apple_writel(appledwc, APPLE_DWC3_CIO_LFPS_OFFSET, APPLE_DWC3_CIO_LFPS_OFFSET_VALUE);
dwc3_apple_writel(appledwc, APPLE_DWC3_CIO_BW_NGT_OFFSET,
APPLE_DWC3_CIO_BW_NGT_OFFSET_VALUE);
dwc3_apple_mask(appledwc, APPLE_DWC3_CIO_LINK_TIMER, APPLE_DWC3_CIO_PENDING_HP_TIMER,
FIELD_PREP(APPLE_DWC3_CIO_PENDING_HP_TIMER,
APPLE_DWC3_CIO_PENDING_HP_TIMER_VALUE));
dwc3_apple_mask(appledwc, APPLE_DWC3_CIO_LINK_TIMER, APPLE_DWC3_CIO_PM_LC_TIMER,
FIELD_PREP(APPLE_DWC3_CIO_PM_LC_TIMER, APPLE_DWC3_CIO_PM_LC_TIMER_VALUE));
dwc3_apple_mask(appledwc, APPLE_DWC3_CIO_LINK_TIMER, APPLE_DWC3_CIO_PM_ENTRY_TIMER,
FIELD_PREP(APPLE_DWC3_CIO_PM_ENTRY_TIMER,
APPLE_DWC3_CIO_PM_ENTRY_TIMER_VALUE));
}
static void dwc3_apple_set_ptrcap(struct dwc3_apple *appledwc, u32 mode)
{
guard(spinlock_irqsave)(&appledwc->dwc.lock);
dwc3_set_prtcap(&appledwc->dwc, mode, false);
}
static int dwc3_apple_core_probe(struct dwc3_apple *appledwc)
{
struct dwc3_probe_data probe_data = {};
int ret;
lockdep_assert_held(&appledwc->lock);
WARN_ON_ONCE(appledwc->state != DWC3_APPLE_PROBE_PENDING);
Annotation
- Immediate include surface: `linux/of.h`, `linux/module.h`, `linux/mutex.h`, `linux/platform_device.h`, `linux/reset.h`, `glue.h`.
- Detected declarations: `struct dwc3_apple`, `enum dwc3_apple_state`, `function dwc3_apple_writel`, `function dwc3_apple_readl`, `function dwc3_apple_mask`, `function dwc3_apple_setup_cio`, `function dwc3_apple_set_ptrcap`, `function dwc3_apple_core_probe`, `function dwc3_apple_core_init`, `function dwc3_apple_init`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: source 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.