Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp340277pxj; Thu, 20 May 2021 10:30:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyls2+A01LOMR9l7y/kYunCoQViufgigt3wsIFPq/Gc8vYGI/ywt7E2rFBX7o/i2hSnlJ06 X-Received: by 2002:a17:907:7355:: with SMTP id dq21mr5772308ejc.503.1621531821485; Thu, 20 May 2021 10:30:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621531821; cv=none; d=google.com; s=arc-20160816; b=v2hnRY9j5vkRTAI6DWZoUmqPvG1q08RVhtC+UAKVNrAnYhjhKdsbM4TxV3H1QrG9mp j0Af1YbSKo1vbcc6s8X6ZICC8NI9hD8crZLgsqeLF7zknoirdRpcFIVTngaCeu3JjUIM g0/ZFu3XoYtyrSYRr1ALfbvqAXAlGzxPhacERC/cRdhGQilyn6W/XQimCo79OMtEdaTG qG44sX/Tx98LpcZ1cXZoJWayS0QVl0CJPj0zidQ3Wo0ydGTXTRyjOAYBpfVuntQI1a25 ooMiz0BgXaLKWGJ2IVPZBsszSOUqcIz/g095fCrzRD+QEJcHwY4tO/TA7qLmeR9TlZFf ying== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=coaXRLuTwQk6AdV5YgTyHkVsjUuXxk0Tdi+QP4+C0ns=; b=nQXZ0PrmC+nvZTcWe0BZHz5fH+PVL8rt8Z0HcfXL90Mjzm2iRwtNTxEIv6tDWaFivL pGmWG9aSWsLHxjRa4Rwc2bLm6foSJBTGJ8ySGkI/L7sGdkVTqbbC/cMgObK71NZdVZOm SEOrYNkrnDcMyy8TfXV6YCICRfeC/wQWTDTIBSk+OrH28ZYzHmyc2uUYBtrxLq9N+bub /GIVREKNIoy0e4/gHXjlrTa2HGIlWhro6P1x5LoghBaZCLoXo6g3ju0Y7VOB0fvhGhfw SsPanniMAC3NWYj057P0LF9pcrvGZqYb/1fcwdP7Vr4CtljoUJ4ImgEew0vzfGpL613o JpAw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wa94q0ar; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id l3si321433ejd.203.2021.05.20.10.29.57; Thu, 20 May 2021 10:30:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Wa94q0ar; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234688AbhETJ5V (ORCPT + 99 others); Thu, 20 May 2021 05:57:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:53312 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234676AbhETJx6 (ORCPT ); Thu, 20 May 2021 05:53:58 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id EE20361028; Thu, 20 May 2021 09:36:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621503405; bh=QTYkxTY5UiP9fvSom/GGK77hxX5tiC+en19uVTJCB4k=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wa94q0arCLrBv2NmEI7Yxj7e7TW77nMszuSPk5H64VL3pmCQOO85aPTRx0O3mAdHC OfwvQCiXKk87noxeJSivb+S5Zog3hmCpCBhUd+VjMhDMMQwp14Jl/rAKvc0Jc9sfYh 49XxBALDwhm4Lvz1VVdG/veiKJbbSRfxrHJD9Uo8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, =?UTF-8?q?Marek=20Beh=C3=BAn?= , Gregory CLEMENT , =?UTF-8?q?Pali=20Roh=C3=A1r?= , Tomasz Maciej Nowak , Anders Trier Olesen , Philip Soares , Viresh Kumar , Sasha Levin Subject: [PATCH 4.19 206/425] cpufreq: armada-37xx: Fix setting TBG parent for load levels Date: Thu, 20 May 2021 11:19:35 +0200 Message-Id: <20210520092138.181310976@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210520092131.308959589@linuxfoundation.org> References: <20210520092131.308959589@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marek Behún [ Upstream commit 22592df194e31baf371906cc720da38fa0ab68f5 ] With CPU frequency determining software [1] we have discovered that after this driver does one CPU frequency change, the base frequency of the CPU is set to the frequency of TBG-A-P clock, instead of the TBG that is parent to the CPU. This can be reproduced on EspressoBIN and Turris MOX: cd /sys/devices/system/cpu/cpufreq/policy0 echo powersave >scaling_governor echo performance >scaling_governor Running the mhz tool before this driver is loaded reports 1000 MHz, and after loading the driver and executing commands above the tool reports 800 MHz. The change of TBG clock selector is supposed to happen in function armada37xx_cpufreq_dvfs_setup. Before the function returns, it does this: parent = clk_get_parent(clk); clk_set_parent(clk, parent); The armada-37xx-periph clock driver has the .set_parent method implemented correctly for this, so if the method was actually called, this would work. But since the introduction of the common clock framework in commit b2476490ef11 ("clk: introduce the common clock..."), the clk_set_parent function checks whether the parent is actually changing, and if the requested new parent is same as the old parent (which is obviously the case for the code above), the .set_parent method is not called at all. This patch fixes this issue by filling the correct TBG clock selector directly in the armada37xx_cpufreq_dvfs_setup during the filling of other registers at the same address. But the determination of CPU TBG index cannot be done via the common clock framework, therefore we need to access the North Bridge Peripheral Clock registers directly in this driver. [1] https://github.com/wtarreau/mhz Signed-off-by: Marek Behún Acked-by: Gregory CLEMENT Tested-by: Pali Rohár Tested-by: Tomasz Maciej Nowak Tested-by: Anders Trier Olesen Tested-by: Philip Soares Fixes: 92ce45fb875d ("cpufreq: Add DVFS support for Armada 37xx") Signed-off-by: Viresh Kumar Signed-off-by: Sasha Levin --- drivers/cpufreq/armada-37xx-cpufreq.c | 35 ++++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/drivers/cpufreq/armada-37xx-cpufreq.c b/drivers/cpufreq/armada-37xx-cpufreq.c index 9b0b490d70ff..99fb0ae7e2d7 100644 --- a/drivers/cpufreq/armada-37xx-cpufreq.c +++ b/drivers/cpufreq/armada-37xx-cpufreq.c @@ -25,6 +25,10 @@ #include "cpufreq-dt.h" +/* Clk register set */ +#define ARMADA_37XX_CLK_TBG_SEL 0 +#define ARMADA_37XX_CLK_TBG_SEL_CPU_OFF 22 + /* Power management in North Bridge register set */ #define ARMADA_37XX_NB_L0L1 0x18 #define ARMADA_37XX_NB_L2L3 0x1C @@ -120,10 +124,15 @@ static struct armada_37xx_dvfs *armada_37xx_cpu_freq_info_get(u32 freq) * will be configured then the DVFS will be enabled. */ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base, - struct clk *clk, u8 *divider) + struct regmap *clk_base, u8 *divider) { + u32 cpu_tbg_sel; int load_lvl; - struct clk *parent; + + /* Determine to which TBG clock is CPU connected */ + regmap_read(clk_base, ARMADA_37XX_CLK_TBG_SEL, &cpu_tbg_sel); + cpu_tbg_sel >>= ARMADA_37XX_CLK_TBG_SEL_CPU_OFF; + cpu_tbg_sel &= ARMADA_37XX_NB_TBG_SEL_MASK; for (load_lvl = 0; load_lvl < LOAD_LEVEL_NR; load_lvl++) { unsigned int reg, mask, val, offset = 0; @@ -142,6 +151,11 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base, mask = (ARMADA_37XX_NB_CLK_SEL_MASK << ARMADA_37XX_NB_CLK_SEL_OFF); + /* Set TBG index, for all levels we use the same TBG */ + val = cpu_tbg_sel << ARMADA_37XX_NB_TBG_SEL_OFF; + mask = (ARMADA_37XX_NB_TBG_SEL_MASK + << ARMADA_37XX_NB_TBG_SEL_OFF); + /* * Set cpu divider based on the pre-computed array in * order to have balanced step. @@ -160,14 +174,6 @@ static void __init armada37xx_cpufreq_dvfs_setup(struct regmap *base, regmap_update_bits(base, reg, mask, val); } - - /* - * Set cpu clock source, for all the level we keep the same - * clock source that the one already configured. For this one - * we need to use the clock framework - */ - parent = clk_get_parent(clk); - clk_set_parent(clk, parent); } /* @@ -360,11 +366,16 @@ static int __init armada37xx_cpufreq_driver_init(void) struct platform_device *pdev; unsigned long freq; unsigned int cur_frequency, base_frequency; - struct regmap *nb_pm_base, *avs_base; + struct regmap *nb_clk_base, *nb_pm_base, *avs_base; struct device *cpu_dev; int load_lvl, ret; struct clk *clk, *parent; + nb_clk_base = + syscon_regmap_lookup_by_compatible("marvell,armada-3700-periph-clock-nb"); + if (IS_ERR(nb_clk_base)) + return -ENODEV; + nb_pm_base = syscon_regmap_lookup_by_compatible("marvell,armada-3700-nb-pm"); @@ -441,7 +452,7 @@ static int __init armada37xx_cpufreq_driver_init(void) armada37xx_cpufreq_avs_configure(avs_base, dvfs); armada37xx_cpufreq_avs_setup(avs_base, dvfs); - armada37xx_cpufreq_dvfs_setup(nb_pm_base, clk, dvfs->divider); + armada37xx_cpufreq_dvfs_setup(nb_pm_base, nb_clk_base, dvfs->divider); clk_put(clk); for (load_lvl = ARMADA_37XX_DVFS_LOAD_0; load_lvl < LOAD_LEVEL_NR; -- 2.30.2