From patchwork Thu Feb 8 23:13:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198659 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp516222dyd; Thu, 8 Feb 2024 15:30:38 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCWk6G7np1B+jJs+pS2tAsBUq0D5DwMLLPv4QvQ7/GPKsohx19+HAqp/u2hLZeS7XYiXukVQPIAbNiwwS7K1Mm5iPjEBRg== X-Google-Smtp-Source: AGHT+IEMZshIPZzOqFja/prkPF8rzAEuZ2IPbl/D19reXsheP4WWgNwyzprydbdyGKlneRZEZVMq X-Received: by 2002:a05:6a00:2d1c:b0:6e0:8718:eac2 with SMTP id fa28-20020a056a002d1c00b006e08718eac2mr104529pfb.23.1707435038104; Thu, 08 Feb 2024 15:30:38 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707435038; cv=pass; d=google.com; s=arc-20160816; b=Jg7ZUaC/3cdUgpx8nSE+0y5OpZlPFfxTVhq2K8+ZoZo0jpCJvDJKWwd5giz6gbe4Ke 0GccoNPLNGQOBGjydNZ907hzeUMZPYBUbShAwhL0jSz6G7TsJGLSBU9pC0s+3YlUuG0G vEtsL29WT9V8qfnIHdl7X+cz7FgfA0T8/tY6utFoGIAuXuI1BCfrJ1UZ8/IWlwnXA3B7 lk7laNYuqjN31jA+12eDD2H6+e89gJuf55FIBg9wtsOMZFLJtRmUIMWga5ZkIZgpKt7Y Zixa9bjqDElJG4/NXWHYcoKxhziv5yAiDGF1+3vnJgIwWbZX4z5nVHCmGx+wNCLL0lvt Gvqw== ARC-Message-Signature: i=2; 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=o+wRszxk0RVAQ49EubcS3o6BAod/YEpz+w8A12Os+Eg=; fh=DCOgySnvkUhutDZ6l+uRTbsPYEa/DfkPJ0GjZwidHdI=; b=eO84N52Z2CCkyEcdZmqzCqUFdGnB6ZZCI724eKX2cadfk3WZVQJQym80mMNs6DLpLC ITGqQlKMiFKxOh0Wk5x0J1eadUhCIVuzFgSE5hMXcWdd7d0GliFLeHVdsPC+RydbWinF 6sTcEO9Ls0XacNKp9b70iQqxRjXgeRT/GWYG/djs6xVz4a/3kAej3OQVXvME5W2dGnWD YX7cTEMC68uyzwsdkLGegs4HxQsHt5D8tZSqPD7/MpnHTVQnnS6NLmOyIPUTDoicKe0e JzEJEjjnQ58CQN5DmkWLVU+V3/4fA7vCISSQ8CER0WoKCZ1Xz22+ZAoWWRhJX6DdF/jx bMkg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RbsmGQXF; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58824-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58824-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCUZAEYoQHoC+tQ4Izu2GmBLBQu5bvOshaJVuImgqOUpIw76Arg1Zv/moyyLKy72OgQoVg4eLoM4IxMaINKQZA686NolsQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id q8-20020aa79828000000b006ddce4f37c0si481283pfl.285.2024.02.08.15.30.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:30:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58824-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RbsmGQXF; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58824-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58824-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 004AB281CE9 for ; Thu, 8 Feb 2024 23:28:54 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AB86660DD3; Thu, 8 Feb 2024 23:15:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="RbsmGQXF" 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 58BA450267; Thu, 8 Feb 2024 23:14:39 +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=1707434082; cv=none; b=lgVw8S1+4r1ydNq8qHtVgC9Xy7YHOfIS3vRUjOxp9X1K9RoYR40j8m/fDcRGqH+mbtV50c9nnlVsC+zMDDmmYcOzDXB5VogYWY3kTI+mJhm7Jp+cVLfutcNx7i+FJmcet6zYpZS58N2DgJIpEdJBdKL62LwLR/vIF0TQrlQ6s5s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434082; c=relaxed/simple; bh=NETfvnw1ab2cyP+I0JYT3vCjGI4smKavYXYp7OlXQfg=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Lfkv0VdWa0EYUerzs6Zf+OsOalABZ2hGO5zopv5Z4sGnaNbJAHKcD68HDsOOsoyp1L8QEL/VNeog2v4saSDBKnCrXaDa9lE1akDIGhhBovteODoJTiaTUdCfHn5PNvjWULSloXk1veRVsTkBJ6GKRCJtXpgubSzHaV3bTn12z7E= 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=RbsmGQXF; 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 Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418MhkpW026726; Thu, 8 Feb 2024 23:14:26 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=o+wRszxk0RVAQ49EubcS 3o6BAod/YEpz+w8A12Os+Eg=; b=RbsmGQXFVzmjoNLNl5ewYhHHaLuLmMw9BHfE ooxs8MEytIb2nGVBsjAdwPpI3fShZJ/6MIeCsCBjxechY3l5K99Eafgp/r6yLBs0 9n2+eZUnZANST2cqYj4LzgGYYzeNehNAh7w9sL98OyGyFBcZgv6v+nsCHMJuIZQ8 6Pv8dCS2yKpmFqazAGUPAjTOrXw6SAWf0l0NNEZVMVzXjKTgkC77SwZbc4ByvIeP ekOak0UuXK6vjI6A3kSz7if+H8zJyb0w3q/VQvJjTw/FrLAgGw5a3hqEBHt00t8y aeni2EcKyUxLcAgAM3XgBq5GriIQBxPwOI4fPEbWpQc6n6myQw== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4pavjs0c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:25 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NEO0H013170 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14: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; Thu, 8 Feb 2024 15:14:24 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 32/53] ALSA: usb-audio: Check for support for requested audio format Date: Thu, 8 Feb 2024 15:13:45 -0800 Message-ID: <20240208231406.27397-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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: Ks6BwNx3ChFFUf7KjWAN8kNc42jvynxW X-Proofpoint-GUID: Ks6BwNx3ChFFUf7KjWAN8kNc42jvynxW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 malwarescore=0 mlxlogscore=999 phishscore=0 bulkscore=0 adultscore=0 clxscore=1015 suspectscore=0 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790375402314776206 X-GMAIL-MSGID: 1790375402314776206 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 | 31 +++++++++++++++++++++++++++++++ sound/usb/card.h | 11 +++++++++++ 2 files changed, 42 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 7dc8007ba839..1ad99a462038 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -155,6 +155,37 @@ 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; + + /* + * 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 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 */