Thread (87 messages) 87 messages, 5 authors, 2024-08-21

[PATCH v24 11/34] ASoC: usb: Fetch ASoC card and pcm device information

flat view
STALE797d SUPERSEDED

From: Wesley Cheng <hidden>
Date: 2024-08-01 01:18:36
Also in: alsa-devel, linux-arm-msm, linux-doc, linux-sound, linux-usb, lkml
Subsystem: sound, sound - soc layer / dynamic audio power management (asoc), the rest · Maintainers: Jaroslav Kysela, Takashi Iwai, Liam Girdwood, Mark Brown, Linus Torvalds

Status: Superseded by v38 (posted 2025-04-09). [go to v38]

Revision v24 (38 revisions archived).

Revisions (38)
  1. rfc
  2. v2 [diff against previous]
  3. v3 [diff against previous]
  4. v4 [diff against previous]
  5. v5 [diff against previous]
  6. v6 [diff against previous]
  7. v7 [diff against previous]
  8. v8 [diff against previous]
  9. v9 [diff against previous]
  10. v10 [diff against previous]
  11. v11 [diff against previous]
  12. v12 [diff against previous]
  13. v13 [diff against previous]
  14. v14 [diff against previous]
  15. v15 [diff against previous]
  16. v16 [diff against previous]
  17. v17 [diff against previous]
  18. v18 [diff against previous]
  19. v19 [diff against previous]
  20. v20 [diff against previous]
  21. v21 [diff against previous]
  22. v22 [diff against previous]
  23. v23 [diff against previous]
  24. v24 current [diff against previous]
  25. v25 [diff against previous]
  26. v26 [diff against previous]
  27. v27 [diff against previous]
  28. v28 [diff against previous] re-posted go to this post re-posted go to this post
  29. v29 [diff against previous]
  30. v30 [diff against previous]
  31. v31 [diff against previous]
  32. v32 [diff against previous]
  33. v33 [diff against previous]
  34. v34 [diff against previous]
  35. v35 [diff against previous]
  36. v36 [diff against previous]
  37. v37 [diff against previous]
  38. v38 [diff against previous]
USB SND needs to know how the USB offload path is being routed.  This would
allow for applications to open the corresponding sound card and pcm device
when it wants to take the audio offload path.  This callback should return
the mapped indexes based on the USB SND device information.

Signed-off-by: Wesley Cheng <redacted>
---
 include/sound/soc-usb.h | 16 ++++++++++++++++
 sound/soc/soc-usb.c     | 28 ++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
index d6b576f971ae..a167e3de0a78 100644
--- a/include/sound/soc-usb.h
+++ b/include/sound/soc-usb.h
@@ -8,6 +8,11 @@
 
 #include <sound/soc.h>
 
+enum snd_soc_usb_kctl {
+	SND_SOC_USB_KCTL_CARD_ROUTE,
+	SND_SOC_USB_KCTL_PCM_ROUTE,
+};
+
 /**
  * struct snd_soc_usb_device
  * @card_idx - sound card index associated with USB device
@@ -32,6 +37,7 @@ struct snd_soc_usb_device {
  * @component - reference to ASoC component
  * @num_supported_streams - number of supported concurrent sessions
  * @connection_status_cb - callback to notify connection events
+ * @get_offload_dev - callback to fetch mapped ASoC device
  * @priv_data - driver data
  **/
 struct snd_soc_usb {
@@ -40,6 +46,8 @@ struct snd_soc_usb {
 	unsigned int num_supported_streams;
 	int (*connection_status_cb)(struct snd_soc_usb *usb,
 			struct snd_soc_usb_device *sdev, bool connected);
+	int (*get_offload_dev)(struct snd_soc_component *component,
+				int card, int pcm, enum snd_soc_usb_kctl route);
 	void *priv_data;
 };
 
@@ -51,6 +59,8 @@ void *snd_soc_usb_find_priv_data(struct device *dev);
 int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
 					struct snd_soc_jack *jack);
 int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component);
+int soc_usb_get_offload_device(struct device *dev, int card, int pcm,
+				enum snd_soc_usb_kctl route);
 
 struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component,
 					      int num_streams, void *data);
@@ -86,6 +96,12 @@ static inline int snd_soc_usb_disable_offload_jack(struct snd_soc_component *com
 	return -ENODEV;
 }
 
+static int soc_usb_get_offload_device(struct device *dev, int card, int pcm,
+					enum snd_soc_usb_kctl route)
+{
+	return -ENODEV;
+}
+
 static inline struct snd_soc_usb *snd_soc_usb_allocate_port(
 					      struct snd_soc_component *component,
 					      int num_streams, void *data)
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
index fe2a75a28af4..3c217ac67c57 100644
--- a/sound/soc/soc-usb.c
+++ b/sound/soc/soc-usb.c
@@ -117,6 +117,34 @@ int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component)
 }
 EXPORT_SYMBOL_GPL(snd_soc_usb_disable_offload_jack);
 
+/**
+ * soc_usb_get_offload_device - Set active USB offload path
+ * @dev - USB device to get offload status
+ * @card - USB card index
+ * @pcm - USB PCM device index
+ *
+ * Fetch the current status for the USB SND card and PCM device indexes
+ * specified.
+ */
+int soc_usb_get_offload_device(struct device *dev, int card, int pcm,
+				enum snd_soc_usb_kctl route)
+{
+	struct snd_soc_usb *ctx;
+	int ret;
+
+	ctx = snd_soc_find_usb_ctx(dev);
+	if (!ctx)
+		return -ENODEV;
+
+	mutex_lock(&ctx_mutex);
+	if (ctx && ctx->get_offload_dev)
+		ret = ctx->get_offload_dev(ctx->component, card, pcm, route);
+	mutex_unlock(&ctx_mutex);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(soc_usb_get_offload_device);
+
 /**
  * snd_soc_usb_find_priv_data() - Retrieve private data stored
  * @dev: device reference
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help