Merge branch 'topic/hwdep-cleanup' into for-linus
[safe/jmp/linux-2.6] / sound / pci / via82xx.c
index 0f171dd..d870554 100644 (file)
@@ -3,7 +3,7 @@
  *
  *   VT82C686A/B/C, VT8233A/C, VT8235
  *
- *     Copyright (c) 2000 Jaroslav Kysela <perex@suse.cz>
+ *     Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
  *                        Tjeerd.Mulder <Tjeerd.Mulder@fujitsu-siemens.com>
  *                    2002 Takashi Iwai <tiwai@suse.de>
  *
@@ -46,7 +46,6 @@
  *     - Optimize position calculation for the 823x chips. 
  */
 
-#include <sound/driver.h>
 #include <asm/io.h>
 #include <linux/delay.h>
 #include <linux/interrupt.h>
@@ -59,6 +58,7 @@
 #include <sound/pcm.h>
 #include <sound/pcm_params.h>
 #include <sound/info.h>
+#include <sound/tlv.h>
 #include <sound/ac97_codec.h>
 #include <sound/mpu401.h>
 #include <sound/initval.h>
@@ -67,7 +67,7 @@
 #define POINTER_DEBUG
 #endif
 
-MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
+MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
 MODULE_DESCRIPTION("VIA VT82xx audio");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
@@ -123,6 +123,7 @@ module_param(enable, bool, 0444);
 #define VIA_REV_8233A          0x40    /* 1 rec, 1 multi-pb, spdf */
 #define VIA_REV_8235           0x50    /* 2 rec, 4 pb, 1 multi-pb, spdif */
 #define VIA_REV_8237           0x60
+#define VIA_REV_8251           0x70
 
 /*
  *  Direct registers
@@ -312,6 +313,7 @@ struct snd_via_sg_table {
 } ;
 
 #define VIA_TABLE_SIZE 255
+#define VIA_MAX_BUFSIZE        (1<<24)
 
 struct viadev {
        unsigned int reg_offset;
@@ -419,7 +421,6 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
 {
        unsigned int i, idx, ofs, rest;
        struct via82xx *chip = snd_pcm_substream_chip(substream);
-       struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
 
        if (dev->table.area == NULL) {
                /* the start of each lists must be aligned to 8 bytes,
@@ -448,15 +449,15 @@ static int build_via_table(struct viadev *dev, struct snd_pcm_substream *substre
                do {
                        unsigned int r;
                        unsigned int flag;
+                       unsigned int addr;
 
                        if (idx >= VIA_TABLE_SIZE) {
                                snd_printk(KERN_ERR "via82xx: too much table size!\n");
                                return -EINVAL;
                        }
-                       ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32((u32)snd_pcm_sgbuf_get_addr(sgbuf, ofs));
-                       r = PAGE_SIZE - (ofs % PAGE_SIZE);
-                       if (rest < r)
-                               r = rest;
+                       addr = snd_pcm_sgbuf_get_addr(substream, ofs);
+                       ((u32 *)dev->table.area)[idx << 1] = cpu_to_le32(addr);
+                       r = snd_pcm_sgbuf_get_chunk_size(substream, ofs, rest);
                        rest -= r;
                        if (! rest) {
                                if (i == periods - 1)
@@ -611,7 +612,7 @@ static void snd_via82xx_channel_reset(struct via82xx *chip, struct viadev *viade
  *  Interrupt handler
  *  Used for 686 and 8233A
  */
-static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_via686_interrupt(int irq, void *dev_id)
 {
        struct via82xx *chip = dev_id;
        unsigned int status;
@@ -621,7 +622,7 @@ static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *r
        if (! (status & chip->intr_mask)) {
                if (chip->rmidi)
                        /* check mpu401 interrupt */
-                       return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data, regs);
+                       return snd_mpu401_uart_interrupt(irq, chip->rmidi->private_data);
                return IRQ_NONE;
        }
 
@@ -657,7 +658,7 @@ static irqreturn_t snd_via686_interrupt(int irq, void *dev_id, struct pt_regs *r
 /*
  *  Interrupt handler
  */
-static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_via8233_interrupt(int irq, void *dev_id)
 {
        struct via82xx *chip = dev_id;
        unsigned int status;
@@ -823,7 +824,8 @@ static snd_pcm_uframes_t snd_via686_pcm_pointer(struct snd_pcm_substream *substr
        struct viadev *viadev = substream->runtime->private_data;
        unsigned int idx, ptr, count, res;
 
-       snd_assert(viadev->tbl_entries, return 0);
+       if (snd_BUG_ON(!viadev->tbl_entries))
+               return 0;
        if (!(inb(VIADEV_REG(viadev, OFFSET_STATUS)) & VIA_REG_STAT_ACTIVE))
                return 0;
 
@@ -854,7 +856,8 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
        unsigned int idx, count, res;
        int status;
        
-       snd_assert(viadev->tbl_entries, return 0);
+       if (snd_BUG_ON(!viadev->tbl_entries))
+               return 0;
 
        spin_lock(&chip->reg_lock);
        count = inl(VIADEV_REG(viadev, OFFSET_CURR_COUNT));
@@ -862,6 +865,11 @@ static snd_pcm_uframes_t snd_via8233_pcm_pointer(struct snd_pcm_substream *subst
        if (!status)
                status = inb(VIADEV_REG(viadev, OFFSET_STATUS));
 
+       /* An apparent bug in the 8251 is worked around by sending a 
+        * REG_CTRL_START. */
+       if (chip->revision == VIA_REV_8251 && (status & VIA_REG_STAT_EOL))
+               snd_via82xx_pcm_trigger(substream, SNDRV_PCM_TRIGGER_START);
+
        if (!(status & VIA_REG_STAT_ACTIVE)) {
                res = 0;
                goto unlock;
@@ -1031,7 +1039,7 @@ static int snd_via8233_playback_prepare(struct snd_pcm_substream *substream)
        else
                rbits = (0x100000 / 48000) * runtime->rate +
                        ((0x100000 % 48000) * runtime->rate) / 48000;
-       snd_assert((rbits & ~0xfffff) == 0, return -EINVAL);
+       snd_BUG_ON(rbits & ~0xfffff);
        snd_via82xx_channel_reset(chip, viadev);
        snd_via82xx_set_table_ptr(chip, viadev);
        outb(chip->playback_volume[viadev->reg_offset / 0x10][0],
@@ -1138,9 +1146,9 @@ static struct snd_pcm_hardware snd_via82xx_hw =
        .rate_max =             48000,
        .channels_min =         1,
        .channels_max =         2,
-       .buffer_bytes_max =     128 * 1024,
+       .buffer_bytes_max =     VIA_MAX_BUFSIZE,
        .period_bytes_min =     32,
-       .period_bytes_max =     128 * 1024,
+       .period_bytes_max =     VIA_MAX_BUFSIZE / 2,
        .periods_min =          2,
        .periods_max =          VIA_TABLE_SIZE / 2,
        .fifo_size =            0,
@@ -1271,7 +1279,18 @@ static int snd_via82xx_pcm_close(struct snd_pcm_substream *substream)
        if (! ratep->used)
                ratep->rate = 0;
        spin_unlock_irq(&ratep->lock);
-
+       if (! ratep->rate) {
+               if (! viadev->direction) {
+                       snd_ac97_update_power(chip->ac97,
+                                             AC97_PCM_FRONT_DAC_RATE, 0);
+                       snd_ac97_update_power(chip->ac97,
+                                             AC97_PCM_SURR_DAC_RATE, 0);
+                       snd_ac97_update_power(chip->ac97,
+                                             AC97_PCM_LFE_DAC_RATE, 0);
+               } else
+                       snd_ac97_update_power(chip->ac97,
+                                             AC97_PCM_LR_ADC_RATE, 0);
+       }
        viadev->substream = NULL;
        return 0;
 }
@@ -1381,10 +1400,9 @@ static int __devinit snd_via8233_pcm_new(struct via82xx *chip)
        /* capture */
        init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
 
-       if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
-                                                        snd_dma_pci_data(chip->pci),
-                                                        64*1024, 128*1024)) < 0)
-               return err;
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
+                                             snd_dma_pci_data(chip->pci),
+                                             64*1024, VIA_MAX_BUFSIZE);
 
        /* PCM #1:  multi-channel playback and 2nd capture */
        err = snd_pcm_new(chip->card, chip->card->shortname, 1, 1, 1, &pcm);
@@ -1400,11 +1418,9 @@ static int __devinit snd_via8233_pcm_new(struct via82xx *chip)
        /* set up capture */
        init_viadev(chip, chip->capture_devno + 1, VIA_REG_CAPTURE_8233_STATUS + 0x10, 7, 1);
 
-       if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
-                                                        snd_dma_pci_data(chip->pci),
-                                                        64*1024, 128*1024)) < 0)
-               return err;
-
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
+                                             snd_dma_pci_data(chip->pci),
+                                             64*1024, VIA_MAX_BUFSIZE);
        return 0;
 }
 
@@ -1436,10 +1452,9 @@ static int __devinit snd_via8233a_pcm_new(struct via82xx *chip)
        /* capture */
        init_viadev(chip, chip->capture_devno, VIA_REG_CAPTURE_8233_STATUS, 6, 1);
 
-       if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
-                                                        snd_dma_pci_data(chip->pci),
-                                                        64*1024, 128*1024)) < 0)
-               return err;
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
+                                             snd_dma_pci_data(chip->pci),
+                                             64*1024, VIA_MAX_BUFSIZE);
 
        /* SPDIF supported? */
        if (! ac97_can_spdif(chip->ac97))
@@ -1456,11 +1471,9 @@ static int __devinit snd_via8233a_pcm_new(struct via82xx *chip)
        /* set up playback */
        init_viadev(chip, chip->playback_devno, 0x30, 3, 0);
 
-       if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
-                                                        snd_dma_pci_data(chip->pci),
-                                                        64*1024, 128*1024)) < 0)
-               return err;
-
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
+                                             snd_dma_pci_data(chip->pci),
+                                             64*1024, VIA_MAX_BUFSIZE);
        return 0;
 }
 
@@ -1488,11 +1501,9 @@ static int __devinit snd_via686_pcm_new(struct via82xx *chip)
        init_viadev(chip, 0, VIA_REG_PLAYBACK_STATUS, 0, 0);
        init_viadev(chip, 1, VIA_REG_CAPTURE_STATUS, 0, 1);
 
-       if ((err = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
-                                                        snd_dma_pci_data(chip->pci),
-                                                        64*1024, 128*1024)) < 0)
-               return err;
-
+       snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
+                                             snd_dma_pci_data(chip->pci),
+                                             64*1024, VIA_MAX_BUFSIZE);
        return 0;
 }
 
@@ -1554,15 +1565,7 @@ static struct snd_kcontrol_new snd_via8233_capture_source __devinitdata = {
        .put = snd_via8233_capture_source_put,
 };
 
-static int snd_via8233_dxs3_spdif_info(struct snd_kcontrol *kcontrol,
-                                      struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define snd_via8233_dxs3_spdif_info    snd_ctl_boolean_mono_info
 
 static int snd_via8233_dxs3_spdif_get(struct snd_kcontrol *kcontrol,
                                      struct snd_ctl_elem_value *ucontrol)
@@ -1681,21 +1684,29 @@ static int snd_via8233_pcmdxs_volume_put(struct snd_kcontrol *kcontrol,
        return change;
 }
 
+static const DECLARE_TLV_DB_SCALE(db_scale_dxs, -9450, 150, 1);
+
 static struct snd_kcontrol_new snd_via8233_pcmdxs_volume_control __devinitdata = {
        .name = "PCM Playback Volume",
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                  SNDRV_CTL_ELEM_ACCESS_TLV_READ),
        .info = snd_via8233_dxs_volume_info,
        .get = snd_via8233_pcmdxs_volume_get,
        .put = snd_via8233_pcmdxs_volume_put,
+       .tlv = { .p = db_scale_dxs }
 };
 
 static struct snd_kcontrol_new snd_via8233_dxs_volume_control __devinitdata = {
        .name = "VIA DXS Playback Volume",
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+       .access = (SNDRV_CTL_ELEM_ACCESS_READWRITE |
+                  SNDRV_CTL_ELEM_ACCESS_TLV_READ),
        .count = 4,
        .info = snd_via8233_dxs_volume_info,
        .get = snd_via8233_dxs_volume_get,
        .put = snd_via8233_dxs_volume_put,
+       .tlv = { .p = db_scale_dxs }
 };
 
 /*
@@ -1740,6 +1751,12 @@ static struct ac97_quirk ac97_quirks[] = {
                .type = AC97_TUNE_HP_ONLY
        },
        {
+               .subvendor = 0x1019,
+               .subdevice = 0x1841,
+               .name = "ECS K7VTA3",
+               .type = AC97_TUNE_HP_ONLY
+       },
+       {
                .subvendor = 0x1849,
                .subdevice = 0x3059,
                .name = "ASRock K7VM2",
@@ -1769,6 +1786,18 @@ static struct ac97_quirk ac97_quirks[] = {
                .name = "Targa Traveller 811",
                .type = AC97_TUNE_HP_ONLY,
        },
+       {
+               .subvendor = 0x161f,
+               .subdevice = 0x2032,
+               .name = "m680x",
+               .type = AC97_TUNE_HP_ONLY, /* http://launchpad.net/bugs/38546 */
+       },
+       {
+               .subvendor = 0x1297,
+               .subdevice = 0xa232,
+               .name = "Shuttle AK32VN",
+               .type = AC97_TUNE_HP_ONLY
+       },
        { } /* terminator */
 };
 
@@ -1791,7 +1820,7 @@ static int __devinit snd_via82xx_mixer_new(struct via82xx *chip, const char *qui
        ac97.private_data = chip;
        ac97.private_free = snd_via82xx_mixer_free_ac97;
        ac97.pci = chip->pci;
-       ac97.scaps = AC97_SCAP_SKIP_MODEM;
+       ac97.scaps = AC97_SCAP_SKIP_MODEM | AC97_SCAP_POWER_SAVE;
        if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
                return err;
 
@@ -1967,7 +1996,7 @@ static int __devinit snd_via686_init_misc(struct via82xx *chip)
        pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
        if (chip->mpu_res) {
                if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
-                                       mpu_port, 1,
+                                       mpu_port, MPU401_INFO_INTEGRATED,
                                        chip->irq, 0, &chip->rmidi) < 0) {
                        printk(KERN_WARNING "unable to initialize MPU-401"
                               " at 0x%lx, skipping\n", mpu_port);
@@ -2009,7 +2038,7 @@ static void __devinit snd_via82xx_proc_init(struct via82xx *chip)
        struct snd_info_entry *entry;
 
        if (! snd_card_proc_new(chip->card, "via82xx", &entry))
-               snd_info_set_text_ops(entry, chip, 1024, snd_via82xx_proc_read);
+               snd_info_set_text_ops(entry, chip, snd_via82xx_proc_read);
 }
 
 /*
@@ -2085,7 +2114,7 @@ static int snd_via82xx_chip_init(struct via82xx *chip)
                        chip->ac97_secondary = 1;
                        goto __ac97_ok2;
                }
-               schedule_timeout_interruptible(1);
+               schedule_timeout_uninterruptible(1);
        } while (time_before(jiffies, end_time));
        /* This is ok, the most of motherboards have only one codec */
 
@@ -2153,9 +2182,9 @@ static int snd_via82xx_suspend(struct pci_dev *pci, pm_message_t state)
                chip->capture_src_saved[1] = inb(chip->port + VIA_REG_CAPTURE_CHANNEL + 0x10);
        }
 
-       pci_set_power_state(pci, PCI_D3hot);
        pci_disable_device(pci);
        pci_save_state(pci);
+       pci_set_power_state(pci, pci_choose_state(pci, state));
        return 0;
 }
 
@@ -2165,9 +2194,15 @@ static int snd_via82xx_resume(struct pci_dev *pci)
        struct via82xx *chip = card->private_data;
        int i;
 
-       pci_restore_state(pci);
-       pci_enable_device(pci);
        pci_set_power_state(pci, PCI_D0);
+       pci_restore_state(pci);
+       if (pci_enable_device(pci) < 0) {
+               printk(KERN_ERR "via82xx: pci_enable_device failed, "
+                      "disabling device\n");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
+       pci_set_master(pci);
 
        snd_via82xx_chip_init(chip);
 
@@ -2201,10 +2236,10 @@ static int snd_via82xx_free(struct via82xx *chip)
        /* disable interrupts */
        for (i = 0; i < chip->num_devs; i++)
                snd_via82xx_channel_reset(chip, &chip->devs[i]);
-       synchronize_irq(chip->irq);
-      __end_hw:
+
        if (chip->irq >= 0)
                free_irq(chip->irq, chip);
+ __end_hw:
        release_and_free_resource(chip->mpu_res);
        pci_release_regions(chip->pci);
 
@@ -2269,7 +2304,7 @@ static int __devinit snd_via82xx_create(struct snd_card *card,
        if (request_irq(pci->irq,
                        chip_type == TYPE_VIA8233 ?
                        snd_via8233_interrupt : snd_via686_interrupt,
-                       SA_INTERRUPT|SA_SHIRQ,
+                       IRQF_SHARED,
                        card->driver, chip)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_via82xx_free(chip);
@@ -2313,98 +2348,72 @@ static struct via823x_info via823x_cards[] __devinitdata = {
        { VIA_REV_8233A, "VIA 8233A", TYPE_VIA8233A },
        { VIA_REV_8235, "VIA 8235", TYPE_VIA8233 },
        { VIA_REV_8237, "VIA 8237", TYPE_VIA8233 },
+       { VIA_REV_8251, "VIA 8251", TYPE_VIA8233 },
 };
 
 /*
  * auto detection of DXS channel supports.
  */
-struct dxs_whitelist {
-       unsigned short subvendor;
-       unsigned short subdevice; 
-       unsigned short mask; 
-       short action;   /* new dxs_support value */
-};
 
-static int __devinit check_dxs_list(struct pci_dev *pci)
-{
-       static struct dxs_whitelist whitelist[] = {
-               { .subvendor = 0x1005, .subdevice = 0x4710, .action = VIA_DXS_ENABLE }, /* Avance Logic Mobo */
-               { .subvendor = 0x1019, .subdevice = 0x0996, .action = VIA_DXS_48K },
-               { .subvendor = 0x1019, .subdevice = 0x0a81, .action = VIA_DXS_NO_VRA }, /* ECS K7VTA3 v8.0 */
-               { .subvendor = 0x1019, .subdevice = 0x0a85, .action = VIA_DXS_NO_VRA }, /* ECS L7VMM2 */
-               { .subvendor = 0x1019, .subdevice = 0xa101, .action = VIA_DXS_SRC },
-               { .subvendor = 0x1019, .subdevice = 0xaa01, .action = VIA_DXS_SRC }, /* ECS K8T890-A */
-               { .subvendor = 0x1025, .subdevice = 0x0033, .action = VIA_DXS_NO_VRA }, /* Acer Inspire 1353LM */
-               { .subvendor = 0x1025, .subdevice = 0x0046, .action = VIA_DXS_SRC }, /* Acer Aspire 1524 WLMi */
-               { .subvendor = 0x1043, .subdevice = 0x8095, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8X (FIXME: possibly VIA_DXS_ENABLE?)*/
-               { .subvendor = 0x1043, .subdevice = 0x80a1, .action = VIA_DXS_NO_VRA }, /* ASUS A7V8-X */
-               { .subvendor = 0x1043, .subdevice = 0x80b0, .action = VIA_DXS_NO_VRA }, /* ASUS A7V600 & K8V*/ 
-               { .subvendor = 0x1043, .subdevice = 0x810d, .action = VIA_DXS_SRC }, /* ASUS */
-               { .subvendor = 0x1043, .subdevice = 0x812a, .action = VIA_DXS_SRC    }, /* ASUS A8V Deluxe */ 
-               { .subvendor = 0x1043, .subdevice = 0x8174, .action = VIA_DXS_SRC    }, /* ASUS */
-               { .subvendor = 0x1071, .subdevice = 0x8375, .action = VIA_DXS_NO_VRA }, /* Vobis/Yakumo/Mitac notebook */
-               { .subvendor = 0x1071, .subdevice = 0x8399, .action = VIA_DXS_NO_VRA }, /* Umax AB 595T (VIA K8N800A - VT8237) */
-               { .subvendor = 0x10cf, .subdevice = 0x118e, .action = VIA_DXS_ENABLE }, /* FSC laptop */
-               { .subvendor = 0x1106, .subdevice = 0x4161, .action = VIA_DXS_NO_VRA }, /* ASRock K7VT2 */
-               { .subvendor = 0x1106, .subdevice = 0x4552, .action = VIA_DXS_NO_VRA }, /* QDI Kudoz 7X/600-6AL */
-               { .subvendor = 0x1106, .subdevice = 0xaa01, .action = VIA_DXS_NO_VRA }, /* EPIA MII */
-               { .subvendor = 0x1106, .subdevice = 0xc001, .action = VIA_DXS_SRC }, /* Insight P4-ITX */
-               { .subvendor = 0x1297, .subdevice = 0xa232, .action = VIA_DXS_ENABLE }, /* Shuttle ?? */
-               { .subvendor = 0x1297, .subdevice = 0xc160, .action = VIA_DXS_ENABLE }, /* Shuttle SK41G */
-               { .subvendor = 0x1458, .subdevice = 0xa002, .action = VIA_DXS_ENABLE }, /* Gigabyte GA-7VAXP */
-               { .subvendor = 0x1462, .subdevice = 0x0080, .action = VIA_DXS_SRC }, /* MSI K8T Neo-FIS2R */
-               { .subvendor = 0x1462, .subdevice = 0x0430, .action = VIA_DXS_SRC }, /* MSI 7142 (K8MM-V) */
-               { .subvendor = 0x1462, .subdevice = 0x0470, .action = VIA_DXS_SRC }, /* MSI KT880 Delta-FSR */
-               { .subvendor = 0x1462, .subdevice = 0x3800, .action = VIA_DXS_ENABLE }, /* MSI KT266 */
-               { .subvendor = 0x1462, .subdevice = 0x5901, .action = VIA_DXS_NO_VRA }, /* MSI KT6 Delta-SR */
-               { .subvendor = 0x1462, .subdevice = 0x7023, .action = VIA_DXS_NO_VRA }, /* MSI K8T Neo2-FI */
-               { .subvendor = 0x1462, .subdevice = 0x7120, .action = VIA_DXS_ENABLE }, /* MSI KT4V */
-               { .subvendor = 0x1462, .subdevice = 0x7142, .action = VIA_DXS_ENABLE }, /* MSI K8MM-V */
-               { .subvendor = 0x1462, .subdevice = 0xb012, .action = VIA_DXS_SRC }, /* P4M800/VIA8237R */
-               { .subvendor = 0x147b, .subdevice = 0x1401, .action = VIA_DXS_ENABLE }, /* ABIT KD7(-RAID) */
-               { .subvendor = 0x147b, .subdevice = 0x1411, .action = VIA_DXS_ENABLE }, /* ABIT VA-20 */
-               { .subvendor = 0x147b, .subdevice = 0x1413, .action = VIA_DXS_ENABLE }, /* ABIT KV8 Pro */
-               { .subvendor = 0x147b, .subdevice = 0x1415, .action = VIA_DXS_NO_VRA }, /* Abit AV8 */
-               { .subvendor = 0x14ff, .subdevice = 0x0403, .action = VIA_DXS_ENABLE }, /* Twinhead mobo */
-               { .subvendor = 0x14ff, .subdevice = 0x0408, .action = VIA_DXS_SRC }, /* Twinhead laptop */
-               { .subvendor = 0x1558, .subdevice = 0x4701, .action = VIA_DXS_SRC }, /* Clevo D470 */
-               { .subvendor = 0x1584, .subdevice = 0x8120, .action = VIA_DXS_ENABLE }, /* Gericom/Targa/Vobis/Uniwill laptop */
-               { .subvendor = 0x1584, .subdevice = 0x8123, .action = VIA_DXS_NO_VRA }, /* Uniwill (Targa Visionary XP-210) */
-               { .subvendor = 0x161f, .subdevice = 0x202b, .action = VIA_DXS_NO_VRA }, /* Amira Note book */
-               { .subvendor = 0x161f, .subdevice = 0x2032, .action = VIA_DXS_48K }, /* m680x machines */
-               { .subvendor = 0x1631, .subdevice = 0xe004, .action = VIA_DXS_ENABLE }, /* Easy Note 3174, Packard Bell */
-               { .subvendor = 0x1695, .subdevice = 0x3005, .action = VIA_DXS_ENABLE }, /* EPoX EP-8K9A */
-               { .subvendor = 0x1695, .subdevice = 0x300c, .action = VIA_DXS_SRC }, /* EPoX EP-8KRAI */
-               { .subvendor = 0x1695, .subdevice = 0x300e, .action = VIA_DXS_SRC }, /* EPoX 9HEAI */
-               { .subvendor = 0x16f3, .subdevice = 0x6405, .action = VIA_DXS_SRC }, /* Jetway K8M8MS */
-               { .subvendor = 0x1734, .subdevice = 0x1078, .action = VIA_DXS_SRC }, /* FSC Amilo L7300 */
-               { .subvendor = 0x1734, .subdevice = 0x1093, .action = VIA_DXS_SRC }, /* FSC */
-               { .subvendor = 0x1849, .subdevice = 0x3059, .action = VIA_DXS_NO_VRA }, /* ASRock K7VM2 */
-               { .subvendor = 0x1849, .subdevice = 0x9739, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */
-               { .subvendor = 0x1849, .subdevice = 0x9761, .action = VIA_DXS_SRC }, /* ASRock mobo(?) */
-               { .subvendor = 0x1919, .subdevice = 0x200a, .action = VIA_DXS_NO_VRA }, /* Soltek SL-K8Tpro-939 */
-               { .subvendor = 0x4005, .subdevice = 0x4710, .action = VIA_DXS_SRC },    /* MSI K7T266 Pro2 (MS-6380 V2.0) BIOS 3.7 */
-               { } /* terminator */
-       };
-       struct dxs_whitelist *w;
-       unsigned short subsystem_vendor;
-       unsigned short subsystem_device;
+static struct snd_pci_quirk dxs_whitelist[] __devinitdata = {
+       SND_PCI_QUIRK(0x1005, 0x4710, "Avance Logic Mobo", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1019, 0x0996, "ESC Mobo", VIA_DXS_48K),
+       SND_PCI_QUIRK(0x1019, 0x0a81, "ECS K7VTA3 v8.0", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x1019, 0x0a85, "ECS L7VMM2", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x1019, 0, "ESC K8", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1019, 0xaa01, "ESC K8T890-A", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1025, 0x0033, "Acer Inspire 1353LM", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x1025, 0x0046, "Acer Aspire 1524 WLMi", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1043, 0, "ASUS A7/A8", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x1071, 0, "Diverse Notebook", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x10cf, 0x118e, "FSC Laptop", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1106, 0, "ASRock", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1297, 0xa231, "Shuttle AK31v2", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1297, 0xa232, "Shuttle", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1297, 0xc160, "Shuttle Sk41G", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte GA-7VAXP", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1462, 0x3800, "MSI KT266", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1462, 0x7120, "MSI KT4V", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1462, 0x7142, "MSI K8MM-V", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1462, 0, "MSI Mobo", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x147b, 0x1401, "ABIT KD7(-RAID)", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x147b, 0x1411, "ABIT VA-20", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x147b, 0x1413, "ABIT KV8 Pro", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x147b, 0x1415, "ABIT AV8", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x14ff, 0x0403, "Twinhead mobo", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x14ff, 0x0408, "Twinhead laptop", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1558, 0x4701, "Clevo D470", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1584, 0x8120, "Diverse Laptop", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1584, 0x8123, "Targa/Uniwill", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x161f, 0x202b, "Amira Notebook", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x161f, 0x2032, "m680x machines", VIA_DXS_48K),
+       SND_PCI_QUIRK(0x1631, 0xe004, "PB EasyNote 3174", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1695, 0x3005, "EPoX EP-8K9A", VIA_DXS_ENABLE),
+       SND_PCI_QUIRK(0x1695, 0, "EPoX mobo", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x16f3, 0, "Jetway K8", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1734, 0, "FSC Laptop", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1849, 0x3059, "ASRock K7VM2", VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x1849, 0, "ASRock mobo", VIA_DXS_SRC),
+       SND_PCI_QUIRK(0x1919, 0x200a, "Soltek SL-K8",  VIA_DXS_NO_VRA),
+       SND_PCI_QUIRK(0x4005, 0x4710, "MSI K7T266", VIA_DXS_SRC),
+       { } /* terminator */
+};
 
-       pci_read_config_word(pci, PCI_SUBSYSTEM_VENDOR_ID, &subsystem_vendor);
-       pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &subsystem_device);
+static int __devinit check_dxs_list(struct pci_dev *pci, int revision)
+{
+       const struct snd_pci_quirk *w;
 
-       for (w = whitelist; w->subvendor; w++) {
-               if (w->subvendor != subsystem_vendor)
-                       continue;
-               if (w->mask) {
-                       if ((w->mask & subsystem_device) == w->subdevice)
-                               return w->action;
-               } else {
-                       if (subsystem_device == w->subdevice)
-                               return w->action;
-               }
+       w = snd_pci_quirk_lookup(pci, dxs_whitelist);
+       if (w) {
+               snd_printdd(KERN_INFO "via82xx: DXS white list for %s found\n",
+                           w->name);
+               return w->value;
        }
 
+       /* for newer revision, default to DXS_SRC */
+       if (revision >= VIA_REV_8235)
+               return VIA_DXS_SRC;
+
        /*
         * not detected, try 48k rate only to be sure.
         */
@@ -2420,28 +2429,26 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
 {
        struct snd_card *card;
        struct via82xx *chip;
-       unsigned char revision;
        int chip_type = 0, card_type;
        unsigned int i;
        int err;
 
-       card = snd_card_new(index, id, THIS_MODULE, 0);
-       if (card == NULL)
-               return -ENOMEM;
+       err = snd_card_create(index, id, THIS_MODULE, 0, &card);
+       if (err < 0)
+               return err;
 
        card_type = pci_id->driver_data;
-       pci_read_config_byte(pci, PCI_REVISION_ID, &revision);
        switch (card_type) {
        case TYPE_CARD_VIA686:
                strcpy(card->driver, "VIA686A");
-               sprintf(card->shortname, "VIA 82C686A/B rev%x", revision);
+               sprintf(card->shortname, "VIA 82C686A/B rev%x", pci->revision);
                chip_type = TYPE_VIA686;
                break;
        case TYPE_CARD_VIA8233:
                chip_type = TYPE_VIA8233;
-               sprintf(card->shortname, "VIA 823x rev%x", revision);
+               sprintf(card->shortname, "VIA 823x rev%x", pci->revision);
                for (i = 0; i < ARRAY_SIZE(via823x_cards); i++) {
-                       if (revision == via823x_cards[i].revision) {
+                       if (pci->revision == via823x_cards[i].revision) {
                                chip_type = via823x_cards[i].type;
                                strcpy(card->shortname, via823x_cards[i].name);
                                break;
@@ -2449,7 +2456,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                }
                if (chip_type != TYPE_VIA8233A) {
                        if (dxs_support == VIA_DXS_AUTO)
-                               dxs_support = check_dxs_list(pci);
+                               dxs_support = check_dxs_list(pci, pci->revision);
                        /* force to use VIA8233 or 8233A model according to
                         * dxs_support module option
                         */
@@ -2460,7 +2467,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                }
                if (chip_type == TYPE_VIA8233A)
                        strcpy(card->driver, "VIA8233A");
-               else if (revision >= VIA_REV_8237)
+               else if (pci->revision >= VIA_REV_8237)
                        strcpy(card->driver, "VIA8237"); /* no slog assignment */
                else
                        strcpy(card->driver, "VIA8233");
@@ -2471,7 +2478,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                goto __error;
        }
                
-       if ((err = snd_via82xx_create(card, pci, chip_type, revision,
+       if ((err = snd_via82xx_create(card, pci, chip_type, pci->revision,
                                      ac97_clock, &chip)) < 0)
                goto __error;
        card->private_data = chip;