From patchwork Tue Jul 25 02:34:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 125277 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9010:0:b0:3e4:2afc:c1 with SMTP id l16csp2192473vqg; Mon, 24 Jul 2023 19:48:44 -0700 (PDT) X-Google-Smtp-Source: APBJJlEQI6LzEnmXrGS6p6y/FWrbZ3DWgEqmlfSCiyoPENyhTkZzhTS8EyGqTGLqtb9Q7OKK1fVz X-Received: by 2002:a05:6a00:2407:b0:668:9fb6:b311 with SMTP id z7-20020a056a00240700b006689fb6b311mr12240167pfh.32.1690253324070; Mon, 24 Jul 2023 19:48:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690253324; cv=none; d=google.com; s=arc-20160816; b=HA9MQeuiiJ+Ys0wwyXfljDtQBK1comd1r0YLyYSji78+p/dS4kR811ZIeCanYXK4s8 f8YA2vwMWwvYu48AY+0wIVGKnGZVpfMsS8wIHovaL8GQ6FfeImd7nMnXZd1uXAGKwjZ8 AKjpJUNuoqsBUmoVscuOSllPJRa2UcXUPhihaEYspH3H9ne0G/30iAMq7O0k0+ralH0R IfYNdg7xtqVotqmL90MHFs/ssqBrYvmQYRTfxxzQr4tWRikYC6QJpyr/ecqZEDY1fOvL I1p53Y36Fevh/4UZfwzEGQQkIxsdHvv3+zlB0APYiD/mg+sdnjAnRxDEmVnz+R8opTwc E1tw== 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=gK0H3ERGpbnoDLtSRDe1cgYtWGuHfeMPw1i4wSf3qYY=; fh=Zah5MX43vfshi7s92Ld+vn5YZO52CQtO4oeiq16jPIc=; b=dU/cuRsfmVWi5IgNAreByim6Npfl+8oIeaom4ny9YNnms1US++M4+teqSARjmRWZnl tKHCS4DbCqr0JtSGN12+LDtloVaJtC7ou7MzbJ5DOtb6LafdCMUDhTpQZqrWoelnvRw0 YAv05SRlqOX6CHVYe/iM7I3vNVJKuEVabhOYnBmbwFr8XIHRIQ+glLxM5tI9G4kRkOzp gkWpqWAXfzwVoN0M59RMJC02A5S3BVksU7GWSNKbtdusWUuDy8SmEYSG3H73ywwgcZHB aqCRZR00ZRHKTTZ3F30rc59K7QxUwlFxAQE2TjS48a91ZzRYaLqf1eYJ7eiQNyYj46xm +auQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=f2m0+S7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dc14-20020a056a0035ce00b00682c0908d51si10429273pfb.126.2023.07.24.19.48.32; Mon, 24 Jul 2023 19:48:44 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=f2m0+S7e; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231292AbjGYCgc (ORCPT + 99 others); Mon, 24 Jul 2023 22:36:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230462AbjGYCf1 (ORCPT ); Mon, 24 Jul 2023 22:35:27 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF6D719B1; Mon, 24 Jul 2023 19:35:15 -0700 (PDT) Received: from pps.filterd (m0279869.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36P2EmnD003501; Tue, 25 Jul 2023 02:34:53 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=gK0H3ERGpbnoDLtSRDe1cgYtWGuHfeMPw1i4wSf3qYY=; b=f2m0+S7e/45UVDdg94lygB7xqLjOdtJr2oLp840W/zwZsx1bGNter8A7hx2K7RMHTqgw /1u7mO4DKydJ9/6bk+YqrsNuQsyahod2rzPo4t3EwkR2pgvMGauTwA9V1xw1y4gDNO7s 6h93Ld1ljuE+G8onPYQuYXc+ZQuS7t09MonVcNPFgQduD5Pa9s7nBS26DaOGOAc9H5Bp BE9SzTGyD2gQFOyEeB7YC6688m1+QVXu+Z2v7ivJQ8U9noqyG7e3bbREiKYaWuE1ARCb hScGxddtHrZkG6UBRU+7d5hH6MYyUAfIYSI9qW0oAuF1zAERBLsZ/5v8q37NuVsKpO7D BA== Received: from nasanppmta01.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s1vh8h4ce-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 02:34:52 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36P2YpeP020427 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 02:34:51 GMT Received: from hu-wcheng-lv.qualcomm.com (10.49.16.6) by nasanex01b.na.qualcomm.com (10.46.141.250) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.30; Mon, 24 Jul 2023 19:34:50 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , , , , , Wesley Cheng Subject: [PATCH v4 31/32] sound: usb: card: Allow for rediscovery of connected USB SND devices Date: Mon, 24 Jul 2023 19:34:15 -0700 Message-ID: <20230725023416.11205-32-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230725023416.11205-1-quic_wcheng@quicinc.com> References: <20230725023416.11205-1-quic_wcheng@quicinc.com> MIME-Version: 1.0 X-Originating-IP: [10.49.16.6] X-ClientProxiedBy: nalasex01a.na.qualcomm.com (10.47.209.196) To nasanex01b.na.qualcomm.com (10.46.141.250) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: k-4Wwz4ybJSX63sHRaBn-UnY3UZnb-mA X-Proofpoint-GUID: k-4Wwz4ybJSX63sHRaBn-UnY3UZnb-mA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-24_18,2023-07-24_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 clxscore=1015 bulkscore=0 impostorscore=0 mlxscore=0 spamscore=0 lowpriorityscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2306200000 definitions=main-2307250020 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,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-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1772359069410007825 X-GMAIL-MSGID: 1772359069410007825 In case of notifying SND platform drivers of connection events, some of these use cases, such as offloading, require an ASoC USB backend device to be initialized before the events can be handled. If the USB backend device has not yet been probed, this leads to missing initial USB audio device connection events. Expose an API that traverses the usb_chip array for connected devices, and to call the respective connection callback registered to the SND platform driver. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 19 +++++++++++++++++++ sound/usb/card.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 365f6d978608..27a89aaa0bf3 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -170,6 +170,25 @@ struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, } EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); +/* + * in case the platform driver was not ready at the time of USB SND + * device connect, expose an API to discover all connected USB devices + * so it can populate any dependent resources/structures. + */ +void snd_usb_rediscover_devices(void) +{ + int i; + + mutex_lock(®ister_mutex); + for (i = 0; i < SNDRV_CARDS; i++) { + if (usb_chip[i]) + if (platform_ops && platform_ops->connect_cb) + platform_ops->connect_cb(usb_chip[i]); + } + mutex_unlock(®ister_mutex); +} +EXPORT_SYMBOL_GPL(snd_usb_rediscover_devices); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index db735680d155..dfd241334e3d 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -219,6 +219,7 @@ int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, int direction); +void snd_usb_rediscover_devices(void); #else static int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) { @@ -235,5 +236,6 @@ static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, { return NULL; } +void snd_usb_rediscover_devices(void) { } #endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */