full autosuspend for USB HID
PATCH 1/1 full autosuspend for USB HID
Hi,
this patch introduces full autosuspend support for USB HID devices that support remote wakeup. It is quite large a patch because keyboards are hard to handle. That's because keyboards are also output devices. The current support for autosuspend in usbhid is based on the pm counters and works on an open/close base. This patch uses the last busy timer based approach.
It does the following changes:
- mark the device busy when input data arrives
- extend the suspend() method to fail autosuspend if
a - a key is being pressed as keyboards usually fail to wakeup on key release b - an LED is on as that makes suspension detectable to the user (optional) c - output is being performed
- defer output to a suspended device (in interrupt)
- handle deferred output in resume()
- trigger wakeup if deferred output is queued
- rework of locking for open/close to make sure suspend/resume have reliable state
- unify locking for the output code path
- handle resets correctly
- synchronize power management and error handling
- request remote wakeup
The basic strategy for input is to keep the device marked busy. The bulk of the patch is for output, the work around for the release stuff and synchronization.
Regards
Oliver
---
drivers/hid/hid-core.c +16 -0
@@ -1006,6 +1006,22 @@ int hid_input_report(struct hid_device * }EXPORT_SYMBOL_GPL (hid_input_report); +int hid_check_keys_pressed (struct hid_device *hid) +{ +struct hid_input *hidinput; +int i; + +list_for_each_entry (hidinput, &hid->inputs, list) { +for (i =0 ; i <BITS_TO_LONGS (KEY_MAX ); i++) +if (hidinput->input->key[i]) +return 1 ; + } + +return 0 ; +} + +EXPORT_SYMBOL_GPL (hid_check_keys_pressed); +static int __init hid_init (void ) {return hidraw_init ();
drivers/hid/usbhid/hiddev.c +12 -4
@@ -249,10 +249,12 @@ static int hiddev_release(struct inode *spin_unlock_irqrestore (&list->hiddev->list_lock, flags);if (!--list->hiddev->open) { -if (list->hiddev->exist) +if (list->hiddev->exist) {usbhid_close (list->hiddev->hid); -else +usbhid_put_power (list->hiddev->hid); + }else {kfree (list->hiddev); + } }kfree (list);
@@ -267,6 +269,7 @@ static int hiddev_open(struct inode *ino {struct hiddev_list *list;unsigned long flags; +int res;int i =iminor (inode) -HIDDEV_MINOR_BASE ;
@@ -285,8 +288,13 @@ static int hiddev_open(struct inode *ino file->private_data = list;if (!list->hiddev->open++) -if (list->hiddev->exist) -usbhid_open (hiddev_table[i]->hid); +if (list->hiddev->exist) { +struct hid_device *hid = hiddev_table[i]->hid; + res =usbhid_get_power (hid); +if (res <0 ) +return -EIO ; +usbhid_open (hid); + }return 0 ; }
drivers/hid/usbhid/usbhid.h +6 -3
@@ -37,7 +37,10 @@ int usbhid_wait_io(struct hid_device* hivoid usbhid_close (struct hid_device *hid);int usbhid_open (struct hid_device *hid);void usbhid_init_reports (struct hid_device *hid); -void usbhid_submit_report (struct hid_device *hid,struct hid_report *report,unsigned char dir); +void usbhid_submit_report +(struct hid_device *hid,struct hid_report *report,unsigned char dir); +int usbhid_get_power (struct hid_device *hid); +void usbhid_put_power (struct hid_device *hid);/* * USB-specific HID struct, to be pointed to
@@ -64,20 +67,20 @@ struct usbhid_device {unsigned char ctrlhead, ctrltail;/* Control fifo head & tail */ char *ctrlbuf;/* Control buffer */ dma_addr_t ctrlbuf_dma;/* Control buffer dma */ -spinlock_t ctrllock;/* Control fifo spinlock */ struct urb *urbout;/* Output URB */ struct hid_report *out[HID_CONTROL_FIFO_SIZE ];/* Output pipe fifo */ unsigned char outhead, outtail;/* Output pipe fifo head & tail */ char *outbuf;/* Output buffer */ dma_addr_t outbuf_dma;/* Output buffer dma */ -spinlock_t outlock;/* Output fifo spinlock */ +spinlock_t outputlock;/* Output fifo spinlock */ unsigned long iofl;/* I/O flags (CTRL_RUNNING, OUT_RUNNING) */ struct timer_list io_retry;/* Retry timer */ unsigned long stop_retry;/* Time to give up, in jiffies */ unsigned int retry_delay;/* Delay length in ms */ struct work_struct reset_work;/* Task context for resets */ +struct work_struct restart_work;/* waking up for output to be done in a task */ wait_queue_head_t wait;/* For sleeping */ };
include/linux/hid.h +4 -0
@@ -425,6 +425,9 @@ struct hid_control_fifo {#define HID_SUSPENDED 5#define HID_CLEAR_HALT 6#define HID_DISCONNECTED 7 +#define HID_REPORTED_IDLE 8 +#define HID_KEYS_PRESSED 9 +#define HID_LED_ON 10struct hid_input {struct list_head list;
@@ -535,6 +538,7 @@ int hidinput_apple_event(struct hid_devivoid hid_output_report (struct hid_report *report,__u8 *data);void hid_free_device (struct hid_device *device);struct hid_device *hid_parse_report (__u8 *start,unsigned size); +int hid_check_keys_pressed (struct hid_device *hid);/* HID quirks API */ u32 usbhid_lookup_quirk (const u16 idVendor,const u16 idProduct);
drivers/hid/usbhid/hid-core.c +313 -71
632 lines not on this page · raw message
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
A message that is not in the archive (sent off-list or not yet received): 200805071450.39499.oliver-GvhC2dPhHPQdnm+yROfE0A@public.gmane.org
Quoted 25 lines · Oliver Neukum
Hi,
this patch introduces full autosuspend support for USB HID devices that support remote wakeup. It is quite large a patch because keyboards are hard to handle. That's because keyboards are also output devices. The current support for autosuspend in usbhid is based on the pm counters and works on an open/close base. This patch uses the last busy timer based approach.
It does the following changes:
- mark the device busy when input data arrives
- extend thesuspend()method to fail autosuspend if
a - a key is being pressed as keyboards usually fail to wakeup on key release b - an LED is on as that makes suspension detectable to the user (optional) c - output is being performed
- defer output to a suspended device (in interrupt)
- handle deferred output inresume()
- trigger wakeup if deferred output is queued
- rework of locking for open/close to make sure suspend/resume have reliable state
- unify locking for the output code path
- handle resets correctly
- synchronize power management and error handling
- request remote wakeup
Quoted 2 lines
The basic strategy for input is to keep the device marked busy. The bulk of the patch is for output, the work around for the release stuff and synchronization.
One big problem we always faced with autosuspend for keyboards is that most of them were not able to autoresume quickly enough to avoid losing keystrokes. Isn't that still a problem?
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Quoted 3 lines · Alan Stern
One big problem we always faced with autosuspend for keyboards is that most of them were not able to autoresume quickly enough to avoid losing keystrokes. Isn't that still a problem?
Hi Alan,
it definitely is, but with autosuspend defaulting to off, and possibility of whitelisting known-good keyboards, we (or HAL, respectively) can still turn autosupend on those that are known to work properly, and still save some power on some systems.
Unfortunately, I vaguely remember that some keyboards exposed the behaviors only when connected to certain HCI controllers, so building the whitelist might not be completely trivial.
Signature · 2 lines
Jiri Kosina SUSE Labs
Quoted 8 lines · Jiri Kosina
Quoted 3 lines · Alan Stern
One big problem we always faced with autosuspend for keyboards is that most of them were not able to autoresume quickly enough to avoid losing keystrokes. Isn't that still a problem?
Hi Alan,
Quoted 8 lines
it definitely is, but with autosuspend defaulting to off, and possibility of whitelisting known-good keyboards, we (or HAL, respectively) can still turn autosupend on those that are known to work properly, and still save some power on some systems.
Unfortunately, I vaguely remember that some keyboards exposed the behaviors only when connected to certain HCI controllers, so building the whitelist might not be completely trivial.
Can we find out what Windows and OS-X do and copy them?
Alan Stern
Quoted 4 lines · Alan Stern
Quoted 3 lines
Unfortunately, I vaguely remember that some keyboards exposed the behaviors only when connected to certain HCI controllers, so building the whitelist might not be completely trivial.
Can we find out what Windows and OS-X do and copy them?
Actually I don't think they do runtime power management on USB HID devices. At least I have never seen any windows machine to make the USB keyboard LEDs to go off :)
Signature · 2 lines
Jiri Kosina SUSE Labs
A message that is not in the archive (sent off-list or not yet received): Pine.LNX.4.64.0805071758240.11363-YCXOAqNspd+N3ZZ/[email protected]
Quoted 10 lines · Jiri Kosina
Quoted 4 lines · Alan Stern
Quoted 3 lines
Unfortunately, I vaguely remember that some keyboards exposed the behaviors only when connected to certain HCI controllers, so building the whitelist might not be completely trivial.
Can we find out what Windows and OS-X do and copy them?
Actually I don't think they do runtime power management on USB HID devices. At least I have never seen any windows machine to make the USB keyboard LEDs to go off :)
I have a vague memory of seeing somewhere a list of keyboard types that one or the other of those OSs _would_ autosuspend. It was pretty short, including only the Apple keyboard and a couple of others.
Unfortunately I don't remember _where_ I saw that list...
Alan Stern
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Am Mittwoch 07 Mai 2008 17:57:14 schrieb Alan Stern:
Quoted 6 lines
Quoted 3 lines
Unfortunately, I vaguely remember that some keyboards exposed the behaviors only when connected to certain HCI controllers, so building the whitelist might not be completely trivial.
Can we find out what Windows and OS-X do and copy them?
Windows has a registry and *.ini files which control which HID devices get power management.
Regards
Oliver
Am Mittwoch 07 Mai 2008 17:46:38 schrieb Alan Stern:
Quoted 6 lines
Quoted 2 lines
The basic strategy for input is to keep the device marked busy. The bulk of the patch is for output, the work around for the release stuff and synchronization.
One big problem we always faced with autosuspend for keyboards is that most of them were not able to autoresume quickly enough to avoid losing keystrokes. Isn't that still a problem?
For some keyboards that seems to be a limitation of the hardware nothing can be done about. Others do work, for example 046d:c312. Generally as autosuspend is now disabled by default this is user space's problem. IMHO the main use case for autosuspend of keyboards will be synchronized with the screen saver.
Regards
Oliver
--
To unsubscribe from this list: send the line "unsubscribe linux-input" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html