Skip to contentSkip to conversation

even newer version of USB HID autosuspend

PATCH Oliver Neukum 3 participants 7 messages Oct 5, 2007 – Oct 8, 2007

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

Hi,

this version fixes the "once failed to suspend, never try again" bug.

Please review and/or test.
This leaves me with a planning difficulty. For keyboards it is not fully transparent. The LEDs are switched off when then keyboard is suspended. Should I now implement a mode where active LEDs block suspension and if so, how do I switch it on?

Regards
Oliver
----

drivers/hid/hid-core.c +16 -0
@@ -990,5 +990,21 @@ 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 < NBITS(KEY_MAX); i++)
+			if (hidinput->input->key[i])
+				return 1;
+	}
+
+	return 0;
+}
+
+EXPORT_SYMBOL_GPL(hid_check_keys_pressed);
+
 MODULE_LICENSE(DRIVER_LICENSE);
 
drivers/hid/usbhid/hid-core.c +314 -72

622 lines not on this page · raw message

drivers/hid/usbhid/hiddev.c +12 -4
@@ -248,10 +248,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);
@@ -266,6 +268,7 @@ static int hiddev_open(struct inode *ino
 {
 	struct hiddev_list *list;
 	unsigned long flags;
+	int res;
 
 	int i = iminor(inode) - HIDDEV_MINOR_BASE;
 
@@ -284,8 +287,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 +66 -34

113 lines not on this page · raw message

include/linux/hid.h +3 -0
@@ -410,6 +410,8 @@ struct hid_control_fifo {
 #define HID_RESET_PENDING	4
 #define HID_SUSPENDED		5
 #define HID_CLEAR_HALT		6
+#define HID_REPORTED_IDLE	7
+#define HID_KEYS_PRESSED	8
 
 struct hid_input {
 	struct list_head list;
@@ -514,6 +516,7 @@ void hid_input_field(struct hid_device *
 void 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);
#1 lore raw
Quoted 1 line · Oliver Neukum

Please review and/or test.

Hi Oliver,

thanks a lot for taking care of this, I will look at it and give it some testing ASAP.

I am still surprised how large this patch has to be ...

Quoted 4 lines

This leaves me with a planning difficulty. For keyboards it is not fully transparent. The LEDs are switched off when then keyboard is suspended. Should I now implement a mode where active LEDs block suspension and if so, how do I switch it on?

Maybe module parameter of usbhid could be used to specify the desired behavior?

Thanks,

Signature · 1 line
Jiri Kosina
#2 lore raw

Am Freitag 05 Oktober 2007 schrieb Jiri Kosina:

Quoted 10 lines · Oliver Neukum
Quoted 2 lines

Please review and/or test.

Hi Oliver,

thanks a lot for taking care of this, I will look at it and give it some testing ASAP.

I am still surprised how large this patch has to be ...

So was I.

1. The input layer insists on doing output from interrupt
2. HID has very elaborate error handling which complicates locking
3. A workaround for autorepeat is included

Quoted 7 lines
Quoted 4 lines

This leaves me with a planning difficulty. For keyboards it is not fully transparent. The LEDs are switched off when then keyboard is suspended. Should I now implement a mode where active LEDs block suspension and if so, how do I switch it on?

Maybe module parameter of usbhid could be used to specify the desired behavior?

Yes, but what are the desired behaviors?

Regards
Oliver

#3 lore raw
Quoted 10 lines · Oliver Neukum
Quoted 7 lines
Quoted 4 lines

This leaves me with a planning difficulty. For keyboards it is not fully transparent. The LEDs are switched off when then keyboard is suspended. Should I now implement a mode where active LEDs block suspension and if so, how do I switch it on?

Maybe module parameter of usbhid could be used to specify the desired behavior?

Yes, but what are the desired behaviors?

I'd say do not autosuspend keyboards (and other led-equipped input devices) unless user explicitely requested to do so and then turn the leds off. We have too many module parameters...

Signature · 1 line
Dmitry
#4 lore raw
Quoted 2 lines · Dmitry Torokhov

I'd say do not autosuspend keyboards (and other led-equipped input devices) unless user explicitely requested to do so

Hi Dmitry,

we *must* do it this way anyway, due to too many USB keyboards being utterly broken when it comes to suspend support.

Signature · 1 line
Jiri Kosina
#5 lore raw
In reply to Dmitry Torokhov

Am Sonntag 07 Oktober 2007 schrieb Dmitry Torokhov:

Quoted 6 lines · Oliver Neukum
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

This leaves me with a planning difficulty. For keyboards it is not fully transparent. The LEDs are switched off when then keyboard is suspended. Should I now implement a mode where active LEDs block suspension and if so, how do I switch it on?

Quoted 8 lines
Quoted 5 lines
Quoted 2 lines

Maybe module parameter of usbhid could be used to specify the desired behavior?

Yes, but what are the desired behaviors?

I'd say do not autosuspend keyboards (and other led-equipped input devices) unless user explicitely requested to do so and then turn the leds off.

So your answer is that we shouldn't care about the LEDs being on and suspend regardless?

Regards
Oliver

#6 lore raw
Quoted 8 lines · Oliver Neukum

Am Sonntag 07 Oktober 2007 schrieb Dmitry Torokhov:

Quoted 3 lines

I'd say do not autosuspend keyboards (and other led-equipped input devices) unless user explicitely requested to do so and then turn the leds off.

So your answer is that we shouldn't care about the LEDs being on and suspend regardless?

Yes, I think so.

Signature · 1 line
Dmitry