From patchwork Sat Sep 16 00:10:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 140808 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:172:b0:3f2:4152:657d with SMTP id h50csp1397549vqi; Fri, 15 Sep 2023 17:18:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEx5KPOT/x8PeX3tRkSiw+/aYWbo/lXoZcsiI36zu7fGws6Jg3yF39cK0b/TS8ZK53G1t8c X-Received: by 2002:a05:6a20:748e:b0:157:e67c:59 with SMTP id p14-20020a056a20748e00b00157e67c0059mr3479555pzd.29.1694823486599; Fri, 15 Sep 2023 17:18:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694823486; cv=none; d=google.com; s=arc-20160816; b=uJEKybG/9a3iY3k+VT9mU8x3eLrEAjUgZ4rTJ3mzJskkQyrTCtyrJNT5CoSpQV3PPQ xoZi1QJH/Mf3Vg+UIFYCJ8B137MfcP654SZZN/Daj3rNqYAVOQ1Ab2Cb8FYHd9aW7dzE avz5QYuQOxbUuuKwAc61BkYlpqRtjY8t6x9HP0gvC9jlgs75tx0F3YgOQDy+CZ21DH8s gEFH4Ci5ymOJn6sGZsRNrrK62PazKQXATzyvlfszXhCiH/DAnqATYAu/vUuGhfKzvgU3 cp/mS/ZyexGNoob09NHVD+74BJt7DxT+MLBCuhRZsw69g4TSqTKmHdWHiMGuAu5Yo8WO GnBw== 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=MhCCCRx4c0AeUz43uLzZOKA4YzcBN2mk3tAWrRRVvW4=; b=DFLiLt3oBUgTnWrFpD+1syrYImfhDAhhdobDgme9XaxAvEpXsS4eeAst3plD179b3n oXVzyTdAd6IdCnl7aqMjwKkOEfWp4sn8Owu7z6vPmvGmH5OAWAUEFeF/WBLBP+FzdTgM SEsOIj6OoiunMYN0RgpLzoPOMlwaRz1wM4lzqcmTJAee247OMXQLPEv5FM6a/zgpil2H 65c9pdiqne7VNflW6KOCcgE4uvTGVcpQcj7/yXdE1TK6Iuv/8lZo2LK5NeT1gFJ5QQu7 knOxEsoe+UCZfsKL/1hTGhDiJ/bY86HeFNqKpZN1JKrULRe9DFUAc0y9yY5VRQPtV2De 9PZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RP8i7ph6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (pete.vger.email. [23.128.96.36]) by mx.google.com with ESMTPS id b10-20020a6567ca000000b005775e17f560si3987931pgs.82.2023.09.15.17.18.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 17:18:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 as permitted sender) client-ip=23.128.96.36; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=RP8i7ph6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.36 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 pete.vger.email (Postfix) with ESMTP id 59672804756D; Fri, 15 Sep 2023 17:16:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238360AbjIPAMZ (ORCPT + 28 others); Fri, 15 Sep 2023 20:12:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238213AbjIPALU (ORCPT ); Fri, 15 Sep 2023 20:11:20 -0400 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3922E270A; Fri, 15 Sep 2023 17:11:15 -0700 (PDT) Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 38FNuwIU028295; Sat, 16 Sep 2023 00:10:47 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=RP8i7ph6Mjtc4QNt9JE2Y0ZyfC8aZH4/LVkj1vLvZPEij0et/SsRwlRxmilhsURrmNkN nx6gzdwJOakbgUHCBtkks5GSLhQfEFqHPwz/3mQCq094ZYBq52OnpGAg3s27Qd26xRpU Y/8D6hIjYNdLHGD97B+IJKf7jRanDtkLbMjgdEJF7fIsmuKmbSsSuNHyi3UBmxOsg1o4 cvQeo81Pb0wt7ZCHbVIs5IhtsAH69vrPJCbpx28KGn1WjPy4udJeI1Eww6STV0NZcWMh tc6X+vkee41u6OAFFjRJY+q3ZNTX4cDtL0pp0bvkEIlWXL27Pd8pWGu1pbGxhlyDkliV sA== Received: from nalasppmta02.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3t4vwc0k22-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 16 Sep 2023 00:10:47 +0000 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 38G0Ak8a011939 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Sat, 16 Sep 2023 00:10:46 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.36; Fri, 15 Sep 2023 17:10:46 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , Wesley Cheng Subject: [PATCH v6 32/33] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Date: Fri, 15 Sep 2023 17:10:25 -0700 Message-ID: <20230916001026.315-33-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230916001026.315-1-quic_wcheng@quicinc.com> References: <20230916001026.315-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-GUID: EF7Eulyn5ZxPRfNGQE1IkVtlkE7qzxjH X-Proofpoint-ORIG-GUID: EF7Eulyn5ZxPRfNGQE1IkVtlkE7qzxjH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.267,Aquarius:18.0.980,Hydra:6.0.601,FMLib:17.11.176.26 definitions=2023-09-15_20,2023-09-15_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 impostorscore=0 mlxscore=0 priorityscore=1501 adultscore=0 phishscore=0 suspectscore=0 lowpriorityscore=0 clxscore=1015 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2308100000 definitions=main-2309160000 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,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.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 (pete.vger.email [0.0.0.0]); Fri, 15 Sep 2023 17:16:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1777151232248231301 X-GMAIL-MSGID: 1777151232248231301 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 */