Commit 96026ce0 authored by Likun Gao's avatar Likun Gao Committed by Alex Deucher

drm/amd/powerplay: set fan target interface for hwmon

Add fan1_target set interface to set fan speed for hwmon.
Signed-off-by: default avatarLikun Gao <Likun.Gao@amd.com>
Reviewed-by: default avatarKevin Wang <kevin1.wang@amd.com>
Reviewed-by: default avatarHuang Rui <ray.huang@amd.com>
Reviewed-by: default avatarAlex Deucher <alexander.deucher@amd.com>
Signed-off-by: default avatarAlex Deucher <alexander.deucher@amd.com>
parent da5f18e8
...@@ -1606,7 +1606,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev, ...@@ -1606,7 +1606,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
u32 value; u32 value;
u32 pwm_mode; u32 pwm_mode;
if (is_support_sw_smu(adev))
pwm_mode = smu_get_fan_control_mode(&adev->smu);
else
pwm_mode = amdgpu_dpm_get_fan_control_mode(adev); pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
if (pwm_mode != AMD_FAN_CTRL_MANUAL) if (pwm_mode != AMD_FAN_CTRL_MANUAL)
return -ENODATA; return -ENODATA;
...@@ -1619,7 +1623,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev, ...@@ -1619,7 +1623,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
if (err) if (err)
return err; return err;
if (adev->powerplay.pp_funcs->set_fan_speed_rpm) { if (is_support_sw_smu(adev)) {
err = smu_set_fan_speed_rpm(&adev->smu, value);
if (err)
return err;
} else if (adev->powerplay.pp_funcs->set_fan_speed_rpm) {
err = amdgpu_dpm_set_fan_speed_rpm(adev, value); err = amdgpu_dpm_set_fan_speed_rpm(adev, value);
if (err) if (err)
return err; return err;
......
...@@ -536,6 +536,7 @@ struct smu_funcs ...@@ -536,6 +536,7 @@ struct smu_funcs
int (*set_fan_control_mode)(struct smu_context *smu, uint32_t mode); int (*set_fan_control_mode)(struct smu_context *smu, uint32_t mode);
int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed); int (*get_fan_speed_percent)(struct smu_context *smu, uint32_t *speed);
int (*set_fan_speed_percent)(struct smu_context *smu, uint32_t speed); int (*set_fan_speed_percent)(struct smu_context *smu, uint32_t speed);
int (*set_fan_speed_rpm)(struct smu_context *smu, uint32_t speed);
}; };
#define smu_init_microcode(smu) \ #define smu_init_microcode(smu) \
...@@ -588,6 +589,8 @@ struct smu_funcs ...@@ -588,6 +589,8 @@ struct smu_funcs
((smu)->funcs->update_od8_settings ? (smu)->funcs->update_od8_settings((smu), (index), (value)) : 0) ((smu)->funcs->update_od8_settings ? (smu)->funcs->update_od8_settings((smu), (index), (value)) : 0)
#define smu_get_current_rpm(smu, speed) \ #define smu_get_current_rpm(smu, speed) \
((smu)->funcs->get_current_rpm ? (smu)->funcs->get_current_rpm((smu), (speed)) : 0) ((smu)->funcs->get_current_rpm ? (smu)->funcs->get_current_rpm((smu), (speed)) : 0)
#define smu_set_fan_speed_rpm(smu, speed) \
((smu)->funcs->set_fan_speed_rpm ? (smu)->funcs->set_fan_speed_rpm((smu), (speed)) : 0)
#define smu_send_smc_msg(smu, msg) \ #define smu_send_smc_msg(smu, msg) \
((smu)->funcs->send_smc_msg? (smu)->funcs->send_smc_msg((smu), (msg)) : 0) ((smu)->funcs->send_smc_msg? (smu)->funcs->send_smc_msg((smu), (msg)) : 0)
#define smu_send_smc_msg_with_param(smu, msg, param) \ #define smu_send_smc_msg_with_param(smu, msg, param) \
......
...@@ -1864,6 +1864,36 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu, ...@@ -1864,6 +1864,36 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu,
return ret; return ret;
} }
static int smu_v11_0_set_fan_speed_rpm(struct smu_context *smu,
uint32_t speed)
{
struct amdgpu_device *adev = smu->adev;
int ret;
uint32_t tach_period, crystal_clock_freq;
bool stop = 0;
if (!speed)
return -EINVAL;
mutex_lock(&(smu->mutex));
ret = smu_v11_0_smc_fan_control(smu, stop);
if (ret)
goto set_fan_speed_rpm_failed;
crystal_clock_freq = amdgpu_asic_get_xclk(adev);
tach_period = 60 * crystal_clock_freq * 10000 / (8 * speed);
WREG32_SOC15(THM, 0, mmCG_TACH_CTRL,
REG_SET_FIELD(RREG32_SOC15(THM, 0, mmCG_TACH_CTRL),
CG_TACH_CTRL, TARGET_PERIOD,
tach_period));
ret = smu_v11_0_set_fan_static_mode(smu, FDO_PWM_MODE_STATIC_RPM);
set_fan_speed_rpm_failed:
mutex_unlock(&(smu->mutex));
return ret;
}
static const struct smu_funcs smu_v11_0_funcs = { static const struct smu_funcs smu_v11_0_funcs = {
.init_microcode = smu_v11_0_init_microcode, .init_microcode = smu_v11_0_init_microcode,
.load_microcode = smu_v11_0_load_microcode, .load_microcode = smu_v11_0_load_microcode,
...@@ -1919,6 +1949,7 @@ static const struct smu_funcs smu_v11_0_funcs = { ...@@ -1919,6 +1949,7 @@ static const struct smu_funcs smu_v11_0_funcs = {
.set_fan_control_mode = smu_v11_0_set_fan_control_mode, .set_fan_control_mode = smu_v11_0_set_fan_control_mode,
.get_fan_speed_percent = smu_v11_0_get_fan_speed_percent, .get_fan_speed_percent = smu_v11_0_get_fan_speed_percent,
.set_fan_speed_percent = smu_v11_0_set_fan_speed_percent, .set_fan_speed_percent = smu_v11_0_set_fan_speed_percent,
.set_fan_speed_rpm = smu_v11_0_set_fan_speed_rpm,
}; };
void smu_v11_0_set_smu_funcs(struct smu_context *smu) void smu_v11_0_set_smu_funcs(struct smu_context *smu)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment