drivers/usb/gadget/function/u_audio.c
Source file repositories/reference/linux-study-clean/drivers/usb/gadget/function/u_audio.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/usb/gadget/function/u_audio.c- Extension
.c- Size
- 35560 bytes
- Lines
- 1464
- Domain
- Driver Families
- Bucket
- drivers/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.
- Touches user memory; correctness depends on fault-safe copying and privilege boundary handling.
- 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/kernel.hlinux/module.hsound/core.hsound/pcm.hsound/pcm_params.hsound/control.hsound/tlv.hlinux/usb/audio.hu_audio.h
Detected Declarations
struct uac_rtd_paramsstruct snd_uac_chipfunction u_audio_set_fback_frequencyfunction u_audio_iso_completefunction u_audio_iso_fback_completefunction uac_pcm_triggerfunction uac_pcm_pointerfunction uac_ssize_to_fmtfunction uac_pcm_openfunction uac_pcm_nullfunction free_epfunction free_ep_fbackfunction set_activefunction u_audio_set_capture_sratefunction u_audio_get_capture_sratefunction u_audio_set_playback_sratefunction u_audio_get_playback_sratefunction u_audio_start_capturefunction u_audio_stop_capturefunction u_audio_start_playbackfunction u_audio_stop_playbackfunction u_audio_suspendfunction u_audio_get_volumefunction u_audio_set_volumefunction u_audio_get_mutefunction u_audio_set_mutefunction u_audio_pitch_infofunction u_audio_pitch_getfunction u_audio_pitch_putfunction u_audio_mute_infofunction u_audio_mute_getfunction u_audio_mute_putfunction u_audio_volume_tlvfunction u_audio_volume_infofunction u_audio_volume_getfunction u_audio_volume_putfunction get_max_sratefunction get_min_sratefunction u_audio_rate_infofunction u_audio_rate_getfunction g_audio_setupfunction g_audio_cleanupexport u_audio_set_capture_srateexport u_audio_get_capture_srateexport u_audio_set_playback_srateexport u_audio_get_playback_srateexport u_audio_start_captureexport u_audio_stop_capture
Annotated Snippet
struct uac_rtd_params {
struct snd_uac_chip *uac; /* parent chip */
bool ep_enabled; /* if the ep is enabled */
struct snd_pcm_substream *ss;
/* Ring buffer */
ssize_t hw_ptr;
void *rbuf;
unsigned int pitch; /* Stream pitch ratio to 1000000 */
unsigned int max_psize; /* MaxPacketSize of endpoint */
struct usb_request **reqs;
struct usb_request *req_fback; /* Feedback endpoint request */
bool fb_ep_enabled; /* if the ep is enabled */
/* Volume/Mute controls and their state */
int fu_id; /* Feature Unit ID */
struct snd_ctl_elem_id snd_kctl_volume_id;
struct snd_ctl_elem_id snd_kctl_mute_id;
s16 volume_min, volume_max, volume_res;
s16 volume;
int mute;
struct snd_ctl_elem_id snd_kctl_rate_id; /* read-only current rate */
int srate; /* selected samplerate */
int active; /* playback/capture running */
spinlock_t lock; /* lock for control transfers */
};
struct snd_uac_chip {
struct g_audio *audio_dev;
struct uac_rtd_params p_prm;
struct uac_rtd_params c_prm;
struct snd_card *card;
struct snd_pcm *pcm;
/* pre-calculated values for playback iso completion */
unsigned long long p_residue_mil;
unsigned int p_interval;
unsigned int p_framesize;
};
static const struct snd_pcm_hardware uac_pcm_hardware = {
.info = SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER
| SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID
| SNDRV_PCM_INFO_PAUSE | SNDRV_PCM_INFO_RESUME,
.rates = SNDRV_PCM_RATE_CONTINUOUS,
.periods_max = BUFF_SIZE_MAX / PRD_SIZE_MAX,
.buffer_bytes_max = BUFF_SIZE_MAX,
.period_bytes_max = PRD_SIZE_MAX,
.periods_min = MIN_PERIODS,
};
static void u_audio_set_fback_frequency(enum usb_device_speed speed,
struct usb_ep *out_ep,
unsigned long long freq,
unsigned int pitch,
void *buf)
{
u32 ff = 0;
const struct usb_endpoint_descriptor *ep_desc;
/*
* Because the pitch base is 1000000, the final divider here
* will be 1000 * 1000000 = 1953125 << 9
*
* Instead of dealing with big numbers lets fold this 9 left shift
*/
if (speed == USB_SPEED_FULL) {
/*
* Full-speed feedback endpoints report frequency
* in samples/frame
* Format is encoded in Q10.10 left-justified in the 24 bits,
* so that it has a Q10.14 format.
*
* ff = (freq << 14) / 1000
*/
freq <<= 5;
} else {
/*
* High-speed feedback endpoints report frequency
Annotation
- Immediate include surface: `linux/kernel.h`, `linux/module.h`, `sound/core.h`, `sound/pcm.h`, `sound/pcm_params.h`, `sound/control.h`, `sound/tlv.h`, `linux/usb/audio.h`.
- Detected declarations: `struct uac_rtd_params`, `struct snd_uac_chip`, `function u_audio_set_fback_frequency`, `function u_audio_iso_complete`, `function u_audio_iso_fback_complete`, `function uac_pcm_trigger`, `function uac_pcm_pointer`, `function uac_ssize_to_fmt`, `function uac_pcm_open`, `function uac_pcm_null`.
- Atlas domain: Driver Families / drivers/usb.
- Implementation status: integration implementation candidate.
- This snippet crosses the user/kernel memory boundary; validate fault handling and access checks before translating the pattern.
- 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.