Skip to content

Commit 1dc669f

Browse files
eldadtiwai
authored andcommitted
ALSA: usb-audio: UAC2: support read-only freq control
Some clocks might be read-only, e.g., external clocks (see also UAC2 4.7.2.1). In this case, setting the sample frequency will always fail (even if the rate is equal to the current clock rate), therefore do not write, but read the value and compare to the requested rate. If the clock is read only, avoid reading it twice. If it doesn't match, return -ENXIO since the clock is invalid for this configuration. Signed-off-by: Eldad Zack <eldad@fogrefinery.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent 027bbc1 commit 1dc669f

1 file changed

Lines changed: 26 additions & 11 deletions

File tree

‎sound/usb/clock.c‎

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -347,27 +347,42 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
347347
__le32 data;
348348
int err, cur_rate, prev_rate;
349349
int clock;
350+
bool writeable;
351+
struct uac_clock_source_descriptor *cs_desc;
350352

351353
clock = snd_usb_clock_find_source(chip, fmt->clock, true);
352354
if (clock < 0)
353355
return clock;
354356

355357
prev_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
356358

357-
data = cpu_to_le32(rate);
358-
if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
359-
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
360-
UAC2_CS_CONTROL_SAM_FREQ << 8,
361-
snd_usb_ctrl_intf(chip) | (clock << 8),
362-
&data, sizeof(data))) < 0) {
363-
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n",
364-
dev->devnum, iface, fmt->altsetting, rate, err);
365-
return err;
366-
}
359+
cs_desc = snd_usb_find_clock_source(chip->ctrl_intf, clock);
360+
writeable = uac2_control_is_writeable(cs_desc->bmControls, UAC2_CS_CONTROL_SAM_FREQ - 1);
361+
if (writeable) {
362+
data = cpu_to_le32(rate);
363+
err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
364+
USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
365+
UAC2_CS_CONTROL_SAM_FREQ << 8,
366+
snd_usb_ctrl_intf(chip) | (clock << 8),
367+
&data, sizeof(data));
368+
if (err < 0) {
369+
snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2): err %d\n",
370+
dev->devnum, iface, fmt->altsetting, rate, err);
371+
return err;
372+
}
367373

368-
cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
374+
cur_rate = get_sample_rate_v2(chip, iface, fmt->altsetting, clock);
375+
} else {
376+
cur_rate = prev_rate;
377+
}
369378

370379
if (cur_rate != rate) {
380+
if (!writeable) {
381+
snd_printk(KERN_WARNING
382+
"%d:%d:%d: freq mismatch (RO clock): req %d, clock runs @%d\n",
383+
dev->devnum, iface, fmt->altsetting, rate, cur_rate);
384+
return -ENXIO;
385+
}
371386
snd_printd(KERN_WARNING
372387
"current rate %d is different from the runtime rate %d\n",
373388
cur_rate, rate);

0 commit comments

Comments
 (0)