From patchwork Tue Apr 24 06:07:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10358687 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 39070601BE for ; Tue, 24 Apr 2018 06:10:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 279E928CF9 for ; Tue, 24 Apr 2018 06:10:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1B4B128CF0; Tue, 24 Apr 2018 06:10:13 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 5ACBA28B8C for ; Tue, 24 Apr 2018 06:10:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=5tparUCRXFLHwu7MIy1+m2DCw8Sh6xTT9vfhKHlfQuE=; b=CZfUznoDGXwd3j9VFXKN0q0R4P TG4IDdQWWiXPhFxfaZQpghFyEz7HmiaxxbXnbBF9+BcowemElx3sHGye0PDPMORPX6uP85/KlROj3 kNLDd4o0LiYl2CO1Z9jjOB+EEULpFT0ldd9sWgryv2EfyFv05nNkd1q/RQGxve+ykCtYG4DaqJZo1 i9V+b+Y59Qsq5n1JkQKGt7PxBflJl8wMYnx3FBsLg6vT9Ed8FKxYJFD1d1629UbOz0YLJFXvIYLvF xk/WeDuEkVyysynMMg3/RAv0JUkZvbJ9TIarqkehVffsUzIVSMIAiVkxoqhBPS1n6IfS3YSPADIvD hPo0Pd6A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAr9N-0004kN-A7; Tue, 24 Apr 2018 06:10:01 +0000 Received: from mail-pf0-x242.google.com ([2607:f8b0:400e:c00::242]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fAr85-000443-Un for linux-arm-kernel@lists.infradead.org; Tue, 24 Apr 2018 06:08:43 +0000 Received: by mail-pf0-x242.google.com with SMTP id h69so11352742pfe.13 for ; Mon, 23 Apr 2018 23:08:31 -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 :in-reply-to:references; bh=QPYUFVe/J7/9TPuQp6Me7vBNCuwLOG0dwd89n7auLzM=; b=hlVN8hmhARxxEXYV9X52+bpt5JD+S0SqjUig86+v1B7xaK6uhKuaHtm4FgT9Tgayl4 fO+Dcx5bJiqFhTDQKF4lyZ4a+22CuBaMbphWa4WxosuzU2j/3FUUclVkCV9IWAPXNp4s Je185/lm/euPOi4cLc48MnGWsjOeLMq0P/dtI= 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:in-reply-to:references; bh=QPYUFVe/J7/9TPuQp6Me7vBNCuwLOG0dwd89n7auLzM=; b=csNDWS0Xza5XYZNWbDfE6KadfkzljCL96NOXvF/YGDl7V0trsDWBxFgVdDN5Dzc4z6 KBsYvv+CZTuLniRG0RPGjw3Q70cIDgU1zFNSxZEeZx832wGvxqGHZNyVpx/x7J8xoku0 ocg7v/9+TNRfkMs9cMfn9e9IM+3usNnQoSpFdEgOcin/3E3SPs+qKL9UTIXjMF50N7Zy psMPVtFGhOiXZ9tWfoHgPpujRa8WR02QN6SsT1aH5maSDYtyYODBGwU+FJtVPWGijntB is7pKfNrfc7QkyI7qJ8oefSbwaWnANA3JJO//QmqOZKnG2kEbwWHICXKQtyzom9+PFmp ZrgQ== X-Gm-Message-State: ALQs6tDZrvPdoQNxfMgu9kvItJXQSGkgoPhg1mjGevMwqRcci2OkF+ak wHDHOcc44xH+ykS/RUfb20bxwQ== X-Google-Smtp-Source: AIpwx49r7ln0+KzuNL4pog4owowE0adbl6tFy7xa+AMKVIcmEaiEO0jMjV4gvkOgISJ7CMoZOllT2g== X-Received: by 2002:a17:902:aa46:: with SMTP id c6-v6mr23027708plr.154.1524550110977; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id r81sm28706474pfj.79.2018.04.23.23.08.29 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 23:08:30 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Miquel Raynal , Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth Subject: [PATCH V2 3/3] cpufreq: add suspend/resume support in Armada 37xx DVFS driver Date: Tue, 24 Apr 2018 11:37:36 +0530 Message-Id: <4ca19364ff10083c3912ce428207c3f713f973b9.1524549644.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180423_230842_043288_292A2D28 X-CRM114-Status: GOOD ( 18.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Viresh Kumar , Vincent Guittot , linux-arm-kernel@lists.infradead.org, linux-pm@vger.kernel.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miquel Raynal Add suspend/resume hooks in Armada 37xx DVFS driver to handle S2RAM operations. As there is currently no 'driver' structure, create one to store both the regmap and the register values during suspend operation. A syscore_ops is used to export the suspend/resume hooks. Signed-off-by: Miquel Raynal Signed-off-by: Viresh Kumar --- V1->V2: - Updated patch based on cpufreq-dt suspend/resume hooks. drivers/cpufreq/armada-37xx-cpufreq.c | 67 +++++++++++++++++++++++++++++++++-- 1 file changed, 65 insertions(+), 2 deletions(-) diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c index 9dafb3bbc334..c827d2437246 100644 --- a/drivers/cpufreq/armada-37xx-cpufreq.c +++ b/drivers/cpufreq/armada-37xx-cpufreq.c @@ -23,6 +23,8 @@ #include #include +#include "cpufreq-dt.h" + /* Power management in North Bridge register set */ #define ARMADA_37XX_NB_L0L1 0x18 #define ARMADA_37XX_NB_L2L3 0x1C @@ -56,6 +58,16 @@ */ #define LOAD_LEVEL_NR 4 +struct armada37xx_cpufreq_state { + struct regmap *regmap; + u32 nb_l0l1; + u32 nb_l2l3; + u32 nb_dyn_mod; + u32 nb_cpu_load; +}; + +static struct armada37xx_cpufreq_state *armada37xx_cpufreq_state; + struct armada_37xx_dvfs { u32 cpu_freq_max; u8 divider[LOAD_LEVEL_NR]; @@ -136,7 +148,7 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base, clk_set_parent(clk, parent); } -static void __init armada37xx_cpufreq_disable_dvfs(struct regmap *base) +static void armada37xx_cpufreq_disable_dvfs(struct regmap *base) { unsigned int reg = ARMADA_37XX_NB_DYN_MOD, mask = ARMADA_37XX_NB_DFS_EN; @@ -162,8 +174,44 @@ static void __init armada37xx_cpufreq_enable_dvfs(struct regmap *base) regmap_update_bits(base, reg, mask, mask); } +static int armada37xx_cpufreq_suspend(struct cpufreq_policy *policy) +{ + struct armada37xx_cpufreq_state *state = armada37xx_cpufreq_state; + + regmap_read(state->regmap, ARMADA_37XX_NB_L0L1, &state->nb_l0l1); + regmap_read(state->regmap, ARMADA_37XX_NB_L2L3, &state->nb_l2l3); + regmap_read(state->regmap, ARMADA_37XX_NB_CPU_LOAD, + &state->nb_cpu_load); + regmap_read(state->regmap, ARMADA_37XX_NB_DYN_MOD, &state->nb_dyn_mod); + + return 0; +} + +static int armada37xx_cpufreq_resume(struct cpufreq_policy *policy) +{ + struct armada37xx_cpufreq_state *state = armada37xx_cpufreq_state; + + /* Ensure DVFS is disabled otherwise the following registers are RO */ + armada37xx_cpufreq_disable_dvfs(state->regmap); + + regmap_write(state->regmap, ARMADA_37XX_NB_L0L1, state->nb_l0l1); + regmap_write(state->regmap, ARMADA_37XX_NB_L2L3, state->nb_l2l3); + regmap_write(state->regmap, ARMADA_37XX_NB_CPU_LOAD, + state->nb_cpu_load); + + /* + * NB_DYN_MOD register is the one that actually enable back DVFS if it + * was enabled before the suspend operation. This must be done last + * otherwise other registers are not writable. + */ + regmap_write(state->regmap, ARMADA_37XX_NB_DYN_MOD, state->nb_dyn_mod); + + return 0; +} + static int __init armada37xx_cpufreq_driver_init(void) { + struct cpufreq_dt_platform_data pdata; struct armada_37xx_dvfs *dvfs; struct platform_device *pdev; unsigned long freq; @@ -213,6 +261,15 @@ static int __init armada37xx_cpufreq_driver_init(void) goto put_clk; } + armada37xx_cpufreq_state = kmalloc(sizeof(*armada37xx_cpufreq_state), + GFP_KERNEL); + if (!armada37xx_cpufreq_state) { + ret = -ENOMEM; + goto put_clk; + } + + armada37xx_cpufreq_state->regmap = nb_pm_base; + armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider); clk_put(clk); @@ -228,7 +285,11 @@ static int __init armada37xx_cpufreq_driver_init(void) /* Now that everything is setup, enable the DVFS at hardware level */ armada37xx_cpufreq_enable_dvfs(nb_pm_base); - pdev = platform_device_register_simple("cpufreq-dt", -1, NULL, 0); + pdata.suspend = armada37xx_cpufreq_suspend; + pdata.resume = armada37xx_cpufreq_resume; + + pdev = platform_device_register_data(NULL, "cpufreq-dt", -1, &pdata, + sizeof(pdata)); ret = PTR_ERR_OR_ZERO(pdev); if (ret) goto disable_dvfs; @@ -243,6 +304,8 @@ static int __init armada37xx_cpufreq_driver_init(void) freq = cur_frequency / dvfs->divider[load_lvl]; dev_pm_opp_remove(cpu_dev, freq); } + + kfree(armada37xx_cpufreq_state); put_clk: clk_put(clk); return ret;