Re: usb hid: reset NumLock

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Pete Zaitcev
Date: Monday, April 2, 2007 - 4:12 pm

On Mon, 2 Apr 2007 16:48:24 +0200 (CEST), Jiri Kosina <jkosina@suse.cz> wrote:


How about this?

diff --git a/drivers/usb/input/hid-core.c b/drivers/usb/input/hid-core.c
index 827a75a..23b1e70 100644
--- a/drivers/usb/input/hid-core.c
+++ b/drivers/usb/input/hid-core.c
@@ -545,6 +545,45 @@ void usbhid_init_reports(struct hid_device *hid)
 		warn("timeout initializing reports");
 }
 
+/*
+ * Reset LEDs which BIOS might have left on. For now, just NumLock (0x01).
+ */
+
+static int hid_find_field_early(struct hid_device *hid, unsigned int page,
+    unsigned int hid_code, struct hid_field **pfield)
+{
+	struct hid_report *report;
+	struct hid_field *field;
+	struct hid_usage *usage;
+	int i, j;
+
+	list_for_each_entry(report, &hid->report_enum[HID_OUTPUT_REPORT].report_list, list) {
+		for (i = 0; i < report->maxfield; i++) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; j++) {
+				usage = &field->usage[j];
+				if ((usage->hid & HID_USAGE_PAGE) == page &&
+				    (usage->hid & 0xFFFF) == hid_code) {
+					*pfield = field;
+					return j;
+				}
+			}
+		}
+	}
+	return -1;
+}
+
+static void usbhid_set_leds(struct hid_device *hid)
+{
+	struct hid_field *field;
+	int offset;
+
+	if ((offset = hid_find_field_early(hid, HID_UP_LED, 0x01, &field)) != -1) {
+		hid_set_field(field, offset, 0);
+		usbhid_submit_report(hid, field->report, USB_DIR_OUT);
+	}
+}
+
 #define USB_VENDOR_ID_GTCO		0x078c
 #define USB_DEVICE_ID_GTCO_90		0x0090
 #define USB_DEVICE_ID_GTCO_100		0x0100
@@ -765,6 +804,9 @@ void usbhid_init_reports(struct hid_device *hid)
 #define USB_VENDOR_ID_SONY			0x054c
 #define USB_DEVICE_ID_SONY_PS3_CONTROLLER	0x0268
 
+#define USB_VENDOR_ID_DELL		0x413c
+#define USB_DEVICE_ID_DELL_W7658	0x2005
+
 /*
  * Alphabetically sorted blacklist by quirk type.
  */
@@ -947,6 +989,8 @@ static const struct hid_blacklist {
 
 	{ USB_VENDOR_ID_CIDC, 0x0103, HID_QUIRK_IGNORE },
 
+	{ USB_VENDOR_ID_DELL, USB_DEVICE_ID_DELL_W7658, HID_QUIRK_RESET_LEDS },
+
 	{ 0, 0 }
 };
 
@@ -1334,6 +1378,8 @@ static int hid_probe(struct usb_interface *intf, const struct usb_device_id *id)
 
 	usbhid_init_reports(hid);
 	hid_dump_device(hid);
+	if (hid->quirks & HID_QUIRK_RESET_LEDS)
+		usbhid_set_leds(hid);
 
 	if (!hidinput_connect(hid))
 		hid->claimed |= HID_CLAIMED_INPUT;
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 8c97d4d..3e8dcb0 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -269,6 +269,7 @@ struct hid_item {
 #define HID_QUIRK_SONY_PS3_CONTROLLER		0x00080000
 #define HID_QUIRK_LOGITECH_S510_DESCRIPTOR	0x00100000
 #define HID_QUIRK_DUPLICATE_USAGES		0x00200000
+#define HID_QUIRK_RESET_LEDS			0x00400000
 
 /*
  * This is the global environment of the parser. This information is

I wasn't sure where to place the function, so I just put it above its
user, to signify that it's special-casing. Also, it's unclear where
to put the quirk entry and defines. There's a comment saying that they
are sorted alphabetically by quirk, but apparently the order was violated
with more recent additions.

-- Pete
-
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
usb hid: reset NumLock, Pete Zaitcev, (Fri Mar 30, 10:59 am)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Fri Mar 30, 11:14 am)
Re: usb hid: reset NumLock, Pete Zaitcev, (Fri Mar 30, 12:54 pm)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Fri Mar 30, 1:29 pm)
Re: usb hid: reset NumLock, Jiri Kosina, (Sat Mar 31, 12:35 pm)
Re: usb hid: reset NumLock, Pete Zaitcev, (Sat Mar 31, 3:43 pm)
Re: usb hid: reset NumLock, Pekka Enberg, (Sun Apr 1, 4:49 am)
Re: usb hid: reset NumLock, Pete Zaitcev, (Sun Apr 1, 9:16 am)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Sun Apr 1, 9:10 pm)
Re: usb hid: reset NumLock, Pete Zaitcev, (Sun Apr 1, 10:24 pm)
Re: usb hid: reset NumLock, Jiri Kosina, (Mon Apr 2, 7:48 am)
Re: usb hid: reset NumLock, Pete Zaitcev, (Mon Apr 2, 4:12 pm)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Mon Apr 2, 10:04 pm)
Re: usb hid: reset NumLock, Pete Zaitcev, (Mon Apr 2, 11:24 pm)
Re: usb hid: reset NumLock, Jiri Kosina, (Tue Apr 3, 1:52 am)
Re: [linux-usb-devel] usb hid: reset NumLock, Robert Marquardt, (Tue Apr 3, 1:57 am)
Re: usb hid: reset NumLock, Jiri Kosina, (Tue Apr 3, 2:32 am)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Wed Apr 4, 8:24 pm)
Re: usb hid: reset NumLock, Jiri Kosina, (Thu Apr 5, 1:50 am)
Re: usb hid: reset NumLock, Pete Zaitcev, (Thu Apr 5, 1:38 pm)
Re: usb hid: reset NumLock, Dmitry Torokhov, (Thu Apr 5, 1:54 pm)
Re: usb hid: reset NumLock, Pete Zaitcev, (Thu Apr 5, 2:22 pm)