Skip to content

UAC2 Gadget: feedback endpoint support

Jerome Brunet linux-usb 2 versions – New

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v3 Latest3 patches 0 repliesNew
  2. v2 RFC3 patches 11 repliesSuperseded

Patches in v3 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3usb: gadget: f_uac2/u_audio: add feedback endpoint supportdrivers/usb/gadget/function/f_uac2.c drivers/usb/gadget/function/u_audio.c drivers/usb/gadget/function/u_audio.h+168 -30 replies
2/3usb: gadget: f_uac2: add adaptive sync support for captureDocumentation/ABI/testing/configfs-usb-gadget-uac2 Documentation/usb/gadget-testing.rst drivers/usb/gadget/function/f_uac2.c +1 more+95 -90 replies
3/3usb: gadget: u_audio: add real feedback implementationDocumentation/ABI/testing/configfs-usb-gadget-uac2 Documentation/usb/gadget-testing.rst drivers/usb/gadget/function/f_uac2.c +3 more+136 -100 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v3 yet.

Read the v3 thread

Cover letter [PATCH v3 0/3] UAC2 Gadget: feedback endpoint support

Current UAC2 gadget implements capture/sync paths as two USB ISO ASYNC endpoints (IN and OUT).

This violates USB spec which says that ISO ASYNC OUT endpoint should have feedback companion endpoint. See USB2.0 spec "5.12.4.1 Synchronization Type": asynchronous sink provides explicit feedback (isochronous pipe). Interesting that for ISO ASYNC *IN* endpoint respective feedback isn't required since source provides implicit feedforward (data stream).

While it's not an issue if UAC2 Gadget is connected to Linux host (Linux ignores missing feedback endpoint), with other hosts like Windows or MacOS the UAC2 Gadget isn't enumerated due to missing feedback endpoint.

This patch series adds feedback endpoint support to UAC2 function, new control to UAC2 mixer which can be used by userspace tools (like alsaloop from alsa-utils) for updating feedback frequency reported to the host. This is useful for usecases when UAC2 Gadget's audio samples are played to another codec or audio card with its own internal freerunning clock so host can be notified that more/less samples are required.

The alsaloop tool requires some (relatively small) modifications in order to start support driving feedback frequency through UAC2 mixer control. That change will be sent as a separate patch to ALSA community.

Also added ability to switch ISO ASYNC OUT endpoint into adaptive endpoint which doesn't require feedback endpoint (as per USB spec).

v2 [2] -> v3:
* Just fold 9 left shift in the feedback calculation to avoid dealing with big numbers (as suggested by Pavel Hofman)

v1 [0] -> v2:
* Instead of HW rate used by gadget (which the controlling application might not be directly dealing with), the kcontrol used to provide the feedback value is expressed in PPM. This way the correction is agnostic of the rate used by the gadget while retaining enough precision to allow a smooth adaptation of the clock on the playback side, if necessary.
* The minimum value for the correction is aligned with sound/usb/endpoint.c at -25%.
* The maximum correction must be chosen more carefully as it impact the bandwidth required by the output EP. The minimum is one extra frame per packet. This is ~500PPM at 192KHz. This seemed more than enough while testing.
Of course, there is a trade off between saving bandwidth and enabling devices with a significant (abnormal) clock deviation. The default extra reserved bandwidth is set at 500PPM but it is configurable through configfs, like the rest of the gadget.

I have kept Ruslan assigned as the author of series. He did the vast majority of the work and deserve the credit. I have merely tweaked in his original patchset.

This patchset has been tested on an arm64 host at HIGH_SPEED, with various rates and channel configuration. I have not tested with FULL_SPEED or SUPER_SPEED.

See here [1] an example of regulation with a patched version of alsaloop.

[0]: https://lore.kernel.org/r/[email protected]
[1]: https://pastebin.com/0hiK7LAe
[2]: https://lore.kernel.org/r/[email protected]

Ruslan Bilovol (3):
usb: gadget: f_uac2/u_audio: add feedback endpoint support
usb: gadget: f_uac2: add adaptive sync support for capture
usb: gadget: u_audio: add real feedback implementation

 .../ABI/testing/configfs-usb-gadget-uac2      |   2 +
 Documentation/usb/gadget-testing.rst          |   2 +
 drivers/usb/gadget/function/f_uac2.c          | 144 ++++++++++-
 drivers/usb/gadget/function/u_audio.c         | 225 +++++++++++++++++-
 drivers/usb/gadget/function/u_audio.h         |  12 +
 drivers/usb/gadget/function/u_uac2.h          |   4 +
 6 files changed, 383 insertions(+), 6 deletions(-)
Signature · 1 line
2.32.0.rc0