Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

power: supply: cros_charge-control: hide start threshold on v2 cmd

ECs implementing the v2 command will not stop charging when the end
threshold is reached. Instead they will begin discharging until the
start threshold is reached, leading to permanent charge and discharge
cycles. This defeats the point of the charge control mechanism.

Avoid the issue by hiding the start threshold on v2 systems.
Instead on those systems program the EC with start == end which forces
the EC to reach and stay at that level.

v1 does not support thresholds and v3 works correctly,
at least judging from the code.

Reported-by: Thomas Koch <linrunner@gmx.net>
Fixes: c6ed48ef5259 ("power: supply: add ChromeOS EC based charge control driver")
Cc: stable@vger.kernel.org
Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
Link: https://lore.kernel.org/r/20241208-cros_charge-control-v2-v1-3-8d168d0f08a3@weissschuh.net
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>

authored by

Thomas Weißschuh and committed by
Sebastian Reichel
c28dc9fc e65a1b7f

+8 -6
+8 -6
drivers/power/supply/cros_charge-control.c
··· 139 139 return -EINVAL; 140 140 141 141 if (is_end_threshold) { 142 + /* Start threshold is not exposed, use fixed value */ 143 + if (priv->cmd_version == 2) 144 + priv->current_start_threshold = val == 100 ? 0 : val; 145 + 142 146 if (val < priv->current_start_threshold) 143 147 return -EINVAL; 144 148 priv->current_end_threshold = val; ··· 238 234 { 239 235 struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(attr, n); 240 236 241 - if (priv->cmd_version < 2) { 242 - if (n == CROS_CHCTL_ATTR_START_THRESHOLD) 243 - return 0; 244 - if (n == CROS_CHCTL_ATTR_END_THRESHOLD) 245 - return 0; 246 - } 237 + if (n == CROS_CHCTL_ATTR_START_THRESHOLD && priv->cmd_version < 3) 238 + return 0; 239 + else if (n == CROS_CHCTL_ATTR_END_THRESHOLD && priv->cmd_version < 2) 240 + return 0; 247 241 248 242 return attr->mode; 249 243 }