public inbox for linux-usb@vger.kernel.org
 help / color / mirror / Atom feed
From: John Keeping <john@metanate.com>
To: Pavel Hofman <pavel.hofman@ivitera.com>
Cc: linux-usb@vger.kernel.org,
	Ruslan Bilovol <ruslan.bilovol@gmail.com>,
	Felipe Balbi <balbi@kernel.org>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Julian Scheel <julian@jusst.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Subject: Re: [PATCH v2 06/11] usb: gadget: u_audio: Rate ctl notifies about current srate (0=stopped)
Date: Tue, 21 Dec 2021 12:07:44 +0000	[thread overview]
Message-ID: <YcHDkIdyXnYv2dRt@donbot> (raw)
In-Reply-To: <20211220211130.88590-7-pavel.hofman@ivitera.com>

On Mon, Dec 20, 2021 at 10:11:25PM +0100, Pavel Hofman wrote:
> The Playback/Capture ctl currently reports rate value set by USB
> control selector UAC2_CS_CONTROL_SAM_FREQ (fixed for UAC1). When the
> host has stopped playback/capture, the reported value does not change.
> The gadget side has no information whether the host has started/stopped
> capture/playback.
> 
> This patch sets the value reported by the respective rate ctl to zero
> when the host side has stopped playback/capture. Also, it calls
> snd_ctl_notify when start/stop  occurs, so that a subscribed client can
> act appropriately.
> 
> Tests have confirmed that USB hosts change UAC2_CS_CONTROL_SAM_FREQ
> before switching altsetting to activate playback/capture, resulting in
> correct order (params->c/p_srate is set to requested rate before
> u_audio_start_capture/playback is called).
> 
> The gadget rate notifications are used by user-space audio gadget
> controller gaudio_ctl https://github.com/pavhofman/gaudio_ctl.
> 
> Signed-off-by: Pavel Hofman <pavel.hofman@ivitera.com>
> ---
>  drivers/usb/gadget/function/u_audio.c | 46 ++++++++++++---------------
>  1 file changed, 21 insertions(+), 25 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_audio.c b/drivers/usb/gadget/function/u_audio.c
> index e737a104156d..a6293415c071 100644
> --- a/drivers/usb/gadget/function/u_audio.c
> +++ b/drivers/usb/gadget/function/u_audio.c
> @@ -64,6 +64,7 @@ struct uac_rtd_params {
>    int mute;
>  
>  	struct snd_kcontrol *snd_kctl_rate; /* read-only current rate */
> +	int rep_srate; /* srate reported by snd_kctl_rate */
>  
>    spinlock_t lock; /* lock for control transfers */
>  
> @@ -496,8 +497,6 @@ static inline void free_ep_fback(struct uac_rtd_params *prm, struct usb_ep *ep)
>  int u_audio_set_capture_srate(struct g_audio *audio_dev, int srate)
>  {
>  	struct uac_params *params = &audio_dev->params;
> -	struct snd_uac_chip *uac = audio_dev->uac;
> -	struct uac_rtd_params *prm = &uac->c_prm;
>  	int i;
>  
>  	dev_dbg(&audio_dev->gadget->dev, "%s: srate %d\n", __func__, srate);
> @@ -516,8 +515,6 @@ EXPORT_SYMBOL_GPL(u_audio_set_capture_srate);
>  
>  int u_audio_set_playback_srate(struct g_audio *audio_dev, int srate)
>  {
> -	struct snd_uac_chip *uac = audio_dev->uac;
> -	struct uac_rtd_params *prm = &uac->p_prm;
>  	struct uac_params *params = &audio_dev->params;
>  	int i;
>  
> @@ -535,6 +532,18 @@ int u_audio_set_playback_srate(struct g_audio *audio_dev, int srate)
>  }
>  EXPORT_SYMBOL_GPL(u_audio_set_playback_srate);
>  
> +static void set_reported_srate(struct uac_rtd_params *prm, int srate)
> +{
> +	struct snd_kcontrol *kctl = prm->snd_kctl_rate;
> +
> +	if (prm->rep_srate != srate) {
> +		prm->rep_srate = srate;
> +		snd_ctl_notify(prm->uac->card, SNDRV_CTL_EVENT_MASK_VALUE,
> +				&kctl->id);
> +		pr_debug("Setting '%s' to %d", kctl->id.name, srate);
> +	}
> +}
> +
>  int u_audio_start_capture(struct g_audio *audio_dev)
>  {
>  	struct snd_uac_chip *uac = audio_dev->uac;
> @@ -574,6 +583,8 @@ int u_audio_start_capture(struct g_audio *audio_dev)
>  			dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
>  	}
>  
> +	set_reported_srate(&uac->c_prm, params->c_srate);
> +
>  	ep_fback = audio_dev->in_ep_fback;
>  	if (!ep_fback)
>  		return 0;
> @@ -619,6 +630,7 @@ void u_audio_stop_capture(struct g_audio *audio_dev)
>  {
>  	struct snd_uac_chip *uac = audio_dev->uac;
>  
> +	set_reported_srate(&uac->c_prm, 0);
>  	if (audio_dev->in_ep_fback)
>  		free_ep_fback(&uac->c_prm, audio_dev->in_ep_fback);
>  	free_ep(&uac->c_prm, audio_dev->out_ep);
> @@ -691,6 +703,8 @@ int u_audio_start_playback(struct g_audio *audio_dev)
>  			dev_err(dev, "%s:%d Error!\n", __func__, __LINE__);
>  	}
>  
> +	set_reported_srate(&uac->p_prm, params->p_srate);
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(u_audio_start_playback);
> @@ -699,6 +713,7 @@ void u_audio_stop_playback(struct g_audio *audio_dev)
>  {
>  	struct snd_uac_chip *uac = audio_dev->uac;
>  
> +	set_reported_srate(&uac->p_prm, 0);
>  	free_ep(&uac->p_prm, audio_dev->in_ep);
>  }
>  EXPORT_SYMBOL_GPL(u_audio_stop_playback);
> @@ -1001,19 +1016,6 @@ static int get_max_srate(const int *srates)
>  	return max_srate;
>  }
>  
> -static int get_min_srate(const int *srates)
> -{
> -	int i, min_srate = INT_MAX;
> -
> -	for (i = 0; i < UAC_MAX_RATES; i++) {
> -		if (srates[i] == 0)
> -			break;
> -		if (srates[i] < min_srate)
> -			min_srate = srates[i];
> -	}
> -	return min_srate;
> -}
> -
>  static int uac_pcm_rate_info(struct snd_kcontrol *kcontrol,
>  				struct snd_ctl_elem_info *uinfo)
>  {
> @@ -1030,7 +1032,7 @@ static int uac_pcm_rate_info(struct snd_kcontrol *kcontrol,
>  		srates = params->c_srates;
>  	else
>  		srates = params->p_srates;
> -	uinfo->value.integer.min = get_min_srate(srates);
> +	uinfo->value.integer.min = 0;
>  	uinfo->value.integer.max = get_max_srate(srates);
>  	return 0;
>  }
> @@ -1039,14 +1041,8 @@ static int uac_pcm_rate_get(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;
>  
> -	if (prm == &uac->c_prm)
> -		ucontrol->value.integer.value[0] = params->c_srate;
> -	else
> -		ucontrol->value.integer.value[0] = params->p_srate;
> +	ucontrol->value.integer.value[0] = prm->rep_srate;

This function was only added in patch 2, wouldn't it be better to add
the rate to the right place at that point?

I think uac_params is supposed to be the fixed (user selected)
parameters whereas uac_rtd_params are the varying values that may be
affected by the host, so the current rate belongs in uac_rtd_params.

>  	return 0;
>  }
> -- 
> 2.25.1
> 

  reply	other threads:[~2021-12-21 12:07 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-20 21:11 [PATCH v2 00/11] usb: gadget: audio: Multiple rates, dyn. bInterval Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 01/11] usb: gadget: u_audio: Subdevice 0 for capture ctls Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 02/11] usb: gadget: u_audio: Support multiple sampling rates Pavel Hofman
2021-12-21 11:35   ` John Keeping
2021-12-22  7:13     ` Pavel Hofman
2022-01-04 15:32       ` John Keeping
2022-01-05 10:55         ` Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 03/11] usb: gadget: f_uac2: " Pavel Hofman
2021-12-21 11:59   ` John Keeping
2021-12-22 10:01     ` Pavel Hofman
2022-01-04 15:33       ` John Keeping
2022-01-05 12:20         ` Pavel Hofman
2022-01-05 12:44           ` John Keeping
2022-01-05 14:05             ` Pavel Hofman
2022-01-06  8:45               ` Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 04/11] usb: gadget: f_uac1: " Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 05/11] usb: gadget: f_uac2: Renaming Clock Sources to fixed names Pavel Hofman
2021-12-21 12:02   ` John Keeping
2021-12-22 10:11     ` Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 06/11] usb: gadget: u_audio: Rate ctl notifies about current srate (0=stopped) Pavel Hofman
2021-12-21 12:07   ` John Keeping [this message]
2021-12-22 10:41     ` Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 07/11] usb: gadget: u_audio: Stopping PCM substream at capture/playback stop Pavel Hofman
2021-12-21 12:18   ` John Keeping
2021-12-22 12:26     ` Pavel Hofman
2021-12-28  9:04       ` [RFC: PATCH " Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 08/11] usb: gadget: u_audio: Adding suspend call Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 09/11] usb: gadget: f_uac2: Adding suspend callback Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 10/11] usb: gadget: f_uac1: " Pavel Hofman
2021-12-20 21:11 ` [PATCH v2 11/11] usb: gadget: f_uac2: Determining bInterval for HS and SS Pavel Hofman
2021-12-21 12:29   ` John Keeping
2021-12-22 13:35     ` Pavel Hofman
2021-12-22 19:50       ` John Keeping
2021-12-23  7:09         ` Pavel Hofman
2022-01-04 15:33           ` John Keeping
2022-01-05 11:31             ` Pavel Hofman
2022-01-06 14:32               ` John Keeping
2022-01-07 10:30                 ` Pavel Hofman
2021-12-21  7:59 ` [PATCH v2 00/11] usb: gadget: audio: Multiple rates, dyn. bInterval Greg Kroah-Hartman
2021-12-22 13:38   ` Pavel Hofman

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=YcHDkIdyXnYv2dRt@donbot \
    --to=john@metanate.com \
    --cc=balbi@kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jbrunet@baylibre.com \
    --cc=julian@jusst.de \
    --cc=linux-usb@vger.kernel.org \
    --cc=pavel.hofman@ivitera.com \
    --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