All of lore.kernel.org
 help / color / mirror / Atom feed
From: Huang Rui <ray.huang-5C7GfCeVMHo@public.gmane.org>
To: amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org
Cc: Likun Gao <Likun.Gao-5C7GfCeVMHo@public.gmane.org>,
	Kevin Wang <Kevin1.Wang-5C7GfCeVMHo@public.gmane.org>,
	Chengming Gui <Jack.Gui-5C7GfCeVMHo@public.gmane.org>
Subject: [PATCH 09/26] drm/amd/powerplay: set fan target interface for hwmon
Date: Mon, 25 Feb 2019 20:12:15 +0800	[thread overview]
Message-ID: <1551096752-18205-10-git-send-email-ray.huang@amd.com> (raw)
In-Reply-To: <1551096752-18205-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>

From: Likun Gao <Likun.Gao@amd.com>

Add fan1_target set interface to set fan speed for hwmon.

Signed-off-by: Likun Gao <Likun.Gao@amd.com>
Reviewed-by: Kevin Wang <kevin1.wang@amd.com>
Reviewed-by: Huang Rui <ray.huang@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c         | 12 ++++++++--
 drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h |  3 +++
 drivers/gpu/drm/amd/powerplay/smu_v11_0.c      | 31 ++++++++++++++++++++++++++
 3 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
index 9413c39..6bc80c1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_pm.c
@@ -1606,7 +1606,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
 	u32 value;
 	u32 pwm_mode;
 
-	pwm_mode = amdgpu_dpm_get_fan_control_mode(adev);
+	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);
+
 	if (pwm_mode != AMD_FAN_CTRL_MANUAL)
 		return -ENODATA;
 
@@ -1619,7 +1623,11 @@ static ssize_t amdgpu_hwmon_set_fan1_target(struct device *dev,
 	if (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);
 		if (err)
 			return err;
diff --git a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
index ef2b807..8464fdb 100644
--- a/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
+++ b/drivers/gpu/drm/amd/powerplay/inc/amdgpu_smu.h
@@ -536,6 +536,7 @@ struct smu_funcs
 	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 (*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) \
@@ -588,6 +589,8 @@ struct smu_funcs
 	((smu)->funcs->update_od8_settings ? (smu)->funcs->update_od8_settings((smu), (index), (value)) : 0)
 #define smu_get_current_rpm(smu, speed) \
 	((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) \
 	((smu)->funcs->send_smc_msg? (smu)->funcs->send_smc_msg((smu), (msg)) : 0)
 #define smu_send_smc_msg_with_param(smu, msg, param) \
diff --git a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
index c0bc4f4..4864de4 100644
--- a/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
+++ b/drivers/gpu/drm/amd/powerplay/smu_v11_0.c
@@ -1863,6 +1863,36 @@ smu_v11_0_set_fan_control_mode(struct smu_context *smu,
 	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 = {
 	.init_microcode = smu_v11_0_init_microcode,
 	.load_microcode = smu_v11_0_load_microcode,
@@ -1918,6 +1948,7 @@ static const struct smu_funcs smu_v11_0_funcs = {
 	.set_fan_control_mode = smu_v11_0_set_fan_control_mode,
 	.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_rpm = smu_v11_0_set_fan_speed_rpm,
 };
 
 void smu_v11_0_set_smu_funcs(struct smu_context *smu)
-- 
2.7.4

_______________________________________________
amd-gfx mailing list
amd-gfx@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

  parent reply	other threads:[~2019-02-25 12:12 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-25 12:12 [PATCH 00/26] Updates for SW SMU driver Huang Rui
     [not found] ` <1551096752-18205-1-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-25 12:12   ` [PATCH 01/26] drm/amd/powerplay: debugfs don't check powerplay when SW SMU is enabled Huang Rui
2019-02-25 12:12   ` [PATCH 02/26] drm/amd/powerplay: add fan rpm limit interface for hwmon Huang Rui
2019-02-25 12:12   ` [PATCH 03/26] drm/amd/powerplay: add fan input " Huang Rui
2019-02-25 12:12   ` [PATCH 04/26] drm/amd/powerplay: implement power1_cap and power1_cap_max interface for SMU11 Huang Rui
     [not found]     ` <1551096752-18205-5-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-26  3:55       ` Alex Deucher
2019-02-25 12:12   ` [PATCH 05/26] drm/amd/powerplay: add STABLE_PSTATE_SCLK and STABLE_PSTATE_MCLK when read sensor " Huang Rui
2019-02-25 12:12   ` [PATCH 06/26] drm/amd/powerplay: implement pwm1 hwmon interface " Huang Rui
2019-02-25 12:12   ` [PATCH 07/26] drm/amd/powerplay: implement pwm1_enable " Huang Rui
     [not found]     ` <1551096752-18205-8-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-26  3:58       ` Alex Deucher
     [not found]         ` <CADnq5_Oaq7mh6V-SyrS72Zgm9wsWosP86-ZPJ-10X2hnq7xgPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-26  5:40           ` Huang, Ray
2019-02-25 12:12   ` [PATCH 08/26] drm/amd/powerplay: implement fan1_enable hwmon interface for SMU11 (v2) Huang Rui
     [not found]     ` <1551096752-18205-9-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-26  3:59       ` Alex Deucher
2019-02-25 12:12   ` Huang Rui [this message]
2019-02-25 12:12   ` [PATCH 10/26] drm/amd/powerplay: get eclk/vclk/dclk for smu11 Huang Rui
2019-02-25 12:12   ` [PATCH 11/26] drm/amd/powerplay: set dpm table of vclk/dclk/eclk for smu11 (v2) Huang Rui
2019-02-25 12:12   ` [PATCH 12/26] drm/amd/powerplay: add smu_late_init for SMU11 Huang Rui
2019-02-25 12:12   ` [PATCH 13/26] drm/amd/powerplay: add limit of pp_feature for smu Huang Rui
     [not found]     ` <1551096752-18205-14-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-26  4:08       ` Alex Deucher
     [not found]         ` <CADnq5_PtdOYSk_FYAb9cQTn7mCkEZuvi8xocPWuW0Eb8OvepzQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2019-02-26  6:01           ` Huang, Ray
     [not found]             ` <MN2PR12MB33093B43C19D5C0D2DBD2E2CEC7B0-rweVpJHSKTpWdvXm18W95QdYzm3356FpvxpqHgZTriW3zl9H0oFU5g@public.gmane.org>
2019-02-26  6:44               ` Gao, Likun
2019-02-25 12:12   ` [PATCH 14/26] drm/amd/powerplay: add od condition for power limit Huang Rui
2019-02-25 12:12   ` [PATCH 15/26] drm/amd/powerplay: add is_dpm_running for SMU11 Huang Rui
2019-02-25 12:12   ` [PATCH 16/26] drm/amd/powerplay: add suspend and resume function for smu Huang Rui
2019-02-25 12:12   ` [PATCH 17/26] drm/amd/powerplay: add condition for smc table hw init Huang Rui
2019-02-25 12:12   ` [PATCH 18/26] drm/amd/powerplay: support sysfs to get socclk, fclk, dcefclk Huang Rui
2019-02-25 12:12   ` [PATCH 19/26] drm/amd/powerplay: support sysfs to set " Huang Rui
2019-02-25 12:12   ` [PATCH 20/26] drm/amd/powerplay: add override pcie parameters Huang Rui
2019-02-25 12:12   ` [PATCH 21/26] drm/amd/powerplay: support sysfs to set/get pcie Huang Rui
2019-02-25 12:12   ` [PATCH 22/26] drm/amd/powerplay: fix smc messsage index report Huang Rui
2019-02-25 12:12   ` [PATCH 23/26] drm/amd/powerplay: fix byte alignment issue of smu11 pptable Huang Rui
2019-02-25 12:12   ` [PATCH 24/26] drm/amd/powerplay: move setting allowed mask and feature enabling together Huang Rui
2019-02-25 12:12   ` [PATCH 25/26] drm/amd/powerplay: fix the issue of checking on message mapping Huang Rui
2019-02-25 12:12   ` [PATCH 26/26] drm/amd/powerplay: use REG32_PCIE wrapper instead for sw smu Huang Rui
     [not found]     ` <1551096752-18205-27-git-send-email-ray.huang-5C7GfCeVMHo@public.gmane.org>
2019-02-26  4:13       ` Alex Deucher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1551096752-18205-10-git-send-email-ray.huang@amd.com \
    --to=ray.huang-5c7gfcevmho@public.gmane.org \
    --cc=Jack.Gui-5C7GfCeVMHo@public.gmane.org \
    --cc=Kevin1.Wang-5C7GfCeVMHo@public.gmane.org \
    --cc=Likun.Gao-5C7GfCeVMHo@public.gmane.org \
    --cc=amd-gfx-PD4FTy7X32lNgt0PjOBp9y5qC8QIuHrW@public.gmane.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.