From patchwork Thu Nov 30 17:41:59 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120265 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp90096qgn; Thu, 30 Nov 2017 09:46:19 -0800 (PST) X-Google-Smtp-Source: AGs4zMYEO+pWYWKSPpNvgQTWWOKTUqK8y3nKCFC4V84ZAqq/SZDxzZsnn6valZd7jqd+LsE65HvI X-Received: by 10.159.195.12 with SMTP id bd12mr3484864plb.14.1512063979371; Thu, 30 Nov 2017 09:46:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512063979; cv=none; d=google.com; s=arc-20160816; b=uP4rusHxu42G8GC6zye2LslTRC6kgvoOzYgJASy6zgabdYBYK/LmQnys0NKZQ1myhl KErSXk5Y7Eai5JvZmnl32WSO3p3s7jQZLbaGdHDvHW1U5QqMaI4Z2m6XiuOivdeQLOdM 5bMY5O090965RziOMtnnjFXmcJVQj6XXN12QB81TqQgvQj0M9eWEYnEfutbS+Sl89vlc 9rx+no7ZUFcIzUdE8RGMZBZbz63hXHoz/9P/h3961C30ySjiI/aCX+/dc/pwMib3zC/R 1W9/fa5zvQ2Rg4mSJr83yHlDceg+gvJO6gXT9cHRUUjN7lHyeTr/HOzSprTEHzONZAjt /MnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=GNTlKV8Yybe6cIveb9+Lcic0eSqsSZ/JUCX3caRrOFOgFFRxI2wmzjCqKAXdDuJA0m EFA2aaNPNtkwnXWjwllB2+KQ/MUdJFC+rrYRuVeInQDd3LuKcEwFVOOPGgZ4C+jqBuFx 6j5l17M6t0JT96Vk3j9Vw9uDgDMNMnGhBmQla5OGLokvgr6xUaYUDiJx4rlpp1jLoMwm FcT17XpfaR/WCoDynC+nAbkMZ9nhkhkn3mykq50xoFd/5y2BF7mjjm+3NBWeAxIc5bjv 6JhBi5HApvlQNK55SxM4iCKGmNS6f6ieX9xaxxKuH6goJCl74aU6hrPxIj1gxQ5g1ZZD R1Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQ+UuEJh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l8si3374193pga.538.2017.11.30.09.46.19; Thu, 30 Nov 2017 09:46:19 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GQ+UuEJh; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754002AbdK3RqQ (ORCPT + 28 others); Thu, 30 Nov 2017 12:46:16 -0500 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36144 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753978AbdK3RqI (ORCPT ); Thu, 30 Nov 2017 12:46:08 -0500 Received: by mail-wm0-f66.google.com with SMTP id b76so14015806wmg.1 for ; Thu, 30 Nov 2017 09:46:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=GQ+UuEJhPYn5PuD3oc8JqiENWvJrDS9t9+viDoc7jJKMMRBOi60gcX7zIK5nGwBGDM UqCY/jywJXx6r/4wtCQM/ym5qzTCxpTSUGNTGe/3A5K7gn/JJPycBL6g15efoiMZqqPM mSWkGbxXFpiCj/au+TvKqsIV1TvxVP7eUKr6k= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MQex56jFB/jBMT1c7EpZ12WTINTo1UOCdc2vpO79A18=; b=YOokZ880AaNYRM2gooPh9jQro5AKMWWttaL5C0ht8btSVWhaa/x/J4X/AJkEw8ZRwR XzJWpzzux/jisu2bkNeiWTnH5vVDjOx2Ai95acQnJGeeOeq4PC0eqRovbjxgztmqTMRI jChVObGYYJQZGpW2Gils8YNUwW2tpxkXLeP8a8++m/Rc4lRgwrFWLIET183OQv1q8Bd4 /pFXULrEb9FaXqiAEaebwvEITe/J3UnoPZe+wSe1lYWNXPoE+Qqs5Su5ykBrfz+d91L4 6Wueix4xcbYQ0cwPS/ZOzmROAJgWBlElChx6+ekWcUyaYfAiyEqQiwaZ+BtZt3MRFysg Rg1g== X-Gm-Message-State: AJaThX5vpc//QvTyzoW/2rPvclwpKnk4zKjIIoblN0RIA+D7moZXhj1c MLI1Xm9ZzSONNTMBBAswuIplXQ== X-Received: by 10.28.0.199 with SMTP id 190mr2411890wma.143.1512063967320; Thu, 30 Nov 2017 09:46:07 -0800 (PST) Received: from localhost.localdomain (cpc90716-aztw32-2-0-cust92.18-1.cable.virginm.net. [86.26.100.93]) by smtp.gmail.com with ESMTPSA id 189sm2412189wmu.3.2017.11.30.09.46.05 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 30 Nov 2017 09:46:06 -0800 (PST) From: srinivas.kandagatla@linaro.org To: gregkh@linuxfoundation.org, broonie@kernel.org, alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, bp@suse.de, poeschel@lemonage.de, treding@nvidia.com, andreas.noever@gmail.com, alan@linux.intel.com, mathieu.poirier@linaro.org, daniel@ffwll.ch, jkosina@suse.cz, sharon.dvir1@mail.huji.ac.il, joe@perches.com, davem@davemloft.net, james.hogan@imgtec.com, michael.opdenacker@free-electrons.com, robh+dt@kernel.org, pawel.moll@arm.com, mark.rutland@arm.com, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-msm@vger.kernel.org, vinod.koul@intel.com, arnd@arndb.de, srinivas.kandagatla@linaro.org Subject: [PATCH v8 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Thu, 30 Nov 2017 17:41:59 +0000 Message-Id: <20171130174200.6684-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> References: <20171130174200.6684-1-srinivas.kandagatla@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sagar Dharia Slimbus HW mandates that clock-pause sequence has to be executed before disabling relevant interface and core clocks. Runtime-PM's autosuspend feature is used here to enter/exit low power mode for Qualcomm's Slimbus controller. Autosuspend feature enables driver to avoid changing power-modes too frequently since entering clock-pause is an expensive sequence Signed-off-by: Sagar Dharia Signed-off-by: Srinivas Kandagatla --- drivers/slimbus/qcom-ctrl.c | 101 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 insertions(+), 3 deletions(-) -- 2.15.0 diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c index af7b109e3d28..8c05346cd69c 100644 --- a/drivers/slimbus/qcom-ctrl.c +++ b/drivers/slimbus/qcom-ctrl.c @@ -20,6 +20,7 @@ #include #include #include +#include #include "slimbus.h" /* Manager registers */ @@ -71,6 +72,7 @@ ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) #define SLIM_ROOT_FREQ 24576000 +#define QCOM_SLIM_AUTOSUSPEND 1000 /* MAX message size over control channel */ #define SLIM_MSGQ_BUF_LEN 40 @@ -281,6 +283,30 @@ static irqreturn_t qcom_slim_interrupt(int irq, void *d) return ret; } +static int qcom_clk_pause_wakeup(struct slim_controller *sctrl) +{ + struct qcom_slim_ctrl *ctrl = dev_get_drvdata(sctrl->dev); + + clk_prepare_enable(ctrl->hclk); + clk_prepare_enable(ctrl->rclk); + enable_irq(ctrl->irq); + + writel_relaxed(1, ctrl->base + FRM_WAKEUP); + /* Make sure framer wakeup write goes through before ISR fires */ + mb(); + /* + * HW Workaround: Currently, slave is reporting lost-sync messages + * after SLIMbus comes out of clock pause. + * Transaction with slave fail before slave reports that message + * Give some time for that report to come + * SLIMbus wakes up in clock gear 10 at 24.576MHz. With each superframe + * being 250 usecs, we wait for 5-10 superframes here to ensure + * we get the message + */ + usleep_range(1250, 2500); + return 0; +} + void *slim_alloc_txbuf(struct qcom_slim_ctrl *ctrl, struct slim_msg_txn *txn, struct completion *done) { @@ -517,6 +543,7 @@ static int qcom_slim_probe(struct platform_device *pdev) sctrl->set_laddr = qcom_set_laddr; sctrl->xfer_msg = qcom_xfer_msg; + sctrl->wakeup = qcom_clk_pause_wakeup; ctrl->tx.n = QCOM_TX_MSGS; ctrl->tx.sl_sz = SLIM_MSGQ_BUF_LEN; ctrl->rx.n = QCOM_RX_MSGS; @@ -624,14 +651,81 @@ static int qcom_slim_remove(struct platform_device *pdev) { struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); - disable_irq(ctrl->irq); - clk_disable_unprepare(ctrl->hclk); - clk_disable_unprepare(ctrl->rclk); + pm_runtime_disable(&pdev->dev); slim_unregister_controller(&ctrl->ctrl); destroy_workqueue(ctrl->rxwq); return 0; } +/* + * If PM_RUNTIME is not defined, these 2 functions become helper + * functions to be called from system suspend/resume. + */ +#ifdef CONFIG_PM +static int qcom_slim_runtime_suspend(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); + int ret; + + dev_dbg(device, "pm_runtime: suspending...\n"); + ret = slim_ctrl_clk_pause(&ctrl->ctrl, false, SLIM_CLK_UNSPECIFIED); + if (ret) { + dev_err(device, "clk pause not entered:%d", ret); + } else { + disable_irq(ctrl->irq); + clk_disable_unprepare(ctrl->hclk); + clk_disable_unprepare(ctrl->rclk); + } + return ret; +} + +static int qcom_slim_runtime_resume(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct qcom_slim_ctrl *ctrl = platform_get_drvdata(pdev); + int ret = 0; + + dev_dbg(device, "pm_runtime: resuming...\n"); + ret = slim_ctrl_clk_pause(&ctrl->ctrl, true, 0); + if (ret) + dev_err(device, "clk pause not exited:%d", ret); + return ret; +} +#endif + +#ifdef CONFIG_PM_SLEEP +static int qcom_slim_suspend(struct device *dev) +{ + int ret = 0; + + if (!pm_runtime_enabled(dev) || + (!pm_runtime_suspended(dev))) { + dev_dbg(dev, "system suspend"); + ret = qcom_slim_runtime_suspend(dev); + } + + return ret; +} + +static int qcom_slim_resume(struct device *dev) +{ + if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { + int ret; + + dev_dbg(dev, "system resume"); + ret = qcom_slim_runtime_resume(dev); + if (!ret) { + pm_runtime_mark_last_busy(dev); + pm_request_autosuspend(dev); + } + return ret; + + } + return 0; +} +#endif /* CONFIG_PM_SLEEP */ + static const struct dev_pm_ops qcom_slim_dev_pm_ops = { SET_SYSTEM_SLEEP_PM_OPS(qcom_slim_suspend, qcom_slim_resume) SET_RUNTIME_PM_OPS( @@ -653,6 +747,7 @@ static struct platform_driver qcom_slim_driver = { .driver = { .name = "qcom_slim_ctrl", .of_match_table = qcom_slim_dt_match, + .pm = &qcom_slim_dev_pm_ops, }, }; module_platform_driver(qcom_slim_driver);