Lines Matching +full:valid +full:- +full:sources

1 // SPDX-License-Identifier: GPL-2.0-or-later
11 #include <linux/usb/audio-v2.h>
12 #include <linux/usb/audio-v3.h>
40 ((proto) == UAC_VERSION_3 ? (p)->v3.field : (p)->v2.field)
48 while ((cs = snd_usb_find_csint_desc(iface->extra, iface->extralen, in find_uac_clock_desc()
83 snd_usb_find_ctrl_interface(chip, fmt->iface); \
85 fmt->protocol == UAC_VERSION_3 ? (type3) : (type2), \
86 fmt->protocol); \
107 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), in uac_clock_selector_get_val()
127 ret = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), in uac_clock_selector_set_val()
140 return -EINVAL; in uac_clock_selector_set_val()
151 return -EINVAL; in uac_clock_selector_set_val()
164 struct usb_device *dev = chip->dev; in uac_clock_source_is_valid_quirk()
168 ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface); in uac_clock_source_is_valid_quirk()
173 if (fmt->protocol == UAC_VERSION_2) { in uac_clock_source_is_valid_quirk()
175 * Assume the clock is valid if clock source supports only one in uac_clock_source_is_valid_quirk()
181 if (fmt->nr_rates == 1 && in uac_clock_source_is_valid_quirk()
182 (fmt->clock & 0xff) == cs_desc->v2.bClockID && in uac_clock_source_is_valid_quirk()
183 (cs_desc->v2.bmAttributes & 0x3) != in uac_clock_source_is_valid_quirk()
193 if (chip->usb_id == USB_ID(0x07fd, 0x0004)) { in uac_clock_source_is_valid_quirk()
207 dev_warn(&dev->dev, in uac_clock_source_is_valid_quirk()
227 struct usb_device *dev = chip->dev; in uac_clock_source_is_valid()
232 ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface); in uac_clock_source_is_valid()
237 if (fmt->protocol == UAC_VERSION_3) in uac_clock_source_is_valid()
238 bmControls = le32_to_cpu(cs_desc->v3.bmControls); in uac_clock_source_is_valid()
240 bmControls = cs_desc->v2.bmControls; in uac_clock_source_is_valid()
242 /* If a clock source can't tell us whether it's valid, we assume it is */ in uac_clock_source_is_valid()
254 dev_warn(&dev->dev, in uac_clock_source_is_valid()
274 const u8 *sources; in __uac_clock_find_source() local
275 int proto = fmt->protocol; in __uac_clock_find_source()
285 return -EINVAL; in __uac_clock_find_source()
295 "clock source %d is not valid, cannot use\n", in __uac_clock_find_source()
297 return -ENXIO; in __uac_clock_find_source()
306 sources = GET_VAL(selector, proto, baCSourceID); in __uac_clock_find_source()
310 bmControls = le32_to_cpu(*(__le32 *)(&selector->v3.baCSourceID[0] + pins)); in __uac_clock_find_source()
312 bmControls = *(__u8 *)(&selector->v2.baCSourceID[0] + pins); in __uac_clock_find_source()
332 ret = uac_clock_selector_get_val(chip, clock_id, fmt->iface); in __uac_clock_find_source()
334 if (!chip->autoclock) in __uac_clock_find_source()
339 /* Selector values are one-based */ in __uac_clock_find_source()
346 if (!chip->autoclock) in __uac_clock_find_source()
347 return -EINVAL; in __uac_clock_find_source()
354 sources[ret - 1], in __uac_clock_find_source()
358 if (chip->quirk_flags & QUIRK_FLAG_SKIP_CLOCK_SELECTOR || in __uac_clock_find_source()
361 err = uac_clock_selector_set_val(chip, entity_id, cur, fmt->iface); in __uac_clock_find_source()
374 if (!validate || ret > 0 || !chip->autoclock) in __uac_clock_find_source()
379 return -ENXIO; in __uac_clock_find_source()
387 sources[i - 1], in __uac_clock_find_source()
392 err = uac_clock_selector_set_val(chip, entity_id, i, fmt->iface); in __uac_clock_find_source()
397 "found and selected valid clock source %d\n", in __uac_clock_find_source()
402 return -ENXIO; in __uac_clock_find_source()
405 /* FIXME: multipliers only act as pass-thru element for now */ in __uac_clock_find_source()
412 return -EINVAL; in __uac_clock_find_source()
417 * the clock source (end-leaf) must be used. However, clock selectors,
432 switch (fmt->protocol) { in snd_usb_clock_find_source()
435 return __uac_clock_find_source(chip, fmt, fmt->clock, visited, in snd_usb_clock_find_source()
438 return -EINVAL; in snd_usb_clock_find_source()
445 struct usb_device *dev = chip->dev; in set_sample_rate_v1()
450 if (!(fmt->attributes & UAC_EP_CS_ATTR_SAMPLE_RATE)) in set_sample_rate_v1()
459 fmt->endpoint, data, sizeof(data)); in set_sample_rate_v1()
461 dev_err(&dev->dev, "%d:%d: cannot set freq %d to ep %#x\n", in set_sample_rate_v1()
462 fmt->iface, fmt->altsetting, rate, fmt->endpoint); in set_sample_rate_v1()
468 if (chip->quirk_flags & QUIRK_FLAG_GET_SAMPLE_RATE) in set_sample_rate_v1()
471 if (chip->sample_rate_read_error > 2) in set_sample_rate_v1()
477 fmt->endpoint, data, sizeof(data)); in set_sample_rate_v1()
479 dev_err(&dev->dev, "%d:%d: cannot get freq at ep %#x\n", in set_sample_rate_v1()
480 fmt->iface, fmt->altsetting, fmt->endpoint); in set_sample_rate_v1()
481 chip->sample_rate_read_error++; in set_sample_rate_v1()
487 dev_info(&dev->dev, "failed to read current rate; disabling the check\n"); in set_sample_rate_v1()
488 chip->sample_rate_read_error = 3; /* three strikes, see above */ in set_sample_rate_v1()
493 dev_warn(&dev->dev, "current rate %d is different from the runtime rate %d\n", crate, rate); in set_sample_rate_v1()
494 // runtime->rate = crate; in set_sample_rate_v1()
503 struct usb_device *dev = chip->dev; in get_sample_rate_v2v3()
515 dev_warn(&dev->dev, "%d:%d: cannot get freq (v2/v3): err %d\n", in get_sample_rate_v2v3()
526 * Return 0 if the clock source is read-only, the actual rate on success,
543 ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface); in snd_usb_set_sample_rate_v2v3()
549 if (fmt->protocol == UAC_VERSION_3) in snd_usb_set_sample_rate_v2v3()
550 bmControls = le32_to_cpu(cs_desc->v3.bmControls); in snd_usb_set_sample_rate_v2v3()
552 bmControls = cs_desc->v2.bmControls; in snd_usb_set_sample_rate_v2v3()
560 err = snd_usb_ctl_msg(chip->dev, usb_sndctrlpipe(chip->dev, 0), UAC2_CS_CUR, in snd_usb_set_sample_rate_v2v3()
568 return get_sample_rate_v2v3(chip, fmt->iface, fmt->altsetting, clock); in snd_usb_set_sample_rate_v2v3()
577 /* First, try to find a valid clock. This may trigger in set_sample_rate_v2v3()
579 * valid. in set_sample_rate_v2v3()
583 /* We did not find a valid clock, but that might be in set_sample_rate_v2v3()
592 if (chip->quirk_flags & QUIRK_FLAG_IGNORE_CLOCK_SOURCE) in set_sample_rate_v2v3()
599 prev_rate = get_sample_rate_v2v3(chip, fmt->iface, fmt->altsetting, clock); in set_sample_rate_v2v3()
607 fmt->iface, fmt->altsetting, rate, cur_rate); in set_sample_rate_v2v3()
617 fmt->iface, fmt->altsetting, rate, cur_rate); in set_sample_rate_v2v3()
621 /* FIXME - TEAC devices require the immediate interface setup */ in set_sample_rate_v2v3()
622 if (USB_ID_VENDOR(chip->usb_id) == 0x0644) { in set_sample_rate_v2v3()
626 usb_set_interface(chip->dev, fmt->iface, fmt->altsetting); in set_sample_rate_v2v3()
627 if (chip->quirk_flags & QUIRK_FLAG_IFACE_DELAY) in set_sample_rate_v2v3()
635 return -ENXIO; in set_sample_rate_v2v3()
643 fmt->iface, fmt->altsetting, rate, fmt->clock); in snd_usb_init_sample_rate()
645 switch (fmt->protocol) { in snd_usb_init_sample_rate()
651 if (chip->badd_profile >= UAC3_FUNCTION_SUBCLASS_GENERIC_IO) { in snd_usb_init_sample_rate()
653 return -ENXIO; in snd_usb_init_sample_rate()