sound/soc/sophgo/cv1800b-sound-dac.c
Source file repositories/reference/linux-study-clean/sound/soc/sophgo/cv1800b-sound-dac.c
File Facts
- System
- Linux kernel
- Corpus path
sound/soc/sophgo/cv1800b-sound-dac.c- Extension
.c- Size
- 5210 bytes
- Lines
- 209
- 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/module.hlinux/platform_device.hlinux/bitfield.hlinux/bits.hsound/soc.hlinux/io.h
Detected Declarations
struct cv1800b_privenum decimation_valuesfunction cv1800b_dac_enablefunction cv1800b_dac_mutefunction cv1800b_dac_decimationfunction cv1800b_dac_dlyfunction cv1800b_dac_hw_paramsfunction cv1800b_dac_dai_triggerfunction cv1800b_dac_probe
Annotated Snippet
struct cv1800b_priv {
void __iomem *regs;
struct device *dev;
};
enum decimation_values {
DECIMATION_64 = 0,
DECIMATION_128,
DECIMATION_256,
DECIMATION_512,
};
static void cv1800b_dac_enable(struct cv1800b_priv *priv, bool enable)
{
u32 val;
val = readl(priv->regs + CV1800B_TXDAC_CTRL0);
val = u32_replace_bits(val, enable, REG_TXDAC_EN);
val = u32_replace_bits(val, enable, REG_I2S_RX_EN);
writel(val, priv->regs + CV1800B_TXDAC_CTRL0);
}
/*
* Control the DAC overwrite bits. When enabled, the DAC outputs the fixed
* overwrite value instead of samples from the I2S input.
*/
static void cv1800b_dac_mute(struct cv1800b_priv *priv, bool enable)
{
u32 val;
val = readl(priv->regs + CV1800B_TXDAC_ANA2);
val = u32_replace_bits(val, enable, TXDAC_OW_EN_L_MASK);
val = u32_replace_bits(val, enable, TXDAC_OW_EN_R_MASK);
writel(val, priv->regs + CV1800B_TXDAC_ANA2);
}
static int cv1800b_dac_decimation(struct cv1800b_priv *priv, u8 dec)
{
u32 val;
if (dec > 3)
return -EINVAL;
val = readl(priv->regs + CV1800B_TXDAC_CTRL1);
val = u32_replace_bits(val, dec, REG_TXDAC_CIC_OPT);
writel(val, priv->regs + CV1800B_TXDAC_CTRL1);
return 0;
}
static int cv1800b_dac_dly(struct cv1800b_priv *priv, u32 dly)
{
u32 val;
if (dly > 63)
return -EINVAL;
val = readl(priv->regs + CV1800B_TXDAC_AFE0);
val = u32_replace_bits(val, dly, REG_TXDAC_INIT_DLY_CNT);
writel(val, priv->regs + CV1800B_TXDAC_AFE0);
return 0;
}
static int cv1800b_dac_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
struct cv1800b_priv *priv = snd_soc_dai_get_drvdata(dai);
int ret;
unsigned int rate = params_rate(params);
if (rate != 48000) {
dev_err(priv->dev, "rate %u is not supported\n", rate);
return -EINVAL;
}
/* Clear DAC overwrite so playback uses I2S data. */
cv1800b_dac_mute(priv, false);
/* minimal decimation for 48kHz is 64*/
ret = cv1800b_dac_decimation(priv, DECIMATION_64);
if (ret)
return ret;
/* value is taken from vendors driver 48kHz
* tested on sg2000 and sg2002.
*/
ret = cv1800b_dac_dly(priv, 0x19);
if (ret)
return ret;
return 0;
}
Annotation
- Immediate include surface: `linux/module.h`, `linux/platform_device.h`, `linux/bitfield.h`, `linux/bits.h`, `sound/soc.h`, `linux/io.h`.
- Detected declarations: `struct cv1800b_priv`, `enum decimation_values`, `function cv1800b_dac_enable`, `function cv1800b_dac_mute`, `function cv1800b_dac_decimation`, `function cv1800b_dac_dly`, `function cv1800b_dac_hw_params`, `function cv1800b_dac_dai_trigger`, `function cv1800b_dac_probe`.
- 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.