drivers/usb/gadget/udc/snps_udc_core.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/udc/snps_udc_core.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/udc/snps_udc_core.c- Extension
.c- Size
- 81709 bytes
- Lines
- 3193
- 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/module.hlinux/pci.hlinux/kernel.hlinux/delay.hlinux/ioport.hlinux/sched.hlinux/slab.hlinux/errno.hlinux/timer.hlinux/list.hlinux/interrupt.hlinux/ioctl.hlinux/fs.hlinux/dmapool.hlinux/prefetch.hlinux/moduleparam.hasm/byteorder.hlinux/unaligned.hamd5536udc.h
Detected Declarations
function print_regsfunction udc_mask_unused_interruptsfunction udc_enable_ep0_interruptsfunction udc_enable_dev_setup_interruptsfunction udc_set_txfifo_addrfunction UDC_QUEUE_CNAKfunction udc_ep_enablefunction ep_initfunction udc_ep_disablefunction udc_alloc_requestfunction udc_free_dma_chainfunction udc_free_requestfunction udc_init_bna_dummyfunction udc_txfifo_writefunction udc_rxfifo_read_dwordsfunction udc_rxfifo_read_bytesfunction udc_rxfifo_readfunction udc_create_dma_chainfunction prep_dmafunction complete_reqfunction udc_get_ppbdu_rxbytesfunction udc_set_rdefunction udc_queuefunction empty_req_queuefunction udc_dequeuefunction udc_set_haltfunction udc_get_framefunction udc_remote_wakeupfunction udc_wakeupfunction make_ep_listsfunction udc_basic_initfunction startup_registersfunction udc_setup_endpointsfunction usb_connectfunction usb_disconnectfunction udc_soft_resetfunction udc_timer_functionfunction udc_handle_halt_statefunction udc_pollstall_timer_functionfunction activate_control_endpointsfunction setup_ep0function amd5536_udc_startfunction shutdownfunction amd5536_udc_stopfunction udc_process_cnak_queuefunction udc_ep0_set_rdefunction RDEfunction udc_data_out_isr
Annotated Snippet
if (dev->ep[i].regs) {
/* read fifo size */
tmp = readl(&dev->ep[i].regs->bufin_framenum);
tmp = AMD_GETBITS(tmp, UDC_EPIN_BUFF_SIZE);
ep->txfifo += tmp;
}
}
return 0;
}
/* CNAK pending field: bit0 = ep0in, bit16 = ep0out */
static u32 cnak_pending;
static void UDC_QUEUE_CNAK(struct udc_ep *ep, unsigned num)
{
if (readl(&ep->regs->ctl) & AMD_BIT(UDC_EPCTL_NAK)) {
DBG(ep->dev, "NAK could not be cleared for ep%d\n", num);
cnak_pending |= 1 << (num);
ep->naking = 1;
} else
cnak_pending = cnak_pending & (~(1 << (num)));
}
/* Enables endpoint, is called by gadget driver */
static int
udc_ep_enable(struct usb_ep *usbep, const struct usb_endpoint_descriptor *desc)
{
struct udc_ep *ep;
struct udc *dev;
u32 tmp;
unsigned long iflags;
u8 udc_csr_epix;
unsigned maxpacket;
if (!usbep
|| usbep->name == ep0_string
|| !desc
|| desc->bDescriptorType != USB_DT_ENDPOINT)
return -EINVAL;
ep = container_of(usbep, struct udc_ep, ep);
dev = ep->dev;
DBG(dev, "udc_ep_enable() ep %d\n", ep->num);
if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN)
return -ESHUTDOWN;
spin_lock_irqsave(&dev->lock, iflags);
ep->ep.desc = desc;
ep->halted = 0;
/* set traffic type */
tmp = readl(&dev->ep[ep->num].regs->ctl);
tmp = AMD_ADDBITS(tmp, desc->bmAttributes, UDC_EPCTL_ET);
writel(tmp, &dev->ep[ep->num].regs->ctl);
/* set max packet size */
maxpacket = usb_endpoint_maxp(desc);
tmp = readl(&dev->ep[ep->num].regs->bufout_maxpkt);
tmp = AMD_ADDBITS(tmp, maxpacket, UDC_EP_MAX_PKT_SIZE);
ep->ep.maxpacket = maxpacket;
writel(tmp, &dev->ep[ep->num].regs->bufout_maxpkt);
/* IN ep */
if (ep->in) {
/* ep ix in UDC CSR register space */
udc_csr_epix = ep->num;
/* set buffer size (tx fifo entries) */
tmp = readl(&dev->ep[ep->num].regs->bufin_framenum);
/* double buffering: fifo size = 2 x max packet size */
tmp = AMD_ADDBITS(
tmp,
maxpacket * UDC_EPIN_BUFF_SIZE_MULT
/ UDC_DWORD_BYTES,
UDC_EPIN_BUFF_SIZE);
writel(tmp, &dev->ep[ep->num].regs->bufin_framenum);
/* calc. tx fifo base addr */
udc_set_txfifo_addr(ep);
/* flush fifo */
tmp = readl(&ep->regs->ctl);
tmp |= AMD_BIT(UDC_EPCTL_F);
writel(tmp, &ep->regs->ctl);
Annotation
- Immediate include surface: `linux/module.h`, `linux/pci.h`, `linux/kernel.h`, `linux/delay.h`, `linux/ioport.h`, `linux/sched.h`, `linux/slab.h`, `linux/errno.h`.
- Detected declarations: `function print_regs`, `function udc_mask_unused_interrupts`, `function udc_enable_ep0_interrupts`, `function udc_enable_dev_setup_interrupts`, `function udc_set_txfifo_addr`, `function UDC_QUEUE_CNAK`, `function udc_ep_enable`, `function ep_init`, `function udc_ep_disable`, `function udc_alloc_request`.
- 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.