From: Takashi Iwai Subject: Re: [RFC] Add dB scale information to AK4xxx codec Date: Thu, 07 Sep 2006 16:52:58 +0200 Message-ID: References: <20060904111303.GA24842@localhost.localdomain> <20060904174121.GA4736@quiche.seehuhn.de> <20060904192738.GA16291@tarte.seehuhn.de> <20060905192453.GA2537@tarte.seehuhn.de> <20060907102954.GA17846@localhost.localdomain> <20060907110027.GA3030@tarte.seehuhn.de> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: multipart/mixed; boundary="Multipart_Thu_Sep__7_16:52:58_2006-1" Return-path: In-Reply-To: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: alsa-devel-bounces@lists.sourceforge.net Errors-To: alsa-devel-bounces@lists.sourceforge.net To: Jochen Voss Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org --Multipart_Thu_Sep__7_16:52:58_2006-1 Content-Type: text/plain; charset=US-ASCII At Thu, 07 Sep 2006 14:49:24 +0200, I wrote: > > At Thu, 7 Sep 2006 12:00:30 +0100, > Jochen Voss wrote: > > > > Hello Takashi, > > > > On Thu, Sep 07, 2006 at 12:33:18PM +0200, Takashi Iwai wrote: > > > Yes. Then we need to take the controls back to a single one. > > > Will do later. > > Ok. > > > > > I still wonder whether this is also true for AK4524... > > No idea about this, I do not have an AK4524 so I cannot test. > > > > > > > Also, it's possible that I did make a silly mistake. Put a debug > > > > > printk around ak->ops.write() in snd_akm4xxx_write() to check what > > > > > values are written to register 4 and 5. > > > > > > > > I will try this in the evening. > > > > This sounded more fun than the simulation I am supposed to do for work, > > so I sneaked away and did this first ;-) > > > > I used the following printk: > > > > ====================================================================== > > --- ak4xxx-adda.c~ 2006-08-31 01:00:11.000000000 +0100 > > +++ ak4xxx-adda.c 2006-09-07 11:49:57.394999424 +0100 > > @@ -40,6 +40,9 @@ > > unsigned char val) > > { > > ak->ops.lock(ak, chip); > > + if (ak->type == SND_AK5365 && (reg==4 || reg==5)) { > > + printk (KERN_INFO "reg%d <- %02x\n", reg, val); > > + } > > ak->ops.write(ak, chip, reg, val); > > > > /* save the data */ > > ====================================================================== > > > > Results from my second test (s2.sh vs s3.sh): > > > > s2.sh: The commands > > > > amixer set "PCM Capture Gain" 0 > > amixer set "PCM Capture Gain" 20 > > amixer set "PCM" 0 > > amixer set "PCM" 80% > > > > translate into > > > > reg4 <- 80 > > reg5 <- 80 > > reg4 <- 94 > > reg5 <- 94 > > reg4 <- 00 > > reg5 <- 00 > > reg4 <- 5e > > reg5 <- 5e > > > > s3.sh: The commands > > > > amixer set "PCM" 0 > > amixer set "PCM" 80% > > amixer set "PCM Capture Gain" 0 > > amixer set "PCM Capture Gain" 20 > > > > translate into > > > > reg4 <- 00 > > reg5 <- 00 > > reg4 <- 5e > > reg5 <- 5e > > reg4 <- 80 > > reg5 <- 80 > > reg4 <- 94 > > reg5 <- 94 > > > > This seems to be the expected register assignments. As stated before, > > these settings lead to different recording volume. > > OK, thanks for confirmation. > > The untested patch for removing IPGA is below. Please give it a > shot. > > I'll check a board with AK4524 (well I have to dig the boxes) whether > it shows shows the same behavior like AK5365. I confirmed that the same behavior appears on AK4524. So, it makes much more sense to combine ADC and IPGA controls to a single control. The patch below is the final version I have on my local tree. Please check whether it works for you. FYI, the second patch is for envy24control to make it work correctly after changing ADC ranges. Takashi --Multipart_Thu_Sep__7_16:52:58_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="ak4xxx-adda-ipga-fix.diff" Content-Transfer-Encoding: 7bit diff -r 4f27a5064cda i2c/other/ak4xxx-adda.c --- a/i2c/other/ak4xxx-adda.c Thu Sep 07 12:40:00 2006 +0200 +++ b/i2c/other/ak4xxx-adda.c Thu Sep 07 16:50:00 2006 +0200 @@ -43,10 +43,7 @@ void snd_akm4xxx_write(struct snd_akm4xx ak->ops.write(ak, chip, reg, val); /* save the data */ - /* don't overwrite with IPGA data */ - if ((ak->type != SND_AK4524 && ak->type != SND_AK5365) || - (reg != 0x04 && reg != 0x05) || (val & 0x80) == 0) - snd_akm4xxx_set(ak, chip, reg, val); + snd_akm4xxx_set(ak, chip, reg, val); ak->ops.unlock(ak, chip); } @@ -70,12 +67,6 @@ static void ak4524_reset(struct snd_akm4 for (reg = 0x04; reg < maxreg; reg++) snd_akm4xxx_write(ak, chip, reg, snd_akm4xxx_get(ak, chip, reg)); - if (ak->type == SND_AK4528) - continue; - /* IPGA */ - for (reg = 0x04; reg < 0x06; reg++) - snd_akm4xxx_write(ak, chip, reg, - snd_akm4xxx_get_ipga(ak, chip, reg) | 0x80); } } @@ -175,7 +166,6 @@ static DECLARE_TLV_DB_SCALE(db_scale_8bi static DECLARE_TLV_DB_SCALE(db_scale_8bit, -12750, 50, 1); static DECLARE_TLV_DB_SCALE(db_scale_7bit, -6350, 50, 1); static DECLARE_TLV_DB_LINEAR(db_scale_linear, TLV_DB_GAIN_MUTE, 0); -static DECLARE_TLV_DB_SCALE(db_scale_ipga, 0, 50, 0); /* * initialize all the ak4xxx chips @@ -190,8 +180,6 @@ void snd_akm4xxx_init(struct snd_akm4xxx 0x01, 0x03, /* 1: ADC/DAC enable */ 0x04, 0x00, /* 4: ADC left muted */ 0x05, 0x00, /* 5: ADC right muted */ - 0x04, 0x80, /* 4: ADC IPGA gain 0dB */ - 0x05, 0x80, /* 5: ADC IPGA gain 0dB */ 0x06, 0x00, /* 6: DAC left muted */ 0x07, 0x00, /* 7: DAC right muted */ 0xff, 0xff @@ -324,13 +312,15 @@ EXPORT_SYMBOL(snd_akm4xxx_init); /* * Mixer callbacks */ +#define AK_IPGA (1<<20) /* including IPGA */ #define AK_VOL_CVT (1<<21) /* need dB conversion */ #define AK_NEEDSMSB (1<<22) /* need MSB update bit */ #define AK_INVERT (1<<23) /* data is inverted */ #define AK_GET_CHIP(val) (((val) >> 8) & 0xff) #define AK_GET_ADDR(val) ((val) & 0xff) -#define AK_GET_SHIFT(val) (((val) >> 16) & 0x1f) +#define AK_GET_SHIFT(val) (((val) >> 16) & 0x0f) #define AK_GET_VOL_CVT(val) (((val) >> 21) & 1) +#define AK_GET_IPGA(val) (((val) >> 20) & 1) #define AK_GET_NEEDSMSB(val) (((val) >> 22) & 1) #define AK_GET_INVERT(val) (((val) >> 23) & 1) #define AK_GET_MASK(val) (((val) >> 24) & 0xff) @@ -371,8 +361,10 @@ static int put_ak_reg(struct snd_kcontro return 0; snd_akm4xxx_set_vol(ak, chip, addr, nval); - if (AK_GET_VOL_CVT(kcontrol->private_value)) + if (AK_GET_VOL_CVT(kcontrol->private_value) && nval < 128) nval = vol_cvt_datt[nval]; + if (AK_GET_IPGA(kcontrol->private_value) && nval >= 128) + nval++; /* need to correct + 1 since both 127 and 128 are 0dB */ if (AK_GET_INVERT(kcontrol->private_value)) nval = mask - nval; if (AK_GET_NEEDSMSB(kcontrol->private_value)) @@ -421,68 +413,6 @@ static int snd_akm4xxx_stereo_volume_put change = put_ak_reg(kcontrol, addr, ucontrol->value.integer.value[0]); change |= put_ak_reg(kcontrol, addr + 1, ucontrol->value.integer.value[1]); - return change; -} - -#define snd_akm4xxx_ipga_gain_info snd_akm4xxx_volume_info - -static int snd_akm4xxx_ipga_gain_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); - int chip = AK_GET_CHIP(kcontrol->private_value); - int addr = AK_GET_ADDR(kcontrol->private_value); - - ucontrol->value.integer.value[0] = - snd_akm4xxx_get_ipga(ak, chip, addr); - return 0; -} - -static int put_ak_ipga(struct snd_kcontrol *kcontrol, int addr, - unsigned char nval) -{ - struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); - int chip = AK_GET_CHIP(kcontrol->private_value); - - if (snd_akm4xxx_get_ipga(ak, chip, addr) == nval) - return 0; - snd_akm4xxx_set_ipga(ak, chip, addr, nval); - snd_akm4xxx_write(ak, chip, addr, nval | 0x80); /* need MSB */ - return 1; -} - -static int snd_akm4xxx_ipga_gain_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - return put_ak_ipga(kcontrol, AK_GET_ADDR(kcontrol->private_value), - ucontrol->value.integer.value[0]); -} - -#define snd_akm4xxx_stereo_gain_info snd_akm4xxx_stereo_volume_info - -static int snd_akm4xxx_stereo_gain_get(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - struct snd_akm4xxx *ak = snd_kcontrol_chip(kcontrol); - int chip = AK_GET_CHIP(kcontrol->private_value); - int addr = AK_GET_ADDR(kcontrol->private_value); - - ucontrol->value.integer.value[0] = - snd_akm4xxx_get_ipga(ak, chip, addr); - ucontrol->value.integer.value[1] = - snd_akm4xxx_get_ipga(ak, chip, addr + 1); - return 0; -} - -static int snd_akm4xxx_stereo_gain_put(struct snd_kcontrol *kcontrol, - struct snd_ctl_elem_value *ucontrol) -{ - int addr = AK_GET_ADDR(kcontrol->private_value); - int change; - - change = put_ak_ipga(kcontrol, addr, ucontrol->value.integer.value[0]); - change |= put_ak_ipga(kcontrol, addr + 1, - ucontrol->value.integer.value[1]); return change; } @@ -702,35 +632,15 @@ static int build_adc_controls(struct snd knew.put = snd_akm4xxx_volume_put; } /* register 4 & 5 */ - knew.private_value = - AK_COMPOSE(idx/2, (idx%2) + 4, 0, 127) | - AK_VOL_CVT; + if (ak->type == SND_AK5365) + knew.private_value = + AK_COMPOSE(idx/2, (idx%2) + 4, 0, 151) | + AK_VOL_CVT | AK_IPGA; + else + knew.private_value = + AK_COMPOSE(idx/2, (idx%2) + 4, 0, 163) | + AK_VOL_CVT | AK_IPGA; knew.tlv.p = db_scale_vol_datt; - err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); - if (err < 0) - return err; - - if (! ak->adc_info || ! ak->adc_info[mixer_ch].gain_name) - knew.name = "IPGA Analog Capture Volume"; - else - knew.name = ak->adc_info[mixer_ch].gain_name; - if (num_stereo == 2) { - knew.info = snd_akm4xxx_stereo_gain_info; - knew.get = snd_akm4xxx_stereo_gain_get; - knew.put = snd_akm4xxx_stereo_gain_put; - } else { - knew.info = snd_akm4xxx_ipga_gain_info; - knew.get = snd_akm4xxx_ipga_gain_get; - knew.put = snd_akm4xxx_ipga_gain_put; - } - /* register 4 & 5 */ - if (ak->type == SND_AK4524) - knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, - 24); - else /* AK5365 */ - knew.private_value = AK_COMPOSE(idx/2, (idx%2) + 4, 0, - 36); - knew.tlv.p = db_scale_ipga; err = snd_ctl_add(ak->card, snd_ctl_new1(&knew, ak)); if (err < 0) return err; @@ -811,11 +721,9 @@ int snd_akm4xxx_build_controls(struct sn if (err < 0) return err; - if (ak->type == SND_AK4524 || ak->type == SND_AK5365) { - err = build_adc_controls(ak); - if (err < 0) - return err; - } + err = build_adc_controls(ak); + if (err < 0) + return err; if (ak->type == SND_AK4355 || ak->type == SND_AK4358) num_emphs = 1; diff -r 4f27a5064cda include/ak4xxx-adda.h --- a/include/ak4xxx-adda.h Thu Sep 07 12:40:00 2006 +0200 +++ b/include/ak4xxx-adda.h Thu Sep 07 16:47:07 2006 +0200 @@ -48,7 +48,6 @@ struct snd_akm4xxx_dac_channel { /* ADC labels and channels */ struct snd_akm4xxx_adc_channel { char *name; /* capture gain volume label */ - char *gain_name; /* IPGA */ char *switch_name; /* capture switch */ unsigned int num_channels; }; @@ -91,13 +90,4 @@ int snd_akm4xxx_build_controls(struct sn #define snd_akm4xxx_set_vol(ak,chip,reg,val) \ ((ak)->volumes[(chip) * 16 + (reg)] = (val)) -/* Warning: IPGA is tricky - we assume the addr + 4 is unused - * so far, it's OK for all AK codecs with IPGA: - * AK4524, AK4528 and EK5365 - */ -#define snd_akm4xxx_get_ipga(ak,chip,reg) \ - snd_akm4xxx_get_vol(ak, chip, (reg) + 4) -#define snd_akm4xxx_set_ipga(ak,chip,reg,val) \ - snd_akm4xxx_set_vol(ak, chip, (reg) + 4, val) - #endif /* __SOUND_AK4XXX_ADDA_H */ diff -r 4f27a5064cda pci/ice1712/revo.c --- a/pci/ice1712/revo.c Thu Sep 07 12:40:00 2006 +0200 +++ b/pci/ice1712/revo.c Thu Sep 07 16:47:37 2006 +0200 @@ -110,7 +110,6 @@ static struct snd_akm4xxx_adc_channel re static struct snd_akm4xxx_adc_channel revo51_adc[] = { { .name = "PCM Capture Volume", - .gain_name = "PCM Capture Gain Volume", .switch_name = "PCM Capture Switch", .num_channels = 2 }, --Multipart_Thu_Sep__7_16:52:58_2006-1 Content-Type: application/octet-stream; type=patch Content-Disposition: attachment; filename="envy24-ipga-fix.diff" Content-Transfer-Encoding: 7bit diff -r 1b93db14895f envy24control/envy24control.c --- a/envy24control/envy24control.c Fri Aug 04 14:28:19 2006 +0200 +++ b/envy24control/envy24control.c Thu Sep 07 16:40:10 2006 +0200 @@ -1570,7 +1570,7 @@ static void create_analog_volume(GtkWidg gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, TRUE, 6); } - adj = gtk_adjustment_new(0, -127, 0, 1, 16, 0); + adj = gtk_adjustment_new(0, -(envy_adc_max()), 0, 1, 16, 0); av_adc_volume_adj[i] = adj; vscale = gtk_vscale_new(GTK_ADJUSTMENT(adj)); gtk_scale_set_draw_value(GTK_SCALE(vscale), FALSE); diff -r 1b93db14895f envy24control/envy24control.h --- a/envy24control/envy24control.h Fri Aug 04 14:28:19 2006 +0200 +++ b/envy24control/envy24control.h Thu Sep 07 16:40:20 2006 +0200 @@ -217,6 +217,7 @@ int envy_dac_volumes(void); int envy_dac_volumes(void); int envy_dac_max(void); int envy_adc_volumes(void); +int envy_adc_max(void); int envy_ipga_volumes(void); int envy_dac_senses(void); int envy_adc_senses(void); diff -r 1b93db14895f envy24control/volume.c --- a/envy24control/volume.c Fri Aug 04 14:28:19 2006 +0200 +++ b/envy24control/volume.c Thu Sep 07 16:44:41 2006 +0200 @@ -33,6 +33,7 @@ static int dac_volumes; static int dac_max = 127; +static int adc_max = 127; static int adc_volumes; static int ipga_volumes; static int dac_senses; @@ -58,6 +59,11 @@ int envy_adc_volumes(void) return adc_volumes; } +int envy_adc_max(void) +{ + return adc_max; +} + int envy_ipga_volumes(void) { return ipga_volumes; @@ -138,8 +144,9 @@ void adc_volume_update(int idx) g_print("Unable to read ipga volume: %s\n", snd_strerror(err)); return; } - gtk_adjustment_set_value(GTK_ADJUSTMENT(av_ipga_volume_adj[idx]), - -0); + if (ipga_volumes > 0) + gtk_adjustment_set_value(GTK_ADJUSTMENT(av_ipga_volume_adj[idx]), + -0); } void ipga_volume_update(int idx) @@ -165,7 +172,7 @@ void ipga_volume_update(int idx) // set ADC volume to max if IPGA volume greater 0 if (ipga_vol) gtk_adjustment_set_value(GTK_ADJUSTMENT(av_adc_volume_adj[idx]), - -127); + -adc_max); } void dac_sense_update(int idx) @@ -342,6 +349,7 @@ void analog_volume_init(void) snd_ctl_elem_info_set_index(info, i); if (snd_ctl_elem_info(ctl, info) < 0) break; + adc_max = snd_ctl_elem_info_get_max(info); } if (i < input_channels - 1) adc_volumes = i; --Multipart_Thu_Sep__7_16:52:58_2006-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline ------------------------------------------------------------------------- Using Tomcat but need to do more? Need to support web services, security? Get stuff done quickly with pre-integrated technology to make your job easier Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642 --Multipart_Thu_Sep__7_16:52:58_2006-1 Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Alsa-devel mailing list Alsa-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/alsa-devel --Multipart_Thu_Sep__7_16:52:58_2006-1--