Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp5138144imu; Tue, 8 Jan 2019 12:12:07 -0800 (PST) X-Google-Smtp-Source: ALg8bN4waU5IZOZG5cx8thQfyLfewMNyngP35calW/oKz1qob216TLojNy+UrdYS72aPQRlXzgRw X-Received: by 2002:a17:902:4401:: with SMTP id k1mr3160531pld.307.1546978327523; Tue, 08 Jan 2019 12:12:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546978327; cv=none; d=google.com; s=arc-20160816; b=lAk5i4hxbX7yoI9Jau6LAPepEEiqL7MOsPKepMiUBn3ve3obWtiMpNDhqvCPm7wM9u U5BYm644lOnGAda+t56gIBKProUSy6+vdwmTxY08P3lFsWPkgU8CsOo9+ahaNMwmTa+u CwAqO3rxcoyGigPbdjnPhxAB/OHxBCE7DtOyGRa6471o1XtwpxPEEs36Gi1/hDHJ2rPm RTA4Z//Ujdev0BdFvYhTGnzjwsnG2A/13+g4LQP4L+mM6gtO5ZyF4xo7mZm7wuZch9e9 F2HUrtIISS1E+5OwPdCNBp7KVQPZwIdpqemwdpFnNF676WR+pNcTSQZNUfm0ymH0xAIO +Aew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=08U1077Zm2EKSdfCqA/pK3u2GpP4dauDaN2vHSKWy+g=; b=e2kgS/jyRN/iEPGQdwA2hS3b7xSthI7l/8hARcuGh2CTPBuiYCuUpSU94inKY8kalr H719Hke2/nDRqm8AGo+X3/48rOdzxdx4eYRIbtMMC/ul0alPqpk9hkxBrT7/PWt/N5jM NQCfiW+OC8qugUl3musmAea4kDac4HQgH4dEJeXbb3mpe8Crb2rS+n+gcJYd8rRTN1iM cfptJbBGhV/78DmAqTM3mQ8sXJNJu74X1Oax0jpHXe/83HDNxuEAqmC9qgpf5j9KgfwV otU76QPzIySobiH08VoK9JRYfMtJ7vtI7NUobLKAqJB2lw5Kfz3GTYnhOxEw9X20f4xZ hULg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=EM8R0XLE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e6si64514587pgk.201.2019.01.08.12.11.33; Tue, 08 Jan 2019 12:12:07 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-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=@kernel.org header.s=default header.b=EM8R0XLE; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729657AbfAHT1Z (ORCPT + 99 others); Tue, 8 Jan 2019 14:27:25 -0500 Received: from mail.kernel.org ([198.145.29.99]:33500 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729616AbfAHT1X (ORCPT ); Tue, 8 Jan 2019 14:27:23 -0500 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 7D3AE2183F; Tue, 8 Jan 2019 19:27:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1546975642; bh=cU3B0wKKFM6sAVf1JmNfLSIVNTdZJPcuK8XPnGos9ls=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EM8R0XLEzbKFkbDDYnE7LuJoPrmwS4KMK5kScpUB1T84P8cMpGNmMIa4PzHVgTRCu bVx8mJZY7ajkGs7bHYq0Pdb5XWgIAF3Dk1WjRd9H1jrWOsAsQkpx4WFYTQ7TojKC7v T3SvcdT6+JR96VxcZeDT51iM/0akshzjYZc+UkzU= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Martin Blumenstingl , Neil Armstrong , Sasha Levin , linux-amlogic@lists.infradead.org, linux-clk@vger.kernel.org Subject: [PATCH AUTOSEL 4.20 028/117] clk: meson: meson8b: fix incorrect divider mapping in cpu_scale_table Date: Tue, 8 Jan 2019 14:24:56 -0500 Message-Id: <20190108192628.121270-28-sashal@kernel.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20190108192628.121270-1-sashal@kernel.org> References: <20190108192628.121270-1-sashal@kernel.org> MIME-Version: 1.0 X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Martin Blumenstingl [ Upstream commit ad9b2b8e53af61375322e3c7d624acf3a3ef53b0 ] The public S805 datasheet only mentions that HHI_SYS_CPU_CLK_CNTL1[20:29] contains a divider called "cpu_scale_div". Unfortunately it does not mention how to use the register contents. The Amlogic 3.10 GPL kernel sources are using the following code to calculate the CPU clock based on that register (taken from arch/arm/mach-meson8/clock.c in the 3.10 Amlogic kernel, shortened to make it easier to read): N = (aml_read_reg32(P_HHI_SYS_CPU_CLK_CNTL1) >> 20) & 0x3FF; if (sel == 3) /* use cpu_scale_div */ div = 2 * N; else div = ... /* not relevant for this example */ cpu_clk = parent_clk / div; This suggests that the formula is: parent_rate / 2 * register_value However, running perf (which can measure the CPU clock rate thanks to the ARM PMU) shows that this formula is not correct. This can be reproduced with the following steps: 1. boot into u-boot 2. let the CPU clock run off the XTAL clock: mw.l 0xC110419C 0x30 1 3. set the cpu_scale_div register: to value 0x1: mw.l 0xC110415C 0x801016A2 1 to value 0x2: mw.l 0xC110415C 0x802016A2 1 to value 0x5: mw.l 0xC110415C 0x805016A2 1 4. let the CPU clock run off cpu_scale_div: mw.l 0xC110419C 0xbd 1 5. boot Linux 6. run: perf stat -aB stress --cpu 4 --timeout 10 7. check the "cycles" value I get the following results depending on the cpu_scale_div value: - (cpu_in_sel - this is the input clock for cpu_scale_div - runs at 1.2GHz) - 0x1 = 300MHz - 0x2 = 200MHz - 0x5 = 100MHz This means that the actual formula to calculate the output of the cpu_scale_div clock is: parent_rate / 2 * (register value + 1). The register value 0x0 is reserved. When letting the CPU clock run off the cpu_scale_div while the value is 0x0 the whole board hangs (even in u-boot). I also verified this with the TWD timer: when adding this to the .dts without specifying it's clock it will auto-detect the PERIPH (which is the input clock of the TWD) clock rate (and the result is shown in the kernel log). On Meson8, Meson8b and Meson8m2 the PERIPH clock is CPUCLK divided by 4. This also matched for all three test-cases from above (in all cases the TWD timer clock rate was approx. one fourth of the CPU clock rate). A small note regarding the "fixes" tag: the original issue seems to exist virtually since forever. Even commit 28b9fcd016126e ("clk: meson8b: Add support for Meson8b clocks") seems to handle this wrong. I still decided to use commit 251b6fd38bcb9c ("clk: meson: rework meson8b cpu clock") because this is the first commit which gets the CPU hiearchy correct and thus it's the first commit where the cpu_scale_div register is used correctly (apart from the bug in the cpu_scale_table). Fixes: 251b6fd38bcb9c ("clk: meson: rework meson8b cpu clock") Signed-off-by: Martin Blumenstingl Signed-off-by: Neil Armstrong Link: https://lkml.kernel.org/r/20180927085921.24627-2-martin.blumenstingl@googlemail.com Signed-off-by: Sasha Levin --- drivers/clk/meson/meson8b.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/drivers/clk/meson/meson8b.c b/drivers/clk/meson/meson8b.c index a059db63907c..1d39273d7a04 100644 --- a/drivers/clk/meson/meson8b.c +++ b/drivers/clk/meson/meson8b.c @@ -584,13 +584,14 @@ static struct clk_fixed_factor meson8b_cpu_div3 = { }; static const struct clk_div_table cpu_scale_table[] = { - { .val = 2, .div = 4 }, - { .val = 3, .div = 6 }, - { .val = 4, .div = 8 }, - { .val = 5, .div = 10 }, - { .val = 6, .div = 12 }, - { .val = 7, .div = 14 }, - { .val = 8, .div = 16 }, + { .val = 1, .div = 4 }, + { .val = 2, .div = 6 }, + { .val = 3, .div = 8 }, + { .val = 4, .div = 10 }, + { .val = 5, .div = 12 }, + { .val = 6, .div = 14 }, + { .val = 7, .div = 16 }, + { .val = 8, .div = 18 }, { /* sentinel */ }, }; -- 2.19.1