[ALSA] snd-emu10k1: Removes some distortion from Audigy 2 ZS Notebook.
authorJames Courtier-Dutton <James@superbug.co.uk>
Wed, 21 Dec 2005 14:06:08 +0000 (15:06 +0100)
committerJaroslav Kysela <perex@suse.cz>
Tue, 3 Jan 2006 11:31:01 +0000 (12:31 +0100)
Modules: EMU10K1/EMU10K2 driver

Description:
Part way to fix ALSA bug#927
Add support for the SPI interface on the CA0108 chip.
This is used to control the registers on the DAC.
Headphone output tested.
Other outputs and Capture not tested yet.
Note: The red LED does not come on, but sound is still OK.

Signed-off-by: James Courtier-Dutton <James@superbug.co.uk>
include/sound/emu10k1.h
sound/pci/emu10k1/emu10k1_main.c
sound/pci/emu10k1/io.c

index 0d6e68c43e63d6a4eb4539d1d5759ee30110ee54..951e40d720d9b1426fdaf29d9bc57b8513083c96 100644 (file)
@@ -1062,6 +1062,8 @@ struct snd_emu_chip_details {
        unsigned char ac97_chip;    /* Has an AC97 chip: 1 = mandatory, 2 = optional */
        unsigned char ecard;        /* APS EEPROM */
        unsigned char emu1212m;     /* EMU 1212m card */
+       unsigned char spi_dac;      /* SPI interface for DAC */
+       unsigned char i2c_adc;      /* I2C interface for ADC */
        const char *driver;
        const char *name;
        const char *id;         /* for backward compatibility - can be NULL if not needed */
@@ -1203,6 +1205,7 @@ unsigned int snd_emu10k1_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, un
 void snd_emu10k1_ptr_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data);
 unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, unsigned int reg, unsigned int chn);
 void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data);
+int snd_emu10k1_spi_write(struct snd_emu10k1 * emu, unsigned int data);
 unsigned int snd_emu10k1_efx_read(struct snd_emu10k1 *emu, unsigned int pc);
 void snd_emu10k1_intr_enable(struct snd_emu10k1 *emu, unsigned int intrenb);
 void snd_emu10k1_intr_disable(struct snd_emu10k1 *emu, unsigned int intrenb);
index f8e2ccd50d60a3bed3468ab64bb7124a8647064e..eb093700fa71ac5374b932a2fe534e1fa80e9b60 100644 (file)
@@ -181,7 +181,32 @@ static int snd_emu10k1_init(struct snd_emu10k1 *emu, int enable_ir, int resume)
                tmp = inl(emu->port + A_IOCFG) & ~0x8; /* Clear bit 3 */
                outl(tmp, emu->port + A_IOCFG);
        }
-
+       if (emu->card_capabilities->spi_dac) { /* Audigy 2 ZS Notebook with DAC Wolfson WM8768/WM8568 */
+               u32 tmp;
+               tmp = snd_emu10k1_spi_write(emu, 0x00ff);
+               tmp = snd_emu10k1_spi_write(emu, 0x02ff);
+               tmp = snd_emu10k1_spi_write(emu, 0x0400);
+               tmp = snd_emu10k1_spi_write(emu, 0x0520);
+               tmp = snd_emu10k1_spi_write(emu, 0x0600);
+               tmp = snd_emu10k1_spi_write(emu, 0x08ff);
+               tmp = snd_emu10k1_spi_write(emu, 0x0aff);
+               tmp = snd_emu10k1_spi_write(emu, 0x0cff);
+               tmp = snd_emu10k1_spi_write(emu, 0x0eff);
+               tmp = snd_emu10k1_spi_write(emu, 0x10ff);
+               tmp = snd_emu10k1_spi_write(emu, 0x1200);
+               tmp = snd_emu10k1_spi_write(emu, 0x1400);
+               tmp = snd_emu10k1_spi_write(emu, 0x1480);
+               tmp = snd_emu10k1_spi_write(emu, 0x1800);
+               tmp = snd_emu10k1_spi_write(emu, 0x1aff);
+               tmp = snd_emu10k1_spi_write(emu, 0x1cff);
+               tmp = snd_emu10k1_spi_write(emu, 0x1e00);
+               tmp = snd_emu10k1_spi_write(emu, 0x0530);
+               tmp = snd_emu10k1_spi_write(emu, 0x0602);
+               tmp = snd_emu10k1_spi_write(emu, 0x0622);
+               tmp = snd_emu10k1_spi_write(emu, 0x1400);
+               snd_emu10k1_ptr20_write(emu, 0x60, 0, 0x10);
+       }
+       
        snd_emu10k1_ptr_write(emu, PTB, 0, emu->ptb_pages.addr);
        snd_emu10k1_ptr_write(emu, TCB, 0, 0);  /* taken from original driver */
        snd_emu10k1_ptr_write(emu, TCBS, 0, 4); /* taken from original driver */
@@ -747,6 +772,7 @@ static struct snd_emu_chip_details emu_chip_details[] = {
         .emu10k2_chip = 1,
         .ca0108_chip = 1,
         .ca_cardbus_chip = 1,
+        .spi_dac = 1,
         .spk71 = 1} ,
        {.vendor = 0x1102, .device = 0x0008, 
         .driver = "Audigy2", .name = "Audigy 2 Value [Unknown]", 
index 5d116dd7403be6576eeb741285f3bd8f8bf54494..7d0cb9db428046f0b27a10375b9ad65b36efca10 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/time.h>
 #include <sound/core.h>
 #include <sound/emu10k1.h>
+#include <linux/delay.h>
 
 unsigned int snd_emu10k1_ptr_read(struct snd_emu10k1 * emu, unsigned int reg, unsigned int chn)
 {
@@ -123,6 +124,41 @@ void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu,
        spin_unlock_irqrestore(&emu->emu_lock, flags);
 }
 
+int snd_emu10k1_spi_write(struct snd_emu10k1 * emu,
+                                  unsigned int data)
+{
+       unsigned int reset, set;
+       unsigned int reg, tmp;
+       int n, result;
+       if (emu->card_capabilities->ca0108_chip) {
+               reg=0x3c; /* PTR20, reg 0x3c */
+       } else {
+               return 1;  /* For other cards types the SPI register is currently unknown. */
+       }
+       if (data > 0xffff) return 1; /* Only 16bit values allowed */
+
+       tmp = snd_emu10k1_ptr20_read(emu, reg, 0);
+               reset = (tmp & ~0x3ffff) | 0x20000; /* Set xxx20000 */
+       set = reset | 0x10000; /* Set xxx1xxxx */
+       snd_emu10k1_ptr20_write(emu, reg, 0, reset | data);
+       tmp = snd_emu10k1_ptr20_read(emu, reg, 0); /* write post */
+       snd_emu10k1_ptr20_write(emu, reg, 0, set | data);
+       result = 1;
+       /* Wait for status bit to return to 0 */
+       for (n=0;n<100;n++) {
+               udelay(10);
+               tmp = snd_emu10k1_ptr20_read(emu, reg, 0);
+               if (!(tmp & 0x10000)) {
+                       result=0;
+                       break;
+               }
+       }
+       if (result) return 1; /* Timed out */
+       snd_emu10k1_ptr20_write(emu, reg, 0, reset | data);
+       tmp = snd_emu10k1_ptr20_read(emu, reg, 0); /* Write post */
+       return 0;
+}
+
 void snd_emu10k1_intr_enable(struct snd_emu10k1 *emu, unsigned int intrenb)
 {
        unsigned long flags;