From 4306a8051380fd04d7f71d68bb2e3a8cebfbc473 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Fri, 19 Feb 2021 21:04:08 +0100 Subject: [PATCH 1/8] Only set one bit required for full-fan-mode and not whole byte --- src/tuxedo_io/tongfang_wmi.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 001413f..deb488c 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -308,9 +308,9 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) // Check current mode uw_ec_read_addr(0x51, 0x07, ®_read_return); - if (reg_read_return.bytes.data_low != 0x40) { - // If not "full fan mode" (ie. 0x40) switch to it (required for fancontrol) - uw_ec_write_addr(0x51, 0x07, 0x40, 0x00, ®_write_return); + if (!(reg_read_return.bytes.data_low & 0x40)) { + // If not "full fan mode" (ie. 0x40 bit set) switch to it (required for fancontrol) + uw_ec_write_addr(0x51, 0x07, reg_read_return.bytes.data_low | 0x40, 0x00, ®_write_return); // Attempt to write both fans as quick as possible before complete ramp-up pr_debug("prevent ramp-up start\n"); for (i = 0; i < 10; ++i) { From 5b99255be8f9b08819a710bf4e251954ed50bd52 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Fri, 19 Feb 2021 21:33:30 +0100 Subject: [PATCH 2/8] Add ioctl to reset fanspeed to auto --- src/tuxedo_io/tongfang_wmi.h | 27 ++++++++++++++++++++++++++- src/tuxedo_io/tuxedo_io.c | 3 +++ src/tuxedo_io/tuxedo_io_ioctl.h | 1 + 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index deb488c..1da271e 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -309,7 +309,7 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) // Check current mode uw_ec_read_addr(0x51, 0x07, ®_read_return); if (!(reg_read_return.bytes.data_low & 0x40)) { - // If not "full fan mode" (ie. 0x40 bit set) switch to it (required for fancontrol) + // If not "full fan mode" (i.e. 0x40 bit set) switch to it (required for fancontrol) uw_ec_write_addr(0x51, 0x07, reg_read_return.bytes.data_low | 0x40, 0x00, ®_write_return); // Attempt to write both fans as quick as possible before complete ramp-up pr_debug("prevent ramp-up start\n"); @@ -326,3 +326,28 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) return 0; } + +static u32 uw_set_fan_auto() +{ + u8 reg_high = 0x18; + u32 i; + union uw_ec_read_return reg_read_return; + union uw_ec_write_return reg_write_return; + u8 low_reg_fan0 = 0x04; + u8 low_reg_fan1 = 0x09; + + // Check current mode + uw_ec_read_addr(0x51, 0x07, ®_read_return); + if (reg_read_return.bytes.data_low & 0x40) { + // If "full fan mode" (i.e. 0x40 bit set) switch it off + uw_ec_write_addr(0x51, 0x07, reg_read_return.bytes.data_low & 0xbf, 0x00, ®_write_return); + // Attempt to write both fans to 100% to restore default "full fan mode" + for (i = 0; i < 10; ++i) { + uw_ec_write_addr(low_reg_fan0, reg_high, 0xc8, 0x00, ®_write_return); + uw_ec_write_addr(low_reg_fan1, reg_high, 0xc8, 0x00, ®_write_return); + msleep(10); + } + } + + return 0; +} diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 032cd10..268410d 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -229,6 +229,9 @@ static long uniwill_ioctl_interface(struct file *file, unsigned int cmd, unsigne uw_ec_write_addr(0x41, 0x07, argument & 0x01, 0x00, ®_write_return); */ break; + case W_UW_FANAUTO: + uw_set_fan_auto(); + break; #ifdef DEBUG case W_TF_BC: copy_result = copy_from_user(&uw_arg, (void *) arg, sizeof(uw_arg)); diff --git a/src/tuxedo_io/tuxedo_io_ioctl.h b/src/tuxedo_io/tuxedo_io_ioctl.h index ccef035..1af3ae4 100644 --- a/src/tuxedo_io/tuxedo_io_ioctl.h +++ b/src/tuxedo_io/tuxedo_io_ioctl.h @@ -83,5 +83,6 @@ #define W_UW_FANSPEED2 _IOW(MAGIC_WRITE_UW, 0x11, int32_t*) #define W_UW_MODE _IOW(MAGIC_WRITE_UW, 0x12, int32_t*) #define W_UW_MODE_ENABLE _IOW(MAGIC_WRITE_UW, 0x13, int32_t*) +#define W_UW_FANAUTO _IOW(MAGIC_WRITE_UW, 0x14) // undo all previous calls of W_UW_FANSPEED and W_UW_FANSPEED2 #endif From 226a40b8fb48ec6d8e2dddce25b33f79a58a8014 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 22 Feb 2021 20:12:58 +0100 Subject: [PATCH 3/8] Fix wrong macro call breaking compilation and add header guard --- src/tuxedo_io/tongfang_wmi.h | 7 ++++++- src/tuxedo_io/tuxedo_io_ioctl.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 1da271e..c19bc9c 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -16,6 +16,9 @@ * 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 @@ -327,7 +330,7 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) return 0; } -static u32 uw_set_fan_auto() +static u32 uw_set_fan_auto(void) { u8 reg_high = 0x18; u32 i; @@ -351,3 +354,5 @@ static u32 uw_set_fan_auto() return 0; } + +#endif diff --git a/src/tuxedo_io/tuxedo_io_ioctl.h b/src/tuxedo_io/tuxedo_io_ioctl.h index 1af3ae4..c86edc3 100644 --- a/src/tuxedo_io/tuxedo_io_ioctl.h +++ b/src/tuxedo_io/tuxedo_io_ioctl.h @@ -83,6 +83,6 @@ #define W_UW_FANSPEED2 _IOW(MAGIC_WRITE_UW, 0x11, int32_t*) #define W_UW_MODE _IOW(MAGIC_WRITE_UW, 0x12, int32_t*) #define W_UW_MODE_ENABLE _IOW(MAGIC_WRITE_UW, 0x13, int32_t*) -#define W_UW_FANAUTO _IOW(MAGIC_WRITE_UW, 0x14) // undo all previous calls of W_UW_FANSPEED and W_UW_FANSPEED2 +#define W_UW_FANAUTO _IO(MAGIC_WRITE_UW, 0x14) // undo all previous calls of W_UW_FANSPEED and W_UW_FANSPEED2 #endif From 96a9485a84d1af929fb335fe741345e7a34e40d0 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 24 Feb 2021 19:56:58 +0100 Subject: [PATCH 4/8] Set balanced profile on init for the time being until we have a way to switch it while tuxedo_io is loaded --- src/tuxedo_io/tongfang_wmi.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index c19bc9c..6d5c959 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -277,6 +277,10 @@ static u32 uniwill_identify(void) static void uniwill_init(void) { 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); // Enable manual mode uw_ec_write_addr(0x41, 0x07, 0x01, 0x00, ®_write_return); From 04756030d6f15f111c1830ad6f9bc880959b3d5d Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 24 Feb 2021 20:33:59 +0100 Subject: [PATCH 5/8] Ignore kdevelop project files --- .gitignore | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 0adeb91..ea2bea9 100644 --- a/.gitignore +++ b/.gitignore @@ -18,9 +18,10 @@ Mkfile.old *.mk .vscode/ +*.kdev4 # Packaging rpm deb/tuxedo-keyboard-* *.deb -*.rpm \ No newline at end of file +*.rpm From b8cb3ed34b4398c70c822c1124b06d8ac2dfe1ae Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 24 Feb 2021 20:35:02 +0100 Subject: [PATCH 6/8] Bump version and add defines to check for minimum version with new ioctl --- src/tuxedo_io/tuxedo_io.c | 2 +- src/tuxedo_io/tuxedo_io_ioctl.h | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 268410d..4fbd794 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -32,7 +32,7 @@ MODULE_DESCRIPTION("Hardware interface for TUXEDO laptops"); MODULE_AUTHOR("TUXEDO Computers GmbH "); -MODULE_VERSION("0.2.1"); +MODULE_VERSION("0.2.2"); MODULE_LICENSE("GPL"); MODULE_ALIAS_CLEVO_INTERFACES(); diff --git a/src/tuxedo_io/tuxedo_io_ioctl.h b/src/tuxedo_io/tuxedo_io_ioctl.h index c86edc3..6a8e61c 100644 --- a/src/tuxedo_io/tuxedo_io_ioctl.h +++ b/src/tuxedo_io/tuxedo_io_ioctl.h @@ -83,6 +83,10 @@ #define W_UW_FANSPEED2 _IOW(MAGIC_WRITE_UW, 0x11, int32_t*) #define W_UW_MODE _IOW(MAGIC_WRITE_UW, 0x12, int32_t*) #define W_UW_MODE_ENABLE _IOW(MAGIC_WRITE_UW, 0x13, int32_t*) + +#define MIN_MAJOR_W_UW_FANAUTO 0 +#define MIN_MINOR_W_UW_FANAUTO 2 +#define MIN_PATCH_W_UW_FANAUTO 2 #define W_UW_FANAUTO _IO(MAGIC_WRITE_UW, 0x14) // undo all previous calls of W_UW_FANSPEED and W_UW_FANSPEED2 #endif From f2b722c7b6e7e59a89b4e01fbf3519ce1915e690 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Wed, 3 Mar 2021 12:09:52 +0100 Subject: [PATCH 7/8] Don't reset fan speed on disable full-fan-mode because it gets reset automatically --- src/tuxedo_io/tongfang_wmi.h | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 6d5c959..b4ba64a 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -336,25 +336,13 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) static u32 uw_set_fan_auto(void) { - u8 reg_high = 0x18; - u32 i; union uw_ec_read_return reg_read_return; union uw_ec_write_return reg_write_return; - u8 low_reg_fan0 = 0x04; - u8 low_reg_fan1 = 0x09; - // Check current mode + // Get current mode uw_ec_read_addr(0x51, 0x07, ®_read_return); - if (reg_read_return.bytes.data_low & 0x40) { - // If "full fan mode" (i.e. 0x40 bit set) switch it off - uw_ec_write_addr(0x51, 0x07, reg_read_return.bytes.data_low & 0xbf, 0x00, ®_write_return); - // Attempt to write both fans to 100% to restore default "full fan mode" - for (i = 0; i < 10; ++i) { - uw_ec_write_addr(low_reg_fan0, reg_high, 0xc8, 0x00, ®_write_return); - uw_ec_write_addr(low_reg_fan1, reg_high, 0xc8, 0x00, ®_write_return); - msleep(10); - } - } + // Switch off "full fan mode" (i.e. unset 0x40 bit) + uw_ec_write_addr(0x51, 0x07, reg_read_return.bytes.data_low & 0xbf, 0x00, ®_write_return); return 0; } From d24f698dd021255feba0ecabe616a6f78aeb0256 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 16 Mar 2021 14:24:18 +0000 Subject: [PATCH 8/8] Remove minimum version defines for single ioctl --- src/tuxedo_io/tuxedo_io_ioctl.h | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/tuxedo_io/tuxedo_io_ioctl.h b/src/tuxedo_io/tuxedo_io_ioctl.h index 6a8e61c..c86edc3 100644 --- a/src/tuxedo_io/tuxedo_io_ioctl.h +++ b/src/tuxedo_io/tuxedo_io_ioctl.h @@ -83,10 +83,6 @@ #define W_UW_FANSPEED2 _IOW(MAGIC_WRITE_UW, 0x11, int32_t*) #define W_UW_MODE _IOW(MAGIC_WRITE_UW, 0x12, int32_t*) #define W_UW_MODE_ENABLE _IOW(MAGIC_WRITE_UW, 0x13, int32_t*) - -#define MIN_MAJOR_W_UW_FANAUTO 0 -#define MIN_MINOR_W_UW_FANAUTO 2 -#define MIN_PATCH_W_UW_FANAUTO 2 #define W_UW_FANAUTO _IO(MAGIC_WRITE_UW, 0x14) // undo all previous calls of W_UW_FANSPEED and W_UW_FANSPEED2 #endif