[ALSA] es1938 - Fix resume
[powerpc.git] / sound / pci / via82xx.c
index 4889600..78a5dfb 100644 (file)
@@ -73,44 +73,37 @@ MODULE_SUPPORTED_DEVICE("{{VIA,VT82C686A/B/C,pci},{VIA,VT8233A/C,8235}}");
 #define SUPPORT_JOYSTICK 1
 #endif
 
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;     /* Enable this card */
-static long mpu_port[SNDRV_CARDS];
+static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
+static char *id = SNDRV_DEFAULT_STR1;  /* ID for this card */
+static long mpu_port;
 #ifdef SUPPORT_JOYSTICK
-static int joystick[SNDRV_CARDS];
+static int joystick;
 #endif
-static int ac97_clock[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 48000};
-static char *ac97_quirk[SNDRV_CARDS];
-static int dxs_support[SNDRV_CARDS];
+static int ac97_clock = 48000;
+static char *ac97_quirk;
+static int dxs_support;
 
-module_param_array(index, int, NULL, 0444);
+module_param(index, int, 0444);
 MODULE_PARM_DESC(index, "Index value for VIA 82xx bridge.");
-module_param_array(id, charp, NULL, 0444);
+module_param(id, charp, 0444);
 MODULE_PARM_DESC(id, "ID string for VIA 82xx bridge.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable audio part of VIA 82xx bridge.");
-module_param_array(mpu_port, long, NULL, 0444);
+module_param(mpu_port, long, 0444);
 MODULE_PARM_DESC(mpu_port, "MPU-401 port. (VT82C686x only)");
 #ifdef SUPPORT_JOYSTICK
-module_param_array(joystick, bool, NULL, 0444);
+module_param(joystick, bool, 0444);
 MODULE_PARM_DESC(joystick, "Enable joystick. (VT82C686x only)");
 #endif
-module_param_array(ac97_clock, int, NULL, 0444);
+module_param(ac97_clock, int, 0444);
 MODULE_PARM_DESC(ac97_clock, "AC'97 codec clock (default 48000Hz).");
-module_param_array(ac97_quirk, charp, NULL, 0444);
+module_param(ac97_quirk, charp, 0444);
 MODULE_PARM_DESC(ac97_quirk, "AC'97 workaround for strange hardware.");
-module_param_array(dxs_support, int, NULL, 0444);
+module_param(dxs_support, int, 0444);
 MODULE_PARM_DESC(dxs_support, "Support for DXS channels (0 = auto, 1 = enable, 2 = disable, 3 = 48k only, 4 = no VRA, 5 = enable any sample rate)");
 
+/* just for backward compatibility */
+static int enable;
+module_param(enable, int, 0444);
 
-/* pci ids */
-#ifndef PCI_DEVICE_ID_VIA_82C686_5
-#define PCI_DEVICE_ID_VIA_82C686_5     0x3058
-#endif
-#ifndef PCI_DEVICE_ID_VIA_8233_5
-#define PCI_DEVICE_ID_VIA_8233_5       0x3059
-#endif
 
 /* revision numbers for via686 */
 #define VIA_REV_686_A          0x10
@@ -663,10 +656,12 @@ static int snd_via82xx_pcm_trigger(snd_pcm_substream_t * substream, int cmd)
                val = 0;
        switch (cmd) {
        case SNDRV_PCM_TRIGGER_START:
+       case SNDRV_PCM_TRIGGER_RESUME:
                val |= VIA_REG_CTRL_START;
                viadev->running = 1;
                break;
        case SNDRV_PCM_TRIGGER_STOP:
+       case SNDRV_PCM_TRIGGER_SUSPEND:
                val = VIA_REG_CTRL_TERMINATE;
                viadev->running = 0;
                break;
@@ -929,12 +924,12 @@ static int snd_via8233_playback_prepare(snd_pcm_substream_t *substream)
 
        if ((rate_changed = via_lock_rate(&chip->rates[0], ac97_rate)) < 0)
                return rate_changed;
-       if (rate_changed) {
+       if (rate_changed)
                snd_ac97_set_rate(chip->ac97, AC97_PCM_FRONT_DAC_RATE,
                                  chip->no_vra ? 48000 : runtime->rate);
-               snd_ac97_set_rate(chip->ac97, AC97_SPDIF,
-                                 chip->no_vra ? 48000 : runtime->rate);
-       }
+       if (chip->spdif_on && viadev->reg_offset == 0x30)
+               snd_ac97_set_rate(chip->ac97, AC97_SPDIF, runtime->rate);
+
        if (runtime->rate == 48000)
                rbits = 0xfffff;
        else
@@ -1035,7 +1030,7 @@ static snd_pcm_hardware_t snd_via82xx_hw =
        .info =                 (SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                                 SNDRV_PCM_INFO_BLOCK_TRANSFER |
                                 SNDRV_PCM_INFO_MMAP_VALID |
-                                SNDRV_PCM_INFO_RESUME |
+                                /* SNDRV_PCM_INFO_RESUME | */
                                 SNDRV_PCM_INFO_PAUSE),
        .formats =              SNDRV_PCM_FMTBIT_U8 | SNDRV_PCM_FMTBIT_S16_LE,
        .rates =                SNDRV_PCM_RATE_48000,
@@ -1484,7 +1479,7 @@ static int snd_via8233_dxs3_spdif_put(snd_kcontrol_t *kcontrol, snd_ctl_elem_val
 }
 
 static snd_kcontrol_new_t snd_via8233_dxs3_spdif_control __devinitdata = {
-       .name = "IEC958 Output Switch",
+       .name = SNDRV_CTL_NAME_IEC958("Output ",NONE,SWITCH),
        .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
        .info = snd_via8233_dxs3_spdif_info,
        .get = snd_via8233_dxs3_spdif_get,
@@ -1622,12 +1617,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
                return err;
        chip->ac97_bus->private_free = snd_via82xx_mixer_free_ac97_bus;
        chip->ac97_bus->clock = chip->ac97_clock;
-       chip->ac97_bus->shared_type = AC97_SHARED_TYPE_VIA;
 
        memset(&ac97, 0, sizeof(ac97));
        ac97.private_data = chip;
        ac97.private_free = snd_via82xx_mixer_free_ac97;
        ac97.pci = chip->pci;
+       ac97.scaps = AC97_SCAP_SKIP_MODEM;
        if ((err = snd_ac97_mixer(chip->ac97_bus, &ac97, &chip->ac97)) < 0)
                return err;
 
@@ -1643,12 +1638,12 @@ static int __devinit snd_via82xx_mixer_new(via82xx_t *chip, const char *quirk_ov
 
 #ifdef SUPPORT_JOYSTICK
 #define JOYSTICK_ADDR  0x200
-static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy)
+static int __devinit snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
 {
        struct gameport *gp;
        struct resource *r;
 
-       if (!joystick[dev])
+       if (!joystick)
                return -ENODEV;
 
        r = request_region(JOYSTICK_ADDR, 8, "VIA686 gameport");
@@ -1660,8 +1655,7 @@ static int __devinit snd_via686_create_gameport(via82xx_t *chip, int dev, unsign
        chip->gameport = gp = gameport_allocate_port();
        if (!gp) {
                printk(KERN_ERR "via82xx: cannot allocate memory for gameport\n");
-               release_resource(r);
-               kfree_nocheck(r);
+               release_and_free_resource(r);
                return -ENOMEM;
        }
 
@@ -1687,12 +1681,11 @@ static void snd_via686_free_gameport(via82xx_t *chip)
 
                gameport_unregister_port(chip->gameport);
                chip->gameport = NULL;
-               release_resource(r);
-               kfree_nocheck(r);
+               release_and_free_resource(r);
        }
 }
 #else
-static inline int snd_via686_create_gameport(via82xx_t *chip, int dev, unsigned char *legacy)
+static inline int snd_via686_create_gameport(via82xx_t *chip, unsigned char *legacy)
 {
        return -ENOSYS;
 }
@@ -1704,7 +1697,7 @@ static inline void snd_via686_free_gameport(via82xx_t *chip) { }
  *
  */
 
-static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
+static int __devinit snd_via8233_init_misc(via82xx_t *chip)
 {
        int i, err, caps;
        unsigned char val;
@@ -1745,7 +1738,7 @@ static int __devinit snd_via8233_init_misc(via82xx_t *chip, int dev)
        return 0;
 }
 
-static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
+static int __devinit snd_via686_init_misc(via82xx_t *chip)
 {
        unsigned char legacy, legacy_cfg;
        int rev_h = 0;
@@ -1756,32 +1749,33 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
        legacy &= ~VIA_FUNC_ENABLE_GAME;        /* disable joystick */
        if (chip->revision >= VIA_REV_686_H) {
                rev_h = 1;
-               if (mpu_port[dev] >= 0x200) {   /* force MIDI */
-                       mpu_port[dev] &= 0xfffc;
-                       pci_write_config_dword(chip->pci, 0x18, mpu_port[dev] | 0x01);
+               if (mpu_port >= 0x200) {        /* force MIDI */
+                       mpu_port &= 0xfffc;
+                       pci_write_config_dword(chip->pci, 0x18, mpu_port | 0x01);
 #ifdef CONFIG_PM
-                       chip->mpu_port_saved = mpu_port[dev];
+                       chip->mpu_port_saved = mpu_port;
 #endif
                } else {
-                       mpu_port[dev] = pci_resource_start(chip->pci, 2);
+                       mpu_port = pci_resource_start(chip->pci, 2);
                }
        } else {
-               switch (mpu_port[dev]) {        /* force MIDI */
+               switch (mpu_port) {     /* force MIDI */
                case 0x300:
                case 0x310:
                case 0x320:
                case 0x330:
                        legacy_cfg &= ~(3 << 2);
-                       legacy_cfg |= (mpu_port[dev] & 0x0030) >> 2;
+                       legacy_cfg |= (mpu_port & 0x0030) >> 2;
                        break;
                default:                        /* no, use BIOS settings */
                        if (legacy & VIA_FUNC_ENABLE_MIDI)
-                               mpu_port[dev] = 0x300 + ((legacy_cfg & 0x000c) << 2);
+                               mpu_port = 0x300 + ((legacy_cfg & 0x000c) << 2);
                        break;
                }
        }
-       if (mpu_port[dev] >= 0x200 &&
-           (chip->mpu_res = request_region(mpu_port[dev], 2, "VIA82xx MPU401")) != NULL) {
+       if (mpu_port >= 0x200 &&
+           (chip->mpu_res = request_region(mpu_port, 2, "VIA82xx MPU401"))
+           != NULL) {
                if (rev_h)
                        legacy |= VIA_FUNC_MIDI_PNP;    /* enable PCI I/O 2 */
                legacy |= VIA_FUNC_ENABLE_MIDI;
@@ -1789,16 +1783,17 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
                if (rev_h)
                        legacy &= ~VIA_FUNC_MIDI_PNP;   /* disable PCI I/O 2 */
                legacy &= ~VIA_FUNC_ENABLE_MIDI;
-               mpu_port[dev] = 0;
+               mpu_port = 0;
        }
 
        pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
        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[dev], 1,
+                                       mpu_port, 1,
                                        chip->irq, 0, &chip->rmidi) < 0) {
-                       printk(KERN_WARNING "unable to initialize MPU-401 at 0x%lx, skipping\n", mpu_port[dev]);
+                       printk(KERN_WARNING "unable to initialize MPU-401"
+                              " at 0x%lx, skipping\n", mpu_port);
                        legacy &= ~VIA_FUNC_ENABLE_MIDI;
                } else {
                        legacy &= ~VIA_FUNC_MIDI_IRQMASK;       /* enable MIDI interrupt */
@@ -1806,7 +1801,7 @@ static int __devinit snd_via686_init_misc(via82xx_t *chip, int dev)
                pci_write_config_byte(chip->pci, VIA_FUNC_ENABLE, legacy);
        }
 
-       snd_via686_create_gameport(chip, dev, &legacy);
+       snd_via686_create_gameport(chip, &legacy);
 
 #ifdef CONFIG_PM
        chip->legacy_saved = legacy;
@@ -1933,11 +1928,12 @@ static int snd_via82xx_chip_init(via82xx_t *chip)
                 * DXS channels don't work properly with VRA if MC97 is disabled.
                 */
                struct pci_dev *pci;
-               pci = pci_find_device(0x1106, 0x3068, NULL); /* MC97 */
+               pci = pci_get_device(0x1106, 0x3068, NULL); /* MC97 */
                if (pci) {
                        unsigned char data;
                        pci_read_config_byte(pci, 0x44, &data);
                        pci_write_config_byte(pci, 0x44, data | 0x40);
+                       pci_dev_put(pci);
                }
        }
 
@@ -2025,10 +2021,7 @@ static int snd_via82xx_free(via82xx_t *chip)
       __end_hw:
        if (chip->irq >= 0)
                free_irq(chip->irq, (void *)chip);
-       if (chip->mpu_res) {
-               release_resource(chip->mpu_res);
-               kfree_nocheck(chip->mpu_res);
-       }
+       release_and_free_resource(chip->mpu_res);
        pci_release_regions(chip->pci);
 
        if (chip->chip_type == TYPE_VIA686) {
@@ -2063,7 +2056,7 @@ static int __devinit snd_via82xx_create(snd_card_t * card,
        if ((err = pci_enable_device(pci)) < 0)
                return err;
 
-       if ((chip = kcalloc(1, sizeof(*chip), GFP_KERNEL)) == NULL) {
+       if ((chip = kzalloc(sizeof(*chip), GFP_KERNEL)) == NULL) {
                pci_disable_device(pci);
                return -ENOMEM;
        }
@@ -2152,10 +2145,13 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
                { .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 = 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 = 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) */
@@ -2168,16 +2164,19 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
                { .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 = 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 = 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 */
@@ -2221,7 +2220,6 @@ static int __devinit check_dxs_list(struct pci_dev *pci)
 static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                                       const struct pci_device_id *pci_id)
 {
-       static int dev;
        snd_card_t *card;
        via82xx_t *chip;
        unsigned char revision;
@@ -2229,14 +2227,7 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
        unsigned int i;
        int err;
 
-       if (dev >= SNDRV_CARDS)
-               return -ENODEV;
-       if (!enable[dev]) {
-               dev++;
-               return -ENOENT;
-       }
-
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+       card = snd_card_new(index, id, THIS_MODULE, 0);
        if (card == NULL)
                return -ENOMEM;
 
@@ -2259,12 +2250,12 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                        }
                }
                if (chip_type != TYPE_VIA8233A) {
-                       if (dxs_support[dev] == VIA_DXS_AUTO)
-                               dxs_support[dev] = check_dxs_list(pci);
+                       if (dxs_support == VIA_DXS_AUTO)
+                               dxs_support = check_dxs_list(pci);
                        /* force to use VIA8233 or 8233A model according to
                         * dxs_support module option
                         */
-                       if (dxs_support[dev] == VIA_DXS_DISABLE)
+                       if (dxs_support == VIA_DXS_DISABLE)
                                chip_type = TYPE_VIA8233A;
                        else
                                chip_type = TYPE_VIA8233;
@@ -2282,14 +2273,15 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                goto __error;
        }
                
-       if ((err = snd_via82xx_create(card, pci, chip_type, revision, ac97_clock[dev], &chip)) < 0)
+       if ((err = snd_via82xx_create(card, pci, chip_type, revision,
+                                     ac97_clock, &chip)) < 0)
                goto __error;
-       if ((err = snd_via82xx_mixer_new(chip, ac97_quirk[dev])) < 0)
+       if ((err = snd_via82xx_mixer_new(chip, ac97_quirk)) < 0)
                goto __error;
 
        if (chip_type == TYPE_VIA686) {
                if ((err = snd_via686_pcm_new(chip)) < 0 ||
-                   (err = snd_via686_init_misc(chip, dev)) < 0)
+                   (err = snd_via686_init_misc(chip)) < 0)
                        goto __error;
        } else {
                if (chip_type == TYPE_VIA8233A) {
@@ -2299,16 +2291,16 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                } else {
                        if ((err = snd_via8233_pcm_new(chip)) < 0)
                                goto __error;
-                       if (dxs_support[dev] == VIA_DXS_48K)
+                       if (dxs_support == VIA_DXS_48K)
                                chip->dxs_fixed = 1;
-                       else if (dxs_support[dev] == VIA_DXS_NO_VRA)
+                       else if (dxs_support == VIA_DXS_NO_VRA)
                                chip->no_vra = 1;
-                       else if (dxs_support[dev] == VIA_DXS_SRC) {
+                       else if (dxs_support == VIA_DXS_SRC) {
                                chip->no_vra = 1;
                                chip->dxs_src = 1;
                        }
                }
-               if ((err = snd_via8233_init_misc(chip, dev)) < 0)
+               if ((err = snd_via8233_init_misc(chip)) < 0)
                        goto __error;
        }
 
@@ -2329,7 +2321,6 @@ static int __devinit snd_via82xx_probe(struct pci_dev *pci,
                return err;
        }
        pci_set_drvdata(pci, card);
-       dev++;
        return 0;
 
  __error:
@@ -2345,6 +2336,7 @@ static void __devexit snd_via82xx_remove(struct pci_dev *pci)
 
 static struct pci_driver driver = {
        .name = "VIA 82xx Audio",
+       .owner = THIS_MODULE,
        .id_table = snd_via82xx_ids,
        .probe = snd_via82xx_probe,
        .remove = __devexit_p(snd_via82xx_remove),