1 // SPDX-License-Identifier: GPL-2.0+
3 * f_uac2.c -- USB Audio Class 2.0 Function
6 * Yadwinder Singh (yadi.brar01@gmail.com)
7 * Jaswinder Singh (jaswinder.singh@linaro.org)
10 * Ruslan Bilovol (ruslan.bilovol@gmail.com)
13 #include <linux/usb/audio.h>
14 #include <linux/usb/audio-v2.h>
15 #include <linux/module.h>
20 /* UAC2 spec: 4.1 Audio Channel Cluster Descriptor */
21 #define UAC2_CHANNEL_MASK 0x07FFFFFF
24 * The driver implements a simple UAC_2 topology.
25 * USB-OUT -> IT_1 -> FU -> OT_3 -> ALSA_Capture
26 * ALSA_Playback -> IT_2 -> FU -> OT_4 -> USB-IN
27 * Capture and Playback sampling rates are independently
28 * controlled by two clock sources :
29 * CLK_5 := c_srate, and CLK_6 := p_srate
31 #define USB_OUT_CLK_ID (out_clk_src_desc.bClockID)
32 #define USB_IN_CLK_ID (in_clk_src_desc.bClockID)
33 #define USB_OUT_FU_ID (out_feature_unit_desc->bUnitID)
34 #define USB_IN_FU_ID (in_feature_unit_desc->bUnitID)
36 #define CONTROL_ABSENT 0
37 #define CONTROL_RDONLY 1
38 #define CONTROL_RDWR 3
40 #define CLK_FREQ_CTRL 0
41 #define CLK_VLD_CTRL 2
42 #define FU_MUTE_CTRL 0
52 #define EPIN_EN(_opts) ((_opts)->p_chmask != 0)
53 #define EPOUT_EN(_opts) ((_opts)->c_chmask != 0)
54 #define FUIN_EN(_opts) (EPIN_EN(_opts) \
55 && ((_opts)->p_mute_present \
56 || (_opts)->p_volume_present))
57 #define FUOUT_EN(_opts) (EPOUT_EN(_opts) \
58 && ((_opts)->c_mute_present \
59 || (_opts)->c_volume_present))
60 #define EPOUT_FBACK_IN_EN(_opts) ((_opts)->c_sync == USB_ENDPOINT_SYNC_ASYNC)
63 struct g_audio g_audio;
64 u8 ac_intf, as_in_intf, as_out_intf;
65 u8 ac_alt, as_in_alt, as_out_alt; /* needed for get_alt() */
67 struct usb_ctrlrequest setup_cr; /* will be used in data stage */
69 /* Interrupt IN endpoint of AC interface */
70 struct usb_ep *int_ep;
74 static inline struct f_uac2 *func_to_uac2(struct usb_function *f)
76 return container_of(f, struct f_uac2, g_audio.func);
80 struct f_uac2_opts *g_audio_to_uac2_opts(struct g_audio *agdev)
82 return container_of(agdev->func.fi, struct f_uac2_opts, func_inst);
85 static int afunc_notify(struct g_audio *agdev, int unit_id, int cs);
87 /* --------- USB Function Interface ------------- */
106 static char clksrc_in[8];
107 static char clksrc_out[8];
109 static struct usb_string strings_fn[] = {
110 [STR_ASSOC].s = "Source/Sink",
111 [STR_IF_CTRL].s = "Topology Control",
112 [STR_CLKSRC_IN].s = clksrc_in,
113 [STR_CLKSRC_OUT].s = clksrc_out,
114 [STR_USB_IT].s = "USBH Out",
115 [STR_IO_IT].s = "USBD Out",
116 [STR_USB_OT].s = "USBH In",
117 [STR_IO_OT].s = "USBD In",
118 [STR_FU_IN].s = "Capture Volume",
119 [STR_FU_OUT].s = "Playback Volume",
120 [STR_AS_OUT_ALT0].s = "Playback Inactive",
121 [STR_AS_OUT_ALT1].s = "Playback Active",
122 [STR_AS_IN_ALT0].s = "Capture Inactive",
123 [STR_AS_IN_ALT1].s = "Capture Active",
127 static struct usb_gadget_strings str_fn = {
128 .language = 0x0409, /* en-us */
129 .strings = strings_fn,
132 static struct usb_gadget_strings *fn_strings[] = {
137 static struct usb_interface_assoc_descriptor iad_desc = {
138 .bLength = sizeof iad_desc,
139 .bDescriptorType = USB_DT_INTERFACE_ASSOCIATION,
141 .bFirstInterface = 0,
142 .bInterfaceCount = 3,
143 .bFunctionClass = USB_CLASS_AUDIO,
144 .bFunctionSubClass = UAC2_FUNCTION_SUBCLASS_UNDEFINED,
145 .bFunctionProtocol = UAC_VERSION_2,
148 /* Audio Control Interface */
149 static struct usb_interface_descriptor std_ac_if_desc = {
150 .bLength = sizeof std_ac_if_desc,
151 .bDescriptorType = USB_DT_INTERFACE,
153 .bAlternateSetting = 0,
154 /* .bNumEndpoints = DYNAMIC */
155 .bInterfaceClass = USB_CLASS_AUDIO,
156 .bInterfaceSubClass = USB_SUBCLASS_AUDIOCONTROL,
157 .bInterfaceProtocol = UAC_VERSION_2,
160 /* Clock source for IN traffic */
161 static struct uac_clock_source_descriptor in_clk_src_desc = {
162 .bLength = sizeof in_clk_src_desc,
163 .bDescriptorType = USB_DT_CS_INTERFACE,
165 .bDescriptorSubtype = UAC2_CLOCK_SOURCE,
166 /* .bClockID = DYNAMIC */
167 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED,
168 .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL),
172 /* Clock source for OUT traffic */
173 static struct uac_clock_source_descriptor out_clk_src_desc = {
174 .bLength = sizeof out_clk_src_desc,
175 .bDescriptorType = USB_DT_CS_INTERFACE,
177 .bDescriptorSubtype = UAC2_CLOCK_SOURCE,
178 /* .bClockID = DYNAMIC */
179 .bmAttributes = UAC_CLOCK_SOURCE_TYPE_INT_FIXED,
180 .bmControls = (CONTROL_RDONLY << CLK_FREQ_CTRL),
184 /* Input Terminal for USB_OUT */
185 static struct uac2_input_terminal_descriptor usb_out_it_desc = {
186 .bLength = sizeof usb_out_it_desc,
187 .bDescriptorType = USB_DT_CS_INTERFACE,
189 .bDescriptorSubtype = UAC_INPUT_TERMINAL,
190 /* .bTerminalID = DYNAMIC */
191 .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING),
193 /* .bCSourceID = DYNAMIC */
195 .bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
198 /* Input Terminal for I/O-In */
199 static struct uac2_input_terminal_descriptor io_in_it_desc = {
200 .bLength = sizeof io_in_it_desc,
201 .bDescriptorType = USB_DT_CS_INTERFACE,
203 .bDescriptorSubtype = UAC_INPUT_TERMINAL,
204 /* .bTerminalID = DYNAMIC */
205 .wTerminalType = cpu_to_le16(UAC_INPUT_TERMINAL_UNDEFINED),
207 /* .bCSourceID = DYNAMIC */
209 .bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
212 /* Ouput Terminal for USB_IN */
213 static struct uac2_output_terminal_descriptor usb_in_ot_desc = {
214 .bLength = sizeof usb_in_ot_desc,
215 .bDescriptorType = USB_DT_CS_INTERFACE,
217 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
218 /* .bTerminalID = DYNAMIC */
219 .wTerminalType = cpu_to_le16(UAC_TERMINAL_STREAMING),
221 /* .bSourceID = DYNAMIC */
222 /* .bCSourceID = DYNAMIC */
223 .bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
226 /* Ouput Terminal for I/O-Out */
227 static struct uac2_output_terminal_descriptor io_out_ot_desc = {
228 .bLength = sizeof io_out_ot_desc,
229 .bDescriptorType = USB_DT_CS_INTERFACE,
231 .bDescriptorSubtype = UAC_OUTPUT_TERMINAL,
232 /* .bTerminalID = DYNAMIC */
233 .wTerminalType = cpu_to_le16(UAC_OUTPUT_TERMINAL_UNDEFINED),
235 /* .bSourceID = DYNAMIC */
236 /* .bCSourceID = DYNAMIC */
237 .bmControls = cpu_to_le16(CONTROL_RDWR << COPY_CTRL),
240 static struct uac2_feature_unit_descriptor *in_feature_unit_desc;
241 static struct uac2_feature_unit_descriptor *out_feature_unit_desc;
243 static struct uac2_ac_header_descriptor ac_hdr_desc = {
244 .bLength = sizeof ac_hdr_desc,
245 .bDescriptorType = USB_DT_CS_INTERFACE,
247 .bDescriptorSubtype = UAC_MS_HEADER,
248 .bcdADC = cpu_to_le16(0x200),
249 .bCategory = UAC2_FUNCTION_IO_BOX,
250 /* .wTotalLength = DYNAMIC */
254 /* AC IN Interrupt Endpoint */
255 static struct usb_endpoint_descriptor fs_ep_int_desc = {
256 .bLength = USB_DT_ENDPOINT_SIZE,
257 .bDescriptorType = USB_DT_ENDPOINT,
259 .bEndpointAddress = USB_DIR_IN,
260 .bmAttributes = USB_ENDPOINT_XFER_INT,
261 .wMaxPacketSize = cpu_to_le16(6),
265 static struct usb_endpoint_descriptor hs_ep_int_desc = {
266 .bLength = USB_DT_ENDPOINT_SIZE,
267 .bDescriptorType = USB_DT_ENDPOINT,
269 .bmAttributes = USB_ENDPOINT_XFER_INT,
270 .wMaxPacketSize = cpu_to_le16(6),
274 static struct usb_endpoint_descriptor ss_ep_int_desc = {
275 .bLength = USB_DT_ENDPOINT_SIZE,
276 .bDescriptorType = USB_DT_ENDPOINT,
278 .bEndpointAddress = USB_DIR_IN,
279 .bmAttributes = USB_ENDPOINT_XFER_INT,
280 .wMaxPacketSize = cpu_to_le16(6),
284 /* Audio Streaming OUT Interface - Alt0 */
285 static struct usb_interface_descriptor std_as_out_if0_desc = {
286 .bLength = sizeof std_as_out_if0_desc,
287 .bDescriptorType = USB_DT_INTERFACE,
289 .bAlternateSetting = 0,
291 .bInterfaceClass = USB_CLASS_AUDIO,
292 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
293 .bInterfaceProtocol = UAC_VERSION_2,
296 /* Audio Streaming OUT Interface - Alt1 */
297 static struct usb_interface_descriptor std_as_out_if1_desc = {
298 .bLength = sizeof std_as_out_if1_desc,
299 .bDescriptorType = USB_DT_INTERFACE,
301 .bAlternateSetting = 1,
303 .bInterfaceClass = USB_CLASS_AUDIO,
304 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
305 .bInterfaceProtocol = UAC_VERSION_2,
308 /* Audio Stream OUT Intface Desc */
309 static struct uac2_as_header_descriptor as_out_hdr_desc = {
310 .bLength = sizeof as_out_hdr_desc,
311 .bDescriptorType = USB_DT_CS_INTERFACE,
313 .bDescriptorSubtype = UAC_AS_GENERAL,
314 /* .bTerminalLink = DYNAMIC */
316 .bFormatType = UAC_FORMAT_TYPE_I,
317 .bmFormats = cpu_to_le32(UAC_FORMAT_TYPE_I_PCM),
321 /* Audio USB_OUT Format */
322 static struct uac2_format_type_i_descriptor as_out_fmt1_desc = {
323 .bLength = sizeof as_out_fmt1_desc,
324 .bDescriptorType = USB_DT_CS_INTERFACE,
325 .bDescriptorSubtype = UAC_FORMAT_TYPE,
326 .bFormatType = UAC_FORMAT_TYPE_I,
329 /* STD AS ISO OUT Endpoint */
330 static struct usb_endpoint_descriptor fs_epout_desc = {
331 .bLength = USB_DT_ENDPOINT_SIZE,
332 .bDescriptorType = USB_DT_ENDPOINT,
334 .bEndpointAddress = USB_DIR_OUT,
335 /* .bmAttributes = DYNAMIC */
336 /* .wMaxPacketSize = DYNAMIC */
340 static struct usb_endpoint_descriptor hs_epout_desc = {
341 .bLength = USB_DT_ENDPOINT_SIZE,
342 .bDescriptorType = USB_DT_ENDPOINT,
344 /* .bmAttributes = DYNAMIC */
345 /* .wMaxPacketSize = DYNAMIC */
349 static struct usb_endpoint_descriptor ss_epout_desc = {
350 .bLength = USB_DT_ENDPOINT_SIZE,
351 .bDescriptorType = USB_DT_ENDPOINT,
353 .bEndpointAddress = USB_DIR_OUT,
354 /* .bmAttributes = DYNAMIC */
355 /* .wMaxPacketSize = DYNAMIC */
359 static struct usb_ss_ep_comp_descriptor ss_epout_desc_comp = {
360 .bLength = sizeof(ss_epout_desc_comp),
361 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
364 /* wBytesPerInterval = DYNAMIC */
367 /* CS AS ISO OUT Endpoint */
368 static struct uac2_iso_endpoint_descriptor as_iso_out_desc = {
369 .bLength = sizeof as_iso_out_desc,
370 .bDescriptorType = USB_DT_CS_ENDPOINT,
372 .bDescriptorSubtype = UAC_EP_GENERAL,
375 .bLockDelayUnits = 0,
379 /* STD AS ISO IN Feedback Endpoint */
380 static struct usb_endpoint_descriptor fs_epin_fback_desc = {
381 .bLength = USB_DT_ENDPOINT_SIZE,
382 .bDescriptorType = USB_DT_ENDPOINT,
384 .bEndpointAddress = USB_DIR_IN,
385 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_USAGE_FEEDBACK,
386 .wMaxPacketSize = cpu_to_le16(3),
390 static struct usb_endpoint_descriptor hs_epin_fback_desc = {
391 .bLength = USB_DT_ENDPOINT_SIZE,
392 .bDescriptorType = USB_DT_ENDPOINT,
394 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_USAGE_FEEDBACK,
395 .wMaxPacketSize = cpu_to_le16(4),
399 static struct usb_endpoint_descriptor ss_epin_fback_desc = {
400 .bLength = USB_DT_ENDPOINT_SIZE,
401 .bDescriptorType = USB_DT_ENDPOINT,
403 .bEndpointAddress = USB_DIR_IN,
404 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_USAGE_FEEDBACK,
405 .wMaxPacketSize = cpu_to_le16(4),
409 static struct usb_ss_ep_comp_descriptor ss_epin_fback_desc_comp = {
410 .bLength = sizeof(ss_epin_fback_desc_comp),
411 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
414 .wBytesPerInterval = cpu_to_le16(4),
418 /* Audio Streaming IN Interface - Alt0 */
419 static struct usb_interface_descriptor std_as_in_if0_desc = {
420 .bLength = sizeof std_as_in_if0_desc,
421 .bDescriptorType = USB_DT_INTERFACE,
423 .bAlternateSetting = 0,
425 .bInterfaceClass = USB_CLASS_AUDIO,
426 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
427 .bInterfaceProtocol = UAC_VERSION_2,
430 /* Audio Streaming IN Interface - Alt1 */
431 static struct usb_interface_descriptor std_as_in_if1_desc = {
432 .bLength = sizeof std_as_in_if1_desc,
433 .bDescriptorType = USB_DT_INTERFACE,
435 .bAlternateSetting = 1,
437 .bInterfaceClass = USB_CLASS_AUDIO,
438 .bInterfaceSubClass = USB_SUBCLASS_AUDIOSTREAMING,
439 .bInterfaceProtocol = UAC_VERSION_2,
442 /* Audio Stream IN Intface Desc */
443 static struct uac2_as_header_descriptor as_in_hdr_desc = {
444 .bLength = sizeof as_in_hdr_desc,
445 .bDescriptorType = USB_DT_CS_INTERFACE,
447 .bDescriptorSubtype = UAC_AS_GENERAL,
448 /* .bTerminalLink = DYNAMIC */
450 .bFormatType = UAC_FORMAT_TYPE_I,
451 .bmFormats = cpu_to_le32(UAC_FORMAT_TYPE_I_PCM),
455 /* Audio USB_IN Format */
456 static struct uac2_format_type_i_descriptor as_in_fmt1_desc = {
457 .bLength = sizeof as_in_fmt1_desc,
458 .bDescriptorType = USB_DT_CS_INTERFACE,
459 .bDescriptorSubtype = UAC_FORMAT_TYPE,
460 .bFormatType = UAC_FORMAT_TYPE_I,
463 /* STD AS ISO IN Endpoint */
464 static struct usb_endpoint_descriptor fs_epin_desc = {
465 .bLength = USB_DT_ENDPOINT_SIZE,
466 .bDescriptorType = USB_DT_ENDPOINT,
468 .bEndpointAddress = USB_DIR_IN,
469 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
470 /* .wMaxPacketSize = DYNAMIC */
474 static struct usb_endpoint_descriptor hs_epin_desc = {
475 .bLength = USB_DT_ENDPOINT_SIZE,
476 .bDescriptorType = USB_DT_ENDPOINT,
478 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
479 /* .wMaxPacketSize = DYNAMIC */
483 static struct usb_endpoint_descriptor ss_epin_desc = {
484 .bLength = USB_DT_ENDPOINT_SIZE,
485 .bDescriptorType = USB_DT_ENDPOINT,
487 .bEndpointAddress = USB_DIR_IN,
488 .bmAttributes = USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC,
489 /* .wMaxPacketSize = DYNAMIC */
493 static struct usb_ss_ep_comp_descriptor ss_epin_desc_comp = {
494 .bLength = sizeof(ss_epin_desc_comp),
495 .bDescriptorType = USB_DT_SS_ENDPOINT_COMP,
498 /* wBytesPerInterval = DYNAMIC */
501 /* CS AS ISO IN Endpoint */
502 static struct uac2_iso_endpoint_descriptor as_iso_in_desc = {
503 .bLength = sizeof as_iso_in_desc,
504 .bDescriptorType = USB_DT_CS_ENDPOINT,
506 .bDescriptorSubtype = UAC_EP_GENERAL,
509 .bLockDelayUnits = 0,
513 static struct usb_descriptor_header *fs_audio_desc[] = {
514 (struct usb_descriptor_header *)&iad_desc,
515 (struct usb_descriptor_header *)&std_ac_if_desc,
517 (struct usb_descriptor_header *)&ac_hdr_desc,
518 (struct usb_descriptor_header *)&in_clk_src_desc,
519 (struct usb_descriptor_header *)&out_clk_src_desc,
520 (struct usb_descriptor_header *)&usb_out_it_desc,
521 (struct usb_descriptor_header *)&out_feature_unit_desc,
522 (struct usb_descriptor_header *)&io_in_it_desc,
523 (struct usb_descriptor_header *)&usb_in_ot_desc,
524 (struct usb_descriptor_header *)&in_feature_unit_desc,
525 (struct usb_descriptor_header *)&io_out_ot_desc,
527 (struct usb_descriptor_header *)&fs_ep_int_desc,
529 (struct usb_descriptor_header *)&std_as_out_if0_desc,
530 (struct usb_descriptor_header *)&std_as_out_if1_desc,
532 (struct usb_descriptor_header *)&as_out_hdr_desc,
533 (struct usb_descriptor_header *)&as_out_fmt1_desc,
534 (struct usb_descriptor_header *)&fs_epout_desc,
535 (struct usb_descriptor_header *)&as_iso_out_desc,
536 (struct usb_descriptor_header *)&fs_epin_fback_desc,
538 (struct usb_descriptor_header *)&std_as_in_if0_desc,
539 (struct usb_descriptor_header *)&std_as_in_if1_desc,
541 (struct usb_descriptor_header *)&as_in_hdr_desc,
542 (struct usb_descriptor_header *)&as_in_fmt1_desc,
543 (struct usb_descriptor_header *)&fs_epin_desc,
544 (struct usb_descriptor_header *)&as_iso_in_desc,
548 static struct usb_descriptor_header *hs_audio_desc[] = {
549 (struct usb_descriptor_header *)&iad_desc,
550 (struct usb_descriptor_header *)&std_ac_if_desc,
552 (struct usb_descriptor_header *)&ac_hdr_desc,
553 (struct usb_descriptor_header *)&in_clk_src_desc,
554 (struct usb_descriptor_header *)&out_clk_src_desc,
555 (struct usb_descriptor_header *)&usb_out_it_desc,
556 (struct usb_descriptor_header *)&out_feature_unit_desc,
557 (struct usb_descriptor_header *)&io_in_it_desc,
558 (struct usb_descriptor_header *)&usb_in_ot_desc,
559 (struct usb_descriptor_header *)&in_feature_unit_desc,
560 (struct usb_descriptor_header *)&io_out_ot_desc,
562 (struct usb_descriptor_header *)&hs_ep_int_desc,
564 (struct usb_descriptor_header *)&std_as_out_if0_desc,
565 (struct usb_descriptor_header *)&std_as_out_if1_desc,
567 (struct usb_descriptor_header *)&as_out_hdr_desc,
568 (struct usb_descriptor_header *)&as_out_fmt1_desc,
569 (struct usb_descriptor_header *)&hs_epout_desc,
570 (struct usb_descriptor_header *)&as_iso_out_desc,
571 (struct usb_descriptor_header *)&hs_epin_fback_desc,
573 (struct usb_descriptor_header *)&std_as_in_if0_desc,
574 (struct usb_descriptor_header *)&std_as_in_if1_desc,
576 (struct usb_descriptor_header *)&as_in_hdr_desc,
577 (struct usb_descriptor_header *)&as_in_fmt1_desc,
578 (struct usb_descriptor_header *)&hs_epin_desc,
579 (struct usb_descriptor_header *)&as_iso_in_desc,
583 static struct usb_descriptor_header *ss_audio_desc[] = {
584 (struct usb_descriptor_header *)&iad_desc,
585 (struct usb_descriptor_header *)&std_ac_if_desc,
587 (struct usb_descriptor_header *)&ac_hdr_desc,
588 (struct usb_descriptor_header *)&in_clk_src_desc,
589 (struct usb_descriptor_header *)&out_clk_src_desc,
590 (struct usb_descriptor_header *)&usb_out_it_desc,
591 (struct usb_descriptor_header *)&out_feature_unit_desc,
592 (struct usb_descriptor_header *)&io_in_it_desc,
593 (struct usb_descriptor_header *)&usb_in_ot_desc,
594 (struct usb_descriptor_header *)&in_feature_unit_desc,
595 (struct usb_descriptor_header *)&io_out_ot_desc,
597 (struct usb_descriptor_header *)&ss_ep_int_desc,
599 (struct usb_descriptor_header *)&std_as_out_if0_desc,
600 (struct usb_descriptor_header *)&std_as_out_if1_desc,
602 (struct usb_descriptor_header *)&as_out_hdr_desc,
603 (struct usb_descriptor_header *)&as_out_fmt1_desc,
604 (struct usb_descriptor_header *)&ss_epout_desc,
605 (struct usb_descriptor_header *)&ss_epout_desc_comp,
606 (struct usb_descriptor_header *)&as_iso_out_desc,
607 (struct usb_descriptor_header *)&ss_epin_fback_desc,
608 (struct usb_descriptor_header *)&ss_epin_fback_desc_comp,
610 (struct usb_descriptor_header *)&std_as_in_if0_desc,
611 (struct usb_descriptor_header *)&std_as_in_if1_desc,
613 (struct usb_descriptor_header *)&as_in_hdr_desc,
614 (struct usb_descriptor_header *)&as_in_fmt1_desc,
615 (struct usb_descriptor_header *)&ss_epin_desc,
616 (struct usb_descriptor_header *)&ss_epin_desc_comp,
617 (struct usb_descriptor_header *)&as_iso_in_desc,
621 struct cntrl_cur_lay2 {
625 struct cntrl_range_lay2 {
626 __le16 wNumSubRanges;
632 struct cntrl_cur_lay3 {
636 struct cntrl_range_lay3 {
637 __le16 wNumSubRanges;
643 static int set_ep_max_packet_size(const struct f_uac2_opts *uac2_opts,
644 struct usb_endpoint_descriptor *ep_desc,
645 enum usb_device_speed speed, bool is_playback)
647 int chmask, srate, ssize;
648 u16 max_size_bw, max_size_ep;
658 case USB_SPEED_SUPER:
668 chmask = uac2_opts->p_chmask;
669 srate = uac2_opts->p_srate;
670 ssize = uac2_opts->p_ssize;
672 chmask = uac2_opts->c_chmask;
673 srate = uac2_opts->c_srate;
674 ssize = uac2_opts->c_ssize;
677 if (!is_playback && (uac2_opts->c_sync == USB_ENDPOINT_SYNC_ASYNC)) {
678 // Win10 requires max packet size + 1 frame
679 srate = srate * (1000 + uac2_opts->fb_max) / 1000;
680 // updated srate is always bigger, therefore DIV_ROUND_UP always yields +1
681 max_size_bw = num_channels(chmask) * ssize *
682 (DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1))));
684 // adding 1 frame provision for Win10
685 max_size_bw = num_channels(chmask) * ssize *
686 (DIV_ROUND_UP(srate, factor / (1 << (ep_desc->bInterval - 1))) + 1);
688 ep_desc->wMaxPacketSize = cpu_to_le16(min_t(u16, max_size_bw,
694 static struct uac2_feature_unit_descriptor *build_fu_desc(int chmask)
696 struct uac2_feature_unit_descriptor *fu_desc;
697 int channels = num_channels(chmask);
698 int fu_desc_size = UAC2_DT_FEATURE_UNIT_SIZE(channels);
700 fu_desc = kzalloc(fu_desc_size, GFP_KERNEL);
704 fu_desc->bLength = fu_desc_size;
705 fu_desc->bDescriptorType = USB_DT_CS_INTERFACE;
707 fu_desc->bDescriptorSubtype = UAC_FEATURE_UNIT;
709 /* bUnitID, bSourceID and bmaControls will be defined later */
714 /* Use macro to overcome line length limitation */
715 #define USBDHDR(p) (struct usb_descriptor_header *)(p)
717 static void setup_headers(struct f_uac2_opts *opts,
718 struct usb_descriptor_header **headers,
719 enum usb_device_speed speed)
721 struct usb_ss_ep_comp_descriptor *epout_desc_comp = NULL;
722 struct usb_ss_ep_comp_descriptor *epin_desc_comp = NULL;
723 struct usb_ss_ep_comp_descriptor *epin_fback_desc_comp = NULL;
724 struct usb_endpoint_descriptor *epout_desc;
725 struct usb_endpoint_descriptor *epin_desc;
726 struct usb_endpoint_descriptor *epin_fback_desc;
727 struct usb_endpoint_descriptor *ep_int_desc;
732 epout_desc = &fs_epout_desc;
733 epin_desc = &fs_epin_desc;
734 epin_fback_desc = &fs_epin_fback_desc;
735 ep_int_desc = &fs_ep_int_desc;
738 epout_desc = &hs_epout_desc;
739 epin_desc = &hs_epin_desc;
740 epin_fback_desc = &hs_epin_fback_desc;
741 ep_int_desc = &hs_ep_int_desc;
744 epout_desc = &ss_epout_desc;
745 epin_desc = &ss_epin_desc;
746 epout_desc_comp = &ss_epout_desc_comp;
747 epin_desc_comp = &ss_epin_desc_comp;
748 epin_fback_desc = &ss_epin_fback_desc;
749 epin_fback_desc_comp = &ss_epin_fback_desc_comp;
750 ep_int_desc = &ss_ep_int_desc;
754 headers[i++] = USBDHDR(&iad_desc);
755 headers[i++] = USBDHDR(&std_ac_if_desc);
756 headers[i++] = USBDHDR(&ac_hdr_desc);
758 headers[i++] = USBDHDR(&in_clk_src_desc);
759 if (EPOUT_EN(opts)) {
760 headers[i++] = USBDHDR(&out_clk_src_desc);
761 headers[i++] = USBDHDR(&usb_out_it_desc);
764 headers[i++] = USBDHDR(out_feature_unit_desc);
768 headers[i++] = USBDHDR(&io_in_it_desc);
771 headers[i++] = USBDHDR(in_feature_unit_desc);
773 headers[i++] = USBDHDR(&usb_in_ot_desc);
777 headers[i++] = USBDHDR(&io_out_ot_desc);
779 if (FUOUT_EN(opts) || FUIN_EN(opts))
780 headers[i++] = USBDHDR(ep_int_desc);
782 if (EPOUT_EN(opts)) {
783 headers[i++] = USBDHDR(&std_as_out_if0_desc);
784 headers[i++] = USBDHDR(&std_as_out_if1_desc);
785 headers[i++] = USBDHDR(&as_out_hdr_desc);
786 headers[i++] = USBDHDR(&as_out_fmt1_desc);
787 headers[i++] = USBDHDR(epout_desc);
789 headers[i++] = USBDHDR(epout_desc_comp);
791 headers[i++] = USBDHDR(&as_iso_out_desc);
793 if (EPOUT_FBACK_IN_EN(opts)) {
794 headers[i++] = USBDHDR(epin_fback_desc);
795 if (epin_fback_desc_comp)
796 headers[i++] = USBDHDR(epin_fback_desc_comp);
801 headers[i++] = USBDHDR(&std_as_in_if0_desc);
802 headers[i++] = USBDHDR(&std_as_in_if1_desc);
803 headers[i++] = USBDHDR(&as_in_hdr_desc);
804 headers[i++] = USBDHDR(&as_in_fmt1_desc);
805 headers[i++] = USBDHDR(epin_desc);
807 headers[i++] = USBDHDR(epin_desc_comp);
809 headers[i++] = USBDHDR(&as_iso_in_desc);
814 static void setup_descriptor(struct f_uac2_opts *opts)
816 /* patch descriptors */
817 int i = 1; /* ID's start with 1 */
820 usb_out_it_desc.bTerminalID = i++;
822 io_in_it_desc.bTerminalID = i++;
824 io_out_ot_desc.bTerminalID = i++;
826 usb_in_ot_desc.bTerminalID = i++;
828 out_feature_unit_desc->bUnitID = i++;
830 in_feature_unit_desc->bUnitID = i++;
832 out_clk_src_desc.bClockID = i++;
834 in_clk_src_desc.bClockID = i++;
836 usb_out_it_desc.bCSourceID = out_clk_src_desc.bClockID;
839 usb_in_ot_desc.bSourceID = in_feature_unit_desc->bUnitID;
840 in_feature_unit_desc->bSourceID = io_in_it_desc.bTerminalID;
842 usb_in_ot_desc.bSourceID = io_in_it_desc.bTerminalID;
845 usb_in_ot_desc.bCSourceID = in_clk_src_desc.bClockID;
846 io_in_it_desc.bCSourceID = in_clk_src_desc.bClockID;
847 io_out_ot_desc.bCSourceID = out_clk_src_desc.bClockID;
849 if (FUOUT_EN(opts)) {
850 io_out_ot_desc.bSourceID = out_feature_unit_desc->bUnitID;
851 out_feature_unit_desc->bSourceID = usb_out_it_desc.bTerminalID;
853 io_out_ot_desc.bSourceID = usb_out_it_desc.bTerminalID;
856 as_out_hdr_desc.bTerminalLink = usb_out_it_desc.bTerminalID;
857 as_in_hdr_desc.bTerminalLink = usb_in_ot_desc.bTerminalID;
859 iad_desc.bInterfaceCount = 1;
860 ac_hdr_desc.wTotalLength = cpu_to_le16(sizeof(ac_hdr_desc));
863 u16 len = le16_to_cpu(ac_hdr_desc.wTotalLength);
865 len += sizeof(in_clk_src_desc);
866 len += sizeof(usb_in_ot_desc);
869 len += in_feature_unit_desc->bLength;
871 len += sizeof(io_in_it_desc);
872 ac_hdr_desc.wTotalLength = cpu_to_le16(len);
873 iad_desc.bInterfaceCount++;
875 if (EPOUT_EN(opts)) {
876 u16 len = le16_to_cpu(ac_hdr_desc.wTotalLength);
878 len += sizeof(out_clk_src_desc);
879 len += sizeof(usb_out_it_desc);
882 len += out_feature_unit_desc->bLength;
884 len += sizeof(io_out_ot_desc);
885 ac_hdr_desc.wTotalLength = cpu_to_le16(len);
886 iad_desc.bInterfaceCount++;
889 setup_headers(opts, fs_audio_desc, USB_SPEED_FULL);
890 setup_headers(opts, hs_audio_desc, USB_SPEED_HIGH);
891 setup_headers(opts, ss_audio_desc, USB_SPEED_SUPER);
894 static int afunc_validate_opts(struct g_audio *agdev, struct device *dev)
896 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev);
898 if (!opts->p_chmask && !opts->c_chmask) {
899 dev_err(dev, "Error: no playback and capture channels\n");
901 } else if (opts->p_chmask & ~UAC2_CHANNEL_MASK) {
902 dev_err(dev, "Error: unsupported playback channels mask\n");
904 } else if (opts->c_chmask & ~UAC2_CHANNEL_MASK) {
905 dev_err(dev, "Error: unsupported capture channels mask\n");
907 } else if ((opts->p_ssize < 1) || (opts->p_ssize > 4)) {
908 dev_err(dev, "Error: incorrect playback sample size\n");
910 } else if ((opts->c_ssize < 1) || (opts->c_ssize > 4)) {
911 dev_err(dev, "Error: incorrect capture sample size\n");
913 } else if (!opts->p_srate) {
914 dev_err(dev, "Error: incorrect playback sampling rate\n");
916 } else if (!opts->c_srate) {
917 dev_err(dev, "Error: incorrect capture sampling rate\n");
921 if (opts->p_volume_max <= opts->p_volume_min) {
922 dev_err(dev, "Error: incorrect playback volume max/min\n");
924 } else if (opts->c_volume_max <= opts->c_volume_min) {
925 dev_err(dev, "Error: incorrect capture volume max/min\n");
927 } else if (opts->p_volume_res <= 0) {
928 dev_err(dev, "Error: negative/zero playback volume resolution\n");
930 } else if (opts->c_volume_res <= 0) {
931 dev_err(dev, "Error: negative/zero capture volume resolution\n");
935 if ((opts->p_volume_max - opts->p_volume_min) % opts->p_volume_res) {
936 dev_err(dev, "Error: incorrect playback volume resolution\n");
938 } else if ((opts->c_volume_max - opts->c_volume_min) % opts->c_volume_res) {
939 dev_err(dev, "Error: incorrect capture volume resolution\n");
947 afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
949 struct f_uac2 *uac2 = func_to_uac2(fn);
950 struct g_audio *agdev = func_to_g_audio(fn);
951 struct usb_composite_dev *cdev = cfg->cdev;
952 struct usb_gadget *gadget = cdev->gadget;
953 struct device *dev = &gadget->dev;
954 struct f_uac2_opts *uac2_opts = g_audio_to_uac2_opts(agdev);
955 struct usb_string *us;
958 ret = afunc_validate_opts(agdev, dev);
962 us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn));
966 if (FUOUT_EN(uac2_opts)) {
967 out_feature_unit_desc = build_fu_desc(uac2_opts->c_chmask);
968 if (!out_feature_unit_desc)
971 if (FUIN_EN(uac2_opts)) {
972 in_feature_unit_desc = build_fu_desc(uac2_opts->p_chmask);
973 if (!in_feature_unit_desc) {
979 iad_desc.iFunction = us[STR_ASSOC].id;
980 std_ac_if_desc.iInterface = us[STR_IF_CTRL].id;
981 in_clk_src_desc.iClockSource = us[STR_CLKSRC_IN].id;
982 out_clk_src_desc.iClockSource = us[STR_CLKSRC_OUT].id;
983 usb_out_it_desc.iTerminal = us[STR_USB_IT].id;
984 io_in_it_desc.iTerminal = us[STR_IO_IT].id;
985 usb_in_ot_desc.iTerminal = us[STR_USB_OT].id;
986 io_out_ot_desc.iTerminal = us[STR_IO_OT].id;
987 std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id;
988 std_as_out_if1_desc.iInterface = us[STR_AS_OUT_ALT1].id;
989 std_as_in_if0_desc.iInterface = us[STR_AS_IN_ALT0].id;
990 std_as_in_if1_desc.iInterface = us[STR_AS_IN_ALT1].id;
992 if (FUOUT_EN(uac2_opts)) {
993 u8 *i_feature = (u8 *)out_feature_unit_desc +
994 out_feature_unit_desc->bLength - 1;
995 *i_feature = us[STR_FU_OUT].id;
997 if (FUIN_EN(uac2_opts)) {
998 u8 *i_feature = (u8 *)in_feature_unit_desc +
999 in_feature_unit_desc->bLength - 1;
1000 *i_feature = us[STR_FU_IN].id;
1004 /* Initialize the configurable parameters */
1005 usb_out_it_desc.bNrChannels = num_channels(uac2_opts->c_chmask);
1006 usb_out_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask);
1007 io_in_it_desc.bNrChannels = num_channels(uac2_opts->p_chmask);
1008 io_in_it_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask);
1009 as_out_hdr_desc.bNrChannels = num_channels(uac2_opts->c_chmask);
1010 as_out_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->c_chmask);
1011 as_in_hdr_desc.bNrChannels = num_channels(uac2_opts->p_chmask);
1012 as_in_hdr_desc.bmChannelConfig = cpu_to_le32(uac2_opts->p_chmask);
1013 as_out_fmt1_desc.bSubslotSize = uac2_opts->c_ssize;
1014 as_out_fmt1_desc.bBitResolution = uac2_opts->c_ssize * 8;
1015 as_in_fmt1_desc.bSubslotSize = uac2_opts->p_ssize;
1016 as_in_fmt1_desc.bBitResolution = uac2_opts->p_ssize * 8;
1017 if (FUOUT_EN(uac2_opts)) {
1018 __le32 *bma = (__le32 *)&out_feature_unit_desc->bmaControls[0];
1021 if (uac2_opts->c_mute_present)
1022 control |= CONTROL_RDWR << FU_MUTE_CTRL;
1023 if (uac2_opts->c_volume_present)
1024 control |= CONTROL_RDWR << FU_VOL_CTRL;
1025 *bma = cpu_to_le32(control);
1027 if (FUIN_EN(uac2_opts)) {
1028 __le32 *bma = (__le32 *)&in_feature_unit_desc->bmaControls[0];
1031 if (uac2_opts->p_mute_present)
1032 control |= CONTROL_RDWR << FU_MUTE_CTRL;
1033 if (uac2_opts->p_volume_present)
1034 control |= CONTROL_RDWR << FU_VOL_CTRL;
1035 *bma = cpu_to_le32(control);
1038 snprintf(clksrc_in, sizeof(clksrc_in), "%uHz", uac2_opts->p_srate);
1039 snprintf(clksrc_out, sizeof(clksrc_out), "%uHz", uac2_opts->c_srate);
1041 ret = usb_interface_id(cfg, fn);
1043 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1046 iad_desc.bFirstInterface = ret;
1048 std_ac_if_desc.bInterfaceNumber = ret;
1049 uac2->ac_intf = ret;
1052 if (EPOUT_EN(uac2_opts)) {
1053 ret = usb_interface_id(cfg, fn);
1055 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1058 std_as_out_if0_desc.bInterfaceNumber = ret;
1059 std_as_out_if1_desc.bInterfaceNumber = ret;
1060 uac2->as_out_intf = ret;
1061 uac2->as_out_alt = 0;
1063 if (EPOUT_FBACK_IN_EN(uac2_opts)) {
1064 fs_epout_desc.bmAttributes =
1065 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC;
1066 hs_epout_desc.bmAttributes =
1067 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC;
1068 ss_epout_desc.bmAttributes =
1069 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ASYNC;
1070 std_as_out_if1_desc.bNumEndpoints++;
1072 fs_epout_desc.bmAttributes =
1073 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ADAPTIVE;
1074 hs_epout_desc.bmAttributes =
1075 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ADAPTIVE;
1076 ss_epout_desc.bmAttributes =
1077 USB_ENDPOINT_XFER_ISOC | USB_ENDPOINT_SYNC_ADAPTIVE;
1081 if (EPIN_EN(uac2_opts)) {
1082 ret = usb_interface_id(cfg, fn);
1084 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1087 std_as_in_if0_desc.bInterfaceNumber = ret;
1088 std_as_in_if1_desc.bInterfaceNumber = ret;
1089 uac2->as_in_intf = ret;
1090 uac2->as_in_alt = 0;
1093 if (FUOUT_EN(uac2_opts) || FUIN_EN(uac2_opts)) {
1094 uac2->int_ep = usb_ep_autoconfig(gadget, &fs_ep_int_desc);
1095 if (!uac2->int_ep) {
1096 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1101 std_ac_if_desc.bNumEndpoints = 1;
1104 /* Calculate wMaxPacketSize according to audio bandwidth */
1105 ret = set_ep_max_packet_size(uac2_opts, &fs_epin_desc, USB_SPEED_FULL,
1108 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1112 ret = set_ep_max_packet_size(uac2_opts, &fs_epout_desc, USB_SPEED_FULL,
1115 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1119 ret = set_ep_max_packet_size(uac2_opts, &hs_epin_desc, USB_SPEED_HIGH,
1122 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1126 ret = set_ep_max_packet_size(uac2_opts, &hs_epout_desc, USB_SPEED_HIGH,
1129 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1133 ret = set_ep_max_packet_size(uac2_opts, &ss_epin_desc, USB_SPEED_SUPER,
1136 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1140 ret = set_ep_max_packet_size(uac2_opts, &ss_epout_desc, USB_SPEED_SUPER,
1143 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1147 if (EPOUT_EN(uac2_opts)) {
1148 agdev->out_ep = usb_ep_autoconfig(gadget, &fs_epout_desc);
1149 if (!agdev->out_ep) {
1150 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1154 if (EPOUT_FBACK_IN_EN(uac2_opts)) {
1155 agdev->in_ep_fback = usb_ep_autoconfig(gadget,
1156 &fs_epin_fback_desc);
1157 if (!agdev->in_ep_fback) {
1158 dev_err(dev, "%s:%d Error!\n",
1159 __func__, __LINE__);
1166 if (EPIN_EN(uac2_opts)) {
1167 agdev->in_ep = usb_ep_autoconfig(gadget, &fs_epin_desc);
1168 if (!agdev->in_ep) {
1169 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1175 agdev->in_ep_maxpsize = max_t(u16,
1176 le16_to_cpu(fs_epin_desc.wMaxPacketSize),
1177 le16_to_cpu(hs_epin_desc.wMaxPacketSize));
1178 agdev->out_ep_maxpsize = max_t(u16,
1179 le16_to_cpu(fs_epout_desc.wMaxPacketSize),
1180 le16_to_cpu(hs_epout_desc.wMaxPacketSize));
1182 agdev->in_ep_maxpsize = max_t(u16, agdev->in_ep_maxpsize,
1183 le16_to_cpu(ss_epin_desc.wMaxPacketSize));
1184 agdev->out_ep_maxpsize = max_t(u16, agdev->out_ep_maxpsize,
1185 le16_to_cpu(ss_epout_desc.wMaxPacketSize));
1187 ss_epin_desc_comp.wBytesPerInterval = ss_epin_desc.wMaxPacketSize;
1188 ss_epout_desc_comp.wBytesPerInterval = ss_epout_desc.wMaxPacketSize;
1190 // HS and SS endpoint addresses are copied from autoconfigured FS descriptors
1191 hs_ep_int_desc.bEndpointAddress = fs_ep_int_desc.bEndpointAddress;
1192 hs_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
1193 hs_epin_fback_desc.bEndpointAddress = fs_epin_fback_desc.bEndpointAddress;
1194 hs_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;
1195 ss_epout_desc.bEndpointAddress = fs_epout_desc.bEndpointAddress;
1196 ss_epin_fback_desc.bEndpointAddress = fs_epin_fback_desc.bEndpointAddress;
1197 ss_epin_desc.bEndpointAddress = fs_epin_desc.bEndpointAddress;
1198 ss_ep_int_desc.bEndpointAddress = fs_ep_int_desc.bEndpointAddress;
1200 setup_descriptor(uac2_opts);
1202 ret = usb_assign_descriptors(fn, fs_audio_desc, hs_audio_desc, ss_audio_desc,
1207 agdev->gadget = gadget;
1209 agdev->params.p_chmask = uac2_opts->p_chmask;
1210 agdev->params.p_srate = uac2_opts->p_srate;
1211 agdev->params.p_ssize = uac2_opts->p_ssize;
1212 if (FUIN_EN(uac2_opts)) {
1213 agdev->params.p_fu.id = USB_IN_FU_ID;
1214 agdev->params.p_fu.mute_present = uac2_opts->p_mute_present;
1215 agdev->params.p_fu.volume_present = uac2_opts->p_volume_present;
1216 agdev->params.p_fu.volume_min = uac2_opts->p_volume_min;
1217 agdev->params.p_fu.volume_max = uac2_opts->p_volume_max;
1218 agdev->params.p_fu.volume_res = uac2_opts->p_volume_res;
1220 agdev->params.c_chmask = uac2_opts->c_chmask;
1221 agdev->params.c_srate = uac2_opts->c_srate;
1222 agdev->params.c_ssize = uac2_opts->c_ssize;
1223 if (FUOUT_EN(uac2_opts)) {
1224 agdev->params.c_fu.id = USB_OUT_FU_ID;
1225 agdev->params.c_fu.mute_present = uac2_opts->c_mute_present;
1226 agdev->params.c_fu.volume_present = uac2_opts->c_volume_present;
1227 agdev->params.c_fu.volume_min = uac2_opts->c_volume_min;
1228 agdev->params.c_fu.volume_max = uac2_opts->c_volume_max;
1229 agdev->params.c_fu.volume_res = uac2_opts->c_volume_res;
1231 agdev->params.req_number = uac2_opts->req_number;
1232 agdev->params.fb_max = uac2_opts->fb_max;
1234 if (FUOUT_EN(uac2_opts) || FUIN_EN(uac2_opts))
1235 agdev->notify = afunc_notify;
1237 ret = g_audio_setup(agdev, "UAC2 PCM", "UAC2_Gadget");
1239 goto err_free_descs;
1244 usb_free_all_descriptors(fn);
1245 agdev->gadget = NULL;
1247 kfree(out_feature_unit_desc);
1248 out_feature_unit_desc = NULL;
1249 kfree(in_feature_unit_desc);
1250 in_feature_unit_desc = NULL;
1255 afunc_notify_complete(struct usb_ep *_ep, struct usb_request *req)
1257 struct g_audio *agdev = req->context;
1258 struct f_uac2 *uac2 = func_to_uac2(&agdev->func);
1260 atomic_dec(&uac2->int_count);
1262 usb_ep_free_request(_ep, req);
1266 afunc_notify(struct g_audio *agdev, int unit_id, int cs)
1268 struct f_uac2 *uac2 = func_to_uac2(&agdev->func);
1269 struct usb_request *req;
1270 struct uac2_interrupt_data_msg *msg;
1271 u16 w_index, w_value;
1274 if (!uac2->int_ep->enabled)
1277 if (atomic_inc_return(&uac2->int_count) > UAC2_DEF_INT_REQ_NUM) {
1278 atomic_dec(&uac2->int_count);
1282 req = usb_ep_alloc_request(uac2->int_ep, GFP_ATOMIC);
1285 goto err_dec_int_count;
1288 msg = kzalloc(sizeof(*msg), GFP_ATOMIC);
1291 goto err_free_request;
1294 w_index = unit_id << 8 | uac2->ac_intf;
1297 msg->bInfo = 0; /* Non-vendor, interface interrupt */
1298 msg->bAttribute = UAC2_CS_CUR;
1299 msg->wIndex = cpu_to_le16(w_index);
1300 msg->wValue = cpu_to_le16(w_value);
1302 req->length = sizeof(*msg);
1304 req->context = agdev;
1305 req->complete = afunc_notify_complete;
1307 ret = usb_ep_queue(uac2->int_ep, req, GFP_ATOMIC);
1317 usb_ep_free_request(uac2->int_ep, req);
1319 atomic_dec(&uac2->int_count);
1325 afunc_set_alt(struct usb_function *fn, unsigned intf, unsigned alt)
1327 struct usb_composite_dev *cdev = fn->config->cdev;
1328 struct f_uac2 *uac2 = func_to_uac2(fn);
1329 struct g_audio *agdev = func_to_g_audio(fn);
1330 struct usb_gadget *gadget = cdev->gadget;
1331 struct device *dev = &gadget->dev;
1334 /* No i/f has more than 2 alt settings */
1336 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1340 if (intf == uac2->ac_intf) {
1341 /* Control I/f has only 1 AltSetting - 0 */
1343 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1347 /* restart interrupt endpoint */
1349 usb_ep_disable(uac2->int_ep);
1350 config_ep_by_speed(gadget, &agdev->func, uac2->int_ep);
1351 usb_ep_enable(uac2->int_ep);
1357 if (intf == uac2->as_out_intf) {
1358 uac2->as_out_alt = alt;
1361 ret = u_audio_start_capture(&uac2->g_audio);
1363 u_audio_stop_capture(&uac2->g_audio);
1364 } else if (intf == uac2->as_in_intf) {
1365 uac2->as_in_alt = alt;
1368 ret = u_audio_start_playback(&uac2->g_audio);
1370 u_audio_stop_playback(&uac2->g_audio);
1372 dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
1380 afunc_get_alt(struct usb_function *fn, unsigned intf)
1382 struct f_uac2 *uac2 = func_to_uac2(fn);
1383 struct g_audio *agdev = func_to_g_audio(fn);
1385 if (intf == uac2->ac_intf)
1386 return uac2->ac_alt;
1387 else if (intf == uac2->as_out_intf)
1388 return uac2->as_out_alt;
1389 else if (intf == uac2->as_in_intf)
1390 return uac2->as_in_alt;
1392 dev_err(&agdev->gadget->dev,
1393 "%s:%d Invalid Interface %d!\n",
1394 __func__, __LINE__, intf);
1400 afunc_disable(struct usb_function *fn)
1402 struct f_uac2 *uac2 = func_to_uac2(fn);
1404 uac2->as_in_alt = 0;
1405 uac2->as_out_alt = 0;
1406 u_audio_stop_capture(&uac2->g_audio);
1407 u_audio_stop_playback(&uac2->g_audio);
1409 usb_ep_disable(uac2->int_ep);
1413 in_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1415 struct usb_request *req = fn->config->cdev->req;
1416 struct g_audio *agdev = func_to_g_audio(fn);
1417 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev);
1418 u16 w_length = le16_to_cpu(cr->wLength);
1419 u16 w_index = le16_to_cpu(cr->wIndex);
1420 u16 w_value = le16_to_cpu(cr->wValue);
1421 u8 entity_id = (w_index >> 8) & 0xff;
1422 u8 control_selector = w_value >> 8;
1423 int value = -EOPNOTSUPP;
1424 int p_srate, c_srate;
1426 p_srate = opts->p_srate;
1427 c_srate = opts->c_srate;
1429 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) {
1430 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
1431 struct cntrl_cur_lay3 c;
1433 memset(&c, 0, sizeof(struct cntrl_cur_lay3));
1435 if (entity_id == USB_IN_CLK_ID)
1436 c.dCUR = cpu_to_le32(p_srate);
1437 else if (entity_id == USB_OUT_CLK_ID)
1438 c.dCUR = cpu_to_le32(c_srate);
1440 value = min_t(unsigned int, w_length, sizeof(c));
1441 memcpy(req->buf, &c, value);
1442 } else if (control_selector == UAC2_CS_CONTROL_CLOCK_VALID) {
1443 *(u8 *)req->buf = 1;
1444 value = min_t(unsigned int, w_length, 1);
1446 dev_err(&agdev->gadget->dev,
1447 "%s:%d control_selector=%d TODO!\n",
1448 __func__, __LINE__, control_selector);
1450 } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
1451 (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
1452 unsigned int is_playback = 0;
1454 if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
1457 if (control_selector == UAC_FU_MUTE) {
1460 u_audio_get_mute(agdev, is_playback, &mute);
1462 *(u8 *)req->buf = mute;
1463 value = min_t(unsigned int, w_length, 1);
1464 } else if (control_selector == UAC_FU_VOLUME) {
1465 struct cntrl_cur_lay2 c;
1468 memset(&c, 0, sizeof(struct cntrl_cur_lay2));
1470 u_audio_get_volume(agdev, is_playback, &volume);
1471 c.wCUR = cpu_to_le16(volume);
1473 value = min_t(unsigned int, w_length, sizeof(c));
1474 memcpy(req->buf, &c, value);
1476 dev_err(&agdev->gadget->dev,
1477 "%s:%d control_selector=%d TODO!\n",
1478 __func__, __LINE__, control_selector);
1481 dev_err(&agdev->gadget->dev,
1482 "%s:%d entity_id=%d control_selector=%d TODO!\n",
1483 __func__, __LINE__, entity_id, control_selector);
1490 in_rq_range(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1492 struct usb_request *req = fn->config->cdev->req;
1493 struct g_audio *agdev = func_to_g_audio(fn);
1494 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev);
1495 u16 w_length = le16_to_cpu(cr->wLength);
1496 u16 w_index = le16_to_cpu(cr->wIndex);
1497 u16 w_value = le16_to_cpu(cr->wValue);
1498 u8 entity_id = (w_index >> 8) & 0xff;
1499 u8 control_selector = w_value >> 8;
1500 int value = -EOPNOTSUPP;
1501 int p_srate, c_srate;
1503 p_srate = opts->p_srate;
1504 c_srate = opts->c_srate;
1506 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) {
1507 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ) {
1508 struct cntrl_range_lay3 r;
1510 if (entity_id == USB_IN_CLK_ID)
1511 r.dMIN = cpu_to_le32(p_srate);
1512 else if (entity_id == USB_OUT_CLK_ID)
1513 r.dMIN = cpu_to_le32(c_srate);
1519 r.wNumSubRanges = cpu_to_le16(1);
1521 value = min_t(unsigned int, w_length, sizeof(r));
1522 memcpy(req->buf, &r, value);
1524 dev_err(&agdev->gadget->dev,
1525 "%s:%d control_selector=%d TODO!\n",
1526 __func__, __LINE__, control_selector);
1528 } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
1529 (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
1530 unsigned int is_playback = 0;
1532 if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
1535 if (control_selector == UAC_FU_VOLUME) {
1536 struct cntrl_range_lay2 r;
1537 s16 max_db, min_db, res_db;
1540 max_db = opts->p_volume_max;
1541 min_db = opts->p_volume_min;
1542 res_db = opts->p_volume_res;
1544 max_db = opts->c_volume_max;
1545 min_db = opts->c_volume_min;
1546 res_db = opts->c_volume_res;
1549 r.wMAX = cpu_to_le16(max_db);
1550 r.wMIN = cpu_to_le16(min_db);
1551 r.wRES = cpu_to_le16(res_db);
1552 r.wNumSubRanges = cpu_to_le16(1);
1554 value = min_t(unsigned int, w_length, sizeof(r));
1555 memcpy(req->buf, &r, value);
1557 dev_err(&agdev->gadget->dev,
1558 "%s:%d control_selector=%d TODO!\n",
1559 __func__, __LINE__, control_selector);
1562 dev_err(&agdev->gadget->dev,
1563 "%s:%d entity_id=%d control_selector=%d TODO!\n",
1564 __func__, __LINE__, entity_id, control_selector);
1571 ac_rq_in(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1573 if (cr->bRequest == UAC2_CS_CUR)
1574 return in_rq_cur(fn, cr);
1575 else if (cr->bRequest == UAC2_CS_RANGE)
1576 return in_rq_range(fn, cr);
1582 out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req)
1584 struct g_audio *agdev = req->context;
1585 struct usb_composite_dev *cdev = agdev->func.config->cdev;
1586 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev);
1587 struct f_uac2 *uac2 = func_to_uac2(&agdev->func);
1588 struct usb_ctrlrequest *cr = &uac2->setup_cr;
1589 u16 w_index = le16_to_cpu(cr->wIndex);
1590 u16 w_value = le16_to_cpu(cr->wValue);
1591 u8 entity_id = (w_index >> 8) & 0xff;
1592 u8 control_selector = w_value >> 8;
1594 if (req->status != 0) {
1595 dev_dbg(&cdev->gadget->dev, "completion err %d\n", req->status);
1599 if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
1600 (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
1601 unsigned int is_playback = 0;
1603 if (FUIN_EN(opts) && (entity_id == USB_IN_FU_ID))
1606 if (control_selector == UAC_FU_MUTE) {
1607 u8 mute = *(u8 *)req->buf;
1609 u_audio_set_mute(agdev, is_playback, mute);
1612 } else if (control_selector == UAC_FU_VOLUME) {
1613 struct cntrl_cur_lay2 *c = req->buf;
1616 volume = le16_to_cpu(c->wCUR);
1617 u_audio_set_volume(agdev, is_playback, volume);
1621 dev_err(&agdev->gadget->dev,
1622 "%s:%d control_selector=%d TODO!\n",
1623 __func__, __LINE__, control_selector);
1624 usb_ep_set_halt(ep);
1630 out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1632 struct usb_request *req = fn->config->cdev->req;
1633 struct g_audio *agdev = func_to_g_audio(fn);
1634 struct f_uac2_opts *opts = g_audio_to_uac2_opts(agdev);
1635 struct f_uac2 *uac2 = func_to_uac2(fn);
1636 u16 w_length = le16_to_cpu(cr->wLength);
1637 u16 w_index = le16_to_cpu(cr->wIndex);
1638 u16 w_value = le16_to_cpu(cr->wValue);
1639 u8 entity_id = (w_index >> 8) & 0xff;
1640 u8 control_selector = w_value >> 8;
1642 if ((entity_id == USB_IN_CLK_ID) || (entity_id == USB_OUT_CLK_ID)) {
1643 if (control_selector == UAC2_CS_CONTROL_SAM_FREQ)
1645 } else if ((FUIN_EN(opts) && (entity_id == USB_IN_FU_ID)) ||
1646 (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) {
1647 memcpy(&uac2->setup_cr, cr, sizeof(*cr));
1648 req->context = agdev;
1649 req->complete = out_rq_cur_complete;
1653 dev_err(&agdev->gadget->dev,
1654 "%s:%d entity_id=%d control_selector=%d TODO!\n",
1655 __func__, __LINE__, entity_id, control_selector);
1661 setup_rq_inf(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1663 struct f_uac2 *uac2 = func_to_uac2(fn);
1664 struct g_audio *agdev = func_to_g_audio(fn);
1665 u16 w_index = le16_to_cpu(cr->wIndex);
1666 u8 intf = w_index & 0xff;
1668 if (intf != uac2->ac_intf) {
1669 dev_err(&agdev->gadget->dev,
1670 "%s:%d Error!\n", __func__, __LINE__);
1674 if (cr->bRequestType & USB_DIR_IN)
1675 return ac_rq_in(fn, cr);
1676 else if (cr->bRequest == UAC2_CS_CUR)
1677 return out_rq_cur(fn, cr);
1683 afunc_setup(struct usb_function *fn, const struct usb_ctrlrequest *cr)
1685 struct usb_composite_dev *cdev = fn->config->cdev;
1686 struct g_audio *agdev = func_to_g_audio(fn);
1687 struct usb_request *req = cdev->req;
1688 u16 w_length = le16_to_cpu(cr->wLength);
1689 int value = -EOPNOTSUPP;
1691 /* Only Class specific requests are supposed to reach here */
1692 if ((cr->bRequestType & USB_TYPE_MASK) != USB_TYPE_CLASS)
1695 if ((cr->bRequestType & USB_RECIP_MASK) == USB_RECIP_INTERFACE)
1696 value = setup_rq_inf(fn, cr);
1698 dev_err(&agdev->gadget->dev, "%s:%d Error!\n",
1699 __func__, __LINE__);
1702 req->length = value;
1703 req->zero = value < w_length;
1704 value = usb_ep_queue(cdev->gadget->ep0, req, GFP_ATOMIC);
1706 dev_err(&agdev->gadget->dev,
1707 "%s:%d Error!\n", __func__, __LINE__);
1715 static inline struct f_uac2_opts *to_f_uac2_opts(struct config_item *item)
1717 return container_of(to_config_group(item), struct f_uac2_opts,
1721 static void f_uac2_attr_release(struct config_item *item)
1723 struct f_uac2_opts *opts = to_f_uac2_opts(item);
1725 usb_put_function_instance(&opts->func_inst);
1728 static struct configfs_item_operations f_uac2_item_ops = {
1729 .release = f_uac2_attr_release,
1732 #define uac2_kstrtou32 kstrtou32
1733 #define uac2_kstrtos16 kstrtos16
1734 #define uac2_kstrtobool(s, base, res) kstrtobool((s), (res))
1736 static const char *u32_fmt = "%u\n";
1737 static const char *s16_fmt = "%hd\n";
1738 static const char *bool_fmt = "%u\n";
1740 #define UAC2_ATTRIBUTE(type, name) \
1741 static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \
1744 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1747 mutex_lock(&opts->lock); \
1748 result = sprintf(page, type##_fmt, opts->name); \
1749 mutex_unlock(&opts->lock); \
1754 static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
1755 const char *page, size_t len) \
1757 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1761 mutex_lock(&opts->lock); \
1762 if (opts->refcnt) { \
1767 ret = uac2_kstrto##type(page, 0, &num); \
1775 mutex_unlock(&opts->lock); \
1779 CONFIGFS_ATTR(f_uac2_opts_, name)
1781 #define UAC2_ATTRIBUTE_SYNC(name) \
1782 static ssize_t f_uac2_opts_##name##_show(struct config_item *item, \
1785 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1789 mutex_lock(&opts->lock); \
1790 switch (opts->name) { \
1791 case USB_ENDPOINT_SYNC_ASYNC: \
1794 case USB_ENDPOINT_SYNC_ADAPTIVE: \
1801 result = sprintf(page, "%s\n", str); \
1802 mutex_unlock(&opts->lock); \
1807 static ssize_t f_uac2_opts_##name##_store(struct config_item *item, \
1808 const char *page, size_t len) \
1810 struct f_uac2_opts *opts = to_f_uac2_opts(item); \
1813 mutex_lock(&opts->lock); \
1814 if (opts->refcnt) { \
1819 if (!strncmp(page, "async", 5)) \
1820 opts->name = USB_ENDPOINT_SYNC_ASYNC; \
1821 else if (!strncmp(page, "adaptive", 8)) \
1822 opts->name = USB_ENDPOINT_SYNC_ADAPTIVE; \
1831 mutex_unlock(&opts->lock); \
1835 CONFIGFS_ATTR(f_uac2_opts_, name)
1837 UAC2_ATTRIBUTE(u32, p_chmask);
1838 UAC2_ATTRIBUTE(u32, p_srate);
1839 UAC2_ATTRIBUTE(u32, p_ssize);
1840 UAC2_ATTRIBUTE(u32, c_chmask);
1841 UAC2_ATTRIBUTE(u32, c_srate);
1842 UAC2_ATTRIBUTE_SYNC(c_sync);
1843 UAC2_ATTRIBUTE(u32, c_ssize);
1844 UAC2_ATTRIBUTE(u32, req_number);
1846 UAC2_ATTRIBUTE(bool, p_mute_present);
1847 UAC2_ATTRIBUTE(bool, p_volume_present);
1848 UAC2_ATTRIBUTE(s16, p_volume_min);
1849 UAC2_ATTRIBUTE(s16, p_volume_max);
1850 UAC2_ATTRIBUTE(s16, p_volume_res);
1852 UAC2_ATTRIBUTE(bool, c_mute_present);
1853 UAC2_ATTRIBUTE(bool, c_volume_present);
1854 UAC2_ATTRIBUTE(s16, c_volume_min);
1855 UAC2_ATTRIBUTE(s16, c_volume_max);
1856 UAC2_ATTRIBUTE(s16, c_volume_res);
1857 UAC2_ATTRIBUTE(u32, fb_max);
1859 static struct configfs_attribute *f_uac2_attrs[] = {
1860 &f_uac2_opts_attr_p_chmask,
1861 &f_uac2_opts_attr_p_srate,
1862 &f_uac2_opts_attr_p_ssize,
1863 &f_uac2_opts_attr_c_chmask,
1864 &f_uac2_opts_attr_c_srate,
1865 &f_uac2_opts_attr_c_ssize,
1866 &f_uac2_opts_attr_c_sync,
1867 &f_uac2_opts_attr_req_number,
1868 &f_uac2_opts_attr_fb_max,
1870 &f_uac2_opts_attr_p_mute_present,
1871 &f_uac2_opts_attr_p_volume_present,
1872 &f_uac2_opts_attr_p_volume_min,
1873 &f_uac2_opts_attr_p_volume_max,
1874 &f_uac2_opts_attr_p_volume_res,
1876 &f_uac2_opts_attr_c_mute_present,
1877 &f_uac2_opts_attr_c_volume_present,
1878 &f_uac2_opts_attr_c_volume_min,
1879 &f_uac2_opts_attr_c_volume_max,
1880 &f_uac2_opts_attr_c_volume_res,
1885 static const struct config_item_type f_uac2_func_type = {
1886 .ct_item_ops = &f_uac2_item_ops,
1887 .ct_attrs = f_uac2_attrs,
1888 .ct_owner = THIS_MODULE,
1891 static void afunc_free_inst(struct usb_function_instance *f)
1893 struct f_uac2_opts *opts;
1895 opts = container_of(f, struct f_uac2_opts, func_inst);
1899 static struct usb_function_instance *afunc_alloc_inst(void)
1901 struct f_uac2_opts *opts;
1903 opts = kzalloc(sizeof(*opts), GFP_KERNEL);
1905 return ERR_PTR(-ENOMEM);
1907 mutex_init(&opts->lock);
1908 opts->func_inst.free_func_inst = afunc_free_inst;
1910 config_group_init_type_name(&opts->func_inst.group, "",
1913 opts->p_chmask = UAC2_DEF_PCHMASK;
1914 opts->p_srate = UAC2_DEF_PSRATE;
1915 opts->p_ssize = UAC2_DEF_PSSIZE;
1916 opts->c_chmask = UAC2_DEF_CCHMASK;
1917 opts->c_srate = UAC2_DEF_CSRATE;
1918 opts->c_ssize = UAC2_DEF_CSSIZE;
1919 opts->c_sync = UAC2_DEF_CSYNC;
1921 opts->p_mute_present = UAC2_DEF_MUTE_PRESENT;
1922 opts->p_volume_present = UAC2_DEF_VOLUME_PRESENT;
1923 opts->p_volume_min = UAC2_DEF_MIN_DB;
1924 opts->p_volume_max = UAC2_DEF_MAX_DB;
1925 opts->p_volume_res = UAC2_DEF_RES_DB;
1927 opts->c_mute_present = UAC2_DEF_MUTE_PRESENT;
1928 opts->c_volume_present = UAC2_DEF_VOLUME_PRESENT;
1929 opts->c_volume_min = UAC2_DEF_MIN_DB;
1930 opts->c_volume_max = UAC2_DEF_MAX_DB;
1931 opts->c_volume_res = UAC2_DEF_RES_DB;
1933 opts->req_number = UAC2_DEF_REQ_NUM;
1934 opts->fb_max = UAC2_DEF_FB_MAX;
1935 return &opts->func_inst;
1938 static void afunc_free(struct usb_function *f)
1940 struct g_audio *agdev;
1941 struct f_uac2_opts *opts;
1943 agdev = func_to_g_audio(f);
1944 opts = container_of(f->fi, struct f_uac2_opts, func_inst);
1946 mutex_lock(&opts->lock);
1948 mutex_unlock(&opts->lock);
1951 static void afunc_unbind(struct usb_configuration *c, struct usb_function *f)
1953 struct g_audio *agdev = func_to_g_audio(f);
1955 g_audio_cleanup(agdev);
1956 usb_free_all_descriptors(f);
1958 agdev->gadget = NULL;
1960 kfree(out_feature_unit_desc);
1961 out_feature_unit_desc = NULL;
1962 kfree(in_feature_unit_desc);
1963 in_feature_unit_desc = NULL;
1966 static struct usb_function *afunc_alloc(struct usb_function_instance *fi)
1968 struct f_uac2 *uac2;
1969 struct f_uac2_opts *opts;
1971 uac2 = kzalloc(sizeof(*uac2), GFP_KERNEL);
1973 return ERR_PTR(-ENOMEM);
1975 opts = container_of(fi, struct f_uac2_opts, func_inst);
1976 mutex_lock(&opts->lock);
1978 mutex_unlock(&opts->lock);
1980 uac2->g_audio.func.name = "uac2_func";
1981 uac2->g_audio.func.bind = afunc_bind;
1982 uac2->g_audio.func.unbind = afunc_unbind;
1983 uac2->g_audio.func.set_alt = afunc_set_alt;
1984 uac2->g_audio.func.get_alt = afunc_get_alt;
1985 uac2->g_audio.func.disable = afunc_disable;
1986 uac2->g_audio.func.setup = afunc_setup;
1987 uac2->g_audio.func.free_func = afunc_free;
1989 return &uac2->g_audio.func;
1992 DECLARE_USB_FUNCTION_INIT(uac2, afunc_alloc_inst, afunc_alloc);
1993 MODULE_LICENSE("GPL");
1994 MODULE_AUTHOR("Yadwinder Singh");
1995 MODULE_AUTHOR("Jaswinder Singh");
1996 MODULE_AUTHOR("Ruslan Bilovol");