Received: by 2002:a05:7412:d8a:b0:e2:908c:2ebd with SMTP id b10csp3386376rdg; Tue, 17 Oct 2023 13:04:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHqhNqHPN5B8K244m4WNZ6XeXqX+l6aWa46/JU3b2fX8Bhf3VuKY8epV8xB2SoynKfeolvA X-Received: by 2002:a05:6358:1e:b0:143:e3a:de5f with SMTP id 30-20020a056358001e00b001430e3ade5fmr3115267rww.26.1697573090030; Tue, 17 Oct 2023 13:04:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573089; cv=none; d=google.com; s=arc-20160816; b=Y+dSFV4Nfg9vebcLRWmIdBgG/dUrGavuysCWXuPAqj8mO9uNOm6/NVRV2mlFa9F+qv V+VIk8gkInn+/OVkZ9NG74lc4jdlo3diP1vSQ5inxl+nzHchChBv0++IubxcyLI8/zSG Spv2S6D3gJ6QimXRyobcerWJPJzY7sWtszDa/Th5QolORj5WINwMCIRiFCYrIOeRxnyP Z9NLboBMudqXA9muOF6X+axg6/7BlwSw9Pq0SjRCtiV85tfMmjz0YPPCkFjvmW7fR2Qt SB0Vqg5CiJLZCGiEG+4ikJdt9Fl2h12+Oke8sl+psLAuvI8YZJSa224qHPwukVq0aSrA 3GQA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=dH3EZ3Jzl3/12IrSu0jI4GH3HGQtq5+vzpa4GA8M+f0=; fh=ASZxE/GudOQkGCAz0d02NHHSpg4iNHYOcDWl1imlof0=; b=EOGRxSlMEUNEuEPpSDoNjOFNqHknDe8p8Es01WFq2k7BZM3cUhyW7Ivv4Dev223Rr9 927tRR1Pgp47PYYO6MDWHSgW8CxF1nSG9RBKBB1CVL/mZ2VkmOJrJ7QWvGD2ofLDp/Gb 9u0PU+B/choe7gQY3w7dhz9TdT4cEOpRja5VLd7x52hOV8pk6E3Zq9yMKWun3IUrDtkt yXbZEBS5jTgudDuE0UT412T4bBX42rAS0z4KI8c9qBsWla34xpiMhFtPxKmO6jDdLl02 WWwpg3Ixacvr8W0UHVN1uJ/stGFO3GCxlj/nX1jkPHfqMyAMBQg+LpNhSzRu6n1cpY0R yT/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CaHFkJvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Return-Path: Received: from morse.vger.email (morse.vger.email. [2620:137:e000::3:1]) by mx.google.com with ESMTPS id x29-20020a056a00189d00b006be25c80c8fsi2376384pfh.267.2023.10.17.13.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:04:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) client-ip=2620:137:e000::3:1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=CaHFkJvi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:1 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 6205F801B89D; Tue, 17 Oct 2023 13:04:47 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344575AbjJQUEh (ORCPT + 99 others); Tue, 17 Oct 2023 16:04:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45512 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344621AbjJQUD4 (ORCPT ); Tue, 17 Oct 2023 16:03:56 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB89910FD; Tue, 17 Oct 2023 13:02:16 -0700 (PDT) Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 39HIBDEr026311; Tue, 17 Oct 2023 20:01:59 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=dH3EZ3Jzl3/12IrSu0jI4GH3HGQtq5+vzpa4GA8M+f0=; b=CaHFkJviym5w1PQGFxKRfDCFXDvdvxJmNhcRvQNkI63S3rJmX3iSmI9FXabFo3rXD56w fjoHjcFzRyza20kV00FA0uy0m3F83DqK9HZYpCDFbZzl472uN1UXHyL+f2lEkg3AvD8F w1qsnBpaWRxpEAwRX5IRrxGZFwenGm81ZuUFWSU5Ix89iwyIngmob2bvjahmxWW3Qmqw vqp/RBihIuqg2VhT7BwqSlPtyaI3orSjcTVzMH0wTxFLI7LrZ5WrI/JUMgZz6vK8rlRn ja+B7JETaA/wjPP3SO9tRmg0RwsEULpdDYKnq3xA576Bsr44tL89IHcrxRueyFUO2Bn3 hg== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3ts85fujf7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 20:01:59 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 39HK1PsI004934 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 20:01:25 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.39; Tue, 17 Oct 2023 13:01:25 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v9 20/34] ALSA: usb-audio: Check for support for requested audio format Date: Tue, 17 Oct 2023 13:00:55 -0700 Message-ID: <20231017200109.11407-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231017200109.11407-1-quic_wcheng@quicinc.com> References: <20231017200109.11407-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) 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: mc9sAtAFsen2WJ0X9Xwgf4PFIDiF-jb1 X-Proofpoint-GUID: mc9sAtAFsen2WJ0X9Xwgf4PFIDiF-jb1 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_03,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 adultscore=0 priorityscore=1501 phishscore=0 malwarescore=0 spamscore=0 mlxscore=0 bulkscore=0 impostorscore=0 suspectscore=0 mlxlogscore=999 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170170 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:04:47 -0700 (PDT) Allow for checks on a specific USB audio device to see if a requested PCM format is supported. This is needed for support for 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..88f431917c15 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 = NULL; + 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 2884912adc96..e26292363cf0 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -216,4 +216,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 */