From d2ff4e4b839b1937ae7ddd0615b710a64e8b9c7a Mon Sep 17 00:00:00 2001 From: Christoffer Sandberg Date: Sat, 18 Sep 2021 00:30:00 +0200 Subject: [PATCH] Add uniwill interface str id and read for tuxedo_io --- src/tuxedo_io/tongfang_wmi.h | 22 ---------------------- src/tuxedo_io/tuxedo_io.c | 20 +++++++++++++++----- src/tuxedo_io/tuxedo_io_ioctl.h | 1 + src/uniwill_interfaces.h | 1 + src/uniwill_keyboard.h | 14 +++++++++++++- 5 files changed, 30 insertions(+), 28 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 703a348..98ebdf4 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -252,28 +252,6 @@ u32 uw_ec_write_addr(u8 addr_low, u8 addr_high, u8 data_low, u8 data_high, union } EXPORT_SYMBOL(uw_ec_write_addr); -static u32 uniwill_identify(void) -{ - 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; - } - - return 0; -} - static void uniwill_init(void) { /* u32 i; diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 8fb8088..9b61dfc 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -51,6 +51,11 @@ static u32 clevo_identify(void) return clevo_get_active_interface_id(NULL) == 0 ? 1 : 0; } +static u32 uniwill_identify(void) +{ + return uniwill_get_active_interface_id(NULL) == 0 ? 1 : 0; +} + /*static int fop_open(struct inode *inode, struct file *file) { return 0; @@ -205,6 +210,8 @@ static long uniwill_ioctl_interface(struct file *file, unsigned int cmd, unsigne u32 copy_result; u32 argument; u8 byte_data; + const char str_no_if[] = ""; + char *str_uniwill_if; union uw_ec_read_return reg_read_return; union uw_ec_write_return reg_write_return; @@ -218,6 +225,13 @@ static long uniwill_ioctl_interface(struct file *file, unsigned int cmd, unsigne #endif switch (cmd) { + case R_UW_HW_IF_STR: + if (uniwill_get_active_interface_id(&str_uniwill_if) == 0) { + copy_result = copy_to_user((char *) arg, str_uniwill_if, strlen(str_uniwill_if) + 1); + } else { + copy_result = copy_to_user((char *) arg, str_no_if, strlen(str_no_if) + 1); + } + break; case R_UW_FANSPEED: uniwill_read_ec_ram(0x1804, &byte_data); result = byte_data; @@ -363,11 +377,7 @@ static int __init tuxedo_io_init(void) // Hardware identification id_check_clevo = clevo_identify(); - id_check_uniwill = uniwill_identify() == 0 ? 1 : 0; - - if (id_check_uniwill == 1) { - uniwill_init(); - } + id_check_uniwill = uniwill_identify(); #ifdef DEBUG if (id_check_clevo == 0 && id_check_uniwill == 0) { diff --git a/src/tuxedo_io/tuxedo_io_ioctl.h b/src/tuxedo_io/tuxedo_io_ioctl.h index 8a6a22c..f271707 100644 --- a/src/tuxedo_io/tuxedo_io_ioctl.h +++ b/src/tuxedo_io/tuxedo_io_ioctl.h @@ -71,6 +71,7 @@ */ // Read +#define R_UW_HW_IF_STR _IOR(MAGIC_READ_UW, 0x00, char*) #define R_UW_FANSPEED _IOR(MAGIC_READ_UW, 0x10, int32_t*) #define R_UW_FANSPEED2 _IOR(MAGIC_READ_UW, 0x11, int32_t*) #define R_UW_FAN_TEMP _IOR(MAGIC_READ_UW, 0x12, int32_t*) diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index e66bff2..835fb87 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -50,5 +50,6 @@ u32 uniwill_add_interface(struct uniwill_interface_t *new_interface); u32 uniwill_remove_interface(struct uniwill_interface_t *interface); 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); #endif diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index e03b569..f2bf3d3 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -90,7 +90,7 @@ static struct key_entry uniwill_wmi_keymap[] = { static struct uniwill_interfaces_t { struct uniwill_interface_t *wmi; -} uniwill_interfaces; +} uniwill_interfaces = { .wmi = NULL }; uniwill_event_callb_t uniwill_event_callb; @@ -168,6 +168,18 @@ u32 uniwill_remove_interface(struct uniwill_interface_t *interface) } EXPORT_SYMBOL(uniwill_remove_interface); +u32 uniwill_get_active_interface_id(char **id_str) +{ + if (IS_ERR_OR_NULL(uniwill_interfaces.wmi)) + return -ENODEV; + + if (!IS_ERR_OR_NULL(id_str)) + *id_str = uniwill_interfaces.wmi->string_id; + + return 0; +} +EXPORT_SYMBOL(uniwill_get_active_interface_id); + static void key_event_work(struct work_struct *work) { sparse_keymap_report_known_event(