sound/soc/codecs/rt1318.c

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

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/rt1318.c
Extension
.c
Size
34432 bytes
Lines
1353
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

if (in_t == pll_out) {
			m_bypass = true;
			n = n_t;
			goto code_find;
		}
		red = abs(in_t - pll_out);
		if (red < red_t) {
			m_bypass = true;
			n = n_t;
			m = m_t;
			if (red == 0)
				goto code_find;
			red_t = red;
		}
		for (m_t = 0; m_t <= max_m; m_t++) {
			out_t = in_t / (m_t + 2);
			red = abs(out_t - pll_out);
			if (red < red_t) {
				m_bypass = false;
				n = n_t;
				m = m_t;
				if (red == 0)
					goto code_find;
				red_t = red;
			}
		}
	}
	pr_debug("Only get approximation about PLL\n");

code_find:

	pll_code->m_bp = m_bypass;
	pll_code->k_bp = k_bypass;
	pll_code->m_code = m;
	pll_code->n_code = n;
	pll_code->k_code = k;
	return 0;
}

static int rt1318_set_dai_pll(struct snd_soc_dai *dai, int pll_id, int source,
			unsigned int freq_in, unsigned int freq_out)
{
	struct snd_soc_component *component = dai->component;
	struct rt1318_priv *rt1318 = snd_soc_component_get_drvdata(component);
	struct rt1318_pll_code pll_code;
	int ret;

	if (!freq_in || !freq_out) {
		dev_dbg(component->dev, "PLL disabled\n");
		rt1318->pll_in = 0;
		rt1318->pll_out = 0;
		return 0;
	}

	if (source == rt1318->pll_src && freq_in == rt1318->pll_in &&
		freq_out == rt1318->pll_out)
		return 0;

	switch (source) {
	case RT1318_PLL_S_BCLK0:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_BCLK0);
		break;
	case RT1318_PLL_S_BCLK1:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_BCLK1);
		break;
	case RT1318_PLL_S_RC:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_RC);
		break;
	case RT1318_PLL_S_MCLK:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_MCLK);
		break;
	case RT1318_PLL_S_SDW_IN_PLL:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_SDW1);
		break;
	case RT1318_PLL_S_SDW_0:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_SDW2);
		break;
	case RT1318_PLL_S_SDW_1:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_SDW3);
		break;
	case RT1318_PLL_S_SDW_2:
		regmap_update_bits(rt1318->regmap, RT1318_CLK1,
			RT1318_PLLIN_MASK, RT1318_PLLIN_SDW4);

Annotation

Implementation Notes