diff mbox series

[RFC,2/2] usb: gadget: u_audio: remove fb_max

Message ID 20211005093729.628833-2-jbrunet@baylibre.com (mailing list archive)
State New, archived
Headers show
Series [RFC,1/2] usb: gadget: uac2: fix maximum bandwidth calculation | expand

Commit Message

Jerome Brunet Oct. 5, 2021, 9:37 a.m. UTC
Having a parameter to customize the extra packet size we would like to
reserve for the audio gadget makes no sense. The maximum size the packet
should have is actually specified by the USB Audio Format Specification.

See https://www.usb.org/sites/default/files/USB%20Audio%20v3.0_0.zip
USB Audio Format section 2.3.1.2.1

Cc: Pavel Hofman <pavel.hofman@ivitera.com>
Cc: Jack Pham <jackp@codeaurora.org>
Signed-off-by: Jerome Brunet <jbrunet@baylibre.com>
---
 I know you guys have continued the development on the audio gadget recently
 I'm sorry I have not been able to follow it closely.
 It is possible this change require a rebase
 I'm sending it now because I think fb_max is part of the problem around
 packet size

 drivers/usb/gadget/function/f_uac2.c  |  4 ---
 drivers/usb/gadget/function/u_audio.c | 40 ++++++++++-----------------
 drivers/usb/gadget/function/u_audio.h |  9 ------
 drivers/usb/gadget/function/u_uac2.h  |  1 -
 4 files changed, 14 insertions(+), 40 deletions(-)
diff mbox series

Patch

diff --git a/drivers/usb/gadget/function/f_uac2.c b/drivers/usb/gadget/function/f_uac2.c
index c152efa30def..381abf8adb31 100644
--- a/drivers/usb/gadget/function/f_uac2.c
+++ b/drivers/usb/gadget/function/f_uac2.c
@@ -961,7 +961,6 @@  afunc_bind(struct usb_configuration *cfg, struct usb_function *fn)
 	agdev->params.c_srate = uac2_opts->c_srate;
 	agdev->params.c_ssize = uac2_opts->c_ssize;
 	agdev->params.req_number = uac2_opts->req_number;
-	agdev->params.fb_max = uac2_opts->fb_max;
 	ret = g_audio_setup(agdev, "UAC2 PCM", "UAC2_Gadget");
 	if (ret)
 		goto err_free_descs;
@@ -1334,7 +1333,6 @@  UAC2_ATTRIBUTE(c_srate);
 UAC2_ATTRIBUTE_SYNC(c_sync);
 UAC2_ATTRIBUTE(c_ssize);
 UAC2_ATTRIBUTE(req_number);
-UAC2_ATTRIBUTE(fb_max);
 
 static struct configfs_attribute *f_uac2_attrs[] = {
 	&f_uac2_opts_attr_p_chmask,
@@ -1345,7 +1343,6 @@  static struct configfs_attribute *f_uac2_attrs[] = {
 	&f_uac2_opts_attr_c_ssize,
 	&f_uac2_opts_attr_c_sync,
 	&f_uac2_opts_attr_req_number,
-	&f_uac2_opts_attr_fb_max,
 	NULL,
 };
 
@@ -1385,7 +1382,6 @@  static struct usb_function_instance *afunc_alloc_inst(void)
 	opts->c_ssize = UAC2_DEF_CSSIZE;
 	opts->c_sync = UAC2_DEF_CSYNC;
 	opts->req_number = UAC2_DEF_REQ_NUM;
-	opts->fb_max = UAC2_DEF_FB_MAX;
 	return &opts->func_inst;
 }
 
diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
index 9e5c950612d0..63def8467e9c 100644
--- a/drivers/usb/gadget/function/u_audio.c
+++ b/drivers/usb/gadget/function/u_audio.c
@@ -607,19 +607,20 @@  EXPORT_SYMBOL_GPL(u_audio_stop_playback);
 static int u_audio_pitch_info(struct snd_kcontrol *kcontrol,
 				   struct snd_ctl_elem_info *uinfo)
 {
-	struct uac_rtd_params *prm = snd_kcontrol_chip(kcontrol);
-	struct snd_uac_chip *uac = prm->uac;
-	struct g_audio *audio_dev = uac->audio_dev;
-	struct uac_params *params = &audio_dev->params;
-	unsigned int pitch_min, pitch_max;
-
-	pitch_min = (1000 - FBACK_SLOW_MAX) * 1000;
-	pitch_max = (1000 + params->fb_max) * 1000;
-
 	uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
 	uinfo->count = 1;
-	uinfo->value.integer.min = pitch_min;
-	uinfo->value.integer.max = pitch_max;
+
+	/*
+	 * TODO: +/- 25% is rough.
+	 * The host constrained by the small and large SIP size so it
+	 * will likely cape before that
+	 *
+	 * On the start of a capture, we should be able to calculate
+	 * the minimum and maximum pitch based on the small and large
+	 * SIP size (See USB Audio Format 3.0 - section 2.3.1.2.1)
+	 */
+	uinfo->value.integer.min = 750000;
+	uinfo->value.integer.max = 1250000;
 	uinfo->value.integer.step = 1;
 	return 0;
 }
@@ -638,29 +639,16 @@  static int u_audio_pitch_put(struct snd_kcontrol *kcontrol,
 				  struct snd_ctl_elem_value *ucontrol)
 {
 	struct uac_rtd_params *prm = snd_kcontrol_chip(kcontrol);
-	struct snd_uac_chip *uac = prm->uac;
-	struct g_audio *audio_dev = uac->audio_dev;
-	struct uac_params *params = &audio_dev->params;
 	unsigned int val;
-	unsigned int pitch_min, pitch_max;
-	int change = 0;
-
-	pitch_min = (1000 - FBACK_SLOW_MAX) * 1000;
-	pitch_max = (1000 + params->fb_max) * 1000;
 
 	val = ucontrol->value.integer.value[0];
 
-	if (val < pitch_min)
-		val = pitch_min;
-	if (val > pitch_max)
-		val = pitch_max;
-
 	if (prm->pitch != val) {
 		prm->pitch = val;
-		change = 1;
+		return 1;
 	}
 
-	return change;
+	return 0;
 }
 
 static const struct snd_kcontrol_new u_audio_controls[]  = {
diff --git a/drivers/usb/gadget/function/u_audio.h b/drivers/usb/gadget/function/u_audio.h
index a218cdf771fe..53e6baf55cbf 100644
--- a/drivers/usb/gadget/function/u_audio.h
+++ b/drivers/usb/gadget/function/u_audio.h
@@ -11,14 +11,6 @@ 
 
 #include <linux/usb/composite.h>
 
-/*
- * Same maximum frequency deviation on the slower side as in
- * sound/usb/endpoint.c. Value is expressed in per-mil deviation.
- * The maximum deviation on the faster side will be provided as
- * parameter, as it impacts the endpoint required bandwidth.
- */
-#define FBACK_SLOW_MAX	250
-
 struct uac_params {
 	/* playback */
 	int p_chmask;	/* channel mask */
@@ -31,7 +23,6 @@  struct uac_params {
 	int c_ssize;	/* sample size */
 
 	int req_number; /* number of preallocated requests */
-	int fb_max;	/* upper frequency drift feedback limit per-mil */
 };
 
 struct g_audio {
diff --git a/drivers/usb/gadget/function/u_uac2.h b/drivers/usb/gadget/function/u_uac2.h
index 179d3ef6a195..9e9c3c5bb1c8 100644
--- a/drivers/usb/gadget/function/u_uac2.h
+++ b/drivers/usb/gadget/function/u_uac2.h
@@ -35,7 +35,6 @@  struct f_uac2_opts {
 	int				c_ssize;
 	int				c_sync;
 	int				req_number;
-	int				fb_max;
 	bool				bound;
 
 	struct mutex			lock;