2020-12-09 13:17:20 +01:00
|
|
|
/*!
|
|
|
|
* Copyright (c) 2020 TUXEDO Computers GmbH <tux@tuxedocomputers.com>
|
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2020-12-04 12:23:39 +01:00
|
|
|
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
|
|
|
|
#include <linux/acpi.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/wmi.h>
|
|
|
|
#include <linux/version.h>
|
|
|
|
#include "clevo_interfaces.h"
|
|
|
|
|
2022-07-16 17:08:15 +02:00
|
|
|
static int clevo_wmi_evaluate(u32 wmi_method_id, u32 wmi_arg, union acpi_object **result)
|
2020-12-04 12:23:39 +01:00
|
|
|
{
|
|
|
|
struct acpi_buffer acpi_buffer_in = { (acpi_size)sizeof(wmi_arg),
|
|
|
|
&wmi_arg };
|
|
|
|
struct acpi_buffer acpi_buffer_out = { ACPI_ALLOCATE_BUFFER, NULL };
|
|
|
|
union acpi_object *acpi_result;
|
|
|
|
acpi_status status_acpi;
|
|
|
|
u32 return_status = 0;
|
|
|
|
|
|
|
|
status_acpi =
|
|
|
|
wmi_evaluate_method(CLEVO_WMI_METHOD_GUID, 0x00, wmi_method_id,
|
|
|
|
&acpi_buffer_in, &acpi_buffer_out);
|
|
|
|
|
|
|
|
if (unlikely(ACPI_FAILURE(status_acpi))) {
|
|
|
|
pr_err("failed to evaluate wmi method\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
acpi_result = (union acpi_object *)acpi_buffer_out.pointer;
|
|
|
|
if (!acpi_result) {
|
|
|
|
pr_err("failed to evaluate WMI method\n");
|
|
|
|
return_status = -1;
|
2022-07-16 17:08:15 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (!IS_ERR_OR_NULL(result)) {
|
|
|
|
*result = acpi_result;
|
2020-12-04 12:23:39 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return return_status;
|
|
|
|
}
|
|
|
|
|
2022-07-16 17:08:15 +02:00
|
|
|
u32 clevo_wmi_interface_method_call(u8 cmd, u32 arg, union acpi_object **result_value)
|
2020-12-04 12:23:39 +01:00
|
|
|
{
|
|
|
|
return clevo_wmi_evaluate(cmd, arg, result_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct clevo_interface_t clevo_wmi_interface = {
|
2021-09-16 00:14:39 +02:00
|
|
|
.string_id = CLEVO_INTERFACE_WMI_STRID,
|
2020-12-04 12:23:39 +01:00
|
|
|
.method_call = clevo_wmi_interface_method_call,
|
|
|
|
};
|
|
|
|
|
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 3, 0)
|
|
|
|
static int clevo_wmi_probe(struct wmi_device *wdev)
|
|
|
|
#else
|
|
|
|
static int clevo_wmi_probe(struct wmi_device *wdev, const void *dummy_context)
|
|
|
|
#endif
|
|
|
|
{
|
2022-07-16 17:08:15 +02:00
|
|
|
u32 status;
|
|
|
|
union acpi_object *out_obj;
|
2020-12-04 12:23:39 +01:00
|
|
|
|
|
|
|
pr_debug("clevo_wmi driver probe\n");
|
|
|
|
|
|
|
|
if (!wmi_has_guid(CLEVO_WMI_EVENT_GUID)) {
|
|
|
|
pr_debug("probe: Clevo event guid missing\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!wmi_has_guid(CLEVO_WMI_METHOD_GUID)) {
|
|
|
|
pr_debug("probe: Clevo method guid missing\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Since the WMI GUIDs aren't unique let's (at least)
|
|
|
|
// check the return of some "known existing general" method
|
2022-07-16 17:08:15 +02:00
|
|
|
status = clevo_wmi_evaluate(0x52, 0, &out_obj);
|
2020-12-04 12:23:39 +01:00
|
|
|
if (status < 0) {
|
|
|
|
pr_debug("probe: Clevo GUIDs present but method call failed\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
2022-07-16 17:08:15 +02:00
|
|
|
if (out_obj->type != ACPI_TYPE_INTEGER || (out_obj->type == ACPI_TYPE_INTEGER && (u32)out_obj->integer.value == 0xffffffff)) {
|
2020-12-04 12:23:39 +01:00
|
|
|
pr_debug(
|
|
|
|
"probe: Clevo GUIDs present but method returned unexpected value\n");
|
2022-07-16 17:08:15 +02:00
|
|
|
ACPI_FREE(out_obj);
|
2020-12-04 12:23:39 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
2022-07-16 17:08:15 +02:00
|
|
|
ACPI_FREE(out_obj);
|
2020-12-04 12:23:39 +01:00
|
|
|
|
|
|
|
// Add this interface
|
|
|
|
clevo_keyboard_add_interface(&clevo_wmi_interface);
|
|
|
|
|
2020-12-08 11:46:13 +01:00
|
|
|
pr_info("interface initialized\n");
|
2020-12-04 12:23:39 +01:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-06-23 11:21:52 +02:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 13, 0)
|
2020-12-04 12:23:39 +01:00
|
|
|
static int clevo_wmi_remove(struct wmi_device *wdev)
|
2021-06-23 11:21:52 +02:00
|
|
|
#else
|
|
|
|
static void clevo_wmi_remove(struct wmi_device *wdev)
|
|
|
|
#endif
|
2020-12-04 12:23:39 +01:00
|
|
|
{
|
|
|
|
pr_debug("clevo_wmi driver remove\n");
|
2021-09-16 00:14:39 +02:00
|
|
|
clevo_keyboard_remove_interface(&clevo_wmi_interface);
|
2021-06-23 11:21:52 +02:00
|
|
|
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 13, 0)
|
2020-12-04 12:23:39 +01:00
|
|
|
return 0;
|
2021-06-23 11:21:52 +02:00
|
|
|
#endif
|
2020-12-04 12:23:39 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
static void clevo_wmi_notify(struct wmi_device *wdev, union acpi_object *dummy)
|
|
|
|
{
|
|
|
|
u32 event_value;
|
2022-07-16 17:08:15 +02:00
|
|
|
union acpi_object *out_obj;
|
|
|
|
u32 status;
|
|
|
|
|
|
|
|
status = clevo_wmi_evaluate(0x01, 0, &out_obj);
|
|
|
|
if (!status) {
|
|
|
|
if (out_obj->type == ACPI_TYPE_INTEGER) {
|
|
|
|
event_value = (u32)out_obj->integer.value;
|
|
|
|
} else {
|
|
|
|
pr_err("return type not integer, use clevo_evaluate_method2\n");
|
|
|
|
}
|
|
|
|
ACPI_FREE(out_obj);
|
|
|
|
}
|
2020-12-04 12:23:39 +01:00
|
|
|
pr_debug("clevo_wmi notify\n");
|
|
|
|
if (!IS_ERR_OR_NULL(clevo_wmi_interface.event_callb)) {
|
|
|
|
// Execute registered callback
|
|
|
|
clevo_wmi_interface.event_callb(event_value);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct wmi_device_id clevo_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 = CLEVO_WMI_EVENT_GUID },
|
2020-12-04 15:50:48 +01:00
|
|
|
{ }
|
2020-12-04 12:23:39 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct wmi_driver clevo_wmi_driver = {
|
2021-09-16 00:14:39 +02:00
|
|
|
.driver = {
|
|
|
|
.name = CLEVO_INTERFACE_WMI_STRID,
|
|
|
|
.owner = THIS_MODULE
|
|
|
|
},
|
2020-12-04 12:23:39 +01:00
|
|
|
.id_table = clevo_wmi_device_ids,
|
|
|
|
.probe = clevo_wmi_probe,
|
|
|
|
.remove = clevo_wmi_remove,
|
|
|
|
.notify = clevo_wmi_notify,
|
|
|
|
};
|
|
|
|
|
|
|
|
module_wmi_driver(clevo_wmi_driver);
|
|
|
|
|
|
|
|
MODULE_AUTHOR("TUXEDO Computers GmbH <tux@tuxedocomputers.com>");
|
|
|
|
MODULE_DESCRIPTION("Driver for Clevo WMI interface");
|
2023-02-23 10:01:33 +01:00
|
|
|
MODULE_VERSION("0.1.0");
|
2020-12-04 12:23:39 +01:00
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(wmi, clevo_wmi_device_ids);
|
2020-12-07 16:37:26 +01:00
|
|
|
MODULE_ALIAS_CLEVO_WMI();
|