diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h deleted file mode 100644 index 98ebdf4..0000000 --- a/src/tuxedo_io/tongfang_wmi.h +++ /dev/null @@ -1,283 +0,0 @@ -/*! - * Copyright (c) 2020 TUXEDO Computers GmbH - * - * This file is part of tuxedo-io. - * - * tuxedo-io 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 . - */ -#ifndef TONGFANG_WMI_H -#define TONGFANG_WMI_H - -#include -#include -#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_EC_REG_LDAT 0x8a -#define UNIWILL_EC_REG_HDAT 0x8b -#define UNIWILL_EC_REG_FLAGS 0x8c -#define UNIWILL_EC_REG_CMDL 0x8d -#define UNIWILL_EC_REG_CMDH 0x8e - -#define UNIWILL_EC_BIT_RFLG 0 -#define UNIWILL_EC_BIT_WFLG 1 -#define UNIWILL_EC_BIT_BFLG 2 -#define UNIWILL_EC_BIT_CFLG 3 -#define UNIWILL_EC_BIT_DRDY 7 - -#define UW_EC_WAIT_CYCLES 0x50 - -union uw_ec_read_return { - u32 dword; - struct { - u8 data_low; - u8 data_high; - } bytes; -}; - -union uw_ec_write_return { - u32 dword; - struct { - u8 addr_low; - u8 addr_high; - u8 data_low; - u8 data_high; - } bytes; -}; - -static bool uniwill_ec_direct = true; - -DEFINE_MUTEX(uniwill_ec_lock); - -static u32 uw_wmi_ec_evaluate(u8 addr_low, u8 addr_high, u8 data_low, u8 data_high, u8 read_flag, u32 *return_buffer) -{ - acpi_status status; - union acpi_object *out_acpi; - u32 e_result = 0; - - // Kernel buffer for input argument - u32 *wmi_arg = (u32 *) kmalloc(sizeof(u32)*10, GFP_KERNEL); - // Byte reference to the input buffer - u8 *wmi_arg_bytes = (u8 *) wmi_arg; - - u8 wmi_instance = 0x00; - u32 wmi_method_id = 0x04; - struct acpi_buffer wmi_in = { (acpi_size) sizeof(wmi_arg), wmi_arg}; - struct acpi_buffer wmi_out = { ACPI_ALLOCATE_BUFFER, NULL }; - - mutex_lock(&uniwill_ec_lock); - - // Zero input buffer - memset(wmi_arg, 0x00, 10 * sizeof(u32)); - - // Configure the input buffer - wmi_arg_bytes[0] = addr_low; - wmi_arg_bytes[1] = addr_high; - wmi_arg_bytes[2] = data_low; - wmi_arg_bytes[3] = data_high; - - if (read_flag != 0) { - wmi_arg_bytes[5] = 0x01; - } - - status = wmi_evaluate_method(UNIWILL_WMI_MGMT_GUID_BC, wmi_instance, wmi_method_id, &wmi_in, &wmi_out); - out_acpi = (union acpi_object *) wmi_out.pointer; - - if (out_acpi && out_acpi->type == ACPI_TYPE_BUFFER) { - memcpy(return_buffer, out_acpi->buffer.pointer, out_acpi->buffer.length); - } /* else if (out_acpi && out_acpi->type == ACPI_TYPE_INTEGER) { - e_result = (u32) out_acpi->integer.value; - }*/ - if (ACPI_FAILURE(status)) { - pr_err("uniwill_wmi.h: Error evaluating method\n"); - e_result = -EIO; - } - - kfree(out_acpi); - kfree(wmi_arg); - - mutex_unlock(&uniwill_ec_lock); - - return e_result; -} - -/** - * EC address read through WMI - */ -static u32 uw_ec_read_addr_wmi(u8 addr_low, u8 addr_high, union uw_ec_read_return *output) -{ - u32 uw_data[10]; - u32 ret = uw_wmi_ec_evaluate(addr_low, addr_high, 0x00, 0x00, 1, uw_data); - output->dword = uw_data[0]; - // pr_debug("addr: 0x%02x%02x value: %0#4x (high: %0#4x) result: %d\n", addr_high, addr_low, output->bytes.data_low, output->bytes.data_high, ret); - return ret; -} - -/** - * EC address write through WMI - */ -static u32 uw_ec_write_addr_wmi(u8 addr_low, u8 addr_high, u8 data_low, u8 data_high, union uw_ec_write_return *output) -{ - u32 uw_data[10]; - u32 ret = uw_wmi_ec_evaluate(addr_low, addr_high, data_low, data_high, 0, uw_data); - output->dword = uw_data[0]; - return ret; -} - -/** - * Direct EC address read - */ -static u32 uw_ec_read_addr_direct(u8 addr_low, u8 addr_high, union uw_ec_read_return *output) -{ - u32 result; - u8 tmp, count, flags; - - mutex_lock(&uniwill_ec_lock); - - ec_write(UNIWILL_EC_REG_LDAT, addr_low); - ec_write(UNIWILL_EC_REG_HDAT, addr_high); - - flags = (0 << UNIWILL_EC_BIT_DRDY) | (1 << UNIWILL_EC_BIT_RFLG); - ec_write(UNIWILL_EC_REG_FLAGS, flags); - - // Wait for ready flag - count = UW_EC_WAIT_CYCLES; - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - while (((tmp & (1 << UNIWILL_EC_BIT_DRDY)) == 0) && count != 0) { - msleep(1); - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - count -= 1; - } - - if (count != 0) { - output->dword = 0; - ec_read(UNIWILL_EC_REG_CMDL, &tmp); - output->bytes.data_low = tmp; - ec_read(UNIWILL_EC_REG_CMDH, &tmp); - output->bytes.data_high = tmp; - result = 0; - } else { - output->dword = 0xfefefefe; - result = -EIO; - } - - ec_write(UNIWILL_EC_REG_FLAGS, 0x00); - - mutex_unlock(&uniwill_ec_lock); - - // pr_debug("addr: 0x%02x%02x value: %0#4x result: %d\n", addr_high, addr_low, output->bytes.data_low, result); - - return result; -} - -static u32 uw_ec_write_addr_direct(u8 addr_low, u8 addr_high, u8 data_low, u8 data_high, union uw_ec_write_return *output) -{ - u32 result = 0; - u8 tmp, count, flags; - - mutex_lock(&uniwill_ec_lock); - - ec_write(UNIWILL_EC_REG_LDAT, addr_low); - ec_write(UNIWILL_EC_REG_HDAT, addr_high); - ec_write(UNIWILL_EC_REG_CMDL, data_low); - ec_write(UNIWILL_EC_REG_CMDH, data_high); - - flags = (0 << UNIWILL_EC_BIT_DRDY) | (1 << UNIWILL_EC_BIT_WFLG); - ec_write(UNIWILL_EC_REG_FLAGS, flags); - - // Wait for ready flag - count = UW_EC_WAIT_CYCLES; - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - while (((tmp & (1 << UNIWILL_EC_BIT_DRDY)) == 0) && count != 0) { - msleep(1); - ec_read(UNIWILL_EC_REG_FLAGS, &tmp); - count -= 1; - } - - // Replicate wmi output depending on success - if (count != 0) { - output->bytes.addr_low = addr_low; - output->bytes.addr_high = addr_high; - output->bytes.data_low = data_low; - output->bytes.data_high = data_high; - result = 0; - } else { - output->dword = 0xfefefefe; - result = -EIO; - } - - ec_write(UNIWILL_EC_REG_FLAGS, 0x00); - - mutex_unlock(&uniwill_ec_lock); - - return result; -} - -u32 uw_ec_read_addr(u8 addr_low, u8 addr_high, union uw_ec_read_return *output) -{ - if (uniwill_ec_direct) { - return uw_ec_read_addr_direct(addr_low, addr_high, output); - } else { - return uw_ec_read_addr_wmi(addr_low, addr_high, output); - } -} -EXPORT_SYMBOL(uw_ec_read_addr); - -u32 uw_ec_write_addr(u8 addr_low, u8 addr_high, u8 data_low, u8 data_high, union uw_ec_write_return *output) -{ - if (uniwill_ec_direct) { - return uw_ec_write_addr_direct(addr_low, addr_high, data_low, data_high, output); - } else { - return uw_ec_write_addr_wmi(addr_low, addr_high, data_low, data_high, output); - } -} -EXPORT_SYMBOL(uw_ec_write_addr); - -static void uniwill_init(void) -{ -/* u32 i; - union uw_ec_read_return reg_read_return; - union uw_ec_write_return reg_write_return; - - // FIXME Hard set balanced profile until we have implemented a way to - // switch it while tuxedo_io is loaded - uw_ec_write_addr(0x51, 0x07, 0x00, 0x00, ®_write_return); - - // Set manual-mode fan-curve in 0x0743 - 0x0747 - // Some kind of default fan-curve is stored in 0x0786 - 0x078a: Using it to initialize manual-mode fan-curve - for (i = 0; i < 5; ++i) { - uw_ec_read_addr(0x86 + i, 0x07, ®_read_return); - uw_ec_write_addr(0x43 + i, 0x07, reg_read_return.bytes.data_low, 0x00, ®_write_return); - } - - // Zero second fan temp for detection - uw_ec_write_addr(0x4f, 0x04, 0x00, 0x00, ®_write_return); -*/ -} - -static void uniwill_exit(void) -{ - // union uw_ec_write_return reg_write_return; - -} - -#endif diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 9b61dfc..80c968d 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -28,7 +28,6 @@ #include #include "../clevo_interfaces.h" #include "../uniwill_interfaces.h" -#include "tongfang_wmi.h" #include "tuxedo_io_ioctl.h" MODULE_DESCRIPTION("Hardware interface for TUXEDO laptops"); @@ -405,10 +404,6 @@ static int __init tuxedo_io_init(void) static void __exit tuxedo_io_exit(void) { - if (id_check_uniwill == 1) { - uniwill_exit(); - } - device_destroy(tuxedo_io_device_class, tuxedo_io_device_handle); class_destroy(tuxedo_io_device_class); cdev_del(&tuxedo_io_cdev); diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index 835fb87..3c1bf45 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -52,4 +52,22 @@ uniwill_read_ec_ram_t uniwill_read_ec_ram; uniwill_write_ec_ram_t uniwill_write_ec_ram; u32 uniwill_get_active_interface_id(char **id_str); +union uw_ec_read_return { + u32 dword; + struct { + u8 data_low; + u8 data_high; + } bytes; +}; + +union uw_ec_write_return { + u32 dword; + struct { + u8 addr_low; + u8 addr_high; + u8 data_low; + u8 data_high; + } bytes; +}; + #endif diff --git a/src/uniwill_wmi.c b/src/uniwill_wmi.c index 7884304..b3dab9a 100644 --- a/src/uniwill_wmi.c +++ b/src/uniwill_wmi.c @@ -38,24 +38,6 @@ #define UW_EC_WAIT_CYCLES 0x50 -union uw_ec_read_return { - u32 dword; - struct { - u8 data_low; - u8 data_high; - } bytes; -}; - -union uw_ec_write_return { - u32 dword; - struct { - u8 addr_low; - u8 addr_high; - u8 data_low; - u8 data_high; - } bytes; -}; - static bool uniwill_ec_direct = true; DEFINE_MUTEX(uniwill_ec_lock);