[PATCH v23 00/32] Introduce QC USB SND audio offloading support
Requesting to see if we can get some Acked-By tags, and merge on usb-next.
Several Qualcomm based chipsets can support USB audio offloading to a dedicated audio DSP, which can take over issuing transfers to the USB host controller. The intention is to reduce the load on the main processors in the SoC, and allow them to be placed into lower power modes. There are several parts to this design: 1. Adding ASoC binding layer 2. Create a USB backend for Q6DSP 3. Introduce XHCI interrupter support 4. Create vendor ops for the USB SND driver
USB | ASoC -------------------------------------------------------------------- | _________________________ | |sm8250 platform card | | |_________________________| | | | | ___V____ ____V____ | |Q6USB | |Q6AFE | | |"codec" | |"cpu" | | |________| |_________| | ^ ^ ^ | | |________| | ___V____ | | |SOC-USB | | ________ ________ | | | |USB SND |<--->|QC offld|<------------>|________| | |(card.c)| | |<---------- | |________| |________|___ | | | ^ ^ | | | ____________V_________ | | | | | |APR/GLINK | __ V_______________V_____ | | | |______________________| |USB SND (endpoint.c) | | | | ^ |_________________________| | | | | ^ | | | ___________V___________ | | | |->|audio DSP | ___________V_____________ | | |_______________________| |XHCI HCD |<- | |_________________________| |
Adding ASoC binding layer: soc-usb: Intention is to treat a USB port similar to a headphone jack. The port is always present on the device, but cable/pin status can be enabled/disabled. Expose mechanisms for USB backend ASoC drivers to communicate with USB SND.
Create a USB backend for Q6DSP: q6usb: Basic backend driver that will be responsible for maintaining the resources needed to initiate a playback stream using the Q6DSP. Will be the entity that checks to make sure the connected USB audio device supports the requested PCM format. If it does not, the PCM open call will fail, and userpsace ALSA can take action accordingly.
Introduce XHCI interrupter support: XHCI HCD supports multiple interrupters, which allows for events to be routed to different event rings. This is determined by "Interrupter Target" field specified in Section "6.4.1.1 Normal TRB" of the XHCI specification.
Events in the offloading case will be routed to an event ring that is assigned to the audio DSP.
Create vendor ops for the USB SND driver: qc_audio_offload: This particular driver has several components associated with it: - QMI stream request handler - XHCI interrupter and resource management - audio DSP memory management
When the audio DSP wants to enable a playback stream, the request is first received by the ASoC platform sound card. Depending on the selected route, ASoC will bring up the individual DAIs in the path. The Q6USB backend DAI will send an AFE port start command (with enabling the USB playback path), and the audio DSP will handle the request accordingly.
Part of the AFE USB port start handling will have an exchange of control messages using the QMI protocol. The qc_audio_offload driver will populate the buffer information: - Event ring base address - EP transfer ring base address
and pass it along to the audio DSP. All endpoint management will now be handed over to the DSP, and the main processor is not involved in transfers.
Overall, implementing this feature will still expose separate sound card and PCM devices for both the platorm card and USB audio device: 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D SM8250-MTP-WCD9380-WSA8810-VA-DMIC 1 [Audio ]: USB-Audio - USB Audio Generic USB Audio at usb-xhci-hcd.1.auto-1.4, high speed
This is to ensure that userspace ALSA entities can decide which route to take when executing the audio playback. In the above, if card#1 is selected, then USB audio data will take the legacy path over the USB PCM drivers, etc...
This feature was validated using: - tinymix: set/enable the multimedia path to route to USB backend - tinyplay: issue playback on platform card
Changelog -------------------------------------------- Changes in v23: - Added MODULE_DESCRIPTION() fields to drivers that needed it.
Changes in v22: - Removed components tag for the ASoC platform card, as the USB SND kcontrol for notifying userspace of offload capable card achieves similar results. - Due to the above, had to remove the review-by tag for the RST documentation, as changes were made to remove the components tag section. - Took in feedback to make the SOC USB add/remove ports void. - Fixed an issue w/ the USB SND kcontrol management for devices that have multi UAC interfaces. (would attempt to create the kcontrol more than once) - Modified SOC USB card and PCM index select to be based off the num_supported streams that is specified by the USB BE DAI. - Modified comments on selecting the latest USB headset for offloading.
Changes in v21: - Added an offload jack disable path from the ASoC platform driver and SOC USB. - Refactored some of the existing SOC USB context look up APIs and created some new helpers to search for the USB context. - Renamed snd_soc_usb_find_format to snd_soc_usb_find_supported_format - Removed some XHCI sideband calls that would allow clients to actually enable the IRQ line associated w/ the secondary interrupter. This is removed because there are other dependencies that are required for that to happen, which are not covered as part of this series, and to avoid confusion. - Due to the above, removed the need to export IMOD setting, and enable/disable interrupter APIs.
Changes in v20: - Fixed up some formatting changes pointed out in the usb.rst - Added SB null check during XHCI sideband unregister in case caller passes improper argument (xhci_sideband_unregister())
Changes in v19: - Rebased to usb-next to account for some new changes in dependent drivers.
Changes in v18: - Rebased to usb-next, which merged in part of the series. Removed these patches. - Reworked Kconfigs for the ASoC USB related components from QCOM Q6DSP drivers to keep dependencies in place for SoC USB and USB SND. - Removed the repurposing of the stop ep sync API into existing XHCI operations. This will be solely used by the XHCI sideband for now.
Changes in v17: - Fixed an issue where one patch was squashed into another. - Re-added some kconfig checks for helpers exposed in USB SND for the soc usb driver, after running different kconfigs.
Changes in v16: - Modified some code layer dependencies so that soc usb can be split as a separate module. - Split the kcontrols from ASoC QCOM common layer into a separate driver - Reworked SOC USB kcontrols for controlling card + pcm offload routing and status so that there are individual controls for card and pcm devices. - Added a kcontrol remove API in SOC USB to remove the controls on the fly. This required to add some kcontrol management to SOC USB. - Removed the disconnect work and workqueue for the QC USB offload as it is not required, since QMI interface driver ensures events are handled in its own WQ.
Changes in v15: - Removed some already merged XHCI changes - Separated SOC USB driver from being always compiled into SOC core. Now configurable from kconfig. - Fixed up ASoC kcontrol naming to fit guidelines. - Removed some unnecessary dummy ifdefs. - Moved usb snd offload capable kcontrol to be initialized by the platform offloading driver.
Changes in v14: - Cleaned up some USB SND related feedback: - Renamed SNDUSB OFFLD playback available --> USB offload capable card - Fixed locking while checking if stream is in use - Replaced some mutex pairs with guard(mutex)
Changes in v13: - Pulled in secondary/primary interrupter rework from Mathias from: https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git/log/drivers/... - Did some cleanup and commit message updates, and tested on current code base. - Added mutex locking to xhci sideband to help prevent any race conditions, esp. for when accessing shared references. - Addresed concerns from Hillf about gfp_flags and locking used in qc_usb_audio_offload. - Rebased onto usb-next
Changes in v12: - Updated copyright year to 2024. Happy new years! - Fixed newline format on mixer offload driver.
Changes in v11: - Modified QMI format structures to be const
Changes in v10: - Added new mixer for exposing kcontrol for sound card created by USB SND. This allows for applications to know which platform sound card has offload support. Will return the card number. - Broke down and cleaned up some functions/APIs within qc_audio_offload driver. - Exported xhci_initialize_ring_info(), and modified XHCI makefile to allow for the XHCI sideband to exist as a module. - Reworked the jack registration and moved it to the QCOM platform card driver, ie sm8250. - Added an SOC USB API to fetch a standard component tag that can be appended to the platform sound card. Added this tag to sm8250 if any USB path exists within the DT node. - Moved kcontrols that existed in the Q6USB driver, and made it a bit more generic, so that naming can be standardized across solutions. SOC USB is now responsible for creation of these kcontrols. - Added a SOC USB RST document explaining some code flows and implementation details so that other vendors can utilize the framework. - Addressed a case where USB device connection events are lost if usb offload driver (qc_audio_offload) is not probed when everything else has been initialized, ie USB SND, SOC USB and ASoC sound card. Add a rediscover device call during module init, to ensure that connection events will be propagated. - Rebased to usb-next.
Changes in v9: - Fixed the dt binding check issue with regards to num-hc-interrupters.
Changes in v8: - Cleaned up snd_soc_usb_find_priv_data() based on Mark's feedback. Removed some of the duplicate looping code that was present on previous patches. Also renamed the API. - Integrated Mathias' suggestions on his new sideband changes: https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git/log/?h=featu... - Addressed some of Mathias' fixme tags, such as: - Resetting transfer ring dequeue/enqueue pointers - Issuing stop endpoint command during ep removal - Reset ERDP properly to first segment ring during interrupter removal. (this is currently just being cleared to 0, but should be pointing to a valid segment if controller is still running.
Changes in v7: - Fixed dt check error for q6usb bindings - Updated q6usb property from qcom,usb-audio-intr-num --> qcom,usb-audio-intr-idx - Removed separate DWC3 HC interrupters num property, and place limits to XHCI one. - Modified xhci_ring_to_sgtable() to use assigned IOVA/DMA address to fetch pages, as it is not ensured event ring allocated is always done in the vmalloc range.
Changes in v6: - Fixed limits and description on several DT bindings (XHCI and Q6USB) - Fixed patch subjects to follow other ALSA/ASoC notations.
USB SND - Addressed devices which expose multiple audio (UAC) interfaces. These devices will create a single USB sound card with multiple audio streams, and receive multiple interface probe routines. QC offload was not properly considering cases with multiple probe calls. - Renamed offload module name and kconfig to fit within the SND domain. - Renamed attach/detach endpoint API to keep the hw_params notation.
Changes in v5: - Removed some unnescessary files that were included - Fixed some typos mentioned - Addressed dt-binding issues and added hc-interrupters definition to usb-xhci.yaml
XHCI: - Moved secondary skip events API to xhci-ring and updated implementation - Utilized existing XHCI APIs, such as inc_deq and xhci_update_erst_dequeue()
USB SND - Renamed and reworked the APIs in "sound: usb: Export USB SND APIs for modules" patch to include suggestions to utilize snd_usb_hw_params/free and to avoid generic naming. - Added a resume_cb() op for completion sake. - Addressed some locking concerns with regards to when registering for platform hooks. - Added routine to disconnect all offloaded devices during module unbind.
ASoC - Replaced individual PCM parameter arguments in snd_soc_usb_connect() with new snd_soc_usb_device structure to pass along PCM info. - Modified snd_jack set report to notify HEADPHONE event, as we do not support record path.
Changes in v4: - Rebased to xhci/for-usb-next - Addressed some dt-bindings comments
XHCI: - Pulled in latest changes from Mathias' feature_interrupters branch: https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git/log/?h=featu...
- Fixed commit text and signage for the XHCI sideband/interrupter related changes - Added some logic to address the FIXME tags mentioned throughout the commits, such as handling multi segment rings and building the SGT, locking concerns, and ep cleanup operations. - Removed some fixme tags for conditions that may not be needed/addressed. - Repurposed the new endpoint stop sync API to be utilized in other places. - Fixed potential compile issue if XHCI sideband config is not defined.
ASoC: - Added sound jack control into the Q6USB driver. Allows for userpsace to know when an offload capable device is connected.
USB SND: - Avoided exporting _snd_pcm_hw_param_set based on Takashi's recommendation. - Split USB QMI packet header definitions into a separate commit. This is used to properly allow the QMI interface driver to parse and route QMI packets accordingly - Added a "depends on" entry when enabling QC audio offload to avoid compile time issues.
Changes in v3: - Changed prefix from RFC to PATCH - Rebased entire series to usb-next - Updated copyright years
XHCI: - Rebased changes on top of XHCI changes merged into usb-next, and only added changes that were still under discussion. - Added change to read in the "num-hc-interrupters" device property.
ASoC: - qusb6 USB backend - Incorporated suggestions to fetch iommu information with existing APIs - Added two new sound kcontrols to fetch offload status and offload device selection. - offload status - will return the card and pcm device in use tinymix -D 0 get 1 --> 1, 0 (offload in progress on card#1 pcm#0)
- device selection - set the card and pcm device to enable offload on. Ex.: tinymix -D 0 set 1 2 0 --> sets offload on card#2 pcm#0 (this should be the USB card)
USB SND: - Fixed up some locking related concerns for registering platform ops. - Moved callbacks under the register_mutex, so that - Modified APIs to properly pass more information about the USB SND device, so that the Q6USB backend can build a device list/map, in order to monitor offload status and device selection.
Changes in v2:
XHCI: - Replaced XHCI and HCD changes with Mathias' XHCI interrupter changes in his tree: https://git.kernel.org/pub/scm/linux/kernel/git/mnyman/xhci.git/log/?h=featu...
Adjustments made to Mathias' changes: - Created xhci-intr.h to export/expose interrupter APIs versus exposing xhci.h. Moved dependent structures to this file as well. (so clients can parse out information from "struct xhci_interrupter") - Added some basic locking when requesting interrupters. - Fixed up some sanity checks. - Removed clearing of the ERSTBA during freeing of the interrupter. (pending issue where SMMU fault occurs if DMA addr returned is 64b - TODO)
- Clean up pending events in the XHCI secondary interrupter. While testing USB bus suspend, it was seen that on bus resume, the xHCI HC would run into a command timeout. - Added offloading APIs to xHCI to fetch transfer and event ring information.
ASoC: - Modified soc-usb to allow for multiple USB port additions. For this to work, the USB offload driver has to have a reference to the USB backend by adding a "usb-soc-be" DT entry to the device saved into XHCI sysdev. - Created separate dt-bindings for defining USB_RX port. - Increased APR timeout to accommodate the situation where the AFE port start command could be delayed due to having to issue a USB bus resume while handling the QMI stream start command.
Wesley Cheng (32): ASoC: Add SOC USB APIs for adding an USB backend ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp ASoC: qdsp6: q6afe: Increase APR timeout ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 ALSA: usb-audio: Introduce USB SND platform op callbacks ALSA: usb-audio: Export USB SND APIs for modules ALSA: usb-audio: Save UAC sample size information usb: dwc3: Specify maximum number of XHCI interrupters usb: host: xhci-plat: Set XHCI max interrupters if property is present ALSA: usb-audio: qcom: Add USB QMI definitions ALSA: usb-audio: qcom: Introduce QC USB SND offloading support ALSA: usb-audio: Check for support for requested audio format ASoC: usb: Add PCM format check API for USB backend ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device ALSA: usb-audio: Prevent starting of audio stream if in use ALSA: usb-audio: Do not allow USB offload path if PCM device is in use ASoC: dt-bindings: Update example for enabling USB offload on SM8250 ALSA: usb-audio: qcom: Populate PCM and USB chip information ASoC: qcom: qdsp6: Add support to track available USB PCM devices ASoC: Introduce SND kcontrols to select sound card and PCM device ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks ASoC: Introduce SND kcontrols to track USB offloading state ASoC: qcom: qdsp6: Add PCM ops to track current state ASoC: usb: Create SOC USB SND jack kcontrol ASoC: qcom: qdsp6: Add headphone jack for offload connection status ASoC: usb: Fetch ASoC sound card information ALSA: usb-audio: Add USB offloading capable kcontrol ALSA: usb-audio: Allow for rediscovery of connected USB SND devices ALSA: usb-audio: qcom: Use card and PCM index from QMI request ASoC: usb: Rediscover USB SND devices on USB port add ASoC: doc: Add documentation for SOC USB
.../bindings/sound/qcom,sm8250.yaml | 15 + Documentation/sound/soc/index.rst | 1 + Documentation/sound/soc/usb.rst | 603 ++++++ drivers/usb/dwc3/core.c | 12 + drivers/usb/dwc3/core.h | 2 + drivers/usb/dwc3/host.c | 3 + drivers/usb/host/xhci-plat.c | 2 + .../sound/qcom,q6dsp-lpass-ports.h | 1 + include/sound/q6usboffload.h | 20 + include/sound/soc-usb.h | 188 ++ sound/soc/Kconfig | 10 + sound/soc/Makefile | 2 + sound/soc/qcom/Kconfig | 15 + sound/soc/qcom/Makefile | 2 + sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6afe-dai.c | 60 + sound/soc/qcom/qdsp6/q6afe.c | 193 +- sound/soc/qcom/qdsp6/q6afe.h | 36 +- sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c | 23 + sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h | 1 + sound/soc/qcom/qdsp6/q6routing.c | 9 + sound/soc/qcom/qdsp6/q6usb.c | 417 ++++ sound/soc/qcom/sm8250.c | 23 +- sound/soc/qcom/usb_offload_utils.c | 56 + sound/soc/qcom/usb_offload_utils.h | 29 + sound/soc/soc-usb.c | 684 ++++++ sound/usb/Kconfig | 25 + sound/usb/Makefile | 2 +- sound/usb/card.c | 109 + sound/usb/card.h | 15 + sound/usb/endpoint.c | 1 + sound/usb/format.c | 1 + sound/usb/helper.c | 1 + sound/usb/pcm.c | 104 +- sound/usb/pcm.h | 11 + sound/usb/qcom/Makefile | 6 + sound/usb/qcom/mixer_usb_offload.c | 65 + sound/usb/qcom/mixer_usb_offload.h | 17 + sound/usb/qcom/qc_audio_offload.c | 1915 +++++++++++++++++ sound/usb/qcom/usb_audio_qmi_v01.c | 892 ++++++++ sound/usb/qcom/usb_audio_qmi_v01.h | 162 ++ 41 files changed, 5705 insertions(+), 29 deletions(-) create mode 100644 Documentation/sound/soc/usb.rst create mode 100644 include/sound/q6usboffload.h create mode 100644 include/sound/soc-usb.h create mode 100644 sound/soc/qcom/qdsp6/q6usb.c create mode 100644 sound/soc/qcom/usb_offload_utils.c create mode 100644 sound/soc/qcom/usb_offload_utils.h create mode 100644 sound/soc/soc-usb.c create mode 100644 sound/usb/qcom/Makefile create mode 100644 sound/usb/qcom/mixer_usb_offload.c create mode 100644 sound/usb/qcom/mixer_usb_offload.h create mode 100644 sound/usb/qcom/qc_audio_offload.c create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.c create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.h
Some platforms may have support for offloading USB audio devices to a dedicated audio DSP. Introduce a set of APIs that allow for management of USB sound card and PCM devices enumerated by the USB SND class driver. This allows for the ASoC components to be aware of what USB devices are available for offloading.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/soc-usb.h | 95 ++++++++++++++++++ sound/soc/Kconfig | 10 ++ sound/soc/Makefile | 2 + sound/soc/soc-usb.c | 217 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 324 insertions(+) create mode 100644 include/sound/soc-usb.h create mode 100644 sound/soc/soc-usb.c
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h new file mode 100644 index 000000000000..e8fe4439c234 --- /dev/null +++ b/include/sound/soc-usb.h @@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef __LINUX_SND_SOC_USB_H +#define __LINUX_SND_SOC_USB_H + +/** + * struct snd_soc_usb_device + * @card_idx - sound card index associated with USB device + * @chip_idx - USB sound chip array index + * @num_playback - number of playback streams + * @num_capture - number of capture streams + **/ +struct snd_soc_usb_device { + int card_idx; + int chip_idx; + int num_playback; + int num_capture; +}; + +/** + * struct snd_soc_usb + * @list - list head for SND SOC struct list + * @component - reference to ASoC component + * @num_supported_streams - number of supported concurrent sessions + * @connection_status_cb - callback to notify connection events + * @priv_data - driver data + **/ +struct snd_soc_usb { + struct list_head list; + struct snd_soc_component *component; + unsigned int num_supported_streams; + int (*connection_status_cb)(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected); + void *priv_data; +}; + +#if IS_ENABLED(CONFIG_SND_SOC_USB) +const char *snd_soc_usb_get_components_tag(bool playback); + +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 *dev); + +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_streams, void *data); +void snd_soc_usb_free_port(struct snd_soc_usb *usb); +void snd_soc_usb_add_port(struct snd_soc_usb *usb); +void snd_soc_usb_remove_port(struct snd_soc_usb *usb); +#else +static inline const char *snd_soc_usb_get_components_tag(bool playback) +{ + return ""; +} + +static inline int snd_soc_usb_connect(struct device *usbdev, + struct snd_soc_usb_device *sdev) +{ + return -ENODEV; +} + +static inline int snd_soc_usb_disconnect(struct device *usbdev, + struct snd_soc_usb_device *sdev) +{ + return -EINVAL; +} + +static inline void *snd_soc_usb_find_priv_data(struct device *dev) +{ + return NULL; +} + +static inline struct snd_soc_usb *snd_soc_usb_allocate_port( + struct snd_soc_component *component, + int num_streams, void *data) +{ + return ERR_PTR(-ENOMEM); +} + +static inline void snd_soc_usb_free_port(struct snd_soc_usb *usb) +{ } + +static inline void snd_soc_usb_add_port(struct snd_soc_usb *usb) +{ + return -EINVAL; +} + +static inline void snd_soc_usb_remove_port(struct snd_soc_usb *usb) +{ + return -ENODEV; +} +#endif /* IS_ENABLED(CONFIG_SND_SOC_USB) */ +#endif /*__LINUX_SND_SOC_USB_H */ diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig index a52afb423b46..c993705c8ac2 100644 --- a/sound/soc/Kconfig +++ b/sound/soc/Kconfig @@ -84,6 +84,16 @@ config SND_SOC_UTILS_KUNIT_TEST config SND_SOC_ACPI tristate
+config SND_SOC_USB + tristate "SoC based USB audio offloading" + depends on SND_USB_AUDIO + help + Enable this option if an ASoC platform card has support to handle + USB audio offloading. This enables the SoC USB layer, which will + notifies the ASoC USB DPCM backend DAI link about available USB audio + devices. Based on the notifications, sequences to enable the audio + stream can be taken based on the design. + # All the supported SoCs source "sound/soc/adi/Kconfig" source "sound/soc/amd/Kconfig" diff --git a/sound/soc/Makefile b/sound/soc/Makefile index fd61847dd1eb..adf9d9203778 100644 --- a/sound/soc/Makefile +++ b/sound/soc/Makefile @@ -35,6 +35,8 @@ endif
obj-$(CONFIG_SND_SOC_ACPI) += snd-soc-acpi.o
+obj-$(CONFIG_SND_SOC_USB) += soc-usb.o + obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ obj-$(CONFIG_SND_SOC) += generic/ diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c new file mode 100644 index 000000000000..8490715791a5 --- /dev/null +++ b/sound/soc/soc-usb.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#include <linux/of.h> +#include <linux/usb.h> +#include <sound/soc.h> +#include <sound/soc-usb.h> +#include "../usb/card.h" + +static DEFINE_MUTEX(ctx_mutex); +static LIST_HEAD(usb_ctx_list); + +static struct device_node *snd_soc_find_phandle(struct device *dev) +{ + struct device_node *node; + + node = of_parse_phandle(dev->of_node, "usb-soc-be", 0); + if (!node) + return ERR_PTR(-ENODEV); + + return node; +} + +static struct snd_soc_usb *snd_soc_usb_ctx_lookup(struct device_node *node) +{ + struct snd_soc_usb *ctx; + + if (!node) + return NULL; + + mutex_lock(&ctx_mutex); + list_for_each_entry(ctx, &usb_ctx_list, list) { + if (ctx->component->dev->of_node == node) { + mutex_unlock(&ctx_mutex); + return ctx; + } + } + mutex_unlock(&ctx_mutex); + + return NULL; +} + +static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev) +{ + struct snd_soc_usb *ctx; + struct device_node *node; + + node = snd_soc_find_phandle(dev); + if (!IS_ERR(node)) { + ctx = snd_soc_usb_ctx_lookup(node); + of_node_put(node); + } else { + ctx = snd_soc_usb_ctx_lookup(dev->of_node); + } + + return ctx ? ctx : NULL; +} + +/** + * snd_soc_usb_find_priv_data() - Retrieve private data stored + * @dev: device reference + * + * Fetch the private data stored in the USB SND SOC structure. + * + */ +void *snd_soc_usb_find_priv_data(struct device *dev) +{ + struct snd_soc_usb *ctx; + + ctx = snd_soc_find_usb_ctx(dev); + + return ctx ? ctx->priv_data : NULL; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data); + +/** + * snd_soc_usb_allocate_port() - allocate a SOC USB device + * @component: USB DPCM backend DAI component + * @num_streams: number of offloading sessions supported + * @data: private data + * + * Allocate and initialize a SOC USB device. This will populate parameters that + * are used in subsequent sequences. + * + */ +struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_streams, void *data) +{ + struct snd_soc_usb *usb; + + usb = kzalloc(sizeof(*usb), GFP_KERNEL); + if (!usb) + return ERR_PTR(-ENOMEM); + + usb->component = component; + usb->priv_data = data; + usb->num_supported_streams = num_streams; + + return usb; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_allocate_port); + +/** + * snd_soc_usb_free_port() - free a SOC USB device + * @usb: allocated SOC USB device + + * Free and remove the SOC USB device from the available list of devices. + * + */ +void snd_soc_usb_free_port(struct snd_soc_usb *usb) +{ + snd_soc_usb_remove_port(usb); + kfree(usb); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); + +/** + * snd_soc_usb_add_port() - Add a USB backend port + * @dev: USB backend device + * @priv: private data + * @connection_cb: connection status callback + * + * Register a USB backend device to the SND USB SOC framework. Memory is + * allocated as part of the USB backend device. + * + */ +void snd_soc_usb_add_port(struct snd_soc_usb *usb) +{ + mutex_lock(&ctx_mutex); + list_add_tail(&usb->list, &usb_ctx_list); + mutex_unlock(&ctx_mutex); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_add_port); + +/** + * snd_soc_usb_remove_port() - Remove a USB backend port + * @dev: USB backend device + * + * Remove a USB backend device from USB SND SOC. Memory is freed when USB + * backend is removed. + * + */ +void snd_soc_usb_remove_port(struct snd_soc_usb *usb) +{ + struct snd_soc_usb *ctx, *tmp; + + mutex_lock(&ctx_mutex); + list_for_each_entry_safe(ctx, tmp, &usb_ctx_list, list) { + if (ctx == usb) { + list_del(&ctx->list); + break; + } + } + mutex_unlock(&ctx_mutex); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port); + +/** + * snd_soc_usb_connect() - Notification of USB device connection + * @usbdev: USB bus device + * @card_idx: USB SND card instance + * + * Notify of a new USB SND device connection. The card_idx can be used to + * handle how the DPCM backend selects, which device to enable USB offloading + * on. + * + */ +int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev) +{ + struct snd_soc_usb *ctx; + + if (!usbdev) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(usbdev); + if (IS_ERR(ctx)) + return -ENODEV; + + mutex_lock(&ctx_mutex); + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, true); + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_connect); + +/** + * snd_soc_usb_disconnect() - Notification of USB device disconnection + * @usbdev: USB bus device + * + * Notify of a new USB SND device disconnection to the USB backend. + * + */ +int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev) +{ + struct snd_soc_usb *ctx; + + if (!usbdev) + return -ENODEV; + + ctx = snd_soc_find_usb_ctx(usbdev); + if (IS_ERR(ctx)) + return -ENODEV; + + mutex_lock(&ctx_mutex); + if (ctx->connection_status_cb) + ctx->connection_status_cb(ctx, sdev, false); + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_disconnect); + +MODULE_LICENSE("GPL"); +MODULE_DESCRIPTION("SoC USB driver for offloading");
Q6DSP supports handling of USB playback audio data if USB audio offloading is enabled. Add a new definition for the USB_RX AFE port, which is referenced when the AFE port is started.
Acked-by: Krzysztof Kozlowski krzysztof.kozlowski@linaro.org Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h | 1 + 1 file changed, 1 insertion(+)
diff --git a/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h b/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h index 39f203256c4f..6d1ce7f5da51 100644 --- a/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h +++ b/include/dt-bindings/sound/qcom,q6dsp-lpass-ports.h @@ -139,6 +139,7 @@ #define DISPLAY_PORT_RX_5 133 #define DISPLAY_PORT_RX_6 134 #define DISPLAY_PORT_RX_7 135 +#define USB_RX 136
#define LPASS_CLK_ID_PRI_MI2S_IBIT 1 #define LPASS_CLK_ID_PRI_MI2S_EBIT 2
The QC ADSP is able to support USB playback endpoints, so that the main application processor can be placed into lower CPU power modes. This adds the required AFE port configurations and port start command to start an audio session.
Specifically, the QC ADSP can support all potential endpoints that are exposed by the audio data interface. This includes, feedback endpoints (both implicit and explicit) as well as the isochronous (data) endpoints. The size of audio samples sent per USB frame (microframe) will be adjusted based on information received on the feedback endpoint.
Some pre-requisites are needed before issuing the AFE port start command, such as setting the USB AFE dev_token. This carries information about the available USB SND cards and PCM devices that have been discovered on the USB bus. The dev_token field is used by the audio DSP to notify the USB offload driver of which card and PCM index to enable playback on.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6afe-dai.c | 60 +++++++ sound/soc/qcom/qdsp6/q6afe.c | 191 ++++++++++++++++++++++- sound/soc/qcom/qdsp6/q6afe.h | 36 ++++- sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c | 23 +++ sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h | 1 + sound/soc/qcom/qdsp6/q6routing.c | 9 ++ 6 files changed, 318 insertions(+), 2 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6afe-dai.c b/sound/soc/qcom/qdsp6/q6afe-dai.c index a9c4f896a7df..80b22d1a24d0 100644 --- a/sound/soc/qcom/qdsp6/q6afe-dai.c +++ b/sound/soc/qcom/qdsp6/q6afe-dai.c @@ -92,6 +92,39 @@ static int q6hdmi_hw_params(struct snd_pcm_substream *substream, return 0; }
+static int q6afe_usb_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + struct q6afe_dai_data *dai_data = dev_get_drvdata(dai->dev); + int channels = params_channels(params); + int rate = params_rate(params); + struct q6afe_usb_cfg *usb = &dai_data->port_config[dai->id].usb_audio; + + usb->sample_rate = rate; + usb->num_channels = channels; + + switch (params_format(params)) { + case SNDRV_PCM_FORMAT_U16_LE: + case SNDRV_PCM_FORMAT_S16_LE: + usb->bit_width = 16; + break; + case SNDRV_PCM_FORMAT_S24_LE: + case SNDRV_PCM_FORMAT_S24_3LE: + usb->bit_width = 24; + break; + case SNDRV_PCM_FORMAT_S32_LE: + usb->bit_width = 32; + break; + default: + dev_err(dai->dev, "%s: invalid format %d\n", + __func__, params_format(params)); + return -EINVAL; + } + + return 0; +} + static int q6i2s_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) @@ -392,6 +425,10 @@ static int q6afe_dai_prepare(struct snd_pcm_substream *substream, q6afe_cdc_dma_port_prepare(dai_data->port[dai->id], &dai_data->port_config[dai->id].dma_cfg); break; + case USB_RX: + q6afe_usb_port_prepare(dai_data->port[dai->id], + &dai_data->port_config[dai->id].usb_audio); + break; default: return -EINVAL; } @@ -618,6 +655,9 @@ static const struct snd_soc_dapm_route q6afe_dapm_routes[] = { {"TX_CODEC_DMA_TX_5", NULL, "TX_CODEC_DMA_TX_5 Capture"}, {"RX_CODEC_DMA_RX_6 Playback", NULL, "RX_CODEC_DMA_RX_6"}, {"RX_CODEC_DMA_RX_7 Playback", NULL, "RX_CODEC_DMA_RX_7"}, + + /* USB playback AFE port receives data for playback, hence use the RX port */ + {"USB Playback", NULL, "USB_RX"}, };
static int msm_dai_q6_dai_probe(struct snd_soc_dai *dai) @@ -645,6 +685,23 @@ static int msm_dai_q6_dai_remove(struct snd_soc_dai *dai) return 0; }
+static const struct snd_soc_dai_ops q6afe_usb_ops = { + .probe = msm_dai_q6_dai_probe, + .prepare = q6afe_dai_prepare, + .hw_params = q6afe_usb_hw_params, + /* + * Shutdown callback required to stop the USB AFE port, which is enabled + * by the prepare() stage. This stops the audio traffic on the USB AFE + * port on the Q6DSP. + */ + .shutdown = q6afe_dai_shutdown, + /* + * Startup callback not needed, as AFE port start command passes the PCM + * parameters within the AFE command, which is provided by the PCM core + * during the prepare() stage. + */ +}; + static const struct snd_soc_dai_ops q6hdmi_ops = { .probe = msm_dai_q6_dai_probe, .remove = msm_dai_q6_dai_remove, @@ -943,6 +1000,8 @@ static const struct snd_soc_dapm_widget q6afe_dai_widgets[] = { 0, SND_SOC_NOPM, 0, 0), SND_SOC_DAPM_AIF_IN("RX_CODEC_DMA_RX_7", "NULL", 0, SND_SOC_NOPM, 0, 0), + + SND_SOC_DAPM_AIF_IN("USB_RX", NULL, 0, SND_SOC_NOPM, 0, 0), };
static const struct snd_soc_component_driver q6afe_dai_component = { @@ -1057,6 +1116,7 @@ static int q6afe_dai_dev_probe(struct platform_device *pdev) cfg.q6i2s_ops = &q6i2s_ops; cfg.q6tdm_ops = &q6tdm_ops; cfg.q6dma_ops = &q6dma_ops; + cfg.q6usb_ops = &q6afe_usb_ops; dais = q6dsp_audio_ports_set_config(dev, &cfg, &num_dais);
return devm_snd_soc_register_component(dev, &q6afe_dai_component, dais, num_dais); diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index ef7557be5d66..948007955934 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -35,6 +35,8 @@ #define AFE_MODULE_TDM 0x0001028A
#define AFE_PARAM_ID_CDC_SLIMBUS_SLAVE_CFG 0x00010235 +#define AFE_PARAM_ID_USB_AUDIO_DEV_PARAMS 0x000102A5 +#define AFE_PARAM_ID_USB_AUDIO_DEV_LPCM_FMT 0x000102AA
#define AFE_PARAM_ID_LPAIF_CLK_CONFIG 0x00010238 #define AFE_PARAM_ID_INT_DIGITAL_CDC_CLK_CONFIG 0x00010239 @@ -44,6 +46,7 @@ #define AFE_PARAM_ID_TDM_CONFIG 0x0001029D #define AFE_PARAM_ID_PORT_SLOT_MAPPING_CONFIG 0x00010297 #define AFE_PARAM_ID_CODEC_DMA_CONFIG 0x000102B8 +#define AFE_PARAM_ID_USB_AUDIO_CONFIG 0x000102A4 #define AFE_CMD_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f4 #define AFE_CMD_RSP_REMOTE_LPASS_CORE_HW_VOTE_REQUEST 0x000100f5 #define AFE_CMD_REMOTE_LPASS_CORE_HW_DEVOTE_REQUEST 0x000100f6 @@ -72,12 +75,16 @@ #define AFE_PORT_CONFIG_I2S_WS_SRC_INTERNAL 0x1 #define AFE_LINEAR_PCM_DATA 0x0
+#define AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG 0x1
/* Port IDs */ #define AFE_API_VERSION_HDMI_CONFIG 0x1 #define AFE_PORT_ID_MULTICHAN_HDMI_RX 0x100E #define AFE_PORT_ID_HDMI_OVER_DP_RX 0x6020
+/* USB AFE port */ +#define AFE_PORT_ID_USB_RX 0x7000 + #define AFE_API_VERSION_SLIMBUS_CONFIG 0x1 /* Clock set API version */ #define AFE_API_VERSION_CLOCK_SET 1 @@ -513,12 +520,96 @@ struct afe_param_id_cdc_dma_cfg { u16 active_channels_mask; } __packed;
+struct afe_param_id_usb_cfg { +/* Minor version used for tracking USB audio device configuration. + * Supported values: AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + */ + u32 cfg_minor_version; +/* Sampling rate of the port. + * Supported values: + * - AFE_PORT_SAMPLE_RATE_8K + * - AFE_PORT_SAMPLE_RATE_11025 + * - AFE_PORT_SAMPLE_RATE_12K + * - AFE_PORT_SAMPLE_RATE_16K + * - AFE_PORT_SAMPLE_RATE_22050 + * - AFE_PORT_SAMPLE_RATE_24K + * - AFE_PORT_SAMPLE_RATE_32K + * - AFE_PORT_SAMPLE_RATE_44P1K + * - AFE_PORT_SAMPLE_RATE_48K + * - AFE_PORT_SAMPLE_RATE_96K + * - AFE_PORT_SAMPLE_RATE_192K + */ + u32 sample_rate; +/* Bit width of the sample. + * Supported values: 16, 24 + */ + u16 bit_width; +/* Number of channels. + * Supported values: 1 and 2 + */ + u16 num_channels; +/* Data format supported by the USB. The supported value is + * 0 (#AFE_USB_AUDIO_DATA_FORMAT_LINEAR_PCM). + */ + u16 data_format; +/* this field must be 0 */ + u16 reserved; +/* device token of actual end USB audio device */ + u32 dev_token; +/* endianness of this interface */ + u32 endian; +/* service interval */ + u32 service_interval; +} __packed; + +/** + * struct afe_param_id_usb_audio_dev_params + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @dev_token: device token of actual end USB audio device + **/ +struct afe_param_id_usb_audio_dev_params { + u32 cfg_minor_version; + u32 dev_token; +} __packed; + +/** + * struct afe_param_id_usb_audio_dev_lpcm_fmt + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @endian: endianness of this interface + **/ +struct afe_param_id_usb_audio_dev_lpcm_fmt { + u32 cfg_minor_version; + u32 endian; +} __packed; + +#define AFE_PARAM_ID_USB_AUDIO_SVC_INTERVAL 0x000102B7 + +/** + * struct afe_param_id_usb_audio_svc_interval + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @svc_interval: service interval + **/ +struct afe_param_id_usb_audio_svc_interval { + u32 cfg_minor_version; + u32 svc_interval; +} __packed; + union afe_port_config { struct afe_param_id_hdmi_multi_chan_audio_cfg hdmi_multi_ch; struct afe_param_id_slimbus_cfg slim_cfg; struct afe_param_id_i2s_cfg i2s_cfg; struct afe_param_id_tdm_cfg tdm_cfg; struct afe_param_id_cdc_dma_cfg dma_cfg; + struct afe_param_id_usb_cfg usb_cfg; } __packed;
@@ -833,6 +924,7 @@ static struct afe_port_map port_maps[AFE_PORT_MAX] = { RX_CODEC_DMA_RX_6, 1, 1}, [RX_CODEC_DMA_RX_7] = { AFE_PORT_ID_RX_CODEC_DMA_RX_7, RX_CODEC_DMA_RX_7, 1, 1}, + [USB_RX] = { AFE_PORT_ID_USB_RX, USB_RX, 1, 1}, };
static void q6afe_port_free(struct kref *ref) @@ -1290,6 +1382,100 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, } EXPORT_SYMBOL_GPL(q6afe_tdm_port_prepare);
+/** + * afe_port_send_usb_dev_param() - Send USB dev token + * + * @port: Instance of afe port + * @cardidx: USB SND card index to reference + * @pcmidx: USB SND PCM device index to reference + * + * The USB dev token carries information about which USB SND card instance and + * PCM device to execute the offload on. This information is carried through + * to the stream enable QMI request, which is handled by the offload class + * driver. The information is parsed to determine which USB device to query + * the required resources for. + */ +int afe_port_send_usb_dev_param(struct q6afe_port *port, int cardidx, int pcmidx) +{ + struct afe_param_id_usb_audio_dev_params usb_dev; + int ret; + + memset(&usb_dev, 0, sizeof(usb_dev)); + + usb_dev.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + usb_dev.dev_token = (cardidx << 16) | (pcmidx << 8); + ret = q6afe_port_set_param_v2(port, &usb_dev, + AFE_PARAM_ID_USB_AUDIO_DEV_PARAMS, + AFE_MODULE_AUDIO_DEV_INTERFACE, sizeof(usb_dev)); + if (ret) + dev_err(port->afe->dev, "%s: AFE device param cmd failed %d\n", + __func__, ret); + + return ret; +} +EXPORT_SYMBOL_GPL(afe_port_send_usb_dev_param); + +static int afe_port_send_usb_params(struct q6afe_port *port, struct q6afe_usb_cfg *cfg) +{ + union afe_port_config *pcfg = &port->port_cfg; + struct afe_param_id_usb_audio_dev_lpcm_fmt lpcm_fmt; + struct afe_param_id_usb_audio_svc_interval svc_int; + int ret; + + if (!pcfg) { + dev_err(port->afe->dev, "%s: Error, no configuration data\n", __func__); + ret = -EINVAL; + goto exit; + } + + memset(&lpcm_fmt, 0, sizeof(lpcm_fmt)); + memset(&svc_int, 0, sizeof(svc_int)); + + lpcm_fmt.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + lpcm_fmt.endian = pcfg->usb_cfg.endian; + ret = q6afe_port_set_param_v2(port, &lpcm_fmt, + AFE_PARAM_ID_USB_AUDIO_DEV_LPCM_FMT, + AFE_MODULE_AUDIO_DEV_INTERFACE, sizeof(lpcm_fmt)); + if (ret) { + dev_err(port->afe->dev, "%s: AFE device param cmd LPCM_FMT failed %d\n", + __func__, ret); + goto exit; + } + + svc_int.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + svc_int.svc_interval = pcfg->usb_cfg.service_interval; + ret = q6afe_port_set_param_v2(port, &svc_int, + AFE_PARAM_ID_USB_AUDIO_SVC_INTERVAL, + AFE_MODULE_AUDIO_DEV_INTERFACE, sizeof(svc_int)); + if (ret) + dev_err(port->afe->dev, "%s: AFE device param cmd svc_interval failed %d\n", + __func__, ret); + +exit: + return ret; +} + +/** + * q6afe_usb_port_prepare() - Prepare usb afe port. + * + * @port: Instance of afe port + * @cfg: USB configuration for the afe port + * + */ +void q6afe_usb_port_prepare(struct q6afe_port *port, + struct q6afe_usb_cfg *cfg) +{ + union afe_port_config *pcfg = &port->port_cfg; + + pcfg->usb_cfg.cfg_minor_version = AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG; + pcfg->usb_cfg.sample_rate = cfg->sample_rate; + pcfg->usb_cfg.num_channels = cfg->num_channels; + pcfg->usb_cfg.bit_width = cfg->bit_width; + + afe_port_send_usb_params(port, cfg); +} +EXPORT_SYMBOL_GPL(q6afe_usb_port_prepare); + /** * q6afe_hdmi_port_prepare() - Prepare hdmi afe port. * @@ -1612,7 +1798,10 @@ struct q6afe_port *q6afe_port_get_from_id(struct device *dev, int id) break; case AFE_PORT_ID_WSA_CODEC_DMA_RX_0 ... AFE_PORT_ID_RX_CODEC_DMA_RX_7: cfg_type = AFE_PARAM_ID_CODEC_DMA_CONFIG; - break; + break; + case AFE_PORT_ID_USB_RX: + cfg_type = AFE_PARAM_ID_USB_AUDIO_CONFIG; + break; default: dev_err(dev, "Invalid port id 0x%x\n", port_id); return ERR_PTR(-EINVAL); diff --git a/sound/soc/qcom/qdsp6/q6afe.h b/sound/soc/qcom/qdsp6/q6afe.h index 65d0676075e1..04c70f904b86 100644 --- a/sound/soc/qcom/qdsp6/q6afe.h +++ b/sound/soc/qcom/qdsp6/q6afe.h @@ -3,7 +3,7 @@ #ifndef __Q6AFE_H__ #define __Q6AFE_H__
-#define AFE_PORT_MAX 129 +#define AFE_PORT_MAX 137
#define MSM_AFE_PORT_TYPE_RX 0 #define MSM_AFE_PORT_TYPE_TX 1 @@ -203,6 +203,36 @@ struct q6afe_cdc_dma_cfg { u16 active_channels_mask; };
+/** + * struct q6afe_usb_cfg + * @cfg_minor_version: Minor version used for tracking USB audio device + * configuration. + * Supported values: + * AFE_API_MINOR_VERSION_USB_AUDIO_CONFIG + * @sample_rate: Sampling rate of the port + * Supported values: + * AFE_PORT_SAMPLE_RATE_8K + * AFE_PORT_SAMPLE_RATE_11025 + * AFE_PORT_SAMPLE_RATE_12K + * AFE_PORT_SAMPLE_RATE_16K + * AFE_PORT_SAMPLE_RATE_22050 + * AFE_PORT_SAMPLE_RATE_24K + * AFE_PORT_SAMPLE_RATE_32K + * AFE_PORT_SAMPLE_RATE_44P1K + * AFE_PORT_SAMPLE_RATE_48K + * AFE_PORT_SAMPLE_RATE_96K + * AFE_PORT_SAMPLE_RATE_192K + * @bit_width: Bit width of the sample. + * Supported values: 16, 24 + * @num_channels: Number of channels + * Supported values: 1, 2 + **/ +struct q6afe_usb_cfg { + u32 cfg_minor_version; + u32 sample_rate; + u16 bit_width; + u16 num_channels; +};
struct q6afe_port_config { struct q6afe_hdmi_cfg hdmi; @@ -210,6 +240,7 @@ struct q6afe_port_config { struct q6afe_i2s_cfg i2s_cfg; struct q6afe_tdm_cfg tdm; struct q6afe_cdc_dma_cfg dma_cfg; + struct q6afe_usb_cfg usb_audio; };
struct q6afe_port; @@ -219,6 +250,8 @@ int q6afe_port_start(struct q6afe_port *port); int q6afe_port_stop(struct q6afe_port *port); void q6afe_port_put(struct q6afe_port *port); int q6afe_get_port_id(int index); +void q6afe_usb_port_prepare(struct q6afe_port *port, + struct q6afe_usb_cfg *cfg); void q6afe_hdmi_port_prepare(struct q6afe_port *port, struct q6afe_hdmi_cfg *cfg); void q6afe_slim_port_prepare(struct q6afe_port *port, @@ -228,6 +261,7 @@ void q6afe_tdm_port_prepare(struct q6afe_port *port, struct q6afe_tdm_cfg *cfg); void q6afe_cdc_dma_port_prepare(struct q6afe_port *port, struct q6afe_cdc_dma_cfg *cfg);
+int afe_port_send_usb_dev_param(struct q6afe_port *port, int cardidx, int pcmidx); int q6afe_port_set_sysclk(struct q6afe_port *port, int clk_id, int clk_src, int clk_root, unsigned int freq, int dir); diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c index 4919001de08b..4a96b11f7fd1 100644 --- a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c +++ b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.c @@ -97,6 +97,26 @@ }
static struct snd_soc_dai_driver q6dsp_audio_fe_dais[] = { + { + .playback = { + .stream_name = "USB Playback", + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, + .channels_min = 1, + .channels_max = 2, + .rate_min = 8000, + .rate_max = 192000, + }, + .id = USB_RX, + .name = "USB_RX", + }, { .playback = { .stream_name = "HDMI Playback", @@ -624,6 +644,9 @@ struct snd_soc_dai_driver *q6dsp_audio_ports_set_config(struct device *dev, case WSA_CODEC_DMA_RX_0 ... RX_CODEC_DMA_RX_7: q6dsp_audio_fe_dais[i].ops = cfg->q6dma_ops; break; + case USB_RX: + q6dsp_audio_fe_dais[i].ops = cfg->q6usb_ops; + break; default: break; } diff --git a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h index 7f052c8a1257..d8dde6dd0aca 100644 --- a/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h +++ b/sound/soc/qcom/qdsp6/q6dsp-lpass-ports.h @@ -11,6 +11,7 @@ struct q6dsp_audio_port_dai_driver_config { const struct snd_soc_dai_ops *q6i2s_ops; const struct snd_soc_dai_ops *q6tdm_ops; const struct snd_soc_dai_ops *q6dma_ops; + const struct snd_soc_dai_ops *q6usb_ops; };
struct snd_soc_dai_driver *q6dsp_audio_ports_set_config(struct device *dev, diff --git a/sound/soc/qcom/qdsp6/q6routing.c b/sound/soc/qcom/qdsp6/q6routing.c index 81fde0681f95..45811f0f0d44 100644 --- a/sound/soc/qcom/qdsp6/q6routing.c +++ b/sound/soc/qcom/qdsp6/q6routing.c @@ -515,6 +515,9 @@ static int msm_routing_put_audio_mixer(struct snd_kcontrol *kcontrol, return 1; }
+static const struct snd_kcontrol_new usb_mixer_controls[] = { + Q6ROUTING_RX_MIXERS(USB_RX) }; + static const struct snd_kcontrol_new hdmi_mixer_controls[] = { Q6ROUTING_RX_MIXERS(HDMI_RX) };
@@ -950,6 +953,10 @@ static const struct snd_soc_dapm_widget msm_qdsp6_widgets[] = { SND_SOC_DAPM_MIXER("MultiMedia8 Mixer", SND_SOC_NOPM, 0, 0, mmul8_mixer_controls, ARRAY_SIZE(mmul8_mixer_controls)),
+ SND_SOC_DAPM_MIXER("USB Mixer", SND_SOC_NOPM, 0, 0, + usb_mixer_controls, + ARRAY_SIZE(usb_mixer_controls)), + };
static const struct snd_soc_dapm_route intercon[] = { @@ -1043,6 +1050,8 @@ static const struct snd_soc_dapm_route intercon[] = { {"MM_UL6", NULL, "MultiMedia6 Mixer"}, {"MM_UL7", NULL, "MultiMedia7 Mixer"}, {"MM_UL8", NULL, "MultiMedia8 Mixer"}, + + Q6ROUTING_RX_DAPM_ROUTE("USB Mixer", "USB_RX"), };
static int routing_hw_params(struct snd_soc_component *component,
For USB offloading situations, the AFE port start command will result in a QMI handshake between the Q6DSP and the main processor. Depending on if the USB bus is suspended, this routine would require more time to complete, as resuming the USB bus has some overhead associated with it. Increase the timeout to 3s to allow for sufficient time for the USB QMI stream enable handshake to complete.
Reviewed-by: Srinivas Kandagatla srinivas.kandagatla@linaro.org Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6afe.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/sound/soc/qcom/qdsp6/q6afe.c b/sound/soc/qcom/qdsp6/q6afe.c index 948007955934..452d7e8b9b30 100644 --- a/sound/soc/qcom/qdsp6/q6afe.c +++ b/sound/soc/qcom/qdsp6/q6afe.c @@ -366,7 +366,7 @@ #define AFE_API_VERSION_SLOT_MAPPING_CONFIG 1 #define AFE_API_VERSION_CODEC_DMA_CONFIG 1
-#define TIMEOUT_MS 1000 +#define TIMEOUT_MS 3000 #define AFE_CMD_RESP_AVAIL 0 #define AFE_CMD_RESP_NONE 1 #define AFE_CLK_TOKEN 1024
Create a USB BE component that will register a new USB port to the ASoC USB framework. This will handle determination on if the requested audio profile is supported by the USB device currently selected.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/q6usboffload.h | 20 ++++ sound/soc/qcom/Kconfig | 10 ++ sound/soc/qcom/qdsp6/Makefile | 1 + sound/soc/qcom/qdsp6/q6usb.c | 207 ++++++++++++++++++++++++++++++++++ 4 files changed, 238 insertions(+) create mode 100644 include/sound/q6usboffload.h create mode 100644 sound/soc/qcom/qdsp6/q6usb.c
diff --git a/include/sound/q6usboffload.h b/include/sound/q6usboffload.h new file mode 100644 index 000000000000..fdc1f5c53a3b --- /dev/null +++ b/include/sound/q6usboffload.h @@ -0,0 +1,20 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * linux/sound/q6usboffload.h -- QDSP6 USB offload + * + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +/** + * struct q6usb_offload + * @dev - dev handle to usb be + * @sid - streamID for iommu + * @intr_num - usb interrupter number + * @domain - allocated iommu domain + **/ +struct q6usb_offload { + struct device *dev; + long long sid; + u16 intr_num; + struct iommu_domain *domain; +}; diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index 762491d6f2f2..a1beafe2b1dd 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -118,6 +118,16 @@ config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS
+config SND_SOC_QDSP6_USB + tristate "SoC ALSA USB offloading backing for QDSP6" + depends on SND_SOC_USB + help + Adds support for USB offloading for QDSP6 ASoC + based platform sound cards. This will enable the + Q6USB DPCM backend DAI link, which will interact + with the SoC USB framework to initialize a session + with active USB SND devices. + config SND_SOC_QDSP6 tristate "SoC ALSA audio driver for QDSP6" depends on QCOM_APR diff --git a/sound/soc/qcom/qdsp6/Makefile b/sound/soc/qcom/qdsp6/Makefile index 26b7c55c9c11..67267304e7e9 100644 --- a/sound/soc/qcom/qdsp6/Makefile +++ b/sound/soc/qcom/qdsp6/Makefile @@ -17,3 +17,4 @@ obj-$(CONFIG_SND_SOC_QDSP6_APM_DAI) += q6apm-dai.o obj-$(CONFIG_SND_SOC_QDSP6_APM_LPASS_DAI) += q6apm-lpass-dais.o obj-$(CONFIG_SND_SOC_QDSP6_PRM) += q6prm.o obj-$(CONFIG_SND_SOC_QDSP6_PRM_LPASS_CLOCKS) += q6prm-clocks.o +obj-$(CONFIG_SND_SOC_QDSP6_USB) += q6usb.o diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c new file mode 100644 index 000000000000..aa36f490ed47 --- /dev/null +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -0,0 +1,207 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/device.h> +#include <linux/dma-mapping.h> +#include <linux/dma-map-ops.h> +#include <linux/err.h> +#include <linux/init.h> +#include <linux/iommu.h> +#include <linux/module.h> +#include <linux/platform_device.h> +#include <linux/slab.h> + +#include <sound/asound.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/q6usboffload.h> +#include <sound/soc.h> +#include <sound/soc-usb.h> + +#include <dt-bindings/sound/qcom,q6afe.h> + +#include "q6afe.h" +#include "q6dsp-lpass-ports.h" + +#define Q6_USB_SID_MASK 0xF + +struct q6usb_port_data { + struct q6afe_usb_cfg usb_cfg; + struct snd_soc_usb *usb; + struct q6usb_offload priv; + int active_usb_chip_idx; +}; + +static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { + SND_SOC_DAPM_HP("USB_RX_BE", NULL), +}; + +static const struct snd_soc_dapm_route q6usb_dapm_routes[] = { + {"USB Playback", NULL, "USB_RX_BE"}, +}; + +static int q6usb_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *params, + struct snd_soc_dai *dai) +{ + return 0; +} + +static const struct snd_soc_dai_ops q6usb_ops = { + .hw_params = q6usb_hw_params, +}; + +static struct snd_soc_dai_driver q6usb_be_dais[] = { + { + .playback = { + .stream_name = "USB BE RX", + .rates = SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 | + SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | + SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | + SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_96000 | + SNDRV_PCM_RATE_192000, + .formats = SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE | + SNDRV_PCM_FMTBIT_U16_LE | SNDRV_PCM_FMTBIT_U16_BE | + SNDRV_PCM_FMTBIT_S24_LE | SNDRV_PCM_FMTBIT_S24_BE | + SNDRV_PCM_FMTBIT_U24_LE | SNDRV_PCM_FMTBIT_U24_BE, + .channels_min = 1, + .channels_max = 2, + .rate_max = 192000, + .rate_min = 8000, + }, + .id = USB_RX, + .name = "USB_RX_BE", + .ops = &q6usb_ops, + }, +}; + +static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, + const struct of_phandle_args *args, + const char **dai_name) +{ + int id = args->args[0]; + int ret = -EINVAL; + int i; + + for (i = 0; i < ARRAY_SIZE(q6usb_be_dais); i++) { + if (q6usb_be_dais[i].id == id) { + *dai_name = q6usb_be_dais[i].name; + ret = 0; + break; + } + } + + return ret; +} + +static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, + struct snd_soc_usb_device *sdev, bool connected) +{ + struct q6usb_port_data *data; + + if (!usb->component) + return -ENODEV; + + data = dev_get_drvdata(usb->component->dev); + + if (connected) { + /* Selects the latest USB headset plugged in for offloading */ + data->active_usb_chip_idx = sdev->card_idx; + } + + return 0; +} + +static int q6usb_component_probe(struct snd_soc_component *component) +{ + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + struct snd_soc_usb *usb; + + usb = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + + snd_soc_usb_add_port(usb); + data->usb = usb; + + return 0; +} + +static void q6usb_component_remove(struct snd_soc_component *component) +{ + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + + snd_soc_usb_remove_port(data->usb); + snd_soc_usb_free_port(data->usb); +} + +static const struct snd_soc_component_driver q6usb_dai_component = { + .probe = q6usb_component_probe, + .remove = q6usb_component_remove, + .name = "q6usb-dai-component", + .dapm_widgets = q6usb_dai_widgets, + .num_dapm_widgets = ARRAY_SIZE(q6usb_dai_widgets), + .dapm_routes = q6usb_dapm_routes, + .num_dapm_routes = ARRAY_SIZE(q6usb_dapm_routes), + .of_xlate_dai_name = q6usb_audio_ports_of_xlate_dai_name, +}; + +static int q6usb_dai_dev_probe(struct platform_device *pdev) +{ + struct device_node *node = pdev->dev.of_node; + struct q6usb_port_data *data; + struct device *dev = &pdev->dev; + struct of_phandle_args args; + int ret; + + data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL); + if (!data) + return -ENOMEM; + + ret = of_property_read_u16(node, "qcom,usb-audio-intr-idx", + &data->priv.intr_num); + if (ret) { + dev_err(&pdev->dev, "failed to read intr idx.\n"); + return ret; + } + + ret = of_parse_phandle_with_fixed_args(node, "iommus", 1, 0, &args); + if (ret < 0) + data->priv.sid = -1; + else + data->priv.sid = args.args[0] & Q6_USB_SID_MASK; + + data->priv.domain = iommu_get_domain_for_dev(&pdev->dev); + + data->priv.dev = dev; + dev_set_drvdata(dev, data); + + return devm_snd_soc_register_component(dev, &q6usb_dai_component, + q6usb_be_dais, ARRAY_SIZE(q6usb_be_dais)); +} + +static const struct of_device_id q6usb_dai_device_id[] = { + { .compatible = "qcom,q6usb" }, + {}, +}; +MODULE_DEVICE_TABLE(of, q6usb_dai_device_id); + +static struct platform_driver q6usb_dai_platform_driver = { + .driver = { + .name = "q6usb-dai", + .of_match_table = of_match_ptr(q6usb_dai_device_id), + }, + .probe = q6usb_dai_dev_probe, + /* + * Remove not required as resources are cleaned up as part of + * component removal. Others are device managed resources. + */ +}; +module_platform_driver(q6usb_dai_platform_driver); + +MODULE_DESCRIPTION("Q6 USB backend dai driver"); +MODULE_LICENSE("GPL");
Allow for different platforms to be notified on USB SND connect/disconnect seqeunces. This allows for platform USB SND modules to properly initialize and populate internal structures with references to the USB SND chip device.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++++ sound/usb/card.h | 9 ++++++++ 2 files changed, 62 insertions(+)
diff --git a/sound/usb/card.c b/sound/usb/card.c index bdb04fa37a71..bb98ea45d1d7 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -118,6 +118,42 @@ MODULE_PARM_DESC(skip_validation, "Skip unit descriptor validation (default: no) static DEFINE_MUTEX(register_mutex); static struct snd_usb_audio *usb_chip[SNDRV_CARDS]; static struct usb_driver usb_audio_driver; +static struct snd_usb_platform_ops *platform_ops; + +/* + * Register platform specific operations that will be notified on events + * which occur in USB SND. The platform driver can utilize this path to + * enable features, such as USB audio offloading, which allows for audio data + * to be queued by an audio DSP. + * + * Only one set of platform operations can be registered to USB SND. The + * platform register operation is protected by the register_mutex. + */ +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops) +{ + guard(mutex)(®ister_mutex); + if (platform_ops) + return -EEXIST; + + platform_ops = ops; + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_register_platform_ops); + +/* + * Unregisters the current set of platform operations. This allows for + * a new set to be registered if required. + * + * The platform unregister operation is protected by the register_mutex. + */ +int snd_usb_unregister_platform_ops(void) +{ + guard(mutex)(®ister_mutex); + platform_ops = NULL; + + return 0; +} +EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops);
/* * disconnect streams @@ -914,7 +950,11 @@ static int usb_audio_probe(struct usb_interface *intf, chip->num_interfaces++; usb_set_intfdata(intf, chip); atomic_dec(&chip->active); + + if (platform_ops && platform_ops->connect_cb) + platform_ops->connect_cb(chip); mutex_unlock(®ister_mutex); + return 0;
__error: @@ -951,6 +991,9 @@ static void usb_audio_disconnect(struct usb_interface *intf) card = chip->card;
mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->disconnect_cb) + platform_ops->disconnect_cb(chip); + if (atomic_inc_return(&chip->shutdown) == 1) { struct snd_usb_stream *as; struct snd_usb_endpoint *ep; @@ -1094,6 +1137,11 @@ static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) chip->system_suspend = chip->num_suspended_intf; }
+ mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->suspend_cb) + platform_ops->suspend_cb(intf, message); + mutex_unlock(®ister_mutex); + return 0; }
@@ -1134,6 +1182,11 @@ static int usb_audio_resume(struct usb_interface *intf)
snd_usb_midi_v2_resume_all(chip);
+ mutex_lock(®ister_mutex); + if (platform_ops && platform_ops->resume_cb) + platform_ops->resume_cb(intf); + mutex_unlock(®ister_mutex); + out: if (chip->num_suspended_intf == chip->system_suspend) { snd_power_change_state(chip->card, SNDRV_CTL_POWER_D0); diff --git a/sound/usb/card.h b/sound/usb/card.h index 6ec95b2edf86..2884912adc96 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -207,4 +207,13 @@ struct snd_usb_stream { struct list_head list; };
+struct snd_usb_platform_ops { + void (*connect_cb)(struct snd_usb_audio *chip); + void (*disconnect_cb)(struct snd_usb_audio *chip); + void (*suspend_cb)(struct usb_interface *intf, pm_message_t message); + void (*resume_cb)(struct usb_interface *intf); +}; + +int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); +int snd_usb_unregister_platform_ops(void); #endif /* __USBAUDIO_CARD_H */
Some vendor modules will utilize useful parsing and endpoint management APIs to start audio playback/capture.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.c | 4 +++ sound/usb/endpoint.c | 1 + sound/usb/helper.c | 1 + sound/usb/pcm.c | 75 +++++++++++++++++++++++++++++++------------- sound/usb/pcm.h | 11 +++++++ 5 files changed, 71 insertions(+), 21 deletions(-)
diff --git a/sound/usb/card.c b/sound/usb/card.c index bb98ea45d1d7..8f1051e1716e 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -1065,6 +1065,7 @@ int snd_usb_lock_shutdown(struct snd_usb_audio *chip) wake_up(&chip->shutdown_wait); return err; } +EXPORT_SYMBOL_GPL(snd_usb_lock_shutdown);
/* autosuspend and unlock the shutdown */ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) @@ -1073,6 +1074,7 @@ void snd_usb_unlock_shutdown(struct snd_usb_audio *chip) if (atomic_dec_and_test(&chip->usage_count)) wake_up(&chip->shutdown_wait); } +EXPORT_SYMBOL_GPL(snd_usb_unlock_shutdown);
int snd_usb_autoresume(struct snd_usb_audio *chip) { @@ -1095,6 +1097,7 @@ int snd_usb_autoresume(struct snd_usb_audio *chip) } return 0; } +EXPORT_SYMBOL_GPL(snd_usb_autoresume);
void snd_usb_autosuspend(struct snd_usb_audio *chip) { @@ -1108,6 +1111,7 @@ void snd_usb_autosuspend(struct snd_usb_audio *chip) for (i = 0; i < chip->num_interfaces; i++) usb_autopm_put_interface(chip->intf[i]); } +EXPORT_SYMBOL_GPL(snd_usb_autosuspend);
static int usb_audio_suspend(struct usb_interface *intf, pm_message_t message) { diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c index 8f65349a06d3..9876abb80853 100644 --- a/sound/usb/endpoint.c +++ b/sound/usb/endpoint.c @@ -1513,6 +1513,7 @@ int snd_usb_endpoint_prepare(struct snd_usb_audio *chip, mutex_unlock(&chip->mutex); return err; } +EXPORT_SYMBOL_GPL(snd_usb_endpoint_prepare);
/* get the current rate set to the given clock by any endpoint */ int snd_usb_endpoint_get_clock_rate(struct snd_usb_audio *chip, int clock) diff --git a/sound/usb/helper.c b/sound/usb/helper.c index bf80e55d013a..4322ae3738e6 100644 --- a/sound/usb/helper.c +++ b/sound/usb/helper.c @@ -62,6 +62,7 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype } return NULL; } +EXPORT_SYMBOL_GPL(snd_usb_find_csint_desc);
/* * Wrapper for usb_control_msg(). diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 08bf535ed163..3adb09ce1702 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -148,6 +148,16 @@ find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, return found; }
+const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, + unsigned int rate, unsigned int channels, bool strict_match, + struct snd_usb_substream *subs) +{ + return find_format(fmt_list_head, format, rate, channels, strict_match, + subs); +} +EXPORT_SYMBOL_GPL(snd_usb_find_format); + static const struct audioformat * find_substream_format(struct snd_usb_substream *subs, const struct snd_pcm_hw_params *params) @@ -157,6 +167,14 @@ find_substream_format(struct snd_usb_substream *subs, true, subs); }
+const struct audioformat * +snd_usb_find_substream_format(struct snd_usb_substream *subs, + const struct snd_pcm_hw_params *params) +{ + return find_substream_format(subs, params); +} +EXPORT_SYMBOL_GPL(snd_usb_find_substream_format); + bool snd_usb_pcm_has_fixed_rate(struct snd_usb_substream *subs) { const struct audioformat *fp; @@ -461,20 +479,9 @@ static void close_endpoints(struct snd_usb_audio *chip, } }
-/* - * hw_params callback - * - * allocate a buffer and set the given audio format. - * - * so far we use a physically linear buffer although packetize transfer - * doesn't need a continuous area. - * if sg buffer is supported on the later version of alsa, we'll follow - * that. - */ -static int snd_usb_hw_params(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *hw_params) +int snd_usb_hw_params(struct snd_usb_substream *subs, + struct snd_pcm_hw_params *hw_params) { - struct snd_usb_substream *subs = substream->runtime->private_data; struct snd_usb_audio *chip = subs->stream->chip; const struct audioformat *fmt; const struct audioformat *sync_fmt; @@ -499,7 +506,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream, if (fmt->implicit_fb) { sync_fmt = snd_usb_find_implicit_fb_sync_format(chip, fmt, hw_params, - !substream->stream, + !subs->direction, &sync_fixed_rate); if (!sync_fmt) { usb_audio_dbg(chip, @@ -579,15 +586,28 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
return ret; } +EXPORT_SYMBOL_GPL(snd_usb_hw_params);
/* - * hw_free callback + * hw_params callback * - * reset the audio format and release the buffer + * allocate a buffer and set the given audio format. + * + * so far we use a physically linear buffer although packetize transfer + * doesn't need a continuous area. + * if sg buffer is supported on the later version of alsa, we'll follow + * that. */ -static int snd_usb_hw_free(struct snd_pcm_substream *substream) +static int snd_usb_pcm_hw_params(struct snd_pcm_substream *substream, + struct snd_pcm_hw_params *hw_params) { struct snd_usb_substream *subs = substream->runtime->private_data; + + return snd_usb_hw_params(subs, hw_params); +} + +int snd_usb_hw_free(struct snd_usb_substream *subs) +{ struct snd_usb_audio *chip = subs->stream->chip;
snd_media_stop_pipeline(subs); @@ -603,6 +623,19 @@ static int snd_usb_hw_free(struct snd_pcm_substream *substream)
return 0; } +EXPORT_SYMBOL_GPL(snd_usb_hw_free); + +/* + * hw_free callback + * + * reset the audio format and release the buffer + */ +static int snd_usb_pcm_hw_free(struct snd_pcm_substream *substream) +{ + struct snd_usb_substream *subs = substream->runtime->private_data; + + return snd_usb_hw_free(subs); +}
/* free-wheeling mode? (e.g. dmix) */ static int in_free_wheeling_mode(struct snd_pcm_runtime *runtime) @@ -1746,8 +1779,8 @@ static int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream static const struct snd_pcm_ops snd_usb_playback_ops = { .open = snd_usb_pcm_open, .close = snd_usb_pcm_close, - .hw_params = snd_usb_hw_params, - .hw_free = snd_usb_hw_free, + .hw_params = snd_usb_pcm_hw_params, + .hw_free = snd_usb_pcm_hw_free, .prepare = snd_usb_pcm_prepare, .trigger = snd_usb_substream_playback_trigger, .sync_stop = snd_usb_pcm_sync_stop, @@ -1758,8 +1791,8 @@ static const struct snd_pcm_ops snd_usb_playback_ops = { static const struct snd_pcm_ops snd_usb_capture_ops = { .open = snd_usb_pcm_open, .close = snd_usb_pcm_close, - .hw_params = snd_usb_hw_params, - .hw_free = snd_usb_hw_free, + .hw_params = snd_usb_pcm_hw_params, + .hw_free = snd_usb_pcm_hw_free, .prepare = snd_usb_pcm_prepare, .trigger = snd_usb_substream_capture_trigger, .sync_stop = snd_usb_pcm_sync_stop, diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h index 388fe2ba346d..be2dd9478982 100644 --- a/sound/usb/pcm.h +++ b/sound/usb/pcm.h @@ -15,4 +15,15 @@ void snd_usb_preallocate_buffer(struct snd_usb_substream *subs); int snd_usb_audioformat_set_sync_ep(struct snd_usb_audio *chip, struct audioformat *fmt);
+const struct audioformat * +snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t format, + unsigned int rate, unsigned int channels, bool strict_match, + struct snd_usb_substream *subs); +const struct audioformat * +snd_usb_find_substream_format(struct snd_usb_substream *subs, + const struct snd_pcm_hw_params *params); + +int snd_usb_hw_params(struct snd_usb_substream *subs, + struct snd_pcm_hw_params *hw_params); +int snd_usb_hw_free(struct snd_usb_substream *subs); #endif /* __USBAUDIO_PCM_H */
Within the UAC descriptor, there is information describing the size of a sample (bSubframeSize/bSubslotSize) and the number of relevant bits (bBitResolution). Currently, fmt_bits carries only the bit resolution, however, some offloading entities may also require the overall size of the sample. Save this information in a separate parameter, as depending on the UAC format type, the sample size can not easily be decoded from other exisiting parameters.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.h | 1 + sound/usb/format.c | 1 + 2 files changed, 2 insertions(+)
diff --git a/sound/usb/card.h b/sound/usb/card.h index 2884912adc96..02e4ea898db5 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -15,6 +15,7 @@ struct audioformat { unsigned int channels; /* # channels */ unsigned int fmt_type; /* USB audio format type (1-3) */ unsigned int fmt_bits; /* number of significant bits */ + unsigned int fmt_sz; /* overall audio sub frame/slot size */ unsigned int frame_size; /* samples per frame for non-audio */ unsigned char iface; /* interface number */ unsigned char altsetting; /* corresponding alternate setting */ diff --git a/sound/usb/format.c b/sound/usb/format.c index 3b45d0ee7693..5fde543536a8 100644 --- a/sound/usb/format.c +++ b/sound/usb/format.c @@ -80,6 +80,7 @@ static u64 parse_audio_format_i_type(struct snd_usb_audio *chip, }
fp->fmt_bits = sample_width; + fp->fmt_sz = sample_bytes;
if ((pcm_formats == 0) && (format == 0 || format == (1 << UAC_FORMAT_TYPE_I_UNDEFINED))) {
Allow for the DWC3 host driver to pass along XHCI property that defines how many interrupters to allocate. This is in relation for the number of event rings that can be potentially used by other processors within the system.
Acked-by: Thinh Nguyen Thinh.Nguyen@synopsys.com Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- drivers/usb/dwc3/core.c | 12 ++++++++++++ drivers/usb/dwc3/core.h | 2 ++ drivers/usb/dwc3/host.c | 3 +++ 3 files changed, 17 insertions(+)
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 7ee61a89520b..7aa6f9700757 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -1573,6 +1573,7 @@ static void dwc3_get_properties(struct dwc3 *dwc) u8 tx_thr_num_pkt_prd = 0; u8 tx_max_burst_prd = 0; u8 tx_fifo_resize_max_num; + u16 num_hc_interrupters; const char *usb_psy_name; int ret;
@@ -1595,6 +1596,9 @@ static void dwc3_get_properties(struct dwc3 *dwc) */ tx_fifo_resize_max_num = 6;
+ /* default to a single XHCI interrupter */ + num_hc_interrupters = 1; + dwc->maximum_speed = usb_get_maximum_speed(dev); dwc->max_ssp_rate = usb_get_maximum_ssp_rate(dev); dwc->dr_mode = usb_get_dr_mode(dev); @@ -1648,6 +1652,12 @@ static void dwc3_get_properties(struct dwc3 *dwc) &tx_thr_num_pkt_prd); device_property_read_u8(dev, "snps,tx-max-burst-prd", &tx_max_burst_prd); + device_property_read_u16(dev, "num-hc-interrupters", + &num_hc_interrupters); + /* DWC3 core allowed to have a max of 8 interrupters */ + if (num_hc_interrupters > 8) + num_hc_interrupters = 8; + dwc->do_fifo_resize = device_property_read_bool(dev, "tx-fifo-resize"); if (dwc->do_fifo_resize) @@ -1736,6 +1746,8 @@ static void dwc3_get_properties(struct dwc3 *dwc) dwc->imod_interval = 0;
dwc->tx_fifo_resize_max_num = tx_fifo_resize_max_num; + + dwc->num_hc_interrupters = num_hc_interrupters; }
/* check whether the core supports IMOD */ diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 3781c736c1a1..95e6989d116e 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1077,6 +1077,7 @@ struct dwc3_scratchpad_array { * @tx_max_burst_prd: max periodic ESS transmit burst size * @tx_fifo_resize_max_num: max number of fifos allocated during txfifo resize * @clear_stall_protocol: endpoint number that requires a delayed status phase + * @num_hc_interrupters: number of host controller interrupters * @hsphy_interface: "utmi" or "ulpi" * @connected: true when we're connected to a host, false otherwise * @softconnect: true when gadget connect is called, false when disconnect runs @@ -1318,6 +1319,7 @@ struct dwc3 { u8 tx_max_burst_prd; u8 tx_fifo_resize_max_num; u8 clear_stall_protocol; + u16 num_hc_interrupters;
const char *hsphy_interface;
diff --git a/drivers/usb/dwc3/host.c b/drivers/usb/dwc3/host.c index a171b27a7845..3e5687d6d631 100644 --- a/drivers/usb/dwc3/host.c +++ b/drivers/usb/dwc3/host.c @@ -180,6 +180,9 @@ int dwc3_host_init(struct dwc3 *dwc) if (DWC3_VER_IS_WITHIN(DWC3, ANY, 300A)) props[prop_idx++] = PROPERTY_ENTRY_BOOL("quirk-broken-port-ped");
+ props[prop_idx++] = PROPERTY_ENTRY_U16("num-hc-interrupters", + dwc->num_hc_interrupters); + if (prop_idx) { ret = device_create_managed_software_node(&xhci->dev, props, NULL); if (ret) {
Some platforms may want to limit the number of XHCI interrupters allocated. This is passed to xhci-plat as a device property. Ensure that this is read and the max_interrupters field is set.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- drivers/usb/host/xhci-plat.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/drivers/usb/host/xhci-plat.c b/drivers/usb/host/xhci-plat.c index 3d071b875308..1c12cadc02a1 100644 --- a/drivers/usb/host/xhci-plat.c +++ b/drivers/usb/host/xhci-plat.c @@ -258,6 +258,8 @@ int xhci_plat_probe(struct platform_device *pdev, struct device *sysdev, const s
device_property_read_u32(tmpdev, "imod-interval-ns", &xhci->imod_interval); + device_property_read_u16(tmpdev, "num-hc-interrupters", + &xhci->max_interrupters); }
/*
The Qualcomm USB audio offload driver utilizes the QMI protocol to communicate with the audio DSP. Add the necessary QMI header and field definitions, so the QMI interface driver is able to route the QMI packet received to the USB audio offload driver.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/qcom/usb_audio_qmi_v01.c | 892 +++++++++++++++++++++++++++++ sound/usb/qcom/usb_audio_qmi_v01.h | 162 ++++++ 2 files changed, 1054 insertions(+) create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.c create mode 100644 sound/usb/qcom/usb_audio_qmi_v01.h
diff --git a/sound/usb/qcom/usb_audio_qmi_v01.c b/sound/usb/qcom/usb_audio_qmi_v01.c new file mode 100644 index 000000000000..5f61a8b1cef2 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.c @@ -0,0 +1,892 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/soc/qcom/qmi.h> + +#include "usb_audio_qmi_v01.h" + +static const struct qmi_elem_info mem_info_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_8_BYTE, + .elem_len = 1, + .elem_size = sizeof(u64), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, va), + }, + { + .data_type = QMI_UNSIGNED_8_BYTE, + .elem_len = 1, + .elem_size = sizeof(u64), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, pa), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct mem_info_v01, size), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info apps_mem_info_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, evt_ring), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, tr_data), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, tr_sync), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, xfer_buff), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct apps_mem_info_v01, dcba), + .ei_array = mem_info_v01_ei, + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_endpoint_descriptor_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bLength), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bDescriptorType), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bEndpointAddress), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bmAttributes), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + wMaxPacketSize), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bInterval), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bRefresh), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_endpoint_descriptor_v01, + bSynchAddress), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +static const struct qmi_elem_info usb_interface_descriptor_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bLength), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bDescriptorType), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceNumber), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bAlternateSetting), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bNumEndpoints), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceClass), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceSubClass), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + bInterfaceProtocol), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0, + .offset = offsetof(struct usb_interface_descriptor_v01, + iInterface), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[] = { + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x01, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + enable), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + audio_format), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + number_of_ch), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + bit_rate), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + xfer_buff_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_req_msg_v01, + service_interval), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[] = { + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct qmi_response_type_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + resp), + .ei_array = qmi_response_type_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + status_valid), + }, + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof(enum usb_qmi_audio_stream_status_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + status), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + internal_status_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + internal_status), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + slot_id_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + slot_id), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_token_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_interface_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_opr_intf_desc), + .ei_array = usb_interface_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_data_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + std_as_sync_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + data_path_delay), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1A, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct apps_mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x1A, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + xhci_mem_info), + .ei_array = apps_mem_info_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1B, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1B, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + interrupter_num), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1C, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + speed_info_valid), + }, + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof(enum usb_qmi_audio_device_speed_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x1C, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + speed_info), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1D, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + controller_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x1D, + .offset = offsetof( + struct qmi_uaudio_stream_resp_msg_v01, + controller_num), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; + +const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[] = { + { + .data_type = QMI_SIGNED_4_BYTE_ENUM, + .elem_len = 1, + .elem_size = sizeof( + enum usb_qmi_audio_device_indication_enum_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x01, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + dev_event), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x02, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + slot_id), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token_valid), + }, + { + .data_type = QMI_UNSIGNED_4_BYTE, + .elem_len = 1, + .elem_size = sizeof(u32), + .array_type = NO_ARRAY, + .tlv_type = 0x10, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_token), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_interface_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x11, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_opr_intf_desc), + .ei_array = usb_interface_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x12, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_data_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct usb_endpoint_descriptor_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x13, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + std_as_sync_ep_desc), + .ei_array = usb_endpoint_descriptor_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision_valid), + }, + { + .data_type = QMI_UNSIGNED_2_BYTE, + .elem_len = 1, + .elem_size = sizeof(u16), + .array_type = NO_ARRAY, + .tlv_type = 0x14, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_spec_revision), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x15, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + data_path_delay), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x16, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + usb_audio_subslot_size), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info_valid), + }, + { + .data_type = QMI_STRUCT, + .elem_len = 1, + .elem_size = sizeof(struct apps_mem_info_v01), + .array_type = NO_ARRAY, + .tlv_type = 0x17, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + xhci_mem_info), + .ei_array = apps_mem_info_v01_ei, + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x18, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + interrupter_num), + }, + { + .data_type = QMI_OPT_FLAG, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num_valid), + }, + { + .data_type = QMI_UNSIGNED_1_BYTE, + .elem_len = 1, + .elem_size = sizeof(u8), + .array_type = NO_ARRAY, + .tlv_type = 0x19, + .offset = offsetof(struct qmi_uaudio_stream_ind_msg_v01, + controller_num), + }, + { + .data_type = QMI_EOTI, + .array_type = NO_ARRAY, + .tlv_type = QMI_COMMON_TLV_TYPE, + }, +}; diff --git a/sound/usb/qcom/usb_audio_qmi_v01.h b/sound/usb/qcom/usb_audio_qmi_v01.h new file mode 100644 index 000000000000..6876c4d225a8 --- /dev/null +++ b/sound/usb/qcom/usb_audio_qmi_v01.h @@ -0,0 +1,162 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#ifndef USB_QMI_V01_H +#define USB_QMI_V01_H + +#define UAUDIO_STREAM_SERVICE_ID_V01 0x41D +#define UAUDIO_STREAM_SERVICE_VERS_V01 0x01 + +#define QMI_UAUDIO_STREAM_RESP_V01 0x0001 +#define QMI_UAUDIO_STREAM_REQ_V01 0x0001 +#define QMI_UAUDIO_STREAM_IND_V01 0x0001 + + +struct mem_info_v01 { + u64 va; + u64 pa; + u32 size; +}; + +struct apps_mem_info_v01 { + struct mem_info_v01 evt_ring; + struct mem_info_v01 tr_data; + struct mem_info_v01 tr_sync; + struct mem_info_v01 xfer_buff; + struct mem_info_v01 dcba; +}; + +struct usb_endpoint_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bEndpointAddress; + u8 bmAttributes; + u16 wMaxPacketSize; + u8 bInterval; + u8 bRefresh; + u8 bSynchAddress; +}; + +struct usb_interface_descriptor_v01 { + u8 bLength; + u8 bDescriptorType; + u8 bInterfaceNumber; + u8 bAlternateSetting; + u8 bNumEndpoints; + u8 bInterfaceClass; + u8 bInterfaceSubClass; + u8 bInterfaceProtocol; + u8 iInterface; +}; + +enum usb_qmi_audio_stream_status_enum_v01 { + USB_QMI_STREAM_STATUS_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_STREAM_REQ_SUCCESS_V01 = 0, + USB_QMI_STREAM_REQ_FAILURE_V01 = 1, + USB_QMI_STREAM_REQ_FAILURE_NOT_FOUND_V01 = 2, + USB_QMI_STREAM_REQ_FAILURE_INVALID_PARAM_V01 = 3, + USB_QMI_STREAM_REQ_FAILURE_MEMALLOC_V01 = 4, + USB_QMI_STREAM_STATUS_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +enum usb_qmi_audio_device_indication_enum_v01 { + USB_QMI_DEVICE_INDICATION_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_DEV_CONNECT_V01 = 0, + USB_QMI_DEV_DISCONNECT_V01 = 1, + USB_QMI_DEV_SUSPEND_V01 = 2, + USB_QMI_DEV_RESUME_V01 = 3, + USB_QMI_DEVICE_INDICATION_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +enum usb_qmi_audio_device_speed_enum_v01 { + USB_QMI_DEVICE_SPEED_ENUM_MIN_VAL_V01 = INT_MIN, + USB_QMI_DEVICE_SPEED_INVALID_V01 = 0, + USB_QMI_DEVICE_SPEED_LOW_V01 = 1, + USB_QMI_DEVICE_SPEED_FULL_V01 = 2, + USB_QMI_DEVICE_SPEED_HIGH_V01 = 3, + USB_QMI_DEVICE_SPEED_SUPER_V01 = 4, + USB_QMI_DEVICE_SPEED_SUPER_PLUS_V01 = 5, + USB_QMI_DEVICE_SPEED_ENUM_MAX_VAL_V01 = INT_MAX, +}; + +struct qmi_uaudio_stream_req_msg_v01 { + u8 enable; + u32 usb_token; + u8 audio_format_valid; + u32 audio_format; + u8 number_of_ch_valid; + u32 number_of_ch; + u8 bit_rate_valid; + u32 bit_rate; + u8 xfer_buff_size_valid; + u32 xfer_buff_size; + u8 service_interval_valid; + u32 service_interval; +}; +#define QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN 46 +extern const struct qmi_elem_info qmi_uaudio_stream_req_msg_v01_ei[]; + +struct qmi_uaudio_stream_resp_msg_v01 { + struct qmi_response_type_v01 resp; + u8 status_valid; + enum usb_qmi_audio_stream_status_enum_v01 status; + u8 internal_status_valid; + u32 internal_status; + u8 slot_id_valid; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 speed_info_valid; + enum usb_qmi_audio_device_speed_enum_v01 speed_info; + u8 controller_num_valid; + u8 controller_num; +}; +#define QMI_UAUDIO_STREAM_RESP_MSG_V01_MAX_MSG_LEN 202 +extern const struct qmi_elem_info qmi_uaudio_stream_resp_msg_v01_ei[]; + +struct qmi_uaudio_stream_ind_msg_v01 { + enum usb_qmi_audio_device_indication_enum_v01 dev_event; + u32 slot_id; + u8 usb_token_valid; + u32 usb_token; + u8 std_as_opr_intf_desc_valid; + struct usb_interface_descriptor_v01 std_as_opr_intf_desc; + u8 std_as_data_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_data_ep_desc; + u8 std_as_sync_ep_desc_valid; + struct usb_endpoint_descriptor_v01 std_as_sync_ep_desc; + u8 usb_audio_spec_revision_valid; + u16 usb_audio_spec_revision; + u8 data_path_delay_valid; + u8 data_path_delay; + u8 usb_audio_subslot_size_valid; + u8 usb_audio_subslot_size; + u8 xhci_mem_info_valid; + struct apps_mem_info_v01 xhci_mem_info; + u8 interrupter_num_valid; + u8 interrupter_num; + u8 controller_num_valid; + u8 controller_num; +}; +#define QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN 181 +extern const struct qmi_elem_info qmi_uaudio_stream_ind_msg_v01_ei[]; + +#endif
Several Qualcomm SoCs have a dedicated audio DSP, which has the ability to support USB sound devices. This vendor driver will implement the required handshaking with the DSP, in order to pass along required resources that will be utilized by the DSP's USB SW. The communication channel used for this handshaking will be using the QMI protocol. Required resources include: - Allocated secondary event ring address - EP transfer ring address - Interrupter number
The above information will allow for the audio DSP to execute USB transfers over the USB bus. It will also be able to support devices that have an implicit feedback and sync endpoint as well. Offloading these data transfers will allow the main/applications processor to enter lower CPU power modes, and sustain a longer duration in those modes.
Audio offloading is initiated with the following sequence: 1. Userspace configures to route audio playback to USB backend and starts playback on the platform soundcard. 2. The Q6DSP AFE will communicate to the audio DSP to start the USB AFE port. 3. This results in a QMI packet with a STREAM enable command. 4. The QC audio offload driver will fetch the required resources, and pass this information as part of the QMI response to the STREAM enable command. 5. Once the QMI response is received the audio DSP will start queuing data on the USB bus.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/Kconfig | 15 + sound/usb/Makefile | 2 +- sound/usb/qcom/Makefile | 2 + sound/usb/qcom/qc_audio_offload.c | 1883 +++++++++++++++++++++++++++++ 4 files changed, 1901 insertions(+), 1 deletion(-) create mode 100644 sound/usb/qcom/Makefile create mode 100644 sound/usb/qcom/qc_audio_offload.c
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 4a9569a3a39a..5cc3eaf53e6b 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,6 +176,21 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000.
+config SND_USB_AUDIO_QMI + tristate "Qualcomm Audio Offload driver" + depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND && SND_SOC_USB + select SND_PCM + help + Say Y here to enable the Qualcomm USB audio offloading feature. + + This module sets up the required QMI stream enable/disable + responses to requests generated by the audio DSP. It passes the + USB transfer resource references, so that the audio DSP can issue + USB transfers to the host controller. + + To compile this driver as a module, choose M here: the module + will be called snd-usb-audio-qmi. + source "sound/usb/line6/Kconfig"
endif # SND_USB diff --git a/sound/usb/Makefile b/sound/usb/Makefile index 0532499dbc6d..54a06a2f73ca 100644 --- a/sound/usb/Makefile +++ b/sound/usb/Makefile @@ -34,5 +34,5 @@ obj-$(CONFIG_SND_USB_UA101) += snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_USX2Y) += snd-usbmidi-lib.o obj-$(CONFIG_SND_USB_US122L) += snd-usbmidi-lib.o
-obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ +obj-$(CONFIG_SND) += misc/ usx2y/ caiaq/ 6fire/ hiface/ bcd2000/ qcom/ obj-$(CONFIG_SND_USB_LINE6) += line6/ diff --git a/sound/usb/qcom/Makefile b/sound/usb/qcom/Makefile new file mode 100644 index 000000000000..a81c9b28d484 --- /dev/null +++ b/sound/usb/qcom/Makefile @@ -0,0 +1,2 @@ +snd-usb-audio-qmi-objs := usb_audio_qmi_v01.o qc_audio_offload.o +obj-$(CONFIG_SND_USB_AUDIO_QMI) += snd-usb-audio-qmi.o \ No newline at end of file diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c new file mode 100644 index 000000000000..eda16d6df0d7 --- /dev/null +++ b/sound/usb/qcom/qc_audio_offload.c @@ -0,0 +1,1883 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ + +#include <linux/ctype.h> +#include <linux/dma-mapping.h> +#include <linux/dma-map-ops.h> +#include <linux/init.h> +#include <linux/iommu.h> +#include <linux/module.h> +#include <linux/moduleparam.h> +#include <linux/soc/qcom/qmi.h> +#include <linux/usb.h> +#include <linux/usb/audio.h> +#include <linux/usb/audio-v2.h> +#include <linux/usb/audio-v3.h> +#include <linux/usb/hcd.h> +#include <linux/usb/quirks.h> +#include <linux/usb/xhci-sideband.h> + +#include <sound/control.h> +#include <sound/core.h> +#include <sound/info.h> +#include <sound/initval.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/q6usboffload.h> +#include <sound/soc.h> +#include <sound/soc-usb.h> + +#include "../usbaudio.h" +#include "../card.h" +#include "../endpoint.h" +#include "../format.h" +#include "../helper.h" +#include "../pcm.h" +#include "../power.h" + +#include "usb_audio_qmi_v01.h" + +/* Stream disable request timeout during USB device disconnect */ +#define DEV_RELEASE_WAIT_TIMEOUT 10000 /* in ms */ + +/* Data interval calculation parameters */ +#define BUS_INTERVAL_FULL_SPEED 1000 /* in us */ +#define BUS_INTERVAL_HIGHSPEED_AND_ABOVE 125 /* in us */ +#define MAX_BINTERVAL_ISOC_EP 16 + +#define QMI_STREAM_REQ_CARD_NUM_MASK 0xffff0000 +#define QMI_STREAM_REQ_DEV_NUM_MASK 0xff00 +#define QMI_STREAM_REQ_DIRECTION 0xff + +/* iommu resource parameters and management */ +#define PREPEND_SID_TO_IOVA(iova, sid) ((u64)(((u64)(iova)) | \ + (((u64)sid) << 32))) +#define IOVA_MASK(iova) (((u64)(iova)) & 0xFFFFFFFF) +#define IOVA_BASE 0x1000 +#define IOVA_XFER_RING_BASE (IOVA_BASE + PAGE_SIZE * (SNDRV_CARDS + 1)) +#define IOVA_XFER_BUF_BASE (IOVA_XFER_RING_BASE + PAGE_SIZE * SNDRV_CARDS * 32) +#define IOVA_XFER_RING_MAX (IOVA_XFER_BUF_BASE - PAGE_SIZE) +#define IOVA_XFER_BUF_MAX (0xfffff000 - PAGE_SIZE) + +#define MAX_XFER_BUFF_LEN (24 * PAGE_SIZE) + +struct iova_info { + struct list_head list; + unsigned long start_iova; + size_t size; + bool in_use; +}; + +struct intf_info { + unsigned long data_xfer_ring_va; + size_t data_xfer_ring_size; + unsigned long sync_xfer_ring_va; + size_t sync_xfer_ring_size; + unsigned long xfer_buf_va; + size_t xfer_buf_size; + phys_addr_t xfer_buf_pa; + unsigned int data_ep_pipe; + unsigned int sync_ep_pipe; + u8 *xfer_buf; + u8 intf_num; + u8 pcm_card_num; + u8 pcm_dev_num; + u8 direction; + bool in_use; +}; + +struct uaudio_qmi_dev { + struct device *dev; + struct q6usb_offload *data; + + /* list to keep track of available iova */ + struct list_head xfer_ring_list; + size_t xfer_ring_iova_size; + unsigned long curr_xfer_ring_iova; + struct list_head xfer_buf_list; + size_t xfer_buf_iova_size; + unsigned long curr_xfer_buf_iova; + + /* bit fields representing pcm card enabled */ + unsigned long card_slot; + /* indicate event ring mapped or not */ + bool er_mapped; + /* reference count to number of possible consumers */ + atomic_t qdev_in_use; + /* idx to last udev card number plugged in */ + unsigned int last_card_num; +}; + +struct uaudio_dev { + struct usb_device *udev; + /* audio control interface */ + struct usb_host_interface *ctrl_intf; + unsigned int usb_core_id; + atomic_t in_use; + struct kref kref; + wait_queue_head_t disconnect_wq; + + /* interface specific */ + int num_intf; + struct intf_info *info; + struct snd_usb_audio *chip; + + /* xhci sideband */ + struct xhci_sideband *sb; + + /* SoC USB device */ + struct snd_soc_usb_device *sdev; +}; + +static struct uaudio_dev uadev[SNDRV_CARDS]; +static struct uaudio_qmi_dev *uaudio_qdev; +static struct uaudio_qmi_svc *uaudio_svc; +static DEFINE_MUTEX(qdev_mutex); + +struct uaudio_qmi_svc { + struct qmi_handle *uaudio_svc_hdl; + struct sockaddr_qrtr client_sq; + bool client_connected; +}; + +enum mem_type { + MEM_EVENT_RING, + MEM_XFER_RING, + MEM_XFER_BUF, +}; + +/* Supported audio formats */ +enum usb_qmi_audio_format { + USB_QMI_PCM_FORMAT_S8 = 0, + USB_QMI_PCM_FORMAT_U8, + USB_QMI_PCM_FORMAT_S16_LE, + USB_QMI_PCM_FORMAT_S16_BE, + USB_QMI_PCM_FORMAT_U16_LE, + USB_QMI_PCM_FORMAT_U16_BE, + USB_QMI_PCM_FORMAT_S24_LE, + USB_QMI_PCM_FORMAT_S24_BE, + USB_QMI_PCM_FORMAT_U24_LE, + USB_QMI_PCM_FORMAT_U24_BE, + USB_QMI_PCM_FORMAT_S24_3LE, + USB_QMI_PCM_FORMAT_S24_3BE, + USB_QMI_PCM_FORMAT_U24_3LE, + USB_QMI_PCM_FORMAT_U24_3BE, + USB_QMI_PCM_FORMAT_S32_LE, + USB_QMI_PCM_FORMAT_S32_BE, + USB_QMI_PCM_FORMAT_U32_LE, + USB_QMI_PCM_FORMAT_U32_BE, +}; + +static enum usb_qmi_audio_device_speed_enum_v01 +get_speed_info(enum usb_device_speed udev_speed) +{ + switch (udev_speed) { + case USB_SPEED_LOW: + return USB_QMI_DEVICE_SPEED_LOW_V01; + case USB_SPEED_FULL: + return USB_QMI_DEVICE_SPEED_FULL_V01; + case USB_SPEED_HIGH: + return USB_QMI_DEVICE_SPEED_HIGH_V01; + case USB_SPEED_SUPER: + return USB_QMI_DEVICE_SPEED_SUPER_V01; + case USB_SPEED_SUPER_PLUS: + return USB_QMI_DEVICE_SPEED_SUPER_PLUS_V01; + default: + return USB_QMI_DEVICE_SPEED_INVALID_V01; + } +} + +static struct snd_usb_substream *find_substream(unsigned int card_num, + unsigned int pcm_idx, unsigned int direction) +{ + struct snd_usb_substream *subs = NULL; + struct snd_usb_audio *chip; + struct snd_usb_stream *as; + + chip = uadev[card_num].chip; + if (!chip || atomic_read(&chip->shutdown)) + goto done; + + if (pcm_idx >= chip->pcm_devs) + goto done; + + if (direction > SNDRV_PCM_STREAM_CAPTURE) + goto done; + + list_for_each_entry(as, &chip->pcm_list, list) { + if (as->pcm_index == pcm_idx) { + subs = &as->substream[direction]; + goto done; + } + } + +done: + return subs; +} + +static int info_idx_from_ifnum(int card_num, int intf_num, bool enable) +{ + int i; + + /* + * default index 0 is used when info is allocated upon + * first enable audio stream req for a pcm device + */ + if (enable && !uadev[card_num].info) + return 0; + + for (i = 0; i < uadev[card_num].num_intf; i++) { + if (enable && !uadev[card_num].info[i].in_use) + return i; + else if (!enable && + uadev[card_num].info[i].intf_num == intf_num) + return i; + } + + return -EINVAL; +} + +static int get_data_interval_from_si(struct snd_usb_substream *subs, + u32 service_interval) +{ + unsigned int bus_intval_mult; + unsigned int bus_intval; + unsigned int binterval; + + if (subs->dev->speed >= USB_SPEED_HIGH) + bus_intval = BUS_INTERVAL_HIGHSPEED_AND_ABOVE; + else + bus_intval = BUS_INTERVAL_FULL_SPEED; + + if (service_interval % bus_intval) + return -EINVAL; + + bus_intval_mult = service_interval / bus_intval; + binterval = ffs(bus_intval_mult); + if (!binterval || binterval > MAX_BINTERVAL_ISOC_EP) + return -EINVAL; + + /* check if another bit is set then bail out */ + bus_intval_mult = bus_intval_mult >> binterval; + if (bus_intval_mult) + return -EINVAL; + + return (binterval - 1); +} + +/* maps audio format received over QMI to asound.h based pcm format */ +static snd_pcm_format_t map_pcm_format(enum usb_qmi_audio_format fmt_received) +{ + switch (fmt_received) { + case USB_QMI_PCM_FORMAT_S8: + return SNDRV_PCM_FORMAT_S8; + case USB_QMI_PCM_FORMAT_U8: + return SNDRV_PCM_FORMAT_U8; + case USB_QMI_PCM_FORMAT_S16_LE: + return SNDRV_PCM_FORMAT_S16_LE; + case USB_QMI_PCM_FORMAT_S16_BE: + return SNDRV_PCM_FORMAT_S16_BE; + case USB_QMI_PCM_FORMAT_U16_LE: + return SNDRV_PCM_FORMAT_U16_LE; + case USB_QMI_PCM_FORMAT_U16_BE: + return SNDRV_PCM_FORMAT_U16_BE; + case USB_QMI_PCM_FORMAT_S24_LE: + return SNDRV_PCM_FORMAT_S24_LE; + case USB_QMI_PCM_FORMAT_S24_BE: + return SNDRV_PCM_FORMAT_S24_BE; + case USB_QMI_PCM_FORMAT_U24_LE: + return SNDRV_PCM_FORMAT_U24_LE; + case USB_QMI_PCM_FORMAT_U24_BE: + return SNDRV_PCM_FORMAT_U24_BE; + case USB_QMI_PCM_FORMAT_S24_3LE: + return SNDRV_PCM_FORMAT_S24_3LE; + case USB_QMI_PCM_FORMAT_S24_3BE: + return SNDRV_PCM_FORMAT_S24_3BE; + case USB_QMI_PCM_FORMAT_U24_3LE: + return SNDRV_PCM_FORMAT_U24_3LE; + case USB_QMI_PCM_FORMAT_U24_3BE: + return SNDRV_PCM_FORMAT_U24_3BE; + case USB_QMI_PCM_FORMAT_S32_LE: + return SNDRV_PCM_FORMAT_S32_LE; + case USB_QMI_PCM_FORMAT_S32_BE: + return SNDRV_PCM_FORMAT_S32_BE; + case USB_QMI_PCM_FORMAT_U32_LE: + return SNDRV_PCM_FORMAT_U32_LE; + case USB_QMI_PCM_FORMAT_U32_BE: + return SNDRV_PCM_FORMAT_U32_BE; + default: + /* + * We expect the caller to do input validation so we should + * never hit this. But we do have to return a proper + * snd_pcm_format_t value due to the __bitwise attribute; so + * just return the equivalent of 0 in case of bad input. + */ + return SNDRV_PCM_FORMAT_S8; + } +} + +/* Offloading IOMMU management */ +static unsigned long uaudio_get_iova(unsigned long *curr_iova, + size_t *curr_iova_size, struct list_head *head, size_t size) +{ + struct iova_info *info, *new_info = NULL; + struct list_head *curr_head; + size_t tmp_size = size; + unsigned long va = 0; + bool found = false; + + if (size % PAGE_SIZE) + goto done; + + if (size > *curr_iova_size) + goto done; + + if (*curr_iova_size == 0) + goto done; + + list_for_each_entry(info, head, list) { + /* exact size iova_info */ + if (!info->in_use && info->size == size) { + info->in_use = true; + va = info->start_iova; + *curr_iova_size -= size; + found = true; + goto done; + } else if (!info->in_use && tmp_size >= info->size) { + if (!new_info) + new_info = info; + tmp_size -= info->size; + if (tmp_size) + continue; + + va = new_info->start_iova; + for (curr_head = &new_info->list; curr_head != + &info->list; curr_head = curr_head->next) { + new_info = list_entry(curr_head, struct + iova_info, list); + new_info->in_use = true; + } + info->in_use = true; + *curr_iova_size -= size; + found = true; + goto done; + } else { + /* iova region in use */ + new_info = NULL; + tmp_size = size; + } + } + + info = kzalloc(sizeof(struct iova_info), GFP_KERNEL); + if (!info) { + va = 0; + goto done; + } + + va = info->start_iova = *curr_iova; + info->size = size; + info->in_use = true; + *curr_iova += size; + *curr_iova_size -= size; + found = true; + list_add_tail(&info->list, head); + +done: + return va; +} + +static void uaudio_put_iova(unsigned long va, size_t size, struct list_head + *head, size_t *curr_iova_size) +{ + struct iova_info *info; + size_t tmp_size = size; + bool found = false; + + list_for_each_entry(info, head, list) { + if (info->start_iova == va) { + if (!info->in_use) + return; + + found = true; + info->in_use = false; + if (info->size == size) + goto done; + } + + if (found && tmp_size >= info->size) { + info->in_use = false; + tmp_size -= info->size; + if (!tmp_size) + goto done; + } + } + + if (!found) + return; + +done: + *curr_iova_size += size; +} + +/** + * uaudio_iommu_unmap() - unmaps iommu memory for adsp + * @mtype: ring type + * @va: virtual address to unmap + * @iova_size: region size + * @mapped_iova_size: mapped region size + * + * Unmaps the memory region that was previously assigned to the adsp. + * + */ +static void uaudio_iommu_unmap(enum mem_type mtype, unsigned long va, + size_t iova_size, size_t mapped_iova_size) +{ + size_t umap_size; + bool unmap = true; + + if (!va || !iova_size) + return; + + switch (mtype) { + case MEM_EVENT_RING: + if (uaudio_qdev->er_mapped) + uaudio_qdev->er_mapped = false; + else + unmap = false; + break; + + case MEM_XFER_RING: + uaudio_put_iova(va, iova_size, &uaudio_qdev->xfer_ring_list, + &uaudio_qdev->xfer_ring_iova_size); + break; + case MEM_XFER_BUF: + uaudio_put_iova(va, iova_size, &uaudio_qdev->xfer_buf_list, + &uaudio_qdev->xfer_buf_iova_size); + break; + default: + unmap = false; + } + + if (!unmap || !mapped_iova_size) + return; + + umap_size = iommu_unmap(uaudio_qdev->data->domain, va, mapped_iova_size); + if (umap_size != mapped_iova_size) + dev_err(uaudio_qdev->data->dev, + "unmapped size %zu for iova 0x%08lx of mapped size %zu\n", + umap_size, va, mapped_iova_size); +} + +/** + * uaudio_iommu_map() - maps iommu memory for adsp + * @mtype: ring type + * @dma_coherent: dma coherent + * @pa: physical address for ring/buffer + * @size: size of memory region + * @sgt: sg table for memory region + * + * Maps the XHCI related resources to a memory region that is assigned to be + * used by the adsp. This will be mapped to the domain, which is created by + * the ASoC USB backend driver. + * + */ +static unsigned long uaudio_iommu_map(enum mem_type mtype, bool dma_coherent, + phys_addr_t pa, size_t size, struct sg_table *sgt) +{ + struct scatterlist *sg; + unsigned long va = 0; + size_t total_len = 0; + unsigned long va_sg; + phys_addr_t pa_sg; + bool map = true; + size_t sg_len; + int prot; + int ret; + int i; + + prot = IOMMU_READ | IOMMU_WRITE; + + if (dma_coherent) + prot |= IOMMU_CACHE; + + switch (mtype) { + case MEM_EVENT_RING: + va = IOVA_BASE; + /* er already mapped */ + if (uaudio_qdev->er_mapped) + map = false; + break; + case MEM_XFER_RING: + va = uaudio_get_iova(&uaudio_qdev->curr_xfer_ring_iova, + &uaudio_qdev->xfer_ring_iova_size, &uaudio_qdev->xfer_ring_list, + size); + break; + case MEM_XFER_BUF: + va = uaudio_get_iova(&uaudio_qdev->curr_xfer_buf_iova, + &uaudio_qdev->xfer_buf_iova_size, &uaudio_qdev->xfer_buf_list, + size); + break; + default: + dev_err(uaudio_qdev->data->dev, "unknown mem type %d\n", mtype); + } + + if (!va || !map) + goto done; + + if (!sgt) + goto skip_sgt_map; + + va_sg = va; + for_each_sg(sgt->sgl, sg, sgt->nents, i) { + sg_len = PAGE_ALIGN(sg->offset + sg->length); + pa_sg = page_to_phys(sg_page(sg)); + ret = iommu_map(uaudio_qdev->data->domain, va_sg, pa_sg, sg_len, + prot, GFP_KERNEL); + if (ret) { + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va = 0; + goto done; + } + + va_sg += sg_len; + total_len += sg_len; + } + + if (size != total_len) { + uaudio_iommu_unmap(MEM_XFER_BUF, va, size, total_len); + va = 0; + } + return va; + +skip_sgt_map: + iommu_map(uaudio_qdev->data->domain, va, pa, size, prot, GFP_KERNEL); + +done: + return va; +} + +/* looks up alias, if any, for controller DT node and returns the index */ +static int usb_get_controller_id(struct usb_device *udev) +{ + if (udev->bus->sysdev && udev->bus->sysdev->of_node) + return of_alias_get_id(udev->bus->sysdev->of_node, "usb"); + + return -ENODEV; +} + +/** + * uaudio_dev_intf_cleanup() - cleanup transfer resources + * @udev: usb device + * @info: usb offloading interface + * + * Cleans up the transfer ring related resources which are assigned per + * endpoint from XHCI. This is invoked when the USB endpoints are no + * longer in use by the adsp. + * + */ +static void uaudio_dev_intf_cleanup(struct usb_device *udev, + struct intf_info *info) +{ + uaudio_iommu_unmap(MEM_XFER_RING, info->data_xfer_ring_va, + info->data_xfer_ring_size, info->data_xfer_ring_size); + info->data_xfer_ring_va = 0; + info->data_xfer_ring_size = 0; + + uaudio_iommu_unmap(MEM_XFER_RING, info->sync_xfer_ring_va, + info->sync_xfer_ring_size, info->sync_xfer_ring_size); + info->sync_xfer_ring_va = 0; + info->sync_xfer_ring_size = 0; + + uaudio_iommu_unmap(MEM_XFER_BUF, info->xfer_buf_va, + info->xfer_buf_size, info->xfer_buf_size); + info->xfer_buf_va = 0; + + usb_free_coherent(udev, info->xfer_buf_size, + info->xfer_buf, info->xfer_buf_pa); + info->xfer_buf_size = 0; + info->xfer_buf = NULL; + info->xfer_buf_pa = 0; + + info->in_use = false; +} + +/** + * uaudio_event_ring_cleanup_free() - cleanup secondary event ring + * @dev: usb offload device + * + * Cleans up the secondary event ring that was requested. This will + * occur when the adsp is no longer transferring data on the USB bus + * across all endpoints. + * + */ +static void uaudio_event_ring_cleanup_free(struct uaudio_dev *dev) +{ + clear_bit(dev->chip->card->number, &uaudio_qdev->card_slot); + /* all audio devices are disconnected */ + if (!uaudio_qdev->card_slot) { + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, + PAGE_SIZE); + xhci_sideband_remove_interrupter(uadev[dev->chip->card->number].sb); + } +} + +static void uaudio_dev_cleanup(struct uaudio_dev *dev) +{ + int if_idx; + + if (!dev->udev) + return; + + /* free xfer buffer and unmap xfer ring and buf per interface */ + for (if_idx = 0; if_idx < dev->num_intf; if_idx++) { + if (!dev->info[if_idx].in_use) + continue; + uaudio_dev_intf_cleanup(dev->udev, &dev->info[if_idx]); + dev_dbg(uaudio_qdev->data->dev, + "release resources: intf# %d card# %d\n", + dev->info[if_idx].intf_num, dev->chip->card->number); + } + + dev->num_intf = 0; + + /* free interface info */ + kfree(dev->info); + dev->info = NULL; + uaudio_event_ring_cleanup_free(dev); + dev->udev = NULL; +} + +/** + * disable_audio_stream() - disable usb snd endpoints + * @subs: usb substream + * + * Closes the USB SND endpoints associated with the current audio stream + * used. This will decrement the USB SND endpoint opened reference count. + * + */ +static void disable_audio_stream(struct snd_usb_substream *subs) +{ + struct snd_usb_audio *chip = subs->stream->chip; + + snd_usb_hw_free(subs); + snd_usb_autosuspend(chip); +} + +/* QMI service disconnect handlers */ +static void qmi_stop_session(void) +{ + struct snd_usb_substream *subs; + struct usb_host_endpoint *ep; + struct snd_usb_audio *chip; + struct intf_info *info; + int pcm_card_num; + int if_idx; + int idx; + + mutex_lock(&qdev_mutex); + /* find all active intf for set alt 0 and cleanup usb audio dev */ + for (idx = 0; idx < SNDRV_CARDS; idx++) { + if (!atomic_read(&uadev[idx].in_use)) + continue; + + chip = uadev[idx].chip; + for (if_idx = 0; if_idx < uadev[idx].num_intf; if_idx++) { + if (!uadev[idx].info || !uadev[idx].info[if_idx].in_use) + continue; + info = &uadev[idx].info[if_idx]; + pcm_card_num = info->pcm_card_num; + subs = find_substream(pcm_card_num, + info->pcm_dev_num, + info->direction); + if (!subs || !chip || atomic_read(&chip->shutdown)) { + dev_err(&subs->dev->dev, + "no sub for c#%u dev#%u dir%u\n", + info->pcm_card_num, + info->pcm_dev_num, + info->direction); + continue; + } + /* Release XHCI endpoints */ + if (info->data_ep_pipe) + ep = usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->data_ep_pipe); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, ep); + + if (info->sync_ep_pipe) + ep = usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, ep); + + disable_audio_stream(subs); + } + atomic_set(&uadev[idx].in_use, 0); + mutex_lock(&chip->mutex); + uaudio_dev_cleanup(&uadev[idx]); + mutex_unlock(&chip->mutex); + } + mutex_unlock(&qdev_mutex); +} + +/** + * qmi_bye_cb() - qmi bye message callback + * @handle: QMI handle + * @node: id of the dying node + * + * This callback is invoked when the QMI bye control message is received + * from the QMI client. Handle the message accordingly by ensuring that + * the USB offload path is disabled and cleaned up. At this point, ADSP + * is not utilizing the USB bus. + * + */ +static void qmi_bye_cb(struct qmi_handle *handle, unsigned int node) +{ + struct uaudio_qmi_svc *svc = uaudio_svc; + + if (svc->uaudio_svc_hdl != handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node == node) { + qmi_stop_session(); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node = 0; + svc->client_sq.sq_port = 0; + svc->client_sq.sq_family = 0; + svc->client_connected = false; + } +} + +/** + * qmi_svc_disconnect_cb() - qmi client disconnected + * @handle: QMI handle + * @node: id of the dying node + * @port: port of the dying client + * + * Invoked when the remote QMI client is disconnected. Handle this event + * the same way as when the QMI bye message is received. This will ensure + * the USB offloading path is disabled and cleaned up. + * + */ +static void qmi_svc_disconnect_cb(struct qmi_handle *handle, + unsigned int node, unsigned int port) +{ + struct uaudio_qmi_svc *svc; + + if (uaudio_svc == NULL) + return; + + svc = uaudio_svc; + if (svc->uaudio_svc_hdl != handle) + return; + + if (svc->client_connected && svc->client_sq.sq_node == node && + svc->client_sq.sq_port == port) { + qmi_stop_session(); + + /* clear QMI client parameters to block further QMI messages */ + svc->client_sq.sq_node = 0; + svc->client_sq.sq_port = 0; + svc->client_sq.sq_family = 0; + svc->client_connected = false; + } +} + +/* QMI client callback handlers from QMI interface */ +static struct qmi_ops uaudio_svc_ops_options = { + .bye = qmi_bye_cb, + .del_client = qmi_svc_disconnect_cb, +}; + +/* kref release callback when all streams are disabled */ +static void uaudio_dev_release(struct kref *kref) +{ + struct uaudio_dev *dev = container_of(kref, struct uaudio_dev, kref); + + uaudio_event_ring_cleanup_free(dev); + atomic_set(&dev->in_use, 0); + wake_up(&dev->disconnect_wq); +} + +/** + * enable_audio_stream() - enable usb snd endpoints + * @subs: usb substream + * @pcm_format: pcm format requested + * @channels: number of channels + * @cur_rate: sample rate + * @datainterval: interval + * + * Opens all USB SND endpoints used for the data interface. This will increment + * the USB SND endpoint's opened count. Requests to keep the interface resumed + * until the audio stream is stopped. Will issue the USB set interface control + * message to enable the data interface. + * + */ +static int enable_audio_stream(struct snd_usb_substream *subs, + snd_pcm_format_t pcm_format, + unsigned int channels, unsigned int cur_rate, + int datainterval) +{ + struct snd_pcm_hw_params params; + struct snd_usb_audio *chip; + struct snd_interval *i; + struct snd_mask *m; + int ret; + + chip = subs->stream->chip; + + _snd_pcm_hw_params_any(¶ms); + + m = hw_param_mask(¶ms, SNDRV_PCM_HW_PARAM_FORMAT); + snd_mask_leave(m, pcm_format); + + i = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_CHANNELS); + snd_interval_setinteger(i); + i->min = i->max = channels; + + i = hw_param_interval(¶ms, SNDRV_PCM_HW_PARAM_RATE); + snd_interval_setinteger(i); + i->min = i->max = cur_rate; + + pm_runtime_barrier(&chip->intf[0]->dev); + snd_usb_autoresume(chip); + + ret = snd_usb_hw_params(subs, ¶ms); + if (ret < 0) + goto put_suspend; + + if (!atomic_read(&chip->shutdown)) { + ret = snd_usb_lock_shutdown(chip); + if (ret < 0) + goto detach_ep; + + if (subs->sync_endpoint) { + ret = snd_usb_endpoint_prepare(chip, subs->sync_endpoint); + if (ret < 0) + goto unlock; + } + + ret = snd_usb_endpoint_prepare(chip, subs->data_endpoint); + if (ret < 0) + goto unlock; + + snd_usb_unlock_shutdown(chip); + + dev_dbg(uaudio_qdev->data->dev, + "selected %s iface:%d altsetting:%d datainterval:%dus\n", + subs->direction ? "capture" : "playback", + subs->cur_audiofmt->iface, subs->cur_audiofmt->altsetting, + (1 << subs->cur_audiofmt->datainterval) * + (subs->dev->speed >= USB_SPEED_HIGH ? + BUS_INTERVAL_HIGHSPEED_AND_ABOVE : + BUS_INTERVAL_FULL_SPEED)); + } + + return 0; + +unlock: + snd_usb_unlock_shutdown(chip); + +detach_ep: + snd_usb_hw_free(subs); + +put_suspend: + snd_usb_autosuspend(chip); + + return ret; +} + +/* returns usb hcd sysdev */ +static struct device *usb_get_usb_backend(struct usb_device *udev) +{ + if (udev->bus->sysdev && udev->bus->sysdev->of_node) + return udev->bus->sysdev; + + return NULL; +} + +/** + * uaudio_transfer_buffer_setup() - fetch and populate xfer buffer params + * @subs: usb substream + * @xfer_buf: xfer buf to be allocated + * @xfer_buf_len: size of allocation + * @mem_info: QMI response info + * + * Allocates and maps the transfer buffers that will be utilized by the + * audio DSP. Will populate the information in the QMI response that is + * sent back to the stream enable request. + * + */ +static int uaudio_transfer_buffer_setup(struct snd_usb_substream *subs, + u8 *xfer_buf, u32 xfer_buf_len, + struct mem_info_v01 *mem_info) +{ + struct sg_table xfer_buf_sgt; + phys_addr_t xfer_buf_pa; + u32 len = xfer_buf_len; + bool dma_coherent; + unsigned long va; + u32 remainder; + u32 mult; + int ret; + + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + + /* xfer buffer, multiple of 4K only */ + if (!len) + len = PAGE_SIZE; + + mult = len / PAGE_SIZE; + remainder = len % PAGE_SIZE; + len = mult * PAGE_SIZE; + len += remainder ? PAGE_SIZE : 0; + + if (len > MAX_XFER_BUFF_LEN) { + dev_err(uaudio_qdev->data->dev, + "req buf len %d > max buf len %lu, setting %lu\n", + len, MAX_XFER_BUFF_LEN, MAX_XFER_BUFF_LEN); + len = MAX_XFER_BUFF_LEN; + } + + xfer_buf = usb_alloc_coherent(subs->dev, len, GFP_KERNEL, &xfer_buf_pa); + if (!xfer_buf) + return -ENOMEM; + + dma_get_sgtable(subs->dev->bus->sysdev, &xfer_buf_sgt, xfer_buf, + xfer_buf_pa, len); + va = uaudio_iommu_map(MEM_XFER_BUF, dma_coherent, xfer_buf_pa, len, + &xfer_buf_sgt); + if (!va) { + ret = -ENOMEM; + goto unmap_sync; + } + + mem_info->pa = xfer_buf_pa; + mem_info->size = len; + mem_info->va = PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + sg_free_table(&xfer_buf_sgt); + + return 0; + +unmap_sync: + usb_free_coherent(subs->dev, len, xfer_buf, xfer_buf_pa); + + return ret; +} + +/** + * uaudio_endpoint_setup() - fetch and populate endpoint params + * @subs: usb substream + * @endpoint: usb endpoint to add + * @card_num: uadev index + * @mem_info: QMI response info + * @ep_desc: QMI ep desc response field + * + * Initialize the USB endpoint being used for a particular USB + * stream. Will request XHCI sideband to reserve the EP for + * offloading as well as populating the QMI response with the + * transfer ring parameters. + * + */ +static phys_addr_t uaudio_endpoint_setup(struct snd_usb_substream *subs, + struct snd_usb_endpoint *endpoint, int card_num, + struct mem_info_v01 *mem_info, + struct usb_endpoint_descriptor_v01 *ep_desc) +{ + struct usb_host_endpoint *ep; + phys_addr_t tr_pa = 0; + struct sg_table *sgt; + bool dma_coherent; + unsigned long va; + struct page *pg; + int ret; + + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + + ep = usb_pipe_endpoint(subs->dev, endpoint->pipe); + if (!ep) { + dev_err(uaudio_qdev->data->dev, "data ep # %d context is null\n", + subs->data_endpoint->ep_num); + goto exit; + } + + memcpy(ep_desc, &ep->desc, sizeof(ep->desc)); + + ret = xhci_sideband_add_endpoint(uadev[card_num].sb, ep); + if (ret < 0) { + dev_err(&subs->dev->dev, + "failed to add data ep to sideband\n"); + ret = -ENODEV; + goto exit; + } + + sgt = xhci_sideband_get_endpoint_buffer(uadev[card_num].sb, ep); + if (!sgt) { + dev_err(&subs->dev->dev, + "failed to get data ep ring address\n"); + ret = -ENODEV; + goto remove_ep; + } + + pg = sg_page(sgt->sgl); + tr_pa = page_to_phys(pg); + mem_info->pa = sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + /* data transfer ring */ + va = uaudio_iommu_map(MEM_XFER_RING, dma_coherent, tr_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto clear_pa; + } + + mem_info->va = PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size = PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa = 0; +remove_ep: + xhci_sideband_remove_endpoint(uadev[card_num].sb, ep); +exit: + return ret; +} + +/** + * uaudio_event_ring_setup() - fetch and populate event ring params + * @subs: usb substream + * @card_num: uadev index + * @mem_info: QMI response info + * + * Register secondary interrupter to XHCI and fetch the event buffer info + * and populate the information into the QMI response. + * + */ +static int uaudio_event_ring_setup(struct snd_usb_substream *subs, + int card_num, struct mem_info_v01 *mem_info) +{ + struct sg_table *sgt; + phys_addr_t er_pa; + bool dma_coherent; + unsigned long va; + struct page *pg; + int ret; + + dma_coherent = dev_is_dma_coherent(subs->dev->bus->sysdev); + er_pa = 0; + + /* event ring */ + ret = xhci_sideband_create_interrupter(uadev[card_num].sb, 1, false, + 0, uaudio_qdev->data->intr_num); + if (ret < 0) { + dev_err(&subs->dev->dev, "failed to fetch interrupter\n"); + goto exit; + } + + sgt = xhci_sideband_get_event_buffer(uadev[card_num].sb); + if (!sgt) { + dev_err(&subs->dev->dev, + "failed to get event ring address\n"); + ret = -ENODEV; + goto remove_interrupter; + } + + pg = sg_page(sgt->sgl); + er_pa = page_to_phys(pg); + mem_info->pa = sg_dma_address(sgt->sgl); + sg_free_table(sgt); + + va = uaudio_iommu_map(MEM_EVENT_RING, dma_coherent, er_pa, + PAGE_SIZE, NULL); + if (!va) { + ret = -ENOMEM; + goto clear_pa; + } + + mem_info->va = PREPEND_SID_TO_IOVA(va, uaudio_qdev->data->sid); + mem_info->size = PAGE_SIZE; + + return 0; + +clear_pa: + mem_info->pa = 0; +remove_interrupter: + xhci_sideband_remove_interrupter(uadev[card_num].sb); +exit: + return ret; +} + +/** + * uaudio_populate_uac_desc() - parse UAC parameters and populate QMI resp + * @subs: usb substream + * @resp: QMI response buffer + * + * Parses information specified within UAC descriptors which explain the + * sample parameters that the device expects. This information is populated + * to the QMI response sent back to the audio DSP. + * + */ +static int uaudio_populate_uac_desc(struct snd_usb_substream *subs, + struct qmi_uaudio_stream_resp_msg_v01 *resp) +{ + struct usb_interface_descriptor *altsd; + struct usb_host_interface *alts; + struct usb_interface *iface; + int protocol; + + iface = usb_ifnum_to_if(subs->dev, subs->cur_audiofmt->iface); + if (!iface) { + dev_err(&subs->dev->dev, "interface # %d does not exist\n", + subs->cur_audiofmt->iface); + return -ENODEV; + } + + alts = &iface->altsetting[subs->cur_audiofmt->altset_idx]; + altsd = get_iface_desc(alts); + protocol = altsd->bInterfaceProtocol; + + if (protocol == UAC_VERSION_1) { + struct uac1_as_header_descriptor *as; + + as = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, + UAC_AS_GENERAL); + if (!as) { + dev_err(&subs->dev->dev, + "%u:%d : no UAC_AS_GENERAL desc\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + return -ENODEV; + } + + resp->data_path_delay = as->bDelay; + resp->data_path_delay_valid = 1; + + resp->usb_audio_subslot_size = subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(0x0100); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_2) { + resp->usb_audio_subslot_size = subs->cur_audiofmt->fmt_sz; + resp->usb_audio_subslot_size_valid = 1; + + resp->usb_audio_spec_revision = le16_to_cpu(0x0200); + resp->usb_audio_spec_revision_valid = 1; + } else if (protocol == UAC_VERSION_3) { + if (iface->intf_assoc->bFunctionSubClass == + UAC3_FUNCTION_SUBCLASS_FULL_ADC_3_0) { + dev_err(&subs->dev->dev, + "full adc is not supported\n"); + return -EINVAL; + } + + switch (le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize)) { + case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_16: + case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_16: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_16: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_16: { + resp->usb_audio_subslot_size = 0x2; + break; + } + + case UAC3_BADD_EP_MAXPSIZE_SYNC_MONO_24: + case UAC3_BADD_EP_MAXPSIZE_SYNC_STEREO_24: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_MONO_24: + case UAC3_BADD_EP_MAXPSIZE_ASYNC_STEREO_24: { + resp->usb_audio_subslot_size = 0x3; + break; + } + + default: + dev_err(&subs->dev->dev, + "%d: %u: Invalid wMaxPacketSize\n", + subs->cur_audiofmt->iface, + subs->cur_audiofmt->altset_idx); + return -EINVAL; + } + resp->usb_audio_subslot_size_valid = 1; + } else { + dev_err(&subs->dev->dev, "unknown protocol version %x\n", + protocol); + return -ENODEV; + } + + memcpy(&resp->std_as_opr_intf_desc, &alts->desc, sizeof(alts->desc)); + + return 0; +} + +/** + * prepare_qmi_response() - prepare stream enable response + * @subs: usb substream + * @req_msg: QMI request message + * @resp: QMI response buffer + * @info_idx: usb interface array index + * + * Prepares the QMI response for a USB QMI stream enable request. Will parse + * out the parameters within the stream enable request, in order to match + * requested audio profile to the ones exposed by the USB device connected. + * + * In addition, will fetch the XHCI transfer resources needed for the handoff to + * happen. This includes, transfer ring and buffer addresses and secondary event + * ring address. These parameters will be communicated as part of the USB QMI + * stream enable response. + * + */ +static int prepare_qmi_response(struct snd_usb_substream *subs, + struct qmi_uaudio_stream_req_msg_v01 *req_msg, + struct qmi_uaudio_stream_resp_msg_v01 *resp, int info_idx) +{ + struct q6usb_offload *data; + u32 xfer_buf_len; + int pcm_dev_num; + int card_num; + u8 *xfer_buf; + int ret; + + pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + xfer_buf_len = req_msg->xfer_buff_size; + card_num = uaudio_qdev->last_card_num; + + if (!uadev[card_num].ctrl_intf) { + dev_err(&subs->dev->dev, "audio ctrl intf info not cached\n"); + ret = -ENODEV; + goto err; + } + + ret = uaudio_populate_uac_desc(subs, resp); + if (ret < 0) + goto err; + + resp->slot_id = subs->dev->slot_id; + resp->slot_id_valid = 1; + + data = snd_soc_usb_find_priv_data(usb_get_usb_backend(subs->dev)); + if (!data) + goto err; + + uaudio_qdev->data = data; + + resp->std_as_opr_intf_desc_valid = 1; + ret = uaudio_endpoint_setup(subs, subs->data_endpoint, card_num, + &resp->xhci_mem_info.tr_data, + &resp->std_as_data_ep_desc); + if (ret < 0) + goto err; + + resp->std_as_data_ep_desc_valid = 1; + + if (subs->sync_endpoint) { + ret = uaudio_endpoint_setup(subs, subs->sync_endpoint, card_num, + &resp->xhci_mem_info.tr_sync, + &resp->std_as_sync_ep_desc); + if (ret < 0) + goto drop_data_ep; + + resp->std_as_sync_ep_desc_valid = 1; + } + + resp->interrupter_num_valid = 1; + resp->controller_num_valid = 0; + ret = usb_get_controller_id(subs->dev); + if (ret >= 0) { + resp->controller_num = ret; + resp->controller_num_valid = 1; + } + + /* event ring */ + ret = uaudio_event_ring_setup(subs, card_num, + &resp->xhci_mem_info.evt_ring); + if (ret < 0) + goto drop_sync_ep; + + uaudio_qdev->er_mapped = true; + resp->interrupter_num = xhci_sideband_interrupter_id(uadev[card_num].sb); + + resp->speed_info = get_speed_info(subs->dev->speed); + if (resp->speed_info == USB_QMI_DEVICE_SPEED_INVALID_V01) { + ret = -ENODEV; + goto free_sec_ring; + } + + resp->speed_info_valid = 1; + + ret = uaudio_transfer_buffer_setup(subs, xfer_buf, req_msg->xfer_buff_size, + &resp->xhci_mem_info.xfer_buff); + if (ret < 0) { + ret = -ENOMEM; + goto free_sec_ring; + } + + resp->xhci_mem_info_valid = 1; + + if (!atomic_read(&uadev[card_num].in_use)) { + kref_init(&uadev[card_num].kref); + init_waitqueue_head(&uadev[card_num].disconnect_wq); + uadev[card_num].num_intf = + subs->dev->config->desc.bNumInterfaces; + uadev[card_num].info = kcalloc(uadev[card_num].num_intf, + sizeof(struct intf_info), GFP_KERNEL); + if (!uadev[card_num].info) { + ret = -ENOMEM; + goto unmap_er; + } + uadev[card_num].udev = subs->dev; + atomic_set(&uadev[card_num].in_use, 1); + } else { + kref_get(&uadev[card_num].kref); + } + + uadev[card_num].usb_core_id = resp->controller_num; + + /* cache intf specific info to use it for unmap and free xfer buf */ + uadev[card_num].info[info_idx].data_xfer_ring_va = + IOVA_MASK(resp->xhci_mem_info.tr_data.va); + uadev[card_num].info[info_idx].data_xfer_ring_size = PAGE_SIZE; + uadev[card_num].info[info_idx].sync_xfer_ring_va = + IOVA_MASK(resp->xhci_mem_info.tr_sync.va); + uadev[card_num].info[info_idx].sync_xfer_ring_size = PAGE_SIZE; + uadev[card_num].info[info_idx].xfer_buf_va = + IOVA_MASK(resp->xhci_mem_info.xfer_buff.va); + uadev[card_num].info[info_idx].xfer_buf_pa = + resp->xhci_mem_info.xfer_buff.pa; + uadev[card_num].info[info_idx].xfer_buf_size = + resp->xhci_mem_info.xfer_buff.size; + uadev[card_num].info[info_idx].data_ep_pipe = subs->data_endpoint ? + subs->data_endpoint->pipe : 0; + uadev[card_num].info[info_idx].sync_ep_pipe = subs->sync_endpoint ? + subs->sync_endpoint->pipe : 0; + uadev[card_num].info[info_idx].xfer_buf = xfer_buf; + uadev[card_num].info[info_idx].pcm_card_num = card_num; + uadev[card_num].info[info_idx].pcm_dev_num = pcm_dev_num; + uadev[card_num].info[info_idx].direction = subs->direction; + uadev[card_num].info[info_idx].intf_num = subs->cur_audiofmt->iface; + uadev[card_num].info[info_idx].in_use = true; + + set_bit(card_num, &uaudio_qdev->card_slot); + + return 0; + +unmap_er: + uaudio_iommu_unmap(MEM_EVENT_RING, IOVA_BASE, PAGE_SIZE, PAGE_SIZE); +free_sec_ring: + xhci_sideband_remove_interrupter(uadev[card_num].sb); +drop_sync_ep: + if (subs->sync_endpoint) { + uaudio_iommu_unmap(MEM_XFER_RING, + IOVA_MASK(resp->xhci_mem_info.tr_sync.va), + PAGE_SIZE, PAGE_SIZE); + xhci_sideband_remove_endpoint(uadev[card_num].sb, + usb_pipe_endpoint(subs->dev, subs->sync_endpoint->pipe)); + } +drop_data_ep: + uaudio_iommu_unmap(MEM_XFER_RING, IOVA_MASK(resp->xhci_mem_info.tr_data.va), + PAGE_SIZE, PAGE_SIZE); + xhci_sideband_remove_endpoint(uadev[card_num].sb, + usb_pipe_endpoint(subs->dev, subs->data_endpoint->pipe)); + +err: + return ret; +} + +/** + * handle_uaudio_stream_req() - handle stream enable/disable request + * @handle: QMI client handle + * @sq: qrtr socket + * @txn: QMI transaction context + * @decoded_msg: decoded QMI message + * + * Main handler for the QMI stream enable/disable requests. This executes the + * corresponding enable/disable stream apis, respectively. + * + */ +static void handle_uaudio_stream_req(struct qmi_handle *handle, + struct sockaddr_qrtr *sq, + struct qmi_txn *txn, + const void *decoded_msg) +{ + struct qmi_uaudio_stream_req_msg_v01 *req_msg; + struct qmi_uaudio_stream_resp_msg_v01 resp = {{0}, 0}; + struct uaudio_qmi_svc *svc = uaudio_svc; + struct snd_usb_audio *chip = NULL; + struct snd_usb_substream *subs; + struct usb_host_endpoint *ep; + int datainterval = -EINVAL; + int info_idx = -EINVAL; + struct intf_info *info; + u8 pcm_card_num; + u8 pcm_dev_num; + u8 direction; + int ret = 0; + + if (!svc->client_connected) { + svc->client_sq = *sq; + svc->client_connected = true; + } + + mutex_lock(&qdev_mutex); + req_msg = (struct qmi_uaudio_stream_req_msg_v01 *)decoded_msg; + if (!req_msg->audio_format_valid || !req_msg->bit_rate_valid || + !req_msg->number_of_ch_valid || !req_msg->xfer_buff_size_valid) { + ret = -EINVAL; + goto response; + } + + if (!uaudio_qdev) { + ret = -EINVAL; + goto response; + } + + direction = (req_msg->usb_token & QMI_STREAM_REQ_DIRECTION); + pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; + pcm_card_num = req_msg->enable ? uaudio_qdev->last_card_num : + ffs(uaudio_qdev->card_slot) - 1; + if (pcm_card_num >= SNDRV_CARDS) { + ret = -EINVAL; + goto response; + } + + if (req_msg->audio_format > USB_QMI_PCM_FORMAT_U32_BE) { + ret = -EINVAL; + goto response; + } + + subs = find_substream(pcm_card_num, pcm_dev_num, direction); + chip = uadev[pcm_card_num].chip; + if (!subs || !chip || atomic_read(&chip->shutdown)) { + ret = -ENODEV; + goto response; + } + + info_idx = info_idx_from_ifnum(pcm_card_num, subs->cur_audiofmt ? + subs->cur_audiofmt->iface : -1, req_msg->enable); + if (atomic_read(&chip->shutdown) || !subs->stream || !subs->stream->pcm + || !subs->stream->chip) { + ret = -ENODEV; + goto response; + } + + if (req_msg->enable) { + if (info_idx < 0 || chip->system_suspend) { + ret = -EBUSY; + goto response; + } + } + + if (req_msg->service_interval_valid) { + ret = get_data_interval_from_si(subs, + req_msg->service_interval); + if (ret == -EINVAL) + goto response; + + datainterval = ret; + } + + uadev[pcm_card_num].ctrl_intf = chip->ctrl_intf; + + if (req_msg->enable) { + ret = enable_audio_stream(subs, + map_pcm_format(req_msg->audio_format), + req_msg->number_of_ch, req_msg->bit_rate, + datainterval); + + if (!ret) + ret = prepare_qmi_response(subs, req_msg, &resp, + info_idx); + } else { + info = &uadev[pcm_card_num].info[info_idx]; + if (info->data_ep_pipe) { + ep = usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->data_ep_pipe); + if (ep) + xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, ep); + info->data_ep_pipe = 0; + } + + if (info->sync_ep_pipe) { + ep = usb_pipe_endpoint(uadev[pcm_card_num].udev, + info->sync_ep_pipe); + if (ep) + xhci_sideband_stop_endpoint(uadev[pcm_card_num].sb, + ep); + xhci_sideband_remove_endpoint(uadev[pcm_card_num].sb, ep); + info->sync_ep_pipe = 0; + } + + disable_audio_stream(subs); + } + +response: + if (!req_msg->enable && ret != -EINVAL && ret != -ENODEV) { + mutex_lock(&chip->mutex); + if (info_idx >= 0) { + info = &uadev[pcm_card_num].info[info_idx]; + uaudio_dev_intf_cleanup( + uadev[pcm_card_num].udev, + info); + } + if (atomic_read(&uadev[pcm_card_num].in_use)) + kref_put(&uadev[pcm_card_num].kref, + uaudio_dev_release); + mutex_unlock(&chip->mutex); + } + mutex_unlock(&qdev_mutex); + + resp.usb_token = req_msg->usb_token; + resp.usb_token_valid = 1; + resp.internal_status = ret; + resp.internal_status_valid = 1; + resp.status = ret ? USB_QMI_STREAM_REQ_FAILURE_V01 : ret; + resp.status_valid = 1; + ret = qmi_send_response(svc->uaudio_svc_hdl, sq, txn, + QMI_UAUDIO_STREAM_RESP_V01, + QMI_UAUDIO_STREAM_RESP_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_resp_msg_v01_ei, &resp); +} + +static struct qmi_msg_handler uaudio_stream_req_handlers = { + .type = QMI_REQUEST, + .msg_id = QMI_UAUDIO_STREAM_REQ_V01, + .ei = qmi_uaudio_stream_req_msg_v01_ei, + .decoded_size = QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN, + .fn = handle_uaudio_stream_req, +}; + +/** + * qc_usb_audio_offload_init_qmi_dev() - initializes qmi dev + * + * Initializes the USB qdev, which is used to carry information pertaining to + * the offloading resources. This device is freed only when there are no longer + * any offloading candidates. (i.e, when all audio devices are disconnected) + * + */ +static int qc_usb_audio_offload_init_qmi_dev(struct usb_device *udev) +{ + uaudio_qdev = kzalloc(sizeof(struct uaudio_qmi_dev), + GFP_KERNEL); + if (!uaudio_qdev) + return -ENOMEM; + + /* initialize xfer ring and xfer buf iova list */ + INIT_LIST_HEAD(&uaudio_qdev->xfer_ring_list); + uaudio_qdev->curr_xfer_ring_iova = IOVA_XFER_RING_BASE; + uaudio_qdev->xfer_ring_iova_size = + IOVA_XFER_RING_MAX - IOVA_XFER_RING_BASE; + + INIT_LIST_HEAD(&uaudio_qdev->xfer_buf_list); + uaudio_qdev->curr_xfer_buf_iova = IOVA_XFER_BUF_BASE; + uaudio_qdev->xfer_buf_iova_size = + IOVA_XFER_BUF_MAX - IOVA_XFER_BUF_BASE; + + return 0; +} + +/** + * qc_usb_audio_offload_probe() - platform op connect handler + * @chip: USB SND device + * + * Platform connect handler when a USB SND device is detected. Will + * notify SOC USB about the connection to enable the USB ASoC backend + * and populate internal USB chip array. + * + */ +static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) +{ + struct usb_device *udev = chip->dev; + struct snd_soc_usb_device *sdev; + struct xhci_sideband *sb; + + /* + * If there is no priv_data, the connected device is on a USB bus + * that doesn't support offloading. Avoid populating entries for + * this device. + */ + if (!snd_soc_usb_find_priv_data(usb_get_usb_backend(udev))) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + if (!uadev[chip->card->number].chip) { + sdev = kzalloc(sizeof(*sdev), GFP_KERNEL); + if (!sdev) + goto exit; + + sb = xhci_sideband_register(udev); + if (!sb) + goto free_sdev; + } else { + sb = uadev[chip->card->number].sb; + sdev = uadev[chip->card->number].sdev; + } + + if (!uaudio_qdev) + qc_usb_audio_offload_init_qmi_dev(udev); + + atomic_inc(&uaudio_qdev->qdev_in_use); + + uadev[chip->card->number].sb = sb; + uadev[chip->card->number].chip = chip; + + sdev->card_idx = chip->card->number; + sdev->chip_idx = chip->index; + uadev[chip->card->number].sdev = sdev; + + uaudio_qdev->last_card_num = chip->card->number; + snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + + return; + +free_sdev: + kfree(sdev); +exit: + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); +} + +/** + * qc_usb_audio_cleanup_qmi_dev() - release qmi device + * + * Frees the USB qdev. Only occurs when there are no longer any potential + * devices that can utilize USB audio offloading. + * + */ +static void qc_usb_audio_cleanup_qmi_dev(void) +{ + kfree(uaudio_qdev); + uaudio_qdev = NULL; +} + +/** + * qc_usb_audio_offload_disconnect() - platform op disconnect handler + * @chip: USB SND device + * + * Platform disconnect handler. Will ensure that any pending stream is + * halted by issuing a QMI disconnect indication packet to the adsp. + * + */ +static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip) +{ + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind = {0}; + struct uaudio_qmi_svc *svc = uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num = chip->card->number; + if (card_num >= SNDRV_CARDS) + return; + + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + dev = &uadev[card_num]; + + /* Device has already been cleaned up, or never populated */ + if (!dev->chip) { + mutex_unlock(&qdev_mutex); + mutex_unlock(&chip->mutex); + return; + } + + /* cleaned up already */ + if (!dev->udev) + goto done; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + mutex_unlock(&qdev_mutex); + dev_dbg(uaudio_qdev->data->dev, + "sending qmi indication disconnect\n"); + disconnect_ind.dev_event = USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id = dev->udev->slot_id; + disconnect_ind.controller_num = dev->usb_core_id; + disconnect_ind.controller_num_valid = 1; + ret = qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, + QMI_UAUDIO_STREAM_IND_V01, + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_ind_msg_v01_ei, + &disconnect_ind); + if (ret < 0) + dev_err(uaudio_qdev->data->dev, + "qmi send failed with err: %d\n", ret); + + ret = wait_event_interruptible_timeout(dev->disconnect_wq, + !atomic_read(&dev->in_use), + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); + if (!ret) { + dev_err(uaudio_qdev->data->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->data->dev, + "failed with ret %d\n", ret); + atomic_set(&dev->in_use, 0); + } + mutex_lock(&qdev_mutex); + mutex_lock(&chip->mutex); + } + + uaudio_dev_cleanup(dev); +done: + /* + * If num_interfaces == 1, the last USB SND interface is being removed. + * This is to accommodate for devices w/ multiple UAC functions. + */ + if (chip->num_interfaces == 1) { + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + xhci_sideband_unregister(dev->sb); + dev->chip = NULL; + kfree(dev->sdev); + dev->sdev = NULL; + } + mutex_unlock(&chip->mutex); + + atomic_dec(&uaudio_qdev->qdev_in_use); + if (!atomic_read(&uaudio_qdev->qdev_in_use)) + qc_usb_audio_cleanup_qmi_dev(); + + mutex_unlock(&qdev_mutex); +} + +/** + * qc_usb_audio_offload_suspend() - USB offload PM suspend handler + * @intf: USB interface + * @message: suspend type + * + * PM suspend handler to ensure that the USB offloading driver is able to stop + * any pending traffic, so that the bus can be suspended. + * + */ +static void qc_usb_audio_offload_suspend(struct usb_interface *intf, + pm_message_t message) +{ + struct qmi_uaudio_stream_ind_msg_v01 disconnect_ind = {0}; + struct snd_usb_audio *chip = usb_get_intfdata(intf); + struct uaudio_qmi_svc *svc = uaudio_svc; + struct uaudio_dev *dev; + int card_num; + int ret; + + if (!chip) + return; + + card_num = chip->card->number; + if (card_num >= SNDRV_CARDS) + return; + + + mutex_lock(&chip->mutex); + dev = &uadev[card_num]; + + if (atomic_read(&dev->in_use)) { + mutex_unlock(&chip->mutex); + dev_dbg(uaudio_qdev->data->dev, "sending qmi indication suspend\n"); + disconnect_ind.dev_event = USB_QMI_DEV_DISCONNECT_V01; + disconnect_ind.slot_id = dev->udev->slot_id; + disconnect_ind.controller_num = dev->usb_core_id; + disconnect_ind.controller_num_valid = 1; + ret = qmi_send_indication(svc->uaudio_svc_hdl, &svc->client_sq, + QMI_UAUDIO_STREAM_IND_V01, + QMI_UAUDIO_STREAM_IND_MSG_V01_MAX_MSG_LEN, + qmi_uaudio_stream_ind_msg_v01_ei, + &disconnect_ind); + if (ret < 0) + dev_err(uaudio_qdev->data->dev, + "qmi send failed with err: %d\n", ret); + + ret = wait_event_interruptible_timeout(dev->disconnect_wq, + !atomic_read(&dev->in_use), + msecs_to_jiffies(DEV_RELEASE_WAIT_TIMEOUT)); + if (!ret) { + dev_err(uaudio_qdev->data->dev, + "timeout while waiting for dev_release\n"); + atomic_set(&dev->in_use, 0); + } else if (ret < 0) { + dev_err(uaudio_qdev->data->dev, + "failed with ret %d\n", ret); + atomic_set(&dev->in_use, 0); + } + mutex_lock(&chip->mutex); + } + mutex_unlock(&chip->mutex); +} + +static struct snd_usb_platform_ops offload_ops = { + .connect_cb = qc_usb_audio_offload_probe, + .disconnect_cb = qc_usb_audio_offload_disconnect, + .suspend_cb = qc_usb_audio_offload_suspend, +}; + +static int __init qc_usb_audio_offload_init(void) +{ + struct uaudio_qmi_svc *svc; + int ret; + + svc = kzalloc(sizeof(struct uaudio_qmi_svc), GFP_KERNEL); + if (!svc) + return -ENOMEM; + + svc->uaudio_svc_hdl = kzalloc(sizeof(struct qmi_handle), GFP_KERNEL); + if (!svc->uaudio_svc_hdl) { + ret = -ENOMEM; + goto free_svc; + } + + ret = qmi_handle_init(svc->uaudio_svc_hdl, + QMI_UAUDIO_STREAM_REQ_MSG_V01_MAX_MSG_LEN, + &uaudio_svc_ops_options, + &uaudio_stream_req_handlers); + ret = qmi_add_server(svc->uaudio_svc_hdl, UAUDIO_STREAM_SERVICE_ID_V01, + UAUDIO_STREAM_SERVICE_VERS_V01, 0); + + uaudio_svc = svc; + + ret = snd_usb_register_platform_ops(&offload_ops); + if (ret < 0) + goto release_qmi; + + return 0; + +release_qmi: + qmi_handle_release(svc->uaudio_svc_hdl); +free_svc: + kfree(svc); + + return ret; +} + +static void __exit qc_usb_audio_offload_exit(void) +{ + struct uaudio_qmi_svc *svc = uaudio_svc; + int idx; + + /* + * Remove all connected devices after unregistering ops, to ensure + * that no further connect events will occur. The disconnect routine + * will issue the QMI disconnect indication, which results in the + * external DSP to stop issuing transfers. + */ + snd_usb_unregister_platform_ops(); + for (idx = 0; idx < SNDRV_CARDS; idx++) + qc_usb_audio_offload_disconnect(uadev[idx].chip); + + qmi_handle_release(svc->uaudio_svc_hdl); + kfree(svc); + uaudio_svc = NULL; +} + +module_init(qc_usb_audio_offload_init); +module_exit(qc_usb_audio_offload_exit); + +MODULE_DESCRIPTION("QC USB Audio Offloading"); +MODULE_LICENSE("GPL");
Allow for checks on a specific USB audio device to see if a requested PCM format is supported. This is needed for support when playback is initiated by the ASoC USB backend path.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.c | 31 +++++++++++++++++++++++++++++++ sound/usb/card.h | 3 +++ 2 files changed, 34 insertions(+)
diff --git a/sound/usb/card.c b/sound/usb/card.c index 8f1051e1716e..fb548a3abcfc 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -155,6 +155,37 @@ int snd_usb_unregister_platform_ops(void) } EXPORT_SYMBOL_GPL(snd_usb_unregister_platform_ops);
+/* + * Checks to see if requested audio profile, i.e sample rate, # of + * channels, etc... is supported by the substream associated to the + * USB audio device. + */ +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction) +{ + struct snd_usb_audio *chip; + struct snd_usb_substream *subs; + struct snd_usb_stream *as; + + /* + * Register mutex is held when populating and clearing usb_chip + * array. + */ + guard(mutex)(®ister_mutex); + chip = usb_chip[card_idx]; + + if (chip && enable[card_idx]) { + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &as->substream[direction]; + if (snd_usb_find_substream_format(subs, params)) + return as; + } + } + + return NULL; +} +EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index 02e4ea898db5..d66cc0b139af 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -217,4 +217,7 @@ struct snd_usb_platform_ops {
int snd_usb_register_platform_ops(struct snd_usb_platform_ops *ops); int snd_usb_unregister_platform_ops(void); + +struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, + struct snd_pcm_hw_params *params, int direction); #endif /* __USBAUDIO_CARD_H */
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(+)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index e8fe4439c234..4b1b992c8b27 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_supported_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_supported_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 8490715791a5..3bb66808f196 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -74,6 +74,31 @@ void *snd_soc_usb_find_priv_data(struct device *dev) } EXPORT_SYMBOL_GPL(snd_soc_usb_find_priv_data);
+/** + * snd_soc_usb_find_supported_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_supported_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_supported_format); + /** * snd_soc_usb_allocate_port() - allocate a SOC USB device * @component: USB DPCM backend DAI component
Check for if the PCM format is supported during the hw_params callback. If the profile is not supported then the userspace ALSA entity will receive an error, and can take further action.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6usb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index aa36f490ed47..ab79a293083e 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -46,7 +46,11 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params, struct snd_soc_dai *dai) { - return 0; + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + int direction = substream->stream; + + return snd_soc_usb_find_supported_format(data->active_usb_chip_idx, + params, direction); }
static const struct snd_soc_dai_ops q6usb_ops = {
With USB audio offloading, an audio session is started from the ASoC platform sound card and PCM devices. Likewise, the USB SND path is still readily available for use, in case the non-offload path is desired. In order to prevent the two entities from attempting to use the USB bus, introduce a flag that determines when either paths are in use.
If a PCM device is already in use, the check will return an error to userspace notifying that the stream is currently busy. This ensures that only one path is using the USB substream.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.h | 1 + sound/usb/pcm.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 3 deletions(-)
diff --git a/sound/usb/card.h b/sound/usb/card.h index d66cc0b139af..3c900e5afbce 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -165,6 +165,7 @@ struct snd_usb_substream { unsigned int pkt_offset_adj; /* Bytes to drop from beginning of packets (for non-compliant devices) */ unsigned int stream_offset_adj; /* Bytes to drop from beginning of stream (for non-compliant devices) */
+ unsigned int opened:1; /* pcm device opened */ unsigned int running: 1; /* running status */ unsigned int period_elapsed_pending; /* delay period handling */
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c index 3adb09ce1702..3e6d33de6ce6 100644 --- a/sound/usb/pcm.c +++ b/sound/usb/pcm.c @@ -1241,8 +1241,17 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream) struct snd_usb_stream *as = snd_pcm_substream_chip(substream); struct snd_pcm_runtime *runtime = substream->runtime; struct snd_usb_substream *subs = &as->substream[direction]; + struct snd_usb_audio *chip = subs->stream->chip; int ret;
+ mutex_lock(&chip->mutex); + if (subs->opened) { + mutex_unlock(&chip->mutex); + return -EBUSY; + } + subs->opened = 1; + mutex_unlock(&chip->mutex); + runtime->hw = snd_usb_hardware; /* need an explicit sync to catch applptr update in low-latency mode */ if (direction == SNDRV_PCM_STREAM_PLAYBACK && @@ -1259,13 +1268,23 @@ static int snd_usb_pcm_open(struct snd_pcm_substream *substream)
ret = setup_hw_info(runtime, subs); if (ret < 0) - return ret; + goto err_open; ret = snd_usb_autoresume(subs->stream->chip); if (ret < 0) - return ret; + goto err_open; ret = snd_media_stream_init(subs, as->pcm, direction); if (ret < 0) - snd_usb_autosuspend(subs->stream->chip); + goto err_resume; + + return 0; + +err_resume: + snd_usb_autosuspend(subs->stream->chip); +err_open: + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); + return ret; }
@@ -1274,6 +1293,7 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream) int direction = substream->stream; struct snd_usb_stream *as = snd_pcm_substream_chip(substream); struct snd_usb_substream *subs = &as->substream[direction]; + struct snd_usb_audio *chip = subs->stream->chip; int ret;
snd_media_stop_pipeline(subs); @@ -1287,6 +1307,9 @@ static int snd_usb_pcm_close(struct snd_pcm_substream *substream)
subs->pcm_substream = NULL; snd_usb_autosuspend(subs->stream->chip); + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex);
return 0; }
Add proper checks and updates to the USB substream once receiving a USB QMI stream enable request. If the substream is already in use from the non offload path, reject the stream enable request. In addition, update the USB substream opened parameter when enabling the offload path, so the non offload path can be blocked.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/qcom/qc_audio_offload.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index eda16d6df0d7..648b97aeae1d 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1460,12 +1460,17 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, goto response; }
+ mutex_lock(&chip->mutex); if (req_msg->enable) { - if (info_idx < 0 || chip->system_suspend) { + if (info_idx < 0 || chip->system_suspend || subs->opened) { ret = -EBUSY; + mutex_unlock(&chip->mutex); + goto response; } + subs->opened = 1; } + mutex_unlock(&chip->mutex);
if (req_msg->service_interval_valid) { ret = get_data_interval_from_si(subs, @@ -1487,6 +1492,11 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, if (!ret) ret = prepare_qmi_response(subs, req_msg, &resp, info_idx); + if (ret < 0) { + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); + } } else { info = &uadev[pcm_card_num].info[info_idx]; if (info->data_ep_pipe) { @@ -1510,6 +1520,9 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle, }
disable_audio_stream(subs); + mutex_lock(&chip->mutex); + subs->opened = 0; + mutex_unlock(&chip->mutex); }
response:
On 6/11/2024 1:57 AM, Wesley Cheng wrote:
Add proper checks and updates to the USB substream once receiving a USB QMI stream enable request. If the substream is already in use from the non offload path, reject the stream enable request. In addition, update the USB substream opened parameter when enabling the offload path, so the non offload path can be blocked.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com
sound/usb/qcom/qc_audio_offload.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
Patch title is missing qcom part and it clearly touches QCOM code. ALSA: usb-audio: qcom:
Add an example on enabling of USB offload for the Q6DSP. The routing can be done by the mixer, which can pass the multimedia stream to the USB backend.
Acked-by: Rob Herring robh@kernel.org Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- .../devicetree/bindings/sound/qcom,sm8250.yaml | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
diff --git a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml index b2e15ebbd1bc..f2d708f899bf 100644 --- a/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml +++ b/Documentation/devicetree/bindings/sound/qcom,sm8250.yaml @@ -229,6 +229,21 @@ examples: sound-dai = <&vamacro 0>; }; }; + + usb-dai-link { + link-name = "USB Playback"; + cpu { + sound-dai = <&q6afedai USB_RX>; + }; + + codec { + sound-dai = <&usbdai USB_RX>; + }; + + platform { + sound-dai = <&q6routing>; + }; + }; };
- |
Currently, only the index to the USB SND card array is passed to the USB backend. Pass through more information, specifically the USB SND card number and the number of PCM devices available. This allows for the DPCM backend to determine what USB resources are available during situations, such as USB audio offloading.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/qcom/qc_audio_offload.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+)
diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 648b97aeae1d..1a45bc289f90 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -170,6 +170,21 @@ enum usb_qmi_audio_format { USB_QMI_PCM_FORMAT_U32_BE, };
+static int usb_qmi_get_pcm_num(struct snd_usb_audio *chip, int direction) +{ + struct snd_usb_substream *subs = NULL; + struct snd_usb_stream *as; + int count = 0; + + list_for_each_entry(as, &chip->pcm_list, list) { + subs = &as->substream[direction]; + if (subs->ep_num) + count++; + } + + return count; +} + static enum usb_qmi_audio_device_speed_enum_v01 get_speed_info(enum usb_device_speed udev_speed) { @@ -1638,6 +1653,8 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip)
sdev->card_idx = chip->card->number; sdev->chip_idx = chip->index; + sdev->num_playback = usb_qmi_get_pcm_num(chip, 0); + sdev->num_capture = usb_qmi_get_pcm_num(chip, 1); uadev[chip->card->number].sdev = sdev;
uaudio_qdev->last_card_num = chip->card->number;
The USB backend should know about which sound resources are being shared between the ASoC and USB SND paths. This can be utilized to properly select and maintain the offloading devices.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6usb.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index ab79a293083e..f1fa75c0ba5b 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -27,11 +27,18 @@
#define Q6_USB_SID_MASK 0xF
+struct q6usb_status { + struct snd_soc_usb_device *sdev; + unsigned int pcm_index; +}; + struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; int active_usb_chip_idx; + unsigned long available_card_slot; + struct q6usb_status status[SNDRV_CARDS]; };
static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { @@ -113,6 +120,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, if (connected) { /* Selects the latest USB headset plugged in for offloading */ data->active_usb_chip_idx = sdev->card_idx; + + set_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].sdev = sdev; + } else { + clear_bit(sdev->card_idx, &data->available_card_slot); + data->status[sdev->card_idx].sdev = NULL; }
return 0;
Add SND kcontrol to SOC USB, which will allow for userpsace to determine which USB card number and PCM device to offload. This allows for userspace to potentially tag an alternate path for a specific USB SND card and PCM device. Previously, control was absent, and the offload path would be enabled on the last USB SND device which was connected. This logic will continue to be applicable if no mixer input is received for specific device selection.
An example to configure the offload device using tinymix: tinymix -D 0 set 'USB Offload Playback Route Card Select' 1 tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0
The above command will configure the offload path to utilize card#1 and PCM stream#0.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/soc-usb.h | 16 ++++ sound/soc/soc-usb.c | 167 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 4b1b992c8b27..495de5143db8 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -6,6 +6,12 @@ #ifndef __LINUX_SND_SOC_USB_H #define __LINUX_SND_SOC_USB_H
+enum snd_soc_usb_kctl { + SND_SOC_USB_KCTL_CARD_ROUTE, + SND_SOC_USB_KCTL_PCM_ROUTE, + SND_SOC_USB_KCTL_MAX, +}; + /** * struct snd_soc_usb_device * @card_idx - sound card index associated with USB device @@ -24,16 +30,26 @@ struct snd_soc_usb_device { * struct snd_soc_usb * @list - list head for SND SOC struct list * @component - reference to ASoC component + * @kctl - list of kcontrols created * @num_supported_streams - number of supported concurrent sessions * @connection_status_cb - callback to notify connection events + * @put_offload_dev - callback to select USB sound card/PCM device + * @get_offload_dev - callback to fetch selected USB sound card/PCM device * @priv_data - driver data **/ struct snd_soc_usb { struct list_head list; struct snd_soc_component *component; + struct snd_kcontrol *kctl[SND_SOC_USB_KCTL_MAX]; unsigned int num_supported_streams; int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); + int (*put_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, + enum snd_soc_usb_kctl type); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, + enum snd_soc_usb_kctl type); void *priv_data; };
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index 3bb66808f196..ef84957014dd 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -15,6 +15,9 @@ static struct device_node *snd_soc_find_phandle(struct device *dev) { struct device_node *node;
+ if (!dev) + return ERR_PTR(-ENODEV); + node = of_parse_phandle(dev->of_node, "usb-soc-be", 0); if (!node) return ERR_PTR(-ENODEV); @@ -57,6 +60,162 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev) return ctx ? ctx : NULL; }
+/* SOC USB sound kcontrols */ +static int soc_usb_put_offload_pcm_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_PCM_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_pcm_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int ret = 0; + int i; + + for (i = 0; i < ctx->num_supported_streams; i++) + ucontrol->value.integer.value[i] = -1; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_PCM_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_put_offload_card_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int ret = 0; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->put_offload_dev) + ret = ctx->put_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_CARD_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; +} + +static int soc_usb_get_offload_card_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int ret = 0; + int i; + + for (i = 0; i < ctx->num_supported_streams; i++) + ucontrol->value.integer.value[i] = -1; + + mutex_lock(&ctx_mutex); + if (ctx && ctx->get_offload_dev) + ret = ctx->get_offload_dev(kcontrol, ucontrol, + SND_SOC_USB_KCTL_CARD_ROUTE); + mutex_unlock(&ctx_mutex); + + return ret; + +} + +static int soc_usb_offload_pcm_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = ctx->num_supported_streams; + uinfo->value.integer.min = -1; + /* Arbitrary max value, as there is no 'limit' on number of PCM devices */ + uinfo->value.integer.max = 0xff; + + return 0; +} + +static int soc_usb_offload_card_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = ctx->num_supported_streams; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static const struct snd_kcontrol_new soc_usb_kcontrols[] = { + [SND_SOC_USB_KCTL_CARD_ROUTE] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "USB Offload Playback Route Card Select", + .info = soc_usb_offload_card_info, + .get = soc_usb_get_offload_card_dev, + .put = soc_usb_put_offload_card_dev, + }, + [SND_SOC_USB_KCTL_PCM_ROUTE] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READWRITE, + .name = "USB Offload Playback Route PCM Select", + .info = soc_usb_offload_pcm_info, + .get = soc_usb_get_offload_pcm_dev, + .put = soc_usb_put_offload_pcm_dev, + }, +}; + +static int snd_soc_usb_control_remove(struct snd_soc_usb *usb) +{ + struct snd_soc_component *component = usb->component; + int i; + + for (i = 0; i < SND_SOC_USB_KCTL_MAX; i++) { + if (usb->kctl[i]) { + snd_ctl_remove(component->card->snd_card, + usb->kctl[i]); + snd_ctl_free_one(usb->kctl[i]); + usb->kctl[i] = NULL; + } + } + + return 0; +} + +static int snd_soc_usb_control_init(struct snd_soc_usb *usb) +{ + struct snd_soc_component *component = usb->component; + int ret; + int i; + + for (i = 0; i < SND_SOC_USB_KCTL_MAX; i++) { + usb->kctl[i] = snd_ctl_new1(&soc_usb_kcontrols[i], component); + ret = snd_ctl_add(component->card->snd_card, usb->kctl[i]); + if (ret < 0) + return ret; + } + + return ret; +} + /** * snd_soc_usb_find_priv_data() - Retrieve private data stored * @dev: device reference @@ -152,6 +311,12 @@ EXPORT_SYMBOL_GPL(snd_soc_usb_free_port); */ void snd_soc_usb_add_port(struct snd_soc_usb *usb) { + int ret; + + ret = snd_soc_usb_control_init(usb); + if (ret < 0) + return; + mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); @@ -178,6 +343,8 @@ void snd_soc_usb_remove_port(struct snd_soc_usb *usb) } } mutex_unlock(&ctx_mutex); + + snd_soc_usb_control_remove(usb); } EXPORT_SYMBOL_GPL(snd_soc_usb_remove_port);
In order for device selection to be supported, the Q6USB backend DAI link will need to be notified about the device to start the offloading session on. Device selection is made possible by setting the Q6AFE device token. The audio DSP utilizes this parameter, and will pass this field back to the USB offload driver within the QMI stream requests.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6usb.c | 115 +++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index f1fa75c0ba5b..5877f132f5f5 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -36,9 +36,12 @@ struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; struct q6usb_offload priv; - int active_usb_chip_idx; + struct mutex mutex; unsigned long available_card_slot; struct q6usb_status status[SNDRV_CARDS]; + bool idx_valid; + int sel_card_idx; + int sel_pcm_idx; };
static const struct snd_soc_dapm_widget q6usb_dai_widgets[] = { @@ -54,10 +57,34 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *dai) { struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct q6afe_port *q6usb_afe; int direction = substream->stream; + int chip_idx; + int ret; + + mutex_lock(&data->mutex); + chip_idx = data->status[data->sel_card_idx].sdev->chip_idx; + + ret = snd_soc_usb_find_supported_format(chip_idx, params, direction); + if (ret < 0) + goto out; + + q6usb_afe = q6afe_port_get_from_id(cpu_dai->dev, USB_RX); + if (IS_ERR(q6usb_afe)) + goto out;
- return snd_soc_usb_find_supported_format(data->active_usb_chip_idx, - params, direction); + ret = afe_port_send_usb_dev_param(q6usb_afe, data->sel_card_idx, + data->sel_pcm_idx); + if (ret < 0) + goto out; + + data->status[data->sel_card_idx].pcm_index = data->sel_pcm_idx; +out: + mutex_unlock(&data->mutex); + + return ret; }
static const struct snd_soc_dai_ops q6usb_ops = { @@ -88,6 +115,70 @@ static struct snd_soc_dai_driver q6usb_be_dais[] = { }, };
+static int q6usb_get_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, + enum snd_soc_usb_kctl type) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + int idx; + + mutex_lock(&data->mutex); + + if (!data->available_card_slot) { + idx = -1; + } else { + if (type == SND_SOC_USB_KCTL_CARD_ROUTE) + idx = data->sel_card_idx; + else + idx = data->sel_pcm_idx; + } + + ucontrol->value.integer.value[0] = idx; + mutex_unlock(&data->mutex); + + return 0; +} + +static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol, + enum snd_soc_usb_kctl type) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + int changed = 0; + int idx; + + idx = ucontrol->value.integer.value[0]; + + mutex_lock(&data->mutex); + switch (type) { + case SND_SOC_USB_KCTL_CARD_ROUTE: + if (idx >= 0 && test_bit(idx, &data->available_card_slot)) { + data->sel_card_idx = idx; + changed = 1; + } + break; + case SND_SOC_USB_KCTL_PCM_ROUTE: + if (idx >= 0 && data->sel_card_idx >= 0 && + idx < data->status[data->sel_card_idx].sdev->num_playback) { + data->sel_pcm_idx = idx; + changed = 1; + } + break; + default: + break; + } + + if (changed) + data->idx_valid = true; + +out: + mutex_unlock(&data->mutex); + + return changed; +} + static int q6usb_audio_ports_of_xlate_dai_name(struct snd_soc_component *component, const struct of_phandle_args *args, const char **dai_name) @@ -117,16 +208,28 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
data = dev_get_drvdata(usb->component->dev);
+ mutex_lock(&data->mutex); if (connected) { /* Selects the latest USB headset plugged in for offloading */ - data->active_usb_chip_idx = sdev->card_idx; + if (!data->idx_valid) { + data->sel_card_idx = sdev->card_idx; + data->sel_pcm_idx = 0; + }
set_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].sdev = sdev; } else { clear_bit(sdev->card_idx, &data->available_card_slot); data->status[sdev->card_idx].sdev = NULL; + + if (data->sel_card_idx == sdev->card_idx) { + data->idx_valid = false; + data->sel_card_idx = data->available_card_slot ? + ffs(data->available_card_slot) - 1 : 0; + data->sel_pcm_idx = 0; + } } + mutex_unlock(&data->mutex);
return 0; } @@ -141,6 +244,8 @@ static int q6usb_component_probe(struct snd_soc_component *component) return -ENOMEM;
usb->connection_status_cb = q6usb_alsa_connection_cb; + usb->put_offload_dev = q6usb_put_offload_dev; + usb->get_offload_dev = q6usb_get_offload_dev;
snd_soc_usb_add_port(usb); data->usb = usb; @@ -194,6 +299,8 @@ static int q6usb_dai_dev_probe(struct platform_device *pdev)
data->priv.domain = iommu_get_domain_for_dev(&pdev->dev);
+ mutex_init(&data->mutex); + data->priv.dev = dev; dev_set_drvdata(dev, data);
Expose helpers in the SoC USB layer so components can update and keep track of the offloading sessions. This exposes a kcontrol to userspace, so that applications can be aware of what the current USB offloading status is. An example output using tinymix is:
USB offloading idle: tinymix -D 0 get 'USB Offload Playback Route Card Status' -->-1 (range -1->32) tinymix -D 0 get 'USB Offload Playback Route PCM Status' -->-1 (range -1->255)
USB offloading active(USB card#1 pcm#0): tinymix -D 0 get 'USB Offload Playback Route Card Status' -->1 (range -1->32) tinymix -D 0 get 'USB Offload Playback Route PCM Status' -->0 (range -1->255)
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/soc-usb.h | 46 ++++++++++ sound/soc/soc-usb.c | 193 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 239 insertions(+)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 495de5143db8..c5aecdd0b006 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -9,9 +9,29 @@ enum snd_soc_usb_kctl { SND_SOC_USB_KCTL_CARD_ROUTE, SND_SOC_USB_KCTL_PCM_ROUTE, + SND_SOC_USB_KCTL_CARD_STATUS, + SND_SOC_USB_KCTL_PCM_STATUS, SND_SOC_USB_KCTL_MAX, };
+enum snd_soc_usb_dai_state { + SND_SOC_USB_IDLE, + SND_SOC_USB_PREPARED, + SND_SOC_USB_RUNNING, +}; + +/** + * struct snd_soc_usb_session + * @active_card_idx - active offloaded sound card + * @active_pcm_idx - active offloaded PCM device + * @state - USB BE DAI link PCM state + */ +struct snd_soc_usb_session { + int active_card_idx; + int active_pcm_idx; + enum snd_soc_usb_dai_state state; +}; + /** * struct snd_soc_usb_device * @card_idx - sound card index associated with USB device @@ -31,6 +51,7 @@ struct snd_soc_usb_device { * @list - list head for SND SOC struct list * @component - reference to ASoC component * @kctl - list of kcontrols created + * @active_list - active sessions * @num_supported_streams - number of supported concurrent sessions * @connection_status_cb - callback to notify connection events * @put_offload_dev - callback to select USB sound card/PCM device @@ -41,6 +62,7 @@ struct snd_soc_usb { struct list_head list; struct snd_soc_component *component; struct snd_kcontrol *kctl[SND_SOC_USB_KCTL_MAX]; + struct snd_soc_usb_session *active_list; unsigned int num_supported_streams; int (*connection_status_cb)(struct snd_soc_usb *usb, struct snd_soc_usb_device *sdev, bool connected); @@ -62,6 +84,11 @@ 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 *dev);
+int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); +int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); +int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state); + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, int num_streams, void *data); void snd_soc_usb_free_port(struct snd_soc_usb *usb); @@ -97,6 +124,25 @@ static inline void *snd_soc_usb_find_priv_data(struct device *dev) return NULL; }
+static inline int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, + int pcm_idx) +{ + return -EINVAL; +} + +static inline int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, + int session_id) +{ + return -EINVAL; +} + +static inline int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, + int session_id, + enum snd_soc_usb_dai_state state) +{ + return -EINVAL; +} + static inline struct snd_soc_usb *snd_soc_usb_allocate_port( struct snd_soc_component *component, int num_streams, void *data) diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index ef84957014dd..faacae8a6a5c 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -61,6 +61,79 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev) }
/* SOC USB sound kcontrols */ +static int snd_soc_usb_get_offload_card_status(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int control_idx = 0; + int card_idx; + int i; + + for (i = 0; i < ctx->num_supported_streams; i++) { + card_idx = -1; + + if (ctx->active_list[i].state == SND_SOC_USB_RUNNING) + card_idx = ctx->active_list[i].active_card_idx; + + ucontrol->value.integer.value[control_idx] = card_idx; + control_idx++; + } + + return 0; +} + +static int snd_soc_usb_offload_card_status_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = ctx->num_supported_streams; + uinfo->value.integer.min = -1; + uinfo->value.integer.max = SNDRV_CARDS; + + return 0; +} + +static int snd_soc_usb_get_offload_pcm_status(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + int control_idx = 0; + int pcm_idx; + int i; + + for (i = 0; i < ctx->num_supported_streams; i++) { + pcm_idx = -1; + + if (ctx->active_list[i].state == SND_SOC_USB_RUNNING) + pcm_idx = ctx->active_list[i].active_pcm_idx; + + ucontrol->value.integer.value[control_idx] = pcm_idx; + control_idx++; + } + + return 0; +} + +static int snd_soc_usb_offload_pcm_status_info(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_info *uinfo) +{ + struct snd_soc_component *component = snd_kcontrol_chip(kcontrol); + struct snd_soc_usb *ctx = snd_soc_usb_ctx_lookup(component->dev->of_node); + + uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; + uinfo->count = ctx->num_supported_streams; + uinfo->value.integer.min = -1; + /* Arbitrary max value, as there is no 'limit' on number of PCM devices */ + uinfo->value.integer.max = 0xff; + + return 0; +} + static int soc_usb_put_offload_pcm_dev(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -181,6 +254,22 @@ static const struct snd_kcontrol_new soc_usb_kcontrols[] = { .get = soc_usb_get_offload_pcm_dev, .put = soc_usb_put_offload_pcm_dev, }, + [SND_SOC_USB_KCTL_CARD_STATUS] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Route Card Status", + .info = snd_soc_usb_offload_card_status_info, + .get = snd_soc_usb_get_offload_card_status, + .put = NULL, + }, + [SND_SOC_USB_KCTL_PCM_STATUS] = { + .iface = SNDRV_CTL_ELEM_IFACE_CARD, + .access = SNDRV_CTL_ELEM_ACCESS_READ, + .name = "USB Offload Playback Route PCM Status", + .info = snd_soc_usb_offload_pcm_status_info, + .get = snd_soc_usb_get_offload_pcm_status, + .put = NULL, + }, };
static int snd_soc_usb_control_remove(struct snd_soc_usb *usb) @@ -216,6 +305,102 @@ static int snd_soc_usb_control_init(struct snd_soc_usb *usb) return ret; }
+/** + * snd_soc_usb_set_session_state() - Set the session state for a session + * @usb: SOC USB device + * @session_id: index to active_list + * @state: USB PCM device index + * + * Set the session state for an entry in active_list. This should be only + * called after snd_soc_usb_prepare_session. + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state) +{ + if (session_id < 0 || session_id >= usb->num_supported_streams) + return -EINVAL; + + mutex_lock(&ctx_mutex); + if (usb->active_list[session_id].state == state) { + mutex_unlock(&ctx_mutex); + return 0; + } + + usb->active_list[session_id].state = state; + mutex_unlock(&ctx_mutex); + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_set_session_state); + +/** + * snd_soc_usb_prepare_session() - Find and prepare a session + * @usb: SOC USB device + * @card_idx: USB card index + * @pcm_idx: USB PCM device index + * + * Find an open active session slot on the SOC USB device. If all slots + * are busy, return an error. If not, claim the slot and place it into + * the SND_SOC_USB_PREPARED state. This should be called first before + * calling snd_soc_usb_set_session_state or snd_soc_usb_shutdown_session. + * + * Returns the session id (index) to active_list, negative on error. + * + */ +int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx) +{ + int i; + + mutex_lock(&ctx_mutex); + for (i = 0; i < usb->num_supported_streams; i++) { + if (usb->active_list[i].state == SND_SOC_USB_IDLE) { + usb->active_list[i].active_card_idx = card_idx; + usb->active_list[i].active_pcm_idx = pcm_idx; + usb->active_list[i].state = SND_SOC_USB_PREPARED; + mutex_unlock(&ctx_mutex); + return i; + } + } + mutex_unlock(&ctx_mutex); + + return -EBUSY; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_prepare_session); + +/** + * snd_soc_usb_shutdown_session() - Set USB SOC to idle state + * @usb: SOC USB device + * @session_id: index to active_list + * + * Place the session specified by session_id into the idle/shutdown state. + * + */ +int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id) +{ + return snd_soc_usb_set_session_state(usb, session_id, SND_SOC_USB_IDLE); +} +EXPORT_SYMBOL_GPL(snd_soc_usb_shutdown_session); + +/** + * snd_soc_usb_get_components_tag() - Retrieve SOC USB component tag + * @playback: direction of audio stream + * + * Returns the USB offload component tag used in the ASoC components + * string. + * + */ +const char *snd_soc_usb_get_components_tag(bool playback) +{ + if (playback) + return "usbplaybackoffload: 1"; + else + return "usbcaptureoffload : 1"; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_get_components_tag); + /** * snd_soc_usb_find_priv_data() - Retrieve private data stored * @dev: device reference @@ -277,6 +462,13 @@ struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *componen if (!usb) return ERR_PTR(-ENOMEM);
+ usb->active_list = kcalloc(num_streams, sizeof(struct snd_soc_usb_session), + GFP_KERNEL); + if (!usb->active_list) { + kfree(usb); + return ERR_PTR(-ENOMEM); + } + usb->component = component; usb->priv_data = data; usb->num_supported_streams = num_streams; @@ -295,6 +487,7 @@ EXPORT_SYMBOL_GPL(snd_soc_usb_allocate_port); void snd_soc_usb_free_port(struct snd_soc_usb *usb) { snd_soc_usb_remove_port(usb); + kfree(usb->active_list); kfree(usb); } EXPORT_SYMBOL_GPL(snd_soc_usb_free_port);
Register PCM callbacks so that the Q6USB DPCM backend dai link can track and update the status of the PCM device. Utilize the SOC USB state APIs to ensure that the SND kcontrol for the offload status is updated properly.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/qdsp6/q6usb.c | 52 +++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-)
diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 5877f132f5f5..2715ac920273 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -30,6 +30,9 @@ struct q6usb_status { struct snd_soc_usb_device *sdev; unsigned int pcm_index; + bool prepared; + bool running; + int session_id; };
struct q6usb_port_data { @@ -81,14 +84,48 @@ static int q6usb_hw_params(struct snd_pcm_substream *substream, goto out;
data->status[data->sel_card_idx].pcm_index = data->sel_pcm_idx; + data->status[data->sel_card_idx].prepared = true; + data->status[data->sel_card_idx].session_id = + snd_soc_usb_prepare_session(data->usb, data->sel_card_idx, + data->sel_pcm_idx); out: mutex_unlock(&data->mutex);
return ret; }
+static int q6usb_prepare(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = true; + snd_soc_usb_set_session_state(data->usb, + data->status[data->sel_card_idx].session_id, + SND_SOC_USB_RUNNING); + mutex_unlock(&data->mutex); + + return 0; +} + +static void q6usb_shutdown(struct snd_pcm_substream *substream, + struct snd_soc_dai *dai) +{ + struct q6usb_port_data *data = dev_get_drvdata(dai->dev); + + mutex_lock(&data->mutex); + data->status[data->sel_card_idx].running = false; + data->status[data->sel_card_idx].prepared = false; + snd_soc_usb_shutdown_session(data->usb, + data->status[data->sel_card_idx].session_id); + mutex_unlock(&data->mutex); +} + static const struct snd_soc_dai_ops q6usb_ops = { .hw_params = q6usb_hw_params, + .prepare = q6usb_prepare, + .shutdown = q6usb_shutdown, };
static struct snd_soc_dai_driver q6usb_be_dais[] = { @@ -149,9 +186,14 @@ static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, int changed = 0; int idx;
+ mutex_lock(&data->mutex); + + /* Don't allow changes to the offloading devices if session is busy */ + if (data->sel_card_idx >= 0 && data->status[data->sel_card_idx].prepared) + goto out; + idx = ucontrol->value.integer.value[0];
- mutex_lock(&data->mutex); switch (type) { case SND_SOC_USB_KCTL_CARD_ROUTE: if (idx >= 0 && test_bit(idx, &data->available_card_slot)) { @@ -210,8 +252,12 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
mutex_lock(&data->mutex); if (connected) { - /* Selects the latest USB headset plugged in for offloading */ - if (!data->idx_valid) { + /* + * Select the latest USB headset plugged in, if session is + * idle, and if no index selected by the kcontrol. + */ + if (!data->idx_valid && + !data->status[data->sel_card_idx].prepared) { data->sel_card_idx = sdev->card_idx; data->sel_pcm_idx = 0; }
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.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/soc-usb.h | 16 +++++++++++ sound/soc/soc-usb.c | 62 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 1 deletion(-)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index c5aecdd0b006..8e94c1991819 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -6,6 +6,8 @@ #ifndef __LINUX_SND_SOC_USB_H #define __LINUX_SND_SOC_USB_H
+#include <sound/soc.h> + enum snd_soc_usb_kctl { SND_SOC_USB_KCTL_CARD_ROUTE, SND_SOC_USB_KCTL_PCM_ROUTE, @@ -88,6 +90,9 @@ int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_i int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, enum snd_soc_usb_dai_state state); +int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack); +int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component);
struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, int num_streams, void *data); @@ -143,6 +148,17 @@ static inline int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, return -EINVAL; }
+static inline int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +{ + return -ENODEV; +} + +static inline int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component) +{ + return -ENODEV; +} + static inline struct snd_soc_usb *snd_soc_usb_allocate_port( struct snd_soc_component *component, int num_streams, void *data) diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index faacae8a6a5c..0baba34910b5 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -4,8 +4,10 @@ */ #include <linux/of.h> #include <linux/usb.h> -#include <sound/soc.h> + +#include <sound/jack.h> #include <sound/soc-usb.h> + #include "../usb/card.h"
static DEFINE_MUTEX(ctx_mutex); @@ -61,6 +63,64 @@ static struct snd_soc_usb *snd_soc_find_usb_ctx(struct device *dev) }
/* 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 Playback Jack", + SND_JACK_HEADPHONE, jack); + if (ret < 0) { + dev_err(component->card->dev, "Unable to add USB offload jack\n"); + 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_disable_offload_jack() - Disables USB offloading jack + * @component: USB DPCM backend DAI component + * @jack: jack structure to disable + * + * Disables the offload jack device, so that further connection events + * won't be notified. + * + * Returns 0 on success, negative on error. + * + */ +int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component) +{ + int ret; + + ret = snd_soc_component_set_jack(component, NULL, NULL); + if (ret) { + dev_err(component->card->dev, "Failed to disable jack: %d\n", ret); + return ret; + } + + return 0; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_disable_offload_jack); + static int snd_soc_usb_get_offload_card_status(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) {
The headphone jack framework has a well defined infrastructure for notifying userspace entities through input devices. Expose a jack device that carries information about if an offload capable device is connected. Applications can further identify specific offloading information through other SND kcontrols.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/qcom/Kconfig | 5 +++ sound/soc/qcom/Makefile | 2 ++ sound/soc/qcom/qdsp6/q6usb.c | 40 +++++++++++++++++++++ sound/soc/qcom/sm8250.c | 23 +++++++++++- sound/soc/qcom/usb_offload_utils.c | 56 ++++++++++++++++++++++++++++++ sound/soc/qcom/usb_offload_utils.h | 29 ++++++++++++++++ 6 files changed, 154 insertions(+), 1 deletion(-) create mode 100644 sound/soc/qcom/usb_offload_utils.c create mode 100644 sound/soc/qcom/usb_offload_utils.h
diff --git a/sound/soc/qcom/Kconfig b/sound/soc/qcom/Kconfig index a1beafe2b1dd..e5284a93cf9a 100644 --- a/sound/soc/qcom/Kconfig +++ b/sound/soc/qcom/Kconfig @@ -118,9 +118,14 @@ config SND_SOC_QDSP6_PRM tristate select SND_SOC_QDSP6_PRM_LPASS_CLOCKS
+config SND_SOC_QCOM_OFFLOAD_UTILS + tristate + config SND_SOC_QDSP6_USB tristate "SoC ALSA USB offloading backing for QDSP6" depends on SND_SOC_USB + select SND_SOC_QCOM_OFFLOAD_UTILS + help Adds support for USB offloading for QDSP6 ASoC based platform sound cards. This will enable the diff --git a/sound/soc/qcom/Makefile b/sound/soc/qcom/Makefile index 16db7b53ddac..985ce2ae286b 100644 --- a/sound/soc/qcom/Makefile +++ b/sound/soc/qcom/Makefile @@ -30,6 +30,7 @@ snd-soc-sc8280xp-y := sc8280xp.o snd-soc-qcom-common-y := common.o snd-soc-qcom-sdw-y := sdw.o snd-soc-x1e80100-y := x1e80100.o +snd-soc-qcom-offload-utils-objs := usb_offload_utils.o
obj-$(CONFIG_SND_SOC_STORM) += snd-soc-storm.o obj-$(CONFIG_SND_SOC_APQ8016_SBC) += snd-soc-apq8016-sbc.o @@ -42,6 +43,7 @@ obj-$(CONFIG_SND_SOC_SM8250) += snd-soc-sm8250.o obj-$(CONFIG_SND_SOC_QCOM_COMMON) += snd-soc-qcom-common.o obj-$(CONFIG_SND_SOC_QCOM_SDW) += snd-soc-qcom-sdw.o obj-$(CONFIG_SND_SOC_X1E80100) += snd-soc-x1e80100.o +obj-$(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) += snd-soc-qcom-offload-utils.o
#DSP lib obj-$(CONFIG_SND_SOC_QDSP6) += qdsp6/ diff --git a/sound/soc/qcom/qdsp6/q6usb.c b/sound/soc/qcom/qdsp6/q6usb.c index 2715ac920273..8a29a5bd1479 100644 --- a/sound/soc/qcom/qdsp6/q6usb.c +++ b/sound/soc/qcom/qdsp6/q6usb.c @@ -14,6 +14,7 @@ #include <linux/slab.h>
#include <sound/asound.h> +#include <sound/jack.h> #include <sound/pcm.h> #include <sound/pcm_params.h> #include <sound/q6usboffload.h> @@ -38,6 +39,7 @@ struct q6usb_status { struct q6usb_port_data { struct q6afe_usb_cfg usb_cfg; struct snd_soc_usb *usb; + struct snd_soc_jack *hs_jack; struct q6usb_offload priv; struct mutex mutex; unsigned long available_card_slot; @@ -252,6 +254,9 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb,
mutex_lock(&data->mutex); if (connected) { + if (!data->available_card_slot) + snd_jack_report(data->hs_jack->jack, 1); + /* * Select the latest USB headset plugged in, if session is * idle, and if no index selected by the kcontrol. @@ -274,11 +279,45 @@ static int q6usb_alsa_connection_cb(struct snd_soc_usb *usb, ffs(data->available_card_slot) - 1 : 0; data->sel_pcm_idx = 0; } + + if (!data->available_card_slot) + snd_jack_report(data->hs_jack->jack, 0); } mutex_unlock(&data->mutex);
return 0; } +static void q6usb_component_disable_jack(struct q6usb_port_data *data) +{ + /* Offload jack has already been disabled */ + if (!data->hs_jack) + return; + + snd_jack_report(data->hs_jack->jack, 0); + data->hs_jack = NULL; +} + +static void q6usb_component_enable_jack(struct q6usb_port_data *data, + struct snd_soc_jack *jack) +{ + snd_jack_report(jack->jack, data->available_card_slot ? 1 : 0); + data->hs_jack = jack; +} + +static int q6usb_component_set_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack, void *priv) +{ + struct q6usb_port_data *data = dev_get_drvdata(component->dev); + + mutex_lock(&data->mutex); + if (jack) + q6usb_component_enable_jack(data, jack); + else + q6usb_component_disable_jack(data); + mutex_unlock(&data->mutex); + + return 0; +}
static int q6usb_component_probe(struct snd_soc_component *component) { @@ -309,6 +348,7 @@ static void q6usb_component_remove(struct snd_soc_component *component)
static const struct snd_soc_component_driver q6usb_dai_component = { .probe = q6usb_component_probe, + .set_jack = q6usb_component_set_jack, .remove = q6usb_component_remove, .name = "q6usb-dai-component", .dapm_widgets = q6usb_dai_widgets, diff --git a/sound/soc/qcom/sm8250.c b/sound/soc/qcom/sm8250.c index a15dafb99b33..a132a814ceb4 100644 --- a/sound/soc/qcom/sm8250.c +++ b/sound/soc/qcom/sm8250.c @@ -12,6 +12,7 @@ #include <linux/input-event-codes.h> #include "qdsp6/q6afe.h" #include "common.h" +#include "usb_offload_utils.h" #include "sdw.h"
#define DRIVER_NAME "sm8250" @@ -22,14 +23,33 @@ struct sm8250_snd_data { struct snd_soc_card *card; struct sdw_stream_runtime *sruntime[AFE_PORT_MAX]; struct snd_soc_jack jack; + struct snd_soc_jack usb_offload_jack; + bool usb_offload_jack_setup; bool jack_setup; };
static int sm8250_snd_init(struct snd_soc_pcm_runtime *rtd) { struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + int ret; + + if (cpu_dai->id == USB_RX) + ret = qcom_snd_usb_offload_jack_setup(rtd, &data->usb_offload_jack, + &data->usb_offload_jack_setup); + else + ret = qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); + return ret; +} + +static void sm8250_snd_exit(struct snd_soc_pcm_runtime *rtd) +{ + struct sm8250_snd_data *data = snd_soc_card_get_drvdata(rtd->card); + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + + if (cpu_dai->id == USB_RX) + qcom_snd_usb_offload_jack_remove(rtd, &data->usb_offload_jack_setup);
- return qcom_snd_wcd_jack_setup(rtd, &data->jack, &data->jack_setup); }
static int sm8250_be_hw_params_fixup(struct snd_soc_pcm_runtime *rtd, @@ -129,6 +149,7 @@ static void sm8250_add_be_ops(struct snd_soc_card *card) for_each_card_prelinks(card, i, link) { if (link->no_pcm == 1) { link->init = sm8250_snd_init; + link->exit = sm8250_snd_exit; link->be_hw_params_fixup = sm8250_be_hw_params_fixup; link->ops = &sm8250_be_ops; } diff --git a/sound/soc/qcom/usb_offload_utils.c b/sound/soc/qcom/usb_offload_utils.c new file mode 100644 index 000000000000..2d35d87d1519 --- /dev/null +++ b/sound/soc/qcom/usb_offload_utils.c @@ -0,0 +1,56 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#include <dt-bindings/sound/qcom,q6afe.h> +#include <linux/module.h> +#include <sound/jack.h> +#include <sound/soc-usb.h> + +#include "usb_offload_utils.h" + +int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup) +{ + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); + int ret = 0; + + if (cpu_dai->id != USB_RX) + return -EINVAL; + + if (!*jack_setup) { + ret = snd_soc_usb_setup_offload_jack(codec_dai->component, jack); + if (ret) + return ret; + } + + *jack_setup = true; + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_setup); + +int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, + bool *jack_setup) +{ + struct snd_soc_dai *cpu_dai = snd_soc_rtd_to_cpu(rtd, 0); + struct snd_soc_dai *codec_dai = snd_soc_rtd_to_codec(rtd, 0); + int ret = 0; + + if (cpu_dai->id != USB_RX) + return -EINVAL; + + if (*jack_setup) { + ret = snd_soc_usb_disable_offload_jack(codec_dai->component); + if (ret) + return ret; + } + + *jack_setup = false; + + return 0; +} +EXPORT_SYMBOL_GPL(qcom_snd_usb_offload_jack_remove); +MODULE_DESCRIPTION("ASoC Q6 USB offload controls"); +MODULE_LICENSE("GPL"); diff --git a/sound/soc/qcom/usb_offload_utils.h b/sound/soc/qcom/usb_offload_utils.h new file mode 100644 index 000000000000..d44f78569b47 --- /dev/null +++ b/sound/soc/qcom/usb_offload_utils.h @@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved. + */ +#ifndef __QCOM_SND_USB_OFFLOAD_UTILS_H__ +#define __QCOM_SND_USB_OFFLOAD_UTILS_H__ + +#include <sound/soc.h> + +#if IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) +int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup); + +int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, + bool *jack_setup); +#else +static inline int qcom_snd_usb_offload_jack_setup(struct snd_soc_pcm_runtime *rtd, + struct snd_soc_jack *jack, bool *jack_setup) +{ + return -ENODEV; +} + +static inline int qcom_snd_usb_offload_jack_remove(struct snd_soc_pcm_runtime *rtd, + bool *jack_setup) +{ + return -ENODEV; +} +#endif /* IS_ENABLED(CONFIG_SND_SOC_QCOM_OFFLOAD_UTILS) */ +#endif /* __QCOM_SND_USB_OFFLOAD_UTILS_H__ */
For USB sound to expose mixer controls to fetch information about the ASoC sound card, add an API that returns the platform sound card number that is registered with SOC USB. Knowing this allows for applications to further query about the offload status.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- include/sound/soc-usb.h | 6 ++++++ sound/soc/soc-usb.c | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+)
diff --git a/include/sound/soc-usb.h b/include/sound/soc-usb.h index 8e94c1991819..ab5ade4942d5 100644 --- a/include/sound/soc-usb.h +++ b/include/sound/soc-usb.h @@ -85,6 +85,7 @@ int snd_soc_usb_find_supported_format(int card_idx, 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 *dev); +int snd_soc_usb_device_offload_available(struct device *dev);
int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); @@ -129,6 +130,11 @@ static inline void *snd_soc_usb_find_priv_data(struct device *dev) return NULL; }
+static inline int snd_soc_usb_device_offload_available(struct device *dev) +{ + return -ENODEV; +} + static inline int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx) { diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index 0baba34910b5..d50bcb9f379e 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -503,6 +503,26 @@ int snd_soc_usb_find_supported_format(int card_idx, } EXPORT_SYMBOL_GPL(snd_soc_usb_find_supported_format);
+/** + * snd_soc_usb_device_offload_available() - Fetch BE DAI link sound card + * @dev: the device to find in SOC USB + * + * Finds the component linked to a specific SOC USB instance, and returns + * the sound card number for the platform card supporting offloading. + * + */ +int snd_soc_usb_device_offload_available(struct device *dev) +{ + struct snd_soc_usb *ctx; + + ctx = snd_soc_find_usb_ctx(dev); + if (!ctx) + return -ENODEV; + + return ctx->component->card->snd_card->number; +} +EXPORT_SYMBOL_GPL(snd_soc_usb_device_offload_available); + /** * snd_soc_usb_allocate_port() - allocate a SOC USB device * @component: USB DPCM backend DAI component
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 --- sound/usb/Kconfig | 10 +++++ sound/usb/qcom/Makefile | 6 ++- sound/usb/qcom/mixer_usb_offload.c | 65 ++++++++++++++++++++++++++++++ sound/usb/qcom/mixer_usb_offload.h | 17 ++++++++ sound/usb/qcom/qc_audio_offload.c | 4 ++ 5 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 sound/usb/qcom/mixer_usb_offload.c create mode 100644 sound/usb/qcom/mixer_usb_offload.h
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig index 5cc3eaf53e6b..1228be3c1f83 100644 --- a/sound/usb/Kconfig +++ b/sound/usb/Kconfig @@ -176,6 +176,16 @@ config SND_BCD2000 To compile this driver as a module, choose M here: the module will be called snd-bcd2000.
+config SND_USB_QC_OFFLOAD_MIXER + bool "Qualcomm USB Audio Offload mixer control" + help + Say Y to enable the Qualcomm USB audio offloading mixer controls. + This exposes an USB offload capable kcontrol to signal to + applications about which platform sound card can support USB + audio offload. This can potentially be used to fetch further + information about the offloading status from the platform sound + card. + config SND_USB_AUDIO_QMI tristate "Qualcomm Audio Offload driver" depends on QCOM_QMI_HELPERS && SND_USB_AUDIO && USB_XHCI_SIDEBAND && SND_SOC_USB diff --git a/sound/usb/qcom/Makefile b/sound/usb/qcom/Makefile index a81c9b28d484..eada5cd7b71f 100644 --- a/sound/usb/qcom/Makefile +++ b/sound/usb/qcom/Makefile @@ -1,2 +1,6 @@ snd-usb-audio-qmi-objs := usb_audio_qmi_v01.o qc_audio_offload.o -obj-$(CONFIG_SND_USB_AUDIO_QMI) += snd-usb-audio-qmi.o \ No newline at end of file +obj-$(CONFIG_SND_USB_AUDIO_QMI) += snd-usb-audio-qmi.o + +ifneq ($(CONFIG_SND_USB_QC_OFFLOAD_MIXER),) +snd-usb-audio-qmi-objs += mixer_usb_offload.o +endif \ No newline at end of file diff --git a/sound/usb/qcom/mixer_usb_offload.c b/sound/usb/qcom/mixer_usb_offload.c new file mode 100644 index 000000000000..cd6e5600e795 --- /dev/null +++ b/sound/usb/qcom/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 "../usbaudio.h" + +#include "mixer_usb_offload.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)); +} diff --git a/sound/usb/qcom/mixer_usb_offload.h b/sound/usb/qcom/mixer_usb_offload.h new file mode 100644 index 000000000000..0efda52e92b6 --- /dev/null +++ b/sound/usb/qcom/mixer_usb_offload.h @@ -0,0 +1,17 @@ +/* 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 + +#if IS_ENABLED(CONFIG_SND_USB_QC_OFFLOAD_MIXER) +int snd_usb_offload_create_ctl(struct snd_usb_audio *chip); +#else +static inline int snd_usb_offload_create_ctl(struct snd_usb_audio *chip) +{ + return -ENODEV; +} +#endif +#endif /* __USB_OFFLOAD_MIXER_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 1a45bc289f90..9aac0985f43c 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -37,6 +37,7 @@ #include "../pcm.h" #include "../power.h"
+#include "mixer_usb_offload.h" #include "usb_audio_qmi_v01.h"
/* Stream disable request timeout during USB device disconnect */ @@ -1660,6 +1661,9 @@ 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);
+ if (chip->num_interfaces == 1) + snd_usb_offload_create_ctl(chip); + mutex_unlock(&chip->mutex); mutex_unlock(&qdev_mutex);
In case of notifying SND platform drivers of connection events, some of these use cases, such as offloading, require an ASoC USB backend device to be initialized before the events can be handled. If the USB backend device has not yet been probed, this leads to missing initial USB audio device connection events.
Expose an API that traverses the usb_chip array for connected devices, and to call the respective connection callback registered to the SND platform driver.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/card.c | 21 +++++++++++++++++++++ sound/usb/card.h | 1 + sound/usb/qcom/qc_audio_offload.c | 2 ++ 3 files changed, 24 insertions(+)
diff --git a/sound/usb/card.c b/sound/usb/card.c index fb548a3abcfc..a7f1e437f67a 100644 --- a/sound/usb/card.c +++ b/sound/usb/card.c @@ -186,6 +186,27 @@ struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, } EXPORT_SYMBOL_GPL(snd_usb_find_suppported_substream);
+/* + * in case the platform driver was not ready at the time of USB SND + * device connect, expose an API to discover all connected USB devices + * so it can populate any dependent resources/structures. + */ +void snd_usb_rediscover_devices(void) +{ + int i; + + guard(mutex)(®ister_mutex); + + if (!platform_ops || !platform_ops->connect_cb) + return; + + for (i = 0; i < SNDRV_CARDS; i++) { + if (usb_chip[i]) + platform_ops->connect_cb(usb_chip[i]); + } +} +EXPORT_SYMBOL_GPL(snd_usb_rediscover_devices); + /* * disconnect streams * called from usb_audio_disconnect() diff --git a/sound/usb/card.h b/sound/usb/card.h index 3c900e5afbce..140928dd9d63 100644 --- a/sound/usb/card.h +++ b/sound/usb/card.h @@ -221,4 +221,5 @@ int snd_usb_unregister_platform_ops(void);
struct snd_usb_stream *snd_usb_find_suppported_substream(int card_idx, struct snd_pcm_hw_params *params, int direction); +void snd_usb_rediscover_devices(void); #endif /* __USBAUDIO_CARD_H */ diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 9aac0985f43c..01aa0753ca83 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -1880,6 +1880,8 @@ static int __init qc_usb_audio_offload_init(void) if (ret < 0) goto release_qmi;
+ snd_usb_rediscover_devices(); + return 0;
release_qmi:
Utilize the card and PCM index coming from the USB QMI stream request. This field follows what is set by the ASoC USB backend, and could potentially carry information about a specific device selected through the ASoC USB backend. The backend also has information about the last USB sound device plugged in, so it can choose to select the last device plugged in, accordingly.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/usb/qcom/qc_audio_offload.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/sound/usb/qcom/qc_audio_offload.c b/sound/usb/qcom/qc_audio_offload.c index 01aa0753ca83..37a90d2ac344 100644 --- a/sound/usb/qcom/qc_audio_offload.c +++ b/sound/usb/qcom/qc_audio_offload.c @@ -107,8 +107,6 @@ struct uaudio_qmi_dev { bool er_mapped; /* reference count to number of possible consumers */ atomic_t qdev_in_use; - /* idx to last udev card number plugged in */ - unsigned int last_card_num; };
struct uaudio_dev { @@ -1256,7 +1254,7 @@ static int prepare_qmi_response(struct snd_usb_substream *subs,
pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; xfer_buf_len = req_msg->xfer_buff_size; - card_num = uaudio_qdev->last_card_num; + card_num = (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 16;
if (!uadev[card_num].ctrl_intf) { dev_err(&subs->dev->dev, "audio ctrl intf info not cached\n"); @@ -1449,8 +1447,7 @@ static void handle_uaudio_stream_req(struct qmi_handle *handle,
direction = (req_msg->usb_token & QMI_STREAM_REQ_DIRECTION); pcm_dev_num = (req_msg->usb_token & QMI_STREAM_REQ_DEV_NUM_MASK) >> 8; - pcm_card_num = req_msg->enable ? uaudio_qdev->last_card_num : - ffs(uaudio_qdev->card_slot) - 1; + pcm_card_num = (req_msg->usb_token & QMI_STREAM_REQ_CARD_NUM_MASK) >> 16; if (pcm_card_num >= SNDRV_CARDS) { ret = -EINVAL; goto response; @@ -1658,7 +1655,6 @@ static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) sdev->num_capture = usb_qmi_get_pcm_num(chip, 1); uadev[chip->card->number].sdev = sdev;
- uaudio_qdev->last_card_num = chip->card->number; snd_soc_usb_connect(usb_get_usb_backend(udev), sdev);
if (chip->num_interfaces == 1)
In case the USB backend device has not been initialized/probed, USB SND device connections can still occur. When the USB backend is eventually made available, previous USB SND device connections are not communicated to the USB backend. Call snd_usb_rediscover_devices() to generate the connect callbacks for all USB SND devices connected. This will allow for the USB backend to be updated with the current set of devices available.
The chip array entries are all populated and removed while under the register_mutex, so going over potential race conditions:
Thread#1: q6usb_component_probe() --> snd_soc_usb_add_port() --> snd_usb_rediscover_devices() --> mutex_lock(register_mutex)
Thread#2 --> usb_audio_disconnect() --> mutex_lock(register_mutex)
So either thread#1 or thread#2 will complete first. If
Thread#1 completes before thread#2: SOC USB will notify DPCM backend of the device connection. Shortly after, once thread#2 runs, we will get a disconnect event for the connected device.
Thread#2 completes before thread#1: Then during snd_usb_rediscover_devices() it won't notify of any connection for that particular chip index.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- sound/soc/soc-usb.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/sound/soc/soc-usb.c b/sound/soc/soc-usb.c index d50bcb9f379e..e708eaf05a95 100644 --- a/sound/soc/soc-usb.c +++ b/sound/soc/soc-usb.c @@ -593,6 +593,8 @@ void snd_soc_usb_add_port(struct snd_soc_usb *usb) mutex_lock(&ctx_mutex); list_add_tail(&usb->list, &usb_ctx_list); mutex_unlock(&ctx_mutex); + + snd_usb_rediscover_devices(); } EXPORT_SYMBOL_GPL(snd_soc_usb_add_port);
With the introduction of the soc-usb driver, add documentation highlighting details on how to utilize the new driver and how it interacts with different components in USB SND and ASoC. It provides examples on how to implement the drivers that will need to be introduced in order to enable USB audio offloading.
Signed-off-by: Wesley Cheng quic_wcheng@quicinc.com --- Documentation/sound/soc/index.rst | 1 + Documentation/sound/soc/usb.rst | 603 ++++++++++++++++++++++++++++++ 2 files changed, 604 insertions(+) create mode 100644 Documentation/sound/soc/usb.rst
diff --git a/Documentation/sound/soc/index.rst b/Documentation/sound/soc/index.rst index e57df2dab2fd..8bed8f8f48da 100644 --- a/Documentation/sound/soc/index.rst +++ b/Documentation/sound/soc/index.rst @@ -18,3 +18,4 @@ The documentation is spilt into the following sections:- jack dpcm codec-to-codec + usb diff --git a/Documentation/sound/soc/usb.rst b/Documentation/sound/soc/usb.rst new file mode 100644 index 000000000000..c5175af52154 --- /dev/null +++ b/Documentation/sound/soc/usb.rst @@ -0,0 +1,603 @@ +================ +ASoC USB support +================ + +Overview +======== +In order to leverage the existing USB sound device support in ALSA, the +introduction of the ASoC USB APIs, allow for the entities to communicate +with one another. + +One potential use case would be to support USB audio offloading, which is +an implementation that allows for an external DSP on the SoC to handle the +transfer of audio data over the USB bus. This would let the main +processor to stay in lower power modes for longer durations. The following +is an example design of how the ASoC and ALSA pieces can be connected +together to achieve this: + +:: + + USB | ASoC + | _________________________ + | | ASoC Platform card | + | |_________________________| + | | | + | ___V____ ____V____ + | |ASoC BE | |ASoC FE | + | |DAI LNK | |DAI LNK | + | |________| |_________| + | ^ ^ ^ + | | |________| + | ___V____ | + | |SOC-USB | | + ________ ________ | | | + |USB SND |<--->|USBSND |<------------>|________| | + |(card.c)| |offld |<---------- | + |________| |________|___ | | | + ^ ^ | | | ____________V_________ + | | | | | |IPC | + __ V_______________V_____ | | | |______________________| + |USB SND (endpoint.c) | | | | ^ + |_________________________| | | | | + ^ | | | ___________V___________ + | | | |->|audio DSP | + ___________V_____________ | | |_______________________| + |XHCI HCD |<- | + |_________________________| | + + +SOC USB driver +============== +Structures +---------- +``struct snd_soc_usb`` + + - ``list``: list head for SND SOC struct list + - ``dev``: USB backend device reference + - ``component``: reference to ASoC component + - ``active_list``: active sessions + - ``num_supported_streams``: number of supported concurrent sessions + - ``connection_status_cb``: callback to notify connection events + - ``put_offload_dev``: callback to select USB sound card/PCM device + - ``get_offload_dev``: callback to fetch selected USB sound card/PCM device + - ``priv_data``: driver data + +The snd_soc_usb structure can be referenced using the ASoC platform card +device, or a USB device (udev->dev). This is created by the ASoC BE DAI +link, and the USB sound entity will be able to pass information to the +ASoC BE DAI link using this structure. + +``struct snd_soc_usb_device`` + + - ``card_idx``: sound card index associated with USB device + - ``chip_idx``: USB sound chip array index + - ``num_playback``: number of playback streams + - ``num_capture``: number of capture streams + +The struct snd_soc_usb_device is created by the USB sound offload driver. +This will carry basic parameters/limitations that will be used to +determine the possible offloading paths for this USB audio device. + +``struct snd_soc_usb_session`` + + - ``active_card_idx``: active offloaded sound card + - ``active_pcm_idx``: active offloaded PCM device + - ``state``: USB BE DAI link PCM state + +The struct snd_soc_usb_session tracks the current offloading state for a +particular card and PCM combination. This structure is carried/saved as +part of the active_list within struct snd_soc_usb. + +The number of entities in the active list corresponds to the number of +snd_soc_usb_session structures that are allocated. This is controlled +by the num_supported_streams that is reported as part of the SOC USB +structure creation. + +Functions +--------- +.. code-block:: rst + + const char *snd_soc_usb_get_components_tag(bool playback); +.. + + - ``playback``: direction of audio stream + +**snd_soc_usb_get_components_tag()** returns the tag used for describing if USB +offloading is supported for appending to the ASoC platform card's components +string. + +Returns a tag based on the direction of the audio stream. + +.. code-block:: rst + + int snd_soc_usb_find_format(int card_idx, struct snd_pcm_hw_params *params, + int direction) +.. + + - ``card_idx``: the index into the USB sound chip array. + - ``params``: Requested PCM parameters from the USB DPCM BE DAI link + - ``direction``: capture or playback + +**snd_soc_usb_find_format()** ensures that the requested audio profile being +requested by the external DSP is supported by the USB device. + +Returns 0 on success, and -EOPNOTSUPP on failure. + +.. code-block:: rst + + int snd_soc_usb_connect(struct device *usbdev, struct snd_soc_usb_device *sdev) +.. + + - ``usbdev``: the usb device that was discovered + - ``sdev``: capabilities of the device + +**snd_soc_usb_connect()** notifies the ASoC USB DCPM BE DAI link of a USB +audio device detection. This can be utilized in the BE DAI +driver to keep track of available USB audio devices. This is intended +to be called by the USB offload driver residing in USB SND. + +Returns 0 on success, negative error code on failure. + +.. code-block:: rst + + int snd_soc_usb_disconnect(struct device *usbdev, struct snd_soc_usb_device *sdev) +.. + + - ``usbdev``: the usb device that was removed + - ``sdev``: capabilities to free + +**snd_soc_usb_disconnect()** notifies the ASoC USB DCPM BE DAI link of a USB +audio device removal. This is intended to be called by the USB offload +driver that resides in USB SND. + +.. code-block:: rst + + void *snd_soc_usb_find_priv_data(struct device *usbdev) +.. + + - ``usbdev``: the usb device to reference to find private data + +**snd_soc_usb_find_priv_data()** fetches the private data saved to the SOC USB +device. + +Returns pointer to priv_data on success, NULL on failure. + +.. code-block:: rst + + int snd_soc_usb_device_offload_available(struct device *dev) +.. + + - ``dev``: the device to find in SOC USB + +**snd_soc_usb_device_offload_available()** fetch the sound card number associated +to the USB BE DAI link. + +Returns a valid sound card index on success, negative on failure. + +.. code-block:: rst + + int snd_soc_usb_prepare_session(struct snd_soc_usb *usb, int card_idx, int pcm_idx); +.. + + - ``usb``: SOC USB device + - ``card_idx``: USB sound card index + - ``pcm_idx``: USB PCM device index + +**snd_soc_usb_prepare_session()** populates active_list with a 'struct +snd_soc_usb_session.' This will move the session into the SND_SOC_USB_PREPARED +state. State updates will always start here. + +Returns index to active_list on success, -EBUSY on failure. + +.. code-block:: rst + + int snd_soc_usb_shutdown_session(struct snd_soc_usb *usb, int session_id); +.. + + - ``usb``: SOC USB device + - ``session_id``: session id returned by **snd_soc_usb_prepare_session()** + +**snd_soc_usb_shutdown_session()** frees up a slot in active_list, which signals +that there is no longer an active offloading device. This allows for another +session to be started. + +Returns 0 on success, -EINVAL if session index is invalid. + +.. code-block:: rst + + int snd_soc_usb_set_session_state(struct snd_soc_usb *usb, int session_id, + enum snd_soc_usb_dai_state state); +.. + + - ``usb``: SOC USB device + - ``session_id``: session id returned by **snd_soc_usb_prepare_session()** + - ``state``: state to move into + +**snd_soc_usb_set_session_state()** moves an offloading session to the desired +state. + +.. code-block:: rst + + int snd_soc_usb_setup_offload_jack(struct snd_soc_component *component, + struct snd_soc_jack *jack) +.. + + - ``component``: ASoC component to add the jack + - ``jack``: ASoC sound jack to add + +**snd_soc_usb_setup_offload_jack()** is a helper to add a sound jack control to +the platform sound card. This will allow for consistent naming to be used on +designs that support USB audio offloading. + +Returns 0 on success, negative otherwise. + +.. code-block:: rst + + struct snd_soc_usb *snd_soc_usb_allocate_port(struct snd_soc_component *component, + int num_supported_streams, void *data); +.. + + - ``component``: DPCM BE DAI link component + - ``num_supported_streams``: number of active streams supported by external DSP + - ``data``: private data + +**snd_soc_usb_allocate_port()** allocates a SOC USB device and populates standard +parameters that is used for further operations. + +Returns a pointer to struct soc_usb on success, negative on error. + +.. code-block:: rst + + void snd_soc_usb_free_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to free + +**snd_soc_usb_free_port()** frees a SOC USB device. + +.. code-block:: rst + + void snd_soc_usb_add_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to add + +**snd_soc_usb_add_port()** add an allocated SOC USB device to the SOC USB framework. +Once added, this device can be referenced by further operations. + +.. code-block:: rst + + void snd_soc_usb_remove_port(struct snd_soc_usb *usb); +.. + + - ``usb``: SOC USB device to remove + +**snd_soc_usb_remove_port()** removes a SOC USB device from the SOC USB framework. +After removing a device, any SOC USB operations would not be able to reference the +device removed. + +How to Register to SOC USB +-------------------------- +The ASoC DPCM USB BE DAI link is the entity responsible for allocating and +registering the SOC USB device on the component bind. Likewise, it will +also be responsible for freeing the allocated resources. An example can +be shown below: + +.. code-block:: rst + + static int q6usb_component_probe(struct snd_soc_component *component) + { + ... + data->usb = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (!data->usb) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + + ret = snd_soc_usb_add_port(usb); + if (ret < 0) { + dev_err(component->dev, "failed to add usb port\n"); + goto free_usb; + } + ... + } + + static void q6usb_component_remove(struct snd_soc_component *component) + { + ... + snd_soc_usb_remove_port(data->usb); + snd_soc_usb_free_port(data->usb); + } + + static const struct snd_soc_component_driver q6usb_dai_component = { + .probe = q6usb_component_probe, + .remove = q6usb_component_remove, + .name = "q6usb-dai-component", + ... + }; +.. + +BE DAI links can pass along vendor specific information as part of the +call to allocate the SOC USB device. This will allow any BE DAI link +parameters or settings to be accessed by the USB offload driver that +resides in USB SND. + +USB Audio Device Connection Flow +-------------------------------- +USB devices can be hotplugged into the USB root hub at any point in time. +The BE DAI link should be aware of the current state of the physical USB +port, i.e. if there are any USB devices with audio interface(s) connected. +The following callback can be used to notify the BE DAI link of any change: + + **connection_status_cb()** + +This is called whenever there is a USB SND interface bind or remove event, +using snd_soc_usb_connect() or snd_soc_usb_disconnect(): + +.. code-block:: rst + + static void qc_usb_audio_offload_probe(struct snd_usb_audio *chip) + { + ... + snd_soc_usb_connect(usb_get_usb_backend(udev), sdev); + ... + } + + static void qc_usb_audio_offload_disconnect(struct snd_usb_audio *chip) + { + ... + snd_soc_usb_disconnect(usb_get_usb_backend(chip->dev), dev->sdev); + ... + } +.. + +In order to account for conditions where driver or device existence is +not guaranteed, USB SND exposes snd_usb_rediscover_devices() to resend the +connect events for any identified USB audio interfaces. Consider the +the following situtation: + + **usb_audio_probe()** + | --> USB audio streams allocated and saved to usb_chip[] + | --> Propagate connect event to USB offload driver in USB SND + | --> **snd_soc_usb_connect()** exits as USB BE DAI link is not ready + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> The USB audio device connect event is missed + +To ensure connection events are not missed, **snd_usb_rediscover_devices()** +is executed when the SOC USB device is registered. Now, when the BE DAI +link component probe occurs, the following highlights the sequence: + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> SOC USB device added, and **snd_usb_rediscover_devices()** runs + + **snd_usb_rediscover_devices()** + | --> Traverses through usb_chip[] and for non-NULL entries issue + | **connection_status_cb()** + +In the case where the USB offload driver is unbounded, while USB SND is +ready, the **snd_usb_rediscover_devices()** is called during module init. +This allows for the offloading path to also be enabled with the following +flow: + + **usb_audio_probe()** + | --> USB audio streams allocated and saved to usb_chip[] + | --> Propagate connect event to USB offload driver in USB SND + | --> USB offload driver **NOT** ready! + + BE DAI link component probe + | --> DAI link is probed and SOC USB port is allocated + | --> No USB connect event due to missing USB offload driver + + USB offload driver probe + | --> **qc_usb_audio_offload_init()** + | --> Calls **snd_usb_rediscover_devices()** to notify of devices + +SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers: + + - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload. + + - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities. + +Implementation +-------------- + +**Example:** + + **Sound Cards**: + + :: + + 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed + + + **Platform Sound Card** - card#0: + + :: + + USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255) + + + **USB Sound Card** - card#1: + + :: + + USB Offload Playback Capable Card 0 (range -1->32) + + +The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as: + + - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen. + - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen. + +The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as: + + - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card. + +USB Offload Playback Route Select Kcontrol +------------------------------------------ +In order to allow for vendor specific implementations on audio offloading device +selection, the SOC USB layer exposes the following: + +.. code-block:: rst + + int (*put_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); + int (*get_offload_dev)(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol); +.. + +These are specific for the **USB Offload Playback Route Select** kcontrol. + +When users issue get/put calls to the kcontrol, the registered SOC USB callbacks +will execute the registered function calls to the DPCM BE DAI link. + +**Callback Registration:** + +.. code-block:: rst + + static int q6usb_component_probe(struct snd_soc_component *component) + { + ... + usb = snd_soc_usb_allocate_port(component, 1, &data->priv); + if (IS_ERR(usb)) + return -ENOMEM; + + usb->connection_status_cb = q6usb_alsa_connection_cb; + usb->put_offload_dev = q6usb_put_offload_dev; + usb->get_offload_dev = q6usb_get_offload_dev; + + ret = snd_soc_usb_add_port(usb); +.. + +**PUT Callback:** + +Can be used to track current device selection, and to issue any external DSP +commands that might be required for enabling audio offloading. + +.. code-block:: rst + + static int q6usb_put_offload_dev(struct snd_kcontrol *kcontrol, + struct snd_ctl_elem_value *ucontrol) + { + ... + if ((cardidx >= 0 && test_bit(cardidx, &data->available_card_slot))) { + data->sel_card_idx = cardidx; + changed = 1; + } + ... + if ((pcmidx >= 0 && pcmidx < data->status[cardidx].sdev->num_playback)) { + data->sel_pcm_idx = pcmidx; + changed = 1; + } +.. + +The above is an example of keeping track of what the userspace entity is +selecting as the playback device. This can be later used to pass the information +along to the external DSP. + + +USB Offload Playback Route Status +--------------------------------- +SOC USB exposes APIs for keeping track of the offloading state, and expects this +to be maintained by the BE DAI link that created/added the SOC USB device. + +**SOC USB State Flow Example** + +:: + + PCM Core | BE USB DAI Link | SOC USB + | | + snd_pcm_hw_params --------> dai_link->ops->hw_params --> snd_soc_usb_prepare_session + | | |--> state = SND_SOC_USB_PREPARED + ... | | |--> slot[0] now active + | | + | | + snd_pcm_do_prepare--------> dai_link->ops->prepare ---> snd_soc_usb_set_session_state + | | |--> state = SND_SOC_USB_RUNNING + ... | | + | | + snd_pcm_release_substream-> dai_link->ops->shutdown---> snd_soc_usb_shutdown_session + | | |--> state = SND_SOC_USB_IDLE + | | |--> slot[0] now idle + + +When executing the kcontrol get callback, it will loop across the active_list array +and report to the application for active USB sound card and USB PCM device indexes. + +USB Offload Playback Capable Card +--------------------------------- +USB sound also creates a kcontrol for applications to help determine which platform +sound card USB offloading is linked to. This will allow applications to further +query the platform sound card for specific information about the current USB offload +status. + +This is added as a separate mixer driver: + - mixer_usb_offload.c + - kcontrol: snd_usb_offload_available_ctl + +**snd_usb_offload_available_get()** fetches the associated sound card by utilizing +the **snd_soc_usb_device_offload_available()** API. + +Mixer Examples +-------------- + + :: + + tinymix -D 0 set 'USB Offload Playback Route Card Select' 2 + tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0 + + + :: + + tinymix -D 0 get 'USB Offload Playback Route Card Select' + --> 2 (range -1->32) + tinymix -D 0 get 'USB Offload Playback Route PCM Select' + --> 0 (range -1->255) + + :: + + tinymix -D 0 get 'USB Offload Playback Route Card Status' + --> 2 (range -1->32) [OFFLD active] + --> -1 (range -1->32) [OFFLD idle] + tinymix -D 0 get 'USB Offload Playback Route PCM Status' + --> 0 (range -1->255) [OFFLD active] + --> -1 (range -1->255) [OFFLD idle] + + :: + + tinymix -D 1 get 'USB Offload Playback Capable Card' + --> 0 (range -1->32)
On Mon, Jun 10, 2024 at 04:58:08PM -0700, Wesley Cheng wrote:
+Overview +======== +In order to leverage the existing USB sound device support in ALSA, the +introduction of the ASoC USB APIs, allow for the entities to communicate +with one another.
"... ASoC USB APIs are introduced to allow for ..."
+USB Audio Device Connection Flow +-------------------------------- +USB devices can be hotplugged into the USB root hub at any point in time. +The BE DAI link should be aware of the current state of the physical USB +port, i.e. if there are any USB devices with audio interface(s) connected. +The following callback can be used to notify the BE DAI link of any change:
- **connection_status_cb()**
"... connection_status_cb() can be used to ..."
Thanks.
Hi Bagas,
On 6/12/2024 5:25 AM, Bagas Sanjaya wrote:
On Mon, Jun 10, 2024 at 04:58:08PM -0700, Wesley Cheng wrote:
+Overview +======== +In order to leverage the existing USB sound device support in ALSA, the +introduction of the ASoC USB APIs, allow for the entities to communicate +with one another.
"... ASoC USB APIs are introduced to allow for ..."
+USB Audio Device Connection Flow +-------------------------------- +USB devices can be hotplugged into the USB root hub at any point in time. +The BE DAI link should be aware of the current state of the physical USB +port, i.e. if there are any USB devices with audio interface(s) connected. +The following callback can be used to notify the BE DAI link of any change:
- **connection_status_cb()**
"... connection_status_cb() can be used to ..."
Thanks.
Thanks for the review, will update
Thanks Wesley Cheng
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
- USB sound - Notifies the sound card number for the ASoC platform sound
card that it is registered to for supporting audio offload.
- SOC USB - Maintains the current status of the offload path, and device
(USB sound card and PCM device) information. This would be the main
card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
- **Sound Cards**:
- ::
0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D
SM8250-MTP-WCD9380-WSA8810-VA-DMIC
1 [C320M ]: USB-Audio - Plantronics C320-M
Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
- **Platform Sound Card** - card#0:
- ::
USB Offload Playback Route Card Select 1 (range -1->32)
USB Offload Playback Route PCM Select 0 (range -1->255)
USB Offload Playback Route Card Status -1 (range -1->32)
USB Offload Playback Route PCM Status -1 (range -1->255)
- **USB Sound Card** - card#1:
- ::
USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
- ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index
- that defines which USB SND resources are currently offloaded. If -1 is seen, it
- signifies that offload is not active.
- ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index
- that defines which USB SND resources are currently offloaded. If -1 is seen, it
- signifies that offload is not active.
- ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which
- selects the USB device to initiate offloading on. If no value is written to the
- kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
- ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects
- the USB device to initiate offloading on. If no value is written to the
- kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
- ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card
- number/index that supports USB offloading. Further/follow up queries about
- the current offload state can be handled by reading the offload status
- kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
+Mixer Examples +--------------
- ::
tinymix -D 0 set 'USB Offload Playback Route Card Select' 2
tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0
- ::
tinymix -D 0 get 'USB Offload Playback Route Card Select'
--> 2 (range -1->32)
tinymix -D 0 get 'USB Offload Playback Route PCM Select'
--> 0 (range -1->255)
- ::
tinymix -D 0 get 'USB Offload Playback Route Card Status'
--> 2 (range -1->32) [OFFLD active]
--> -1 (range -1->32) [OFFLD idle]
tinymix -D 0 get 'USB Offload Playback Route PCM Status'
--> 0 (range -1->255) [OFFLD active]
--> -1 (range -1->255) [OFFLD idle]
- ::
tinymix -D 1 get 'USB Offload Playback Capable Card'
--> 0 (range -1->32)
Yes, looking at examples again, I'm still not sure I understand. There are two cards and you do linking between them, this feels broken by design. From my point of view USB Offload should be property of USB card and not involve any other card in a system.
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
+ - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload.
+ - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
+ **Sound Cards**:
+ ::
+ 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
+ **Platform Sound Card** - card#0:
+ ::
+ USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255)
+ **USB Sound Card** - card#1:
+ ::
+ USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
+ - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
+ - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
+ - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
+Mixer Examples +--------------
+ ::
+ tinymix -D 0 set 'USB Offload Playback Route Card Select' 2 + tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Select' + --> 2 (range -1->32) + tinymix -D 0 get 'USB Offload Playback Route PCM Select' + --> 0 (range -1->255)
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Status' + --> 2 (range -1->32) [OFFLD active] + --> -1 (range -1->32) [OFFLD idle] + tinymix -D 0 get 'USB Offload Playback Route PCM Status' + --> 0 (range -1->255) [OFFLD active] + --> -1 (range -1->255) [OFFLD idle]
+ ::
+ tinymix -D 1 get 'USB Offload Playback Capable Card' + --> 0 (range -1->32)
Yes, looking at examples again, I'm still not sure I understand. There are two cards and you do linking between them, this feels broken by design. From my point of view USB Offload should be property of USB card and not involve any other card in a system.
Main benefit to having two cards (keeping one for USB SND and another for the ASoC platform sound card) is that current applications won't break. The behavior is the same, in that if something opens the USB sound card, it will go through the same non-offloaded path. During initial reviews, I think this was a big point where folks wanted the USB PCM path to still be an option.
If applications want to add the offload capabilities to its environment, they can enable it as an additional feature.
Thanks Wesley Cheng
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
+ - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload.
+ - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
+ **Sound Cards**:
+ ::
+ 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
+ **Platform Sound Card** - card#0:
+ ::
+ USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255)
+ **USB Sound Card** - card#1:
+ ::
+ USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
+ - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
+ - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
+ - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
+Mixer Examples +--------------
+ ::
+ tinymix -D 0 set 'USB Offload Playback Route Card Select' 2 + tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Select' + --> 2 (range -1->32) + tinymix -D 0 get 'USB Offload Playback Route PCM Select' + --> 0 (range -1->255)
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Status' + --> 2 (range -1->32) [OFFLD active] + --> -1 (range -1->32) [OFFLD idle] + tinymix -D 0 get 'USB Offload Playback Route PCM Status' + --> 0 (range -1->255) [OFFLD active] + --> -1 (range -1->255) [OFFLD idle]
+ ::
+ tinymix -D 1 get 'USB Offload Playback Capable Card' + --> 0 (range -1->32)
Yes, looking at examples again, I'm still not sure I understand. There are two cards and you do linking between them, this feels broken by design. From my point of view USB Offload should be property of USB card and not involve any other card in a system.
Main benefit to having two cards (keeping one for USB SND and another for the ASoC platform sound card) is that current applications won't break. The behavior is the same, in that if something opens the USB sound card, it will go through the same non-offloaded path. During initial reviews, I think this was a big point where folks wanted the USB PCM path to still be an option.
I'm not against having two cards, in fact I hope that USB card looks and behaves the same as before this patch set, with only difference being controls for enabling offload.
If applications want to add the offload capabilities to its environment, they can enable it as an additional feature.
That sounds fine to me.
Hi Amadeusz,
On 6/13/2024 12:46 AM, Amadeusz Sławiński wrote:
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
+ - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload.
+ - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
+ **Sound Cards**:
+ ::
+ 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
+ **Platform Sound Card** - card#0:
+ ::
+ USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255)
+ **USB Sound Card** - card#1:
+ ::
+ USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
+ - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
+ - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
+ - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
Sorry for the late response.
I think either way, even with the "Enable Offload" kcontrol in USB SND, we'd need a way to link these cards, because if you have multiple USB audio devices connected, and say... your offload mechanism only supports one stream. Then I assume we'd still need to way to determine if that stream can be enabled for that USB SND device or not.
Since the USB SND isn't really the entity maintaining the offload path, I went with the decision to add that route selection to the ASoC platform card. It would have access to all the parameters supported by the audio DSP.
Thanks Wesley Cheng
+Mixer Examples +--------------
+ ::
+ tinymix -D 0 set 'USB Offload Playback Route Card Select' 2 + tinymix -D 0 set 'USB Offload Playback Route PCM Select' 0
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Select' + --> 2 (range -1->32) + tinymix -D 0 get 'USB Offload Playback Route PCM Select' + --> 0 (range -1->255)
+ ::
+ tinymix -D 0 get 'USB Offload Playback Route Card Status' + --> 2 (range -1->32) [OFFLD active] + --> -1 (range -1->32) [OFFLD idle] + tinymix -D 0 get 'USB Offload Playback Route PCM Status' + --> 0 (range -1->255) [OFFLD active] + --> -1 (range -1->255) [OFFLD idle]
+ ::
+ tinymix -D 1 get 'USB Offload Playback Capable Card' + --> 0 (range -1->32)
Yes, looking at examples again, I'm still not sure I understand. There are two cards and you do linking between them, this feels broken by design. From my point of view USB Offload should be property of USB card and not involve any other card in a system.
Main benefit to having two cards (keeping one for USB SND and another for the ASoC platform sound card) is that current applications won't break. The behavior is the same, in that if something opens the USB sound card, it will go through the same non-offloaded path. During initial reviews, I think this was a big point where folks wanted the USB PCM path to still be an option.
I'm not against having two cards, in fact I hope that USB card looks and behaves the same as before this patch set, with only difference being controls for enabling offload.
If applications want to add the offload capabilities to its environment, they can enable it as an additional feature.
That sounds fine to me.
On 6/17/2024 7:02 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/13/2024 12:46 AM, Amadeusz Sławiński wrote:
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
+ - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload.
+ - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
+ **Sound Cards**:
+ ::
+ 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
+ **Platform Sound Card** - card#0:
+ ::
+ USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255)
+ **USB Sound Card** - card#1:
+ ::
+ USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
+ - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
+ - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
+ - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
Sorry for the late response.
I think either way, even with the "Enable Offload" kcontrol in USB SND, we'd need a way to link these cards, because if you have multiple USB audio devices connected, and say... your offload mechanism only supports one stream. Then I assume we'd still need to way to determine if that stream can be enabled for that USB SND device or not.
Since the USB SND isn't really the entity maintaining the offload path, I went with the decision to add that route selection to the ASoC platform card. It would have access to all the parameters supported by the audio DSP.
Problem with card selection is that it will most likely work in pretty random way during reboots and similar scenarios.
Taking from your example: USB Offload Playback Route Card Select 1 (range -1->32) USB Offload Playback Route PCM Select 0 (range -1->255) USB Offload Playback Route Card Status -1 (range -1->32) USB Offload Playback Route PCM Status -1 (range -1->255)
This tells that hw:1,0 will be offloaded USB card. What happens if after reboot the USB card and offload card change places, the control will be pointing at its owner... Another scenario to consider is that user attaches two USB cards and only first one does offload. Now what happens when they enumerate in different order after reboot (swapping places)? Taking into the account that most systems restore previous values of controls in some way - this will point at wrong card.
In my opinion Offload capability should be the capability of the endpoint - in this case USB card (even if in the background it needs to talk to some other device) and it should be exposed as such. Currently you are mixing capabilities of your audio card with capabilities of USB card.
And adding more controls will not make it easy to use from end user perspective. Most users will most likely want for the devices to perform offload automatically if possible to save power and just have control to disable it in case they want to test if it works better without it in case of some problems.
Additional question what happens if you want to offload two usb cards, currently the above set of controls allows you to only point at one card, will you be adding additional set of above controls dynamically for each USB card attached?
Thanks, Amadeusz
Hi Amadeusz,
On 6/18/2024 4:42 AM, Amadeusz Sławiński wrote:
On 6/17/2024 7:02 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/13/2024 12:46 AM, Amadeusz Sławiński wrote:
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
+In the case where the USB offload driver is unbounded, while USB SND is
unbounded -> unbound
(...)
+SOC USB and USB Sound Kcontrols +=============================== +Details +------- +SOC USB and USB sound expose a set of SND kcontrols for applications to select +and fetch the current offloading status for the ASoC platform sound card. Kcontrols +are split between two layers:
+ - USB sound - Notifies the sound card number for the ASoC platform sound + card that it is registered to for supporting audio offload.
+ - SOC USB - Maintains the current status of the offload path, and device + (USB sound card and PCM device) information. This would be the main + card that applications can read to determine offloading capabilities.
+Implementation +--------------
+**Example:**
+ **Sound Cards**:
+ ::
+ 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D + SM8250-MTP-WCD9380-WSA8810-VA-DMIC + 1 [C320M ]: USB-Audio - Plantronics C320-M + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1, full speed
+ **Platform Sound Card** - card#0:
+ ::
+ USB Offload Playback Route Card Select 1 (range -1->32) + USB Offload Playback Route PCM Select 0 (range -1->255) + USB Offload Playback Route Card Status -1 (range -1->32) + USB Offload Playback Route PCM Status -1 (range -1->255)
+ **USB Sound Card** - card#1:
+ ::
+ USB Offload Playback Capable Card 0 (range -1->32)
+The platform sound card(card#0) kcontrols are created as part of adding the SOC +USB device using **snd_soc_usb_add_port()**. The following kcontrols are defined +as:
+ - ``USB Offload Playback Route Card Status`` **(R)**: USB sound card device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM device index + that defines which USB SND resources are currently offloaded. If -1 is seen, it + signifies that offload is not active. + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB sound card index which + selects the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered card index will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
+ - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM index which selects + the USB device to initiate offloading on. If no value is written to the + kcontrol, then the last USB device discovered PCM zero index will be chosen.
+The USB sound card(card#1) kcontrols are created as USB audio devices are plugged +into the physical USB port and enumerated. The kcontrols are defined as:
+ - ``USB Offload Playback Capable Card`` **(R)**: Provides the sound card + number/index that supports USB offloading. Further/follow up queries about + the current offload state can be handled by reading the offload status + kcontrol exposed by the platform card.
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
Sorry for the late response.
I think either way, even with the "Enable Offload" kcontrol in USB SND, we'd need a way to link these cards, because if you have multiple USB audio devices connected, and say... your offload mechanism only supports one stream. Then I assume we'd still need to way to determine if that stream can be enabled for that USB SND device or not.
Since the USB SND isn't really the entity maintaining the offload path, I went with the decision to add that route selection to the ASoC platform card. It would have access to all the parameters supported by the audio DSP.
Problem with card selection is that it will most likely work in pretty random way during reboots and similar scenarios.
Taking from your example: USB Offload Playback Route Card Select 1 (range -1->32) USB Offload Playback Route PCM Select 0 (range -1->255) USB Offload Playback Route Card Status -1 (range -1->32) USB Offload Playback Route PCM Status -1 (range -1->255)
This tells that hw:1,0 will be offloaded USB card. What happens if after reboot the USB card and offload card change places, the control will be pointing at its owner... Another scenario to consider is that user attaches two USB cards and only first one does offload. Now what happens when they enumerate in different order after reboot (swapping places)? Taking into the account that most systems restore previous values of controls in some way - this will point at wrong card.
That sounds like a problem that would exist with current USB SND implementation too? Removing the offloading perspective, how does the system ensure that the previous setting stays persistent? For example, as you mentioned, depending on which USB device enumerates first, the sound card may be different so cards will be switched.
I think I mentioned this previously in another discussion, but I think the idea was that with the USB Offload Playback Capable Card
kcontrol, would allow the system to at least know there is an offload capable path pointing to the ASoC platform card, and fetch more detailed information about which device is selected for offloading, etc...
In my opinion Offload capability should be the capability of the endpoint - in this case USB card (even if in the background it needs to talk to some other device) and it should be exposed as such. Currently you are mixing capabilities of your audio card with capabilities of USB card.
And adding more controls will not make it easy to use from end user perspective. Most users will most likely want for the devices to perform offload automatically if possible to save power and just have control to disable it in case they want to test if it works better without it in case of some problems.
I agree with you that we need to keep the controls at a minimum, but I think what I have in place is fairly reasonable. If we switch to having the USB SND controlling things, we'd save maybe one control? I think keeping the offload status controls are still fairly valuable in both scenarios, as userspace may need to verify which USB SND card is being offloaded.
Additional question what happens if you want to offload two usb cards, currently the above set of controls allows you to only point at one card, will you be adding additional set of above controls dynamically for each USB card attached?
It would depend on the number of offload streams that folks may be supporting on their platform. In our case we only have one available stream, so applications would need to switch between the two devices using the card/pcm selector.
In this case, there will be only one set of controls to select the card/pcm device. As of now (I think I'll change to to add another separate set of controls per stream) if you did support multiple streams, then the current card/PCM device selector would take in multiple arugments. (ie for two streams the kcontrol can take in two values)
Thanks Wesley Cheng
On 6/18/2024 10:52 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/18/2024 4:42 AM, Amadeusz Sławiński wrote:
On 6/17/2024 7:02 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/13/2024 12:46 AM, Amadeusz Sławiński wrote:
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:58 AM, Wesley Cheng wrote:
(...)
> +In the case where the USB offload driver is unbounded, while USB > SND is
unbounded -> unbound
(...)
> +SOC USB and USB Sound Kcontrols > +=============================== > +Details > +------- > +SOC USB and USB sound expose a set of SND kcontrols for > applications to select > +and fetch the current offloading status for the ASoC platform > sound card. Kcontrols > +are split between two layers: > + > + - USB sound - Notifies the sound card number for the ASoC > platform sound > + card that it is registered to for supporting audio offload. > + > + - SOC USB - Maintains the current status of the offload > path, and device > + (USB sound card and PCM device) information. This would > be the main > + card that applications can read to determine offloading > capabilities. > + > +Implementation > +-------------- > + > +**Example:** > + > + **Sound Cards**: > + > + :: > + > + 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D > + SM8250-MTP-WCD9380-WSA8810-VA-DMIC > + 1 [C320M ]: USB-Audio - Plantronics C320-M > + Plantronics Plantronics C320-M at > usb-xhci-hcd.1.auto-1, full speed > + > + > + **Platform Sound Card** - card#0: > + > + :: > + > + USB Offload Playback Route Card Select 1 (range -1->32) > + USB Offload Playback Route PCM Select 0 (range -1->255) > + USB Offload Playback Route Card Status -1 (range -1->32) > + USB Offload Playback Route PCM Status -1 (range -1->255) > + > + > + **USB Sound Card** - card#1: > + > + :: > + > + USB Offload Playback Capable Card 0 (range -1->32) > + > + > +The platform sound card(card#0) kcontrols are created as part of > adding the SOC > +USB device using **snd_soc_usb_add_port()**. The following > kcontrols are defined > +as: > + > + - ``USB Offload Playback Route Card Status`` **(R)**: USB > sound card device index > + that defines which USB SND resources are currently > offloaded. If -1 is seen, it > + signifies that offload is not active. > + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM > device index > + that defines which USB SND resources are currently > offloaded. If -1 is seen, it > + signifies that offload is not active. > + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB > sound card index which > + selects the USB device to initiate offloading on. If no > value is written to the > + kcontrol, then the last USB device discovered card index > will be chosen.
I see only one kcontrol, what if hardware is capable of offloading on more cards, is it possible to do offloading on more than one device?
> + - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB PCM > index which selects > + the USB device to initiate offloading on. If no value is > written to the > + kcontrol, then the last USB device discovered PCM zero index > will be chosen. > + > +The USB sound card(card#1) kcontrols are created as USB audio > devices are plugged > +into the physical USB port and enumerated. The kcontrols are > defined as: > + > + - ``USB Offload Playback Capable Card`` **(R)**: Provides the > sound card > + number/index that supports USB offloading. Further/follow > up queries about > + the current offload state can be handled by reading the > offload status > + kcontrol exposed by the platform card. > +
Why do we need to some magic between cards? I feel like whole kcontrol thing is overengineered a bit - I'm not sure I understand the need to do linking between cards. It would feel a lot simpler if USB card exposed one "USB Offload" kcontrol on USB card if USB controller supports offloading and allowed to set it to true/false to allow user to choose if they want to do offloading on device.
(...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
Sorry for the late response.
I think either way, even with the "Enable Offload" kcontrol in USB SND, we'd need a way to link these cards, because if you have multiple USB audio devices connected, and say... your offload mechanism only supports one stream. Then I assume we'd still need to way to determine if that stream can be enabled for that USB SND device or not.
Since the USB SND isn't really the entity maintaining the offload path, I went with the decision to add that route selection to the ASoC platform card. It would have access to all the parameters supported by the audio DSP.
Problem with card selection is that it will most likely work in pretty random way during reboots and similar scenarios.
Taking from your example: USB Offload Playback Route Card Select 1 (range -1->32) USB Offload Playback Route PCM Select 0 (range -1->255) USB Offload Playback Route Card Status -1 (range -1->32) USB Offload Playback Route PCM Status -1 (range -1->255)
This tells that hw:1,0 will be offloaded USB card. What happens if after reboot the USB card and offload card change places, the control will be pointing at its owner... Another scenario to consider is that user attaches two USB cards and only first one does offload. Now what happens when they enumerate in different order after reboot (swapping places)? Taking into the account that most systems restore previous values of controls in some way - this will point at wrong card.
That sounds like a problem that would exist with current USB SND implementation too? Removing the offloading perspective, how does the system ensure that the previous setting stays persistent? For example, as you mentioned, depending on which USB device enumerates first, the sound card may be different so cards will be switched.
It works because there is no control pointing at other card. My main problem is with controls which have card and pcm id of other card in it.
I think I mentioned this previously in another discussion, but I think the idea was that with the USB Offload Playback Capable Card
kcontrol, would allow the system to at least know there is an offload capable path pointing to the ASoC platform card, and fetch more detailed information about which device is selected for offloading, etc...
This works only in your design, where USB Offload is backed by card, what happens if it is backed by something else?
In my opinion Offload capability should be the capability of the endpoint - in this case USB card (even if in the background it needs to talk to some other device) and it should be exposed as such. Currently you are mixing capabilities of your audio card with capabilities of USB card.
And adding more controls will not make it easy to use from end user perspective. Most users will most likely want for the devices to perform offload automatically if possible to save power and just have control to disable it in case they want to test if it works better without it in case of some problems.
I agree with you that we need to keep the controls at a minimum, but I think what I have in place is fairly reasonable. If we switch to having the USB SND controlling things, we'd save maybe one control? I think keeping the offload status controls are still fairly valuable in both scenarios, as userspace may need to verify which USB SND card is being offloaded.
It should be able to tell which one is being offloaded by examining which USB card has Offload control set to true.
I would assume that USB cards that cannot perform Offload have no control at all, as it is unneeded. And ones that can do, have Offload control. And ones actively being Offloaded have it set to true, otherwise to false.
End user has no need to know where it is offloaded. I'm not HW person, but I would assume that it is even unlikely that someone will design HW, where it is possible to Offload one endpoint to two different places, as this complicates things a lot, but if it were possible, from design perspective it would make a lot more sense to set it in Offloaded USB card settings, instead of some seemingly unrelated controller card device. And that is assuming that all solutions use some other card device to perform Offload.
Additional question what happens if you want to offload two usb cards, currently the above set of controls allows you to only point at one card, will you be adding additional set of above controls dynamically for each USB card attached?
It would depend on the number of offload streams that folks may be supporting on their platform. In our case we only have one available stream, so applications would need to switch between the two devices using the card/pcm selector.
In this case, there will be only one set of controls to select the card/pcm device. As of now (I think I'll change to to add another separate set of controls per stream) if you did support multiple streams, then the current card/PCM device selector would take in multiple arugments. (ie for two streams the kcontrol can take in two values)
Then it is implementation detail of your device, and it should be implemented as controls in your device instead of as part of generic API.
Thanks, Amadeusz
Hi Amaduesz,
On 6/19/2024 12:52 AM, Amadeusz Sławiński wrote:
On 6/18/2024 10:52 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/18/2024 4:42 AM, Amadeusz Sławiński wrote:
On 6/17/2024 7:02 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/13/2024 12:46 AM, Amadeusz Sławiński wrote:
On 6/12/2024 9:28 PM, Wesley Cheng wrote:
Hi Amadeusz,
On 6/12/2024 7:47 AM, Amadeusz Sławiński wrote: > On 6/11/2024 1:58 AM, Wesley Cheng wrote: > > (...) > >> +In the case where the USB offload driver is unbounded, while >> USB SND is > > unbounded -> unbound > > (...) > >> +SOC USB and USB Sound Kcontrols >> +=============================== >> +Details >> +------- >> +SOC USB and USB sound expose a set of SND kcontrols for >> applications to select >> +and fetch the current offloading status for the ASoC platform >> sound card. Kcontrols >> +are split between two layers: >> + >> + - USB sound - Notifies the sound card number for the ASoC >> platform sound >> + card that it is registered to for supporting audio offload. >> + >> + - SOC USB - Maintains the current status of the offload >> path, and device >> + (USB sound card and PCM device) information. This would >> be the main >> + card that applications can read to determine offloading >> capabilities. >> + >> +Implementation >> +-------------- >> + >> +**Example:** >> + >> + **Sound Cards**: >> + >> + :: >> + >> + 0 [SM8250MTPWCD938]: sm8250 - >> SM8250-MTP-WCD9380-WSA8810-VA-D >> + SM8250-MTP-WCD9380-WSA8810-VA-DMIC >> + 1 [C320M ]: USB-Audio - Plantronics C320-M >> + Plantronics Plantronics C320-M at >> usb-xhci-hcd.1.auto-1, full speed >> + >> + >> + **Platform Sound Card** - card#0: >> + >> + :: >> + >> + USB Offload Playback Route Card Select 1 (range -1->32) >> + USB Offload Playback Route PCM Select 0 (range -1->255) >> + USB Offload Playback Route Card Status -1 (range -1->32) >> + USB Offload Playback Route PCM Status -1 (range -1->255) >> + >> + >> + **USB Sound Card** - card#1: >> + >> + :: >> + >> + USB Offload Playback Capable Card 0 (range -1->32) >> + >> + >> +The platform sound card(card#0) kcontrols are created as part >> of adding the SOC >> +USB device using **snd_soc_usb_add_port()**. The following >> kcontrols are defined >> +as: >> + >> + - ``USB Offload Playback Route Card Status`` **(R)**: USB >> sound card device index >> + that defines which USB SND resources are currently >> offloaded. If -1 is seen, it >> + signifies that offload is not active. >> + - ``USB Offload Playback Route PCM Status`` **(R)**: USB PCM >> device index >> + that defines which USB SND resources are currently >> offloaded. If -1 is seen, it >> + signifies that offload is not active. >> + - ``USB Offload Playback Route Card Select`` **(R/W)**: USB >> sound card index which >> + selects the USB device to initiate offloading on. If no >> value is written to the >> + kcontrol, then the last USB device discovered card index >> will be chosen. > > I see only one kcontrol, what if hardware is capable of > offloading on more cards, is it possible to do offloading on more > than one device? > >> + - ``USB Offload Playback Route PCM Select`` **(R/W)**: USB >> PCM index which selects >> + the USB device to initiate offloading on. If no value is >> written to the >> + kcontrol, then the last USB device discovered PCM zero >> index will be chosen. >> + >> +The USB sound card(card#1) kcontrols are created as USB audio >> devices are plugged >> +into the physical USB port and enumerated. The kcontrols are >> defined as: >> + >> + - ``USB Offload Playback Capable Card`` **(R)**: Provides the >> sound card >> + number/index that supports USB offloading. Further/follow >> up queries about >> + the current offload state can be handled by reading the >> offload status >> + kcontrol exposed by the platform card. >> + > > > Why do we need to some magic between cards? I feel like whole > kcontrol thing is overengineered a bit - I'm not sure I > understand the need to do linking between cards. It would feel a > lot simpler if USB card exposed one "USB Offload" kcontrol on USB > card if USB controller supports offloading and allowed to set it > to true/false to allow user to choose if they want to do > offloading on device. > > (...)
Based on feedback from Pierre, what I understood is that for some applications, there won't be an order on which sound card is queried/opened first.
Yes if you have multiple cards, they are probed in random order.
So the end use case example given was if an application opened the USB sound card first, it can see if there is an offload path available. If there is then it can enable the offload path on the corresponding card if desired.
This still doesn't explain why you need to link cards using controls. What would not work with simple "Enable Offload" with true/false values on USB card that works while you do have above routing controls?
Sorry for the late response.
I think either way, even with the "Enable Offload" kcontrol in USB SND, we'd need a way to link these cards, because if you have multiple USB audio devices connected, and say... your offload mechanism only supports one stream. Then I assume we'd still need to way to determine if that stream can be enabled for that USB SND device or not.
Since the USB SND isn't really the entity maintaining the offload path, I went with the decision to add that route selection to the ASoC platform card. It would have access to all the parameters supported by the audio DSP.
Problem with card selection is that it will most likely work in pretty random way during reboots and similar scenarios.
Taking from your example: USB Offload Playback Route Card Select 1 (range -1->32) USB Offload Playback Route PCM Select 0 (range -1->255) USB Offload Playback Route Card Status -1 (range -1->32) USB Offload Playback Route PCM Status -1 (range -1->255)
This tells that hw:1,0 will be offloaded USB card. What happens if after reboot the USB card and offload card change places, the control will be pointing at its owner... Another scenario to consider is that user attaches two USB cards and only first one does offload. Now what happens when they enumerate in different order after reboot (swapping places)? Taking into the account that most systems restore previous values of controls in some way - this will point at wrong card.
That sounds like a problem that would exist with current USB SND implementation too? Removing the offloading perspective, how does the system ensure that the previous setting stays persistent? For example, as you mentioned, depending on which USB device enumerates first, the sound card may be different so cards will be switched.
It works because there is no control pointing at other card. My main problem is with controls which have card and pcm id of other card in it.
I think I mentioned this previously in another discussion, but I think the idea was that with the USB Offload Playback Capable Card
kcontrol, would allow the system to at least know there is an offload capable path pointing to the ASoC platform card, and fetch more detailed information about which device is selected for offloading, etc...
This works only in your design, where USB Offload is backed by card, what happens if it is backed by something else?
In my opinion Offload capability should be the capability of the endpoint - in this case USB card (even if in the background it needs to talk to some other device) and it should be exposed as such. Currently you are mixing capabilities of your audio card with capabilities of USB card.
And adding more controls will not make it easy to use from end user perspective. Most users will most likely want for the devices to perform offload automatically if possible to save power and just have control to disable it in case they want to test if it works better without it in case of some problems.
I agree with you that we need to keep the controls at a minimum, but I think what I have in place is fairly reasonable. If we switch to having the USB SND controlling things, we'd save maybe one control? I think keeping the offload status controls are still fairly valuable in both scenarios, as userspace may need to verify which USB SND card is being offloaded.
It should be able to tell which one is being offloaded by examining which USB card has Offload control set to true.
I would assume that USB cards that cannot perform Offload have no control at all, as it is unneeded. And ones that can do, have Offload control. And ones actively being Offloaded have it set to true, otherwise to false.
End user has no need to know where it is offloaded. I'm not HW person, but I would assume that it is even unlikely that someone will design HW, where it is possible to Offload one endpoint to two different places, as this complicates things a lot, but if it were possible, from design perspective it would make a lot more sense to set it in Offloaded USB card settings, instead of some seemingly unrelated controller card device. And that is assuming that all solutions use some other card device to perform Offload.
Additional question what happens if you want to offload two usb cards, currently the above set of controls allows you to only point at one card, will you be adding additional set of above controls dynamically for each USB card attached?
It would depend on the number of offload streams that folks may be supporting on their platform. In our case we only have one available stream, so applications would need to switch between the two devices using the card/pcm selector.
In this case, there will be only one set of controls to select the card/pcm device. As of now (I think I'll change to to add another separate set of controls per stream) if you did support multiple streams, then the current card/PCM device selector would take in multiple arugments. (ie for two streams the kcontrol can take in two values)
Then it is implementation detail of your device, and it should be implemented as controls in your device instead of as part of generic API.
I initially had it as part of the device specific files, but I did get some feedback on [1], it might be better to have generic control names, hence the reason for moving into soc-usb.
I'll spend some time to evaluate your suggestion about moving the logic to control the offloading from USB SND versus ASoC, since there are valid points. However, before I do that, I just want to make sure folks are also inline with that thinking. I've had to put a lot of effort moving things around such as the previous example, and now you've suggested to move it back to the vendor specific drivers.
@Pierre, since you've helped with providing a lot of valuable input in the previous revisions on the kcontrol uses, what do you think about the proposal from Amadeusz? Basically shifting the offload device selection into USB SND from the ASoC USB BE driver, and having this per USB SND device.
[1] https://lore.kernel.org/linux-usb/20231017200109.11407-30-quic_wcheng@quicin...
I'll spend some time to evaluate your suggestion about moving the logic to control the offloading from USB SND versus ASoC, since there are valid points. However, before I do that, I just want to make sure folks are also inline with that thinking. I've had to put a lot of effort moving things around such as the previous example, and now you've suggested to move it back to the vendor specific drivers.
@Pierre, since you've helped with providing a lot of valuable input in the previous revisions on the kcontrol uses, what do you think about the proposal from Amadeusz? Basically shifting the offload device selection into USB SND from the ASoC USB BE driver, and having this per USB SND device.
[1] https://lore.kernel.org/linux-usb/20231017200109.11407-30-quic_wcheng@quicin...
This thread is very hard to follow, I am not sure I fully understood the initial proposal, and I am not sure I follow Amadeusz' either.
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
At any rate, I would put all the controls under the USB generic card, because it's always present no matter what the controller or DSP configurations are.
Hi Pierre,
On 6/21/2024 1:27 AM, Pierre-Louis Bossart wrote:
I'll spend some time to evaluate your suggestion about moving the logic to control the offloading from USB SND versus ASoC, since there are valid points. However, before I do that, I just want to make sure folks are also inline with that thinking. I've had to put a lot of effort moving things around such as the previous example, and now you've suggested to move it back to the vendor specific drivers.
@Pierre, since you've helped with providing a lot of valuable input in the previous revisions on the kcontrol uses, what do you think about the proposal from Amadeusz? Basically shifting the offload device selection into USB SND from the ASoC USB BE driver, and having this per USB SND device.
[1] https://lore.kernel.org/linux-usb/20231017200109.11407-30-quic_wcheng@quicin...
This thread is very hard to follow, I am not sure I fully understood the initial proposal, and I am not sure I follow Amadeusz' either.
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
Thanks
Wesley Cheng
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
Hi Pierre/Amadeusz,
On 7/2/2024 1:30 AM, Pierre-Louis Bossart wrote:
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
No, writable and readable.
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
[1] - Re: [PATCH v23 32/32] ASoC: doc: Add documentation for SOC USB - Amadeusz Sławiński (kernel.org) https://lore.kernel.org/linux-usb/510468c7-b181-48d0-bf2d-3e478b2f2aca@linux.intel.com/
Thanks
Wesley Cheng
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
It's a bit over-engineered IMHO.
My alternate suggestion is a read-only control reporting that offload is possible. Then userspace attempts to open a PCM device on the ASoC card, any failures due to resources would be handled at that point.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
It's very hard to follow, I don't understand what userspace needs to 'control' - in the modify sense. What userspace needs is a place to read from, and then select the PCM device and follow usual ALSA configuration with hw_params.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
No, writable and readable.
The writable part introduces a complicated error handling, e.g. what happens if you have an offloaded stream and then this control is changed with amixer while streaming?
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
I still fundamentally don't get why userspace would try and modify any controls, this makes the flows more complicated IMHO since you also have the PCM open/hw_params stages. I really think it'd be more than enough if the USB card exposed read-only values showing that offload is possible and which card/device to map to. Then userspace uses the ASoC PCM device and errors are handled at that level.
On 7/3/2024 10:49 AM, Pierre-Louis Bossart wrote:
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
It's a bit over-engineered IMHO.
My alternate suggestion is a read-only control reporting that offload is possible. Then userspace attempts to open a PCM device on the ASoC card, any failures due to resources would be handled at that point.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
It's very hard to follow, I don't understand what userspace needs to 'control' - in the modify sense. What userspace needs is a place to read from, and then select the PCM device and follow usual ALSA configuration with hw_params.
From what I've seen I assumed that goal is to allow Offloading of specific stream from USB card. Otherwise I would say controls are not needed at all, as more user friendly solution is Offloading streams in order they are used as long as resources are available.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
No, writable and readable.
The writable part introduces a complicated error handling, e.g. what happens if you have an offloaded stream and then this control is changed with amixer while streaming?
-EBUSY? and keep old value
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
I still fundamentally don't get why userspace would try and modify any controls, this makes the flows more complicated IMHO since you also have the PCM open/hw_params stages. I really think it'd be more than enough if the USB card exposed read-only values showing that offload is possible and which card/device to map to. Then userspace uses the ASoC PCM device and errors are handled at that level.
I tend to agree, less values to change, less chance something breaks. However I think that there should be some way to disable Offload in case something doesn't work properly. (It doesn't have to be control, one can go with module parameter or sysfs toggle or something.)
There are really multiple layers to deal with
a) is the controller able to support the offload path? IIRC this is embedded in an obscure XHCI property, it would make sense to expose it as a control, or component string, of the USB card.
If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
b) is there a companion card capable of dealing with the offload path? Since the presence of this card may depend on driver probe, there should be a control on the USB card. userspace could detect changes to this control and detect if that path is or is no longer enabled.
So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
It's a bit over-engineered IMHO.
My alternate suggestion is a read-only control reporting that offload is possible. Then userspace attempts to open a PCM device on the ASoC card, any failures due to resources would be handled at that point.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform
card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
It's very hard to follow, I don't understand what userspace needs to 'control' - in the modify sense. What userspace needs is a place to read from, and then select the PCM device and follow usual ALSA configuration with hw_params.
From what I've seen I assumed that goal is to allow Offloading of specific stream from USB card. Otherwise I would say controls are not needed at all, as more user friendly solution is Offloading streams in order they are used as long as resources are available.
That's not great in terms of audio routing, you'd really want more rules or controlled behavior where the order in which devices are used does not matter.
c) which PCM device is actually offloaded? This could be plural for some implementations. The mapping between PCM devices exposed by the USB card, and those exposed by the companion card, should be known to userspace. I am not sure how this would be done though, a variable number of controls is a sure way to confuse userspace.
Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
No, writable and readable.
The writable part introduces a complicated error handling, e.g. what happens if you have an offloaded stream and then this control is changed with amixer while streaming?
-EBUSY? and keep old value
That would require a stop, fw_free, close, reopening of the non-offloaded device and restart. Best to avoid interrupting streams, if there are no resources that should be detected with an early fail during open/hw_params. Once the stream is flowing, it should not be interrupted - unless the USB device is removed of course.
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
I still fundamentally don't get why userspace would try and modify any controls, this makes the flows more complicated IMHO since you also have the PCM open/hw_params stages. I really think it'd be more than enough if the USB card exposed read-only values showing that offload is possible and which card/device to map to. Then userspace uses the ASoC PCM device and errors are handled at that level.
I tend to agree, less values to change, less chance something breaks. However I think that there should be some way to disable Offload in case something doesn't work properly. (It doesn't have to be control, one can go with module parameter or sysfs toggle or something.)
Agree with this, a 'static' configuration to disable offload would be just fine. Module parameter is fine.
A control to read if offload is possible and what the mapping is would be good. From there on, userspace may open the offloaded PCM and deal with all events (hw_params not supported, xruns, removal, etc).
On 7/3/2024 2:50 AM, Pierre-Louis Bossart wrote:
> There are really multiple layers to deal with > > a) is the controller able to support the offload path? IIRC this is > embedded in an obscure XHCI property, it would make sense to > expose it > as a control, or component string, of the USB card. If a component string/tag is desired, I already have some way of doing that. I can add it to the USB card.
> b) is there a companion card capable of dealing with the offload > path? > Since the presence of this card may depend on driver probe, there > should > be a control on the USB card. userspace could detect changes to this > control and detect if that path is or is no longer enabled. So currently, the "USB Offload Playback Capable Card" kcontrol (on the USB card) will determine if there is an offload path. However, this differs than what Amadeusz is suggesting, in that he wants a single kcontrol created for EACH USB card identified (per USB audio device), and a simple enable/disable control to determine if the offload path is enabled for that card/pcm stream.
It would be a simpler approach for the userspace, and if the card that handles the offload card isn't present, then these enable/disable control will be set to "disabled," and even if users attempt to set the control, it won't go through.
Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
It's a bit over-engineered IMHO.
My alternate suggestion is a read-only control reporting that offload is possible. Then userspace attempts to open a PCM device on the ASoC card, any failures due to resources would be handled at that point.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform
card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
It's very hard to follow, I don't understand what userspace needs to 'control' - in the modify sense. What userspace needs is a place to read from, and then select the PCM device and follow usual ALSA configuration with hw_params.
From what I've seen I assumed that goal is to allow Offloading of specific stream from USB card. Otherwise I would say controls are not needed at all, as more user friendly solution is Offloading streams in order they are used as long as resources are available.
That's not great in terms of audio routing, you'd really want more rules or controlled behavior where the order in which devices are used does not matter.
So to clarify, when I mention to 'control' this is in case userspace does want to modify which USB device is offloaded. By default, the current behavior is that the latest USB headset is going to be enabled for offloading. IF say...userspace has some mechanism to switch which USB device is offloaded, they can do so using:
USB Offload Playback Route Card Select
USB Offload Playback Route PCM Select
The above controls are read/write. read will fetch the current USB card and pcm indexes being enabled for offload. write will set the USB card and pcm index to enable offload on. Both reside on the ASoC card that is associated w/ the USB BE DAI link.
> c) which PCM device is actually offloaded? This could be plural > for some > implementations. The mapping between PCM devices exposed by the USB > card, and those exposed by the companion card, should be known to > userspace. I am not sure how this would be done though, a variable > number of controls is a sure way to confuse userspace. Expanding on Amadeusz's suggestion, my idea is to have an enable/disable kcontrol per USB stream. For example, one USB card could have multiple PCM devices (USB streams). So we would have something like:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream#1 enable/disable
....
are those read-only or not?
No, writable and readable.
The writable part introduces a complicated error handling, e.g. what happens if you have an offloaded stream and then this control is changed with amixer while streaming?
-EBUSY? and keep old value
That would require a stop, fw_free, close, reopening of the non-offloaded device and restart. Best to avoid interrupting streams, if there are no resources that should be detected with an early fail during open/hw_params. Once the stream is flowing, it should not be interrupted
- unless the USB device is removed of course.
I agree. We don't want to interrupt streams if some reason someone tries to switch the offload path. If there is already an active offload stream, then any attempt to switch/control which USB card/pcm stream is offload is going to be ignored.
So we'd know which USB card and PCM device is selected for USB SND. However, I see what you're getting at in case there are multiple supported streams, because userspace needs to know which ASoC card/pcm combination corresponds to which USB device/combination.
I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
What do you think about having a USB card kcontrol to display the mapped ASoC card and PCM indexes?
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
To summarize, if we did this, I'd plan to remove all the kcontrols in ASoC card, and have the following in the USB card for an USB audio device that supports one USB stream:
PCM Offload Playback Enable Stream#0 enable/disable
PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, PCM device#1)
... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
I still fundamentally don't get why userspace would try and modify any controls, this makes the flows more complicated IMHO since you also have the PCM open/hw_params stages. I really think it'd be more than enough if the USB card exposed read-only values showing that offload is possible and which card/device to map to. Then userspace uses the ASoC PCM device and errors are handled at that level.
Just so I understand...is it really desired that userspace doesn't have the flexibility to choose which USB device is offloaded? I know it complicates what needs to be done, but it could be just an additional feature that can be added later on. Again, by default, we select the last USB headset plugged in to be enabled for offload by default.
I tend to agree, less values to change, less chance something breaks. However I think that there should be some way to disable Offload in case something doesn't work properly. (It doesn't have to be control, one can go with module parameter or sysfs toggle or something.)
Agree with this, a 'static' configuration to disable offload would be just fine. Module parameter is fine.
A control to read if offload is possible and what the mapping is would be good. From there on, userspace may open the offloaded PCM and deal with all events (hw_params not supported, xruns, removal, etc).
I can look into adding this mapping part to the USB SND card, so we know which ASoC card/pcm devices are associated to the USB SND device for offloading. Thank you for the discussions and input!
Thanks
Wesley Cheng
On 7/4/2024 12:05 AM, Wesley Cheng wrote:
On 7/3/2024 2:50 AM, Pierre-Louis Bossart wrote:
>> There are really multiple layers to deal with >> >> a) is the controller able to support the offload path? IIRC this is >> embedded in an obscure XHCI property, it would make sense to >> expose it >> as a control, or component string, of the USB card. > If a component string/tag is desired, I already have some way of > doing that. I can add it to the USB card. > >> b) is there a companion card capable of dealing with the offload >> path? >> Since the presence of this card may depend on driver probe, there >> should >> be a control on the USB card. userspace could detect changes to this >> control and detect if that path is or is no longer enabled. > So currently, the "USB Offload Playback Capable Card" kcontrol (on > the USB card) will determine if there is an offload path. However, > this differs than what Amadeusz is suggesting, in that he wants a > single kcontrol created for EACH USB card identified (per USB audio > device), and a simple enable/disable control to determine if the > offload path is enabled for that card/pcm stream. > > It would be a simpler approach for the userspace, and if the card > that handles the offload card isn't present, then these > enable/disable control will be set to "disabled," and even if users > attempt to set the control, it won't go through. Not following. Are you suggesting userspace would modify the enable/disable status?
Yes, this is the suggestion. One writeable kcontrol on the USB SND audio device that will control if that USB audio device is going to be offloaded. If the kcontrol reads back "enabled" (or 1) then userspace knows that the offload path is active. Else, if it reads "disabled" (or 0) after the attempt to set the kcontrol, then the offload path was unsuccessfully enabled, ie maybe due to no available offload streams.
It's a bit over-engineered IMHO.
My alternate suggestion is a read-only control reporting that offload is possible. Then userspace attempts to open a PCM device on the ASoC card, any failures due to resources would be handled at that point.
I would just have a read-only control that reports what the hardware can do and which other card can deal with offload. It's up to userspace to select the offloaded PCM device or not.
That is what I have implemented in the previous patch series. One USB SND kcontrol within each USB audio device, which points to the ASoC platform card that supports offloading:
"USB Offload Playback Capable Card" --> returns the card index to the ASoC platform card
From there the offloading control is all within the ASoC platform
card. This is opposite to what Amaduesz suggested in that, the offload control of which USB device to offload should be within USB SND (not ASoC)
It's very hard to follow, I don't understand what userspace needs to 'control' - in the modify sense. What userspace needs is a place to read from, and then select the PCM device and follow usual ALSA configuration with hw_params.
From what I've seen I assumed that goal is to allow Offloading of specific stream from USB card. Otherwise I would say controls are not needed at all, as more user friendly solution is Offloading streams in order they are used as long as resources are available.
That's not great in terms of audio routing, you'd really want more rules or controlled behavior where the order in which devices are used does not matter.
So to clarify, when I mention to 'control' this is in case userspace does want to modify which USB device is offloaded. By default, the current behavior is that the latest USB headset is going to be enabled for offloading. IF say...userspace has some mechanism to switch which USB device is offloaded, they can do so using:
USB Offload Playback Route Card Select
USB Offload Playback Route PCM Select
The above controls are read/write. read will fetch the current USB card and pcm indexes being enabled for offload. write will set the USB card and pcm index to enable offload on. Both reside on the ASoC card that is associated w/ the USB BE DAI link.
>> c) which PCM device is actually offloaded? This could be plural >> for some >> implementations. The mapping between PCM devices exposed by the USB >> card, and those exposed by the companion card, should be known to >> userspace. I am not sure how this would be done though, a variable >> number of controls is a sure way to confuse userspace. > Expanding on Amadeusz's suggestion, my idea is to have an > enable/disable kcontrol per USB stream. For example, one USB card > could have multiple PCM devices (USB streams). So we would have > something like: > > PCM Offload Playback Enable Stream#0 enable/disable > > PCM Offload Playback Enable Stream#1 enable/disable > > .... are those read-only or not?
No, writable and readable.
The writable part introduces a complicated error handling, e.g. what happens if you have an offloaded stream and then this control is changed with amixer while streaming?
-EBUSY? and keep old value
That would require a stop, fw_free, close, reopening of the non-offloaded device and restart. Best to avoid interrupting streams, if there are no resources that should be detected with an early fail during open/hw_params. Once the stream is flowing, it should not be interrupted
- unless the USB device is removed of course.
I agree. We don't want to interrupt streams if some reason someone tries to switch the offload path. If there is already an active offload stream, then any attempt to switch/control which USB card/pcm stream is offload is going to be ignored.
> So we'd know which USB card and PCM device is selected for USB > SND. However, I see what you're getting at in case there are > multiple supported streams, because userspace needs to know which > ASoC card/pcm combination corresponds to which USB device/combination. I don't understand how this would help map the two parts? There's got to be an additional mapping...
It won't help with the mapping. That is something which we'd need to add, suggestion below.
> What do you think about having a USB card kcontrol to display the > mapped ASoC card and PCM indexes? > > PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, > PCM device#1) > > To summarize, if we did this, I'd plan to remove all the kcontrols > in ASoC card, and have the following in the USB card for an USB > audio device that supports one USB stream: > > PCM Offload Playback Enable Stream#0 enable/disable > > PCM Offload Playback Enable Stream Mapping#0 0, 1 (ASoC card#0, > PCM device#1) ... which is suggested here.
Assuming these are read-only controls, we would need to know which PCM device on the USB card can be optimized with the use of which PCM device on the ASoC card. That means a set of three values. You would also want a number of streams to make the guesswork on controls less painful.
OK, so now to just figuring out something that both you and Amadeusz can agree on before I put time implementing it. So I've implemented the "enable/disable" path that Amadeusz suggested, which is highlighted in my previous response, for evaluation purposes. The overall question is which layer should control the devices that will be offloaded. In my submissions up until now, the control was given to the ASoC platform card to determine which USB device to offload. Amadeusz mentioned that it might be beneficial to move the control to the USB SND devices, because what if the offloading is NOT backed by ASoC. (highlighted in [1]) However, IMO the current implementation assumes there is ASoC involved, which should mean that there is some platform "card" that is backing the offload path. Please let me know if my understanding is incorrect, @Amadeusz.
I still fundamentally don't get why userspace would try and modify any controls, this makes the flows more complicated IMHO since you also have the PCM open/hw_params stages. I really think it'd be more than enough if the USB card exposed read-only values showing that offload is possible and which card/device to map to. Then userspace uses the ASoC PCM device and errors are handled at that level.
Just so I understand...is it really desired that userspace doesn't have the flexibility to choose which USB device is offloaded? I know it complicates what needs to be done, but it could be just an additional feature that can be added later on. Again, by default, we select the last USB headset plugged in to be enabled for offload by default.
If it chooses endpoint by itself perhaps you can send patch set without controls first? This has added benefit of less patches in series, making it easier to review and it won't block whole patch set by discussion on controls feature. Controls can be added in followup series.
I tend to agree, less values to change, less chance something breaks. However I think that there should be some way to disable Offload in case something doesn't work properly. (It doesn't have to be control, one can go with module parameter or sysfs toggle or something.)
Agree with this, a 'static' configuration to disable offload would be just fine. Module parameter is fine.
A control to read if offload is possible and what the mapping is would be good. From there on, userspace may open the offloaded PCM and deal with all events (hw_params not supported, xruns, removal, etc).
I can look into adding this mapping part to the USB SND card, so we know which ASoC card/pcm devices are associated to the USB SND device for offloading. Thank you for the discussions and input!
Thanks
Wesley Cheng
Just so I understand...is it really desired that userspace doesn't have the flexibility to choose which USB device is offloaded? I know it complicates what needs to be done, but it could be just an additional feature that can be added later on. Again, by default, we select the last USB headset plugged in to be enabled for offload by default.
If it chooses endpoint by itself perhaps you can send patch set without controls first? This has added benefit of less patches in series, making it easier to review and it won't block whole patch set by discussion on controls feature. Controls can be added in followup series.
We do need read-only controls for userspace to know that offload is possible and which card/device to use. That can be done in a first step assuming there's a single device plugged-in.
Dealing with multiple devices and defining rules or configuration options to select the offloaded device is a second-level problem.
In most cases the only thing that will be offloaded is a headset anyways, so the selection could be rather static based on a vendor/system ID, all other USB devices would be ignored.
On 7/4/2024 4:25 AM, Pierre-Louis Bossart wrote:
Just so I understand...is it really desired that userspace doesn't have the flexibility to choose which USB device is offloaded? I know it complicates what needs to be done, but it could be just an additional feature that can be added later on. Again, by default, we select the last USB headset plugged in to be enabled for offload by default.
If it chooses endpoint by itself perhaps you can send patch set without controls first? This has added benefit of less patches in series, making it easier to review and it won't block whole patch set by discussion on controls feature. Controls can be added in followup series.
We do need read-only controls for userspace to know that offload is possible and which card/device to use. That can be done in a first step assuming there's a single device plugged-in.
I agree, some kcontrol need to be present to at least determine:
1. USB SND device is offload capable (ASoC card and PCM index)- Fetches associated (mapped) ASoC platform card and PCM index (read only)
2. ASoC platform card offload status - Current offload status (read only)
Those would be the minimum kcontrols we could have at this time. I will remove the device selection part, and leave that for future discussions. Does this sound good, Amadeusz/Pierre?
Dealing with multiple devices and defining rules or configuration options to select the offloaded device is a second-level problem.
In most cases the only thing that will be offloaded is a headset anyways, so the selection could be rather static based on a vendor/system ID, all other USB devices would be ignored.
If the USB SND offload driver (ie qc_audio_offload) isn't compiled in, then it would be disabled. Do we need some over-arching mechanism to disable the offload functionality? Although, one thing I can see if I can add is some device classification within the USB offload vendor driver.
Thanks
Wesley Cheng
Hi Pierre/Amadeusz,
On 7/8/2024 4:16 PM, Wesley Cheng wrote:
On 7/4/2024 4:25 AM, Pierre-Louis Bossart wrote:
Just so I understand...is it really desired that userspace doesn't have the flexibility to choose which USB device is offloaded? I know it complicates what needs to be done, but it could be just an additional feature that can be added later on. Again, by default, we select the last USB headset plugged in to be enabled for offload by default.
If it chooses endpoint by itself perhaps you can send patch set without controls first? This has added benefit of less patches in series, making it easier to review and it won't block whole patch set by discussion on controls feature. Controls can be added in followup series.
We do need read-only controls for userspace to know that offload is possible and which card/device to use. That can be done in a first step assuming there's a single device plugged-in.
I agree, some kcontrol need to be present to at least determine:
USB SND device is offload capable (ASoC card and PCM index)- Fetches associated (mapped) ASoC platform card and PCM index (read only)
ASoC platform card offload status - Current offload status (read only)
Those would be the minimum kcontrols we could have at this time. I will remove the device selection part, and leave that for future discussions. Does this sound good, Amadeusz/Pierre?
So I reworked the series a bit with respects to the kcontrols that we had, and I simplified it for the next submission. I went ahead and just have a read only kcontrol residing in the USB SND device and will implement #1 above:
/ # tinymix -D 1 contents Number of controls: 9 ctl type num name value 0 INT 2 Capture Channel Map 0, 0 (range 0->36) 1 INT 2 Playback Channel Map 0, 0 (range 0->36) 2 BOOL 1 Headset Capture Switch On 3 INT 1 Headset Capture Volume 10 (range 0->13) 4 BOOL 1 Sidetone Playback Switch On 5 INT 1 Sidetone Playback Volume 4096 (range 0->8192) 6 BOOL 1 Headset Playback Switch On 7 INT 2 Headset Playback Volume 20, 20 (range 0->24) 8 INT 2 USB Offload Playback Route PCM#0 0, 0 (range -1->255)
If there is an available audio offload path, then the value will show the card and pcm index that it is mapped to. That way the application will know which card/pcm device to open from there. In the above example, the offload path is mapped to card#0 pcm#0. If there is no offload path available, it will show -1, -1.
For now, I removed the control that allows for explicit selection of which USB card and PCM device to offload, and will take this up on a separate series as we see fit. The codebase I have now will select the last USB headset plugged in for offloading. Will clean up the changes and submit a new revision with the other feedback included as well.
Thanks
Wesley Cheng
Dealing with multiple devices and defining rules or configuration options to select the offloaded device is a second-level problem.
In most cases the only thing that will be offloaded is a headset anyways, so the selection could be rather static based on a vendor/system ID, all other USB devices would be ignored.
If the USB SND offload driver (ie qc_audio_offload) isn't compiled in, then it would be disabled. Do we need some over-arching mechanism to disable the offload functionality? Although, one thing I can see if I can add is some device classification within the USB offload vendor driver.
Thanks
Wesley Cheng
On 6/11/2024 1:57 AM, Wesley Cheng wrote:
Wesley Cheng (32): ASoC: Add SOC USB APIs for adding an USB backend ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp ASoC: qdsp6: q6afe: Increase APR timeout ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 ALSA: usb-audio: Introduce USB SND platform op callbacks ALSA: usb-audio: Export USB SND APIs for modules ALSA: usb-audio: Save UAC sample size information usb: dwc3: Specify maximum number of XHCI interrupters usb: host: xhci-plat: Set XHCI max interrupters if property is present ALSA: usb-audio: qcom: Add USB QMI definitions ALSA: usb-audio: qcom: Introduce QC USB SND offloading support ALSA: usb-audio: Check for support for requested audio format ASoC: usb: Add PCM format check API for USB backend ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device ALSA: usb-audio: Prevent starting of audio stream if in use ALSA: usb-audio: Do not allow USB offload path if PCM device is in use ASoC: dt-bindings: Update example for enabling USB offload on SM8250 ALSA: usb-audio: qcom: Populate PCM and USB chip information ASoC: qcom: qdsp6: Add support to track available USB PCM devices ASoC: Introduce SND kcontrols to select sound card and PCM device ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks ASoC: Introduce SND kcontrols to track USB offloading state ASoC: qcom: qdsp6: Add PCM ops to track current state ASoC: usb: Create SOC USB SND jack kcontrol ASoC: qcom: qdsp6: Add headphone jack for offload connection status ASoC: usb: Fetch ASoC sound card information ALSA: usb-audio: Add USB offloading capable kcontrol ALSA: usb-audio: Allow for rediscovery of connected USB SND devices ALSA: usb-audio: qcom: Use card and PCM index from QMI request ASoC: usb: Rediscover USB SND devices on USB port add ASoC: doc: Add documentation for SOC USB
I'm not sure how other reviewers feel about this, but is there any chance to group patches in some logical order? It is bit hard to review when I need to jump from generic ALSA to ASoC then QCOM code and then there are dt-bindings mixed in between and back again.
On 6/12/24 16:50, Amadeusz Sławiński wrote:
On 6/11/2024 1:57 AM, Wesley Cheng wrote:
Wesley Cheng (32): ASoC: Add SOC USB APIs for adding an USB backend ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp ASoC: qdsp6: q6afe: Increase APR timeout ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 ALSA: usb-audio: Introduce USB SND platform op callbacks ALSA: usb-audio: Export USB SND APIs for modules ALSA: usb-audio: Save UAC sample size information usb: dwc3: Specify maximum number of XHCI interrupters usb: host: xhci-plat: Set XHCI max interrupters if property is present ALSA: usb-audio: qcom: Add USB QMI definitions ALSA: usb-audio: qcom: Introduce QC USB SND offloading support ALSA: usb-audio: Check for support for requested audio format ASoC: usb: Add PCM format check API for USB backend ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device ALSA: usb-audio: Prevent starting of audio stream if in use ALSA: usb-audio: Do not allow USB offload path if PCM device is in use ASoC: dt-bindings: Update example for enabling USB offload on SM8250 ALSA: usb-audio: qcom: Populate PCM and USB chip information ASoC: qcom: qdsp6: Add support to track available USB PCM devices ASoC: Introduce SND kcontrols to select sound card and PCM device ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks ASoC: Introduce SND kcontrols to track USB offloading state ASoC: qcom: qdsp6: Add PCM ops to track current state ASoC: usb: Create SOC USB SND jack kcontrol ASoC: qcom: qdsp6: Add headphone jack for offload connection status ASoC: usb: Fetch ASoC sound card information ALSA: usb-audio: Add USB offloading capable kcontrol ALSA: usb-audio: Allow for rediscovery of connected USB SND devices ALSA: usb-audio: qcom: Use card and PCM index from QMI request ASoC: usb: Rediscover USB SND devices on USB port add ASoC: doc: Add documentation for SOC USB
I'm not sure how other reviewers feel about this, but is there any chance to group patches in some logical order? It is bit hard to review when I need to jump from generic ALSA to ASoC then QCOM code and then there are dt-bindings mixed in between and back again.
Completely agree. And splitting the 32 patches in smaller sets would help as well, every time I want to review I just don't have the time to go through 32 heavy-duty patches across USB/ALSA/ASoC.
Hi Pierre,
On 6/12/2024 7:59 AM, Pierre-Louis Bossart wrote:
On 6/12/24 16:50, Amadeusz Sławiński wrote:
On 6/11/2024 1:57 AM, Wesley Cheng wrote:
Wesley Cheng (32): ASoC: Add SOC USB APIs for adding an USB backend ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp ASoC: qdsp6: q6afe: Increase APR timeout ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 ALSA: usb-audio: Introduce USB SND platform op callbacks ALSA: usb-audio: Export USB SND APIs for modules ALSA: usb-audio: Save UAC sample size information usb: dwc3: Specify maximum number of XHCI interrupters usb: host: xhci-plat: Set XHCI max interrupters if property is present ALSA: usb-audio: qcom: Add USB QMI definitions ALSA: usb-audio: qcom: Introduce QC USB SND offloading support ALSA: usb-audio: Check for support for requested audio format ASoC: usb: Add PCM format check API for USB backend ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device ALSA: usb-audio: Prevent starting of audio stream if in use ALSA: usb-audio: Do not allow USB offload path if PCM device is in use ASoC: dt-bindings: Update example for enabling USB offload on SM8250 ALSA: usb-audio: qcom: Populate PCM and USB chip information ASoC: qcom: qdsp6: Add support to track available USB PCM devices ASoC: Introduce SND kcontrols to select sound card and PCM device ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks ASoC: Introduce SND kcontrols to track USB offloading state ASoC: qcom: qdsp6: Add PCM ops to track current state ASoC: usb: Create SOC USB SND jack kcontrol ASoC: qcom: qdsp6: Add headphone jack for offload connection status ASoC: usb: Fetch ASoC sound card information ALSA: usb-audio: Add USB offloading capable kcontrol ALSA: usb-audio: Allow for rediscovery of connected USB SND devices ALSA: usb-audio: qcom: Use card and PCM index from QMI request ASoC: usb: Rediscover USB SND devices on USB port add ASoC: doc: Add documentation for SOC USB
I'm not sure how other reviewers feel about this, but is there any chance to group patches in some logical order? It is bit hard to review when I need to jump from generic ALSA to ASoC then QCOM code and then there are dt-bindings mixed in between and back again.
Completely agree. And splitting the 32 patches in smaller sets would help as well, every time I want to review I just don't have the time to go through 32 heavy-duty patches across USB/ALSA/ASoC.
Will try my best, but I've already attempted to compartmentalize everything as how it is. Will try to first re-organize the patches based on what Amadeusz recommended and see if that helps.
Thanks Wesley Cheng
Hi Amadeusz,
On 6/12/2024 7:50 AM, Amadeusz Sławiński wrote:
On 6/11/2024 1:57 AM, Wesley Cheng wrote:
Wesley Cheng (32): ASoC: Add SOC USB APIs for adding an USB backend ASoC: dt-bindings: qcom,q6dsp-lpass-ports: Add USB_RX port ASoC: qcom: qdsp6: Introduce USB AFE port to q6dsp ASoC: qdsp6: q6afe: Increase APR timeout ASoC: qcom: qdsp6: Add USB backend ASoC driver for Q6 ALSA: usb-audio: Introduce USB SND platform op callbacks ALSA: usb-audio: Export USB SND APIs for modules ALSA: usb-audio: Save UAC sample size information usb: dwc3: Specify maximum number of XHCI interrupters usb: host: xhci-plat: Set XHCI max interrupters if property is present ALSA: usb-audio: qcom: Add USB QMI definitions ALSA: usb-audio: qcom: Introduce QC USB SND offloading support ALSA: usb-audio: Check for support for requested audio format ASoC: usb: Add PCM format check API for USB backend ASoC: qcom: qdsp6: Ensure PCM format is supported by USB audio device ALSA: usb-audio: Prevent starting of audio stream if in use ALSA: usb-audio: Do not allow USB offload path if PCM device is in use ASoC: dt-bindings: Update example for enabling USB offload on SM8250 ALSA: usb-audio: qcom: Populate PCM and USB chip information ASoC: qcom: qdsp6: Add support to track available USB PCM devices ASoC: Introduce SND kcontrols to select sound card and PCM device ASoC: qcom: qdsp6: Add SOC USB offload select get/put callbacks ASoC: Introduce SND kcontrols to track USB offloading state ASoC: qcom: qdsp6: Add PCM ops to track current state ASoC: usb: Create SOC USB SND jack kcontrol ASoC: qcom: qdsp6: Add headphone jack for offload connection status ASoC: usb: Fetch ASoC sound card information ALSA: usb-audio: Add USB offloading capable kcontrol ALSA: usb-audio: Allow for rediscovery of connected USB SND devices ALSA: usb-audio: qcom: Use card and PCM index from QMI request ASoC: usb: Rediscover USB SND devices on USB port add ASoC: doc: Add documentation for SOC USB
I'm not sure how other reviewers feel about this, but is there any chance to group patches in some logical order? It is bit hard to review when I need to jump from generic ALSA to ASoC then QCOM code and then there are dt-bindings mixed in between and back again.
OK I'll see if I can re-order them to make it easier to look at between layers.
Thanks Wesley Cheng
participants (4)
-
Amadeusz Sławiński
-
Bagas Sanjaya
-
Pierre-Louis Bossart
-
Wesley Cheng