ALSA: hda: Cancel delayed work during suspend
[linux-2.6.git] / sound / pci / ad1889.c
index 999aaea..9d91d61 100644 (file)
  *     PM support
  *     MIDI support
  *     Game Port support
- *     SG DMA support (this will need *alot* of work)
+ *     SG DMA support (this will need *a lot* of work)
  */
 
 #include <linux/init.h>
 #include <linux/pci.h>
+#include <linux/dma-mapping.h>
 #include <linux/slab.h>
 #include <linux/interrupt.h>
 #include <linux/compiler.h>
 #include <linux/delay.h>
+#include <linux/module.h>
 
-#include <sound/driver.h>
 #include <sound/core.h>
 #include <sound/pcm.h>
 #include <sound/initval.h>
@@ -50,7 +51,7 @@
 #include "ad1889.h"
 #include "ac97/ac97_id.h"
 
-#define        AD1889_DRVVER   "$Revision: 1.4 $"
+#define        AD1889_DRVVER   "Version: 1.7"
 
 MODULE_AUTHOR("Kyle McMartin <kyle@parisc-linux.org>, Thibaut Varene <t-bone@parisc-linux.org>");
 MODULE_DESCRIPTION("Analog Devices AD1889 ALSA sound driver");
@@ -65,7 +66,7 @@ static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
 module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for the AD1889 soundcard.");
 
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
+static bool enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
 module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable AD1889 soundcard.");
 
@@ -87,20 +88,20 @@ struct ad1889_register_state {
 };
 
 struct snd_ad1889 {
-       snd_card_t *card;
+       struct snd_card *card;
        struct pci_dev *pci;
 
        int irq;
        unsigned long bar;
        void __iomem *iobase;
 
-       ac97_t *ac97;
-       ac97_bus_t *ac97_bus;
-       snd_pcm_t *pcm;
-       snd_info_entry_t *proc;
+       struct snd_ac97 *ac97;
+       struct snd_ac97_bus *ac97_bus;
+       struct snd_pcm *pcm;
+       struct snd_info_entry *proc;
 
-       snd_pcm_substream_t *psubs;
-       snd_pcm_substream_t *csubs;
+       struct snd_pcm_substream *psubs;
+       struct snd_pcm_substream *csubs;
 
        /* playback register state */
        struct ad1889_register_state wave;
@@ -240,15 +241,15 @@ ad1889_channel_reset(struct snd_ad1889 *chip, unsigned int channel)
        }
 }
 
-static inline u16
-snd_ad1889_ac97_read(ac97_t *ac97, unsigned short reg)
+static u16
+snd_ad1889_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
 {
        struct snd_ad1889 *chip = ac97->private_data;
        return ad1889_readw(chip, AD_AC97_BASE + reg);
 }
 
-static inline void
-snd_ad1889_ac97_write(ac97_t *ac97, unsigned short reg, unsigned short val)
+static void
+snd_ad1889_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigned short val)
 {
        struct snd_ad1889 *chip = ac97->private_data;
        ad1889_writew(chip, AD_AC97_BASE + reg, val);
@@ -264,29 +265,29 @@ snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
                mdelay(1);
        if (!retry) {
                snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n",
-                      __FUNCTION__);
+                      __func__);
                return -EIO;
        }
-       ad1889_debug("[%s] ready after %d ms\n", __FUNCTION__, 400 - retry);
+       ad1889_debug("[%s] ready after %d ms\n", __func__, 400 - retry);
 
        return 0;
 }
 
 static int 
-snd_ad1889_hw_params(snd_pcm_substream_t *substream,
-                       snd_pcm_hw_params_t *hw_params)
+snd_ad1889_hw_params(struct snd_pcm_substream *substream,
+                       struct snd_pcm_hw_params *hw_params)
 {
        return snd_pcm_lib_malloc_pages(substream, 
                                        params_buffer_bytes(hw_params));
 }
 
 static int
-snd_ad1889_hw_free(snd_pcm_substream_t *substream)
+snd_ad1889_hw_free(struct snd_pcm_substream *substream)
 {
        return snd_pcm_lib_free_pages(substream);
 }
 
-static snd_pcm_hardware_t snd_ad1889_playback_hw = {
+static struct snd_pcm_hardware snd_ad1889_playback_hw = {
        .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER,
        .formats = SNDRV_PCM_FMTBIT_S16_LE,
@@ -303,7 +304,7 @@ static snd_pcm_hardware_t snd_ad1889_playback_hw = {
        /*.fifo_size = 0,*/
 };
 
-static snd_pcm_hardware_t snd_ad1889_capture_hw = {
+static struct snd_pcm_hardware snd_ad1889_capture_hw = {
        .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
                SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_BLOCK_TRANSFER,
        .formats = SNDRV_PCM_FMTBIT_S16_LE,
@@ -321,10 +322,10 @@ static snd_pcm_hardware_t snd_ad1889_capture_hw = {
 };
 
 static int
-snd_ad1889_playback_open(snd_pcm_substream_t *ss)
+snd_ad1889_playback_open(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
-       snd_pcm_runtime_t *rt = ss->runtime;
+       struct snd_pcm_runtime *rt = ss->runtime;
 
        chip->psubs = ss;
        rt->hw = snd_ad1889_playback_hw;
@@ -333,10 +334,10 @@ snd_ad1889_playback_open(snd_pcm_substream_t *ss)
 }
 
 static int
-snd_ad1889_capture_open(snd_pcm_substream_t *ss)
+snd_ad1889_capture_open(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
-       snd_pcm_runtime_t *rt = ss->runtime;
+       struct snd_pcm_runtime *rt = ss->runtime;
 
        chip->csubs = ss;
        rt->hw = snd_ad1889_capture_hw;
@@ -345,7 +346,7 @@ snd_ad1889_capture_open(snd_pcm_substream_t *ss)
 }
 
 static int
-snd_ad1889_playback_close(snd_pcm_substream_t *ss)
+snd_ad1889_playback_close(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
        chip->psubs = NULL;
@@ -353,7 +354,7 @@ snd_ad1889_playback_close(snd_pcm_substream_t *ss)
 }
 
 static int
-snd_ad1889_capture_close(snd_pcm_substream_t *ss)
+snd_ad1889_capture_close(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
        chip->csubs = NULL;
@@ -361,10 +362,10 @@ snd_ad1889_capture_close(snd_pcm_substream_t *ss)
 }
 
 static int
-snd_ad1889_playback_prepare(snd_pcm_substream_t *ss)
+snd_ad1889_playback_prepare(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
-       snd_pcm_runtime_t *rt = ss->runtime;
+       struct snd_pcm_runtime *rt = ss->runtime;
        unsigned int size = snd_pcm_lib_buffer_bytes(ss);
        unsigned int count = snd_pcm_lib_period_bytes(ss);
        u16 reg;
@@ -411,10 +412,10 @@ snd_ad1889_playback_prepare(snd_pcm_substream_t *ss)
 }
 
 static int
-snd_ad1889_capture_prepare(snd_pcm_substream_t *ss)
+snd_ad1889_capture_prepare(struct snd_pcm_substream *ss)
 {
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
-       snd_pcm_runtime_t *rt = ss->runtime;
+       struct snd_pcm_runtime *rt = ss->runtime;
        unsigned int size = snd_pcm_lib_buffer_bytes(ss);
        unsigned int count = snd_pcm_lib_period_bytes(ss);
        u16 reg;
@@ -462,7 +463,7 @@ snd_ad1889_capture_prepare(snd_pcm_substream_t *ss)
    DMA should be *triggered* by this call.
    The WSMC "WAEN" bit triggers DMA Wave On/Off */
 static int
-snd_ad1889_playback_trigger(snd_pcm_substream_t *ss, int cmd)
+snd_ad1889_playback_trigger(struct snd_pcm_substream *ss, int cmd)
 {
        u16 wsmc;
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
@@ -503,7 +504,7 @@ snd_ad1889_playback_trigger(snd_pcm_substream_t *ss, int cmd)
    DMA should be *triggered* by this call.
    The RAMC "ADEN" bit triggers DMA ADC On/Off */
 static int
-snd_ad1889_capture_trigger(snd_pcm_substream_t *ss, int cmd)
+snd_ad1889_capture_trigger(struct snd_pcm_substream *ss, int cmd)
 {
        u16 ramc;
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
@@ -538,7 +539,7 @@ snd_ad1889_capture_trigger(snd_pcm_substream_t *ss, int cmd)
 
 /* Called in atomic context with IRQ disabled */
 static snd_pcm_uframes_t
-snd_ad1889_playback_pointer(snd_pcm_substream_t *ss)
+snd_ad1889_playback_pointer(struct snd_pcm_substream *ss)
 {
        size_t ptr = 0;
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
@@ -549,14 +550,15 @@ snd_ad1889_playback_pointer(snd_pcm_substream_t *ss)
        ptr = ad1889_readl(chip, AD_DMA_WAVCA);
        ptr -= chip->wave.addr;
        
-       snd_assert((ptr >= 0) && (ptr < chip->wave.size), return 0);
+       if (snd_BUG_ON(ptr >= chip->wave.size))
+               return 0;
        
        return bytes_to_frames(ss->runtime, ptr);
 }
 
 /* Called in atomic context with IRQ disabled */
 static snd_pcm_uframes_t
-snd_ad1889_capture_pointer(snd_pcm_substream_t *ss)
+snd_ad1889_capture_pointer(struct snd_pcm_substream *ss)
 {
        size_t ptr = 0;
        struct snd_ad1889 *chip = snd_pcm_substream_chip(ss);
@@ -567,12 +569,13 @@ snd_ad1889_capture_pointer(snd_pcm_substream_t *ss)
        ptr = ad1889_readl(chip, AD_DMA_ADCCA);
        ptr -= chip->ramc.addr;
 
-       snd_assert((ptr >= 0) && (ptr < chip->ramc.size), return 0);
+       if (snd_BUG_ON(ptr >= chip->ramc.size))
+               return 0;
        
        return bytes_to_frames(ss->runtime, ptr);
 }
 
-static snd_pcm_ops_t snd_ad1889_playback_ops = {
+static struct snd_pcm_ops snd_ad1889_playback_ops = {
        .open = snd_ad1889_playback_open,
        .close = snd_ad1889_playback_close,
        .ioctl = snd_pcm_lib_ioctl,
@@ -583,7 +586,7 @@ static snd_pcm_ops_t snd_ad1889_playback_ops = {
        .pointer = snd_ad1889_playback_pointer, 
 };
 
-static snd_pcm_ops_t snd_ad1889_capture_ops = {
+static struct snd_pcm_ops snd_ad1889_capture_ops = {
        .open = snd_ad1889_capture_open,
        .close = snd_ad1889_capture_close,
        .ioctl = snd_pcm_lib_ioctl,
@@ -595,9 +598,7 @@ static snd_pcm_ops_t snd_ad1889_capture_ops = {
 };
 
 static irqreturn_t
-snd_ad1889_interrupt(int irq, 
-                    void *dev_id, 
-                    struct pt_regs *regs)
+snd_ad1889_interrupt(int irq, void *dev_id)
 {
        unsigned long st;
        struct snd_ad1889 *chip = dev_id;
@@ -624,10 +625,10 @@ snd_ad1889_interrupt(int irq,
 }
 
 static int __devinit
-snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, snd_pcm_t **rpcm)
+snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, struct snd_pcm **rpcm)
 {
        int err;
-       snd_pcm_t *pcm;
+       struct snd_pcm *pcm;
 
        if (rpcm)
                *rpcm = NULL;
@@ -666,7 +667,7 @@ snd_ad1889_pcm_init(struct snd_ad1889 *chip, int device, snd_pcm_t **rpcm)
 }
 
 static void
-snd_ad1889_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
+snd_ad1889_proc_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
 {
        struct snd_ad1889 *chip = entry->private_data;
        u16 reg;
@@ -749,10 +750,10 @@ snd_ad1889_proc_read(snd_info_entry_t *entry, snd_info_buffer_t *buffer)
 static void __devinit
 snd_ad1889_proc_init(struct snd_ad1889 *chip)
 {
-       snd_info_entry_t *entry;
+       struct snd_info_entry *entry;
 
        if (!snd_card_proc_new(chip->card, chip->card->driver, &entry))
-               snd_info_set_text_ops(entry, chip, 1024, snd_ad1889_proc_read);
+               snd_info_set_text_ops(entry, chip, snd_ad1889_proc_read);
 }
 
 static struct ac97_quirk ac97_quirks[] = {
@@ -791,14 +792,14 @@ snd_ad1889_ac97_xinit(struct snd_ad1889 *chip)
 }
 
 static void
-snd_ad1889_ac97_bus_free(ac97_bus_t *bus)
+snd_ad1889_ac97_bus_free(struct snd_ac97_bus *bus)
 {
        struct snd_ad1889 *chip = bus->private_data;
        chip->ac97_bus = NULL;
 }
 
 static void
-snd_ad1889_ac97_free(ac97_t *ac97)
+snd_ad1889_ac97_free(struct snd_ac97 *ac97)
 {
        struct snd_ad1889 *chip = ac97->private_data;
        chip->ac97 = NULL;
@@ -808,8 +809,8 @@ static int __devinit
 snd_ad1889_ac97_init(struct snd_ad1889 *chip, const char *quirk_override)
 {
        int err;
-       ac97_template_t ac97;
-       static ac97_bus_ops_t ops = {
+       struct snd_ac97_template ac97;
+       static struct snd_ac97_bus_ops ops = {
                .write = snd_ad1889_ac97_write,
                .read = snd_ad1889_ac97_read,
        };
@@ -856,10 +857,8 @@ snd_ad1889_free(struct snd_ad1889 *chip)
 
        spin_unlock_irq(&chip->lock);
 
-       synchronize_irq(chip->irq);
-       
        if (chip->irq >= 0)
-               free_irq(chip->irq, (void*)chip);
+               free_irq(chip->irq, chip);
 
 skip_hw:
        if (chip->iobase)
@@ -872,8 +871,8 @@ skip_hw:
        return 0;
 }
 
-static inline int
-snd_ad1889_dev_free(snd_device_t *device) 
+static int
+snd_ad1889_dev_free(struct snd_device *device) 
 {
        struct snd_ad1889 *chip = device->device_data;
        return snd_ad1889_free(chip);
@@ -894,14 +893,14 @@ snd_ad1889_init(struct snd_ad1889 *chip)
 }
 
 static int __devinit
-snd_ad1889_create(snd_card_t *card,
+snd_ad1889_create(struct snd_card *card,
                  struct pci_dev *pci,
                  struct snd_ad1889 **rchip)
 {
        int err;
 
        struct snd_ad1889 *chip;
-       static snd_device_ops_t ops = {
+       static struct snd_device_ops ops = {
                .dev_free = snd_ad1889_dev_free,
        };
 
@@ -909,10 +908,10 @@ snd_ad1889_create(snd_card_t *card,
 
        if ((err = pci_enable_device(pci)) < 0)
                return err;
-       
+
        /* check PCI availability (32bit DMA) */
-       if (pci_set_dma_mask(pci, 0xffffffff) < 0 ||
-           pci_set_consistent_dma_mask(pci, 0xffffffff) < 0) {
+       if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0 ||
+           pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
                printk(KERN_ERR PFX "error setting 32-bit DMA mask.\n");
                pci_disable_device(pci);
                return -ENXIO;
@@ -934,7 +933,7 @@ snd_ad1889_create(snd_card_t *card,
                goto free_and_ret;
 
        chip->bar = pci_resource_start(pci, 0);
-       chip->iobase = ioremap_nocache(chip->bar, pci_resource_len(pci, 0));
+       chip->iobase = pci_ioremap_bar(pci, 0);
        if (chip->iobase == NULL) {
                printk(KERN_ERR PFX "unable to reserve region.\n");
                err = -EBUSY;
@@ -946,7 +945,7 @@ snd_ad1889_create(snd_card_t *card,
        spin_lock_init(&chip->lock);    /* only now can we call ad1889_free */
 
        if (request_irq(pci->irq, snd_ad1889_interrupt,
-                       SA_INTERRUPT|SA_SHIRQ, card->driver, (void*)chip)) {
+                       IRQF_SHARED, KBUILD_MODNAME, chip)) {
                printk(KERN_ERR PFX "cannot obtain IRQ %d\n", pci->irq);
                snd_ad1889_free(chip);
                return -EBUSY;
@@ -985,7 +984,7 @@ snd_ad1889_probe(struct pci_dev *pci,
 {
        int err;
        static int devno;
-       snd_card_t *card;
+       struct snd_card *card;
        struct snd_ad1889 *chip;
 
        /* (1) */
@@ -997,10 +996,10 @@ snd_ad1889_probe(struct pci_dev *pci,
        }
 
        /* (2) */
-       card = snd_card_new(index[devno], id[devno], THIS_MODULE, 0);
+       err = snd_card_create(index[devno], id[devno], THIS_MODULE, 0, &card);
        /* XXX REVISIT: we can probably allocate chip in this call */
-       if (card == NULL)
-               return -ENOMEM;
+       if (err < 0)
+               return err;
 
        strcpy(card->driver, "AD1889");
        strcpy(card->shortname, "Analog Devices AD1889");
@@ -1050,14 +1049,14 @@ snd_ad1889_remove(struct pci_dev *pci)
        pci_set_drvdata(pci, NULL);
 }
 
-static struct pci_device_id snd_ad1889_ids[] = {
+static DEFINE_PCI_DEVICE_TABLE(snd_ad1889_ids) = {
        { PCI_DEVICE(PCI_VENDOR_ID_ANALOG_DEVICES, PCI_DEVICE_ID_AD1889JS) },
        { 0, },
 };
 MODULE_DEVICE_TABLE(pci, snd_ad1889_ids);
 
-static struct pci_driver ad1889_pci = {
-       .name = "AD1889 Audio",
+static struct pci_driver ad1889_pci_driver = {
+       .name = KBUILD_MODNAME,
        .id_table = snd_ad1889_ids,
        .probe = snd_ad1889_probe,
        .remove = __devexit_p(snd_ad1889_remove),
@@ -1066,13 +1065,13 @@ static struct pci_driver ad1889_pci = {
 static int __init
 alsa_ad1889_init(void)
 {
-       return pci_register_driver(&ad1889_pci);
+       return pci_register_driver(&ad1889_pci_driver);
 }
 
 static void __exit
 alsa_ad1889_fini(void)
 {
-       pci_unregister_driver(&ad1889_pci);
+       pci_unregister_driver(&ad1889_pci_driver);
 }
 
 module_init(alsa_ad1889_init);