Commit 97dd69b1 authored by Daisuke Nojiri's avatar Daisuke Nojiri Committed by Sebastian Reichel
Browse files

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: default avatarDaisuke Nojiri <dnojiri@chromium.org>
Signed-off-by: default avatarSebastian Reichel <sebastian.reichel@collabora.com>
parent d41dab4c
Loading
Loading
Loading
Loading
+22 −3
Original line number Diff line number Diff line
@@ -227,8 +227,7 @@ static int cros_pchg_get_prop(struct power_supply *psy,
	return 0;
}

static int cros_pchg_event(const struct charger_data *charger,
			   unsigned long host_event)
static int cros_pchg_event(const struct charger_data *charger)
{
	int i;

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

	return cros_pchg_event(charger, host_event);
	return cros_pchg_event(charger);
}

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

	platform_set_drvdata(pdev, charger);

	ret = cros_pchg_port_count(charger);
	if (ret <= 0) {
		/*
@@ -349,9 +350,27 @@ static int cros_pchg_probe(struct platform_device *pdev)
	return 0;
}

#ifdef CONFIG_PM_SLEEP
static int __maybe_unused cros_pchg_resume(struct device *dev)
{
	struct charger_data *charger = dev_get_drvdata(dev);

	/*
	 * Sync all ports on resume in case reports from EC are lost during
	 * the last suspend.
	 */
	cros_pchg_event(charger);

	return 0;
}
#endif

static SIMPLE_DEV_PM_OPS(cros_pchg_pm_ops, NULL, cros_pchg_resume);

static struct platform_driver cros_pchg_driver = {
	.driver = {
		.name = DRV_NAME,
		.pm = &cros_pchg_pm_ops,
	},
	.probe = cros_pchg_probe
};