From 36372473514f47b20b97683503fa1e96b710bb1e Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Fri, 3 Sep 2021 22:07:13 +0200 Subject: [PATCH] Add basic uniwill-wmi module - Add separate uniwill-wmi module - Add uniwill interfaces header --- Makefile | 3 +- dkms.conf | 4 ++ src/uniwill_interfaces.h | 29 +++++++++++ src/uniwill_wmi.c | 110 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 145 insertions(+), 1 deletion(-) create mode 100644 src/uniwill_interfaces.h create mode 100644 src/uniwill_wmi.c diff --git a/Makefile b/Makefile index 8d031d9..c60cf4d 100644 --- a/Makefile +++ b/Makefile @@ -19,7 +19,8 @@ obj-m := ./src/tuxedo_keyboard.o \ ./src/clevo_wmi.o \ ./src/clevo_acpi.o \ - ./src/tuxedo_io/tuxedo_io.o + ./src/tuxedo_io/tuxedo_io.o \ + ./src/uniwill_wmi.o PWD := $(shell pwd) KDIR := /lib/modules/$(shell uname -r)/build diff --git a/dkms.conf b/dkms.conf index 2d3424c..54db155 100644 --- a/dkms.conf +++ b/dkms.conf @@ -17,6 +17,10 @@ DEST_MODULE_LOCATION[3]="/kernel/lib/" BUILT_MODULE_NAME[3]="tuxedo_io" BUILT_MODULE_LOCATION[3]="src/tuxedo_io" +DEST_MODULE_LOCATION[4]="/kernel/lib/" +BUILT_MODULE_NAME[4]="uniwill_wmi" +BUILT_MODULE_LOCATION[4]="src/" + MAKE[0]="make KDIR=/lib/modules/${kernelver}/build" CLEAN="make clean" AUTOINSTALL="yes" diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h new file mode 100644 index 0000000..a167be9 --- /dev/null +++ b/src/uniwill_interfaces.h @@ -0,0 +1,29 @@ +/*! + * Copyright (c) 2021 TUXEDO Computers GmbH + * + * This file is part of tuxedo-keyboard. + * + * tuxedo-keyboard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. If not, see . + */ +#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 MODULE_ALIAS_UNIWILL_WMI() \ + MODULE_ALIAS("wmi:" UNIWILL_WMI_EVENT_GUID_2); \ + MODULE_ALIAS("wmi:" UNIWILL_WMI_MGMT_GUID_BC); diff --git a/src/uniwill_wmi.c b/src/uniwill_wmi.c new file mode 100644 index 0000000..f3a839a --- /dev/null +++ b/src/uniwill_wmi.c @@ -0,0 +1,110 @@ +/*! + * Copyright (c) 2021 TUXEDO Computers GmbH + * + * This file is part of tuxedo-keyboard. + * + * tuxedo-keyboard is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this software. If not, see . + */ +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt +#include +#include +#include +#include +#include "uniwill_interfaces.h" + +/*u32 uniwill_wmi_interface_method_call(u8 cmd, u32 arg, u32 *result_value) +{ + return uniwill_wmi_evaluate(cmd, arg, result_value); +} + +struct uniwill_interface_t uniwill_wmi_interface = { + .string_id = "uniwill_wmi", + .method_call = uniwill_wmi_interface_method_call, +};*/ + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0) +static int uniwill_wmi_probe(struct wmi_device *wdev) +#else +static int uniwill_wmi_probe(struct wmi_device *wdev, const void *dummy_context) +#endif +{ + 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) { + pr_debug("probe: At least one Uniwill GUID missing\n"); + return -ENODEV; + } + + // TODO: Add interface and init + + pr_info("interface initialized\n"); + + return 0; +} + +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 13, 0) +static int uniwill_wmi_remove(struct wmi_device *wdev) +#else +static void uniwill_wmi_remove(struct wmi_device *wdev) +#endif +{ + pr_debug("uniwill_wmi driver remove\n"); +#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 13, 0) + return 0; +#endif +} + +static void uniwill_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy) +{ + //u32 event_value; + pr_debug("uniwill_wmi notify\n"); + /*if (!IS_ERR_OR_NULL(uniwill_wmi_interface.event_callb)) { + // Execute registered callback + // TODO + }*/ +} + +static const struct wmi_device_id uniwill_wmi_device_ids[] = { + // Listing one should be enough, for a driver that "takes care of all anyways" + // also prevents probe (and handling) per "device" + { .guid_string = UNIWILL_WMI_EVENT_GUID_2 }, + { } +}; + +static struct wmi_driver uniwill_wmi_driver = { + .driver = { .name = "uniwill_wmi", .owner = THIS_MODULE }, + .id_table = uniwill_wmi_device_ids, + .probe = uniwill_wmi_probe, + .remove = uniwill_wmi_remove, + .notify = uniwill_wmi_notify, +}; + +module_wmi_driver(uniwill_wmi_driver); + +MODULE_AUTHOR("TUXEDO Computers GmbH "); +MODULE_DESCRIPTION("Driver for Uniwill WMI interface"); +MODULE_VERSION("0.0.1"); +MODULE_LICENSE("GPL"); + +MODULE_DEVICE_TABLE(wmi, uniwill_wmi_device_ids); +MODULE_ALIAS_UNIWILL_WMI();