if (fmt->protocol == UAC_VERSION_2) { /* * Assume the clock is valid if clock source supports only one * single sample rate, the terminal is connected directly to it * (there is no clock selector) and clock type is internal. * This is to deal with some Denon DJ controllers that always * reports that clock is invalid.
*/ if (fmt->nr_rates == 1 &&
(fmt->clock & 0xff) == cs_desc->v2.bClockID &&
(cs_desc->v2.bmAttributes & 0x3) !=
UAC_CLOCK_SOURCE_TYPE_EXT) returntrue;
}
/* * 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;
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(ctrl_intf) | (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); returnfalse;
}
ret = !!data;
count++;
}
}
return ret;
}
staticbool uac_clock_source_is_valid(struct snd_usb_audio *chip, conststruct audioformat *fmt, int source_id)
{ int err; unsignedchar data; struct usb_device *dev = chip->dev;
u32 bmControls; union uac23_clock_source_desc *cs_desc; struct usb_host_interface *ctrl_intf;
/* If a clock source can't tell us whether it's valid, we assume it is */ if (!uac_v2v3_control_is_readable(bmControls,
UAC2_CS_CONTROL_CLOCK_VALID)) returntrue;
if (err < 0) {
dev_warn(&dev->dev, "%s(): cannot get clock validity for id %d\n",
__func__, source_id); returnfalse;
}
if (data) returntrue; else return uac_clock_source_is_valid_quirk(chip, fmt, source_id);
}
staticint __uac_clock_find_source(struct snd_usb_audio *chip, conststruct audioformat *fmt, int entity_id, unsignedlong *visited, bool validate)
{ union uac23_clock_source_desc *source; union uac23_clock_selector_desc *selector; union uac23_clock_multiplier_desc *multiplier; int ret, i, cur, err, pins, clock_id; const u8 *sources; int proto = fmt->protocol; bool readable, writeable;
u32 bmControls;
entity_id &= 0xff;
if (test_and_set_bit(entity_id, visited)) {
usb_audio_warn(chip, "%s(): recursive clock topology detected, id %d.\n",
__func__, entity_id); return -EINVAL;
}
/* first, see if the ID we're looking at is a clock source already */
source = snd_usb_find_clock_source(chip, entity_id, fmt); if (source) {
entity_id = GET_VAL(source, proto, bClockID); if (validate && !uac_clock_source_is_valid(chip, fmt,
entity_id)) {
usb_audio_err(chip, "clock source %d is not valid, cannot use\n",
entity_id); return -ENXIO;
} return entity_id;
}
selector = snd_usb_find_clock_selector(chip, entity_id, fmt); if (selector) {
pins = GET_VAL(selector, proto, bNrInPins);
clock_id = GET_VAL(selector, proto, bClockID);
sources = GET_VAL(selector, proto, baCSourceID);
cur = 0;
/* for now just warn about buggy device */ if (!readable)
usb_audio_warn(chip, "%s(): clock selector control is not readable, id %d\n",
__func__, clock_id);
/* the entity ID we are looking at is a selector.
* find out what it currently selects */
ret = uac_clock_selector_get_val(chip, clock_id, fmt->iface); if (ret < 0) { if (!chip->autoclock) return ret; goto find_others;
}
/* Selector values are one-based */
if (ret > pins || ret < 1) {
usb_audio_err(chip, "%s(): selector reported illegal value, id %d, ret %d\n",
__func__, clock_id, ret);
if (!chip->autoclock) return -EINVAL; goto find_others;
}
find_source:
cur = ret;
ret = __uac_clock_find_source(chip, fmt,
sources[ret - 1],
visited, validate); if (ret > 0) { /* Skip setting clock selector again for some devices */ if (chip->quirk_flags & QUIRK_FLAG_SKIP_CLOCK_SELECTOR ||
!writeable) return ret;
err = uac_clock_selector_set_val(chip, entity_id, cur, fmt->iface); if (err < 0) { if (pins == 1) {
usb_audio_dbg(chip, "%s(): selector returned an error, " "assuming a firmware bug, id %d, ret %d\n",
__func__, clock_id, err); return ret;
} return err;
}
}
if (!validate || ret > 0 || !chip->autoclock) return ret;
find_others: if (!writeable) return -ENXIO;
/* The current clock source is invalid, try others. */ for (i = 1; i <= pins; i++) { if (i == cur) continue;
ret = __uac_clock_find_source(chip, fmt,
sources[i - 1],
visited, true); if (ret < 0) continue;
err = uac_clock_selector_set_val(chip, entity_id, i, fmt->iface); if (err < 0) continue;
/* FIXME: multipliers only act as pass-thru element for now */
multiplier = snd_usb_find_clock_multiplier(chip, entity_id, fmt); if (multiplier) return __uac_clock_find_source(chip, fmt,
GET_VAL(multiplier, proto, bCSourceID),
visited, validate);
return -EINVAL;
}
/* * For all kinds of sample rate settings and other device queries, * the clock source (end-leaf) must be used. However, clock selectors, * clock multipliers and sample rate converters may be specified as * clock source input to terminal. This functions walks the clock path * to its end and tries to find the source. * * The 'visited' bitfield is used internally to detect recursive loops. * * Returns the clock source UnitID (>=0) on success, or an error.
*/ int snd_usb_clock_find_source(struct snd_usb_audio *chip, conststruct audioformat *fmt, bool validate)
{
DECLARE_BITMAP(visited, 256);
memset(visited, 0, sizeof(visited));
switch (fmt->protocol) { case UAC_VERSION_2: case UAC_VERSION_3: return __uac_clock_find_source(chip, fmt, fmt->clock, visited,
validate); default: return -EINVAL;
}
}
staticint set_sample_rate_v1(struct snd_usb_audio *chip, conststruct audioformat *fmt, int rate)
{ struct usb_device *dev = chip->dev; unsignedchar data[3]; int err, crate;
/* if endpoint doesn't have sampling rate control, bail out */ if (!(fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE)) return 0;
/* Don't check the sample rate for devices which we know don't
* support reading */ if (chip->quirk_flags & QUIRK_FLAG_GET_SAMPLE_RATE) return 0; /* the firmware is likely buggy, don't repeat to fail too many times */ if (chip->sample_rate_read_error > 2) return 0;
err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
UAC_EP_CS_ATTR_SAMPLE_RATE << 8,
fmt->endpoint, data, sizeof(data)); if (err < 0) {
dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n",
fmt->iface, fmt->altsetting, fmt->endpoint);
chip->sample_rate_read_error++; return 0; /* some devices don't support reading */
}
crate = data[0] | (data[1] << 8) | (data[2] << 16); if (!crate) {
dev_info(&dev->dev, "failed to read current rate; disabling the check\n");
chip->sample_rate_read_error = 3; /* three strikes, see above */ return 0;
}
if (crate != rate) {
dev_warn(&dev->dev, "current rate %d is different from the runtime rate %d\n", crate, rate); // runtime->rate = crate;
}
return 0;
}
staticint get_sample_rate_v2v3(struct snd_usb_audio *chip, int iface, int altsetting, int clock)
{ struct usb_device *dev = chip->dev;
__le32 data; int err; struct usb_host_interface *ctrl_intf;
/* * Try to set the given sample rate: * * Return 0 if the clock source is read-only, the actual rate on success, * or a negative error code. * * This function gets called from format.c to validate each sample rate, too. * Hence no message is shown upon error
*/ int snd_usb_set_sample_rate_v2v3(struct snd_usb_audio *chip, conststruct audioformat *fmt, int clock, int rate)
{ bool writeable;
u32 bmControls;
__le32 data; int err; union uac23_clock_source_desc *cs_desc; struct usb_host_interface *ctrl_intf;
staticint set_sample_rate_v2v3(struct snd_usb_audio *chip, conststruct audioformat *fmt, int rate)
{ int cur_rate, prev_rate; int clock;
/* First, try to find a valid clock. This may trigger * automatic clock selection if the current clock is not * valid.
*/
clock = snd_usb_clock_find_source(chip, fmt, true); if (clock < 0) { /* We did not find a valid clock, but that might be * because the current sample rate does not match an * external clock source. Try again without validation * and we will do another validation after setting the * rate.
*/
clock = snd_usb_clock_find_source(chip, fmt, false);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.