[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1429967240-4033-3-git-send-email-sudipm.mukherjee@gmail.com>
Date: Sat, 25 Apr 2015 18:37:20 +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>,
jdelvare@...e.de
Cc: linux-kernel@...r.kernel.org,
Sudip Mukherjee <sudipm.mukherjee@...il.com>
Subject: [PATCH v3 WIP 3/3] i2c-parport: modify driver to use new parport device model
modify i2c-parport driver to use the new parallel port device model.
Signed-off-by: Sudip Mukherjee <sudip@...torindia.org>
---
H Jean,
based on our discussion I have given one more module parameter with
default as parport0 to connect to. And I have tested with i2c-parport
connected to my parport1 and staging/panel connected to parport0.
will request you to kindly test this series on your hardware...
drivers/i2c/busses/i2c-parport.c | 76 ++++++++++++++++++++++++----------------
drivers/i2c/busses/i2c-parport.h | 4 +++
2 files changed, 49 insertions(+), 31 deletions(-)
diff --git a/drivers/i2c/busses/i2c-parport.c b/drivers/i2c/busses/i2c-parport.c
index a1fac5a..e173c72 100644
--- a/drivers/i2c/busses/i2c-parport.c
+++ b/drivers/i2c/busses/i2c-parport.c
@@ -160,20 +160,29 @@ static void i2c_parport_irq(void *data)
"SMBus alert received but no ARA client!\n");
}
-static void i2c_parport_attach(struct parport *port)
+static struct pardev_cb i2c_parport_cb = {
+ .flags = PARPORT_FLAG_EXCL,
+ .irq_func = i2c_parport_irq,
+};
+
+static int i2c_parport_attach(struct parport *port)
{
struct i2c_par *adapter;
+ if (port->number != parport)
+ return -ENODEV;
+
adapter = kzalloc(sizeof(struct i2c_par), GFP_KERNEL);
if (adapter == NULL) {
printk(KERN_ERR "i2c-parport: Failed to kzalloc\n");
- return;
+ return -ENOMEM;
}
+ 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, "i2c-parport",
+ &i2c_parport_cb);
if (!adapter->pdev) {
printk(KERN_ERR "i2c-parport: Unable to register with parport\n");
goto err_free;
@@ -230,46 +239,28 @@ static void i2c_parport_attach(struct parport *port)
mutex_lock(&adapter_list_lock);
list_add_tail(&adapter->node, &adapter_list);
mutex_unlock(&adapter_list_lock);
- return;
+ return 0;
err_unregister:
parport_release(adapter->pdev);
parport_unregister_device(adapter->pdev);
err_free:
kfree(adapter);
+ return -ENODEV;
}
-static void i2c_parport_detach(struct parport *port)
+static int i2c_parport_probe(struct device *dev)
{
- struct i2c_par *adapter, *_n;
+ if (strcmp(dev_name(dev), "i2c-parport"))
+ return -ENODEV;
- /* 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);
+ 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 +277,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..59afa83 100644
--- a/drivers/i2c/busses/i2c-parport.h
+++ b/drivers/i2c/busses/i2c-parport.h
@@ -104,3 +104,7 @@ MODULE_PARM_DESC(type,
" 6 = Barco LPT->DVI (K5800236) adapter\n"
" 7 = One For All JP1 parallel port adapter\n"
);
+
+static int parport;
+module_param(parport, int, 0);
+MODULE_PARM_DESC(parport, "The parport to be used, default 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