From patchwork Fri Oct 6 15:51:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Srinivas Kandagatla X-Patchwork-Id: 115077 Delivered-To: patch@linaro.org Received: by 10.80.163.170 with SMTP id s39csp1519673edb; Fri, 6 Oct 2017 08:52:09 -0700 (PDT) X-Received: by 10.84.210.165 with SMTP id a34mr297812pli.298.1507305129115; Fri, 06 Oct 2017 08:52:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507305129; cv=none; d=google.com; s=arc-20160816; b=t0al7FkipBBLJ67Fgx86pWbhoq+5KRbmRFz8WtcuIUPxJkqDaw9zN4wdCgmEcRhYfj kzCD3WFix8euS+MFHzgHXazdw8iK6gdeKKqoybr9KtkmX0+BTwXfhE1jdxDP/1JQjtur MAs4Ptzroj9Kgzhl7zCso7JJoaa9X1MQYvYE8ECGuXXBuE7/86qQuEQqCUoTc4Fo3mph w8WGNo/ikz5SVdsGodPHWNGQnjKLKufeFVn0S2iNKTAIzSBRt/H79n/UXlp/dusN4gBE 6b31Qcf2CKAuwveZp4JdU4xpov0uhUh990vU9kJUfX7GFnV3PtzxWYlBXAgfrpreE5/k sZAw== 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=1t9KeSG1JYPEQDvI11M+q/AFCKVRw1axLwBKp1thtaA=; b=weY9L93pp9DAbM6hKtp43UUp+nsiNxPvurUPUsc1qaxGsIKno2OLcHNydDFujAyQxH 0VFEGEsvx6KhYt7Wer8+H6mhqYYXwObz3QohmiRidaI5se8U9TDctT2qks1c0sZG0pix QHmNa1mlQHHI2h/bIcG6ezb6Q8C9eqt5sqD5qpXpX8k+eEhuzL/aq5kVRcmN8BTSBGM6 8OFoOPGYFeCUvoctS72Wi/rQ3sOoTEp9WwIwTaqEfl6Uo2rBtp75fYX18xAB3B+2Hx0b Uv2Ckf3m//1qqJmJOAhjhIEF6E8A7Eexn3OLSuZ/axN/dJQdJJCeSTVNGZNo/yQ5LE3m hA/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=Fm1DVGcY; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 i186si1462881pfg.401.2017.10.06.08.52.08; Fri, 06 Oct 2017 08:52:09 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of devicetree-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=Fm1DVGcY; spf=pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=devicetree-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 S1752629AbdJFPwG (ORCPT + 6 others); Fri, 6 Oct 2017 11:52:06 -0400 Received: from mail-wr0-f181.google.com ([209.85.128.181]:45170 "EHLO mail-wr0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752878AbdJFPwA (ORCPT ); Fri, 6 Oct 2017 11:52:00 -0400 Received: by mail-wr0-f181.google.com with SMTP id k7so2330187wre.2 for ; Fri, 06 Oct 2017 08:52:00 -0700 (PDT) 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=CtoHELCpuxSzEDoabBLrSTtJtOeKz8uCXeFp/N7vi3w=; b=Fm1DVGcYYa8/YDA0BK/edAorjRpnYquBsWFbdMK1iKMMX0bO4h/8iTt5RdUzvQ/ifd Gm6uFkR0qfOMAz5zAdky5N37YlmcQGvK/FVl2YjBcw3sc5ZP60E+RVEV/uxBLL3iS7Z2 0nj4B960VIP/mZuAMMIsdGAOrFWDQ/tUphyaw= 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=CtoHELCpuxSzEDoabBLrSTtJtOeKz8uCXeFp/N7vi3w=; b=h7j7zu6AzHdbQxJhYiCXvPSaYcNN0nzo5Ys+IBjuajzgbCj/B4xOXyvv8s2GQlawp3 OiGmbTdKsHIgXZSC+GQOgJSyEwsksIzP5sF7RK4atEoUPg4i9YLaUZmRJF1vN9KNwDnV qw5TwZ+tvrEoZJGW/kzTjKvO1M+jpbgQSb32jH7R6blb6qmSnBR989EBcxfRwPLsAq23 66sjs0+Vx3yLJdtbVawjwzNKEPO2ofwrCP4m6pbJ/8kJYEmOOwgbUs92HmiHEuM5BWcw wzPU8VAAnJuxUws/GSiqelKcq77qlgUqGusLAIJ1f0nGFeV7/W0wPnYXCsaNav6WwPoY Jb5g== X-Gm-Message-State: AMCzsaWhhy7GERMfATLf8sqdaFU3w3eS+498huc6BI07ImNrfJI4LPMA UqOg83gPBPkPM12Xy0Cp6XW1mQ== X-Google-Smtp-Source: AOwi7QCfp6yAR4TrJWh5SChztkQntLVx1l7QZwEysI9/3pBm4UCIwnte5ehkazeF6WcHUuyPJHHnOQ== X-Received: by 10.223.134.212 with SMTP id 20mr2327382wry.81.1507305119520; Fri, 06 Oct 2017 08:51:59 -0700 (PDT) Received: from localhost.localdomain (static.8.26.4.46.clients.your-server.de. [46.4.26.8]) by smtp.gmail.com with ESMTPSA id r21sm1510327wmd.26.2017.10.06.08.51.58 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 06 Oct 2017 08:51:59 -0700 (PDT) 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, gong.chen@linux.intel.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, kheitke@audience.com, linux-arm-msm@vger.kernel.org, arnd@arndb.de, Srinivas Kandagatla Subject: [Patch v6 5/7] slimbus: qcom: Add runtime-pm support using clock-pause feature Date: Fri, 6 Oct 2017 17:51:34 +0200 Message-Id: <20171006155136.4682-6-srinivas.kandagatla@linaro.org> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171006155136.4682-1-srinivas.kandagatla@linaro.org> References: <20171006155136.4682-1-srinivas.kandagatla@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@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/slim-qcom-ctrl.c | 128 +++++++++++++++++++++++++++++++++++++-- drivers/slimbus/slim-qcom.h | 1 + 2 files changed, 125 insertions(+), 4 deletions(-) -- 2.9.3 -- To unsubscribe from this list: send the line "unsubscribe devicetree" 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/slim-qcom-ctrl.c b/drivers/slimbus/slim-qcom-ctrl.c index d0574e1..05ba44f 100644 --- a/drivers/slimbus/slim-qcom-ctrl.c +++ b/drivers/slimbus/slim-qcom-ctrl.c @@ -21,6 +21,7 @@ #include #include #include +#include #include "slim-qcom.h" #define MSM_SLIM_NAME "msm_slim_ctrl" @@ -217,6 +218,30 @@ static irqreturn_t msm_slim_interrupt(int irq, void *d) return ret; } +static int msm_clk_pause_wakeup(struct slim_controller *ctrl) +{ + struct msm_slim_ctrl *dev = slim_get_ctrldata(ctrl); + + clk_prepare_enable(dev->hclk); + clk_prepare_enable(dev->rclk); + enable_irq(dev->irq); + + writel_relaxed(1, dev->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; +} + static int msm_xfer_msg(struct slim_controller *ctrl, struct slim_msg_txn *txn, void *pbuf) { @@ -286,7 +311,6 @@ static int msm_set_laddr(struct slim_controller *ctrl, */ msg.wbuf = buf; msg.num_bytes = 7; - ret = slim_processtxn(&dev->ctrl, &txn); if (ret) @@ -417,6 +441,8 @@ static int msm_slim_probe(struct platform_device *pdev) dev->ctrl.set_laddr = msm_set_laddr; dev->ctrl.xfer_msg = msm_xfer_msg; + dev->ctrl.wakeup = msm_clk_pause_wakeup; + dev->ctrl.tx.n = MSM_TX_MSGS; dev->ctrl.rx.n = MSM_RX_MSGS; dev->ctrl.tx.sl_sz = SLIM_MSGQ_BUF_LEN; @@ -532,6 +558,12 @@ static int msm_slim_probe(struct platform_device *pdev) */ mb(); + pm_runtime_use_autosuspend(&pdev->dev); + pm_runtime_set_autosuspend_delay(&pdev->dev, MSM_SLIM_AUTOSUSPEND); + pm_runtime_set_active(&pdev->dev); + pm_runtime_mark_last_busy(&pdev->dev); + pm_runtime_enable(&pdev->dev); + dev_dbg(dev->dev, "MSM SB controller is up:ver:0x%x!\n", dev->ver); return 0; @@ -562,14 +594,101 @@ static int msm_slim_remove(struct platform_device *pdev) dma_free_coherent(&pdev->dev, (ctrl->tx.sl_sz * ctrl->tx.n), ctrl->tx.base, ctrl->tx.phy); - disable_irq(dev->irq); - clk_disable_unprepare(dev->rclk); - clk_disable_unprepare(dev->hclk); + pm_runtime_disable(&pdev->dev); slim_del_controller(&dev->ctrl); destroy_workqueue(dev->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 msm_slim_runtime_suspend(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); + int ret; + + dev_dbg(device, "pm_runtime: suspending...\n"); + ret = slim_ctrl_clk_pause(&dev->ctrl, false, SLIM_CLK_UNSPECIFIED); + if (ret) { + dev_err(device, "clk pause not entered:%d", ret); + } else { + disable_irq(dev->irq); + clk_disable_unprepare(dev->hclk); + clk_disable_unprepare(dev->rclk); + } + return ret; +} + +static int msm_slim_runtime_resume(struct device *device) +{ + struct platform_device *pdev = to_platform_device(device); + struct msm_slim_ctrl *dev = platform_get_drvdata(pdev); + int ret = 0; + + dev_dbg(device, "pm_runtime: resuming...\n"); + ret = slim_ctrl_clk_pause(&dev->ctrl, true, 0); + if (ret) + dev_err(device, "clk pause not exited:%d", ret); + return ret; +} +#endif + +#ifdef CONFIG_PM_SLEEP +static int msm_slim_suspend(struct device *dev) +{ + int ret = 0; + + if (!pm_runtime_enabled(dev) || + (!pm_runtime_suspended(dev))) { + dev_dbg(dev, "system suspend"); + ret = msm_slim_runtime_suspend(dev); + } + if (ret == -EISCONN) { + /** + * 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 + */ + ret = 0; + } + return ret; +} + +static int msm_slim_resume(struct device *dev) +{ + if (!pm_runtime_enabled(dev) || !pm_runtime_suspended(dev)) { + int ret; + + dev_dbg(dev, "system resume"); + ret = msm_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 msm_slim_dev_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(msm_slim_suspend, msm_slim_resume) + SET_RUNTIME_PM_OPS( + msm_slim_runtime_suspend, + msm_slim_runtime_resume, + NULL + ) +}; + static const struct of_device_id msm_slim_dt_match[] = { { .compatible = "qcom,slim", @@ -584,6 +703,7 @@ static struct platform_driver msm_slim_driver = { .name = MSM_SLIM_NAME, .owner = THIS_MODULE, .of_match_table = msm_slim_dt_match, + .pm = &msm_slim_dev_pm_ops, }, }; module_platform_driver(msm_slim_driver); diff --git a/drivers/slimbus/slim-qcom.h b/drivers/slimbus/slim-qcom.h index 0ad59c3..8b1d649 100644 --- a/drivers/slimbus/slim-qcom.h +++ b/drivers/slimbus/slim-qcom.h @@ -23,6 +23,7 @@ ((l) | ((mt) << 5) | ((mc) << 8) | ((dt) << 15) | ((ad) << 16)) #define SLIM_ROOT_FREQ 24576000 +#define MSM_SLIM_AUTOSUSPEND 1000 /* MAX message size over control channel */ #define SLIM_MSGQ_BUF_LEN 40