sound/soc/codecs/mt6660.c

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

File Facts

System
Linux kernel
Corpus path
sound/soc/codecs/mt6660.c
Extension
.c
Size
15071 bytes
Lines
581
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 reg_size_table {
	u32 addr;
	u8 size;
};

static const struct reg_size_table mt6660_reg_size_table[] = {
	{ MT6660_REG_HPF1_COEF, 4 },
	{ MT6660_REG_HPF2_COEF, 4 },
	{ MT6660_REG_TDM_CFG3, 2 },
	{ MT6660_REG_RESV17, 2 },
	{ MT6660_REG_RESV23, 2 },
	{ MT6660_REG_SIGMAX, 2 },
	{ MT6660_REG_DEVID, 2 },
	{ MT6660_REG_HCLIP_CTRL, 2 },
	{ MT6660_REG_DA_GAIN, 2 },
};

static int mt6660_get_reg_size(uint32_t addr)
{
	int i;

	for (i = 0; i < ARRAY_SIZE(mt6660_reg_size_table); i++) {
		if (mt6660_reg_size_table[i].addr == addr)
			return mt6660_reg_size_table[i].size;
	}
	return 1;
}

static int mt6660_reg_write(void *context, unsigned int reg, unsigned int val)
{
	struct mt6660_chip *chip = context;
	int size = mt6660_get_reg_size(reg);
	u8 reg_data[4];
	int i;

	for (i = 0; i < size; i++)
		reg_data[size - i - 1] = (val >> (8 * i)) & 0xff;

	return i2c_smbus_write_i2c_block_data(chip->i2c, reg, size, reg_data);
}

static int mt6660_reg_read(void *context, unsigned int reg, unsigned int *val)
{
	struct mt6660_chip *chip = context;
	int size = mt6660_get_reg_size(reg);
	int i, ret;
	u8 data[4];
	u32 reg_data = 0;

	ret = i2c_smbus_read_i2c_block_data(chip->i2c, reg, size, data);
	if (ret < 0)
		return ret;
	for (i = 0; i < size; i++) {
		reg_data <<= 8;
		reg_data |= data[i];
	}
	*val = reg_data;
	return 0;
}

static const struct regmap_config mt6660_regmap_config = {
	.reg_bits = 8,
	.val_bits = 32,
	.reg_write = mt6660_reg_write,
	.reg_read = mt6660_reg_read,
};

static int mt6660_codec_dac_event(struct snd_soc_dapm_widget *w,
	struct snd_kcontrol *kcontrol, int event)
{
	if (event == SND_SOC_DAPM_POST_PMU)
		usleep_range(1000, 1100);
	return 0;
}

static int mt6660_codec_classd_event(struct snd_soc_dapm_widget *w,
	struct snd_kcontrol *kcontrol, int event)
{
	struct snd_soc_component *component =
		snd_soc_dapm_to_component(w->dapm);
	int ret;

	switch (event) {
	case SND_SOC_DAPM_PRE_PMU:
		dev_dbg(component->dev,
			"%s: before classd turn on\n", __func__);
		/* config to adaptive mode */
		ret = snd_soc_component_update_bits(component,
			MT6660_REG_BST_CTRL, 0x03, 0x03);
		if (ret < 0) {

Annotation

Implementation Notes