ALSA: hda - Release assigned pin/cvt at error path of hdmi_pcm_open()
[linux-2.6.git] / sound / pci / als300.c
index 96cfb8a..8196e22 100644 (file)
  *  to keep track of what period we are in.
  */
 
-#include <sound/driver.h>
 #include <linux/delay.h>
 #include <linux/init.h>
-#include <linux/moduleparam.h>
+#include <linux/module.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
 #include <linux/interrupt.h>
 #define PLAYBACK_BLOCK_COUNTER 0x9A
 #define RECORD_BLOCK_COUNTER   0x9B
 
-#define DEBUG_CALLS    1
-#define DEBUG_PLAY_REC 1
+#define DEBUG_CALLS    0
+#define DEBUG_PLAY_REC 0
 
 #if DEBUG_CALLS
-#define snd_als300_dbgcalls(format, args...) printk(format, ##args)
-#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__)
-#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__)
+#define snd_als300_dbgcalls(format, args...) printk(KERN_DEBUG format, ##args)
+#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
+#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
 #else
 #define snd_als300_dbgcalls(format, args...)
 #define snd_als300_dbgcallenter()
@@ -116,7 +115,14 @@ MODULE_SUPPORTED_DEVICE("{{Avance Logic,ALS300},{Avance Logic,ALS300+}}");
 
 static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
 static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
+static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
+
+module_param_array(index, int, NULL, 0444);
+MODULE_PARM_DESC(index, "Index value for ALS300 sound card.");
+module_param_array(id, charp, NULL, 0444);
+MODULE_PARM_DESC(id, "ID string for ALS300 sound card.");
+module_param_array(enable, bool, NULL, 0444);
+MODULE_PARM_DESC(enable, "Enable ALS300 sound card.");
 
 struct snd_als300 {
        unsigned long port;
@@ -146,7 +152,7 @@ struct snd_als300_substream_data {
        int block_counter_register;
 };
 
-static struct pci_device_id snd_als300_ids[] = {
+static DEFINE_PCI_DEVICE_TABLE(snd_als300_ids) = {
        { 0x4005, 0x0300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300 },
        { 0x4005, 0x0308, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DEVICE_ALS300_PLUS },
        { 0, }
@@ -190,7 +196,7 @@ static int snd_als300_free(struct snd_als300 *chip)
        snd_als300_dbgcallenter();
        snd_als300_set_irq_flag(chip, IRQ_DISABLE);
        if (chip->irq >= 0)
-               free_irq(chip->irq, (void *)chip);
+               free_irq(chip->irq, chip);
        pci_release_regions(chip->pci);
        pci_disable_device(chip->pci);
        kfree(chip);
@@ -204,8 +210,7 @@ static int snd_als300_dev_free(struct snd_device *device)
        return snd_als300_free(chip);
 }
 
-static irqreturn_t snd_als300_interrupt(int irq, void *dev_id,
-                                               struct pt_regs *regs)
+static irqreturn_t snd_als300_interrupt(int irq, void *dev_id)
 {
        u8 status;
        struct snd_als300 *chip = dev_id;
@@ -236,8 +241,7 @@ static irqreturn_t snd_als300_interrupt(int irq, void *dev_id,
        return IRQ_HANDLED;
 }
 
-static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id,
-                                               struct pt_regs *regs)
+static irqreturn_t snd_als300plus_interrupt(int irq, void *dev_id)
 {
        u8 general, mpu, dram;
        struct snd_als300 *chip = dev_id;
@@ -446,7 +450,7 @@ static int snd_als300_capture_close(struct snd_pcm_substream *substream)
 }
 
 static int snd_als300_pcm_hw_params(struct snd_pcm_substream *substream,
-                                       snd_pcm_hw_params_t * hw_params)
+                                   struct snd_pcm_hw_params *hw_params)
 {
        return snd_pcm_lib_malloc_pages(substream,
                                        params_buffer_bytes(hw_params));
@@ -675,7 +679,7 @@ static void snd_als300_init(struct snd_als300 *chip)
        snd_als300_dbgcallleave();
 }
 
-static int __devinit snd_als300_create(snd_card_t *card,
+static int __devinit snd_als300_create(struct snd_card *card,
                                       struct pci_dev *pci, int chip_type,
                                       struct snd_als300 **rchip)
 {
@@ -683,7 +687,7 @@ static int __devinit snd_als300_create(snd_card_t *card,
        void *irq_handler;
        int err;
 
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free = snd_als300_dev_free,
        };
        *rchip = NULL;
@@ -692,8 +696,8 @@ static int __devinit snd_als300_create(snd_card_t *card,
        if ((err = pci_enable_device(pci)) < 0)
                return err;
 
-       if (pci_set_dma_mask(pci, DMA_28BIT_MASK) < 0 ||
-               pci_set_consistent_dma_mask(pci, DMA_28BIT_MASK) < 0) {
+       if (pci_set_dma_mask(pci, DMA_BIT_MASK(28)) < 0 ||
+               pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(28)) < 0) {
                printk(KERN_ERR "error setting 28bit DMA mask\n");
                pci_disable_device(pci);
                return -ENXIO;
@@ -724,8 +728,8 @@ static int __devinit snd_als300_create(snd_card_t *card,
        else
                irq_handler = snd_als300_interrupt;
 
-       if (request_irq(pci->irq, irq_handler, IRQF_DISABLED|IRQF_SHARED,
-                                       card->shortname, (void *)chip)) {
+       if (request_irq(pci->irq, irq_handler, IRQF_SHARED,
+                       KBUILD_MODNAME, chip)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_als300_free(chip);
                return -EBUSY;
@@ -735,7 +739,8 @@ static int __devinit snd_als300_create(snd_card_t *card,
 
        snd_als300_init(chip);
 
-       if (snd_als300_ac97(chip) < 0) {
+       err = snd_als300_ac97(chip);
+       if (err < 0) {
                snd_printk(KERN_WARNING "Could not create ac97\n");
                snd_als300_free(chip);
                return err;
@@ -770,9 +775,9 @@ static int snd_als300_suspend(struct pci_dev *pci, pm_message_t state)
        snd_pcm_suspend_all(chip->pcm);
        snd_ac97_suspend(chip->ac97);
 
-       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;
 }
 
@@ -781,9 +786,14 @@ static int snd_als300_resume(struct pci_dev *pci)
        struct snd_card *card = pci_get_drvdata(pci);
        struct snd_als300 *chip = card->private_data;
 
-       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 "als300: pci_enable_device failed, "
+                      "disabling device\n");
+               snd_card_disconnect(card);
+               return -EIO;
+       }
        pci_set_master(pci);
 
        snd_als300_init(chip);
@@ -809,10 +819,10 @@ static int __devinit snd_als300_probe(struct pci_dev *pci,
                return -ENOENT;
        }
 
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
 
-       if (card == NULL)
-               return -ENOMEM;
+       if (err < 0)
+               return err;
 
        chip_type = pci_id->driver_data;
 
@@ -843,7 +853,7 @@ static int __devinit snd_als300_probe(struct pci_dev *pci,
 }
 
 static struct pci_driver driver = {
-       .name = "ALS300",
+       .name = KBUILD_MODNAME,
        .id_table = snd_als300_ids,
        .probe = snd_als300_probe,
        .remove = __devexit_p(snd_als300_remove),