sound/soc/codecs/uda1342.c

Source file repositories/reference/linux-study-clean/sound/soc/codecs/uda1342.c

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/uda1342.c
Extension
.c
Size
9144 bytes
Lines
348
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 uda1342_priv {
	int sysclk;
	int dai_fmt;

	struct snd_pcm_substream *provider_substream;
	struct snd_pcm_substream *consumer_substream;

	struct regmap *regmap;
	struct i2c_client *i2c;
};

static const struct reg_default uda1342_reg_defaults[] = {
	{ 0x00, 0x1042 },
	{ 0x01, 0x0000 },
	{ 0x10, 0x0088 },
	{ 0x11, 0x0000 },
	{ 0x12, 0x0000 },
	{ 0x20, 0x0080 },
	{ 0x21, 0x0080 },
};

static int uda1342_mute(struct snd_soc_dai *dai, int mute, int direction)
{
	struct snd_soc_component *component = dai->component;
	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
	unsigned int mask;
	unsigned int val = 0;

	/* Master mute */
	mask = BIT(5);
	if (mute)
		val = mask;

	return regmap_update_bits(uda1342->regmap, 0x10, mask, val);
}

static int uda1342_startup(struct snd_pcm_substream *substream,
			   struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
	struct snd_pcm_runtime *provider_runtime;

	if (uda1342->provider_substream) {
		provider_runtime = uda1342->provider_substream->runtime;

		snd_pcm_hw_constraint_single(substream->runtime,
					     SNDRV_PCM_HW_PARAM_RATE, provider_runtime->rate);
		snd_pcm_hw_constraint_single(substream->runtime,
					     SNDRV_PCM_HW_PARAM_SAMPLE_BITS,
					     provider_runtime->sample_bits);

		uda1342->consumer_substream = substream;
	} else {
		uda1342->provider_substream = substream;
	}

	return 0;
}

static void uda1342_shutdown(struct snd_pcm_substream *substream,
			     struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);

	if (uda1342->provider_substream == substream)
		uda1342->provider_substream = uda1342->consumer_substream;

	uda1342->consumer_substream = NULL;
}

static int uda1342_hw_params(struct snd_pcm_substream *substream,
			     struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
{
	struct snd_soc_component *component = dai->component;
	struct uda1342_priv *uda1342 = snd_soc_component_get_drvdata(component);
	struct device *dev = &uda1342->i2c->dev;
	unsigned int hw_params = 0;

	if (substream == uda1342->consumer_substream)
		return 0;

	/* set SYSCLK / fs ratio */
	switch (uda1342->sysclk / params_rate(params)) {
	case 512:
		break;
	case 384:
		hw_params |= BIT(4);
		break;

Annotation

Implementation Notes