Linux USB
 help / color / mirror / Atom feed
From: Wesley Cheng <quic_wcheng@quicinc.com>
To: <mathias.nyman@intel.com>, <gregkh@linuxfoundation.org>,
	<lgirdwood@gmail.com>, <broonie@kernel.org>, <perex@perex.cz>,
	<tiwai@suse.com>, <agross@kernel.org>, <andersson@kernel.org>,
	<konrad.dybcio@linaro.org>, <robh+dt@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<srinivas.kandagatla@linaro.org>, <bgoswami@quicinc.com>,
	<Thinh.Nguyen@synopsys.com>
Cc: <linux-kernel@vger.kernel.org>, <linux-usb@vger.kernel.org>,
	<alsa-devel@alsa-project.org>, <linux-arm-msm@vger.kernel.org>,
	<devicetree@vger.kernel.org>,
	Wesley Cheng <quic_wcheng@quicinc.com>
Subject: [PATCH v7 11/33] ALSA: usb-audio: Introduce USB SND platform op callbacks
Date: Thu, 21 Sep 2023 14:48:21 -0700	[thread overview]
Message-ID: <20230921214843.18450-12-quic_wcheng@quicinc.com> (raw)
In-Reply-To: <20230921214843.18450-1-quic_wcheng@quicinc.com>

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 <quic_wcheng@quicinc.com>
---
 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(&register_mutex);
+	if (platform_ops) {
+		ret = -EEXIST;
+		goto out;
+	}
+
+	platform_ops = ops;
+out:
+	mutex_unlock(&register_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(&register_mutex);
+	platform_ops = NULL;
+	mutex_unlock(&register_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(&register_mutex);
+
 	return 0;
 
  __error:
@@ -947,6 +994,9 @@ static void usb_audio_disconnect(struct usb_interface *intf)
 	card = chip->card;
 
 	mutex_lock(&register_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(&register_mutex);
+	if (platform_ops && platform_ops->suspend_cb)
+		platform_ops->suspend_cb(intf, message);
+	mutex_unlock(&register_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(&register_mutex);
+	if (platform_ops && platform_ops->resume_cb)
+		platform_ops->resume_cb(intf);
+	mutex_unlock(&register_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 */

  parent reply	other threads:[~2023-09-21 21:49 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-21 21:48 [PATCH v7 00/33] Introduce QC USB SND audio offloading support Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 01/33] xhci: add support to allocate several interrupters Wesley Cheng
2023-09-28 10:31   ` Mathias Nyman
2023-10-02 20:07     ` Wesley Cheng
2023-10-04 14:02       ` Mathias Nyman
2023-10-04 18:35         ` Wesley Cheng
2023-10-04 23:42           ` Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 02/33] xhci: add helper to stop endpoint and wait for completion Wesley Cheng
2023-09-28 13:31   ` Mathias Nyman
2023-09-28 22:10     ` Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 03/33] xhci: sideband: add initial api to register a sideband entity Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 04/33] usb: host: xhci-mem: Cleanup pending secondary event ring events Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 05/33] usb: host: xhci-mem: Allow for interrupter clients to choose specific index Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 06/33] ASoC: Add SOC USB APIs for adding an USB backend Wesley Cheng
2023-09-27 14:48   ` Mark Brown
2023-09-27 19:57     ` Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 07/33] ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 08/33] ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 09/33] ASoC: qdsp6: q6afe: Increase APR timeout Wesley Cheng
2023-09-27 14:50   ` Mark Brown
2023-09-27 20:01     ` Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 10/33] ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 Wesley Cheng
2023-09-21 21:48 ` Wesley Cheng [this message]
2023-09-21 21:48 ` [PATCH v7 12/33] ALSA: usb-audio: Export USB SND APIs for modules Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 13/33] dt-bindings: usb: dwc3: Limit num-hc-interrupters definition Wesley Cheng
2023-09-25 15:32   ` Rob Herring
2023-09-21 21:48 ` [PATCH v7 14/33] dt-bindings: usb: xhci: Add " Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 15/33] usb: dwc3: Specify maximum number of XHCI interrupters Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 16/33] usb: host: xhci-plat: Set XHCI max interrupters if property is present Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 17/33] ALSA: usb-audio: qcom: Add USB QMI definitions Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 18/33] ALSA: usb-audio: qcom: Introduce QC USB SND offloading support Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 19/33] ALSA: usb-audio: Check for support for requested audio format Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 20/33] ASoC: usb: Add PCM format check API for USB backend Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 21/33] ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 22/33] ALSA: usb-audio: Prevent starting of audio stream if in use Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 23/33] ASoC: dt-bindings: Add Q6USB backend Wesley Cheng
2023-09-25 15:34   ` Rob Herring
2023-09-21 21:48 ` [PATCH v7 24/33] ASoC: dt-bindings: Update example for enabling USB offload on SM8250 Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 25/33] ASoC: qcom: qdsp6: q6afe: Split USB AFE dev_token param into separate API Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 26/33] ALSA: usb-audio: qcom: Populate PCM and USB chip information Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 27/33] ASoC: qcom: qdsp6: Add support to track available USB PCM devices Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 28/33] ASoC: qcom: qdsp6: Add SND kcontrol to select offload device Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 29/33] ASoC: qcom: qdsp6: Add SND kcontrol for fetching offload status Wesley Cheng
2023-09-27 15:02   ` Mark Brown
2023-09-27 20:10     ` Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 30/33] ASoC: qcom: qdsp6: Add headphone jack for offload connection status Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 31/33] ALSA: usb-audio: qcom: Use card and PCM index from QMI request Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 32/33] ALSA: usb-audio: Allow for rediscovery of connected USB SND devices Wesley Cheng
2023-09-21 21:48 ` [PATCH v7 33/33] ASoC: usb: Rediscover USB SND devices on USB port add Wesley Cheng
2023-09-27 15:04 ` [PATCH v7 00/33] Introduce QC USB SND audio offloading support Mark Brown
2023-09-27 15:46   ` Greg KH

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230921214843.18450-12-quic_wcheng@quicinc.com \
    --to=quic_wcheng@quicinc.com \
    --cc=Thinh.Nguyen@synopsys.com \
    --cc=agross@kernel.org \
    --cc=alsa-devel@alsa-project.org \
    --cc=andersson@kernel.org \
    --cc=bgoswami@quicinc.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=konrad.dybcio@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=perex@perex.cz \
    --cc=robh+dt@kernel.org \
    --cc=srinivas.kandagatla@linaro.org \
    --cc=tiwai@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox