From patchwork Fri Feb 18 09:49:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jing Leng <3090101217@zju.edu.cn> X-Patchwork-Id: 544271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA892C433F5 for ; Fri, 18 Feb 2022 09:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233791AbiBRJuu (ORCPT ); Fri, 18 Feb 2022 04:50:50 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233820AbiBRJur (ORCPT ); Fri, 18 Feb 2022 04:50:47 -0500 Received: from zg8tmty1ljiyny4xntqumjca.icoremail.net (zg8tmty1ljiyny4xntqumjca.icoremail.net [165.227.154.27]) by lindbergh.monkeyblade.net (Postfix) with SMTP id CED8926A2C1; Fri, 18 Feb 2022 01:50:27 -0800 (PST) Received: from jleng.ambarella.net (unknown [116.246.37.178]) by mail-app2 (Coremail) with SMTP id by_KCgCnrYW8aw9ink_8AQ--.55562S2; Fri, 18 Feb 2022 17:49:55 +0800 (CST) From: 3090101217@zju.edu.cn To: gregkh@linuxfoundation.org Cc: balbi@kernel.org, jleng@ambarella.com, pavel.hofman@ivitera.com, ruslan.bilovol@gmail.com, linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org Subject: [PATCH v2] usb: gadget: f_uac1: add set requests support Date: Fri, 18 Feb 2022 17:49:47 +0800 Message-Id: <20220218094947.3835-1-3090101217@zju.edu.cn> X-Mailer: git-send-email 2.17.1 In-Reply-To: References: X-CM-TRANSID: by_KCgCnrYW8aw9ink_8AQ--.55562S2 X-Coremail-Antispam: 1UD129KB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-SenderInfo: qtqziiyqrsilo62m3hxhgxhubq/1tbiAwMFBVNG3FklugAAsP Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org From: Jing Leng Currently the f_uac1 driver only supports UAC_SET_CUR request. But when uac1 device is plugged to Ubuntu 20.04 PC, at the stage of setup, the PC will send UAC_SET_RES request, If the device doesn't respond to the request, the PC will abort the setup process and uac1 device can't be recognized on Ubuntu 20.04 PC. So f_uac1 driver should handle other set requests. Fixes: 0356e6283c71 ("usb: gadget: f_uac1: add volume and mute support") Signed-off-by: Jing Leng --- ChangeLog v1->v2: - Add "Fixes:" tag in the changelog area --- drivers/usb/gadget/function/f_uac1.c | 44 +++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/drivers/usb/gadget/function/f_uac1.c b/drivers/usb/gadget/function/f_uac1.c index 03f50643fbba..c9d8ec4fdf22 100644 --- a/drivers/usb/gadget/function/f_uac1.c +++ b/drivers/usb/gadget/function/f_uac1.c @@ -589,7 +589,7 @@ in_rq_res(struct usb_function *fn, const struct usb_ctrlrequest *cr) } static void -out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) +out_rq_complete(struct usb_ep *ep, struct usb_request *req) { struct g_audio *audio = req->context; struct usb_composite_dev *cdev = audio->func.config->cdev; @@ -614,9 +614,11 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) is_playback = 1; if (control_selector == UAC_FU_MUTE) { - u8 mute = *(u8 *)req->buf; + if (cr->bRequest == UAC_SET_CUR) { + u8 mute = *(u8 *)req->buf; - u_audio_set_mute(audio, is_playback, mute); + u_audio_set_mute(audio, is_playback, mute); + } return; } else if (control_selector == UAC_FU_VOLUME) { @@ -624,7 +626,34 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) s16 volume; volume = le16_to_cpu(*c); - u_audio_set_volume(audio, is_playback, volume); + + switch (cr->bRequest) { + case UAC_SET_CUR: + u_audio_set_volume(audio, is_playback, volume); + break; + case UAC_SET_MIN: + if (is_playback) + opts->p_volume_min = volume; + else + opts->c_volume_min = volume; + break; + case UAC_SET_MAX: + if (is_playback) + opts->p_volume_max = volume; + else + opts->c_volume_max = volume; + break; + case UAC_SET_RES: + if (is_playback) + opts->p_volume_res = volume; + else + opts->c_volume_res = volume; + break; + case UAC_SET_MEM: + break; + default: + break; + } return; } else { @@ -643,7 +672,7 @@ out_rq_cur_complete(struct usb_ep *ep, struct usb_request *req) } static int -out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) +ac_rq_out(struct usb_function *fn, const struct usb_ctrlrequest *cr) { struct usb_request *req = fn->config->cdev->req; struct g_audio *audio = func_to_g_audio(fn); @@ -659,7 +688,7 @@ out_rq_cur(struct usb_function *fn, const struct usb_ctrlrequest *cr) (FUOUT_EN(opts) && (entity_id == USB_OUT_FU_ID))) { memcpy(&uac1->setup_cr, cr, sizeof(*cr)); req->context = audio; - req->complete = out_rq_cur_complete; + req->complete = out_rq_complete; return w_length; } else { @@ -789,8 +818,7 @@ f_audio_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl) value = audio_get_endpoint_req(f, ctrl); break; case USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE: - if (ctrl->bRequest == UAC_SET_CUR) - value = out_rq_cur(f, ctrl); + value = ac_rq_out(f, ctrl); break; case USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE: value = ac_rq_in(f, ctrl);