X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=sound%2Fisa%2Fad1848%2Fad1848.c;fp=sound%2Fisa%2Fad1848%2Fad1848.c;h=99908e44124da32593b6fa85ea87eafeb4cc1c6b;hb=43bc926fffd92024b46cafaf7350d669ba9ca884;hp=8c399340cd7240b4c75834d9037d87cade038958;hpb=cee37fe97739d85991964371c1f3a745c00dd236;p=linux-2.6.git diff --git a/sound/isa/ad1848/ad1848.c b/sound/isa/ad1848/ad1848.c index 8c399340c..99908e441 100644 --- a/sound/isa/ad1848/ad1848.c +++ b/sound/isa/ad1848/ad1848.c @@ -23,6 +23,8 @@ #include #include +#include +#include #include #include #include @@ -60,14 +62,15 @@ MODULE_PARM_DESC(dma1, "DMA1 # for AD1848 driver."); module_param_array(thinkpad, bool, NULL, 0444); MODULE_PARM_DESC(thinkpad, "Enable only for the onboard CS4248 of IBM Thinkpad 360/750/755 series."); -static snd_card_t *snd_ad1848_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; +static struct platform_device *devices[SNDRV_CARDS]; -static int __init snd_card_ad1848_probe(int dev) +static int __init snd_ad1848_probe(struct platform_device *pdev) { - snd_card_t *card; - ad1848_t *chip; - snd_pcm_t *pcm; + int dev = pdev->id; + struct snd_card *card; + struct snd_ad1848 *chip; + struct snd_pcm *pcm; int err; if (port[dev] == SNDRV_AUTO_PORT) { @@ -91,49 +94,119 @@ static int __init snd_card_ad1848_probe(int dev) irq[dev], dma1[dev], thinkpad[dev] ? AD1848_HW_THINKPAD : AD1848_HW_DETECT, - &chip)) < 0) { - snd_card_free(card); - return err; - } + &chip)) < 0) + goto _err; + card->private_data = chip; + + if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) + goto _err; + + if ((err = snd_ad1848_mixer(chip)) < 0) + goto _err; - if ((err = snd_ad1848_pcm(chip, 0, &pcm)) < 0) { - snd_card_free(card); - return err; - } - if ((err = snd_ad1848_mixer(chip)) < 0) { - snd_card_free(card); - return err; - } strcpy(card->driver, "AD1848"); strcpy(card->shortname, pcm->name); sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", pcm->name, chip->port, irq[dev], dma1[dev]); - if (thinkpad[dev]) { + if (thinkpad[dev]) strcat(card->longname, " [Thinkpad]"); - } - if ((err = snd_card_register(card)) < 0) { - snd_card_free(card); - return err; - } - snd_ad1848_cards[dev] = card; + snd_card_set_dev(card, &pdev->dev); + + if ((err = snd_card_register(card)) < 0) + goto _err; + + platform_set_drvdata(pdev, card); + return 0; + + _err: + snd_card_free(card); + return err; +} + +static int __devexit snd_ad1848_remove(struct platform_device *devptr) +{ + snd_card_free(platform_get_drvdata(devptr)); + platform_set_drvdata(devptr, NULL); return 0; } +#ifdef CONFIG_PM +static int snd_ad1848_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct snd_card *card = platform_get_drvdata(pdev); + struct snd_ad1848 *chip = card->private_data; + + snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); + chip->suspend(chip); + return 0; +} + +static int snd_ad1848_resume(struct platform_device *pdev) +{ + struct snd_card *card = platform_get_drvdata(pdev); + struct snd_ad1848 *chip = card->private_data; + + chip->resume(chip); + snd_power_change_state(card, SNDRV_CTL_POWER_D0); + return 0; +} +#endif + +#define SND_AD1848_DRIVER "snd_ad1848" + +static struct platform_driver snd_ad1848_driver = { + .probe = snd_ad1848_probe, + .remove = __devexit_p(snd_ad1848_remove), +#ifdef CONFIG_PM + .suspend = snd_ad1848_suspend, + .resume = snd_ad1848_resume, +#endif + .driver = { + .name = SND_AD1848_DRIVER + }, +}; + +static void __init_or_module snd_ad1848_unregister_all(void) +{ + int i; + + for (i = 0; i < ARRAY_SIZE(devices); ++i) + platform_device_unregister(devices[i]); + platform_driver_unregister(&snd_ad1848_driver); +} + static int __init alsa_card_ad1848_init(void) { - int dev, cards; + int i, cards, err; - for (dev = cards = 0; dev < SNDRV_CARDS && enable[dev]; dev++) - if (snd_card_ad1848_probe(dev) >= 0) - cards++; + err = platform_driver_register(&snd_ad1848_driver); + if (err < 0) + return err; + cards = 0; + for (i = 0; i < SNDRV_CARDS; i++) { + struct platform_device *device; + if (! enable[i]) + continue; + device = platform_device_register_simple(SND_AD1848_DRIVER, + i, NULL, 0); + if (IS_ERR(device)) + continue; + if (!platform_get_drvdata(device)) { + platform_device_unregister(device); + continue; + } + devices[i] = device; + cards++; + } if (!cards) { #ifdef MODULE printk(KERN_ERR "AD1848 soundcard not found or device busy\n"); #endif + snd_ad1848_unregister_all(); return -ENODEV; } return 0; @@ -141,10 +214,7 @@ static int __init alsa_card_ad1848_init(void) static void __exit alsa_card_ad1848_exit(void) { - int idx; - - for (idx = 0; idx < SNDRV_CARDS; idx++) - snd_card_free(snd_ad1848_cards[idx]); + snd_ad1848_unregister_all(); } module_init(alsa_card_ad1848_init)