RFC/RFT: Input - sysfs integration
Subsystems (15)
cover RFC/RFT: Input - sysfs integration
[Argh, resending with subjects and proper CCs]
Hi,
The following set of patches deals with converting input subsystem to the driver model and intergrate it with sysfs. This allows us to remove custom-made input hotplug handler and finally have an option of netlink-only hotplug notifier.
Some changes to the driver core were required. I decided that I did not want to add an additional class to /sys/class directory; instead class code was changed to allow nesting several classes. This way we can have:
/sys/class/input/
|-- devices
| |-- input0
| |-- input1
| `-- input2
`-- interfaces
|-- event0
...
|-- mouse1
`-- ts0and not clutter the top-level directory. Top-level classes define individual subsystems, lower-level classes define individual parts. In this particular case 'devices' directory contains class devices corresponding to input_dev structures whereas 'interfaces' has class devices produced by input interfaces (handlers), such as evdev, mousedev, tsdev and joydev.
I believe that other subsystems, such as firewire, SCSI, USB and I2C could also be moved to a hierarchy of classes to make /sys tree more organized.
Although all this compatible with pre-udev hotplug scripts I was advised that having sub-classes will require some changes to udev.
Class interface code was slightly changed to pass interface to add/remove methods. This way subsystem can have a generic handler and still call individual interfaces's methods if needed. There are couple if I2O patches that deal with class interface code, these are not directly related to this series, but required for compiling. The maintainer acked them and will push with the rest of I2O updates.
When registering class devices hotplug event is now sent before adding interfaces, otherwise children's hotplug events would reach userspace (udev) first.
The full sysfs input hierarchy on by laptop is the following:
[dtor@core ~]$ tree /sys/class/input/ /sys/class/input/
|-- devices
| |-- input0
| | |-- capabilities
| | | |-- abs
| | | |-- ev
| | | |-- ff
| | | |-- key
| | | |-- led
| | | |-- msc
| | | |-- rel
| | | |-- snd
| | | `-- sw
| | |-- device -> ../../../../devices/platform/i8042/serio1
| | |-- event0 -> ../../../../class/input/interfaces/event0
| | |-- id
| | | |-- bustype
| | | |-- product
| | | |-- vendor
| | | `-- version
| | |-- name
| | |-- phys
| | `-- uniq
| |-- input1
| | |-- capabilities
| | | |-- abs
| | | |-- ev
| | | |-- ff
| | | |-- key
| | | |-- led
| | | |-- msc
| | | |-- rel
| | | |-- snd
| | | `-- sw
| | |-- device -> ../../../../devices/platform/i8042/serio0
| | |-- event1 -> ../../../../class/input/interfaces/event1
| | |-- id
| | | |-- bustype
| | | |-- product
| | | |-- vendor
| | | `-- version
| | |-- mouse0 -> ../../../../class/input/interfaces/mouse0
| | |-- name
| | |-- phys
| | |-- ts0 -> ../../../../class/input/interfaces/ts0
| | `-- uniq
| `-- input2
| |-- capabilities
| | |-- abs
| | |-- ev
| | |-- ff
| | |-- key
| | |-- led
| | |-- msc
| | |-- rel
| | |-- snd
| | `-- sw
| |-- device -> ../../../../devices/platform/i8042/serio0/serio2
| |-- event2 -> ../../../../class/input/interfaces/event2
| |-- id
| | |-- bustype
| | |-- product
| | |-- vendor
| | `-- version
| |-- mouse1 -> ../../../../class/input/interfaces/mouse1
| |-- name
| |-- phys
| |-- ts1 -> ../../../../class/input/interfaces/ts1
| `-- uniq
`-- interfaces
|-- event0
| |-- dev
| `-- device -> ../../../../class/input/devices/input0
|-- event1
| |-- dev
| `-- device -> ../../../../class/input/devices/input1
|-- event2
| |-- dev
| `-- device -> ../../../../class/input/devices/input2
|-- mice
| `-- dev
|-- mouse0
| |-- dev
| `-- device -> ../../../../class/input/devices/input1
|-- mouse1
| |-- dev
| `-- device -> ../../../../class/input/devices/input2
|-- ts0
| |-- dev
| `-- device -> ../../../../class/input/devices/input1
`-- ts1
|-- dev
`-- device -> ../../../../class/input/devices/input2Review/comments/testing will be appreciated.
Thank you.
--
Dmitry
PATCH 1/28 I2O: remove class interface
I2O: remove i2o_device_class_interface misuse
The intent of class interfaces was to provide different 'views' at the same object, not just run some code every time a new class device is registered. Kill interface structure, make class core register default attributes and set up sysfs links right when registering class devices.
---
drivers/message/i2o/device.c | 255 ++++++++++++++++++++----------------------- 1 files changed, 122 insertions(+), 133 deletions(-)
drivers/message/i2o/device.c +122 -133
@@ -45,10 +45,10 @@ static inline int i2o_device_issue_claimwritel (type, &msg->body[0 ]);return i2o_msg_post_wait (dev->iop, m,60 ); -}; +}/** -* i2o_device_claim - claim a device for use by an OSM +* i2o_device_claim - claim a device for use by an OSM * @dev: I2O device to claim * @drv: I2O driver which wants to claim the device *
@@ -73,7 +73,7 @@ int i2o_device_claim(struct i2o_device *up (&dev->lock);return rc; -}; +}/** * i2o_device_claim_release - release a device that the OSM is using
@@ -119,7 +119,8 @@ int i2o_device_claim_release(struct i2o_up (&dev->lock);return rc; -}; +} +/** * i2o_device_release - release the memory for a I2O device
@@ -135,39 +136,62 @@ static void i2o_device_release(struct depr_debug ("i2o: device %s released\n" , dev->bus_id);kfree (i2o_dev); -}; +}/** -* i2o_device_class_release - Remove I2O device attributes +* i2o_device_class_release - I2O class device release function * @cd: I2O class device which is added to the I2O device class * -* Removes attributes from the I2O device again. Also search each device -* on the controller for I2O devices which refert to this device as parent -* or user and remove this links also. +* The function is just a stub - memory will be freed when +* associated I2O device is released. */ static void i2o_device_class_release (struct class_device *cd) { -struct i2o_device *i2o_dev, *tmp; -struct i2o_controller *c; +/* empty */ +} - i2o_dev =to_i2o_device (cd->dev); - c = i2o_dev->iop; +/** +* i2o_device_class_show_class_id - Displays class id of I2O device +* @cd: class device of which the class id should be displayed +* @buf: buffer into which the class id should be printed +* +* Returns the number of bytes which are printed into the buffer. +*/ +static ssize_t i2o_device_class_show_class_id (struct class_device *cd, +char *buf) +{ +struct i2o_device *dev =to_i2o_device (cd->dev); -sysfs_remove_link (&i2o_dev->device.kobj,"parent" ); -sysfs_remove_link (&i2o_dev->device.kobj,"user" ); +sprintf (buf,"0x%03x\n" , dev->lct_data.class_id); +return strlen (buf) +1 ; +} -list_for_each_entry (tmp, &c->devices, list) { -if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) -sysfs_remove_link (&tmp->device.kobj,"parent" ); -if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid) -sysfs_remove_link (&tmp->device.kobj,"user" ); - } +/** +* i2o_device_class_show_tid - Displays TID of I2O device +* @cd: class device of which the TID should be displayed +* @buf: buffer into which the class id should be printed +* +* Returns the number of bytes which are printed into the buffer. +*/ +static ssize_t i2o_device_class_show_tid (struct class_device *cd,char *buf) +{ +struct i2o_device *dev =to_i2o_device (cd->dev); + +sprintf (buf,"0x%03x\n" , dev->lct_data.tid); +return strlen (buf) +1 ; +} + +static struct class_device_attribute i2o_device_class_attrs[] = { +__ATTR (class_id,S_IRUGO , i2o_device_class_show_class_id,NULL ), +__ATTR (tid,S_IRUGO , i2o_device_class_show_tid,NULL ), + __ATTR_NULL };/* I2O device class */ static struct class i2o_device_class = { - .name ="i2o_device" , - .release = i2o_device_class_release + .name ="i2o_device" , + .release = i2o_device_class_release, + .class_dev_attrs = i2o_device_class_attrs, };/**
@@ -197,7 +221,67 @@ static struct i2o_device *i2o_device_all dev->classdev.dev = &dev->device;return dev; -}; +} + +/** +* i2o_setup_sysfs_links - Adds attributes to the I2O device +* @cd: I2O class device which is added to the I2O device class +* +* This function get called when a I2O device is added to the class. It +* creates the attributes for each device and creates user/parent symlink +* if necessary. +* +* Returns 0 on success or negative error code on failure. +*/ +static void i2o_setup_sysfs_links (struct i2o_device *i2o_dev) +{ +struct i2o_controller *c = i2o_dev->iop; +struct i2o_device *tmp; + +/* create user entries for this device */ + tmp =i2o_iop_find_device (i2o_dev->iop, i2o_dev->lct_data.user_tid); +if (tmp && tmp != i2o_dev) +sysfs_create_link (&i2o_dev->device.kobj, + &tmp->device.kobj,"user" ); + +/* create user entries refering to this device */ +list_for_each_entry (tmp, &c->devices, list) +if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid && + tmp != i2o_dev) +sysfs_create_link (&tmp->device.kobj, + &i2o_dev->device.kobj,"user" ); + +/* create parent entries for this device */ + tmp =i2o_iop_find_device (i2o_dev->iop, i2o_dev->lct_data.parent_tid); +if (tmp && tmp != i2o_dev) +sysfs_create_link (&i2o_dev->device.kobj, + &tmp->device.kobj,"parent" ); + +/* create parent entries refering to this device */ +list_for_each_entry (tmp, &c->devices, list) +if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid && + tmp != i2o_dev) +sysfs_create_link (&tmp->device.kobj, + &i2o_dev->device.kobj,"parent" ); +} + +static void i2o_remove_sysfs_links (struct i2o_device *i2o_dev) +{ +struct i2o_controller *c = i2o_dev->iop; +struct i2o_device *tmp; + +sysfs_remove_link (&i2o_dev->device.kobj,"parent" ); +sysfs_remove_link (&i2o_dev->device.kobj,"user" ); + +list_for_each_entry (tmp, &c->devices, list) { +if (tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) +sysfs_remove_link (&tmp->device.kobj,"parent" ); +if (tmp->lct_data.user_tid == i2o_dev->lct_data.tid) +sysfs_remove_link (&tmp->device.kobj,"user" ); + } +} + +/** * i2o_device_add - allocate a new I2O device and add it to the IOP
@@ -222,6 +306,7 @@ static struct i2o_device *i2o_device_add } dev->lct_data = *entry; + dev->iop = c;snprintf (dev->device.bus_id,BUS_ID_SIZE ,"%d:%03x" , c->unit, dev->lct_data.tid);
@@ -229,7 +314,6 @@ static struct i2o_device *i2o_device_addsnprintf (dev->classdev.class_id,BUS_ID_SIZE ,"%d:%03x" , c->unit, dev->lct_data.tid); - dev->iop = c; dev->device.parent = &c->device;device_register (&dev->device);
@@ -238,12 +322,14 @@ static struct i2o_device *i2o_device_addclass_device_register (&dev->classdev); +i2o_setup_sysfs_links (dev); +i2o_driver_notify_device_add_all (dev);pr_debug ("i2o: device %s added\n" , dev->device.bus_id);return dev; -}; +}/** * i2o_device_remove - remove an I2O device from the I2O core
@@ -256,10 +342,11 @@ static struct i2o_device *i2o_device_addvoid i2o_device_remove (struct i2o_device *i2o_dev) {i2o_driver_notify_device_remove_all (i2o_dev); +i2o_remove_sysfs_links (i2o_dev);class_device_unregister (&i2o_dev->classdev);list_del (&i2o_dev->list);device_unregister (&i2o_dev->device); -}; +}/** * i2o_device_parse_lct - Parse a previously fetched LCT and create devices
@@ -337,99 +424,8 @@ int i2o_device_parse_lct(struct i2o_contup (&c->lct_lock);return 0 ; -}; - -/** -* i2o_device_class_show_class_id - Displays class id of I2O device -* @cd: class device of which the class id should be displayed -* @buf: buffer into which the class id should be printed -* -* Returns the number of bytes which are printed into the buffer. -*/ -static ssize_t i2o_device_class_show_class_id (struct class_device *cd, -char *buf) -{ -struct i2o_device *dev =to_i2o_device (cd->dev); - -sprintf (buf,"0x%03x\n" , dev->lct_data.class_id); -return strlen (buf) +1 ; -}; - -/** -* i2o_device_class_show_tid - Displays TID of I2O device -* @cd: class device of which the TID should be displayed -* @buf: buffer into which the class id should be printed -* -* Returns the number of bytes which are printed into the buffer. -*/ -static ssize_t i2o_device_class_show_tid (struct class_device *cd,char *buf) -{ -struct i2o_device *dev =to_i2o_device (cd->dev); - -sprintf (buf,"0x%03x\n" , dev->lct_data.tid); -return strlen (buf) +1 ; -}; - -/* I2O device class attributes */ -static CLASS_DEVICE_ATTR(class_id, S_IRUGO, i2o_device_class_show_class_id, - NULL); -static CLASS_DEVICE_ATTR(tid, S_IRUGO, i2o_device_class_show_tid, NULL); - -/** -* i2o_device_class_add - Adds attributes to the I2O device -* @cd: I2O class device which is added to the I2O device class -* -* This function get called when a I2O device is added to the class. It -* creates the attributes for each device and creates user/parent symlink -* if necessary. -* -* Returns 0 on success or negative error code on failure. -*/ -static int i2o_device_class_add (struct class_device *cd) -{ -struct i2o_device *i2o_dev, *tmp; -struct i2o_controller *c; - - i2o_dev =to_i2o_device (cd->dev); - c = i2o_dev->iop; - -class_device_create_file (cd, &class_device_attr_class_id); -class_device_create_file (cd, &class_device_attr_tid); - -/* create user entries for this device */ - tmp =i2o_iop_find_device (i2o_dev->iop, i2o_dev->lct_data.user_tid); -if (tmp && (tmp != i2o_dev)) -sysfs_create_link (&i2o_dev->device.kobj, &tmp->device.kobj, -"user" ); - -/* create user entries refering to this device */ -list_for_each_entry (tmp, &c->devices, list) -if ((tmp->lct_data.user_tid == i2o_dev->lct_data.tid) - && (tmp != i2o_dev)) -sysfs_create_link (&tmp->device.kobj, - &i2o_dev->device.kobj,"user" ); - -/* create parent entries for this device */ - tmp =i2o_iop_find_device (i2o_dev->iop, i2o_dev->lct_data.parent_tid); -if (tmp && (tmp != i2o_dev)) -sysfs_create_link (&i2o_dev->device.kobj, &tmp->device.kobj, -"parent" ); - -/* create parent entries refering to this device */ -list_for_each_entry (tmp, &c->devices, list) -if ((tmp->lct_data.parent_tid == i2o_dev->lct_data.tid) - && (tmp != i2o_dev)) -sysfs_create_link (&tmp->device.kobj, - &i2o_dev->device.kobj,"parent" ); - -return 0 ; -}; +} -/* I2O device class interface */ -static struct class_interface i2o_device_class_interface = { - .class = &i2o_device_class, - .add = i2o_device_class_add -};/* * Run time support routines
@@ -553,11 +549,11 @@ int i2o_parm_field_get(struct i2o_device }/* -* if oper == I2O_PARAMS_TABLE_GET, get from all rows -* if fieldcount == -1 return all fields +* if oper == I2O_PARAMS_TABLE_GET, get from all rows +* if fieldcount == -1 return all fields * ibuf and ibuflen are unused (use NULL, 0) -* else return specific fields -* ibuf contains fieldindexes +* else return specific fields +* ibuf contains fieldindexes * * if oper == I2O_PARAMS_LIST_GET, get from specific rows * if fieldcount == -1 return all fields
@@ -611,14 +607,8 @@ int i2o_parm_table_get(struct i2o_device*/ int i2o_device_init (void ) { -int rc; - - rc =class_register (&i2o_device_class); -if (rc) -return rc; - -return class_interface_register (&i2o_device_class_interface); -}; +return class_register (&i2o_device_class); +}/** * i2o_device_exit - I2O devices exit function
@@ -627,9 +617,8 @@ int i2o_device_init(void)*/ void i2o_device_exit (void ) { -class_interface_register (&i2o_device_class_interface);class_unregister (&i2o_device_class); -}; +}EXPORT_SYMBOL (i2o_device_claim);EXPORT_SYMBOL (i2o_device_claim_release);
Re: [patch 01/28] I2O: remove class interface
Quoted 10 lines · Dmitry Torokhov
I2O: remove
i2o_device_class_interfacemisuseThe intent of class interfaces was to provide different 'views' at the same object, not just run some code every time a new class device is registered. Kill interface structure, make class core register default attributes and set up sysfs links right when registering class devices.
Signed-off-by Dmitry Torokhov <[email protected]>
I've applied this. I've also cleaned up the class stuff some more and converted the drivers/message/i2o/iop.c code to use the easier class and class_device interfaces, as you should not have 2 refcounted structures trying to control the same overall structure. The i2o device structure is still like this and remains to be fixed up. If no one does it soon, I'll clean it up too.
thanks,
greg k-h
Re: [patch 01/28] I2O: remove class interface
Hello,
Quoted 9 lines · Greg KH
Quoted 8 lines · Dmitry Torokhov
I2O: remove
i2o_device_class_interfacemisuse The intent of class interfaces was to provide different 'views' at the same object, not just run some code every time a new class device is registered. Kill interface structure, make class core register default attributes and set up sysfs links right when registering class devices.Signed-off-by Dmitry Torokhov <[email protected]>
Quoted 6 lines
I've applied this. I've also cleaned up the class stuff some more and converted the
drivers/message/i2o/iop.ccode to use the easier class andclass_deviceinterfaces, as you should not have 2 refcounted structures trying to control the same overall structure. The i2o device structure is still like this and remains to be fixed up. If no one does it soon, I'll clean it up too.
Could you please wait until i supply the patch, if everyone applies patches it's very hard to get those changes and mine together...
And i really don't see that this change is highly critical...
Thank you very much for your understanding...
Best regards,
Markus Lidel
------------------------------------------
Markus Lidel (Senior IT Consultant)
Shadow Connect GmbH
Carl-Reisch-Weg 12
D-86381 Krumbach
Germany
Phone: +49 82 82/99 51-0 Fax: +49 82 82/99 51-11
E-Mail: [email protected] URL: http://www.shadowconnect.com
PATCH 2/28 I2O: remove i2o_device_class
In reply to Dmitry TorokhovI2O: cleanup - remove i2o_device_class
I2O devices reside on their own bus so there should be no reason to also have i2c_device class that mirros i2o bus.
---
drivers/message/i2o/core.h | 3 - drivers/message/i2o/device.c | 71 +++++++------------------------------------ drivers/message/i2o/driver.c | 3 + drivers/message/i2o/iop.c | 10 ------ include/linux/i2o.h | 2 - 5 files changed, 17 insertions(+), 72 deletions(-)
drivers/message/i2o/device.c +13 -58
@@ -138,17 +138,6 @@ static void i2o_device_release(struct dekfree (i2o_dev); } -/** -* i2o_device_class_release - I2O class device release function -* @cd: I2O class device which is added to the I2O device class -* -* The function is just a stub - memory will be freed when -* associated I2O device is released. -*/ -static void i2o_device_class_release (struct class_device *cd) -{ -/* empty */ -}/** * i2o_device_class_show_class_id - Displays class id of I2O device
@@ -157,12 +146,13 @@ static void i2o_device_class_release(str* * Returns the number of bytes which are printed into the buffer. */ -static ssize_t i2o_device_class_show_class_id (struct class_device *cd, -char *buf) +static ssize_t i2o_device_show_class_id (struct device *dev, +struct device_attribute *attr, +char *buf) { -struct i2o_device *dev =to_i2o_device (cd->dev); +struct i2o_device *i2o_dev =to_i2o_device (dev); -sprintf (buf,"0x%03x\n" , dev->lct_data.class_id); +sprintf (buf,"0x%03x\n" , i2o_dev->lct_data.class_id);return strlen (buf) +1 ; }
@@ -173,27 +163,22 @@ static ssize_t i2o_device_class_show_cla* * Returns the number of bytes which are printed into the buffer. */ -static ssize_t i2o_device_class_show_tid (struct class_device *cd,char *buf) +static ssize_t i2o_device_show_tid (struct device *dev, +struct device_attribute *attr, +char *buf) { -struct i2o_device *dev =to_i2o_device (cd->dev); +struct i2o_device *i2o_dev =to_i2o_device (dev); -sprintf (buf,"0x%03x\n" , dev->lct_data.tid); +sprintf (buf,"0x%03x\n" , i2o_dev->lct_data.tid);return strlen (buf) +1 ; } -static struct class_device_attribute i2o_device_class_attrs[] = { -__ATTR (class_id,S_IRUGO , i2o_device_class_show_class_id,NULL ), -__ATTR (tid,S_IRUGO , i2o_device_class_show_tid,NULL ), +struct device_attribute i2o_device_attrs[] = { +__ATTR (class_id,S_IRUGO , i2o_device_show_class_id,NULL ), +__ATTR (tid,S_IRUGO , i2o_device_show_tid,NULL ), __ATTR_NULL }; -/* I2O device class */ -static struct class i2o_device_class = { - .name ="i2o_device" , - .release = i2o_device_class_release, - .class_dev_attrs = i2o_device_class_attrs, -}; -/** * i2o_device_alloc - Allocate a I2O device and initialize it *
@@ -217,8 +202,6 @@ static struct i2o_device *i2o_device_all dev->device.bus = &i2o_bus_type; dev->device.release = &i2o_device_release; - dev->classdev.class = &i2o_device_class; - dev->classdev.dev = &dev->device;return dev; }
@@ -311,17 +294,12 @@ static struct i2o_device *i2o_device_addsnprintf (dev->device.bus_id,BUS_ID_SIZE ,"%d:%03x" , c->unit, dev->lct_data.tid); -snprintf (dev->classdev.class_id,BUS_ID_SIZE ,"%d:%03x" , c->unit, - dev->lct_data.tid); - dev->device.parent = &c->device;device_register (&dev->device);list_add_tail (&dev->list, &c->devices); -class_device_register (&dev->classdev); -i2o_setup_sysfs_links (dev);i2o_driver_notify_device_add_all (dev);
@@ -343,7 +321,6 @@ void i2o_device_remove(struct i2o_device {i2o_driver_notify_device_remove_all (i2o_dev);i2o_remove_sysfs_links (i2o_dev); -class_device_unregister (&i2o_dev->classdev);list_del (&i2o_dev->list);device_unregister (&i2o_dev->device); }
@@ -598,28 +575,6 @@ int i2o_parm_table_get(struct i2o_devicereturn size; } -/** -* i2o_device_init - Initialize I2O devices -* -* Registers the I2O device class. -* -* Returns 0 on success or negative error code on failure. -*/ -int i2o_device_init (void ) -{ -return class_register (&i2o_device_class); -} - -/** -* i2o_device_exit - I2O devices exit function -* -* Unregisters the I2O device class. -*/ -void i2o_device_exit (void ) -{ -class_unregister (&i2o_device_class); -} -EXPORT_SYMBOL (i2o_device_claim);EXPORT_SYMBOL (i2o_device_claim_release);EXPORT_SYMBOL (i2o_parm_field_get);
drivers/message/i2o/driver.c +3 -0
@@ -58,9 +58,12 @@ static int i2o_bus_match(struct device * };/* I2O bus type */ +extern struct device_attribute i2o_device_attrs[]; +struct bus_type i2o_bus_type = { .name ="i2o" , .match = i2o_bus_match, + .dev_attrs = i2o_device_attrs, };/**
include/linux/i2o.h +0 -2
@@ -66,8 +66,6 @@ struct i2o_device {struct device device;struct semaphore lock;/* device lock */ - -struct class_device classdev;/* i2o device class */ };/*
drivers/message/i2o/core.h +0 -3
@@ -36,9 +36,6 @@ extern void __exit i2o_pci_exit(void);extern void i2o_device_remove (struct i2o_device *);extern int i2o_device_parse_lct (struct i2o_controller *); -extern int i2o_device_init (void ); -extern void i2o_device_exit (void ); -/* IOP */ extern struct i2o_controller *i2o_iop_alloc (void );extern void i2o_iop_free (struct i2o_controller *);
drivers/message/i2o/iop.c +1 -9
@@ -1246,13 +1246,9 @@ static int __init i2o_iop_init(void) printk(KERN_INFO OSM_DESCRIPTION " v" OSM_VERSION "\n"); - rc =i2o_device_init (); -if (rc) - goto exit; -if ((rc =class_register (&i2o_controller_class))) {osm_err ("can't register class i2o_controller\n" ); - goto device_exit; + goto exit; }if ((rc =i2o_driver_init ()))
@@ -1275,9 +1271,6 @@ static int __init i2o_iop_init(void) class_exit:class_unregister (&i2o_controller_class); - device_exit: -i2o_device_exit (); - exit:return rc; }
@@ -1293,7 +1286,6 @@ static void __exit i2o_iop_exit(void)i2o_exec_exit ();i2o_driver_exit ();class_unregister (&i2o_controller_class); -i2o_device_exit (); };module_init (i2o_iop_init);
Re: [patch 02/28] I2O: remove i2o_device_class
Quoted 4 lines · Dmitry Torokhov
I2O: cleanup - remove
i2o_device_classI2O devices reside on their own bus so there should be no reason to also have
i2c_deviceclass that mirros i2o bus.
Ok, nice, this is good. But it doesn't apply at all, somethings odd. What tree is this diffed against, Linus's or -mm?
thanks,
greg k-h
PATCH 3/28 Driver core: allow nesting classes
In reply to Dmitry TorokhovDriver core: allow nesting classes
This will allow unclutter /sys/classes directory, combining classes related to the same subsystem "under one roof".
---
drivers/base/class.c | 8 +++++++- include/linux/device.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-)
drivers/base/class.c +7 -1
@@ -135,6 +135,7 @@ static void remove_class_attrs(struct clint class_register (struct class * cls) { +struct class *parent;int error;pr_debug ("device class '%s': registering\n" , cls->name);
@@ -146,7 +147,11 @@ int class_register(struct class * cls)if (error)return error; -subsys_set_kset (cls, class_subsys); + parent =class_get (cls->parent); +if (parent) +subsys_set_kset (cls, parent->subsys); +else +subsys_set_kset (cls, class_subsys); error =subsystem_register (&cls->subsys);if (!error) {
@@ -161,6 +166,7 @@ void class_unregister(struct class * clspr_debug ("device class '%s': unregistering\n" , cls->name);remove_class_attrs (cls);subsystem_unregister (&cls->subsys); +class_put (cls->parent); }static void class_create_release (struct class *cls)
include/linux/device.h +1 -0
@@ -157,6 +157,7 @@ struct class {struct module * owner;struct subsystem subsys; +struct class * parent;struct list_head children;struct list_head interfaces;struct semaphore sem;/* locks both the children and interfaces lists */
PATCH 4/28 Driver core: make parent class define subsystem
In reply to Dmitry TorokhovDriver core: make parent class define subsystem for its children
When there is a hierarchy of classes make parent class define subsystem as reported in hotplug notifications. The full class path is reported in a new CLASS environment variable.
---
drivers/base/class.c | 14 ++++++++++++-- 1 files changed, 12 insertions(+), 2 deletions(-)
drivers/base/class.c +12 -2
@@ -337,25 +337,35 @@ static int class_hotplug_filter(struct kstatic const char *class_hotplug_name (struct kset *kset,struct kobject *kobj) {struct class_device *class_dev =to_class_dev (kobj); +struct class *class = class_dev->class; -return class_dev->class->name; +while (class->parent) + class = class->parent; + +return class->name; }static int class_hotplug (struct kset *kset,struct kobject *kobj,char **envp,int num_envp,char *buffer,int buffer_size) {struct class_device *class_dev =to_class_dev (kobj); +const char *path;int i =0 ;int length =0 ;int retval =0 ;pr_debug ("%s - name = %s\n" , __FUNCTION__, class_dev->class_id); + path =kobject_get_path (&class_dev->class->subsys.kset.kobj,GFP_KERNEL ); +add_hotplug_env_var (envp, num_envp, &i, buffer, buffer_size, + &length,"CLASS=%s" , path); +kfree (path); +if (class_dev->dev) {/* add physical device, backing this device */ struct device *dev = class_dev->dev; -char *path =kobject_get_path (&dev->kobj,GFP_KERNEL ); + path =kobject_get_path (&dev->kobj,GFP_KERNEL );add_hotplug_env_var (envp, num_envp, &i, buffer, buffer_size, &length,"PHYSDEVPATH=%s" , path);kfree (path);
PATCH 5/28 Driver core: pass interface to class intreface methods
In reply to Dmitry TorokhovDriver core: pass interface to class intreface methods
Pass interface as argument to add() and remove() class interface methods. This way a subsystem can implement generic add/remove handlers and then call interface-specific ones.
---
drivers/base/class.c | 8 ++++---- drivers/pcmcia/ds.c | 6 ++++-- drivers/pcmcia/rsrc_nonstatic.c | 6 ++++-- drivers/pcmcia/socket_sysfs.c | 6 ++++-- drivers/scsi/sg.c | 8 ++++---- include/linux/device.h | 4 ++-- 6 files changed, 22 insertions(+), 16 deletions(-)
drivers/base/class.c +4 -4
@@ -546,7 +546,7 @@ int class_device_add(struct class_devicelist_add_tail (&class_dev->node, &parent->children);list_for_each_entry (class_intf, &parent->interfaces, node)if (class_intf->add) - class_intf->add (class_dev); + class_intf->add (class_dev, class_intf);up (&parent->sem); }kobject_hotplug (&class_dev->kobj,KOBJ_ADD );
@@ -627,7 +627,7 @@ void class_device_del(struct class_deviclist_del_init (&class_dev->node);list_for_each_entry (class_intf, &parent->interfaces, node)if (class_intf->remove) - class_intf->remove (class_dev); + class_intf->remove (class_dev, class_intf);up (&parent->sem); }
@@ -731,7 +731,7 @@ int class_interface_register(struct claslist_add_tail (&class_intf->node, &parent->interfaces);if (class_intf->add) {list_for_each_entry (class_dev, &parent->children, node) - class_intf->add (class_dev); + class_intf->add (class_dev, class_intf); }up (&parent->sem);
@@ -750,7 +750,7 @@ void class_interface_unregister(struct clist_del_init (&class_intf->node);if (class_intf->remove) {list_for_each_entry (class_dev, &parent->children, node) - class_intf->remove (class_dev); + class_intf->remove (class_dev, class_intf); }up (&parent->sem);
include/linux/device.h +2 -2
@@ -252,8 +252,8 @@ struct class_interface {struct list_head node;struct class *class; -int (*add) (struct class_device *); -void (*remove) (struct class_device *); +int (*add) (struct class_device *,struct class_interface *); +void (*remove) (struct class_device *,struct class_interface *); };extern int class_interface_register (struct class_interface *);
drivers/pcmcia/ds.c +4 -2
@@ -1157,7 +1157,8 @@ static struct pcmcia_callback pcmcia_bus .requery = pcmcia_bus_rescan, }; -static int __devinit pcmcia_bus_add_socket (struct class_device *class_dev) +static int __devinit pcmcia_bus_add_socket (struct class_device *class_dev, +struct class_interface *class_intf) {struct pcmcia_socket *socket =class_get_devdata (class_dev);int ret;
@@ -1192,7 +1193,8 @@ static int __devinit pcmcia_bus_add_sockreturn 0 ; } -static void pcmcia_bus_remove_socket (struct class_device *class_dev) +static void pcmcia_bus_remove_socket (struct class_device *class_dev, +struct class_interface *class_intf) {struct pcmcia_socket *socket =class_get_devdata (class_dev);
drivers/pcmcia/rsrc_nonstatic.c +4 -2
@@ -994,7 +994,8 @@ static struct class_device_attribute *pc NULL, }; -static int __devinit pccard_sysfs_add_rsrc (struct class_device *class_dev) +static int __devinit pccard_sysfs_add_rsrc (struct class_device *class_dev, +struct class_interface *class_intf) {struct pcmcia_socket *s =class_get_devdata (class_dev);struct class_device_attribute **attr;
@@ -1011,7 +1012,8 @@ static int __devinit pccard_sysfs_add_rsreturn ret; } -static void __devexit pccard_sysfs_remove_rsrc(struct class_device *class_dev) +static void __devexit pccard_sysfs_remove_rsrc(struct class_device *class_dev, +struct class_interface *class_intf) {struct pcmcia_socket *s =class_get_devdata (class_dev);struct class_device_attribute **attr;
drivers/pcmcia/socket_sysfs.c +4 -2
@@ -341,7 +341,8 @@ static struct bin_attribute pccard_cis_a .write = pccard_store_cis, }; -static int __devinit pccard_sysfs_add_socket (struct class_device *class_dev) +static int __devinit pccard_sysfs_add_socket (struct class_device *class_dev, +struct class_interface *class_intf) {struct class_device_attribute **attr;int ret =0 ;
@@ -357,7 +358,8 @@ static int __devinit pccard_sysfs_add_soreturn ret; } -static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev) +static void __devexit pccard_sysfs_remove_socket(struct class_device *class_dev, +struct class_interface *class_intf) {struct class_device_attribute **attr;
drivers/scsi/sg.c +4 -4
@@ -104,8 +104,8 @@ static int sg_allow_dio = SG_ALLOW_DIO_D#define SG_DEV_ARR_LUMP 32/* amount to over allocate sg_dev_arr by */ -static int sg_add (struct class_device *); -static void sg_remove (struct class_device *); +static int sg_add (struct class_device *,struct class_interface *); +static void sg_remove (struct class_device *,struct class_interface *);static Scsi_Request *dummy_cmdp;/* only used for sizeof */
@@ -1506,7 +1506,7 @@ static int sg_alloc(struct gendisk *disk }static int -sg_add (struct class_device *cl_dev) +sg_add (struct class_device *cl_dev,struct class_interface *cl_intf) {struct scsi_device *scsidp =to_scsi_device (cl_dev->dev);struct gendisk *disk;
@@ -1582,7 +1582,7 @@ out: }static void -sg_remove (struct class_device *cl_dev) +sg_remove (struct class_device *cl_dev,struct class_interface *cl_intf) {struct scsi_device *scsidp =to_scsi_device (cl_dev->dev);Sg_device *sdp =NULL ;
PATCH 6/28 Driver core: send hotplug event before adding class interfaces
In reply to Dmitry TorokhovDriver core: send hotplug event before adding class interfaces
Move call to kobject_hotplug() above code that adds interfaces to a class device, otherwise children's hotplug events may reach userspace first.
---
drivers/base/class.c | 3 ++- 1 files changed, 2 insertions(+), 1 deletion(-)
drivers/base/class.c +2 -1
@@ -540,6 +540,8 @@ int class_device_add(struct class_device class_name); } +kobject_hotplug (&class_dev->kobj,KOBJ_ADD ); +/* notify any interfaces this device is now here */ if (parent) {down (&parent->sem);
@@ -549,7 +551,6 @@ int class_device_add(struct class_device class_intf->add (class_dev, class_intf);up (&parent->sem); } -kobject_hotplug (&class_dev->kobj,KOBJ_ADD ); register_done:if (error && parent)
PATCH 7/28 Input: kill devfs references
In reply to Dmitry TorokhovInput: remove references to devfs from input subsystem
---
drivers/input/evdev.c | 4 ---- drivers/input/input.c | 7 ------- drivers/input/joydev.c | 4 ---- drivers/input/mousedev.c | 9 +-------- drivers/input/tsdev.c | 7 ------- 5 files changed, 1 insertion(+), 30 deletions(-)
drivers/input/evdev.c +0 -4
@@ -20,7 +20,6 @@#include <linux/major.h> #include <linux/smp_lock.h> #include <linux/device.h> -#include <linux/devfs_fs_kernel.h> #include <linux/compat.h> struct evdev {
@@ -687,8 +686,6 @@ static struct input_handle *evdev_connec evdev_table[minor] = evdev; -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + minor), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/event%d" , minor);class_device_create (input_class,MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + minor), dev->dev,"event%d" , minor);
@@ -703,7 +700,6 @@ static void evdev_disconnect(struct inpuclass_device_destroy (input_class,MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + evdev->minor)); -devfs_remove ("input/event%d" , evdev->minor); evdev->exist =0 ;if (evdev->open) {
drivers/input/input.c +0 -7
@@ -22,7 +22,6 @@#include <linux/interrupt.h> #include <linux/poll.h> #include <linux/device.h> -#include <linux/devfs_fs_kernel.h> MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>" );MODULE_DESCRIPTION ("Input core" );
@@ -769,13 +768,8 @@ static int __init input_init(void) goto fail2; } - err =devfs_mk_dir ("input" ); -if (err) - goto fail3; -return 0 ; - fail3:unregister_chrdev (INPUT_MAJOR ,"input" ); fail2:input_proc_exit (); fail1:class_destroy (input_class);return err;
@@ -784,7 +778,6 @@ static int __init input_init(void) static void __exit input_exit(void) {input_proc_exit (); -devfs_remove ("input" );unregister_chrdev (INPUT_MAJOR ,"input" );class_destroy (input_class); }
drivers/input/joydev.c +0 -4
@@ -26,7 +26,6 @@#include <linux/init.h> #include <linux/smp_lock.h> #include <linux/device.h> -#include <linux/devfs_fs_kernel.h> MODULE_AUTHOR ("Vojtech Pavlik <[email protected]>" );MODULE_DESCRIPTION ("Joystick device interfaces" );
@@ -514,8 +513,6 @@ static struct input_handle *joydev_conne joydev_table[minor] = joydev; -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + minor), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/js%d" , minor);class_device_create (input_class,MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + minor), dev->dev,"js%d" , minor);
@@ -529,7 +526,6 @@ static void joydev_disconnect(struct inpstruct joydev_list *list;class_device_destroy (input_class,MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + joydev->minor)); -devfs_remove ("input/js%d" , joydev->minor); joydev->exist =0 ;if (joydev->open) {
drivers/input/mousedev.c +1 -8
@@ -9,7 +9,7 @@* the Free Software Foundation. */ -#define MOUSEDEV_MINOR_BASE 32 +#define MOUSEDEV_MINOR_BASE 32#define MOUSEDEV_MINORS 32#define MOUSEDEV_MIX 31
@@ -24,7 +24,6 @@#include <linux/random.h> #include <linux/major.h> #include <linux/device.h> -#include <linux/devfs_fs_kernel.h> #ifdef CONFIG_INPUT_MOUSEDEV_PSAUX #include <linux/miscdevice.h> #endif
@@ -649,8 +648,6 @@ static struct input_handle *mousedev_con mousedev_table[minor] = mousedev; -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE + minor), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/mouse%d" , minor);class_device_create (input_class,MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE + minor), dev->dev,"mouse%d" , minor);
@@ -665,7 +662,6 @@ static void mousedev_disconnect(struct iclass_device_destroy (input_class,MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE + mousedev->minor)); -devfs_remove ("input/mouse%d" , mousedev->minor); mousedev->exist =0 ;if (mousedev->open) {
@@ -738,8 +734,6 @@ static int __init mousedev_init(void) mousedev_mix.exist =1 ; mousedev_mix.minor =MOUSEDEV_MIX ; -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE +MOUSEDEV_MIX ), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/mice" );class_device_create (input_class,MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE +MOUSEDEV_MIX ),NULL ,"mice" );
@@ -759,7 +753,6 @@ static void __exit mousedev_exit(void)if (psaux_registered)misc_deregister (&psaux_mouse);#endif -devfs_remove ("input/mice" );class_device_destroy (input_class,MKDEV (INPUT_MAJOR ,MOUSEDEV_MINOR_BASE +MOUSEDEV_MIX ));input_unregister_handler (&mousedev_handler);
drivers/input/tsdev.c +0 -7
@@ -53,7 +53,6 @@#include <linux/random.h> #include <linux/time.h> #include <linux/device.h> -#include <linux/devfs_fs_kernel.h> #ifndef CONFIG_INPUT_TSDEV_SCREEN_X #define CONFIG_INPUT_TSDEV_SCREEN_X 240
@@ -410,10 +409,6 @@ static struct input_handle *tsdev_connec tsdev_table[minor] = tsdev; -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + minor), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/ts%d" , minor); -devfs_mk_cdev (MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + minor +TSDEV_MINORS /2 ), -S_IFCHR |S_IRUGO |S_IWUSR ,"input/tsraw%d" , minor);class_device_create (input_class,MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + minor), dev->dev,"ts%d" , minor);
@@ -428,8 +423,6 @@ static void tsdev_disconnect(struct inpuclass_device_destroy (input_class,MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + tsdev->minor)); -devfs_remove ("input/ts%d" , tsdev->minor); -devfs_remove ("input/tsraw%d" , tsdev->minor); tsdev->exist =0 ;if (tsdev->open) {
PATCH 8/28 Input: prepare to sysfs integration
In reply to Dmitry TorokhovInput: prepare to sysfs integration
Add struct class_device to input_dev; add input_allocate_dev() to dynamically allocate input devices; dynamically allocated devices are automatically registered with sysfs.
---
drivers/input/input.c | 77 ++++++++++++++++++++++++++++++++++++++++++++++---- include/linux/input.h | 24 ++++++++++++++- 2 files changed, 95 insertions(+), 6 deletions(-)
include/linux/input.h +23 -1
@@ -12,6 +12,7 @@#ifdef __KERNEL__#include <linux/time.h> #include <linux/list.h> +#include <linux/device.h> #else #include <sys/time.h> #include <sys/ioctl.h>
@@ -889,11 +890,15 @@ struct input_dev {struct semaphore sem;/* serializes open and close operations */ unsigned int users; -struct device *dev; +struct class_device cdev; +struct device *dev;/* will be removed soon */ + +int dynalloc;/* temporarily */ struct list_head h_list;struct list_head node; }; +#define to_input_dev (d) container_of(d, struct input_dev, cdev)/* * Structure for hotplug & device<->driver matching.
@@ -984,6 +989,23 @@ static inline void init_input_dev(structINIT_LIST_HEAD (&dev->node); } +struct input_dev *input_allocate_device (void ); + +static inline void input_free_device (struct input_dev *dev) +{ +kfree (dev); +} + +static inline struct input_dev *input_get_device (struct input_dev *dev) +{ +return to_input_dev (class_device_get (&dev->cdev)); +} + +static inline void input_put_device (struct input_dev *dev) +{ +class_device_put (&dev->cdev); +} +void input_register_device (struct input_dev *);void input_unregister_device (struct input_dev *);
drivers/input/input.c +72 -5
128 lines not on this page · raw message
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 7 lines · Dmitry Torokhov
Input: prepare to sysfs integration
Add struct
class_devicetoinput_dev; addinput_allocate_dev()to dynamically allocate input devices; dynamically allocated devices are automatically registered with sysfs.Signed-off-by Dmitry Torokhov <[email protected]>
Ok, I've applied this one, and the other "convert the input drivers to be dynamic" to my tree, as this is all great work.
I'll work on the last few patches that you have, with regard to how to tie it into sysfs "properly" now, and get back to you, just wanted to apply all of these, so we have a common base to work on.
Oh, I did change one thing in this patch:
Quoted 2 lines
+EXPORT_SYMBOL(input_allocate_device);
I made that EXPORT_SYMBOL_GPL(). Let me know if you object to this.
thanks,
greg k-h
Dmitry Torokhov
maintainerRe: [patch 08/28] Input: prepare to sysfs integration
Quoted 7 lines · Greg KH
Quoted 6 lines · Dmitry Torokhov
Input: prepare to sysfs integration
Add struct
class_devicetoinput_dev; addinput_allocate_dev()to dynamically allocate input devices; dynamically allocated devices are automatically registered with sysfs.
Quoted 9 lines
Quoted 1 line
Signed-off-by Dmitry Torokhov <[email protected]>Ok, I've applied this one, and the other "convert the input drivers to be dynamic" to my tree, as this is all great work.
I'll work on the last few patches that you have, with regard to how to tie it into sysfs "properly" now, and get back to you, just wanted to apply all of these, so we have a common base to work on.
Greg,
Could you please drop these patches for a while? Or maybe just don't push them to Linus yet. The reason is that I want to change input_allocate_device to take bitmap of supported events. This way I could allocate ABS tables dynamically at the same time I allocate input_dev itself and it will simplify error handling logic in drivers and it will save I think 1260 bytes per input_dev structure which is nice. And I don't want to go through all subsystems yet again soI want to fold into my input dynalloc patch...
Quoted 7 lines
Oh, I did change one thing in this patch:
Quoted 2 lines
+EXPORT_SYMBOL(input_allocate_device);
I made that
EXPORT_SYMBOL_GPL(). Let me know if you object to this.
That's fine with me.
--
Dmitry
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 18 lines · Dmitry Torokhov
Quoted 7 lines · Greg KH
Quoted 6 lines · Dmitry Torokhov
Input: prepare to sysfs integration
Add struct
class_devicetoinput_dev; addinput_allocate_dev()to dynamically allocate input devices; dynamically allocated devices are automatically registered with sysfs.Quoted 9 lines
Quoted 1 line
Signed-off-by Dmitry Torokhov <[email protected]>Ok, I've applied this one, and the other "convert the input drivers to be dynamic" to my tree, as this is all great work.
I'll work on the last few patches that you have, with regard to how to tie it into sysfs "properly" now, and get back to you, just wanted to apply all of these, so we have a common base to work on.
Quoted 4 lines
Greg,
Could you please drop these patches for a while? Or maybe just don't push them to Linus yet.
How about I hold on to them, until you send me replacements for them? I'm using quilt so I can just drop them and add your new ones very easily. I will not push them to Linus until you and Vojtech say it's ok for me to do so.
Quoted 7 lines
The reason is that I want to change
input_allocate_deviceto take bitmap of supported events. This way I could allocate ABS tables dynamically at the same time I allocateinput_devitself and it will simplify error handling logic in drivers and it will save I think 1260 bytes perinput_devstructure which is nice. And I don't want to go through all subsystems yet again soI want to fold into my input dynalloc patch...
That sounds good.
thanks,
greg k-h
Dmitry Torokhov
maintainerRe: [patch 08/28] Input: prepare to sysfs integration
Quoted 10 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
The reason is that I want to change
input_allocate_deviceto take bitmap of supported events. This way I could allocate ABS tables dynamically at the same time I allocateinput_devitself and it will simplify error handling logic in drivers and it will save I think 1260 bytes perinput_devstructure which is nice. And I don't want to go through all subsystems yet again soI want to fold into my input dynalloc patch...
Quoted 2 lines
That sounds good.
Well, I tried implementing the proposal above and interface came out pretty awkward to use. My next option is to move abs table into "->private" structure, much like keytable was moved, or (for HID-like devices) allocate it when actually needed and adjust individual drivers. So I guess the patches that you have right now are good after all.
--
Dmitry
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 14 lines · Dmitry Torokhov
Quoted 10 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
The reason is that I want to change
input_allocate_deviceto take bitmap of supported events. This way I could allocate ABS tables dynamically at the same time I allocateinput_devitself and it will simplify error handling logic in drivers and it will save I think 1260 bytes perinput_devstructure which is nice. And I don't want to go through all subsystems yet again soI want to fold into my input dynalloc patch...Quoted 2 lines
That sounds good.
Quoted 6 lines
Well, I tried implementing the proposal above and interface came out pretty awkward to use. My next option is to move abs table into "->private" structure, much like keytable was moved, or (for HID-like devices) allocate it when actually needed and adjust individual drivers. So I guess the patches that you have right now are good after all.
The problem is that the ->abs tables are accessed in the input core and in the handlers, too, which means they have to share the lifetime rules with the input_dev struct itself.
That means we probably have a problem with the drivers deallocating the keytable, while the device still exists, because there is a reference to it from say sysfs, and keyboard.c tries to access the keytable because of an ioctl.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 22 lines · Vojtech Pavlik
Quoted 14 lines · Dmitry Torokhov
Quoted 10 lines · Greg KH
Quoted 7 lines · Dmitry Torokhov
The reason is that I want to change
input_allocate_deviceto take bitmap of supported events. This way I could allocate ABS tables dynamically at the same time I allocateinput_devitself and it will simplify error handling logic in drivers and it will save I think 1260 bytes perinput_devstructure which is nice. And I don't want to go through all subsystems yet again soI want to fold into my input dynalloc patch...Quoted 2 lines
That sounds good.
Quoted 6 lines
Well, I tried implementing the proposal above and interface came out pretty awkward to use. My next option is to move abs table into "->private" structure, much like keytable was moved, or (for HID-like devices) allocate it when actually needed and adjust individual drivers. So I guess the patches that you have right now are good after all.
Quoted 9 lines
The problem is that the ->abs tables are accessed in the input core and in the handlers, too, which means they have to share the lifetime rules with the
input_devstruct itself.That means we probably have a problem with the drivers deallocating the keytable, while the device still exists, because there is a reference to it from say sysfs, and
keyboard.ctries to access the keytable because of an ioctl.
Not necessarily, you just need to make sure that you don't try to access these fields when input_dev is "half-dead". But we have many issues with locking/lifetime rules in input core so that's just another item that needs to be considered.
I wanted to get basic sysfs support in and then work on locking...
Signature · 1 line
Dmitry
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 6 lines · Dmitry Torokhov
Not necessarily, you just need to make sure that you don't try to access these fields when
input_devis "half-dead". But we have many issues with locking/lifetime rules in input core so that's just another item that needs to be considered.I wanted to get basic sysfs support in and then work on locking...
... when the first one to fix should be the lifetime rules. Both sysfs stuff and locking depend on those...
Re: [patch 08/28] Input: prepare to sysfs integration
Quoted 2 lines · Al Viro
... when the first one to fix should be the lifetime rules. Both sysfs stuff and locking depend on those...
FWIW for me it is easier to think about lifetime rules when I already have sysfs support. I mean sysfs itself dictates basic lifetime rules, additional constraints are just that - additional constraints.
Signature · 1 line
Dmitry
PATCH 9/28 Input: convert net/bluetooth to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert net/bluetooth to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
net/bluetooth/hidp/core.c | 13 ++++++++----- 1 files changed, 8 insertions(+), 5 deletions(-)
net/bluetooth/hidp/core.c +8 -5
@@ -520,7 +520,7 @@ static int hidp_session(void *arg)if (session->input) {input_unregister_device (session->input); -kfree (session->input); + session->input =NULL ; }up_write (&hidp_session_sem);
@@ -536,6 +536,8 @@ static inline void hidp_setup_input(stru input->private = session; + input->name ="Bluetooth HID Boot Protocol Device" ; + input->id.bustype =BUS_BLUETOOTH ; input->id.vendor = req->vendor; input->id.product = req->product;
@@ -582,16 +584,15 @@ int hidp_add_connection(struct hidp_connreturn -ENOTUNIQ ; session =kmalloc (sizeof (struct hidp_session ),GFP_KERNEL ); -if (!session) +if (!session)return -ENOMEM ;memset (session,0 ,sizeof (struct hidp_session )); - session->input =kmalloc (sizeof (struct input_dev ),GFP_KERNEL ); + session->input =input_allocate_device ();if (!session->input) {kfree (session);return -ENOMEM ; } -memset (session->input,0 ,sizeof (struct input_dev ));down_write (&hidp_session_sem);
@@ -651,8 +652,10 @@ unlink:__hidp_unlink_session (session); -if (session->input) +if (session->input) {input_unregister_device (session->input); + session->input =NULL ;/* don't try to free it here */ + } failed:up_write (&hidp_session_sem);
Marcel Holtmann
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Hi Dmitry,
Quoted 5 lines
Input: convert net/bluetooth to dynamic
input_devallocationThis is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>
on the condition your stuff got merged, then this patch is ok with me.
Regards
Marcel
Dmitry Torokhov
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 4 lines · Marcel Holtmann
Hi Dmitry,
Quoted 2 lines
Input: convert net/bluetooth to dynamic
input_devallocation
Quoted 8 lines
Quoted 3 lines
This is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>on the condition your stuff got merged, then this patch is ok with me.
Signed-off-by Marcel Holtmann <[email protected]>
I was planning on getting patch 8 (preparation patch) into kernel ASAP and then just sending individual subsystem patches to maintainers and Andrew so they can merge at their leisure (but don't wait for too long ;))
Signature · 1 line
Dmitry
Marcel Holtmann
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Hi Dmitry,
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Input: convert net/bluetooth to dynamic
input_devallocationThis is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>on the condition your stuff got merged, then this patch is ok with me.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Marcel Holtmann <[email protected]>I was planning on getting patch 8 (preparation patch) into kernel ASAP and then just sending individual subsystem patches to maintainers and Andrew so they can merge at their leisure (but don't wait for too long ;))
I have no problem with you submitting the changes. If Vojtech is fine with the proposed way, I would say that we get all of these changes into mainline now. The device model integration is long overdue.
Regards
Marcel
Re: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 13 lines · Marcel Holtmann
Hi Dmitry,
Quoted 11 lines
Quoted 10 lines
Quoted 5 lines
Input: convert net/bluetooth to dynamic
input_devallocationThis is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>on the condition your stuff got merged, then this patch is ok with me.
Signed-off-by Marcel Holtmann <[email protected]>
Quoted 8 lines
Quoted 4 lines
I was planning on getting patch 8 (preparation patch) into kernel ASAP and then just sending individual subsystem patches to maintainers and Andrew so they can merge at their leisure (but don't wait for too long ;))
I have no problem with you submitting the changes. If Vojtech is fine with the proposed way, I would say that we get all of these changes into mainline now. The device model integration is long overdue.
I'm fine with it, yes. I'm not completely convinced that an input device is really a class and not a device. ;) But I can understand that view.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Dmitry Torokhov
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 19 lines · Vojtech Pavlik
Quoted 18 lines · Marcel Holtmann
Hi Dmitry,
Quoted 15 lines
Quoted 10 lines
Quoted 5 lines
Input: convert net/bluetooth to dynamic
input_devallocationThis is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>on the condition your stuff got merged, then this patch is ok with me.
Signed-off-by Marcel Holtmann <[email protected]>I was planning on getting patch 8 (preparation patch) into kernel ASAP and then just sending individual subsystem patches to maintainers and Andrew so they can merge at their leisure (but don't wait for too long ;))
Quoted 6 lines
Quoted 3 lines
I have no problem with you submitting the changes. If Vojtech is fine with the proposed way, I would say that we get all of these changes into mainline now. The device model integration is long overdue.
I'm fine with it, yes. I'm not completely convinced that an input device is really a class and not a device. ;) But I can understand that view.
They are devices - class devices :). I have the following distinction in my head - "normal" devices (bus devices) are real hardware devices and their drivers need to do resource and/or power management. Class devices represent virtual devices - some kind of abstraction - that unify and combine "real" devices from several buses into one class. And of course nothing shoudl stop us from building class devices on top of other class devices, if needed.
Anyway, I think if Greg gives up and agrees on nesting classes all of it can go in -mm for now and I will contact other maintainers to verify that changes work. IIRC video/dvb mainatiners prefered all changes to go through them.
In any case I don't expect it reach Linus until after 2.6.14 released
- do you agree?
Signature · 1 line
Dmitry
Re: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 5 lines · Dmitry Torokhov
Anyway, I think if Greg gives up and agrees on nesting classes all of it can go in -mm for now and I will contact other maintainers to verify that changes work. IIRC video/dvb mainatiners prefered all changes to go through them.
No, I don't agree with this. Give me a day to write up what I think we should do instead (something along the lines of "subclasses")
Quoted 2 lines
In any case I don't expect it reach Linus until after 2.6.14 released
- do you agree?
Oh, I agree this isn't 2.6.14 material :)
thanks,
greg k-h
Dmitry Torokhov
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 10 lines · Greg KH
Quoted 5 lines · Dmitry Torokhov
Anyway, I think if Greg gives up and agrees on nesting classes all of it can go in -mm for now and I will contact other maintainers to verify that changes work. IIRC video/dvb mainatiners prefered all changes to go through them.
No, I don't agree with this. Give me a day to write up what I think we should do instead (something along the lines of "subclasses")
Hmm.. nested class _is_ a subclass. It is just not a separate object structure (like you don't have sub-devices either). But I guess I better wait fro your write-up...
Signature · 1 line
Dmitry
Re: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
In reply to Dmitry TorokhovQuoted 24 lines · Dmitry Torokhov
Quoted 23 lines · Vojtech Pavlik
Quoted 21 lines · Marcel Holtmann
Hi Dmitry,
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Input: convert net/bluetooth to dynamic
input_devallocationThis is required for
input_devsysfs integrationSigned-off-by Dmitry Torokhov <[email protected]>on the condition your stuff got merged, then this patch is ok with me.
Quoted 7 lines
Quoted 2 lines
Signed-off-by Marcel Holtmann <[email protected]>I was planning on getting patch 8 (preparation patch) into kernel ASAP and then just sending individual subsystem patches to maintainers and Andrew so they can merge at their leisure (but don't wait for too long ;))
I have no problem with you submitting the changes. If Vojtech is fine with the proposed way, I would say that we get all of these changes into mainline now. The device model integration is long overdue.
Quoted 8 lines
Quoted 2 lines
I'm fine with it, yes. I'm not completely convinced that an input device is really a class and not a device. ;) But I can understand that view.
They are devices - class devices :). I have the following distinction in my head - "normal" devices (bus devices) are real hardware devices and their drivers need to do resource and/or power management. Class devices represent virtual devices - some kind of abstraction - that unify and combine "real" devices from several buses into one class.
Yes. While input drivers do need to care about power management usually, the input device abstraction itself doesn't have to, which makes it indeed a special kind of a device.
Quoted 2 lines
And of course nothing shoudl stop us from building class devices on top of other class devices, if needed.
I was always wondering whether the distinction between bus/class was needed, as the border isn't very clear.
Quoted 7 lines
Anyway, I think if Greg gives up and agrees on nesting classes all of it can go in -mm for now and I will contact other maintainers to verify that changes work. IIRC video/dvb mainatiners prefered all changes to go through them.
In any case I don't expect it reach Linus until after 2.6.14 released
- do you agree?
Yup.
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
Dmitry Torokhov
maintainerRe: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 11 lines · Vojtech Pavlik
Quoted 5 lines · Dmitry Torokhov
They are devices - class devices :). I have the following distinction in my head - "normal" devices (bus devices) are real hardware devices and their drivers need to do resource and/or power management. Class devices represent virtual devices - some kind of abstraction - that unify and combine "real" devices from several buses into one class.
Yes. While input drivers do need to care about power management usually, the input device abstraction itself doesn't have to, which makes it indeed a special kind of a device.
Right. They just signal to underlying hardware driver when they are in use (open), but the actual power management is left to the specific bus/driver, not input core.
Quoted 3 lines
I was always wondering whether the distinction between bus/class was needed, as the border isn't very clear.
Classes combine devices which are logically the same, i.e. they perform similar functions. Buses combine devices that are perform different functions but have similar hardware interface. For example a network cards - it is a class. You can have network card sit on a PCI, USB, ISA buses but for the rest of the kernel they are accesses through netdev abstraction. At least this is my understanding of our device model ;)
Signature · 1 line
Dmitry
Re: [patch 09/28] Input: convert net/bluetooth to dynamic input_dev allocation
Quoted 21 lines · Dmitry Torokhov
Quoted 11 lines · Vojtech Pavlik
Quoted 5 lines · Dmitry Torokhov
They are devices - class devices :). I have the following distinction in my head - "normal" devices (bus devices) are real hardware devices and their drivers need to do resource and/or power management. Class devices represent virtual devices - some kind of abstraction - that unify and combine "real" devices from several buses into one class.
Yes. While input drivers do need to care about power management usually, the input device abstraction itself doesn't have to, which makes it indeed a special kind of a device.
Right. They just signal to underlying hardware driver when they are in use (open), but the actual power management is left to the specific bus/driver, not input core.
Quoted 3 lines
I was always wondering whether the distinction between bus/class was needed, as the border isn't very clear.
Quoted 7 lines
Classes combine devices which are logically the same, i.e. they perform similar functions. Buses combine devices that are perform different functions but have similar hardware interface. For example a network cards - it is a class. You can have network card sit on a PCI, USB, ISA buses but for the rest of the kernel they are accesses through netdev abstraction. At least this is my understanding of our device model ;)
Especially with things like Ethernet - there is not much difference between it and other busses like SCSI. Both the Ethernet card and the SCSI card give access to a bus behind them, they're in fact just bridges.
You can have a harddrive sitting on both SCSI and Ethernet (iSCSI), and there even is an IP-over-SCSI patch somewhere that allows connecting two machines with a SCSI cable.
Similarly, you can have USB on PCI and on ISA. There will be two different USB controllers in different places in the bus hierarchy. Yet they can be accessed through the same means, something that would make them a class.
[I'm playing a bit of a devil's advocate here - I see what the distinction is trying to achieve.]
Signature · 2 lines
Vojtech Pavlik SuSE Labs, SuSE CR
PATCH 10/28 Input: convert drivers/macintosh to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert drivers/macntosh to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/macintosh/adbhid.c | 220 +++++++++++++++++++++++--------------------- drivers/macintosh/mac_hid.c | 44 ++++---- 2 files changed, 139 insertions(+), 125 deletions(-)
drivers/macintosh/adbhid.c +115 -105
@@ -206,7 +206,7 @@ u8 adb_to_linux_keycodes[128] = { };struct adbhid { -struct input_dev input; +struct input_dev *input;int id;int default_id;int original_handler_id;
@@ -291,10 +291,10 @@ adbhid_input_keycode(int id, int keycodeswitch (keycode) {case ADB_KEY_CAPSLOCK :/* Generate down/up events for CapsLock everytime. */ -input_regs (&ahid->input, regs); -input_report_key (&ahid->input,KEY_CAPSLOCK ,1 ); -input_report_key (&ahid->input,KEY_CAPSLOCK ,0 ); -input_sync (&ahid->input); +input_regs (ahid->input, regs); +input_report_key (ahid->input,KEY_CAPSLOCK ,1 ); +input_report_key (ahid->input,KEY_CAPSLOCK ,0 ); +input_sync (ahid->input);return ;#ifdef CONFIG_PPC_PMAC case ADB_KEY_POWER_OLD :/* Power key on PBook 3400 needs remapping */
@@ -347,10 +347,10 @@ adbhid_input_keycode(int id, int keycode }if (adbhid[id]->keycode[keycode]) { -input_regs (&adbhid[id]->input, regs); -input_report_key (&adbhid[id]->input, +input_regs (adbhid[id]->input, regs); +input_report_key (adbhid[id]->input, adbhid[id]->keycode[keycode], !up_flag); -input_sync (&adbhid[id]->input); +input_sync (adbhid[id]->input); }else printk (KERN_INFO "Unhandled ADB key (scancode %#02x) %s.\n" , keycode, up_flag ?"released" :"pressed" );
@@ -441,20 +441,20 @@ adbhid_mouse_input(unsigned char *data,break ; } -input_regs (&adbhid[id]->input, regs); +input_regs (adbhid[id]->input, regs); -input_report_key (&adbhid[id]->input,BTN_LEFT , !((data[1 ] >>7 ) &1 )); -input_report_key (&adbhid[id]->input,BTN_MIDDLE , !((data[2 ] >>7 ) &1 )); +input_report_key (adbhid[id]->input,BTN_LEFT , !((data[1 ] >>7 ) &1 )); +input_report_key (adbhid[id]->input,BTN_MIDDLE , !((data[2 ] >>7 ) &1 ));if (nb >=4 && adbhid[id]->mouse_kind !=ADBMOUSE_TRACKPAD ) -input_report_key (&adbhid[id]->input,BTN_RIGHT , !((data[3 ] >>7 ) &1 )); +input_report_key (adbhid[id]->input,BTN_RIGHT , !((data[3 ] >>7 ) &1 )); -input_report_rel (&adbhid[id]->input,REL_X , +input_report_rel (adbhid[id]->input,REL_X , ((data[2 ]&0x7f ) <64 ? (data[2 ]&0x7f ) : (data[2 ]&0x7f )-128 )); -input_report_rel (&adbhid[id]->input,REL_Y , +input_report_rel (adbhid[id]->input,REL_Y , ((data[1 ]&0x7f ) <64 ? (data[1 ]&0x7f ) : (data[1 ]&0x7f )-128 )); -input_sync (&adbhid[id]->input); +input_sync (adbhid[id]->input); } static void
@@ -467,7 +467,7 @@ adbhid_buttons_input(unsigned char *datareturn ; } -input_regs (&adbhid[id]->input, regs); +input_regs (adbhid[id]->input, regs);switch (adbhid[id]->original_handler_id) {default :
@@ -477,19 +477,19 @@ adbhid_buttons_input(unsigned char *dataswitch (data[1 ] &0x0f ) {case 0x0 :/* microphone */ -input_report_key (&adbhid[id]->input,KEY_SOUND , down); +input_report_key (adbhid[id]->input,KEY_SOUND , down);break ;case 0x1 :/* mute */ -input_report_key (&adbhid[id]->input,KEY_MUTE , down); +input_report_key (adbhid[id]->input,KEY_MUTE , down);break ;case 0x2 :/* volume decrease */ -input_report_key (&adbhid[id]->input,KEY_VOLUMEDOWN , down); +input_report_key (adbhid[id]->input,KEY_VOLUMEDOWN , down);break ;case 0x3 :/* volume increase */ -input_report_key (&adbhid[id]->input,KEY_VOLUMEUP , down); +input_report_key (adbhid[id]->input,KEY_VOLUMEUP , down);break ;default :
@@ -513,19 +513,19 @@ adbhid_buttons_input(unsigned char *dataswitch (data[1 ] &0x0f ) {case 0x8 :/* mute */ -input_report_key (&adbhid[id]->input,KEY_MUTE , down); +input_report_key (adbhid[id]->input,KEY_MUTE , down);break ;case 0x7 :/* volume decrease */ -input_report_key (&adbhid[id]->input,KEY_VOLUMEDOWN , down); +input_report_key (adbhid[id]->input,KEY_VOLUMEDOWN , down);break ;case 0x6 :/* volume increase */ -input_report_key (&adbhid[id]->input,KEY_VOLUMEUP , down); +input_report_key (adbhid[id]->input,KEY_VOLUMEUP , down);break ;case 0xb :/* eject */ -input_report_key (&adbhid[id]->input,KEY_EJECTCD , down); +input_report_key (adbhid[id]->input,KEY_EJECTCD , down);break ;case 0xa :/* brightness decrease */
@@ -539,7 +539,7 @@ adbhid_buttons_input(unsigned char *data } }#endif /* CONFIG_PMAC_BACKLIGHT */ -input_report_key (&adbhid[id]->input,KEY_BRIGHTNESSDOWN , down); +input_report_key (adbhid[id]->input,KEY_BRIGHTNESSDOWN , down);break ;case 0x9 :/* brightness increase */
@@ -553,19 +553,19 @@ adbhid_buttons_input(unsigned char *data } }#endif /* CONFIG_PMAC_BACKLIGHT */ -input_report_key (&adbhid[id]->input,KEY_BRIGHTNESSUP , down); +input_report_key (adbhid[id]->input,KEY_BRIGHTNESSUP , down);break ;case 0xc :/* videomode switch */ -input_report_key (&adbhid[id]->input,KEY_SWITCHVIDEOMODE , down); +input_report_key (adbhid[id]->input,KEY_SWITCHVIDEOMODE , down);break ;case 0xd :/* keyboard illumination toggle */ -input_report_key (&adbhid[id]->input,KEY_KBDILLUMTOGGLE , down); +input_report_key (adbhid[id]->input,KEY_KBDILLUMTOGGLE , down);break ;case 0xe :/* keyboard illumination decrease */ -input_report_key (&adbhid[id]->input,KEY_KBDILLUMDOWN , down); +input_report_key (adbhid[id]->input,KEY_KBDILLUMDOWN , down);break ;case 0xf :
@@ -573,7 +573,7 @@ adbhid_buttons_input(unsigned char *datacase 0x8f :case 0x0f :/* keyboard illumination increase */ -input_report_key (&adbhid[id]->input,KEY_KBDILLUMUP , down); +input_report_key (adbhid[id]->input,KEY_KBDILLUMUP , down);break ;case 0x7f :
@@ -596,7 +596,7 @@ adbhid_buttons_input(unsigned char *databreak ; } -input_sync (&adbhid[id]->input); +input_sync (adbhid[id]->input); }static struct adb_request led_request;
@@ -683,7 +683,7 @@ adb_message_handler(struct notifier_blocint i;for (i =1 ; i <16 ; i++) {if (adbhid[i]) -del_timer_sync (&adbhid[i]->input.timer); +del_timer_sync (&adbhid[i]->input->timer); } }
@@ -699,153 +699,163 @@ adb_message_handler(struct notifier_blocreturn NOTIFY_DONE ; } -static void +static int adbhid_input_register (int id,int default_id,int original_handler_id,int current_handler_id,int mouse_kind) { +struct adbhid *hid; +struct input_dev *input_dev; +int err;int i;if (adbhid[id]) {printk (KERN_ERR "Trying to reregister ADB HID on ID %d\n" , id); -return ; +return -EEXIST ; } -if (!(adbhid[id] =kmalloc (sizeof (struct adbhid ),GFP_KERNEL ))) -return ; - -memset (adbhid[id],0 ,sizeof (struct adbhid )); -sprintf (adbhid[id]->phys,"adb%d:%d.%02x/input" , id, default_id, original_handler_id); + adbhid[id] = hid =kzalloc (sizeof (struct adbhid ),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!hid || !input_dev) { + err = -ENOMEM ; + goto fail; -init_input_dev (&adbhid[id]->input); + } - adbhid[id]->id = default_id; - adbhid[id]->original_handler_id = original_handler_id; - adbhid[id]->current_handler_id = current_handler_id; - adbhid[id]->mouse_kind = mouse_kind; - adbhid[id]->flags =0 ; - adbhid[id]->input.private = adbhid[id]; - adbhid[id]->input.name = adbhid[id]->name; - adbhid[id]->input.phys = adbhid[id]->phys; - adbhid[id]->input.id.bustype =BUS_ADB ; - adbhid[id]->input.id.vendor =0x0001 ; - adbhid[id]->input.id.product = (id <<12 ) | (default_id <<8 ) | original_handler_id; - adbhid[id]->input.id.version =0x0100 ; +sprintf (hid->phys,"adb%d:%d.%02x/input" , id, default_id, original_handler_id); + + hid->id = default_id; + hid->original_handler_id = original_handler_id; + hid->current_handler_id = current_handler_id; + hid->mouse_kind = mouse_kind; + hid->flags =0 ; + input_dev->private = hid; + input_dev->name = hid->name; + input_dev->phys = hid->phys; + input_dev->id.bustype =BUS_ADB ; + input_dev->id.vendor =0x0001 ; + input_dev->id.product = (id <<12 ) | (default_id <<8 ) | original_handler_id; + input_dev->id.version =0x0100 ;switch (default_id) {case ADB_KEYBOARD : -if (!(adbhid[id]->keycode =kmalloc (sizeof (adb_to_linux_keycodes),GFP_KERNEL ))) { -kfree (adbhid[id]); -return ; + hid->keycode =kmalloc (sizeof (adb_to_linux_keycodes),GFP_KERNEL ); +if (!hid->keycode) { + err = -ENOMEM ; + goto fail; } -sprintf (adbhid[id]->name,"ADB keyboard" ); +sprintf (hid->name,"ADB keyboard" ); -memcpy (adbhid[id]->keycode, adb_to_linux_keycodes,sizeof (adb_to_linux_keycodes)); +memcpy (hid->keycode, adb_to_linux_keycodes,sizeof (adb_to_linux_keycodes));printk (KERN_INFO "Detected ADB keyboard, type " );switch (original_handler_id) {default :printk ("<unknown>.\n" ); - adbhid[id]->input.id.version =ADB_KEYBOARD_UNKNOWN ; + input_dev->id.version =ADB_KEYBOARD_UNKNOWN ;break ;case 0x01 :case 0x02 :case 0x03 :case 0x06 :case 0x08 :case 0x0C :case 0x10 :case 0x18 :case 0x1B :case 0x1C :case 0xC0 :case 0xC3 :case 0xC6 :printk ("ANSI.\n" ); - adbhid[id]->input.id.version =ADB_KEYBOARD_ANSI ; + input_dev->id.version =ADB_KEYBOARD_ANSI ;break ;case 0x04 :case 0x05 :case 0x07 :case 0x09 :case 0x0D :case 0x11 :case 0x14 :case 0x19 :case 0x1D :case 0xC1 :case 0xC4 :case 0xC7 :printk ("ISO, swapping keys.\n" ); - adbhid[id]->input.id.version =ADB_KEYBOARD_ISO ; - i = adbhid[id]->keycode[10 ]; - adbhid[id]->keycode[10 ] = adbhid[id]->keycode[50 ]; - adbhid[id]->keycode[50 ] = i; + input_dev->id.version =ADB_KEYBOARD_ISO ; + i = hid->keycode[10 ]; + hid->keycode[10 ] = hid->keycode[50 ]; + hid->keycode[50 ] = i;break ;case 0x12 :case 0x15 :case 0x16 :case 0x17 :case 0x1A :case 0x1E :case 0xC2 :case 0xC5 :case 0xC8 :case 0xC9 :printk ("JIS.\n" ); - adbhid[id]->input.id.version =ADB_KEYBOARD_JIS ; + input_dev->id.version =ADB_KEYBOARD_JIS ;break ; }for (i =0 ; i <128 ; i++) -if (adbhid[id]->keycode[i]) -set_bit (adbhid[id]->keycode[i], adbhid[id]->input.keybit); +if (hid->keycode[i]) +set_bit (hid->keycode[i], input_dev->keybit); - adbhid[id]->input.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_LED ) |BIT (EV_REP ); - adbhid[id]->input.ledbit[0 ] =BIT (LED_SCROLLL ) |BIT (LED_CAPSL ) |BIT (LED_NUML ); - adbhid[id]->input.event = adbhid_kbd_event; - adbhid[id]->input.keycodemax =127 ; - adbhid[id]->input.keycodesize =1 ; + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_LED ) |BIT (EV_REP ); + input_dev->ledbit[0 ] =BIT (LED_SCROLLL ) |BIT (LED_CAPSL ) |BIT (LED_NUML ); + input_dev->event = adbhid_kbd_event; + input_dev->keycodemax =127 ; + input_dev->keycodesize =1 ;break ;case ADB_MOUSE : -sprintf (adbhid[id]->name,"ADB mouse" ); +sprintf (hid->name,"ADB mouse" ); - adbhid[id]->input.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); - adbhid[id]->input.keybit[LONG (BTN_MOUSE )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); - adbhid[id]->input.relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ); + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); + input_dev->keybit[LONG (BTN_MOUSE )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); + input_dev->relbit[0 ] =BIT (REL_X ) |BIT (REL_Y );break ;case ADB_MISC :switch (original_handler_id) {case 0x02 :/* Adjustable keyboard button device */ -sprintf (adbhid[id]->name,"ADB adjustable keyboard buttons" ); - adbhid[id]->input.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ); -set_bit (KEY_SOUND , adbhid[id]->input.keybit); -set_bit (KEY_MUTE , adbhid[id]->input.keybit); -set_bit (KEY_VOLUMEUP , adbhid[id]->input.keybit); -set_bit (KEY_VOLUMEDOWN , adbhid[id]->input.keybit); +sprintf (hid->name,"ADB adjustable keyboard buttons" ); + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ); +set_bit (KEY_SOUND , input_dev->keybit); +set_bit (KEY_MUTE , input_dev->keybit); +set_bit (KEY_VOLUMEUP , input_dev->keybit); +set_bit (KEY_VOLUMEDOWN , input_dev->keybit);break ;case 0x1f :/* Powerbook button device */ -sprintf (adbhid[id]->name,"ADB Powerbook buttons" ); - adbhid[id]->input.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ); -set_bit (KEY_MUTE , adbhid[id]->input.keybit); -set_bit (KEY_VOLUMEUP , adbhid[id]->input.keybit); -set_bit (KEY_VOLUMEDOWN , adbhid[id]->input.keybit); -set_bit (KEY_BRIGHTNESSUP , adbhid[id]->input.keybit); -set_bit (KEY_BRIGHTNESSDOWN , adbhid[id]->input.keybit); -set_bit (KEY_EJECTCD , adbhid[id]->input.keybit); -set_bit (KEY_SWITCHVIDEOMODE , adbhid[id]->input.keybit); -set_bit (KEY_KBDILLUMTOGGLE , adbhid[id]->input.keybit); -set_bit (KEY_KBDILLUMDOWN , adbhid[id]->input.keybit); -set_bit (KEY_KBDILLUMUP , adbhid[id]->input.keybit); +sprintf (hid->name,"ADB Powerbook buttons" ); + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ); +set_bit (KEY_MUTE , input_dev->keybit); +set_bit (KEY_VOLUMEUP , input_dev->keybit); +set_bit (KEY_VOLUMEDOWN , input_dev->keybit); +set_bit (KEY_BRIGHTNESSUP , input_dev->keybit); +set_bit (KEY_BRIGHTNESSDOWN , input_dev->keybit); +set_bit (KEY_EJECTCD , input_dev->keybit); +set_bit (KEY_SWITCHVIDEOMODE , input_dev->keybit); +set_bit (KEY_KBDILLUMTOGGLE , input_dev->keybit); +set_bit (KEY_KBDILLUMDOWN , input_dev->keybit); +set_bit (KEY_KBDILLUMUP , input_dev->keybit);break ; } -if (adbhid[id]->name[0 ]) +if (hid->name[0 ])break ;/* else fall through */ default :printk (KERN_INFO "Trying to register unknown ADB device to input layer.\n" ); -kfree (adbhid[id]); -return ; + err = -ENODEV ; + goto fail; } - adbhid[id]->input.keycode = adbhid[id]->keycode; - -input_register_device (&adbhid[id]->input); + input_dev->keycode = hid->keycode; -printk (KERN_INFO "input: %s on %s\n" , - adbhid[id]->name, adbhid[id]->phys); +input_register_device (input_dev);if (default_id ==ADB_KEYBOARD ) {/* HACK WARNING!! This should go away as soon there is an utility * to control that for event devices. */ - adbhid[id]->input.rep[REP_DELAY ] =500 ;/* input layer default: 250 */ - adbhid[id]->input.rep[REP_PERIOD ] =66 ;/* input layer default: 33 */ + input_dev->rep[REP_DELAY ] =500 ;/* input layer default: 250 */ + input_dev->rep[REP_PERIOD ] =66 ;/* input layer default: 33 */ } + +return 0 ; + + fail:input_free_device (input_dev); +kfree (hid); + adbhid[id] =NULL ; +return err; }static void adbhid_input_unregister (int id) { -input_unregister_device (&adbhid[id]->input); +input_unregister_device (adbhid[id]->input);if (adbhid[id]->keycode)kfree (adbhid[id]->keycode);kfree (adbhid[id]);
@@ -858,7 +868,7 @@ adbhid_input_reregister(int id, int defa int cur_handler_id, int mk) { if (adbhid[id]) { - if (adbhid[id]->input.id.product != + if (adbhid[id]->input->id.product != ((id << 12)|(default_id << 8)|org_handler_id)) {adbhid_input_unregister (id ); adbhid_input_register(id, default_id, org_handler_id,
drivers/macintosh/mac_hid.c +24 -20
72 lines not on this page · raw message
PATCH 11/28 Input: convert konicawc to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert konicawc to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/usb/media/konicawc.c | 89 +++++++++++++++++++++++++++++-------------- 1 files changed, 61 insertions(+), 28 deletions(-)
drivers/usb/media/konicawc.c +61 -28
@@ -119,7 +119,7 @@ struct konicawc {int yplanesz;/* Number of bytes in the Y plane */ unsigned int buttonsts:1;#ifdef CONFIG_INPUT -struct input_dev input; +struct input_dev *input;char input_physname[64 ];#endif };
@@ -218,6 +218,57 @@ static void konicawc_adjust_picture(strukonicawc_camera_on (uvd); } +#ifdef CONFIG_INPUT + +static void konicawc_register_input (struct konicawc *cam,struct usb_device *dev) +{ +struct input_dev *input_dev; + +usb_make_path (dev, cam->input_physname,sizeof (cam->input_physname)); +strncat (cam->input_physname,"/input0" ,sizeof (cam->input_physname)); + + cam->input = input_dev =input_allocate_device (); +if (!input_dev) { +warn ("Not enough memory for camera's input device\n" ); +return ; + } + + input_dev->name ="Konicawc snapshot button" ; + input_dev->phys = cam->input_physname; +usb_to_input_id (dev, &input_dev->id); + input_dev->cdev.dev = &dev->dev; + + input_dev->evbit[0 ] =BIT (EV_KEY ); + input_dev->keybit[LONG (BTN_0 )] =BIT (BTN_0 ); + + input_dev->private = cam; + +input_register_device (cam->input); +} + +static void konicawc_unregister_input (struct konicawc *cam) +{ +if (cam->input) { +input_unregister_device (cam->input); + cam->input =NULL ; + } +} + +static void konicawc_report_buttonstat (struct konicawc *cam) +{ +if (cam->input) { +input_report_key (cam->input,BTN_0 , cam->buttonsts); +input_sync (cam->input); + } +} + +#else + +static inline void konicawc_register_input (struct konicawc *cam,struct usb_device *dev) { } +static inline void konicawc_unregister_input (struct konicawc *cam) { } +static inline void konicawc_report_buttonstat (struct konicawc *cam) { } + +#endif /* CONFIG_INPUT */ static int konicawc_compress_iso (struct uvd *uvd,struct urb *dataurb,struct urb *stsurb) {
@@ -273,10 +324,7 @@ static int konicawc_compress_iso(structif (button != cam->buttonsts) {DEBUG (2 ,"button: %sclicked" , button ?"" :"un" ); cam->buttonsts = button; -#ifdef CONFIG_INPUT -input_report_key (&cam->input,BTN_0 , cam->buttonsts); -input_sync (&cam->input); -#endif +konicawc_report_buttonstat (cam); }if (sts ==0x01 ) {/* drop frame */
@@ -645,9 +693,9 @@ static int konicawc_set_video_mode(strucRingQueue_Flush (&uvd->dp); cam->lastframe =-2 ;if (uvd->curframe !=-1 ) { - uvd->frame[uvd->curframe].curline =0 ; - uvd->frame[uvd->curframe].seqRead_Length =0 ; - uvd->frame[uvd->curframe].seqRead_Index =0 ; + uvd->frame[uvd->curframe].curline =0 ; + uvd->frame[uvd->curframe].seqRead_Length =0 ; + uvd->frame[uvd->curframe].seqRead_Index =0 ; }konicawc_start_data (uvd);
@@ -718,7 +766,6 @@ static void konicawc_configure_video(strDEBUG (1 ,"setting initial values" ); } -static int konicawc_probe (struct usb_interface *intf,const struct usb_device_id *devid) {struct usb_device *dev =interface_to_usbdev (intf);
@@ -839,21 +886,8 @@ static int konicawc_probe(struct usb_interr ("usbvideo_RegisterVideoDevice() failed." ); uvd =NULL ; } -#ifdef CONFIG_INPUT -/* Register input device for button */ -memset (&cam->input,0 ,sizeof (struct input_dev )); - cam->input.name ="Konicawc snapshot button" ; - cam->input.private = cam; - cam->input.evbit[0 ] =BIT (EV_KEY ); - cam->input.keybit[LONG (BTN_0 )] =BIT (BTN_0 ); -usb_to_input_id (dev, &cam->input.id); -input_register_device (&cam->input); - -usb_make_path (dev, cam->input_physname,56 ); -strcat (cam->input_physname,"/input0" ); - cam->input.phys = cam->input_physname; -info ("konicawc: %s on %s\n" , cam->input.name, cam->input.phys); -#endif + +konicawc_register_input (cam, dev); }if (uvd) {
@@ -869,10 +903,9 @@ static void konicawc_free_uvd(struct uvdint i;struct konicawc *cam = (struct konicawc *)uvd->user_data; -#ifdef CONFIG_INPUT -input_unregister_device (&cam->input); -#endif -for (i=0 ; i <USBVIDEO_NUMSBUF ; i++) { +konicawc_unregister_input (cam); + +for (i =0 ; i <USBVIDEO_NUMSBUF ; i++) {usb_free_urb (cam->sts_urb[i]); cam->sts_urb[i] =NULL ; }
PATCH 12/28 Input: convert onetouch to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert onetouch to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/usb/storage/onetouch.c | 105 ++++++++++++++++++++--------------------- 1 files changed, 53 insertions(+), 52 deletions(-)
drivers/usb/storage/onetouch.c +53 -52
@@ -5,7 +5,7 @@* Copyright (c) 2005 Nick Sillik <[email protected]> * * Initial work by: -* Copyright (c) 2003 Erik Thyren <[email protected]> +* Copyright (c) 2003 Erik Thyren <[email protected]> * * Based on usbmouse.c (Vojtech Pavlik) and xpad.c (Marko Friedemann) *
@@ -46,7 +46,7 @@ void onetouch_release_input(void *onetoustruct usb_onetouch {char name[128 ];char phys[64 ]; -struct input_dev dev;/* input device interface */ +struct input_dev *dev;/* input device interface */ struct usb_device *udev;/* usb device */ struct urb *irq;/* urb for interrupt in report */
@@ -58,7 +58,7 @@ static void usb_onetouch_irq(struct urb {struct usb_onetouch *onetouch = urb->context;signed char *data = onetouch->data; -struct input_dev *dev = &onetouch->dev; +struct input_dev *dev = onetouch->dev;int status;switch (urb->status) {
@@ -74,11 +74,9 @@ static void usb_onetouch_irq(struct urb }input_regs (dev, regs); - -input_report_key (&onetouch->dev,ONETOUCH_BUTTON , - data[0 ] &0x02 ); - +input_report_key (dev,ONETOUCH_BUTTON , data[0 ] &0x02 );input_sync (dev); + resubmit: status =usb_submit_urb (urb,SLAB_ATOMIC );if (status)
@@ -113,8 +111,8 @@ int onetouch_connect_input(struct us_datstruct usb_host_interface *interface;struct usb_endpoint_descriptor *endpoint;struct usb_onetouch *onetouch; +struct input_dev *input_dev;int pipe, maxp; -char path[64 ]; interface = ss->pusb_intf->cur_altsetting;
@@ -122,62 +120,62 @@ int onetouch_connect_input(struct us_datreturn -ENODEV ; endpoint = &interface->endpoint[2 ].desc; -if (!(endpoint->bEndpointAddress &USB_DIR_IN )) +if (!(endpoint->bEndpointAddress &USB_DIR_IN ))return -ENODEV ; -if ((endpoint->bmAttributes &USB_ENDPOINT_XFERTYPE_MASK ) +if ((endpoint->bmAttributes &USB_ENDPOINT_XFERTYPE_MASK ) !=USB_ENDPOINT_XFER_INT )return -ENODEV ; pipe =usb_rcvintpipe (udev, endpoint->bEndpointAddress); maxp =usb_maxpacket (udev, pipe,usb_pipeout (pipe)); -if (!(onetouch =kcalloc (1 ,sizeof (struct usb_onetouch ),GFP_KERNEL ))) -return -ENOMEM ; + onetouch =kzalloc (sizeof (struct usb_onetouch ),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!onetouch || !input_dev) + goto fail1; onetouch->data =usb_buffer_alloc (udev,ONETOUCH_PKT_LEN ,SLAB_ATOMIC , &onetouch->data_dma); -if (!onetouch->data){ -kfree (onetouch); -return -ENOMEM ; - } +if (!onetouch->data) + goto fail1; onetouch->irq =usb_alloc_urb (0 ,GFP_KERNEL ); -if (!onetouch->irq){ -kfree (onetouch); -usb_buffer_free (udev,ONETOUCH_PKT_LEN , - onetouch->data, onetouch->data_dma); -return -ENODEV ; - } - +if (!onetouch->irq) + goto fail2; onetouch->udev = udev; - -set_bit (EV_KEY , onetouch->dev.evbit); -set_bit (ONETOUCH_BUTTON , onetouch->dev.keybit); -clear_bit (0 , onetouch->dev.keybit); - - onetouch->dev.private = onetouch; - onetouch->dev.open = usb_onetouch_open; - onetouch->dev.close = usb_onetouch_close; - -usb_make_path (udev, path,sizeof (path)); -sprintf (onetouch->phys,"%s/input0" , path); - - onetouch->dev.name = onetouch->name; - onetouch->dev.phys = onetouch->phys; - -usb_to_input_id (udev, &onetouch->dev.id); - - onetouch->dev.dev = &udev->dev; + onetouch->dev = input_dev;if (udev->manufacturer) -strcat (onetouch->name, udev->manufacturer); -if (udev->product) -sprintf (onetouch->name,"%s %s" , onetouch->name, - udev->product); +strlcpy (onetouch->name, udev->manufacturer, +sizeof (onetouch->name)); +if (udev->product) { +if (udev->manufacturer) +strlcat (onetouch->name," " ,sizeof (onetouch->name)); +strlcat (onetouch->name, udev->product,sizeof (onetouch->name)); + } +if (!strlen (onetouch->name)) -sprintf (onetouch->name,"Maxtor Onetouch %04x:%04x" , - onetouch->dev.id.vendor, onetouch->dev.id.product); +snprintf (onetouch->name,sizeof (onetouch->name), +"Maxtor Onetouch %04x:%04x" , +le16_to_cpu (udev->descriptor.idVendor), +le16_to_cpu (udev->descriptor.idProduct)); + +usb_make_path (udev, onetouch->phys,sizeof (onetouch->phys)); +strlcat (onetouch->phys,"/input0" ,sizeof (onetouch->phys)); + + input_dev->name = onetouch->name; + input_dev->phys = onetouch->phys; +usb_to_input_id (udev, &input_dev->id); + input_dev->cdev.dev = &udev->dev; + +set_bit (EV_KEY , input_dev->evbit); +set_bit (ONETOUCH_BUTTON , input_dev->keybit); +clear_bit (0 , input_dev->keybit); + + input_dev->private = onetouch; + input_dev->open = usb_onetouch_open; + input_dev->close = usb_onetouch_close; usb_fill_int_urb(onetouch->irq, udev, pipe, onetouch->data, (maxp > 8 ? 8 : maxp),
@@ -188,10 +186,15 @@ int onetouch_connect_input(struct us_dat ss->extra_destructor = onetouch_release_input; ss->extra = onetouch; -input_register_device (&onetouch->dev); -printk (KERN_INFO "usb-input: %s on %s\n" , onetouch->dev.name, path); +input_register_device (onetouch->dev);return 0 ; + + fail2:usb_buffer_free (udev,ONETOUCH_PKT_LEN , + onetouch->data, onetouch->data_dma); + fail1:kfree (onetouch); +input_free_device (input_dev); +return -ENOMEM ; }void onetouch_release_input (void *onetouch_)
@@ -200,11 +203,9 @@ void onetouch_release_input(void *onetouif (onetouch) {usb_kill_urb (onetouch->irq); -input_unregister_device (&onetouch->dev); +input_unregister_device (onetouch->dev);usb_free_urb (onetouch->irq);usb_buffer_free (onetouch->udev,ONETOUCH_PKT_LEN , onetouch->data, onetouch->data_dma); -printk (KERN_INFO "usb-input: deregistering %s\n" , - onetouch->dev.name); } }
PATCH 13/28 drivers/input/mouse: convert to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert drivers/input/mouse to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/input/mouse/alps.c | 67 +++++++++++++------------ drivers/input/mouse/alps.h | 2 drivers/input/mouse/amimouse.c | 51 +++++++++---------- drivers/input/mouse/inport.c | 96 ++++++++++++++++++----------------- drivers/input/mouse/lifebook.c | 16 +++-- drivers/input/mouse/logibm.c | 88 ++++++++++++++++---------------- drivers/input/mouse/logips2pp.c | 20 ++++--- drivers/input/mouse/maplemouse.c | 10 +-- drivers/input/mouse/pc110pad.c | 70 ++++++++++++-------------- drivers/input/mouse/psmouse-base.c | 99 +++++++++++++++++++------------------ drivers/input/mouse/psmouse.h | 2 drivers/input/mouse/rpcmouse.c | 43 +++++++--------- drivers/input/mouse/sermouse.c | 84 ++++++++++++++----------------- drivers/input/mouse/synaptics.c | 6 +- drivers/input/mouse/vsxxxaa.c | 84 ++++++++++++++----------------- 15 files changed, 370 insertions(+), 368 deletions(-)
drivers/input/mouse/amimouse.c +25 -26
@@ -34,10 +34,7 @@ MODULE_DESCRIPTION("Amiga mouse driver")MODULE_LICENSE ("GPL" );static int amimouse_lastx, amimouse_lasty; -static struct input_dev amimouse_dev; - -static char *amimouse_name ="Amiga mouse" ; -static char *amimouse_phys ="amimouse/input0" ; +static struct input_dev *amimouse_dev;static irqreturn_t amimouse_interrupt (int irq,void *dummy,struct pt_regs *fp) {
@@ -62,16 +59,16 @@ static irqreturn_t amimouse_interrupt(in potgor = custom.potgor; -input_regs (&amimouse_dev, fp); +input_regs (amimouse_dev, fp); -input_report_rel (&amimouse_dev,REL_X , dx); -input_report_rel (&amimouse_dev,REL_Y , dy); +input_report_rel (amimouse_dev,REL_X , dx); +input_report_rel (amimouse_dev,REL_Y , dy); -input_report_key (&amimouse_dev,BTN_LEFT , ciaa.pra &0x40 ); -input_report_key (&amimouse_dev,BTN_MIDDLE , potgor &0x0100 ); -input_report_key (&amimouse_dev,BTN_RIGHT , potgor &0x0400 ); +input_report_key (amimouse_dev,BTN_LEFT , ciaa.pra &0x40 ); +input_report_key (amimouse_dev,BTN_MIDDLE , potgor &0x0100 ); +input_report_key (amimouse_dev,BTN_RIGHT , potgor &0x0400 ); -input_sync (&amimouse_dev); +input_sync (amimouse_dev);return IRQ_HANDLED ; }
@@ -103,28 +100,30 @@ static int __init amimouse_init(void)if (!MACH_IS_AMIGA || !AMIGAHW_PRESENT (AMI_MOUSE ))return -ENODEV ; - amimouse_dev.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); - amimouse_dev.relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ); - amimouse_dev.keybit[LONG (BTN_LEFT )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); - amimouse_dev.open = amimouse_open; - amimouse_dev.close = amimouse_close; - - amimouse_dev.name = amimouse_name; - amimouse_dev.phys = amimouse_phys; - amimouse_dev.id.bustype =BUS_AMIGA ; - amimouse_dev.id.vendor =0x0001 ; - amimouse_dev.id.product =0x0002 ; - amimouse_dev.id.version =0x0100 ; +if (!(amimouse_dev =input_allocate_device ())) +return -ENOMEM ; + + amimouse_dev->name ="Amiga mouse" ; + amimouse_dev->phys ="amimouse/input0" ; + amimouse_dev->id.bustype =BUS_AMIGA ; + amimouse_dev->id.vendor =0x0001 ; + amimouse_dev->id.product =0x0002 ; + amimouse_dev->id.version =0x0100 ; + + amimouse_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); + amimouse_dev->relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ); + amimouse_dev->keybit[LONG (BTN_LEFT )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); + amimouse_dev->open = amimouse_open; + amimouse_dev->close = amimouse_close; -input_register_device (&amimouse_dev); +input_register_device (amimouse_dev); -printk (KERN_INFO "input: %s at joy0dat\n" , amimouse_name);return 0 ; } static void __exit amimouse_exit(void) { -input_unregister_device (&amimouse_dev); +input_unregister_device (amimouse_dev); }module_init (amimouse_init);
drivers/input/mouse/inport.c +49 -47
146 lines not on this page · raw message
drivers/input/mouse/logibm.c +45 -43
118 lines not on this page · raw message
drivers/input/mouse/maplemouse.c +3 -7
@@ -41,13 +41,12 @@ static int dc_mouse_connect(struct mapleunsigned long data =be32_to_cpu (dev->devinfo.function_data[0 ]);struct input_dev *input_dev; -if (!(input_dev =kmalloc (sizeof (struct input_dev ),GFP_KERNEL ))) -return -1 ; + dev->private_data = input_dev =input_allocate_device (); +if (!input_dev) +return -ENOMEM ; dev->private_data = input_dev; -memset (input_dev,0 ,sizeof (struct dc_mouse )); -init_input_dev (input_dev); input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); input_dev->keybit[LONG (BTN_MOUSE )] =BIT (BTN_LEFT ) |BIT (BTN_RIGHT ) |BIT (BTN_MIDDLE ); input_dev->relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ) |BIT (REL_WHEEL );
@@ -59,8 +58,6 @@ static int dc_mouse_connect(struct maplemaple_getcond_callback (dev, dc_mouse_callback,1 ,MAPLE_FUNC_MOUSE ); -printk (KERN_INFO "input: mouse(0x%lx): %s\n" , data, input_dev->name); -return 0 ; }
@@ -70,7 +67,6 @@ static void dc_mouse_disconnect(struct mstruct input_dev *input_dev = dev->private_data;input_unregister_device (input_dev); -kfree (input_dev); }
drivers/input/mouse/pc110pad.c +34 -36
115 lines not on this page · raw message
drivers/input/mouse/rpcmouse.c +21 -22
70 lines not on this page · raw message
drivers/input/mouse/sermouse.c +40 -44
126 lines not on this page · raw message
drivers/input/mouse/vsxxxaa.c +40 -44
138 lines not on this page · raw message
drivers/input/mouse/psmouse-base.c +53 -46
230 lines not on this page · raw message
drivers/input/mouse/psmouse.h +1 -1
@@ -36,7 +36,7 @@ typedef enum {struct psmouse {void *private; -struct input_dev dev; +struct input_dev *dev;struct ps2dev ps2dev;char *vendor;char *name;
drivers/input/mouse/synaptics.c +3 -3
@@ -342,7 +342,7 @@ static void synaptics_parse_hw_state(uns*/ static void synaptics_process_packet (struct psmouse *psmouse) { -struct input_dev *dev = &psmouse->dev; +struct input_dev *dev = psmouse->dev;struct synaptics_data *priv = psmouse->private;struct synaptics_hw_state hw;int num_fingers;
@@ -473,7 +473,7 @@ static unsigned char synaptics_detect_pkstatic psmouse_ret_t synaptics_process_byte (struct psmouse *psmouse,struct pt_regs *regs) { -struct input_dev *dev = &psmouse->dev; +struct input_dev *dev = psmouse->dev;struct synaptics_data *priv = psmouse->private;input_regs (dev, regs);
@@ -645,7 +645,7 @@ int synaptics_init(struct psmouse *psmouSYN_ID_MAJOR (priv->identity),SYN_ID_MINOR (priv->identity), priv->model_id, priv->capabilities, priv->ext_cap); -set_input_params (&psmouse->dev, priv); +set_input_params (psmouse->dev, priv); psmouse->protocol_handler = synaptics_process_byte; psmouse->set_rate = synaptics_set_rate;
drivers/input/mouse/alps.c +35 -32
110 lines not on this page · raw message
drivers/input/mouse/logips2pp.c +11 -9
@@ -40,7 +40,7 @@ struct ps2pp_info {static psmouse_ret_t ps2pp_process_byte (struct psmouse *psmouse,struct pt_regs *regs) { -struct input_dev *dev = &psmouse->dev; +struct input_dev *dev = psmouse->dev;unsigned char *packet = psmouse->packet;if (psmouse->pktcnt <3 )
@@ -257,25 +257,27 @@ static struct ps2pp_info *get_model_infostatic void ps2pp_set_model_properties (struct psmouse *psmouse,struct ps2pp_info *model_info,int using_ps2pp) { +struct input_dev *input_dev = psmouse->dev; +if (model_info->features &PS2PP_SIDE_BTN ) -set_bit (BTN_SIDE , psmouse->dev.keybit); +set_bit (BTN_SIDE , input_dev->keybit);if (model_info->features &PS2PP_EXTRA_BTN ) -set_bit (BTN_EXTRA , psmouse->dev.keybit); +set_bit (BTN_EXTRA , input_dev->keybit);if (model_info->features &PS2PP_TASK_BTN ) -set_bit (BTN_TASK , psmouse->dev.keybit); +set_bit (BTN_TASK , input_dev->keybit);if (model_info->features &PS2PP_NAV_BTN ) { -set_bit (BTN_FORWARD , psmouse->dev.keybit); -set_bit (BTN_BACK , psmouse->dev.keybit); +set_bit (BTN_FORWARD , input_dev->keybit); +set_bit (BTN_BACK , input_dev->keybit); }if (model_info->features &PS2PP_WHEEL ) -set_bit (REL_WHEEL , psmouse->dev.relbit); +set_bit (REL_WHEEL , input_dev->relbit);if (model_info->features &PS2PP_HWHEEL ) -set_bit (REL_HWHEEL , psmouse->dev.relbit); +set_bit (REL_HWHEEL , input_dev->relbit);switch (model_info->kind) {case PS2PP_KIND_WHEEL :
@@ -387,7 +389,7 @@ int ps2pp_init(struct psmouse *psmouse, }if (buttons <3 ) -clear_bit (BTN_MIDDLE , psmouse->dev.keybit); +clear_bit (BTN_MIDDLE , psmouse->dev->keybit);if (model_info)ps2pp_set_model_properties (psmouse, model_info, use_ps2pp);
drivers/input/mouse/alps.h +1 -1
@@ -22,7 +22,7 @@ struct alps_model_info { };struct alps_data { -struct input_dev dev2;/* Relative device */ +struct input_dev *dev2;/* Relative device */ char name[32 ];/* Name */ char phys[32 ];/* Phys */ struct alps_model_info *i;/* Info */
drivers/input/mouse/lifebook.c +9 -7
@@ -34,7 +34,7 @@ static struct dmi_system_id lifebook_dmistatic psmouse_ret_t lifebook_process_byte (struct psmouse *psmouse,struct pt_regs *regs) {unsigned char *packet = psmouse->packet; -struct input_dev *dev = &psmouse->dev; +struct input_dev *dev = psmouse->dev;if (psmouse->pktcnt !=3 )return PSMOUSE_GOOD_DATA ;
@@ -113,15 +113,17 @@ int lifebook_detect(struct psmouse *psmoint lifebook_init (struct psmouse *psmouse) { +struct input_dev *input_dev = psmouse->dev; +if (lifebook_absolute_mode (psmouse))return -1 ; - psmouse->dev.evbit[0 ] =BIT (EV_ABS ) |BIT (EV_KEY ) |BIT (EV_REL ); - psmouse->dev.keybit[LONG (BTN_LEFT )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); - psmouse->dev.keybit[LONG (BTN_TOUCH )] =BIT (BTN_TOUCH ); - psmouse->dev.relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ); -input_set_abs_params (&psmouse->dev,ABS_X ,0 ,1024 ,0 ,0 ); -input_set_abs_params (&psmouse->dev,ABS_Y ,0 ,1024 ,0 ,0 ); + input_dev->evbit[0 ] =BIT (EV_ABS ) |BIT (EV_KEY ) |BIT (EV_REL ); + input_dev->keybit[LONG (BTN_LEFT )] =BIT (BTN_LEFT ) |BIT (BTN_MIDDLE ) |BIT (BTN_RIGHT ); + input_dev->keybit[LONG (BTN_TOUCH )] =BIT (BTN_TOUCH ); + input_dev->relbit[0 ] =BIT (REL_X ) |BIT (REL_Y ); +input_set_abs_params (input_dev,ABS_X ,0 ,1024 ,0 ,0 ); +input_set_abs_params (input_dev,ABS_Y ,0 ,1024 ,0 ,0 ); psmouse->protocol_handler = lifebook_process_byte; psmouse->set_resolution = lifebook_set_resolution;
PATCH 14/28 drivers/input/keyboard: convert to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert drivers/input/keyboard to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/input/keyboard/amikbd.c | 59 +++++------ drivers/input/keyboard/atkbd.c | 188 +++++++++++++++++++----------------- drivers/input/keyboard/corgikbd.c | 74 +++++++------- drivers/input/keyboard/lkkbd.c | 126 ++++++++++++------------ drivers/input/keyboard/maple_keyb.c | 76 ++++++-------- drivers/input/keyboard/newtonkbd.c | 83 +++++++-------- drivers/input/keyboard/spitzkbd.c | 77 ++++++++------ drivers/input/keyboard/sunkbd.c | 117 +++++++++++----------- drivers/input/keyboard/xtkbd.c | 82 +++++++-------- 9 files changed, 450 insertions(+), 432 deletions(-)
drivers/input/keyboard/atkbd.c +102 -86
@@ -185,12 +185,12 @@ static struct {struct atkbd { -struct ps2dev ps2dev; +struct ps2dev ps2dev; +struct input_dev *dev;/* Written only during init */ char name[64 ];char phys[32 ]; -struct input_dev dev;unsigned short id;unsigned char keycode[512 ];
@@ -290,7 +290,7 @@ static irqreturn_t atkbd_interrupt(strucif (!atkbd->enabled) goto out; -input_event (&atkbd->dev,EV_MSC ,MSC_RAW , code); +input_event (atkbd->dev,EV_MSC ,MSC_RAW , code);if (atkbd->translated) {
@@ -326,10 +326,10 @@ static irqreturn_t atkbd_interrupt(struc atkbd->release =1 ; goto out;case ATKBD_RET_HANGUEL : -atkbd_report_key (&atkbd->dev, regs,KEY_HANGUEL ,3 ); +atkbd_report_key (atkbd->dev, regs,KEY_HANGUEL ,3 ); goto out;case ATKBD_RET_HANJA : -atkbd_report_key (&atkbd->dev, regs,KEY_HANJA ,3 ); +atkbd_report_key (atkbd->dev, regs,KEY_HANJA ,3 ); goto out;case ATKBD_RET_ERR :printk (KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n" , serio->phys);
@@ -345,7 +345,7 @@ static irqreturn_t atkbd_interrupt(struc }if (atkbd->keycode[code] !=ATKBD_KEY_NULL ) -input_event (&atkbd->dev,EV_MSC ,MSC_SCAN , code); +input_event (atkbd->dev,EV_MSC ,MSC_SCAN , code);switch (atkbd->keycode[code]) {case ATKBD_KEY_NULL :
@@ -365,7 +365,7 @@ static irqreturn_t atkbd_interrupt(struc"to make it known.\n" , code & 0x80 ? "e0" : "", code & 0x7f); } -input_sync (&atkbd->dev); +input_sync (atkbd->dev);break ;case ATKBD_SCR_1 : scroll =1 - atkbd->release *2 ;
@@ -390,7 +390,7 @@ static irqreturn_t atkbd_interrupt(strucbreak ;default : value = atkbd->release ?0 : - (1 + (!atkbd->softrepeat &&test_bit (atkbd->keycode[code], atkbd->dev.key))); + (1 + (!atkbd->softrepeat &&test_bit (atkbd->keycode[code], atkbd->dev->key)));switch (value) {/* Workaround Toshiba laptop multiple keypress */ case 0 :
@@ -398,7 +398,7 @@ static irqreturn_t atkbd_interrupt(strucbreak ;case 1 : atkbd->last = code; - atkbd->time = jiffies +msecs_to_jiffies (atkbd->dev.rep[REP_DELAY ]) /2 ; + atkbd->time = jiffies +msecs_to_jiffies (atkbd->dev->rep[REP_DELAY ]) /2 ;break ;case 2 :if (!time_after (jiffies, atkbd->time) && atkbd->last == code)
@@ -406,16 +406,16 @@ static irqreturn_t atkbd_interrupt(strucbreak ; } -atkbd_report_key (&atkbd->dev, regs, atkbd->keycode[code], value); +atkbd_report_key (atkbd->dev, regs, atkbd->keycode[code], value); }if (atkbd->scroll) { -input_regs (&atkbd->dev, regs); +input_regs (atkbd->dev, regs);if (click !=-1 ) -input_report_key (&atkbd->dev,BTN_MIDDLE , click); -input_report_rel (&atkbd->dev,REL_WHEEL , scroll); -input_report_rel (&atkbd->dev,REL_HWHEEL , hscroll); -input_sync (&atkbd->dev); +input_report_key (atkbd->dev,BTN_MIDDLE , click); +input_report_rel (atkbd->dev,REL_WHEEL , scroll); +input_report_rel (atkbd->dev,REL_HWHEEL , hscroll); +input_sync (atkbd->dev); } atkbd->release =0 ;
@@ -463,7 +463,6 @@ static int atkbd_event(struct input_devreturn 0 ; -case EV_REP :if (atkbd->softrepeat)return 0 ;
@@ -693,7 +692,7 @@ static void atkbd_disconnect(struct seridevice_remove_file (&serio->dev, &atkbd_attr_softrepeat);device_remove_file (&serio->dev, &atkbd_attr_softraw); -input_unregister_device (&atkbd->dev); +input_unregister_device (atkbd->dev);serio_close (serio);serio_set_drvdata (serio,NULL );kfree (atkbd);
@@ -701,7 +700,7 @@ static void atkbd_disconnect(struct seri/* -* atkbd_set_device_attrs() initializes keyboard's keycode table +* atkbd_set_keycode_table() initializes keyboard's keycode table * according to the selected scancode set */
@@ -737,53 +736,58 @@ static void atkbd_set_keycode_table(strustatic void atkbd_set_device_attrs (struct atkbd *atkbd) { +struct input_dev *input_dev = atkbd->dev;int i; -memset (&atkbd->dev,0 ,sizeof (struct input_dev )); +if (atkbd->extra) +sprintf (atkbd->name,"AT Set 2 Extra keyboard" ); +else +sprintf (atkbd->name,"AT %s Set %d keyboard" , + atkbd->translated ?"Translated" :"Raw" , atkbd->set); -init_input_dev (&atkbd->dev); +sprintf (atkbd->phys,"%s/input0" , atkbd->ps2dev.serio->phys); - atkbd->dev.name = atkbd->name; - atkbd->dev.phys = atkbd->phys; - atkbd->dev.id.bustype =BUS_I8042 ; - atkbd->dev.id.vendor =0x0001 ; - atkbd->dev.id.product = atkbd->translated ?1 : atkbd->set; - atkbd->dev.id.version = atkbd->id; - atkbd->dev.event = atkbd_event; - atkbd->dev.private = atkbd; - atkbd->dev.dev = &atkbd->ps2dev.serio->dev; + input_dev->name = atkbd->name; + input_dev->phys = atkbd->phys; + input_dev->id.bustype =BUS_I8042 ; + input_dev->id.vendor =0x0001 ; + input_dev->id.product = atkbd->translated ?1 : atkbd->set; + input_dev->id.version = atkbd->id; + input_dev->event = atkbd_event; + input_dev->private = atkbd; + input_dev->cdev.dev = &atkbd->ps2dev.serio->dev; - atkbd->dev.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ) |BIT (EV_MSC ); + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REP ) |BIT (EV_MSC );if (atkbd->write) { - atkbd->dev.evbit[0 ] |=BIT (EV_LED ); - atkbd->dev.ledbit[0 ] =BIT (LED_NUML ) |BIT (LED_CAPSL ) |BIT (LED_SCROLLL ); + input_dev->evbit[0 ] |=BIT (EV_LED ); + input_dev->ledbit[0 ] =BIT (LED_NUML ) |BIT (LED_CAPSL ) |BIT (LED_SCROLLL ); }if (atkbd->extra) - atkbd->dev.ledbit[0 ] |=BIT (LED_COMPOSE ) |BIT (LED_SUSPEND ) | + input_dev->ledbit[0 ] |=BIT (LED_COMPOSE ) |BIT (LED_SUSPEND ) |BIT (LED_SLEEP ) |BIT (LED_MUTE ) |BIT (LED_MISC );if (!atkbd->softrepeat) { - atkbd->dev.rep[REP_DELAY ] =250 ; - atkbd->dev.rep[REP_PERIOD ] =33 ; + input_dev->rep[REP_DELAY ] =250 ; + input_dev->rep[REP_PERIOD ] =33 ; } - atkbd->dev.mscbit[0 ] = atkbd->softraw ?BIT (MSC_SCAN ) :BIT (MSC_RAW ) |BIT (MSC_SCAN ); + input_dev->mscbit[0 ] = atkbd->softraw ?BIT (MSC_SCAN ) :BIT (MSC_RAW ) |BIT (MSC_SCAN );if (atkbd->scroll) { - atkbd->dev.evbit[0 ] |=BIT (EV_REL ); - atkbd->dev.relbit[0 ] =BIT (REL_WHEEL ) |BIT (REL_HWHEEL ); -set_bit (BTN_MIDDLE , atkbd->dev.keybit); + input_dev->evbit[0 ] |=BIT (EV_REL ); + input_dev->relbit[0 ] =BIT (REL_WHEEL ) |BIT (REL_HWHEEL ); +set_bit (BTN_MIDDLE , input_dev->keybit); } - atkbd->dev.keycode = atkbd->keycode; - atkbd->dev.keycodesize =sizeof (unsigned char ); - atkbd->dev.keycodemax =ARRAY_SIZE (atkbd_set2_keycode); + input_dev->keycode = atkbd->keycode; + input_dev->keycodesize =sizeof (unsigned char ); + input_dev->keycodemax =ARRAY_SIZE (atkbd_set2_keycode);for (i =0 ; i <512 ; i++)if (atkbd->keycode[i] && atkbd->keycode[i] <ATKBD_SPECIAL ) -set_bit (atkbd->keycode[i], atkbd->dev.keybit); +set_bit (atkbd->keycode[i], input_dev->keybit); }/*
@@ -796,13 +800,15 @@ static void atkbd_set_device_attrs(strucstatic int atkbd_connect (struct serio *serio,struct serio_driver *drv) {struct atkbd *atkbd; -int err; - -if (!(atkbd =kmalloc (sizeof (struct atkbd ),GFP_KERNEL ))) -return -ENOMEM ; +struct input_dev *dev; +int err = -ENOMEM ; -memset (atkbd,0 ,sizeof (struct atkbd )); + atkbd =kzalloc (sizeof (struct atkbd ),GFP_KERNEL ); + dev =input_allocate_device (); +if (!atkbd || !dev) + goto fail; + atkbd->dev = dev;ps2_init (&atkbd->ps2dev, serio);switch (serio->id.type) {
@@ -828,19 +834,15 @@ static int atkbd_connect(struct serio *sserio_set_drvdata (serio, atkbd); err =serio_open (serio, drv); -if (err) { -serio_set_drvdata (serio,NULL ); -kfree (atkbd); -return err; - } +if (err) + goto fail;if (atkbd->write) {if (atkbd_probe (atkbd)) {serio_close (serio); -serio_set_drvdata (serio,NULL ); -kfree (atkbd); -return -ENODEV ; + err = -ENODEV ; + goto fail; } atkbd->set =atkbd_select_set (atkbd, atkbd_set, atkbd_extra);
@@ -851,19 +853,9 @@ static int atkbd_connect(struct serio *s atkbd->id =0xab00 ; } -if (atkbd->extra) -sprintf (atkbd->name,"AT Set 2 Extra keyboard" ); -else -sprintf (atkbd->name,"AT %s Set %d keyboard" , - atkbd->translated ?"Translated" :"Raw" , atkbd->set); - -sprintf (atkbd->phys,"%s/input0" , serio->phys); -atkbd_set_keycode_table (atkbd);atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); -device_create_file (&serio->dev, &atkbd_attr_extra);device_create_file (&serio->dev, &atkbd_attr_scroll);device_create_file (&serio->dev, &atkbd_attr_set);
@@ -872,9 +864,14 @@ static int atkbd_connect(struct serio *satkbd_enable (atkbd); -printk (KERN_INFO "input: %s on %s\n" , atkbd->name, serio->phys); +input_register_device (atkbd->dev);return 0 ; + + fail:serio_set_drvdata (serio,NULL ); +input_free_device (dev); +kfree (atkbd); +return err; }/*
@@ -896,9 +893,9 @@ static int atkbd_reconnect(struct serioatkbd_disable (atkbd);if (atkbd->write) { - param[0 ] = (test_bit (LED_SCROLLL , atkbd->dev.led) ?1 :0 ) - | (test_bit (LED_NUML , atkbd->dev.led) ?2 :0 ) - | (test_bit (LED_CAPSL , atkbd->dev.led) ?4 :0 ); + param[0 ] = (test_bit (LED_SCROLLL , atkbd->dev->led) ?1 :0 ) + | (test_bit (LED_NUML , atkbd->dev->led) ?2 :0 ) + | (test_bit (LED_CAPSL , atkbd->dev->led) ?4 :0 );if (atkbd_probe (atkbd))return -1 ;
@@ -1008,6 +1005,7 @@ static ssize_t atkbd_show_extra(struct astatic ssize_t atkbd_set_extra (struct atkbd *atkbd,const char *buf,size_t count) { +struct input_dev *new_dev;unsigned long value;char *rest;
@@ -1019,12 +1017,19 @@ static ssize_t atkbd_set_extra(struct atreturn -EINVAL ;if (atkbd->extra != value) { -/* unregister device as it's properties will change */ -input_unregister_device (&atkbd->dev); +/* +* Since device's properties will change we need to +* unregister old device. But allocate new one first +* to make sure we have it. +*/ +if (!(new_dev =input_allocate_device ())) +return -ENOMEM ; +input_unregister_device (atkbd->dev); + atkbd->dev = new_dev; atkbd->set =atkbd_select_set (atkbd, atkbd->set, value);atkbd_activate (atkbd);atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); +input_register_device (atkbd->dev); }return count; }
@@ -1036,6 +1041,7 @@ static ssize_t atkbd_show_scroll(structstatic ssize_t atkbd_set_scroll (struct atkbd *atkbd,const char *buf,size_t count) { +struct input_dev *new_dev;unsigned long value;char *rest;
@@ -1044,12 +1050,14 @@ static ssize_t atkbd_set_scroll(struct areturn -EINVAL ;if (atkbd->scroll != value) { -/* unregister device as it's properties will change */ -input_unregister_device (&atkbd->dev); +if (!(new_dev =input_allocate_device ())) +return -ENOMEM ; +input_unregister_device (atkbd->dev); + atkbd->dev = new_dev; atkbd->scroll = value;atkbd_set_keycode_table (atkbd);atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); +input_register_device (atkbd->dev); }return count; }
@@ -1061,6 +1069,7 @@ static ssize_t atkbd_show_set(struct atkstatic ssize_t atkbd_set_set (struct atkbd *atkbd,const char *buf,size_t count) { +struct input_dev *new_dev;unsigned long value;char *rest;
@@ -1072,13 +1081,15 @@ static ssize_t atkbd_set_set(struct atkbreturn -EINVAL ;if (atkbd->set != value) { -/* unregister device as it's properties will change */ -input_unregister_device (&atkbd->dev); +if (!(new_dev =input_allocate_device ())) +return -ENOMEM ; +input_unregister_device (atkbd->dev); + atkbd->dev = new_dev; atkbd->set =atkbd_select_set (atkbd, value, atkbd->extra);atkbd_activate (atkbd);atkbd_set_keycode_table (atkbd);atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); +input_register_device (atkbd->dev); }return count; }
@@ -1090,6 +1101,7 @@ static ssize_t atkbd_show_softrepeat(strstatic ssize_t atkbd_set_softrepeat (struct atkbd *atkbd,const char *buf,size_t count) { +struct input_dev *new_dev;unsigned long value;char *rest;
@@ -1101,15 +1113,16 @@ static ssize_t atkbd_set_softrepeat(strureturn -EINVAL ;if (atkbd->softrepeat != value) { -/* unregister device as it's properties will change */ -input_unregister_device (&atkbd->dev); +if (!(new_dev =input_allocate_device ())) +return -ENOMEM ; +input_unregister_device (atkbd->dev); + atkbd->dev = new_dev; atkbd->softrepeat = value;if (atkbd->softrepeat) atkbd->softraw =1 ;atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); +input_register_device (atkbd->dev); } -return count; }
@@ -1121,6 +1134,7 @@ static ssize_t atkbd_show_softraw(structstatic ssize_t atkbd_set_softraw (struct atkbd *atkbd,const char *buf,size_t count) { +struct input_dev *new_dev;unsigned long value;char *rest;
@@ -1129,11 +1143,13 @@ static ssize_t atkbd_set_softraw(structreturn -EINVAL ;if (atkbd->softraw != value) { -/* unregister device as it's properties will change */ -input_unregister_device (&atkbd->dev); +if (!(new_dev =input_allocate_device ())) +return -ENOMEM ; +input_unregister_device (atkbd->dev); + atkbd->dev = new_dev; atkbd->softraw = value;atkbd_set_device_attrs (atkbd); -input_register_device (&atkbd->dev); +input_register_device (atkbd->dev); }return count; }
drivers/input/keyboard/amikbd.c +29 -30
94 lines not on this page · raw message
drivers/input/keyboard/lkkbd.c +63 -63
212 lines not on this page · raw message
drivers/input/keyboard/corgikbd.c +39 -35
143 lines not on this page · raw message
drivers/input/keyboard/xtkbd.c +39 -43
121 lines not on this page · raw message
drivers/input/keyboard/newtonkbd.c +39 -44
125 lines not on this page · raw message
drivers/input/keyboard/sunkbd.c +62 -55
179 lines not on this page · raw message
drivers/input/keyboard/maple_keyb.c +33 -43
120 lines not on this page · raw message
drivers/input/keyboard/spitzkbd.c +44 -33
147 lines not on this page · raw message
PATCH 15/28 drivers/input/touchscreen: convert to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert drivers/input/touchscreen to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/input/touchscreen/corgi_ts.c | 93 +++++++++--------- drivers/input/touchscreen/elo.c | 89 ++++++++--------- drivers/input/touchscreen/gunze.c | 66 ++++++------ drivers/input/touchscreen/h3600_ts_input.c | 149 +++++++++++------------------ drivers/input/touchscreen/hp680_ts_input.c | 58 +++++------ drivers/input/touchscreen/mk712.c | 80 +++++++-------- drivers/input/touchscreen/mtouch.c | 64 ++++++------ 7 files changed, 285 insertions(+), 314 deletions(-)
drivers/input/touchscreen/gunze.c +33 -33
@@ -48,14 +48,12 @@ MODULE_LICENSE("GPL");#define GUNZE_MAX_LENGTH 10 -static char *gunze_name ="Gunze AHL-51S TouchScreen" ; -/* * Per-touchscreen data. */ struct gunze { -struct input_dev dev; +struct input_dev *dev;struct serio *serio;int idx;unsigned char data[GUNZE_MAX_LENGTH ];
@@ -64,7 +62,7 @@ struct gunze {static void gunze_process_packet (struct gunze * gunze,struct pt_regs *regs) { -struct input_dev *dev = &gunze->dev; +struct input_dev *dev = gunze->dev;if (gunze->idx !=GUNZE_MAX_LENGTH || gunze->data[5 ] !=',' || (gunze->data[0 ] !='T' && gunze->data[0 ] !='R' )) {
@@ -100,11 +98,13 @@ static irqreturn_t gunze_interrupt(strucstatic void gunze_disconnect (struct serio *serio) { -struct gunze * gunze =serio_get_drvdata (serio); +struct gunze *gunze =serio_get_drvdata (serio); -input_unregister_device (&gunze->dev); +input_get_device (gunze->dev); +input_unregister_device (gunze->dev);serio_close (serio);serio_set_drvdata (serio,NULL ); +input_put_device (gunze->dev);kfree (gunze); }
@@ -117,45 +117,45 @@ static void gunze_disconnect(struct seristatic int gunze_connect (struct serio *serio,struct serio_driver *drv) {struct gunze *gunze; +struct input_dev *input_dev;int err; -if (!(gunze =kmalloc (sizeof (struct gunze ),GFP_KERNEL ))) -return -ENOMEM ; - -memset (gunze,0 ,sizeof (struct gunze )); - -init_input_dev (&gunze->dev); - gunze->dev.evbit[0 ] =BIT (EV_KEY ) |BIT (EV_ABS ); - gunze->dev.keybit[LONG (BTN_TOUCH )] =BIT (BTN_TOUCH ); -input_set_abs_params (&gunze->dev,ABS_X ,24 ,1000 ,0 ,0 ); -input_set_abs_params (&gunze->dev,ABS_Y ,24 ,1000 ,0 ,0 ); + gunze =kzalloc (sizeof (struct gunze ),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!gunze || !input_dev) { + err = -ENOMEM ; + goto fail; + } gunze->serio = serio; - + gunze->dev = input_dev;sprintf (gunze->phys,"%s/input0" , serio->phys); - gunze->dev.private = gunze; - gunze->dev.name = gunze_name; - gunze->dev.phys = gunze->phys; - gunze->dev.id.bustype =BUS_RS232 ; - gunze->dev.id.vendor =SERIO_GUNZE ; - gunze->dev.id.product =0x0051 ; - gunze->dev.id.version =0x0100 ; + input_dev->private = gunze; + input_dev->name ="Gunze AHL-51S TouchScreen" ; + input_dev->phys = gunze->phys; + input_dev->id.bustype =BUS_RS232 ; + input_dev->id.vendor =SERIO_GUNZE ; + input_dev->id.product =0x0051 ; + input_dev->id.version =0x0100 ; + input_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_ABS ); + input_dev->keybit[LONG (BTN_TOUCH )] =BIT (BTN_TOUCH ); +input_set_abs_params (input_dev,ABS_X ,24 ,1000 ,0 ,0 ); +input_set_abs_params (input_dev,ABS_Y ,24 ,1000 ,0 ,0 );serio_set_drvdata (serio, gunze); err =serio_open (serio, drv); -if (err) { -serio_set_drvdata (serio,NULL ); -kfree (gunze); -return err; - } - -input_register_device (&gunze->dev); - -printk (KERN_INFO "input: %s on %s\n" , gunze_name, serio->phys); +if (err) + goto fail; +input_register_device (gunze->dev);return 0 ; + + fail:serio_set_drvdata (serio,NULL ); +input_free_device (input_dev); +kfree (gunze); +return err; }/*
drivers/input/touchscreen/mk712.c +41 -39
135 lines not on this page · raw message
drivers/input/touchscreen/h3600_ts_input.c +59 -90
230 lines not on this page · raw message
drivers/input/touchscreen/corgi_ts.c +47 -46
140 lines not on this page · raw message
drivers/input/touchscreen/elo.c +44 -45
167 lines not on this page · raw message
drivers/input/touchscreen/mtouch.c +32 -32
108 lines not on this page · raw message
drivers/input/touchscreen/hp680_ts_input.c +29 -29
87 lines not on this page · raw message
PATCH 17/28 Input: convert ucb1x00-ts to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert ucb1x00-ts to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/mfd/ucb1x00-ts.c | 45 +++++++++++++++++++++++++-------------------- 1 files changed, 25 insertions(+), 20 deletions(-)
drivers/mfd/ucb1x00-ts.c +25 -20
@@ -40,7 +40,7 @@struct ucb1x00_ts { -struct input_dev idev; +struct input_dev *idev;struct ucb1x00 *ucb;wait_queue_head_t irq_wait;
@@ -56,16 +56,16 @@ static int adcsync;static inline void ucb1x00_ts_evt_add (struct ucb1x00_ts *ts,u16 pressure,u16 x,u16 y) { -input_report_abs (&ts->idev,ABS_X , x); -input_report_abs (&ts->idev,ABS_Y , y); -input_report_abs (&ts->idev,ABS_PRESSURE , pressure); -input_sync (&ts->idev); +input_report_abs (ts->idev,ABS_X , x); +input_report_abs (ts->idev,ABS_Y , y); +input_report_abs (ts->idev,ABS_PRESSURE , pressure); +input_sync (ts->idev); }static inline void ucb1x00_ts_event_release (struct ucb1x00_ts *ts) { -input_report_abs (&ts->idev,ABS_PRESSURE ,0 ); -input_sync (&ts->idev); +input_report_abs (ts->idev,ABS_PRESSURE ,0 ); +input_sync (ts->idev); }/*
@@ -341,26 +341,30 @@ static int ucb1x00_ts_add(struct ucb1x00 {struct ucb1x00_ts *ts; - ts =kmalloc (sizeof (struct ucb1x00_ts ),GFP_KERNEL ); + ts =kzalloc (sizeof (struct ucb1x00_ts ),GFP_KERNEL );if (!ts)return -ENOMEM ; -memset (ts,0 ,sizeof (struct ucb1x00_ts )); + ts->idev =input_allocate_device (); +if (!ts->idev) { +kfree (ts); +return -ENOMEM ; + } ts->ucb = dev->ucb; ts->adcsync = adcsync ?UCB_SYNC :UCB_NOSYNC ; - ts->idev.name ="Touchscreen panel" ; - ts->idev.id.product = ts->ucb->id; - ts->idev.open = ucb1x00_ts_open; - ts->idev.close = ucb1x00_ts_close; - -__set_bit (EV_ABS , ts->idev.evbit); -__set_bit (ABS_X , ts->idev.absbit); -__set_bit (ABS_Y , ts->idev.absbit); -__set_bit (ABS_PRESSURE , ts->idev.absbit); + ts->idev->name ="Touchscreen panel" ; + ts->idev->id.product = ts->ucb->id; + ts->idev->open = ucb1x00_ts_open; + ts->idev->close = ucb1x00_ts_close; + +__set_bit (EV_ABS , ts->idev->evbit); +__set_bit (ABS_X , ts->idev->absbit); +__set_bit (ABS_Y , ts->idev->absbit); +__set_bit (ABS_PRESSURE , ts->idev->absbit); -input_register_device (&ts->idev); +input_register_device (ts->idev); dev->priv = ts;
@@ -370,7 +374,8 @@ static int ucb1x00_ts_add(struct ucb1x00static void ucb1x00_ts_remove (struct ucb1x00_dev *dev) {struct ucb1x00_ts *ts = dev->priv; -input_unregister_device (&ts->idev); + +input_unregister_device (ts->idev);kfree (ts); }
PATCH 18/28 Input: convert sound/ppc/beep to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert sound/ppc/beep to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
sound/ppc/beep.c | 68 ++++++++++++++++++++++++++++++------------------------- 1 files changed, 38 insertions(+), 30 deletions(-)
sound/ppc/beep.c +38 -30
@@ -31,14 +31,14 @@#include "pmac.h" struct snd_pmac_beep { -int running;/* boolean */ -int volume;/* mixer volume: 0-100 */ +int running;/* boolean */ +int volume;/* mixer volume: 0-100 */ int volume_play;/* currently playing volume */ int hz;int nsamples;short *buf;/* allocated wave buffer */ dma_addr_t addr;/* physical address of buffer */ -struct input_dev dev; +struct input_dev *dev; };/*
@@ -212,47 +212,55 @@ static snd_kcontrol_new_t snd_pmac_beep_int __init snd_pmac_attach_beep (pmac_t *chip) {pmac_beep_t *beep; -int err; - - beep =kmalloc (sizeof (*beep),GFP_KERNEL ); -if (! beep) -return -ENOMEM ; - -memset (beep,0 ,sizeof (*beep)); - beep->buf =dma_alloc_coherent (&chip->pdev->dev,BEEP_BUFLEN *4 , - &beep->addr,GFP_KERNEL ); - - beep->dev.evbit[0 ] =BIT (EV_SND ); - beep->dev.sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); - beep->dev.event = snd_pmac_beep_event; - beep->dev.private = chip; +struct input_dev *input_dev; +void *dmabuf; +int err = -ENOMEM ; + + beep =kzalloc (sizeof (*beep),GFP_KERNEL ); + dmabuf =dma_alloc_coherent (&chip->pdev->dev,BEEP_BUFLEN *4 , + &beep->addr,GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!beep || !dmabuf || !input_dev) + goto fail;/* FIXME: set more better values */ - beep->dev.name ="PowerMac Beep" ; - beep->dev.phys ="powermac/beep" ; - beep->dev.id.bustype =BUS_ADB ; - beep->dev.id.vendor =0x001f ; - beep->dev.id.product =0x0001 ; - beep->dev.id.version =0x0100 ; + input_dev->name ="PowerMac Beep" ; + input_dev->phys ="powermac/beep" ; + input_dev->id.bustype =BUS_ADB ; + input_dev->id.vendor =0x001f ; + input_dev->id.product =0x0001 ; + input_dev->id.version =0x0100 ; + + input_dev->evbit[0 ] =BIT (EV_SND ); + input_dev->sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); + input_dev->event = snd_pmac_beep_event; + input_dev->private = chip; + input_dev->cdev.dev = &chip->pdev->dev; + beep->dev = input_dev; + beep->buf = dmabuf; beep->volume =BEEP_VOLUME ; beep->running =0 ; -if ((err =snd_ctl_add (chip->card,snd_ctl_new1 (&snd_pmac_beep_mixer, chip))) <0 ) { -kfree (beep->buf); -kfree (beep); -return err; - } + + err =snd_ctl_add (chip->card,snd_ctl_new1 (&snd_pmac_beep_mixer, chip)); +if (err <0 ) + goto fail; chip->beep = beep; -input_register_device (&beep->dev); +input_register_device (beep->dev);return 0 ; + + fail:input_free_device (input_dev); +kfree (dmabuf); +kfree (beep); +return err; }void snd_pmac_detach_beep (pmac_t *chip) {if (chip->beep) { -input_unregister_device (&chip->beep->dev); +input_unregister_device (chip->beep->dev);dma_free_coherent (&chip->pdev->dev,BEEP_BUFLEN *4 , chip->beep->buf, chip->beep->addr);kfree (chip->beep);
PATCH 19/28 Input: convert sonypi to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert sonypi to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/char/sonypi.c | 92 ++++++++++++++++++++++++++++---------------------- 1 files changed, 53 insertions(+), 39 deletions(-)
drivers/char/sonypi.c +53 -39
@@ -424,10 +424,6 @@ static struct sonypi_eventtypes {#define SONYPI_BUF_SIZE 128 -/* The name of the devices for the input device drivers */ -#define SONYPI_JOG_INPUTNAME "Sony Vaio Jogdial" -#define SONYPI_KEY_INPUTNAME "Sony Vaio Keys" -/* Correspondance table between sonypi events and input layer events */ static struct { int sonypiev;
@@ -490,8 +486,8 @@ static struct sonypi_device {struct fasync_struct *fifo_async;int open_count;int model; -struct input_dev input_jog_dev; -struct input_dev input_key_dev; +struct input_dev *input_jog_dev; +struct input_dev *input_key_dev;struct work_struct input_work;struct kfifo *input_fifo;spinlock_t input_fifo_lock;
@@ -779,8 +775,8 @@ static void input_keyrelease(void *data)static void sonypi_report_input_event (u8 event) { -struct input_dev *jog_dev = &sonypi_device.input_jog_dev; -struct input_dev *key_dev = &sonypi_device.input_key_dev; +struct input_dev *jog_dev = sonypi_device.input_jog_dev; +struct input_dev *key_dev = sonypi_device.input_key_dev;struct sonypi_keypress kp = {NULL };int i;
@@ -1203,6 +1199,47 @@ static struct device_driver sonypi_drive .shutdown = sonypi_shutdown, }; +static int __devinit sonypi_create_input_devices (void ) +{ +struct input_dev *jog_dev; +struct input_dev *key_dev; +int i; + + sonypi_device.input_jog_dev = jog_dev =input_allocate_device (); +if (!jog_dev) +return -ENOMEM ; + + jog_dev->name ="Sony Vaio Jogdial" ; + jog_dev->id.bustype =BUS_ISA ; + jog_dev->id.vendor =PCI_VENDOR_ID_SONY ; + + jog_dev->evbit[0 ] =BIT (EV_KEY ) |BIT (EV_REL ); + jog_dev->keybit[LONG (BTN_MOUSE )] =BIT (BTN_MIDDLE ); + jog_dev->relbit[0 ] =BIT (REL_WHEEL ); + + sonypi_device.input_key_dev = key_dev =input_allocate_device (); +if (!key_dev) { +input_free_device (jog_dev); + sonypi_device.input_jog_dev =NULL ; +return -ENOMEM ; + } + + key_dev->name ="Sony Vaio Keys" ; + key_dev->id.bustype =BUS_ISA ; + key_dev->id.vendor =PCI_VENDOR_ID_SONY ; + +/* Initialize the Input Drivers: special keys */ + key_dev->evbit[0 ] =BIT (EV_KEY ); +for (i =0 ; sonypi_inputkeys[i].sonypiev; i++) +if (sonypi_inputkeys[i].inputev) +set_bit (sonypi_inputkeys[i].inputev, key_dev->keybit); + +input_register_device (jog_dev); +input_register_device (key_dev); + +return 0 ; +} +static int __devinit sonypi_probe (void ) {int i, ret;
@@ -1298,34 +1335,10 @@ static int __devinit sonypi_probe(void) }if (useinput) { -/* Initialize the Input Drivers: jogdial */ -int i; - sonypi_device.input_jog_dev.evbit[0 ] = -BIT (EV_KEY ) |BIT (EV_REL ); - sonypi_device.input_jog_dev.keybit[LONG (BTN_MOUSE )] = -BIT (BTN_MIDDLE ); - sonypi_device.input_jog_dev.relbit[0 ] =BIT (REL_WHEEL ); - sonypi_device.input_jog_dev.name =SONYPI_JOG_INPUTNAME ; - sonypi_device.input_jog_dev.id.bustype =BUS_ISA ; - sonypi_device.input_jog_dev.id.vendor =PCI_VENDOR_ID_SONY ; - -input_register_device (&sonypi_device.input_jog_dev); -printk (KERN_INFO "%s input method installed.\n" , - sonypi_device.input_jog_dev.name); -/* Initialize the Input Drivers: special keys */ - sonypi_device.input_key_dev.evbit[0 ] =BIT (EV_KEY ); -for (i =0 ; sonypi_inputkeys[i].sonypiev; i++) -if (sonypi_inputkeys[i].inputev) -set_bit (sonypi_inputkeys[i].inputev, - sonypi_device.input_key_dev.keybit); - sonypi_device.input_key_dev.name =SONYPI_KEY_INPUTNAME ; - sonypi_device.input_key_dev.id.bustype =BUS_ISA ; - sonypi_device.input_key_dev.id.vendor =PCI_VENDOR_ID_SONY ; - -input_register_device (&sonypi_device.input_key_dev); -printk (KERN_INFO "%s input method installed.\n" , - sonypi_device.input_key_dev.name); + ret =sonypi_create_input_devices (); +if (ret) + goto out_inputdevices;spin_lock_init (&sonypi_device.input_fifo_lock); sonypi_device.input_fifo =
@@ -1375,8 +1388,9 @@ static int __devinit sonypi_probe(void) out_platformdev:kfifo_free (sonypi_device.input_fifo); out_infifo: -input_unregister_device (&sonypi_device.input_key_dev); -input_unregister_device (&sonypi_device.input_jog_dev); +input_unregister_device (sonypi_device.input_key_dev); +input_unregister_device (sonypi_device.input_jog_dev); +out_inputdevices:free_irq (sonypi_device.irq, sonypi_irq); out_reqirq:release_region (sonypi_device.ioport1, sonypi_device.region_size);
@@ -1402,8 +1416,8 @@ static void __devexit sonypi_remove(voidplatform_device_unregister (sonypi_device.pdev);if (useinput) { -input_unregister_device (&sonypi_device.input_key_dev); -input_unregister_device (&sonypi_device.input_jog_dev); +input_unregister_device (sonypi_device.input_key_dev); +input_unregister_device (sonypi_device.input_jog_dev);kfifo_free (sonypi_device.input_fifo); }
PATCH 20/28 Input: convert driver/input/misc to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert driver/input/misc to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/input/misc/m68kspkr.c | 40 ++++++++++++++++++------------------ drivers/input/misc/pcspkr.c | 34 +++++++++++++++--------------- drivers/input/misc/sparcspkr.c | 45 ++++++++++++++++++++--------------------- 3 files changed, 59 insertions(+), 60 deletions(-)
drivers/input/misc/m68kspkr.c +20 -20
@@ -24,9 +24,7 @@ MODULE_AUTHOR("Richard Zidlicky <rz@linuMODULE_DESCRIPTION ("m68k beeper driver" );MODULE_LICENSE ("GPL" ); -static char m68kspkr_name[] ="m68k beeper" ; -static char m68kspkr_phys[] ="m68k/generic" ; -static struct input_dev m68kspkr_dev; +static struct input_dev *m68kspkr_dev;static int m68kspkr_event (struct input_dev *dev,unsigned int type,unsigned int code,int value) {
@@ -51,32 +49,34 @@ static int m68kspkr_event(struct input_dstatic int __init m68kspkr_init (void ) { -if (!mach_beep){ -printk ("%s: no lowlevel beep support\n" , m68kspkr_name); -return -1 ; +if (!mach_beep) { +printk (KERN_INFO "m68kspkr: no lowlevel beep support\n" ); +return -ENODEV ; } - m68kspkr_dev.evbit[0 ] =BIT (EV_SND ); - m68kspkr_dev.sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); - m68kspkr_dev.event = m68kspkr_event; - - m68kspkr_dev.name = m68kspkr_name; - m68kspkr_dev.phys = m68kspkr_phys; - m68kspkr_dev.id.bustype =BUS_HOST ; - m68kspkr_dev.id.vendor =0x001f ; - m68kspkr_dev.id.product =0x0001 ; - m68kspkr_dev.id.version =0x0100 ; - -input_register_device (&m68kspkr_dev); + m68kspkr_dev =input_allocate_device (); +if (!m68kspkr_dev) +return -ENOMEM ; + + m68kspkr_dev->name ="m68k beeper" ; + m68kspkr_dev->phys ="m68k/generic" ; + m68kspkr_dev->id.bustype =BUS_HOST ; + m68kspkr_dev->id.vendor =0x001f ; + m68kspkr_dev->id.product =0x0001 ; + m68kspkr_dev->id.version =0x0100 ; + + m68kspkr_dev->evbit[0 ] =BIT (EV_SND ); + m68kspkr_dev->sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); + m68kspkr_dev->event = m68kspkr_event; -printk (KERN_INFO "input: %s\n" , m68kspkr_name); +input_register_device (m68kspkr_dev);return 0 ; } static void __exit m68kspkr_exit(void) { -input_unregister_device (&m68kspkr_dev); +input_unregister_device (m68kspkr_dev); }module_init (m68kspkr_init);
drivers/input/misc/pcspkr.c +17 -17
@@ -23,9 +23,7 @@ MODULE_AUTHOR("Vojtech Pavlik <vojtech@uMODULE_DESCRIPTION ("PC Speaker beeper driver" );MODULE_LICENSE ("GPL" ); -static char pcspkr_name[] ="PC Speaker" ; -static char pcspkr_phys[] ="isa0061/input0" ; -static struct input_dev pcspkr_dev; +static struct input_dev *pcspkr_dev;static DEFINE_SPINLOCK (i8253_beep_lock);
@@ -68,27 +66,29 @@ static int pcspkr_event(struct input_devstatic int __init pcspkr_init (void ) { - pcspkr_dev.evbit[0 ] =BIT (EV_SND ); - pcspkr_dev.sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); - pcspkr_dev.event = pcspkr_event; - - pcspkr_dev.name = pcspkr_name; - pcspkr_dev.phys = pcspkr_phys; - pcspkr_dev.id.bustype =BUS_ISA ; - pcspkr_dev.id.vendor =0x001f ; - pcspkr_dev.id.product =0x0001 ; - pcspkr_dev.id.version =0x0100 ; + pcspkr_dev =input_allocate_device (); +if (!pcspkr_dev) +return -ENOMEM ; + + pcspkr_dev->name ="PC Speaker" ; + pcspkr_dev->name ="isa0061/input0" ; + pcspkr_dev->id.bustype =BUS_ISA ; + pcspkr_dev->id.vendor =0x001f ; + pcspkr_dev->id.product =0x0001 ; + pcspkr_dev->id.version =0x0100 ; + + pcspkr_dev->evbit[0 ] =BIT (EV_SND ); + pcspkr_dev->sndbit[0 ] =BIT (SND_BELL ) |BIT (SND_TONE ); + pcspkr_dev->event = pcspkr_event; -input_register_device (&pcspkr_dev); - -printk (KERN_INFO "input: %s\n" , pcspkr_name); +input_register_device (pcspkr_dev);return 0 ; } static void __exit pcspkr_exit(void) { -input_unregister_device (&pcspkr_dev); +input_unregister_device (pcspkr_dev);/* turn off the speaker */ pcspkr_event (NULL ,EV_SND ,SND_BELL ,0 ); }
drivers/input/misc/sparcspkr.c +22 -23
86 lines not on this page · raw message
PATCH 22/28 drivers/media: convert to dynamic input_dev allocation
In reply to Dmitry TorokhovInput: convert drivers/media to dynamic input_dev allocation
This is required for input_dev sysfs integration
---
drivers/media/common/ir-common.c | 1 drivers/media/dvb/cinergyT2/cinergyT2.c | 108 ++++++++++++++++++---------- drivers/media/dvb/dvb-usb/dvb-usb-remote.c | 50 +++++++----- drivers/media/dvb/dvb-usb/dvb-usb.h | 3 drivers/media/dvb/ttpci/av7110_ir.c | 37 +++++---- drivers/media/dvb/ttpci/budget-ci.c | 24 +++--- drivers/media/dvb/ttusb-dec/ttusb_dec.c | 51 ++++++++----- drivers/media/video/bttvp.h | 2 drivers/media/video/cx88/cx88-input.c | 58 ++++++++------- drivers/media/video/ir-kbd-gpio.c | 52 +++++++------ drivers/media/video/ir-kbd-i2c.c | 33 ++++---- drivers/media/video/saa7134/saa7134-input.c | 39 +++++----- drivers/media/video/saa7134/saa7134.h | 2 13 files changed, 268 insertions(+), 192 deletions(-)
drivers/media/video/ir-kbd-i2c.c +19 -14
@@ -121,10 +121,9 @@ static IR_KEYTAB_TYPE ir_codes_purpletv[ }; -struct IR ;struct IR {struct i2c_client c; -struct input_dev input; +struct input_dev *input;struct ir_input_state ir;struct work_struct work;
@@ -271,9 +270,9 @@ static void ir_key_poll(struct IR *ir) }if (0 == rc) { -ir_input_nokey (&ir->input,&ir->ir); +ir_input_nokey (ir->input, &ir->ir); }else { -ir_input_keydown (&ir->input,&ir->ir, ir_key, ir_raw); +ir_input_keydown (ir->input, &ir->ir, ir_key, ir_raw); } }
@@ -318,11 +317,18 @@ static int ir_attach(struct i2c_adapterchar *name;int ir_type;struct IR *ir; +struct input_dev *input_dev; -if (NULL == (ir =kmalloc (sizeof (struct IR ),GFP_KERNEL ))) + ir =kzalloc (sizeof (struct IR ),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!ir || !input_dev) { +kfree (ir); +input_free_device (input_dev);return -ENOMEM ; -memset (ir,0 ,sizeof (*ir)); + } + ir->c = client_template; + ir->input = input_dev;i2c_set_clientdata (&ir->c, ir); ir->c.adapter = adap;
@@ -375,13 +381,12 @@ static int ir_attach(struct i2c_adapter ir->c.dev.bus_id);/* init + register input device */ -ir_input_init (&ir->input,&ir->ir,ir_type,ir_codes); - ir->input.id.bustype =BUS_I2C ; - ir->input.name = ir->c.name; - ir->input.phys = ir->phys; -input_register_device (&ir->input); -printk (DEVNAME ": %s detected at %s [%s]\n" , - ir->input.name,ir->input.phys,adap->name); +ir_input_init (input_dev, &ir->ir, ir_type, ir_codes); + input_dev->id.bustype =BUS_I2C ; + input_dev->name = ir->c.name; + input_dev->phys = ir->phys; + +input_register_device (ir->input);/* start polling via eventd */ INIT_WORK (&ir->work, ir_work, ir);
@@ -402,7 +407,7 @@ static int ir_detach(struct i2c_client *flush_scheduled_work ();/* unregister devices */ -input_unregister_device (&ir->input); +input_unregister_device (ir->input);i2c_detach_client (&ir->c);/* free memory */
drivers/media/video/ir-kbd-gpio.c +28 -24
112 lines not on this page · raw message
drivers/media/video/saa7134/saa7134.h +1 -1
@@ -351,7 +351,7 @@ struct saa7134_oss {/* IR input */ struct saa7134_ir { -struct input_dev dev; +struct input_dev *dev;struct ir_input_state ir;char name[32 ];char phys[32 ];
drivers/media/video/saa7134/saa7134-input.c +21 -18
@@ -425,9 +425,9 @@ static int build_key(struct saa7134_devif ((ir->mask_keydown && (0 != (gpio & ir->mask_keydown))) || (ir->mask_keyup && (0 == (gpio & ir->mask_keyup)))) { -ir_input_keydown (&ir->dev,&ir->ir,data,data); +ir_input_keydown (ir->dev, &ir->ir, data, data); }else { -ir_input_nokey (&ir->dev,&ir->ir); +ir_input_nokey (ir->dev, &ir->ir); }return 0 ; }
@@ -456,6 +456,7 @@ static void saa7134_input_timer(unsignedint saa7134_input_init1 (struct saa7134_dev *dev) {struct saa7134_ir *ir; +struct input_dev *input_dev;IR_KEYTAB_TYPE *ir_codes =NULL ;u32 mask_keycode =0 ;u32 mask_keydown =0 ;
@@ -535,10 +536,13 @@ int saa7134_input_init1(struct saa7134_dreturn -ENODEV ; } - ir =kmalloc (sizeof (*ir),GFP_KERNEL ); -if (NULL == ir) + ir =kzalloc (sizeof (*ir),GFP_KERNEL ); + input_dev =input_allocate_device (); +if (!ir || !input_dev) { +kfree (ir); +input_free_device (input_dev);return -ENOMEM ; -memset (ir,0 ,sizeof (*ir)); + }/* init hardware-specific stuff */ ir->mask_keycode = mask_keycode;
@@ -552,19 +556,19 @@ int saa7134_input_init1(struct saa7134_dsnprintf (ir->phys,sizeof (ir->phys),"pci-%s/ir0" ,pci_name (dev->pci)); -ir_input_init (&ir->dev, &ir->ir, ir_type, ir_codes); - ir->dev.name = ir->name; - ir->dev.phys = ir->phys; - ir->dev.id.bustype =BUS_PCI ; - ir->dev.id.version =1 ; +ir_input_init (input_dev, &ir->ir, ir_type, ir_codes); + input_dev->name = ir->name; + input_dev->phys = ir->phys; + input_dev->id.bustype =BUS_PCI ; + input_dev->id.version =1 ;if (dev->pci->subsystem_vendor) { - ir->dev.id.vendor = dev->pci->subsystem_vendor; - ir->dev.id.product = dev->pci->subsystem_device; + input_dev->id.vendor = dev->pci->subsystem_vendor; + input_dev->id.product = dev->pci->subsystem_device; }else { - ir->dev.id.vendor = dev->pci->vendor; - ir->dev.id.product = dev->pci->device; + input_dev->id.vendor = dev->pci->vendor; + input_dev->id.product = dev->pci->device; } - ir->dev.dev = &dev->pci->dev; + input_dev->cdev.dev = &dev->pci->dev;/* all done */ dev->remote = ir;
@@ -576,8 +580,7 @@ int saa7134_input_init1(struct saa7134_dadd_timer (&ir->timer); } -input_register_device (&dev->remote->dev); -printk ("%s: registered input device for IR\n" ,dev->name); +input_register_device (ir->dev);return 0 ; }
@@ -586,9 +589,9 @@ void saa7134_input_fini(struct saa7134_dif (NULL == dev->remote)return ; -input_unregister_device (&dev->remote->dev);if (dev->remote->polling)del_timer_sync (&dev->remote->timer); +input_unregister_device (dev->remote->dev);kfree (dev->remote); dev->remote =NULL ; }
drivers/media/video/bttvp.h +1 -1
@@ -240,7 +240,7 @@ struct bttv_pll_info {/* for gpio-connected remote control */ struct bttv_input { -struct input_dev dev; +struct input_dev *dev;struct ir_input_state ir;char name[32 ];char phys[32 ];
drivers/media/dvb/ttpci/budget-ci.c +13 -11
@@ -64,7 +64,7 @@struct budget_ci {struct budget budget; -struct input_dev input_dev; +struct input_dev *input_dev;struct tasklet_struct msp430_irq_tasklet;struct tasklet_struct ciintf_irq_tasklet;int slot_status;
@@ -145,7 +145,7 @@ static void msp430_ir_debounce(unsignedstatic void msp430_ir_interrupt (unsigned long data) {struct budget_ci *budget_ci = (struct budget_ci *) data; -struct input_dev *dev = &budget_ci->input_dev; +struct input_dev *dev = budget_ci->input_dev;unsigned int code =ttpci_budget_debiread (&budget_ci->budget,DEBINOSWAP ,DEBIADDR_IR ,2 ,1 ,0 ) >>8 ;
@@ -181,25 +181,27 @@ static void msp430_ir_interrupt(unsignedstatic int msp430_ir_init (struct budget_ci *budget_ci) {struct saa7146_dev *saa = budget_ci->budget.dev; +struct input_dev *input_dev;int i; -memset (&budget_ci->input_dev,0 ,sizeof (struct input_dev )); + budget_ci->input_dev = input_dev =input_allocate_device (); +if (!input_dev) +return -ENOMEM ;sprintf (budget_ci->ir_dev_name,"Budget-CI dvb ir receiver %s" , saa->name); - budget_ci->input_dev.name = budget_ci->ir_dev_name; -set_bit (EV_KEY , budget_ci->input_dev.evbit); + input_dev->name = budget_ci->ir_dev_name; -for (i =0 ; i <sizeof (key_map) /sizeof (*key_map); i++) +set_bit (EV_KEY , input_dev->evbit); +for (i =0 ; i <ARRAY_SIZE (key_map); i++)if (key_map[i]) -set_bit (key_map[i], budget_ci->input_dev.keybit); +set_bit (key_map[i], input_dev->keybit); -input_register_device (&budget_ci->input_dev); +input_register_device (budget_ci->input_dev); - budget_ci->input_dev.timer.function = msp430_ir_debounce; + input_dev->timer.function = msp430_ir_debounce;saa7146_write (saa,IER ,saa7146_read (saa,IER ) |MASK_06 ); -saa7146_setgpio (saa,3 ,SAA7146_GPIO_IRQHI );return 0 ;
@@ -208,7 +210,7 @@ static int msp430_ir_init(struct budget_static void msp430_ir_deinit (struct budget_ci *budget_ci) {struct saa7146_dev *saa = budget_ci->budget.dev; -struct input_dev *dev = &budget_ci->input_dev; +struct input_dev *dev = budget_ci->input_dev;saa7146_write (saa,IER ,saa7146_read (saa,IER ) & ~MASK_06 );saa7146_setgpio (saa,3 ,SAA7146_GPIO_INPUT );
drivers/media/dvb/cinergyT2/cinergyT2.c +70 -38
183 lines not on this page · raw message
drivers/media/common/ir-common.c +0 -1
@@ -252,7 +252,6 @@ void ir_input_init(struct input_dev *devif (ir_codes)memcpy (ir->ir_codes, ir_codes,sizeof (ir->ir_codes)); -init_input_dev (dev); dev->keycode = ir->ir_codes; dev->keycodesize =sizeof (IR_KEYTAB_TYPE ); dev->keycodemax =IR_KEYTAB_SIZE ;
drivers/media/dvb/dvb-usb/dvb-usb-remote.c +28 -22
106 lines not on this page · raw message
drivers/media/dvb/dvb-usb/dvb-usb.h +2 -1
@@ -300,7 +300,8 @@ struct dvb_usb_device {int (*fe_init) (struct dvb_frontend *);/* remote control */ -struct input_dev rc_input_dev; +struct input_dev *rc_input_dev; +char rc_phys[64 ];struct work_struct rc_query_work;u32 last_event;int last_state;
drivers/media/dvb/ttpci/av7110_ir.c +21 -16
@@ -15,7 +15,7 @@static int av_cnt;static struct av7110 *av_list[4 ]; -static struct input_dev input_dev; +static struct input_dev *input_dev;static u16 key_map [256 ] = {KEY_0 ,KEY_1 ,KEY_2 ,KEY_3 ,KEY_4 ,KEY_5 ,KEY_6 ,KEY_7 ,
@@ -43,10 +43,10 @@ static u16 key_map [256] = {static void av7110_emit_keyup (unsigned long data) { -if (!data || !test_bit (data, input_dev.key)) +if (!data || !test_bit (data, input_dev->key))return ; -input_event (&input_dev,EV_KEY , data, !!0 ); +input_event (input_dev,EV_KEY , data, !!0 ); }
@@ -112,13 +112,13 @@ static void av7110_emit_key(unsigned lonif (timer_pending (&keyup_timer)) {del_timer (&keyup_timer);if (keyup_timer.data != keycode || new_toggle != old_toggle) { -input_event (&input_dev,EV_KEY , keyup_timer.data, !!0 ); -input_event (&input_dev,EV_KEY , keycode, !0 ); +input_event (input_dev,EV_KEY , keyup_timer.data, !!0 ); +input_event (input_dev,EV_KEY , keycode, !0 ); }else -input_event (&input_dev,EV_KEY , keycode,2 ); +input_event (input_dev,EV_KEY , keycode,2 ); }else -input_event (&input_dev,EV_KEY , keycode, !0 ); +input_event (input_dev,EV_KEY , keycode, !0 ); keyup_timer.expires = jiffies +UP_TIMEOUT ; keyup_timer.data = keycode;
@@ -132,13 +132,13 @@ static void input_register_keys(void) {int i; -memset (input_dev.keybit,0 ,sizeof (input_dev.keybit)); +memset (input_dev->keybit,0 ,sizeof (input_dev->keybit)); -for (i =0 ; i <sizeof (key_map) /sizeof (key_map[0 ]); i++) { +for (i =0 ; i <ARRAY_SIZE (key_map); i++) {if (key_map[i] >KEY_MAX ) key_map[i] =0 ;else if (key_map[i] >KEY_RESERVED ) -set_bit (key_map[i], input_dev.keybit); +set_bit (key_map[i], input_dev->keybit); } }
@@ -216,12 +216,17 @@ int __init av7110_ir_init(struct av7110init_timer (&keyup_timer); keyup_timer.data =0 ; - input_dev.name ="DVB on-card IR receiver" ; -set_bit (EV_KEY , input_dev.evbit); -set_bit (EV_REP , input_dev.evbit); + input_dev =input_allocate_device (); +if (!input_dev) +return -ENOMEM ; + + input_dev->name ="DVB on-card IR receiver" ; + +set_bit (EV_KEY , input_dev->evbit); +set_bit (EV_REP , input_dev->evbit);input_register_keys (); -input_register_device (&input_dev); - input_dev.timer.function = input_repeat_key; +input_register_device (input_dev); + input_dev->timer.function = input_repeat_key; e =create_proc_entry ("av7110_ir" ,S_IFREG |S_IRUGO |S_IWUSR ,NULL );if (e) {
@@ -256,7 +261,7 @@ void __exit av7110_ir_exit(struct av7110if (av_cnt ==1 ) {del_timer_sync (&keyup_timer);remove_proc_entry ("av7110_ir" ,NULL ); -input_unregister_device (&input_dev); +input_unregister_device (input_dev); } av_cnt--;
drivers/media/dvb/ttusb-dec/ttusb_dec.c +32 -19
98 lines not on this page · raw message
drivers/media/video/cx88/cx88-input.c +32 -26
136 lines not on this page · raw message
PATCH 23/28 Input: show sysfs path in /proc/bus/input/devices
In reply to Dmitry TorokhovInput: show sysfs path in /proc/bus/input/devices
Show that sysfs and phys path are different objects.
---
drivers/input/input.c | 6 ++++++ 1 files changed, 6 insertions(+)
drivers/input/input.c +6 -0
@@ -474,17 +474,21 @@ static int input_devices_read(char *buf, {struct input_dev *dev;struct input_handle *handle; +const char *path;off_t at =0 ;int i, len, cnt =0 ;list_for_each_entry (dev, &input_dev_list, node) { + path = dev->dynalloc ?kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ) :NULL ; + len =sprintf (buf,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); len +=sprintf (buf + len,"N: Name=\"%s\"\n" , dev->name ? dev->name :"" ); len +=sprintf (buf + len,"P: Phys=%s\n" , dev->phys ? dev->phys :"" ); + len +=sprintf (buf + len,"S: Sysfs=%s\n" , path ? path :"" ); len +=sprintf (buf + len,"H: Handlers=" );list_for_each_entry (handle, &dev->h_list, d_node)
@@ -515,6 +519,8 @@ static int input_devices_read(char *buf,if (cnt >= count)break ; } + +kfree (path); }if (&dev->node == &input_dev_list)
PATCH 24/28 Input: export input_dev data via sysfs attributes
In reply to Dmitry TorokhovInput: export various input device attributes via sysfs
The following structure is exported:
input0/
|-- name
|-- phys
|-- uniq
|-- id/{bustype|vendor|product|version}
`-- capabilities/{ev|abs|rel|key|led|msc|ff|sw}---
drivers/input/input.c | 157 ++++++++++++++++++++++++++++++++++++++++++-------- 1 files changed, 134 insertions(+), 23 deletions(-)
drivers/input/input.c +134 -23
@@ -308,6 +308,7 @@ static struct input_device_id *input_matMATCH_BIT (ledbit,LED_MAX );MATCH_BIT (sndbit,SND_MAX );MATCH_BIT (ffbit,FF_MAX ); +MATCH_BIT (swbit,SW_MAX );return id; }
@@ -433,6 +434,23 @@ static void input_call_hotplug(char *ver#endif +static int input_print_bitmap (char *buf,unsigned long *bitmap,int max) +{ +int i; +int len =0 ; + +for (i =NBITS (max) -1 ; i >0 ; i--) +if (bitmap[i]) +break ; + +for (; i >=0 ; i--) + len +=sprintf (buf + len,"%lx%s" , bitmap[i], i >0 ?" " :"" ); + + len +=sprintf (buf + len,"\n" ); + +return len; +} +#ifdef CONFIG_PROC_FS static struct proc_dir_entry *proc_bus_input_dir;
@@ -454,20 +472,17 @@ static unsigned int input_devices_poll(sreturn 0 ; } -#define SPRINTF_BIT_B (bit, name, max) \ - do { \ - len += sprintf(buf + len, "B: %s", name); \ - for (i = NBITS(max) - 1; i >= 0; i--) \ - if (dev->bit[i]) break; \ - for (; i >= 0; i--) \ - len += sprintf(buf + len, "%lx ", dev->bit[i]); \ - len += sprintf(buf + len, "\n"); \ +#define SPRINTF_BIT_B (ev, bm) \ + do { \ + len += sprintf(buf + len, "B: %s=", #ev); \ + len += input_print_bitmap(buf + len, \ + dev->bm##bit, ev##_MAX); \ } while (0) -#define SPRINTF_BIT_B2 (bit, name, max, ev) \ - do { \ - if (test_bit(ev, dev->evbit)) \ - SPRINTF_BIT_B(bit, name, max); \ +#define SPRINTF_BIT_B2 (ev, bm) \ + do { \ + if (test_bit(EV_##ev, dev->evbit)) \ + SPRINTF_BIT_B(ev, bm); \ } while (0)static int input_devices_read (char *buf,char **start,off_t pos,int count,int *eof,void *data)
@@ -477,7 +492,7 @@ static int input_devices_read(char *buf,const char *path;off_t at =0 ; -int i, len, cnt =0 ; +int len, cnt =0 ;list_for_each_entry (dev, &input_dev_list, node) {
@@ -496,15 +511,15 @@ static int input_devices_read(char *buf, len +=sprintf (buf + len,"\n" ); -SPRINTF_BIT_B (evbit,"EV=" ,EV_MAX ); -SPRINTF_BIT_B2 (keybit,"KEY=" ,KEY_MAX ,EV_KEY ); -SPRINTF_BIT_B2 (relbit,"REL=" ,REL_MAX ,EV_REL ); -SPRINTF_BIT_B2 (absbit,"ABS=" ,ABS_MAX ,EV_ABS ); -SPRINTF_BIT_B2 (mscbit,"MSC=" ,MSC_MAX ,EV_MSC ); -SPRINTF_BIT_B2 (ledbit,"LED=" ,LED_MAX ,EV_LED ); -SPRINTF_BIT_B2 (sndbit,"SND=" ,SND_MAX ,EV_SND ); -SPRINTF_BIT_B2 (ffbit,"FF=" ,FF_MAX ,EV_FF ); -SPRINTF_BIT_B2 (swbit,"SW=" ,SW_MAX ,EV_SW ); +SPRINTF_BIT_B (EV , ev); +SPRINTF_BIT_B2 (KEY , key); +SPRINTF_BIT_B2 (REL , rel); +SPRINTF_BIT_B2 (ABS , abs); +SPRINTF_BIT_B2 (MSC , msc); +SPRINTF_BIT_B2 (LED , led); +SPRINTF_BIT_B2 (SND , snd); +SPRINTF_BIT_B2 (FF , ff); +SPRINTF_BIT_B2 (SW , sw); len +=sprintf (buf + len,"\n" );
@@ -611,6 +626,96 @@ static inline int input_proc_init(void)static inline void input_proc_exit (void ) { }#endif +#define INPUT_DEV_STRING_ATTR_SHOW (name) \ +static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \ +{ \ + struct input_dev *input_dev = to_input_dev(dev); \ + int retval; \ + \ + retval = down_interruptible(&input_dev->sem); \ + if (retval) \ + return retval; \ + \ + retval = sprintf(buf, "%s\n", input_dev->name ? input_dev->name : ""); \ + \ + up(&input_dev->sem); \ + \ + return retval; \ +} + +INPUT_DEV_STRING_ATTR_SHOW (name); +INPUT_DEV_STRING_ATTR_SHOW (phys); +INPUT_DEV_STRING_ATTR_SHOW (uniq); + +static struct class_device_attribute input_dev_attrs[] = { +__ATTR (name,S_IRUGO , input_dev_show_name,NULL ), +__ATTR (phys,S_IRUGO , input_dev_show_phys,NULL ), +__ATTR (uniq,S_IRUGO , input_dev_show_uniq,NULL ), + __ATTR_NULL +}; + +#define INPUT_DEV_ID_ATTR (name) \ +static ssize_t input_dev_show_id_##name(struct class_device *dev, char *buf) \ +{ \ + struct input_dev *input_dev = to_input_dev(dev); \ + return sprintf(buf, "%04x\n", input_dev->id.name); \ +} \ +static CLASS_DEVICE_ATTR(name, S_IRUGO, input_dev_show_id_##name, NULL); + +INPUT_DEV_ID_ATTR (bustype); +INPUT_DEV_ID_ATTR (vendor); +INPUT_DEV_ID_ATTR (product); +INPUT_DEV_ID_ATTR (version); + +static struct attribute *input_dev_id_attrs[] = { + &class_device_attr_bustype.attr, + &class_device_attr_vendor.attr, + &class_device_attr_product.attr, + &class_device_attr_version.attr, +NULL +}; + +static struct attribute_group input_dev_id_attr_group = { + .name ="id" , + .attrs = input_dev_id_attrs, +}; + +#define INPUT_DEV_CAP_ATTR (ev, bm) \ +static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \ +{ \ + struct input_dev *input_dev = to_input_dev(dev); \ + return input_print_bitmap(buf, input_dev->bm##bit, ev##_MAX); \ +} \ +static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL); + +INPUT_DEV_CAP_ATTR (EV , ev); +INPUT_DEV_CAP_ATTR (KEY , key); +INPUT_DEV_CAP_ATTR (REL , rel); +INPUT_DEV_CAP_ATTR (ABS , abs); +INPUT_DEV_CAP_ATTR (MSC , msc); +INPUT_DEV_CAP_ATTR (LED , led); +INPUT_DEV_CAP_ATTR (SND , snd); +INPUT_DEV_CAP_ATTR (FF , ff); +INPUT_DEV_CAP_ATTR (SW , sw); + +static struct attribute *input_dev_caps_attrs[] = { + &class_device_attr_ev.attr, + &class_device_attr_key.attr, + &class_device_attr_rel.attr, + &class_device_attr_abs.attr, + &class_device_attr_msc.attr, + &class_device_attr_led.attr, + &class_device_attr_snd.attr, + &class_device_attr_ff.attr, + &class_device_attr_sw.attr, +NULL +}; + +static struct attribute_group input_dev_caps_attr_group = { + .name ="capabilities" , + .attrs = input_dev_caps_attrs, +}; +static void input_dev_release (struct class_device *class_dev) {struct input_dev *dev =to_input_dev (class_dev);
@@ -622,6 +727,7 @@ static void input_dev_release(struct clastatic struct class input_dev_class = { .name ="input_dev" , .release = input_dev_release, + .class_dev_attrs = input_dev_attrs, };struct input_dev *input_allocate_device (void )
@@ -659,6 +765,8 @@ static void input_register_classdevice(skfree (path);class_device_add (&dev->cdev); +sysfs_create_group (&dev->cdev.kobj, &input_dev_id_attr_group); +sysfs_create_group (&dev->cdev.kobj, &input_dev_caps_attr_group); }void input_register_device (struct input_dev *dev)
@@ -725,8 +833,11 @@ void input_unregister_device(struct inpulist_del_init (&dev->node); -if (dev->dynalloc) +if (dev->dynalloc) { +sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group); +sysfs_remove_group (&dev->cdev.kobj, &input_dev_id_attr_group);class_device_unregister (&dev->cdev); + }input_wakeup_procfs_readers (); }
PATCH 25/28 input core: implement class hierachy
In reply to Dmitry TorokhovInput: create 'input' class hierarchy
Make 'input' a root class and add 'devices' and 'interfaces' subclasses. 'devices' subclass will contain input_dev class devices whereas 'interfaces' will have devices created by input handlers, such as evdev, mousedev, etc.
---
drivers/input/evdev.c | 12 +-- drivers/input/input.c | 178 +++++++++++++++++++++++++++++++++-------------- drivers/input/joydev.c | 12 +-- drivers/input/mousedev.c | 70 +++++++++--------- drivers/input/tsdev.c | 23 ++---- include/linux/input.h | 9 +- 6 files changed, 188 insertions(+), 116 deletions(-)
drivers/input/input.c +126 -52
@@ -32,6 +32,8 @@ EXPORT_SYMBOL(input_register_device);EXPORT_SYMBOL (input_unregister_device);EXPORT_SYMBOL (input_register_handler);EXPORT_SYMBOL (input_unregister_handler); +EXPORT_SYMBOL (input_create_interface_device); +EXPORT_SYMBOL (input_destroy_interface_device);EXPORT_SYMBOL (input_grab_device);EXPORT_SYMBOL (input_release_device);EXPORT_SYMBOL (input_open_device);
@@ -39,10 +41,14 @@ EXPORT_SYMBOL(input_close_device);EXPORT_SYMBOL (input_accept_process);EXPORT_SYMBOL (input_flush_device);EXPORT_SYMBOL (input_event); -EXPORT_SYMBOL (input_class); +EXPORT_SYMBOL (input_interface_class);#define INPUT_DEVICES 256 +static struct class input_class = { + .name ="input" , +}; +static LIST_HEAD (input_dev_list);static LIST_HEAD (input_handler_list);
@@ -496,7 +502,7 @@ static int input_devices_read(char *buf,list_for_each_entry (dev, &input_dev_list, node) { - path = dev->dynalloc ?kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ) :NULL ; + path =kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ); len =sprintf (buf,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version);
@@ -725,7 +731,8 @@ static void input_dev_release(struct cla }static struct class input_dev_class = { - .name ="input_dev" , + .name ="devices" , + .parent = &input_class, .release = input_dev_release, .class_dev_attrs = input_dev_attrs, };
@@ -737,8 +744,6 @@ struct input_dev *input_allocate_device( dev =kzalloc (sizeof (struct input_dev ),GFP_KERNEL );if (dev) { dev->dynalloc =1 ; - dev->cdev.class = &input_dev_class; -class_device_initialize (&dev->cdev);INIT_LIST_HEAD (&dev->h_list);INIT_LIST_HEAD (&dev->node); }
@@ -746,38 +751,24 @@ struct input_dev *input_allocate_device(return dev; } -static void input_register_classdevice (struct input_dev *dev) +int input_register_device (struct input_dev *dev) {static atomic_t input_no =ATOMIC_INIT (0 ); -const char *path; - -__module_get (THIS_MODULE ); - - dev->dev = dev->cdev.dev; - -snprintf (dev->cdev.class_id,sizeof (dev->cdev.class_id), -"input%ld" , (unsigned long )atomic_inc_return (&input_no) -1 ); - - path =kobject_get_path (&dev->cdev.class->subsys.kset.kobj,GFP_KERNEL ); -printk (KERN_INFO "input: %s/%s as %s\n" , - dev->name ? dev->name :"Unspecified device" , - path ? path :"" , dev->cdev.class_id); -kfree (path); - -class_device_add (&dev->cdev); -sysfs_create_group (&dev->cdev.kobj, &input_dev_id_attr_group); -sysfs_create_group (&dev->cdev.kobj, &input_dev_caps_attr_group); -} - -void input_register_device (struct input_dev *dev) -{struct input_handle *handle;struct input_handler *handler;struct input_device_id *id; +const char *path; +int error; -set_bit (EV_SYN , dev->evbit); +if (!dev->dynalloc) { +printk (KERN_WARNING "input: device %s is statically allocated, will not register\n" +"Please convert to input_allocate_device() or contact [email protected]\n" , + dev->name ? dev->name :"<Unknown>" ); +return -EINVAL ; + }init_MUTEX (&dev->sem); +set_bit (EV_SYN , dev->evbit);/* * If delay and period are pre-set by the driver, then autorepeating
@@ -801,23 +792,46 @@ void input_register_device(struct input_if ((handle = handler->connect (handler, dev, id)))input_link_handle (handle); + dev->cdev.class = &input_dev_class; +snprintf (dev->cdev.class_id,sizeof (dev->cdev.class_id), +"input%ld" , (unsigned long )atomic_inc_return (&input_no) -1 ); -if (dev->dynalloc) -input_register_classdevice (dev); + error =class_device_register (&dev->cdev); +if (error) +return error; + + error =sysfs_create_group (&dev->cdev.kobj, &input_dev_id_attr_group); +if (error) + goto fail1; + + error =sysfs_create_group (&dev->cdev.kobj, &input_dev_caps_attr_group); +if (error) + goto fail2; + + path =kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ); +printk (KERN_INFO "input: %s as %s\n" , + dev->name ? dev->name :"Unspecified device" , path ? path :"N/A" ); +kfree (path);#ifdef CONFIG_HOTPLUG input_call_hotplug ("add" , dev);#endif input_wakeup_procfs_readers (); + +__module_get (THIS_MODULE ); + +return 0 ; + + fail2:sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group); + fail1:sysfs_remove_group (&dev->cdev.kobj, &input_dev_id_attr_group); +return error; }void input_unregister_device (struct input_dev *dev) {struct list_head * node, * next; -if (!dev)return ; -del_timer_sync (&dev->timer);list_for_each_safe (node, next, &dev->h_list) {
@@ -833,11 +847,9 @@ void input_unregister_device(struct inpulist_del_init (&dev->node); -if (dev->dynalloc) { -sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group); -sysfs_remove_group (&dev->cdev.kobj, &input_dev_id_attr_group); -class_device_unregister (&dev->cdev); - } +sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group); +sysfs_remove_group (&dev->cdev.kobj, &input_dev_id_attr_group); +class_device_unregister (&dev->cdev);input_wakeup_procfs_readers (); }
@@ -885,6 +897,63 @@ void input_unregister_handler(struct inpinput_wakeup_procfs_readers (); } + +static void input_interface_dev_release (struct class_device *class_dev) +{ +kfree (class_dev); +module_put (THIS_MODULE ); +} + +struct class input_interface_class = { + .name ="interfaces" , + .parent = &input_class, + .release = input_interface_dev_release, +}; + +int input_create_interface_device (struct input_handle *handle,dev_t devt) +{ +struct class_device *dev; +int error; + + dev =kzalloc (sizeof (struct class_device ),GFP_KERNEL ); +if (!dev) +return -ENOMEM ; + + dev->devt = devt; + dev->class = &input_interface_class; +strlcpy (dev->class_id, handle->name,BUS_ID_SIZE ); + + error =class_device_register (dev); +if (error) +return error; + +if (handle->dev) { +sysfs_create_link (&dev->kobj, &handle->dev->cdev.kobj,"device" ); +sysfs_create_link (&handle->dev->cdev.kobj, &dev->kobj, +kobject_name (&dev->kobj)); + } + + handle->intf_dev = dev; + +__module_get (THIS_MODULE ); + +return 0 ; +} + +void input_destroy_interface_device (struct input_handle *handle) +{ +if (handle->intf_dev) { +if (handle->dev) { +sysfs_remove_link (&handle->dev->cdev.kobj, +kobject_name (&handle->intf_dev->kobj)); +sysfs_remove_link (&handle->intf_dev->kobj,"device" ); + } + +class_device_unregister (handle->intf_dev); + handle->intf_dev =NULL ; + } +} +static int input_open_file (struct inode *inode,struct file *file) {struct input_handler *handler = input_table[iminor (inode) >>5 ];
@@ -921,40 +990,44 @@ static struct file_operations input_fops .open = input_open_file, }; -struct class *input_class; -static int __init input_init (void ) {int err; - err =class_register (&input_dev_class); + err =class_register (&input_class);if (err) { -printk (KERN_ERR "input: unable to register input_dev class\n" ); +printk (KERN_ERR "input: unable to register input class\n" );return err; } - input_class =class_create (THIS_MODULE ,"input" ); -if (IS_ERR (input_class)) { -printk (KERN_ERR "input: unable to register input class\n" ); - err =PTR_ERR (input_class); + err =class_register (&input_dev_class); +if (err) { +printk (KERN_ERR "input: unable to register device class\n" ); goto fail1; } + err =class_register (&input_interface_class); +if (err) { +printk (KERN_ERR "input: unable to register handler class\n" ); + goto fail2; + } + err =input_proc_init ();if (err) - goto fail2; + goto fail3; err =register_chrdev (INPUT_MAJOR ,"input" , &input_fops);if (err) {printk (KERN_ERR "input: unable to register char major %d" ,INPUT_MAJOR ); - goto fail3; + goto fail4; }return 0 ; - fail3:input_proc_exit (); - fail2:class_destroy (input_class); - fail1:class_unregister (&input_dev_class); + fail4:input_proc_exit (); + fail3:class_unregister (&input_interface_class); + fail2:class_unregister (&input_dev_class); + fail1:class_unregister (&input_class);return err; }
@@ -962,8 +1035,9 @@ static void __exit input_exit(void) {input_proc_exit ();unregister_chrdev (INPUT_MAJOR ,"input" ); -class_destroy (input_class); +class_unregister (&input_interface_class);class_unregister (&input_dev_class); +class_unregister (&input_class); }subsys_initcall (input_init);
include/linux/input.h +6 -3
@@ -891,7 +891,6 @@ struct input_dev {unsigned int users;struct class_device cdev; -struct device *dev;/* will be removed soon */ int dynalloc;/* temporarily */
@@ -970,6 +969,7 @@ struct input_handle {int open;char *name; +struct class_device *intf_dev;struct input_dev *dev;struct input_handler *handler;
@@ -1006,12 +1006,15 @@ static inline void input_put_device(struclass_device_put (&dev->cdev); } -void input_register_device (struct input_dev *); +int input_register_device (struct input_dev *);void input_unregister_device (struct input_dev *);void input_register_handler (struct input_handler *);void input_unregister_handler (struct input_handler *); +int input_create_interface_device (struct input_handle *,dev_t ); +void input_destroy_interface_device (struct input_handle *); +int input_grab_device (struct input_handle *);void input_release_device (struct input_handle *);
@@ -1074,7 +1077,7 @@ static inline void input_set_abs_params( dev->absbit[LONG (axis)] |=BIT (axis); } -extern struct class *input_class; +extern struct class input_interface_class;#endif #endif
drivers/input/evdev.c +5 -7
@@ -669,9 +669,9 @@ static struct input_handle *evdev_connecreturn NULL ; } -if (!(evdev =kmalloc (sizeof (struct evdev ),GFP_KERNEL ))) + evdev =kzalloc (sizeof (struct evdev ),GFP_KERNEL ); +if (!evdev)return NULL ; -memset (evdev,0 ,sizeof (struct evdev ));INIT_LIST_HEAD (&evdev->list);init_waitqueue_head (&evdev->wait);
@@ -686,9 +686,8 @@ static struct input_handle *evdev_connec evdev_table[minor] = evdev; -class_device_create (input_class, -MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + minor), - dev->dev,"event%d" , minor); +input_create_interface_device (&evdev->handle, +MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + minor));return &evdev->handle; }
@@ -698,8 +697,7 @@ static void evdev_disconnect(struct inpustruct evdev *evdev = handle->private;struct evdev_list *list; -class_device_destroy (input_class, -MKDEV (INPUT_MAJOR ,EVDEV_MINOR_BASE + evdev->minor)); +input_destroy_interface_device (handle); evdev->exist =0 ;if (evdev->open) {
drivers/input/joydev.c +5 -7
@@ -456,9 +456,9 @@ static struct input_handle *joydev_connereturn NULL ; } -if (!(joydev =kmalloc (sizeof (struct joydev ),GFP_KERNEL ))) + joydev =kmalloc (sizeof (struct joydev ),GFP_KERNEL ); +if (!joydev)return NULL ; -memset (joydev,0 ,sizeof (struct joydev ));INIT_LIST_HEAD (&joydev->list);init_waitqueue_head (&joydev->wait);
@@ -513,10 +513,8 @@ static struct input_handle *joydev_conne joydev_table[minor] = joydev; -class_device_create (input_class, -MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + minor), - dev->dev,"js%d" , minor); - +input_create_interface_device (&joydev->handle, +MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + minor));return &joydev->handle; }
@@ -525,7 +523,7 @@ static void joydev_disconnect(struct inpstruct joydev *joydev = handle->private;struct joydev_list *list; -class_device_destroy (input_class,MKDEV (INPUT_MAJOR ,JOYDEV_MINOR_BASE + joydev->minor)); +input_destroy_interface_device (handle); joydev->exist =0 ;if (joydev->open) {
drivers/input/mousedev.c +36 -34
124 lines not on this page · raw message
drivers/input/tsdev.c +10 -13
@@ -35,7 +35,7 @@* e-mail - mail your message to <[email protected]>. */ -#define TSDEV_MINOR_BASE 128 +#define TSDEV_MINOR_BASE 128#define TSDEV_MINORS 32/* First 16 devices are h3600_ts compatible; second 16 are h3600_tsraw */ #define TSDEV_MINOR_MASK 15
@@ -378,9 +378,9 @@ static struct input_handle *tsdev_connecreturn NULL ; } -if (!(tsdev =kmalloc (sizeof (struct tsdev ),GFP_KERNEL ))) + tsdev =kzalloc (sizeof (struct tsdev ),GFP_KERNEL ); +if (!tsdev)return NULL ; -memset (tsdev,0 ,sizeof (struct tsdev ));INIT_LIST_HEAD (&tsdev->list);init_waitqueue_head (&tsdev->wait);
@@ -395,24 +395,22 @@ static struct input_handle *tsdev_connec tsdev->handle.private = tsdev;/* Precompute the rough calibration matrix */ - delta = dev->absmax [ABS_X ] - dev->absmin [ABS_X ] +1 ; + delta = dev->absmax[ABS_X ] - dev->absmin[ABS_X ] +1 ;if (delta ==0 ) delta =1 ; tsdev->cal.xscale = (xres <<8 ) / delta; - tsdev->cal.xtrans = - ((dev->absmin [ABS_X ] * tsdev->cal.xscale) >>8 ); + tsdev->cal.xtrans = - ((dev->absmin[ABS_X ] * tsdev->cal.xscale) >>8 ); - delta = dev->absmax [ABS_Y ] - dev->absmin [ABS_Y ] +1 ; + delta = dev->absmax[ABS_Y ] - dev->absmin[ABS_Y ] +1 ;if (delta ==0 ) delta =1 ; tsdev->cal.yscale = (yres <<8 ) / delta; - tsdev->cal.ytrans = - ((dev->absmin [ABS_Y ] * tsdev->cal.yscale) >>8 ); + tsdev->cal.ytrans = - ((dev->absmin[ABS_Y ] * tsdev->cal.yscale) >>8 ); tsdev_table[minor] = tsdev; -class_device_create (input_class, -MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + minor), - dev->dev,"ts%d" , minor); - +input_create_interface_device (&tsdev->handle, +MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + minor));return &tsdev->handle; }
@@ -421,8 +419,7 @@ static void tsdev_disconnect(struct inpustruct tsdev *tsdev = handle->private;struct tsdev_list *list; -class_device_destroy (input_class, -MKDEV (INPUT_MAJOR ,TSDEV_MINOR_BASE + tsdev->minor)); +input_destroy_interface_device (handle); tsdev->exist =0 ;if (tsdev->open) {
PATCH 26/28 input core: remove custom-made hotplug handler
In reply to Dmitry TorokhovInput: remove custom-made hotplug handler
Now that all input devices are registered with sysfs we can remove old custom-made hotplug handler and crate a standard one.
---
drivers/input/input.c | 255 +++++++++++++++++++++----------------------------- 1 files changed, 110 insertions(+), 145 deletions(-)
drivers/input/input.c +110 -145
@@ -322,125 +322,7 @@ static struct input_device_id *input_matreturn NULL ; } - -/* -* Input hotplugging interface - loading event handlers based on -* device bitfields. -*/ - -#ifdef CONFIG_HOTPLUG - -/* -* Input hotplugging invokes what /proc/sys/kernel/hotplug says -* (normally /sbin/hotplug) when input devices get added or removed. -* -* This invokes a user mode policy agent, typically helping to load driver -* or other modules, configure the device, and more. Drivers can provide -* a MODULE_DEVICE_TABLE to help with module loading subtasks. -* -*/ - -#define SPRINTF_BIT_A (bit, name, max) \ - do { \ - envp[i++] = scratch; \ - scratch += sprintf(scratch, name); \ - for (j = NBITS(max) - 1; j >= 0; j--) \ - if (dev->bit[j]) break; \ - for (; j >= 0; j--) \ - scratch += sprintf(scratch, "%lx ", dev->bit[j]); \ - scratch++; \ - } while (0) - -#define SPRINTF_BIT_A2 (bit, name, max, ev) \ - do { \ - if (test_bit(ev, dev->evbit)) \ - SPRINTF_BIT_A(bit, name, max); \ - } while (0) - -static void input_call_hotplug (char *verb,struct input_dev *dev) -{ -char *argv[3 ], **envp, *buf, *scratch; -int i =0 , j, value; - -if (!hotplug_path[0 ]) { -printk (KERN_ERR "input.c: calling hotplug without a hotplug agent defined\n" ); -return ; - } -if (in_interrupt ()) { -printk (KERN_ERR "input.c: calling hotplug from interrupt\n" ); -return ; - } -if (!current->fs->root) { -printk (KERN_WARNING "input.c: calling hotplug without valid filesystem\n" ); -return ; - } -if (!(envp = (char **)kmalloc (20 *sizeof (char *),GFP_KERNEL ))) { -printk (KERN_ERR "input.c: not enough memory allocating hotplug environment\n" ); -return ; - } -if (!(buf =kmalloc (1024 ,GFP_KERNEL ))) { -kfree (envp); -printk (KERN_ERR "input.c: not enough memory allocating hotplug environment\n" ); -return ; - } - - argv[0 ] = hotplug_path; - argv[1 ] ="input" ; - argv[2 ] =NULL ; - - envp[i++] ="HOME=/" ; - envp[i++] ="PATH=/sbin:/bin:/usr/sbin:/usr/bin" ; - - scratch = buf; - - envp[i++] = scratch; - scratch +=sprintf (scratch,"ACTION=%s" , verb) +1 ; - - envp[i++] = scratch; - scratch +=sprintf (scratch,"PRODUCT=%x/%x/%x/%x" , - dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version) +1 ; - -if (dev->name) { - envp[i++] = scratch; - scratch +=sprintf (scratch,"NAME=%s" , dev->name) +1 ; - } - -if (dev->phys) { - envp[i++] = scratch; - scratch +=sprintf (scratch,"PHYS=%s" , dev->phys) +1 ; - } - -SPRINTF_BIT_A (evbit,"EV=" ,EV_MAX ); -SPRINTF_BIT_A2 (keybit,"KEY=" ,KEY_MAX ,EV_KEY ); -SPRINTF_BIT_A2 (relbit,"REL=" ,REL_MAX ,EV_REL ); -SPRINTF_BIT_A2 (absbit,"ABS=" ,ABS_MAX ,EV_ABS ); -SPRINTF_BIT_A2 (mscbit,"MSC=" ,MSC_MAX ,EV_MSC ); -SPRINTF_BIT_A2 (ledbit,"LED=" ,LED_MAX ,EV_LED ); -SPRINTF_BIT_A2 (sndbit,"SND=" ,SND_MAX ,EV_SND ); -SPRINTF_BIT_A2 (ffbit,"FF=" ,FF_MAX ,EV_FF ); -SPRINTF_BIT_A2 (swbit,"SW=" ,SW_MAX ,EV_SW ); - - envp[i++] =NULL ; - -#ifdef INPUT_DEBUG -printk (KERN_DEBUG "input.c: calling %s %s [%s %s %s %s %s]\n" , - argv[0 ], argv[1 ], envp[0 ], envp[1 ], envp[2 ], envp[3 ], envp[4 ]); -#endif - - value =call_usermodehelper (argv [0 ], argv, envp,0 ); - -kfree (buf); -kfree (envp); - -#ifdef INPUT_DEBUG -if (value !=0 ) -printk (KERN_DEBUG "input.c: hotplug returned %d\n" , value); -#endif -} - -#endif - -static int input_print_bitmap (char *buf,unsigned long *bitmap,int max) +static int input_print_bitmap (char *buf,int buf_size,unsigned long *bitmap,int max) {int i;int len =0 ;
@@ -450,10 +332,8 @@ static int input_print_bitmap(char *buf,break ;for (; i >=0 ; i--) - len +=sprintf (buf + len,"%lx%s" , bitmap[i], i >0 ?" " :"" ); - - len +=sprintf (buf + len,"\n" ); - + len +=snprintf (buf + len,max (buf_size - len,0 ), +"%lx%s" , bitmap[i], i >0 ?" " :"" );return len; }
@@ -478,17 +358,18 @@ static unsigned int input_devices_poll(sreturn 0 ; } -#define SPRINTF_BIT_B (ev, bm) \ +#define SPRINTF_BIT (ev, bm) \ do { \ len += sprintf(buf + len, "B: %s=", #ev); \ - len += input_print_bitmap(buf + len, \ + len += input_print_bitmap(buf + len, INT_MAX, \ dev->bm##bit, ev##_MAX); \ + len += sprintf(buf + len, "\n"); \ } while (0) -#define SPRINTF_BIT_B2 (ev, bm) \ +#define TEST_AND_SPRINTF_BIT (ev, bm) \ do { \ if (test_bit(EV_##ev, dev->evbit)) \ - SPRINTF_BIT_B(ev, bm); \ + SPRINTF_BIT(ev, bm); \ } while (0)static int input_devices_read (char *buf,char **start,off_t pos,int count,int *eof,void *data)
@@ -517,15 +398,15 @@ static int input_devices_read(char *buf, len +=sprintf (buf + len,"\n" ); -SPRINTF_BIT_B (EV , ev); -SPRINTF_BIT_B2 (KEY , key); -SPRINTF_BIT_B2 (REL , rel); -SPRINTF_BIT_B2 (ABS , abs); -SPRINTF_BIT_B2 (MSC , msc); -SPRINTF_BIT_B2 (LED , led); -SPRINTF_BIT_B2 (SND , snd); -SPRINTF_BIT_B2 (FF , ff); -SPRINTF_BIT_B2 (SW , sw); +SPRINTF_BIT (EV , ev); +TEST_AND_SPRINTF_BIT (KEY , key); +TEST_AND_SPRINTF_BIT (REL , rel); +TEST_AND_SPRINTF_BIT (ABS , abs); +TEST_AND_SPRINTF_BIT (MSC , msc); +TEST_AND_SPRINTF_BIT (LED , led); +TEST_AND_SPRINTF_BIT (SND , snd); +TEST_AND_SPRINTF_BIT (FF , ff); +TEST_AND_SPRINTF_BIT (SW , sw); len +=sprintf (buf + len,"\n" );
@@ -690,7 +571,7 @@ static struct attribute_group input_dev_ static ssize_t input_dev_show_cap_##bm(struct class_device *dev, char *buf) \ { \ struct input_dev *input_dev = to_input_dev(dev); \ - return input_print_bitmap(buf, input_dev->bm##bit, ev##_MAX); \ + return input_print_bitmap(buf, PAGE_SIZE, input_dev->bm##bit, ev##_MAX);\ } \ static CLASS_DEVICE_ATTR(bm, S_IRUGO, input_dev_show_cap_##bm, NULL);
@@ -730,10 +611,102 @@ static void input_dev_release(struct clamodule_put (THIS_MODULE ); } +#ifdef CONFIG_HOTPLUG + +/* +* Input hotplugging interface - loading event handlers based on +* device bitfields. +*/ + +static int input_add_hotplug_bm_var (char **envp,int num_envp,int *cur_index,char *buffer,int buffer_size, +int *cur_len,const char *name,unsigned long *bitmap,int max) +{ +if (*cur_index >= num_envp -1 ) +return -ENOMEM ; + + envp[*cur_index] = buffer + *cur_len; + + *cur_len +=snprintf (buffer + *cur_len,max (buffer_size - *cur_len,0 ), name); +if (*cur_len > buffer_size) +return -ENOMEM ; + + *cur_len +=input_print_bitmap (buffer + *cur_len,max (buffer_size - *cur_len,0 ), + bitmap, max) +1 ; +if (*cur_len > buffer_size) +return -ENOMEM ; + + (*cur_index)++; +return 0 ; +} + +#define INPUT_ADD_HOTPLUG_VAR(fmt, val...) \ + do { \ + int err = add_hotplug_env_var(envp, num_envp, &i, \ + buffer, buffer_size, &len, \ + fmt, val); \ + if (err) \ + return err; \ + } while (0) + +#define INPUT_ADD_HOTPLUG_BM_VAR (name, bm, max) \ + do { \ + int err = input_add_hotplug_bm_var(envp, num_envp, &i, \ + buffer, buffer_size, &len, \ + name, bm, max); \ + if (err) \ + return err; \ + } while (0) + +static int input_dev_hotplug (struct class_device *cdev,char **envp,int num_envp,char *buffer,int buffer_size) +{ +struct input_dev *dev =to_input_dev (cdev); +int i =0 ; +int len =0 ; + +INPUT_ADD_HOTPLUG_VAR ("PRODUCT=%x/%x/%x/%x" , + dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); +if (dev->name) +INPUT_ADD_HOTPLUG_VAR ("NAME=\"%s\"" , dev->name); +if (dev->phys) +INPUT_ADD_HOTPLUG_VAR ("PHYS=\"%s\"" , dev->phys); +if (dev->phys) +INPUT_ADD_HOTPLUG_VAR ("UNIQ=\"%s\"" , dev->uniq); + +INPUT_ADD_HOTPLUG_BM_VAR ("EV=" , dev->evbit,EV_MAX ); +if (test_bit (EV_KEY , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("KEY=" , dev->keybit,KEY_MAX ); +if (test_bit (EV_REL , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("REL=" , dev->relbit,REL_MAX ); +if (test_bit (EV_ABS , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("ABS=" , dev->absbit,ABS_MAX ); +if (test_bit (EV_MSC , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("MSC=" , dev->mscbit,MSC_MAX ); +if (test_bit (EV_LED , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("LED=" , dev->ledbit,LED_MAX ); +if (test_bit (EV_SND , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("SND=" , dev->sndbit,SND_MAX ); +if (test_bit (EV_FF , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("FF=" , dev->ffbit,FF_MAX ); +if (test_bit (EV_SW , dev->evbit)) +INPUT_ADD_HOTPLUG_BM_VAR ("SW=" , dev->swbit,SW_MAX ); + + envp[i] =NULL ; + +return 0 ; +} + +#else +static int input_dev_hotplug (struct class_device *cdev,char **envp,int num_envp,char *buffer,int buffer_size) +{ +return 0 ; +} +#endif +static struct class input_dev_class = { .name ="devices" , .parent = &input_class, .release = input_dev_release, + .hotplug = input_dev_hotplug, .class_dev_attrs = input_dev_attrs, };
@@ -813,10 +786,6 @@ int input_register_device(struct input_d dev->name ? dev->name : "Unspecified device", path ? path : "N/A");kfree (path); -#ifdef CONFIG_HOTPLUG -input_call_hotplug ("add" , dev); -#endif -input_wakeup_procfs_readers ();__module_get (THIS_MODULE );
@@ -841,10 +810,6 @@ void input_unregister_device(struct inpu handle->handler->disconnect (handle); } -#ifdef CONFIG_HOTPLUG -input_call_hotplug ("remove" , dev); -#endif -list_del_init (&dev->node);sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group);
Marcel Holtmann
maintainerHi Dmitry,
Quoted 4 lines
The following set of patches deals with converting input subsystem to the driver model and intergrate it with sysfs. This allows us to remove custom-made input hotplug handler and finally have an option of netlink-only hotplug notifier.
do you have a GIT tree with all that changes that I can simply pull in for testing?
Regards
Marcel
Dmitry Torokhov
maintainerQuoted 10 lines · Marcel Holtmann
Hi Dmitry,
Quoted 4 lines
The following set of patches deals with converting input subsystem to the driver model and intergrate it with sysfs. This allows us to remove custom-made input hotplug handler and finally have an option of netlink-only hotplug notifier.
do you have a GIT tree with all that changes that I can simply pull in for testing?
Not yet, but I think I will set one up if there is a general approval of the direction of the series.
Signature · 1 line
Dmitry
PATCH 27/28 Input: convert input handlers to class interfaces
In reply to Dmitry TorokhovInput: convert input handlers to class interfaces
Thit is exactly why class interfaces were created - to provide several different 'views' for the same hardware.
---
drivers/input/input.c | 455 +++++++++++++++++++++++++------------------------- include/linux/input.h | 8 2 files changed, 232 insertions(+), 231 deletions(-)
drivers/input/input.c +228 -227
@@ -49,9 +49,6 @@ static struct class input_class = { .name = "input", }; -static LIST_HEAD (input_dev_list); -static LIST_HEAD (input_handler_list); -static struct input_handler *input_table[8 ];void input_event (struct input_dev *dev,unsigned int type,unsigned int code,int value)
@@ -271,12 +268,6 @@ void input_close_device(struct input_hanup (&dev->sem); } -static void input_link_handle (struct input_handle *handle) -{ -list_add_tail (&handle->d_node, &handle->dev->h_list); -list_add_tail (&handle->h_node, &handle->handler->h_list); -} -#define MATCH_BIT (bit, max) \ for (i = 0; i < NBITS(max); i++) \ if ((id->bit[i] & dev->bit[i]) != id->bit[i]) \
@@ -337,182 +328,6 @@ static int input_print_bitmap(char *buf,return len; } -#ifdef CONFIG_PROC_FS - -static struct proc_dir_entry *proc_bus_input_dir; -static DECLARE_WAIT_QUEUE_HEAD (input_devices_poll_wait); -static int input_devices_state; - -static inline void input_wakeup_procfs_readers (void ) -{ - input_devices_state++; -wake_up (&input_devices_poll_wait); -} - -static unsigned int input_devices_poll (struct file *file,poll_table *wait) -{ -int state = input_devices_state; -poll_wait (file, &input_devices_poll_wait, wait); -if (state != input_devices_state) -return POLLIN |POLLRDNORM ; -return 0 ; -} - -#define SPRINTF_BIT (ev, bm) \ - do { \ - len += sprintf(buf + len, "B: %s=", #ev); \ - len += input_print_bitmap(buf + len, INT_MAX, \ - dev->bm##bit, ev##_MAX); \ - len += sprintf(buf + len, "\n"); \ - } while (0) - -#define TEST_AND_SPRINTF_BIT (ev, bm) \ - do { \ - if (test_bit(EV_##ev, dev->evbit)) \ - SPRINTF_BIT(ev, bm); \ - } while (0) - -static int input_devices_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) -{ -struct input_dev *dev; -struct input_handle *handle; -const char *path; - -off_t at =0 ; -int len, cnt =0 ; - -list_for_each_entry (dev, &input_dev_list, node) { - - path =kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ); - - len =sprintf (buf,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , - dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); - - len +=sprintf (buf + len,"N: Name=\"%s\"\n" , dev->name ? dev->name :"" ); - len +=sprintf (buf + len,"P: Phys=%s\n" , dev->phys ? dev->phys :"" ); - len +=sprintf (buf + len,"S: Sysfs=%s\n" , path ? path :"" ); - len +=sprintf (buf + len,"H: Handlers=" ); - -list_for_each_entry (handle, &dev->h_list, d_node) - len +=sprintf (buf + len,"%s " , handle->name); - - len +=sprintf (buf + len,"\n" ); - -SPRINTF_BIT (EV , ev); -TEST_AND_SPRINTF_BIT (KEY , key); -TEST_AND_SPRINTF_BIT (REL , rel); -TEST_AND_SPRINTF_BIT (ABS , abs); -TEST_AND_SPRINTF_BIT (MSC , msc); -TEST_AND_SPRINTF_BIT (LED , led); -TEST_AND_SPRINTF_BIT (SND , snd); -TEST_AND_SPRINTF_BIT (FF , ff); -TEST_AND_SPRINTF_BIT (SW , sw); - - len +=sprintf (buf + len,"\n" ); - - at += len; - -if (at >= pos) { -if (!*start) { - *start = buf + (pos - (at - len)); - cnt = at - pos; - }else cnt += len; - buf += len; -if (cnt >= count) -break ; - } - -kfree (path); - } - -if (&dev->node == &input_dev_list) - *eof =1 ; - -return (count > cnt) ? cnt : count; -} - -static int input_handlers_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) -{ -struct input_handler *handler; - -off_t at =0 ; -int len =0 , cnt =0 ; -int i =0 ; - -list_for_each_entry (handler, &input_handler_list, node) { - -if (handler->fops) - len =sprintf (buf,"N: Number=%d Name=%s Minor=%d\n" , - i++, handler->name, handler->minor); -else - len =sprintf (buf,"N: Number=%d Name=%s\n" , - i++, handler->name); - - at += len; - -if (at >= pos) { -if (!*start) { - *start = buf + (pos - (at - len)); - cnt = at - pos; - }else cnt += len; - buf += len; -if (cnt >= count) -break ; - } - } -if (&handler->node == &input_handler_list) - *eof =1 ; - -return (count > cnt) ? cnt : count; -} - -static struct file_operations input_fileops; - -static int __init input_proc_init (void ) -{ -struct proc_dir_entry *entry; - - proc_bus_input_dir =proc_mkdir ("input" , proc_bus); -if (!proc_bus_input_dir) -return -ENOMEM ; - - proc_bus_input_dir->owner =THIS_MODULE ; - - entry =create_proc_read_entry ("devices" ,0 , proc_bus_input_dir, input_devices_read,NULL ); -if (!entry) - goto fail1; - - entry->owner =THIS_MODULE ; - input_fileops = *entry->proc_fops; - entry->proc_fops = &input_fileops; - entry->proc_fops->poll = input_devices_poll; - - entry =create_proc_read_entry ("handlers" ,0 , proc_bus_input_dir, input_handlers_read,NULL ); -if (!entry) - goto fail2; - - entry->owner =THIS_MODULE ; - -return 0 ; - - fail2:remove_proc_entry ("devices" , proc_bus_input_dir); - fail1:remove_proc_entry ("input" , proc_bus); -return -ENOMEM ; -} - -static void input_proc_exit (void ) -{ -remove_proc_entry ("devices" , proc_bus_input_dir); -remove_proc_entry ("handlers" , proc_bus_input_dir); -remove_proc_entry ("input" , proc_bus); -} - -#else /* !CONFIG_PROC_FS */ -static inline void input_wakeup_procfs_readers (void ) { } -static inline int input_proc_init (void ) {return 0 ; } -static inline void input_proc_exit (void ) { } -#endif -#define INPUT_DEV_STRING_ATTR_SHOW (name) \ static ssize_t input_dev_show_##name(struct class_device *dev, char *buf) \ { \
@@ -710,6 +525,188 @@ static struct class input_dev_class = { .class_dev_attrs = input_dev_attrs, }; +#ifdef CONFIG_PROC_FS + +static struct proc_dir_entry *proc_bus_input_dir; +static DECLARE_WAIT_QUEUE_HEAD (input_devices_poll_wait); +static int input_devices_state; + +static inline void input_wakeup_procfs_readers (void ) +{ + input_devices_state++; +wake_up (&input_devices_poll_wait); +} + +static unsigned int input_devices_poll (struct file *file,poll_table *wait) +{ +int state = input_devices_state; +poll_wait (file, &input_devices_poll_wait, wait); +if (state != input_devices_state) +return POLLIN |POLLRDNORM ; +return 0 ; +} + +#define SPRINTF_BIT (ev, bm) \ + do { \ + len += sprintf(buf + len, "B: %s=", #ev); \ + len += input_print_bitmap(buf + len, INT_MAX, \ + dev->bm##bit, ev##_MAX); \ + len += sprintf(buf + len, "\n"); \ + } while (0) + +#define TEST_AND_SPRINTF_BIT (ev, bm) \ + do { \ + if (test_bit(EV_##ev, dev->evbit)) \ + SPRINTF_BIT(ev, bm); \ + } while (0) + +static int input_devices_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) +{ +struct list_head *node; +struct input_dev *dev; +struct input_handle *handle; +const char *path; + +off_t at =0 ; +int len, cnt =0 ; + +list_for_each (node, &input_dev_class.children) { + + dev = to_input_dev(container_of(node, struct class_device, node)); + path =kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ); + + len =sprintf (buf,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , + dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); + + len +=sprintf (buf + len,"N: Name=\"%s\"\n" , dev->name ? dev->name :"" ); + len +=sprintf (buf + len,"P: Phys=%s\n" , dev->phys ? dev->phys :"" ); + len +=sprintf (buf + len,"S: Sysfs=%s\n" , path ? path :"" ); + len +=sprintf (buf + len,"H: Handlers=" ); + +list_for_each_entry (handle, &dev->h_list, d_node) + len +=sprintf (buf + len,"%s " , handle->name); + + len +=sprintf (buf + len,"\n" ); + +SPRINTF_BIT (EV , ev); +TEST_AND_SPRINTF_BIT (KEY , key); +TEST_AND_SPRINTF_BIT (REL , rel); +TEST_AND_SPRINTF_BIT (ABS , abs); +TEST_AND_SPRINTF_BIT (MSC , msc); +TEST_AND_SPRINTF_BIT (LED , led); +TEST_AND_SPRINTF_BIT (SND , snd); +TEST_AND_SPRINTF_BIT (FF , ff); +TEST_AND_SPRINTF_BIT (SW , sw); + + len +=sprintf (buf + len,"\n" ); + + at += len; + +if (at >= pos) { +if (!*start) { + *start = buf + (pos - (at - len)); + cnt = at - pos; + }else cnt += len; + buf += len; +if (cnt >= count) +break ; + } + +kfree (path); + } + +if (node == &input_dev_class.children) + *eof =1 ; + +return (count > cnt) ? cnt : count; +} + +static int input_handlers_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) +{ +struct list_head *node; +struct input_handler *handler; + +off_t at =0 ; +int len =0 , cnt =0 ; +int i =0 ; + +list_for_each (node, &input_dev_class.interfaces) { + + handler = to_input_handler(container_of(node, struct class_interface, node)); + +if (handler->fops) + len =sprintf (buf,"N: Number=%d Name=%s Minor=%d\n" , + i++, handler->name, handler->minor); +else + len =sprintf (buf,"N: Number=%d Name=%s\n" , + i++, handler->name); + + at += len; + +if (at >= pos) { +if (!*start) { + *start = buf + (pos - (at - len)); + cnt = at - pos; + }else cnt += len; + buf += len; +if (cnt >= count) +break ; + } + } + +if (node == &input_dev_class.interfaces) + *eof =1 ; + +return (count > cnt) ? cnt : count; +} + +static struct file_operations input_fileops; + +static int __init input_proc_init (void ) +{ +struct proc_dir_entry *entry; + + proc_bus_input_dir =proc_mkdir ("input" , proc_bus); +if (!proc_bus_input_dir) +return -ENOMEM ; + + proc_bus_input_dir->owner =THIS_MODULE ; + + entry =create_proc_read_entry ("devices" ,0 , proc_bus_input_dir, input_devices_read,NULL ); +if (!entry) + goto fail1; + + entry->owner =THIS_MODULE ; + input_fileops = *entry->proc_fops; + entry->proc_fops = &input_fileops; + entry->proc_fops->poll = input_devices_poll; + + entry =create_proc_read_entry ("handlers" ,0 , proc_bus_input_dir, input_handlers_read,NULL ); +if (!entry) + goto fail2; + + entry->owner =THIS_MODULE ; + +return 0 ; + + fail2:remove_proc_entry ("devices" , proc_bus_input_dir); + fail1:remove_proc_entry ("input" , proc_bus); +return -ENOMEM ; +} + +static void input_proc_exit (void ) +{ +remove_proc_entry ("devices" , proc_bus_input_dir); +remove_proc_entry ("handlers" , proc_bus_input_dir); +remove_proc_entry ("input" , proc_bus); +} + +#else /* !CONFIG_PROC_FS */ +static inline void input_wakeup_procfs_readers (void ) { } +static inline int input_proc_init (void ) {return 0 ; } +static inline void input_proc_exit (void ) { } +#endif +struct input_dev *input_allocate_device (void ) {struct input_dev *dev;
@@ -718,7 +715,6 @@ struct input_dev *input_allocate_device(if (dev) { dev->dynalloc =1 ;INIT_LIST_HEAD (&dev->h_list); -INIT_LIST_HEAD (&dev->node); }return dev;
@@ -727,9 +723,6 @@ struct input_dev *input_allocate_device(int input_register_device (struct input_dev *dev) {static atomic_t input_no =ATOMIC_INIT (0 ); -struct input_handle *handle; -struct input_handler *handler; -struct input_device_id *id;const char *path;int error;
@@ -757,13 +750,6 @@ int input_register_device(struct input_d }INIT_LIST_HEAD (&dev->h_list); -list_add_tail (&dev->node, &input_dev_list); - -list_for_each_entry (handler, &input_handler_list, node) -if (!handler->blacklist || !input_match_device (handler->blacklist, dev)) -if ((id =input_match_device (handler->id_table, dev))) -if ((handle = handler->connect (handler, dev, id))) -input_link_handle (handle); dev->cdev.class = &input_dev_class; snprintf(dev->cdev.class_id, sizeof(dev->cdev.class_id),
@@ -799,19 +785,8 @@ int input_register_device(struct input_dvoid input_unregister_device (struct input_dev *dev) { -struct list_head * node, * next; -del_timer_sync (&dev->timer); -list_for_each_safe (node, next, &dev->h_list) { -struct input_handle * handle =to_handle (node); -list_del_init (&handle->d_node); -list_del_init (&handle->h_node); - handle->handler->disconnect (handle); - } - -list_del_init (&dev->node); -sysfs_remove_group (&dev->cdev.kobj, &input_dev_caps_attr_group);sysfs_remove_group (&dev->cdev.kobj, &input_dev_id_attr_group);class_device_unregister (&dev->cdev);
@@ -819,46 +794,72 @@ void input_unregister_device(struct inpuinput_wakeup_procfs_readers (); } -void input_register_handler (struct input_handler *handler) +static int input_handler_add_device (struct class_device *cdev,struct class_interface *intf) { -struct input_dev *dev; +struct input_dev *dev =to_input_dev (cdev); +struct input_handler *handler =to_input_handler (intf);struct input_handle *handle;struct input_device_id *id; -if (!handler)return ; +if (!handler->blacklist || !input_match_device (handler->blacklist, dev)) { + id =input_match_device (handler->id_table, dev); +if (id) { + handle = handler->connect (handler, dev, id); +if (handle) { +list_add_tail (&handle->d_node, &dev->h_list); +list_add_tail (&handle->h_node, &handler->h_list); +return 0 ; + } + } + } + +return -ENODEV ; +} + +static void input_handler_remove_device (struct class_device *cdev,struct class_interface *intf) +{ +struct input_dev *dev =to_input_dev (cdev); +struct input_handler *handler =to_input_handler (intf); +struct input_handle *handle, *next; + +list_for_each_entry_safe (handle, next, &dev->h_list, d_node) { +if (handle->handler == handler) { +list_del_init (&handle->h_node); +list_del_init (&handle->d_node); + handler->disconnect (handle); + } + } +} + +int input_register_handler (struct input_handler *handler) +{ +int error;INIT_LIST_HEAD (&handler->h_list);if (handler->fops !=NULL ) input_table[handler->minor >>5 ] = handler; -list_add_tail (&handler->node, &input_handler_list); + handler->intf.class = &input_dev_class; + handler->intf.add = input_handler_add_device; + handler->intf.remove = input_handler_remove_device; -list_for_each_entry (dev, &input_dev_list, node) -if (!handler->blacklist || !input_match_device (handler->blacklist, dev)) -if ((id =input_match_device (handler->id_table, dev))) -if ((handle = handler->connect (handler, dev, id))) -input_link_handle (handle); + error =class_interface_register (&handler->intf); +if (error) +return error;input_wakeup_procfs_readers (); + +return 0 ; }void input_unregister_handler (struct input_handler *handler) { -struct list_head * node, * next; - -list_for_each_safe (node, next, &handler->h_list) { -struct input_handle * handle =to_handle_h (node); -list_del_init (&handle->h_node); -list_del_init (&handle->d_node); - handler->disconnect (handle); - } - -list_del_init (&handler->node); -if (handler->fops !=NULL ) input_table[handler->minor >>5 ] =NULL ; +class_interface_unregister (&handler->intf); +input_wakeup_procfs_readers (); }
include/linux/input.h +4 -4
@@ -895,7 +895,6 @@ struct input_dev {int dynalloc;/* temporarily */ struct list_head h_list; -struct list_head node; };#define to_input_dev (d) container_of(d, struct input_dev, cdev)
@@ -960,8 +959,10 @@ struct input_handler {struct input_device_id *blacklist;struct list_head h_list; -struct list_head node; + +struct class_interface intf; }; +#define to_input_handler (h) container_of(h, struct input_handler, intf)struct input_handle {
@@ -986,7 +987,6 @@ struct input_handle {static inline void init_input_dev (struct input_dev *dev) {INIT_LIST_HEAD (&dev->h_list); -INIT_LIST_HEAD (&dev->node); }struct input_dev *input_allocate_device (void );
@@ -1009,7 +1009,7 @@ static inline void input_put_device(struint input_register_device (struct input_dev *);void input_unregister_device (struct input_dev *); -void input_register_handler (struct input_handler *); +int input_register_handler (struct input_handler *);void input_unregister_handler (struct input_handler *);int input_create_interface_device (struct input_handle *,dev_t );
PATCH 28/28 Input: convert to seq_file
In reply to Dmitry TorokhovInput: convert /proc handling to seq_file
---
drivers/input/input.c | 239 +++++++++++++++++++++++++++++++------------------- 1 files changed, 150 insertions(+), 89 deletions(-)
drivers/input/input.c +150 -89
@@ -18,6 +18,7 @@#include <linux/random.h> #include <linux/major.h> #include <linux/proc_fs.h> +#include <linux/seq_file.h> #include <linux/kobject_uevent.h> #include <linux/interrupt.h> #include <linux/poll.h>
@@ -537,7 +538,7 @@ static inline void input_wakeup_procfs_rwake_up (&input_devices_poll_wait); } -static unsigned int input_devices_poll (struct file *file,poll_table *wait) +static unsigned int input_proc_devices_poll (struct file *file,poll_table *wait) {int state = input_devices_state;poll_wait (file, &input_devices_poll_wait, wait);
@@ -546,121 +547,182 @@ static unsigned int input_devices_poll(sreturn 0 ; } -#define SPRINTF_BIT (ev, bm) \ +static struct list_head *list_get_nth_element (struct list_head *list,loff_t *pos) +{ +struct list_head *node; +loff_t i =0 ; + +list_for_each (node, list) +if (i++ == *pos) +return node; + +return NULL ; +} + +static struct list_head *list_get_next_element (struct list_head *list,struct list_head *element,loff_t *pos) +{ +if (element->next == list) +return NULL ; + + ++(*pos); +return element->next; +} + +static void *input_devices_seq_start (struct seq_file *seq,loff_t *pos) +{ +down (&input_dev_class.sem); +return list_get_nth_element (&input_dev_class.children, pos); +} + +static void *input_devices_seq_next (struct seq_file *seq,void *v,loff_t *pos) +{ +return list_get_next_element (&input_dev_class.children, v, pos); +} + +static void input_devices_seq_stop (struct seq_file *seq,void *v) +{ +up (&input_dev_class.sem); +} + +static void input_seq_print_bitmap (struct seq_file *seq,const char *name, +unsigned long *bitmap,int max) +{ +int i; + +for (i =NBITS (max) -1 ; i >0 ; i--) +if (bitmap[i]) +break ; + +seq_printf (seq,"B: %s=" , name); +for (; i >=0 ; i--) +seq_printf (seq,"%lx%s" , bitmap[i], i >0 ?" " :"" ); +seq_putc (seq,'\n' ); +} + +#define SEQ_PRINTF_BIT (ev, bm) \ do { \ - len += sprintf(buf + len, "B: %s=", #ev); \ - len += input_print_bitmap(buf + len, INT_MAX, \ - dev->bm##bit, ev##_MAX); \ - len += sprintf(buf + len, "\n"); \ + input_seq_print_bitmap(seq, #ev, \ + dev->bm##bit, ev##_MAX); \ } while (0) -#define TEST_AND_SPRINTF_BIT (ev, bm) \ +#define TEST_AND_SEQ_PRINTF_BIT (ev, bm) \ do { \ if (test_bit(EV_##ev, dev->evbit)) \ - SPRINTF_BIT(ev, bm); \ + SEQ_PRINTF_BIT(ev, bm); \ } while (0) -static int input_devices_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) +static int input_devices_seq_show (struct seq_file *seq,void *v) { -struct list_head *node; -struct input_dev *dev; + struct class_device *cdev = container_of(v, struct class_device, node); +struct input_dev *dev =to_input_dev (cdev); +const char *path =kobject_get_path (&cdev->kobj,GFP_KERNEL );struct input_handle *handle; -const char *path; -off_t at =0 ; -int len, cnt =0 ; +seq_printf (seq,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , + dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); -list_for_each (node, &input_dev_class.children) { +seq_printf (seq,"N: Name=\"%s\"\n" , dev->name ? dev->name :"" ); +seq_printf (seq,"P: Phys=%s\n" , dev->phys ? dev->phys :"" ); +seq_printf (seq,"S: Sysfs=%s\n" , path ? path :"" ); +seq_printf (seq,"H: Handlers=" ); + +list_for_each_entry (handle, &dev->h_list, d_node) +seq_printf (seq,"%s " , handle->name); +seq_putc (seq,'\n' ); + +SEQ_PRINTF_BIT (EV , ev); +TEST_AND_SEQ_PRINTF_BIT (KEY , key); +TEST_AND_SEQ_PRINTF_BIT (REL , rel); +TEST_AND_SEQ_PRINTF_BIT (ABS , abs); +TEST_AND_SEQ_PRINTF_BIT (MSC , msc); +TEST_AND_SEQ_PRINTF_BIT (LED , led); +TEST_AND_SEQ_PRINTF_BIT (SND , snd); +TEST_AND_SEQ_PRINTF_BIT (FF , ff); +TEST_AND_SEQ_PRINTF_BIT (SW , sw); - dev = to_input_dev(container_of(node, struct class_device, node)); - path =kobject_get_path (&dev->cdev.kobj,GFP_KERNEL ); +seq_putc (seq,'\n' ); - len =sprintf (buf,"I: Bus=%04x Vendor=%04x Product=%04x Version=%04x\n" , - dev->id.bustype, dev->id.vendor, dev->id.product, dev->id.version); - - len +=sprintf (buf + len,"N: Name=\"%s\"\n" , dev->name ? dev->name :"" ); - len +=sprintf (buf + len,"P: Phys=%s\n" , dev->phys ? dev->phys :"" ); - len +=sprintf (buf + len,"S: Sysfs=%s\n" , path ? path :"" ); - len +=sprintf (buf + len,"H: Handlers=" ); +kfree (path); +return 0 ; +} -list_for_each_entry (handle, &dev->h_list, d_node) - len +=sprintf (buf + len,"%s " , handle->name); +static struct seq_operations input_devices_seq_ops = { + .start = input_devices_seq_start, + .next = input_devices_seq_next, + .stop = input_devices_seq_stop, + .show = input_devices_seq_show, +}; - len +=sprintf (buf + len,"\n" ); +static int input_proc_devices_open (struct inode *inode,struct file *file) +{ +return seq_open (file, &input_devices_seq_ops); +} -SPRINTF_BIT (EV , ev); -TEST_AND_SPRINTF_BIT (KEY , key); -TEST_AND_SPRINTF_BIT (REL , rel); -TEST_AND_SPRINTF_BIT (ABS , abs); -TEST_AND_SPRINTF_BIT (MSC , msc); -TEST_AND_SPRINTF_BIT (LED , led); -TEST_AND_SPRINTF_BIT (SND , snd); -TEST_AND_SPRINTF_BIT (FF , ff); -TEST_AND_SPRINTF_BIT (SW , sw); - - len +=sprintf (buf + len,"\n" ); - - at += len; - -if (at >= pos) { -if (!*start) { - *start = buf + (pos - (at - len)); - cnt = at - pos; - }else cnt += len; - buf += len; -if (cnt >= count) -break ; - } +static struct file_operations input_devices_fileops = { + .owner =THIS_MODULE , + .open = input_proc_devices_open, + .poll = input_proc_devices_poll, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +}; -kfree (path); - } +static void *input_handlers_seq_start (struct seq_file *seq,loff_t *pos) +{ +down (&input_dev_class.sem); +return list_get_nth_element (&input_dev_class.interfaces, pos); +} -if (node == &input_dev_class.children) - *eof =1 ; +static void *input_handlers_seq_next (struct seq_file *seq,void *v,loff_t *pos) +{ +return list_get_next_element (&input_dev_class.interfaces, v, pos); +} -return (count > cnt) ? cnt : count; +static void input_handlers_seq_stop (struct seq_file *seq,void *v) +{ +up (&input_dev_class.sem); } -static int input_handlers_read (char *buf,char **start,off_t pos,int count,int *eof,void *data) +static int input_handlers_seq_show (struct seq_file *seq,void *v) { + struct class_interface *intf = container_of(v, struct class_interface, node); +struct input_handler *handler =to_input_handler (intf);struct list_head *node; -struct input_handler *handler; - -off_t at =0 ; -int len =0 , cnt =0 ;int i =0 ;list_for_each (node, &input_dev_class.interfaces) { +if (node == v) +break ; + i++; + } - handler = to_input_handler(container_of(node, struct class_interface, node)); +seq_printf (seq,"N: Number=%d Name=%s" , i, handler->name); +if (handler->fops) +seq_printf (seq," Minor=%d" , handler->minor); +seq_putc (seq,'\n' ); -if (handler->fops) - len =sprintf (buf,"N: Number=%d Name=%s Minor=%d\n" , - i++, handler->name, handler->minor); -else - len =sprintf (buf,"N: Number=%d Name=%s\n" , - i++, handler->name); - - at += len; - -if (at >= pos) { -if (!*start) { - *start = buf + (pos - (at - len)); - cnt = at - pos; - }else cnt += len; - buf += len; -if (cnt >= count) -break ; - } - } +return 0 ; +} -if (node == &input_dev_class.interfaces) - *eof =1 ; +static struct seq_operations input_handlers_seq_ops = { + .start = input_handlers_seq_start, + .next = input_handlers_seq_next, + .stop = input_handlers_seq_stop, + .show = input_handlers_seq_show, +}; -return (count > cnt) ? cnt : count; +static int input_proc_handlers_open (struct inode *inode,struct file *file) +{ +return seq_open (file, &input_handlers_seq_ops); } -static struct file_operations input_fileops; +static struct file_operations input_handlers_fileops = { + .owner =THIS_MODULE , + .open = input_proc_handlers_open, + .read = seq_read, + .llseek = seq_lseek, + .release = seq_release, +};static int __init input_proc_init (void ) {
@@ -672,20 +734,19 @@ static int __init input_proc_init(void) proc_bus_input_dir->owner =THIS_MODULE ; - entry =create_proc_read_entry ("devices" ,0 , proc_bus_input_dir, input_devices_read,NULL ); + entry =create_proc_entry ("devices" ,0 , proc_bus_input_dir);if (!entry) goto fail1; entry->owner =THIS_MODULE ; - input_fileops = *entry->proc_fops; - entry->proc_fops = &input_fileops; - entry->proc_fops->poll = input_devices_poll; + entry->proc_fops = &input_devices_fileops; - entry =create_proc_read_entry ("handlers" ,0 , proc_bus_input_dir, input_handlers_read,NULL ); + entry =create_proc_entry ("handlers" ,0 , proc_bus_input_dir);if (!entry) goto fail2; entry->owner =THIS_MODULE ; + entry->proc_fops = &input_handlers_fileops;return 0 ;
A message that is not in the archive (sent off-list or not yet received): [email protected]
Re: [patch 16/28] drivers/usb/input: convert to dynamic input_dev allocation
Quoted 2 lines · Dmitry Torokhov
Input: convert
drivers/iusb/inputto dynamicinput_devallocation
The absfuzz initialisation in kbtab_probe() got lost.
Re: [patch 16/28] drivers/usb/input: convert to dynamic input_dev allocation
Quoted 6 lines · Andrew Morton
Quoted 2 lines · Dmitry Torokhov
Input: convert
drivers/iusb/inputto dynamicinput_devallocationThe absfuzz initialisation in
kbtab_probe()got lost.
Looks fine here:
+ input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0);
+ input_set_abs_params(input_dev, ABS_X, 0, 0x1750, 4, 0);
^^^Is there something in your tree that not in Linus's yet?
Signature · 1 line
Dmitry
Re: [patch 16/28] drivers/usb/input: convert to dynamic input_dev allocation
Quoted 11 lines · Dmitry Torokhov
Quoted 6 lines · Andrew Morton
Quoted 2 lines · Dmitry Torokhov
Input: convert
drivers/iusb/inputto dynamicinput_devallocationThe absfuzz initialisation in
kbtab_probe()got lost.Looks fine here:
Review
Quoted 3 lines
(quoted diff) +2
-0+ input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0); + input_set_abs_params(input_dev, ABS_X, 0, 0x1750, 4, 0); ^^^
Oh. You mean they replace these?
- kbtab->dev.absfuzz[ABS_X] = 4;
- kbtab->dev.absfuzz[ABS_Y] = 4;
Not a step forward in readability?
Quoted 3 lines
Is there something in your tree that not in Linus's yet?
Yeah, some stuff, that's why I noticed.
Re: [patch 16/28] drivers/usb/input: convert to dynamic input_dev allocation
Quoted 21 lines · Andrew Morton
Quoted 11 lines · Dmitry Torokhov
Quoted 6 lines · Andrew Morton
Quoted 2 lines · Dmitry Torokhov
Input: convert
drivers/iusb/inputto dynamicinput_devallocationThe absfuzz initialisation in
kbtab_probe()got lost.Looks fine here:
Review
Quoted 3 lines
(quoted diff) +2
-0+ input_set_abs_params(input_dev, ABS_X, 0, 0x2000, 4, 0); + input_set_abs_params(input_dev, ABS_X, 0, 0x1750, 4, 0); ^^^Oh. You mean they replace these?
(quoted diff) +0
-2- kbtab->dev.absfuzz[ABS_X] = 4; - kbtab->dev.absfuzz[ABS_Y] = 4;
Quoted 2 lines
Not a step forward in readability?
Depends... It's much more compact so quite often you can see entire device specification on one screen which is nice IMHO. Just remeber "min, max, fuzz, flat" ;)
Signature · 1 line
Dmitry