2024-02-01 07:08:56

by vincenttew

[permalink] [raw]
Subject: [PATCH] ALSA: usb-audio: retry clock validate when it takes some times

Behringer UMC202HD and UMC404HD take some times to validate the clock
source. To prevent more DAC have the same delay which return the false
in the first time, remove the USB id check to have a chance to retry the
clock validate.

Signed-off-by: vincenttew <[email protected]>
---
sound/usb/clock.c | 43 ++++++++++++++++++-------------------------
1 file changed, 18 insertions(+), 25 deletions(-)

diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index b118cf97607f..16d7a456dd10 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -181,34 +181,27 @@ static bool uac_clock_source_is_valid_quirk(struct snd_usb_audio *chip,
return true;
}

- /*
- * MOTU MicroBook IIc
- * Sample rate changes takes more than 2 seconds for this device. Clock
- * validity request returns false during that period.
- */
- if (chip->usb_id == USB_ID(0x07fd, 0x0004)) {
- count = 0;
+ count = 0;

- while ((!ret) && (count < 50)) {
- int err;
+ while ((!ret) && (count < 50)) {
+ int err;

- msleep(100);
-
- err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
- USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
- UAC2_CS_CONTROL_CLOCK_VALID << 8,
- snd_usb_ctrl_intf(chip) | (source_id << 8),
- &data, sizeof(data));
- if (err < 0) {
- dev_warn(&dev->dev,
- "%s(): cannot get clock validity for id %d\n",
- __func__, source_id);
- return false;
- }
-
- ret = !!data;
- count++;
+ msleep(100);
+
+ err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC2_CS_CUR,
+ USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
+ UAC2_CS_CONTROL_CLOCK_VALID << 8,
+ snd_usb_ctrl_intf(chip) | (source_id << 8),
+ &data, sizeof(data));
+ if (err < 0) {
+ dev_warn(&dev->dev,
+ "%s(): cannot get clock validity for id %d\n",
+ __func__, source_id);
+ return false;
}
+
+ ret = !!data;
+ count++;
}

return ret;
--
2.43.0.429.g432eaa2c6b-goog



2024-02-01 10:38:14

by Alexander Tsoy

[permalink] [raw]
Subject: Re: [PATCH] ALSA: usb-audio: retry clock validate when it takes some times

В Чт, 01/02/2024 в 15:06 +0800, vincenttew пишет:
> Behringer UMC202HD and UMC404HD take some times to validate the clock
> source. To prevent more DAC have the same delay which return the
> false
> in the first time, remove the USB id check to have a chance to retry
> the
> clock validate.
>
> Signed-off-by: vincenttew <[email protected]>

Thank you for the patch! My thought about this change:
- Retrying clock source validation probably make sense only in the case
of Internal clock. But I'm not sure.
- If we want to make this a standard driver behaviour, then the code
needs to be moved out of the quirk function IMO.

2024-02-01 13:22:45

by Takashi Iwai

[permalink] [raw]
Subject: Re: [PATCH] ALSA: usb-audio: retry clock validate when it takes some times

On Thu, 01 Feb 2024 11:36:11 +0100,
Alexander Tsoy wrote:
>
> ? ??, 01/02/2024 ? 15:06 +0800, vincenttew ?????:
> > Behringer UMC202HD and UMC404HD take some times to validate the clock
> > source. To prevent more DAC have the same delay which return the
> > false
> > in the first time, remove the USB id check to have a chance to retry
> > the
> > clock validate.
> >
> > Signed-off-by: vincenttew <[email protected]>
>
> Thank you for the patch! My thought about this change:
> - Retrying clock source validation probably make sense only in the case
> of Internal clock. But I'm not sure.

It's an interesting point.

> - If we want to make this a standard driver behaviour, then the code
> needs to be moved out of the quirk function IMO.

I'm a bit afraid of applying this unconditionally to all cases. At
first, we can start with the vendor matching (e.g. MOTU and Behringer)
to apply it...


thanks,

Takashi