Skip to contentSkip to conversation

platform/x86: clamp charge thresholds on fujitsu

PATCH In review Jelle van der Waa 4 participants 7 messages Jun 9, 2025 – Jun 13, 2025

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

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
#1 lore raw

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
index 162809140f68..c8aeb28a783c 100644
@@ -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
maintainer Reviewed-by on v1 1/2
#2 lore raw

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.

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
index 162809140f68..c8aeb28a783c 100644
@@ -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)
maintainer
#3 lore raw

Re: [PATCH 1/2] platform/x86: fujitsu: use unsigned int for kstrtounit

In reply to Jelle van der Waa
Quoted 12 lines · Jelle van der Waa

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 +0 -0
index 162809140f68..c8aeb28a783c 100644

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 -0
 	ret = kstrtouint(buf, 10, &value);
 	if (ret)
 
Signature · 1 line
 i.
#4 lore raw

PATCH 2/2 platform/x86: fujitsu: clamp charge_control_end_threshold values to 50

In reply to 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.

---
 drivers/platform/x86/fujitsu-laptop.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/platform/x86/fujitsu-laptop.c +4 -1
index c8aeb28a783c..f6a4a02e8d44 100644
@@ -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
maintainer Reviewed-by on v1 2/2
#5 lore raw

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.

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
index c8aeb28a783c..f6a4a02e8d44 100644
@@ -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);
maintainer Acked-by on the v1 series
#6 lore raw
In reply to Jelle van der Waa
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: 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

This patch series looks good to me.