From patchwork Fri Dec 15 21:49:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 179561 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:3b04:b0:fb:cd0c:d3e with SMTP id c4csp9598980dys; Fri, 15 Dec 2023 13:54:12 -0800 (PST) X-Google-Smtp-Source: AGHT+IFgS5dIKQBpLa81Kx1NIx1MAqcF6RwTziI/oaSlYPx6fPtHKJyjfJoZk19d6kilPfJhSHsF X-Received: by 2002:a05:6a20:9716:b0:190:921b:89c4 with SMTP id hr22-20020a056a20971600b00190921b89c4mr10598176pzc.18.1702677252703; Fri, 15 Dec 2023 13:54:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1702677252; cv=none; d=google.com; s=arc-20160816; b=BcqxBxt6Z99spXZLuWobNoK8jdDHcWNOETaqjOHlgLlpIa9slwJs8gRMznZ7vJjNxx AKg4il1exSihfX6H+rl4tfjBxmR4Cc7Sxfy9MU2HqIHXvTaDvlTTjao4j3A9wIkvb5Pf H5PhISQAR2w1VNXxuHMMnbtK35dzgpmg+ofS3DuWIyFoKn/2xHEi4UElKHZJcO7W686n igeJa8DzzN5mIxXgM5YQ7s4aAPTjnIQU8bu+fzZ0kwqs33pcYbQjuZfX9HCbjQXp5jpi WB+zM4XLavO/MvCi6/Alk/J52Fo7cF0A1bIQl59meikG3rTeYee8v/siPEiujcI2rH6F 9IHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=E7ozCBUEd5eMhyDHRgWtlAvFMDO6aFPFBgk1S/Zoj9c=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=cYhQaFySbCSZ0KM6Toyli7AG4w3h8I0CrFYoYtgl1gjeyQ2pfU+RNigZNSJP0/cGEc qL1fICeI07jyIm6CRp0sGAKXB6RwAnwYwIKIBnuTYU5Ptmdlc+sLpAGIpM39cBsCuKWF ggahhK3nDplkTRTUSclHygqY5j4PYw1ouxuxnuXfDduSvu6jKGESOGWzujGSUK+kWufA Vy/d8WnECObY6cY2vnrQWO6g/53BesOgc5HomK/aw7HoHzki1vRa0mCfNahtTJG3LM9S 5ddMGGK8wGA018y1PqWIFCoNJpFe6aR5YENasi2Jjpgt75Bd0toJ7c6MJYS/8KFMwCb9 3Y+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gGgyIaMl; spf=pass (google.com: domain of linux-kernel+bounces-1682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id kp18-20020a056a00465200b006be0f482c0fsi13840110pfb.63.2023.12.15.13.54.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Dec 2023 13:54:12 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-1682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=gGgyIaMl; spf=pass (google.com: domain of linux-kernel+bounces-1682-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-1682-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 7F3F1B240C5 for ; Fri, 15 Dec 2023 21:52:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2637F6720E; Fri, 15 Dec 2023 21:50:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gGgyIaMl" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E1F7147F7C; Fri, 15 Dec 2023 21:50:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 3BFKbmJO028203; Fri, 15 Dec 2023 21:50:12 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-type; s=qcppdkim1; bh=E7ozCBUEd5eMhyDHRgWt lAvFMDO6aFPFBgk1S/Zoj9c=; b=gGgyIaMlr3ziblkhokAmdfsjLZSWoufpqN20 EJU7/KjLaQVLNp4By70TQqFmhKAUZ1D1iq4689pdheTysB9LYmDEHolYhQsuoSv5 i+JroaWf+Ek2PnlA227Km++i7yhpFAIwoA9SEFpdNV0f0RC9UwkOG5Vff746SAEv OcNvy2+EJWNMoEyXXmsiso1ZuGnmnAHmJ+fSl6U6DkW4caCQE+Ow/3jZDRF/8GHS TfLd7fq/EpX/E3fOuJmMczDgmdcTlp7QWBWoN9qPmZ4D5VNGZV4CjRjkFARILGzm h5WHFIGstZywjSv+7wjfJhm1Uxp4XSDMKJGUcth7BcAW6ckRdw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3v0hdfa7dy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 21:50:12 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 3BFLoBxB000882 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 15 Dec 2023 21:50:12 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Fri, 15 Dec 2023 13:50:11 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v10 20/41] ALSA: usb-audio: Check for support for requested audio format Date: Fri, 15 Dec 2023 13:49:34 -0800 Message-ID: <20231215214955.12110-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231215214955.12110-1-quic_wcheng@quicinc.com> References: <20231215214955.12110-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: CO-rQNBSrQp81y63R4yTYutARmZquPxD X-Proofpoint-GUID: CO-rQNBSrQp81y63R4yTYutARmZquPxD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_01,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 mlxlogscore=999 impostorscore=0 spamscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 priorityscore=1501 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2312150152 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1785386503202322129 X-GMAIL-MSGID: 1785386503202322129 Allow for checks on a specific USB audio device to see if a requested PCM format is supported. This is needed for support when playback is initiated by the ASoC USB backend path. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 40 ++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 11 +++++++++++ 2 files changed, 51 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index c0b312e264bf..11b827b7a2a5 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -162,6 +162,46 @@ int snd_usb_unregister_platform_ops(void) } EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); +/* + * Checks to see if requested audio profile, i.e sample rate, # of + * channels, etc... is supported by the substream associated to the + * USB audio device. + */ +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction) +{ + struct snd_usb_audio *chip; + struct snd_usb_substream *subs; + struct snd_usb_stream *as; + const struct audioformat *fmt; + + /* + * Register mutex is held when populating and clearing usb_chip + * array. + */ + mutex_lock(®ister_mutex); + chip = usb_chip[card_idx]; + if (!chip) { + mutex_unlock(®ister_mutex); + return NULL; + } + + if (enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &as->substream[direction]; + fmt = snd_usb_find_substream_format(subs, params); + if (fmt) { + mutex_unlock(®ister_mutex); + return as; + } + } + } + mutex_unlock(®ister_mutex); + + return NULL; +} +EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index 02e4ea898db5..ed4a664e24e5 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -217,4 +217,15 @@ struct snd_usb_platform_ops { int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); + +#if IS_ENABLED(CONFIG_SND_USB_AUDIO) +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction); +#else +static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction) +{ + return NULL; +} +#endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */