From patchwork Wed Nov 15 14:10:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 118964 Delivered-To: patch@linaro.org Received: by 10.140.22.164 with SMTP id 33csp4367854qgn; Wed, 15 Nov 2017 06:15:55 -0800 (PST) X-Google-Smtp-Source: AGs4zMYRXJWvi3lVbNlssiFq7r0IlOd0l/BX5rmPnR3ewS7F7f9u5a4/LtDkKM90aC8y4XY/he/E X-Received: by 10.159.229.10 with SMTP id s10mr13663799plq.386.1510755355553; Wed, 15 Nov 2017 06:15:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510755355; cv=none; d=google.com; s=arc-20160816; b=f34LDZILzDUO/sy2nqnRYZbXJBpmxfl/nld1ru/H1340kIdjzH0Zy/mxvrqMjvFUAL sMJmDv5UX+Ay+mXc3+yFY7SEWibZCx8Zz86dsFz2xBVa2pqncDMORnCjZSDplcnEWKEo Kfp8GEZQptV0eXcN9wGtcx6ml23wX1EZolMEYaklvsKk2iqbueLAtycPlxPYLoGofHSs LJJDL+nj+mLU7MRHaQJJ25d872Mcy1Fi22Q5snFpUOL9gbF7gZMSObOjps6YXBLy96ve HKDr276R7cm/SY8YZwJJ/szGJ8Yw+Yr25czsqr2q9JpKkvp5eX3xRGOAq11dzXjL4Fzo HJgQ== 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=FMKo6n9YKXZneGhZWsMg6YkvcXNL4K92A8Wvfqbr024=; b=DWg/OEBxLRACL0H9aYk47waqQB6sOQFnr3z9dk1qoCDI81Eytnq7/C36nsLQutGudV sOzhZVmvt4x1zpdnYpA9+FJtlWwHohLwd8pECy5z9WPmkZcBsZxZQxuyQaOMSFYv/US6 sau7vG/mdjchMrv0fwBRICETf2Q7pfVzgARaGQdOPT3FdfNEr7+TaIEmbF9dPq6bNKb2 PtzNLIBA5HtaGxHEUaoWbIhwlLmzLSWCNPwp5VRTX2aRHEMh2dl6G98aojj1Je4xCTEg Syi58AGvZ58v1tl8z+6w6Diz41ssxb3u0q7M3L/krjMO8nh5clFRsG7PHsw/wNjUDYiX s/Cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CxY7hq/3; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (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 42si6334793plb.653.2017.11.15.06.15.55; Wed, 15 Nov 2017 06:15:55 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=CxY7hq/3; spf=pass (google.com: best guess record for domain of linux-arm-msm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-arm-msm-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757973AbdKOOPx (ORCPT + 10 others); Wed, 15 Nov 2017 09:15:53 -0500 Received: from mail-wr0-f196.google.com ([209.85.128.196]:52687 "EHLO mail-wr0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932438AbdKOONr (ORCPT ); Wed, 15 Nov 2017 09:13:47 -0500 Received: by mail-wr0-f196.google.com with SMTP id o14so1672833wrf.9 for ; Wed, 15 Nov 2017 06:13:47 -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=Fpp9bd4NzhrFt49fV29VG9EqNkVvbhn6sFBTqylybMA=; b=CxY7hq/3XqxttWax2mU+2L9gXvBThCsqzfZLLaAbC3W9Lp6ao++iBLNReAgLtNzpzX 8CmqZnPqVV5tVvr6ZJ9RCcwxG0o2LIuzQC/y8Stl5QuVJAgpVwQ5xLTOGncJ7iQsElvn +mXsmpp8FoHdTUnEROoLlo38D6V+WMB3Ukme0= 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=Fpp9bd4NzhrFt49fV29VG9EqNkVvbhn6sFBTqylybMA=; b=d73PeG6K9k+LGBBiZ+PSYw2Q6pTd32wG5Uin77JbLCIwOUPMbqi8/NIO+BExID8BQk np1YQAJ9XAavoosx86+kM6spZGxt0LWK2x+UVTSZh+EjP0uBxC52Tn4zV6wDrj3RbbcK KoRulL43849lAPH/DosegGUv1mw7oKifaX6Rs8S9Ofa7VU8Y0H3QJD6Oz2HtjfOxP3C0 CQYId7xOYJ/qAS7vbgrs4EJisNg8aLNDLEOCJHTvxDon/NI9llruHVyXShtf71+RqMPp C6Dppm6AGJtQPYSd6AwxMYIthr4db1dY1SpOTFfOlCWE+cYz+V91Sdh1DwThYQn1eNty oIOw== X-Gm-Message-State: AJaThX4UP8LBQg1woK7UbXeORb+ERybRWI+ao0Tih7vSjCn/Q5HAelCU OwpZbOZp/mGOxeQe6L9TK1dsaQ== X-Received: by 10.223.186.202 with SMTP id w10mr10057830wrg.132.1510755224760; Wed, 15 Nov 2017 06:13:44 -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 m11sm56707wrf.56.2017.11.15.06.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 15 Nov 2017 06:13:44 -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 Subject: [PATCH v7 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Wed, 15 Nov 2017 14:10:42 +0000 Message-Id: <20171115141043.29202-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> References: <20171115141043.29202-1-srinivas.kandagatla@linaro.org> Sender: linux-arm-msm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-arm-msm@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 | 113 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 110 insertions(+), 3 deletions(-) -- 2.15.0 -- To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/drivers/slimbus/qcom-ctrl.c b/drivers/slimbus/qcom-ctrl.c index 25c1974f04ec..38340b104db4 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 @@ -295,6 +297,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) { @@ -540,6 +566,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; @@ -647,14 +674,93 @@ 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); + } + + /* + * If the clock pause failed due to active channels, there is + * a possibility that some audio stream is active during suspend. + * (e.g. modem usecase during suspend) + * We dont want to return suspend failure in that case so that + * display and relevant components can still go to suspend. + * If there is some other error, then it should prevent + * system level suspend + */ + if (ret == -EISCONN) + ret = 0; + + 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( @@ -676,6 +782,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);