All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH RESEND] serdev: add controller runtime PM support
@ 2018-05-30 10:50 Johan Hovold
  2018-05-30 13:20 ` Rob Herring
  0 siblings, 1 reply; 2+ messages in thread
From: Johan Hovold @ 2018-05-30 10:50 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Rob Herring
  Cc: Sebastian Reichel, Tony Lindgren, H. Nikolaus Schaller,
	Andreas Kemnade, Mark Rutland, Arnd Bergmann, Pavel Machek,
	linux-kernel, linux-serial, linux-pm, Johan Hovold

Add support for controller runtime power management to serdev core. This
is needed to allow slave drivers to manage the runtime PM state of the
underlying serial controller when its driver, in turn, implements more
aggressive runtime power management (e.g. using autosuspend).

For some applications, for example, where loss off initial data after a
remote-wakeup event is acceptable or where rx is not used at all,
aggressive serial controller runtime PM may be used without further
involvement of the slave driver. But when this is not the case, the
slave driver must be able to indicate when incoming data is expected in
order to avoid data loss.

To facilitate the common case, where the serial controller power state
is active whenever the port is open (which is the case with just about
every serial driver), and where data loss is not acceptable and cannot
even be prevented by explicit controller runtime power management, an
RPM reference is taken in serdev open and put again at close. This
reference can later be balanced by any serdev driver which wants and/or
can handle aggressive controller runtime PM.

Note that the .ignore_children flag is set for the serdev controller to
allow the underlying hardware to idle when no I/O is expected, regardless
of the slave device RPM state.

Acked-by: Tony Lindgren <tony@atomide.com>
Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Signed-off-by: Johan Hovold <johan@kernel.org>
---

Hi Rob and Greg,

This is a resend of the serdev controller runtime PM patch, which you
haven't commented on yet (possibly due to the following extensive
discussions on how to generalise the aggressive OMAP serial runtime PM
implementation).

This patch works with what we have today, regardless of how we end up
configuring the serial controller (active) runtime PM behaviour
(currently done through sysfs for OMAP), which is a separate issue.

No changes in this resend, besides me adding Tony's and Sebastian's ack
and reviewed-by tags and dropping the second patch which only served as
an example of how to use this in a serdev driver.

Johan


 drivers/tty/serdev/core.c | 33 ++++++++++++++++++++++++++++++---
 1 file changed, 30 insertions(+), 3 deletions(-)

diff --git a/drivers/tty/serdev/core.c b/drivers/tty/serdev/core.c
index df93b727e984..e5e84303faca 100644
--- a/drivers/tty/serdev/core.c
+++ b/drivers/tty/serdev/core.c
@@ -13,6 +13,7 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_device.h>
+#include <linux/pm_runtime.h>
 #include <linux/serdev.h>
 #include <linux/slab.h>
 
@@ -143,11 +144,28 @@ EXPORT_SYMBOL_GPL(serdev_device_remove);
 int serdev_device_open(struct serdev_device *serdev)
 {
 	struct serdev_controller *ctrl = serdev->ctrl;
+	int ret;
 
 	if (!ctrl || !ctrl->ops->open)
 		return -EINVAL;
 
-	return ctrl->ops->open(ctrl);
+	ret = ctrl->ops->open(ctrl);
+	if (ret)
+		return ret;
+
+	ret = pm_runtime_get_sync(&ctrl->dev);
+	if (ret < 0) {
+		pm_runtime_put_noidle(&ctrl->dev);
+		goto err_close;
+	}
+
+	return 0;
+
+err_close:
+	if (ctrl->ops->close)
+		ctrl->ops->close(ctrl);
+
+	return ret;
 }
 EXPORT_SYMBOL_GPL(serdev_device_open);
 
@@ -158,6 +176,8 @@ void serdev_device_close(struct serdev_device *serdev)
 	if (!ctrl || !ctrl->ops->close)
 		return;
 
+	pm_runtime_put(&ctrl->dev);
+
 	ctrl->ops->close(ctrl);
 }
 EXPORT_SYMBOL_GPL(serdev_device_close);
@@ -416,6 +436,9 @@ struct serdev_controller *serdev_controller_alloc(struct device *parent,
 
 	dev_set_name(&ctrl->dev, "serial%d", id);
 
+	pm_runtime_no_callbacks(&ctrl->dev);
+	pm_suspend_ignore_children(&ctrl->dev, true);
+
 	dev_dbg(&ctrl->dev, "allocated controller 0x%p id %d\n", ctrl, id);
 	return ctrl;
 
@@ -547,20 +570,23 @@ int serdev_controller_add(struct serdev_controller *ctrl)
 	if (ret)
 		return ret;
 
+	pm_runtime_enable(&ctrl->dev);
+
 	ret_of = of_serdev_register_devices(ctrl);
 	ret_acpi = acpi_serdev_register_devices(ctrl);
 	if (ret_of && ret_acpi) {
 		dev_dbg(&ctrl->dev, "no devices registered: of:%d acpi:%d\n",
 			ret_of, ret_acpi);
 		ret = -ENODEV;
-		goto out_dev_del;
+		goto err_rpm_disable;
 	}
 
 	dev_dbg(&ctrl->dev, "serdev%d registered: dev:%p\n",
 		ctrl->nr, &ctrl->dev);
 	return 0;
 
-out_dev_del:
+err_rpm_disable:
+	pm_runtime_disable(&ctrl->dev);
 	device_del(&ctrl->dev);
 	return ret;
 };
@@ -591,6 +617,7 @@ void serdev_controller_remove(struct serdev_controller *ctrl)
 
 	dummy = device_for_each_child(&ctrl->dev, NULL,
 				      serdev_remove_device);
+	pm_runtime_disable(&ctrl->dev);
 	device_del(&ctrl->dev);
 }
 EXPORT_SYMBOL_GPL(serdev_controller_remove);
-- 
2.17.0

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

* Re: [PATCH RESEND] serdev: add controller runtime PM support
  2018-05-30 10:50 [PATCH RESEND] serdev: add controller runtime PM support Johan Hovold
@ 2018-05-30 13:20 ` Rob Herring
  0 siblings, 0 replies; 2+ messages in thread
From: Rob Herring @ 2018-05-30 13:20 UTC (permalink / raw)
  To: Johan Hovold
  Cc: Greg Kroah-Hartman, Sebastian Reichel, Tony Lindgren,
	H. Nikolaus Schaller, Andreas Kemnade, Mark Rutland,
	Arnd Bergmann, Pavel Machek, linux-kernel,
	open list:SERIAL DRIVERS, linux-pm

On Wed, May 30, 2018 at 5:50 AM, Johan Hovold <johan@kernel.org> wrote:
> Add support for controller runtime power management to serdev core. This
> is needed to allow slave drivers to manage the runtime PM state of the
> underlying serial controller when its driver, in turn, implements more
> aggressive runtime power management (e.g. using autosuspend).
>
> For some applications, for example, where loss off initial data after a
> remote-wakeup event is acceptable or where rx is not used at all,
> aggressive serial controller runtime PM may be used without further
> involvement of the slave driver. But when this is not the case, the
> slave driver must be able to indicate when incoming data is expected in
> order to avoid data loss.
>
> To facilitate the common case, where the serial controller power state
> is active whenever the port is open (which is the case with just about
> every serial driver), and where data loss is not acceptable and cannot
> even be prevented by explicit controller runtime power management, an
> RPM reference is taken in serdev open and put again at close. This
> reference can later be balanced by any serdev driver which wants and/or
> can handle aggressive controller runtime PM.
>
> Note that the .ignore_children flag is set for the serdev controller to
> allow the underlying hardware to idle when no I/O is expected, regardless
> of the slave device RPM state.
>
> Acked-by: Tony Lindgren <tony@atomide.com>
> Reviewed-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
> Signed-off-by: Johan Hovold <johan@kernel.org>
> ---
>
> Hi Rob and Greg,
>
> This is a resend of the serdev controller runtime PM patch, which you
> haven't commented on yet (possibly due to the following extensive
> discussions on how to generalise the aggressive OMAP serial runtime PM
> implementation).
>
> This patch works with what we have today, regardless of how we end up
> configuring the serial controller (active) runtime PM behaviour
> (currently done through sysfs for OMAP), which is a separate issue.
>
> No changes in this resend, besides me adding Tony's and Sebastian's ack
> and reviewed-by tags and dropping the second patch which only served as
> an example of how to use this in a serdev driver.

Acked-by: Rob Herring <robh@kernel.org>

Rob

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

end of thread, other threads:[~2018-05-30 13:20 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-05-30 10:50 [PATCH RESEND] serdev: add controller runtime PM support Johan Hovold
2018-05-30 13:20 ` Rob Herring

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.