sound/soc/rockchip/rockchip_sai.c
Source file repositories/reference/linux-study-clean/sound/soc/rockchip/rockchip_sai.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/rockchip/rockchip_sai.c- Extension
.c- Size
- 42734 bytes
- Lines
- 1531
- Domain
- Driver Families
- Bucket
- sound/soc
- 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.
- 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/mfd/syscon.hlinux/delay.hlinux/of_device.hlinux/clk.hlinux/pm_runtime.hlinux/regmap.hlinux/reset.hlinux/spinlock.hsound/pcm_params.hsound/dmaengine_pcm.hsound/tlv.hrockchip_sai.h
Detected Declarations
struct rk_sai_devenum fpw_modefunction rockchip_sai_stream_validfunction rockchip_sai_fsync_lost_detectfunction rockchip_sai_fsync_err_detectfunction rockchip_sai_poll_clk_idlefunction rockchip_sai_poll_stream_idlefunction rockchip_sai_xfer_clk_stop_and_waitfunction rockchip_sai_runtime_suspendfunction rockchip_sai_runtime_resumefunction rockchip_sai_fifo_xrun_detectfunction rockchip_sai_dma_ctrlfunction rockchip_sai_resetfunction rockchip_sai_clearfunction rockchip_sai_xfer_startfunction rockchip_sai_xfer_stopfunction rockchip_sai_startfunction rockchip_sai_stopfunction rockchip_sai_fmt_createfunction rockchip_sai_set_fmtfunction scoped_guardfunction rockchip_sai_hw_paramsfunction scoped_guardfunction rockchip_sai_preparefunction rockchip_sai_path_configfunction rockchip_sai_path_preparefunction rockchip_sai_parse_pathsfunction rockchip_sai_triggerfunction rockchip_sai_dai_probefunction rockchip_sai_startupfunction rockchip_sai_shutdownfunction rockchip_sai_set_tdm_slotfunction rockchip_sai_set_sysclkfunction rockchip_sai_wr_regfunction rockchip_sai_rd_regfunction rockchip_sai_volatile_regfunction rockchip_sai_precious_regfunction rockchip_sai_init_daifunction of_property_for_each_stringfunction rockchip_sai_wait_time_infofunction rockchip_sai_rd_wait_time_getfunction rockchip_sai_rd_wait_time_putfunction rockchip_sai_wr_wait_time_getfunction rockchip_sai_wr_wait_time_putfunction rockchip_sai_isrfunction rockchip_sai_probefunction rockchip_sai_remove
Annotated Snippet
struct rk_sai_dev {
struct device *dev;
struct clk *hclk;
struct clk *mclk;
struct regmap *regmap;
struct reset_control *rst_h;
struct reset_control *rst_m;
struct snd_dmaengine_dai_dma_data capture_dma_data;
struct snd_dmaengine_dai_dma_data playback_dma_data;
struct snd_pcm_substream *substreams[SNDRV_PCM_STREAM_LAST + 1];
unsigned int mclk_rate;
unsigned int wait_time[SNDRV_PCM_STREAM_LAST + 1];
unsigned int tx_lanes;
unsigned int rx_lanes;
unsigned int sdi[MAX_LANES];
unsigned int sdo[MAX_LANES];
unsigned int version;
enum fpw_mode fpw;
int fw_ratio;
bool has_capture;
bool has_playback;
bool is_master_mode;
bool is_tdm;
bool initialized;
/* protects register writes that depend on the state of XFER[1:0] */
spinlock_t xfer_lock;
};
static bool rockchip_sai_stream_valid(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct rk_sai_dev *sai = snd_soc_dai_get_drvdata(dai);
if (!substream)
return false;
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK &&
sai->has_playback)
return true;
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE &&
sai->has_capture)
return true;
return false;
}
static int rockchip_sai_fsync_lost_detect(struct rk_sai_dev *sai, bool en)
{
unsigned int fw, cnt;
if (sai->is_master_mode || sai->version < SAI_VER_2311)
return 0;
regmap_read(sai->regmap, SAI_FSCR, &fw);
cnt = SAI_FSCR_FW_V(fw) << 1; /* two fsync lost */
regmap_update_bits(sai->regmap, SAI_INTCR,
SAI_INTCR_FSLOSTC, SAI_INTCR_FSLOSTC);
regmap_update_bits(sai->regmap, SAI_INTCR,
SAI_INTCR_FSLOST_MASK,
SAI_INTCR_FSLOST(en));
/*
* The `cnt` is the number of SCLK cycles of the CRU's SCLK signal that
* should be used as timeout. Consequently, in slave mode, this value
* is only correct if the CRU SCLK is equal to the external SCLK.
*/
regmap_update_bits(sai->regmap, SAI_FS_TIMEOUT,
SAI_FS_TIMEOUT_VAL_MASK | SAI_FS_TIMEOUT_EN_MASK,
SAI_FS_TIMEOUT_VAL(cnt) | SAI_FS_TIMEOUT_EN(en));
return 0;
}
static int rockchip_sai_fsync_err_detect(struct rk_sai_dev *sai,
bool en)
{
if (sai->is_master_mode || sai->version < SAI_VER_2311)
return 0;
regmap_update_bits(sai->regmap, SAI_INTCR,
SAI_INTCR_FSERRC, SAI_INTCR_FSERRC);
regmap_update_bits(sai->regmap, SAI_INTCR,
SAI_INTCR_FSERR_MASK,
SAI_INTCR_FSERR(en));
return 0;
}
static int rockchip_sai_poll_clk_idle(struct rk_sai_dev *sai)
Annotation
- Immediate include surface: `linux/module.h`, `linux/mfd/syscon.h`, `linux/delay.h`, `linux/of_device.h`, `linux/clk.h`, `linux/pm_runtime.h`, `linux/regmap.h`, `linux/reset.h`.
- Detected declarations: `struct rk_sai_dev`, `enum fpw_mode`, `function rockchip_sai_stream_valid`, `function rockchip_sai_fsync_lost_detect`, `function rockchip_sai_fsync_err_detect`, `function rockchip_sai_poll_clk_idle`, `function rockchip_sai_poll_stream_idle`, `function rockchip_sai_xfer_clk_stop_and_wait`, `function rockchip_sai_runtime_suspend`, `function rockchip_sai_runtime_resume`.
- Atlas domain: Driver Families / sound/soc.
- 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.