sound/drivers/pcsp/pcsp_lib.c
Source file repositories/reference/linux-study-clean/sound/drivers/pcsp/pcsp_lib.c
File Facts
- System
- Linux kernel
- Corpus path
sound/drivers/pcsp/pcsp_lib.c- Extension
.c- Size
- 9146 bytes
- Lines
- 353
- Domain
- Driver Families
- Bucket
- sound/drivers
- 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.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/module.hlinux/gfp.hlinux/moduleparam.hlinux/interrupt.hlinux/io.hsound/core.hsound/pcm.hpcsp.h
Detected Declarations
function pcsp_call_pcm_elapsedfunction pcsp_timer_updatefunction pcsp_pointer_updatefunction pcsp_do_timerfunction pcsp_start_playingfunction pcsp_stop_playingfunction pcsp_sync_stopfunction snd_pcsp_playback_closefunction snd_pcsp_playback_hw_paramsfunction snd_pcsp_playback_hw_freefunction snd_pcsp_playback_preparefunction snd_pcsp_triggerfunction snd_pcsp_playback_pointerfunction snd_pcsp_playback_openfunction snd_pcsp_new_pcm
Annotated Snippet
if (!nforce_wa) {
outb_p(chip->val61, 0x61);
outb_p(timer_cnt, 0x42);
outb(chip->val61 ^ 1, 0x61);
} else {
outb(chip->val61 ^ 2, 0x61);
chip->thalf = 1;
}
raw_spin_unlock_irqrestore(&i8253_lock, flags);
}
chip->ns_rem = PCSP_PERIOD_NS();
ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem);
chip->ns_rem -= ns;
return ns;
}
static void pcsp_pointer_update(struct snd_pcsp *chip)
{
struct snd_pcm_substream *substream;
size_t period_bytes, buffer_bytes;
int periods_elapsed;
unsigned long flags;
/* update the playback position */
substream = chip->playback_substream;
if (!substream)
return;
period_bytes = snd_pcm_lib_period_bytes(substream);
buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
spin_lock_irqsave(&chip->substream_lock, flags);
chip->playback_ptr += PCSP_INDEX_INC() * chip->fmt_size;
periods_elapsed = chip->playback_ptr - chip->period_ptr;
if (periods_elapsed < 0) {
#if PCSP_DEBUG
dev_dbg(chip->card->dev,
"PCSP: buffer_bytes mod period_bytes != 0 ? (%zi %zi %zi)\n",
chip->playback_ptr, period_bytes, buffer_bytes);
#endif
periods_elapsed += buffer_bytes;
}
periods_elapsed /= period_bytes;
/* wrap the pointer _before_ calling snd_pcm_period_elapsed(),
* or ALSA will BUG on us. */
chip->playback_ptr %= buffer_bytes;
if (periods_elapsed) {
chip->period_ptr += periods_elapsed * period_bytes;
chip->period_ptr %= buffer_bytes;
queue_work(system_highpri_wq, &pcsp_pcm_work);
}
spin_unlock_irqrestore(&chip->substream_lock, flags);
}
enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
{
struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
int pointer_update;
u64 ns;
if (!atomic_read(&chip->timer_active) || !chip->playback_substream)
return HRTIMER_NORESTART;
pointer_update = !chip->thalf;
ns = pcsp_timer_update(chip);
if (!ns) {
dev_warn(chip->card->dev, "PCSP: unexpected stop\n");
return HRTIMER_NORESTART;
}
if (pointer_update)
pcsp_pointer_update(chip);
hrtimer_forward_now(handle, ns_to_ktime(ns));
return HRTIMER_RESTART;
}
static int pcsp_start_playing(struct snd_pcsp *chip)
{
#if PCSP_DEBUG
dev_dbg(chip->card->dev, "PCSP: start_playing called\n");
#endif
if (atomic_read(&chip->timer_active)) {
dev_err(chip->card->dev, "PCSP: Timer already active\n");
return -EIO;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/gfp.h`, `linux/moduleparam.h`, `linux/interrupt.h`, `linux/io.h`, `sound/core.h`, `sound/pcm.h`, `pcsp.h`.
- Detected declarations: `function pcsp_call_pcm_elapsed`, `function pcsp_timer_update`, `function pcsp_pointer_update`, `function pcsp_do_timer`, `function pcsp_start_playing`, `function pcsp_stop_playing`, `function pcsp_sync_stop`, `function snd_pcsp_playback_close`, `function snd_pcsp_playback_hw_params`, `function snd_pcsp_playback_hw_free`.
- Atlas domain: Driver Families / sound/drivers.
- 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.