From patchwork Tue Jan 2 21:45:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 184480 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7301:6f82:b0:100:9c79:88ff with SMTP id tb2csp4700123dyb; Tue, 2 Jan 2024 13:50:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IGNMTZ9WY35r+x2uVtBOJ+7kWvq1Pi8vXIU/Ill3rhfF4bFzmSJIrQlluHXNJJP3uCHApW2 X-Received: by 2002:a05:620a:1202:b0:781:5d3a:72ca with SMTP id u2-20020a05620a120200b007815d3a72camr12346037qkj.113.1704232247277; Tue, 02 Jan 2024 13:50:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704232247; cv=none; d=google.com; s=arc-20160816; b=nudc6RDDAwuROaUqkq472BEhvkaN4P+r82CdK1+oILByNY3E92Jpd+hbql5sK2mW/o 998M+2uyobxq4DIwR7U41l9Vk2GMfhgN5iBUFxhAX3tl8mj0IWfxqa0xVfwvBzYmF0YF T3SEIC2lC9R6yhKCMi13kmw2JturXoN145tQrCV2JtmtDQC2AW18x3gVVShqIlbm3azv xn6MiXx5quooiqstO+0sheJABhmb2mN22z55261QrKfcFQsYmo8OtYcYm9QUc4ssAZ08 XOKGwCBdKifU8yF2XEBJT9B1FDmMNYdC69FINXHelh3SksiWyRW0Gt+F3ODoU5LECKum Jv1Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=soLP1wxYe/Q2Qo2eRZtDOZ0+xrFrE1vGLjGfET0ejzk=; fh=0KzismZj+xI0Z//ZGdqKIH/FO9LtSZM7Yj4P0VtrCz0=; b=BnLOneM2bTRmdOIy3p3KqhCe5ZL3E04yJWYI5w8XGOjHwiZ/XVtegf9Ldm3bXqc7hW AxNCGMUXGudWbk1NasugyrZlP572PzAXE3aKhzZGN96iWbicmbQzbZP2BIs5qzjfMWnB 5k8x4N5EznwjXrzvEKqflxpXGl0cQLuJWU5bQ0GlWgqdr3/PRxIIc2LwvXx1CVKPfr4f cR/+nLgfs8SqBmR9D4AEinvhf7ssQLGvbNfSC6fzXdWbWJSzTHc4gIY/HujQpxfn3QGZ 2GAPQyIszdDOWzUMAxljXVc2W6ycexSZErXhju1RvHHrW4YW7ssMR1PQ9tI7xW5p3swV aBjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Gc5GYfZS; spf=pass (google.com: domain of linux-kernel+bounces-14866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14866-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s2-20020a05620a030200b0077da484038csi27196271qkm.579.2024.01.02.13.50.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 13:50:47 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-14866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Gc5GYfZS; spf=pass (google.com: domain of linux-kernel+bounces-14866-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-14866-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 080AF1C214E3 for ; Tue, 2 Jan 2024 21:50:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 11D141805F; Tue, 2 Jan 2024 21:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Gc5GYfZS" X-Original-To: linux-kernel@vger.kernel.org Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 95FF5171C7; Tue, 2 Jan 2024 21:46:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279867.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 402Lh5HM002858; Tue, 2 Jan 2024 21:46:21 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=soLP1wxYe/Q2Qo2eRZtD OZ0+xrFrE1vGLjGfET0ejzk=; b=Gc5GYfZSFkOK9HSqeRSumdi51AFcq2HZkdAB n8R3+lvq7mwuLjWc4DXVEBbaRS2SPHaIXyTVOXnFpll1Jwt3fNCwoGa0SGD3QoZO 07SiVtzZYrDumCwOauCz0P3lP1S7rsWy7g4zQYPoDO3JyNcUBYDmi1kkHJlmxQtL 0iEVHiQAT0P43FDewDMACl/as1oSSD6dhXEd93wJpYSmU0PIYTArNMb6Jc4Z/m+c dlTbF762DZvQOSybcMLyHNBN48E4sZf4AXoe0wHHJLnYy2O2RaakKOaId64P4gwT ERcsVAZhhmMKi++2uXYsNAZm0HgtFeX1mqh4LDmi5VecYBHbsw== Received: from nalasppmta04.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3vch7n96r6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 02 Jan 2024 21:46:21 +0000 (GMT) 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 402LkLHx005500 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 2 Jan 2024 21:46:21 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.40; Tue, 2 Jan 2024 13:46:20 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v12 11/41] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Tue, 2 Jan 2024 13:45:19 -0800 Message-ID: <20240102214549.22498-12-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240102214549.22498-1-quic_wcheng@quicinc.com> References: <20240102214549.22498-1-quic_wcheng@quicinc.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nalasex01c.na.qualcomm.com (10.47.97.35) 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: bX9C0CTpgzmUSPBTIrpx8uyseukmb6kH X-Proofpoint-ORIG-GUID: bX9C0CTpgzmUSPBTIrpx8uyseukmb6kH X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.997,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-12-09_02,2023-12-07_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 impostorscore=0 phishscore=0 mlxlogscore=909 mlxscore=0 lowpriorityscore=0 priorityscore=1501 malwarescore=0 bulkscore=0 spamscore=0 clxscore=1015 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2311290000 definitions=main-2401020161 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787017032823098319 X-GMAIL-MSGID: 1787017032823098319 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 | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 9 ++++++++ 2 files changed, 69 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1b2edc0fd2e9..1ef6d144aa51 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,49 @@ 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; + +/* + * Register platform specific operations that will be notified on events + * which occur in USB SND. The platform driver can utilize this path to + * enable features, such as USB audio offloading, which allows for audio data + * to be queued by an audio DSP. + * + * Only one set of platform operations can be registered to USB SND. The + * platform register operation is protected by the register_mutex. + */ +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) +{ + int ret; + + mutex_lock(®ister_mutex); + if (platform_ops) { + ret = -EEXIST; + goto out; + } + + platform_ops = ops; +out: + mutex_unlock(®ister_mutex); + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_register_platform_ops); + +/* + * Unregisters the current set of platform operations. This allows for + * a new set to be registered if required. + * + * The platform unregister operation is protected by the register_mutex. + */ +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 @@ -910,7 +953,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: @@ -947,6 +994,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; @@ -1090,6 +1140,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; } @@ -1130,6 +1185,11 @@ static int usb_audio_resume(struct usb_interface *intf) snd_usb_midi_v2_resume_all(chip); + mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->resume_cb) + platform_ops->resume_cb(intf); + mutex_unlock(®ister_mutex); + out: if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); diff --git a/sound/usb/card.h b/sound/usb/card.h index 6ec95b2edf86..2884912adc96 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,13 @@ 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); + void (*resume_cb)(struct usb_interface *intf); +}; + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); #endif /* __USBAUDIO_CARD_H */