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.

Dependency Surface

Detected Declarations

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

Implementation Notes