linux-doc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Pavel Hofman <pavel.hofman@ivitera.com>
To: Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Jonathan Corbet <corbet@lwn.net>
Cc: gschmottlach@gmail.com, linux-usb@vger.kernel.org,
	linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 2/8] usb: gadget: f_uac2/u_audio: add feedback endpoint support
Date: Sat, 17 Apr 2021 11:43:15 +0200	[thread overview]
Message-ID: <be928b87-9ebe-43da-216d-40904b7ef8e0@ivitera.com> (raw)
In-Reply-To: <1614603943-11668-3-git-send-email-ruslan.bilovol@gmail.com>

Dne 01. 03. 21 v 14:05 Ruslan Bilovol napsal(a):
> +static void u_audio_set_fback_frequency(enum usb_device_speed speed,
> +					unsigned int freq, void *buf)
> +{
> +	u32 ff = 0;
> +
> +	if (speed == USB_SPEED_FULL) {
> +		/*
> +		 * Full-speed feedback endpoints report frequency
> +		 * in samples/microframe
> +		 * Format is encoded in Q10.10 left-justified in the 24 bits,
> +		 * so that it has a Q10.14 format.
> +		 */
> +		ff = DIV_ROUND_UP((freq << 14), 1000);
> +	} else {
> +		/*
> +		 * High-speed feedback endpoints report frequency
> +		 * in samples/microframe.
> +		 * Format is encoded in Q12.13 fitted into four bytes so that
> +		 * the binary point is located between the second and the third
> +		 * byte format (that is Q16.16)
> +		 *
> +		 * Prevent integer overflow by calculating in Q12.13 format and
> +		 * then shifting to Q16.16
> +		 */
> +		ff = DIV_ROUND_UP((freq << 13), (8*1000)) << 3;
> +	}

Hi Ruslan,

Thanks a lot for your patch. The HS calculation of Q16.16 feedback value
overflows at some 524kHz, disallowing use of larger samplerates (e.g.
768kHz or higher).

I tested the formula used in alsa USB driver
https://github.com/torvalds/linux/blob/d99676af540c2dc829999928fb81c58c80a1dce4/sound/usb/endpoint.c#L80
which uses only 10bit shift. The feedback control in UAC2 gadget now
works up to 4M samplerate with 1Hz precision (tested on RPi4 with
bInterval = 1, checked in stream0 proc file on linux host).

--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -118,7 +119,8 @@ static void u_audio_set_fback_frequency(enum
usb_device_speed speed,
                 * Prevent integer overflow by calculating in Q12.13
format and
                 * then shifting to Q16.16
                 */
-               ff = DIV_ROUND_UP((freq << 13), (8*1000)) << 3;
+               //ff = DIV_ROUND_UP((freq << 13), (8*1000)) << 3;
+               ff = ((freq << 10) + 62) / 125;
        }
        *(__le32 *)buf = cpu_to_le32(ff);
 }


Best regards,

Pavel.





  reply	other threads:[~2021-04-17  9:51 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-01 13:05 [PATCH 0/8] USB Audio Gadget part 2: Feedback endpoint, Volume/Mute support Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 1/8] usb: gadget: u_audio: convert to strscpy Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 2/8] usb: gadget: f_uac2/u_audio: add feedback endpoint support Ruslan Bilovol
2021-04-17  9:43   ` Pavel Hofman [this message]
2021-03-01 13:05 ` [PATCH 3/8] usb: gadget: f_uac2: add adaptive sync support for capture Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 4/8] usb: gadget: u_audio: add real feedback implementation Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 5/8] usb: audio-v2: add ability to define feature unit descriptor Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 6/8] usb: gadget: u_audio: add bi-directional volume and mute support Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 7/8] usb: gadget: f_uac2: add " Ruslan Bilovol
2021-03-01 13:05 ` [PATCH 8/8] usb: gadget: f_uac1: " Ruslan Bilovol
2021-03-23 11:56 ` [PATCH 0/8] USB Audio Gadget part 2: Feedback endpoint, Volume/Mute support Greg Kroah-Hartman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=be928b87-9ebe-43da-216d-40904b7ef8e0@ivitera.com \
    --to=pavel.hofman@ivitera.com \
    --cc=balbi@kernel.org \
    --cc=corbet@lwn.net \
    --cc=gregkh@linuxfoundation.org \
    --cc=gschmottlach@gmail.com \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=ruslan.bilovol@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).