[i2c] [PATCH] i2c-parport-light: Port to the new device driver model

Jean Delvare khali at linux-fr.org
Thu Mar 8 09:16:02 CET 2007


Port the i2c-parport-light driver to the new device driver model. I'm
using Rene Herman's new isa bus type, as it fits the needs nicely. The
benefit is that we can now give a proper parent to our i2c adapter,
which will soon be mandatory.

Also fix a small race on driver unload: we need to unregister the
i2c adapter before we power it off.

Signed-off-by: Jean Delvare <khali at linux-fr.org>
---
 drivers/i2c/busses/i2c-parport-light.c |   58 ++++++++++++++++++++++++--------
 1 file changed, 44 insertions(+), 14 deletions(-)

--- linux-2.6.21-rc3.orig/drivers/i2c/busses/i2c-parport-light.c	2007-03-08 08:42:05.000000000 +0100
+++ linux-2.6.21-rc3/drivers/i2c/busses/i2c-parport-light.c	2007-03-08 09:02:45.000000000 +0100
@@ -1,7 +1,7 @@
 /* ------------------------------------------------------------------------ *
- * i2c-parport.c I2C bus over parallel port                                 *
+ * i2c-parport-light.c I2C bus over parallel port                           *
  * ------------------------------------------------------------------------ *
-   Copyright (C) 2003-2004 Jean Delvare <khali at linux-fr.org>
+   Copyright (C) 2003-2007 Jean Delvare <khali at linux-fr.org>
    
    Based on older i2c-velleman.c driver
    Copyright (C) 1995-2000 Simon G. Vogl
@@ -27,6 +27,7 @@
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/init.h>
+#include <linux/isa.h>
 #include <linux/ioport.h>
 #include <linux/i2c.h>
 #include <linux/i2c-algo-bit.h>
@@ -118,25 +119,31 @@ static struct i2c_adapter parport_adapte
 
 /* ----- Module loading, unloading and information ------------------------ */
 
-static int __init i2c_parport_init(void)
+static int __devinit parport_match(struct device *dev, unsigned int id)
 {
 	if (type < 0) {
-		printk(KERN_WARNING "i2c-parport: adapter type unspecified\n");
-		return -ENODEV;
+		dev_err(dev, "Adapter type unspecified\n");
+		return 0;
 	}
 
 	if (type >= ARRAY_SIZE(adapter_parm)) {
-		printk(KERN_WARNING "i2c-parport: invalid type (%d)\n", type);
-		return -ENODEV;
+		dev_err(dev, "Invalid adapter type (%d)\n", type);
+		return 0;
 	}
 
 	if (base == 0) {
-		printk(KERN_INFO "i2c-parport: using default base 0x%x\n", DEFAULT_BASE);
+		dev_info(dev, "Using default base 0x%x\n", DEFAULT_BASE);
 		base = DEFAULT_BASE;
 	}
+	return 1;
+}
 
-	if (!request_region(base, 3, "i2c-parport"))
-		return -ENODEV;
+static int __devinit parport_probe(struct device *dev, unsigned int id)
+{
+	if (!request_region(base, 3, "i2c-parport-light")) {
+		dev_err(dev, "I/O region request failed\n");
+		return -EBUSY;
+	}
 
         if (!adapter_parm[type].getscl.val)
 		parport_algo_data.getscl = NULL;
@@ -148,8 +155,9 @@ static int __init i2c_parport_init(void)
 	if (adapter_parm[type].init.val)
 		line_set(1, &adapter_parm[type].init);
 
+	parport_adapter.dev.parent = dev;
 	if (i2c_bit_add_bus(&parport_adapter) < 0) {
-		printk(KERN_ERR "i2c-parport: Unable to register with I2C\n");
+		dev_err(dev, "Unable to register with I2C\n");
 		release_region(base, 3);
 		return -ENODEV;
 	}
@@ -157,14 +165,36 @@ static int __init i2c_parport_init(void)
 	return 0;
 }
 
-static void __exit i2c_parport_exit(void)
+static int __devexit parport_remove(struct device *dev, unsigned int id)
 {
+	i2c_del_adapter(&parport_adapter);
+
 	/* Un-init if needed (power off...) */
 	if (adapter_parm[type].init.val)
 		line_set(0, &adapter_parm[type].init);
-
-	i2c_del_adapter(&parport_adapter);
 	release_region(base, 3);
+
+	return 0;
+}
+
+static struct isa_driver i2c_parport_driver = {
+	.match		= parport_match,
+	.probe		= parport_probe,
+	.remove		= __devexit_p(parport_remove),
+	.driver = {
+		.owner	= THIS_MODULE,
+		.name	= "i2c-parport-light",
+	},
+};
+
+static int __init i2c_parport_init(void)
+{
+	return isa_register_driver(&i2c_parport_driver, 1);
+}
+
+static void __exit i2c_parport_exit(void)
+{
+	isa_unregister_driver(&i2c_parport_driver);
 }
 
 MODULE_AUTHOR("Jean Delvare <khali at linux-fr.org>");


-- 
Jean Delvare



More information about the i2c mailing list