diff options
author | Takashi Iwai <tiwai@suse.de> | 2020-11-23 09:53:31 +0100 |
---|---|---|
committer | Takashi Iwai <tiwai@suse.de> | 2020-11-23 15:15:16 +0100 |
commit | bf6313a0ff766925462e97b4e733d5952de02367 (patch) | |
tree | 4fd24aae13948d68f4fd6d02eef16cec62bf428a /sound/usb/clock.c | |
parent | ALSA: usb-audio: Fix EP matching for continuous rates (diff) | |
download | linux-bf6313a0ff766925462e97b4e733d5952de02367.tar.xz linux-bf6313a0ff766925462e97b4e733d5952de02367.zip |
ALSA: usb-audio: Refactor endpoint management
This is an intensive surgery for the endpoint and stream management
for achieving more robust and clean code.
The goals of this patch are:
- More clear endpoint resource changes
- The interface altsetting control in a single place
Below are brief description of the whole changes.
First off, most of the endpoint operations are moved into endpoint.c,
so that the snd_usb_endpoint object is only referred in other places.
The endpoint object is acquired and released via the new functions
snd_usb_endpoint_open() and snd_usb_endpoint_close() that are called
at PCM hw_params and hw_free callbacks, respectively. Those are
ref-counted and EPs can manage the multiple opens.
The open callback receives the audioformat and hw_params arguments,
and those are used for initializing the EP parameters; especially the
endpoint, interface and altset numbers are read from there, as well as
the PCM parameters like the format, rate and channels. Those are
stored in snd_usb_endpoint object. If it's the secondary open, the
function checks whether the given parameters are compatible with the
already opened EP setup, too.
The coupling with a sync EP (including an implicit feedback sync) is
done by the sole snd_usb_endpoint_set_sync() call.
The configuration of each endpoint is done in a single shot via
snd_usb_endpoint_configure() call. This is the place where most of
PCM configurations are done. A few flags and special handling in the
snd_usb_substream are dropped along with this change.
A significant difference wrt the configuration from the previous code
is the order of USB host interface setups. Now the interface is
always disabled at beginning and (re-)enabled at the last step of
snd_usb_endpoint_configure(), in order to be compliant with the
standard UAC2/3. For UAC1, the interface is set before the parameter
setups since there seem devices that require it (e.g. Yamaha THR10),
just like how it was done in the previous driver code.
The start/stop are almost same as before, also single-shots. The URB
callbacks need to be set via snd_usb_endpoint_set_callback() like the
previous code at the trigger phase, too.
Finally, the flag for the re-setup is set at the device suspend
through the full EP list, instead of PCM trigger. This catches the
overlooked cases where the PCM hasn't been running yet but the device
needs the full setup after resume.
Tested-by: Keith Milner <kamilner@superlative.org>
Tested-by: Dylan Robinson <dylan_robinson@motu.com>
Link: https://lore.kernel.org/r/20201123085347.19667-26-tiwai@suse.de
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/usb/clock.c')
-rw-r--r-- | sound/usb/clock.c | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/sound/usb/clock.c b/sound/usb/clock.c index f25da11fce3a..b869a711afbf 100644 --- a/sound/usb/clock.c +++ b/sound/usb/clock.c @@ -613,7 +613,6 @@ int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip, static int set_sample_rate_v2v3(struct snd_usb_audio *chip, struct audioformat *fmt, int rate) { - struct usb_device *dev = chip->dev; int cur_rate, prev_rate; int clock; @@ -656,15 +655,6 @@ static int set_sample_rate_v2v3(struct snd_usb_audio *chip, return -ENXIO; } - /* Some devices doesn't respond to sample rate changes while the - * interface is active. */ - if (rate != prev_rate) { - usb_set_interface(dev, fmt->iface, 0); - snd_usb_set_interface_quirk(chip); - usb_set_interface(dev, fmt->iface, fmt->altsetting); - snd_usb_set_interface_quirk(chip); - } - validation: /* validate clock after rate change */ if (!uac_clock_source_is_valid(chip, fmt, clock)) @@ -675,6 +665,9 @@ validation: int snd_usb_init_sample_rate(struct snd_usb_audio *chip, struct audioformat *fmt, int rate) { + usb_audio_dbg(chip, "%d:%d Set sample rate %d, clock %d\n", + fmt->iface, fmt->altsetting, rate, fmt->clock); + switch (fmt->protocol) { case UAC_VERSION_1: default: |