linux-amlogic.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: b.galvani@gmail.com (Beniamino Galvani)
To: linus-amlogic@lists.infradead.org
Subject: [PATCH 2/4] ARM: meson: add clock measurement function
Date: Sun,  3 Dec 2017 10:17:11 +0100	[thread overview]
Message-ID: <20171203091713.22029-3-b.galvani@gmail.com> (raw)
In-Reply-To: <20171203091713.22029-1-b.galvani@gmail.com>

Add add a function to measure the current clock rate.

Signed-off-by: Beniamino Galvani <b.galvani@gmail.com>
---
 arch/arm/include/asm/arch-meson/clock.h | 34 +++++++++++++++++++++++++
 arch/arm/mach-meson/Makefile            |  2 +-
 arch/arm/mach-meson/clock.c             | 45 +++++++++++++++++++++++++++++++++
 3 files changed, 80 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/include/asm/arch-meson/clock.h
 create mode 100644 arch/arm/mach-meson/clock.c

diff --git a/arch/arm/include/asm/arch-meson/clock.h b/arch/arm/include/asm/arch-meson/clock.h
new file mode 100644
index 0000000000..b43b23386c
--- /dev/null
+++ b/arch/arm/include/asm/arch-meson/clock.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2017 - Beniamino Galvani <b.galvani@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+#ifndef _MESON_CLOCK_H_
+#define _MESON_CLOCK_H_
+
+/* CBUS clock measure registers */
+#define MSR_CLK_DUTY		0xc1108758
+#define MSR_CLK_REG0		0xc110875c
+#define MSR_CLK_REG1		0xc1108760
+#define MSR_CLK_REG2		0xc1108764
+
+#define CLK_GP0_PLL		4
+#define CLK_GP1_PLL		5
+#define CLK_81			7
+#define CLK_MMC			23
+#define CLK_MOD_ETH_TX		40
+#define CLK_MOD_ETH_RX_RMII	41
+#define CLK_FCLK_DIV5		43
+#define CLK_SD_EMMC_CLK_C	51
+#define CLK_SD_EMMC_CLK_B	52
+
+/* Clock gates */
+#define HHI_GCLK_MPEG0		0x140
+#define HHI_GCLK_MPEG1		0x144
+#define HHI_GCLK_MPEG2		0x148
+#define HHI_GCLK_OTHER		0x150
+#define HHI_GCLK_AO		0x154
+
+ulong meson_measure_clk_rate(unsigned int clk);
+
+#endif
diff --git a/arch/arm/mach-meson/Makefile b/arch/arm/mach-meson/Makefile
index bf49b8b1e5..e7ea4fc5b0 100644
--- a/arch/arm/mach-meson/Makefile
+++ b/arch/arm/mach-meson/Makefile
@@ -4,4 +4,4 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
-obj-y += board.o sm.o
+obj-y += board.o clock.o sm.o
diff --git a/arch/arm/mach-meson/clock.c b/arch/arm/mach-meson/clock.c
new file mode 100644
index 0000000000..73be11e90d
--- /dev/null
+++ b/arch/arm/mach-meson/clock.c
@@ -0,0 +1,45 @@
+/*
+ * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ *
+ * Clock rate measuring.
+ */
+
+#include <common.h>
+#include <asm/arch/clock.h>
+#include <asm/io.h>
+
+ulong meson_measure_clk_rate(unsigned int clk)
+{
+	ulong start;
+	ulong mhz;
+
+	writel(0, MSR_CLK_REG0);
+
+	/* Set the measurement gate to 64uS */
+	clrsetbits_le32(MSR_CLK_REG0, 0xffff, 64 - 1);
+	clrbits_le32(MSR_CLK_REG0,
+		     BIT(17) |		/* disable continuous measurement */
+		     BIT(18));		/* disable interrupts */
+	clrsetbits_le32(MSR_CLK_REG0,
+			GENMASK(20, 26),
+			clk << 20);	/* select the clock */
+	setbits_le32(MSR_CLK_REG0,
+		     BIT(19) |		/* enable the clock */
+		     BIT(16));		/* enable measuring */
+
+	start = get_timer(0);
+	while (readl(MSR_CLK_REG0) & BIT(31)) {
+		if (get_timer(start) > 100) {
+			debug("could not measure clk %u rate\n", clk);
+			return -ETIMEDOUT;
+		}
+	}
+
+	/* Disable measuring */
+	clrbits_le32(MSR_CLK_REG0, BIT(16));
+
+	mhz = ((readl(MSR_CLK_REG2) + 31) & 0xfffff) >> 6;
+	return mhz * 1000000;
+}
-- 
2.14.3

  parent reply	other threads:[~2017-12-03  9:17 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-03  9:17 [PATCH 0/4] Meson clock driver Beniamino Galvani
2017-12-03  9:17 ` [PATCH 1/4] ARM: dts: update gxbb-clkc.h from Linux 4.14 Beniamino Galvani
2017-12-06 13:38   ` Neil Armstrong
2017-12-03  9:17 ` Beniamino Galvani [this message]
2017-12-06 13:40   ` [PATCH 2/4] ARM: meson: add clock measurement function Neil Armstrong
2017-12-11 14:57   ` Simon Glass
2017-12-03  9:17 ` [PATCH 3/4] clk: add Amlogic meson clock driver Beniamino Galvani
2017-12-06 13:41   ` Neil Armstrong
2017-12-11 14:57   ` Simon Glass
2018-03-29  8:42   ` Neil Armstrong
2018-03-29 22:41     ` Simon Glass
2018-03-30  7:53       ` Neil Armstrong
2018-03-30  8:41         ` Simon Glass
2018-03-30 14:27           ` Andreas Färber
2018-03-31  8:44             ` Simon Glass
2017-12-03  9:17 ` [PATCH 4/4] meson: use the " Beniamino Galvani
2017-12-06 13:43   ` Neil Armstrong
2017-12-11 14:57   ` Simon Glass
2017-12-13  2:33   ` [U-Boot,4/4] " Tom Rini
2018-03-28  8:59 ` [PATCH 0/4] Meson " Neil Armstrong
2018-03-28 10:52   ` Beniamino Galvani
2018-03-28 13:44     ` Neil Armstrong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20171203091713.22029-3-b.galvani@gmail.com \
    --to=b.galvani@gmail.com \
    --cc=linus-amlogic@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).