linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update
@ 2020-06-29 21:13 Prashant Malani
  2020-06-29 21:13 ` [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support Prashant Malani
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Prashant Malani @ 2020-06-29 21:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: heikki.krogerus, Prashant Malani, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck

Use a work queue to call the port update routines, instead of doing it
directly in the PD notifier callback. This will prevent other drivers
with PD notifier callbacks from being blocked on the port update routine
completing.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
---

Changes in v4:
- Removed extra newline.
- Moved both variable declarations into one line.

Changes in v3:
- Use new 100 character line length limit.

Changes in v2:
- No changes.

 drivers/platform/chrome/cros_ec_typec.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 0c041b79cbba..69c4118e280c 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -58,6 +58,7 @@ struct cros_typec_data {
 	/* Array of ports, indexed by port number. */
 	struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
 	struct notifier_block nb;
+	struct work_struct port_work;
 };
 
 static int cros_typec_parse_port_props(struct typec_capability *cap,
@@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
 	return 0;
 }
 
-static int cros_ec_typec_event(struct notifier_block *nb,
-			       unsigned long host_event, void *_notify)
+static void cros_typec_port_work(struct work_struct *work)
 {
-	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
-						     nb);
-	int ret, i;
+	struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
+	int i, ret;
 
 	for (i = 0; i < typec->num_ports; i++) {
 		ret = cros_typec_port_update(typec, i);
 		if (ret < 0)
 			dev_warn(typec->dev, "Update failed for port: %d\n", i);
 	}
+}
+
+static int cros_ec_typec_event(struct notifier_block *nb,
+			       unsigned long host_event, void *_notify)
+{
+	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
+
+	schedule_work(&typec->port_work);
 
 	return NOTIFY_OK;
 }
@@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
 	if (ret < 0)
 		return ret;
 
+	INIT_WORK(&typec->port_work, cros_typec_port_work);
+
+	/*
+	 * Safe to call port update here, since we haven't registered the
+	 * PD notifier yet.
+	 */
 	for (i = 0; i < typec->num_ports; i++) {
 		ret = cros_typec_port_update(typec, i);
 		if (ret < 0)
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support
  2020-06-29 21:13 [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Prashant Malani
@ 2020-06-29 21:13 ` Prashant Malani
  2020-06-30 14:23   ` Heikki Krogerus
  2020-06-29 21:17 ` [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Guenter Roeck
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Prashant Malani @ 2020-06-29 21:13 UTC (permalink / raw)
  To: linux-kernel
  Cc: heikki.krogerus, Prashant Malani, Guenter Roeck, Benson Leung,
	Enric Balletbo i Serra

Define basic suspend resume functions for cros-ec-typec. On suspend, we
simply ensure that any pending port update work is completed, and on
resume, we re-poll the port state to account for any
changes/disconnections that might have occurred during suspend.

Signed-off-by: Prashant Malani <pmalani@chromium.org>
Reviewed-by: Guenter Roeck <groeck@chromium.org>
---

Changes in v4:
- No changes (added Reviewed-by received in v3).

Changes in v3:
- Remove superfluous DEV_PM_OPS #define.

Changes in v2:
- Remove #ifdef-ery, add __maybe_unused tag to functions.

 drivers/platform/chrome/cros_ec_typec.c | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
index 69c4118e280c..cb95d190f06a 100644
--- a/drivers/platform/chrome/cros_ec_typec.c
+++ b/drivers/platform/chrome/cros_ec_typec.c
@@ -720,11 +720,35 @@ static int cros_typec_probe(struct platform_device *pdev)
 	return ret;
 }
 
+static int __maybe_unused cros_typec_suspend(struct device *dev)
+{
+	struct cros_typec_data *typec = dev_get_drvdata(dev);
+
+	cancel_work_sync(&typec->port_work);
+
+	return 0;
+}
+
+static int __maybe_unused cros_typec_resume(struct device *dev)
+{
+	struct cros_typec_data *typec = dev_get_drvdata(dev);
+
+	/* Refresh port state. */
+	schedule_work(&typec->port_work);
+
+	return 0;
+}
+
+static const struct dev_pm_ops cros_typec_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(cros_typec_suspend, cros_typec_resume)
+};
+
 static struct platform_driver cros_typec_driver = {
 	.driver	= {
 		.name = DRV_NAME,
 		.acpi_match_table = ACPI_PTR(cros_typec_acpi_id),
 		.of_match_table = of_match_ptr(cros_typec_of_match),
+		.pm = &cros_typec_pm_ops,
 	},
 	.probe = cros_typec_probe,
 };
-- 
2.27.0.212.ge8ba1cc988-goog


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update
  2020-06-29 21:13 [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Prashant Malani
  2020-06-29 21:13 ` [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support Prashant Malani
@ 2020-06-29 21:17 ` Guenter Roeck
  2020-06-29 21:47   ` Prashant Malani
  2020-06-30 14:22 ` Heikki Krogerus
  2020-07-01  9:11 ` Enric Balletbo i Serra
  3 siblings, 1 reply; 7+ messages in thread
From: Guenter Roeck @ 2020-06-29 21:17 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Heikki Krogerus, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck

On Mon, Jun 29, 2020 at 2:13 PM Prashant Malani <pmalani@chromium.org> wrote:
>
> Use a work queue to call the port update routines, instead of doing it
> directly in the PD notifier callback. This will prevent other drivers
> with PD notifier callbacks from being blocked on the port update routine
> completing.
>
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

I can see you are having fun with me :-)

> -       int ret, i;
> +       int i, ret;

Reviewed-by: Guenter Roeck <groeck@chromium.org>

> ---
>
> Changes in v4:
> - Removed extra newline.
> - Moved both variable declarations into one line.
>
> Changes in v3:
> - Use new 100 character line length limit.
>
> Changes in v2:
> - No changes.
>
>  drivers/platform/chrome/cros_ec_typec.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 0c041b79cbba..69c4118e280c 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -58,6 +58,7 @@ struct cros_typec_data {
>         /* Array of ports, indexed by port number. */
>         struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
>         struct notifier_block nb;
> +       struct work_struct port_work;
>  };
>
>  static int cros_typec_parse_port_props(struct typec_capability *cap,
> @@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
>         return 0;
>  }
>
> -static int cros_ec_typec_event(struct notifier_block *nb,
> -                              unsigned long host_event, void *_notify)
> +static void cros_typec_port_work(struct work_struct *work)
>  {
> -       struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> -                                                    nb);
> -       int ret, i;
> +       struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
> +       int i, ret;
>
>         for (i = 0; i < typec->num_ports; i++) {
>                 ret = cros_typec_port_update(typec, i);
>                 if (ret < 0)
>                         dev_warn(typec->dev, "Update failed for port: %d\n", i);
>         }
> +}
> +
> +static int cros_ec_typec_event(struct notifier_block *nb,
> +                              unsigned long host_event, void *_notify)
> +{
> +       struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
> +
> +       schedule_work(&typec->port_work);
>
>         return NOTIFY_OK;
>  }
> @@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
>         if (ret < 0)
>                 return ret;
>
> +       INIT_WORK(&typec->port_work, cros_typec_port_work);
> +
> +       /*
> +        * Safe to call port update here, since we haven't registered the
> +        * PD notifier yet.
> +        */
>         for (i = 0; i < typec->num_ports; i++) {
>                 ret = cros_typec_port_update(typec, i);
>                 if (ret < 0)
> --
> 2.27.0.212.ge8ba1cc988-goog
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update
  2020-06-29 21:17 ` [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Guenter Roeck
@ 2020-06-29 21:47   ` Prashant Malani
  0 siblings, 0 replies; 7+ messages in thread
From: Prashant Malani @ 2020-06-29 21:47 UTC (permalink / raw)
  To: Guenter Roeck
  Cc: linux-kernel, Heikki Krogerus, Benson Leung,
	Enric Balletbo i Serra, Guenter Roeck

On Mon, Jun 29, 2020 at 2:18 PM Guenter Roeck <groeck@google.com> wrote:
>
> On Mon, Jun 29, 2020 at 2:13 PM Prashant Malani <pmalani@chromium.org> wrote:
> >
> > Use a work queue to call the port update routines, instead of doing it
> > directly in the PD notifier callback. This will prevent other drivers
> > with PD notifier callbacks from being blocked on the port update routine
> > completing.
> >
> > Signed-off-by: Prashant Malani <pmalani@chromium.org>
>
> I can see you are having fun with me :-)

Haha, my apologies , I'm being forgetful :)
>
> > -       int ret, i;
> > +       int i, ret;
>
> Reviewed-by: Guenter Roeck <groeck@chromium.org>
>
> > ---
> >
> > Changes in v4:
> > - Removed extra newline.
> > - Moved both variable declarations into one line.
> >
> > Changes in v3:
> > - Use new 100 character line length limit.
> >
> > Changes in v2:
> > - No changes.
> >
> >  drivers/platform/chrome/cros_ec_typec.c | 23 ++++++++++++++++++-----
> >  1 file changed, 18 insertions(+), 5 deletions(-)
> >
> > diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> > index 0c041b79cbba..69c4118e280c 100644
> > --- a/drivers/platform/chrome/cros_ec_typec.c
> > +++ b/drivers/platform/chrome/cros_ec_typec.c
> > @@ -58,6 +58,7 @@ struct cros_typec_data {
> >         /* Array of ports, indexed by port number. */
> >         struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
> >         struct notifier_block nb;
> > +       struct work_struct port_work;
> >  };
> >
> >  static int cros_typec_parse_port_props(struct typec_capability *cap,
> > @@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
> >         return 0;
> >  }
> >
> > -static int cros_ec_typec_event(struct notifier_block *nb,
> > -                              unsigned long host_event, void *_notify)
> > +static void cros_typec_port_work(struct work_struct *work)
> >  {
> > -       struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> > -                                                    nb);
> > -       int ret, i;
> > +       struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
> > +       int i, ret;
> >
> >         for (i = 0; i < typec->num_ports; i++) {
> >                 ret = cros_typec_port_update(typec, i);
> >                 if (ret < 0)
> >                         dev_warn(typec->dev, "Update failed for port: %d\n", i);
> >         }
> > +}
> > +
> > +static int cros_ec_typec_event(struct notifier_block *nb,
> > +                              unsigned long host_event, void *_notify)
> > +{
> > +       struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
> > +
> > +       schedule_work(&typec->port_work);
> >
> >         return NOTIFY_OK;
> >  }
> > @@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
> >         if (ret < 0)
> >                 return ret;
> >
> > +       INIT_WORK(&typec->port_work, cros_typec_port_work);
> > +
> > +       /*
> > +        * Safe to call port update here, since we haven't registered the
> > +        * PD notifier yet.
> > +        */
> >         for (i = 0; i < typec->num_ports; i++) {
> >                 ret = cros_typec_port_update(typec, i);
> >                 if (ret < 0)
> > --
> > 2.27.0.212.ge8ba1cc988-goog
> >

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update
  2020-06-29 21:13 [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Prashant Malani
  2020-06-29 21:13 ` [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support Prashant Malani
  2020-06-29 21:17 ` [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Guenter Roeck
@ 2020-06-30 14:22 ` Heikki Krogerus
  2020-07-01  9:11 ` Enric Balletbo i Serra
  3 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2020-06-30 14:22 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Benson Leung, Enric Balletbo i Serra, Guenter Roeck

On Mon, Jun 29, 2020 at 02:13:27PM -0700, Prashant Malani wrote:
> Use a work queue to call the port update routines, instead of doing it
> directly in the PD notifier callback. This will prevent other drivers
> with PD notifier callbacks from being blocked on the port update routine
> completing.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> 
> Changes in v4:
> - Removed extra newline.
> - Moved both variable declarations into one line.
> 
> Changes in v3:
> - Use new 100 character line length limit.
> 
> Changes in v2:
> - No changes.
> 
>  drivers/platform/chrome/cros_ec_typec.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 0c041b79cbba..69c4118e280c 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -58,6 +58,7 @@ struct cros_typec_data {
>  	/* Array of ports, indexed by port number. */
>  	struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
>  	struct notifier_block nb;
> +	struct work_struct port_work;
>  };
>  
>  static int cros_typec_parse_port_props(struct typec_capability *cap,
> @@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
>  	return 0;
>  }
>  
> -static int cros_ec_typec_event(struct notifier_block *nb,
> -			       unsigned long host_event, void *_notify)
> +static void cros_typec_port_work(struct work_struct *work)
>  {
> -	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> -						     nb);
> -	int ret, i;
> +	struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
> +	int i, ret;
>  
>  	for (i = 0; i < typec->num_ports; i++) {
>  		ret = cros_typec_port_update(typec, i);
>  		if (ret < 0)
>  			dev_warn(typec->dev, "Update failed for port: %d\n", i);
>  	}
> +}
> +
> +static int cros_ec_typec_event(struct notifier_block *nb,
> +			       unsigned long host_event, void *_notify)
> +{
> +	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
> +
> +	schedule_work(&typec->port_work);
>  
>  	return NOTIFY_OK;
>  }
> @@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
>  	if (ret < 0)
>  		return ret;
>  
> +	INIT_WORK(&typec->port_work, cros_typec_port_work);
> +
> +	/*
> +	 * Safe to call port update here, since we haven't registered the
> +	 * PD notifier yet.
> +	 */
>  	for (i = 0; i < typec->num_ports; i++) {
>  		ret = cros_typec_port_update(typec, i);
>  		if (ret < 0)
> -- 
> 2.27.0.212.ge8ba1cc988-goog

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support
  2020-06-29 21:13 ` [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support Prashant Malani
@ 2020-06-30 14:23   ` Heikki Krogerus
  0 siblings, 0 replies; 7+ messages in thread
From: Heikki Krogerus @ 2020-06-30 14:23 UTC (permalink / raw)
  To: Prashant Malani
  Cc: linux-kernel, Guenter Roeck, Benson Leung, Enric Balletbo i Serra

On Mon, Jun 29, 2020 at 02:13:29PM -0700, Prashant Malani wrote:
> Define basic suspend resume functions for cros-ec-typec. On suspend, we
> simply ensure that any pending port update work is completed, and on
> resume, we re-poll the port state to account for any
> changes/disconnections that might have occurred during suspend.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>
> Reviewed-by: Guenter Roeck <groeck@chromium.org>

Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com>

> ---
> 
> Changes in v4:
> - No changes (added Reviewed-by received in v3).
> 
> Changes in v3:
> - Remove superfluous DEV_PM_OPS #define.
> 
> Changes in v2:
> - Remove #ifdef-ery, add __maybe_unused tag to functions.
> 
>  drivers/platform/chrome/cros_ec_typec.c | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 69c4118e280c..cb95d190f06a 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -720,11 +720,35 @@ static int cros_typec_probe(struct platform_device *pdev)
>  	return ret;
>  }
>  
> +static int __maybe_unused cros_typec_suspend(struct device *dev)
> +{
> +	struct cros_typec_data *typec = dev_get_drvdata(dev);
> +
> +	cancel_work_sync(&typec->port_work);
> +
> +	return 0;
> +}
> +
> +static int __maybe_unused cros_typec_resume(struct device *dev)
> +{
> +	struct cros_typec_data *typec = dev_get_drvdata(dev);
> +
> +	/* Refresh port state. */
> +	schedule_work(&typec->port_work);
> +
> +	return 0;
> +}
> +
> +static const struct dev_pm_ops cros_typec_pm_ops = {
> +	SET_SYSTEM_SLEEP_PM_OPS(cros_typec_suspend, cros_typec_resume)
> +};
> +
>  static struct platform_driver cros_typec_driver = {
>  	.driver	= {
>  		.name = DRV_NAME,
>  		.acpi_match_table = ACPI_PTR(cros_typec_acpi_id),
>  		.of_match_table = of_match_ptr(cros_typec_of_match),
> +		.pm = &cros_typec_pm_ops,
>  	},
>  	.probe = cros_typec_probe,
>  };

thanks,

-- 
heikki

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update
  2020-06-29 21:13 [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Prashant Malani
                   ` (2 preceding siblings ...)
  2020-06-30 14:22 ` Heikki Krogerus
@ 2020-07-01  9:11 ` Enric Balletbo i Serra
  3 siblings, 0 replies; 7+ messages in thread
From: Enric Balletbo i Serra @ 2020-07-01  9:11 UTC (permalink / raw)
  To: Prashant Malani, linux-kernel
  Cc: heikki.krogerus, Benson Leung, Guenter Roeck

Hi Prashant,

Thank you for the patch. And thanks to Guenter and Heikki for reviewing it.

On 29/6/20 23:13, Prashant Malani wrote:
> Use a work queue to call the port update routines, instead of doing it
> directly in the PD notifier callback. This will prevent other drivers
> with PD notifier callbacks from being blocked on the port update routine
> completing.
> 
> Signed-off-by: Prashant Malani <pmalani@chromium.org>

Applied for 5.9 both patches with the corresponding reviewed tags.

> ---
> 
> Changes in v4:
> - Removed extra newline.
> - Moved both variable declarations into one line.
> 
> Changes in v3:
> - Use new 100 character line length limit.
> 
> Changes in v2:
> - No changes.
> 
>  drivers/platform/chrome/cros_ec_typec.c | 23 ++++++++++++++++++-----
>  1 file changed, 18 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c
> index 0c041b79cbba..69c4118e280c 100644
> --- a/drivers/platform/chrome/cros_ec_typec.c
> +++ b/drivers/platform/chrome/cros_ec_typec.c
> @@ -58,6 +58,7 @@ struct cros_typec_data {
>  	/* Array of ports, indexed by port number. */
>  	struct cros_typec_port *ports[EC_USB_PD_MAX_PORTS];
>  	struct notifier_block nb;
> +	struct work_struct port_work;
>  };
>  
>  static int cros_typec_parse_port_props(struct typec_capability *cap,
> @@ -619,18 +620,24 @@ static int cros_typec_get_cmd_version(struct cros_typec_data *typec)
>  	return 0;
>  }
>  
> -static int cros_ec_typec_event(struct notifier_block *nb,
> -			       unsigned long host_event, void *_notify)
> +static void cros_typec_port_work(struct work_struct *work)
>  {
> -	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data,
> -						     nb);
> -	int ret, i;
> +	struct cros_typec_data *typec = container_of(work, struct cros_typec_data, port_work);
> +	int i, ret;
>  
>  	for (i = 0; i < typec->num_ports; i++) {
>  		ret = cros_typec_port_update(typec, i);
>  		if (ret < 0)
>  			dev_warn(typec->dev, "Update failed for port: %d\n", i);
>  	}
> +}
> +
> +static int cros_ec_typec_event(struct notifier_block *nb,
> +			       unsigned long host_event, void *_notify)
> +{
> +	struct cros_typec_data *typec = container_of(nb, struct cros_typec_data, nb);
> +
> +	schedule_work(&typec->port_work);
>  
>  	return NOTIFY_OK;
>  }
> @@ -689,6 +696,12 @@ static int cros_typec_probe(struct platform_device *pdev)
>  	if (ret < 0)
>  		return ret;
>  
> +	INIT_WORK(&typec->port_work, cros_typec_port_work);
> +
> +	/*
> +	 * Safe to call port update here, since we haven't registered the
> +	 * PD notifier yet.
> +	 */
>  	for (i = 0; i < typec->num_ports; i++) {
>  		ret = cros_typec_port_update(typec, i);
>  		if (ret < 0)
> 

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-07-01  9:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-29 21:13 [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Prashant Malani
2020-06-29 21:13 ` [PATCH v4 2/2] platform/chrome: cros_ec_typec: Add PM support Prashant Malani
2020-06-30 14:23   ` Heikki Krogerus
2020-06-29 21:17 ` [PATCH v4 1/2] platform/chrome: cros_ec_typec: Use workqueue for port update Guenter Roeck
2020-06-29 21:47   ` Prashant Malani
2020-06-30 14:22 ` Heikki Krogerus
2020-07-01  9:11 ` Enric Balletbo i Serra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).