All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
@ 2022-09-02 15:27 Yury Zhuravlev
  2022-09-09 20:50 ` Alex Deucher
  0 siblings, 1 reply; 8+ messages in thread
From: Yury Zhuravlev @ 2022-09-02 15:27 UTC (permalink / raw)
  To: amd-gfx

[-- Attachment #1: Type: text/plain, Size: 2903 bytes --]

Hello,

During the setup, the fan manager https://github.com/markusressel/fan2go I
found that my Vega56 was not working correctly. This fan manager expects
what read PWM value should be the same as you wrote before, but it's not
the case. PWM value was volatile, and what is more critical, if I wrote
200, after reading I saw ~70-100, which is very confusing.
After that, I started reading the amdgpu driver, and how fan speed works,
and I found what PWM value was calculated from RPM speed and not correct
for my case (different BIOS or fan configuration?).
Because it looked wrong, I started looking into different implementations
and found that Vega20 used mmCG_FDO_CTRL1 and mmCG_THERMAL_STATUS registers
to calculate the PWM value.
I also checked how we set PWM for Vega10 and found the same registers.
After that, I copy-pasted the function from Vega20 to Vega10, and it
started working much better. It still has some fluctuation, but as I
understand, this behavior is expected.

I have no in-depth information about amdgpu, and the original function may
have been for some reason (maybe for some broken BIOS?), but I suppose
somebody forgot to backport this code after prototype implementation.

It would be my first patch here. Sorry if I skipped some procedures, will
be appreciated it if you help me.

Regards,

---
diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
index dad3e3741a4e..190af79f3236 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
@@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr
*hwmgr,
 int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
                uint32_t *speed)
 {
-       uint32_t current_rpm;
-       uint32_t percent = 0;
-
-       if (hwmgr->thermal_controller.fanInfo.bNoFan)
-               return 0;
+       struct amdgpu_device *adev = hwmgr->adev;
+       uint32_t duty100, duty;
+       uint64_t tmp64;

-       if (vega10_get_current_rpm(hwmgr, &current_rpm))
-               return -1;
+       duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
+                               CG_FDO_CTRL1, FMAX_DUTY100);
+       duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
+                               CG_THERMAL_STATUS, FDO_PWM_DUTY);

-       if (hwmgr->thermal_controller.
-                       advanceFanControlParameters.usMaxFanRPM != 0)
-               percent = current_rpm * 255 /
-                       hwmgr->thermal_controller.
-                       advanceFanControlParameters.usMaxFanRPM;
+       if (!duty100)
+               return -EINVAL;

-       *speed = MIN(percent, 255);
+       tmp64 = (uint64_t)duty * 255;
+       do_div(tmp64, duty100);
+       *speed = MIN((uint32_t)tmp64, 255);

        return 0;
 }
--

[-- Attachment #2: Type: text/html, Size: 3324 bytes --]

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
@ 2022-09-02 17:24 Yury Zhuravlev
  2022-09-06 15:04 ` Deucher, Alexander
  0 siblings, 1 reply; 8+ messages in thread
From: Yury Zhuravlev @ 2022-09-02 17:24 UTC (permalink / raw)
  To: amd-gfx


[-- Attachment #1.1: Type: text/plain, Size: 1510 bytes --]

Hello,

During the setup, the fan manager https://github.com/markusressel/fan2go I
found that my Vega56 was not working correctly. This fan manager expects
what read PWM value should be the same as you wrote before, but it's not
the case. PWM value was volatile, and what is more critical, if I wrote
200, after reading I saw ~70-100, which is very confusing.
After that, I started reading the amdgpu driver, and how fan speed works,
and I found what PWM value was calculated from RPM speed and not correct
for my case (different BIOS or fan configuration?).
Because it looked wrong, I started looking into different implementations
and found that Vega20 used mmCG_FDO_CTRL1 and mmCG_THERMAL_STATUS registers
to calculate the PWM value.
I also checked how we set PWM for Vega10 and found the same registers.
After that, I copy-pasted the function from Vega20 to Vega10, and it
started working much better. It still has some fluctuation, but as I
understand, this behavior is expected.

I have no in-depth information about amdgpu, and the original function may
have been for some reason (maybe for some broken BIOS?), but I suppose
somebody forgot to backport this code after prototype implementation.

It would be my first patch here. Sorry if I skipped some procedures, will
be appreciated it if you help me.
Also, sorry for the patch in the attachment, I have not been using any mail
programs for the last six years, only web clients, and it's strange to do
it nowadays (PRs much more common...).

Regards,

[-- Attachment #1.2: Type: text/html, Size: 1704 bytes --]

[-- Attachment #2: 0001-getting-fan-speed-pwm-for-vega10-properly.patch --]
[-- Type: text/x-patch, Size: 1303 bytes --]

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
index dad3e3741a4e..190af79f3236 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
@@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
 int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
 		uint32_t *speed)
 {
-	uint32_t current_rpm;
-	uint32_t percent = 0;
-
-	if (hwmgr->thermal_controller.fanInfo.bNoFan)
-		return 0;
+	struct amdgpu_device *adev = hwmgr->adev;
+	uint32_t duty100, duty;
+	uint64_t tmp64;
 
-	if (vega10_get_current_rpm(hwmgr, &current_rpm))
-		return -1;
+	duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
+				CG_FDO_CTRL1, FMAX_DUTY100);
+	duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
+				CG_THERMAL_STATUS, FDO_PWM_DUTY);
 
-	if (hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM != 0)
-		percent = current_rpm * 255 /
-			hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM;
+	if (!duty100)
+		return -EINVAL;
 
-	*speed = MIN(percent, 255);
+	tmp64 = (uint64_t)duty * 255;
+	do_div(tmp64, duty100);
+	*speed = MIN((uint32_t)tmp64, 255);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
  2022-09-02 17:24 Yury Zhuravlev
@ 2022-09-06 15:04 ` Deucher, Alexander
  2022-09-07  4:33   ` Quan, Evan
  0 siblings, 1 reply; 8+ messages in thread
From: Deucher, Alexander @ 2022-09-06 15:04 UTC (permalink / raw)
  To: Yury Zhuravlev, amd-gfx@lists.freedesktop.org, Quan, Evan,
	Feng, Kenneth


[-- Attachment #1.1: Type: text/plain, Size: 2398 bytes --]

[Public]

@Quan, Evan<mailto:Evan.Quan@amd.com>, @Feng, Kenneth<mailto:Kenneth.Feng@amd.com> can you take a look?

Thanks,

Alex
________________________________
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> on behalf of Yury Zhuravlev <stalkerg@gmail.com>
Sent: Friday, September 2, 2022 1:24 PM
To: amd-gfx@lists.freedesktop.org <amd-gfx@lists.freedesktop.org>
Subject: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly

Hello,

During the setup, the fan manager https://github.com/markusressel/fan2go<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmarkusressel%2Ffan2go&data=05%7C01%7Calexander.deucher%40amd.com%7C0903d6788f924045996108da8d086ecb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637977365572428876%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=IOJR10xHaW9cUZ%2Fv0Q%2BZDFFQJ1pbv2dUKP0zpxK4s8M%3D&reserved=0> I found that my Vega56 was not working correctly. This fan manager expects what read PWM value should be the same as you wrote before, but it's not the case. PWM value was volatile, and what is more critical, if I wrote 200, after reading I saw ~70-100, which is very confusing.
After that, I started reading the amdgpu driver, and how fan speed works, and I found what PWM value was calculated from RPM speed and not correct for my case (different BIOS or fan configuration?).
Because it looked wrong, I started looking into different implementations and found that Vega20 used mmCG_FDO_CTRL1 and mmCG_THERMAL_STATUS registers to calculate the PWM value.
I also checked how we set PWM for Vega10 and found the same registers. After that, I copy-pasted the function from Vega20 to Vega10, and it started working much better. It still has some fluctuation, but as I understand, this behavior is expected.

I have no in-depth information about amdgpu, and the original function may have been for some reason (maybe for some broken BIOS?), but I suppose somebody forgot to backport this code after prototype implementation.

It would be my first patch here. Sorry if I skipped some procedures, will be appreciated it if you help me.
Also, sorry for the patch in the attachment, I have not been using any mail programs for the last six years, only web clients, and it's strange to do it nowadays (PRs much more common...).

Regards,

[-- Attachment #1.2: Type: text/html, Size: 4223 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-getting-fan-speed-pwm-for-vega10-properly.patch --]
[-- Type: text/x-patch; name="0001-getting-fan-speed-pwm-for-vega10-properly.patch", Size: 1303 bytes --]

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
index dad3e3741a4e..190af79f3236 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
@@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
 int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
 		uint32_t *speed)
 {
-	uint32_t current_rpm;
-	uint32_t percent = 0;
-
-	if (hwmgr->thermal_controller.fanInfo.bNoFan)
-		return 0;
+	struct amdgpu_device *adev = hwmgr->adev;
+	uint32_t duty100, duty;
+	uint64_t tmp64;
 
-	if (vega10_get_current_rpm(hwmgr, &current_rpm))
-		return -1;
+	duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
+				CG_FDO_CTRL1, FMAX_DUTY100);
+	duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
+				CG_THERMAL_STATUS, FDO_PWM_DUTY);
 
-	if (hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM != 0)
-		percent = current_rpm * 255 /
-			hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM;
+	if (!duty100)
+		return -EINVAL;
 
-	*speed = MIN(percent, 255);
+	tmp64 = (uint64_t)duty * 255;
+	do_div(tmp64, duty100);
+	*speed = MIN((uint32_t)tmp64, 255);
 
 	return 0;
 }

^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
  2022-09-06 15:04 ` Deucher, Alexander
@ 2022-09-07  4:33   ` Quan, Evan
  0 siblings, 0 replies; 8+ messages in thread
From: Quan, Evan @ 2022-09-07  4:33 UTC (permalink / raw)
  To: Deucher, Alexander, Yury Zhuravlev, amd-gfx@lists.freedesktop.org,
	Feng, Kenneth

[-- Attachment #1: Type: text/plain, Size: 3016 bytes --]

[Public]

Thanks Alex and Yury.
The changes seem reasonable to me. Feel free to add my RB: Reviewed-by: Evan Quan <evan.quan@amd.com>

BR
Evan
From: Deucher, Alexander <Alexander.Deucher@amd.com>
Sent: Tuesday, September 6, 2022 11:05 PM
To: Yury Zhuravlev <stalkerg@gmail.com>; amd-gfx@lists.freedesktop.org; Quan, Evan <Evan.Quan@amd.com>; Feng, Kenneth <Kenneth.Feng@amd.com>
Subject: Re: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly


[Public]

@Quan, Evan<mailto:Evan.Quan@amd.com>, @Feng, Kenneth<mailto:Kenneth.Feng@amd.com> can you take a look?

Thanks,

Alex
________________________________
From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org<mailto:amd-gfx-bounces@lists.freedesktop.org>> on behalf of Yury Zhuravlev <stalkerg@gmail.com<mailto:stalkerg@gmail.com>>
Sent: Friday, September 2, 2022 1:24 PM
To: amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org> <amd-gfx@lists.freedesktop.org<mailto:amd-gfx@lists.freedesktop.org>>
Subject: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly

Hello,

During the setup, the fan manager https://github.com/markusressel/fan2go<https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fmarkusressel%2Ffan2go&data=05%7C01%7Calexander.deucher%40amd.com%7C0903d6788f924045996108da8d086ecb%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637977365572428876%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=IOJR10xHaW9cUZ%2Fv0Q%2BZDFFQJ1pbv2dUKP0zpxK4s8M%3D&reserved=0> I found that my Vega56 was not working correctly. This fan manager expects what read PWM value should be the same as you wrote before, but it's not the case. PWM value was volatile, and what is more critical, if I wrote 200, after reading I saw ~70-100, which is very confusing.
After that, I started reading the amdgpu driver, and how fan speed works, and I found what PWM value was calculated from RPM speed and not correct for my case (different BIOS or fan configuration?).
Because it looked wrong, I started looking into different implementations and found that Vega20 used mmCG_FDO_CTRL1 and mmCG_THERMAL_STATUS registers to calculate the PWM value.
I also checked how we set PWM for Vega10 and found the same registers. After that, I copy-pasted the function from Vega20 to Vega10, and it started working much better. It still has some fluctuation, but as I understand, this behavior is expected.

I have no in-depth information about amdgpu, and the original function may have been for some reason (maybe for some broken BIOS?), but I suppose somebody forgot to backport this code after prototype implementation.

It would be my first patch here. Sorry if I skipped some procedures, will be appreciated it if you help me.
Also, sorry for the patch in the attachment, I have not been using any mail programs for the last six years, only web clients, and it's strange to do it nowadays (PRs much more common...).

Regards,

[-- Attachment #2: Type: text/html, Size: 7401 bytes --]

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
  2022-09-02 15:27 Yury Zhuravlev
@ 2022-09-09 20:50 ` Alex Deucher
  0 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2022-09-09 20:50 UTC (permalink / raw)
  To: Yury Zhuravlev; +Cc: amd-gfx

On Mon, Sep 5, 2022 at 3:04 AM Yury Zhuravlev <stalkerg@gmail.com> wrote:
>
> Hello,
>
> During the setup, the fan manager https://github.com/markusressel/fan2go I found that my Vega56 was not working correctly. This fan manager expects what read PWM value should be the same as you wrote before, but it's not the case. PWM value was volatile, and what is more critical, if I wrote 200, after reading I saw ~70-100, which is very confusing.
> After that, I started reading the amdgpu driver, and how fan speed works, and I found what PWM value was calculated from RPM speed and not correct for my case (different BIOS or fan configuration?).
> Because it looked wrong, I started looking into different implementations and found that Vega20 used mmCG_FDO_CTRL1 and mmCG_THERMAL_STATUS registers to calculate the PWM value.
> I also checked how we set PWM for Vega10 and found the same registers. After that, I copy-pasted the function from Vega20 to Vega10, and it started working much better. It still has some fluctuation, but as I understand, this behavior is expected.
>
> I have no in-depth information about amdgpu, and the original function may have been for some reason (maybe for some broken BIOS?), but I suppose somebody forgot to backport this code after prototype implementation.
>
> It would be my first patch here. Sorry if I skipped some procedures, will be appreciated it if you help me.

Please send this as a proper patch with your Signed-off-by using git-send-email.

Alex

>
> Regards,
>
> ---
> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> index dad3e3741a4e..190af79f3236 100644
> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> @@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
>  int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
>                 uint32_t *speed)
>  {
> -       uint32_t current_rpm;
> -       uint32_t percent = 0;
> -
> -       if (hwmgr->thermal_controller.fanInfo.bNoFan)
> -               return 0;
> +       struct amdgpu_device *adev = hwmgr->adev;
> +       uint32_t duty100, duty;
> +       uint64_t tmp64;
>
> -       if (vega10_get_current_rpm(hwmgr, &current_rpm))
> -               return -1;
> +       duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
> +                               CG_FDO_CTRL1, FMAX_DUTY100);
> +       duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
> +                               CG_THERMAL_STATUS, FDO_PWM_DUTY);
>
> -       if (hwmgr->thermal_controller.
> -                       advanceFanControlParameters.usMaxFanRPM != 0)
> -               percent = current_rpm * 255 /
> -                       hwmgr->thermal_controller.
> -                       advanceFanControlParameters.usMaxFanRPM;
> +       if (!duty100)
> +               return -EINVAL;
>
> -       *speed = MIN(percent, 255);
> +       tmp64 = (uint64_t)duty * 255;
> +       do_div(tmp64, duty100);
> +       *speed = MIN((uint32_t)tmp64, 255);
>
>         return 0;
>  }
> --

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
@ 2022-09-18  7:23 stalkerg
  2022-09-19  2:06 ` Quan, Evan
  0 siblings, 1 reply; 8+ messages in thread
From: stalkerg @ 2022-09-18  7:23 UTC (permalink / raw)
  To: amd-gfx; +Cc: alexander.deucher, stalkerg

Instead of using RPM speed, we will use a function from vega20 based on PWM registers.

Signed-off-by: Yury Zhuravlev <stalkerg@gmail.com>
---
 .../amd/pm/powerplay/hwmgr/vega10_thermal.c   | 25 +++++++++----------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
index dad3e3741a4e..190af79f3236 100644
--- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
+++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
@@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct pp_hwmgr *hwmgr,
 int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
 		uint32_t *speed)
 {
-	uint32_t current_rpm;
-	uint32_t percent = 0;
-
-	if (hwmgr->thermal_controller.fanInfo.bNoFan)
-		return 0;
+	struct amdgpu_device *adev = hwmgr->adev;
+	uint32_t duty100, duty;
+	uint64_t tmp64;
 
-	if (vega10_get_current_rpm(hwmgr, &current_rpm))
-		return -1;
+	duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_FDO_CTRL1),
+				CG_FDO_CTRL1, FMAX_DUTY100);
+	duty = REG_GET_FIELD(RREG32_SOC15(THM, 0, mmCG_THERMAL_STATUS),
+				CG_THERMAL_STATUS, FDO_PWM_DUTY);
 
-	if (hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM != 0)
-		percent = current_rpm * 255 /
-			hwmgr->thermal_controller.
-			advanceFanControlParameters.usMaxFanRPM;
+	if (!duty100)
+		return -EINVAL;
 
-	*speed = MIN(percent, 255);
+	tmp64 = (uint64_t)duty * 255;
+	do_div(tmp64, duty100);
+	*speed = MIN((uint32_t)tmp64, 255);
 
 	return 0;
 }
-- 
2.35.1


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* RE: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
  2022-09-18  7:23 [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly stalkerg
@ 2022-09-19  2:06 ` Quan, Evan
  2022-09-19 15:53   ` Alex Deucher
  0 siblings, 1 reply; 8+ messages in thread
From: Quan, Evan @ 2022-09-19  2:06 UTC (permalink / raw)
  To: stalkerg, amd-gfx@lists.freedesktop.org; +Cc: Deucher, Alexander

[AMD Official Use Only - General]

Reviewed-by: Evan Quan <evan.quan@amd.com>

> -----Original Message-----
> From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> stalkerg
> Sent: Sunday, September 18, 2022 3:23 PM
> To: amd-gfx@lists.freedesktop.org
> Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; stalkerg
> <stalkerg@gmail.com>
> Subject: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
> 
> Instead of using RPM speed, we will use a function from vega20 based on
> PWM registers.
> 
> Signed-off-by: Yury Zhuravlev <stalkerg@gmail.com>
> ---
>  .../amd/pm/powerplay/hwmgr/vega10_thermal.c   | 25 +++++++++----------
>  1 file changed, 12 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> index dad3e3741a4e..190af79f3236 100644
> --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> @@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct
> pp_hwmgr *hwmgr,
>  int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
>  		uint32_t *speed)
>  {
> -	uint32_t current_rpm;
> -	uint32_t percent = 0;
> -
> -	if (hwmgr->thermal_controller.fanInfo.bNoFan)
> -		return 0;
> +	struct amdgpu_device *adev = hwmgr->adev;
> +	uint32_t duty100, duty;
> +	uint64_t tmp64;
> 
> -	if (vega10_get_current_rpm(hwmgr, &current_rpm))
> -		return -1;
> +	duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0,
> mmCG_FDO_CTRL1),
> +				CG_FDO_CTRL1, FMAX_DUTY100);
> +	duty = REG_GET_FIELD(RREG32_SOC15(THM, 0,
> mmCG_THERMAL_STATUS),
> +				CG_THERMAL_STATUS, FDO_PWM_DUTY);
> 
> -	if (hwmgr->thermal_controller.
> -			advanceFanControlParameters.usMaxFanRPM != 0)
> -		percent = current_rpm * 255 /
> -			hwmgr->thermal_controller.
> -			advanceFanControlParameters.usMaxFanRPM;
> +	if (!duty100)
> +		return -EINVAL;
> 
> -	*speed = MIN(percent, 255);
> +	tmp64 = (uint64_t)duty * 255;
> +	do_div(tmp64, duty100);
> +	*speed = MIN((uint32_t)tmp64, 255);
> 
>  	return 0;
>  }
> --
> 2.35.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
  2022-09-19  2:06 ` Quan, Evan
@ 2022-09-19 15:53   ` Alex Deucher
  0 siblings, 0 replies; 8+ messages in thread
From: Alex Deucher @ 2022-09-19 15:53 UTC (permalink / raw)
  To: Quan, Evan; +Cc: Deucher, Alexander, stalkerg, amd-gfx@lists.freedesktop.org

Applied.  Thanks!

Alex

On Sun, Sep 18, 2022 at 10:06 PM Quan, Evan <Evan.Quan@amd.com> wrote:
>
> [AMD Official Use Only - General]
>
> Reviewed-by: Evan Quan <evan.quan@amd.com>
>
> > -----Original Message-----
> > From: amd-gfx <amd-gfx-bounces@lists.freedesktop.org> On Behalf Of
> > stalkerg
> > Sent: Sunday, September 18, 2022 3:23 PM
> > To: amd-gfx@lists.freedesktop.org
> > Cc: Deucher, Alexander <Alexander.Deucher@amd.com>; stalkerg
> > <stalkerg@gmail.com>
> > Subject: [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly
> >
> > Instead of using RPM speed, we will use a function from vega20 based on
> > PWM registers.
> >
> > Signed-off-by: Yury Zhuravlev <stalkerg@gmail.com>
> > ---
> >  .../amd/pm/powerplay/hwmgr/vega10_thermal.c   | 25 +++++++++----------
> >  1 file changed, 12 insertions(+), 13 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> > b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> > index dad3e3741a4e..190af79f3236 100644
> > --- a/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> > +++ b/drivers/gpu/drm/amd/pm/powerplay/hwmgr/vega10_thermal.c
> > @@ -67,22 +67,21 @@ int vega10_fan_ctrl_get_fan_speed_info(struct
> > pp_hwmgr *hwmgr,
> >  int vega10_fan_ctrl_get_fan_speed_pwm(struct pp_hwmgr *hwmgr,
> >               uint32_t *speed)
> >  {
> > -     uint32_t current_rpm;
> > -     uint32_t percent = 0;
> > -
> > -     if (hwmgr->thermal_controller.fanInfo.bNoFan)
> > -             return 0;
> > +     struct amdgpu_device *adev = hwmgr->adev;
> > +     uint32_t duty100, duty;
> > +     uint64_t tmp64;
> >
> > -     if (vega10_get_current_rpm(hwmgr, &current_rpm))
> > -             return -1;
> > +     duty100 = REG_GET_FIELD(RREG32_SOC15(THM, 0,
> > mmCG_FDO_CTRL1),
> > +                             CG_FDO_CTRL1, FMAX_DUTY100);
> > +     duty = REG_GET_FIELD(RREG32_SOC15(THM, 0,
> > mmCG_THERMAL_STATUS),
> > +                             CG_THERMAL_STATUS, FDO_PWM_DUTY);
> >
> > -     if (hwmgr->thermal_controller.
> > -                     advanceFanControlParameters.usMaxFanRPM != 0)
> > -             percent = current_rpm * 255 /
> > -                     hwmgr->thermal_controller.
> > -                     advanceFanControlParameters.usMaxFanRPM;
> > +     if (!duty100)
> > +             return -EINVAL;
> >
> > -     *speed = MIN(percent, 255);
> > +     tmp64 = (uint64_t)duty * 255;
> > +     do_div(tmp64, duty100);
> > +     *speed = MIN((uint32_t)tmp64, 255);
> >
> >       return 0;
> >  }
> > --
> > 2.35.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-09-19 15:54 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-09-18  7:23 [PATCH] drm/amdgpu: getting fan speed pwm for vega10 properly stalkerg
2022-09-19  2:06 ` Quan, Evan
2022-09-19 15:53   ` Alex Deucher
  -- strict thread matches above, loose matches on Subject: below --
2022-09-02 17:24 Yury Zhuravlev
2022-09-06 15:04 ` Deucher, Alexander
2022-09-07  4:33   ` Quan, Evan
2022-09-02 15:27 Yury Zhuravlev
2022-09-09 20:50 ` Alex Deucher

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.