Commit dfbf98b5 authored by Adam Belay's avatar Adam Belay

[PATCH] Convert CS4236B driver - 2.5.44 (3/4)

This patch converts the CS4236B sound card driver to the new PnP APIs.  Also it
makes pnp_driver_register return the number of matches during the driver add.
This should serve as a sample driver, along with the serial and parport_pc.
parent 0bf17971
...@@ -151,6 +151,8 @@ struct bus_type pnp_bus_type = { ...@@ -151,6 +151,8 @@ struct bus_type pnp_bus_type = {
int pnp_register_driver(struct pnp_driver *drv) int pnp_register_driver(struct pnp_driver *drv)
{ {
int count; int count;
struct list_head *pos;
pnp_dbg("the driver '%s' has been registered", drv->name); pnp_dbg("the driver '%s' has been registered", drv->name);
drv->driver.name = drv->name; drv->driver.name = drv->name;
...@@ -159,7 +161,15 @@ int pnp_register_driver(struct pnp_driver *drv) ...@@ -159,7 +161,15 @@ int pnp_register_driver(struct pnp_driver *drv)
drv->driver.remove = pnp_device_remove; drv->driver.remove = pnp_device_remove;
count = driver_register(&drv->driver); count = driver_register(&drv->driver);
return count ? count : 1;
/* get the number of initial matches */
if (count >= 0){
count = 0;
list_for_each(pos,&drv->driver.devices){
count++;
}
}
return count;
} }
void pnp_unregister_driver(struct pnp_driver *drv) void pnp_unregister_driver(struct pnp_driver *drv)
......
...@@ -94,7 +94,6 @@ struct pnp_driver { ...@@ -94,7 +94,6 @@ struct pnp_driver {
int (*probe) (struct pnp_dev *dev, const struct pnp_id *card_id, int (*probe) (struct pnp_dev *dev, const struct pnp_id *card_id,
const struct pnp_id *dev_id); const struct pnp_id *dev_id);
void (*remove) (struct pnp_dev *dev); void (*remove) (struct pnp_dev *dev);
struct device * (*legacy) (void);
struct device_driver driver; struct device_driver driver;
}; };
......
...@@ -3026,8 +3026,6 @@ static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_ ...@@ -3026,8 +3026,6 @@ static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_
{ {
char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name; char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
printk(KERN_INFO "ad1848: %s detected\n", busname);
/* Initialize this baby. */ /* Initialize this baby. */
if(ad1848_init_generic(bus, hw_config, slot)) { if(ad1848_init_generic(bus, hw_config, slot)) {
...@@ -3039,9 +3037,6 @@ static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_ ...@@ -3039,9 +3037,6 @@ static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_
hw_config->dma2); hw_config->dma2);
return 1; return 1;
} }
else
printk(KERN_INFO "ad1848: Failed to initialize %s\n", busname);
return 0; return 0;
} }
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
*/ */
#include <linux/config.h> #include <linux/config.h>
#include <linux/isapnp.h> #include <linux/pnp.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/init.h> #include <linux/init.h>
...@@ -71,7 +71,7 @@ static int mpu_base = 0, mpu_irq = 0; ...@@ -71,7 +71,7 @@ static int mpu_base = 0, mpu_irq = 0;
static int synth_base = 0, synth_irq = 0; static int synth_base = 0, synth_irq = 0;
static int mpu_detected = 0; static int mpu_detected = 0;
int __init probe_cs4232_mpu(struct address_info *hw_config) int probe_cs4232_mpu(struct address_info *hw_config)
{ {
/* /*
* Just write down the config values. * Just write down the config values.
...@@ -83,7 +83,7 @@ int __init probe_cs4232_mpu(struct address_info *hw_config) ...@@ -83,7 +83,7 @@ int __init probe_cs4232_mpu(struct address_info *hw_config)
return 1; return 1;
} }
static unsigned char crystal_key[] __initdata = /* A 32 byte magic key sequence */ static unsigned char crystal_key[] = /* A 32 byte magic key sequence */
{ {
0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc, 0x96, 0x35, 0x9a, 0xcd, 0xe6, 0xf3, 0x79, 0xbc,
0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2, 0x5e, 0xaf, 0x57, 0x2b, 0x15, 0x8a, 0xc5, 0xe2,
...@@ -97,7 +97,7 @@ static void sleep(unsigned howlong) ...@@ -97,7 +97,7 @@ static void sleep(unsigned howlong)
schedule_timeout(howlong); schedule_timeout(howlong);
} }
int __init probe_cs4232(struct address_info *hw_config, int isapnp_configured) int probe_cs4232(struct address_info *hw_config, int isapnp_configured)
{ {
int i, n; int i, n;
int base = hw_config->io_base, irq = hw_config->irq; int base = hw_config->io_base, irq = hw_config->irq;
...@@ -218,7 +218,7 @@ int __init probe_cs4232(struct address_info *hw_config, int isapnp_configured) ...@@ -218,7 +218,7 @@ int __init probe_cs4232(struct address_info *hw_config, int isapnp_configured)
return 0; return 0;
} }
void __init attach_cs4232(struct address_info *hw_config) void attach_cs4232(struct address_info *hw_config)
{ {
int base = hw_config->io_base, int base = hw_config->io_base,
irq = hw_config->irq, irq = hw_config->irq,
...@@ -277,7 +277,7 @@ void __init attach_cs4232(struct address_info *hw_config) ...@@ -277,7 +277,7 @@ void __init attach_cs4232(struct address_info *hw_config)
} }
} }
static void __exit unload_cs4232(struct address_info *hw_config) static void unload_cs4232(struct address_info *hw_config)
{ {
int base = hw_config->io_base, irq = hw_config->irq; int base = hw_config->io_base, irq = hw_config->irq;
int dma1 = hw_config->dma, dma2 = hw_config->dma2; int dma1 = hw_config->dma, dma2 = hw_config->dma2;
...@@ -357,48 +357,24 @@ MODULE_PARM_DESC(isapnp,"Enable ISAPnP probing (default 1)"); ...@@ -357,48 +357,24 @@ MODULE_PARM_DESC(isapnp,"Enable ISAPnP probing (default 1)");
/* All cs4232 based cards have the main ad1848 card either as CSC0000 or /* All cs4232 based cards have the main ad1848 card either as CSC0000 or
* CSC0100. */ * CSC0100. */
struct isapnp_device_id isapnp_cs4232_list[] __initdata = { static const struct pnp_id cs4232_pnp_table[] = {
{ ISAPNP_ANY_ID, ISAPNP_ANY_ID, { .id = "CSC0100", .driver_data = 0 },
ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100), { .id = "CSC0000", .driver_data = 0 },
0 },
{ ISAPNP_ANY_ID, ISAPNP_ANY_ID,
ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000),
0 },
/* Guillemot Turtlebeach something appears to be cs4232 compatible /* Guillemot Turtlebeach something appears to be cs4232 compatible
* (untested) */ * (untested) */
{ ISAPNP_VENDOR('C','S','C'), ISAPNP_ANY_ID, { .id = "GIM0100", .driver_data = 0 },
ISAPNP_VENDOR('G','I','M'), ISAPNP_FUNCTION(0x0100), { .id = ""}
0 },
{0}
}; };
MODULE_DEVICE_TABLE(isapnp, isapnp_cs4232_list); /*MODULE_DEVICE_TABLE(isapnp, isapnp_cs4232_list);*/
int cs4232_isapnp_probe(struct pci_dev *dev, const struct isapnp_device_id *id) static int cs4232_pnp_probe(struct pnp_dev *dev, const struct pnp_id *card_id, const struct pnp_id *dev_id)
{ {
int ret;
struct address_info *isapnpcfg; struct address_info *isapnpcfg;
isapnpcfg=(struct address_info*)kmalloc(sizeof(*isapnpcfg),GFP_KERNEL); isapnpcfg=(struct address_info*)kmalloc(sizeof(*isapnpcfg),GFP_KERNEL);
if (!isapnpcfg) if (!isapnpcfg)
return -ENOMEM; return -ENOMEM;
/*
* If device is active, assume configured with /proc/isapnp
* and use anyway. Any other way to check this?
*/
ret = dev->prepare(dev);
if(ret && ret != -EBUSY) {
printk(KERN_ERR "cs4232: ISA PnP found device that could not be autoconfigured.\n");
kfree(isapnpcfg);
return -ENODEV;
}
if(ret != -EBUSY) {
if(dev->activate(dev) < 0) {
printk(KERN_WARNING "cs4232: ISA PnP activate failed\n");
kfree(isapnpcfg);
return -ENODEV;
}
} /* else subfunction is already activated */
isapnpcfg->irq = dev->irq_resource[0].start; isapnpcfg->irq = dev->irq_resource[0].start;
isapnpcfg->dma = dev->dma_resource[0].start; isapnpcfg->dma = dev->dma_resource[0].start;
...@@ -409,10 +385,25 @@ int cs4232_isapnp_probe(struct pci_dev *dev, const struct isapnp_device_id *id) ...@@ -409,10 +385,25 @@ int cs4232_isapnp_probe(struct pci_dev *dev, const struct isapnp_device_id *id)
return -ENODEV; return -ENODEV;
} }
attach_cs4232(isapnpcfg); attach_cs4232(isapnpcfg);
pci_set_drvdata(dev,isapnpcfg); dev->driver_data = isapnpcfg;
return 0; return 0;
} }
static void cs4232_pnp_remove(struct pnp_dev *dev)
{
struct address_info *cfg = (struct address_info*) dev->driver_data;
if (cfg)
unload_cs4232(cfg);
}
static struct pnp_driver cs4232_driver = {
.name = "cs4232",
.card_id_table = NULL,
.id_table = cs4232_pnp_table,
.probe = cs4232_pnp_probe,
.remove = cs4232_pnp_remove,
};
static int __init init_cs4232(void) static int __init init_cs4232(void)
{ {
#ifdef CONFIG_SOUND_WAVEFRONT_MODULE #ifdef CONFIG_SOUND_WAVEFRONT_MODULE
...@@ -420,7 +411,7 @@ static int __init init_cs4232(void) ...@@ -420,7 +411,7 @@ static int __init init_cs4232(void)
printk(KERN_INFO "cs4232: set synthio and synthirq to use the wavefront facilities.\n"); printk(KERN_INFO "cs4232: set synthio and synthirq to use the wavefront facilities.\n");
else { else {
synth_base = synthio; synth_base = synthio;
synth_irq = synthirq; synth_irq = synthirq;
} }
#else #else
if(synthio != -1) if(synthio != -1)
...@@ -429,7 +420,7 @@ static int __init init_cs4232(void) ...@@ -429,7 +420,7 @@ static int __init init_cs4232(void)
cfg.irq = -1; cfg.irq = -1;
if (isapnp && if (isapnp &&
(isapnp_probe_devs(isapnp_cs4232_list, cs4232_isapnp_probe) > 0) (pnp_register_driver(&cs4232_driver) > 0)
) )
return 0; return 0;
...@@ -456,24 +447,13 @@ static int __init init_cs4232(void) ...@@ -456,24 +447,13 @@ static int __init init_cs4232(void)
if (probe_cs4232(&cfg,FALSE) == 0) if (probe_cs4232(&cfg,FALSE) == 0)
return -ENODEV; return -ENODEV;
attach_cs4232(&cfg); attach_cs4232(&cfg);
return 0;
}
static int __exit cs4232_isapnp_remove(struct pci_dev *dev,
const struct isapnp_device_id *id)
{
struct address_info *cfg = (struct address_info*)pci_get_drvdata(dev);
if (cfg)
unload_cs4232(cfg);
pci_set_drvdata(dev,NULL);
dev->deactivate(dev);
return 0; return 0;
} }
static void __exit cleanup_cs4232(void) static void __exit cleanup_cs4232(void)
{ {
isapnp_probe_devs(isapnp_cs4232_list, cs4232_isapnp_remove); pnp_unregister_driver(&cs4232_driver);
if (cfg.irq != -1) if (cfg.irq != -1)
unload_cs4232(&cfg); /* Unloads global MPU as well, if needed */ unload_cs4232(&cfg); /* Unloads global MPU as well, if needed */
} }
...@@ -488,7 +468,7 @@ static int __init setup_cs4232(char *str) ...@@ -488,7 +468,7 @@ static int __init setup_cs4232(char *str)
int ints[7]; int ints[7];
/* If we have isapnp cards, no need for options */ /* If we have isapnp cards, no need for options */
if (isapnp_probe_devs(isapnp_cs4232_list, cs4232_isapnp_probe) > 0) if (pnp_register_driver(&cs4232_driver) > 0)
return 1; return 1;
str = get_options(str, ARRAY_SIZE(ints), ints); str = get_options(str, ARRAY_SIZE(ints), ints);
......
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