Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4d208ca4 authored by Mark Brown's avatar Mark Brown
Browse files

ASoC: tlv320aic32x4: Convert to direct regmap API usage



This moves us towards being able to remove the duplicate register I/O
functionality in ASoC and saves some code.

Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 752b7764
Loading
Loading
Loading
Loading
+23 −66
Original line number Original line Diff line number Diff line
@@ -60,9 +60,8 @@ struct aic32x4_rate_divs {
};
};


struct aic32x4_priv {
struct aic32x4_priv {
	struct regmap *regmap;
	u32 sysclk;
	u32 sysclk;
	u8 page_no;
	void *control_data;
	u32 power_cfg;
	u32 power_cfg;
	u32 micpga_routing;
	u32 micpga_routing;
	bool swapdacs;
	bool swapdacs;
@@ -262,67 +261,25 @@ static const struct snd_soc_dapm_route aic32x4_dapm_routes[] = {
	{"Right ADC", NULL, "Right Input Mixer"},
	{"Right ADC", NULL, "Right Input Mixer"},
};
};


static inline int aic32x4_change_page(struct snd_soc_codec *codec,
static const struct regmap_range_cfg aic32x4_regmap_pages[] = {
					unsigned int new_page)
	{
	{
	struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
		.selector_reg = 0,
	u8 data[2];
		.selector_mask  = 0xff,
	int ret;
		.window_start = 0,

		.window_len = 128,
	data[0] = 0x00;
		.range_min = AIC32X4_PAGE1,
	data[1] = new_page & 0xff;
		.range_max = AIC32X4_PAGE1 + 127,

	},
	ret = codec->hw_write(codec->control_data, data, 2);
};
	if (ret == 2) {
		aic32x4->page_no = new_page;
		return 0;
	} else {
		return ret;
	}
}

static int aic32x4_write(struct snd_soc_codec *codec, unsigned int reg,
				unsigned int val)
{
	struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
	unsigned int page = reg / 128;
	unsigned int fixed_reg = reg % 128;
	u8 data[2];
	int ret;

	/* A write to AIC32X4_PSEL is really a non-explicit page change */
	if (reg == AIC32X4_PSEL)
		return aic32x4_change_page(codec, val);

	if (aic32x4->page_no != page) {
		ret = aic32x4_change_page(codec, page);
		if (ret != 0)
			return ret;
	}


	data[0] = fixed_reg & 0xff;
static const struct regmap_config aic32x4_regmap = {
	data[1] = val & 0xff;
	.reg_bits = 8,
	.val_bits = 8,


	if (codec->hw_write(codec->control_data, data, 2) == 2)
	.max_register = AIC32X4_RMICPGAVOL,
		return 0;
	.ranges = aic32x4_regmap_pages,
	else
	.num_ranges = ARRAY_SIZE(aic32x4_regmap_pages),
		return -EIO;
};
}

static unsigned int aic32x4_read(struct snd_soc_codec *codec, unsigned int reg)
{
	struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
	unsigned int page = reg / 128;
	unsigned int fixed_reg = reg % 128;
	int ret;

	if (aic32x4->page_no != page) {
		ret = aic32x4_change_page(codec, page);
		if (ret != 0)
			return ret;
	}
	return i2c_smbus_read_byte_data(codec->control_data, fixed_reg & 0xff);
}


static inline int aic32x4_get_divs(int mclk, int rate)
static inline int aic32x4_get_divs(int mclk, int rate)
{
{
@@ -618,8 +575,7 @@ static int aic32x4_probe(struct snd_soc_codec *codec)
	struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
	struct aic32x4_priv *aic32x4 = snd_soc_codec_get_drvdata(codec);
	u32 tmp_reg;
	u32 tmp_reg;


	codec->hw_write = (hw_write_t) i2c_master_send;
	snd_soc_codec_set_cache_io(codec, 8, 8, SND_SOC_REGMAP);
	codec->control_data = aic32x4->control_data;


	if (aic32x4->rstn_gpio >= 0) {
	if (aic32x4->rstn_gpio >= 0) {
		ndelay(10);
		ndelay(10);
@@ -687,8 +643,6 @@ static int aic32x4_remove(struct snd_soc_codec *codec)
}
}


static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = {
static struct snd_soc_codec_driver soc_codec_dev_aic32x4 = {
	.read = aic32x4_read,
	.write = aic32x4_write,
	.probe = aic32x4_probe,
	.probe = aic32x4_probe,
	.remove = aic32x4_remove,
	.remove = aic32x4_remove,
	.suspend = aic32x4_suspend,
	.suspend = aic32x4_suspend,
@@ -715,7 +669,10 @@ static int aic32x4_i2c_probe(struct i2c_client *i2c,
	if (aic32x4 == NULL)
	if (aic32x4 == NULL)
		return -ENOMEM;
		return -ENOMEM;


	aic32x4->control_data = i2c;
	aic32x4->regmap = devm_regmap_init_i2c(i2c, &aic32x4_regmap);
	if (IS_ERR(aic32x4->regmap))
		return PTR_ERR(aic32x4->regmap);

	i2c_set_clientdata(i2c, aic32x4);
	i2c_set_clientdata(i2c, aic32x4);


	if (pdata) {
	if (pdata) {