aboutsummaryrefslogtreecommitdiffstats
path: root/sound/i2c/other
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2006-09-08 06:27:38 -0400
committerJaroslav Kysela <perex@suse.cz>2006-09-23 04:46:55 -0400
commit854b66e44260320c21ebe4b8a18e189f2e45b5be (patch)
tree2e9636686f69d9f7ab659d3afa1b7495ef6de7d8 /sound/i2c/other
parent8f88820ee49359ea33af42845456ce9dbf54d39a (diff)
[ALSA] ak4xxx - Remove bogus IPGA controls
Remove IPGA volume controls and merge the IPGA range to ADC volume controls. These two volumes are not really independent but connected simply in different ranges 0-0x7f and 0x80-max. It doesn't make sense to provide two controls. Since both 0x7f and 0x80 specify 0dB, a hack is needed for IPGA range to skip 0x80 (increment one) for such controls. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@suse.cz>
Diffstat (limited to 'sound/i2c/other')
-rw-r--r--sound/i2c/other/ak4xxx-adda.c128
1 files changed, 18 insertions, 110 deletions
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index c34cb4684607..5da49e2eb350 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -43,10 +43,7 @@ void snd_akm4xxx_write(struct snd_akm4xxx *ak, int chip, unsigned char reg,
43 ak->ops.write(ak, chip, reg, val); 43 ak->ops.write(ak, chip, reg, val);
44 44
45 /* save the data */ 45 /* save the data */
46 /* don't overwrite with IPGA data */ 46 snd_akm4xxx_set(ak, chip, reg, val);
47 if ((ak->type != SND_AK4524 && ak->type != SND_AK5365) ||
48 (reg != 0x04 && reg != 0x05) || (val & 0x80) == 0)
49 snd_akm4xxx_set(ak, chip, reg, val);
50 ak->ops.unlock(ak, chip); 47 ak->ops.unlock(ak, chip);
51} 48}
52 49
@@ -70,12 +67,6 @@ static void ak4524_reset(struct snd_akm4xxx *ak, int state)
70 for (reg = 0x04; reg < maxreg; reg++) 67 for (reg = 0x04; reg < maxreg; reg++)
71 snd_akm4xxx_write(ak, chip, reg, 68 snd_akm4xxx_write(ak, chip, reg,
72 snd_akm4xxx_get(ak, chip, reg)); 69 snd_akm4xxx_get(ak, chip, reg));
73 if (ak->type == SND_AK4528)
74 continue;
75 /* IPGA */
76 for (reg = 0x04; reg < 0x06; reg++)
77 snd_akm4xxx_write(ak, chip, reg,
78 snd_akm4xxx_get_ipga(ak, chip, reg) | 0x80);
79 } 70 }
80} 71}
81 72
@@ -175,7 +166,6 @@ static DECLARE_TLV_DB_SCALE(db_scale_vol_datt, -6350, 50, 1);
175static DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1); 166static DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1);
176static DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1); 167static DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1);
177static DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0); 168static DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0);
178static DECLARE_TLV_DB_SCALE(db_scale_ipga, 0, 50, 0);
179 169
180/* 170/*
181 * initialize all the ak4xxx chips 171 * initialize all the ak4xxx chips
@@ -190,8 +180,6 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
190 0x01, 0x03, /* 1: ADC/DAC enable */ 180 0x01, 0x03, /* 1: ADC/DAC enable */
191 0x04, 0x00, /* 4: ADC left muted */ 181 0x04, 0x00, /* 4: ADC left muted */
192 0x05, 0x00, /* 5: ADC right muted */ 182 0x05, 0x00, /* 5: ADC right muted */
193 0x04, 0x80, /* 4: ADC IPGA gain 0dB */
194 0x05, 0x80, /* 5: ADC IPGA gain 0dB */
195 0x06, 0x00, /* 6: DAC left muted */ 183 0x06, 0x00, /* 6: DAC left muted */
196 0x07, 0x00, /* 7: DAC right muted */ 184 0x07, 0x00, /* 7: DAC right muted */
197 0xff, 0xff 185 0xff, 0xff
@@ -324,13 +312,15 @@ EXPORT_SYMBOL(snd_akm4xxx_init);
324/* 312/*
325 * Mixer callbacks 313 * Mixer callbacks
326 */ 314 */
315#define AK_IPGA (1<<20) /* including IPGA */
327#define AK_VOL_CVT (1<<21) /* need dB conversion */ 316#define AK_VOL_CVT (1<<21) /* need dB conversion */
328#define AK_NEEDSMSB (1<<22) /* need MSB update bit */ 317#define AK_NEEDSMSB (1<<22) /* need MSB update bit */
329#define AK_INVERT (1<<23) /* data is inverted */ 318#define AK_INVERT (1<<23) /* data is inverted */
330#define AK_GET_CHIP(val) (((val) >> 8) & 0xff) 319#define AK_GET_CHIP(val) (((val) >> 8) & 0xff)
331#define AK_GET_ADDR(val) ((val) & 0xff) 320#define AK_GET_ADDR(val) ((val) & 0xff)
332#define AK_GET_SHIFT(val) (((val) >> 16) & 0x1f) 321#define AK_GET_SHIFT(val) (((val) >> 16) & 0x0f)
333#define AK_GET_VOL_CVT(val) (((val) >> 21) & 1) 322#define AK_GET_VOL_CVT(val) (((val) >> 21) & 1)
323#define AK_GET_IPGA(val) (((val) >> 20) & 1)
334#define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1) 324#define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1)
335#define AK_GET_INVERT(val) (((val) >> 23) & 1) 325#define AK_GET_INVERT(val) (((val) >> 23) & 1)
336#define AK_GET_MASK(val) (((val) >> 24) & 0xff) 326#define AK_GET_MASK(val) (((val) >> 24) & 0xff)
@@ -371,8 +361,10 @@ static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
371 return 0; 361 return 0;
372 362
373 snd_akm4xxx_set_vol(ak, chip, addr, nval); 363 snd_akm4xxx_set_vol(ak, chip, addr, nval);
374 if (AK_GET_VOL_CVT(kcontrol->private_value)) 364 if (AK_GET_VOL_CVT(kcontrol->private_value) && nval < 128)
375 nval = vol_cvt_datt[nval]; 365 nval = vol_cvt_datt[nval];
366 if (AK_GET_IPGA(kcontrol->private_value) && nval >= 128)
367 nval++; /* need to correct + 1 since both 127 and 128 are 0dB */
376 if (AK_GET_INVERT(kcontrol->private_value)) 368 if (AK_GET_INVERT(kcontrol->private_value))
377 nval = mask - nval; 369 nval = mask - nval;
378 if (AK_GET_NEEDSMSB(kcontrol->private_value)) 370 if (AK_GET_NEEDSMSB(kcontrol->private_value))
@@ -424,68 +416,6 @@ static int snd_akm4xxx_stereo_volume_put(struct snd_kcontrol *kcontrol,
424 return change; 416 return change;
425} 417}
426 418
427#define snd_akm4xxx_ipga_gain_info snd_akm4xxx_volume_info
428
429static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol,
430 struct snd_ctl_elem_value *ucontrol)
431{
432 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
433 int chip = AK_GET_CHIP(kcontrol->private_value);
434 int addr = AK_GET_ADDR(kcontrol->private_value);
435
436 ucontrol->value.integer.value[0] =
437 snd_akm4xxx_get_ipga(ak, chip, addr);
438 return 0;
439}
440
441static int put_ak_ipga(struct snd_kcontrol *kcontrol, int addr,
442 unsigned char nval)
443{
444 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
445 int chip = AK_GET_CHIP(kcontrol->private_value);
446
447 if (snd_akm4xxx_get_ipga(ak, chip, addr) == nval)
448 return 0;
449 snd_akm4xxx_set_ipga(ak, chip, addr, nval);
450 snd_akm4xxx_write(ak, chip, addr, nval | 0x80); /* need MSB */
451 return 1;
452}
453
454static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol,
455 struct snd_ctl_elem_value *ucontrol)
456{
457 return put_ak_ipga(kcontrol, AK_GET_ADDR(kcontrol->private_value),
458 ucontrol->value.integer.value[0]);
459}
460
461#define snd_akm4xxx_stereo_gain_info snd_akm4xxx_stereo_volume_info
462
463static int snd_akm4xxx_stereo_gain_get(struct snd_kcontrol *kcontrol,
464 struct snd_ctl_elem_value *ucontrol)
465{
466 struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol);
467 int chip = AK_GET_CHIP(kcontrol->private_value);
468 int addr = AK_GET_ADDR(kcontrol->private_value);
469
470 ucontrol->value.integer.value[0] =
471 snd_akm4xxx_get_ipga(ak, chip, addr);
472 ucontrol->value.integer.value[1] =
473 snd_akm4xxx_get_ipga(ak, chip, addr + 1);
474 return 0;
475}
476
477static int snd_akm4xxx_stereo_gain_put(struct snd_kcontrol *kcontrol,
478 struct snd_ctl_elem_value *ucontrol)
479{
480 int addr = AK_GET_ADDR(kcontrol->private_value);
481 int change;
482
483 change = put_ak_ipga(kcontrol, addr, ucontrol->value.integer.value[0]);
484 change |= put_ak_ipga(kcontrol, addr + 1,
485 ucontrol->value.integer.value[1]);
486 return change;
487}
488
489static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol, 419static int snd_akm4xxx_deemphasis_info(struct snd_kcontrol *kcontrol,
490 struct snd_ctl_elem_info *uinfo) 420 struct snd_ctl_elem_info *uinfo)
491{ 421{
@@ -702,35 +632,15 @@ static int build_adc_controls(struct snd_akm4xxx *ak)
702 knew.put = snd_akm4xxx_volume_put; 632 knew.put = snd_akm4xxx_volume_put;
703 } 633 }
704 /* register 4 & 5 */ 634 /* register 4 & 5 */
705 knew.private_value = 635 if (ak->type == SND_AK5365)
706 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) | 636 knew.private_value =
707 AK_VOL_CVT; 637 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 151) |
708 knew.tlv.p = db_scale_vol_datt; 638 AK_VOL_CVT | AK_IPGA;
709 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
710 if (err < 0)
711 return err;
712
713 if (! ak->adc_info || ! ak->adc_info[mixer_ch].gain_name)
714 knew.name = "IPGA Analog Capture Volume";
715 else 639 else
716 knew.name = ak->adc_info[mixer_ch].gain_name; 640 knew.private_value =
717 if (num_stereo == 2) { 641 AK_COMPOSE(idx/2, (idx%2) + 4, 0, 163) |
718 knew.info = snd_akm4xxx_stereo_gain_info; 642 AK_VOL_CVT | AK_IPGA;
719 knew.get = snd_akm4xxx_stereo_gain_get; 643 knew.tlv.p = db_scale_vol_datt;
720 knew.put = snd_akm4xxx_stereo_gain_put;
721 } else {
722 knew.info = snd_akm4xxx_ipga_gain_info;
723 knew.get = snd_akm4xxx_ipga_gain_get;
724 knew.put = snd_akm4xxx_ipga_gain_put;
725 }
726 /* register 4 & 5 */
727 if (ak->type == SND_AK4524)
728 knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0,
729 24);
730 else /* AK5365 */
731 knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0,
732 36);
733 knew.tlv.p = db_scale_ipga;
734 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); 644 err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak));
735 if (err < 0) 645 if (err < 0)
736 return err; 646 return err;
@@ -811,11 +721,9 @@ int snd_akm4xxx_build_controls(struct snd_akm4xxx *ak)
811 if (err < 0) 721 if (err < 0)
812 return err; 722 return err;
813 723
814 if (ak->type == SND_AK4524 || ak->type == SND_AK5365) { 724 err = build_adc_controls(ak);
815 err = build_adc_controls(ak); 725 if (err < 0)
816 if (err < 0) 726 return err;
817 return err;
818 }
819 727
820 if (ak->type == SND_AK4355 || ak->type == SND_AK4358) 728 if (ak->type == SND_AK4355 || ak->type == SND_AK4358)
821 num_emphs = 1; 729 num_emphs = 1;