diff --git a/src/tuxedo_io/tuxedo_io.c b/src/tuxedo_io/tuxedo_io.c index 1121ebd..98f27ce 100644 --- a/src/tuxedo_io/tuxedo_io.c +++ b/src/tuxedo_io/tuxedo_io.c @@ -262,24 +262,6 @@ static long clevo_ioctl_interface(struct file *file, unsigned int cmd, unsigned return 0; } -static int has_universal_ec_fan_control(void) { - int ret; - u8 data; - - if (uw_feats->model == UW_MODEL_PH4TRX) { - // For some reason, on this particular device, the 2nd fan is not controlled via the - // "GPU" fan curve when the bit to separate both fancurves is set, but the old fan - // control works just fine. - return 0; - } - - ret = uniwill_read_ec_ram(0x078e, &data); - if (ret < 0) { - return ret; - } - return (data >> 6) & 1; -} - static int set_full_fan_mode(bool enable) { u8 mode_data; @@ -315,7 +297,7 @@ static int uw_init_fan(void) { u16 addr_gpu_custom_fan_table_start_temp = 0x0f40; u16 addr_gpu_custom_fan_table_fan_speed = 0x0f50; - if (!fans_initialized && (has_universal_ec_fan_control() == 1)) { + if (!fans_initialized && uw_feats->uniwill_has_universal_ec_fan_control) { set_full_fan_mode(false); uniwill_read_ec_ram(addr_use_custom_fan_table_0, &value_use_custom_fan_table_0); @@ -360,7 +342,7 @@ static u32 uw_set_fan(u32 fan_index, u8 fan_speed) u16 addr_cpu_custom_fan_table_fan_speed = 0x0f20; u16 addr_gpu_custom_fan_table_fan_speed = 0x0f50; - if (has_universal_ec_fan_control() == 1) { + if (uw_feats->uniwill_has_universal_ec_fan_control) { uw_init_fan(); if (fan_index == 0) @@ -416,7 +398,7 @@ static u32 uw_set_fan_auto(void) { u8 mode_data; - if (has_universal_ec_fan_control() == 1) { + if (uw_feats->uniwill_has_universal_ec_fan_control) { u16 addr_use_custom_fan_table_0 = 0x07c5; // use different tables for both fans (0x0f00-0x0f2f and 0x0f30-0x0f5f respectivly) u16 addr_use_custom_fan_table_1 = 0x07c6; // enable 0x0fxx fantables u8 offset_use_custom_fan_table_0 = 7; @@ -611,7 +593,7 @@ static long uniwill_ioctl_interface(struct file *file, unsigned int cmd, unsigne copy_result = copy_to_user((void *) arg, &result, sizeof(result)); break; case R_UW_FANS_OFF_AVAILABLE: - /*result = has_universal_ec_fan_control(); + /*result = uw_feats->uniwill_has_universal_ec_fan_control ? 1 : 0; if (result == 1) { result = 0; } @@ -622,7 +604,7 @@ static long uniwill_ioctl_interface(struct file *file, unsigned int cmd, unsigne copy_result = copy_to_user((void *) arg, &result, sizeof(result)); break; case R_UW_FANS_MIN_SPEED: - /*result = has_universal_ec_fan_control(); + /*result = uw_feats->uniwill_has_universal_ec_fan_control? 1 : 0; if (result == 1) { result = 20; } diff --git a/src/uniwill_interfaces.h b/src/uniwill_interfaces.h index 705ccda..ceba580 100644 --- a/src/uniwill_interfaces.h +++ b/src/uniwill_interfaces.h @@ -106,6 +106,7 @@ struct uniwill_device_features_t { bool uniwill_profile_v1_three_profs_leds_only; bool uniwill_has_charging_prio; bool uniwill_has_charging_profile; + bool uniwill_has_universal_ec_fan_control; }; struct uniwill_device_features_t *uniwill_get_device_features(void); diff --git a/src/uniwill_keyboard.h b/src/uniwill_keyboard.h index e72d4ee..332acd6 100644 --- a/src/uniwill_keyboard.h +++ b/src/uniwill_keyboard.h @@ -950,10 +950,31 @@ static ssize_t uw_charging_prio_store(struct device *child, return -EINVAL; } +static int has_universal_ec_fan_control(void) { + int ret; + u8 data; + + struct uniwill_device_features_t *uw_feats = &uniwill_device_features; + + if (uw_feats->model == UW_MODEL_PH4TRX) { + // For some reason, on this particular device, the 2nd fan is not controlled via the + // "GPU" fan curve when the bit to separate both fancurves is set, but the old fan + // control works just fine. + return 0; + } + + ret = uniwill_read_ec_ram(0x078e, &data); + if (ret < 0) { + return ret; + } + return (data >> 6) & 1; +} + struct uniwill_device_features_t *uniwill_get_device_features(void) { struct uniwill_device_features_t *uw_feats = &uniwill_device_features; u32 status; + int result; bool feats_loaded; if (uw_feats_loaded) @@ -1013,6 +1034,14 @@ struct uniwill_device_features_t *uniwill_get_device_features(void) if (uw_has_charging_profile(&uw_feats->uniwill_has_charging_profile) != 0) feats_loaded = false; + result = has_universal_ec_fan_control(); + if (result < 0) { + feats_loaded = false; + } else { + uw_feats->uniwill_has_universal_ec_fan_control = (result == 1); + } + + if (feats_loaded) pr_debug("feats loaded\n"); else