Merge branch 'topic/cs423x-merge' into for-linus
[safe/jmp/linux-2.6] / sound / isa / sgalaxy.c
index 52f2294..6fe27b9 100644 (file)
  *
  */
 
-#include <sound/driver.h>
-#include <asm/dma.h>
 #include <linux/init.h>
+#include <linux/err.h>
+#include <linux/isa.h>
 #include <linux/delay.h>
 #include <linux/time.h>
 #include <linux/interrupt.h>
 #include <linux/moduleparam.h>
+#include <asm/dma.h>
 #include <sound/core.h>
 #include <sound/sb.h>
-#include <sound/ad1848.h>
+#include <sound/wss.h>
 #include <sound/control.h>
 #define SNDRV_LEGACY_FIND_FREE_IRQ
 #define SNDRV_LEGACY_FIND_FREE_DMA
@@ -65,8 +66,6 @@ MODULE_PARM_DESC(dma1, "DMA1 # for Sound Galaxy driver.");
 #define SGALAXY_AUXC_LEFT 18
 #define SGALAXY_AUXC_RIGHT 19
 
-static snd_card_t *snd_sgalaxy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
-
 #define PFX    "sgalaxy: "
 
 /*
@@ -75,7 +74,7 @@ static snd_card_t *snd_sgalaxy_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR;
 
 #define AD1848P1( port, x ) ( port + c_d_c_AD1848##x )
 
-/* from lowlevel/sb/sb.c - to avoid having to allocate a sb_t for the */
+/* from lowlevel/sb/sb.c - to avoid having to allocate a struct snd_sb for the */
 /* short time we actually need it.. */
 
 static int snd_sgalaxy_sbdsp_reset(unsigned long port)
@@ -94,7 +93,8 @@ static int snd_sgalaxy_sbdsp_reset(unsigned long port)
        return 0;
 }
 
-static int __init snd_sgalaxy_sbdsp_command(unsigned long port, unsigned char val)
+static int __devinit snd_sgalaxy_sbdsp_command(unsigned long port,
+                                              unsigned char val)
 {
        int i;
                
@@ -107,12 +107,12 @@ static int __init snd_sgalaxy_sbdsp_command(unsigned long port, unsigned char va
        return 0;
 }
 
-static irqreturn_t snd_sgalaxy_dummy_interrupt(int irq, void *dev_id, struct pt_regs *regs)
+static irqreturn_t snd_sgalaxy_dummy_interrupt(int irq, void *dev_id)
 {
        return IRQ_NONE;
 }
 
-static int __init snd_sgalaxy_setup_wss(unsigned long port, int irq, int dma)
+static int __devinit snd_sgalaxy_setup_wss(unsigned long port, int irq, int dma)
 {
        static int interrupt_bits[] = {-1, -1, -1, -1, -1, -1, -1, 0x08, -1, 
                                       0x10, 0x18, 0x20, -1, -1, -1, -1};
@@ -145,7 +145,7 @@ static int __init snd_sgalaxy_setup_wss(unsigned long port, int irq, int dma)
         if (tmp < 0)
                 return -EINVAL;
 
-       if (request_irq(irq, snd_sgalaxy_dummy_interrupt, SA_INTERRUPT, "sgalaxy", NULL)) {
+       if (request_irq(irq, snd_sgalaxy_dummy_interrupt, IRQF_DISABLED, "sgalaxy", NULL)) {
                snd_printk(KERN_ERR "sgalaxy: can't grab irq %d\n", irq);
                return -EIO;
        }
@@ -159,7 +159,7 @@ static int __init snd_sgalaxy_setup_wss(unsigned long port, int irq, int dma)
        return 0;
 }
 
-static int __init snd_sgalaxy_detect(int dev, int irq, int dma)
+static int __devinit snd_sgalaxy_detect(int dev, int irq, int dma)
 {
 #if 0
        snd_printdd(PFX "switching to WSS mode\n");
@@ -175,15 +175,17 @@ static int __init snd_sgalaxy_detect(int dev, int irq, int dma)
        return snd_sgalaxy_setup_wss(wssport[dev], irq, dma);
 }
 
-static struct ad1848_mix_elem snd_sgalaxy_controls[] = {
-AD1848_DOUBLE("Aux Playback Switch", 0, SGALAXY_AUXC_LEFT, SGALAXY_AUXC_RIGHT, 7, 7, 1, 1),
-AD1848_DOUBLE("Aux Playback Volume", 0, SGALAXY_AUXC_LEFT, SGALAXY_AUXC_RIGHT, 0, 0, 31, 0)
+static struct snd_kcontrol_new snd_sgalaxy_controls[] = {
+WSS_DOUBLE("Aux Playback Switch", 0,
+               SGALAXY_AUXC_LEFT, SGALAXY_AUXC_RIGHT, 7, 7, 1, 1),
+WSS_DOUBLE("Aux Playback Volume", 0,
+               SGALAXY_AUXC_LEFT, SGALAXY_AUXC_RIGHT, 0, 0, 31, 0)
 };
 
-static int __init snd_sgalaxy_mixer(ad1848_t *chip)
+static int __devinit snd_sgalaxy_mixer(struct snd_wss *chip)
 {
-       snd_card_t *card = chip->card;
-       snd_ctl_elem_id_t id1, id2;
+       struct snd_card *card = chip->card;
+       struct snd_ctl_elem_id id1, id2;
        unsigned int idx;
        int err;
 
@@ -210,31 +212,40 @@ static int __init snd_sgalaxy_mixer(ad1848_t *chip)
                return err;
        /* build AUX2 input */
        for (idx = 0; idx < ARRAY_SIZE(snd_sgalaxy_controls); idx++) {
-               if ((err = snd_ad1848_add_ctl_elem(chip, &snd_sgalaxy_controls[idx])) < 0)
+               err = snd_ctl_add(card,
+                               snd_ctl_new1(&snd_sgalaxy_controls[idx], chip));
+               if (err < 0)
                        return err;
        }
        return 0;
 }
 
-static int __init snd_sgalaxy_probe(int dev)
+static int __devinit snd_sgalaxy_match(struct device *devptr, unsigned int dev)
 {
-       static int possible_irqs[] = {7, 9, 10, 11, -1};
-       static int possible_dmas[] = {1, 3, 0, -1};
-       int err, xirq, xdma1;
-       snd_card_t *card;
-       ad1848_t *chip;
-
+       if (!enable[dev])
+               return 0;
        if (sbport[dev] == SNDRV_AUTO_PORT) {
                snd_printk(KERN_ERR PFX "specify SB port\n");
-               return -EINVAL;
+               return 0;
        }
        if (wssport[dev] == SNDRV_AUTO_PORT) {
                snd_printk(KERN_ERR PFX "specify WSS port\n");
-               return -EINVAL;
+               return 0;
        }
-       card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
-       if (card == NULL)
-               return -ENOMEM;
+       return 1;
+}
+
+static int __devinit snd_sgalaxy_probe(struct device *devptr, unsigned int dev)
+{
+       static int possible_irqs[] = {7, 9, 10, 11, -1};
+       static int possible_dmas[] = {1, 3, 0, -1};
+       int err, xirq, xdma1;
+       struct snd_card *card;
+       struct snd_wss *chip;
+
+       err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
+       if (err < 0)
+               return err;
 
        xirq = irq[dev];
        if (xirq == SNDRV_AUTO_IRQ) {
@@ -256,17 +267,21 @@ static int __init snd_sgalaxy_probe(int dev)
        if ((err = snd_sgalaxy_detect(dev, xirq, xdma1)) < 0)
                goto _err;
 
-       if ((err = snd_ad1848_create(card, wssport[dev] + 4,
-                                    xirq, xdma1,
-                                    AD1848_HW_DETECT, &chip)) < 0)
+       err = snd_wss_create(card, wssport[dev] + 4, -1,
+                            xirq, xdma1, -1,
+                            WSS_HW_DETECT, 0, &chip);
+       if (err < 0)
                goto _err;
+       card->private_data = chip;
 
-       if ((err = snd_ad1848_pcm(chip, 0, NULL)) < 0) {
-               snd_printdd(PFX "error creating new ad1848 PCM device\n");
+       err = snd_wss_pcm(chip, 0, NULL);
+       if (err < 0) {
+               snd_printdd(PFX "error creating new WSS PCM device\n");
                goto _err;
        }
-       if ((err = snd_ad1848_mixer(chip)) < 0) {
-               snd_printdd(PFX "error creating new ad1848 mixer\n");
+       err = snd_wss_mixer(chip);
+       if (err < 0) {
+               snd_printdd(PFX "error creating new WSS mixer\n");
                goto _err;
        }
        if ((err = snd_sgalaxy_mixer(chip)) < 0) {
@@ -279,13 +294,12 @@ static int __init snd_sgalaxy_probe(int dev)
        sprintf(card->longname, "Sound Galaxy at 0x%lx, irq %d, dma %d",
                wssport[dev], xirq, xdma1);
 
-       if ((err = snd_card_set_generic_dev(card)) < 0)
-               goto _err;
+       snd_card_set_dev(card, devptr);
 
        if ((err = snd_card_register(card)) < 0)
                goto _err;
 
-       snd_sgalaxy_cards[dev] = card;
+       dev_set_drvdata(devptr, card);
        return 0;
 
  _err:
@@ -293,30 +307,62 @@ static int __init snd_sgalaxy_probe(int dev)
        return err;
 }
 
-static int __init alsa_card_sgalaxy_init(void)
+static int __devexit snd_sgalaxy_remove(struct device *devptr, unsigned int dev)
 {
-       int dev, cards;
+       snd_card_free(dev_get_drvdata(devptr));
+       dev_set_drvdata(devptr, NULL);
+       return 0;
+}
 
-       for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) {
-               if (snd_sgalaxy_probe(dev) >= 0)
-                       cards++;
-       }
-       if (!cards) {
-#ifdef MODULE
-               snd_printk(KERN_ERR "Sound Galaxy soundcard not found or device busy\n");
-#endif
-               return -ENODEV;
-       }
+#ifdef CONFIG_PM
+static int snd_sgalaxy_suspend(struct device *pdev, unsigned int n,
+                              pm_message_t state)
+{
+       struct snd_card *card = dev_get_drvdata(pdev);
+       struct snd_wss *chip = card->private_data;
 
+       snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
+       chip->suspend(chip);
        return 0;
 }
 
-static void __exit alsa_card_sgalaxy_exit(void)
+static int snd_sgalaxy_resume(struct device *pdev, unsigned int n)
 {
-       int idx;
+       struct snd_card *card = dev_get_drvdata(pdev);
+       struct snd_wss *chip = card->private_data;
+
+       chip->resume(chip);
+       snd_wss_out(chip, SGALAXY_AUXC_LEFT, chip->image[SGALAXY_AUXC_LEFT]);
+       snd_wss_out(chip, SGALAXY_AUXC_RIGHT, chip->image[SGALAXY_AUXC_RIGHT]);
+
+       snd_power_change_state(card, SNDRV_CTL_POWER_D0);
+       return 0;
+}
+#endif
 
-       for (idx = 0; idx < SNDRV_CARDS; idx++)
-               snd_card_free(snd_sgalaxy_cards[idx]);
+#define DEV_NAME "sgalaxy"
+
+static struct isa_driver snd_sgalaxy_driver = {
+       .match          = snd_sgalaxy_match,
+       .probe          = snd_sgalaxy_probe,
+       .remove         = __devexit_p(snd_sgalaxy_remove),
+#ifdef CONFIG_PM
+       .suspend        = snd_sgalaxy_suspend,
+       .resume         = snd_sgalaxy_resume,
+#endif
+       .driver         = {
+               .name   = DEV_NAME
+       },
+};
+
+static int __init alsa_card_sgalaxy_init(void)
+{
+       return isa_register_driver(&snd_sgalaxy_driver, SNDRV_CARDS);
+}
+
+static void __exit alsa_card_sgalaxy_exit(void)
+{
+       isa_unregister_driver(&snd_sgalaxy_driver);
 }
 
 module_init(alsa_card_sgalaxy_init)