From patchwork Thu Dec 7 10:27:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 120950 Delivered-To: patch@linaro.org Received: by 10.140.22.227 with SMTP id 90csp8178691qgn; Thu, 7 Dec 2017 02:30:57 -0800 (PST) X-Google-Smtp-Source: AGs4zMbY6nXVVF3WSZ6IBTuacbqf21p06k3QIgC0mYJvNWOsbvgRq4eAXTybPGVNwG8Ntn17unBf X-Received: by 10.99.176.69 with SMTP id z5mr25439279pgo.131.1512642657365; Thu, 07 Dec 2017 02:30:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1512642657; cv=none; d=google.com; s=arc-20160816; b=TYzmj4BKOt2hcsxyEscELDdkoq+TmJy1pMzcKdNiRoAzGszyHg3Lj3K8lPnSeByb1J P6h/D/J6l3YRrvwmFW/Kyd/Hkuc6UvRYg8+t4z5BBYVVJbAbra3c2hEwVOF7YIbOv6fb yCWgPmGGwlo4L5HmzNnngP5tsfqd7yBXVZN5VuayzMYS98JdjNeF+mcCh1icmO41eLNC qJtiV22mGxnFfLpPism7RNvLYuboCbhqWN5pCahGo3e3vw9NL/MED1TzyeCwcrlNAYbQ V15SvSHV7fiksieXgBJ1PvHzKx9N5U+fxxXNjKWOql94s4BwiV6JWGeOyP1rFvW46yg1 P3cg== 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=BETBiwNrOnk/fXJANlW0LmTOgyJ9SbAq3cchUMT8JtQ=; b=ae6BIYoAUSpPWlWy/KDYrBcjzh9HlipGwV6d9nXJOMsClbE8NvzKi0VytEzePN+HPO OmKfRLtlPAybC6f62ivPuwx/lEA3b2WhQXbfRCtSKo3Dv38DPACTPno3SGRbh8VUi9YU oDm9Rj6/pYSSEbaF/2h0VLrMx/oN+CBK7a72kS03X4PQc0Nj9X8aps3jv8iBxOto5J8n DVcS4sQAn5rDRnGPVKl+lzfozOv1gDREbHBNOTUkAmzRH4NuBn2WX3fUQFCHlOHTi0ig hjGT1TOLh1N6WWEWesJriP+U9lP/1cok4X37cUWv2IInR3Pbe/VeRw0DFjsqWiNe2ZRW OWCQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=LjSy9n2h; 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 q1si3547248plb.29.2017.12.07.02.30.57; Thu, 07 Dec 2017 02:30:57 -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=LjSy9n2h; 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 S1752641AbdLGKaz (ORCPT + 10 others); Thu, 7 Dec 2017 05:30:55 -0500 Received: from mail-wr0-f193.google.com ([209.85.128.193]:36531 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752880AbdLGKat (ORCPT ); Thu, 7 Dec 2017 05:30:49 -0500 Received: by mail-wr0-f193.google.com with SMTP id v105so6925788wrc.3 for ; Thu, 07 Dec 2017 02:30:48 -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=mcGCY1IGw6hkYqp6Bo7Ty2bBqtfvNw7BV0esJxIG4P8=; b=LjSy9n2hGkJkiAVTzdZvF0a8K4rPBHEh+5xjHnxYP2GYR++RGCC9yy3nC2Zx1Krtlf MqFkJxzKHEI6z0YwNGKQFmHsYyjRSsqiCLt0RyUB+4Vi1ftPUNMf6vnD3CC1HWXr/OW/ ijApRevG9qIadvCJrtwzyo2KjWsBCdQdH42yQ= 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=mcGCY1IGw6hkYqp6Bo7Ty2bBqtfvNw7BV0esJxIG4P8=; b=AuTvFPIchClF5iuyzqu0Wy/QJFCNaRVY8b6ggtIyDXixpQLzP6TdFofCWReQ7FI0F9 RWbaF5Cq83REhW8e5fOYX+BSC9BByaf6n00LHV85Nin0FUb3pXuas6ilUAM0M/+RFnao Zz2abjoOgmMww9AekaUbNA8Yhc0L4WEx+iCcrLnZWMi8yY3QTvjN06gmKUNjtsajxXX0 MAC+v1YrBHT/aUr0/lKJTXQSLjSTyRUjZFpFpuUtOVW9Obaz3l/rx0TBTfek8tOFvCNy vhQxP/vi39NUEmPPn0C676j4JwUWmIG5BqvACwK9mRypx2WGptYW8SkzLaLpd+tkC8dE O4xQ== X-Gm-Message-State: AJaThX5/EPBqyQqxyBvcRYTFdwCZVzlp11K2EaOTYwZhmRN48Y0OEb8w F5CcPAsNNoH8gAvVjyCkT9acDg== X-Received: by 10.223.170.150 with SMTP id h22mr22497525wrc.26.1512642648283; Thu, 07 Dec 2017 02:30:48 -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 k2sm4837734wrg.4.2017.12.07.02.30.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 07 Dec 2017 02:30:47 -0800 (PST) From: srinivas.kandagatla@linaro.org To: Mark Brown , Greg Kroah-Hartman , alsa-devel@alsa-project.org Cc: sdharia@codeaurora.org, Rob Herring , Mark Rutland , Jonathan Corbet , pombredanne@nexb.com, j.neuschaefer@gmx.net, linux-arm-msm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Srinivas Kandagatla Subject: [PATCH v9 12/13] slimbus: qcom: Add runtime-pm support using clock-pause Date: Thu, 7 Dec 2017 10:27:19 +0000 Message-Id: <20171207102720.21071-13-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171207102720.21071-1-srinivas.kandagatla@linaro.org> References: <20171207102720.21071-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 | 101 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 98 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 36e828b703b4..2c9a275d8d9e 100644 --- a/drivers/slimbus/qcom-ctrl.c +++ b/drivers/slimbus/qcom-ctrl.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "slimbus.h" /* Manager registers */ @@ -63,6 +64,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 @@ -273,6 +275,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) { @@ -509,6 +535,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; @@ -616,14 +643,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( @@ -645,6 +739,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);