Skip to contentSkip to conversation

From: Rezwanul Kabir <[email protected]>

PATCH Applied Matthew Garrett 4 participants 6 messages Nov 2, 2009 – Dec 10, 2009 1 message not in the archive

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

PATCH 1/1 From: Rezwanul Kabir <[email protected]>

dell-wmi: Add support for new Dell systems

Newer Dell systems support HotKey features differently from legacy systems. A new vendor specifc HotKey SMBIOS table (Type 0xB2) is defined. This table contains a mapping between scancode and the corresponding predefined keyfunction ( i.e. keycode).. Also, a new ACPI-WMI event type (called KeyIDList) with a value of 0x0010 is defined. Any BIOS containing 0xB2 table will send hotkey notifications using KeyIDList event.

This is Rezwanul's patch, updated to ensure that brightness events are not sent if the backlight is controlled via ACPI and with the default keycode for the display output switching altered to match desktop expectations.

---
 drivers/platform/x86/dell-wmi.c |  129 +++++++++++++++++++++++++++++++++++----
 1 files changed, 116 insertions(+), 13 deletions(-)
drivers/platform/x86/dell-wmi.c +116 -13
index 0f900cc..67f3fe7 100644
@@ -31,6 +31,7 @@
 #include <acpi/acpi_drivers.h>
 #include <linux/acpi.h>
 #include <linux/string.h>
+#include <linux/dmi.h>
 
 MODULE_AUTHOR("Matthew Garrett <[email protected]>");
 MODULE_DESCRIPTION("Dell laptop WMI hotkeys driver");
@@ -38,6 +39,8 @@ MODULE_LICENSE("GPL");
 
 #define DELL_EVENT_GUID "9DBB5994-A997-11DA-B012-B622A1EF5492"
 
+static int acpi_video;
+
 MODULE_ALIAS("wmi:"DELL_EVENT_GUID);
 
 struct key_entry {
@@ -54,7 +57,7 @@ enum { KE_KEY, KE_SW, KE_IGNORE, KE_END };
  * via the keyboard controller so should not be sent again.
  */
 
-static struct key_entry dell_wmi_keymap[] = {
+static struct key_entry dell_legacy_wmi_keymap[] = {
 	{KE_KEY, 0xe045, KEY_PROG1},
 	{KE_KEY, 0xe009, KEY_EJECTCD},
 
@@ -72,7 +75,7 @@ static struct key_entry dell_wmi_keymap[] = {
 
 	/* The next device is at offset 6, the active devices are at
 	   offset 8 and the attached devices at offset 10 */
-	{KE_KEY, 0xe00b, KEY_DISPLAYTOGGLE},
+	{KE_KEY, 0xe00b, KEY_SWITCHVIDEOMODE},
 
 	{KE_IGNORE, 0xe00c, KEY_KBDILLUMTOGGLE},
 
@@ -96,6 +99,47 @@ static struct key_entry dell_wmi_keymap[] = {
 	{KE_END, 0}
 };
 
+static bool dell_new_hk_type;
+
+struct dell_new_keymap_entry {
+	u16 scancode;
+	u16 keycode;
+};
+
+struct dell_hotkey_table {
+	struct dmi_header header;
+	struct dell_new_keymap_entry keymap[];
+
+};
+
+static struct key_entry *dell_new_wmi_keymap;
+
+static u16 bios_to_linux_keycode[256] = {
+
+	KEY_MEDIA,	KEY_NEXTSONG,	KEY_PLAYPAUSE, KEY_PREVIOUSSONG,
+	KEY_STOPCD,	KEY_UNKNOWN,	KEY_UNKNOWN,	KEY_UNKNOWN,
+	KEY_WWW,	KEY_UNKNOWN,	KEY_VOLUMEDOWN, KEY_MUTE,
+	KEY_VOLUMEUP,	KEY_UNKNOWN,	KEY_BATTERY,	KEY_EJECTCD,
+	KEY_UNKNOWN,	KEY_SLEEP,	KEY_PROG1, KEY_BRIGHTNESSDOWN,
+	KEY_BRIGHTNESSUP,	KEY_UNKNOWN,	KEY_KBDILLUMTOGGLE,
+	KEY_UNKNOWN,	KEY_SWITCHVIDEOMODE,	KEY_UNKNOWN, KEY_UNKNOWN,
+	KEY_SWITCHVIDEOMODE,	KEY_UNKNOWN,	KEY_UNKNOWN, KEY_PROG2,
+	KEY_UNKNOWN, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
+	KEY_PROG3
+};
+
+
+static struct key_entry *dell_wmi_keymap = dell_legacy_wmi_keymap;
+
 static struct input_dev *dell_wmi_input_dev;
 
 static struct key_entry *dell_wmi_get_entry_by_scancode(int code)
@@ -164,24 +208,78 @@ static void dell_wmi_notify(u32 value, void *context)
 	obj = (union acpi_object *)response.pointer;
 
 	if (obj && obj->type == ACPI_TYPE_BUFFER) {
-		int *buffer = (int *)obj->buffer.pointer;
-		/*
-		 *  The upper bytes of the event may contain
-		 *  additional information, so mask them off for the
-		 *  scancode lookup
-		 */
-		key = dell_wmi_get_entry_by_scancode(buffer[1] & 0xFFFF);
-		if (key) {
+		int reported_key;
+		u16 *buffer_entry = (u16 *)obj->buffer.pointer;
+		if (dell_new_hk_type && (buffer_entry[1] != 0x10)) {
+			printk(KERN_INFO "dell-wmi: Received unknown WMI event"
+					 " (0x%x)\n", buffer_entry[1]);
+			return;
+		}
+
+		if (dell_new_hk_type)
+			reported_key = (int)buffer_entry[2];
+		else
+			reported_key = (int)buffer_entry[1] & 0xffff;
+
+		key = dell_wmi_get_entry_by_scancode(reported_key);
+
+		if (!key) {
+			printk(KERN_INFO "dell-wmi: Unknown key %x pressed\n",
+				reported_key);
+		} else if ((key->keycode == KEY_BRIGHTNESSUP ||
+			    key->keycode == KEY_BRIGHTNESSDOWN) && acpi_video) {
+			/* Don't report brightness notifications that will also
+			 * come via ACPI */
+			return;
+		} else {
 			input_report_key(dell_wmi_input_dev, key->keycode, 1);
 			input_sync(dell_wmi_input_dev);
 			input_report_key(dell_wmi_input_dev, key->keycode, 0);
 			input_sync(dell_wmi_input_dev);
-		} else if (buffer[1] & 0xFFFF)
-			printk(KERN_INFO "dell-wmi: Unknown key %x pressed\n",
-			       buffer[1] & 0xFFFF);
+		}
 	}
 }
 
+
+static void setup_new_hk_map(const struct dmi_header *dm)
+{
+
+	int i;
+	int hotkey_num = (dm->length-4)/sizeof(struct dell_new_keymap_entry);
+	struct dell_hotkey_table *table =
+		container_of(dm, struct dell_hotkey_table, header);
+
+	dell_new_wmi_keymap = kzalloc((hotkey_num+1) *
+				      sizeof(struct key_entry), GFP_KERNEL);
+
+	for (i = 0; i < hotkey_num; i++) {
+		dell_new_wmi_keymap[i].type = KE_KEY;
+		dell_new_wmi_keymap[i].code = table->keymap[i].scancode;
+		dell_new_wmi_keymap[i].keycode =
+			(table->keymap[i].keycode > 255) ? 0 :
+			bios_to_linux_keycode[table->keymap[i].keycode];
+	}
+
+	dell_new_wmi_keymap[i].type = KE_END;
+	dell_new_wmi_keymap[i].code = 0;
+	dell_new_wmi_keymap[i].keycode = 0;
+
+	dell_wmi_keymap = dell_new_wmi_keymap;
+
+}
+
+
+static void find_hk_type(const struct dmi_header *dm, void *dummy)
+{
+
+	if ((dm->type == 0xb2) && (dm->length > 6)) {
+		dell_new_hk_type = true;
+		setup_new_hk_map(dm);
+	}
+
+}
+
+
 static int __init dell_wmi_input_setup(void)
 {
 	struct key_entry *key;
@@ -226,6 +324,9 @@ static int __init dell_wmi_init(void)
 	int err;
 
 	if (wmi_has_guid(DELL_EVENT_GUID)) {
+
+		dmi_walk(find_hk_type, NULL);
+
 		err = dell_wmi_input_setup();
 
 		if (err)
@@ -240,6 +341,8 @@ static int __init dell_wmi_init(void)
 			return err;
 		}
 
+		acpi_video = acpi_video_backlight_support();
+
 	} else
 		printk(KERN_WARNING "dell-wmi: No known WMI GUID found\n");
 
Signature · 1 line
1.6.5.1
#1 lore raw

Oops. I seem to have got the subject and attribution the wrong way round there. Len, can you fix that or should I resend?

Signature · 1 line
Matthew Garrett | [email protected]
reviewer Applied
#2 lore raw

Re: [PATCH] dell-wmi: Add support for new Dell systems ([PATCH] From: Rezwanul Kabir <[email protected]>)

applied

thanks,
Len Brown, Intel Open Source Technology Center

#3 lore raw

Re: [[email protected]: [PATCH] From: Rezwanul Kabir <[email protected]>]

In reply to Matthew Garrett
Quoted 4 lines
Quoted 4 lines

dell-wmi: Add support for new Dell systems

Newer Dell systems support HotKey features differently from legacy systems. A new vendor specifc HotKey SMBIOS table (Type 0xB2) is

[snip]

I get improved, but still not flawless, behavior with this patch, testing on my Dell E4300 with bios A05 (tested on top of approximately Ubuntu's 2.6.31-14.47 which is more or less 2.6.31.4).

[    7.068589] input: Dell WMI hotkeys as /devices/virtual/input/input8
[  621.845305] dell-wmi: Received unknown WMI event 0x11
[ 1580.825651] dell-wmi: Received unknown WMI event 0x11
[ 1585.239914] dell-wmi: Received unknown WMI event 0x11
[ 1586.675563] dell-wmi: Received unknown WMI event 0x11
[ 1587.442542] dell-wmi: Received unknown WMI event 0x11
[ 1623.471288] keyboard.c: can't emulate rawmode for keycode 241
[ 1623.471301] keyboard.c: can't emulate rawmode for keycode 241
[ 1626.035593] keyboard.c: can't emulate rawmode for keycode 241
[ 1626.035605] keyboard.c: can't emulate rawmode for keycode 241

The keyboard.c complaints are from when I hit Fn-F8 (display switch). I can trigger the same complaint with Fn-Left (display brightness auto), with code 240.

I don't see keyboard.c complaints from Fn-Right, which toggles the keyboard illumination and reports code 228.

I don't know what event causes the "event 0x11" complaint. It seems to be purely cosmetic and not directly tied to user interaction?

Fn-F8, Display Toggle, gives code 241 on the WMI event8 *and* code 227 on /dev/input/event4 "Video Bus". That seems ... wrong.

There is an interesting behavior with Fn-Up and Fn-Down -- normally they do not trigger events on /dev/input/event8 although I can see ACPI interrupt count increasing in /proc/interrupts. However there is some state that I can toggle after about 5 minutes of futzing -- I still haven't figured out what the toggle is -- that causes event8 to show Brightness key events:

Event: time 1257214081.248619, type 1 (Key), code 236 (?), value 0
Event: time 1257214081.248621, -------------- Report Sync ------------
Event: time 1257214087.837272, type 1 (Key), code 240 (Unknown), value 1
Event: time 1257214087.837278, -------------- Report Sync ------------
Event: time 1257214087.837282, type 1 (Key), code 240 (Unknown), value 0
Event: time 1257214087.837284, -------------- Report Sync ------------
Event: time 1257214089.908451, type 1 (Key), code 225 (Brightness up), value 1
Event: time 1257214089.908457, -------------- Report Sync ------------
Event: time 1257214089.908460, type 1 (Key), code 225 (Brightness up), value 0
Event: time 1257214089.908462, -------------- Report Sync ------------
Event: time 1257214095.235095, type 1 (Key), code 240 (Unknown), value 1
Event: time 1257214095.235102, -------------- Report Sync ------------
Event: time 1257214095.235106, type 1 (Key), code 240 (Unknown), value 0
Event: time 1257214095.235108, -------------- Report Sync ------------ ^C

Other keys of interest:

Fn-F3, a Battery glyph, gives keycode 236
Fn-F2, Battery with lighting bolt, gives no WMI key event but does increase /proc/interrupts' ACPI entry
Fn-F7, "DCP", gives code 148 (Prog1)

Volume keys and mute don't show WMI events (they work fine through the 8042 keyboard channel), but /dev/input/event8 does have event codes for them.

-andy

#4 lore raw

Re: [[email protected]: [PATCH] From: Rezwanul Kabir <[email protected]>]

Quoted 3 lines · Andy Isaacson

The keyboard.c complaints are from when I hit Fn-F8 (display switch). I can trigger the same complaint with Fn-Left (display brightness auto), with code 240.

Hm. 241 is KEY_VIDEO_NEXT - I thought I'd changed that to be KEY_SWITCHVIDEOMODE? 240 is KEY_UNKNOWN. I don't think we've currently got an appropriate key to map the ALS button to.

Quoted 2 lines

I don't know what event causes the "event 0x11" complaint. It seems to be purely cosmetic and not directly tied to user interaction?

On my test system, that's the "battery with lightning flash" key. I have no idea what it's meant to do, or how we're meant to interpret that event.

Quoted 2 lines

Fn-F8, Display Toggle, gives code 241 on the WMI event8 *and* code 227 on /dev/input/event4 "Video Bus". That seems ... wrong.

Yup. Unfortunately on my system, it only gets delivered via WMI and not via ACPI, so doing the same thing as for the brightness keys doesn't look like it'll work.

Signature · 1 line
Matthew Garrett | [email protected]
#5 lore raw

Re: [[email protected]: [PATCH] From: Rezwanul Kabir <[email protected]>]

Right, so, brown paper bag time... my testing last night was with completely the wrong kernel, with a previous version of the patch.

Quoted 3 lines

Hm. 241 is KEY_VIDEO_NEXT - I thought I'd changed that to be KEY_SWITCHVIDEOMODE? 240 is KEY_UNKNOWN. I don't think we've currently got an appropriate key to map the ALS button to.

Verified with the correct kernel on E4300 with GMA, I get 227 on the WMI input event device and 227 on the ACPI Video Bus device.

Quoted 6 lines
Quoted 2 lines

I don't know what event causes the "event 0x11" complaint. It seems to be purely cosmetic and not directly tied to user interaction?

On my test system, that's the "battery with lightning flash" key. I have no idea what it's meant to do, or how we're meant to interpret that event.

Yes, Fn-F2 (battery with lighting bolt) is the trigger for the "Received unknown WMI event (0x11)" message. It also toggles battery charge -- if I press it when the battery is charging, the battery stops charging:
grep 'charging state' /proc/acpi/battery/BAT0/state
charging state: charged

Pressing Fn-F2 again gets the battery charging again and triggers another "unknown WMI event (0x11)" message.

Quoted 6 lines
Quoted 2 lines

Fn-F8, Display Toggle, gives code 241 on the WMI event8 *and* code 227 on /dev/input/event4 "Video Bus". That seems ... wrong.

Yup. Unfortunately on my system, it only gets delivered via WMI and not via ACPI, so doing the same thing as for the brightness keys doesn't look like it'll work.

On an E6400 with NVidia graphics, I do get 227 on WMI and do not have a Video Bus object (but the VID1 event does show up in acpi_listen). Appears to be a difference between laptops with Intel GMA versus NVidia, sigh.

so... condition delivery of KEY_SWITCHVIDEOMODE on whether the videobus object is present? Seems kinda nasty...

-andy