From: Takashi Iwai Subject: Re: debugging nm256: some results, many questions Date: Wed, 15 Mar 2006 10:55:36 +0100 Message-ID: References: <20060223185253.GA7954@tigerbay> <20060311174421.GB7775@tigerbay> <20060313064627.GA3864@tigerbay> <20060313145534.GA7995@tigerbay> <20060314195946.GA3633@tigerbay> <20060315060922.GA30060@tigerbay> Mime-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Return-path: In-Reply-To: <20060315060922.GA30060@tigerbay> Sender: alsa-devel-admin@lists.sourceforge.net Errors-To: alsa-devel-admin@lists.sourceforge.net List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , List-Archive: To: Florian Schlichting Cc: alsa-devel@lists.sourceforge.net List-Id: alsa-devel@alsa-project.org At Wed, 15 Mar 2006 14:09:22 +0800, Florian Schlichting wrote: > > On Tue, Mar 14, 2006 at 09:16:28PM +0100, Takashi Iwai wrote: > > At Wed, 15 Mar 2006 03:59:46 +0800, > > Florian Schlichting wrote: > > > Also, there are some warnings during compile and a problem with depmod > > > loops at install > > > ---------- > > > Building modules, stage 2. > > > MODPOST > > > *** Warning: "snd_minor_info_oss_init" [/usr/src/cvs/alsa/alsa-driver/acore/snd.ko] undefined! > > > *** Warning: "snd_lookup_oss_minor_data" [/usr/src/cvs/alsa/alsa-driver/acore/snd.ko] undefined! > > > *** Warning: "snd_info_minor_unregister" [/usr/src/cvs/alsa/alsa-driver/acore/snd.ko] undefined! > > > *** Warning: "snd_minor_info_oss_done" [/usr/src/cvs/alsa/alsa-driver/acore/snd.ko] undefined! > > > *** Warning: "snd_info_minor_register" [/usr/src/cvs/alsa/alsa-driver/acore/snd.ko] undefined! > > > > > > [...] > > > > > > WARNING: Loop detected: > > > /lib/modules/2.6.15-max/kernel/sound/acore/snd.ko which needs snd.ko > > > again! > > > ---------- > > > (and the rest of the ALSA modules is ignored), so although I could > > > build things, it wouldn't "make install" and I can't make a final smoke > > > test :-( > > > > Hm, it sounds like CONFIG_PROC_FS isn't defined properly. > > Please check alsa-driver/include/linux/autoconf.h. It's generated by > > configure script. > > hmmm... do you mean this: > > #define CONFIG_ACPI_SLEEP_PROC_FS 1 > #undef CONFIG_ACPI_SLEEP_PROC_SLEEP > [...] > #undef CONFIG_PCI_LEGACY_PROC > [...] > #define CONFIG_SCSI_PROC_FS 1 > [...] > #define CONFIG_PROC_FS 1 > #define CONFIG_PROC_KCORE 1 > [...] > #define CONFIG_SND_VERBOSE_PROCFS 1 > > -.- > > I noticed the errors said something with oss. My compile commmand line > was './cvscompile --with-isapnp=no --with-sequencer=no --with-oss=no > --with-cards=nm256' and that still gives the above errors. I just > recompiled with just './cvscompile --with-cards=nm256' and there are no > errors, depmod runs fine, I can insert the module... perfect! Then something conflicts. Could you check CONFIG_SND_OSSEMUL in autoconfig.h? > The mixer > settings also survive a suspend, apart from Master Volume which becomes > muted (but I guess that's intented? I can't confirm bug#1532) Hm, no, it's not intended. I think this is the side effect of using ac97->regs[]. The ac97 codec routine mutes the master volume to avoid noise at suspend, and resumes it with the cache value. Please try the newer patch below. > Thus, are we done fixing an issue that has bugged poor nm256 owners for > years?? bug#328, bug#914 and kbug#3719 look like their > submitters/contributors might be interested in giving it a try... > > Summary: treat the nm256 mixer as a write-only device so as to avoid > hangs on initialisation (fixes: bug#....[when confirmed]) and clean up > an older workaround in ac97_codec > Signed-off-by: Florian Schlichting Thanks, I'll apply the patch once after you confirm the newer one. Takashi Index: alsa-kernel/include/ac97_codec.h =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/include/ac97_codec.h,v retrieving revision 1.75 diff -u -r1.75 ac97_codec.h --- alsa-kernel/include/ac97_codec.h 9 Feb 2006 11:43:01 -0000 1.75 +++ alsa-kernel/include/ac97_codec.h 15 Mar 2006 09:54:37 -0000 @@ -433,6 +433,12 @@ struct snd_info_entry *proc; }; +/* static resolution table */ +struct snd_ac97_res_table { + unsigned short reg; /* register */ + unsigned short bits; /* resolution bitmask */ +}; + struct snd_ac97_template { void *private_data; void (*private_free) (struct snd_ac97 *ac97); @@ -440,14 +446,7 @@ unsigned short num; /* number of codec: 0 = primary, 1 = secondary */ unsigned short addr; /* physical address of codec [0-3] */ unsigned int scaps; /* driver capabilities */ - unsigned int limited_regs; /* allow limited registers only */ - DECLARE_BITMAP(reg_accessed, 0x80); /* bit flags */ -}; - -/* static resolution table */ -struct snd_ac97_res_table { - unsigned short reg; /* register */ - unsigned short bits; /* resolution bitmask */ + const struct snd_ac97_res_table *res_table; /* static resolution */ }; struct snd_ac97 { @@ -476,7 +475,6 @@ unsigned int rates[6]; /* see AC97_RATES_* defines */ unsigned int spdif_status; unsigned short regs[0x80]; /* register cache */ - unsigned int limited_regs; /* allow limited registers only */ DECLARE_BITMAP(reg_accessed, 0x80); /* bit flags */ union { /* vendor specific code */ struct { Index: alsa-kernel/pci/ac97/ac97_codec.c =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/ac97/ac97_codec.c,v retrieving revision 1.202 diff -u -r1.202 ac97_codec.c --- alsa-kernel/pci/ac97/ac97_codec.c 9 Feb 2006 11:46:47 -0000 1.202 +++ alsa-kernel/pci/ac97/ac97_codec.c 15 Mar 2006 09:54:37 -0000 @@ -192,9 +192,6 @@ static int snd_ac97_valid_reg(struct snd_ac97 *ac97, unsigned short reg) { - if (ac97->limited_regs && ! test_bit(reg, ac97->reg_accessed)) - return 0; - /* filter some registers for buggy codecs */ switch (ac97->id) { case AC97_ID_AK4540: @@ -1008,9 +1005,6 @@ break; } - if (ac97->limited_regs && test_bit(reg, ac97->reg_accessed)) - return 1; /* allow without check */ - val = snd_ac97_read(ac97, reg); if (!(val & mask)) { /* nothing seems to be here - mute flag is not set */ @@ -1866,8 +1860,7 @@ ac97->num = template->num; ac97->addr = template->addr; ac97->scaps = template->scaps; - ac97->limited_regs = template->limited_regs; - memcpy(ac97->reg_accessed, template->reg_accessed, sizeof(ac97->reg_accessed)); + ac97->res_table = template->res_table; bus->codec[ac97->num] = ac97; mutex_init(&ac97->reg_mutex); mutex_init(&ac97->page_mutex); Index: alsa-kernel/pci/nm256/nm256.c =================================================================== RCS file: /home/iwai/cvs/alsa/alsa-kernel/pci/nm256/nm256.c,v retrieving revision 1.81 diff -u -r1.81 nm256.c --- alsa-kernel/pci/nm256/nm256.c 16 Jan 2006 16:40:06 -0000 1.81 +++ alsa-kernel/pci/nm256/nm256.c 15 Mar 2006 09:54:37 -0000 @@ -228,6 +228,7 @@ unsigned int use_cache: 1; /* use one big coef. table */ unsigned int reset_workaround: 1; /* Workaround for some laptops to avoid freeze */ unsigned int reset_workaround_2: 1; /* Extended workaround for some other laptops to avoid freeze */ + unsigned int in_resume: 1; int mixer_base; /* register offset of ac97 mixer */ int mixer_status_offset; /* offset of mixer status reg. */ @@ -242,6 +243,7 @@ struct nm256_stream streams[2]; struct snd_ac97 *ac97; + unsigned short *ac97_regs; /* register caches, only for valid regs */ struct snd_pcm *pcm; @@ -1153,23 +1155,63 @@ return 0; } +/* + * Initial register values to be written to the AC97 mixer. + * While most of these are identical to the reset values, we do this + * so that we have most of the register contents cached--this avoids + * reading from the mixer directly (which seems to be problematic, + * probably due to ignorance). + */ + +struct initialValues { + unsigned short reg; + unsigned short value; +}; + +static struct initialValues nm256_ac97_init_val[] = +{ + { AC97_MASTER, 0x8000 }, + { AC97_HEADPHONE, 0x8000 }, + { AC97_MASTER_MONO, 0x8000 }, + { AC97_PC_BEEP, 0x8000 }, + { AC97_PHONE, 0x8008 }, + { AC97_MIC, 0x8000 }, + { AC97_LINE, 0x8808 }, + { AC97_CD, 0x8808 }, + { AC97_VIDEO, 0x8808 }, + { AC97_AUX, 0x8808 }, + { AC97_PCM, 0x8808 }, + { AC97_REC_SEL, 0x0000 }, + { AC97_REC_GAIN, 0x0B0B }, + { AC97_GENERAL_PURPOSE, 0x0000 }, + { AC97_3D_CONTROL, 0x8000 }, + { AC97_VENDOR_ID1, 0x8384 }, + { AC97_VENDOR_ID2, 0x7609 }, +}; + +static int nm256_ac97_idx(unsigned short reg) +{ + int i; + for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) + if (nm256_ac97_init_val[i].reg == reg) + return i; + return -1; +} + /* + * some nm256 easily crash when reading from mixer registers + * thus we're treating it as a write-only mixer and cache the + * written values */ static unsigned short snd_nm256_ac97_read(struct snd_ac97 *ac97, unsigned short reg) { struct nm256 *chip = ac97->private_data; - int res; - - if (reg >= 128) - return 0; + int idx = nm256_ac97_idx(reg); - if (! snd_nm256_ac97_ready(chip)) + if (idx < 0) return 0; - res = snd_nm256_readw(chip, chip->mixer_base + reg); - /* Magic delay. Bleah yucky. */ - msleep(1); - return res; + return chip->ac97_regs[idx]; } /* @@ -1180,8 +1222,12 @@ { struct nm256 *chip = ac97->private_data; int tries = 2; + int idx = nm256_ac97_idx(reg); u32 base; + if (idx < 0) + return; + base = chip->mixer_base; snd_nm256_ac97_ready(chip); @@ -1190,12 +1236,32 @@ while (tries-- > 0) { snd_nm256_writew(chip, base + reg, val); msleep(1); /* a little delay here seems better.. */ - if (snd_nm256_ac97_ready(chip)) + if (snd_nm256_ac97_ready(chip)) { + /* successful write: set cache */ + chip->ac97_regs[idx] = val; return; + } } snd_printd("nm256: ac97 codec not ready..\n"); } +/* static resolution table */ +static struct snd_ac97_res_table nm256_res_table[] = { + { AC97_MASTER, 0x1f1f }, + { AC97_HEADPHONE, 0x1f1f }, + { AC97_MASTER_MONO, 0x001f }, + { AC97_PC_BEEP, 0x001f }, + { AC97_PHONE, 0x001f }, + { AC97_MIC, 0x001f }, + { AC97_LINE, 0x1f1f }, + { AC97_CD, 0x1f1f }, + { AC97_VIDEO, 0x1f1f }, + { AC97_AUX, 0x1f1f }, + { AC97_PCM, 0x1f1f }, + { AC97_REC_GAIN, 0x0f0f }, + { } /* terminator */ +}; + /* initialize the ac97 into a known state */ static void snd_nm256_ac97_reset(struct snd_ac97 *ac97) @@ -1213,6 +1279,16 @@ snd_nm256_writeb(chip, 0x6cc, 0x80); snd_nm256_writeb(chip, 0x6cc, 0x0); } + if (! chip->in_resume) { + int i; + for (i = 0; i < ARRAY_SIZE(nm256_ac97_init_val); i++) { + /* preload the cache, so as to avoid even a single + * read of the mixer regs + */ + snd_nm256_ac97_write(ac97, nm256_ac97_init_val[i].reg, + nm256_ac97_init_val[i].value); + } + } } /* create an ac97 mixer interface */ @@ -1221,32 +1297,25 @@ { struct snd_ac97_bus *pbus; struct snd_ac97_template ac97; - int i, err; + int err; static struct snd_ac97_bus_ops ops = { .reset = snd_nm256_ac97_reset, .write = snd_nm256_ac97_write, .read = snd_nm256_ac97_read, }; - /* looks like nm256 hangs up when unexpected registers are touched... */ - static int mixer_regs[] = { - AC97_MASTER, AC97_HEADPHONE, AC97_MASTER_MONO, - AC97_PC_BEEP, AC97_PHONE, AC97_MIC, AC97_LINE, AC97_CD, - AC97_VIDEO, AC97_AUX, AC97_PCM, AC97_REC_SEL, - AC97_REC_GAIN, AC97_GENERAL_PURPOSE, AC97_3D_CONTROL, - /*AC97_EXTENDED_ID,*/ - AC97_VENDOR_ID1, AC97_VENDOR_ID2, - -1 - }; + + chip->ac97_regs = kcalloc(sizeof(short), + ARRAY_SIZE(nm256_ac97_init_val), GFP_KERNEL); + if (! chip->ac97_regs) + return -ENOMEM; if ((err = snd_ac97_bus(chip->card, 0, &ops, NULL, &pbus)) < 0) return err; memset(&ac97, 0, sizeof(ac97)); ac97.scaps = AC97_SCAP_AUDIO; /* we support audio! */ - ac97.limited_regs = 1; - for (i = 0; mixer_regs[i] >= 0; i++) - set_bit(mixer_regs[i], ac97.reg_accessed); ac97.private_data = chip; + ac97.res_table = nm256_res_table; pbus->no_vra = 1; err = snd_ac97_mixer(pbus, &ac97, &chip->ac97); if (err < 0) @@ -1331,6 +1400,7 @@ int i; /* Perform a full reset on the hardware */ + chip->in_resume = 1; pci_restore_state(pci); pci_enable_device(pci); snd_nm256_init_chip(chip); @@ -1348,6 +1418,7 @@ } snd_power_change_state(card, SNDRV_CTL_POWER_D0); + chip->in_resume = 0; return 0; } #endif /* CONFIG_PM */ @@ -1372,6 +1443,7 @@ free_irq(chip->irq, chip); pci_disable_device(chip->pci); + kfree(chip->ac97_regs); kfree(chip); return 0; } ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642