ASoC: usb: Fetch ASoC card and pcm device information

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.

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-18-quic_wcheng@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
Wesley Cheng 2025-04-09 12:47:50 -07:00 committed by Greg Kroah-Hartman
parent 0bb5f3614b
commit 234ed32592
2 changed files with 62 additions and 0 deletions

View file

@ -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 - SoC USB representation of a USB sound device
* @card_idx: sound card index associated with USB device
@ -36,6 +41,12 @@ struct snd_soc_usb_device {
* @list: list head for SND SOC struct list
* @component: reference to ASoC component
* @connection_status_cb: callback to notify connection events
* @update_offload_route_info: callback to fetch mapped ASoC card and pcm
* device pair. This is unrelated to the concept
* of DAPM route. The "route" argument carries
* an array used for a kcontrol output for either
* the card or pcm index. "path" determines the
* which entry to look for. (ie mapped card or pcm)
* @priv_data: driver data
**/
struct snd_soc_usb {
@ -44,6 +55,10 @@ struct snd_soc_usb {
int (*connection_status_cb)(struct snd_soc_usb *usb,
struct snd_soc_usb_device *sdev,
bool connected);
int (*update_offload_route_info)(struct snd_soc_component *component,
int card, int pcm, int direction,
enum snd_soc_usb_kctl path,
long *route);
void *priv_data;
};
@ -58,6 +73,9 @@ 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);
int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
int direction, enum snd_soc_usb_kctl path,
long *route);
struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component,
void *data);
@ -95,6 +113,13 @@ static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *compo
return 0;
}
static int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
int direction, enum snd_soc_usb_kctl path,
long *route)
{
return -ENODEV;
}
static inline struct snd_soc_usb *
snd_soc_usb_allocate_port(struct snd_soc_component *component, void *data)
{

View file

@ -90,6 +90,43 @@ int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component,
}
EXPORT_SYMBOL_GPL(snd_soc_usb_setup_offload_jack);
/**
* snd_soc_usb_update_offload_route - Find active USB offload path
* @dev: USB device to get offload status
* @card: USB card index
* @pcm: USB PCM device index
* @direction: playback or capture direction
* @path: pcm or card index
* @route: pointer to route output array
*
* Fetch the current status for the USB SND card and PCM device indexes
* specified. The "route" argument should be an array of integers being
* used for a kcontrol output. The first element should have the selected
* card index, and the second element should have the selected pcm device
* index.
*/
int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm,
int direction, enum snd_soc_usb_kctl path,
long *route)
{
struct snd_soc_usb *ctx;
int ret = -ENODEV;
mutex_lock(&ctx_mutex);
ctx = snd_soc_find_usb_ctx(dev);
if (!ctx)
goto exit;
if (ctx->update_offload_route_info)
ret = ctx->update_offload_route_info(ctx->component, card, pcm,
direction, path, route);
exit:
mutex_unlock(&ctx_mutex);
return ret;
}
EXPORT_SYMBOL_GPL(snd_soc_usb_update_offload_route);
/**
* snd_soc_usb_find_priv_data() - Retrieve private data stored
* @usbdev: device reference