Skip to content

Commit c28dc9f

Browse files
t-8chsre
authored andcommitted
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: c6ed48e ("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>
1 parent e65a1b7 commit c28dc9f

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/power/supply/cros_charge-control.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ static ssize_t cros_chctl_store_threshold(struct device *dev, struct cros_chctl_
139139
return -EINVAL;
140140

141141
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+
142146
if (val < priv->current_start_threshold)
143147
return -EINVAL;
144148
priv->current_end_threshold = val;
@@ -234,12 +238,10 @@ static umode_t cros_chtl_attr_is_visible(struct kobject *kobj, struct attribute
234238
{
235239
struct cros_chctl_priv *priv = cros_chctl_attr_to_priv(attr, n);
236240

237-
if (priv->cmd_version < 2) {
238-
if (n == CROS_CHCTL_ATTR_START_THRESHOLD)
239-
return 0;
240-
if (n == CROS_CHCTL_ATTR_END_THRESHOLD)
241-
return 0;
242-
}
241+
if (n == CROS_CHCTL_ATTR_START_THRESHOLD && priv->cmd_version < 3)
242+
return 0;
243+
else if (n == CROS_CHCTL_ATTR_END_THRESHOLD && priv->cmd_version < 2)
244+
return 0;
243245

244246
return attr->mode;
245247
}

0 commit comments

Comments
 (0)