[TC] dec_esp: Driver model for the PMAZ-A
[powerpc.git] / sound / isa / sgalaxy.c
index 2e1d467..4fcd0f4 100644 (file)
@@ -64,6 +64,8 @@ MODULE_PARM_DESC(irq, "IRQ # for Sound Galaxy driver.");
 module_param_array(dma1, int, NULL, 0444);
 MODULE_PARM_DESC(dma1, "DMA1 # for Sound Galaxy driver.");
 
+static struct platform_device *devices[SNDRV_CARDS];
+
 #define SGALAXY_AUXC_LEFT 18
 #define SGALAXY_AUXC_RIGHT 19
 
@@ -107,7 +109,7 @@ 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;
 }
@@ -145,7 +147,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;
        }
@@ -340,6 +342,15 @@ static struct platform_driver snd_sgalaxy_driver = {
        },
 };
 
+static void __init_or_module snd_sgalaxy_unregister_all(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(devices); ++i)
+               platform_device_unregister(devices[i]);
+       platform_driver_unregister(&snd_sgalaxy_driver);
+}
+
 static int __init alsa_card_sgalaxy_init(void)
 {
        int i, cards, err;
@@ -349,33 +360,34 @@ static int __init alsa_card_sgalaxy_init(void)
                return err;
 
        cards = 0;
-       for (i = 0; i < SNDRV_CARDS && enable[i]; i++) {
+       for (i = 0; i < SNDRV_CARDS; i++) {
                struct platform_device *device;
+               if (! enable[i])
+                       continue;
                device = platform_device_register_simple(SND_SGALAXY_DRIVER,
                                                         i, NULL, 0);
-               if (IS_ERR(device)) {
-                       err = PTR_ERR(device);
-                       goto errout;
+               if (IS_ERR(device))
+                       continue;
+               if (!platform_get_drvdata(device)) {
+                       platform_device_unregister(device);
+                       continue;
                }
+               devices[i] = device;
                cards++;
        }
        if (!cards) {
 #ifdef MODULE
                snd_printk(KERN_ERR "Sound Galaxy soundcard not found or device busy\n");
 #endif
-               err = -ENODEV;
-               goto errout;
+               snd_sgalaxy_unregister_all();
+               return -ENODEV;
        }
        return 0;
-
- errout:
-       platform_driver_unregister(&snd_sgalaxy_driver);
-       return err;
 }
 
 static void __exit alsa_card_sgalaxy_exit(void)
 {
-       platform_driver_unregister(&snd_sgalaxy_driver);
+       snd_sgalaxy_unregister_all();
 }
 
 module_init(alsa_card_sgalaxy_init)