sound/soc/codecs/simple-amplifier.c

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

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/simple-amplifier.c
Extension
.c
Size
26659 bytes
Lines
977
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 simple_amp_single {
	struct gpio_desc *gpio;
	bool is_inverted;
	int kctrl_val;
	const char *control_name;
};

struct simple_amp_point {
	u32 gpio_val;
	int gain_db;
};

struct simple_amp_range {
	unsigned int nb_points;
	struct simple_amp_point min;
	struct simple_amp_point max;
};

struct simple_amp_ranges {
	unsigned int nb_ranges;
	struct simple_amp_range *tab_ranges;
};

struct simple_amp_labels {
	unsigned int nb_labels;
	const char **tab_labels;
};

enum simple_amp_mode {
	SIMPLE_AMP_MODE_NONE,
	SIMPLE_AMP_MODE_RANGES,
	SIMPLE_AMP_MODE_LABELS,
};

struct simple_amp_multi {
	struct gpio_descs *gpios;
	u32 kctrl_val;
	u32 kctrl_max;
	const char *control_name;
	unsigned int *tlv_array;
	enum simple_amp_mode mode;
	union {
		struct simple_amp_ranges ranges;
		struct simple_amp_labels labels;
	};
};

struct simple_amp_data {
	unsigned int supports;
#define SIMPLE_AUDIO_SUPPORT_PGA		BIT(0)
#define SIMPLE_AUDIO_SUPPORT_POWER_SUPPLIES	BIT(1)
#define SIMPLE_AUDIO_SUPPORT_MUTE		BIT(2)
#define SIMPLE_AUDIO_SUPPORT_BYPASS		BIT(3)

	const struct snd_soc_dapm_widget *dapm_widgets;
	unsigned int num_dapm_widgets;
	const struct snd_soc_dapm_route *dapm_routes;
	unsigned int num_dapm_routes;
};

struct simple_amp {
	const struct simple_amp_data *data;
	struct gpio_desc *gpiod_enable;
	struct simple_amp_single mute;
	struct simple_amp_single bypass;
	struct simple_amp_multi gain;
};

static int simple_amp_power_event(struct snd_soc_dapm_widget *w,
				  struct snd_kcontrol *control, int event)
{
	struct snd_soc_component *c = snd_soc_dapm_to_component(w->dapm);
	struct simple_amp *simple_amp = snd_soc_component_get_drvdata(c);
	int val;

	switch (event) {
	case SND_SOC_DAPM_POST_PMU:
		val = 1;
		break;
	case SND_SOC_DAPM_PRE_PMD:
		val = 0;
		break;
	default:
		WARN(1, "Unexpected event");
		return -EINVAL;
	}

	gpiod_set_value_cansleep(simple_amp->gpiod_enable, val);

	return 0;

Annotation

Implementation Notes