platform/x86: clamp charge thresholds on fujitsu
Subsystems (2)
cover platform/x86: clamp charge thresholds on fujitsu
For userspace programs it is not know what the valid charge control threshold values are, clamping them to the nearest supported threshold makes the API easier to use for power management daemons such as UPower.
Jelle van der Waa (2):
platform/x86: fujitsu: use unsigned int for kstrtounit platform/x86: fujitsu: clamp charge_control_end_threshold values to 50
drivers/platform/x86/fujitsu-laptop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)
Signature · 1 line
2.49.0
PATCH 1/2 platform/x86: fujitsu: use unsigned int for kstrtounit
The charge control threshold value ranges from 0-100.
--- drivers/platform/x86/fujitsu-laptop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/platform/x86/fujitsu-laptop.c +2 -1
@@ -180,7 +180,8 @@ static ssize_t charge_control_end_threshold_store(struct device *dev, const char *buf, size_t count) { int cc_end_value, s006_cc_return; -int value, ret; +int ret; +unsigned int value; ret =kstrtouint (buf,10 , &value);if (ret)
Signature · 1 line
2.49.0
Re: [PATCH 1/2] platform/x86: fujitsu: use unsigned int for kstrtounit
Hi,
Quoted 3 lines · Jelle van der Waa
The charge control threshold value ranges from 0-100.
Signed-off-by Jelle van der Waa <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 18 lines
--- drivers/platform/x86/fujitsu-laptop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/platform/x86/fujitsu-laptop.c +2
-1@@ -180,7 +180,8 @@ static ssize_t charge_control_end_threshold_store(struct device *dev, const char *buf, size_t count) { int cc_end_value, s006_cc_return; -int value, ret; +int ret; +unsigned int value; ret =kstrtouint (buf,10 , &value);if (ret)
Ilpo Järvinen
maintainerRe: [PATCH 1/2] platform/x86: fujitsu: use unsigned int for kstrtounit
In reply to Jelle van der WaaQuoted 12 lines · Jelle van der Waa
The charge control threshold value ranges from 0-100.
Signed-off-by Jelle van der Waa <[email protected]>--- drivers/platform/x86/fujitsu-laptop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/platform/x86/fujitsu-laptop.c +0
-0
drivers/platform/x86/fujitsu-laptop.c static ssize_t charge_control_end_threshold_store(struct device *dev, · line 184
Quoted 6 lines
drivers/platform/x86/fujitsu-laptop.c +2
-1@@ -180,7 +180,8 @@ static ssize_t charge_control_end_threshold_store(struct device *dev, const char *buf, size_t count) { int cc_end_value, s006_cc_return; -int value, ret; +int ret; +unsigned int value;
Thanks.
I've applied this series to the review-ilpo-next branch but I changed these variables to the reverse xmas-tree order while applying. In general, if there's no good reason to do otherwise, reverse xmas tree order is preferred for local variables.
Quoted 4 lines
drivers/platform/x86/fujitsu-laptop.c +0
-0ret =kstrtouint (buf,10 , &value);if (ret)
Signature · 1 line
i.
PATCH 2/2 platform/x86: fujitsu: clamp charge_control_end_threshold values to 50
In reply to Jelle van der WaaFollow the sysfs ABI documentation that drivers should round written values to the nearest supported value instead of returning an error.
Tested on a Fujitsu Lifebook U7720.
--- drivers/platform/x86/fujitsu-laptop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/fujitsu-laptop.c +4 -1
@@ -187,9 +187,12 @@ static ssize_t charge_control_end_threshold_store(struct device *dev,if (ret)return ret; -if (value <50 || value >100 ) +if (value >100 )return -EINVAL ; +if (value <50 ) + value =50 ; + cc_end_value = value *0x100 +0x20 ; s006_cc_return =call_fext_func (fext,FUNC_S006_METHOD ,CHARGE_CONTROL_RW , cc_end_value,0x0 );
Signature · 1 line
2.49.0
Re: [PATCH 2/2] platform/x86: fujitsu: clamp charge_control_end_threshold values to 50
Hi,
Quoted 6 lines · Jelle van der Waa
Follow the sysfs ABI documentation that drivers should round written values to the nearest supported value instead of returning an error.
Tested on a Fujitsu Lifebook U7720.
Signed-off-by Jelle van der Waa <[email protected]>
Thanks, patch looks good to me:
Regards,
Hans
Quoted 22 lines
--- drivers/platform/x86/fujitsu-laptop.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)drivers/platform/x86/fujitsu-laptop.c +4
-1@@ -187,9 +187,12 @@ static ssize_t charge_control_end_threshold_store(struct device *dev,if (ret)return ret; -if (value <50 || value >100 ) +if (value >100 )return -EINVAL ; +if (value <50 ) + value =50 ; + cc_end_value = value *0x100 +0x20 ; s006_cc_return =call_fext_func (fext,FUNC_S006_METHOD ,CHARGE_CONTROL_RW , cc_end_value,0x0 );
Quoted 4 lines · Jelle van der Waa
For userspace programs it is not know what the valid charge control threshold values are, clamping them to the nearest supported threshold makes the API easier to use for power management daemons such as UPower.
Quoted 9 lines
Jelle van der Waa (2):
platform/x86: fujitsu: use unsigned int for kstrtounit platform/x86: fujitsu: clampcharge_control_end_thresholdvalues to 50drivers/platform/x86/fujitsu-laptop.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-)Signature · 1 line
2.49.0
This patch series looks good to me.