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

[PATCH] add class support to drivers/char/tipar.c

This patch adds class support to the Texas Instruments graphing calculators
with a parallel link cable.

I have verified it compiles. If someone has the hardware please verify it works.
parent f8d8c844
...@@ -58,6 +58,7 @@ ...@@ -58,6 +58,7 @@
#include <asm/bitops.h> #include <asm/bitops.h>
#include <linux/devfs_fs_kernel.h> /* DevFs support */ #include <linux/devfs_fs_kernel.h> /* DevFs support */
#include <linux/parport.h> /* Our code depend on parport */ #include <linux/parport.h> /* Our code depend on parport */
#include <linux/device.h>
/* /*
* TI definitions * TI definitions
...@@ -92,6 +93,8 @@ static int timeout = TIMAXTIME; /* timeout in tenth of seconds */ ...@@ -92,6 +93,8 @@ static int timeout = TIMAXTIME; /* timeout in tenth of seconds */
static unsigned int tp_count; /* tipar count */ static unsigned int tp_count; /* tipar count */
static unsigned long opened; /* opened devices */ static unsigned long opened; /* opened devices */
static struct class_simple *tipar_class;
/* --- macros for parport access -------------------------------------- */ /* --- macros for parport access -------------------------------------- */
#define r_dtr(x) (parport_read_data(table[(x)].dev->port)) #define r_dtr(x) (parport_read_data(table[(x)].dev->port))
...@@ -424,18 +427,26 @@ tipar_setup(char *str) ...@@ -424,18 +427,26 @@ tipar_setup(char *str)
static int static int
tipar_register(int nr, struct parport *port) tipar_register(int nr, struct parport *port)
{ {
int err = 0;
/* Register our module into parport */ /* Register our module into parport */
table[nr].dev = parport_register_device(port, "tipar", table[nr].dev = parport_register_device(port, "tipar",
NULL, NULL, NULL, 0, NULL, NULL, NULL, 0,
(void *) &table[nr]); (void *) &table[nr]);
if (table[nr].dev == NULL) if (table[nr].dev == NULL) {
return 1; err = 1;
goto out;
}
class_simple_device_add(tipar_class, MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr),
NULL, "par%d", nr);
/* Use devfs, tree: /dev/ticables/par/[0..2] */ /* Use devfs, tree: /dev/ticables/par/[0..2] */
devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr), err = devfs_mk_cdev(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr),
S_IFCHR | S_IRUGO | S_IWUGO, S_IFCHR | S_IRUGO | S_IWUGO,
"ticables/par/%d", nr); "ticables/par/%d", nr);
if (err)
goto out_class;
/* Display informations */ /* Display informations */
printk(KERN_INFO "tipar%d: using %s (%s).\n", nr, port->name, printk(KERN_INFO "tipar%d: using %s (%s).\n", nr, port->name,
...@@ -447,7 +458,14 @@ tipar_register(int nr, struct parport *port) ...@@ -447,7 +458,14 @@ tipar_register(int nr, struct parport *port)
else else
printk("tipar%d: link cable not found.\n", nr); printk("tipar%d: link cable not found.\n", nr);
return 0; err = 0;
goto out;
out_class:
class_simple_device_remove(MKDEV(TIPAR_MAJOR, TIPAR_MINOR + nr));
class_simple_destroy(tipar_class);
out:
return err;
} }
static void static void
...@@ -477,23 +495,38 @@ static struct parport_driver tipar_driver = { ...@@ -477,23 +495,38 @@ static struct parport_driver tipar_driver = {
int __init int __init
tipar_init_module(void) tipar_init_module(void)
{ {
int err = 0;
printk("tipar: parallel link cable driver, version %s\n", printk("tipar: parallel link cable driver, version %s\n",
DRIVER_VERSION); DRIVER_VERSION);
if (register_chrdev(TIPAR_MAJOR, "tipar", &tipar_fops)) { if (register_chrdev(TIPAR_MAJOR, "tipar", &tipar_fops)) {
printk("tipar: unable to get major %d\n", TIPAR_MAJOR); printk("tipar: unable to get major %d\n", TIPAR_MAJOR);
return -EIO; err = -EIO;
goto out;
} }
/* Use devfs with tree: /dev/ticables/par/[0..2] */ /* Use devfs with tree: /dev/ticables/par/[0..2] */
devfs_mk_dir("ticables/par"); devfs_mk_dir("ticables/par");
tipar_class = class_simple_create(THIS_MODULE, "ticables");
if (IS_ERR(tipar_class)) {
err = PTR_ERR(tipar_class);
goto out_chrdev;
}
if (parport_register_driver(&tipar_driver)) { if (parport_register_driver(&tipar_driver)) {
printk("tipar: unable to register with parport\n"); printk("tipar: unable to register with parport\n");
return -EIO; err = -EIO;
goto out;
} }
return 0; err = 0;
goto out;
out_chrdev:
unregister_chrdev(TIPAR_MAJOR, "tipar");
out:
return err;
} }
void __exit void __exit
...@@ -510,8 +543,10 @@ tipar_cleanup_module(void) ...@@ -510,8 +543,10 @@ tipar_cleanup_module(void)
if (table[i].dev == NULL) if (table[i].dev == NULL)
continue; continue;
parport_unregister_device(table[i].dev); parport_unregister_device(table[i].dev);
class_simple_device_remove(MKDEV(TIPAR_MAJOR, i));
devfs_remove("ticables/par/%d", i); devfs_remove("ticables/par/%d", i);
} }
class_simple_destroy(tipar_class);
devfs_remove("ticables/par"); devfs_remove("ticables/par");
printk("tipar: module unloaded !\n"); printk("tipar: module unloaded !\n");
......
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