From patchwork Wed May 30 10:50:59 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johan Hovold X-Patchwork-Id: 10438403 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id DBC29602CC for ; Wed, 30 May 2018 10:52:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD699285CE for ; Wed, 30 May 2018 10:52:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C1F7728928; Wed, 30 May 2018 10:52:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06E04285CE for ; Wed, 30 May 2018 10:52:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751591AbeE3Kwr (ORCPT ); Wed, 30 May 2018 06:52:47 -0400 Received: from mail-lf0-f68.google.com ([209.85.215.68]:39546 "EHLO mail-lf0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751813AbeE3Kwq (ORCPT ); Wed, 30 May 2018 06:52:46 -0400 Received: by mail-lf0-f68.google.com with SMTP id t134-v6so3564743lff.6; Wed, 30 May 2018 03:52:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id; bh=WCYpqXdCMlyrBjjRUn3zFbemLyMLvKv3fukMrZ6+hOw=; b=tbSI9GJrO6mOscnJ6UmiEqKoBIQJs1mlFlW6lLuqhfyf4PXOiiYIhNsO/qbnEPG7B+ aB9tYfgXk5YqU+TEBedJ8aQ0kSbl5lVAjoHzr2MPSVUIYRg555VkS+o4N866O+T+h01k wmuLhrBTIWUsLfTr09CEWOX2baC2F+Eodp0IXeyq8x0ppxhslYCA3hrM9bVDiLEMvgY/ eIfWLa0lB8d0hadJo1Hny3zhX7oHDi+BCYuja+8K+xmWutBdAiu8cretCAr/f8QBNMtx eEwQe7maLLwVKUN8hiShvdyJ/WEhOKRn+/luEGL9RJGznugR12q0z3G1pOv6Xdvbkkew dwFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id; bh=WCYpqXdCMlyrBjjRUn3zFbemLyMLvKv3fukMrZ6+hOw=; b=l+qx7rRh3xXMAUOJ/z/Tog+z8xGSv6k/mPHRlLekoQCVja8RYg+6oyuNc/uf0ye8hC CldZB5t3MRcU308svBLxEriEHi4H4Md0ZtOYbk0TMhrHJuSdPUQmECQkIGVMCmfp0y0t BrXAUqVjPhPtFk0ofPzm8Amk5sM0u9zvpi+8CuoRaq7EO9BEeNtg9VVtNRD6IW9INFL4 tagoIBoXM3MKhPUa0XQFZlX4wwK1QdlEC8f3+SxgM9nBDr5AH/YJE/8agI3Ay9vWeApz xZlps/Mt5PfCgzLWI/BHd1CRtGEjxp/H3HvX3kr3S2oOvZNI25Pc/ktX03xnaq/KyLQ8 sPOw== X-Gm-Message-State: ALKqPwdS/5+BrMVPnPf1O+Py+6FOgwuvBvIBHjBS0vfNUpX87DFx/wkh LJyemGdZWoc1MaMdRM6KsyE= X-Google-Smtp-Source: ADUXVKJBjB69rSnsGQuo1hng0ts3Dt57K/ao6Tbkwnu5J3Kguvl0Oz0QN5fDQTG7B60Vf80qPzBqWg== X-Received: by 2002:a19:9855:: with SMTP id a82-v6mr1352506lfe.87.1527677564346; Wed, 30 May 2018 03:52:44 -0700 (PDT) Received: from xi.terra (c-8bb2e655.07-184-6d6c6d4.bbcust.telenor.se. [85.230.178.139]) by smtp.gmail.com with ESMTPSA id w2-v6sm7062719ljw.70.2018.05.30.03.52.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 30 May 2018 03:52:43 -0700 (PDT) Received: from johan by xi.terra with local (Exim 4.90_1) (envelope-from ) id 1fNyig-0005aa-NN; Wed, 30 May 2018 12:52:42 +0200 From: Johan Hovold To: Greg Kroah-Hartman , Rob Herring Cc: Sebastian Reichel , Tony Lindgren , "H. Nikolaus Schaller" , Andreas Kemnade , Mark Rutland , Arnd Bergmann , Pavel Machek , linux-kernel@vger.kernel.org, linux-serial@vger.kernel.org, linux-pm@vger.kernel.org, Johan Hovold Subject: [PATCH RESEND] serdev: add controller runtime PM support Date: Wed, 30 May 2018 12:50:59 +0200 Message-Id: <20180530105059.21409-1-johan@kernel.org> X-Mailer: git-send-email 2.17.0 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Sebastian Reichel Signed-off-by: Johan Hovold Acked-by: Rob Herring --- 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 #include #include +#include #include #include @@ -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);