Received: by 2002:a05:6358:701b:b0:131:369:b2a3 with SMTP id 27csp3920647rwo; Mon, 24 Jul 2023 20:07:58 -0700 (PDT) X-Google-Smtp-Source: APBJJlHfc8XqOq1jQnR3jmfhq4bCcbKyZVJdFUkgHGvJ3A2k2TSEqslKBwg6WSvl+Ran8M9e3BJ0 X-Received: by 2002:a50:ec8d:0:b0:521:aeba:c6c0 with SMTP id e13-20020a50ec8d000000b00521aebac6c0mr9981749edr.36.1690254477825; Mon, 24 Jul 2023 20:07:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1690254477; cv=none; d=google.com; s=arc-20160816; b=VO+9EasMjaxcy6Ae1dpDXsmLV9acJr5vodWiyuHcaraT+NS+huRd+uO8dzc/nHHGOO B3NLaPeJU8rtHurzkiHJ8XTgD3/s5BIhV3qZRQyZlVE1/n9+KJKXYb7eIlb7lJEPELbj IfMwfmIltxObazVyZUs9WWzMhxGyGPeQG3V6wWoQ067F4YX8oSyo/te44xsBg+GC0oMf YqV0+KeK/lBIFP+JDJFUQO/1ZPrlDkMIwxJy/tQ61bYJTRtHf/RsMq1t79STogFwam4Z 3XFjdC6vKbouGmXoTsxBJRyk+UvHycNKgPHkqcyw+JB6m7zFC3hHBngBwiJI8SMdYZjl grfw== 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=FjY82JzU0n/q9JbCeJO4JnY3PdzsO5csmqYFNBEIyfg=; fh=Zah5MX43vfshi7s92Ld+vn5YZO52CQtO4oeiq16jPIc=; b=qVnGbFRkfB43BKNuEazWuac1Rg6EfH4Q1fqGYu8Thrg46J2o+8isCM+g+2V8Rsm+yC qj5JPavW3XaqF0t/roU82k9RyqwSi8TJDKwUdJi5J2pZs//mCLnaAbYIWJ+AdSEw2c8/ IMSzYOPl1xzH/UG2rF/geTeWIHWJ4HK7tKLlU8EJJpuoqssCk1M8bnq2XDUhETlVgMtE XBHxLnqRyPlM6Cjynw1Z6mCt3h4GNeqvbxY3QVGDqwonStw8kH4YvbPY/jDZzlxqc9+4 0nE8fOOJIHa1EPN6YdsaGGSm5TuR2dQHiTKoihVbZL7yHUYUeirRRVkLU29HoVevuEeN INFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=iQL2kyCb; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l6-20020aa7d946000000b005221da47f59si3988149eds.172.2023.07.24.20.07.33; Mon, 24 Jul 2023 20:07:57 -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=iQL2kyCb; 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 S231153AbjGYCfq (ORCPT + 99 others); Mon, 24 Jul 2023 22:35:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230339AbjGYCfN (ORCPT ); Mon, 24 Jul 2023 22:35:13 -0400 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D7291737; Mon, 24 Jul 2023 19:35:07 -0700 (PDT) Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 36P1VAVn011602; Tue, 25 Jul 2023 02:34:38 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=FjY82JzU0n/q9JbCeJO4JnY3PdzsO5csmqYFNBEIyfg=; b=iQL2kyCbtf/cL9Bm5o/dd+Y7GXGZ42w06mVdwsbUHiduwmR5x9be7qQpJQdnYcs/uc77 E8qr9DsyOE4Hvmghzaj9anIX637twiPoeCeLgFwExIEll/7rGZerneVOzPw5XvMWl/8o GIkukyAzu2lKmn+2kj2Ejx4GfyPPaqFGczesoXJoX9j2OgIZpXCBMQUlFLe6Q8zZS0Ms Jjl91hF1Y1jUfirB3I/obqEoN/+z3N1Lzp+R1gf6JVr8UU9PEbdvi/cliciSsWrtm0Qx V/03PuWOV4FmbiBJRwzfojCSE+Afk9E0tLOkyQXp4KW0BkPHseWiG+y2gsLESd16eJP3 Gw== Received: from nasanppmta02.qualcomm.com (i-global254.qualcomm.com [199.106.103.254]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3s1qa3sub0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 02:34:38 +0000 Received: from nasanex01b.na.qualcomm.com (nasanex01b.na.qualcomm.com [10.46.141.250]) by NASANPPMTA02.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 36P2YbqN012470 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 25 Jul 2023 02:34:37 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:36 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , , , , , Wesley Cheng Subject: [PATCH v4 11/32] sound: usb: card: Introduce USB SND platform op callbacks Date: Mon, 24 Jul 2023 19:33:55 -0700 Message-ID: <20230725023416.11205-12-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 Content-Type: text/plain 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: HNv_1sM8K399V2SGSo9-ppZkK1Nn6QcH X-Proofpoint-GUID: HNv_1sM8K399V2SGSo9-ppZkK1Nn6QcH 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 impostorscore=0 phishscore=0 malwarescore=0 suspectscore=0 clxscore=1015 mlxlogscore=904 priorityscore=1501 mlxscore=0 adultscore=0 spamscore=0 lowpriorityscore=0 bulkscore=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 Allow for different platforms to be notified on USB SND connect/disconnect seqeunces. This allows for platform USB SND modules to properly initialize and populate internal structures with references to the USB SND chip device. Signed-off-by: Wesley Cheng --- sound/usb/card.c | 36 ++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 20 ++++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index f6e99ced8068..9365d1e17836 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -117,6 +117,30 @@ MODULE_PARM_DESC(skip_validation, "Skip unit descriptor validation (default: no) static DEFINE_MUTEX(register_mutex); static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; static struct usb_driver usb_audio_driver; +static struct snd_usb_platform_ops *platform_ops; + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) +{ + if (platform_ops) + return -EEXIST; + + mutex_lock(®ister_mutex); + platform_ops = ops; + mutex_unlock(®ister_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_register_platform_ops); + +int snd_usb_unregister_platform_ops(void) +{ + mutex_lock(®ister_mutex); + platform_ops = NULL; + mutex_unlock(®ister_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); /* * disconnect streams @@ -908,7 +932,11 @@ static int usb_audio_probe(struct usb_interface *intf, chip->num_interfaces++; usb_set_intfdata(intf, chip); atomic_dec(&chip->active); + + if (platform_ops && platform_ops->connect_cb) + platform_ops->connect_cb(chip); mutex_unlock(®ister_mutex); + return 0; __error: @@ -945,6 +973,9 @@ static void usb_audio_disconnect(struct usb_interface *intf) card = chip->card; mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->disconnect_cb) + platform_ops->disconnect_cb(chip); + if (atomic_inc_return(&chip->shutdown) == 1) { struct snd_usb_stream *as; struct snd_usb_endpoint *ep; @@ -1086,6 +1117,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) chip->system_suspend = chip->num_suspended_intf; } + mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->suspend_cb) + platform_ops->suspend_cb(intf, message); + mutex_unlock(®ister_mutex); + return 0; } diff --git a/sound/usb/card.h b/sound/usb/card.h index 6ec95b2edf86..c48744724f7d 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,24 @@ struct snd_usb_stream { struct list_head list; }; +struct snd_usb_platform_ops { + void (*connect_cb)(struct snd_usb_audio *chip); + void (*disconnect_cb)(struct snd_usb_audio *chip); + void (*suspend_cb)(struct usb_interface *intf, pm_message_t message); +}; + +#if IS_ENABLED(CONFIG_SND_USB_AUDIO) +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); +#else +static int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) +{ + return -EOPNOTSUPP; +} + +static int snd_usb_unregister_platform_ops(void) +{ + return -EOPNOTSUPP; +} +#endif /* IS_ENABLED(CONFIG_SND_USB_AUDIO) */ #endif /* __USBAUDIO_CARD_H */