[ALSA] intel8x0 - Add quirk for Compaq Deskpro EN
[safe/jmp/linux-2.6] / sound / pci / intel8x0.c
index 9c1bce7..c52abd0 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   ALSA driver for Intel ICH (i8x0) chipsets
  *
- *     Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
+ *     Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  *
  *
  *   This code also contains alpha support for SiS 735 chipsets provided
@@ -26,7 +26,6 @@
  *
  */      
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -43,7 +42,7 @@
 #include <asm/pgtable.h>
 #include <asm/cacheflush.h>
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{Intel,82801AA-ICH},"
@@ -71,6 +70,7 @@ static char *ac97_quirk;
 static int buggy_semaphore;
 static int buggy_irq = -1; /* auto-check */
 static int xbox;
+static int spdif_aclink = -1;
 
 module_param(index, int, 0444);
 MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
@@ -86,6 +86,8 @@ module_param(buggy_irq, bool, 0444);
 MODULE_PARM_DESC(buggy_irq, "Enable workaround for buggy interrupts on some motherboards.");
 module_param(xbox, bool, 0444);
 MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
+module_param(spdif_aclink, int, 0444);
+MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
 
 /* just for backward compatibility */
 static int enable;
@@ -368,12 +370,8 @@ struct intel8x0 {
 
        int irq;
 
-       unsigned int mmio;
-       unsigned long addr;
-       void __iomem *remap_addr;
-       unsigned int bm_mmio;
-       unsigned long bmaddr;
-       void __iomem *remap_bmaddr;
+       void __iomem *addr;
+       void __iomem *bmaddr;
 
        struct pci_dev *pci;
        struct snd_card *card;
@@ -446,72 +444,48 @@ MODULE_DEVICE_TABLE(pci, snd_intel8x0_ids);
  *  Lowlevel I/O - busmaster
  */
 
-static u8 igetbyte(struct intel8x0 *chip, u32 offset)
+static inline u8 igetbyte(struct intel8x0 *chip, u32 offset)
 {
-       if (chip->bm_mmio)
-               return readb(chip->remap_bmaddr + offset);
-       else
-               return inb(chip->bmaddr + offset);
+       return ioread8(chip->bmaddr + offset);
 }
 
-static u16 igetword(struct intel8x0 *chip, u32 offset)
+static inline u16 igetword(struct intel8x0 *chip, u32 offset)
 {
-       if (chip->bm_mmio)
-               return readw(chip->remap_bmaddr + offset);
-       else
-               return inw(chip->bmaddr + offset);
+       return ioread16(chip->bmaddr + offset);
 }
 
-static u32 igetdword(struct intel8x0 *chip, u32 offset)
+static inline u32 igetdword(struct intel8x0 *chip, u32 offset)
 {
-       if (chip->bm_mmio)
-               return readl(chip->remap_bmaddr + offset);
-       else
-               return inl(chip->bmaddr + offset);
+       return ioread32(chip->bmaddr + offset);
 }
 
-static void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
+static inline void iputbyte(struct intel8x0 *chip, u32 offset, u8 val)
 {
-       if (chip->bm_mmio)
-               writeb(val, chip->remap_bmaddr + offset);
-       else
-               outb(val, chip->bmaddr + offset);
+       iowrite8(val, chip->bmaddr + offset);
 }
 
-static void iputword(struct intel8x0 *chip, u32 offset, u16 val)
+static inline void iputword(struct intel8x0 *chip, u32 offset, u16 val)
 {
-       if (chip->bm_mmio)
-               writew(val, chip->remap_bmaddr + offset);
-       else
-               outw(val, chip->bmaddr + offset);
+       iowrite16(val, chip->bmaddr + offset);
 }
 
-static void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
+static inline void iputdword(struct intel8x0 *chip, u32 offset, u32 val)
 {
-       if (chip->bm_mmio)
-               writel(val, chip->remap_bmaddr + offset);
-       else
-               outl(val, chip->bmaddr + offset);
+       iowrite32(val, chip->bmaddr + offset);
 }
 
 /*
  *  Lowlevel I/O - AC'97 registers
  */
 
-static u16 iagetword(struct intel8x0 *chip, u32 offset)
+static inline u16 iagetword(struct intel8x0 *chip, u32 offset)
 {
-       if (chip->mmio)
-               return readw(chip->remap_addr + offset);
-       else
-               return inw(chip->addr + offset);
+       return ioread16(chip->addr + offset);
 }
 
-static void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
+static inline void iaputword(struct intel8x0 *chip, u32 offset, u16 val)
 {
-       if (chip->mmio)
-               writew(val, chip->remap_addr + offset);
-       else
-               outw(val, chip->addr + offset);
+       iowrite16(val, chip->addr + offset);
 }
 
 /*
@@ -736,11 +710,13 @@ static void snd_intel8x0_setup_periods(struct intel8x0 *chip, struct ichdev *ich
 static void fill_nocache(void *buf, int size, int nocache)
 {
        size = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
-       change_page_attr(virt_to_page(buf), size, nocache ? PAGE_KERNEL_NOCACHE : PAGE_KERNEL);
-       global_flush_tlb();
+       if (nocache)
+               set_pages_uc(virt_to_page(buf), size);
+       else
+               set_pages_wb(virt_to_page(buf), size);
 }
 #else
-#define fill_nocache(buf,size,nocache)
+#define fill_nocache(buf, size, nocache) do { ; } while (0)
 #endif
 
 /*
@@ -750,10 +726,11 @@ static void fill_nocache(void *buf, int size, int nocache)
 static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ichdev)
 {
        unsigned long port = ichdev->reg_offset;
+       unsigned long flags;
        int status, civ, i, step;
        int ack = 0;
 
-       spin_lock(&chip->reg_lock);
+       spin_lock_irqsave(&chip->reg_lock, flags);
        status = igetbyte(chip, port + ichdev->roff_sr);
        civ = igetbyte(chip, port + ICH_REG_OFF_CIV);
        if (!(status & ICH_BCIS)) {
@@ -793,7 +770,7 @@ static inline void snd_intel8x0_update(struct intel8x0 *chip, struct ichdev *ich
                        ack = 1;
                }
        }
-       spin_unlock(&chip->reg_lock);
+       spin_unlock_irqrestore(&chip->reg_lock, flags);
        if (ack && ichdev->substream) {
                snd_pcm_period_elapsed(ichdev->substream);
        }
@@ -1606,10 +1583,14 @@ static int __devinit snd_intel8x0_pcm(struct intel8x0 *chip)
        case DEVICE_INTEL_ICH4:
                tbl = intel_pcms;
                tblsize = ARRAY_SIZE(intel_pcms);
+               if (spdif_aclink)
+                       tblsize--;
                break;
        case DEVICE_NFORCE:
                tbl = nforce_pcms;
                tblsize = ARRAY_SIZE(nforce_pcms);
+               if (spdif_aclink)
+                       tblsize--;
                break;
        case DEVICE_ALI:
                tbl = ali_pcms;
@@ -1727,6 +1708,12 @@ static struct ac97_pcm ac97_pcm_defs[] __devinitdata = {
 };
 
 static struct ac97_quirk ac97_quirks[] __devinitdata = {
+        {
+               .subvendor = 0x0e11,
+               .subdevice = 0x000e,
+               .name = "Compaq Deskpro EN",    /* AD1885 */
+               .type = AC97_TUNE_HP_ONLY
+        },
        {
                .subvendor = 0x0e11,
                .subdevice = 0x008a,
@@ -1759,6 +1746,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
        },
        {
                .subvendor = 0x1025,
+               .subdevice = 0x0082,
+               .name = "Acer Travelmate 2310",
+               .type = AC97_TUNE_HP_ONLY
+       },
+       {
+               .subvendor = 0x1025,
                .subdevice = 0x0083,
                .name = "Acer Aspire 3003LCi",
                .type = AC97_TUNE_HP_ONLY
@@ -1819,6 +1812,18 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
        },
        {
                .subvendor = 0x1028,
+               .subdevice = 0x0186,
+               .name = "Dell Latitude D810", /* cf. Malone #41015 */
+               .type = AC97_TUNE_HP_MUTE_LED
+       },
+       {
+               .subvendor = 0x1028,
+               .subdevice = 0x0188,
+               .name = "Dell Inspiron 6000",
+               .type = AC97_TUNE_HP_MUTE_LED /* cf. Malone #41015 */
+       },
+       {
+               .subvendor = 0x1028,
                .subdevice = 0x0191,
                .name = "Dell Inspiron 8600",
                .type = AC97_TUNE_HP_ONLY
@@ -1839,7 +1844,7 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
                .subvendor = 0x103c,
                .subdevice = 0x088c,
                .name = "HP nc8000",
-               .type = AC97_TUNE_MUTE_LED
+               .type = AC97_TUNE_HP_MUTE_LED
        },
        {
                .subvendor = 0x103c,
@@ -1933,6 +1938,12 @@ static struct ac97_quirk ac97_quirks[] __devinitdata = {
        },
        {
                .subvendor = 0x10cf,
+               .subdevice = 0x127e,
+               .name = "Fujitsu Lifebook C1211D",
+               .type = AC97_TUNE_HP_ONLY
+       },
+       {
+               .subvendor = 0x10cf,
                .subdevice = 0x12ec,
                .name = "Fujitsu-Siemens 4010",
                .type = AC97_TUNE_HP_ONLY
@@ -2068,24 +2079,26 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
        };
 
        chip->spdif_idx = -1; /* use PCMOUT (or disabled) */
-       switch (chip->device_type) {
-       case DEVICE_NFORCE:
-               chip->spdif_idx = NVD_SPBAR;
-               break;
-       case DEVICE_ALI:
-               chip->spdif_idx = ALID_AC97SPDIFOUT;
-               break;
-       case DEVICE_INTEL_ICH4:
-               chip->spdif_idx = ICHD_SPBAR;
-               break;
-       };
+       if (!spdif_aclink) {
+               switch (chip->device_type) {
+               case DEVICE_NFORCE:
+                       chip->spdif_idx = NVD_SPBAR;
+                       break;
+               case DEVICE_ALI:
+                       chip->spdif_idx = ALID_AC97SPDIFOUT;
+                       break;
+               case DEVICE_INTEL_ICH4:
+                       chip->spdif_idx = ICHD_SPBAR;
+                       break;
+               };
+       }
 
        chip->in_ac97_init = 1;
        
        memset(&ac97, 0, sizeof(ac97));
        ac97.private_data = chip;
        ac97.private_free = snd_intel8x0_mixer_free_ac97;
-       ac97.scaps = AC97_SCAP_SKIP_MODEM;
+       ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
        if (chip->xbox)
                ac97.scaps |= AC97_SCAP_DETECT_BY_VENDOR;
        if (chip->device_type != DEVICE_ALI) {
@@ -2144,7 +2157,6 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
                                snd_printk(KERN_ERR "Unable to initialize codec #%d\n", i);
                        if (i == 0)
                                goto __err;
-                       continue;
                }
        }
        /* tune up the primary codec */
@@ -2201,11 +2213,11 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
                if ((igetdword(chip, ICHREG(GLOB_STA)) & ICH_SAMPLE_CAP) == ICH_SAMPLE_16_20)
                        chip->smp20bit = 1;
        }
-       if (chip->device_type == DEVICE_NFORCE) {
+       if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
                /* 48kHz only */
                chip->ichd[chip->spdif_idx].pcm->rates = SNDRV_PCM_RATE_48000;
        }
-       if (chip->device_type == DEVICE_INTEL_ICH4) {
+       if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
                /* use slot 10/11 for SPDIF */
                u32 val;
                val = igetdword(chip, ICHREG(GLOB_CNT)) & ~ICH_PCM_SPDIF_MASK;
@@ -2333,7 +2345,7 @@ static int snd_intel8x0_ich_chip_init(struct intel8x0 *chip, int probing)
                /* unmute the output on SIS7012 */
                iputword(chip, 0x4c, igetword(chip, 0x4c) | 1);
        }
-       if (chip->device_type == DEVICE_NFORCE) {
+       if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
                /* enable SPDIF interrupt */
                unsigned int val;
                pci_read_config_dword(chip->pci, 0x4c, &val);
@@ -2426,7 +2438,7 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
        /* reset channels */
        for (i = 0; i < chip->bdbars_count; i++)
                iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
-       if (chip->device_type == DEVICE_NFORCE) {
+       if (chip->device_type == DEVICE_NFORCE && !spdif_aclink) {
                /* stop the spdif interrupt */
                unsigned int val;
                pci_read_config_dword(chip->pci, 0x4c, &val);
@@ -2443,10 +2455,10 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
                        fill_nocache(chip->bdbars.area, chip->bdbars.bytes, 0);
                snd_dma_free_pages(&chip->bdbars);
        }
-       if (chip->remap_addr)
-               iounmap(chip->remap_addr);
-       if (chip->remap_bmaddr)
-               iounmap(chip->remap_bmaddr);
+       if (chip->addr)
+               pci_iounmap(chip->pci, chip->addr);
+       if (chip->bmaddr)
+               pci_iounmap(chip->pci, chip->bmaddr);
        pci_release_regions(chip->pci);
        pci_disable_device(chip->pci);
        kfree(chip);
@@ -2489,7 +2501,10 @@ static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
        }
        pci_disable_device(pci);
        pci_save_state(pci);
-       pci_set_power_state(pci, pci_choose_state(pci, state));
+       /* The call below may disable built-in speaker on some laptops
+        * after S2RAM.  So, don't touch it.
+        */
+       /* pci_set_power_state(pci, pci_choose_state(pci, state)); */
        return 0;
 }
 
@@ -2508,8 +2523,9 @@ static int intel8x0_resume(struct pci_dev *pci)
                return -EIO;
        }
        pci_set_master(pci);
+       snd_intel8x0_chip_init(chip, 0);
        if (request_irq(pci->irq, snd_intel8x0_interrupt,
-                       IRQF_DISABLED|IRQF_SHARED, card->shortname, chip)) {
+                       IRQF_SHARED, card->shortname, chip)) {
                printk(KERN_ERR "intel8x0: unable to grab IRQ %d, "
                       "disabling device\n", pci->irq);
                snd_card_disconnect(card);
@@ -2517,10 +2533,9 @@ static int intel8x0_resume(struct pci_dev *pci)
        }
        chip->irq = pci->irq;
        synchronize_irq(chip->irq);
-       snd_intel8x0_chip_init(chip, 0);
 
        /* re-initialize mixer stuff */
-       if (chip->device_type == DEVICE_INTEL_ICH4) {
+       if (chip->device_type == DEVICE_INTEL_ICH4 && !spdif_aclink) {
                /* enable separate SDINs for ICH4 */
                iputbyte(chip, ICHREG(SDM), chip->sdm_saved);
                /* use slot 10/11 for SPDIF */
@@ -2793,35 +2808,27 @@ static int __devinit snd_intel8x0_create(struct snd_card *card,
 
        if (device_type == DEVICE_ALI) {
                /* ALI5455 has no ac97 region */
-               chip->bmaddr = pci_resource_start(pci, 0);
+               chip->bmaddr = pci_iomap(pci, 0, 0);
                goto port_inited;
        }
 
-       if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) {      /* ICH4 and Nforce */
-               chip->mmio = 1;
-               chip->addr = pci_resource_start(pci, 2);
-               chip->remap_addr = ioremap_nocache(chip->addr,
-                                                  pci_resource_len(pci, 2));
-               if (chip->remap_addr == NULL) {
-                       snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
-                       snd_intel8x0_free(chip);
-                       return -EIO;
-               }
-       } else {
-               chip->addr = pci_resource_start(pci, 0);
-       }
-       if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) {      /* ICH4 */
-               chip->bm_mmio = 1;
-               chip->bmaddr = pci_resource_start(pci, 3);
-               chip->remap_bmaddr = ioremap_nocache(chip->bmaddr,
-                                                    pci_resource_len(pci, 3));
-               if (chip->remap_bmaddr == NULL) {
-                       snd_printk(KERN_ERR "Controller space ioremap problem\n");
-                       snd_intel8x0_free(chip);
-                       return -EIO;
-               }
-       } else {
-               chip->bmaddr = pci_resource_start(pci, 1);
+       if (pci_resource_flags(pci, 2) & IORESOURCE_MEM) /* ICH4 and Nforce */
+               chip->addr = pci_iomap(pci, 2, 0);
+       else
+               chip->addr = pci_iomap(pci, 0, 0);
+       if (!chip->addr) {
+               snd_printk(KERN_ERR "AC'97 space ioremap problem\n");
+               snd_intel8x0_free(chip);
+               return -EIO;
+       }
+       if (pci_resource_flags(pci, 3) & IORESOURCE_MEM) /* ICH4 */
+               chip->bmaddr = pci_iomap(pci, 3, 0);
+       else
+               chip->bmaddr = pci_iomap(pci, 1, 0);
+       if (!chip->bmaddr) {
+               snd_printk(KERN_ERR "Controller space ioremap problem\n");
+               snd_intel8x0_free(chip);
+               return -EIO;
        }
 
  port_inited:
@@ -2885,16 +2892,7 @@ static int __devinit snd_intel8x0_create(struct snd_card *card,
                ICH_REG_ALI_INTERRUPTSR : ICH_REG_GLOB_STA;
        chip->int_sta_mask = int_sta_masks;
 
-       /* request irq after initializaing int_sta_mask, etc */
-       if (request_irq(pci->irq, snd_intel8x0_interrupt,
-                       IRQF_DISABLED|IRQF_SHARED, card->shortname, chip)) {
-               snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
-               snd_intel8x0_free(chip);
-               return -EBUSY;
-       }
-       chip->irq = pci->irq;
        pci_set_master(pci);
-       synchronize_irq(chip->irq);
 
        switch(chip->device_type) {
        case DEVICE_INTEL_ICH4:
@@ -2924,6 +2922,15 @@ static int __devinit snd_intel8x0_create(struct snd_card *card,
                return err;
        }
 
+       /* request irq after initializaing int_sta_mask, etc */
+       if (request_irq(pci->irq, snd_intel8x0_interrupt,
+                       IRQF_SHARED, card->shortname, chip)) {
+               snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
+               snd_intel8x0_free(chip);
+               return -EBUSY;
+       }
+       chip->irq = pci->irq;
+
        if ((err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops)) < 0) {
                snd_intel8x0_free(chip);
                return err;
@@ -2964,6 +2971,29 @@ static struct shortname_table {
        { 0, NULL },
 };
 
+static struct snd_pci_quirk spdif_aclink_defaults[] __devinitdata = {
+       SND_PCI_QUIRK(0x147b, 0x1c1a, "ASUS KN8", 1),
+       { } /* end */
+};
+
+/* look up white/black list for SPDIF over ac-link */
+static int __devinit check_default_spdif_aclink(struct pci_dev *pci)
+{
+       const struct snd_pci_quirk *w;
+
+       w = snd_pci_quirk_lookup(pci, spdif_aclink_defaults);
+       if (w) {
+               if (w->value)
+                       snd_printdd(KERN_INFO "intel8x0: Using SPDIF over "
+                                   "AC-Link for %s\n", w->name);
+               else
+                       snd_printdd(KERN_INFO "intel8x0: Using integrated "
+                                   "SPDIF DMA for %s\n", w->name);
+               return w->value;
+       }
+       return 0;
+}
+
 static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
                                        const struct pci_device_id *pci_id)
 {
@@ -2976,16 +3006,18 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
        if (card == NULL)
                return -ENOMEM;
 
-       switch (pci_id->driver_data) {
-       case DEVICE_NFORCE:
-               strcpy(card->driver, "NFORCE");
-               break;
-       case DEVICE_INTEL_ICH4:
-               strcpy(card->driver, "ICH4");
-               break;
-       default:
-               strcpy(card->driver, "ICH");
-               break;
+       if (spdif_aclink < 0)
+               spdif_aclink = check_default_spdif_aclink(pci);
+
+       strcpy(card->driver, "ICH");
+       if (!spdif_aclink) {
+               switch (pci_id->driver_data) {
+               case DEVICE_NFORCE:
+                       strcpy(card->driver, "NFORCE");
+                       break;
+               case DEVICE_INTEL_ICH4:
+                       strcpy(card->driver, "ICH4");
+               }
        }
 
        strcpy(card->shortname, "Intel ICH");
@@ -3025,8 +3057,8 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
        snd_intel8x0_proc_init(chip);
 
        snprintf(card->longname, sizeof(card->longname),
-                "%s with %s at %#lx, irq %i", card->shortname,
-                snd_ac97_get_short_name(chip->ac97[0]), chip->addr, chip->irq);
+                "%s with %s at irq %i", card->shortname,
+                snd_ac97_get_short_name(chip->ac97[0]), chip->irq);
 
        if (! ac97_clock)
                intel8x0_measure_ac97_clock(chip);