drivers/usb/gadget/udc/max3420_udc.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/udc/max3420_udc.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/udc/max3420_udc.c- Extension
.c- Size
- 30600 bytes
- Lines
- 1331
- 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/delay.hlinux/device.hlinux/interrupt.hlinux/io.hlinux/module.hlinux/bitfield.hlinux/of.hlinux/of_irq.hlinux/prefetch.hlinux/usb/ch9.hlinux/usb/gadget.hlinux/spi/spi.hlinux/gpio/consumer.h
Detected Declarations
struct max3420_reqstruct max3420_epstruct max3420_udcfunction spi_ack_ctrlfunction spi_rd8_ackfunction spi_rd8function spi_wr8_ackfunction spi_wr8function spi_rd_buffunction spi_wr_buffunction spi_max3420_enablefunction spi_max3420_stallfunction spi_max3420_rwkupfunction __max3420_stopfunction __max3420_startfunction max3420_startfunction max3420_vbus_handlerfunction max3420_irq_handlerfunction max3420_getstatusfunction max3420_set_clear_featurefunction max3420_handle_setupfunction max3420_req_donefunction max3420_do_datafunction max3420_handle_irqsfunction max3420_threadfunction max3420_ep_set_haltfunction __max3420_ep_enablefunction max3420_ep_enablefunction max3420_nukefunction list_for_each_entry_safefunction __max3420_ep_disablefunction max3420_ep_disablefunction max3420_free_requestfunction max3420_ep_queuefunction max3420_ep_dequeuefunction max3420_wakeupfunction max3420_udc_startfunction max3420_udc_stopfunction max3420_eps_initfunction max3420_probefunction max3420_remove
Annotated Snippet
struct max3420_req {
struct usb_request usb_req;
struct list_head queue;
struct max3420_ep *ep;
};
struct max3420_ep {
struct usb_ep ep_usb;
struct max3420_udc *udc;
struct list_head queue;
char name[MAX3420_EPNAME_SIZE];
unsigned int maxpacket;
spinlock_t lock;
int halted;
u32 todo;
int id;
};
struct max3420_udc {
struct usb_gadget gadget;
struct max3420_ep ep[MAX3420_MAX_EPS];
struct usb_gadget_driver *driver;
struct task_struct *thread_task;
int remote_wkp, is_selfpowered;
bool vbus_active, softconnect;
struct usb_ctrlrequest setup;
struct mutex spi_bus_mutex;
struct max3420_req ep0req;
struct spi_device *spi;
struct device *dev;
spinlock_t lock;
bool suspended;
u8 ep0buf[64];
u32 todo;
};
#define to_max3420_req(r) container_of((r), struct max3420_req, usb_req)
#define to_max3420_ep(e) container_of((e), struct max3420_ep, ep_usb)
#define to_udc(g) container_of((g), struct max3420_udc, gadget)
#define DRIVER_DESC "MAX3420 USB Device-Mode Driver"
static const char driver_name[] = "max3420-udc";
/* Control endpoint configuration.*/
static const struct usb_endpoint_descriptor ep0_desc = {
.bEndpointAddress = USB_DIR_OUT,
.bmAttributes = USB_ENDPOINT_XFER_CONTROL,
.wMaxPacketSize = cpu_to_le16(MAX3420_EP_MAX_PACKET),
};
static void spi_ack_ctrl(struct max3420_udc *udc)
{
struct spi_device *spi = udc->spi;
struct spi_transfer transfer;
struct spi_message msg;
u8 txdata[1];
memset(&transfer, 0, sizeof(transfer));
spi_message_init(&msg);
txdata[0] = MAX3420_ACKSTAT;
transfer.tx_buf = txdata;
transfer.len = 1;
spi_message_add_tail(&transfer, &msg);
spi_sync(spi, &msg);
}
static u8 spi_rd8_ack(struct max3420_udc *udc, u8 reg, int actstat)
{
struct spi_device *spi = udc->spi;
struct spi_transfer transfer;
struct spi_message msg;
u8 txdata[2], rxdata[2];
memset(&transfer, 0, sizeof(transfer));
spi_message_init(&msg);
txdata[0] = MAX3420_SPI_CMD_RD(reg) | (actstat ? MAX3420_ACKSTAT : 0);
transfer.tx_buf = txdata;
transfer.rx_buf = rxdata;
transfer.len = 2;
spi_message_add_tail(&transfer, &msg);
spi_sync(spi, &msg);
return rxdata[1];
}
Annotation
- Immediate include surface: `linux/delay.h`, `linux/device.h`, `linux/interrupt.h`, `linux/io.h`, `linux/module.h`, `linux/bitfield.h`, `linux/of.h`, `linux/of_irq.h`.
- Detected declarations: `struct max3420_req`, `struct max3420_ep`, `struct max3420_udc`, `function spi_ack_ctrl`, `function spi_rd8_ack`, `function spi_rd8`, `function spi_wr8_ack`, `function spi_wr8`, `function spi_rd_buf`, `function spi_wr_buf`.
- 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.