Commit 4d70c59b authored by Stephen Boyd's avatar Stephen Boyd

ARM: msm: Divorce msm_timer from local timer API

Separate the msm_timer from the local timer API. This will allow
us to remove ARM local timer support in the near future and gets
us closer to moving this driver to drivers/clocksource.
Acked-by: default avatarDavid Brown <davidb@codeaurora.org>
Acked-by: default avatarMarc Zyngier <marc.zyngier@arm.com>
Cc: Daniel Walker <dwalker@fifo99.com>
Cc: Bryan Huntsman <bryanh@codeaurora.org>
Signed-off-by: default avatarStephen Boyd <sboyd@codeaurora.org>
parent 05a65485
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/clocksource.h> #include <linux/clocksource.h>
#include <linux/clockchips.h> #include <linux/clockchips.h>
#include <linux/cpu.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/interrupt.h> #include <linux/interrupt.h>
#include <linux/irq.h> #include <linux/irq.h>
...@@ -26,7 +27,6 @@ ...@@ -26,7 +27,6 @@
#include <linux/sched_clock.h> #include <linux/sched_clock.h>
#include <asm/mach/time.h> #include <asm/mach/time.h>
#include <asm/localtimer.h>
#include "common.h" #include "common.h"
...@@ -49,7 +49,7 @@ static void __iomem *sts_base; ...@@ -49,7 +49,7 @@ static void __iomem *sts_base;
static irqreturn_t msm_timer_interrupt(int irq, void *dev_id) static irqreturn_t msm_timer_interrupt(int irq, void *dev_id)
{ {
struct clock_event_device *evt = *(struct clock_event_device **)dev_id; struct clock_event_device *evt = dev_id;
/* Stop the timer tick */ /* Stop the timer tick */
if (evt->mode == CLOCK_EVT_MODE_ONESHOT) { if (evt->mode == CLOCK_EVT_MODE_ONESHOT) {
u32 ctrl = readl_relaxed(event_base + TIMER_ENABLE); u32 ctrl = readl_relaxed(event_base + TIMER_ENABLE);
...@@ -101,18 +101,7 @@ static void msm_timer_set_mode(enum clock_event_mode mode, ...@@ -101,18 +101,7 @@ static void msm_timer_set_mode(enum clock_event_mode mode,
writel_relaxed(ctrl, event_base + TIMER_ENABLE); writel_relaxed(ctrl, event_base + TIMER_ENABLE);
} }
static struct clock_event_device msm_clockevent = { static struct clock_event_device __percpu *msm_evt;
.name = "gp_timer",
.features = CLOCK_EVT_FEAT_ONESHOT,
.rating = 200,
.set_next_event = msm_timer_set_next_event,
.set_mode = msm_timer_set_mode,
};
static union {
struct clock_event_device *evt;
struct clock_event_device * __percpu *percpu_evt;
} msm_evt;
static void __iomem *source_base; static void __iomem *source_base;
...@@ -138,37 +127,65 @@ static struct clocksource msm_clocksource = { ...@@ -138,37 +127,65 @@ static struct clocksource msm_clocksource = {
.flags = CLOCK_SOURCE_IS_CONTINUOUS, .flags = CLOCK_SOURCE_IS_CONTINUOUS,
}; };
#ifdef CONFIG_LOCAL_TIMERS static int msm_timer_irq;
static int msm_timer_has_ppi;
static int __cpuinit msm_local_timer_setup(struct clock_event_device *evt) static int __cpuinit msm_local_timer_setup(struct clock_event_device *evt)
{ {
/* Use existing clock_event for cpu 0 */ int cpu = smp_processor_id();
if (!smp_processor_id()) int err;
return 0;
evt->irq = msm_timer_irq;
evt->irq = msm_clockevent.irq; evt->name = "msm_timer";
evt->name = "local_timer"; evt->features = CLOCK_EVT_FEAT_ONESHOT;
evt->features = msm_clockevent.features; evt->rating = 200;
evt->rating = msm_clockevent.rating;
evt->set_mode = msm_timer_set_mode; evt->set_mode = msm_timer_set_mode;
evt->set_next_event = msm_timer_set_next_event; evt->set_next_event = msm_timer_set_next_event;
evt->cpumask = cpumask_of(cpu);
clockevents_config_and_register(evt, GPT_HZ, 4, 0xffffffff);
if (msm_timer_has_ppi) {
enable_percpu_irq(evt->irq, IRQ_TYPE_EDGE_RISING);
} else {
err = request_irq(evt->irq, msm_timer_interrupt,
IRQF_TIMER | IRQF_NOBALANCING |
IRQF_TRIGGER_RISING, "gp_timer", evt);
if (err)
pr_err("request_irq failed\n");
}
*__this_cpu_ptr(msm_evt.percpu_evt) = evt;
clockevents_config_and_register(evt, GPT_HZ, 4, 0xf0000000);
enable_percpu_irq(evt->irq, IRQ_TYPE_EDGE_RISING);
return 0; return 0;
} }
static void msm_local_timer_stop(struct clock_event_device *evt) static void __cpuinit msm_local_timer_stop(struct clock_event_device *evt)
{ {
evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt); evt->set_mode(CLOCK_EVT_MODE_UNUSED, evt);
disable_percpu_irq(evt->irq); disable_percpu_irq(evt->irq);
} }
static struct local_timer_ops msm_local_timer_ops __cpuinitdata = { static int __cpuinit msm_timer_cpu_notify(struct notifier_block *self,
.setup = msm_local_timer_setup, unsigned long action, void *hcpu)
.stop = msm_local_timer_stop, {
/*
* Grab cpu pointer in each case to avoid spurious
* preemptible warnings
*/
switch (action & ~CPU_TASKS_FROZEN) {
case CPU_STARTING:
msm_local_timer_setup(this_cpu_ptr(msm_evt));
break;
case CPU_DYING:
msm_local_timer_stop(this_cpu_ptr(msm_evt));
break;
}
return NOTIFY_OK;
}
static struct notifier_block msm_timer_cpu_nb __cpuinitdata = {
.notifier_call = msm_timer_cpu_notify,
}; };
#endif /* CONFIG_LOCAL_TIMERS */
static notrace u32 msm_sched_clock_read(void) static notrace u32 msm_sched_clock_read(void)
{ {
...@@ -178,38 +195,35 @@ static notrace u32 msm_sched_clock_read(void) ...@@ -178,38 +195,35 @@ static notrace u32 msm_sched_clock_read(void)
static void __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq, static void __init msm_timer_init(u32 dgt_hz, int sched_bits, int irq,
bool percpu) bool percpu)
{ {
struct clock_event_device *ce = &msm_clockevent;
struct clocksource *cs = &msm_clocksource; struct clocksource *cs = &msm_clocksource;
int res; int res = 0;
msm_timer_irq = irq;
msm_timer_has_ppi = percpu;
msm_evt = alloc_percpu(struct clock_event_device);
if (!msm_evt) {
pr_err("memory allocation failed for clockevents\n");
goto err;
}
ce->cpumask = cpumask_of(0); if (percpu)
ce->irq = irq; res = request_percpu_irq(irq, msm_timer_interrupt,
"gp_timer", msm_evt);
clockevents_config_and_register(ce, GPT_HZ, 4, 0xffffffff); if (res) {
if (percpu) { pr_err("request_percpu_irq failed\n");
msm_evt.percpu_evt = alloc_percpu(struct clock_event_device *); } else {
if (!msm_evt.percpu_evt) { res = register_cpu_notifier(&msm_timer_cpu_nb);
pr_err("memory allocation failed for %s\n", ce->name); if (res) {
free_percpu_irq(irq, msm_evt);
goto err; goto err;
} }
*__this_cpu_ptr(msm_evt.percpu_evt) = ce;
res = request_percpu_irq(ce->irq, msm_timer_interrupt, /* Immediately configure the timer on the boot CPU */
ce->name, msm_evt.percpu_evt); msm_local_timer_setup(__this_cpu_ptr(msm_evt));
if (!res) {
enable_percpu_irq(ce->irq, IRQ_TYPE_EDGE_RISING);
#ifdef CONFIG_LOCAL_TIMERS
local_timer_register(&msm_local_timer_ops);
#endif
}
} else {
msm_evt.evt = ce;
res = request_irq(ce->irq, msm_timer_interrupt,
IRQF_TIMER | IRQF_NOBALANCING |
IRQF_TRIGGER_RISING, ce->name, &msm_evt.evt);
} }
if (res)
pr_err("request_irq failed for %s\n", ce->name);
err: err:
writel_relaxed(TIMER_ENABLE_EN, source_base + TIMER_ENABLE); writel_relaxed(TIMER_ENABLE_EN, source_base + TIMER_ENABLE);
res = clocksource_register_hz(cs, dgt_hz); res = clocksource_register_hz(cs, dgt_hz);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment