From patchwork Wed Mar 8 23:57:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 66539 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:570d:b0:a1:2e52:cf23 with SMTP id h13csp888450dyk; Wed, 8 Mar 2023 16:16:17 -0800 (PST) X-Google-Smtp-Source: AK7set9zTv3makHLXCqvqgbAbS4ARi2pxxeO0rhGKHR9TUkcuPpqE6XGGyB5khOJKVEt4pXkT1Rr X-Received: by 2002:a17:90b:3b4f:b0:237:5dc6:ce14 with SMTP id ot15-20020a17090b3b4f00b002375dc6ce14mr20351910pjb.7.1678320977240; Wed, 08 Mar 2023 16:16:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678320977; cv=none; d=google.com; s=arc-20160816; b=v0ahgVNsuKV6dt7wEvm8bb/4NClAES4lWBVkuztDwTFlUSqqgVMfv8XEDC0uKmPrza m4xpvlQe2jJpPh75KAgIsreuwuWr35gTT7IkwcMQFQrqC1FA7UzfmMKg50+vzVk9Gt78 8lXBEGpPH/oAfT3D0nP1SubVRgch/OQIYYtHc4Qz4Khq6bPeudR9d2UAzPCusxZEaf9g FYEMolRMOs8Mrl7V5xvhxMwGHoJg3E+JZ2yYSaVPe3FGGAIbGed6OQ9pkE81s9a0/M5p JP5wAJ6/BABuX1eZopYu6TRRoKm7VSpFAvUhfpx3xHNmUhJkxSyOYOzT2l/vS9o6prE2 CrOg== 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=0Cb4kpHPUQsn2sdakstI25sJvfLYrwtdEAZ3IGoRd+8=; b=Rk/3fnFm7soXc8G2D0/I33aUkP9AMmVJNlotTX4biN/tr3X5sD7TinLPWJt6Anjbgt p7xhZL7GrYL7jZy3sJ30xg2MApLCLFaaftmwnbMaMuc91bf5fCTz22NapSbS99ZIjkS5 +NBUVF573YwRICfg+KGR2OvwN7ahyLGrD98vEQylyLx80N1rQD/L5pW8xQl5kmVS27Ht FCGsz41dKf0kM2OObFsWIBFSxNpmvQlH38JL64F0Bi6hCBqt3wgZvwcDjvW2gelwA2Vj 2OcAw/bDTx0ilOHt16xekNqrOxvUwG5gnUwDjoX6Ycs4fh9pr7i0xxRPK3nOxN7QsWb5 wUjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=oYtzkW1A; 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 22-20020a631756000000b00502e5477334si4282320pgx.687.2023.03.08.16.16.02; Wed, 08 Mar 2023 16:16:17 -0800 (PST) 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=oYtzkW1A; 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 S230383AbjCIAAW (ORCPT + 99 others); Wed, 8 Mar 2023 19:00:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35876 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229823AbjCHX6c (ORCPT ); Wed, 8 Mar 2023 18:58:32 -0500 Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA7B884831; Wed, 8 Mar 2023 15:58:30 -0800 (PST) Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 328K8Avu017405; Wed, 8 Mar 2023 23:58:14 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=0Cb4kpHPUQsn2sdakstI25sJvfLYrwtdEAZ3IGoRd+8=; b=oYtzkW1AXIH0kfPjZpfSx63fTLKaK7WaomATVLF/XcUK+OrAamKf+1/MO4Ywft8fRBGQ bMkigKmytOJMzbUtr+gGiCN/vjTsIRYSgdBBBQ2oQ/8UrluSmScu7/mFStHuhdshGeMv KN9GDqOcS3FSnbk1IxjX8xQZxb9rwdt2ReC3OWy6Qb/6IvDbyTj3NAISvQeoIoiUqoWI 2+R6oW+WQq+dezwJh+5KP64qwXFJiYOtKX+N7IMerYw5yqvoaMjG4SyHU3wrP3GCVjPY 65K49OPr62XtKeMnQt5wHtXiaqu0KZPm/JOUUY8Lr7HX7yfC/KWqGKn7P53k9MYM7cA7 vw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3p6vnah88u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 08 Mar 2023 23:58:13 +0000 Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA04.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 328NwDe6016313 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 8 Mar 2023 23:58:13 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.986.41; Wed, 8 Mar 2023 15:58:12 -0800 From: Wesley Cheng To: , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v3 27/28] sound: usb: card: Allow for rediscovery of connected USB SND devices Date: Wed, 8 Mar 2023 15:57:50 -0800 Message-ID: <20230308235751.495-28-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230308235751.495-1-quic_wcheng@quicinc.com> References: <20230308235751.495-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: tbAGHuJxD45blQGUq_vyv07IC4r-k_pr X-Proofpoint-ORIG-GUID: tbAGHuJxD45blQGUq_vyv07IC4r-k_pr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-03-08_15,2023-03-08_03,2023-02-09_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 adultscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 impostorscore=0 mlxscore=0 phishscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2212070000 definitions=main-2303080200 X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE, SPF_PASS 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759847096957708132?= X-GMAIL-MSGID: =?utf-8?q?1759847096957708132?= 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 e51461ac33cd..25267c1cc64e 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 922868d2dccd..7bbaee87a48a 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 int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) { @@ -235,5 +236,6 @@ 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 */