Re: [PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support
Hi Ruslan, Thank you for the patch! Perhaps something to improve: [auto build test WARNING on balbi-usb/next] [also build test WARNING on v4.14-rc8 next-20171107] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Ruslan-Bilovol/usb-gadget-add-USB-Audio-Device-Class-3-0-gadget-support/20171107-175202 base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next coccinelle warnings: (new ones prefixed by >>) >> drivers/usb/gadget/function/f_uac3.c:766:2-9: alloc with no test, possible >> model on line 780 vim +766 drivers/usb/gadget/function/f_uac3.c 722 723 static int f_audio_bind(struct usb_configuration *cfg, struct usb_function *fn) 724 { 725 struct f_uac3 *uac3 = func_to_uac3(fn); 726 struct g_audio *audio = func_to_g_audio(fn); 727 struct usb_composite_dev *cdev = cfg->cdev; 728 struct usb_gadget *gadget = cdev->gadget; 729 struct device *dev = >dev; 730 struct f_uac3_opts *uac3_opts; 731 struct uac3_hc_descriptor_header *cluster_desc; 732 struct uac3_hc_desc *hc_desc; 733 struct usb_string *us; 734 u16 hc_desc_id = 1; /* HC id always starts from 1 */ 735 int ret; 736 737 uac3_opts = container_of(fn->fi, struct f_uac3_opts, func_inst); 738 739 us = usb_gstrings_attach(cdev, fn_strings, ARRAY_SIZE(strings_fn)); 740 if (IS_ERR(us)) 741 return PTR_ERR(us); 742 743 iad_desc.iFunction = us[STR_ASSOC].id; 744 std_ac_if_desc.iInterface = us[STR_IF_CTRL].id; 745 std_as_out_if0_desc.iInterface = us[STR_AS_OUT_ALT0].id; 746 std_as_out_if1_desc.iInterface = us[STR_AS_OUT_ALT1].id; 747 std_as_in_if0_desc.iInterface = us[STR_AS_IN_ALT0].id; 748 std_as_in_if1_desc.iInterface = us[STR_AS_IN_ALT1].id; 749 750 INIT_LIST_HEAD(>hc_desc_list); 751 752 /* Initialize the configurable parameters */ 753 cluster_desc = build_cluster_descriptor(uac3_opts, 0); /* capture */ 754 if (cluster_desc) { 755 hc_desc = kzalloc(sizeof *hc_desc, GFP_KERNEL); 756 hc_desc->hc_header = cluster_desc; 757 list_add(_desc->list, >hc_desc_list); 758 cluster_desc->wDescriptorID = cpu_to_le16(hc_desc_id); 759 usb_out_it_desc.wClusterDescrID = cluster_desc->wDescriptorID; 760 as_out_hdr_desc.wClusterDescrID = cluster_desc->wDescriptorID; 761 hc_desc_id++; 762 } 763 764 cluster_desc = build_cluster_descriptor(uac3_opts, 1); /* playback */ 765 if (cluster_desc) { > 766 hc_desc = kzalloc(sizeof *hc_desc, GFP_KERNEL); 767 hc_desc->hc_header = cluster_desc; 768 list_add(_desc->list, >hc_desc_list); 769 cluster_desc->wDescriptorID = cpu_to_le16(hc_desc_id); 770 io_in_it_desc.wClusterDescrID = cluster_desc->wDescriptorID; 771 as_in_hdr_desc.wClusterDescrID = cluster_desc->wDescriptorID; 772 } 773 774 as_out_hdr_desc.bSubslotSize = uac3_opts->c_ssize; 775 as_out_hdr_desc.bBitResolution = uac3_opts->c_ssize * 8; 776 as_in_hdr_desc.bSubslotSize = uac3_opts->p_ssize; 777 as_in_hdr_desc.bBitResolution = uac3_opts->p_ssize * 8; 778 779 /* alloc and configure Feature Unit descriptors */ > 780 usb_out_fu_desc = > alloc_fu_desc(num_channels(uac3_opts->c_chmask), 781 USB_OUT_FU_ID, 782 USB_OUT_IT_ID); 783 if (!usb_out_fu_desc) { 784 dev_err(dev, "%s: can't allocate OUT FU descriptor on %s\n", 785 fn->name, gadget->name); 786 ret = -ENOMEM; 787 goto err_free_hc_desc; 788 } 789 790 usb_in_fu_desc = alloc_fu_desc(num_channels(uac3_opts->p_chmask), 791 USB_IN_FU_ID, 792 IO_IN_IT_ID); 793 if (!usb_in_fu_desc) { 794 dev_err(dev, "%s: can't allocate IN FU descriptor on %s\n", 795 fn->name, gadget->name); 796 ret = -ENOMEM; 797 goto err_free_out_fu_desc; 798 } 799 800 /* update AC desc size with allocated FUs */ 801 ac_hdr_desc.wTotalLength = cpu_to_le16( 802sizeof in_clk_src_desc + sizeof out_clk_src_desc 803
Re: [PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support
Hi Ruslan, Thank you for the patch! Yet something to improve: [auto build test ERROR on balbi-usb/next] [also build test ERROR on v4.14-rc8 next-20171107] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system] url: https://github.com/0day-ci/linux/commits/Ruslan-Bilovol/usb-gadget-add-USB-Audio-Device-Class-3-0-gadget-support/20171107-175202 base: https://git.kernel.org/pub/scm/linux/kernel/git/balbi/usb.git next config: i386-allmodconfig (attached as .config) compiler: gcc-6 (Debian 6.2.0-3) 6.2.0 20160901 reproduce: # save the attached .config to linux build tree make ARCH=i386 All errors (new ones prefixed by >>): >> drivers/usb/gadget/function/f_uac3.c:10:32: fatal error: >> linux/usb/audio-v3.h: No such file or directory #include ^ compilation terminated. vim +10 drivers/usb/gadget/function/f_uac3.c > 10 #include 11 #include 12 --- 0-DAY kernel test infrastructureOpen Source Technology Center https://lists.01.org/pipermail/kbuild-all Intel Corporation .config.gz Description: application/gzip
[PATCH 1/1] usb: gadget: add USB Audio Device Class 3.0 gadget support
Recently released USB Audio Class 3.0 specification introduces many significant changes comparing to previous versions, like - new Power Domains, support for LPM/L1 - new Cluster descriptor - changed layout of all class-specific descriptors - new High Capability descriptors - New class-specific String descriptors - new and removed units - additional sources for interrupts - removed Type II Audio Data Formats - ... and many other things (check spec) It also provides backward compatibility through multiple configurations, as well as requires mandatory support for BADD (Basic Audio Device Definition) on each ADC3.0 compliant device This patch adds UAC3 gadget support basing on UAC3 specification, implementing Generic I/O Profile (BAOF + BAIF) from BADD document. There are still few areas for future improvements because not all functionality is completely implemented, for example volume, mute and power management handling has dummy implementation in some places Signed-off-by: Ruslan Bilovol--- Documentation/ABI/testing/configfs-usb-gadget-uac3 | 14 + Documentation/usb/gadget-testing.txt | 41 + drivers/usb/gadget/Kconfig | 22 + drivers/usb/gadget/function/Makefile |2 + drivers/usb/gadget/function/f_uac3.c | 1497 drivers/usb/gadget/function/u_uac3.h | 38 + drivers/usb/gadget/legacy/Kconfig |3 +- 7 files changed, 1616 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-uac3 create mode 100644 drivers/usb/gadget/function/f_uac3.c create mode 100644 drivers/usb/gadget/function/u_uac3.h diff --git a/Documentation/ABI/testing/configfs-usb-gadget-uac3 b/Documentation/ABI/testing/configfs-usb-gadget-uac3 new file mode 100644 index 000..54bb00e --- /dev/null +++ b/Documentation/ABI/testing/configfs-usb-gadget-uac3 @@ -0,0 +1,14 @@ +What: /config/usb-gadget/gadget/functions/uac3.name +Date: Nov 2017 +KernelVersion: 4.16 +Description: + The attributes: + + c_chmask - capture channel mask + c_srate - capture sampling rate + c_ssize - capture sample size (bytes) + p_chmask - playback channel mask + p_srate - playback sampling rate + p_ssize - playback sample size (bytes) + req_number - the number of pre-allocated request + for both capture and playback diff --git a/Documentation/usb/gadget-testing.txt b/Documentation/usb/gadget-testing.txt index fbc397d..36d5e2b 100644 --- a/Documentation/usb/gadget-testing.txt +++ b/Documentation/usb/gadget-testing.txt @@ -21,6 +21,7 @@ provided by gadgets. 18. UVC function 19. PRINTER function 20. UAC1 function (new API) +21. UAC3 function 1. ACM function @@ -817,3 +818,43 @@ e.g.: $ arecord -f dat -t wav -D hw:CARD=UAC1Gadget,DEV=0 | \ aplay -D default:CARD=OdroidU3 + +21. UAC3 function += + +The function is provided by usb_f_uac3.ko module. + +Function-specific configfs interface + + +The function name to use when creating the function directory is "uac3". +The uac3 function provides these attributes in its function directory: + + c_chmask - capture channel mask + c_srate - capture sampling rate + c_ssize - capture sample size (bytes) + p_chmask - playback channel mask + p_srate - playback sampling rate + p_ssize - playback sample size (bytes) + req_number - the number of pre-allocated request for both capture +and playback + +The attributes have sane default values. + +Testing the UAC3 function +- + +device: run the gadget +host: aplay -l # should list our USB Audio Gadget + +This function does not require real hardware support, it just +sends a stream of audio data to/from the host. In order to +actually hear something at the device side, a command similar +to this must be used at the device side: + +$ arecord -f dat -t wav -D hw:2,0 | aplay -D hw:0,0 & + +e.g.: + +$ arecord -f dat -t wav -D hw:CARD=UAC3Gadget,DEV=0 | \ +aplay -D default:CARD=OdroidU3 diff --git a/drivers/usb/gadget/Kconfig b/drivers/usb/gadget/Kconfig index 31cce78..d53ae7d 100644 --- a/drivers/usb/gadget/Kconfig +++ b/drivers/usb/gadget/Kconfig @@ -200,6 +200,9 @@ config USB_F_UAC1_LEGACY config USB_F_UAC2 tristate +config USB_F_UAC3 + tristate + config USB_F_UVC tristate @@ -418,6 +421,25 @@ config USB_CONFIGFS_F_UAC2 received from the USB Host and choose to provide whatever it wants as audio data to the USB Host. +config USB_CONFIGFS_F_UAC3 + bool "Audio Class 3.0" + depends on USB_CONFIGFS + depends on SND + select USB_LIBCOMPOSITE + select SND_PCM + select USB_U_AUDIO + select USB_F_UAC3 +