hwmon: (dell-smm) Support additional attributes
Subsystems (3)
v3 cover hwmon: (dell-smm) Support additional attributes
From: Armin Wolf <[email protected]>
This patch series adds support for fanX_min, fanX_max and fanX_target. A second patch also removes some unnecessary includes.
Both patches where tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Changes in v3:
- improve fanX_min/_max/_target detection logic
Changes in v2:
- update documentation
- prevent out-of-bounds read/write when module is loaded with custom fan_max value
Armin Wolf (2):
hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
hwmon: (dell-smm) Remove unnecessary includes
Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 63 ++++++++++++++++++++++---- 2 files changed, 58 insertions(+), 8 deletions(-)
--
2.20.1
PATCH v3 1/2 hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by adding fanX_min, fanX_max and fanX_target attributes. All are RO since fan control happens over pwm.
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)
Documentation/hwmon/dell-smm-hwmon.rst +3 -0
@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,
drivers/hwmon/dell-smm-hwmon.c +55 -6
97 lines not on this page · raw message
--
2.20.1
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Am 27.09.21 um 00:10 schrieb [email protected]:
Quoted 138 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +55
-7@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ]; + +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } } dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data, --
Quoted 2 lines
2.20.1
Are there any problems with this patch? I already tested it on two models, is there something
else i should verify/change?
Armin
Guenter Roeck
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Quoted 137 lines · Armin Wolf
Am 27.09.21 um 00:10 schrieb [email protected]:
Quoted 136 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>---
Documentation/hwmon/dell-smm-hwmon.rst| 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++---2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +0
-0@@ -34,6 +34,9 @@ Name Perm Description=============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label.
Documentation/hwmon/dell-smm-hwmon.rst +3
-0+fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPMpwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,
drivers/hwmon/dell-smm-hwmon.c +8
-0@@ -76,6 +76,7 @@ struct dell_smm_data { int temp_type[DELL_SMM_NO_TEMP]; bool fan[DELL_SMM_NO_FANS]; int fan_type[DELL_SMM_NO_FANS]; + int *fan_nominal_speed[DELL_SMM_NO_FANS]; }; MODULE_AUTHOR("Massimo Dal Zotto ([email protected])");@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types if (data->fan[channel] && !data->disallow_fan_type_call) return 0444; + break; + case hwmon_fan_min: + case hwmon_fan_max: + case hwmon_fan_target: + if (data->fan_nominal_speed[channel]) + return 0444; + break;default:
break;drivers/hwmon/dell-smm-hwmon.c +19
-0@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; + return 0; + case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0]; + + return 0; + case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + + return 0; + case hwmon_fan_target: + ret = i8k_get_fan_status(data, channel); + if (ret < 0) + return ret; + + if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; + return 0;default:
break;drivers/hwmon/dell-smm-hwmon.c +0
-0@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {
HWMON_T_INPUT|HWMON_T_LABEL
),
HWMON_CHANNEL_INFO(fan,- HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL + HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN | HWMON_F_MAX |+
HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX| +HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX| +HWMON_F_TARGET
),
HWMON_CHANNEL_INFO(pwm,
HWMON_PWM_INPUT|HWMON_PWM_ENABLE,drivers/hwmon/dell-smm-hwmon.c +22
-3@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); struct device *dell_smm_hwmon_dev; - int i, err; + int i, state, err; for (i = 0; i < DELL_SMM_NO_TEMP; i++) { data->temp_type[i] = i8k_get_temp_type(i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err = i8k_get_fan_status(data, i); if (err < 0) err = i8k_get_fan_type(data, i); - if (err >= 0) - data->fan[i] = true; + + if (err < 0) + continue; + + data->fan[i] = true; + data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max + 1, + sizeof(*data->fan_nominal_speed[i]), + GFP_KERNEL); + if (!data->fan_nominal_speed[i]) + continue; + + for (state = 0; state <= data->i8k_fan_max; state++) { + err = i8k_get_fan_nominal_speed(data, i, state); + if (err < 0) { + /* Mark nominal speed table as invalid in case of error */ + devm_kfree(dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] = NULL; + break; + } + data->fan_nominal_speed[i][state] = err; + } }
Quoted 8 lines
Quoted 4 lines
drivers/hwmon/dell-smm-hwmon.c +0
-0dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,Signature · 1 line
2.20.1Are there any problems with this patch? I already tested it on two models, is there something
else i should verify/change?
I am waiting for an Acked-by:/Reviewed-by: from Pali.
Guenter
Pali Rohár
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
In reply to [email protected]Quoted 21 lines · On Monday 27 September 2021 00:10:43 [email protected] wrote:
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +0
-0
Documentation/hwmon/dell-smm-hwmon.rst Name Perm Description · line 39
Quoted 6 lines
Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM
Hello!
I do not know API / meaning of these 3 properties, so I looked into hwmon documentation at:
https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html#fans
And in documentation is written that both 3 properties (min, max and target) are RW.
I'm somehow lost as I have not fully understood what is the original meaning of these 3 properties. Guenter could you help?
After reading I understood it as that these properties are for HW which supports controlling directly fan speed via RPM (and not PWM). And so user can set lower and upper limit of fan speed (via _min and _max) or can set exact RPM value (via _target).
Quoted 30 lines
Documentation/hwmon/dell-smm-hwmon.rst +0
-0pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +8
-0@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;
drivers/hwmon/dell-smm-hwmon.c static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a · line 753
Quoted 6 lines
drivers/hwmon/dell-smm-hwmon.c +3
-0@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ];
When fan is turned off then it has speed 0 RPM. So should not be minimal fan speed always hardcoded to zero?
Quoted 77 lines
drivers/hwmon/dell-smm-hwmon.c +44
-7+ +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } } dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data, --2.20.1
Guenter Roeck
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Quoted 31 lines · Pali Rohár
Quoted 21 lines · On Monday 27 September 2021 00:10:43 [email protected] wrote:
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +0
-0Documentation/hwmon/dell-smm-hwmon.rst Name Perm Description · line 39
Quoted 6 lines
Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPMHello!
Quoted 7 lines
I do not know API / meaning of these 3 properties, so I looked into hwmon documentation at:
https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html#fansAnd in documentation is written that both 3 properties (min, max and target) are RW.
That is the expectation. That doesn't mean they _have_ to be RW. It doesn't make sense to categorically demand that attributes are RW if the hardware does not support it.
Quoted 3 lines
I'm somehow lost as I have not fully understood what is the original meaning of these 3 properties. Guenter could you help?
min: lower fan speed results in warning/error.
max: higher fan speed results in error
target: target fan speed. The controller should set the fan speed
to this level.
Quoted 5 lines
After reading I understood it as that these properties are for HW which supports controlling directly fan speed via RPM (and not PWM). And so user can set lower and upper limit of fan speed (via
_minand_max) or can set exact RPM value (via_target).
Not really. The controller can try to modify a pwm value to reach the configured target fan speed. min/max values apply to both pwm and rpm controlled fans.
Quoted 31 lines
Quoted 31 lines
Documentation/hwmon/dell-smm-hwmon.rst +0
-0pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +8
-0@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a
Quoted 9 lines
drivers/hwmon/dell-smm-hwmon.c static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a · line 753
Quoted 5 lines
drivers/hwmon/dell-smm-hwmon.c +3
-0*val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ];When fan is turned off then it has speed 0 RPM. So should not be minimal fan speed always hardcoded to zero?
No. Fans can be turned off on most systems/controllers. This means the "minimum" fan speed would always be 0, and the attribute would be worthless. In other words, "fan turned off" is always an exception.
Quoted 77 lines
Quoted 77 lines
drivers/hwmon/dell-smm-hwmon.c +44
-7+ +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } } dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data, --2.20.1
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Am 11.10.21 um 20:48 schrieb Guenter Roeck:
Quoted 59 lines · Pali Rohár
Quoted 32 lines · On Monday 27 September 2021 00:10:43 [email protected] wrote:
Quoted 25 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>---
Documentation/hwmon/dell-smm-hwmon.rst| 3 ++
drivers/hwmon/dell-smm-hwmon.c | 61
+++++++++++++++++++++++---2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +0
-0@@ -34,6 +34,9 @@ Name Perm Description=============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label.
Documentation/hwmon/dell-smm-hwmon.rst Name Perm Description · line 39
Quoted 3 lines
Documentation/hwmon/dell-smm-hwmon.rst +3
-0+fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPMHello!
Quoted 7 lines
I do not know API / meaning of these 3 properties, so I looked into hwmon documentation at:
https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html#fansAnd in documentation is written that both 3 properties (min, max and target) are RW.
That is the expectation. That doesn't mean they _have_ to be RW. It doesn't make sense to categorically demand that attributes are RW if the hardware does not support it.
Quoted 3 lines
I'm somehow lost as I have not fully understood what is the original meaning of these 3 properties. Guenter could you help?
min: lower fan speed results in warning/error.
max: higher fan speed results in error
target: target fan speed. The controller should set the fan speed to this level.Quoted 5 lines
After reading I understood it as that these properties are for HW which supports controlling directly fan speed via RPM (and not PWM). And so user can set lower and upper limit of fan speed (via
_minand_max) or can set exact RPM value (via_target).
Quoted 4 lines
Not really. The controller can try to modify a pwm value to reach the configured target fan speed. min/max values apply to both pwm and rpm controlled fans.
The reason i made fanX_target RO is that the SMM interface does not directly support setting the fan speed in rpm. Since the attributes should reflect the hardware implementation, making fanX_target RW would make no sense (at least to me).
Quoted 43 lines
Quoted 33 lines
Quoted 33 lines
pwm[1-3] RW Control the fan PWM duty-cycle.
pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +8
-0@@ -76,6 +76,7 @@ struct dell_smm_data { int temp_type[DELL_SMM_NO_TEMP]; bool fan[DELL_SMM_NO_FANS]; int fan_type[DELL_SMM_NO_FANS]; + int *fan_nominal_speed[DELL_SMM_NO_FANS]; }; MODULE_AUTHOR("Massimo Dal Zotto ([email protected])");@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_types if (data->fan[channel] && !data->disallow_fan_type_call) return 0444; + break; + case hwmon_fan_min: + case hwmon_fan_max: + case hwmon_fan_target: + if (data->fan_nominal_speed[channel]) + return 0444; + break;default:
break;drivers/hwmon/dell-smm-hwmon.c +0
-0@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev,enum
hwmon_sensor_typestype, u32 aQuoted 9 lines
Quoted 5 lines
*val = ret;
+ return 0;
+ casehwmon_fan_min:
+ *val = data->fan_nominal_speed[channel][0];When fan is turned off then it has speed 0 RPM. So should not be minimal fan speed always hardcoded to zero?
Quoted 4 lines
No. Fans can be turned off on most systems/controllers. This means the "minimum" fan speed would always be 0, and the attribute would be worthless. In other words, "fan turned off" is always an exception.
I am not sure if we can assume that the fans will have 0 rpm when turned off. Maybe some notebook model defines 100 rpm as "turned off"?
In this case we should trust the nominal speed for "off" rather than assume its 0 rpm.
Quoted 87 lines
Quoted 86 lines
Quoted 86 lines
+
+ return 0;
+ casehwmon_fan_max:
+ *val = data->fan_nominal_speed[channel][data->i8k_fan_max];drivers/hwmon/dell-smm-hwmon.c +12
-0+ + return 0; + case hwmon_fan_target: + ret = i8k_get_fan_status(data, channel); + if (ret < 0) + return ret; + + if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0;
default:
break;drivers/hwmon/dell-smm-hwmon.c +0
-0@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {
HWMON_T_INPUT|HWMON_T_LABEL
),
HWMON_CHANNEL_INFO(fan,- HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL + HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN |
HWMON_F_MAX|
+HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX|
+HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX|
+HWMON_F_TARGET
),
HWMON_CHANNEL_INFO(pwm,
HWMON_PWM_INPUT|HWMON_PWM_ENABLE,drivers/hwmon/dell-smm-hwmon.c +1
-1@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); struct device *dell_smm_hwmon_dev; - int i, err; + int i, state, err; for (i = 0; i < DELL_SMM_NO_TEMP; i++) {data->temp_type[i] =
i8k_get_temp_type(i);drivers/hwmon/dell-smm-hwmon.c +15
-2@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err = i8k_get_fan_status(data, i); if (err < 0) err = i8k_get_fan_type(data, i); - if (err >= 0) - data->fan[i] = true; + + if (err < 0) + continue; + + data->fan[i] = true; + data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), + GFP_KERNEL); + if (!data->fan_nominal_speed[i]) + continue; + + for (state = 0; state <= data->i8k_fan_max; state++) { + err = i8k_get_fan_nominal_speed(data, i, state); + if (err < 0) { + /* Mark nominal speed table as invalid in case oferror */
+devm_kfree(dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] = NULL; + break;
+ }
+ data->fan_nominal_speed[i][state] = err; + }
}
dell_smm_hwmon_dev= devm_hwmon_device_register_with_info(dev, "dell_smm", data,Signature · 1 line
2.20.1
Pali Rohár
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Quoted 66 lines · On Monday 11 October 2021 21:14:36 Armin Wolf wrote:
Am 11.10.21 um 20:48 schrieb Guenter Roeck:
Quoted 61 lines · Pali Rohár
Quoted 34 lines · On Monday 27 September 2021 00:10:43 [email protected] wrote:
Quoted 27 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>---
Documentation/hwmon/dell-smm-hwmon.rst| 3 ++
drivers/hwmon/dell-smm-hwmon.c | 61
+++++++++++++++++++++++---2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +0
-0@@ -34,6 +34,9 @@ Name Perm Description=============================== =======
=======================================
fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label.Documentation/hwmon/dell-smm-hwmon.rst Name Perm Description · line 39
Quoted 3 lines
Documentation/hwmon/dell-smm-hwmon.rst +3
-0+fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPMHello!
Quoted 7 lines
I do not know API / meaning of these 3 properties, so I looked into hwmon documentation at:
https://www.kernel.org/doc/html/latest/hwmon/sysfs-interface.html#fansAnd in documentation is written that both 3 properties (min, max and target) are RW.
That is the expectation. That doesn't mean they _have_ to be RW. It doesn't make sense to categorically demand that attributes are RW if the hardware does not support it.
Quoted 3 lines
I'm somehow lost as I have not fully understood what is the original meaning of these 3 properties. Guenter could you help?
min: lower fan speed results in warning/error.
max: higher fan speed results in error
target: target fan speed. The controller should set the fan speed to this level.Quoted 5 lines
After reading I understood it as that these properties are for HW which supports controlling directly fan speed via RPM (and not PWM). And so user can set lower and upper limit of fan speed (via
_minand_max) or can set exact RPM value (via_target).Quoted 4 lines
Not really. The controller can try to modify a pwm value to reach the configured target fan speed. min/max values apply to both pwm and rpm controlled fans.
Quoted 5 lines
The reason i made
fanX_targetRO is that the SMM interface does not directly support
setting the fan speed in rpm. Since the attributes should reflect the hardware implementation,
makingfanX_targetRW would make no sense (at least to me).
Ok. Then patch seems to be fine.
Quoted 46 lines
Quoted 46 lines
Quoted 45 lines
Quoted 34 lines
pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan
control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +1
-0@@ -76,6 +76,7 @@ struct dell_smm_data { int temp_type[DELL_SMM_NO_TEMP]; bool fan[DELL_SMM_NO_FANS]; int fan_type[DELL_SMM_NO_FANS]; + int *fan_nominal_speed[DELL_SMM_NO_FANS]; }; MODULE_AUTHOR("Massimo Dal Zotto ([email protected])");@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(constvoid *drvdata, enum
hwmon_sensor_types
if (data->fan[channel] && !data->disallow_fan_type_call) return 0444;+ break;
+ casehwmon_fan_min:
+ casehwmon_fan_max:
+ casehwmon_fan_target:
+ if (data->fan_nominal_speed[channel]) + return 0444;
+
break;
default:
break;drivers/hwmon/dell-smm-hwmon.c static int dell_smm_read(struct device · line 754
Quoted 7 lines
drivers/hwmon/dell-smm-hwmon.c +3
-0@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; + return 0; + case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0];When fan is turned off then it has speed 0 RPM. So should not be minimal fan speed always hardcoded to zero?
Quoted 3 lines
Quoted 3 lines
No. Fans can be turned off on most systems/controllers. This means the "minimum" fan speed would always be 0, and the attribute would be worthless. In other words, "fan turned off" is always an exception.
Ok!
Quoted 2 lines
I am not sure if we can assume that the fans will have 0 rpm when turned off.
E6440 reports 0 rpm when fan is turned off.
Quoted 1 line
Maybe some notebook model defines 100 rpm as "turned off"?
I really do not know.
Quoted 91 lines
In this case we should trust the nominal speed for "off" rather than assume its 0 rpm.
Quoted 88 lines
Quoted 87 lines
Quoted 87 lines
drivers/hwmon/dell-smm-hwmon.c +16
-0+ + return 0; + case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + + return 0; + case hwmon_fan_target: + ret = i8k_get_fan_status(data, channel); + if (ret < 0) + return ret; + + if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; + return 0;default:
break;drivers/hwmon/dell-smm-hwmon.c +0
-0@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {
HWMON_T_INPUT|HWMON_T_LABEL
),
HWMON_CHANNEL_INFO(fan,- HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL, - HWMON_F_INPUT | HWMON_F_LABEL + HWMON_F_INPUT | HWMON_F_LABEL | HWMON_F_MIN |
HWMON_F_MAX|
+HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX|
+HWMON_F_TARGET,
+HWMON_F_INPUT|HWMON_F_LABEL|HWMON_F_MIN|HWMON_F_MAX|
+HWMON_F_TARGET
),
HWMON_CHANNEL_INFO(pwm,
HWMON_PWM_INPUT|HWMON_PWM_ENABLE,drivers/hwmon/dell-smm-hwmon.c +1
-1@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) { struct dell_smm_data *data = dev_get_drvdata(dev); struct device *dell_smm_hwmon_dev; - int i, err; + int i, state, err; for (i = 0; i < DELL_SMM_NO_TEMP; i++) {data->temp_type[i] =
i8k_get_temp_type(i);drivers/hwmon/dell-smm-hwmon.c +15
-2@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err = i8k_get_fan_status(data, i); if (err < 0) err = i8k_get_fan_type(data, i); - if (err >= 0) - data->fan[i] = true; + + if (err < 0) + continue; + + data->fan[i] = true; + data->fan_nominal_speed[i] = devm_kmalloc_array(dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), + GFP_KERNEL); + if (!data->fan_nominal_speed[i]) + continue; + + for (state = 0; state <= data->i8k_fan_max; state++) { + err = i8k_get_fan_nominal_speed(data, i, state); + if (err < 0) { + /* Mark nominal speed table as invalid in caseof error */
+devm_kfree(dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] = NULL; + break;
+ }
+ data->fan_nominal_speed[i][state] = err; + }
}
dell_smm_hwmon_dev= devm_hwmon_device_register_with_info(dev, "dell_smm", data,Signature · 1 line
2.20.1
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
In reply to [email protected]Quoted 11 lines · On Monday 27 September 2021 00:10:43 [email protected] wrote:
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>
Quoted 129 lines
--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +55
-7@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ]; + +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } } dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data, --2.20.1
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
In reply to [email protected]Quoted 8 lines · On Mon, Sep 27, 2021 at 12:10:43AM +0200, [email protected] wrote:
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.
Quoted 4 lines
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>Reviewed-by Pali Rohár <[email protected]>
Applied.
Thanks,
Guenter
Quoted 129 lines
--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)--
2.20.1Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +55
-6@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ]; + +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } } dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Am 13.10.21 um 20:51 schrieb Guenter Roeck:
Quoted 146 lines · On Mon, Sep 27, 2021 at 12:10:43AM +0200, [email protected] wrote:
Quoted 8 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Quoted 4 lines
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>Reviewed-by Pali Rohár <[email protected]>Applied.
Thanks,
GuenterQuoted 128 lines
--- Documentation/hwmon/dell-smm-hwmon.rst | 3 ++ drivers/hwmon/dell-smm-hwmon.c | 61 +++++++++++++++++++++++--- 2 files changed, 58 insertions(+), 6 deletions(-)--
2.20.1Documentation/hwmon/dell-smm-hwmon.rst +3
-0@@ -34,6 +34,9 @@ Name Perm Description =============================== ======= ======================================= fan[1-3]_input RO Fan speed in RPM. fan[1-3]_label RO Fan label. +fan[1-3]_min RO Minimal Fan speed in RPM +fan[1-3]_max RO Maximal Fan speed in RPM +fan[1-3]_target RO Expected Fan speed in RPM pwm[1-3] RW Control the fan PWM duty-cycle. pwm1_enable WO Enable or disable automatic BIOS fan control (not supported on all laptops,drivers/hwmon/dell-smm-hwmon.c +55
-6@@ -76,6 +76,7 @@ struct dell_smm_data {int temp_type[DELL_SMM_NO_TEMP ];bool fan[DELL_SMM_NO_FANS ];int fan_type[DELL_SMM_NO_FANS ]; +int *fan_nominal_speed[DELL_SMM_NO_FANS ]; };MODULE_AUTHOR ("Massimo Dal Zotto ([email protected])" );@@ -673,6 +674,13 @@ static umode_t dell_smm_is_visible(const void *drvdata, enum hwmon_sensor_typesif (data->fan[channel] && !data->disallow_fan_type_call)return 0444 ; +break ; +case hwmon_fan_min: +case hwmon_fan_max: +case hwmon_fan_target: +if (data->fan_nominal_speed[channel]) +return 0444 ; +break ;default :break ;@@ -740,6 +748,25 @@ static int dell_smm_read(struct device *dev, enum hwmon_sensor_types type, u32 a *val = ret; +return 0 ; +case hwmon_fan_min: + *val = data->fan_nominal_speed[channel][0 ]; + +return 0 ; +case hwmon_fan_max: + *val = data->fan_nominal_speed[channel][data->i8k_fan_max]; + +return 0 ; +case hwmon_fan_target: + ret =i8k_get_fan_status (data, channel); +if (ret <0 ) +return ret; + +if (ret > data->i8k_fan_max) + ret = data->i8k_fan_max; + + *val = data->fan_nominal_speed[channel][ret]; +return 0 ;default :break ;@@ -889,9 +916,12 @@ static const struct hwmon_channel_info *dell_smm_info[] = {HWMON_T_INPUT |HWMON_T_LABEL ),HWMON_CHANNEL_INFO (fan, -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL , -HWMON_F_INPUT |HWMON_F_LABEL +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET , +HWMON_F_INPUT |HWMON_F_LABEL |HWMON_F_MIN |HWMON_F_MAX | +HWMON_F_TARGET ), HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE,@@ -910,7 +940,7 @@ static int __init dell_smm_init_hwmon(struct device *dev) {struct dell_smm_data *data =dev_get_drvdata (dev);struct device *dell_smm_hwmon_dev; -int i, err; +int i, state, err;for (i =0 ; i <DELL_SMM_NO_TEMP ; i++) { data->temp_type[i] =i8k_get_temp_type (i);@@ -926,8 +956,27 @@ static int __init dell_smm_init_hwmon(struct device *dev) err =i8k_get_fan_status (data, i);if (err <0 ) err =i8k_get_fan_type (data, i); -if (err >=0 ) - data->fan[i] = true; + +if (err <0 ) +continue ; + + data->fan[i] = true; + data->fan_nominal_speed[i] =devm_kmalloc_array (dev, data->i8k_fan_max +1 , +sizeof (*data->fan_nominal_speed[i]), +GFP_KERNEL ); +if (!data->fan_nominal_speed[i]) +continue ; + +for (state =0 ; state <= data->i8k_fan_max; state++) { + err =i8k_get_fan_nominal_speed (data, i, state); +if (err <0 ) { +/* Mark nominal speed table as invalid in case of error */ +devm_kfree (dev, data->fan_nominal_speed[i]); + data->fan_nominal_speed[i] =NULL ; +break ; + } + data->fan_nominal_speed[i][state] = err; + } }
Quoted 1 line
drivers/hwmon/dell-smm-hwmon.c static int __init dell_smm_init_hwmon(struct device *dev) · line 982
Quoted 1 line
drivers/hwmon/dell-smm-hwmon.c +0
-0dell_smm_hwmon_dev = devm_hwmon_device_register_with_info(dev, "dell_smm", data,
After looking at hwmon-next today, i noticed that this patch was apparently removed.
Is there a issue with this patch causing the revert?
Guenter Roeck
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Quoted 16 lines · Armin Wolf
Am 13.10.21 um 20:51 schrieb Guenter Roeck:
Quoted 15 lines · On Mon, Sep 27, 2021 at 12:10:43AM +0200, [email protected] wrote:
Quoted 8 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Quoted 4 lines
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>Reviewed-by Pali Rohár <[email protected]>Applied.
[ ... ]
Quoted 3 lines
After looking at hwmon-next today, i noticed that this patch was apparently removed.
Is there a issue with this patch causing the revert?
Not that I recall. Looks like I messed up. Sorry, and thanks for noticing. I added it back in.
Guenter
Re: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Am 17.10.21 um 00:00 schrieb Guenter Roeck:
Quoted 24 lines · Armin Wolf
Quoted 16 lines
Am 13.10.21 um 20:51 schrieb Guenter Roeck:
Quoted 15 lines · On Mon, Sep 27, 2021 at 12:10:43AM +0200, [email protected] wrote:
Quoted 8 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Quoted 4 lines
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>Reviewed-by Pali Rohár <[email protected]>Applied.
[ ... ]
Quoted 3 lines
After looking at hwmon-next today, i noticed that this patch was apparently removed.
Is there a issue with this patch causing the revert?
Quoted 5 lines
Not that I recall. Looks like I messed up. Sorry, and thanks for noticing.
I added it back in.Guenter
It seems its not the only patch missing, i cant find the following patches anymore:
[PATCH v2] hwmon: acpi_power_meter: Use acpi_bus_get_acpi_device() [PATCH v2 04/20 hwmon: max31722: Warn about failure to put device in stand-by in .remove()
Guenter Roeck
maintainerRe: [PATCH v3 1/2] hwmon: (dell-smm) Add support for fanX_min, fanX_max and fanX_target
Quoted 29 lines · Armin Wolf
Am 17.10.21 um 00:00 schrieb Guenter Roeck:
Quoted 28 lines · Armin Wolf
Quoted 16 lines
Am 13.10.21 um 20:51 schrieb Guenter Roeck:
Quoted 15 lines · On Mon, Sep 27, 2021 at 12:10:43AM +0200, [email protected] wrote:
Quoted 8 lines
From: Armin Wolf <[email protected]>
The nominal speed of each fan can be obtained with
i8k_get_fan_nominal_speed(), however the result is not available from userspace.
Change that by addingfanX_min,fanX_maxandfanX_targetattributes. All are RO since fan control happens over pwm.Quoted 4 lines
Tested on a Dell Inspiron 3505 and a Dell Latitude C600.
Signed-off-by Armin Wolf <[email protected]>Reviewed-by Pali Rohár <[email protected]>Applied.
[ ... ]
Quoted 3 lines
After looking at hwmon-next today, i noticed that this patch was apparently removed.
Is there a issue with this patch causing the revert?Not that I recall. Looks like I messed up. Sorry, and thanks for noticing.
I added it back in.
Quoted 8 lines
Quoted 1 line
Guenter
It seems its not the only patch missing, i cant find the following patches anymore:
[PATCH v2] hwmon:
acpi_power_meter: Useacpi_bus_get_acpi_device()[PATCH v2 04/20 hwmon: max31722: Warn about failure to put device in stand-by in .remove()
You are right. I added them back in. Must have had a blackout or something :-(.
Thanks a lot for checking!
Guenter
PATCH v3 2/2 hwmon: (dell-smm) Remove unnecessary includes
In reply to [email protected]From: Armin Wolf <[email protected]>
sched.h and io.h are not used anywhere in dell-smm-hwmon.c.
--- drivers/hwmon/dell-smm-hwmon.c | 2 -- 1 file changed, 2 deletions(-)
drivers/hwmon/dell-smm-hwmon.c +0 -2
@@ -26,8 +26,6 @@#include <linux/mutex.h> #include <linux/hwmon.h> #include <linux/uaccess.h> -#include <linux/io.h> -#include <linux/sched.h> #include <linux/ctype.h> #include <linux/smp.h>
--
2.20.1
Re: [PATCH v3 2/2] hwmon: (dell-smm) Remove unnecessary includes
Quoted 5 lines · On Mon, Sep 27, 2021 at 12:10:44AM +0200, [email protected] wrote:
From: Armin Wolf <[email protected]>
sched.handio.hare not used anywhere indell-smm-hwmon.c.Signed-off-by Armin Wolf <[email protected]>
Applied.
Thanks,
Guenter
Quoted 19 lines
--- drivers/hwmon/dell-smm-hwmon.c | 2 -- 1 file changed, 2 deletions(-)--
2.20.1drivers/hwmon/dell-smm-hwmon.c +0
-2@@ -26,8 +26,6 @@#include <linux/mutex.h> #include <linux/hwmon.h> #include <linux/uaccess.h> -#include <linux/io.h> -#include <linux/sched.h> #include <linux/ctype.h> #include <linux/smp.h>