[PATCH 5/6] power: supply: max77759: sync supplier state at probe
From: André Draszik
Date: Fri Nov 27 2026 - 14:10:22 EST
Supplier events emitted before max77759_charger finishes probing (or
before reloading the charger module) are missed, leaving charging off
until the next supplier event.
max77759_charger_probe() calls max77759_charger_init(), which forces
MODE_OFF, and then registers the power_supply notifier without reading
the supplier's current state.
Extract the supplier read and work scheduling from psy_changed() into
max77759_sync_tcpm_psy() and run it via power_supply_for_each_psy() at
the end of probe. Hold chg->retry_lock across the property reads and
state update so the initial scan cannot overwrite a concurrent notifier
event with stale values.
Fixes: 70d7dd27f6dc ("power: supply: max77759: add charger driver")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: André Draszik <andre.draszik@xxxxxxxxxx>
---
drivers/power/supply/max77759_charger.c | 61 +++++++++++++++++++++------------
1 file changed, 39 insertions(+), 22 deletions(-)
diff --git a/drivers/power/supply/max77759_charger.c b/drivers/power/supply/max77759_charger.c
index 7a7d9a54d888..fe71e8143954 100644
--- a/drivers/power/supply/max77759_charger.c
+++ b/drivers/power/supply/max77759_charger.c
@@ -663,34 +663,31 @@ static void psy_work_item(struct work_struct *work)
}
}
-static int psy_changed(struct notifier_block *nb, unsigned long evt, void *data)
+static int max77759_sync_tcpm_psy(struct power_supply *psy, void *data)
{
- struct max77759_charger *chg = container_of(nb, struct max77759_charger,
- nb);
union power_supply_propval current_limit, online;
static const char *psy_name = "tcpm-source";
- struct power_supply *psy = data;
+ struct max77759_charger *chg = data;
int ret;
- if (!strnstr(psy->desc->name, psy_name, strlen(psy_name)) ||
- evt != PSY_EVENT_PROP_CHANGED)
- return NOTIFY_OK;
-
- ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE,
- &online);
- if (!ret && online.intval)
- ret = power_supply_get_property(psy,
- POWER_SUPPLY_PROP_CURRENT_MAX,
- ¤t_limit);
- if (ret) {
- if (ret != -ENODEV)
- dev_err(chg->dev,
- "Failed to get supplier psy property: %d\n",
- ret);
- online.intval = 0;
- }
+ if (!strnstr(psy->desc->name, psy_name, strlen(psy_name)))
+ return 0;
scoped_guard(mutex, &chg->retry_lock) {
+ ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_ONLINE,
+ &online);
+ if (!ret && online.intval)
+ ret = power_supply_get_property(psy,
+ POWER_SUPPLY_PROP_CURRENT_MAX,
+ ¤t_limit);
+ if (ret) {
+ if (ret != -ENODEV)
+ dev_err(chg->dev,
+ "Failed to get supplier psy property: %d\n",
+ ret);
+ online.intval = 0;
+ }
+
chg->tcpm_online = online.intval;
chg->tcpm_current_limit = online.intval ?
current_limit.intval : 0;
@@ -699,6 +696,20 @@ static int psy_changed(struct notifier_block *nb, unsigned long evt, void *data)
schedule_delayed_work(&chg->psy_work, 0);
+ return 1;
+}
+
+static int psy_changed(struct notifier_block *nb, unsigned long evt, void *data)
+{
+ struct max77759_charger *chg = container_of(nb, struct max77759_charger,
+ nb);
+ struct power_supply *psy = data;
+
+ if (evt != PSY_EVENT_PROP_CHANGED)
+ return NOTIFY_OK;
+
+ max77759_sync_tcpm_psy(psy, chg);
+
return NOTIFY_OK;
}
@@ -773,7 +784,13 @@ static int max77759_charger_probe(struct platform_device *pdev)
return dev_err_probe(dev, ret,
"Failed to add devm action to unregister psy notifier\n");
- return max77759_init_irqhandler(chg);
+ ret = max77759_init_irqhandler(chg);
+ if (ret)
+ return ret;
+
+ power_supply_for_each_psy(chg, max77759_sync_tcpm_psy);
+
+ return 0;
}
static const struct platform_device_id max77759_charger_id[] = {
--
2.56.1.839.g22a8290db9-goog