14 #include <linux/usb/audio.h>
17 #include <linux/module.h>
24 static int p_chmask = 0x3;
29 static int p_srate = 48000;
34 static int p_ssize = 2;
39 static int c_chmask = 0x3;
44 static int c_srate = 64000;
49 static int c_ssize = 2;
53 #define DMA_ADDR_INVALID (~(dma_addr_t)0)
55 #define ALT_SET(x, a) do {(x) &= ~0xff; (x) |= (a); } while (0)
56 #define ALT_GET(x) ((x) & 0xff)
57 #define INTF_SET(x, i) do {(x) &= 0xff; (x) |= ((i) << 8); } while (0)
58 #define INTF_GET(x) ((x >> 8) & 0xff)
71 #define USB_OUT_IT_ID 1
73 #define IO_OUT_OT_ID 3
74 #define USB_IN_OT_ID 4
75 #define USB_OUT_CLK_ID 5
76 #define USB_IN_CLK_ID 6
78 #define CONTROL_ABSENT 0
79 #define CONTROL_RDONLY 1
80 #define CONTROL_RDWR 3
82 #define CLK_FREQ_CTRL 0
83 #define CLK_VLD_CTRL 2
131 #define BUFF_SIZE_MAX (PAGE_SIZE * 16)
132 #define PRD_SIZE_MAX PAGE_SIZE
133 #define MIN_PERIODS 4
183 if (&uac2->
c_prm != r)
195 num += (chanmask & 1);
207 bool update_alsa =
false;
224 pr_debug(
"%s: iso_complete status(%d) %d/%d\n",
251 spin_unlock_irqrestore(&prm->
lock, flags);
269 struct audio_dev *agdev = uac2_to_agdev(uac2);
301 spin_unlock_irqrestore(&prm->
lock, flags);
368 runtime->
hw = uac2_pcm_hardware;
372 runtime->
hw.rate_min = p_srate;
375 runtime->
hw.period_bytes_min = 2 * uac2->
p_prm.max_psize
376 / runtime->
hw.periods_min;
379 runtime->
hw.rate_min = c_srate;
382 runtime->
hw.period_bytes_min = 2 * uac2->
c_prm.max_psize
383 / runtime->
hw.periods_min;
386 runtime->
hw.rate_max = runtime->
hw.rate_min;
387 runtime->
hw.channels_max = runtime->
hw.channels_min;
401 .open = uac2_pcm_open,
402 .close = uac2_pcm_null,
404 .hw_params = uac2_pcm_hw_params,
405 .hw_free = uac2_pcm_hw_free,
406 .trigger = uac2_pcm_trigger,
407 .pointer = uac2_pcm_pointer,
408 .prepare = uac2_pcm_null,
430 p_chmask ? 1 : 0, c_chmask ? 1 : 0, &pcm);
453 platform_set_drvdata(pdev, card);
468 struct snd_card *card = platform_get_drvdata(pdev);
470 platform_set_drvdata(pdev,
NULL);
478 static int alsa_uac2_init(
struct audio_dev *agdev)
483 uac2->
pdrv.probe = snd_uac2_probe;
484 uac2->
pdrv.remove = snd_uac2_remove;
503 static void alsa_uac2_exit(
struct audio_dev *agdev)
529 static const char ifassoc[] =
"Source/Sink";
530 static const char ifctrl[] =
"Topology Control";
531 static char clksrc_in[8];
532 static char clksrc_out[8];
533 static const char usb_it[] =
"USBH Out";
534 static const char io_it[] =
"USBD Out";
535 static const char usb_ot[] =
"USBH In";
536 static const char io_ot[] =
"USBD In";
537 static const char out_alt0[] =
"Playback Inactive";
538 static const char out_alt1[] =
"Playback Active";
539 static const char in_alt0[] =
"Capture Inactive";
540 static const char in_alt1[] =
"Capture Active";
560 .strings = strings_fn,
569 .bLength =
sizeof devqual_desc,
574 .bDeviceSubClass = 0x02,
575 .bDeviceProtocol = 0x01,
576 .bNumConfigurations = 1,
581 .bLength =
sizeof iad_desc,
584 .bFirstInterface = 0,
585 .bInterfaceCount = 3,
593 .bLength =
sizeof std_ac_if_desc,
596 .bAlternateSetting = 0,
690 .wTotalLength =
sizeof in_clk_src_desc +
sizeof out_clk_src_desc
691 +
sizeof usb_out_it_desc +
sizeof io_in_it_desc
698 .bLength =
sizeof std_as_out_if0_desc,
701 .bAlternateSetting = 0,
710 .bLength =
sizeof std_as_out_if1_desc,
713 .bAlternateSetting = 1,
761 .bLength =
sizeof as_iso_out_desc,
767 .bLockDelayUnits = 0,
773 .bLength =
sizeof std_as_in_if0_desc,
776 .bAlternateSetting = 0,
785 .bLength =
sizeof std_as_in_if1_desc,
788 .bAlternateSetting = 1,
836 .bLength =
sizeof as_iso_in_desc,
842 .bLockDelayUnits = 0,
926 if (prm->
ureq[i].req) {
927 usb_ep_dequeue(ep, prm->
ureq[i].req);
928 usb_ep_free_request(ep, prm->
ureq[i].req);
933 if (usb_ep_disable(ep))
935 "%s:%d Error!\n", __func__, __LINE__);
941 struct audio_dev *agdev = func_to_agdev(fn);
951 "%s:%d Error!\n", __func__, __LINE__);
961 "%s:%d Error!\n", __func__, __LINE__);
972 "%s:%d Error!\n", __func__, __LINE__);
983 "%s:%d Error!\n", __func__, __LINE__);
984 agdev->
out_ep->driver_data = agdev;
989 "%s:%d Error!\n", __func__, __LINE__);
990 agdev->
in_ep->driver_data = agdev;
998 if (gadget_is_dualspeed(gadget))
1001 prm = &agdev->
uac2.c_prm;
1007 "%s:%d Error!\n", __func__, __LINE__);
1010 prm = &agdev->
uac2.p_prm;
1016 "%s:%d Error!\n", __func__, __LINE__);
1019 return alsa_uac2_init(agdev);
1025 struct audio_dev *agdev = func_to_agdev(fn);
1030 alsa_uac2_exit(agdev);
1032 prm = &agdev->
uac2.p_prm;
1035 prm = &agdev->
uac2.c_prm;
1038 if (gadget_is_dualspeed(gadget))
1052 struct audio_dev *agdev = func_to_agdev(fn);
1063 "%s:%d Error!\n", __func__, __LINE__);
1071 "%s:%d Error!\n", __func__, __LINE__);
1089 "%s:%d Error!\n", __func__, __LINE__);
1102 if (prm->
ureq[i].req) {
1112 "%s:%d Error!\n", __func__, __LINE__);
1117 prm->
ureq[
i].pp = prm;
1123 req->
complete = agdev_iso_complete;
1127 dev_err(&uac2->
pdev.dev,
"%d Error!\n", __LINE__);
1136 struct audio_dev *agdev = func_to_agdev(fn);
1147 "%s:%d Invalid Interface %d!\n",
1148 __func__, __LINE__, intf);
1156 struct audio_dev *agdev = func_to_agdev(fn);
1170 struct audio_dev *agdev = func_to_agdev(fn);
1175 u8 entity_id = (w_index >> 8) & 0xff;
1176 u8 control_selector = w_value >> 8;
1187 value =
min_t(
unsigned, w_length,
sizeof c);
1190 *(
u8 *)req->
buf = 1;
1191 value =
min_t(
unsigned, w_length, 1);
1194 "%s:%d control_selector=%d TODO!\n",
1195 __func__, __LINE__, control_selector);
1205 struct audio_dev *agdev = func_to_agdev(fn);
1210 u8 entity_id = (w_index >> 8) & 0xff;
1211 u8 control_selector = w_value >> 8;
1225 r.wNumSubRanges = 1;
1227 value =
min_t(
unsigned, w_length,
sizeof r);
1231 "%s:%d control_selector=%d TODO!\n",
1232 __func__, __LINE__, control_selector);
1242 return in_rq_cur(fn, cr);
1244 return in_rq_range(fn, cr);
1254 u8 control_selector = w_value >> 8;
1265 struct audio_dev *agdev = func_to_agdev(fn);
1268 u8 intf = w_index & 0xff;
1272 "%s:%d Error!\n", __func__, __LINE__);
1277 return ac_rq_in(fn, cr);
1279 return out_rq_cur(fn, cr);
1288 struct audio_dev *agdev = func_to_agdev(fn);
1299 value = setup_rq_inf(fn, cr);
1301 dev_err(&uac2->
pdev.dev,
"%s:%d Error!\n", __func__, __LINE__);
1309 "%s:%d Error!\n", __func__, __LINE__);
1321 agdev_g = kzalloc(
sizeof *agdev_g,
GFP_KERNEL);
1322 if (agdev_g ==
NULL) {
1411 agdev_g->
func.name =
"uac2_func";
1412 agdev_g->
func.strings = fn_strings;
1413 agdev_g->
func.bind = afunc_bind;
1414 agdev_g->
func.unbind = afunc_unbind;
1415 agdev_g->
func.set_alt = afunc_set_alt;
1416 agdev_g->
func.get_alt = afunc_get_alt;
1417 agdev_g->
func.disable = afunc_disable;
1418 agdev_g->
func.setup = afunc_setup;
1434 snprintf(clksrc_in,
sizeof(clksrc_in),
"%uHz", p_srate);
1435 snprintf(clksrc_out,
sizeof(clksrc_out),
"%uHz", c_srate);