sound/usb/pcm.c
Source file repositories/reference/linux-study-clean/sound/usb/pcm.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/pcm.c- Extension
.c- Size
- 50707 bytes
- Lines
- 1834
- Domain
- Driver Families
- Bucket
- sound/usb
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration 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.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/init.hlinux/slab.hlinux/bitrev.hlinux/ratelimit.hlinux/usb.hlinux/usb/audio.hlinux/usb/audio-v2.hsound/core.hsound/pcm.hsound/pcm_params.husbaudio.hcard.hquirks.hendpoint.hhelper.hpcm.hclock.hpower.hmedia.himplicit.h
Detected Declarations
function snd_usb_pcm_delayfunction snd_usb_pcm_pointerfunction find_formatfunction list_for_each_entryfunction snd_usb_find_formatfunction find_substream_formatfunction snd_usb_find_substream_formatfunction snd_usb_pcm_has_fixed_ratefunction init_pitch_v1function init_pitch_v2function snd_usb_init_pitchfunction stop_endpointsfunction start_endpointsfunction sync_pending_stopsfunction snd_usb_pcm_sync_stopfunction snd_usb_audioformat_set_sync_epfunction get_endpointfunction get_endpointfunction snd_usb_pcm_change_statefunction snd_usb_pcm_suspendfunction snd_usb_pcm_resumefunction close_endpointsfunction snd_usb_hw_paramsfunction scoped_guardfunction snd_usb_pcm_hw_paramsfunction snd_usb_hw_freefunction snd_usb_pcm_hw_freefunction in_free_wheeling_modefunction lowlatency_playback_availablefunction snd_usb_pcm_preparefunction hw_check_valid_formatfunction apply_hw_params_minmaxfunction get_endpoint_in_usefunction hw_rule_ratefunction hw_rule_channelsfunction apply_hw_params_format_bitsfunction hw_rule_formatfunction hw_rule_period_timefunction hw_rule_period_size_implicit_fbfunction hw_rule_periods_implicit_fbfunction setup_hw_infofunction list_for_each_entryfunction snd_usb_pcm_openfunction scoped_guardfunction snd_usb_pcm_closefunction retire_capture_urbfunction scoped_guardfunction urb_ctx_queue_advance
Annotated Snippet
if (strict_match) {
if (!(fp->formats & pcm_format_to_bits(format)))
continue;
if (fp->channels != channels)
continue;
}
if (rate < fp->rate_min || rate > fp->rate_max)
continue;
if (!(fp->rates & SNDRV_PCM_RATE_CONTINUOUS)) {
unsigned int i;
for (i = 0; i < fp->nr_rates; i++)
if (fp->rate_table[i] == rate)
break;
if (i >= fp->nr_rates)
continue;
}
attr = fp->ep_attr & USB_ENDPOINT_SYNCTYPE;
if (!found) {
found = fp;
cur_attr = attr;
continue;
}
/* avoid async out and adaptive in if the other method
* supports the same format.
* this is a workaround for the case like
* M-audio audiophile USB.
*/
if (subs && attr != cur_attr) {
if ((attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE))
continue;
if ((cur_attr == USB_ENDPOINT_SYNC_ASYNC &&
subs->direction == SNDRV_PCM_STREAM_PLAYBACK) ||
(cur_attr == USB_ENDPOINT_SYNC_ADAPTIVE &&
subs->direction == SNDRV_PCM_STREAM_CAPTURE)) {
found = fp;
cur_attr = attr;
continue;
}
}
/* find the format with the largest max. packet size */
if (fp->maxpacksize > found->maxpacksize) {
found = fp;
cur_attr = attr;
}
}
return found;
}
const struct audioformat *
snd_usb_find_format(struct list_head *fmt_list_head, snd_pcm_format_t format,
unsigned int rate, unsigned int channels, bool strict_match,
struct snd_usb_substream *subs)
{
return find_format(fmt_list_head, format, rate, channels, strict_match,
subs);
}
EXPORT_SYMBOL_GPL(snd_usb_find_format);
static const struct audioformat *
find_substream_format(struct snd_usb_substream *subs,
const struct snd_pcm_hw_params *params)
{
return find_format(&subs->fmt_list, params_format(params),
params_rate(params), params_channels(params),
true, subs);
}
const struct audioformat *
snd_usb_find_substream_format(struct snd_usb_substream *subs,
const struct snd_pcm_hw_params *params)
{
return find_substream_format(subs, params);
}
EXPORT_SYMBOL_GPL(snd_usb_find_substream_format);
bool snd_usb_pcm_has_fixed_rate(struct snd_usb_substream *subs)
{
const struct audioformat *fp;
struct snd_usb_audio *chip;
int rate = -1;
if (!subs)
return false;
chip = subs->stream->chip;
if (!(chip->quirk_flags & QUIRK_FLAG_FIXED_RATE))
return false;
list_for_each_entry(fp, &subs->fmt_list, list) {
Annotation
- Immediate include surface: `linux/init.h`, `linux/slab.h`, `linux/bitrev.h`, `linux/ratelimit.h`, `linux/usb.h`, `linux/usb/audio.h`, `linux/usb/audio-v2.h`, `sound/core.h`.
- Detected declarations: `function snd_usb_pcm_delay`, `function snd_usb_pcm_pointer`, `function find_format`, `function list_for_each_entry`, `function snd_usb_find_format`, `function find_substream_format`, `function snd_usb_find_substream_format`, `function snd_usb_pcm_has_fixed_rate`, `function init_pitch_v1`, `function init_pitch_v2`.
- Atlas domain: Driver Families / sound/usb.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
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.