Message ID | 20240925010000.2231406-1-quic_wcheng@quicinc.com |
---|---|
Headers | show |
Series | Introduce QC USB SND audio offloading support | expand |
> + 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``: jack component to populate > + > +**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 > + > + int snd_soc_usb_disable_offload_jack(struct snd_soc_component *component) > +.. > + > + - ``component``: ASoC component to disable the jack > + > +**snd_soc_usb_disable_offload_jack()** is a helper to disable a sound jack control > +on the platform sound card. is disable_offload_jack() the companion operation to setup_offload_jack()? it's not clear to me if there's any relationship between the two. > + > +Returns 0 on success, negative otherwise. > + > +.. code-block:: rst > + > + int snd_soc_usb_update_offload_route(struct device *dev, int card, int pcm, > + int direction, long *route) > +.. > + > + - ``dev``: USB device to look up offload path mapping > + - ``card``: USB sound card index > + - ``pcm``: USB sound PCM device index > + - ``direction``: direction to fetch offload routing information > + - ``route``: mapping of sound card and pcm indexes for the offload path. This is > + an array of two integers that will carry the card and pcm device indexes > + in that specific order. This can be used as the array for the kcontrol > + output. > + > +**snd_soc_usb_update_offload_route()** calls a registered callback to the USB BE DAI > +link to fetch the information about the mapped ASoC devices for executing USB audio > +offload for the device. ``route`` may be a pointer to a kcontrol value output array, > +which carries values when the kcontrol is read. > + > +Returns 0 on success, negative otherwise. please clarify what happens if there is no offloaded device for a specific USB card. from [2] below it looks like the intended behavior for a device without offload capabilities would be to return 0 but the mapping would use the -1 magic value to state there is no offload? > +**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. I don't think the last sentence is correct, below [1] you show an example where the free_port() routine is required... > + > + static void q6usb_component_remove(struct snd_soc_component *component) > + { > + ... [1] > + 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 ports 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. > +connection_status_cb() can be used to notify the BE DAI link of any change. > + > +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 situation: > + > + **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 unbound, 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 > + > +USB Offload Related Kcontrols > +============================= > +Details > +------- > +A set of kcontrols can be utilized by applications to help select the proper sound > +devices to enable USB audio offloading. SOC USB exposes the get_offload_dev() > +callback that designs can use to ensure that the proper indices are returned to the > +application. > + > +Implementation > +-------------- > + > +**Example:** > + > + **Sound Cards**: > + > + :: > + > + 0 [SM8250MTPWCD938]: sm8250 - SM8250-MTP-WCD9380-WSA8810-VA-D > + SM8250-MTP-WCD9380-WSA8810-VA-DMIC > + 1 [Seri ]: USB-Audio - Plantronics Blackwire 3225 Seri > + Plantronics Plantronics Blackwire > + 3225 Seri at usb-xhci-hcd.1.auto-1.1, > + full sp > + 2 [C320M ]: USB-Audio - Plantronics C320-M > + Plantronics Plantronics C320-M at usb-xhci-hcd.1.auto-1.2, full speed > + > + **USB Sound Card** - card#1: > + > + :: > + > + USB Offload Playback Route PCM#0 -1, -1 (range -1->255) > + > + **USB Sound Card** - card#2: > + > + :: > + > + USB Offload Playback Route PCM#0 0, 1 (range -1->255) > + > +The above example shows a scenario where the system has one ASoC platform card > +(card#0) and two USB sound devices connected (card#1 and card#2). When reading > +the available kcontrols for each USB audio device, the following kcontrol lists > +the mapped offload path for the specific device: > + > + ``USB Offload Playback Route#*`` > + > +The kcontrol is indexed, because a USB audio device could potentially have > +several PCM devices. The above kcontrols are defined as: > + > + - ``USB Offload Playback Route PCM`` **(R)**: Returns the ASoC platform sound > + card and PCM device index. The output **"0, 1"** (card index, PCM device index) > + signifies that there is an available offload path for the USB SND device > + through card#0 - PCM device#1. If **"-1, -1"** is seen, then no offload path is > + available for the USB SND device. [2] maybe I got this wrong but you may want to clarify that the kcontrol is always created, but the values indicate if the offload support is real or not? > + > +USB Offload Playback Route 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 (*update_offload_route_info)(struct snd_soc_component *component, > + int card, int pcm, long *route); > +.. > + > +These are specific for the **USB Offload Playback Route PCM#** kcontrol. > + > +When users issue get 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->update_offload_route_info = q6usb_get_offload_dev; > + > + ret = snd_soc_usb_add_port(usb); > +.. > + > +Existing USB Sound Kcontrol > +--------------------------- > +With the introduction of USB offload support, the above USB offload kcontrol > +can be added to the pre existing list of kcontrols identified by the USB sound is this 'can be added' or 'will be added'? The latter seems more correct to me, I don't see anything optional or conditional in the description and the example below. > +framework. These kcontrols are still the main controls that are used to > +modify characteristics pertaining to the USB audio device. > + > + :: > + > + 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 -1, -1 (range -1->255) > + > +Since USB audio device controls are handled over the USB control endpoint, use the > +existing mechanisms present in the USB mixer to set parameters, such as volume.
On 9/25/2024 2:59 AM, Wesley Cheng wrote: > 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 userspace 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 platform 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... > > The current limitation is that the latest USB audio device that is identified > will be automatically selected by the Q6USB BE DAI for offloading. Future > patches can be added to possibly add for more flexibility, but until the userpace > applications can be better defined, having these mechanisms will complicate the > overall implementation. > > USB offload Kcontrols > ===================== > Part of the vendor offload package will have a mixer driver associated with it > (mixer_usb_offload.c). This entity will be responsible for coordinating with > SOC USB and the Q6USB backend DAI to fetch information about the sound card > and PCM device indices associated with the offload path. The logic is done > based on the current implementation of how paths are controlled within the QC > ASoC implementation. > > QC ASoC Q6Routing > ----------------- > Within the Q6 ASOC design, the registered ASoC platform card will expose a set > of kcontrols for enabling the BE DAI links to the FE DAI link. For example: > > tinymix -D 0 contents > Number of controls: 1033 > ctl type num name value > ... > 1025 BOOL 1 USB Mixer MultiMedia1 Off > 1026 BOOL 1 USB Mixer MultiMedia2 Off > 1027 BOOL 1 USB Mixer MultiMedia3 Off > 1028 BOOL 1 USB Mixer MultiMedia4 Off > 1029 BOOL 1 USB Mixer MultiMedia5 Off > 1030 BOOL 1 USB Mixer MultiMedia6 Off > 1031 BOOL 1 USB Mixer MultiMedia7 Off > 1032 BOOL 1 USB Mixer MultiMedia8 Off > > Each of these kcontrols will enable the USB BE DAI link (q6usb) to be connected > to a FE DAI link (q6asm). Since each of these controls are DAPM widgets, when > it is enabled, the DAPM widget's "connect" flag is updated accordingly. > > USB Offload Mapping > ------------------- > Based on the Q6routing, the USB BE DAI link can determine which sound card and > PCM device is enabled for offloading. Fetching the ASoC platform sound card's > information is fairly straightforward, and the bulk of the work goes to finding > the corresponding PCM device index. As mentioned above, the USB BE DAI can > traverse the DAPM widgets to find the DAPM path that is related to the control > for the "USB Mixer." Based on which "USB Mixer" is enabled, it can find the > corresponding DAPM widget associated w/ the FE DAI link (Multimedia*). From there > it can find the PCM device created for the Multimedia* stream. > > Only one BE DAI link can be enabled per FE DAI. For example, if the HDMI path is > enabled for Multimedia1, the USB Mixer will be disabled and switched over. > > Examples of kcontrol > -------------------- > tinymix -D 0 contents > Number of controls: 1033 > ctl type num name > ... > 1025 BOOL 1 USB Mixer MultiMedia1 Off > 1026 BOOL 1 USB Mixer MultiMedia2 On > 1027 BOOL 1 USB Mixer MultiMedia3 Off > 1028 BOOL 1 USB Mixer MultiMedia4 Off > 1029 BOOL 1 USB Mixer MultiMedia5 Off > 1030 BOOL 1 USB Mixer MultiMedia6 Off > 1031 BOOL 1 USB Mixer MultiMedia7 Off > 1032 BOOL 1 USB Mixer MultiMedia8 Off > > tinymix -D 2 contents > Number of controls: 7 > ctl type num name value > 0 INT 2 Playback Channel Map 0, 0 (range 0->36) > 1 BOOL 2 MDR-1ADAC Playback Switch On, On > 2 BOOL 1 MDR-1ADAC Playback Switch On > 3 INT 2 MDR-1ADAC Playback Volume 127, 127 (range 0->127) > 4 INT 1 MDR-1ADAC Playback Volume 127 (range 0->127) > 5 BOOL 1 Sony Internal Clock Validity On > 6 INT 2 USB Offload Playback Route PCM#0 0, 1 (range -1->255) > > The example highlights that the userspace/application can utilize the offload path > for the USB device on card#0 PCM device#1. > > When dealing with multiple USB audio devices, only the latest USB device identified > is going to be selected for offload capable. > > 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 1 (range 0->4) > 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 -1, -1 (range -1->255) > > "-1, -1" shows that this device has no route to the offload path. > > This feature was validated using: > - tinymix: set/enable the multimedia path to route to USB backend > - tinyplay: issue playback on platform card > Just a reminder that I'm still not a fan of this design. Two seemingly unrelated Front Ends end up accessing same resource and blocking each other, that's why there is a need for above kcontrol interface. In my opinion the fact that audio is routed through different HW paths, should not require separate Front Ends. It should start on same FE as it ends on one device. It would be a lot more user friendly that when end user opens USB FE it will just happen automatically, with current implementation user space needs to be aware of two separate front ends and internal dependency between them based on kcontrol value. If there is need to selectively disable it due to problems with some HW or in testing, just provide simple kcontrol on whole USB device with values "auto"(default), "force" (to always force offload), "off" (to disable it).