diff mbox series

cros_pchg: Sync port status on resume

Message ID 20230417221610.1507341-1-dnojiri@chromium.org
State Accepted
Commit 97dd69b1ade166f3200546e5fb7984986cafcf81
Headers show
Series cros_pchg: Sync port status on resume | expand

Commit Message

Daisuke Nojiri April 17, 2023, 10:16 p.m. UTC
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>
---
 .../power/supply/cros_peripheral_charger.c    | 25 ++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

Comments

Sebastian Reichel May 8, 2023, 12:32 p.m. UTC | #1
Hi,

On Mon, Apr 17, 2023 at 03:16:10PM -0700, Daisuke Nojiri wrote:
> 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>
> ---

Thanks, queued.

-- Sebastian

>  .../power/supply/cros_peripheral_charger.c    | 25 ++++++++++++++++---
>  1 file changed, 22 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
> index 1379afd9698d..a204f2355be4 100644
> --- a/drivers/power/supply/cros_peripheral_charger.c
> +++ b/drivers/power/supply/cros_peripheral_charger.c
> @@ -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
>  };
> -- 
> 2.39.2
>
Daisuke Nojiri Aug. 29, 2023, 5:46 p.m. UTC | #2
Hi Sebastian. Friendly ping. Any progress on this? Thanks,


On Mon, May 8, 2023 at 9:37 AM Sebastian Reichel
<sebastian.reichel@collabora.com> wrote:
>
> Hi,
>
> On Mon, Apr 17, 2023 at 03:16:10PM -0700, Daisuke Nojiri wrote:
> > 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>
> > ---
>
> Thanks, queued.
>
> -- Sebastian
>
> >  .../power/supply/cros_peripheral_charger.c    | 25 ++++++++++++++++---
> >  1 file changed, 22 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
> > index 1379afd9698d..a204f2355be4 100644
> > --- a/drivers/power/supply/cros_peripheral_charger.c
> > +++ b/drivers/power/supply/cros_peripheral_charger.c
> > @@ -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
> >  };
> > --
> > 2.39.2
> >
Sebastian Reichel Sept. 14, 2023, 4:18 p.m. UTC | #3
Hi,

On Tue, Aug 29, 2023 at 10:46:19AM -0700, Daisuke Nojiri wrote:
> Hi Sebastian. Friendly ping. Any progress on this? Thanks,

Please don't top-post on kernel mailing lists. Also I queued this On
2023-05-08, as you quoted. The patch landed in 6.4-rc1.

-- Sebastian

> On Mon, May 8, 2023 at 9:37 AM Sebastian Reichel
> <sebastian.reichel@collabora.com> wrote:
> > On Mon, Apr 17, 2023 at 03:16:10PM -0700, Daisuke Nojiri wrote:
> > > 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>
> > > ---
> >
> > Thanks, queued.
> >
> > -- Sebastian
> >
> > >  .../power/supply/cros_peripheral_charger.c    | 25 ++++++++++++++++---
> > >  1 file changed, 22 insertions(+), 3 deletions(-)
> > >
> > > diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
> > > index 1379afd9698d..a204f2355be4 100644
> > > --- a/drivers/power/supply/cros_peripheral_charger.c
> > > +++ b/drivers/power/supply/cros_peripheral_charger.c
> > > @@ -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
> > >  };
> > > --
> > > 2.39.2
> > >
diff mbox series

Patch

diff --git a/drivers/power/supply/cros_peripheral_charger.c b/drivers/power/supply/cros_peripheral_charger.c
index 1379afd9698d..a204f2355be4 100644
--- a/drivers/power/supply/cros_peripheral_charger.c
+++ b/drivers/power/supply/cros_peripheral_charger.c
@@ -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
 };