From patchwork Thu Feb 8 23:13:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wesley Cheng X-Patchwork-Id: 198638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp512655dyd; Thu, 8 Feb 2024 15:21:36 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVzfHlPb8BpbtChHxdY908T3Jg2w0xhyeZb47XNMxv+TLHkdPv9Fdn7QCBO3bDiX32acUOHwcDHD2pAHjJPttbqvk2wYg== X-Google-Smtp-Source: AGHT+IH11pA0jkXcAMEUki4oMn3m4CTaw4WGFBr156eeY8/scr1rGeF/e4x8N8nHvghci0hkGaNN X-Received: by 2002:a05:6a00:92a8:b0:6e0:5e78:7509 with SMTP id jw40-20020a056a0092a800b006e05e787509mr1027822pfb.31.1707434496121; Thu, 08 Feb 2024 15:21:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707434496; cv=pass; d=google.com; s=arc-20160816; b=Yw9hyyfHhj8kgcZ97Wjl5WhGRdovT9X9O3Nw3kt7ntyyh/ylwHfn3cG2Qfl83jKZqL fTPAkFFgBgjjAq69Bo1VTr0gwCLAHPZ5F5TYoGGbwixQFMHSMQVVc47YjeDJuTnS/cka VoFbOuRTB8BjSAAbbO9aX+IGZCEowARVbzRY0QPcFScMCXdqIGuVbUzH3Gw0lX7suvOT GEha4CYkbbnFYN0LAn2owonY8Afire817643Y/+N8206gZl2BmpD4lcmwapsb/d32qrs KBy5SEEoC0e0xrmCApaRv9fj9ZPLw/PcfxeEPmjzzY1fvl5801Sq4U2Tl6M4k0p5WHaP RBjw== ARC-Message-Signature: i=2; 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=S9VTWxSz7x4qq1AeYZyZG+OFcZ7lvmr3A4Wyz4IN404=; fh=u+/pmkQpt/5Y+DifftmjUD5pAdbd2XJguD6yel/yQwQ=; b=RDk9q+e5voZFDDe6LeeewIum+e5acfQRzQuXy88kdt0/1RFUOz7hdNH6fJPwE2HtAo Hdi5HtyWo1TIzsLjTbU4C+M4tp3CG2PLQ4IavoBvoJ1xVadZSmrWiarqwHKQNgAaBkh5 1ygYB2plaf+PmVuFtQw0ZlNxjkwhoRvtEW0wexm/GwpNzOqTeiMu7EUq07FcTO6M03V9 q4tfxER45By5hMu0a9HAYcNW3FESpyffHAkeTJLuBhhmXzXn5qWSAzIqYFxEDm2O+S8A WQgt7CRPu76jYrwbMxjJElJqw3b8/ssxpMKmkW+xr7Q9XwXmf58crH3G+sDYlkE4E12x j5iQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nmyhFz94; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58808-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58808-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com X-Forwarded-Encrypted: i=2; AJvYcCWs9EQNyOvYKE+GlYShEoCp/J+lGZ5IffucmdWwKniez46fXAwAyQ9GtBUPjnxZRIDgqM8t0g6u5iYj9LsVNYDKoX/vxg== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 75-20020a63014e000000b005d509aa1476si572310pgb.549.2024.02.08.15.21.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Feb 2024 15:21:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-58808-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=nmyhFz94; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-58808-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-58808-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 8595928EC69 for ; Thu, 8 Feb 2024 23:20:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2D3E657885; Thu, 8 Feb 2024 23:14:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="nmyhFz94" 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 17D1250A70; Thu, 8 Feb 2024 23:14:36 +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=1707434079; cv=none; b=eMzWc20vP72bogeh7vkTQspRHtDFW3aFjFUe/Z2mw7+kx91PUp7ARo7VGt45OqF7tDuEIYidLO6qqFW3bl24dGP1pvZ77dyyGlhvVaV37xro5wxSSQ+zw1E+EIObIi1Gp9QT16z6utXVVeOvhNa5Rd3CivrgUsqomiX3i9Wv6+s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707434079; c=relaxed/simple; bh=NFb5KrutHq3DEtEEDYwpfG5twPMjHvzujusJINVO7hw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=VZj/40COk3HGsY7SPh5NK4yNjYd2CDZbNn9oQuhuxbQVN1ti48Ppnuo5TXvlIW+yaktYwQJv+u30j75YjfNp48DTu+EIpdQHm8lPyIrRTHfuGZ7QiU7Z5byanggdIryblK7ygY/jN7zNLrL5U6Wl7j/BMkRPECGNuhNRuYDg3hA= 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=nmyhFz94; 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 Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 418MWXUY003836; Thu, 8 Feb 2024 23:14:24 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=S9VTWxSz7x4qq1AeYZyZ G+OFcZ7lvmr3A4Wyz4IN404=; b=nmyhFz94i58NcMtBUXFTjFvgn+JoddbHFpsq 1HZftJnOtPoWWU7bO5CnwCN8LXMX9FxFr3dzeHIp8KxM3AwnF4AarfXKFDs4aIj0 aF2A/2fMkgy/btH6W45Lk0pewA1cxI2qghchH8N90oekuxcjmDNP08NIXD4gMUJs jhkCCT2o3MXkkxCDUWJK4GnCNwT9HmBBSTv/CD5c2sljVtnrFExxfY5SkWx1143D OVP3VakBVlgWgT/r4dpWng1lw5Zl8KcbQgYBFZNKdepNSS3CIYlFKeXvZSkKGxyO v5r06cBM0/CqJpwX1lyNLjC0JZdMPkhnsjUug6kHG3W3LaBapg== Received: from nalasppmta01.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3w4m3ak1pe-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 08 Feb 2024 23:14:23 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA01.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 418NEMsw005590 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 8 Feb 2024 23:14:23 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; Thu, 8 Feb 2024 15:14:22 -0800 From: Wesley Cheng To: , , , , , , , , , , , , , , CC: , , , , , , , Wesley Cheng Subject: [PATCH v14 25/53] ALSA: usb-audio: Introduce USB SND platform op callbacks Date: Thu, 8 Feb 2024 15:13:38 -0800 Message-ID: <20240208231406.27397-26-quic_wcheng@quicinc.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20240208231406.27397-1-quic_wcheng@quicinc.com> References: <20240208231406.27397-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-ORIG-GUID: MV9UD4QMEr-0_X4WY57egN_5DuUEBoQP X-Proofpoint-GUID: MV9UD4QMEr-0_X4WY57egN_5DuUEBoQP X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-08_11,2024-02-08_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 lowpriorityscore=0 impostorscore=0 phishscore=0 mlxlogscore=934 adultscore=0 priorityscore=1501 malwarescore=0 spamscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2401310000 definitions=main-2402080131 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790374834249768760 X-GMAIL-MSGID: 1790374834249768760 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 | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 9 ++++++++ 2 files changed, 62 insertions(+) diff --git a/sound/usb/card.c b/sound/usb/card.c index 1b2edc0fd2e9..ca4f3bc1b42d 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,42 @@ 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) +{ + guard(mutex)(®ister_mutex); + if (platform_ops) + return -EEXIST; + + platform_ops = 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 = NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops); /* * disconnect streams @@ -910,7 +946,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 +987,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 +1133,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 +1178,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 */