X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=sound%2Fisa%2Fcmi8330.c;h=4d198ec71e9b410aad2100e189c3293453d3129c;hb=f974a8ec96571535ee07880a023bcce0e3f2c76b;hp=c09a8009d2fa7230196a27fab89231dcfcc4fb7b;hpb=b643b0fdbc59cf6bbb086974b29d2571e9e9f646;p=linux-2.6 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c index c09a8009d2..4d198ec71e 100644 --- a/sound/isa/cmi8330.c +++ b/sound/isa/cmi8330.c @@ -43,10 +43,9 @@ * full control over both mixers. */ -#include #include #include -#include +#include #include #include #include @@ -108,8 +107,8 @@ MODULE_PARM_DESC(wssirq, "IRQ # for CMI8330 WSS driver."); module_param_array(wssdma, int, NULL, 0444); MODULE_PARM_DESC(wssdma, "DMA for CMI8330 WSS driver."); -static struct platform_device *platform_devices[SNDRV_CARDS]; #ifdef CONFIG_PNP +static int isa_registered; static int pnp_registered; #endif @@ -286,39 +285,21 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard, const struct pnp_card_device_id *id) { struct pnp_dev *pdev; - struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); int err; - if (!cfg) - return -ENOMEM; acard->cap = pnp_request_card_device(card, id->devs[0].id, NULL); - if (acard->cap == NULL) { - kfree(cfg); + if (acard->cap == NULL) return -EBUSY; - } + acard->play = pnp_request_card_device(card, id->devs[1].id, NULL); - if (acard->play == NULL) { - kfree(cfg); + if (acard->play == NULL) return -EBUSY; - } pdev = acard->cap; - pnp_init_resource_table(cfg); - /* allocate AD1848 resources */ - if (wssport[dev] != SNDRV_AUTO_PORT) - pnp_resource_change(&cfg->port_resource[0], wssport[dev], 8); - if (wssdma[dev] != SNDRV_AUTO_DMA) - pnp_resource_change(&cfg->dma_resource[0], wssdma[dev], 1); - if (wssirq[dev] != SNDRV_AUTO_IRQ) - pnp_resource_change(&cfg->irq_resource[0], wssirq[dev], 1); - - err = pnp_manual_config_dev(pdev, cfg, 0); - if (err < 0) - snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP manual resources are invalid, using auto config\n"); + err = pnp_activate_dev(pdev); if (err < 0) { snd_printk(KERN_ERR "CMI8330/C3D (AD1848) PnP configure failure\n"); - kfree(cfg); return -EBUSY; } wssport[dev] = pnp_port_start(pdev, 0); @@ -327,23 +308,10 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard, /* allocate SB16 resources */ pdev = acard->play; - pnp_init_resource_table(cfg); - if (sbport[dev] != SNDRV_AUTO_PORT) - pnp_resource_change(&cfg->port_resource[0], sbport[dev], 16); - if (sbdma8[dev] != SNDRV_AUTO_DMA) - pnp_resource_change(&cfg->dma_resource[0], sbdma8[dev], 1); - if (sbdma16[dev] != SNDRV_AUTO_DMA) - pnp_resource_change(&cfg->dma_resource[1], sbdma16[dev], 1); - if (sbirq[dev] != SNDRV_AUTO_IRQ) - pnp_resource_change(&cfg->irq_resource[0], sbirq[dev], 1); - - err = pnp_manual_config_dev(pdev, cfg, 0); - if (err < 0) - snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP manual resources are invalid, using auto config\n"); + err = pnp_activate_dev(pdev); if (err < 0) { snd_printk(KERN_ERR "CMI8330/C3D (SB16) PnP configure failure\n"); - kfree(cfg); return -EBUSY; } sbport[dev] = pnp_port_start(pdev, 0); @@ -351,7 +319,6 @@ static int __devinit snd_cmi8330_pnp(int dev, struct snd_cmi8330 *acard, sbdma16[dev] = pnp_dma(pdev, 1); sbirq[dev] = pnp_irq(pdev, 0); - kfree(cfg); return 0; } #endif @@ -547,70 +514,78 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev) return snd_card_register(card); } -static int __devinit snd_cmi8330_nonpnp_probe(struct platform_device *pdev) +static int __devinit snd_cmi8330_isa_match(struct device *pdev, + unsigned int dev) { - struct snd_card *card; - int err; - int dev = pdev->id; - + if (!enable[dev] || is_isapnp_selected(dev)) + return 0; if (wssport[dev] == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR PFX "specify wssport\n"); - return -EINVAL; + return 0; } if (sbport[dev] == SNDRV_AUTO_PORT) { snd_printk(KERN_ERR PFX "specify sbport\n"); - return -EINVAL; + return 0; } + return 1; +} + +static int __devinit snd_cmi8330_isa_probe(struct device *pdev, + unsigned int dev) +{ + struct snd_card *card; + int err; card = snd_cmi8330_card_new(dev); if (! card) return -ENOMEM; - snd_card_set_dev(card, &pdev->dev); + snd_card_set_dev(card, pdev); if ((err = snd_cmi8330_probe(card, dev)) < 0) { snd_card_free(card); return err; } - platform_set_drvdata(pdev, card); + dev_set_drvdata(pdev, card); return 0; } -static int __devexit snd_cmi8330_nonpnp_remove(struct platform_device *devptr) +static int __devexit snd_cmi8330_isa_remove(struct device *devptr, + unsigned int dev) { - snd_card_free(platform_get_drvdata(devptr)); - platform_set_drvdata(devptr, NULL); + snd_card_free(dev_get_drvdata(devptr)); + dev_set_drvdata(devptr, NULL); return 0; } #ifdef CONFIG_PM -static int snd_cmi8330_nonpnp_suspend(struct platform_device *dev, pm_message_t state) +static int snd_cmi8330_isa_suspend(struct device *dev, unsigned int n, + pm_message_t state) { - return snd_cmi8330_suspend(platform_get_drvdata(dev)); + return snd_cmi8330_suspend(dev_get_drvdata(dev)); } -static int snd_cmi8330_nonpnp_resume(struct platform_device *dev) +static int snd_cmi8330_isa_resume(struct device *dev, unsigned int n) { - return snd_cmi8330_resume(platform_get_drvdata(dev)); + return snd_cmi8330_resume(dev_get_drvdata(dev)); } #endif -#define CMI8330_DRIVER "snd_cmi8330" +#define DEV_NAME "cmi8330" -static struct platform_driver snd_cmi8330_driver = { - .probe = snd_cmi8330_nonpnp_probe, - .remove = __devexit_p(snd_cmi8330_nonpnp_remove), +static struct isa_driver snd_cmi8330_driver = { + .match = snd_cmi8330_isa_match, + .probe = snd_cmi8330_isa_probe, + .remove = __devexit_p(snd_cmi8330_isa_remove), #ifdef CONFIG_PM - .suspend = snd_cmi8330_nonpnp_suspend, - .resume = snd_cmi8330_nonpnp_resume, + .suspend = snd_cmi8330_isa_suspend, + .resume = snd_cmi8330_isa_resume, #endif .driver = { - .name = CMI8330_DRIVER + .name = DEV_NAME }, }; #ifdef CONFIG_PNP -static unsigned int __devinitdata cmi8330_pnp_devices; - static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *pcard, const struct pnp_card_device_id *pid) { @@ -640,7 +615,6 @@ static int __devinit snd_cmi8330_pnp_detect(struct pnp_card_link *pcard, } pnp_set_card_drvdata(pcard, card); dev++; - cmi8330_pnp_devices++; return 0; } @@ -675,63 +649,34 @@ static struct pnp_card_driver cmi8330_pnpc_driver = { }; #endif /* CONFIG_PNP */ -static void __init_or_module snd_cmi8330_unregister_all(void) -{ - int i; - -#ifdef CONFIG_PNP - if (pnp_registered) - pnp_unregister_card_driver(&cmi8330_pnpc_driver); -#endif - for (i = 0; i < ARRAY_SIZE(platform_devices); ++i) - platform_device_unregister(platform_devices[i]); - platform_driver_unregister(&snd_cmi8330_driver); -} - static int __init alsa_card_cmi8330_init(void) { - int i, err, cards = 0; - - if ((err = platform_driver_register(&snd_cmi8330_driver)) < 0) - return err; - - for (i = 0; i < SNDRV_CARDS; i++) { - struct platform_device *device; - if (! enable[i] || is_isapnp_selected(i)) - continue; - device = platform_device_register_simple(CMI8330_DRIVER, - i, NULL, 0); - if (IS_ERR(device)) - continue; - if (!platform_get_drvdata(device)) { - platform_device_unregister(device); - continue; - } - platform_devices[i] = device; - cards++; - } + int err; + err = isa_register_driver(&snd_cmi8330_driver, SNDRV_CARDS); #ifdef CONFIG_PNP + if (!err) + isa_registered = 1; + err = pnp_register_card_driver(&cmi8330_pnpc_driver); - if (!err) { + if (!err) pnp_registered = 1; - cards += cmi8330_pnp_devices; - } -#endif - if (!cards) { -#ifdef MODULE - snd_printk(KERN_ERR "CMI8330 not found or device busy\n"); + if (isa_registered) + err = 0; #endif - snd_cmi8330_unregister_all(); - return -ENODEV; - } - return 0; + return err; } static void __exit alsa_card_cmi8330_exit(void) { - snd_cmi8330_unregister_all(); +#ifdef CONFIG_PNP + if (pnp_registered) + pnp_unregister_card_driver(&cmi8330_pnpc_driver); + + if (isa_registered) +#endif + isa_unregister_driver(&snd_cmi8330_driver); } module_init(alsa_card_cmi8330_init)