]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/ali5451/ali5451.c
Auto-update from upstream
[linux-2.6-omap-h63xx.git] / sound / pci / ali5451 / ali5451.c
index ce6c9fadb5948b57c185dbf44d91e783bb969de0..4e76c4a636d93e9de0d6116fd3d4fde9edd72077 100644 (file)
@@ -45,23 +45,25 @@ MODULE_DESCRIPTION("ALI M5451");
 MODULE_LICENSE("GPL");
 MODULE_SUPPORTED_DEVICE("{{ALI,M5451,pci},{ALI,M5451}}");
 
-static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;     /* Index 0-MAX */
-static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;      /* ID for this card */
-static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
-static int pcm_channels[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 32};
-static int spdif[SNDRV_CARDS] = {[0 ... (SNDRV_CARDS - 1)] = 0};
+static int index = SNDRV_DEFAULT_IDX1; /* Index */
+static char *id = SNDRV_DEFAULT_STR1;  /* ID for this card */
+static int pcm_channels = 32;
+static int spdif = 0;
 
-module_param_array(index, int, NULL, 0444);
+module_param(index, int, 0444);
 MODULE_PARM_DESC(index, "Index value for ALI M5451 PCI Audio.");
-module_param_array(id, charp, NULL, 0444);
+module_param(id, charp, 0444);
 MODULE_PARM_DESC(id, "ID string for ALI M5451 PCI Audio.");
-module_param_array(enable, bool, NULL, 0444);
-MODULE_PARM_DESC(enable, "Enable ALI 5451 PCI Audio.");
-module_param_array(pcm_channels, int, NULL, 0444);
+module_param(pcm_channels, int, 0444);
 MODULE_PARM_DESC(pcm_channels, "PCM Channels");
-module_param_array(spdif, bool, NULL, 0444);
+module_param(spdif, bool, 0444);
 MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
 
+/* just for backward compatibility */
+static int enable;
+module_param(enable, bool, 0444);
+
+
 /*
  *  Debug part definitions
  */
@@ -78,15 +80,7 @@ MODULE_PARM_DESC(spdif, "Support SPDIF I/O");
  *  Constants definition
  */
 
-#ifndef PCI_VENDOR_ID_ALI
-#define PCI_VENDOR_ID_ALI      0x10b9
-#endif
-
-#ifndef PCI_DEVICE_ID_ALI_5451
-#define PCI_DEVICE_ID_ALI_5451 0x5451
-#endif
-
-#define DEVICE_ID_ALI5451      ((PCI_VENDOR_ID_ALI<<16)|PCI_DEVICE_ID_ALI_5451)
+#define DEVICE_ID_ALI5451      ((PCI_VENDOR_ID_AL<<16)|PCI_DEVICE_ID_AL_M5451)
 
 
 #define ALI_CHANNELS           32
@@ -326,13 +320,12 @@ static void ali_read_regs(ali_t *codec, int channel)
 static void ali_read_cfg(unsigned int vendor, unsigned deviceid)
 {
        unsigned int dwVal;
-       struct pci_dev *pci_dev = NULL;
+       struct pci_dev *pci_dev;
        int i,j;
 
-
-        pci_dev = pci_find_device(vendor, deviceid, pci_dev);
-        if (pci_dev == NULL)
-                return ;
+       pci_dev = pci_get_device(vendor, deviceid, NULL);
+       if (pci_dev == NULL)
+               return ;
 
        printk("\nM%x PCI CFG\n", deviceid);
        printk("    ");
@@ -349,6 +342,7 @@ static void ali_read_cfg(unsigned int vendor, unsigned deviceid)
                }
                printk("\n");
        }
+       pci_dev_put(pci_dev);
  }
 static void ali_read_ac97regs(ali_t *codec, int secondary)
 {
@@ -404,10 +398,8 @@ static int snd_ali_codec_ready(    ali_t *codec,
                res = snd_ali_5451_peek(codec,port);
                if (! (res & 0x8000))
                        return 0;
-               if (sched) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(1);
-               }
+               if (sched)
+                       schedule_timeout_uninterruptible(1);
        } while (time_after_eq(end_time, jiffies));
        snd_ali_5451_poke(codec, port, res & ~0x8000);
        snd_printdd("ali_codec_ready: codec is not ready.\n ");
@@ -427,12 +419,10 @@ static int snd_ali_stimer_ready(ali_t *codec, int sched)
                dwChk2 = snd_ali_5451_peek(codec, ALI_STIMER);
                if (dwChk2 != dwChk1)
                        return 0;
-               if (sched) {
-                       set_current_state(TASK_UNINTERRUPTIBLE);
-                       schedule_timeout(1);
-               }
+               if (sched)
+                       schedule_timeout_uninterruptible(1);
        } while (time_after_eq(end_time, jiffies));
-       snd_printk("ali_stimer_read: stimer is not ready.\n");
+       snd_printk(KERN_ERR "ali_stimer_read: stimer is not ready.\n");
        return -EIO;
 }
 
@@ -444,7 +434,7 @@ static void snd_ali_codec_poke(ali_t *codec,int secondary,
        unsigned int port = 0;
 
        if (reg >= 0x80) {
-               snd_printk("ali_codec_poke: reg(%xh) invalid.\n", reg);
+               snd_printk(KERN_ERR "ali_codec_poke: reg(%xh) invalid.\n", reg);
                return;
        }
 
@@ -473,7 +463,7 @@ static unsigned short snd_ali_codec_peek( ali_t *codec,
        unsigned int port = 0;
 
        if (reg >= 0x80) {
-               snd_printk("ali_codec_peek: reg(%xh) invalid.\n", reg);
+               snd_printk(KERN_ERR "ali_codec_peek: reg(%xh) invalid.\n", reg);
                return ~0;
        }
 
@@ -677,7 +667,7 @@ static int snd_ali_alloc_pcm_channel(ali_t *codec, int channel)
        unsigned int idx =  channel & 0x1f;
 
        if (codec->synth.chcnt >= ALI_CHANNELS){
-               snd_printk("ali_alloc_pcm_channel: no free channels.\n");
+               snd_printk(KERN_ERR "ali_alloc_pcm_channel: no free channels.\n");
                return -1;
        }
 
@@ -708,7 +698,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
                if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
                        return result;
                } else {
-                       snd_printk("ali_find_free_channel: record channel is busy now.\n");
+                       snd_printk(KERN_ERR "ali_find_free_channel: record channel is busy now.\n");
                        return -1;
                }
        }
@@ -720,7 +710,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
                if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0) {
                        return result;
                } else {
-                       snd_printk("ali_find_free_channel: S/PDIF out channel is in busy now.\n");
+                       snd_printk(KERN_ERR "ali_find_free_channel: S/PDIF out channel is in busy now.\n");
                }
        }
 
@@ -728,7 +718,7 @@ static int snd_ali_find_free_channel(ali_t * codec, int rec)
                if ((result = snd_ali_alloc_pcm_channel(codec,idx)) >= 0)
                        return result;
        }
-       snd_printk("ali_find_free_channel: no free channels.\n");
+       snd_printk(KERN_ERR "ali_find_free_channel: no free channels.\n");
        return -1;
 }
 
@@ -742,7 +732,7 @@ static void snd_ali_free_channel_pcm(ali_t *codec, int channel)
                return;
 
        if (!(codec->synth.chmap & (1 << idx))) {
-               snd_printk("ali_free_channel_pcm: channel %d is not in use.\n",channel);
+               snd_printk(KERN_ERR "ali_free_channel_pcm: channel %d is not in use.\n",channel);
                return;
        } else {
                codec->synth.chmap &= ~(1 << idx);
@@ -804,7 +794,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
        }
 
        if (count > 50000) {
-               snd_printk("ali_detect_spdif_rate: timeout!\n");
+               snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
                return;
        }
 
@@ -817,7 +807,7 @@ static void snd_ali_detect_spdif_rate(ali_t *codec)
        }
 
        if (count > 50000) {
-               snd_printk("ali_detect_spdif_rate: timeout!\n");
+               snd_printk(KERN_ERR "ali_detect_spdif_rate: timeout!\n");
                return;
        }
 
@@ -1085,7 +1075,7 @@ static snd_ali_voice_t *snd_ali_alloc_voice(ali_t * codec, int type, int rec, in
                idx = channel > 0 ? snd_ali_alloc_pcm_channel(codec, channel) :
                        snd_ali_find_free_channel(codec,rec);
                if(idx < 0) {
-                       snd_printk("ali_alloc_voice: err.\n");
+                       snd_printk(KERN_ERR "ali_alloc_voice: err.\n");
                        spin_unlock_irqrestore(&codec->voice_alloc, flags);
                        return NULL;
                }
@@ -1487,13 +1477,13 @@ static int snd_ali_prepare(snd_pcm_substream_t * substream)
                }
                rate = snd_ali_get_spdif_in_rate(codec);
                if (rate == 0) {
-                       snd_printk("ali_capture_preapre: spdif rate detect err!\n");
+                       snd_printk(KERN_WARNING "ali_capture_preapre: spdif rate detect err!\n");
                        rate = 48000;
                }
                bValue = inb(ALI_REG(codec,ALI_SPDIF_CTRL));
                if (bValue & 0x10) {
                        outb(bValue,ALI_REG(codec,ALI_SPDIF_CTRL));
-                       printk("clear SPDIF parity error flag.\n");
+                       printk(KERN_WARNING "clear SPDIF parity error flag.\n");
                }
 
                if (rate != 48000)
@@ -1803,6 +1793,7 @@ struct ali_pcm_description {
        unsigned int capture_num;
        snd_pcm_ops_t *playback_ops;
        snd_pcm_ops_t *capture_ops;
+       unsigned short class;
 };
 
 
@@ -1821,12 +1812,11 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
        err = snd_pcm_new(codec->card, desc->name, device,
                          desc->playback_num, desc->capture_num, &pcm);
        if (err < 0) {
-               snd_printk("snd_ali_pcm: err called snd_pcm_new.\n");
+               snd_printk(KERN_ERR "snd_ali_pcm: err called snd_pcm_new.\n");
                return err;
        }
        pcm->private_data = codec;
        pcm->private_free = snd_ali_pcm_free;
-       pcm->info_flags = 0;
        if (desc->playback_ops)
                snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, desc->playback_ops);
        if (desc->capture_ops)
@@ -1836,6 +1826,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
                                              snd_dma_pci_data(codec->pci), 64*1024, 128*1024);
 
        pcm->info_flags = 0;
+       pcm->dev_class = desc->class;
        pcm->dev_subclass = SNDRV_PCM_SUBCLASS_GENERIC_MIX;
        strcpy(pcm->name, desc->name);
        codec->pcm[0] = pcm;
@@ -1844,7 +1835,7 @@ static int __devinit snd_ali_pcm(ali_t * codec, int device, struct ali_pcm_descr
 
 static struct ali_pcm_description ali_pcms[] = {
        { "ALI 5451", ALI_CHANNELS, 1, &snd_ali_playback_ops, &snd_ali_capture_ops },
-       { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops }
+       { "ALI 5451 modem", 1, 1, &snd_ali_modem_playback_ops, &snd_ali_modem_capture_ops, SNDRV_PCM_CLASS_MODEM }
 };
 
 static int __devinit snd_ali_build_pcms(ali_t *codec)
@@ -1999,10 +1990,12 @@ static int __devinit snd_ali_mixer(ali_t * codec)
        for ( i = 0 ; i < codec->num_of_codecs ; i++) {
                ac97.num = i;
                if ((err = snd_ac97_mixer(codec->ac97_bus, &ac97, &codec->ac97[i])) < 0) {
-                       snd_printk("ali mixer %d creating error.\n", i);
+                       snd_printk(KERN_ERR "ali mixer %d creating error.\n", i);
                        if(i == 0)
-               return err;
-       }
+                               return err;
+                       codec->num_of_codecs = 1;
+                       break;
+               }
        }
 
        if (codec->spdif_support) {
@@ -2116,6 +2109,8 @@ static int snd_ali_free(ali_t * codec)
 #ifdef CONFIG_PM
        kfree(codec->image);
 #endif
+       pci_dev_put(codec->pci_m1533);
+       pci_dev_put(codec->pci_m7101);
        kfree(codec);
        return 0;
 }
@@ -2129,7 +2124,7 @@ static int snd_ali_chip_init(ali_t *codec)
        snd_ali_printk("chip initializing ... \n");
 
        if (snd_ali_reset_5451(codec)) {
-               snd_printk("ali_chip_init: reset 5451 error.\n");
+               snd_printk(KERN_ERR "ali_chip_init: reset 5451 error.\n");
                return -1;
        }
 
@@ -2204,7 +2199,7 @@ static int __devinit snd_ali_resources(ali_t *codec)
        codec->port = pci_resource_start(codec->pci, 0);
 
        if (request_irq(codec->pci->irq, snd_ali_card_interrupt, SA_INTERRUPT|SA_SHIRQ, "ALI 5451", (void *)codec)) {
-               snd_printk("Unable to request irq.\n");
+               snd_printk(KERN_ERR "Unable to request irq.\n");
                return -EBUSY;
        }
        codec->irq = codec->pci->irq;
@@ -2244,12 +2239,12 @@ static int __devinit snd_ali_create(snd_card_t * card,
        /* check, if we can restrict PCI DMA transfers to 31 bits */
        if (pci_set_dma_mask(pci, 0x7fffffff) < 0 ||
            pci_set_consistent_dma_mask(pci, 0x7fffffff) < 0) {
-               snd_printk("architecture does not support 31bit PCI busmaster DMA\n");
+               snd_printk(KERN_ERR "architecture does not support 31bit PCI busmaster DMA\n");
                pci_disable_device(pci);
                return -ENXIO;
        }
 
-       if ((codec = kcalloc(1, sizeof(*codec), GFP_KERNEL)) == NULL) {
+       if ((codec = kzalloc(sizeof(*codec), GFP_KERNEL)) == NULL) {
                pci_disable_device(pci);
                return -ENOMEM;
        }
@@ -2305,7 +2300,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
        codec->chregs.data.ainten = 0x00;
 
        /* M1533: southbridge */
-               pci_dev = pci_find_device(0x10b9, 0x1533, NULL);
+       pci_dev = pci_get_device(0x10b9, 0x1533, NULL);
        codec->pci_m1533 = pci_dev;
        if (! codec->pci_m1533) {
                snd_printk(KERN_ERR "ali5451: cannot find ALi 1533 chip.\n");
@@ -2313,7 +2308,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
                return -ENODEV;
        }
        /* M7101: power management */
-               pci_dev = pci_find_device(0x10b9, 0x7101, NULL);
+       pci_dev = pci_get_device(0x10b9, 0x7101, NULL);
        codec->pci_m7101 = pci_dev;
        if (! codec->pci_m7101 && codec->revision == ALI_5451_V02) {
                snd_printk(KERN_ERR "ali5451: cannot find ALi 7101 chip.\n");
@@ -2333,7 +2328,7 @@ static int __devinit snd_ali_create(snd_card_t * card,
        }
 
        if ((err = snd_ali_chip_init(codec)) < 0) {
-               snd_printk("ali create: chip init error.\n");
+               snd_printk(KERN_ERR "ali create: chip init error.\n");
                return err;
        }
 
@@ -2356,25 +2351,17 @@ static int __devinit snd_ali_create(snd_card_t * card,
 static int __devinit snd_ali_probe(struct pci_dev *pci,
                                   const struct pci_device_id *pci_id)
 {
-       static int dev;
        snd_card_t *card;
        ali_t *codec;
        int err;
 
        snd_ali_printk("probe ...\n");
 
-        if (dev >= SNDRV_CARDS)
-                return -ENODEV;
-       if (!enable[dev]) {
-               dev++;
-               return -ENOENT;
-       }
-
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
+       card = snd_card_new(index, id, THIS_MODULE, 0);
        if (card == NULL)
                return -ENOMEM;
 
-       if ((err = snd_ali_create(card, pci, pcm_channels[dev], spdif[dev], &codec)) < 0) {
+       if ((err = snd_ali_create(card, pci, pcm_channels, spdif, &codec)) < 0) {
                snd_card_free(card);
                return err;
        }
@@ -2405,7 +2392,6 @@ static int __devinit snd_ali_probe(struct pci_dev *pci,
                return err;
        }
        pci_set_drvdata(pci, card);
-       dev++;
        return 0;
 }
 
@@ -2417,6 +2403,7 @@ static void __devexit snd_ali_remove(struct pci_dev *pci)
 
 static struct pci_driver driver = {
        .name = "ALI 5451",
+       .owner = THIS_MODULE,
        .id_table = snd_ali_ids,
        .probe = snd_ali_probe,
        .remove = __devexit_p(snd_ali_remove),