From patchwork Wed Nov 6 19:33:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 13865405 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 3F57220BB35; Wed, 6 Nov 2024 19:34:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; cv=none; b=IxDiAZioPXKRKadzeC4A7tU+u5+bBDA3TroLKLYqaUWnvcqnhb1eN3XEiF7RU8YI+ygnbbZuRygzGJGw+HcPuAW3dDUSggW+SUnbaP8EPFPINIvbKtgP3tcsk3ditHHVMrEinH3L0S4SNKUem1YDPIvtH6hNVQjGRnyqrG1xdCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730921689; c=relaxed/simple; bh=8LFfZvsEZtb7Rvtz20t3R2gyJJLgeD0OdIXEJmaqk0Q=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=qEUCmog77eox47GzEzKzBpoKiHlmz20IQwntB+9Q/FRNadG/ajJ5hsFqRMFCiJ2TKuz6iCY2pMiFckneJ0hhGyOXGkTU2G34H57N4HYjl5H4WxvL6Vw8aLVwpGInDTAs+NPHUahWxUil5KNDPIzimNzA4Wp/nm3+AegsHdPq5Kg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=gi/EwZQd; arc=none smtp.client-ip=205.220.180.131 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="gi/EwZQd" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 4A6Inm6c028867; Wed, 6 Nov 2024 19:34:33 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= ttnVezO587R3SiE4KfuBdhmGnpXGor59yM9glqfHyt0=; b=gi/EwZQd63p8OXuN ej6rOo4uQlycneIEqSUnsZxwgCWrIWLEJ3WSt1DBqkqPsGGdzPNXWeaexpoK3ZGQ NSjsHBVDAJCoTTKyDD7TOcs6yB9ECeqVzBSAmlDo3+DL8feCPgsrxi3m5paU9gDl CDQk+1ha4xKUg1e3Exo3b6D/WFqzzTI7jyyoSg1oSl5QRNaiT9Y+8PfGSn8fu6jR oqIzqlHahatf+kyLtbLvDwDHrMyvMKajEvLjeJvfpKuqgS46R7z6yGOhJPxU2jb9 S1L8pnMHqwjCZMGJyzXqz2hoxiPnb7Dktn7EanAiFJTs/v+Tt8rWbY2P5r3pvjYO 45YD7w== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 42nd28c9r4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 06 Nov 2024 19:34:32 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 4A6JYVLi008646 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 6 Nov 2024 19:34:31 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.1544.9; Wed, 6 Nov 2024 11:34:31 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v30 09/30] ALSA: usb-audio: Check for support for requested audio format Date: Wed, 6 Nov 2024 11:33:52 -0800 Message-ID: <20241106193413.1730413-10-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20241106193413.1730413-1-quic_wcheng@quicinc.com> References: <20241106193413.1730413-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-input@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01b.na.qualcomm.com (10.47.209.197) 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: dNnddCKWtpdlRluaTPSRu3QeqYDpfvD3 X-Proofpoint-GUID: dNnddCKWtpdlRluaTPSRu3QeqYDpfvD3 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 adultscore=0 mlxlogscore=999 clxscore=1015 lowpriorityscore=0 impostorscore=0 priorityscore=1501 spamscore=0 phishscore=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2411060148 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. Reviewed-by: Pierre-Louis Bossart Signed-off-by: Wesley Cheng --- sound/usb/card.c | 32 ++++++++++++++++++++++++++++++++ sound/usb/card.h | 3 +++ 2 files changed, 35 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index a0087bde684c..6c5b0e02e57b 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -119,6 +119,38 @@ static DEFINE_MUTEX(register_mutex); static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; static struct usb_driver usb_audio_driver; +/* + * 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; + + /* + * Register mutex is held when populating and clearing usb_chip + * array. + */ + guard(mutex)(®ister_mutex); + chip = usb_chip[card_idx]; + + if (chip && enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &as->substream[direction]; + if (snd_usb_find_substream_format(subs, params)) + return as; + } + } + + 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 6ec95b2edf86..4f4f3f39b7fa 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,7 @@ struct snd_usb_stream { struct list_head list; }; +struct snd_usb_stream * +snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, + int direction); #endif /* __USBAUDIO_CARD_H */