From patchwork Tue Jan 2 21:45:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 184487 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4700530dyb; Tue, 2 Jan 2024 13:52:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IGRYwyqTUSa6CctvkV10SU+1Y06vVfcQKFrKq2RYdJ0kiI2cRSkNswImHxFdy+MJy1YQ/3A X-Received: by 2002:a05:6a20:6d98:b0:195:fa5c:f918 with SMTP id gl24-20020a056a206d9800b00195fa5cf918mr4828646pzb.4.1704232323337; Tue, 02 Jan 2024 13:52:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704232323; cv=none; d=google.com; s=arc-20160816; b=MPPn1aBpey7pDclqUjf9eiBP1aERj6Z+J2orguN6xSP6RWxpnf1RG47O9OBSmxjYLf k8Qoi05s3jaIPKjs7tQSoOrV3kqnOMZMeQLcQ2rHn5FyG7ETvraI3r3BtDs7LRZ/USbx lPT7gqLHRyq2J8GOO12pGOk76dt8XsiBNeyiKxmWaCRzejgp0aRMHcIuANGtZpL9ZCDd 8Uml/GqSy2L9kqd1nHiK0B1FX5G42T7fFWgu6vIdfwR4vng7txTpTN9oRJRHOW/ZQYaY vWQNAGhHfelGZnSbk3Oj8h+RLU7pRDvpTUebv0HWH2yDc1pEA45dhksj27v3D+mjTd1f IofQ== 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=cQhvyudO4R1saPfsmzgOlXDWeI4iMOkHf8cRCuFo5NkFd+b2hqQjKVRfZZMK8VomJP qi/P2Jmojw9iZNmiQwOAFLB+d1YOVMM95m6pw0mMdipYdtXGFlVhq/Ixsxj69qdBt1rQ 78bBndg+rETlYVAh6mqLpz+o8mKYvr6hRG1XZdBw3QN6cs3SUAUGoWDHi0EZ7+wW7Wqh XCpq50VFpis4MnyjEw/MSu0/hQphboDZo+CCMtlfEbFNHBnT4+M2NMOCbaNL/qS7Xtrb Y3Yakb4Sr1mx7k7fGOxpL2FMT9xVK0jJaj870vTXpknNLdpfhRegUSO4KWTi7rLDOeRw Qo+Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MfN7nYLP; spf=pass (google.com: domain of linux-kernel+bounces-14873-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14873-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id y13-20020a056a00038d00b006daa81ef27esi1555065pfs.240.2024.01.02.13.52.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:52:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14873-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=MfN7nYLP; spf=pass (google.com: domain of linux-kernel+bounces-14873-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14873-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 0FA4E284A16 for ; Tue, 2 Jan 2024 21:52:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CD1A718036; Tue, 2 Jan 2024 21:46:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="MfN7nYLP" 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 B5DDA1803F; Tue, 2 Jan 2024 21:46:44 +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 (m0279862.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 402KfG3Z013656; Tue, 2 Jan 2024 21:46:25 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=MfN7nYLP45pB9qTdhf46XgOJuyNNiatjVY87 zQ0xriAjOg+i/WB33/JGSl3bziBgyNoK6RiaTOKFZYpPi74RBg3Yhs+0N2NzWW8j fKvQgtWRZagM4b80Vtilpq50apgL93p6c99VzcxfsUpl6ieEfHObNaAVBh3QD8rT QUdQL8AzTusn6Bui4KSnCx5IwoGUYNnmUh8Wmv5UHCM6Pc2dTIWUQxckwcR+4Uqe 8sfEvvCs+SpAYUPFoEaegmN7pfticT1sC4mVRzIXOY4coQgPc4jyXRS8ilTYBws2 6ktvbJ8kC84DjuFzKG712tS6qPEY/ygG+9Y8ZJK4SNyviLlAww== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vcgub98m0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 21:46:24 +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 402LkOPG003246 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jan 2024 21:46:24 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; Tue, 2 Jan 2024 13:46:23 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v12 20/41] ALSA: usb-audio: Check for support for requested audio format Date: Tue, 2 Jan 2024 13:45:28 -0800 Message-ID: <20240102214549.22498-21-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240102214549.22498-1-quic_wcheng@quicinc.com> References: <20240102214549.22498-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: Hv9Z3CG5-qY2wVJBzrcPuK8btiheKgIp X-Proofpoint-GUID: Hv9Z3CG5-qY2wVJBzrcPuK8btiheKgIp 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 lowpriorityscore=0 phishscore=0 priorityscore=1501 clxscore=1015 mlxlogscore=999 impostorscore=0 adultscore=0 spamscore=0 mlxscore=0 bulkscore=0 suspectscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401020161 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787017112551749981 X-GMAIL-MSGID: 1787017112551749981 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 */