Message ID | 20240213005422.3121-47-quic_wcheng@quicinc.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | Introduce QC USB SND audio offloading support | expand |
On Tue, 13 Feb 2024 01:54:18 +0100, Wesley Cheng wrote: > > --- a/sound/usb/Makefile > +++ b/sound/usb/Makefile > @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ > stream.o \ > validate.o > > +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o > snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o > snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o This puts the code into snd-usb-audio driver, and that causes a dependency mess, since... > +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, > + struct snd_ctl_elem_value *ucontrol) > +{ > + struct device *sysdev = snd_kcontrol_chip(kcontrol); > + int ret; > + > + ret = snd_soc_usb_device_offload_available(sysdev); ... here you call snd_soc_usb_*() stuff that belongs to snd-soc-usb. That is, with this patch, snd-usb-audio driver will depend on snd-soc-usb, while snd-soc-usb also depends on snd-usb-audio for its helpers again. I believe the better way would be to move this whole miser_usb_offload code into sound/usb/qcom/. You need only usb_device and snd_card objects at the creation, and you can get them in qcom driver side, too. thanks, Takashi
Hi Takashi, On 2/13/2024 4:18 AM, Takashi Iwai wrote: > On Tue, 13 Feb 2024 01:54:18 +0100, > Wesley Cheng wrote: >> >> --- a/sound/usb/Makefile >> +++ b/sound/usb/Makefile >> @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ >> stream.o \ >> validate.o >> >> +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o >> snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o >> snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o > > This puts the code into snd-usb-audio driver, and that causes a > dependency mess, since... > I see what you mean after moving some things into modules, etc... Will fix this accordingly. >> +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, >> + struct snd_ctl_elem_value *ucontrol) >> +{ >> + struct device *sysdev = snd_kcontrol_chip(kcontrol); >> + int ret; >> + >> + ret = snd_soc_usb_device_offload_available(sysdev); > > ... here you call snd_soc_usb_*() stuff that belongs to snd-soc-usb. > That is, with this patch, snd-usb-audio driver will depend on > snd-soc-usb, while snd-soc-usb also depends on snd-usb-audio for its > helpers again. > > I believe the better way would be to move this whole miser_usb_offload > code into sound/usb/qcom/. You need only usb_device and snd_card > objects at the creation, and you can get them in qcom driver side, > too. > Yes, plan is just to compile this as part of the overall offload module if the config is enabled. Thanks Wesley Cheng
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 4c842fbe6365..3e7be258d0e3 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,10 +176,14 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000. +config SND_USB_OFFLOAD_MIXER + bool + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND select SND_PCM + select SND_USB_OFFLOAD_MIXER help Say Y here to enable the Qualcomm USB audio offloading feature. diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 246788268ddd..8c54660a11b0 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -22,6 +22,7 @@ snd-usb-audio-objs := card.o \ stream.o \ validate.o +snd-usb-audio-$(CONFIG_SND_USB_OFFLOAD_MIXER) += mixer_usb_offload.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_MIDI_V2) += midi2.o snd-usb-audio-$(CONFIG_SND_USB_AUDIO_USE_MEDIA_CONTROLLER) += media.o diff --git a/sound/usb/mixer_usb_offload.c b/sound/usb/mixer_usb_offload.c new file mode 100644 index 000000000000..8adb9e227c1b --- /dev/null +++ b/sound/usb/mixer_usb_offload.c @@ -0,0 +1,65 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/usb.h> + +#include <sound/core.h> +#include <sound/control.h> +#include <sound/soc-usb.h> + +#include "card.h" +#include "mixer.h" +#include "mixer_usb_offload.h" +#include "usbaudio.h" + +static int +snd_usb_offload_available_get(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct device *sysdev = snd_kcontrol_chip(kcontrol); + int ret; + + ret = snd_soc_usb_device_offload_available(sysdev); + ucontrol->value.integer.value[0] = ret < 0 ? -1 : ret; + + return ret < 0 ? ret : 0; +} + +static int snd_usb_offload_available_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = 1; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new snd_usb_offload_available_ctl = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Capable Card", + .info = snd_usb_offload_available_info, + .get = snd_usb_offload_available_get, +}; + +/** + * snd_usb_offload_create_ctl() - Add USB offload bounded mixer + * @chip - USB SND chip device + * + * Creates a sound control for a USB audio device, so that applications can + * query for if there is an available USB audio offload path, and which + * card is managing it. + */ +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip) +{ + struct usb_device *udev = chip->dev; + + return snd_ctl_add(chip->card, + snd_ctl_new1(&snd_usb_offload_available_ctl, + udev->bus->sysdev)); +} +EXPORT_SYMBOL_GPL(snd_usb_offload_create_ctl); diff --git a/sound/usb/mixer_usb_offload.h b/sound/usb/mixer_usb_offload.h new file mode 100644 index 000000000000..12a2cd1d72e9 --- /dev/null +++ b/sound/usb/mixer_usb_offload.h @@ -0,0 +1,11 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __USB_OFFLOAD_MIXER_H +#define __USB_OFFLOAD_MIXER_H + +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip); +#endif /* __USB_OFFLOAD_MIXER_H */ + diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 17cee0cf2ff5..265e6d970925 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -34,6 +34,7 @@ #include "../endpoint.h" #include "../format.h" #include "../helper.h" +#include "../mixer_usb_offload.h" #include "../pcm.h" #include "../power.h" @@ -1648,6 +1649,8 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) uaudio_qdev->last_card_num = chip->card->number; snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + snd_usb_offload_create_ctl(chip); + mutex_unlock(&chip->mutex); mutex_unlock(&qdev_mutex);
In order to allow userspace/applications know about USB offloading status, expose a sound kcontrol that fetches information about which sound card index is associated with the ASoC platform card supporting offloading. In the USB audio offloading framework, the ASoC BE DAI link is the entity responsible for registering to the SOC USB layer. SOC USB will expose more details about the current offloading status, which includes the USB sound card and USB PCM device indexes currently being used. It is expected for the USB offloading driver to add the kcontrol to the sound card associated with the USB audio device. An example output would look like: tinymix -D 1 get 'USB Offload Playback Capable Card' 0 (range -1->32) Ths example signifies that card#0 has an USB offload capable path available. Signed-off-by: Wesley Cheng <quic_wcheng@quicinc.com> testing new mixer --- sound/usb/Kconfig | 4 ++ sound/usb/Makefile | 1 + sound/usb/mixer_usb_offload.c | 65 +++++++++++++++++++++++++++++++ sound/usb/mixer_usb_offload.h | 11 ++++++ sound/usb/qcom/qc_audio_offload.c | 3 ++ 5 files changed, 84 insertions(+) create mode 100644 sound/usb/mixer_usb_offload.c create mode 100644 sound/usb/mixer_usb_offload.h