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

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>

authored by

Daisuke Nojiri and committed by
Sebastian Reichel
97dd69b1 d41dab4c

+22 -3
+22 -3
drivers/power/supply/cros_peripheral_charger.c
··· 227 227 return 0; 228 228 } 229 229 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) 232 231 { 233 232 int i; 234 233 ··· 255 256 if (!(host_event & EC_MKBP_PCHG_DEVICE_EVENT)) 256 257 return NOTIFY_DONE; 257 258 258 - return cros_pchg_event(charger, host_event); 259 + return cros_pchg_event(charger); 259 260 } 260 261 261 262 static int cros_pchg_probe(struct platform_device *pdev) ··· 279 280 charger->dev = dev; 280 281 charger->ec_dev = ec_dev; 281 282 charger->ec_device = ec_device; 283 + 284 + platform_set_drvdata(pdev, charger); 282 285 283 286 ret = cros_pchg_port_count(charger); 284 287 if (ret <= 0) { ··· 350 349 return 0; 351 350 } 352 351 352 + #ifdef CONFIG_PM_SLEEP 353 + static int __maybe_unused cros_pchg_resume(struct device *dev) 354 + { 355 + struct charger_data *charger = dev_get_drvdata(dev); 356 + 357 + /* 358 + * Sync all ports on resume in case reports from EC are lost during 359 + * the last suspend. 360 + */ 361 + cros_pchg_event(charger); 362 + 363 + return 0; 364 + } 365 + #endif 366 + 367 + static SIMPLE_DEV_PM_OPS(cros_pchg_pm_ops, NULL, cros_pchg_resume); 368 + 353 369 static struct platform_driver cros_pchg_driver = { 354 370 .driver = { 355 371 .name = DRV_NAME, 372 + .pm = &cros_pchg_pm_ops, 356 373 }, 357 374 .probe = cros_pchg_probe 358 375 };