mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: "open list:BAREBOX" <barebox@lists.infradead.org>
Subject: [PATCH 06/20] clocksource: timer-ti-dm: add support for K3 SoCs
Date: Fri, 29 Nov 2024 12:44:21 +0100	[thread overview]
Message-ID: <20241129-k3-r5-v1-6-67c4bb42a5c7@pengutronix.de> (raw)
In-Reply-To: <20241129-k3-r5-v1-0-67c4bb42a5c7@pengutronix.de>

K3 SoCs have a timer compatible to the ones found on the AM335x SoCs.
This patch adds support for these SoCs to the driver. The main
difference is that on AM335x we do not have clk support and get the
timer frequency from a SoC specific call, thus we have to play some
ifdeffery to add clk support for K3 and still keep the SoC specific
call to the AM335x code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/clocksource/timer-ti-dm.c | 53 +++++++++++++++++++++++++++++++++++----
 1 file changed, 48 insertions(+), 5 deletions(-)

diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
index 8473cf733d..eb658402f5 100644
--- a/drivers/clocksource/timer-ti-dm.c
+++ b/drivers/clocksource/timer-ti-dm.c
@@ -21,8 +21,8 @@
 #include <clock.h>
 #include <init.h>
 #include <io.h>
-#include <mach/omap/am33xx-silicon.h>
 #include <mach/omap/am33xx-clock.h>
+#include <linux/clk.h>
 
 #include <stdio.h>
 
@@ -65,10 +65,15 @@ static struct clocksource dmtimer_cs = {
 	.priority = 70,
 };
 
+struct omap_dmtimer_data {
+	int (*get_clock)(struct device *dev);
+};
+
 static int omap_dmtimer_probe(struct device *dev)
 {
 	struct resource *iores;
-	u64 clk_speed;
+	int clk_speed;
+	const struct omap_dmtimer_data *data;
 
 	/* one timer is enough */
 	if (base)
@@ -79,8 +84,12 @@ static int omap_dmtimer_probe(struct device *dev)
 		return PTR_ERR(iores);
 	base = IOMEM(iores->start);
 
-	clk_speed = am33xx_get_osc_clock();
-	clk_speed *= 1000;
+	data = device_get_match_data(dev);
+
+	clk_speed = data->get_clock(dev);
+	if (clk_speed < 0)
+		return clk_speed;
+
 	dmtimer_cs.mult = clocksource_hz2mult(clk_speed, dmtimer_cs.shift);
 
 	/* Enable counter */
@@ -89,10 +98,44 @@ static int omap_dmtimer_probe(struct device *dev)
 	return init_clock(&dmtimer_cs);
 }
 
+static int am335x_get_clock(struct device *dev)
+{
+	return am33xx_get_osc_clock() * 1000;
+}
+
+static __maybe_unused struct omap_dmtimer_data am335x_data = {
+	.get_clock = am335x_get_clock,
+};
+
+static int k3_get_clock(struct device *dev)
+{
+	struct clk *clk;
+
+	clk = clk_get(dev, NULL);
+	if (IS_ERR(clk))
+		return dev_err_probe(dev, PTR_ERR(clk), "Cannot get clock\n");
+
+	return clk_get_rate(clk);
+}
+
+static __maybe_unused struct omap_dmtimer_data k3_data = {
+	.get_clock = k3_get_clock,
+};
+
 static __maybe_unused struct of_device_id omap_dmtimer_dt_ids[] = {
+#ifdef CONFIG_ARCH_OMAP
 	{
 		.compatible = "ti,am335x-timer",
-	}, {
+		.data = &am335x_data,
+	},
+#endif
+#ifdef CONFIG_ARCH_K3
+	{
+		.compatible = "ti,am654-timer",
+		.data = &k3_data,
+	},
+#endif
+	{
 		/* sentinel */
 	}
 };

-- 
2.39.5




  parent reply	other threads:[~2024-11-29 11:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-29 11:44 [PATCH 00/20] ARM: K3: Add R5 boot support Sascha Hauer
2024-11-29 11:44 ` [PATCH 01/20] ARM: add ARMv7R MPU support Sascha Hauer
2024-11-29 11:44 ` [PATCH 02/20] lib/rationale: compile for pbl Sascha Hauer
2024-11-29 11:44 ` [PATCH 03/20] DDR: Add k3 DDR driver Sascha Hauer
2024-11-29 11:44 ` [PATCH 04/20] ARM: move ARM_CPU_PART_* defines to header Sascha Hauer
2024-11-29 11:44 ` [PATCH 05/20] nommu_v7_vectors_init: disable for r5 Sascha Hauer
2024-11-29 11:44 ` Sascha Hauer [this message]
2024-11-29 11:44 ` [PATCH 07/20] ARM: K3: mount /boot even with env handling disabled Sascha Hauer
2024-11-29 11:44 ` [PATCH 08/20] clk: add K3 clk driver Sascha Hauer
2024-11-29 11:44 ` [PATCH 09/20] pmdomain: add K3 driver Sascha Hauer
2024-11-29 11:44 ` [PATCH 10/20] rproc: add K3 arm64 rproc driver Sascha Hauer
2024-11-29 11:44 ` [PATCH 11/20] ARM: k3: add k3_debug_ll_init() Sascha Hauer
2024-11-29 11:44 ` [PATCH 12/20] ARM: K3: use debug_ll code for regular PBL console Sascha Hauer
2024-11-29 11:44 ` [PATCH 13/20] elf: use iomem regions as fallback when loading to non-sdram memory Sascha Hauer
2024-11-29 11:44 ` [PATCH 14/20] rproc: add K3 system_controller Sascha Hauer
2024-11-29 11:44 ` [PATCH 15/20] firmware: ti_sci: add function to get global handle Sascha Hauer
2024-11-29 11:44 ` [PATCH 16/20] ARM: k3: Add initial r5 support Sascha Hauer
2024-11-29 11:44 ` [PATCH 17/20] ARM: k3: Add k3img tool Sascha Hauer
2024-11-29 11:44 ` [PATCH 18/20] ARM: beagleplay: add binary files Sascha Hauer
2024-11-29 11:44 ` [PATCH 19/20] ARM: beagleplay: add Cortex-R5 boot support Sascha Hauer
2024-11-29 11:44 ` [PATCH 20/20] Documentation: add build documentation for TI K3 SoCs Sascha Hauer

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=20241129-k3-r5-v1-6-67c4bb42a5c7@pengutronix.de \
    --to=s.hauer@pengutronix.de \
    --cc=barebox@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