ASoC: usb: Create SOC USB SND jack kcontrol
authorWesley Cheng <quic_wcheng@quicinc.com>
Wed, 9 Apr 2025 19:47:49 +0000 (12:47 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 11 Apr 2025 11:02:31 +0000 (13:02 +0200)
Expose API for creation of a jack control for notifying of available
devices that are plugged in/discovered, and that support offloading.  This
allows for control names to be standardized across implementations of USB
audio offloading.

Reviewed-by: Pierre-Louis Bossart <pierre-louis.bossart@linux.intel.com>
Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
Acked-by: Mark Brown <broonie@kernel.org>
Link: https://lore.kernel.org/r/20250409194804.3773260-17-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
include/sound/soc-usb.h
sound/soc/soc-usb.c

index 188b8df529322615f6ca20cd99bb8fd86ec80201..e9eb8dbb2e0ecf7f7abd9d213b73dbd08afd73bd 100644 (file)
@@ -56,6 +56,9 @@ int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev);
 int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev);
 void *snd_soc_usb_find_priv_data(struct device *usbdev);
 
+int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
+                                  struct snd_soc_jack *jack);
+
 struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component,
                                              void *data);
 void snd_soc_usb_free_port(struct snd_soc_usb *usb);
@@ -86,6 +89,12 @@ static inline void *snd_soc_usb_find_priv_data(struct device *usbdev)
        return NULL;
 }
 
+static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
+                                                struct snd_soc_jack *jack)
+{
+       return 0;
+}
+
 static inline struct snd_soc_usb *
 snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data)
 {
index cb2025d7b58fda8917d620d9b7fcda5c408f0296..ec894182f816bddfb5e1d8c8215a8a8bdc0feff7 100644 (file)
@@ -4,7 +4,10 @@
  */
 #include <linux/of.h>
 #include <linux/usb.h>
+
+#include <sound/jack.h>
 #include <sound/soc-usb.h>
+
 #include "../usb/card.h"
 
 static DEFINE_MUTEX(ctx_mutex);
@@ -52,6 +55,41 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev)
        return ctx ? ctx : NULL;
 }
 
+/* SOC USB sound kcontrols */
+/**
+ * snd_soc_usb_setup_offload_jack() - Create USB offloading jack
+ * @component: USB DPCM backend DAI component
+ * @jack: jack structure to create
+ *
+ * Creates a jack device for notifying userspace of the availability
+ * of an offload capable device.
+ *
+ * Returns 0 on success, negative on error.
+ *
+ */
+int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
+                                  struct snd_soc_jack *jack)
+{
+       int ret;
+
+       ret = snd_soc_card_jack_new(component->card, "USB Offload Jack",
+                                   SND_JACK_USB, jack);
+       if (ret < 0) {
+               dev_err(component->card->dev, "Unable to add USB offload jack: %d\n",
+                       ret);
+               return ret;
+       }
+
+       ret = snd_soc_component_set_jack(component, jack, NULL);
+       if (ret) {
+               dev_err(component->card->dev, "Failed to set jack: %d\n", ret);
+               return ret;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_usb_setup_offload_jack);
+
 /**
  * snd_soc_usb_find_priv_data() - Retrieve private data stored
  * @usbdev: device reference