sound/soc/sunxi/sun8i-codec-analog.c

Source file repositories/reference/linux-study-clean/sound/soc/sunxi/sun8i-codec-analog.c

File Facts

System
Linux kernel
Corpus path
sound/soc/sunxi/sun8i-codec-analog.c
Extension
.c
Size
27465 bytes
Lines
854
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 sun8i_codec_analog_quirks {
	bool has_headphone;
	bool has_hmic;
	bool has_linein;
	bool has_lineout;
	bool has_mbias;
	bool has_mic2;
};

static const struct sun8i_codec_analog_quirks sun8i_a23_quirks = {
	.has_headphone	= true,
	.has_hmic	= true,
	.has_linein	= true,
	.has_mbias	= true,
	.has_mic2	= true,
};

static const struct sun8i_codec_analog_quirks sun8i_h3_quirks = {
	.has_linein	= true,
	.has_lineout	= true,
	.has_mbias	= true,
	.has_mic2	= true,
};

static int sun8i_codec_analog_add_mixer(struct snd_soc_component *cmpnt,
					const struct sun8i_codec_analog_quirks *quirks)
{
	struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(cmpnt);
	struct device *dev = cmpnt->dev;
	int ret;

	if (!quirks->has_mic2 && !quirks->has_linein) {
		/*
		 * Apply the special widget set which has uses a control
		 * without MIC2 and Line In, for SoCs without these.
		 * TODO: not all special cases are supported now, this case
		 * is present because it's the case of V3s.
		 */
		ret = snd_soc_dapm_new_controls(dapm,
						sun8i_v3s_codec_mixer_widgets,
						ARRAY_SIZE(sun8i_v3s_codec_mixer_widgets));
		if (ret) {
			dev_err(dev, "Failed to add V3s Mixer DAPM widgets: %d\n", ret);
			return ret;
		}
	} else {
		/* Apply the generic mixer widget set. */
		ret = snd_soc_dapm_new_controls(dapm,
						sun8i_codec_mixer_widgets,
						ARRAY_SIZE(sun8i_codec_mixer_widgets));
		if (ret) {
			dev_err(dev, "Failed to add Mixer DAPM widgets: %d\n", ret);
			return ret;
		}
	}

	ret = snd_soc_dapm_add_routes(dapm, sun8i_codec_mixer_routes,
				      ARRAY_SIZE(sun8i_codec_mixer_routes));
	if (ret) {
		dev_err(dev, "Failed to add Mixer DAPM routes: %d\n", ret);
		return ret;
	}

	return 0;
}

static const struct sun8i_codec_analog_quirks sun8i_v3s_quirks = {
	.has_headphone	= true,
	.has_hmic	= true,
};

static int sun8i_codec_analog_cmpnt_probe(struct snd_soc_component *cmpnt)
{
	struct device *dev = cmpnt->dev;
	const struct sun8i_codec_analog_quirks *quirks;
	int ret;

	/*
	 * This would never return NULL unless someone directly registers a
	 * platform device matching this driver's name, without specifying a
	 * device tree node.
	 */
	quirks = of_device_get_match_data(dev);

	/* Add controls, widgets, and routes for individual features */
	ret = sun8i_codec_analog_add_mixer(cmpnt, quirks);
	if (ret)
		return ret;

	if (quirks->has_headphone) {

Annotation

Implementation Notes