Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial
[safe/jmp/linux-2.6] / sound / isa / opti9xx / opti92x-ad1848.c
index 19706b0..d622d29 100644 (file)
@@ -141,15 +141,7 @@ struct snd_opti9xx {
 
        spinlock_t lock;
 
-       long wss_base;
        int irq;
-       int dma1;
-       int dma2;
-
-       long fm_port;
-
-       long mpu_port;
-       int mpu_irq;
 
 #ifdef CONFIG_PNP
        struct pnp_dev *dev;
@@ -185,7 +177,7 @@ MODULE_DEVICE_TABLE(pnp_card, snd_opti9xx_pnpids);
 #endif
 
 static char * snd_opti9xx_names[] = {
-       "unkown",
+       "unknown",
        "82C928",       "82C929",
        "82C924",       "82C925",
        "82C930",       "82C931",       "82C933"
@@ -216,13 +208,7 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
 
        spin_lock_init(&chip->lock);
 
-       chip->wss_base = -1;
        chip->irq = -1;
-       chip->dma1 = -1;
-       chip->dma2 = -1;
-       chip->fm_port = -1;
-       chip->mpu_port = -1;
-       chip->mpu_irq = -1;
 
        switch (hardware) {
 #ifndef OPTi93X
@@ -252,7 +238,7 @@ static int __devinit snd_opti9xx_init(struct snd_opti9xx *chip,
 #endif /* OPTi93X */
 
        default:
-               snd_printk("chip %d not supported\n", hardware);
+               snd_printk(KERN_ERR "chip %d not supported\n", hardware);
                return -ENODEV;
        }
        return 0;
@@ -294,7 +280,7 @@ static unsigned char snd_opti9xx_read(struct snd_opti9xx *chip,
 #endif /* OPTi93X */
 
        default:
-               snd_printk("chip %d not supported\n", chip->hardware);
+               snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
        }
 
        spin_unlock_irqrestore(&chip->lock, flags);
@@ -336,7 +322,7 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
 #endif /* OPTi93X */
 
        default:
-               snd_printk("chip %d not supported\n", chip->hardware);
+               snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
        }
 
        spin_unlock_irqrestore(&chip->lock, flags);
@@ -348,7 +334,10 @@ static void snd_opti9xx_write(struct snd_opti9xx *chip, unsigned char reg,
                (snd_opti9xx_read(chip, reg) & ~(mask)) | ((value) & (mask)))
 
 
-static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
+static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip,
+                                          long wss_base,
+                                          int irq, int dma1, int dma2,
+                                          long mpu_port, int mpu_irq)
 {
        unsigned char wss_base_bits;
        unsigned char irq_bits;
@@ -412,11 +401,11 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
 #endif /* OPTi93X */
 
        default:
-               snd_printk("chip %d not supported\n", chip->hardware);
+               snd_printk(KERN_ERR "chip %d not supported\n", chip->hardware);
                return -EINVAL;
        }
 
-       switch (chip->wss_base) {
+       switch (wss_base) {
        case 0x530:
                wss_base_bits = 0x00;
                break;
@@ -430,13 +419,13 @@ static int __devinit snd_opti9xx_configure(struct snd_opti9xx *chip)
                wss_base_bits = 0x02;
                break;
        default:
-               snd_printk("WSS port 0x%lx not valid\n", chip->wss_base);
+               snd_printk(KERN_WARNING "WSS port 0x%lx not valid\n", wss_base);
                goto __skip_base;
        }
        snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(1), wss_base_bits << 4, 0x30);
 
 __skip_base:
-       switch (chip->irq) {
+       switch (irq) {
 //#ifdef OPTi93X
        case 5:
                irq_bits = 0x05;
@@ -455,11 +444,11 @@ __skip_base:
                irq_bits = 0x04;
                break;
        default:
-               snd_printk("WSS irq # %d not valid\n", chip->irq);
+               snd_printk(KERN_WARNING "WSS irq # %d not valid\n", irq);
                goto __skip_resources;
        }
 
-       switch (chip->dma1) {
+       switch (dma1) {
        case 0:
                dma_bits = 0x01;
                break;
@@ -470,36 +459,36 @@ __skip_base:
                dma_bits = 0x03;
                break;
        default:
-               snd_printk("WSS dma1 # %d not valid\n", chip->dma1);
+               snd_printk(KERN_WARNING "WSS dma1 # %d not valid\n", dma1);
                goto __skip_resources;
        }
 
 #if defined(CS4231) || defined(OPTi93X)
-       if (chip->dma1 == chip->dma2) {
-               snd_printk("don't want to share dmas\n");
+       if (dma1 == dma2) {
+               snd_printk(KERN_ERR "don't want to share dmas\n");
                return -EBUSY;
        }
 
-       switch (chip->dma2) {
+       switch (dma2) {
        case 0:
        case 1:
                break;
        default:
-               snd_printk("WSS dma2 # %d not valid\n", chip->dma2);
+               snd_printk(KERN_WARNING "WSS dma2 # %d not valid\n", dma2);
                goto __skip_resources;
        }
        dma_bits |= 0x04;
 #endif /* CS4231 || OPTi93X */
 
 #ifndef OPTi93X
-        outb(irq_bits << 3 | dma_bits, chip->wss_base);
+        outb(irq_bits << 3 | dma_bits, wss_base);
 #else /* OPTi93X */
        snd_opti9xx_write(chip, OPTi9XX_MC_REG(3), (irq_bits << 3 | dma_bits));
 #endif /* OPTi93X */
 
 __skip_resources:
        if (chip->hardware > OPTi9XX_HW_82C928) {
-               switch (chip->mpu_port) {
+               switch (mpu_port) {
                case 0:
                case -1:
                        break;
@@ -516,12 +505,12 @@ __skip_resources:
                        mpu_port_bits = 0x00;
                        break;
                default:
-                       snd_printk("MPU-401 port 0x%lx not valid\n",
-                               chip->mpu_port);
+                       snd_printk(KERN_WARNING
+                                  "MPU-401 port 0x%lx not valid\n", mpu_port);
                        goto __skip_mpu;
                }
 
-               switch (chip->mpu_irq) {
+               switch (mpu_irq) {
                case 5:
                        mpu_irq_bits = 0x02;
                        break;
@@ -535,13 +524,13 @@ __skip_resources:
                        mpu_irq_bits = 0x01;
                        break;
                default:
-                       snd_printk("MPU-401 irq # %d not valid\n",
-                               chip->mpu_irq);
+                       snd_printk(KERN_WARNING "MPU-401 irq # %d not valid\n",
+                               mpu_irq);
                        goto __skip_mpu;
                }
 
                snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(6),
-                       (chip->mpu_port <= 0) ? 0x00 :
+                       (mpu_port <= 0) ? 0x00 :
                                0x80 | mpu_port_bits << 5 | mpu_irq_bits << 3,
                        0xf8);
        }
@@ -697,6 +686,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
 {
        static long possible_ports[] = {0x530, 0xe80, 0xf40, 0x604, -1};
        int error;
+       int xdma2;
        struct snd_opti9xx *chip = card->private_data;
        struct snd_wss *codec;
 #ifdef CS4231
@@ -711,31 +701,25 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
                                                "OPTi9xx MC")) == NULL)
                return -ENOMEM;
 
-       chip->wss_base = port;
-       chip->fm_port = fm_port;
-       chip->mpu_port = mpu_port;
-       chip->irq = irq;
-       chip->mpu_irq = mpu_irq;
-       chip->dma1 = dma1;
 #if defined(CS4231) || defined(OPTi93X)
-       chip->dma2 = dma2;
+       xdma2 = dma2;
 #else
-       chip->dma2 = -1;
+       xdma2 = -1;
 #endif
 
-       if (chip->wss_base == SNDRV_AUTO_PORT) {
-               chip->wss_base = snd_legacy_find_free_ioport(possible_ports, 4);
-               if (chip->wss_base < 0) {
-                       snd_printk("unable to find a free WSS port\n");
+       if (port == SNDRV_AUTO_PORT) {
+               port = snd_legacy_find_free_ioport(possible_ports, 4);
+               if (port < 0) {
+                       snd_printk(KERN_ERR "unable to find a free WSS port\n");
                        return -EBUSY;
                }
        }
-       error = snd_opti9xx_configure(chip);
+       error = snd_opti9xx_configure(chip, port, irq, dma1, xdma2,
+                                     mpu_port, mpu_irq);
        if (error)
                return error;
 
-       error = snd_wss_create(card, chip->wss_base + 4, -1,
-                              chip->irq, chip->dma1, chip->dma2,
+       error = snd_wss_create(card, port + 4, -1, irq, dma1, xdma2,
 #ifdef OPTi93X
                               WSS_HW_OPTI93X, WSS_HWSHARE_IRQ,
 #else
@@ -759,35 +743,35 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
                return error;
 #endif
 #ifdef OPTi93X
-       error = request_irq(chip->irq, snd_opti93x_interrupt,
+       error = request_irq(irq, snd_opti93x_interrupt,
                            IRQF_DISABLED, DEV_NAME" - WSS", codec);
        if (error < 0) {
                snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", chip->irq);
                return error;
        }
 #endif
+       chip->irq = irq;
        strcpy(card->driver, chip->name);
        sprintf(card->shortname, "OPTi %s", card->driver);
 #if defined(CS4231) || defined(OPTi93X)
        sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d&%d",
-               card->shortname, pcm->name, chip->wss_base + 4,
-               chip->irq, chip->dma1, chip->dma2);
+               card->shortname, pcm->name, port + 4, irq, dma1, xdma2);
 #else
        sprintf(card->longname, "%s, %s at 0x%lx, irq %d, dma %d",
-               card->shortname, pcm->name, chip->wss_base + 4,
-               chip->irq, chip->dma1);
+               card->shortname, pcm->name, port + 4, irq, dma1);
 #endif /* CS4231 || OPTi93X */
 
-       if (chip->mpu_port <= 0 || chip->mpu_port == SNDRV_AUTO_PORT)
+       if (mpu_port <= 0 || mpu_port == SNDRV_AUTO_PORT)
                rmidi = NULL;
-       else
-               if ((error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                               chip->mpu_port, 0, chip->mpu_irq, IRQF_DISABLED,
-                               &rmidi)))
+       else {
+               error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
+                               mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi);
+               if (error)
                        snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
-                                  chip->mpu_port);
+                                  mpu_port);
+       }
 
-       if (chip->fm_port > 0 && chip->fm_port != SNDRV_AUTO_PORT) {
+       if (fm_port > 0 && fm_port != SNDRV_AUTO_PORT) {
                struct snd_opl3 *opl3 = NULL;
 #ifndef OPTi93X
                if (chip->hardware == OPTi9XX_HW_82C928 ||
@@ -797,9 +781,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
                        /* assume we have an OPL4 */
                        snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
                                               0x20, 0x20);
-                       if (snd_opl4_create(card,
-                                           chip->fm_port,
-                                           chip->fm_port - 8,
+                       if (snd_opl4_create(card, fm_port, fm_port - 8,
                                            2, &opl3, &opl4) < 0) {
                                /* no luck, use OPL3 instead */
                                snd_opti9xx_write_mask(chip, OPTi9XX_MC_REG(2),
@@ -807,22 +789,14 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
                        }
                }
 #endif /* !OPTi93X */
-               if (!opl3 && snd_opl3_create(card,
-                                            chip->fm_port,
-                                            chip->fm_port + 2,
+               if (!opl3 && snd_opl3_create(card, fm_port, fm_port + 2,
                                             OPL3_HW_AUTO, 0, &opl3) < 0) {
                        snd_printk(KERN_WARNING "no OPL device at 0x%lx-0x%lx\n",
-                                  chip->fm_port, chip->fm_port + 4 - 1);
+                                  fm_port, fm_port + 4 - 1);
                }
                if (opl3) {
-#ifdef CS4231
-                       const int t1dev = 1;
-#else
-                       const int t1dev = 0;
-#endif
-                       if ((error = snd_opl3_timer_new(opl3, t1dev, t1dev+1)) < 0)
-                               return error;
-                       if ((error = snd_opl3_hwdep_new(opl3, 0, 1, &synth)) < 0)
+                       error = snd_opl3_hwdep_new(opl3, 0, 1, &synth);
+                       if (error < 0)
                                return error;
                }
        }
@@ -830,15 +804,18 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
        return snd_card_register(card);
 }
 
-static struct snd_card *snd_opti9xx_card_new(void)
+static int snd_opti9xx_card_new(struct snd_card **cardp)
 {
        struct snd_card *card;
+       int err;
 
-       card = snd_card_new(index, id, THIS_MODULE, sizeof(struct snd_opti9xx));
-       if (! card)
-               return NULL;
+       err = snd_card_create(index, id, THIS_MODULE,
+                             sizeof(struct snd_opti9xx), &card);
+       if (err < 0)
+               return err;
        card->private_free = snd_card_opti9xx_free;
-       return card;
+       *cardp = card;
+       return 0;
 }
 
 static int __devinit snd_opti9xx_isa_match(struct device *devptr,
@@ -897,15 +874,15 @@ static int __devinit snd_opti9xx_isa_probe(struct device *devptr,
 #if defined(CS4231) || defined(OPTi93X)
        if (dma2 == SNDRV_AUTO_DMA) {
                if ((dma2 = snd_legacy_find_free_dma(possible_dma2s[dma1 % 4])) < 0) {
-                       snd_printk("unable to find a free DMA2\n");
+                       snd_printk(KERN_ERR "unable to find a free DMA2\n");
                        return -EBUSY;
                }
        }
 #endif
 
-       card = snd_opti9xx_card_new();
-       if (! card)
-               return -ENOMEM;
+       error = snd_opti9xx_card_new(&card);
+       if (error < 0)
+               return error;
 
        if ((error = snd_card_opti9xx_detect(card, card->private_data)) < 0) {
                snd_card_free(card);
@@ -950,9 +927,9 @@ static int __devinit snd_opti9xx_pnp_probe(struct pnp_card_link *pcard,
                return -EBUSY;
        if (! isapnp)
                return -ENODEV;
-       card = snd_opti9xx_card_new();
-       if (! card)
-               return -ENOMEM;
+       error = snd_opti9xx_card_new(&card);
+       if (error < 0)
+               return error;
        chip = card->private_data;
 
        hw = snd_card_opti9xx_pnp(chip, pcard, pid);