sound/soc/rockchip/rockchip_spdif.c
Source file repositories/reference/linux-study-clean/sound/soc/rockchip/rockchip_spdif.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/rockchip/rockchip_spdif.c- Extension
.c- Size
- 11355 bytes
- Lines
- 451
- 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.
- 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/bitfield.hlinux/module.hlinux/delay.hlinux/clk.hlinux/pm_runtime.hlinux/mfd/syscon.hlinux/regmap.hsound/pcm_params.hsound/pcm_iec958.hsound/dmaengine_pcm.hrockchip_spdif.h
Detected Declarations
struct rk_spdif_devenum rk_spdif_typefunction rk_spdif_runtime_suspendfunction rk_spdif_runtime_resumefunction rk_spdif_hw_paramsfunction rk_spdif_triggerfunction rk_spdif_dai_probefunction rk_spdif_set_sysclkfunction rk_spdif_wr_regfunction rk_spdif_rd_regfunction rk_spdif_volatile_regfunction rk_spdif_suspendfunction rk_spdif_probe
Annotated Snippet
struct rk_spdif_dev {
struct device *dev;
struct clk *mclk;
struct clk *hclk;
struct snd_dmaengine_dai_dma_data playback_dma_data;
struct regmap *regmap;
};
static int rk_spdif_runtime_suspend(struct device *dev)
{
struct rk_spdif_dev *spdif = dev_get_drvdata(dev);
regcache_cache_only(spdif->regmap, true);
clk_disable_unprepare(spdif->mclk);
clk_disable_unprepare(spdif->hclk);
return 0;
}
static int rk_spdif_runtime_resume(struct device *dev)
{
struct rk_spdif_dev *spdif = dev_get_drvdata(dev);
int ret;
ret = clk_prepare_enable(spdif->hclk);
if (ret) {
dev_err(spdif->dev, "hclk clock enable failed %d\n", ret);
return ret;
}
ret = clk_prepare_enable(spdif->mclk);
if (ret) {
clk_disable_unprepare(spdif->hclk);
dev_err(spdif->dev, "mclk clock enable failed %d\n", ret);
return ret;
}
regcache_cache_only(spdif->regmap, false);
regcache_mark_dirty(spdif->regmap);
ret = regcache_sync(spdif->regmap);
if (ret) {
regcache_cache_only(spdif->regmap, true);
clk_disable_unprepare(spdif->mclk);
clk_disable_unprepare(spdif->hclk);
}
return ret;
}
static int rk_spdif_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct rk_spdif_dev *spdif = snd_soc_dai_get_drvdata(dai);
unsigned int mclk_rate = clk_get_rate(spdif->mclk);
unsigned int val = SPDIF_CFGR_HALFWORD_ENABLE;
int bmc, div, ret, i;
u16 *fc;
u8 cs[CS_BYTE];
ret = snd_pcm_create_iec958_consumer_hw_params(params, cs, sizeof(cs));
if (ret < 0)
return ret;
fc = (u16 *)cs;
for (i = 0; i < CS_BYTE / 2; i++)
regmap_write(spdif->regmap, SPDIF_CHNSRn(i), CS_FRAME(fc[i]));
regmap_update_bits(spdif->regmap, SPDIF_CFGR, SPDIF_CFGR_CSE_MASK,
SPDIF_CFGR_CSE_EN);
/* bmc = 128fs */
bmc = 128 * params_rate(params);
div = DIV_ROUND_CLOSEST(mclk_rate, bmc);
val |= SPDIF_CFGR_CLK_DIV(div);
switch (params_format(params)) {
case SNDRV_PCM_FORMAT_S16_LE:
val |= SPDIF_CFGR_VDW_16;
val |= SPDIF_CFGR_ADJ_RIGHT_J;
break;
case SNDRV_PCM_FORMAT_S20_3LE:
val |= SPDIF_CFGR_VDW_20;
val |= SPDIF_CFGR_ADJ_RIGHT_J;
break;
case SNDRV_PCM_FORMAT_S24_LE:
Annotation
- Immediate include surface: `linux/bitfield.h`, `linux/module.h`, `linux/delay.h`, `linux/clk.h`, `linux/pm_runtime.h`, `linux/mfd/syscon.h`, `linux/regmap.h`, `sound/pcm_params.h`.
- Detected declarations: `struct rk_spdif_dev`, `enum rk_spdif_type`, `function rk_spdif_runtime_suspend`, `function rk_spdif_runtime_resume`, `function rk_spdif_hw_params`, `function rk_spdif_trigger`, `function rk_spdif_dai_probe`, `function rk_spdif_set_sysclk`, `function rk_spdif_wr_reg`, `function rk_spdif_rd_reg`.
- Atlas domain: Driver Families / sound/soc.
- Implementation status: source implementation candidate.
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.