sound: use DEFINE_PCI_DEVICE_TABLE
[safe/jmp/linux-2.6] / sound / pci / mixart / mixart.c
index 43ee3b2..7e8e7da 100644 (file)
  */
 
 
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
 #include <linux/dma-mapping.h>
 #include <linux/moduleparam.h>
 #include <linux/mutex.h>
+
 #include <sound/core.h>
 #include <sound/initval.h>
 #include <sound/info.h>
@@ -60,8 +60,8 @@ MODULE_PARM_DESC(enable, "Enable Digigram " CARD_NAME " soundcard.");
 /*
  */
 
-static struct pci_device_id snd_mixart_ids[] = {
-       { 0x1057, 0x0003, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0, }, /* MC8240 */
+static DEFINE_PCI_DEVICE_TABLE(snd_mixart_ids) = {
+       { PCI_VDEVICE(MOTOROLA, 0x0003), 0, }, /* MC8240 */
        { 0, }
 };
 
@@ -471,7 +471,7 @@ static int snd_mixart_prepare(struct snd_pcm_substream *subs)
        struct snd_mixart *chip = snd_pcm_substream_chip(subs);
        struct mixart_stream *stream = subs->runtime->private_data;
 
-       /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */
+       /* TODO de façon non bloquante, réappliquer les hw_params (rate, bits, codec) */
 
        snd_printdd("snd_mixart_prepare\n");
 
@@ -607,6 +607,7 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,
        /* set the format to the board */
        err = mixart_set_format(stream, format);
        if(err < 0) {
+               mutex_unlock(&mgr->setup_mutex);
                return err;
        }
 
@@ -651,7 +652,7 @@ static int snd_mixart_hw_free(struct snd_pcm_substream *subs)
 static struct snd_pcm_hardware snd_mixart_analog_caps =
 {
        .info             = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                             SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
+                             SNDRV_PCM_INFO_MMAP_VALID |
                              SNDRV_PCM_INFO_PAUSE),
        .formats          = ( SNDRV_PCM_FMTBIT_U8 |
                              SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
@@ -672,7 +673,7 @@ static struct snd_pcm_hardware snd_mixart_analog_caps =
 static struct snd_pcm_hardware snd_mixart_digital_caps =
 {
        .info             = ( SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_INTERLEAVED |
-                             SNDRV_PCM_INFO_MMAP_VALID | SNDRV_PCM_INFO_SYNC_START |
+                             SNDRV_PCM_INFO_MMAP_VALID |
                              SNDRV_PCM_INFO_PAUSE),
        .formats          = ( SNDRV_PCM_FMTBIT_U8 |
                              SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S16_BE |
@@ -708,7 +709,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
                pcm_number = MIXART_PCM_ANALOG;
                runtime->hw = snd_mixart_analog_caps;
        } else {
-               snd_assert ( pcm == chip->pcm_dig ); 
+               snd_BUG_ON(pcm != chip->pcm_dig);
                pcm_number = MIXART_PCM_DIGITAL;
                runtime->hw = snd_mixart_digital_caps;
        }
@@ -783,7 +784,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
                pcm_number = MIXART_PCM_ANALOG;
                runtime->hw = snd_mixart_analog_caps;
        } else {
-               snd_assert ( pcm == chip->pcm_dig ); 
+               snd_BUG_ON(pcm != chip->pcm_dig);
                pcm_number = MIXART_PCM_DIGITAL;
                runtime->hw = snd_mixart_digital_caps;
        }
@@ -1010,7 +1011,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
                .dev_free = snd_mixart_chip_dev_free,
        };
 
-       mgr->chip[idx] = chip = kzalloc(sizeof(*chip), GFP_KERNEL);
+       chip = kzalloc(sizeof(*chip), GFP_KERNEL);
        if (! chip) {
                snd_printk(KERN_ERR "cannot allocate chip\n");
                return -ENOMEM;
@@ -1025,6 +1026,7 @@ static int __devinit snd_mixart_create(struct mixart_mgr *mgr, struct snd_card *
                return err;
        }
 
+       mgr->chip[idx] = chip;
        snd_card_set_dev(card, &mgr->pci->dev);
 
        return 0;
@@ -1065,7 +1067,7 @@ static int snd_mixart_free(struct mixart_mgr *mgr)
 
        /* release irq  */
        if (mgr->irq >= 0)
-               free_irq(mgr->irq, (void *)mgr);
+               free_irq(mgr->irq, mgr);
 
        /* reset board if some firmware was loaded */
        if(mgr->dsp_loaded) {
@@ -1108,13 +1110,13 @@ static long long snd_mixart_BA0_llseek(struct snd_info_entry *entry,
        offset = offset & ~3; /* 4 bytes aligned */
 
        switch(orig) {
-       case 0:  /* SEEK_SET */
+       case SEEK_SET:
                file->f_pos = offset;
                break;
-       case 1:  /* SEEK_CUR */
+       case SEEK_CUR:
                file->f_pos += offset;
                break;
-       case 2:  /* SEEK_END, offset is negative */
+       case SEEK_END: /* offset is negative */
                file->f_pos = MIXART_BA0_SIZE + offset;
                break;
        default:
@@ -1134,13 +1136,13 @@ static long long snd_mixart_BA1_llseek(struct snd_info_entry *entry,
        offset = offset & ~3; /* 4 bytes aligned */
 
        switch(orig) {
-       case 0:  /* SEEK_SET */
+       case SEEK_SET:
                file->f_pos = offset;
                break;
-       case 1:  /* SEEK_CUR */
+       case SEEK_CUR:
                file->f_pos += offset;
                break;
-       case 2: /* SEEK_END, offset is negative */
+       case SEEK_END: /* offset is negative */
                file->f_pos = MIXART_BA1_SIZE + offset;
                break;
        default:
@@ -1243,7 +1245,6 @@ static void __devinit snd_mixart_proc_init(struct snd_mixart *chip)
        /* text interface to read perf and temp meters */
        if (! snd_card_proc_new(chip->card, "board_info", &entry)) {
                entry->private_data = chip;
-               entry->c.text.read_size = 1024;
                entry->c.text.read = snd_mixart_proc_read;
        }
 
@@ -1290,7 +1291,7 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
        pci_set_master(pci);
 
        /* check if we can restrict PCI DMA transfers to 32 bits */
-       if (pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) {
+       if (pci_set_dma_mask(pci, DMA_BIT_MASK(32)) < 0) {
                snd_printk(KERN_ERR "architecture does not support 32bit PCI busmaster DMA\n");
                pci_disable_device(pci);
                return -ENXIO;
@@ -1315,11 +1316,17 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
        }
        for (i = 0; i < 2; i++) {
                mgr->mem[i].phys = pci_resource_start(pci, i);
-               mgr->mem[i].virt = ioremap_nocache(mgr->mem[i].phys,
-                                                  pci_resource_len(pci, i));
+               mgr->mem[i].virt = pci_ioremap_bar(pci, i);
+               if (!mgr->mem[i].virt) {
+                       printk(KERN_ERR "unable to remap resource 0x%lx\n",
+                              mgr->mem[i].phys);
+                       snd_mixart_free(mgr);
+                       return -EBUSY;
+               }
        }
 
-       if (request_irq(pci->irq, snd_mixart_interrupt, SA_INTERRUPT|SA_SHIRQ, CARD_NAME, (void *)mgr)) {
+       if (request_irq(pci->irq, snd_mixart_interrupt, IRQF_SHARED,
+                       CARD_NAME, mgr)) {
                snd_printk(KERN_ERR "unable to grab IRQ %d\n", pci->irq);
                snd_mixart_free(mgr);
                return -EBUSY;
@@ -1359,12 +1366,12 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
                else
                        idx = index[dev] + i;
                snprintf(tmpid, sizeof(tmpid), "%s-%d", id[dev] ? id[dev] : "MIXART", i);
-               card = snd_card_new(idx, tmpid, THIS_MODULE, 0);
+               err = snd_card_create(idx, tmpid, THIS_MODULE, 0, &card);
 
-               if (! card) {
+               if (err < 0) {
                        snd_printk(KERN_ERR "cannot allocate the card %d\n", i);
                        snd_mixart_free(mgr);
-                       return -ENOMEM;
+                       return err;
                }
 
                strcpy(card->driver, CARD_NAME);
@@ -1372,6 +1379,7 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
                sprintf(card->longname, "%s [PCM #%d]", mgr->longname, i);
 
                if ((err = snd_mixart_create(mgr, card, i)) < 0) {
+                       snd_card_free(card);
                        snd_mixart_free(mgr);
                        return err;
                }