[alsa-devel] [PATCH 0/2] ASoC: tpa6130a2: Use the core to set the gain limit
Hello,
Core will receive support for limiting the volume on controls, so the custom way of doing it in the tpa driver is no longer needed. There was also a problem within the tpa driver when custom limit has been configured. The second patch fixes that.
The combination of the snd_soc_limit_volume, and this series works really nicely together.
--- Peter Ujfalusi (2): Revert "ASoC: tpa6130a2: Support for limiting gain" ASoC: tpa6130a2: Fix for the custom kcontrol functions
include/sound/tpa6130a2-plat.h | 1 - sound/soc/codecs/tpa6130a2.c | 90 +++++++-------------------------------- 2 files changed, 16 insertions(+), 75 deletions(-)
This reverts commit 6f3991152f20933b77eff30413e893bf1a15e578.
Since core has now support for limiting the volume on controls this patch is not needed. Furthermore, this patch actually prevents the core to set new volume on the TPA.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@nokia.com --- include/sound/tpa6130a2-plat.h | 1 - sound/soc/codecs/tpa6130a2.c | 76 ++++----------------------------------- 2 files changed, 8 insertions(+), 69 deletions(-)
diff --git a/include/sound/tpa6130a2-plat.h b/include/sound/tpa6130a2-plat.h index 426f627..e29fde6 100644 --- a/include/sound/tpa6130a2-plat.h +++ b/include/sound/tpa6130a2-plat.h @@ -31,7 +31,6 @@ enum tpa_model { struct tpa6130a2_platform_data { enum tpa_model id; int power_gpio; - int limit_gain; };
#endif diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c index 31f67b5..0cf3e38 100644 --- a/sound/soc/codecs/tpa6130a2.c +++ b/sound/soc/codecs/tpa6130a2.c @@ -46,9 +46,6 @@ static const char *tpa6140a2_supply_names[TPA6130A2_NUM_SUPPLIES] = { "AVdd", };
-#define TPA6130A2_GAIN_MAX 0x3f -#define TPA6140A2_GAIN_MAX 0x1f - /* This struct is used to save the context */ struct tpa6130a2_data { struct mutex mutex; @@ -57,7 +54,6 @@ struct tpa6130a2_data { int power_gpio; unsigned char power_state; enum tpa_model id; - int gain_limit; };
static int tpa6130a2_i2c_read(int reg) @@ -180,40 +176,6 @@ exit: return ret; }
-static int tpa6130a2_info_volsw(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_info *uinfo) -{ - struct soc_mixer_control *mc = - (struct soc_mixer_control *)kcontrol->private_value; - struct tpa6130a2_data *data; - - BUG_ON(tpa6130a2_client == NULL); - data = i2c_get_clientdata(tpa6130a2_client); - - mutex_lock(&data->mutex); - switch (mc->reg) { - case TPA6130A2_REG_VOL_MUTE: - if (data->gain_limit != mc->max) - mc->max = data->gain_limit; - break; - default: - dev_err(&tpa6130a2_client->dev, - "Invalid register: 0x02%x\n", mc->reg); - goto out; - } - if (unlikely(mc->max == 1)) - uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; - else - uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; - - uinfo->count = 1; - uinfo->value.integer.min = 0; - uinfo->value.integer.max = mc->max; -out: - mutex_unlock(&data->mutex); - return 0; -} - static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { @@ -277,15 +239,6 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol, return 1; }
-#define SOC_SINGLE_EXT_TLV_TPA(xname, xreg, xshift, xmax, xinvert, tlv_array) \ -{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \ - .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\ - SNDRV_CTL_ELEM_ACCESS_READWRITE,\ - .tlv.p = (tlv_array), \ - .info = tpa6130a2_info_volsw, \ - .get = tpa6130a2_get_reg, .put = tpa6130a2_set_reg, \ - .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) } - /* * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going * down in gain. @@ -305,9 +258,10 @@ static const unsigned int tpa6130_tlv[] = { };
static const struct snd_kcontrol_new tpa6130a2_controls[] = { - SOC_SINGLE_EXT_TLV_TPA("TPA6130A2 Headphone Playback Volume", - TPA6130A2_REG_VOL_MUTE, 0, TPA6130A2_GAIN_MAX, 0, - tpa6130_tlv), + SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume", + TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0, + tpa6130a2_get_reg, tpa6130a2_set_reg, + tpa6130_tlv), };
static const unsigned int tpa6140_tlv[] = { @@ -318,9 +272,10 @@ static const unsigned int tpa6140_tlv[] = { };
static const struct snd_kcontrol_new tpa6140a2_controls[] = { - SOC_SINGLE_EXT_TLV_TPA("TPA6140A2 Headphone Playback Volume", - TPA6130A2_REG_VOL_MUTE, 1, TPA6140A2_GAIN_MAX, 0, - tpa6140_tlv), + SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume", + TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0, + tpa6130a2_get_reg, tpa6130a2_set_reg, + tpa6140_tlv), };
/* @@ -499,31 +454,16 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client, case TPA6130A2: for (i = 0; i < ARRAY_SIZE(data->supplies); i++) data->supplies[i].supply = tpa6130a2_supply_names[i]; - if (pdata->limit_gain > 0 && - pdata->limit_gain < TPA6130A2_GAIN_MAX) - data->gain_limit = pdata->limit_gain; - else - data->gain_limit = TPA6130A2_GAIN_MAX; break; case TPA6140A2: for (i = 0; i < ARRAY_SIZE(data->supplies); i++) data->supplies[i].supply = tpa6140a2_supply_names[i];; - if (pdata->limit_gain > 0 && - pdata->limit_gain < TPA6140A2_GAIN_MAX) - data->gain_limit = pdata->limit_gain; - else - data->gain_limit = TPA6140A2_GAIN_MAX; break; default: dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n", pdata->id); for (i = 0; i < ARRAY_SIZE(data->supplies); i++) data->supplies[i].supply = tpa6130a2_supply_names[i]; - if (pdata->limit_gain > 0 && - pdata->limit_gain < TPA6130A2_GAIN_MAX) - data->gain_limit = pdata->limit_gain; - else - data->gain_limit = TPA6130A2_GAIN_MAX; }
ret = regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
Since the functions arre only used for volume register, change their name, and also fix them to properly handle the cases, when via soc core the volume is limited.
Signed-off-by: Peter Ujfalusi peter.ujfalusi@nokia.com --- sound/soc/codecs/tpa6130a2.c | 18 ++++++++++-------- 1 files changed, 10 insertions(+), 8 deletions(-)
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c index 0cf3e38..fa4fa33 100644 --- a/sound/soc/codecs/tpa6130a2.c +++ b/sound/soc/codecs/tpa6130a2.c @@ -176,7 +176,7 @@ exit: return ret; }
-static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol, +static int tpa6130a2_get_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct soc_mixer_control *mc = @@ -184,7 +184,8 @@ static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol, struct tpa6130a2_data *data; unsigned int reg = mc->reg; unsigned int shift = mc->shift; - unsigned int mask = mc->max; + int max = mc->max; + unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert;
BUG_ON(tpa6130a2_client == NULL); @@ -197,13 +198,13 @@ static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
if (invert) ucontrol->value.integer.value[0] = - mask - ucontrol->value.integer.value[0]; + max - ucontrol->value.integer.value[0];
mutex_unlock(&data->mutex); return 0; }
-static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol, +static int tpa6130a2_put_volsw(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct soc_mixer_control *mc = @@ -211,7 +212,8 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol, struct tpa6130a2_data *data; unsigned int reg = mc->reg; unsigned int shift = mc->shift; - unsigned int mask = mc->max; + int max = mc->max; + unsigned int mask = (1 << fls(max)) - 1; unsigned int invert = mc->invert; unsigned int val = (ucontrol->value.integer.value[0] & mask); unsigned int val_reg; @@ -220,7 +222,7 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol, data = i2c_get_clientdata(tpa6130a2_client);
if (invert) - val = mask - val; + val = max - val;
mutex_lock(&data->mutex);
@@ -260,7 +262,7 @@ static const unsigned int tpa6130_tlv[] = { static const struct snd_kcontrol_new tpa6130a2_controls[] = { SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume", TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0, - tpa6130a2_get_reg, tpa6130a2_set_reg, + tpa6130a2_get_volsw, tpa6130a2_put_volsw, tpa6130_tlv), };
@@ -274,7 +276,7 @@ static const unsigned int tpa6140_tlv[] = { static const struct snd_kcontrol_new tpa6140a2_controls[] = { SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume", TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0, - tpa6130a2_get_reg, tpa6130a2_set_reg, + tpa6130a2_get_volsw, tpa6130a2_put_volsw, tpa6140_tlv), };
On Fri, May 07, 2010 at 02:24:09PM +0300, Peter Ujfalusi wrote:
Hello,
Core will receive support for limiting the volume on controls, so the custom way of doing it in the tpa driver is no longer needed. There was also a problem within the tpa driver when custom limit has been configured. The second patch fixes that.
The combination of the snd_soc_limit_volume, and this series works really nicely together.
Having discussed with Liam on IRC I've applied these two as well due to the dependency on the core change.
participants (2)
-
Mark Brown
-
Peter Ujfalusi