Commit e075b3c8 authored by Pali Rohár's avatar Pali Rohár Committed by Darren Hart

dell-wmi: Generate one sparse keymap for all machines

This patch reworks code for generating sparse keymap and processing WMI
events. It unifies procedure for generating sparse keymap and also unifies
big switch code for processing WMI events of different types. After this
patch dell-wmi driver does not differ between "old" and "new" hotkey type.

It constructs sparse keymap table with all WMI codes. It is because on some
laptops (e.g. Dell Latitude E6440) ACPI/firmware send both event types (old
and new).

Each WMI code in sparse keymap table is prefixed by 16bit event type, so it
does not change functionality on laptops with "old" hotkey support (those
without scancodes in DMI).

This allow us to distinguish between same WMI codes with different types in
sparse keymap. Thanks to this WMI events of type 0x0011 were moved from big
switch into sparse keymap table too.

This patch also fixes possible bug in parsing WMI event buffer introduced
in commit 5ea25597 ("dell-wmi: Add support for new Dell systems"). That
commit changed buffer type from int* to u16* without fixing code. More at:
http://lkml.iu.edu/hypermail/linux/kernel/1507.0/01950.htmlSigned-off-by: default avatarPali Rohár <pali.rohar@gmail.com>
Tested-by: default avatarMichał Kępień <kernel@kempniu.pl>
Reviewed-by: default avatarMichał Kępień <kernel@kempniu.pl>
Tested-by: default avatarGabriele Mazzotta <gabriele.mzt@gmail.com>
Signed-off-by: default avatarDarren Hart <dvhart@linux.intel.com>
parent 3237a861
...@@ -80,12 +80,13 @@ static const struct dmi_system_id dell_wmi_smbios_list[] __initconst = { ...@@ -80,12 +80,13 @@ static const struct dmi_system_id dell_wmi_smbios_list[] __initconst = {
}; };
/* /*
* Keymap for WMI events of type 0x0000
*
* Certain keys are flagged as KE_IGNORE. All of these are either * Certain keys are flagged as KE_IGNORE. All of these are either
* notifications (rather than requests for change) or are also sent * notifications (rather than requests for change) or are also sent
* via the keyboard controller so should not be sent again. * via the keyboard controller so should not be sent again.
*/ */
static const struct key_entry dell_wmi_keymap_type_0000[] __initconst = {
static const struct key_entry dell_wmi_legacy_keymap[] __initconst = {
{ KE_IGNORE, 0x003a, { KEY_CAPSLOCK } }, { KE_IGNORE, 0x003a, { KEY_CAPSLOCK } },
/* Key code is followed by brightness level */ /* Key code is followed by brightness level */
...@@ -183,12 +184,8 @@ static const struct key_entry dell_wmi_legacy_keymap[] __initconst = { ...@@ -183,12 +184,8 @@ static const struct key_entry dell_wmi_legacy_keymap[] __initconst = {
{ KE_IGNORE, 0xe0f7, { KEY_MUTE } }, { KE_IGNORE, 0xe0f7, { KEY_MUTE } },
{ KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } }, { KE_IGNORE, 0xe0f8, { KEY_VOLUMEDOWN } },
{ KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } }, { KE_IGNORE, 0xe0f9, { KEY_VOLUMEUP } },
{ KE_END, 0 }
}; };
static bool dell_new_hk_type;
struct dell_bios_keymap_entry { struct dell_bios_keymap_entry {
u16 scancode; u16 scancode;
u16 keycode; u16 keycode;
...@@ -202,6 +199,7 @@ struct dell_bios_hotkey_table { ...@@ -202,6 +199,7 @@ struct dell_bios_hotkey_table {
struct dell_dmi_results { struct dell_dmi_results {
int err; int err;
int keymap_size;
struct key_entry *keymap; struct key_entry *keymap;
}; };
...@@ -250,10 +248,12 @@ static const u16 bios_to_linux_keycode[256] __initconst = { ...@@ -250,10 +248,12 @@ static const u16 bios_to_linux_keycode[256] __initconst = {
}; };
/* /*
* Keymap for WMI events of type 0x0010
*
* These are applied if the 0xB2 DMI hotkey table is present and doesn't * These are applied if the 0xB2 DMI hotkey table is present and doesn't
* override them. * override them.
*/ */
static const struct key_entry dell_wmi_extra_keymap[] __initconst = { static const struct key_entry dell_wmi_keymap_type_0010[] __initconst = {
/* Fn-lock */ /* Fn-lock */
{ KE_IGNORE, 0x151, { KEY_RESERVED } }, { KE_IGNORE, 0x151, { KEY_RESERVED } },
...@@ -273,21 +273,39 @@ static const struct key_entry dell_wmi_extra_keymap[] __initconst = { ...@@ -273,21 +273,39 @@ static const struct key_entry dell_wmi_extra_keymap[] __initconst = {
{ KE_IGNORE, 0x155, { KEY_RESERVED } }, { KE_IGNORE, 0x155, { KEY_RESERVED } },
}; };
/*
* Keymap for WMI events of type 0x0011
*/
static const struct key_entry dell_wmi_keymap_type_0011[] __initconst = {
/* Battery unplugged */
{ KE_IGNORE, 0xfff0, { KEY_RESERVED } },
/* Battery inserted */
{ KE_IGNORE, 0xfff1, { KEY_RESERVED } },
/* Keyboard backlight level changed */
{ KE_IGNORE, 0x01e1, { KEY_RESERVED } },
{ KE_IGNORE, 0x02ea, { KEY_RESERVED } },
{ KE_IGNORE, 0x02eb, { KEY_RESERVED } },
{ KE_IGNORE, 0x02ec, { KEY_RESERVED } },
{ KE_IGNORE, 0x02f6, { KEY_RESERVED } },
};
static struct input_dev *dell_wmi_input_dev; static struct input_dev *dell_wmi_input_dev;
static void dell_wmi_process_key(int reported_key) static void dell_wmi_process_key(int type, int code)
{ {
const struct key_entry *key; const struct key_entry *key;
key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev, key = sparse_keymap_entry_from_scancode(dell_wmi_input_dev,
reported_key); (type << 16) | code);
if (!key) { if (!key) {
pr_info("Unknown key with scancode 0x%x pressed\n", pr_info("Unknown key with type 0x%04x and code 0x%04x pressed\n",
reported_key); type, code);
return; return;
} }
pr_debug("Key %x pressed\n", reported_key); pr_debug("Key with type 0x%04x and code 0x%04x pressed\n", type, code);
/* Don't report brightness notifications that will also come via ACPI */ /* Don't report brightness notifications that will also come via ACPI */
if ((key->keycode == KEY_BRIGHTNESSUP || if ((key->keycode == KEY_BRIGHTNESSUP ||
...@@ -295,7 +313,7 @@ static void dell_wmi_process_key(int reported_key) ...@@ -295,7 +313,7 @@ static void dell_wmi_process_key(int reported_key)
acpi_video_handles_brightness_key_presses()) acpi_video_handles_brightness_key_presses())
return; return;
if (reported_key == 0xe025 && !wmi_requires_smbios_request) if (type == 0x0000 && code == 0xe025 && !wmi_requires_smbios_request)
return; return;
sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true); sparse_keymap_report_entry(dell_wmi_input_dev, key, 1, true);
...@@ -333,18 +351,6 @@ static void dell_wmi_notify(u32 value, void *context) ...@@ -333,18 +351,6 @@ static void dell_wmi_notify(u32 value, void *context)
buffer_entry = (u16 *)obj->buffer.pointer; buffer_entry = (u16 *)obj->buffer.pointer;
buffer_size = obj->buffer.length/2; buffer_size = obj->buffer.length/2;
if (!dell_new_hk_type) {
if (buffer_size >= 3 && buffer_entry[1] == 0x0)
dell_wmi_process_key(buffer_entry[2]);
else if (buffer_size >= 2)
dell_wmi_process_key(buffer_entry[1]);
else
pr_info("Received unknown WMI event\n");
kfree(obj);
return;
}
buffer_end = buffer_entry + buffer_size; buffer_end = buffer_entry + buffer_size;
/* /*
...@@ -379,62 +385,18 @@ static void dell_wmi_notify(u32 value, void *context) ...@@ -379,62 +385,18 @@ static void dell_wmi_notify(u32 value, void *context)
pr_debug("Process buffer (%*ph)\n", len*2, buffer_entry); pr_debug("Process buffer (%*ph)\n", len*2, buffer_entry);
switch (buffer_entry[1]) { switch (buffer_entry[1]) {
case 0x00: case 0x0000: /* One key pressed or event occurred */
for (i = 2; i < len; ++i) { if (len > 2)
switch (buffer_entry[i]) { dell_wmi_process_key(0x0000, buffer_entry[2]);
case 0xe043: /* Other entries could contain additional information */
/* NIC Link is Up */
pr_debug("NIC Link is Up\n");
break; break;
case 0xe044: case 0x0010: /* Sequence of keys pressed */
/* NIC Link is Down */ case 0x0011: /* Sequence of events occurred */
pr_debug("NIC Link is Down\n");
break;
case 0xe045:
/* Unknown event but defined in DSDT */
default:
/* Unknown event */
pr_info("Unknown WMI event type 0x00: "
"0x%x\n", (int)buffer_entry[i]);
break;
}
}
break;
case 0x10:
/* Keys pressed */
for (i = 2; i < len; ++i) for (i = 2; i < len; ++i)
dell_wmi_process_key(buffer_entry[i]); dell_wmi_process_key(buffer_entry[1],
break; buffer_entry[i]);
case 0x11:
for (i = 2; i < len; ++i) {
switch (buffer_entry[i]) {
case 0xfff0:
/* Battery unplugged */
pr_debug("Battery unplugged\n");
break;
case 0xfff1:
/* Battery inserted */
pr_debug("Battery inserted\n");
break;
case 0x01e1:
case 0x02ea:
case 0x02eb:
case 0x02ec:
case 0x02f6:
/* Keyboard backlight level changed */
pr_debug("Keyboard backlight level "
"changed\n");
break; break;
default: default: /* Unknown event */
/* Unknown event */
pr_info("Unknown WMI event type 0x11: "
"0x%x\n", (int)buffer_entry[i]);
break;
}
}
break;
default:
/* Unknown event */
pr_info("Unknown WMI event type 0x%x\n", pr_info("Unknown WMI event type 0x%x\n",
(int)buffer_entry[1]); (int)buffer_entry[1]);
break; break;
...@@ -459,7 +421,6 @@ static bool have_scancode(u32 scancode, const struct key_entry *keymap, int len) ...@@ -459,7 +421,6 @@ static bool have_scancode(u32 scancode, const struct key_entry *keymap, int len)
} }
static void __init handle_dmi_entry(const struct dmi_header *dm, static void __init handle_dmi_entry(const struct dmi_header *dm,
void *opaque) void *opaque)
{ {
...@@ -467,7 +428,6 @@ static void __init handle_dmi_entry(const struct dmi_header *dm, ...@@ -467,7 +428,6 @@ static void __init handle_dmi_entry(const struct dmi_header *dm,
struct dell_bios_hotkey_table *table; struct dell_bios_hotkey_table *table;
int hotkey_num, i, pos = 0; int hotkey_num, i, pos = 0;
struct key_entry *keymap; struct key_entry *keymap;
int num_bios_keys;
if (results->err || results->keymap) if (results->err || results->keymap)
return; /* We already found the hotkey table. */ return; /* We already found the hotkey table. */
...@@ -491,8 +451,7 @@ static void __init handle_dmi_entry(const struct dmi_header *dm, ...@@ -491,8 +451,7 @@ static void __init handle_dmi_entry(const struct dmi_header *dm,
return; return;
} }
keymap = kcalloc(hotkey_num + ARRAY_SIZE(dell_wmi_extra_keymap) + 1, keymap = kcalloc(hotkey_num, sizeof(struct key_entry), GFP_KERNEL);
sizeof(struct key_entry), GFP_KERNEL);
if (!keymap) { if (!keymap) {
results->err = -ENOMEM; results->err = -ENOMEM;
return; return;
...@@ -529,31 +488,15 @@ static void __init handle_dmi_entry(const struct dmi_header *dm, ...@@ -529,31 +488,15 @@ static void __init handle_dmi_entry(const struct dmi_header *dm,
pos++; pos++;
} }
num_bios_keys = pos;
for (i = 0; i < ARRAY_SIZE(dell_wmi_extra_keymap); i++) {
const struct key_entry *entry = &dell_wmi_extra_keymap[i];
/*
* Check if we've already found this scancode. This takes
* quadratic time, but it doesn't matter unless the list
* of extra keys gets very long.
*/
if (!have_scancode(entry->code, keymap, num_bios_keys)) {
keymap[pos] = *entry;
pos++;
}
}
keymap[pos].type = KE_END;
results->keymap = keymap; results->keymap = keymap;
results->keymap_size = pos;
} }
static int __init dell_wmi_input_setup(void) static int __init dell_wmi_input_setup(void)
{ {
struct dell_dmi_results dmi_results = {}; struct dell_dmi_results dmi_results = {};
int err; struct key_entry *keymap;
int err, i, pos = 0;
dell_wmi_input_dev = input_allocate_device(); dell_wmi_input_dev = input_allocate_device();
if (!dell_wmi_input_dev) if (!dell_wmi_input_dev)
...@@ -577,21 +520,71 @@ static int __init dell_wmi_input_setup(void) ...@@ -577,21 +520,71 @@ static int __init dell_wmi_input_setup(void)
goto err_free_dev; goto err_free_dev;
} }
if (dmi_results.keymap) { keymap = kcalloc(dmi_results.keymap_size +
dell_new_hk_type = true; ARRAY_SIZE(dell_wmi_keymap_type_0000) +
ARRAY_SIZE(dell_wmi_keymap_type_0010) +
ARRAY_SIZE(dell_wmi_keymap_type_0011) +
1,
sizeof(struct key_entry), GFP_KERNEL);
if (!keymap) {
kfree(dmi_results.keymap);
err = -ENOMEM;
goto err_free_dev;
}
/* Append table with events of type 0x0010 which comes from DMI */
for (i = 0; i < dmi_results.keymap_size; i++) {
keymap[pos] = dmi_results.keymap[i];
keymap[pos].code |= (0x0010 << 16);
pos++;
}
kfree(dmi_results.keymap);
err = sparse_keymap_setup(dell_wmi_input_dev, /* Append table with extra events of type 0x0010 which are not in DMI */
dmi_results.keymap, NULL); for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0010); i++) {
const struct key_entry *entry = &dell_wmi_keymap_type_0010[i];
/* /*
* Sparse keymap library makes a copy of keymap so we * Check if we've already found this scancode. This takes
* don't need the original one that was allocated. * quadratic time, but it doesn't matter unless the list
* of extra keys gets very long.
*/ */
kfree(dmi_results.keymap); if (dmi_results.keymap_size &&
} else { have_scancode(entry->code | (0x0010 << 16),
err = sparse_keymap_setup(dell_wmi_input_dev, keymap, dmi_results.keymap_size)
dell_wmi_legacy_keymap, NULL); )
continue;
keymap[pos] = *entry;
keymap[pos].code |= (0x0010 << 16);
pos++;
}
/* Append table with events of type 0x0011 */
for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0011); i++) {
keymap[pos] = dell_wmi_keymap_type_0011[i];
keymap[pos].code |= (0x0011 << 16);
pos++;
} }
/*
* Now append also table with "legacy" events of type 0x0000. Some of
* them are reported also on laptops which have scancodes in DMI.
*/
for (i = 0; i < ARRAY_SIZE(dell_wmi_keymap_type_0000); i++) {
keymap[pos] = dell_wmi_keymap_type_0000[i];
pos++;
}
keymap[pos].type = KE_END;
err = sparse_keymap_setup(dell_wmi_input_dev, keymap, NULL);
/*
* Sparse keymap library makes a copy of keymap so we don't need the
* original one that was allocated.
*/
kfree(keymap);
if (err) if (err)
goto err_free_dev; goto err_free_dev;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment