From f7d79e6bbcf5993f334eb9a7fb9ae294a5b760f1 Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Fri, 29 May 2020 17:47:18 +0200 Subject: [PATCH] Add basic probe and wmi notifiers --- src/uniwill_keyboard.h | 93 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index 0b77252..1c924a5 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -18,20 +18,113 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "tuxedo_keyboard_common.h" +#include +#include + +#define UNIWILL_WMI_MGMT_GUID_BA "ABBC0F6D-8EA1-11D1-00A0-C90629100000" +#define UNIWILL_WMI_MGMT_GUID_BB "ABBC0F6E-8EA1-11D1-00A0-C90629100000" +#define UNIWILL_WMI_MGMT_GUID_BC "ABBC0F6F-8EA1-11D1-00A0-C90629100000" + +#define UNIWILL_WMI_EVENT_GUID_0 "ABBC0F70-8EA1-11D1-00A0-C90629100000" +#define UNIWILL_WMI_EVENT_GUID_1 "ABBC0F71-8EA1-11D1-00A0-C90629100000" +#define UNIWILL_WMI_EVENT_GUID_2 "ABBC0F72-8EA1-11D1-00A0-C90629100000" + +#define UNIWILL_OSD_RADIOON 0x01A +#define UNIWILL_OSD_RADIOOFF 0x01B struct tuxedo_keyboard_driver uniwill_keyboard_driver; static struct key_entry uniwill_wmi_keymap[] = { + { KE_KEY, UNIWILL_OSD_RADIOON, { KEY_RFKILL } }, + { KE_KEY, UNIWILL_OSD_RADIOOFF, { KEY_RFKILL } }, { KE_END, 0 } }; +static void uniwill_wmi_handle_event(u32 value, void *context, u32 guid_nr) +{ + struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *obj; + + acpi_status status; + int code; + + status = wmi_get_event_data(value, &response); + if (status != AE_OK) { + TUXEDO_ERROR("uniwill handle event -> bad event status\n"); + return; + } + + obj = (union acpi_object *) response.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) { + code = obj->integer.value; + if (!sparse_keymap_report_known_event(current_driver->input_device, code, 1, true)) { + TUXEDO_DEBUG("Unknown key - %d (%0#6x)\n", code, code); + } + } + + kfree(obj); +} + +static void uniwill_wmi_notify0(u32 value, void *context) +{ + uniwill_wmi_handle_event(value, context, 0); +} + +static void uniwill_wmi_notify1(u32 value, void *context) +{ + uniwill_wmi_handle_event(value, context, 1); +} + +static void uniwill_wmi_notify2(u32 value, void *context) +{ + uniwill_wmi_handle_event(value, context, 2); +} + static int uniwill_keyboard_probe(struct platform_device *dev) { + int status; + + // Look for for GUIDs used on uniwill devices + status = + wmi_has_guid(UNIWILL_WMI_EVENT_GUID_0) && + wmi_has_guid(UNIWILL_WMI_EVENT_GUID_1) && + wmi_has_guid(UNIWILL_WMI_EVENT_GUID_2) && + wmi_has_guid(UNIWILL_WMI_MGMT_GUID_BA) && + wmi_has_guid(UNIWILL_WMI_MGMT_GUID_BB) && + wmi_has_guid(UNIWILL_WMI_MGMT_GUID_BC); + + if (!status) { + TUXEDO_DEBUG("probe: At least one Uniwill GUID missing\n"); + return -ENODEV; + } + + // Attempt to add event handlers + status = + wmi_install_notify_handler(UNIWILL_WMI_EVENT_GUID_0, uniwill_wmi_notify0, NULL) && + wmi_install_notify_handler(UNIWILL_WMI_EVENT_GUID_1, uniwill_wmi_notify1, NULL) && + wmi_install_notify_handler(UNIWILL_WMI_EVENT_GUID_2, uniwill_wmi_notify2, NULL); + + if (!status) { + TUXEDO_ERROR("probe: Failed to install at least one uniwill notify handler\n"); + goto err_remove_notifiers; + } + + return 0; + +err_remove_notifiers: + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_0); + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_1); + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_2); + return -ENODEV; } static int uniwill_keyboard_remove(struct platform_device *dev) { + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_0); + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_1); + wmi_remove_notify_handler(UNIWILL_WMI_EVENT_GUID_2); + return 0; }