From patchwork Tue Apr 24 06:07:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 134052 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1845159lji; Mon, 23 Apr 2018 23:08:27 -0700 (PDT) X-Google-Smtp-Source: AIpwx48h+/K5Dix74oiQbN57dx/UkeG1htiV0VIupDSpkNjtYEhOrzNOVC4ItOJXI1yVfD04RIZw X-Received: by 10.101.74.9 with SMTP id s9mr19054070pgq.91.1524550107227; Mon, 23 Apr 2018 23:08:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524550107; cv=none; d=google.com; s=arc-20160816; b=Ta/D7/NHtFVby7fZ1aa/pPrOuA0K+LjwfGd8ivYIKW1Zk+YYzZTqoGw20A0lhaTqjm jtRwKyLYvDsRAKpuPS3+WCA8IFtUSgYR5NmVlLXaeL5Mne65dws+RmLdHUUyw+ksnXjF Joxi8j+qfNecI7xM/AJg1u7Uf3kA9PDmqkpGjEGFU6C4zyj+kLFYPYBPBdWafUcFiAbY m6FpPmQSTzKb76aOqAvSQRBm7N0bIfOapWCtPGuYP4dvOoDTNgca2mJvlqcLi4GgmP7h UE7Iqm7QNQH/u/pZFeF6yvNCe6m5B77QXrpgnpmEOvPEHL8GLYbsNgZGGv1wPETSvJIY 4qkg== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=WJUC6XeR6FAzawrBGixqPEcqYbV4w00vw6FiMaOqXnw=; b=Kt5+xoUnRX4O2DvFiQ9p2q7uGbiqIGMMS7w0jrzapAWLzm1mXNOGubuFFEUlg3RX1w KO7meMRGNOw5ak2tnEWzZ5YGIv0/79ZPZMz3TRLMUoeblKMOxErHEQ6VAtNf/1HwmePz QcCdPTUk1aDN/44t3wTaW5gv/NzJgToZaPyOyaGejuCEkGNuVR3gU1rixexcrHxijPHg +eItlxXw3SWjA5f3RVZjM2oaTrXCAbcaQXzyD27KIEHllheOm7C0l1kn5qq/zU3YtZs0 YlOqUMnA/Sk3eIa747T35WwRmbslShM1UT1mtDZgByjm2kmQp9DwB/oioSrWXGTnvx/C +a7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=RTsWvb2g; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 y5si12475283pfe.184.2018.04.23.23.08.27; Mon, 23 Apr 2018 23:08:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=RTsWvb2g; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1756213AbeDXGI0 (ORCPT + 11 others); Tue, 24 Apr 2018 02:08:26 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:40291 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756208AbeDXGIZ (ORCPT ); Tue, 24 Apr 2018 02:08:25 -0400 Received: by mail-pf0-f194.google.com with SMTP id f189so2245143pfa.7 for ; Mon, 23 Apr 2018 23:08:25 -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=WJUC6XeR6FAzawrBGixqPEcqYbV4w00vw6FiMaOqXnw=; b=RTsWvb2gFI4hcwbW6l6f8ITyji5e/1507Mn7rC7Eo/1cJxGY8QpPv52HwSecM32ikh K6icj1G8ymXPMG7yA8t/d1EfjQP/W6nyVGCR6kUny+8+kAHpRrNv7J+714F+li4LLCCT VDCixLZ+Vcddufgg5T6Y5qz94l6KdqQn2eO8I= 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=WJUC6XeR6FAzawrBGixqPEcqYbV4w00vw6FiMaOqXnw=; b=WroVjIrSIP107QfplKVKSB+0IPsp0o+OW6rk2eUc91dNPX1avXlhzjxHKRtlrpmf2I WWur5pC3UXJV2/W6dyH5jBN3wghMIA/OTMpcn98J/Cu6pbM+V0Tf9ZC+sL5XH0P+SDjI B33FarTwSp23cRLeBTF+b4+GVmMiq1diQudDIYvzz4ggE4w7gwhz60pP126pqQrdMwhb 5T+uAyDRZ81+/l2UfX8XoCJkMMJAkaNwFXFBlJTp0xJ0zsZux1trr+N3D2c+F45ix3U5 y+vq21w6RlmvZwQhT9HwmAedTSKL09+vNwE5Omdsq8crf6MDpIs9d0YwuZ229z96FLr3 Tt9A== X-Gm-Message-State: ALQs6tBG63SW7+32IeyQyPBd4kRRN+FRsOVom46KShO0lQuhGvo8gUdJ Pm79F1Z1FDQH48vg10jgWnMS4A== X-Received: by 10.99.120.202 with SMTP id t193mr19344138pgc.255.1524550105295; Mon, 23 Apr 2018 23:08:25 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id o88sm30049575pfk.91.2018.04.23.23.08.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 23:08:24 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Miquel Raynal Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot Subject: [PATCH 1/3] cpufreq: dt: Allow platform specific suspend/resume callbacks Date: Tue, 24 Apr 2018 11:37:34 +0530 Message-Id: <031b87c0dd05625c83ac920a8da661e72afb4b02.1524549644.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Platforms may need to implement platform specific suspend/resume hooks. Update cpufreq-dt driver's platform data to contain those for such platforms. Signed-off-by: Viresh Kumar --- drivers/cpufreq/cpufreq-dt.c | 10 ++++++++-- drivers/cpufreq/cpufreq-dt.h | 5 +++++ 2 files changed, 13 insertions(+), 2 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/cpufreq/cpufreq-dt.c b/drivers/cpufreq/cpufreq-dt.c index 190ea0dccb79..0a9ebf00be46 100644 --- a/drivers/cpufreq/cpufreq-dt.c +++ b/drivers/cpufreq/cpufreq-dt.c @@ -346,8 +346,14 @@ static int dt_cpufreq_probe(struct platform_device *pdev) if (ret) return ret; - if (data && data->have_governor_per_policy) - dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY; + if (data) { + if (data->have_governor_per_policy) + dt_cpufreq_driver.flags |= CPUFREQ_HAVE_GOVERNOR_PER_POLICY; + + dt_cpufreq_driver.resume = data->resume; + if (data->suspend) + dt_cpufreq_driver.suspend = data->suspend; + } ret = cpufreq_register_driver(&dt_cpufreq_driver); if (ret) diff --git a/drivers/cpufreq/cpufreq-dt.h b/drivers/cpufreq/cpufreq-dt.h index 54d774e46c43..d5aeea13433e 100644 --- a/drivers/cpufreq/cpufreq-dt.h +++ b/drivers/cpufreq/cpufreq-dt.h @@ -12,8 +12,13 @@ #include +struct cpufreq_policy; + struct cpufreq_dt_platform_data { bool have_governor_per_policy; + + int (*suspend)(struct cpufreq_policy *policy); + int (*resume)(struct cpufreq_policy *policy); }; #endif /* __CPUFREQ_DT_H__ */ From patchwork Tue Apr 24 06:07:35 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 134053 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1845192lji; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) X-Google-Smtp-Source: AIpwx491EmFgxxz6wrol0SmO8JwS0mnshja0i60LwME60Z1gMKnKAH35gWC0apbKTwNz0+oEG7H+ X-Received: by 2002:a17:902:9a44:: with SMTP id x4-v6mr24154758plv.312.1524550110024; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524550110; cv=none; d=google.com; s=arc-20160816; b=dMll9SXEdEkMFYDp4mYT6GOe/iDWQ5e0biQWU6kIX+z76pw4n0UHx78INuAkltK8HB vuaanrQPpurqCUmDriCi+NAsS5hbudSMRUh+FAd9t6u38uJ36QOUv9gtG0Z4BPO+b/FZ PgWKEzkrCetyIerl0dsF9PACJWcM4aVlLgyUpLHJ6jT1ei/w8Ip+JbMVfnFHAFpen30i oJTVXOy/5ODMvKel1/wXv5BsngTfsMr7Ogxwpv1dBwgens/RxjatyIVU17BYR1fgGCjR BecSRN3/hJ2YHoBaMP545/xpUkUiB2QDkaL+miw19fqFKNf7UdLbIMudQBbPzhlCYMRh yn2Q== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=LSc1f52RWyaXjsmGQjSUQJJPClcBxFISoOl0tmFo4MnN1mbY3IwtMVi2wNSLfEVy7t fXosaZVyh1jiNYGx8rByj3UuJnjaOFt9kJWnGq4h5LYawBjYhibWzE74gmo5HZQeuLAN SqszmCa+R4vaW1QtKS7qETFUNtMbL+Z9eYtC/eU6txi2uhBfIs9h4ptooTinaux6Rnml ZiOl+o4BSxBeu4aeuzX20ISJAJGMZho+ZysN+A2C+stCKNokLnuposmsw+R+l29/EN1h VyxaB+JlYcyYUpFkt1bYOy4LNOrSnyRjYSc+efW7TM2TvTdyZkDVp37uriUbOu43HfwW MwWQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=VIKCf1AR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 y5si12475283pfe.184.2018.04.23.23.08.29; Mon, 23 Apr 2018 23:08:30 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=VIKCf1AR; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1756214AbeDXGI3 (ORCPT + 11 others); Tue, 24 Apr 2018 02:08:29 -0400 Received: from mail-pf0-f194.google.com ([209.85.192.194]:44279 "EHLO mail-pf0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756208AbeDXGI2 (ORCPT ); Tue, 24 Apr 2018 02:08:28 -0400 Received: by mail-pf0-f194.google.com with SMTP id p15so11347898pff.11 for ; Mon, 23 Apr 2018 23:08:28 -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=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=VIKCf1AR5xv8xlDyyrm5fW8U9WomwcJ2O9oBLeDk/LlQeCIW882SBD+Gf8W1Fk8E1R oNgMbFWebUXidcDY2FhIlo1eJ28L2pifiNU8fPpLTuCBOZQ28bTbWSXtJfPr8yNZQk31 r88oERAtyJcoEY3S0crqKt0JD3t3eGWMysIfE= 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=z3umFelSZyo4/s2aIJrG7pE6wGW7GPFzfnER4DGATgg=; b=RPfEpaaRT5xapimlxTnb5mCBBu/S34+StxSYLjVGXGkdI0qtuZ32RhGzDPLFEHMc9p o/3SrnpaQfPndFj83GrHEtvok2vGgYuVzbTYcU0UfScSdLPELZYoIGdrLaHwaG3a/J46 oU/MvzZ/SIrrFq91/x1LbXMXg7jOuMLEUPMa6t8mKsTTiWdLHFBWAhWn9UAxxg6tu367 REpuXtfM3hep2pGy6WSAMGpo5sOgYPCoIFNKlQVgeYI8xUTW+KdOobRmf35FgWNxVP02 7wekEdVJ80Yu7chAa2aJVknen0OWp3CCbcdipXqEBmBOv53vM3r6wUxEczVonTxYz+ot n0rQ== X-Gm-Message-State: ALQs6tCeHEm7YSH0oK2S1JrHdSLrhLrCuCgso0T3/3zWJahaS1G3MiZG RPFThF0L/egO6L2nRszjdNQeGQ== X-Received: by 2002:a17:902:5ac1:: with SMTP id g1-v6mr11242228plm.43.1524550108118; Mon, 23 Apr 2018 23:08:28 -0700 (PDT) Received: from localhost ([122.172.61.40]) by smtp.gmail.com with ESMTPSA id o64sm25774195pfb.62.2018.04.23.23.08.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 23 Apr 2018 23:08:27 -0700 (PDT) From: Viresh Kumar To: Rafael Wysocki , Miquel Raynal , Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org Subject: [PATCH 2/3] cpufreq: armada: Free resources on error paths Date: Tue, 24 Apr 2018 11:37:35 +0530 Message-Id: X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The resources weren't freed on failures, free them properly. Signed-off-by: Viresh Kumar --- drivers/cpufreq/armada-37xx-cpufreq.c | 40 +++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 14 deletions(-) -- 2.15.0.194.g9af6a3dea062 diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c index 72a2975499db..9dafb3bbc334 100644 --- a/drivers/cpufreq/armada-37xx-cpufreq.c +++ b/drivers/cpufreq/armada-37xx-cpufreq.c @@ -166,6 +166,7 @@ static int __init armada37xx_cpufreq_driver_init(void) { struct armada_37xx_dvfs *dvfs; struct platform_device *pdev; + unsigned long freq; unsigned int cur_frequency; struct regmap *nb_pm_base; struct device *cpu_dev; @@ -202,38 +203,49 @@ static int __init armada37xx_cpufreq_driver_init(void) cur_frequency = clk_get_rate(clk); if (!cur_frequency) { dev_err(cpu_dev, "Failed to get clock rate for CPU\n"); - clk_put(clk); - return -EINVAL; + ret = -EINVAL; + goto put_clk; } dvfs = armada_37xx_cpu_freq_info_get(cur_frequency); - if (!dvfs) - return -EINVAL; + if (!dvfs) { + ret = -EINVAL; + goto put_clk; + } armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider); clk_put(clk); for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR; load_lvl++) { - unsigned long freq = cur_frequency / dvfs->divider[load_lvl]; + freq = cur_frequency / dvfs->divider[load_lvl]; ret = dev_pm_opp_add(cpu_dev, freq, 0); - if (ret) { - /* clean-up the already added opp before leaving */ - while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) { - freq = cur_frequency / dvfs->divider[load_lvl]; - dev_pm_opp_remove(cpu_dev, freq); - } - return ret; - } + if (ret) + goto remove_opp; } /* 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); + ret = PTR_ERR_OR_ZERO(pdev); + if (ret) + goto disable_dvfs; + + return 0; - return PTR_ERR_OR_ZERO(pdev); +disable_dvfs: + armada37xx_cpufreq_disable_dvfs(nb_pm_base); +remove_opp: + /* clean-up the already added opp before leaving */ + while (load_lvl-- > ARMADA_37XX_DVFS_LOAD_0) { + freq = cur_frequency / dvfs->divider[load_lvl]; + dev_pm_opp_remove(cpu_dev, freq); + } +put_clk: + clk_put(clk); + return ret; } /* late_initcall, to guarantee the driver is loaded after A37xx clock driver */ late_initcall(armada37xx_cpufreq_driver_init); 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: 134054 Delivered-To: patch@linaro.org Received: by 10.46.151.6 with SMTP id r6csp1845234lji; Mon, 23 Apr 2018 23:08:33 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+Zer3Nu1m152U2g+ftNr/pBJ+V0qRzsQAMKb0XlN+MDaaXoCCqagq1/1zY07VS+jJkZW7o X-Received: by 10.167.130.22 with SMTP id k22mr22728399pfi.73.1524550112995; Mon, 23 Apr 2018 23:08:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1524550112; cv=none; d=google.com; s=arc-20160816; b=RGW4y37MO8ZRPegIXtvDjRFnMWCblHG+ncuhe3A1oxnVc96QtrO50yYF+Goo2xUZDS J2VOVW6ld+BeXbQ+aBJ48CTQNeBt/hJ3vkZdkvKRVVMy1puP++5QdSKMDLoi0OZ/UQxx s6jSwSy9sescO5U59b1FuXrapaZ7h3jCi/3uzdxsbeA7hMOPaetnSqRy1ysUlzyuiGOg ACfZi1fDk380FmnYBIMQOU9fwH79ugyLKiuv5gyez7ZlXMIE4vKaNs2sCC/XF314pdev 22qK0zLioWSaWov3mzhpnE6jr2y6X78Mq1//A+bAdwwTmpJkccs6AfLUEiD+ZbA1MaOG 0ghA== 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:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=QPYUFVe/J7/9TPuQp6Me7vBNCuwLOG0dwd89n7auLzM=; b=JEwYKStW8HAo77zSXi/csrlC8X4b1NHP3S03KWmonwU1t9++ABaqFJd5Cyodo8tAz2 XTPBpuOleMMxm/pNh9GPmemxrbqSpyO+uoDVrBgc5qtL5v0dYcnSOPYfXaLdDcXDKlcf oTD/ByXf4AnLefl+2AvpNkBpwoNJJDAWR740C0HpyIY62HhXOdKX7FwOfjKHDiPq+5rO 78KuvHHfl86Q/x2B+GHUYJ8RKZ1D0n+dsv11QIW2U1Gb9o1FzBTkvFPNfnfEF+ZA06Ve jRn0V/mtWyFBf/IKO/3mUECRbl0wJsU3Y53i2u+FNyaCaV8gAa4lrRO7lanUI7lZ0/b8 sTvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hlVN8hmh; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 y5si12475283pfe.184.2018.04.23.23.08.32; Mon, 23 Apr 2018 23:08:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-pm-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=hlVN8hmh; spf=pass (google.com: best guess record for domain of linux-pm-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-pm-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 S1756215AbeDXGIc (ORCPT + 11 others); Tue, 24 Apr 2018 02:08:32 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:38644 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756208AbeDXGIb (ORCPT ); Tue, 24 Apr 2018 02:08:31 -0400 Received: by mail-pf0-f193.google.com with SMTP id o76so6644303pfi.5 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=Xw3bHPr5LDZWFW1SVJpBXpuuVFnxOgs1HAlxJtgX6AQlA2STtuASA0goGfLKwZ7Mid xr0gHVcdhQNR8mSIiKkiem+TF+FYWz6PEQhjEdkbJgW01OM3xuy/hbX/6KUPCQGFMCKh UnLEjus9sMIlIWq7Z/jahd1ycspmrwyURChpzsy/GT64MATybGt3FKw+MhhwPgGeE8l1 tgRBp4WUoNCi/l+SEpHM5kCNxOdjUcZW5i66CyDEVR0rhTWznRiHSKrlhZL6FuaZcAJv Pr4Xdryx1tHQBEtSJcu3+vdAdXHnRXu98kAgUquJKj+wX4bE47rnCxZwFKhK/AvHZ0NF UEHQ== X-Gm-Message-State: ALQs6tDH4+zP8jQ+sEGgZ29WW6n0Bn/kyNPiESP7P7LX3zyxxMhRW71p FMTQwV6vzCAsVBGx7Dn5H23fLg== 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 Cc: Viresh Kumar , linux-pm@vger.kernel.org, Vincent Guittot , linux-arm-kernel@lists.infradead.org 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: Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org 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(-) -- 2.15.0.194.g9af6a3dea062 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;