Skip to content

Commit

Permalink
usb: gadget: u_audio: EP-OUT bInterval in fback frequency
Browse files Browse the repository at this point in the history
commit f5dfd98 upstream.

The patch increases the bitshift in feedback frequency
calculation with EP-OUT bInterval value.

Tests have revealed that Win10 and OSX UAC2 drivers require
the feedback frequency to be based on the actual packet
interval instead of on the USB2 microframe. Otherwise they
ignore the feedback value. Linux snd-usb-audio driver
detects the applied bitshift automatically.

Tested-by: Henrik Enquist <henrik.enquist@gmail.com>
Signed-off-by: Pavel Hofman <pavel.hofman@ivitera.com>
Cc: stable <stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210906130822.12256-1-pavel.hofman@ivitera.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
pavhofman authored and gregkh committed Sep 30, 2021
1 parent 2951779 commit 40fe835
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/usb/gadget/function/u_audio.c
Expand Up @@ -76,11 +76,13 @@ static const struct snd_pcm_hardware uac_pcm_hardware = {
};

static void u_audio_set_fback_frequency(enum usb_device_speed speed,
struct usb_ep *out_ep,
unsigned long long freq,
unsigned int pitch,
void *buf)
{
u32 ff = 0;
const struct usb_endpoint_descriptor *ep_desc;

/*
* Because the pitch base is 1000000, the final divider here
Expand Down Expand Up @@ -108,8 +110,13 @@ static void u_audio_set_fback_frequency(enum usb_device_speed speed,
* byte fromat (that is Q16.16)
*
* ff = (freq << 16) / 8000
*
* Win10 and OSX UAC2 drivers require number of samples per packet
* in order to honor the feedback value.
* Linux snd-usb-audio detects the applied bit-shift automatically.
*/
freq <<= 4;
ep_desc = out_ep->desc;
freq <<= 4 + (ep_desc->bInterval - 1);
}

ff = DIV_ROUND_CLOSEST_ULL((freq * pitch), 1953125);
Expand Down Expand Up @@ -247,7 +254,7 @@ static void u_audio_iso_fback_complete(struct usb_ep *ep,
pr_debug("%s: iso_complete status(%d) %d/%d\n",
__func__, status, req->actual, req->length);

u_audio_set_fback_frequency(audio_dev->gadget->speed,
u_audio_set_fback_frequency(audio_dev->gadget->speed, audio_dev->out_ep,
params->c_srate, prm->pitch,
req->buf);

Expand Down Expand Up @@ -506,7 +513,7 @@ int u_audio_start_capture(struct g_audio *audio_dev)
* be meauserd at start of playback
*/
prm->pitch = 1000000;
u_audio_set_fback_frequency(audio_dev->gadget->speed,
u_audio_set_fback_frequency(audio_dev->gadget->speed, ep,
params->c_srate, prm->pitch,
req_fback->buf);

Expand Down

0 comments on commit 40fe835

Please sign in to comment.