sound/usb/clock.c
Source file repositories/reference/linux-study-clean/sound/usb/clock.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/clock.c- Extension
.c- Size
- 19290 bytes
- Lines
- 692
- Domain
- Driver Families
- Bucket
- sound/usb
- Inferred role
- Driver Families: implementation source
- Status
- source implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bitops.hlinux/init.hlinux/string.hlinux/usb.hlinux/usb/audio.hlinux/usb/audio-v2.hlinux/usb/audio-v3.hsound/core.hsound/info.hsound/pcm.husbaudio.hcard.hhelper.hclock.hquirks.h
Detected Declarations
function boolfunction validate_clock_sourcefunction validate_clock_selectorfunction validate_clock_multiplierfunction uac_clock_selector_get_valfunction uac_clock_selector_set_valfunction uac_clock_source_is_valid_quirkfunction modelsfunction uac_clock_source_is_validfunction __uac_clock_find_sourcefunction sourcefunction set_sample_rate_v1function get_sample_rate_v2v3function snd_usb_set_sample_rate_v2v3function set_sample_rate_v2v3function snd_usb_init_sample_rate
Annotated Snippet
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);
return false;
}
ret = !!data;
count++;
}
}
return ret;
}
static bool uac_clock_source_is_valid(struct snd_usb_audio *chip,
const struct audioformat *fmt,
int source_id)
{
int err;
unsigned char data;
struct usb_device *dev = chip->dev;
u32 bmControls;
union uac23_clock_source_desc *cs_desc;
struct usb_host_interface *ctrl_intf;
ctrl_intf = snd_usb_find_ctrl_interface(chip, fmt->iface);
cs_desc = snd_usb_find_clock_source(chip, source_id, fmt);
if (!cs_desc)
return false;
if (fmt->protocol == UAC_VERSION_3)
bmControls = le32_to_cpu(cs_desc->v3.bmControls);
else
bmControls = cs_desc->v2.bmControls;
/* 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))
return true;
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);
return false;
}
if (data)
return true;
else
return uac_clock_source_is_valid_quirk(chip, fmt, source_id);
}
static int __uac_clock_find_source(struct snd_usb_audio *chip,
const struct audioformat *fmt, int entity_id,
unsigned long *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;
Annotation
- Immediate include surface: `linux/bitops.h`, `linux/init.h`, `linux/string.h`, `linux/usb.h`, `linux/usb/audio.h`, `linux/usb/audio-v2.h`, `linux/usb/audio-v3.h`, `sound/core.h`.
- Detected declarations: `function bool`, `function validate_clock_source`, `function validate_clock_selector`, `function validate_clock_multiplier`, `function uac_clock_selector_get_val`, `function uac_clock_selector_set_val`, `function uac_clock_source_is_valid_quirk`, `function models`, `function uac_clock_source_is_valid`, `function __uac_clock_find_source`.
- Atlas domain: Driver Families / sound/usb.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.