From: "tip-bot2 for Markus Schneider-Pargmann (TI)" <tip-bot2@linutronix.de>
To: linux-tip-commits@vger.kernel.org
Cc: "Markus Schneider-Pargmann (TI)" <msp@baylibre.com>,
Daniel Lezcano <daniel.lezcano@kernel.org>,
x86@kernel.org, linux-kernel@vger.kernel.org
Subject: [tip: timers/clocksource] clocksource/drivers/timer-ti-dm: Add clocksource support
Date: Sat, 13 Jun 2026 14:33:05 -0000 [thread overview]
Message-ID: <178136118597.1650852.2924579907696443774.tip-bot2@tip-bot2> (raw)
In-Reply-To: <20260508-topic-ti-dm-clkevt-v6-16-v5-2-61d546a0aff9@baylibre.com>
The following commit has been merged into the timers/clocksource branch of tip:
Commit-ID: b8eeeca5545659c5d67264b151784e74b18c8254
Gitweb: https://git.kernel.org/tip/b8eeeca5545659c5d67264b151784e74b18c8254
Author: Markus Schneider-Pargmann (TI) <msp@baylibre.com>
AuthorDate: Fri, 08 May 2026 15:39:28 +02:00
Committer: Daniel Lezcano <daniel.lezcano@kernel.org>
CommitterDate: Wed, 03 Jun 2026 10:05:47 +02:00
clocksource/drivers/timer-ti-dm: Add clocksource support
Add support for using the TI Dual-Mode Timer as a clocksource. The
driver automatically picks the first timer that is marked as always-on
on with the "ti,timer-alwon" property to be the clocksource.
The timer can then be used for CPU independent time keeping.
Signed-off-by: Markus Schneider-Pargmann (TI) <msp@baylibre.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@kernel.org>
Link: https://patch.msgid.link/20260508-topic-ti-dm-clkevt-v6-16-v5-2-61d546a0aff9@baylibre.com
---
drivers/clocksource/timer-ti-dm.c | 103 +++++++++++++++++++++++++++++-
1 file changed, 103 insertions(+)
diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
index 793e7cd..98cc343 100644
--- a/drivers/clocksource/timer-ti-dm.c
+++ b/drivers/clocksource/timer-ti-dm.c
@@ -20,6 +20,7 @@
#include <linux/clk.h>
#include <linux/clk-provider.h>
+#include <linux/clocksource.h>
#include <linux/cpu_pm.h>
#include <linux/module.h>
#include <linux/io.h>
@@ -29,6 +30,7 @@
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/platform_data/dmtimer-omap.h>
+#include <linux/sched_clock.h>
#include <clocksource/timer-ti-dm.h>
#include <linux/delay.h>
@@ -148,6 +150,14 @@ static u32 omap_reserved_systimers;
static LIST_HEAD(omap_timer_list);
static DEFINE_SPINLOCK(dm_timer_lock);
+struct dmtimer_clocksource {
+ struct clocksource dev;
+ struct dmtimer *timer;
+ unsigned int loadval;
+};
+
+static void __iomem *omap_dm_timer_sched_clock_counter;
+
enum {
REQUEST_ANY = 0,
REQUEST_BY_ID,
@@ -1185,6 +1195,92 @@ static const struct dev_pm_ops omap_dm_timer_pm_ops = {
static const struct of_device_id omap_timer_match[];
+static struct dmtimer_clocksource *omap_dm_timer_to_clocksource(struct clocksource *cs)
+{
+ return container_of(cs, struct dmtimer_clocksource, dev);
+}
+
+static u64 omap_dm_timer_read_cycles(struct clocksource *cs)
+{
+ struct dmtimer_clocksource *clksrc = omap_dm_timer_to_clocksource(cs);
+ struct dmtimer *timer = clksrc->timer;
+
+ return (u64)__omap_dm_timer_read_counter(timer);
+}
+
+static u64 notrace omap_dm_timer_read_sched_clock(void)
+{
+ /* Posted mode is not active here, so we can read directly */
+ return readl_relaxed(omap_dm_timer_sched_clock_counter);
+}
+
+static void omap_dm_timer_clocksource_suspend(struct clocksource *cs)
+{
+ struct dmtimer_clocksource *clksrc = omap_dm_timer_to_clocksource(cs);
+ struct dmtimer *timer = clksrc->timer;
+
+ clksrc->loadval = __omap_dm_timer_read_counter(timer);
+ __omap_dm_timer_stop(timer);
+}
+
+static void omap_dm_timer_clocksource_resume(struct clocksource *cs)
+{
+ struct dmtimer_clocksource *clksrc = omap_dm_timer_to_clocksource(cs);
+ struct dmtimer *timer = clksrc->timer;
+
+ dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, clksrc->loadval);
+ dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR);
+}
+
+static void omap_dm_timer_clocksource_unregister(void *data)
+{
+ struct clocksource *cs = data;
+
+ clocksource_unregister(cs);
+}
+
+static int omap_dm_timer_setup_clocksource(struct dmtimer *timer)
+{
+ struct device *dev = &timer->pdev->dev;
+ struct dmtimer_clocksource *clksrc;
+ int err;
+
+ __omap_dm_timer_init_regs(timer);
+
+ timer->reserved = 1;
+
+ clksrc = devm_kzalloc(dev, sizeof(*clksrc), GFP_KERNEL);
+ if (!clksrc)
+ return -ENOMEM;
+
+ clksrc->timer = timer;
+
+ clksrc->dev.name = "omap_dm_timer";
+ clksrc->dev.rating = 300;
+ clksrc->dev.read = omap_dm_timer_read_cycles;
+ clksrc->dev.mask = CLOCKSOURCE_MASK(32);
+ clksrc->dev.flags = CLOCK_SOURCE_IS_CONTINUOUS;
+ clksrc->dev.suspend = omap_dm_timer_clocksource_suspend;
+ clksrc->dev.resume = omap_dm_timer_clocksource_resume;
+
+ dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, 0);
+ dmtimer_write(timer, OMAP_TIMER_LOAD_REG, 0);
+ dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST | OMAP_TIMER_CTRL_AR);
+
+ omap_dm_timer_sched_clock_counter = timer->func_base + _OMAP_TIMER_COUNTER_OFFSET;
+ sched_clock_register(omap_dm_timer_read_sched_clock, 32, timer->fclk_rate);
+
+ err = clocksource_register_hz(&clksrc->dev, timer->fclk_rate);
+ if (err)
+ return dev_err_probe(dev, err, "Could not register as clocksource\n");
+
+ err = devm_add_action_or_reset(dev, omap_dm_timer_clocksource_unregister, &clksrc->dev);
+ if (err)
+ return dev_err_probe(dev, err, "Could not register clocksource_unregister action\n");
+
+ return 0;
+}
+
/**
* omap_dm_timer_probe - probe function called for every registered device
* @pdev: pointer to current timer platform device
@@ -1272,6 +1368,13 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
timer->pdev = pdev;
+ if (timer->capability & OMAP_TIMER_ALWON && !IS_ERR_OR_NULL(timer->fclk) &&
+ !omap_dm_timer_sched_clock_counter) {
+ ret = omap_dm_timer_setup_clocksource(timer);
+ if (ret)
+ return ret;
+ }
+
pm_runtime_enable(dev);
if (!timer->reserved) {
next prev parent reply other threads:[~2026-06-13 14:33 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-08 13:39 [PATCH v5 0/3] clocksource/drivers/timer-ti-dm: Add clocksource and clockevent support Markus Schneider-Pargmann (TI)
2026-05-08 13:39 ` [PATCH v5 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment Markus Schneider-Pargmann (TI)
2026-06-13 14:33 ` [tip: timers/clocksource] " tip-bot2 for Markus Schneider-Pargmann (TI)
2026-05-08 13:39 ` [PATCH v5 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support Markus Schneider-Pargmann (TI)
2026-06-13 14:33 ` tip-bot2 for Markus Schneider-Pargmann (TI) [this message]
2026-05-08 13:39 ` [PATCH v5 3/3] clocksource/drivers/timer-ti-dm: Add clockevent support Markus Schneider-Pargmann (TI)
2026-06-13 14:33 ` [tip: timers/clocksource] " tip-bot2 for Markus Schneider-Pargmann (TI)
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=178136118597.1650852.2924579907696443774.tip-bot2@tip-bot2 \
--to=tip-bot2@linutronix.de \
--cc=daniel.lezcano@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-tip-commits@vger.kernel.org \
--cc=msp@baylibre.com \
--cc=x86@kernel.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
all inboxes | Powered by JetHome®