From nobody Thu Sep 19 21:31:58 2024 Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 8A9EA1BFDEC; Thu, 12 Sep 2024 19:40:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726170019; cv=none; b=JpPPM5Gbo3CELdOG8lYofUTzuxMqGaeal/jWPiiw5qgMWZHD+0n5SnTlw232E80J08AqEtt5hA6EIX+1lAcYpZIOFNleKPELTHD7IVIZMHXojhkMWOSRSQMqsgip7mD2Kln99o77Odrgc0wlbq5Nla8nutjjhXR8hxgl5PsrqhI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726170019; c=relaxed/simple; bh=6AqDjoRyqy6LqZrw6Wfm9KSKYephW441qNNZBK1XyFY=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=SMeYYzvcRxX/G/mQEjvXesZRCBfWcgXjg0nHhVCgYsaEXyZ3b9R/1SlQ/BFI1Al0d5SjqdXKxvH//93q8Ux8E3dEqfSHRAiU7KdlPWY3ufGVdGEkdii26qmQPfqbDfEz4Cdg1g7OJwZXhSQvFUt6oDv3AyZZzMqTuMKt5IKoQX0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=NlOtf478; arc=none smtp.client-ip=205.220.180.131 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="NlOtf478" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 48CJVsBq027792; Thu, 12 Sep 2024 19:39:55 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=qcppdkim1; bh= uab/+NaMfWEzUKyixsCiUSLJhDlynbFL9O2pQiQ0Y+Q=; b=NlOtf478C2ElAjVc JTYigTrVC+PLDo+wwEq/RgEA8A/M3od3TDJN3EiI2nv3bTZkCGdrguDXaBZxSfo1 5Iv5z6Pnnscus9MCtitivCYPVGX805OSrreQO2M3j40IwQj1SeTgifAtpsKr/fqG /nXoaqazELla5kB7PRn3KsQSZf9mPUIvZPNqrugZI2tEJSUqvjQlD3Nf11k9d83W 50CSXfNp+bTrdAfd2Fb9jHi/WpvhzTjlrbHa0Zy5y1ff4m0DrPI3Mcclw0jBityg E+EfIrlG/suSD6xgESMG5U2cJFCfrI1wDe4/+vadIVFuFxxRDMNtatF2Cnj+NA8O 5To3yQ== Received: from nalasppmta05.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 41gy8p6jc6-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2024 19:39:55 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA05.qualcomm.com (8.18.1.2/8.18.1.2) with ESMTPS id 48CJdscn009895 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 12 Sep 2024 19:39:54 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.1544.9; Thu, 12 Sep 2024 12:39:53 -0700 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , , Wesley Cheng Subject: [PATCH v27 26/32] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Thu, 12 Sep 2024 12:39:29 -0700 Message-ID: <20240912193935.1916426-27-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240912193935.1916426-1-quic_wcheng@quicinc.com> References: <20240912193935.1916426-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 Content-Transfer-Encoding: quoted-printable 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: 6nEdKSU-4GKPyB2pJyfU56pQaBGlBBmM X-Proofpoint-ORIG-GUID: 6nEdKSU-4GKPyB2pJyfU56pQaBGlBBmM X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.60.29 definitions=2024-09-06_09,2024-09-06_01,2024-09-02_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 clxscore=1015 impostorscore=0 mlxscore=0 bulkscore=0 suspectscore=0 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 adultscore=0 phishscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2408220000 definitions=main-2409120144 Content-Type: text/plain; charset="utf-8" Allow for different platforms to be notified on USB SND connect/disconnect sequences. 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 | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 10 ++++++++++ 2 files changed, 59 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1f9dfcd8f336..326292f37841 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,42 @@ MODULE_PARM_DESC(skip_validation, "Skip unit descripto= r 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 d= ata + * 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) +{ + guard(mutex)(®ister_mutex); + if (platform_ops) + return -EEXIST; + + platform_ops =3D ops; + 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) +{ + guard(mutex)(®ister_mutex); + platform_ops =3D NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); =20 /* * Checks to see if requested audio profile, i.e sample rate, # of @@ -946,7 +982,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; =20 __error: @@ -983,6 +1023,9 @@ static void usb_audio_disconnect(struct usb_interface = *intf) card =3D chip->card; =20 mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->disconnect_cb) + platform_ops->disconnect_cb(chip); + if (atomic_inc_return(&chip->shutdown) =3D=3D 1) { struct snd_usb_stream *as; struct snd_usb_endpoint *ep; @@ -1130,6 +1173,9 @@ static int usb_audio_suspend(struct usb_interface *in= tf, pm_message_t message) chip->system_suspend =3D chip->num_suspended_intf; } =20 + if (platform_ops && platform_ops->suspend_cb) + platform_ops->suspend_cb(intf, message); + return 0; } =20 @@ -1170,6 +1216,9 @@ static int usb_audio_resume(struct usb_interface *int= f) =20 snd_usb_midi_v2_resume_all(chip); =20 + if (platform_ops && platform_ops->resume_cb) + platform_ops->resume_cb(intf); + out: if (chip->num_suspended_intf =3D=3D 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 cdafc9e9cecd..d8b8522e1613 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -209,7 +209,17 @@ struct snd_usb_stream { struct list_head list; }; =20 +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); +}; + struct snd_usb_stream * snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *= params, int direction); + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); #endif /* __USBAUDIO_CARD_H */