diff mbox series

[v20,22/41] ASoC: usb: Add PCM format check API for USB backend

Message ID 20240425215125.29761-23-quic_wcheng@quicinc.com (mailing list archive)
State Superseded
Headers show
Series Introduce QC USB SND audio offloading support | expand

Commit Message

Wesley Cheng April 25, 2024, 9:51 p.m. UTC
Introduce a helper to check if a particular PCM format is supported by the
USB audio device connected.  If the USB audio device does not have an
audio profile which can support the requested format, then notify the USB
backend.

Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
---
 include/sound/soc-usb.h |  9 +++++++++
 sound/soc/soc-usb.c     | 25 +++++++++++++++++++++++++
 2 files changed, 34 insertions(+)

Comments

Amadeusz Sławiński April 26, 2024, 1:25 p.m. UTC | #1
On 4/25/2024 11:51 PM, Wesley Cheng wrote:
> Introduce a helper to check if a particular PCM format is supported by the
> USB audio device connected.  If the USB audio device does not have an
> audio profile which can support the requested format, then notify the USB
> backend.
> 
> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
> ---

(...)

> +/**
> + * snd_soc_usb_find_format() - Check if audio format is supported
> + * @card_idx: USB sound chip array index
> + * @params: PCM parameters
> + * @direction: capture or playback
> + *
> + * Ensure that a requested audio profile from the ASoC side is able to be
> + * supported by the USB device.
> + *
> + * Return 0 on success, negative on error.
> + *
> + */
> +int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params,
> +			int direction)

Perhaps name function similar to its snd_usb equivalent, so 
snd_soc_usb_find_supported_format?

> +{
> +	struct snd_usb_stream *as;
> +
> +	as = snd_usb_find_suppported_substream(card_idx, params, direction);
> +	if (!as)
> +		return -EOPNOTSUPP;
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(snd_soc_usb_find_format);
> +
>   /**
>    * snd_soc_usb_allocate_port() - allocate a SOC USB device
>    * @component: USB DPCM backend DAI component
>
Wesley Cheng April 30, 2024, 8:01 a.m. UTC | #2
Hi Amadeusz,

On 4/26/2024 6:25 AM, Amadeusz Sławiński wrote:
> On 4/25/2024 11:51 PM, Wesley Cheng wrote:
>> Introduce a helper to check if a particular PCM format is supported by 
>> the
>> USB audio device connected.  If the USB audio device does not have an
>> audio profile which can support the requested format, then notify the USB
>> backend.
>>
>> Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com>
>> ---
> 
> (...)
> 
>> +/**
>> + * snd_soc_usb_find_format() - Check if audio format is supported
>> + * @card_idx: USB sound chip array index
>> + * @params: PCM parameters
>> + * @direction: capture or playback
>> + *
>> + * Ensure that a requested audio profile from the ASoC side is able 
>> to be
>> + * supported by the USB device.
>> + *
>> + * Return 0 on success, negative on error.
>> + *
>> + */
>> +int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params 
>> *params,
>> +            int direction)
> 
> Perhaps name function similar to its snd_usb equivalent, so 
> snd_soc_usb_find_supported_format?
> 

Will do.

Thanks
Wesley Cheng
diff mbox series

Patch

diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
index 5b2fa0877523..8f2d3064b520 100644
--- a/include/sound/soc-usb.h
+++ b/include/sound/soc-usb.h
@@ -39,6 +39,8 @@  struct snd_soc_usb {
 
 #if IS_ENABLED(CONFIG_SND_SOC_USB)
 const char *snd_soc_usb_get_components_tag(bool playback);
+int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params,
+			int direction);
 
 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);
@@ -55,6 +57,13 @@  static inline const char *snd_soc_usb_get_components_tag(bool playback)
 	return "";
 }
 
+static inline int snd_soc_usb_find_format(int card_idx,
+					  struct snd_pcm_hw_params *params,
+					  int direction)
+{
+	return -EINVAL;
+}
+
 static inline int snd_soc_usb_connect(struct device *usbdev,
 					struct snd_soc_usb_device *sdev)
 {
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
index d21db2345966..bc77204fd2db 100644
--- a/sound/soc/soc-usb.c
+++ b/sound/soc/soc-usb.c
@@ -80,6 +80,31 @@  void *snd_soc_usb_find_priv_data(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data);
 
+/**
+ * snd_soc_usb_find_format() - Check if audio format is supported
+ * @card_idx: USB sound chip array index
+ * @params: PCM parameters
+ * @direction: capture or playback
+ *
+ * Ensure that a requested audio profile from the ASoC side is able to be
+ * supported by the USB device.
+ *
+ * Return 0 on success, negative on error.
+ *
+ */
+int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params,
+			int direction)
+{
+	struct snd_usb_stream *as;
+
+	as = snd_usb_find_suppported_substream(card_idx, params, direction);
+	if (!as)
+		return -EOPNOTSUPP;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(snd_soc_usb_find_format);
+
 /**
  * snd_soc_usb_allocate_port() - allocate a SOC USB device
  * @component: USB DPCM backend DAI component