Skip to contentSkip to conversation

drm/radeon: use 0-255 rather than 0-100 for pwm fan range

PATCH In review Alex Deucher 3 participants 5 messages Feb 4, 2015 – Apr 14, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/radeon: use 0-255 rather than 0-100 for pwm fan range

0-255 seems to be the preferred range for the pwm interface.

---
 drivers/gpu/drm/radeon/radeon_pm.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +6 -2
index 91e1bd2..9f758d3 100644
@@ -585,7 +585,7 @@ static ssize_t radeon_hwmon_set_pwm1_enable(struct device *dev,
 	if (err)
 		return err;
 
-	switch(value) {
+	switch (value) {
 	case 1: /* manual, percent-based */
 		rdev->asic->dpm.fan_ctrl_set_mode(rdev, FDO_PWM_MODE_STATIC);
 		break;
@@ -608,7 +608,7 @@ static ssize_t radeon_hwmon_get_pwm1_max(struct device *dev,
 					 struct device_attribute *attr,
 					 char *buf)
 {
-	return sprintf(buf, "%i\n", 100); /* pwm uses percent-based fan-control */
+	return sprintf(buf, "%i\n", 255);
 }
 
 static ssize_t radeon_hwmon_set_pwm1(struct device *dev,
@@ -623,6 +623,8 @@ static ssize_t radeon_hwmon_set_pwm1(struct device *dev,
 	if (err)
 		return err;
 
+	value = (value * 100) / 255;
+
 	err = rdev->asic->dpm.set_fan_speed_percent(rdev, value);
 	if (err)
 		return err;
@@ -642,6 +644,8 @@ static ssize_t radeon_hwmon_get_pwm1(struct device *dev,
 	if (err)
 		return err;
 
+	speed = (speed * 255) / 100;
+
 	return sprintf(buf, "%i\n", speed);
 }
 
Signature · 6 lines
1.8.3.1

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel
#1 lore raw

Am 04.02.2015 um 23:27 schrieb Alex Deucher:

Quoted 3 lines

0-255 seems to be the preferred range for the pwm interface.

Yeah, using 100 on a 8bit pwm timer sounds rather obviously wrong.

Patch is Reviewed-by: Christian König <[email protected]>

Quoted 36 lines
---
  drivers/gpu/drm/radeon/radeon_pm.c | 8 ++++++--
  1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +4 -2
index 91e1bd2..9f758d3 100644
@@ -585,7 +585,7 @@ static ssize_t radeon_hwmon_set_pwm1_enable(struct device *dev,
  	if (err)
  		return err;
 
-	switch(value) {
+	switch (value) {
  	case 1: /* manual, percent-based */
  		rdev->asic->dpm.fan_ctrl_set_mode(rdev, FDO_PWM_MODE_STATIC);
  		break;
@@ -608,7 +608,7 @@ static ssize_t radeon_hwmon_get_pwm1_max(struct device *dev,
  					 struct device_attribute *attr,
  					 char *buf)
  {
-	return sprintf(buf, "%i\n", 100); /* pwm uses percent-based fan-control */
+	return sprintf(buf, "%i\n", 255);
  }
 
  static ssize_t radeon_hwmon_set_pwm1(struct device *dev,
@@ -623,6 +623,8 @@ static ssize_t radeon_hwmon_set_pwm1(struct device *dev,
  	if (err)
  		return err;
 
+	value = (value * 100) / 255;
+
  	err = rdev->asic->dpm.set_fan_speed_percent(rdev, value);
  	if (err)
  		return err;

drivers/gpu/drm/radeon/radeon_pm.c static ssize_t radeon_hwmon_get_pwm1(struct device *dev, · line 651

Quoted 8 lines
drivers/gpu/drm/radeon/radeon_pm.c +2 -0
@@ -642,6 +644,8 @@ static ssize_t radeon_hwmon_get_pwm1(struct device *dev,
  	if (err)
  		return err;
 
+	speed = (speed * 255) / 100;
+
  	return sprintf(buf, "%i\n", speed);
  }
 

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#2 lore raw
Quoted 20 lines · Christian König

Am 04.02.2015 um 23:27 schrieb Alex Deucher:

Quoted 3 lines

0-255 seems to be the preferred range for the pwm interface.

Yeah, using 100 on a 8bit pwm timer sounds rather obviously wrong.

Patch is Reviewed-by: Christian König <[email protected]>

Quoted 12 lines
---
   drivers/gpu/drm/radeon/radeon_pm.c | 8 ++++++--
   1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
index 91e1bd2..9f758d3 100644
@@ -585,7 +585,7 @@ static ssize_t radeon_hwmon_set_pwm1_enable(struct device *dev,
   	if (err)
   		return err;
 
Quoted 12 lines

drivers/gpu/drm/radeon/radeon_pm.c static ssize_t radeon_hwmon_get_pwm1_max(struct device *dev, · line 612

Quoted 12 lines
drivers/gpu/drm/radeon/radeon_pm.c +2 -2
-	switch(value) {
+	switch (value) {
   	case 1: /* manual, percent-based */
   		rdev->asic->dpm.fan_ctrl_set_mode(rdev, FDO_PWM_MODE_STATIC);
   		break;
@@ -608,7 +608,7 @@ static ssize_t radeon_hwmon_get_pwm1_max(struct device *dev,
   					 struct device_attribute *attr,
   					 char *buf)
   {
-	return sprintf(buf, "%i\n", 100); /* pwm uses percent-based fan-control */
+	return sprintf(buf, "%i\n", 255);
   }

This is not a standard name as it is not documented in https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

Apparently, the pwm value should always have been exposed as 0-255 and I screwed it up in nouveau by having it be 0-100...

Maybe we should ask pwm*_max to be defined so as new applications could do the right thing while not having nouveau change its ABI. I guess it is ok to change it for radeon as there are so few users currently but the interface has been in nouveau for multiple years already!

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw
Quoted 45 lines · Martin Peres
Quoted 31 lines · Christian König

Am 04.02.2015 um 23:27 schrieb Alex Deucher:

Quoted 4 lines

0-255 seems to be the preferred range for the pwm interface.

Yeah, using 100 on a 8bit pwm timer sounds rather obviously wrong.

Patch is Reviewed-by: Christian König <[email protected]>

Quoted 20 lines
---
   drivers/gpu/drm/radeon/radeon_pm.c | 8 ++++++--
   1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +1 -0
index 91e1bd2..9f758d3 100644
@@ -585,7 +585,7 @@ static ssize_t radeon_hwmon_set_pwm1_enable(struct
 device *dev,
        if (err)
                return err;
   -    switch(value) {
+       switch (value) {
        case 1: /* manual, percent-based */
                rdev->asic->dpm.fan_ctrl_set_mode(rdev,
FDO_PWM_MODE_STATIC);
                break;
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
@@ -608,7 +608,7 @@ static ssize_t radeon_hwmon_get_pwm1_max(struct
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/radeon/radeon_pm.c +0 -1
 device *dev,
                                         struct device_attribute *attr,
                                         char *buf)
   {
-       return sprintf(buf, "%i\n", 100); /* pwm uses percent-based

fan-control */

+       return sprintf(buf, "%i\n", 255);
   }

This is not a standard name as it is not documented in
https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

Quoted 8 lines

Apparently, the pwm value should always have been exposed as 0-255 and I screwed it up in nouveau by having it be 0-100...

Maybe we should ask pwm*_max to be defined so as new applications could do the right thing while not having nouveau change its ABI. I guess it is ok to change it for radeon as there are so few users currently but the interface has been in nouveau for multiple years already!

IIRC, I changed it in the same kernel as the original patch went in.

Alex
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel

#4 lore raw
Quoted 45 lines · Alex Deucher
Quoted 44 lines · Martin Peres
Quoted 28 lines · Christian König

Am 04.02.2015 um 23:27 schrieb Alex Deucher:

Quoted 3 lines

0-255 seems to be the preferred range for the pwm interface.

Yeah, using 100 on a 8bit pwm timer sounds rather obviously wrong.

Patch is Reviewed-by: Christian König <[email protected]>

Quoted 20 lines
---
    drivers/gpu/drm/radeon/radeon_pm.c | 8 ++++++--
    1 file changed, 6 insertions(+), 2 deletions(-)
drivers/gpu/drm/radeon/radeon_pm.c +1 -0
index 91e1bd2..9f758d3 100644
@@ -585,7 +585,7 @@ static ssize_t radeon_hwmon_set_pwm1_enable(struct
 device *dev,
         if (err)
                 return err;
    -    switch(value) {
+       switch (value) {
         case 1: /* manual, percent-based */
                 rdev->asic->dpm.fan_ctrl_set_mode(rdev,
FDO_PWM_MODE_STATIC);
                 break;
drivers/gpu/drm/radeon/radeon_pm.c +0 -0
@@ -608,7 +608,7 @@ static ssize_t radeon_hwmon_get_pwm1_max(struct
Quoted 8 lines
Quoted 8 lines
drivers/gpu/drm/radeon/radeon_pm.c +0 -1
 device *dev,
                                          struct device_attribute *attr,
                                          char *buf)
    {
-       return sprintf(buf, "%i\n", 100); /* pwm uses percent-based

fan-control */

+       return sprintf(buf, "%i\n", 255);
    }

This is not a standard name as it is not documented in
https://www.kernel.org/doc/Documentation/hwmon/sysfs-interface

Apparently, the pwm value should always have been exposed as 0-255 and I screwed it up in nouveau by having it be 0-100...

Quoted 8 lines
Quoted 5 lines

Maybe we should ask pwm*_max to be defined so as new applications could do the right thing while not having nouveau change its ABI. I guess it is ok to change it for radeon as there are so few users currently but the interface has been in nouveau for multiple years already!

IIRC, I changed it in the same kernel as the original patch went in.

Alex

Wonderful!
_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel