sound/soc/codecs/ntp8835.c

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

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/ntp8835.c
Extension
.c
Size
12422 bytes
Lines
481
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 ntp8835_priv {
	struct i2c_client *i2c;
	struct reset_control *reset;
	unsigned int format;
	struct clk *mclk;
	unsigned int mclk_rate;
};

static const DECLARE_TLV_DB_RANGE(ntp8835_vol_scale,
	0, 1, TLV_DB_SCALE_ITEM(-15000, 0, 0),
	2, 6, TLV_DB_SCALE_ITEM(-15000, 1000, 0),
	7, 0xff, TLV_DB_SCALE_ITEM(-10000, 50, 0),
);

static int ntp8835_mute_info(struct snd_kcontrol *kcontrol,
			     struct snd_ctl_elem_info *uinfo)
{
	uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
	uinfo->access =
		(SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE);
	uinfo->count = 1;

	uinfo->value.integer.min = 0;
	uinfo->value.integer.max = 1;
	uinfo->value.integer.step = 1;

	return 0;
}

static int ntp8835_mute_get(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
	unsigned int val;

	val = snd_soc_component_read(component, NTP8835_SOFT_MUTE);

	ucontrol->value.integer.value[0] = val ? 0 : 1;
	return 0;
}

static int ntp8835_mute_put(struct snd_kcontrol *kcontrol,
			    struct snd_ctl_elem_value *ucontrol)
{
	struct snd_soc_component *component = snd_kcontrol_chip(kcontrol);
	unsigned int val;

	val = ucontrol->value.integer.value[0] ? 0 : 7;

	snd_soc_component_write(component, NTP8835_SOFT_MUTE, val);

	return 0;
}

static const struct snd_kcontrol_new ntp8835_vol_control[] = {
	SOC_SINGLE_TLV("Playback Volume", NTP8835_MASTER_VOL, 0,
		       0xff, 0, ntp8835_vol_scale),
	{
		.iface = SNDRV_CTL_ELEM_IFACE_MIXER,
		.name = "Playback Switch",
		.info = ntp8835_mute_info,
		.access = SNDRV_CTL_ELEM_ACCESS_TLV_READ | SNDRV_CTL_ELEM_ACCESS_READWRITE,
		.get = ntp8835_mute_get,
		.put = ntp8835_mute_put,
	},
};

static void ntp8835_reset_gpio(struct ntp8835_priv *ntp8835)
{
	/*
	 * Proper initialization sequence for NTP835 amplifier requires driving
	 * /RESET signal low during power up for at least 0.1us. The sequence is,
	 * according to NTP8835 datasheet, 6.2 Timing Sequence (recommended):
	 * Deassert for T2 >= 1ms...
	 */
	reset_control_deassert(ntp8835->reset);
	fsleep(1000);

	/* ...Assert for T3 >= 0.1us... */
	reset_control_assert(ntp8835->reset);
	fsleep(1);

	/* ...Deassert, and wait for T4 >= 0.5ms before sound on sequence. */
	reset_control_deassert(ntp8835->reset);
	fsleep(500);
}

static const struct reg_sequence ntp8835_sound_on[] = {
	{ NTP8835_PWM_MASK_CTRL0,	NTP8835_PWM_MASK_CTRL0_FPMLD },
	{ NTP8835_PWM_SWITCH,		0x00 },

Annotation

Implementation Notes