Commit c9a7dc2c authored by Rene Herman's avatar Rene Herman Committed by Jaroslav Kysela

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: default avatarRene Herman <rene.herman@gmail.com>
Acked-by: default avatarKrzysztof Helt <krzysztof.h1@wp.pl>
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
Signed-off-by: default avatarJaroslav Kysela <perex@perex.cz>
parent 8f4f4ef6
...@@ -1147,79 +1147,84 @@ static snd_pcm_uframes_t snd_wss_capture_pointer(struct snd_pcm_substream *subst ...@@ -1147,79 +1147,84 @@ static snd_pcm_uframes_t snd_wss_capture_pointer(struct snd_pcm_substream *subst
static int snd_ad1848_probe(struct snd_wss *chip) static int snd_ad1848_probe(struct snd_wss *chip)
{ {
unsigned long timeout = jiffies + msecs_to_jiffies(1000);
unsigned long flags; unsigned long flags;
int i, id, rev, ad1847; unsigned char r;
unsigned short hardware = 0;
int err = 0;
int i;
id = 0; while (wss_inb(chip, CS4231P(REGSEL)) & CS4231_INIT) {
ad1847 = 0; if (time_after(jiffies, timeout))
for (i = 0; i < 1000; i++) { return -ENODEV;
mb(); cond_resched();
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);
}
} }
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); spin_lock_irqsave(&chip->reg_lock, flags);
inb(chip->port + CS4231P(STATUS)); /* clear any pendings IRQ */
outb(0, chip->port + CS4231P(STATUS)); /* set CS423x MODE 1 */
mb(); snd_wss_out(chip, CS4231_MISC_INFO, 0);
if (id == WSS_HW_AD1848) {
/* check if there are more than 16 registers */ snd_wss_out(chip, CS4231_RIGHT_INPUT, 0x45); /* 0x55 & ~0x10 */
rev = snd_wss_in(chip, CS4231_MISC_INFO); r = snd_wss_in(chip, CS4231_RIGHT_INPUT);
snd_wss_out(chip, CS4231_MISC_INFO, 0x40); if (r != 0x45) {
for (i = 0; i < 16; ++i) { /* RMGE always high on AD1847 */
if (snd_wss_in(chip, i) != snd_wss_in(chip, i + 16)) { if ((r & ~CS4231_ENABLE_MIC_GAIN) != 0x45) {
id = WSS_HW_CMI8330; err = -ENODEV;
break; 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 */ /* clear pending IRQ */
/* on CMI8330 it is volume control register and can be set 0 */ wss_inb(chip, CS4231P(STATUS));
snd_wss_out(chip, CS4231_MISC_INFO, CS4231_MODE2); wss_outb(chip, CS4231P(STATUS), 0);
snd_wss_dout(chip, CS4231_VERSION, 0x00); mb();
rev = snd_wss_in(chip, CS4231_VERSION) & 0xe7;
if (rev) if ((chip->hardware & WSS_HW_TYPE_MASK) != WSS_HW_DETECT)
id = 0; goto out;
snd_wss_out(chip, CS4231_MISC_INFO, 0);
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_mode;
/*
* 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_mode;
}
}
if (r & 0x80)
chip->hardware = WSS_HW_CS4248;
else
chip->hardware = WSS_HW_AD1848;
out_mode:
snd_wss_out(chip, CS4231_MISC_INFO, 0);
out:
spin_unlock_irqrestore(&chip->reg_lock, flags); spin_unlock_irqrestore(&chip->reg_lock, flags);
return 0; /* all things are ok.. */ return err;
} }
static int snd_wss_probe(struct snd_wss *chip) static int snd_wss_probe(struct snd_wss *chip)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment