sound/spi/at73c213.c
Source file repositories/reference/linux-study-clean/sound/spi/at73c213.c
File Facts
- System
- Linux kernel
- Corpus path
sound/spi/at73c213.c- Extension
.c- Size
- 27693 bytes
- Lines
- 1100
- Domain
- Driver Families
- Bucket
- sound/spi
- 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.
- Touches IRQ or DMA behavior; this matters for the representative real-device path.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/clk.hlinux/err.hlinux/delay.hlinux/device.hlinux/dma-mapping.hlinux/init.hlinux/interrupt.hlinux/module.hlinux/mutex.hlinux/platform_device.hlinux/io.hsound/initval.hsound/control.hsound/core.hsound/pcm.hlinux/atmel-ssc.hlinux/spi/spi.hlinux/spi/at73c213.hat73c213.h
Detected Declarations
struct snd_at73c213function snd_at73c213_write_regfunction snd_at73c213_set_bitratefunction snd_at73c213_pcm_openfunction snd_at73c213_pcm_closefunction snd_at73c213_pcm_hw_paramsfunction snd_at73c213_pcm_preparefunction snd_at73c213_pcm_triggerfunction snd_at73c213_pcm_pointerfunction snd_at73c213_pcm_newfunction snd_at73c213_interruptfunction scoped_guardfunction snd_at73c213_mono_getfunction snd_at73c213_mono_putfunction snd_at73c213_stereo_infofunction snd_at73c213_stereo_getfunction snd_at73c213_stereo_putfunction snd_at73c213_mono_switch_getfunction snd_at73c213_mono_switch_putfunction snd_at73c213_pa_volume_infofunction snd_at73c213_line_capture_volume_infofunction snd_at73c213_aux_capture_volume_infofunction snd_at73c213_mixerfunction snd_at73c213_ssc_initfunction snd_at73c213_chip_initfunction snd_at73c213_dev_freefunction snd_at73c213_dev_initfunction snd_at73c213_probefunction snd_at73c213_removefunction snd_at73c213_suspendfunction snd_at73c213_resume
Annotated Snippet
struct snd_at73c213 {
struct snd_card *card;
struct snd_pcm *pcm;
struct snd_pcm_substream *substream;
struct at73c213_board_info *board;
int irq;
int period;
unsigned long bitrate;
struct ssc_device *ssc;
struct spi_device *spi;
u8 spi_wbuffer[2];
u8 spi_rbuffer[2];
/* Image of the SPI registers in AT73C213. */
u8 reg_image[18];
/* Protect SSC registers against concurrent access. */
spinlock_t lock;
/* Protect mixer registers against concurrent access. */
struct mutex mixer_lock;
};
#define get_chip(card) ((struct snd_at73c213 *)card->private_data)
static int
snd_at73c213_write_reg(struct snd_at73c213 *chip, u8 reg, u8 val)
{
struct spi_message msg;
struct spi_transfer msg_xfer = {
.len = 2,
.cs_change = 0,
};
int retval;
spi_message_init(&msg);
chip->spi_wbuffer[0] = reg;
chip->spi_wbuffer[1] = val;
msg_xfer.tx_buf = chip->spi_wbuffer;
msg_xfer.rx_buf = chip->spi_rbuffer;
spi_message_add_tail(&msg_xfer, &msg);
retval = spi_sync(chip->spi, &msg);
if (!retval)
chip->reg_image[reg] = val;
return retval;
}
static struct snd_pcm_hardware snd_at73c213_playback_hw = {
.info = SNDRV_PCM_INFO_INTERLEAVED |
SNDRV_PCM_INFO_BLOCK_TRANSFER,
.formats = SNDRV_PCM_FMTBIT_S16_BE,
.rates = SNDRV_PCM_RATE_CONTINUOUS,
.rate_min = 8000, /* Replaced by chip->bitrate later. */
.rate_max = 50000, /* Replaced by chip->bitrate later. */
.channels_min = 1,
.channels_max = 2,
.buffer_bytes_max = 64 * 1024 - 1,
.period_bytes_min = 512,
.period_bytes_max = 64 * 1024 - 1,
.periods_min = 4,
.periods_max = 1024,
};
/*
* Calculate and set bitrate and divisions.
*/
static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
{
unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
unsigned long dac_rate_new, ssc_div;
int status;
unsigned long ssc_div_max, ssc_div_min;
int max_tries;
/*
* We connect two clocks here, picking divisors so the I2S clocks
* out data at the same rate the DAC clocks it in ... and as close
* as practical to the desired target rate.
*
* The DAC master clock (MCLK) is programmable, and is either 256
* or (not here) 384 times the I2S output clock (BCLK).
*/
/* SSC clock / (bitrate * stereo * 16-bit). */
ssc_div = ssc_rate / (BITRATE_TARGET * 2 * 16);
ssc_div_min = ssc_rate / (BITRATE_MAX * 2 * 16);
ssc_div_max = ssc_rate / (BITRATE_MIN * 2 * 16);
max_tries = (ssc_div_max - ssc_div_min) / 2;
Annotation
- Immediate include surface: `linux/clk.h`, `linux/err.h`, `linux/delay.h`, `linux/device.h`, `linux/dma-mapping.h`, `linux/init.h`, `linux/interrupt.h`, `linux/module.h`.
- Detected declarations: `struct snd_at73c213`, `function snd_at73c213_write_reg`, `function snd_at73c213_set_bitrate`, `function snd_at73c213_pcm_open`, `function snd_at73c213_pcm_close`, `function snd_at73c213_pcm_hw_params`, `function snd_at73c213_pcm_prepare`, `function snd_at73c213_pcm_trigger`, `function snd_at73c213_pcm_pointer`, `function snd_at73c213_pcm_new`.
- Atlas domain: Driver Families / sound/spi.
- Implementation status: source 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.