sound: use DEFINE_PCI_DEVICE_TABLE
[safe/jmp/linux-2.6] / sound / pci / mixart / mixart.c
index b218e1d..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>
@@ -58,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, }
 };
 
@@ -469,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");
 
@@ -589,7 +591,7 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,
        /*  set up format for the stream */
        format = params_format(hw);
 
-       down(&mgr->setup_mutex);
+       mutex_lock(&mgr->setup_mutex);
 
        /* update the stream levels */
        if( stream->pcm_number <= MIXART_PCM_DIGITAL ) {
@@ -605,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;
        }
 
@@ -628,7 +631,7 @@ static int snd_mixart_hw_params(struct snd_pcm_substream *subs,
                                bufferinfo[i].available_length,
                                subs->number);
        }
-       up(&mgr->setup_mutex);
+       mutex_unlock(&mgr->setup_mutex);
 
        return err;
 }
@@ -649,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 |
@@ -670,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 |
@@ -700,13 +703,13 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
        int err = 0;
        int pcm_number;
 
-       down(&mgr->setup_mutex);
+       mutex_lock(&mgr->setup_mutex);
 
        if ( pcm == chip->pcm ) {
                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;
        }
@@ -758,7 +761,7 @@ static int snd_mixart_playback_open(struct snd_pcm_substream *subs)
        }
 
  _exit_open:
-       up(&mgr->setup_mutex);
+       mutex_unlock(&mgr->setup_mutex);
 
        return err;
 }
@@ -775,13 +778,13 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
        int err = 0;
        int pcm_number;
 
-       down(&mgr->setup_mutex);
+       mutex_lock(&mgr->setup_mutex);
 
        if ( pcm == chip->pcm ) {
                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;
        }
@@ -836,7 +839,7 @@ static int snd_mixart_capture_open(struct snd_pcm_substream *subs)
        }
 
  _exit_open:
-       up(&mgr->setup_mutex);
+       mutex_unlock(&mgr->setup_mutex);
 
        return err;
 }
@@ -849,7 +852,7 @@ static int snd_mixart_close(struct snd_pcm_substream *subs)
        struct mixart_mgr *mgr = chip->mgr;
        struct mixart_stream *stream = subs->runtime->private_data;
 
-       down(&mgr->setup_mutex);
+       mutex_lock(&mgr->setup_mutex);
 
        snd_printdd("snd_mixart_close C%d/P%d/Sub%d\n", chip->chip_idx, stream->pcm_number, subs->number);
 
@@ -868,7 +871,7 @@ static int snd_mixart_close(struct snd_pcm_substream *subs)
        stream->status    = MIXART_STREAM_STATUS_FREE;
        stream->substream = NULL;
 
-       up(&mgr->setup_mutex);
+       mutex_unlock(&mgr->setup_mutex);
        return 0;
 }
 
@@ -1008,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;
@@ -1023,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;
@@ -1063,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) {
@@ -1106,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:
@@ -1132,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:
@@ -1241,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;
        }
 
@@ -1288,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, 0xffffffff) < 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;
@@ -1313,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;
@@ -1335,12 +1344,12 @@ static int __devinit snd_mixart_probe(struct pci_dev *pci,
        mgr->msg_fifo_writeptr = 0;
 
        spin_lock_init(&mgr->msg_lock);
-       init_MUTEX(&mgr->msg_mutex);
+       mutex_init(&mgr->msg_mutex);
        init_waitqueue_head(&mgr->msg_sleep);
        atomic_set(&mgr->msg_processed, 0);
 
        /* init setup mutex*/
-       init_MUTEX(&mgr->setup_mutex);
+       mutex_init(&mgr->setup_mutex);
 
        /* init message taslket */
        tasklet_init(&mgr->msg_taskq, snd_mixart_msg_tasklet, (unsigned long) mgr);
@@ -1357,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);
@@ -1370,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;
                }