aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/codecs
diff options
context:
space:
mode:
Diffstat (limited to 'sound/soc/codecs')
-rw-r--r--sound/soc/codecs/tpa6130a2.c76
1 files changed, 8 insertions, 68 deletions
diff --git a/sound/soc/codecs/tpa6130a2.c b/sound/soc/codecs/tpa6130a2.c
index 31f67b527ca1..0cf3e3862e7b 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] = {
46 "AVdd", 46 "AVdd",
47}; 47};
48 48
49#define TPA6130A2_GAIN_MAX 0x3f
50#define TPA6140A2_GAIN_MAX 0x1f
51
52/* This struct is used to save the context */ 49/* This struct is used to save the context */
53struct tpa6130a2_data { 50struct tpa6130a2_data {
54 struct mutex mutex; 51 struct mutex mutex;
@@ -57,7 +54,6 @@ struct tpa6130a2_data {
57 int power_gpio; 54 int power_gpio;
58 unsigned char power_state; 55 unsigned char power_state;
59 enum tpa_model id; 56 enum tpa_model id;
60 int gain_limit;
61}; 57};
62 58
63static int tpa6130a2_i2c_read(int reg) 59static int tpa6130a2_i2c_read(int reg)
@@ -180,40 +176,6 @@ exit:
180 return ret; 176 return ret;
181} 177}
182 178
183static int tpa6130a2_info_volsw(struct snd_kcontrol *kcontrol,
184 struct snd_ctl_elem_info *uinfo)
185{
186 struct soc_mixer_control *mc =
187 (struct soc_mixer_control *)kcontrol->private_value;
188 struct tpa6130a2_data *data;
189
190 BUG_ON(tpa6130a2_client == NULL);
191 data = i2c_get_clientdata(tpa6130a2_client);
192
193 mutex_lock(&data->mutex);
194 switch (mc->reg) {
195 case TPA6130A2_REG_VOL_MUTE:
196 if (data->gain_limit != mc->max)
197 mc->max = data->gain_limit;
198 break;
199 default:
200 dev_err(&tpa6130a2_client->dev,
201 "Invalid register: 0x02%x\n", mc->reg);
202 goto out;
203 }
204 if (unlikely(mc->max == 1))
205 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
206 else
207 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
208
209 uinfo->count = 1;
210 uinfo->value.integer.min = 0;
211 uinfo->value.integer.max = mc->max;
212out:
213 mutex_unlock(&data->mutex);
214 return 0;
215}
216
217static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol, 179static int tpa6130a2_get_reg(struct snd_kcontrol *kcontrol,
218 struct snd_ctl_elem_value *ucontrol) 180 struct snd_ctl_elem_value *ucontrol)
219{ 181{
@@ -277,15 +239,6 @@ static int tpa6130a2_set_reg(struct snd_kcontrol *kcontrol,
277 return 1; 239 return 1;
278} 240}
279 241
280#define SOC_SINGLE_EXT_TLV_TPA(xname, xreg, xshift, xmax, xinvert, tlv_array) \
281{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, \
282 .access = SNDRV_CTL_ELEM_ACCESS_TLV_READ |\
283 SNDRV_CTL_ELEM_ACCESS_READWRITE,\
284 .tlv.p = (tlv_array), \
285 .info = tpa6130a2_info_volsw, \
286 .get = tpa6130a2_get_reg, .put = tpa6130a2_set_reg, \
287 .private_value = SOC_SINGLE_VALUE(xreg, xshift, xmax, xinvert) }
288
289/* 242/*
290 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going 243 * TPA6130 volume. From -59.5 to 4 dB with increasing step size when going
291 * down in gain. 244 * down in gain.
@@ -305,9 +258,10 @@ static const unsigned int tpa6130_tlv[] = {
305}; 258};
306 259
307static const struct snd_kcontrol_new tpa6130a2_controls[] = { 260static const struct snd_kcontrol_new tpa6130a2_controls[] = {
308 SOC_SINGLE_EXT_TLV_TPA("TPA6130A2 Headphone Playback Volume", 261 SOC_SINGLE_EXT_TLV("TPA6130A2 Headphone Playback Volume",
309 TPA6130A2_REG_VOL_MUTE, 0, TPA6130A2_GAIN_MAX, 0, 262 TPA6130A2_REG_VOL_MUTE, 0, 0x3f, 0,
310 tpa6130_tlv), 263 tpa6130a2_get_reg, tpa6130a2_set_reg,
264 tpa6130_tlv),
311}; 265};
312 266
313static const unsigned int tpa6140_tlv[] = { 267static const unsigned int tpa6140_tlv[] = {
@@ -318,9 +272,10 @@ static const unsigned int tpa6140_tlv[] = {
318}; 272};
319 273
320static const struct snd_kcontrol_new tpa6140a2_controls[] = { 274static const struct snd_kcontrol_new tpa6140a2_controls[] = {
321 SOC_SINGLE_EXT_TLV_TPA("TPA6140A2 Headphone Playback Volume", 275 SOC_SINGLE_EXT_TLV("TPA6140A2 Headphone Playback Volume",
322 TPA6130A2_REG_VOL_MUTE, 1, TPA6140A2_GAIN_MAX, 0, 276 TPA6130A2_REG_VOL_MUTE, 1, 0x1f, 0,
323 tpa6140_tlv), 277 tpa6130a2_get_reg, tpa6130a2_set_reg,
278 tpa6140_tlv),
324}; 279};
325 280
326/* 281/*
@@ -499,31 +454,16 @@ static int __devinit tpa6130a2_probe(struct i2c_client *client,
499 case TPA6130A2: 454 case TPA6130A2:
500 for (i = 0; i < ARRAY_SIZE(data->supplies); i++) 455 for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
501 data->supplies[i].supply = tpa6130a2_supply_names[i]; 456 data->supplies[i].supply = tpa6130a2_supply_names[i];
502 if (pdata->limit_gain > 0 &&
503 pdata->limit_gain < TPA6130A2_GAIN_MAX)
504 data->gain_limit = pdata->limit_gain;
505 else
506 data->gain_limit = TPA6130A2_GAIN_MAX;
507 break; 457 break;
508 case TPA6140A2: 458 case TPA6140A2:
509 for (i = 0; i < ARRAY_SIZE(data->supplies); i++) 459 for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
510 data->supplies[i].supply = tpa6140a2_supply_names[i];; 460 data->supplies[i].supply = tpa6140a2_supply_names[i];;
511 if (pdata->limit_gain > 0 &&
512 pdata->limit_gain < TPA6140A2_GAIN_MAX)
513 data->gain_limit = pdata->limit_gain;
514 else
515 data->gain_limit = TPA6140A2_GAIN_MAX;
516 break; 461 break;
517 default: 462 default:
518 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n", 463 dev_warn(dev, "Unknown TPA model (%d). Assuming 6130A2\n",
519 pdata->id); 464 pdata->id);
520 for (i = 0; i < ARRAY_SIZE(data->supplies); i++) 465 for (i = 0; i < ARRAY_SIZE(data->supplies); i++)
521 data->supplies[i].supply = tpa6130a2_supply_names[i]; 466 data->supplies[i].supply = tpa6130a2_supply_names[i];
522 if (pdata->limit_gain > 0 &&
523 pdata->limit_gain < TPA6130A2_GAIN_MAX)
524 data->gain_limit = pdata->limit_gain;
525 else
526 data->gain_limit = TPA6130A2_GAIN_MAX;
527 } 467 }
528 468
529 ret = regulator_bulk_get(dev, ARRAY_SIZE(data->supplies), 469 ret = regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),