parport: add device-model to parport subsystem
Subsystems (4)
Sudip Mukherjee
maintainerPATCH v3 1/3 parport: add device-model to parport subsystem
another WIP for your review. since this is not a formal patch for applying so writing the comments here.
all points raised by Dan in v2 and v1 has been covered in this patch. almost all the points raised by Greg in v1 has also been covered.
apart from those points, v2 started using probe function. Without probe, whenever any driver is trying to register, it is getting bound to all the available parallel ports. To solve that probe was required. Now the driver is binding only to the device it has registered. And that device will appear as a subdevice of the particular parallel port it wants to use.
In v1 Greg mentioned that we do not need to maintain our own list. That has been partially done. we are no longer maintaining the list of drivers. But we still need to maintain the list of ports and devices as that will be used by drivers which are not yet converted to device model. When all drivers are converted to use the device-model parallel port all these lists can be removed.
v2 had one more problem: it was creating some ghost parallel ports during port probing. we have now introduced the use of parport_del_port to remove registerd ports if probing has failed.
This version can be tested.
as of now only staging/panel and i2c-parport has been converted. I have tested this code with staging/panel.
Hi Alan,
for your testing I think you will need paride and pcd, I was looking at them now, but i suppose it will be little tricky to convert them as it is doing its own probing of the parallel port based on the base address. I will convert it and give you a patchset for your testing latest by monday.
--- drivers/parport/parport_pc.c | 4 +- drivers/parport/procfs.c | 15 ++- drivers/parport/share.c | 258 ++++++++++++++++++++++++++++++++++++++++--- include/linux/parport.h | 40 ++++++- 4 files changed, 299 insertions(+), 18 deletions(-)
drivers/parport/parport_pc.c +2 -2
@@ -2255,7 +2255,7 @@ out5:release_region (base+0x3 ,5 );release_region (base,3 ); out4: -parport_put_port (p); +parport_del_port (p); out3:kfree (priv); out2:
@@ -2294,7 +2294,7 @@ void parport_pc_unregister_port(struct parport *p) priv->dma_handle);#endif kfree (p->private_data); -parport_put_port (p); +parport_del_port (p);kfree (ops);/* hope no-one cached it */ }EXPORT_SYMBOL (parport_pc_unregister_port);
drivers/parport/procfs.c +14 -1
@@ -21,6 +21,7 @@#include <linux/parport.h> #include <linux/ctype.h> #include <linux/sysctl.h> +#include <linux/device.h> #include <asm/uaccess.h>
@@ -558,8 +559,18 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { +int ret; + parport_default_sysctl_table.sysctl_header =register_sysctl_table (parport_default_sysctl_table.dev_dir); +if (!parport_default_sysctl_table.sysctl_header) +return -ENOMEM ; + ret =parport_bus_init (); +if (ret) { +unregister_sysctl_table (parport_default_sysctl_table. + sysctl_header); +return ret; + }return 0 ; }
@@ -570,6 +581,7 @@ static void __exit parport_default_proc_unregister(void) sysctl_header); parport_default_sysctl_table.sysctl_header = NULL; } +parport_bus_exit (); }#else /* no sysctl or no procfs*/
@@ -596,11 +608,12 @@ int parport_device_proc_unregister(struct pardevice *device)static int __init parport_default_proc_register (void ) { -return 0 ; +return parport_bus_init (); } static void __exit parport_default_proc_unregister (void) { +parport_bus_exit (); }#endif
drivers/parport/share.c +244 -14
348 lines not on this page · raw message
include/linux/parport.h +39 -1
@@ -13,6 +13,7 @@#include <linux/wait.h> #include <linux/irqreturn.h> #include <linux/semaphore.h> +#include <linux/device.h> #include <asm/ptrace.h> #include <uapi/linux/parport.h>
@@ -145,6 +146,8 @@ struct pardevice {unsigned int flags;struct pardevice *next;struct pardevice *prev; +struct device dev; +bool devmodel;struct parport_state *state;/* saved status over preemption */ wait_queue_head_t wait_q;unsigned long int time;
@@ -156,6 +159,8 @@ struct pardevice {void * sysctl_table; }; +#define to_pardevice (n) container_of(n, struct pardevice, dev) +/* IEEE1284 information */ /* IEEE1284 phases. These are exposed to userland through ppdev IOCTL
@@ -195,7 +200,7 @@ struct parport {* This may unfortulately be null if the * port has a legacy driver. */ - +struct device bus_dev;/* to link with the bus */ struct parport *physport;/* If this is a non-default mux parport, i.e. we're a clone of a real
@@ -245,15 +250,24 @@ struct parport {struct parport *slaves[3 ]; }; +#define to_parport_dev (n) container_of(n, struct parport, bus_dev) +#define DEFAULT_SPIN_TIME 500/* us */ struct parport_driver {const char *name;void (*attach) (struct parport *);void (*detach) (struct parport *); +int (*match_port)(struct parport *); +int (*probe)(struct device *); +struct device_driver driver; +bool devmodel;struct list_head list; }; +int parport_bus_init (void ); +void parport_bus_exit (void ); +/* parport_register_port registers a new parallel port at the given address (if one does not already exist) and returns a pointer to it. This entails claiming the I/O region, IRQ and DMA. NULL is returned
@@ -274,8 +288,19 @@ extern void parport_remove_port(struct parport *port);/* Register a new high-level driver. */ extern int parport_register_driver (struct parport_driver *); +int __must_check __parport_register_drv (struct parport_driver *, +struct module *, +const char *mod_name); +/* +* parport_register_drv must be a macro so that KBUILD_MODNAME can +* be expanded +*/ +#define parport_register_drv (driver) \ + __parport_register_drv(driver, THIS_MODULE, KBUILD_MODNAME) +/* Unregister a high-level driver. */ extern void parport_unregister_driver (struct parport_driver *); +void parport_unregister_driver (struct parport_driver *);/* If parport_register_driver doesn't fit your needs, perhaps * parport_find_xxx does. */
@@ -288,6 +313,15 @@ extern irqreturn_t parport_irq_handler(int irq, void *dev_id);/* Reference counting for ports. */ extern struct parport *parport_get_port (struct parport *);extern void parport_put_port (struct parport *); +void parport_del_port (struct parport *); + +struct pardev_cb { +int (*preempt)(void *); +void (*wakeup)(void *); +void *private; +void (*irq_func)(void *); +unsigned int flags; +};/* parport_register_device declares that a device is connected to a port, and tells the kernel all it needs to know.
@@ -301,6 +335,10 @@ struct pardevice *parport_register_device(struct parport *port,void (*irq_func)(void *), int flags, void *handle); +struct pardevice * +parport_register_dev_model (struct parport *port,const char *name, +struct pardev_cb *par_dev_cb); +/* parport_unregister unlinks a device from the chain. */ extern void parport_unregister_device (struct pardevice *dev);
Signature · 1 line
1.8.1.2
Sudip Mukherjee
maintainerPATCH v3 2/3 staging: panel: modify driver to use new parport device model
modify panel driver to use the new parallel port device model.
--- drivers/staging/panel/panel.c | 63 +++++++++++++++++-------------------------- 1 file changed, 24 insertions(+), 39 deletions(-)
drivers/staging/panel/panel.c +24 -39
@@ -2188,25 +2188,35 @@ static struct notifier_block panel_notifier = { 0 }; -static void panel_attach (struct parport *port) +static int panel_probe (struct device *dev) +{ +if (strcmp (dev_name (dev),"panel" )) +return -ENODEV ; + +return 0 ; +} + +struct pardev_cb panel_cb = { + .flags =0 ,/*PARPORT_DEV_EXCL */ + .private = &pprt, +}; + +static int panel_attach (struct parport *port) {if (port->number != parport) -return ; +return -ENODEV ;if (pprt) {pr_err ("%s: port->number=%d parport=%d, already registered!\n" , __func__, port->number, parport); -return ; +return -EAGAIN ; } - pprt =parport_register_device (port,"panel" ,NULL ,NULL ,/* pf, kf */ -NULL , -/*PARPORT_DEV_EXCL */ -0 , (void *)&pprt); + pprt =parport_register_dev_model (port,"panel" , &panel_cb);if (pprt ==NULL ) {pr_err ("%s: port->number=%d parport=%d, parport_register_device() failed\n" , __func__, port->number, parport); -return ; +return -ENODEV ; }if (parport_claim (pprt)) {
@@ -2230,7 +2240,7 @@ static void panel_attach(struct parport *port) goto err_lcd_unreg; }register_reboot_notifier (&panel_notifier); -return ; +return 0 ; err_lcd_unreg:if (lcd.enabled)
@@ -2238,40 +2248,14 @@ err_lcd_unreg: err_unreg_device:parport_unregister_device (pprt); pprt =NULL ; -} -static void panel_detach (struct parport *port) -{ -if (port->number != parport) -return ; - -if (!pprt) { -pr_err ("%s: port->number=%d parport=%d, nothing to unregister.\n" , - __func__, port->number, parport); -return ; - } - -unregister_reboot_notifier (&panel_notifier); - -if (keypad.enabled && keypad_initialized) { -misc_deregister (&keypad_dev); - keypad_initialized =0 ; - } - -if (lcd.enabled && lcd.initialized) { -misc_deregister (&lcd_dev); - lcd.initialized = false; - } - -parport_release (pprt); -parport_unregister_device (pprt); - pprt =NULL ; +return -ENODEV ; }static struct parport_driver panel_driver = { .name ="panel" , - .attach = panel_attach, - .detach = panel_detach, + .match_port = panel_attach, + .probe = panel_probe, };/* init function */
@@ -2380,7 +2364,7 @@ static int __init panel_init_module(void)return -ENODEV ; } - err =parport_register_driver (&panel_driver); + err =parport_register_drv (&panel_driver);if (err) {pr_err ("could not register with parport. Aborting.\n" );return err;
@@ -2398,6 +2382,7 @@ static int __init panel_init_module(void) static void __exit panel_cleanup_module(void) { +unregister_reboot_notifier (&panel_notifier);if (scan_timer.function !=NULL )del_timer_sync (&scan_timer);
Signature · 1 line
1.8.1.2
Sudip Mukherjee
maintainerPATCH v3 3/3 i2c-parport: modify driver to use new parport device model
In reply to Sudip Mukherjeemodify i2c-parport driver to use the new parallel port device model.
---
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(-)
drivers/i2c/busses/i2c-parport.c +45 -31
@@ -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); }
drivers/i2c/busses/i2c-parport.h +4 -0
@@ -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" );
Signature · 1 line
1.8.1.2
Re: [PATCH v3 WIP 3/3] i2c-parport: modify driver to use new parport device model
drivers/i2c/busses/i2c-parport.h MODULE_PARM_DESC(type, · line 110
Quoted 3 lines
drivers/i2c/busses/i2c-parport.h +3
-0+static int parport; +module_param (parport, int,0 ); +MODULE_PARM_DESC (parport,"The parport to be used, default parport0\n" );
Minor suggested enhancement: this ought to be an array so you can attach multiple instances to a system.
Alan
Sudip Mukherjee
maintainerRe: [PATCH v3 WIP 3/3] i2c-parport: modify driver to use new parport device model
Quoted 6 lines · One Thousand Gnomes
drivers/i2c/busses/i2c-parport.h MODULE_PARM_DESC(type, · line 110
Quoted 3 lines
drivers/i2c/busses/i2c-parport.h +3
-0+static int parport; +module_param (parport, int,0 ); +MODULE_PARM_DESC (parport,"The parport to be used, default parport0\n" );Minor suggested enhancement: this ought to be an array so you can attach multiple instances to a system.
ok. infact, i was looking at paride yesterday night, and it is also having option to register maximum of 4 instances. the current patchset allows registration of device to only one port. I need to change that part.
regards
sudip
Quoted 2 lines
Alan
Quoted 5 lines
for your testing I think you will need paride and pcd, I was looking at them now, but i suppose it will be little tricky to convert them as it is doing its own probing of the parallel port based on the base address. I will convert it and give you a patchset for your testing latest by monday.
No hurry I doubt the CDROM will be here until the middle of the week, but will give it a go once it arrives. To be honest I suspect ZIP (imm and epp) are probably the only drives that still get used much.
Alan