From: Rene Herman <rene.herman@keyaccess.nl>
To: Takashi Iwai <tiwai@suse.de>
Cc: ALSA devel <alsa-devel@alsa-project.org>,
Krzysztof Helt <krzysztof.h1@poczta.fm>
Subject: [PATCH] ALSA: wss_lib: rework snd_ad1848_probe()
Date: Wed, 06 Aug 2008 08:42:08 +0200 [thread overview]
Message-ID: <489947C0.30104@keyaccess.nl> (raw)
[-- Attachment #1: Type: text/plain, Size: 574 bytes --]
Hi Takashi.
This reworks snd_ad1848_probe(), making for IMO significantly more
straightforward reading.
The original had a somewhat odd try-loop where it not only waited for
the codec to come out of init but also retried a failed basic detect
which seems to not make sense. Except for that, the detection logic
should be unchanged.
I am by the way rather unsure what it is that the spin_lock is trying to
protect us from here. What's the error scenario if we just not take it?
We aren't live yet...
Next step is folding this into snd_wss_probe() directly.
Rene.
[-- Attachment #2: 0001-ALSA-wss_lib-rework-snd_ad1848_probe.patch --]
[-- Type: text/plain, Size: 4876 bytes --]
>From 69a1e117af7fd35ebd4c093fcd8151996a43a69b Mon Sep 17 00:00:00 2001
From: Rene Herman <rene.herman@gmail.com>
Date: Wed, 6 Aug 2008 08:09:34 +0200
Subject: [PATCH] ALSA: wss_lib: rework snd_ad1848_probe()
Make snd_ad1848_probe() easier to follow. With an exception for only
trying once as soon as the codec is out of init (which should be all
that's needed) the detection logic should be unchanged.
Signed-off-by: Rene Herman <rene.herman@gmail.com>
---
sound/isa/wss/wss_lib.c | 131 ++++++++++++++++++++++++-----------------------
1 files changed, 67 insertions(+), 64 deletions(-)
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 955db45..802474b 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -1147,79 +1147,82 @@ static snd_pcm_uframes_t snd_wss_capture_pointer(struct snd_pcm_substream *subst
static int snd_ad1848_probe(struct snd_wss *chip)
{
+ unsigned long timeout = jiffies + msecs_to_jiffies(1000);
unsigned long flags;
- int i, id, rev, ad1847;
+ unsigned char r;
+ unsigned short hardware = 0;
+ int err = 0;
+ int i;
- id = 0;
- ad1847 = 0;
- for (i = 0; i < 1000; i++) {
- mb();
- if (inb(chip->port + CS4231P(REGSEL)) & CS4231_INIT)
- msleep(1);
- else {
- spin_lock_irqsave(&chip->reg_lock, flags);
- snd_wss_out(chip, CS4231_MISC_INFO, 0x00);
- snd_wss_out(chip, CS4231_LEFT_INPUT, 0xaa);
- snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x45);
- rev = snd_wss_in(chip, CS4231_RIGHT_INPUT);
- if (rev == 0x65) {
- spin_unlock_irqrestore(&chip->reg_lock, flags);
- id = 1;
- ad1847 = 1;
- break;
- }
- if (rev == 0x45) {
- rev = snd_wss_in(chip, CS4231_LEFT_INPUT);
- if (rev == 0xaa || rev == 0x8a) {
- spin_unlock_irqrestore(&chip->reg_lock, flags);
- id = 1;
- break;
- }
- }
- spin_unlock_irqrestore(&chip->reg_lock, flags);
- }
+ while (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
+ if (time_after(jiffies, timeout))
+ return -ENODEV;
+ cond_resched();
}
- if (id != 1)
- return -ENODEV; /* no valid device found */
- id = 0;
- if (chip->hardware == WSS_HW_DETECT)
- id = ad1847 ? WSS_HW_AD1847 : WSS_HW_AD1848;
-
spin_lock_irqsave(&chip->reg_lock, flags);
- inb(chip->port + CS4231P(STATUS)); /* clear any pendings IRQ */
- outb(0, chip->port + CS4231P(STATUS));
- mb();
- if (id == WSS_HW_AD1848) {
- /* check if there are more than 16 registers */
- rev = snd_wss_in(chip, CS4231_MISC_INFO);
- snd_wss_out(chip, CS4231_MISC_INFO, 0x40);
- for (i = 0; i < 16; ++i) {
- if (snd_wss_in(chip, i) != snd_wss_in(chip, i + 16)) {
- id = WSS_HW_CMI8330;
- break;
- }
+
+ /* set CS423x MODE 1 */
+ snd_wss_out(chip, CS4231_MISC_INFO, 0);
+
+ snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x45); /* 0x55 & ~0x10 */
+ r = snd_wss_in(chip, CS4231_RIGHT_INPUT);
+ if (r != 0x45) {
+ /* RMGE always high on AD1847 */
+ if ((r & ~CS4231_ENABLE_MIC_GAIN) != 0x45) {
+ err = -ENODEV;
+ goto out;
+ }
+ hardware = WSS_HW_AD1847;
+ } else {
+ snd_wss_out(chip, CS4231_LEFT_INPUT, 0xaa);
+ r = snd_wss_in(chip, CS4231_LEFT_INPUT);
+ /* L/RMGE always low on AT2320 */
+ if ((r | CS4231_ENABLE_MIC_GAIN) != 0xaa) {
+ err = -ENODEV;
+ goto out;
}
- snd_wss_out(chip, CS4231_MISC_INFO, 0x00);
- if (id != WSS_HW_CMI8330 && (rev & 0x80))
- id = WSS_HW_CS4248;
- if (id == WSS_HW_CMI8330 && (rev & 0x0f) != 0x0a)
- id = 0;
}
- if (id == WSS_HW_CMI8330) {
- /* verify it is not CS4231 by changing the version register */
- /* on CMI8330 it is volume control register and can be set 0 */
- snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
- snd_wss_dout(chip, CS4231_VERSION, 0x00);
- rev = snd_wss_in(chip, CS4231_VERSION) & 0xe7;
- if (rev)
- id = 0;
- snd_wss_out(chip, CS4231_MISC_INFO, 0);
+
+ /* clear pending IRQ */
+ wss_inb(chip, CS4231P(STATUS));
+ wss_outb(chip, CS4231P(STATUS), 0);
+ mb();
+
+ if ((chip->hardware & WSS_HW_TYPE_MASK) != WSS_HW_DETECT)
+ goto out;
+
+ if (hardware) {
+ chip->hardware = hardware;
+ goto out;
}
- if (id)
- chip->hardware = id;
+ r = snd_wss_in(chip, CS4231_MISC_INFO);
+
+ /* set CS423x MODE 2 */
+ snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2);
+ for (i = 0; i < 16; i++) {
+ if (snd_wss_in(chip, i) != snd_wss_in(chip, 16 + i)) {
+ /* we have more than 16 registers: check ID */
+ if ((r & 0xf) != 0xa)
+ goto out;
+ /*
+ * on CMI8330, CS4231_VERSION is volume control and
+ * can be set to 0
+ */
+ snd_wss_dout(chip, CS4231_VERSION, 0);
+ r = snd_wss_in(chip, CS4231_VERSION) & 0xe7;
+ if (!r)
+ chip->hardware = WSS_HW_CMI8330;
+ goto out;
+ }
+ }
+ if (r & 0x80)
+ chip->hardware = WSS_HW_CS4248;
+ else
+ chip->hardware = WSS_HW_AD1848;
+out:
spin_unlock_irqrestore(&chip->reg_lock, flags);
- return 0; /* all things are ok.. */
+ return err;
}
static int snd_wss_probe(struct snd_wss *chip)
--
1.5.5
[-- Attachment #3: Type: text/plain, Size: 160 bytes --]
_______________________________________________
Alsa-devel mailing list
Alsa-devel@alsa-project.org
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
next reply other threads:[~2008-08-06 6:42 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-08-06 6:42 Rene Herman [this message]
2008-08-06 6:56 ` [PATCH] ALSA: wss_lib: rework snd_ad1848_probe() Rene Herman
2008-08-06 10:07 ` Takashi Iwai
-- strict thread matches above, loose matches on Subject: below --
2008-08-06 7:57 krzysztof.h1
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=489947C0.30104@keyaccess.nl \
--to=rene.herman@keyaccess.nl \
--cc=alsa-devel@alsa-project.org \
--cc=krzysztof.h1@poczta.fm \
--cc=tiwai@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.