[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1430220623-8738-2-git-send-email-sudipm.mukherjee@gmail.com>
Date: Tue, 28 Apr 2015 17:00:21 +0530
From: Sudip Mukherjee <sudipm.mukherjee@...il.com>
To: Greg KH <gregkh@...uxfoundation.org>,
Dan Carpenter <dan.carpenter@...cle.com>,
One Thousand Gnomes <gnomes@...rguk.ukuu.org.uk>,
Jean Delvare <jdelvare@...e.de>
Cc: linux-kernel@...r.kernel.org,
Sudip Mukherjee <sudipm.mukherjee@...il.com>
Subject: [PATCH v4 WIP 2/4] i2c-parport: modify driver to use new parport device model
modify i2c-parport driver to use the new parallel port device model.
v4: according to the suggestion of Alan, array is being used in the
module parameter. Hopefully no one will use more than 4 instances.
Hi Jean,
This patchset is good for testing. Can you please check what is
happening to your hardware...
Signed-off-by: Sudip Mukherjee <sudip@...torindia.org>
---
drivers/i2c/busses/i2c-parport.c | 95 ++++++++++++++++++++++++++++------------
drivers/i2c/busses/i2c-parport.h | 7 +++
2 files changed, 74 insertions(+), 28 deletions(-)
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index a1fac5a..b07db1c 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -160,20 +160,49 @@ static void i2c_parport_irq(void *data)
"SMBus alert received but no ARA client!\n");
}
+static struct pardev_cb i2c_parport_cb = {
+ .flags = PARPORT_FLAG_EXCL,
+ .irq_func = i2c_parport_irq,
+};
+
static void i2c_parport_attach(struct parport *port)
{
struct i2c_par *adapter;
+ int i;
+ char *name;
+
+ if (!is_parport(&port->bus_dev))
+ return;
+
+ name = kzalloc(13, GFP_KERNEL);
+ if (!name)
+ return;
+
+ for (i = 0; i < 4; i++) {
+ if (parport[i] == -1)
+ continue;
+ if (port->number == parport[i])
+ break;
+ }
+ if (i == 4) { /* port mentioned not found */
+ kfree(name);
+ return;
+ }
+ sprintf(name, "i2c-parport%d", i);
adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
if (adapter == NULL) {
printk(KERN_ERR "i2c-parport: Failed to kzalloc\n");
+ kfree(name);
return;
}
+ i2c_parport_cb.private = adapter;
pr_debug("i2c-parport: attaching to %s\n", port->name);
parport_disable_irq(port);
- adapter->pdev = parport_register_device(port, "i2c-parport",
- NULL, NULL, i2c_parport_irq, PARPORT_FLAG_EXCL, adapter);
+ adapter->pdev = parport_register_dev_model(port, name,
+ &i2c_parport_cb);
+ kfree(name);
if (!adapter->pdev) {
printk(KERN_ERR "i2c-parport: Unable to register with parport\n");
goto err_free;
@@ -237,39 +266,26 @@ static void i2c_parport_attach(struct parport *port)
parport_unregister_device(adapter->pdev);
err_free:
kfree(adapter);
+ return;
}
-static void i2c_parport_detach(struct parport *port)
+static int i2c_parport_probe(struct device *dev)
{
- struct i2c_par *adapter, *_n;
+ char *name = dev_name(dev);
- /* Walk the list */
- mutex_lock(&adapter_list_lock);
- list_for_each_entry_safe(adapter, _n, &adapter_list, node) {
- if (adapter->pdev->port == port) {
- if (adapter->ara) {
- parport_disable_irq(port);
- i2c_unregister_device(adapter->ara);
- }
- i2c_del_adapter(&adapter->adapter);
-
- /* Un-init if needed (power off...) */
- if (adapter_parm[type].init.val)
- line_set(port, 0, &adapter_parm[type].init);
-
- parport_release(adapter->pdev);
- parport_unregister_device(adapter->pdev);
- list_del(&adapter->node);
- kfree(adapter);
- }
- }
- mutex_unlock(&adapter_list_lock);
+ if (is_parport(dev))
+ return -ENODEV;
+
+ if (strlen(name) != 12 || strncmp(dev_name(dev), "i2c-parport", 11))
+ return -ENODEV;
+
+ return 0;
}
static struct parport_driver i2c_parport_driver = {
.name = "i2c-parport",
- .attach = i2c_parport_attach,
- .detach = i2c_parport_detach,
+ .match_port = i2c_parport_attach,
+ .probe = i2c_parport_probe,
};
/* ----- Module loading, unloading and information ------------------------ */
@@ -286,11 +302,34 @@ static int __init i2c_parport_init(void)
return -ENODEV;
}
- return parport_register_driver(&i2c_parport_driver);
+ return parport_register_drv(&i2c_parport_driver);
}
static void __exit i2c_parport_exit(void)
{
+ struct i2c_par *adapter, *_n;
+
+ /* Walk the list */
+ mutex_lock(&adapter_list_lock);
+ list_for_each_entry_safe(adapter, _n, &adapter_list, node) {
+ if (adapter->ara) {
+ parport_disable_irq(adapter->pdev->port);
+ i2c_unregister_device(adapter->ara);
+ }
+ i2c_del_adapter(&adapter->adapter);
+
+ /* Un-init if needed (power off...) */
+ if (adapter_parm[type].init.val)
+ line_set(adapter->pdev->port, 0,
+ &adapter_parm[type].init);
+
+ parport_release(adapter->pdev);
+ parport_unregister_device(adapter->pdev);
+ list_del(&adapter->node);
+ kfree(adapter);
+ }
+ mutex_unlock(&adapter_list_lock);
+
parport_unregister_driver(&i2c_parport_driver);
}
diff --git a/drivers/i2c/busses/i2c-parport.h b/drivers/i2c/busses/i2c-parport.h
index 4e12945..00655f4 100644
--- a/drivers/i2c/busses/i2c-parport.h
+++ b/drivers/i2c/busses/i2c-parport.h
@@ -104,3 +104,10 @@ MODULE_PARM_DESC(type,
" 6 = Barco LPT->DVI (K5800236) adapter\n"
" 7 = One For All JP1 parallel port adapter\n"
);
+
+static int parport[4] = {0, -1, -1, -1};
+module_param_array(parport, int, NULL, 0);
+MODULE_PARM_DESC(parport, "Atmost 4 instances are allowed.\n"
+ "Mention portnumbers in array.\n"
+ "If the port is not to be used mention -1.\n"
+ "Default is one instance connected to parport0\n");
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists