sound/soc/codecs/rt5514-spi.c
Source file repositories/reference/linux-study-clean/sound/soc/codecs/rt5514-spi.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/codecs/rt5514-spi.c- Extension
.c- Size
- 12976 bytes
- Lines
- 515
- Domain
- Driver Families
- Bucket
- sound/soc
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- 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/module.hlinux/input.hlinux/spi/spi.hlinux/device.hlinux/init.hlinux/delay.hlinux/interrupt.hlinux/irq.hlinux/slab.hlinux/sched.hlinux/uaccess.hlinux/regulator/consumer.hlinux/pm_qos.hlinux/sysfs.hlinux/clk.hsound/core.hsound/pcm.hsound/pcm_params.hsound/soc.hsound/soc-dapm.hsound/initval.hsound/tlv.hrt5514-spi.h
Detected Declarations
struct rt5514_dspfunction rt5514_spi_copy_workfunction rt5514_schedule_copyfunction rt5514_spi_irqfunction rt5514_spi_pcm_openfunction rt5514_spi_hw_paramsfunction rt5514_spi_hw_freefunction rt5514_spi_pcm_pointerfunction rt5514_spi_pcm_probefunction rt5514_spi_pcm_newfunction rt5514_spi_burst_readfunction rt5514_spi_burst_writefunction rt5514_spi_probefunction rt5514_suspendfunction rt5514_resumeexport rt5514_spi_burst_readexport rt5514_spi_burst_write
Annotated Snippet
struct rt5514_dsp {
struct device *dev;
struct delayed_work copy_work;
struct mutex dma_lock;
struct snd_pcm_substream *substream;
unsigned int buf_base, buf_limit, buf_rp;
size_t buf_size, get_size, dma_offset;
};
static const struct snd_pcm_hardware rt5514_spi_pcm_hardware = {
.info = SNDRV_PCM_INFO_MMAP |
SNDRV_PCM_INFO_MMAP_VALID |
SNDRV_PCM_INFO_INTERLEAVED,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
.period_bytes_min = PAGE_SIZE,
.period_bytes_max = 0x20000 / 8,
.periods_min = 8,
.periods_max = 8,
.channels_min = 1,
.channels_max = 1,
.buffer_bytes_max = 0x20000,
};
static struct snd_soc_dai_driver rt5514_spi_dai = {
.name = "rt5514-dsp-cpu-dai",
.id = 0,
.capture = {
.stream_name = "DSP Capture",
.channels_min = 1,
.channels_max = 1,
.rates = SNDRV_PCM_RATE_16000,
.formats = SNDRV_PCM_FMTBIT_S16_LE,
},
};
static void rt5514_spi_copy_work(struct work_struct *work)
{
struct rt5514_dsp *rt5514_dsp =
container_of(work, struct rt5514_dsp, copy_work.work);
struct snd_pcm_runtime *runtime;
size_t period_bytes, truncated_bytes = 0;
unsigned int cur_wp, remain_data;
u8 buf[8];
mutex_lock(&rt5514_dsp->dma_lock);
if (!rt5514_dsp->substream) {
dev_err(rt5514_dsp->dev, "No pcm substream\n");
goto done;
}
runtime = rt5514_dsp->substream->runtime;
period_bytes = snd_pcm_lib_period_bytes(rt5514_dsp->substream);
if (!period_bytes) {
schedule_delayed_work(&rt5514_dsp->copy_work, 5);
goto done;
}
if (rt5514_dsp->buf_size % period_bytes)
rt5514_dsp->buf_size = (rt5514_dsp->buf_size / period_bytes) *
period_bytes;
if (rt5514_dsp->get_size >= rt5514_dsp->buf_size) {
rt5514_spi_burst_read(RT5514_BUFFER_VOICE_WP, (u8 *)&buf,
sizeof(buf));
cur_wp = buf[0] | buf[1] << 8 | buf[2] << 16 |
buf[3] << 24;
if (cur_wp >= rt5514_dsp->buf_rp)
remain_data = (cur_wp - rt5514_dsp->buf_rp);
else
remain_data =
(rt5514_dsp->buf_limit - rt5514_dsp->buf_rp) +
(cur_wp - rt5514_dsp->buf_base);
if (remain_data < period_bytes) {
schedule_delayed_work(&rt5514_dsp->copy_work, 5);
goto done;
}
}
if (rt5514_dsp->buf_rp + period_bytes <= rt5514_dsp->buf_limit) {
rt5514_spi_burst_read(rt5514_dsp->buf_rp,
runtime->dma_area + rt5514_dsp->dma_offset,
period_bytes);
if (rt5514_dsp->buf_rp + period_bytes == rt5514_dsp->buf_limit)
rt5514_dsp->buf_rp = rt5514_dsp->buf_base;
else
rt5514_dsp->buf_rp += period_bytes;
} else {
Annotation
- Immediate include surface: `linux/module.h`, `linux/input.h`, `linux/spi/spi.h`, `linux/device.h`, `linux/init.h`, `linux/delay.h`, `linux/interrupt.h`, `linux/irq.h`.
- Detected declarations: `struct rt5514_dsp`, `function rt5514_spi_copy_work`, `function rt5514_schedule_copy`, `function rt5514_spi_irq`, `function rt5514_spi_pcm_open`, `function rt5514_spi_hw_params`, `function rt5514_spi_hw_free`, `function rt5514_spi_pcm_pointer`, `function rt5514_spi_pcm_probe`, `function rt5514_spi_pcm_new`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
- IRQ or DMA behavior appears here, which is relevant to the selected PCIe/NVMe device path.
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.