#include <linux/of_irq.h>
#include <linux/slab.h>
#include <linux/clk-provider.h>
-#include "common.h"
/*
* This driver configures the 2 16-bit count-up timers as follows:
ttccs->xttc.clk = clk;
err = clk_prepare_enable(ttccs->xttc.clk);
- if (WARN_ON(err))
+ if (WARN_ON(err)) {
+ kfree(ttccs);
return;
+ }
ttccs->xttc.clk_rate_change_nb.notifier_call =
xttcps_rate_change_clocksource_cb;
err = clocksource_register_hz(&ttccs->cs,
clk_get_rate(ttccs->xttc.clk) / PRESCALE);
- if (WARN_ON(err))
+ if (WARN_ON(err)) {
+ kfree(ttccs);
return;
-
+ }
}
static int xttcps_rate_change_clockevent_cb(struct notifier_block *nb,
ttcce->xttc.clk = clk;
err = clk_prepare_enable(ttcce->xttc.clk);
- if (WARN_ON(err))
+ if (WARN_ON(err)) {
+ kfree(ttcce);
return;
+ }
ttcce->xttc.clk_rate_change_nb.notifier_call =
xttcps_rate_change_clockevent_cb;
err = request_irq(irq, xttcps_clock_event_interrupt,
IRQF_DISABLED | IRQF_TIMER,
ttcce->ce.name, ttcce);
- if (WARN_ON(err))
+ if (WARN_ON(err)) {
+ kfree(ttcce);
return;
+ }
clockevents_config_and_register(&ttcce->ce,
clk_get_rate(ttcce->xttc.clk) / PRESCALE, 1, 0xfffe);
* Initializes the timer hardware and register the clock source and clock event
* timers with Linux kernal timer framework
*/
-static void __init xttcps_timer_init_of(struct device_node *timer)
+static void __init xttcps_timer_init(struct device_node *timer)
{
unsigned int irq;
void __iomem *timer_baseaddr;
struct clk *clk;
+ static int initialized;
+
+ if (initialized)
+ return;
+
+ initialized = 1;
/*
* Get the 1st Triple Timer Counter (TTC) block from the device tree
pr_info("%s #0 at %p, irq=%d\n", timer->name, timer_baseaddr, irq);
}
-void __init xttcps_timer_init(void)
-{
- const char * const timer_list[] = {
- "cdns,ttc",
- NULL
- };
- struct device_node *timer;
-
- timer = of_find_compatible_node(NULL, NULL, timer_list[0]);
- if (!timer) {
- pr_err("ERROR: no compatible timer found\n");
- BUG();
- }
-
- xttcps_timer_init_of(timer);
-}
+CLOCKSOURCE_OF_DECLARE(ttc, "cdns,ttc", xttcps_timer_init);