From 74fb5ab4b8ee1374766a1f8adc2736b0791b706b Mon Sep 17 00:00:00 2001 From: Luke Dashjr Date: Tue, 14 Jan 2014 22:22:07 +0000 Subject: [PATCH] adl: Set iSpeedType to RPM for get-fanspeed requests ...and ensure we don't change do something weird with the fan when initially setting user-defined speed flag. Fixes crash on R9 cards. Thanks to tkg for hints on what was wrong! RPM preferred over percent since writing RPM back is always supported (while percent is not in some cases). Conflicts: adl.c --- adl.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/adl.c b/adl.c index ed78053d..dff6794f 100644 --- a/adl.c +++ b/adl.c @@ -473,8 +473,8 @@ void init_adl(int nDevs) ga->lpTemperature.iSize = sizeof(ADLTemperature); ga->lpFanSpeedInfo.iSize = sizeof(ADLFanSpeedInfo); ga->lpFanSpeedValue.iSize = ga->DefFanSpeedValue.iSize = sizeof(ADLFanSpeedValue); - ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - ga->DefFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; + ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM; + ga->DefFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM; /* Now get the current performance levels for any existing overclock */ if (ADL_Overdrive5_ODPerformanceLevels_Get(iAdapterIndex, 0, lpOdPerformanceLevels) != ADL_OK) @@ -546,6 +546,7 @@ void init_adl(int nDevs) applog(LOG_INFO, "Failed to ADL_Overdrive5_FanSpeed_Get for default value"); else ga->def_fan_valid = true; + if (gpus[gpu].gpu_fan) set_fanspeed(gpu, gpus[gpu].gpu_fan); else @@ -1089,20 +1090,21 @@ int set_fanspeed(int gpu, int iFanSpeed) ga->targetfan = iFanSpeed; lock_adl(); + ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM; if (ADL_Overdrive5_FanSpeed_Get(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue) != ADL_OK) { applog(LOG_DEBUG, "GPU %d call to fanspeed get failed", gpu); } + if (!(ga->lpFanSpeedValue.iFlags & ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED)) { + /* If user defined is not already specified, set it first */ + ga->lpFanSpeedValue.iFlags |= ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; + ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue); + } if (!(ga->lpFanSpeedInfo.iFlags & ADL_DL_FANCTRL_SUPPORTS_PERCENT_WRITE)) { /* Must convert speed to an RPM */ iFanSpeed = ga->lpFanSpeedInfo.iMaxRPM * iFanSpeed / 100; ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_RPM; } else ga->lpFanSpeedValue.iSpeedType = ADL_DL_FANCTRL_SPEED_TYPE_PERCENT; - if (!(ga->lpFanSpeedValue.iFlags & ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED)) { - /* If user defined is not already specified, set it first */ - ga->lpFanSpeedValue.iFlags = ADL_DL_FANCTRL_FLAG_USER_DEFINED_SPEED; - ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue); - } ga->lpFanSpeedValue.iFanSpeed = iFanSpeed; ret = ADL_Overdrive5_FanSpeed_Set(ga->iAdapterIndex, 0, &ga->lpFanSpeedValue); ga->managed = true;