From 2d33628610302171e7d5082217f384d091a05ff2 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Mon, 15 Feb 2021 22:01:13 +0100 Subject: [PATCH 1/5] Proof of concept initialization of manual-mode fan-curve --- src/tuxedo_io/tongfang_wmi.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 001413f..7160c34 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -16,6 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this software. If not, see . */ +#pragma once + #include #include #include @@ -273,7 +275,26 @@ static u32 uniwill_identify(void) static void uniwill_init(void) { + u32 i; + u8 uninitialized; + union uw_ec_read_return reg_read_return; union uw_ec_write_return reg_write_return; + // default fan-curve set by Tongfang Windows OSD-driver on Tuxedo Book BA15 + u8 default_fan_curve[5] = {0x32, 0x5a, 0x64, 0x6e, 0x78}; + + // Set manual-mode fan-curve if uninitialized + uninitialized = 1; + for (i = 0; i < 5; ++i) { + uw_ec_read_addr(0x43 + i, 0x07, ®_read_return); + if (reg_read_return.bytes.data_low != 0x00) { + uninitialized = 0; + } + } + if (uninitialized) { + for (i = 0; i < 5; ++i) { + uw_ec_write_addr(0x43 + i, 0x07, default_fan_curve[i], 0x00, ®_write_return); + } + } // Enable manual mode uw_ec_write_addr(0x41, 0x07, 0x01, 0x00, ®_write_return); From 1b58247daf05c9c2c337aacdfd2c5def3169c393 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Tue, 16 Feb 2021 16:50:44 +0100 Subject: [PATCH 2/5] Use default values found elsewhere in the ec memory insted of hardcoded values --- src/tuxedo_io/tongfang_wmi.h | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 7160c34..05c9c93 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -279,10 +279,8 @@ static void uniwill_init(void) u8 uninitialized; union uw_ec_read_return reg_read_return; union uw_ec_write_return reg_write_return; - // default fan-curve set by Tongfang Windows OSD-driver on Tuxedo Book BA15 - u8 default_fan_curve[5] = {0x32, 0x5a, 0x64, 0x6e, 0x78}; - // Set manual-mode fan-curve if uninitialized + // Check if manual-mode fan-curve stored in 0x0743 - 0x0747 is initialized uninitialized = 1; for (i = 0; i < 5; ++i) { uw_ec_read_addr(0x43 + i, 0x07, ®_read_return); @@ -290,9 +288,12 @@ static void uniwill_init(void) uninitialized = 0; } } + // Set manual-mode fan-curve if uninitialized if (uninitialized) { + // 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_write_addr(0x43 + i, 0x07, default_fan_curve[i], 0x00, ®_write_return); + 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); } } From ea23edca26c663c6622ca5cf883859f40d6320cc Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Thu, 18 Feb 2021 20:18:05 +0100 Subject: [PATCH 3/5] Use universal header guard --- src/tuxedo_io/tongfang_wmi.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index 05c9c93..fe3bd97 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -16,7 +16,8 @@ * You should have received a copy of the GNU General Public License * along with this software. If not, see . */ -#pragma once +#ifndef TONGFANG_WMI_H +#define TONGFANG_WMI_H #include #include @@ -348,3 +349,5 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) return 0; } + +#endif From cbb258e13d590df5c88ee573184fa66b1302477f Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Thu, 25 Feb 2021 14:40:47 +0100 Subject: [PATCH 4/5] Always initialize custom fan curve to prevent inconsistencies --- src/tuxedo_io/tongfang_wmi.h | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/tuxedo_io/tongfang_wmi.h b/src/tuxedo_io/tongfang_wmi.h index fe3bd97..9f4fa9e 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -283,12 +283,15 @@ static void uniwill_init(void) // Check if manual-mode fan-curve stored in 0x0743 - 0x0747 is initialized uninitialized = 1; - for (i = 0; i < 5; ++i) { + // Uninitialized check unused: The Windows driver overwrites these values + // on start and on Linux we don't have an offical way to customize this + // setting so we just reset them to default every start to prevent inconsitencies + /*for (i = 0; i < 5; ++i) { uw_ec_read_addr(0x43 + i, 0x07, ®_read_return); if (reg_read_return.bytes.data_low != 0x00) { uninitialized = 0; } - } + }*/ // Set manual-mode fan-curve if uninitialized if (uninitialized) { // Some kind of default fan-curve is stored in 0x0786 - 0x078a: Using it to initialize manual-mode fan-curve From 6519645696499d73b198658637a329e25cc2dff3 Mon Sep 17 00:00:00 2001 From: Werner Sembach Date: Thu, 25 Feb 2021 15:11:19 +0100 Subject: [PATCH 5/5] Fix typo and use bool type --- 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 9f4fa9e..1eaa475 100644 --- a/src/tuxedo_io/tongfang_wmi.h +++ b/src/tuxedo_io/tongfang_wmi.h @@ -277,15 +277,15 @@ static u32 uniwill_identify(void) static void uniwill_init(void) { u32 i; - u8 uninitialized; + bool uninitialized; union uw_ec_read_return reg_read_return; union uw_ec_write_return reg_write_return; // Check if manual-mode fan-curve stored in 0x0743 - 0x0747 is initialized - uninitialized = 1; + uninitialized = true; // Uninitialized check unused: The Windows driver overwrites these values // on start and on Linux we don't have an offical way to customize this - // setting so we just reset them to default every start to prevent inconsitencies + // setting so we just reset them to default every start to prevent inconsistencies /*for (i = 0; i < 5; ++i) { uw_ec_read_addr(0x43 + i, 0x07, ®_read_return); if (reg_read_return.bytes.data_low != 0x00) {