Skip to content

Commit 97dd69b

Browse files
dnojirisre
authored andcommitted
power: supply: cros_pchg: Sync port status on resume
When a stylus is removed (or attached) during suspend, the device detach (or attach) events can be lost. This patch makes the peripheral device charge driver retrieve the latest status from the EC on resume. BUG=b:276414488 TEST=Redrix Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
1 parent d41dab4 commit 97dd69b

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

drivers/power/supply/cros_peripheral_charger.c

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,7 @@ static int cros_pchg_get_prop(struct power_supply *psy,
227227
return 0;
228228
}
229229

230-
static int cros_pchg_event(const struct charger_data *charger,
231-
unsigned long host_event)
230+
static int cros_pchg_event(const struct charger_data *charger)
232231
{
233232
int i;
234233

@@ -256,7 +255,7 @@ static int cros_ec_notify(struct notifier_block *nb,
256255
if (!(host_event & EC_MKBP_PCHG_DEVICE_EVENT))
257256
return NOTIFY_DONE;
258257

259-
return cros_pchg_event(charger, host_event);
258+
return cros_pchg_event(charger);
260259
}
261260

262261
static int cros_pchg_probe(struct platform_device *pdev)
@@ -281,6 +280,8 @@ static int cros_pchg_probe(struct platform_device *pdev)
281280
charger->ec_dev = ec_dev;
282281
charger->ec_device = ec_device;
283282

283+
platform_set_drvdata(pdev, charger);
284+
284285
ret = cros_pchg_port_count(charger);
285286
if (ret <= 0) {
286287
/*
@@ -349,9 +350,27 @@ static int cros_pchg_probe(struct platform_device *pdev)
349350
return 0;
350351
}
351352

353+
#ifdef CONFIG_PM_SLEEP
354+
static int __maybe_unused cros_pchg_resume(struct device *dev)
355+
{
356+
struct charger_data *charger = dev_get_drvdata(dev);
357+
358+
/*
359+
* Sync all ports on resume in case reports from EC are lost during
360+
* the last suspend.
361+
*/
362+
cros_pchg_event(charger);
363+
364+
return 0;
365+
}
366+
#endif
367+
368+
static SIMPLE_DEV_PM_OPS(cros_pchg_pm_ops, NULL, cros_pchg_resume);
369+
352370
static struct platform_driver cros_pchg_driver = {
353371
.driver = {
354372
.name = DRV_NAME,
373+
.pm = &cros_pchg_pm_ops,
355374
},
356375
.probe = cros_pchg_probe
357376
};

0 commit comments

Comments
 (0)