From patchwork Fri Jul 3 06:11:56 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory CLEMENT X-Patchwork-Id: 6712921 Return-Path: X-Original-To: patchwork-linux-pm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id DB50FC05AC for ; Fri, 3 Jul 2015 06:13:19 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id ECCC1205EB for ; Fri, 3 Jul 2015 06:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0D49320520 for ; Fri, 3 Jul 2015 06:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754545AbbGCGMv (ORCPT ); Fri, 3 Jul 2015 02:12:51 -0400 Received: from down.free-electrons.com ([37.187.137.238]:55208 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754166AbbGCGMP (ORCPT ); Fri, 3 Jul 2015 02:12:15 -0400 Received: by mail.free-electrons.com (Postfix, from userid 106) id 3E8AD1F4F; Fri, 3 Jul 2015 08:12:14 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from localhost (von69-1-88-162-9-206.fbx.proxad.net [88.162.9.206]) by mail.free-electrons.com (Postfix) with ESMTPSA id A112F66B; Fri, 3 Jul 2015 08:12:13 +0200 (CEST) From: Gregory CLEMENT To: Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , Gregory CLEMENT Cc: Thomas Petazzoni , Ezequiel Garcia , linux-arm-kernel@lists.infradead.org, Mike Turquette , Stephen Boyd , linux-clk@vger.kernel.org, linux-kernel@vger.kernel.org, Daniel Lezcano , "Rafael J. Wysocki" , linux-pm@vger.kernel.org, Maxime Ripard , Boris BREZILLON , Lior Amsalem , Tawfik Bayouk , Nadav Haklai Subject: [PATCH RFC 4/5] ARM: mvebu: Armada 38x: Add dynamic frequency scaling support in pmsu Date: Fri, 3 Jul 2015 08:11:56 +0200 Message-Id: <1435903917-20486-5-git-send-email-gregory.clement@free-electrons.com> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1435903917-20486-1-git-send-email-gregory.clement@free-electrons.com> References: <1435903917-20486-1-git-send-email-gregory.clement@free-electrons.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This commit add the last missing piece of code enabling dynamic frequency scaling support for Armada 38x. The main difference with Armada XP is that the Cortex A9 CPU frequencies of the Armada 38x SoCs are not independent. Even if a SoC contains a single CPU, some specific initialization has to be done at pmsu level: this unit must not wait for the second CPU when the frequency is modified. Signed-off-by: Gregory CLEMENT --- arch/arm/mach-mvebu/pmsu.c | 67 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 61 insertions(+), 6 deletions(-) diff --git a/arch/arm/mach-mvebu/pmsu.c b/arch/arm/mach-mvebu/pmsu.c index f19be0ac0068..a2ced0b7fa0a 100644 --- a/arch/arm/mach-mvebu/pmsu.c +++ b/arch/arm/mach-mvebu/pmsu.c @@ -352,6 +352,13 @@ void mvebu_v7_pmsu_idle_exit(void) /* cancel ask HW to power down the L2 Cache if possible */ reg = readl(pmsu_mp_base + PMSU_CTL_CFG(hw_cpu)); reg &= ~PMSU_CTL_CFG_L2_PWDDN; + + /* + * When exiting from idle state such as cpuidle or hotplug, + * Enable PMU wait for the CPU to enter WFI when doing DFS + * by setting CPUx Frequency ID to 1 + */ + reg |= 1 << PMSU_CTL_CFG_CPU0_FRQ_ID_SFT; writel(reg, pmsu_mp_base + PMSU_CTL_CFG(hw_cpu)); /* cancel Enable wakeup events and mask interrupts */ @@ -586,6 +593,38 @@ int armada_xp_pmsu_dfs_request(int cpu) return 0; } +void mvebu_v7_pmsu_disable_dfs_cpu(int hw_cpu) +{ + u32 reg; + + if (pmsu_mp_base == NULL) + return; + /* + * Disable PMU wait for the CPU to enter WFI when doing DFS + * by setting CPUx Frequency ID to 0 + */ + reg = readl(pmsu_mp_base + PMSU_CTL_CFG(hw_cpu)); + reg &= ~(PMSU_CTL_CFG_CPU0_FRQ_ID_MSK << PMSU_CTL_CFG_CPU0_FRQ_ID_SFT); + writel(reg, pmsu_mp_base + PMSU_CTL_CFG(hw_cpu)); +} + +int armada_38x_pmsu_dfs_request(int cpu) +{ + /* + * Protect CPU DFS from changing the number of online cpus number during + * frequency transition by temporarily disable cpu hotplug + */ + cpu_hotplug_disable(); + + /* Trigger the DFS on all the CPUs */ + on_each_cpu(mvebu_pmsu_dfs_request_local, + NULL, false); + + cpu_hotplug_enable(); + + return 0; +} + int mvebu_pmsu_dfs_request(int cpu) { return mvebu_pmsu_dfs_request_ptr(cpu); @@ -595,15 +634,19 @@ struct cpufreq_dt_platform_data armada_xp_cpufreq_dt_pd = { .independent_clocks = true, }; +struct cpufreq_dt_platform_data armada_38x_cpufreq_dt_pd = { + .independent_clocks = false, +}; + static int __init mvebu_pmsu_cpufreq_init(void) { struct device_node *np; struct resource res; int ret, cpu; - if (!of_machine_is_compatible("marvell,armadaxp")) + if (!of_machine_is_compatible("marvell,armadaxp") && + !of_machine_is_compatible("marvell,armada380")) return 0; - /* * In order to have proper cpufreq handling, we need to ensure * that the Device Tree description of the CPU clock includes @@ -648,6 +691,8 @@ static int __init mvebu_pmsu_cpufreq_init(void) return PTR_ERR(clk); } + clk_prepare_enable(clk); + /* * In case of a failure of dev_pm_opp_add(), we don't * bother with cleaning up the registered OPP (there's @@ -666,10 +711,20 @@ static int __init mvebu_pmsu_cpufreq_init(void) return ret; } } - mvebu_pmsu_dfs_request_ptr = armada_xp_pmsu_dfs_request; - platform_device_register_data(NULL, "cpufreq-dt", -1, - &armada_xp_cpufreq_dt_pd, - sizeof(armada_xp_cpufreq_dt_pd)); + if (of_machine_is_compatible("marvell,armada380")) { + if (num_online_cpus() == 1) + mvebu_v7_pmsu_disable_dfs_cpu(1); + + mvebu_pmsu_dfs_request_ptr = armada_38x_pmsu_dfs_request; + platform_device_register_data(NULL, "cpufreq-dt", -1, + &armada_38x_cpufreq_dt_pd, + sizeof(armada_38x_cpufreq_dt_pd)); + } else if (of_machine_is_compatible("marvell,armadaxp")) { + mvebu_pmsu_dfs_request_ptr = armada_xp_pmsu_dfs_request; + platform_device_register_data(NULL, "cpufreq-dt", -1, + &armada_xp_cpufreq_dt_pd, + sizeof(armada_xp_cpufreq_dt_pd)); + } return 0; }