Re: [PATCH] Driver Core patches for 2.6.6

From: Greg KH
Date: Fri May 14 2004 - 20:18:54 EST


ChangeSet 1.1587.5.17, 2004/05/02 20:29:59-07:00, hannal@xxxxxxxxxx

[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.


drivers/char/tipar.c | 49 ++++++++++++++++++++++++++++++++++++++++++-------
1 files changed, 42 insertions(+), 7 deletions(-)


diff -Nru a/drivers/char/tipar.c b/drivers/char/tipar.c
--- a/drivers/char/tipar.c Fri May 14 15:58:43 2004
+++ b/drivers/char/tipar.c Fri May 14 15:58:43 2004
@@ -58,6 +58,7 @@
#include <asm/bitops.h>
#include <linux/devfs_fs_kernel.h> /* DevFs support */
#include <linux/parport.h> /* Our code depend on parport */
+#include <linux/device.h>

/*
* TI definitions
@@ -92,6 +93,8 @@
static unsigned int tp_count; /* tipar count */
static unsigned long opened; /* opened devices */

+static struct class_simple *tipar_class;
+
/* --- macros for parport access -------------------------------------- */

#define r_dtr(x) (parport_read_data(table[(x)].dev->port))
@@ -424,18 +427,26 @@
static int
tipar_register(int nr, struct parport *port)
{
+ int err = 0;
+
/* Register our module into parport */
table[nr].dev = parport_register_device(port, "tipar",
NULL, NULL, NULL, 0,
(void *) &table[nr]);

- if (table[nr].dev == NULL)
- return 1;
+ if (table[nr].dev == NULL) {
+ 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] */
- 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,
"ticables/par/%d", nr);
+ if (err)
+ goto out_class;

/* Display informations */
printk(KERN_INFO "tipar%d: using %s (%s).\n", nr, port->name,
@@ -447,7 +458,14 @@
else
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
@@ -477,23 +495,38 @@
int __init
tipar_init_module(void)
{
+ int err = 0;
+
printk("tipar: parallel link cable driver, version %s\n",
DRIVER_VERSION);

if (register_chrdev(TIPAR_MAJOR, "tipar", &tipar_fops)) {
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] */
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)) {
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
@@ -510,8 +543,10 @@
if (table[i].dev == NULL)
continue;
parport_unregister_device(table[i].dev);
+ class_simple_device_remove(MKDEV(TIPAR_MAJOR, i));
devfs_remove("ticables/par/%d", i);
}
+ class_simple_destroy(tipar_class);
devfs_remove("ticables/par");

printk("tipar: module unloaded !\n");

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/