Commit e15f75b5 authored by Hanna V. Linder's avatar Hanna V. Linder Committed by Greg Kroah-Hartman

[PATCH] Add class support to drivers/net/wan/cosa.c

This patch adds sysfs class support to the Cosa driver. I have verified it
compiles but do not have the hardware to test it. If someone could that
would be helpful.
parent 31c4141f
...@@ -93,6 +93,7 @@ ...@@ -93,6 +93,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/smp_lock.h> #include <linux/smp_lock.h>
#include <linux/device.h>
#undef COSA_SLOW_IO /* for testing purposes only */ #undef COSA_SLOW_IO /* for testing purposes only */
#undef REALLY_SLOW_IO #undef REALLY_SLOW_IO
...@@ -233,6 +234,9 @@ static int dma[MAX_CARDS+1]; ...@@ -233,6 +234,9 @@ static int dma[MAX_CARDS+1];
/* IRQ can be safely autoprobed */ /* IRQ can be safely autoprobed */
static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, }; static int irq[MAX_CARDS+1] = { -1, -1, -1, -1, -1, -1, 0, };
/* for class stuff*/
static struct class_simple *cosa_class;
#ifdef MODULE #ifdef MODULE
MODULE_PARM(io, "1-" __MODULE_STRING(MAX_CARDS) "i"); MODULE_PARM(io, "1-" __MODULE_STRING(MAX_CARDS) "i");
MODULE_PARM_DESC(io, "The I/O bases of the COSA or SRP cards"); MODULE_PARM_DESC(io, "The I/O bases of the COSA or SRP cards");
...@@ -359,7 +363,7 @@ static void debug_status_out(struct cosa_data *cosa, int status); ...@@ -359,7 +363,7 @@ static void debug_status_out(struct cosa_data *cosa, int status);
static int __init cosa_init(void) static int __init cosa_init(void)
{ {
int i; int i, err = 0;
printk(KERN_INFO "cosa v1.08 (c) 1997-2000 Jan Kasprzak <kas@fi.muni.cz>\n"); printk(KERN_INFO "cosa v1.08 (c) 1997-2000 Jan Kasprzak <kas@fi.muni.cz>\n");
#ifdef CONFIG_SMP #ifdef CONFIG_SMP
...@@ -369,12 +373,14 @@ static int __init cosa_init(void) ...@@ -369,12 +373,14 @@ static int __init cosa_init(void)
if (register_chrdev(cosa_major, "cosa", &cosa_fops)) { if (register_chrdev(cosa_major, "cosa", &cosa_fops)) {
printk(KERN_WARNING "cosa: unable to get major %d\n", printk(KERN_WARNING "cosa: unable to get major %d\n",
cosa_major); cosa_major);
return -EIO; err = -EIO;
goto out;
} }
} else { } else {
if (!(cosa_major=register_chrdev(0, "cosa", &cosa_fops))) { if (!(cosa_major=register_chrdev(0, "cosa", &cosa_fops))) {
printk(KERN_WARNING "cosa: unable to register chardev\n"); printk(KERN_WARNING "cosa: unable to register chardev\n");
return -EIO; err = -EIO;
goto out;
} }
} }
for (i=0; i<MAX_CARDS; i++) for (i=0; i<MAX_CARDS; i++)
...@@ -384,15 +390,33 @@ static int __init cosa_init(void) ...@@ -384,15 +390,33 @@ static int __init cosa_init(void)
if (!nr_cards) { if (!nr_cards) {
printk(KERN_WARNING "cosa: no devices found.\n"); printk(KERN_WARNING "cosa: no devices found.\n");
unregister_chrdev(cosa_major, "cosa"); unregister_chrdev(cosa_major, "cosa");
return -ENODEV; err = -ENODEV;
goto out;
} }
devfs_mk_dir("cosa"); devfs_mk_dir("cosa");
cosa_class = class_simple_create(THIS_MODULE, "cosa");
if (IS_ERR(cosa_class)) {
err = PTR_ERR(cosa_class);
goto out_chrdev;
}
for (i=0; i<nr_cards; i++) { for (i=0; i<nr_cards; i++) {
devfs_mk_cdev(MKDEV(cosa_major, i), class_simple_device_add(cosa_class, MKDEV(cosa_major, i),
NULL, "cosa%d", i);
err = devfs_mk_cdev(MKDEV(cosa_major, i),
S_IFCHR|S_IRUSR|S_IWUSR, S_IFCHR|S_IRUSR|S_IWUSR,
"cosa/%d", i); "cosa/%d", i);
if (err) {
class_simple_device_remove(MKDEV(cosa_major, i));
goto out_chrdev;
} }
return 0; }
err = 0;
goto out;
out_chrdev:
unregister_chrdev(cosa_major, "cosa");
out:
return err;
} }
module_init(cosa_init); module_init(cosa_init);
...@@ -402,8 +426,11 @@ static void __exit cosa_exit(void) ...@@ -402,8 +426,11 @@ static void __exit cosa_exit(void)
int i; int i;
printk(KERN_INFO "Unloading the cosa module\n"); printk(KERN_INFO "Unloading the cosa module\n");
for (i=0; i<nr_cards; i++) for (i=0; i<nr_cards; i++) {
class_simple_device_remove(MKDEV(cosa_major, i));
devfs_remove("cosa/%d", i); devfs_remove("cosa/%d", i);
}
class_simple_destroy(cosa_class);
devfs_remove("cosa"); devfs_remove("cosa");
for (cosa=cosa_cards; nr_cards--; cosa++) { for (cosa=cosa_cards; nr_cards--; cosa++) {
/* Clean up the per-channel data */ /* Clean up the per-channel data */
......
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