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.

Dependency Surface

Detected Declarations

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

Implementation Notes