Commit 527483a8 authored by Michał Kępień's avatar Michał Kępień Committed by Darren Hart (VMware)

platform/x86: fujitsu-laptop: use a sparse keymap for hotkey event generation

Simplify hotkey event generation by using a sparse keymap.  As sparse
keymap operates on scancodes instead of keycodes, adjust variable names
and debug messages accordingly.

This patch only handles the default keymap for clarity.
Signed-off-by: default avatarMichał Kępień <kernel@kempniu.pl>
Reviewed-by: default avatarJonathan Woithe <jwoithe@just42.net>
[dvhart: correct flag passed to call_fext_func in acpi_fujitsu_laptop_notify]
Signed-off-by: default avatarDarren Hart (VMware) <dvhart@infradead.org>
parent f66735f8
...@@ -756,9 +756,22 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event) ...@@ -756,9 +756,22 @@ static void acpi_fujitsu_bl_notify(struct acpi_device *device, u32 event)
/* ACPI device for hotkey handling */ /* ACPI device for hotkey handling */
static const struct key_entry keymap_default[] = {
{ KE_KEY, KEY1_CODE, { KEY_PROG1 } },
{ KE_KEY, KEY2_CODE, { KEY_PROG2 } },
{ KE_KEY, KEY3_CODE, { KEY_PROG3 } },
{ KE_KEY, KEY4_CODE, { KEY_PROG4 } },
{ KE_KEY, KEY5_CODE, { KEY_RFKILL } },
{ KE_KEY, BIT(26), { KEY_TOUCHPAD_TOGGLE } },
{ KE_END, 0 }
};
static const struct key_entry *keymap = keymap_default;
static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device) static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
{ {
struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device); struct fujitsu_laptop *fujitsu_laptop = acpi_driver_data(device);
int ret;
fujitsu_laptop->input = devm_input_allocate_device(&device->dev); fujitsu_laptop->input = devm_input_allocate_device(&device->dev);
if (!fujitsu_laptop->input) if (!fujitsu_laptop->input)
...@@ -772,14 +785,9 @@ static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device) ...@@ -772,14 +785,9 @@ static int acpi_fujitsu_laptop_input_setup(struct acpi_device *device)
fujitsu_laptop->input->id.bustype = BUS_HOST; fujitsu_laptop->input->id.bustype = BUS_HOST;
fujitsu_laptop->input->id.product = 0x06; fujitsu_laptop->input->id.product = 0x06;
set_bit(EV_KEY, fujitsu_laptop->input->evbit); ret = sparse_keymap_setup(fujitsu_laptop->input, keymap, NULL);
set_bit(fujitsu_bl->keycode1, fujitsu_laptop->input->keybit); if (ret)
set_bit(fujitsu_bl->keycode2, fujitsu_laptop->input->keybit); return ret;
set_bit(fujitsu_bl->keycode3, fujitsu_laptop->input->keybit);
set_bit(fujitsu_bl->keycode4, fujitsu_laptop->input->keybit);
set_bit(fujitsu_bl->keycode5, fujitsu_laptop->input->keybit);
set_bit(KEY_TOUCHPAD_TOGGLE, fujitsu_laptop->input->keybit);
set_bit(KEY_UNKNOWN, fujitsu_laptop->input->keybit);
return input_register_device(fujitsu_laptop->input); return input_register_device(fujitsu_laptop->input);
} }
...@@ -995,61 +1003,54 @@ static int acpi_fujitsu_laptop_remove(struct acpi_device *device) ...@@ -995,61 +1003,54 @@ static int acpi_fujitsu_laptop_remove(struct acpi_device *device)
return 0; return 0;
} }
static void acpi_fujitsu_laptop_press(int keycode) static void acpi_fujitsu_laptop_press(int scancode)
{ {
struct input_dev *input = fujitsu_laptop->input; struct input_dev *input = fujitsu_laptop->input;
int status; int status;
status = kfifo_in_locked(&fujitsu_laptop->fifo, status = kfifo_in_locked(&fujitsu_laptop->fifo,
(unsigned char *)&keycode, sizeof(keycode), (unsigned char *)&scancode, sizeof(scancode),
&fujitsu_laptop->fifo_lock); &fujitsu_laptop->fifo_lock);
if (status != sizeof(keycode)) { if (status != sizeof(scancode)) {
vdbg_printk(FUJLAPTOP_DBG_WARN, vdbg_printk(FUJLAPTOP_DBG_WARN,
"Could not push keycode [0x%x]\n", keycode); "Could not push scancode [0x%x]\n", scancode);
return; return;
} }
input_report_key(input, keycode, 1); sparse_keymap_report_event(input, scancode, 1, false);
input_sync(input);
vdbg_printk(FUJLAPTOP_DBG_TRACE, vdbg_printk(FUJLAPTOP_DBG_TRACE,
"Push keycode into ringbuffer [%d]\n", keycode); "Push scancode into ringbuffer [0x%x]\n", scancode);
} }
static void acpi_fujitsu_laptop_release(void) static void acpi_fujitsu_laptop_release(void)
{ {
struct input_dev *input = fujitsu_laptop->input; struct input_dev *input = fujitsu_laptop->input;
int keycode, status; int scancode, status;
while (true) { while (true) {
status = kfifo_out_locked(&fujitsu_laptop->fifo, status = kfifo_out_locked(&fujitsu_laptop->fifo,
(unsigned char *)&keycode, (unsigned char *)&scancode,
sizeof(keycode), sizeof(scancode),
&fujitsu_laptop->fifo_lock); &fujitsu_laptop->fifo_lock);
if (status != sizeof(keycode)) if (status != sizeof(scancode))
return; return;
input_report_key(input, keycode, 0); sparse_keymap_report_event(input, scancode, 0, false);
input_sync(input);
vdbg_printk(FUJLAPTOP_DBG_TRACE, vdbg_printk(FUJLAPTOP_DBG_TRACE,
"Pop keycode from ringbuffer [%d]\n", keycode); "Pop scancode from ringbuffer [0x%x]\n", scancode);
} }
} }
static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event) static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
{ {
struct input_dev *input; struct input_dev *input;
int keycode; int scancode, i = 0;
unsigned int irb = 1; unsigned int irb;
int i;
input = fujitsu_laptop->input; input = fujitsu_laptop->input;
if (event != ACPI_FUJITSU_NOTIFY_CODE1) { if (event != ACPI_FUJITSU_NOTIFY_CODE1) {
keycode = KEY_UNKNOWN;
vdbg_printk(FUJLAPTOP_DBG_WARN, vdbg_printk(FUJLAPTOP_DBG_WARN,
"Unsupported event [0x%x]\n", event); "Unsupported event [0x%x]\n", event);
input_report_key(input, keycode, 1); sparse_keymap_report_event(input, -1, 1, true);
input_sync(input);
input_report_key(input, keycode, 0);
input_sync(input);
return; return;
} }
...@@ -1057,40 +1058,16 @@ static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event) ...@@ -1057,40 +1058,16 @@ static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
fujitsu_laptop->flags_state = fujitsu_laptop->flags_state =
call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0); call_fext_func(FUNC_FLAGS, 0x4, 0x0, 0x0);
i = 0; while ((irb = call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 &&
while ((irb = i++ < MAX_HOTKEY_RINGBUFFER_SIZE) {
call_fext_func(FUNC_BUTTONS, 0x1, 0x0, 0x0)) != 0 scancode = irb & 0x4ff;
&& (i++) < MAX_HOTKEY_RINGBUFFER_SIZE) { if (sparse_keymap_entry_from_scancode(input, scancode))
switch (irb & 0x4ff) { acpi_fujitsu_laptop_press(scancode);
case KEY1_CODE: else if (scancode == 0)
keycode = fujitsu_bl->keycode1; acpi_fujitsu_laptop_release();
break; else
case KEY2_CODE:
keycode = fujitsu_bl->keycode2;
break;
case KEY3_CODE:
keycode = fujitsu_bl->keycode3;
break;
case KEY4_CODE:
keycode = fujitsu_bl->keycode4;
break;
case KEY5_CODE:
keycode = fujitsu_bl->keycode5;
break;
case 0:
keycode = 0;
break;
default:
vdbg_printk(FUJLAPTOP_DBG_WARN, vdbg_printk(FUJLAPTOP_DBG_WARN,
"Unknown GIRB result [%x]\n", irb); "Unknown GIRB result [%x]\n", irb);
keycode = -1;
break;
}
if (keycode > 0)
acpi_fujitsu_laptop_press(keycode);
else if (keycode == 0)
acpi_fujitsu_laptop_release();
} }
/* On some models (first seen on the Skylake-based Lifebook /* On some models (first seen on the Skylake-based Lifebook
...@@ -1098,14 +1075,8 @@ static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event) ...@@ -1098,14 +1075,8 @@ static void acpi_fujitsu_laptop_notify(struct acpi_device *device, u32 event)
* handled in software; its state is queried using FUNC_FLAGS * handled in software; its state is queried using FUNC_FLAGS
*/ */
if ((fujitsu_laptop->flags_supported & BIT(26)) && if ((fujitsu_laptop->flags_supported & BIT(26)) &&
(call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26))) { (call_fext_func(FUNC_FLAGS, 0x1, 0x0, 0x0) & BIT(26)))
keycode = KEY_TOUCHPAD_TOGGLE; sparse_keymap_report_event(input, BIT(26), 1, true);
input_report_key(input, keycode, 1);
input_sync(input);
input_report_key(input, keycode, 0);
input_sync(input);
}
} }
/* Initialization */ /* Initialization */
......
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