drivers/media/usb/usbtv/usbtv-audio.c
Source file repositories/reference/linux-study-clean/drivers/media/usb/usbtv/usbtv-audio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/media/usb/usbtv/usbtv-audio.c- Extension
.c- Size
- 9962 bytes
- Lines
- 378
- Domain
- Driver Families
- Bucket
- drivers/media
- 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.
- 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
sound/core.hsound/initval.hsound/ac97_codec.hsound/pcm_params.husbtv.h
Detected Declarations
function snd_usbtv_pcm_openfunction snd_usbtv_pcm_closefunction snd_usbtv_preparefunction usbtv_audio_urb_receivedfunction usbtv_audio_startfunction usbtv_audio_stopfunction usbtv_audio_suspendfunction usbtv_audio_resumefunction snd_usbtv_triggerfunction snd_usbtv_card_triggerfunction snd_usbtv_pointerfunction usbtv_audio_initfunction usbtv_audio_free
Annotated Snippet
if (buffer_pos + chunk_length >= runtime->buffer_size) {
size_t cnt = (runtime->buffer_size - buffer_pos) *
frame_bytes;
memcpy(runtime->dma_area + buffer_pos * frame_bytes,
urb_current, cnt);
memcpy(runtime->dma_area, urb_current + cnt,
chunk_length * frame_bytes - cnt);
} else {
memcpy(runtime->dma_area + buffer_pos * frame_bytes,
urb_current, chunk_length * frame_bytes);
}
buffer_pos += chunk_length;
period_pos += chunk_length;
if (buffer_pos >= runtime->buffer_size)
buffer_pos -= runtime->buffer_size;
if (period_pos >= runtime->period_size) {
period_pos -= runtime->period_size;
period_elapsed = 1;
}
}
snd_pcm_stream_lock_irqsave(substream, flags);
chip->snd_buffer_pos = buffer_pos;
chip->snd_period_pos = period_pos;
snd_pcm_stream_unlock_irqrestore(substream, flags);
if (period_elapsed)
snd_pcm_period_elapsed(substream);
usb_submit_urb(urb, GFP_ATOMIC);
}
static int usbtv_audio_start(struct usbtv *chip)
{
unsigned int pipe;
static const u16 setup[][2] = {
/* These seem to enable the device. */
{ USBTV_BASE + 0x0008, 0x0001 },
{ USBTV_BASE + 0x01d0, 0x00ff },
{ USBTV_BASE + 0x01d9, 0x0002 },
{ USBTV_BASE + 0x01da, 0x0013 },
{ USBTV_BASE + 0x01db, 0x0012 },
{ USBTV_BASE + 0x01e9, 0x0002 },
{ USBTV_BASE + 0x01ec, 0x006c },
{ USBTV_BASE + 0x0294, 0x0020 },
{ USBTV_BASE + 0x0255, 0x00cf },
{ USBTV_BASE + 0x0256, 0x0020 },
{ USBTV_BASE + 0x01eb, 0x0030 },
{ USBTV_BASE + 0x027d, 0x00a6 },
{ USBTV_BASE + 0x0280, 0x0011 },
{ USBTV_BASE + 0x0281, 0x0040 },
{ USBTV_BASE + 0x0282, 0x0011 },
{ USBTV_BASE + 0x0283, 0x0040 },
{ 0xf891, 0x0010 },
/* this sets the input from composite */
{ USBTV_BASE + 0x0284, 0x00aa },
};
chip->snd_bulk_urb = usb_alloc_urb(0, GFP_KERNEL);
if (chip->snd_bulk_urb == NULL)
goto err_alloc_urb;
pipe = usb_rcvbulkpipe(chip->udev, USBTV_AUDIO_ENDP);
chip->snd_bulk_urb->transfer_buffer = kzalloc(
USBTV_AUDIO_URBSIZE, GFP_KERNEL);
if (chip->snd_bulk_urb->transfer_buffer == NULL)
goto err_transfer_buffer;
usb_fill_bulk_urb(chip->snd_bulk_urb, chip->udev, pipe,
chip->snd_bulk_urb->transfer_buffer, USBTV_AUDIO_URBSIZE,
usbtv_audio_urb_received, chip);
/* starting the stream */
usbtv_set_regs(chip, setup, ARRAY_SIZE(setup));
usb_clear_halt(chip->udev, pipe);
usb_submit_urb(chip->snd_bulk_urb, GFP_ATOMIC);
return 0;
err_transfer_buffer:
usb_free_urb(chip->snd_bulk_urb);
Annotation
- Immediate include surface: `sound/core.h`, `sound/initval.h`, `sound/ac97_codec.h`, `sound/pcm_params.h`, `usbtv.h`.
- Detected declarations: `function snd_usbtv_pcm_open`, `function snd_usbtv_pcm_close`, `function snd_usbtv_prepare`, `function usbtv_audio_urb_received`, `function usbtv_audio_start`, `function usbtv_audio_stop`, `function usbtv_audio_suspend`, `function usbtv_audio_resume`, `function snd_usbtv_trigger`, `function snd_usbtv_card_trigger`.
- Atlas domain: Driver Families / drivers/media.
- Implementation status: source 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.