drivers/usb/gadget/function/f_uac2.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/f_uac2.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/f_uac2.c- Extension
.c- Size
- 66372 bytes
- Lines
- 2309
- 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.
- 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/usb/audio.hlinux/usb/audio-v2.hlinux/module.hu_audio.hu_uac2.h
Detected Declarations
struct f_uac2struct cntrl_cur_lay2struct cntrl_range_lay2struct cntrl_cur_lay3struct cntrl_subrange_lay3function get_max_sratefunction get_max_bw_for_bintfunction set_ep_max_packet_size_bintfunction setup_headersfunction setup_descriptorfunction afunc_validate_optsfunction afunc_bindfunction afunc_notify_completefunction afunc_notifyfunction afunc_set_altfunction afunc_get_altfunction afunc_disablefunction afunc_suspendfunction in_rq_curfunction in_rq_rangefunction ac_rq_infunction uac2_cs_control_sam_freqfunction out_rq_cur_completefunction out_rq_curfunction setup_rq_inffunction afunc_setupfunction f_uac2_attr_releasefunction afunc_free_instfunction afunc_freefunction afunc_unbind
Annotated Snippet
struct f_uac2 {
struct g_audio g_audio;
u8 ac_intf, as_in_intf, as_out_intf;
u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */
struct usb_ctrlrequest setup_cr; /* will be used in data stage */
/* Interrupt IN endpoint of AC interface */
struct usb_ep *int_ep;
atomic_t int_count;
/* transient state, only valid during handling of a single control request */
int clock_id;
};
static inline struct f_uac2 *func_to_uac2(struct usb_function *f)
{
return container_of(f, struct f_uac2, g_audio.func);
}
static inline
struct f_uac2_opts *g_audio_to_uac2_opts(struct g_audio *agdev)
{
return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
}
static int afunc_notify(struct g_audio *agdev, int unit_id, int cs);
/* --------- USB Function Interface ------------- */
enum {
STR_ASSOC,
STR_IF_CTRL,
STR_CLKSRC_IN,
STR_CLKSRC_OUT,
STR_USB_IT,
STR_USB_IT_CH,
STR_IO_IT,
STR_IO_IT_CH,
STR_USB_OT,
STR_IO_OT,
STR_FU_IN,
STR_FU_OUT,
STR_AS_OUT_ALT0,
STR_AS_OUT_ALT1,
STR_AS_IN_ALT0,
STR_AS_IN_ALT1,
NUM_STR_DESCRIPTORS,
};
static struct usb_string strings_fn[NUM_STR_DESCRIPTORS + 1] = {};
static const char *const speed_names[] = {
[USB_SPEED_UNKNOWN] = "UNKNOWN",
[USB_SPEED_LOW] = "LS",
[USB_SPEED_FULL] = "FS",
[USB_SPEED_HIGH] = "HS",
[USB_SPEED_WIRELESS] = "W",
[USB_SPEED_SUPER] = "SS",
[USB_SPEED_SUPER_PLUS] = "SS+",
};
static struct usb_gadget_strings str_fn = {
.language = 0x0409, /* en-us */
.strings = strings_fn,
};
static struct usb_gadget_strings *fn_strings[] = {
&str_fn,
NULL,
};
static struct usb_interface_assoc_descriptor iad_desc = {
.bLength = sizeof iad_desc,
.bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
.bFirstInterface = 0,
.bInterfaceCount = 3,
.bFunctionClass = USB_CLASS_AUDIO,
.bFunctionSubClass = UAC2_FUNCTION_SUBCLASS_UNDEFINED,
.bFunctionProtocol = UAC_VERSION_2,
};
/* Audio Control Interface */
static struct usb_interface_descriptor std_ac_if_desc = {
.bLength = sizeof std_ac_if_desc,
.bDescriptorType = USB_DT_INTERFACE,
.bAlternateSetting = 0,
/* .bNumEndpoints = DYNAMIC */
.bInterfaceClass = USB_CLASS_AUDIO,
Annotation
- Immediate include surface: `linux/usb/audio.h`, `linux/usb/audio-v2.h`, `linux/module.h`, `u_audio.h`, `u_uac2.h`.
- Detected declarations: `struct f_uac2`, `struct cntrl_cur_lay2`, `struct cntrl_range_lay2`, `struct cntrl_cur_lay3`, `struct cntrl_subrange_lay3`, `function get_max_srate`, `function get_max_bw_for_bint`, `function set_ep_max_packet_size_bint`, `function setup_headers`, `function setup_descriptor`.
- 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.
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.