Received: by 2002:a05:7412:37c9:b0:e2:908c:2ebd with SMTP id jz9csp2763124rdb; Fri, 22 Sep 2023 07:48:51 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFJ5PY1+WHS5299G42pznR2V+vX2HvIiU95/dU4r+TJ8ZaaYKzAKEJGfHm4niFHBQlZb3ru X-Received: by 2002:a17:90a:88e:b0:277:11b1:d5c4 with SMTP id v14-20020a17090a088e00b0027711b1d5c4mr1457814pjc.41.1695394131301; Fri, 22 Sep 2023 07:48:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695394131; cv=none; d=google.com; s=arc-20160816; b=pRPyP4VizmZlHuuT+pD5G6s5BXiCh6YZNrATT44t10pyB63cmX8KQwlYifZQgZANMe xF369vA/BoU+1ViT+LBtIIVyZprTf9kDAhCXVouo4Y3pdMt+9IF/Jqde+DG/T0prN6Zy EtOznkLWgvmmwqyZekTXwoNKflQqCu7C5DEilQl30KV6CJf+1Wt7qebIRS3e8q7bQAlx jD33KoFDrj/EXNJrxNWgFf3fGjaThGaCTkShZQjO5HokSaPk3WGkBY8jAaepopSkhHdP mPbLS1BBhdPZQMTwQtbcF7rBV3/J6dtxp3oxJRk28/7fFMSvR6LcM566oC7o5002iZp1 rc2A== 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=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=tA6jrdHqPDtiScYwvENmW96HVNgMsTU0pkJFl860xsLad2TVYUtP3/G0+FnQRhFS5C prNH+DLxUACFu8qdBDK6bnUlyJzd+lgATnxxhtDp98vmyKEVqMLlqUpkTzyZZcYF04GR a7LrHjE/H7IvfkepYpxQHARuq/4y0xu34bEQ1oZyc0MuB7QFYcrSpiZCTt7ukkBaKu9b GWip5TWwjpD3CxaDiDz72AGneW8rwICjBPwFBaMECMJi5A2546NYGVFkZJqIqLz5vtGf hR5NTeemMMHiQ5ehctV9nkmdwxvB4Q+xtOGeDO63QApcmAvLy2YTDfhPUHwepvRolwPe t2WA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qh8jXbPl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id ip11-20020a17090b314b00b00262ca5c4c12si4497688pjb.178.2023.09.22.07.48.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Sep 2023 07:48:51 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Qh8jXbPl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 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 snail.vger.email (Postfix) with ESMTP id D1EED82F0BEF; Thu, 21 Sep 2023 14:53:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233022AbjIUVxr (ORCPT + 99 others); Thu, 21 Sep 2023 17:53:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232670AbjIUVxW (ORCPT ); Thu, 21 Sep 2023 17:53:22 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CB4B3A8C; Thu, 21 Sep 2023 14:49:38 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38LKs3lq027021; Thu, 21 Sep 2023 21:49:00 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=Qh8jXbPlOYiKd08ahmmzOR6cuBSdT3UJGWF3A0fkBhBXRTU4/JPpyTJpa1fwYhAGKudV mw4eozX9wR56/Sy8TvCsACSCNmS39hJlSQjW5ssYd9LcT2U7QgLKtdD27Iqgh1IrrfQu 3Kg9ZqWw7QWmVgO4V6TwJEOR3mOuJAza3ydIL5TQCUemCbmlFDdzeY8mJU6UqZGrofe4 hwyhHCR+9Zdgk5hLcVSLPyO5ynlaDMGncBZag3jrdBB6PjqLWaKTP1g06Rga3BJFko1V FJq3MCD6knqphrpH+pA1xbMODjINxvvnG9Cf7FJea3af9x8YDaB9D6mYD2BRx8Ay0c+Q xA== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t8uf2g9pk-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:49:00 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 38LLmxXk031083 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Sep 2023 21:48:59 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.36; Thu, 21 Sep 2023 14:48:58 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v7 19/33] ALSA: usb-audio: Check for support for requested audio format Date: Thu, 21 Sep 2023 14:48:29 -0700 Message-ID: <20230921214843.18450-20-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com> References: <20230921214843.18450-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-GUID: 2kToF6aRGq---6me_PG0So9suarmzHKO X-Proofpoint-ORIG-GUID: 2kToF6aRGq---6me_PG0So9suarmzHKO X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-09-21_18,2023-09-21_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 malwarescore=0 adultscore=0 mlxlogscore=999 mlxscore=0 impostorscore=0 clxscore=1015 suspectscore=0 phishscore=0 bulkscore=0 lowpriorityscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2309210188 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Thu, 21 Sep 2023 14:53:49 -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 */