sound: use DEFINE_PCI_DEVICE_TABLE
[safe/jmp/linux-2.6] / sound / pci / emu10k1 / emu10k1x.c
index 2208dbd..df47f73 100644 (file)
@@ -29,7 +29,6 @@
  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
  *
  */
-#include <sound/driver.h>
 #include <linux/init.h>
 #include <linux/interrupt.h>
 #include <linux/pci.h>
@@ -185,7 +184,7 @@ MODULE_PARM_DESC(enable, "Enable the EMU10K1X soundcard.");
  * The hardware has 3 channels for playback and 1 for capture.
  *  - channel 0 is the front channel
  *  - channel 1 is the rear channel
- *  - channel 2 is the center/lfe chanel
+ *  - channel 2 is the center/lfe channel
  * Volume is controlled by the AC97 for the front and rear channels by
  * the PCM Playback Volume, Sigmatel Surround Playback Volume and 
  * Surround Playback Volume. The Sigmatel 4-Speaker Stereo switch affects
@@ -235,7 +234,7 @@ struct emu10k1x {
        struct resource *res_port;
        int irq;
 
-       unsigned int revision;          /* chip revision */
+       unsigned char revision;         /* chip revision */
        unsigned int serial;            /* serial number */
        unsigned short model;           /* subsystem id */
 
@@ -328,22 +327,22 @@ static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
 static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
 {
        unsigned long flags;
-       unsigned int enable;
-  
+       unsigned int intr_enable;
+
        spin_lock_irqsave(&emu->emu_lock, flags);
-       enable = inl(emu->port + INTE) | intrenb;
-       outl(enable, emu->port + INTE);
+       intr_enable = inl(emu->port + INTE) | intrenb;
+       outl(intr_enable, emu->port + INTE);
        spin_unlock_irqrestore(&emu->emu_lock, flags);
 }
 
 static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
 {
        unsigned long flags;
-       unsigned int enable;
-  
+       unsigned int intr_enable;
+
        spin_lock_irqsave(&emu->emu_lock, flags);
-       enable = inl(emu->port + INTE) & ~intrenb;
-       outl(enable, emu->port + INTE);
+       intr_enable = inl(emu->port + INTE) & ~intrenb;
+       outl(intr_enable, emu->port + INTE);
        spin_unlock_irqrestore(&emu->emu_lock, flags);
 }
 
@@ -460,7 +459,7 @@ static int snd_emu10k1x_pcm_prepare(struct snd_pcm_substream *substream)
        u32 period_size_bytes = frames_to_bytes(runtime, runtime->period_size);
        int i;
        
-       for(i=0; i < runtime->periods; i++) {
+       for(i = 0; i < runtime->periods; i++) {
                *table_base++=runtime->dma_addr+(i*period_size_bytes);
                *table_base++=period_size_bytes<<16;
        }
@@ -755,13 +754,13 @@ static int snd_emu10k1x_free(struct emu10k1x *chip)
        // disable audio
        outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
 
+       /* release the irq */
+       if (chip->irq >= 0)
+               free_irq(chip->irq, chip);
+
        // release the i/o port
        release_and_free_resource(chip->res_port);
 
-       // release the irq
-       if (chip->irq >= 0)
-               free_irq(chip->irq, (void *)chip);
-
        // release the DMA
        if (chip->dma_buffer.area) {
                snd_dma_free_pages(&chip->dma_buffer);
@@ -780,8 +779,7 @@ static int snd_emu10k1x_dev_free(struct snd_device *device)
        return snd_emu10k1x_free(chip);
 }
 
-static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id,
-                                         struct pt_regs *regs)
+static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
 {
        unsigned int status;
 
@@ -797,9 +795,9 @@ static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id,
 
        // capture interrupt
        if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
-               struct emu10k1x_voice *pvoice = &chip->capture_voice;
-               if (pvoice->use)
-                       snd_emu10k1x_pcm_interrupt(chip, pvoice);
+               struct emu10k1x_voice *cap_voice = &chip->capture_voice;
+               if (cap_voice->use)
+                       snd_emu10k1x_pcm_interrupt(chip, cap_voice);
                else
                        snd_emu10k1x_intr_disable(chip, 
                                                  INTE_CAP_0_LOOP |
@@ -860,7 +858,6 @@ static int __devinit snd_emu10k1x_pcm(struct emu10k1x *emu, int device, struct s
        }
 
        pcm->info_flags = 0;
-       pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
        switch(device) {
        case 0:
                strcpy(pcm->name, "EMU10K1X Front");
@@ -899,8 +896,8 @@ static int __devinit snd_emu10k1x_create(struct snd_card *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) {
                snd_printk(KERN_ERR "error to set 28bit mask DMA\n");
                pci_disable_device(pci);
                return -ENXIO;
@@ -928,8 +925,7 @@ static int __devinit snd_emu10k1x_create(struct snd_card *card,
        }
 
        if (request_irq(pci->irq, snd_emu10k1x_interrupt,
-                       SA_INTERRUPT|SA_SHIRQ, "EMU10K1X",
-                       (void *)chip)) {
+                       IRQF_SHARED, "EMU10K1X", chip)) {
                snd_printk(KERN_ERR "emu10k1x: cannot grab irq %d\n", pci->irq);
                snd_emu10k1x_free(chip);
                return -EBUSY;
@@ -944,7 +940,7 @@ static int __devinit snd_emu10k1x_create(struct snd_card *card,
 
        pci_set_master(pci);
        /* read revision & serial */
-       pci_read_config_byte(pci, PCI_REVISION_ID, (char *)&chip->revision);
+       chip->revision = pci->revision;
        pci_read_config_dword(pci, PCI_SUBSYSTEM_VENDOR_ID, &chip->serial);
        pci_read_config_word(pci, PCI_SUBSYSTEM_ID, &chip->model);
        snd_printk(KERN_INFO "Model %04x Rev %08x Serial %08x\n", chip->model,
@@ -1044,8 +1040,7 @@ static void snd_emu10k1x_proc_reg_write(struct snd_info_entry *entry,
                if (sscanf(line, "%x %x %x", &reg, &channel_id, &val) != 3)
                        continue;
 
-               if ((reg < 0x49) && (reg >=0) && (val <= 0xffffffff) 
-                   && (channel_id >=0) && (channel_id <= 2) )
+               if (reg < 0x49 && val <= 0xffffffff && channel_id <= 2)
                        snd_emu10k1x_ptr_write(emu, reg, channel_id, val);
        }
 }
@@ -1055,8 +1050,7 @@ static int __devinit snd_emu10k1x_proc_init(struct emu10k1x * emu)
        struct snd_info_entry *entry;
        
        if(! snd_card_proc_new(emu->card, "emu10k1x_regs", &entry)) {
-               snd_info_set_text_ops(entry, emu, 1024, snd_emu10k1x_proc_reg_read);
-               entry->c.text.write_size = 64;
+               snd_info_set_text_ops(entry, emu, snd_emu10k1x_proc_reg_read);
                entry->c.text.write = snd_emu10k1x_proc_reg_write;
                entry->mode |= S_IWUSR;
                entry->private_data = emu;
@@ -1065,14 +1059,7 @@ static int __devinit snd_emu10k1x_proc_init(struct emu10k1x * emu)
        return 0;
 }
 
-static int snd_emu10k1x_shared_spdif_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
-{
-       uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
-       uinfo->count = 1;
-       uinfo->value.integer.min = 0;
-       uinfo->value.integer.max = 1;
-       return 0;
-}
+#define snd_emu10k1x_shared_spdif_info snd_ctl_boolean_mono_info
 
 static int snd_emu10k1x_shared_spdif_get(struct snd_kcontrol *kcontrol,
                                         struct snd_ctl_elem_value *ucontrol)
@@ -1287,7 +1274,7 @@ static void snd_emu10k1x_midi_interrupt(struct emu10k1x *emu, unsigned int statu
        do_emu10k1x_midi_interrupt(emu, &emu->midi, status);
 }
 
-static void snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
+static int snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
                                  struct emu10k1x_midi *midi, unsigned char cmd, int ack)
 {
        unsigned long flags;
@@ -1313,11 +1300,14 @@ static void snd_emu10k1x_midi_cmd(struct emu10k1x * emu,
                ok = 1;
        }
        spin_unlock_irqrestore(&midi->input_lock, flags);
-       if (!ok)
+       if (!ok) {
                snd_printk(KERN_ERR "midi_cmd: 0x%x failed at 0x%lx (status = 0x%x, data = 0x%x)!!!\n",
                           cmd, emu->port,
                           mpu401_read_stat(emu, midi),
                           mpu401_read_data(emu, midi));
+               return 1;
+       }
+       return 0;
 }
 
 static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream)
@@ -1327,18 +1317,24 @@ static int snd_emu10k1x_midi_input_open(struct snd_rawmidi_substream *substream)
        unsigned long flags;
        
        emu = midi->emu;
-       snd_assert(emu, return -ENXIO);
+       if (snd_BUG_ON(!emu))
+               return -ENXIO;
        spin_lock_irqsave(&midi->open_lock, flags);
        midi->midi_mode |= EMU10K1X_MIDI_MODE_INPUT;
        midi->substream_input = substream;
        if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
                spin_unlock_irqrestore(&midi->open_lock, flags);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
+               if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
+                       goto error_out;
+               if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
+                       goto error_out;
        } else {
                spin_unlock_irqrestore(&midi->open_lock, flags);
        }
        return 0;
+
+error_out:
+       return -EIO;
 }
 
 static int snd_emu10k1x_midi_output_open(struct snd_rawmidi_substream *substream)
@@ -1348,18 +1344,24 @@ static int snd_emu10k1x_midi_output_open(struct snd_rawmidi_substream *substream
        unsigned long flags;
 
        emu = midi->emu;
-       snd_assert(emu, return -ENXIO);
+       if (snd_BUG_ON(!emu))
+               return -ENXIO;
        spin_lock_irqsave(&midi->open_lock, flags);
        midi->midi_mode |= EMU10K1X_MIDI_MODE_OUTPUT;
        midi->substream_output = substream;
        if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
                spin_unlock_irqrestore(&midi->open_lock, flags);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1);
+               if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 1))
+                       goto error_out;
+               if (snd_emu10k1x_midi_cmd(emu, midi, MPU401_ENTER_UART, 1))
+                       goto error_out;
        } else {
                spin_unlock_irqrestore(&midi->open_lock, flags);
        }
        return 0;
+
+error_out:
+       return -EIO;
 }
 
 static int snd_emu10k1x_midi_input_close(struct snd_rawmidi_substream *substream)
@@ -1367,20 +1369,22 @@ static int snd_emu10k1x_midi_input_close(struct snd_rawmidi_substream *substream
        struct emu10k1x *emu;
        struct emu10k1x_midi *midi = substream->rmidi->private_data;
        unsigned long flags;
+       int err = 0;
 
        emu = midi->emu;
-       snd_assert(emu, return -ENXIO);
+       if (snd_BUG_ON(!emu))
+               return -ENXIO;
        spin_lock_irqsave(&midi->open_lock, flags);
        snd_emu10k1x_intr_disable(emu, midi->rx_enable);
        midi->midi_mode &= ~EMU10K1X_MIDI_MODE_INPUT;
        midi->substream_input = NULL;
        if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_OUTPUT)) {
                spin_unlock_irqrestore(&midi->open_lock, flags);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
+               err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
        } else {
                spin_unlock_irqrestore(&midi->open_lock, flags);
        }
-       return 0;
+       return err;
 }
 
 static int snd_emu10k1x_midi_output_close(struct snd_rawmidi_substream *substream)
@@ -1388,20 +1392,22 @@ static int snd_emu10k1x_midi_output_close(struct snd_rawmidi_substream *substrea
        struct emu10k1x *emu;
        struct emu10k1x_midi *midi = substream->rmidi->private_data;
        unsigned long flags;
+       int err = 0;
 
        emu = midi->emu;
-       snd_assert(emu, return -ENXIO);
+       if (snd_BUG_ON(!emu))
+               return -ENXIO;
        spin_lock_irqsave(&midi->open_lock, flags);
        snd_emu10k1x_intr_disable(emu, midi->tx_enable);
        midi->midi_mode &= ~EMU10K1X_MIDI_MODE_OUTPUT;
        midi->substream_output = NULL;
        if (!(midi->midi_mode & EMU10K1X_MIDI_MODE_INPUT)) {
                spin_unlock_irqrestore(&midi->open_lock, flags);
-               snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
+               err = snd_emu10k1x_midi_cmd(emu, midi, MPU401_RESET, 0);
        } else {
                spin_unlock_irqrestore(&midi->open_lock, flags);
        }
-       return 0;
+       return err;
 }
 
 static void snd_emu10k1x_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
@@ -1409,7 +1415,8 @@ static void snd_emu10k1x_midi_input_trigger(struct snd_rawmidi_substream *substr
        struct emu10k1x *emu;
        struct emu10k1x_midi *midi = substream->rmidi->private_data;
        emu = midi->emu;
-       snd_assert(emu, return);
+       if (snd_BUG_ON(!emu))
+               return;
 
        if (up)
                snd_emu10k1x_intr_enable(emu, midi->rx_enable);
@@ -1424,7 +1431,8 @@ static void snd_emu10k1x_midi_output_trigger(struct snd_rawmidi_substream *subst
        unsigned long flags;
 
        emu = midi->emu;
-       snd_assert(emu, return);
+       if (snd_BUG_ON(!emu))
+               return;
 
        if (up) {
                int max = 4;
@@ -1534,9 +1542,9 @@ static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
                return -ENOENT;
        }
 
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
-       if (card == NULL)
-               return -ENOMEM;
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
+       if (err < 0)
+               return err;
 
        if ((err = snd_emu10k1x_create(card, pci, &chip)) < 0) {
                snd_card_free(card);
@@ -1578,6 +1586,8 @@ static int __devinit snd_emu10k1x_probe(struct pci_dev *pci,
        sprintf(card->longname, "%s at 0x%lx irq %i",
                card->shortname, chip->port, chip->irq);
 
+       snd_card_set_dev(card, &pci->dev);
+
        if ((err = snd_card_register(card)) < 0) {
                snd_card_free(card);
                return err;
@@ -1595,8 +1605,8 @@ static void __devexit snd_emu10k1x_remove(struct pci_dev *pci)
 }
 
 // PCI IDs
-static struct pci_device_id snd_emu10k1x_ids[] = {
-       { 0x1102, 0x0006, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },    /* Dell OEM version (EMU10K1) */
+static DEFINE_PCI_DEVICE_TABLE(snd_emu10k1x_ids) = {
+       { PCI_VDEVICE(CREATIVE, 0x0006), 0 },   /* Dell OEM version (EMU10K1) */
        { 0, }
 };
 MODULE_DEVICE_TABLE(pci, snd_emu10k1x_ids);
@@ -1612,12 +1622,7 @@ static struct pci_driver driver = {
 // initialization of the module
 static int __init alsa_card_emu10k1x_init(void)
 {
-       int err;
-
-       if ((err = pci_register_driver(&driver)) > 0)
-               return err;
-
-       return 0;
+       return pci_register_driver(&driver);
 }
 
 // clean up the module