From patchwork Tue Oct 17 20:01:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 154463 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4370330vqb; Tue, 17 Oct 2023 13:03:39 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEbG+rlWsvnmRdjZNgOIwCqTU81/5kTTVLC5mXfMJKFrFC0GqveqHyIxln3dy0a9v+Z5HAs X-Received: by 2002:a05:6a00:1d12:b0:6b2:51a0:e1c9 with SMTP id a18-20020a056a001d1200b006b251a0e1c9mr3380994pfx.1.1697573019032; Tue, 17 Oct 2023 13:03:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573019; cv=none; d=google.com; s=arc-20160816; b=QmmxQOcrzsSyoe5DFRM5ogCR7Voj+lWUjjksZSjYolH0H0Hjud6Np2QYPY9G9KQ/rs 6xnQsVRdSWI6lHxrB+Lq6QBzOWexq9Qk/QvURCQtEzdbGS1oOFeTB0oVcpfaJAdl9heb Oss4wvu/8pDNoVlU5G0UCxooXoUFnS4qpuJF4PWs7AkPgiVUXCrfql9XeN4hQi0+KjkI bBOviC5UZblc5xZZSjN1ZyNjpmASiVVp+FDM1E12UEbyD7p7m2zb6ZQgBdpmdCVejF7s Il0i4a0d+wFn2+wc1T5tfRv1FWG9mAMSJWhDX4I/ALiznSC7dc4w1GEeBa64m8GpnXAw HzcQ== 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=CL3FVM1qBZnRnbh0US8YjFD3CDy8ri2rtoQ7u0QpjGc=; fh=ASZxE/GudOQkGCAz0d02NHHSpg4iNHYOcDWl1imlof0=; b=NtO0n25aMURmxrufuoB2P95FzFjHMqyd4rjRCQAC6cwavFs8Oj9x06Ex6aFUtmibjC 6Luc8/g0Pj4uGBlgyLaIRNBAQMx9v9fOLpVmoHbFz+DGUlvMrD2gpefcihEmJcb+RLRM 720qsi5nqVV8ubXocDQ4LDwce/KrFGxTpOwLu4GRHgmCJpZzEbLZ+zDPM3FTAqimUwND Vmnv4FWFi0PO466eZyQnIpeTR4C2b8qJjJjUhHSEA1vPqG9kaT8hJKNNKLxlGUQojqxd F1Ios4qD59EjdUlUlbnKm/M0TMylf3ysrPPawaH5IuiMEB1jzvhvKhiVbmeOBTnp4EUV CD0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Li9ytFau; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (fry.vger.email. [2620:137:e000::3:8]) by mx.google.com with ESMTPS id q13-20020a056a00084d00b006bd9c159a98si2425257pfk.186.2023.10.17.13.03.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:03:39 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 as permitted sender) client-ip=2620:137:e000::3:8; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Li9ytFau; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:8 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 fry.vger.email (Postfix) with ESMTP id 96D3B80EA7A1; Tue, 17 Oct 2023 13:03:24 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235125AbjJQUCI (ORCPT + 21 others); Tue, 17 Oct 2023 16:02:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344000AbjJQUBx (ORCPT ); Tue, 17 Oct 2023 16:01:53 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0EF31FD; Tue, 17 Oct 2023 13:01:46 -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 39HGNrrq010263; Tue, 17 Oct 2023 20:01:31 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=CL3FVM1qBZnRnbh0US8YjFD3CDy8ri2rtoQ7u0QpjGc=; b=Li9ytFauUDGnZBdoNEuvwt4IeYr5g21y8ahoFi4SqosqMGzDNHrXdN7v23l3DTXB1A/L PRo1eQdwFmcPgZVrUAMV50ryiFWWvrjpGC0npIpoK4zU+0AU/C+hZEuTj/vL1zyD6OjW cyf42tlJ7RZitAHBzMEwhBM53+wN4l+c/sxvKyX29d5RheR/XY5Dkfq5d580RIhhTLUB GP8NOX8fN9nQMCiQYg6HDMNgox8IKftiyX3DDb8GKPy+1QistkaIxeGAFL5JkHMsIFEv aVV7SeR/9B71SlWJROHhKOyK/KnDnAv/pa1gnXHVR+SQ+0NuxAsxV2DBWfa2V5nO5wgF bw== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3tsb7xjxtq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 20:01:30 +0000 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 39HK1T62010322 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 17 Oct 2023 20:01:29 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.39; Tue, 17 Oct 2023 13:01:29 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v9 33/34] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Tue, 17 Oct 2023 13:01:08 -0700 Message-ID: <20231017200109.11407-34-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231017200109.11407-1-quic_wcheng@quicinc.com> References: <20231017200109.11407-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 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: LCCT4hvCHVlrkIYKANs65OmVC9gniLMy X-Proofpoint-GUID: LCCT4hvCHVlrkIYKANs65OmVC9gniLMy X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.980,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-10-17_03,2023-10-17_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 mlxlogscore=999 suspectscore=0 lowpriorityscore=0 spamscore=0 bulkscore=0 mlxscore=0 phishscore=0 malwarescore=0 impostorscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2309180000 definitions=main-2310170170 X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email 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 (fry.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:03:24 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780034325689802386 X-GMAIL-MSGID: 1780034325689802386 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 88f431917c15..7d3f470754ca 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -202,6 +202,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 01f7e10f30f4..c0aeda17ed69 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -221,11 +221,13 @@ 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); +void snd_usb_rediscover_devices(void); #else static struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, int direction) { return NULL; } +static void snd_usb_rediscover_devices(void) { } #endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */