* [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment
2025-06-23 19:24 [PATCH 0/3] clocksource/drivers/timer-ti-dm: Add clocksource and clockevent support Markus Schneider-Pargmann
@ 2025-06-23 19:24 ` Markus Schneider-Pargmann
2025-06-24 10:27 ` Dhruva Gole
2025-06-25 19:58 ` Kevin Hilman
2025-06-23 19:24 ` [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support Markus Schneider-Pargmann
2025-06-23 19:24 ` [PATCH 3/3] clocksource/drivers/timer-ti-dm: Add clockevent support Markus Schneider-Pargmann
2 siblings, 2 replies; 7+ messages in thread
From: Markus Schneider-Pargmann @ 2025-06-23 19:24 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Vishal Mahaveer, Kevin Hilman, Dhruva Gole, Sebin Francis,
Kendall Willis, Akashdeep Kaur, linux-kernel,
Markus Schneider-Pargmann
ti,always-on property doesn't exist. ti,timer-alwon is meant here. Fix
this minor bug in the comment.
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
drivers/clocksource/timer-ti-dm-systimer.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
index 985a6d08512b42f499b3e243eb69cc9674bc8e53..fb0a3cc23b5a35e2906a253d36ccef2baccca50a 100644
--- a/drivers/clocksource/timer-ti-dm-systimer.c
+++ b/drivers/clocksource/timer-ti-dm-systimer.c
@@ -226,7 +226,7 @@ static bool __init dmtimer_is_preferred(struct device_node *np)
* Some omap3 boards with unreliable oscillator must not use the counter_32k
* or dmtimer1 with 32 KiHz source. Additionally, the boards with unreliable
* oscillator should really set counter_32k as disabled, and delete dmtimer1
- * ti,always-on property, but let's not count on it. For these quirky cases,
+ * ti,timer-alwon property, but let's not count on it. For these quirky cases,
* we prefer using the always-on secure dmtimer12 with the internal 32 KiHz
* clock as the clocksource, and any available dmtimer as clockevent.
*
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment
2025-06-23 19:24 ` [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment Markus Schneider-Pargmann
@ 2025-06-24 10:27 ` Dhruva Gole
2025-06-25 19:58 ` Kevin Hilman
1 sibling, 0 replies; 7+ messages in thread
From: Dhruva Gole @ 2025-06-24 10:27 UTC (permalink / raw)
To: Markus Schneider-Pargmann
Cc: Daniel Lezcano, Thomas Gleixner, Vishal Mahaveer, Kevin Hilman,
Sebin Francis, Kendall Willis, Akashdeep Kaur, linux-kernel
On Jun 23, 2025 at 21:24:28 +0200, Markus Schneider-Pargmann wrote:
> ti,always-on property doesn't exist. ti,timer-alwon is meant here. Fix
> this minor bug in the comment.
>
> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
> ---
> drivers/clocksource/timer-ti-dm-systimer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
> index 985a6d08512b42f499b3e243eb69cc9674bc8e53..fb0a3cc23b5a35e2906a253d36ccef2baccca50a 100644
> --- a/drivers/clocksource/timer-ti-dm-systimer.c
> +++ b/drivers/clocksource/timer-ti-dm-systimer.c
> @@ -226,7 +226,7 @@ static bool __init dmtimer_is_preferred(struct device_node *np)
> * Some omap3 boards with unreliable oscillator must not use the counter_32k
> * or dmtimer1 with 32 KiHz source. Additionally, the boards with unreliable
> * oscillator should really set counter_32k as disabled, and delete dmtimer1
> - * ti,always-on property, but let's not count on it. For these quirky cases,
> + * ti,timer-alwon property, but let's not count on it. For these quirky cases,
Reviewed-by: Dhruva Gole <d-gole@ti.com>
--
Best regards,
Dhruva Gole
Texas Instruments Incorporated
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment
2025-06-23 19:24 ` [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment Markus Schneider-Pargmann
2025-06-24 10:27 ` Dhruva Gole
@ 2025-06-25 19:58 ` Kevin Hilman
1 sibling, 0 replies; 7+ messages in thread
From: Kevin Hilman @ 2025-06-25 19:58 UTC (permalink / raw)
To: Markus Schneider-Pargmann, Daniel Lezcano, Thomas Gleixner
Cc: Vishal Mahaveer, Dhruva Gole, Sebin Francis, Kendall Willis,
Akashdeep Kaur, linux-kernel, Markus Schneider-Pargmann
Markus Schneider-Pargmann <msp@baylibre.com> writes:
> ti,always-on property doesn't exist. ti,timer-alwon is meant here. Fix
> this minor bug in the comment.
>
> Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
Reviewed-by: Kevin Hilman <khilman@baylibre.com>
> ---
> drivers/clocksource/timer-ti-dm-systimer.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/clocksource/timer-ti-dm-systimer.c b/drivers/clocksource/timer-ti-dm-systimer.c
> index 985a6d08512b42f499b3e243eb69cc9674bc8e53..fb0a3cc23b5a35e2906a253d36ccef2baccca50a 100644
> --- a/drivers/clocksource/timer-ti-dm-systimer.c
> +++ b/drivers/clocksource/timer-ti-dm-systimer.c
> @@ -226,7 +226,7 @@ static bool __init dmtimer_is_preferred(struct device_node *np)
> * Some omap3 boards with unreliable oscillator must not use the counter_32k
> * or dmtimer1 with 32 KiHz source. Additionally, the boards with unreliable
> * oscillator should really set counter_32k as disabled, and delete dmtimer1
> - * ti,always-on property, but let's not count on it. For these quirky cases,
> + * ti,timer-alwon property, but let's not count on it. For these quirky cases,
> * we prefer using the always-on secure dmtimer12 with the internal 32 KiHz
> * clock as the clocksource, and any available dmtimer as clockevent.
> *
>
> --
> 2.49.0
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support
2025-06-23 19:24 [PATCH 0/3] clocksource/drivers/timer-ti-dm: Add clocksource and clockevent support Markus Schneider-Pargmann
2025-06-23 19:24 ` [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment Markus Schneider-Pargmann
@ 2025-06-23 19:24 ` Markus Schneider-Pargmann
2025-06-24 15:51 ` kernel test robot
2025-06-23 19:24 ` [PATCH 3/3] clocksource/drivers/timer-ti-dm: Add clockevent support Markus Schneider-Pargmann
2 siblings, 1 reply; 7+ messages in thread
From: Markus Schneider-Pargmann @ 2025-06-23 19:24 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Vishal Mahaveer, Kevin Hilman, Dhruva Gole, Sebin Francis,
Kendall Willis, Akashdeep Kaur, linux-kernel,
Markus Schneider-Pargmann
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 <msp@baylibre.com>
---
drivers/clocksource/timer-ti-dm.c | 137 +++++++++++++++++++++++++++++++++++++-
1 file changed, 136 insertions(+), 1 deletion(-)
diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
index e9e32df6b56664bc0bd94050380314a757d05ebd..085609ba2d249dcc8f53c8aaa831d8fbe69b3753 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>
@@ -27,8 +28,10 @@
#include <linux/err.h>
#include <linux/pm_runtime.h>
#include <linux/of.h>
+#include <linux/of_address.h>
#include <linux/platform_device.h>
#include <linux/platform_data/dmtimer-omap.h>
+#include <linux/sched_clock.h>
#include <clocksource/timer-ti-dm.h>
@@ -141,12 +144,23 @@ struct dmtimer {
struct notifier_block nb;
struct notifier_block fclk_nb;
unsigned long fclk_rate;
+
+ struct dmtimer_clocksource *clksrc;
};
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 resource_size_t omap_dm_timer_clocksource_base;
+static void __iomem *omap_dm_timer_sched_clock_counter;
+
enum {
REQUEST_ANY = 0,
REQUEST_BY_ID,
@@ -1073,6 +1087,107 @@ static const struct dev_pm_ops omap_dm_timer_pm_ops = {
static const struct of_device_id omap_timer_match[];
+static void omap_dm_timer_find_alwon(void)
+{
+ struct device_node *np;
+
+ for_each_matching_node(np, omap_timer_match) {
+ struct resource res;
+
+ if (!of_device_is_available(np))
+ continue;
+
+ if (!of_property_read_bool(np, "ti,timer-alwon"))
+ continue;
+
+ if (of_address_to_resource(np, 0, &res))
+ continue;
+
+ omap_dm_timer_clocksource_base = res.start;
+
+ of_node_put(np);
+ return;
+ }
+
+ omap_dm_timer_clocksource_base = -1;
+}
+
+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 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;
+ timer->clksrc = clksrc;
+
+ 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");
+
+ return 0;
+}
+
/**
* omap_dm_timer_probe - probe function called for every registered device
* @pdev: pointer to current timer platform device
@@ -1086,8 +1201,12 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
struct dmtimer *timer;
struct device *dev = &pdev->dev;
const struct dmtimer_platform_data *pdata;
+ struct resource *res;
int ret;
+ if (!omap_dm_timer_clocksource_base)
+ omap_dm_timer_find_alwon();
+
pdata = of_device_get_match_data(dev);
if (!pdata)
pdata = dev_get_platdata(dev);
@@ -1160,6 +1279,16 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
timer->pdev = pdev;
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+
+ if (omap_dm_timer_clocksource_base && res &&
+ res->start == omap_dm_timer_clocksource_base &&
+ !IS_ERR_OR_NULL(timer->fclk)) {
+ ret = omap_dm_timer_setup_clocksource(timer);
+ if (ret)
+ return ret;
+ }
+
pm_runtime_enable(dev);
if (!timer->reserved) {
@@ -1187,6 +1316,9 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
return 0;
err_disable:
+ if (timer->clksrc)
+ clocksource_unregister(&timer->clksrc->dev);
+
pm_runtime_disable(dev);
return ret;
}
@@ -1201,10 +1333,13 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
*/
static void omap_dm_timer_remove(struct platform_device *pdev)
{
- struct dmtimer *timer;
+ struct dmtimer *timer = dev_get_drvdata(&pdev->dev);
unsigned long flags;
int ret = -EINVAL;
+ if (timer->clksrc)
+ clocksource_unregister(&timer->clksrc->dev);
+
spin_lock_irqsave(&dm_timer_lock, flags);
list_for_each_entry(timer, &omap_timer_list, node)
if (!strcmp(dev_name(&timer->pdev->dev),
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support
2025-06-23 19:24 ` [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support Markus Schneider-Pargmann
@ 2025-06-24 15:51 ` kernel test robot
0 siblings, 0 replies; 7+ messages in thread
From: kernel test robot @ 2025-06-24 15:51 UTC (permalink / raw)
To: Markus Schneider-Pargmann, Daniel Lezcano, Thomas Gleixner
Cc: oe-kbuild-all, Vishal Mahaveer, Kevin Hilman, Dhruva Gole,
Sebin Francis, Kendall Willis, Akashdeep Kaur, linux-kernel,
Markus Schneider-Pargmann
Hi Markus,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 19272b37aa4f83ca52bdf9c16d5d81bdd1354494]
url: https://github.com/intel-lab-lkp/linux/commits/Markus-Schneider-Pargmann/clocksource-drivers-timer-ti-dm-Fix-property-name-in-comment/20250624-032923
base: 19272b37aa4f83ca52bdf9c16d5d81bdd1354494
patch link: https://lore.kernel.org/r/20250623-topic-ti-dm-clkevt-v6-16-v1-2-b00086761ee1%40baylibre.com
patch subject: [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support
config: arm64-randconfig-002-20250624 (https://download.01.org/0day-ci/archive/20250624/202506242304.M75bDdRW-lkp@intel.com/config)
compiler: aarch64-linux-gcc (GCC) 10.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250624/202506242304.M75bDdRW-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202506242304.M75bDdRW-lkp@intel.com/
All warnings (new ones prefixed by >>, old ones prefixed by <<):
>> WARNING: modpost: vmlinux: section mismatch in reference: omap_dm_timer_setup_clocksource+0x634 (section: .text) -> sched_clock_register (section: .init.text)
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 3/3] clocksource/drivers/timer-ti-dm: Add clockevent support
2025-06-23 19:24 [PATCH 0/3] clocksource/drivers/timer-ti-dm: Add clocksource and clockevent support Markus Schneider-Pargmann
2025-06-23 19:24 ` [PATCH 1/3] clocksource/drivers/timer-ti-dm: Fix property name in comment Markus Schneider-Pargmann
2025-06-23 19:24 ` [PATCH 2/3] clocksource/drivers/timer-ti-dm: Add clocksource support Markus Schneider-Pargmann
@ 2025-06-23 19:24 ` Markus Schneider-Pargmann
2 siblings, 0 replies; 7+ messages in thread
From: Markus Schneider-Pargmann @ 2025-06-23 19:24 UTC (permalink / raw)
To: Daniel Lezcano, Thomas Gleixner
Cc: Vishal Mahaveer, Kevin Hilman, Dhruva Gole, Sebin Francis,
Kendall Willis, Akashdeep Kaur, linux-kernel,
Markus Schneider-Pargmann
Add support for using the TI Dual-Mode Timer for clockevents. The second
always on device with the "ti,timer-alwon" property is selected to be
used for clockevents. The first one is used as clocksource.
This allows clockevents to be setup independently of the CPU.
Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
---
drivers/clocksource/timer-ti-dm.c | 138 ++++++++++++++++++++++++++++++++++++--
1 file changed, 133 insertions(+), 5 deletions(-)
diff --git a/drivers/clocksource/timer-ti-dm.c b/drivers/clocksource/timer-ti-dm.c
index 085609ba2d249dcc8f53c8aaa831d8fbe69b3753..a17e3e81508793a46cdee815bde3ad17fedd55e7 100644
--- a/drivers/clocksource/timer-ti-dm.c
+++ b/drivers/clocksource/timer-ti-dm.c
@@ -21,8 +21,10 @@
#include <linux/clk.h>
#include <linux/clk-provider.h>
#include <linux/clocksource.h>
+#include <linux/clockchips.h>
#include <linux/cpu_pm.h>
#include <linux/module.h>
+#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/device.h>
#include <linux/err.h>
@@ -158,7 +160,14 @@ struct dmtimer_clocksource {
unsigned int loadval;
};
+struct omap_dm_timer_clockevent {
+ struct clock_event_device dev;
+ struct dmtimer *timer;
+ u32 period;
+};
+
static resource_size_t omap_dm_timer_clocksource_base;
+static resource_size_t omap_dm_timer_clockevent_base;
static void __iomem *omap_dm_timer_sched_clock_counter;
enum {
@@ -1091,6 +1100,9 @@ static void omap_dm_timer_find_alwon(void)
{
struct device_node *np;
+ if (omap_dm_timer_clocksource_base && omap_dm_timer_clockevent_base)
+ return;
+
for_each_matching_node(np, omap_timer_match) {
struct resource res;
@@ -1103,13 +1115,22 @@ static void omap_dm_timer_find_alwon(void)
if (of_address_to_resource(np, 0, &res))
continue;
- omap_dm_timer_clocksource_base = res.start;
+ if (!omap_dm_timer_clocksource_base) {
+ omap_dm_timer_clocksource_base = res.start;
+ continue;
+ }
- of_node_put(np);
- return;
+ if (res.start != omap_dm_timer_clocksource_base) {
+ omap_dm_timer_clockevent_base = res.start;
+
+ of_node_put(np);
+ return;
+ }
}
- omap_dm_timer_clocksource_base = -1;
+ if (!omap_dm_timer_clocksource_base)
+ omap_dm_timer_clocksource_base = -1;
+ omap_dm_timer_clockevent_base = -1;
}
static struct dmtimer_clocksource *omap_dm_timer_to_clocksource(struct clocksource *cs)
@@ -1188,6 +1209,105 @@ static int omap_dm_timer_setup_clocksource(struct dmtimer *timer)
return 0;
}
+static struct omap_dm_timer_clockevent *to_dm_timer_clockevent(struct clock_event_device *evt)
+{
+ return container_of(evt, struct omap_dm_timer_clockevent, dev);
+}
+
+static int omap_dm_timer_evt_set_next_event(unsigned long cycles,
+ struct clock_event_device *evt)
+{
+ struct omap_dm_timer_clockevent *clkevt = to_dm_timer_clockevent(evt);
+ struct dmtimer *timer = clkevt->timer;
+
+ dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, 0xffffffff - cycles);
+ dmtimer_write(timer, OMAP_TIMER_CTRL_REG, OMAP_TIMER_CTRL_ST);
+
+ return 0;
+}
+
+static int omap_dm_timer_evt_shutdown(struct clock_event_device *evt)
+{
+ struct omap_dm_timer_clockevent *clkevt = to_dm_timer_clockevent(evt);
+ struct dmtimer *timer = clkevt->timer;
+
+ __omap_dm_timer_stop(timer);
+
+ return 0;
+}
+
+static int omap_dm_timer_evt_set_periodic(struct clock_event_device *evt)
+{
+ struct omap_dm_timer_clockevent *clkevt = to_dm_timer_clockevent(evt);
+ struct dmtimer *timer = clkevt->timer;
+
+ omap_dm_timer_evt_shutdown(evt);
+
+ omap_dm_timer_set_load(&timer->cookie, clkevt->period);
+ dmtimer_write(timer, OMAP_TIMER_COUNTER_REG, clkevt->period);
+ dmtimer_write(timer, OMAP_TIMER_CTRL_REG,
+ OMAP_TIMER_CTRL_AR | OMAP_TIMER_CTRL_ST);
+
+ return 0;
+}
+
+static irqreturn_t omap_dm_timer_evt_interrupt(int irq, void *dev_id)
+{
+ struct omap_dm_timer_clockevent *clkevt = dev_id;
+ struct dmtimer *timer = clkevt->timer;
+
+ __omap_dm_timer_write_status(timer, OMAP_TIMER_INT_OVERFLOW);
+
+ clkevt->dev.event_handler(&clkevt->dev);
+
+ return IRQ_HANDLED;
+}
+
+static int omap_dm_timer_setup_clockevent(struct dmtimer *timer)
+{
+ struct device *dev = &timer->pdev->dev;
+ struct omap_dm_timer_clockevent *clkevt;
+ int ret;
+
+ clkevt = devm_kzalloc(dev, sizeof(*clkevt), GFP_KERNEL);
+ if (!clkevt)
+ return -ENOMEM;
+
+ timer->reserved = 1;
+ clkevt->timer = timer;
+
+ clkevt->dev.name = "omap_dm_timer";
+ clkevt->dev.features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
+ clkevt->dev.rating = 300;
+ clkevt->dev.set_next_event = omap_dm_timer_evt_set_next_event;
+ clkevt->dev.set_state_shutdown = omap_dm_timer_evt_shutdown;
+ clkevt->dev.set_state_periodic = omap_dm_timer_evt_set_periodic;
+ clkevt->dev.set_state_oneshot = omap_dm_timer_evt_shutdown;
+ clkevt->dev.set_state_oneshot_stopped = omap_dm_timer_evt_shutdown;
+ clkevt->dev.tick_resume = omap_dm_timer_evt_shutdown;
+ clkevt->dev.cpumask = cpu_possible_mask;
+ clkevt->period = 0xffffffff - DIV_ROUND_CLOSEST(timer->fclk_rate, HZ);
+
+ __omap_dm_timer_init_regs(timer);
+ __omap_dm_timer_stop(timer);
+ __omap_dm_timer_enable_posted(timer);
+
+ ret = devm_request_irq(dev, timer->irq, omap_dm_timer_evt_interrupt,
+ IRQF_TIMER, "omap_dm_timer_clockevent", clkevt);
+ if (ret) {
+ dev_err(dev, "Failed to request interrupt: %d\n", ret);
+ return ret;
+ }
+
+ __omap_dm_timer_int_enable(timer, OMAP_TIMER_INT_OVERFLOW);
+
+ clockevents_config_and_register(&clkevt->dev, timer->fclk_rate,
+ 3,
+ 0xffffffff);
+
+ return 0;
+}
+
/**
* omap_dm_timer_probe - probe function called for every registered device
* @pdev: pointer to current timer platform device
@@ -1204,7 +1324,7 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
struct resource *res;
int ret;
- if (!omap_dm_timer_clocksource_base)
+ if (!omap_dm_timer_clocksource_base || !omap_dm_timer_clockevent_base)
omap_dm_timer_find_alwon();
pdata = of_device_get_match_data(dev);
@@ -1281,6 +1401,14 @@ static int omap_dm_timer_probe(struct platform_device *pdev)
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (omap_dm_timer_clockevent_base && res &&
+ res->start == omap_dm_timer_clockevent_base &&
+ !IS_ERR_OR_NULL(timer->fclk)) {
+ ret = omap_dm_timer_setup_clockevent(timer);
+ if (ret)
+ return ret;
+ }
+
if (omap_dm_timer_clocksource_base && res &&
res->start == omap_dm_timer_clocksource_base &&
!IS_ERR_OR_NULL(timer->fclk)) {
--
2.49.0
^ permalink raw reply related [flat|nested] 7+ messages in thread