Commit 0c83affb authored by Adam Belay's avatar Adam Belay

ALS100 Updates

Updates the als100 driver to use the pnp apis.  Includes resource config
templates.
parent ba4d3dce
...@@ -24,11 +24,7 @@ ...@@ -24,11 +24,7 @@
#include <linux/init.h> #include <linux/init.h>
#include <linux/wait.h> #include <linux/wait.h>
#include <linux/time.h> #include <linux/time.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>
...@@ -96,167 +92,126 @@ MODULE_PARM_DESC(dma16, "16-bit DMA # for als100 driver."); ...@@ -96,167 +92,126 @@ MODULE_PARM_DESC(dma16, "16-bit DMA # for als100 driver.");
MODULE_PARM_SYNTAX(dma16, SNDRV_DMA16_DESC); MODULE_PARM_SYNTAX(dma16, SNDRV_DMA16_DESC);
struct snd_card_als100 { struct snd_card_als100 {
#ifdef __ISAPNP__ int dev_no;
struct isapnp_dev *dev; struct pnp_dev *dev;
struct isapnp_dev *devmpu; struct pnp_dev *devmpu;
struct isapnp_dev *devopl; struct pnp_dev *devopl;
#endif /* __ISAPNP__ */
}; };
static snd_card_t *snd_als100_cards[SNDRV_CARDS] = SNDRV_DEFAULT_PTR; static struct pnp_card_id snd_als100_pnpids[] __devinitdata = {
#ifdef __ISAPNP__
static struct isapnp_card *snd_als100_isapnp_cards[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
static const struct isapnp_card_id *snd_als100_isapnp_id[SNDRV_CARDS] __devinitdata = SNDRV_DEFAULT_PTR;
#define ISAPNP_ALS100(_va, _vb, _vc, _device, _audio, _mpu401, _opl) \
{ \
ISAPNP_CARD_ID(_va, _vb, _vc, _device), \
devs : { ISAPNP_DEVICE_ID('@', '@', '@', _audio), \
ISAPNP_DEVICE_ID('@', 'X', '@', _mpu401), \
ISAPNP_DEVICE_ID('@', 'H', '@', _opl) } \
}
static struct isapnp_card_id snd_als100_pnpids[] __devinitdata = {
/* ALS100 - PRO16PNP */ /* ALS100 - PRO16PNP */
ISAPNP_ALS100('A','L','S',0x0001,0x0001,0x0001,0x0001), { .id = "ALS0001", .devs = { { "@@@0001" }, { "@X@0001" }, { "@H@0001" }, } },
/* ALS110 - MF1000 - Digimate 3D Sound */ /* ALS110 - MF1000 - Digimate 3D Sound */
ISAPNP_ALS100('A','L','S',0x0110,0x1001,0x1001,0x1001), { .id = "ALS0110", .devs = { { "@@@1001" }, { "@X@1001" }, { "@H@1001" }, } },
/* ALS120 */ /* ALS120 */
ISAPNP_ALS100('A','L','S',0x0120,0x2001,0x2001,0x2001), { .id = "ALS0120", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
/* ALS200 */ /* ALS200 */
ISAPNP_ALS100('A','L','S',0x0200,0x0020,0x0020,0x0001), { .id = "ALS0200", .devs = { { "@@@0020" }, { "@X@0020" }, { "@H@0001" }, } },
/* RTL3000 */ /* RTL3000 */
ISAPNP_ALS100('R','T','L',0x3000,0x2001,0x2001,0x2001), { .id = "RTL3000", .devs = { { "@@@2001" }, { "@X@2001" }, { "@H@2001" }, } },
{ ISAPNP_CARD_END, } { .id = "", } /* end */
}; };
ISAPNP_CARD_TABLE(snd_als100_pnpids); MODULE_DEVICE_TABLE(pnp_card, snd_als100_pnpids);
#endif /* __ISAPNP__ */
#define DRIVER_NAME "snd-card-als100" #define DRIVER_NAME "snd-card-als100"
static struct pnp_card_driver als100_pnpc_driver;
#ifdef __ISAPNP__ static int __devinit snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard,
static int __init snd_card_als100_isapnp(int dev, struct snd_card_als100 *acard) struct pnp_card *card,
const struct pnp_card_id *id)
{ {
const struct isapnp_card_id *id = snd_als100_isapnp_id[dev]; struct pnp_dev *pdev;
struct isapnp_card *card = snd_als100_isapnp_cards[dev]; struct pnp_resource_table * cfg = kmalloc(GFP_ATOMIC, sizeof(struct pnp_resource_table));
struct isapnp_dev *pdev; int err;
if (!cfg)
acard->dev = isapnp_find_dev(card, id->devs[0].vendor, id->devs[0].function, NULL); return -ENOMEM;
if (acard->dev->active) { acard->dev = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[0].id, NULL);
acard->dev = NULL; if (acard->dev == NULL) {
return -EBUSY; kfree(cfg);
} return -ENODEV;
acard->devmpu = isapnp_find_dev(card, id->devs[1].vendor, id->devs[1].function, NULL);
if (acard->devmpu->active) {
acard->dev = acard->devmpu = NULL;
return -EBUSY;
}
acard->devopl = isapnp_find_dev(card, id->devs[2].vendor, id->devs[2].function, NULL);
if (acard->devopl->active) {
acard->dev = acard->devmpu = acard->devopl = NULL;
return -EBUSY;
} }
acard->devmpu = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[1].id, acard->dev);
acard->devopl = pnp_request_card_device(&als100_pnpc_driver, card, id->devs[2].id, acard->devmpu);
pdev = acard->dev; pdev = acard->dev;
if (pdev->prepare(pdev)<0)
return -EAGAIN;
pnp_init_resource_table(cfg);
/* 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 (dma8[dev] != SNDRV_AUTO_DMA) if (dma8[dev] != SNDRV_AUTO_DMA)
isapnp_resource_change(&pdev->dma_resource[0], dma8[dev], pnp_resource_change(&cfg->dma_resource[0], dma8[dev], 1);
1);
if (dma16[dev] != SNDRV_AUTO_DMA) if (dma16[dev] != SNDRV_AUTO_DMA)
isapnp_resource_change(&pdev->dma_resource[1], dma16[dev], pnp_resource_change(&cfg->dma_resource[1], dma16[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"); err = pnp_activate_dev(pdev);
return -EBUSY; if (err < 0) {
printk(KERN_ERR PFX "AUDIO pnp configure failure\n");
return err;
} }
port[dev] = pnp_port_start(pdev, 0);
port[dev] = pdev->resource[0].start; dma8[dev] = pnp_dma(pdev, 1);
dma8[dev] = pdev->dma_resource[1].start; dma16[dev] = pnp_dma(pdev, 0);
dma16[dev] = pdev->dma_resource[0].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);
printk(KERN_ERR PFX "MPU-401 isapnp configure failure\n"); if (err < 0)
mpu_port[dev] = -1; goto __mpu_error;
acard->devmpu = NULL; mpu_port[dev] = pnp_port_start(pdev, 0);
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;
pdev = acard->devopl; mpu_port[dev] = -1;
if (pdev == NULL || pdev->prepare(pdev)<0) {
fm_port[dev] = -1;
return 0;
} }
pdev = acard->devopl;
if (pdev != NULL) {
pnp_init_resource_table(cfg);
if (fm_port[dev] != SNDRV_AUTO_PORT) if (fm_port[dev] != SNDRV_AUTO_PORT)
isapnp_resource_change(&pdev->resource[0], fm_port[dev], 4); pnp_resource_change(&cfg->port_resource[0], fm_port[dev], 4);
if ((pnp_manual_config_dev(pdev, cfg, 0)) < 0)
if (pdev->activate(pdev)<0) { printk(KERN_ERR PFX "OPL3 the requested resources are invalid, using auto config\n");
printk(KERN_ERR PFX "OPL isapnp configure failure\n"); err = pnp_activate_dev(pdev);
fm_port[dev] = -1; if (err < 0)
acard->devopl = NULL; goto __fm_error;
fm_port[dev] = pnp_port_start(pdev, 0);
} else { } else {
fm_port[dev] = pdev->resource[0].start; __fm_error:
} if (pdev) {
pnp_release_card_device(pdev);
return 0; printk(KERN_ERR PFX "OPL3 pnp configure failure, skipping\n");
}
static void snd_card_als100_deactivate(struct snd_card_als100 *acard)
{
if (acard->dev) {
acard->dev->deactivate(acard->dev);
acard->dev = NULL;
}
if (acard->devmpu) {
acard->devmpu->deactivate(acard->devmpu);
acard->devmpu = NULL;
} }
if (acard->devopl) {
acard->devopl->deactivate(acard->devopl);
acard->devopl = NULL; acard->devopl = NULL;
fm_port[dev] = -1;
} }
}
#endif /* __ISAPNP__ */
static void snd_card_als100_free(snd_card_t *card) kfree(cfg);
{ return 0;
struct snd_card_als100 *acard = (struct snd_card_als100 *)card->private_data;
if (acard) {
#ifdef __ISAPNP__
snd_card_als100_deactivate(acard);
#endif /* __ISAPNP__ */
}
} }
static int __init snd_card_als100_probe(int dev) static int __init snd_card_als100_probe(int dev,
struct pnp_card *pcard,
const struct pnp_card_id *pid)
{ {
int error; int error;
sb_t *chip; sb_t *chip;
...@@ -268,18 +223,11 @@ static int __init snd_card_als100_probe(int dev) ...@@ -268,18 +223,11 @@ static int __init snd_card_als100_probe(int dev)
sizeof(struct snd_card_als100))) == NULL) sizeof(struct snd_card_als100))) == NULL)
return -ENOMEM; return -ENOMEM;
acard = (struct snd_card_als100 *)card->private_data; acard = (struct snd_card_als100 *)card->private_data;
card->private_free = snd_card_als100_free;
#ifdef __ISAPNP__ if ((error = snd_card_als100_isapnp(dev, acard, pcard, pid))) {
if ((error = snd_card_als100_isapnp(dev, acard))) {
snd_card_free(card); snd_card_free(card);
return error; return error;
} }
#else
printk(KERN_ERR PFX "you have to enable PnP support ...\n");
snd_card_free(card);
return -ENOSYS;
#endif /* __ISAPNP__ */
if ((error = snd_sbdsp_create(card, port[dev], if ((error = snd_sbdsp_create(card, port[dev],
irq[dev], irq[dev],
...@@ -336,13 +284,12 @@ static int __init snd_card_als100_probe(int dev) ...@@ -336,13 +284,12 @@ static int __init snd_card_als100_probe(int dev)
snd_card_free(card); snd_card_free(card);
return error; return error;
} }
snd_als100_cards[dev] = card; pnp_set_card_drvdata(pcard, card);
return 0; return 0;
} }
#ifdef __ISAPNP__ static int __devinit snd_als100_pnp_detect(struct pnp_card *card,
static int __init snd_als100_isapnp_detect(struct isapnp_card *card, const struct pnp_card_id *id)
const struct isapnp_card_id *id)
{ {
static int dev; static int dev;
int res; int res;
...@@ -350,9 +297,7 @@ static int __init snd_als100_isapnp_detect(struct isapnp_card *card, ...@@ -350,9 +297,7 @@ static int __init snd_als100_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_als100_isapnp_cards[dev] = card; res = snd_card_als100_probe(dev, card, id);
snd_als100_isapnp_id[dev] = id;
res = snd_card_als100_probe(dev);
if (res < 0) if (res < 0)
return res; return res;
dev++; dev++;
...@@ -360,17 +305,28 @@ static int __init snd_als100_isapnp_detect(struct isapnp_card *card, ...@@ -360,17 +305,28 @@ static int __init snd_als100_isapnp_detect(struct isapnp_card *card,
} }
return -ENODEV; return -ENODEV;
} }
#endif
static void __devexit snd_als100_pnp_remove(struct pnp_card * 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 als100_pnpc_driver = {
.flags = PNP_DRIVER_RES_DISABLE,
.name = "als100",
.id_table = snd_als100_pnpids,
.probe = snd_als100_pnp_detect,
.remove = __devexit_p(snd_als100_pnp_remove),
};
static int __init alsa_card_als100_init(void) static int __init alsa_card_als100_init(void)
{ {
int cards = 0; int cards = 0;
#ifdef __ISAPNP__ cards += pnp_register_card_driver(&als100_pnpc_driver);
cards += isapnp_probe_cards(snd_als100_pnpids, snd_als100_isapnp_detect);
#else
printk(KERN_ERR PFX "you have to enable ISA PnP support.\n");
#endif
#ifdef MODULE #ifdef MODULE
if (!cards) if (!cards)
printk(KERN_ERR "no ALS100 based soundcards found\n"); printk(KERN_ERR "no ALS100 based soundcards found\n");
...@@ -380,10 +336,7 @@ static int __init alsa_card_als100_init(void) ...@@ -380,10 +336,7 @@ static int __init alsa_card_als100_init(void)
static void __exit alsa_card_als100_exit(void) static void __exit alsa_card_als100_exit(void)
{ {
int dev; pnp_unregister_card_driver(&als100_pnpc_driver);
for (dev = 0; dev < SNDRV_CARDS; dev++)
snd_card_free(snd_als100_cards[dev]);
} }
module_init(alsa_card_als100_init) module_init(alsa_card_als100_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