diff mbox series

[v9,21/34] ASoC: usb: Add PCM format check API for USB backend

Message ID 20231017200109.11407-22-quic_wcheng@quicinc.com (mailing list archive)
State New, archived
Headers show
Series Introduce QC USB SND audio offloading support | expand

Commit Message

Wesley Cheng Oct. 17, 2023, 8 p.m. UTC
Introduce a check for 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 |  3 +++
 sound/soc/soc-usb.c     | 13 +++++++++++++
 2 files changed, 16 insertions(+)

Comments

Pierre-Louis Bossart Oct. 17, 2023, 10:33 p.m. UTC | #1
On 10/17/23 15:00, Wesley Cheng wrote:
> Introduce a check for if a particular PCM format is supported by the USB

Introduce a helper to check if a ...

> 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 |  3 +++
>  sound/soc/soc-usb.c     | 13 +++++++++++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
> index 58c686f4f7ba..c6ddc055c4cd 100644
> --- a/include/sound/soc-usb.h
> +++ b/include/sound/soc-usb.h
> @@ -37,6 +37,9 @@ struct snd_soc_usb {
>  	void *priv_data;
>  };
>  
> +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);
>  void *snd_soc_usb_find_priv_data(struct device *usbdev);
> diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
> index 73b1bcc3b506..7407678a993e 100644
> --- a/sound/soc/soc-usb.c
> +++ b/sound/soc/soc-usb.c
> @@ -63,6 +63,19 @@ void *snd_soc_usb_find_priv_data(struct device *dev)
>  }
>  EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data);
>  
> +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);

Is this the right way to check for formats?

formats are defined within the scope of an endpoint, and those endpoints
are themselves defined within the scope of an interface?

I don't see a notion of endpoint here. Does this assume all endpoints
are valid, or maybe the existence of a single endpoint in a device?

Confused.
Wesley Cheng Oct. 18, 2023, 8:33 p.m. UTC | #2
Hi Pierre,

On 10/17/2023 3:33 PM, Pierre-Louis Bossart wrote:
> 
> 
> On 10/17/23 15:00, Wesley Cheng wrote:
>> Introduce a check for if a particular PCM format is supported by the USB
> 
> Introduce a helper to check if a ...
> 

Ack.

>> 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 |  3 +++
>>   sound/soc/soc-usb.c     | 13 +++++++++++++
>>   2 files changed, 16 insertions(+)
>>
>> diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
>> index 58c686f4f7ba..c6ddc055c4cd 100644
>> --- a/include/sound/soc-usb.h
>> +++ b/include/sound/soc-usb.h
>> @@ -37,6 +37,9 @@ struct snd_soc_usb {
>>   	void *priv_data;
>>   };
>>   
>> +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);
>>   void *snd_soc_usb_find_priv_data(struct device *usbdev);
>> diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
>> index 73b1bcc3b506..7407678a993e 100644
>> --- a/sound/soc/soc-usb.c
>> +++ b/sound/soc/soc-usb.c
>> @@ -63,6 +63,19 @@ void *snd_soc_usb_find_priv_data(struct device *dev)
>>   }
>>   EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data);
>>   
>> +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);
> 
> Is this the right way to check for formats?
> 
> formats are defined within the scope of an endpoint, and those endpoints
> are themselves defined within the scope of an interface?
> 
> I don't see a notion of endpoint here. Does this assume all endpoints
> are valid, or maybe the existence of a single endpoint in a device?
> 
> Confused.

At least in terms of USB and USB UAC, formats are defined within an 
audio streaming interface descriptor, which will include multiple (up to 
2) USB endpoints.  Those endpoints will be described w/ both an audio 
streaming endpoint descriptor as well as a standard USB endpoint 
descriptor.  The audio interface/format descriptors are the ones that 
carry the information about what formats are supported by the USB 
device.  So this API finds a possible USB AS streaming descriptor on the 
device that matches the requested one.  Endpoints will be opened 
subsequently when the audio stream is started, and an interface is 
enabled by sending a SET_INTERFACE control packet on the USB bus.

Thanks
Wesley Cheng
diff mbox series

Patch

diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h
index 58c686f4f7ba..c6ddc055c4cd 100644
--- a/include/sound/soc-usb.h
+++ b/include/sound/soc-usb.h
@@ -37,6 +37,9 @@  struct snd_soc_usb {
 	void *priv_data;
 };
 
+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);
 void *snd_soc_usb_find_priv_data(struct device *usbdev);
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c
index 73b1bcc3b506..7407678a993e 100644
--- a/sound/soc/soc-usb.c
+++ b/sound/soc/soc-usb.c
@@ -63,6 +63,19 @@  void *snd_soc_usb_find_priv_data(struct device *dev)
 }
 EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data);
 
+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_add_port() - Add a USB backend port
  * @dev: USB backend device