public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jit Loon Lim <jit.loon.lim@intel.com>
To: u-boot@lists.denx.de
Cc: Jagan Teki <jagan@amarulasolutions.com>,
	Vignesh R <vigneshr@ti.com>, Marek <marex@denx.de>,
	Simon <simon.k.r.goldschmidt@gmail.com>,
	Tien Fong <tien.fong.chee@intel.com>,
	Kok Kiang <kok.kiang.hea@intel.com>,
	Siew Chin <elly.siew.chin.lim@intel.com>,
	Sin Hui <sin.hui.kho@intel.com>, Raaj <raaj.lokanathan@intel.com>,
	Dinesh <dinesh.maniyam@intel.com>,
	Boon Khai <boon.khai.ng@intel.com>,
	Alif <alif.zakuan.yuslaimi@intel.com>,
	Teik Heng <teik.heng.chong@intel.com>,
	Hazim <muhammad.hazim.izzat.zamri@intel.com>,
	Jit Loon Lim <jit.loon.lim@intel.com>,
	Sieu Mun Tang <sieu.mun.tang@intel.com>
Subject: [PATCH 3/9] arm: socfpga: dm: Add clock manager for Diamond Mesa
Date: Sun, 18 Sep 2022 20:17:45 +0800	[thread overview]
Message-ID: <20220918121751.26370-3-jit.loon.lim@intel.com> (raw)
In-Reply-To: <20220918121751.26370-1-jit.loon.lim@intel.com>

From: Siew Chin Lim <elly.siew.chin.lim@intel.com>

Add clock manager driver for Diamond Mesa.

Signed-off-by: Siew Chin Lim <elly.siew.chin.lim@intel.com>
Signed-off-by: Jit Loon Lim <jit.loon.lim@intel.com>
---
 arch/arm/mach-socfpga/clock_manager_dm.c      | 79 +++++++++++++++++++
 .../include/mach/clock_manager_dm.h           | 14 ++++
 2 files changed, 93 insertions(+)
 create mode 100644 arch/arm/mach-socfpga/clock_manager_dm.c
 create mode 100644 arch/arm/mach-socfpga/include/mach/clock_manager_dm.h

diff --git a/arch/arm/mach-socfpga/clock_manager_dm.c b/arch/arm/mach-socfpga/clock_manager_dm.c
new file mode 100644
index 0000000000..47a7693845
--- /dev/null
+++ b/arch/arm/mach-socfpga/clock_manager_dm.c
@@ -0,0 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ *
+ */
+
+#include <clk.h>
+#include <common.h>
+#include <dm.h>
+#include <malloc.h>
+#include <asm/arch/clock_manager.h>
+#include <asm/arch/system_manager.h>
+#include <asm/io.h>
+#include <dt-bindings/clock/dm-clock.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+static ulong cm_get_rate_dm(u32 id)
+{
+	struct udevice *dev;
+	struct clk clk;
+	ulong rate;
+	int ret;
+
+	ret = uclass_get_device_by_driver(UCLASS_CLK,
+					  DM_DRIVER_GET(socfpga_dm_clk),
+					  &dev);
+	if (ret)
+		return 0;
+
+	clk.id = id;
+	ret = clk_request(dev, &clk);
+	if (ret < 0)
+		return 0;
+
+	rate = clk_get_rate(&clk);
+
+	clk_free(&clk);
+
+	if ((rate == (unsigned long)-ENXIO) ||
+	    (rate == (unsigned long)-EIO)) {
+		debug("%s id %u: clk_get_rate err: %ld\n",
+		      __func__, id, rate);
+		return 0;
+	}
+
+	return rate;
+}
+
+static u32 cm_get_rate_dm_khz(u32 id)
+{
+	return cm_get_rate_dm(id) / 1000;
+}
+
+unsigned long cm_get_mpu_clk_hz(void)
+{
+	return cm_get_rate_dm(DM_MPU_CLK);
+}
+
+unsigned int cm_get_l4_sys_free_clk_hz(void)
+{
+	return cm_get_rate_dm(DM_L4_SYS_FREE_CLK);
+}
+
+void cm_print_clock_quick_summary(void)
+{
+	printf("MPU       %10d kHz\n",
+	       cm_get_rate_dm_khz(DM_MPU_CLK));
+	printf("L4 Main	    %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_MAIN_CLK));
+	printf("L4 sys free %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_SYS_FREE_CLK));
+	printf("L4 MP       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_MP_CLK));
+	printf("L4 SP       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_L4_SP_CLK));
+	printf("SDMMC       %8d kHz\n",
+	       cm_get_rate_dm_khz(DM_SDMMC_CLK));
+}
diff --git a/arch/arm/mach-socfpga/include/mach/clock_manager_dm.h b/arch/arm/mach-socfpga/include/mach/clock_manager_dm.h
new file mode 100644
index 0000000000..a355fda692
--- /dev/null
+++ b/arch/arm/mach-socfpga/include/mach/clock_manager_dm.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Copyright (C) 2020 Intel Corporation <www.intel.com>
+ */
+
+#ifndef _CLOCK_MANAGER_DM_
+#define _CLOCK_MANAGER_DM_
+
+unsigned long cm_get_mpu_clk_hz(void);
+
+#include <asm/arch/clock_manager_soc64.h>
+#include "../../../../../drivers/clk/altera/clk-dm.h"
+
+#endif /* _CLOCK_MANAGER_DM_ */
-- 
2.26.2


  parent reply	other threads:[~2022-09-18 12:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-18 12:17 [PATCH 1/9] drivers: clk: dm: Add clock driver for Diamond Mesa Jit Loon Lim
2022-09-18 12:17 ` [PATCH 2/9] drivers: clk: dm: Add memory " Jit Loon Lim
2022-09-18 12:17 ` Jit Loon Lim [this message]
2022-09-18 12:17 ` [PATCH 4/9] ddr: altera: dm: Add SDRAM " Jit Loon Lim
2022-09-18 12:17 ` [PATCH 5/9] arm: socfpga: dm: Add SPL " Jit Loon Lim
2022-09-18 12:17 ` [PATCH 6/9] board: intel: dm: Add socdk board support " Jit Loon Lim
2022-09-18 12:17 ` [PATCH 7/9] arm: dts: dm: Add base dtsi and devkit dts " Jit Loon Lim
2022-09-18 12:17 ` [PATCH 8/9] configs: dm: Add Diamond Mesa CONFIGs Jit Loon Lim
2022-09-18 12:17 ` [PATCH 9/9] arm: socfpga: dm: Enable Intel Diamond Mesa bulid Jit Loon Lim
2022-09-28 17:14 ` [PATCH 1/9] drivers: clk: dm: Add clock driver for Diamond Mesa Sean Anderson

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=20220918121751.26370-3-jit.loon.lim@intel.com \
    --to=jit.loon.lim@intel.com \
    --cc=alif.zakuan.yuslaimi@intel.com \
    --cc=boon.khai.ng@intel.com \
    --cc=dinesh.maniyam@intel.com \
    --cc=elly.siew.chin.lim@intel.com \
    --cc=jagan@amarulasolutions.com \
    --cc=kok.kiang.hea@intel.com \
    --cc=marex@denx.de \
    --cc=muhammad.hazim.izzat.zamri@intel.com \
    --cc=raaj.lokanathan@intel.com \
    --cc=sieu.mun.tang@intel.com \
    --cc=simon.k.r.goldschmidt@gmail.com \
    --cc=sin.hui.kho@intel.com \
    --cc=teik.heng.chong@intel.com \
    --cc=tien.fong.chee@intel.com \
    --cc=u-boot@lists.denx.de \
    --cc=vigneshr@ti.com \
    /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