linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
To: linux-clk@vger.kernel.org
Cc: linux-mips@vger.kernel.org, tsbogend@alpha.franken.de,
	john@phrozen.org, linux-kernel@vger.kernel.org,
	p.zabel@pengutronix.de, mturquette@baylibre.com,
	sboyd@kernel.org, robh+dt@kernel.org,
	krzysztof.kozlowski+dt@linaro.org, matthias.bgg@gmail.com,
	devicetree@vger.kernel.org, arinc.unal@arinc9.com
Subject: [PATCH 09/10] mips: ralink: get cpu rate from new driver code
Date: Mon, 20 Mar 2023 17:18:22 +0100	[thread overview]
Message-ID: <20230320161823.1424278-10-sergio.paracuellos@gmail.com> (raw)
In-Reply-To: <20230320161823.1424278-1-sergio.paracuellos@gmail.com>

At very early stage on boot, there is a need to set 'mips_hpt_frequency'.
This timer frequency is a half of the CPU frequency. To get clocks properly
set we need to call to 'of_clk_init()' and properly get cpu clock frequency
afterwards. Depending on the SoC, CPU clock index in the clock provider is
different being two for MT7620 SoC and one for the rest. Hence, adapt code
to be aligned with new clock driver.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 arch/mips/ralink/clk.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/arch/mips/ralink/clk.c b/arch/mips/ralink/clk.c
index 5b02bb7e0829..3d29e956f785 100644
--- a/arch/mips/ralink/clk.c
+++ b/arch/mips/ralink/clk.c
@@ -11,29 +11,41 @@
 #include <linux/clkdev.h>
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
+#include <asm/mach-ralink/ralink_regs.h>
 
 #include <asm/time.h>
 
 #include "common.h"
 
-void ralink_clk_add(const char *dev, unsigned long rate)
+static int clk_cpu_index(void)
 {
-	struct clk *clk = clk_register_fixed_rate(NULL, dev, NULL, 0, rate);
+	if (ralink_soc == RALINK_UNKNOWN)
+		return -1;
 
-	if (!clk)
-		panic("failed to add clock");
+	if (ralink_soc == MT762X_SOC_MT7620A ||
+	    ralink_soc == MT762X_SOC_MT7620N)
+		return 2;
 
-	clkdev_create(clk, NULL, "%s", dev);
+	return 1;
 }
 
 void __init plat_time_init(void)
 {
+	struct of_phandle_args clkspec;
 	struct clk *clk;
+	int cpu_clk_idx;
 
 	ralink_of_remap();
 
-	ralink_clk_init();
-	clk = clk_get_sys("cpu", NULL);
+	cpu_clk_idx = clk_cpu_index();
+	if (cpu_clk_idx == -1)
+		panic("unable to get CPU clock index");
+
+	of_clk_init(NULL);
+	clkspec.np = of_find_node_by_name(NULL, "sysc");
+	clkspec.args_count = 1;
+	clkspec.args[0] = cpu_clk_idx;
+	clk = of_clk_get_from_provider(&clkspec);
 	if (IS_ERR(clk))
 		panic("unable to get CPU clock, err=%ld", PTR_ERR(clk));
 	pr_info("CPU Clock: %ldMHz\n", clk_get_rate(clk) / 1000000);
-- 
2.25.1


  parent reply	other threads:[~2023-03-20 16:26 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 16:18 [PATCH 00/10] mips: ralink: add complete clock and reset driver for mtmips SoCs Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 01/10] dt: bindings: clock: add mtmips SoCs clock device tree binding documentation Sergio Paracuellos
2023-03-20 16:36   ` Krzysztof Kozlowski
2023-03-20 16:43     ` Arınç ÜNAL
2023-03-20 16:50       ` Krzysztof Kozlowski
2023-03-20 17:24     ` Sergio Paracuellos
2023-03-20 17:36       ` Krzysztof Kozlowski
2023-03-20 17:57         ` Arınç ÜNAL
2023-03-20 18:02           ` Krzysztof Kozlowski
2023-03-20 18:09             ` Arınç ÜNAL
2023-03-20 18:15               ` Krzysztof Kozlowski
2023-03-21  4:34                 ` Sergio Paracuellos
2023-03-21  6:32                   ` Krzysztof Kozlowski
2023-03-21  6:38                     ` Arınç ÜNAL
2023-03-21  6:43                       ` Krzysztof Kozlowski
2023-03-21  6:56                         ` Sergio Paracuellos
2023-03-21  7:19                           ` Krzysztof Kozlowski
2023-03-21  7:27                             ` Sergio Paracuellos
2023-03-21  7:39                             ` Arınç ÜNAL
2023-03-21  8:04                               ` Krzysztof Kozlowski
2023-03-21  8:24                                 ` Arınç ÜNAL
2023-03-21  8:27                                   ` Krzysztof Kozlowski
2023-03-21  8:33                                     ` Arınç ÜNAL
2023-03-21  8:39                                       ` Krzysztof Kozlowski
2023-03-21  8:53                                         ` Arınç ÜNAL
2023-03-21  9:01                                           ` Krzysztof Kozlowski
2023-03-21  9:02                                             ` Arınç ÜNAL
2023-03-24 22:10                                               ` Rob Herring
2023-03-24 23:15                                                 ` Arınç ÜNAL
2023-03-24 22:13                                               ` Rob Herring
2023-03-21  4:29         ` Sergio Paracuellos
2023-03-20 18:01   ` Krzysztof Kozlowski
2023-03-20 18:07     ` Arınç ÜNAL
2023-03-20 18:11       ` Krzysztof Kozlowski
2023-03-20 18:23         ` Arınç ÜNAL
2023-03-21  6:34           ` Krzysztof Kozlowski
2023-03-20 16:18 ` [PATCH 02/10] clk: ralink: add clock and reset driver for MTMIPS SoCs Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 03/10] mips: ralink: rt288x: remove clock related code Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 04/10] mips: ralink: rt305x: " Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 05/10] mips: ralink: rt3883: " Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 06/10] mips: ralink: mt7620: " Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 07/10] mips: ralink: remove clock related function prototypes Sergio Paracuellos
2023-03-20 19:38   ` Stephen Boyd
2023-03-20 20:17     ` Sergio Paracuellos
2023-03-20 21:21       ` Stephen Boyd
2023-03-21  4:23         ` Sergio Paracuellos
2023-03-20 16:18 ` [PATCH 08/10] mips: ralink: remove reset related code Sergio Paracuellos
2023-03-20 16:18 ` Sergio Paracuellos [this message]
2023-03-20 16:18 ` [PATCH 10/10] MAINTAINERS: add Mediatek MTMIPS Clock maintainer Sergio Paracuellos

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=20230320161823.1424278-10-sergio.paracuellos@gmail.com \
    --to=sergio.paracuellos@gmail.com \
    --cc=arinc.unal@arinc9.com \
    --cc=devicetree@vger.kernel.org \
    --cc=john@phrozen.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mturquette@baylibre.com \
    --cc=p.zabel@pengutronix.de \
    --cc=robh+dt@kernel.org \
    --cc=sboyd@kernel.org \
    --cc=tsbogend@alpha.franken.de \
    /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).