sound/usb/misc/ua101.c
Source file repositories/reference/linux-study-clean/sound/usb/misc/ua101.c
File Facts
- System
- Linux kernel
- Corpus path
sound/usb/misc/ua101.c- Extension
.c- Size
- 36567 bytes
- Lines
- 1338
- 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.
- 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/module.hlinux/slab.hlinux/usb.hlinux/usb/audio.hsound/core.hsound/initval.hsound/pcm.hsound/pcm_params.h../usbaudio.h../midi.h
Detected Declarations
struct ua101struct ua101_streamstruct ua101_urbfunction abort_usb_capturefunction abort_usb_playbackfunction playback_urb_completefunction first_playback_urb_completefunction copy_playback_datafunction add_with_wraparoundfunction playback_workfunction copy_capture_datafunction capture_urb_completefunction scoped_guardfunction first_capture_urb_completefunction submit_stream_urbsfunction kill_stream_urbsfunction enable_iso_interfacefunction disable_iso_interfacefunction stop_usb_capturefunction start_usb_capturefunction stop_usb_playbackfunction start_usb_playbackfunction scoped_guardfunction abort_alsa_capturefunction abort_alsa_playbackfunction set_stream_hwfunction capture_pcm_openfunction playback_pcm_openfunction capture_pcm_closefunction playback_pcm_closefunction capture_pcm_hw_paramsfunction playback_pcm_hw_paramsfunction capture_pcm_preparefunction scoped_guardfunction playback_pcm_preparefunction scoped_guardfunction capture_pcm_triggerfunction playback_pcm_triggerfunction ua101_pcm_pointerfunction capture_pcm_pointerfunction playback_pcm_pointerfunction find_format_descriptorfunction detect_usb_formatfunction alloc_stream_buffersfunction free_stream_buffersfunction alloc_stream_urbsfunction free_stream_urbsfunction free_usb_related_resources
Annotated Snippet
struct ua101 {
struct usb_device *dev;
struct snd_card *card;
struct usb_interface *intf[INTF_COUNT];
int card_index;
struct snd_pcm *pcm;
struct list_head midi_list;
u64 format_bit;
unsigned int rate;
unsigned int packets_per_second;
spinlock_t lock;
struct mutex mutex;
unsigned long states;
/* FIFO to synchronize playback rate to capture rate */
unsigned int rate_feedback_start;
unsigned int rate_feedback_count;
u8 rate_feedback[MAX_QUEUE_LENGTH];
struct list_head ready_playback_urbs;
struct work_struct playback_work;
wait_queue_head_t alsa_capture_wait;
wait_queue_head_t rate_feedback_wait;
wait_queue_head_t alsa_playback_wait;
struct ua101_stream {
struct snd_pcm_substream *substream;
unsigned int usb_pipe;
unsigned int channels;
unsigned int frame_bytes;
unsigned int max_packet_bytes;
unsigned int period_pos;
unsigned int buffer_pos;
unsigned int queue_length;
struct ua101_urb {
struct urb urb;
struct usb_iso_packet_descriptor iso_frame_desc[1];
struct list_head ready_list;
} *urbs[MAX_QUEUE_LENGTH];
struct {
unsigned int size;
void *addr;
dma_addr_t dma;
} buffers[MAX_MEMORY_BUFFERS];
} capture, playback;
};
static DEFINE_MUTEX(devices_mutex);
static unsigned int devices_used;
static struct usb_driver ua101_driver;
static void abort_alsa_playback(struct ua101 *ua);
static void abort_alsa_capture(struct ua101 *ua);
static const char *usb_error_string(int err)
{
switch (err) {
case -ENODEV:
return "no device";
case -ENOENT:
return "endpoint not enabled";
case -EPIPE:
return "endpoint stalled";
case -ENOSPC:
return "not enough bandwidth";
case -ESHUTDOWN:
return "device disabled";
case -EHOSTUNREACH:
return "device suspended";
case -EINVAL:
case -EAGAIN:
case -EFBIG:
case -EMSGSIZE:
return "internal error";
default:
return "unknown error";
}
}
static void abort_usb_capture(struct ua101 *ua)
{
if (test_and_clear_bit(USB_CAPTURE_RUNNING, &ua->states)) {
wake_up(&ua->alsa_capture_wait);
wake_up(&ua->rate_feedback_wait);
}
}
static void abort_usb_playback(struct ua101 *ua)
{
if (test_and_clear_bit(USB_PLAYBACK_RUNNING, &ua->states))
wake_up(&ua->alsa_playback_wait);
Annotation
- Immediate include surface: `linux/init.h`, `linux/module.h`, `linux/slab.h`, `linux/usb.h`, `linux/usb/audio.h`, `sound/core.h`, `sound/initval.h`, `sound/pcm.h`.
- Detected declarations: `struct ua101`, `struct ua101_stream`, `struct ua101_urb`, `function abort_usb_capture`, `function abort_usb_playback`, `function playback_urb_complete`, `function first_playback_urb_complete`, `function copy_playback_data`, `function add_with_wraparound`, `function playback_work`.
- Atlas domain: Driver Families / sound/usb.
- 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.