Commit 8faa56b9 authored by Adam Belay's avatar Adam Belay

AZT2320 PnP Updates

Converts this driver to the pnp api.
parent 2612989b
...@@ -36,11 +36,7 @@ ...@@ -36,11 +36,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/time.h> #include <linux/time.h>
#include <linux/wait.h> #include <linux/wait.h>
#ifndef LINUX_ISAPNP_H #include <linux/pnp.h>
#include <linux/isapnp.h>
#define isapnp_card pci_bus
#define isapnp_dev pci_dev
#endif
#include <sound/core.h> #include <sound/core.h>
#define SNDRV_GET_ID #define SNDRV_GET_ID
#include <sound/initval.h> #include <sound/initval.h>
...@@ -109,134 +105,112 @@ MODULE_PARM_DESC(dma2, "2nd DMA # for azt2320 driver."); ...@@ -109,134 +105,112 @@ MODULE_PARM_DESC(dma2, "2nd DMA # for azt2320 driver.");
MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC); MODULE_PARM_SYNTAX(dma2, SNDRV_DMA_DESC);
struct snd_card_azt2320 { struct snd_card_azt2320 {
#ifdef __ISAPNP__ #ifdef CONFIG_PNP
struct isapnp_dev *dev; int dev_no;
struct isapnp_dev *devmpu; struct pnp_dev *dev;
#endif /* __ISAPNP__ */ struct pnp_dev *devmpu;
#endif /* CONFIG_PNP */
}; };
static snd_card_t *snd_azt2320_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; static struct pnp_card_device_id snd_azt2320_pnpids[] __devinitdata = {
#ifdef __ISAPNP__
static struct isapnp_card *snd_azt2320_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
static const struct isapnp_card_id *snd_azt2320_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
#define ISAPNP_AZT2320(_va, _vb, _vc, _device, _audio, _mpu401) \
{ \
ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
.devs = { ISAPNP_DEVICE_ID(_va, _vb, _vc, _audio), \
ISAPNP_DEVICE_ID(_va, _vb, _vc, _mpu401), } \
}
static struct isapnp_card_id snd_azt2320_pnpids[] __devinitdata = {
/* PRO16V */ /* PRO16V */
ISAPNP_AZT2320('A','Z','T',0x1008,0x1008,0x2001), { .id = "AZT1008", .devs = { { "AZT1008" }, { "AZT2001" }, } },
/* Aztech Sound Galaxy 16 */ /* Aztech Sound Galaxy 16 */
ISAPNP_AZT2320('A','Z','T',0x2320,0x0001,0x0002), { .id = "AZT2320", .devs = { { "AZT0001" }, { "AZT0002" }, } },
/* Packard Bell Sound III 336 AM/SP */ /* Packard Bell Sound III 336 AM/SP */
ISAPNP_AZT2320('A','Z','T',0x3000,0x1003,0x2001), { .id = "AZT3000", .devs = { { "AZT1003" }, { "AZT2001" }, } },
/* AT3300 */ /* AT3300 */
ISAPNP_AZT2320('A','Z','T',0x3002,0x1004,0x2001), { .id = "AZT3002", .devs = { { "AZT1004" }, { "AZT2001" }, } },
/* --- */ /* --- */
ISAPNP_AZT2320('A','Z','T',0x3005,0x1003,0x2001), { .id = "AZT3005", .devs = { { "AZT1003" }, { "AZT2001" }, } },
/* --- */ /* --- */
ISAPNP_AZT2320('A','Z','T',0x3011,0x1003,0x2001), { .id = "AZT3011", .devs = { { "AZT1003" }, { "AZT2001" }, } },
{ ISAPNP_CARD_END, } /* end */ { .id = "" } /* end */
}; };
ISAPNP_CARD_TABLE(snd_azt2320_pnpids); MODULE_DEVICE_TABLE(pnp_card, snd_azt2320_pnpids);
#endif /* __ISAPNP__ */
#define DRIVER_NAME "snd-card-azt2320" #define DRIVER_NAME "snd-card-azt2320"
static int __init snd_card_azt2320_isapnp(int dev, struct snd_card_azt2320 *acard,
#ifdef __ISAPNP__ struct pnp_card_link *card,
static int __init snd_card_azt2320_isapnp(int dev, struct snd_card_azt2320 *acard) const struct pnp_card_device_id *id)
{ {
const struct isapnp_card_id *id = snd_azt2320_isapnp_id[dev]; struct pnp_dev *pdev;
struct isapnp_card *card = snd_azt2320_isapnp_cards[dev]; struct pnp_resource_table * cfg = kmalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
struct isapnp_dev *pdev; int err;
acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL); if (!cfg)
if (acard->dev->active) { return -ENOMEM;
acard->dev = NULL;
return -EBUSY; acard->dev = pnp_request_card_device(card, id->devs[0].id, NULL);
} if (acard->dev == NULL) {
acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL); kfree(cfg);
if (acard->devmpu->active) { return -ENODEV;
acard->dev = acard->devmpu = NULL;
return -EBUSY;
} }
acard->devmpu = pnp_request_card_device(card, id->devs[1].id, NULL);
pdev = acard->dev; pdev = acard->dev;
if (pdev->prepare(pdev) < 0) pnp_init_resource_table(cfg);
return -EAGAIN;
/* override resources */
if (port[dev] != SNDRV_AUTO_PORT) if (port[dev] != SNDRV_AUTO_PORT)
isapnp_resource_change(&pdev->resource[0], port[dev], 16); pnp_resource_change(&cfg->port_resource[0], port[dev], 16);
if (fm_port[dev] != SNDRV_AUTO_PORT) if (fm_port[dev] != SNDRV_AUTO_PORT)
isapnp_resource_change(&pdev->resource[1], fm_port[dev], 4); pnp_resource_change(&cfg->port_resource[1], fm_port[dev], 4);
if (wss_port[dev] != SNDRV_AUTO_PORT) if (wss_port[dev] != SNDRV_AUTO_PORT)
isapnp_resource_change(&pdev->resource[2], wss_port[dev], pnp_resource_change(&cfg->port_resource[2], wss_port[dev], 4);
4);
if (dma1[dev] != SNDRV_AUTO_DMA) if (dma1[dev] != SNDRV_AUTO_DMA)
isapnp_resource_change(&pdev->dma_resource[0], dma1[dev], pnp_resource_change(&cfg->dma_resource[0], dma1[dev], 1);
1);
if (dma2[dev] != SNDRV_AUTO_DMA) if (dma2[dev] != SNDRV_AUTO_DMA)
isapnp_resource_change(&pdev->dma_resource[1], dma2[dev], pnp_resource_change(&cfg->dma_resource[1], dma2[dev], 1);
1);
if (irq[dev] != SNDRV_AUTO_IRQ) if (irq[dev] != SNDRV_AUTO_IRQ)
isapnp_resource_change(&pdev->irq_resource[0], irq[dev], 1); pnp_resource_change(&cfg->irq_resource[0], irq[dev], 1);
if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
if (pdev->activate(pdev) < 0) { printk(KERN_ERR PFX "AUDIO the requested resources are invalid, using auto config\n");
printk(KERN_ERR PFX "AUDIO isapnp configure failure\n");
return -EBUSY; err = pnp_activate_dev(pdev);
if (err < 0) {
printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
kfree(cfg);
return err;
} }
port[dev] = pnp_port_start(pdev, 0);
port[dev] = pdev->resource[0].start; fm_port[dev] = pnp_port_start(pdev, 1);
fm_port[dev] = pdev->resource[1].start; wss_port[dev] = pnp_port_start(pdev, 2);
wss_port[dev] = pdev->resource[2].start; dma1[dev] = pnp_dma(pdev, 0);
dma1[dev] = pdev->dma_resource[0].start; dma2[dev] = pnp_dma(pdev, 1);
dma2[dev] = pdev->dma_resource[1].start; irq[dev] = pnp_irq(pdev, 0);
irq[dev] = pdev->irq_resource[0].start;
pdev = acard->devmpu; pdev = acard->devmpu;
if (pdev == NULL || pdev->prepare(pdev) < 0) { if (pdev != NULL) {
mpu_port[dev] = -1; pnp_init_resource_table(cfg);
return 0;
}
if (mpu_port[dev] != SNDRV_AUTO_PORT) if (mpu_port[dev] != SNDRV_AUTO_PORT)
isapnp_resource_change(&pdev->resource[0], mpu_port[dev], pnp_resource_change(&cfg->port_resource[0], mpu_port[dev], 2);
2);
if (mpu_irq[dev] != SNDRV_AUTO_IRQ) if (mpu_irq[dev] != SNDRV_AUTO_IRQ)
isapnp_resource_change(&pdev->irq_resource[0], mpu_irq[dev], pnp_resource_change(&cfg->irq_resource[0], mpu_irq[dev], 1);
1); if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
printk(KERN_ERR PFX "MPU401 the requested resources are invalid, using auto config\n");
if (pdev->activate(pdev) < 0) { err = pnp_activate_dev(pdev);
/* not fatal error */ if (err < 0)
printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n"); goto __mpu_error;
mpu_port[dev] = -1; mpu_port[dev] = pnp_port_start(pdev, 0);
acard->devmpu = NULL; mpu_irq[dev] = pnp_irq(pdev, 0);
} else { } else {
mpu_port[dev] = pdev->resource[0].start; __mpu_error:
mpu_irq[dev] = pdev->irq_resource[0].start; if (pdev) {
pnp_release_card_device(pdev);
printk(KERN_ERR PFX "MPU401 pnp configure failure, skipping\n");
}
acard->devmpu = NULL;
mpu_port[dev] = -1;
} }
kfree (cfg);
return 0; return 0;
} }
static void snd_card_azt2320_deactivate(struct snd_card_azt2320 *acard)
{
if (acard->dev)
acard->dev->deactivate(acard->dev);
if (acard->devmpu)
acard->devmpu->deactivate(acard->devmpu);
}
#endif /* __ISAPNP__ */
/* same of snd_sbdsp_command by Jaroslav Kysela */ /* same of snd_sbdsp_command by Jaroslav Kysela */
static int __init snd_card_azt2320_command(unsigned long port, unsigned char val) static int __init snd_card_azt2320_command(unsigned long port, unsigned char val)
{ {
...@@ -265,18 +239,9 @@ static int __init snd_card_azt2320_enable_wss(unsigned long port) ...@@ -265,18 +239,9 @@ static int __init snd_card_azt2320_enable_wss(unsigned long port)
return 0; return 0;
} }
static void snd_card_azt2320_free(snd_card_t *card) static int __init snd_card_azt2320_probe(int dev,
{ struct pnp_card_link *pcard,
struct snd_card_azt2320 *acard = (struct snd_card_azt2320 *)card->private_data; const struct pnp_card_device_id *pid)
if (acard) {
#ifdef __ISAPNP__
snd_card_azt2320_deactivate(acard);
#endif /* __ISAPNP__ */
}
}
static int __init snd_card_azt2320_probe(int dev)
{ {
int error; int error;
snd_card_t *card; snd_card_t *card;
...@@ -288,14 +253,11 @@ static int __init snd_card_azt2320_probe(int dev) ...@@ -288,14 +253,11 @@ static int __init snd_card_azt2320_probe(int dev)
sizeof(struct snd_card_azt2320))) == NULL) sizeof(struct snd_card_azt2320))) == NULL)
return -ENOMEM; return -ENOMEM;
acard = (struct snd_card_azt2320 *)card->private_data; acard = (struct snd_card_azt2320 *)card->private_data;
card->private_free = snd_card_azt2320_free;
#ifdef __ISAPNP__ if ((error = snd_card_azt2320_isapnp(dev, acard, pcard, pid))) {
if ((error = snd_card_azt2320_isapnp(dev, acard))) {
snd_card_free(card); snd_card_free(card);
return error; return error;
} }
#endif /* __ISAPNP__ */
if ((error = snd_card_azt2320_enable_wss(port[dev]))) { if ((error = snd_card_azt2320_enable_wss(port[dev]))) {
snd_card_free(card); snd_card_free(card);
...@@ -360,13 +322,12 @@ static int __init snd_card_azt2320_probe(int dev) ...@@ -360,13 +322,12 @@ static int __init snd_card_azt2320_probe(int dev)
snd_card_free(card); snd_card_free(card);
return error; return error;
} }
snd_azt2320_cards[dev] = card; pnp_set_card_drvdata(pcard, card);
return 0; return 0;
} }
#ifdef __ISAPNP__ static int __init snd_azt2320_pnp_detect(struct pnp_card_link *card,
static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card, const struct pnp_card_device_id *id)
const struct isapnp_card_id *id)
{ {
static int dev; static int dev;
int res; int res;
...@@ -374,9 +335,7 @@ static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card, ...@@ -374,9 +335,7 @@ static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card,
for ( ; dev < SNDRV_CARDS; dev++) { for ( ; dev < SNDRV_CARDS; dev++) {
if (!enable[dev]) if (!enable[dev])
continue; continue;
snd_azt2320_isapnp_cards[dev] = card; res = snd_card_azt2320_probe(dev,card,id);
snd_azt2320_isapnp_id[dev] = id;
res = snd_card_azt2320_probe(dev);
if (res < 0) if (res < 0)
return res; return res;
dev++; dev++;
...@@ -384,7 +343,22 @@ static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card, ...@@ -384,7 +343,22 @@ static int __init snd_azt2320_isapnp_detect(struct isapnp_card *card,
} }
return -ENODEV; return -ENODEV;
} }
#endif
static void __devexit snd_azt2320_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);
}
static struct pnp_card_driver azt2320_pnpc_driver = {
.flags = PNP_DRIVER_RES_DISABLE,
.name = "azt2320",
.id_table = snd_azt2320_pnpids,
.probe = snd_azt2320_pnp_detect,
.remove = __devexit_p(snd_azt2320_pnp_remove),
};
static int __init alsa_card_azt2320_init(void) static int __init alsa_card_azt2320_init(void)
{ {
...@@ -395,6 +369,7 @@ static int __init alsa_card_azt2320_init(void) ...@@ -395,6 +369,7 @@ static int __init alsa_card_azt2320_init(void)
#else #else
printk(KERN_ERR PFX "you have to enable ISA PnP support.\n"); printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
#endif #endif
cards += pnp_register_card_driver(&azt2320_pnpc_driver);
#ifdef MODULE #ifdef MODULE
if (!cards) if (!cards)
printk(KERN_ERR "no AZT2320 based soundcards found\n"); printk(KERN_ERR "no AZT2320 based soundcards found\n");
...@@ -404,10 +379,7 @@ static int __init alsa_card_azt2320_init(void) ...@@ -404,10 +379,7 @@ static int __init alsa_card_azt2320_init(void)
static void __exit alsa_card_azt2320_exit(void) static void __exit alsa_card_azt2320_exit(void)
{ {
int dev; pnp_unregister_card_driver(&azt2320_pnpc_driver);
for (dev = 0; dev < SNDRV_CARDS; dev++)
snd_card_free(snd_azt2320_cards[dev]);
} }
module_init(alsa_card_azt2320_init) module_init(alsa_card_azt2320_init)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment