fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / sound / isa / ad1816a / ad1816a.c
index 9677dae..5903450 100644 (file)
@@ -53,28 +53,30 @@ static int irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;    /* Pnp setup */
 static int mpu_irq[SNDRV_CARDS] = SNDRV_DEFAULT_IRQ;   /* Pnp setup */
 static int dma1[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* PnP setup */
 static int dma2[SNDRV_CARDS] = SNDRV_DEFAULT_DMA;      /* PnP setup */
-static int boot_devs;
+static int clockfreq[SNDRV_CARDS];
 
-module_param_array(index, int, boot_devs, 0444);
+module_param_array(index, int, NULL, 0444);
 MODULE_PARM_DESC(index, "Index value for ad1816a based soundcard.");
-module_param_array(id, charp, boot_devs, 0444);
+module_param_array(id, charp, NULL, 0444);
 MODULE_PARM_DESC(id, "ID string for ad1816a based soundcard.");
-module_param_array(enable, bool, boot_devs, 0444);
+module_param_array(enable, bool, NULL, 0444);
 MODULE_PARM_DESC(enable, "Enable ad1816a based soundcard.");
-module_param_array(port, long, boot_devs, 0444);
+module_param_array(port, long, NULL, 0444);
 MODULE_PARM_DESC(port, "Port # for ad1816a driver.");
-module_param_array(mpu_port, long, boot_devs, 0444);
+module_param_array(mpu_port, long, NULL, 0444);
 MODULE_PARM_DESC(mpu_port, "MPU-401 port # for ad1816a driver.");
-module_param_array(fm_port, long, boot_devs, 0444);
+module_param_array(fm_port, long, NULL, 0444);
 MODULE_PARM_DESC(fm_port, "FM port # for ad1816a driver.");
-module_param_array(irq, int, boot_devs, 0444);
+module_param_array(irq, int, NULL, 0444);
 MODULE_PARM_DESC(irq, "IRQ # for ad1816a driver.");
-module_param_array(mpu_irq, int, boot_devs, 0444);
+module_param_array(mpu_irq, int, NULL, 0444);
 MODULE_PARM_DESC(mpu_irq, "MPU-401 IRQ # for ad1816a driver.");
-module_param_array(dma1, int, boot_devs, 0444);
+module_param_array(dma1, int, NULL, 0444);
 MODULE_PARM_DESC(dma1, "1st DMA # for ad1816a driver.");
-module_param_array(dma2, int, boot_devs, 0444);
+module_param_array(dma2, int, NULL, 0444);
 MODULE_PARM_DESC(dma2, "2nd DMA # for ad1816a driver.");
+module_param_array(clockfreq, int, NULL, 0444);
+MODULE_PARM_DESC(clockfreq, "Clock frequency for ad1816a driver (default = 0).");
 
 struct snd_card_ad1816a {
        struct pnp_dev *dev;
@@ -84,6 +86,8 @@ struct snd_card_ad1816a {
 static struct pnp_card_device_id snd_ad1816a_pnpids[] = {
        /* Analog Devices AD1815 */
        { .id = "ADS7150", .devs = { { .id = "ADS7150" }, { .id = "ADS7151" } } },
+       /* Analog Device AD1816? */
+       { .id = "ADS7180", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
        /* Analog Devices AD1816A - added by Kenneth Platz <kxp@atl.hp.com> */
        { .id = "ADS7181", .devs = { { .id = "ADS7180" }, { .id = "ADS7181" } } },
        /* Analog Devices AD1816A - Aztech/Newcom SC-16 3D */
@@ -116,6 +120,8 @@ static int __devinit snd_card_ad1816a_pnp(int dev, struct snd_card_ad1816a *acar
        struct pnp_resource_table *cfg = kmalloc(sizeof(*cfg), GFP_KERNEL);
        int err;
 
+       if (!cfg)
+               return -ENOMEM;
        acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
        if (acard->dev == NULL) {
                kfree(cfg);
@@ -184,10 +190,10 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
                                            const struct pnp_card_device_id *pid)
 {
        int error;
-       snd_card_t *card;
+       struct snd_card *card;
        struct snd_card_ad1816a *acard;
-       ad1816a_t *chip;
-       opl3_t *opl3;
+       struct snd_ad1816a *chip;
+       struct snd_opl3 *opl3;
 
        if ((card = snd_card_new(index[dev], id[dev], THIS_MODULE,
                                 sizeof(struct snd_card_ad1816a))) == NULL)
@@ -208,6 +214,8 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
                snd_card_free(card);
                return error;
        }
+       if (clockfreq[dev] >= 5000 && clockfreq[dev] <= 100000)
+               chip->clock_freq = clockfreq[dev];
 
        strcpy(card->driver, "AD1816A");
        strcpy(card->shortname, "ADI SoundPort AD1816A");
@@ -226,7 +234,7 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
 
        if (mpu_port[dev] > 0) {
                if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
-                                       mpu_port[dev], 0, mpu_irq[dev], SA_INTERRUPT,
+                                       mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED,
                                        NULL) < 0)
                        printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
        }
@@ -256,6 +264,8 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
        return 0;
 }
 
+static unsigned int __devinitdata ad1816a_devices;
+
 static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
                                            const struct pnp_card_device_id *id)
 {
@@ -269,6 +279,7 @@ static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
                if (res < 0)
                        return res;
                dev++;
+               ad1816a_devices++;
                return 0;
        }
         return -ENODEV;
@@ -276,10 +287,8 @@ static int __devinit snd_ad1816a_pnp_detect(struct pnp_card_link *card,
 
 static void __devexit snd_ad1816a_pnp_remove(struct pnp_card_link * pcard)
 {
-       snd_card_t *card = (snd_card_t *) pnp_get_card_drvdata(pcard);
-
-       snd_card_disconnect(card);
-       snd_card_free_in_thread(card);
+       snd_card_free(pnp_get_card_drvdata(pcard));
+       pnp_set_card_drvdata(pcard, NULL);
 }
 
 static struct pnp_card_driver ad1816a_pnpc_driver = {
@@ -288,20 +297,25 @@ static struct pnp_card_driver ad1816a_pnpc_driver = {
        .id_table       = snd_ad1816a_pnpids,
        .probe          = snd_ad1816a_pnp_detect,
        .remove         = __devexit_p(snd_ad1816a_pnp_remove),
+       /* FIXME: suspend/resume */
 };
 
 static int __init alsa_card_ad1816a_init(void)
 {
-       int cards = 0;
+       int err;
 
-       cards += pnp_register_card_driver(&ad1816a_pnpc_driver);
-#ifdef MODULE
-       if (!cards) {
+       err = pnp_register_card_driver(&ad1816a_pnpc_driver);
+       if (err)
+               return err;
+
+       if (!ad1816a_devices) {
                pnp_unregister_card_driver(&ad1816a_pnpc_driver);
+#ifdef MODULE
                printk(KERN_ERR "no AD1816A based soundcards found.\n");
-       }
 #endif /* MODULE */
-       return cards ? 0 : -ENODEV;
+               return -ENODEV;
+       }
+       return 0;
 }
 
 static void __exit alsa_card_ad1816a_exit(void)