From: sboyd@codeaurora.org (Stephen Boyd)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 4/8] msm: timer: Fix ONESHOT mode interrupts
Date: Tue, 8 Nov 2011 10:34:06 -0800 [thread overview]
Message-ID: <1320777250-23263-5-git-send-email-sboyd@codeaurora.org> (raw)
In-Reply-To: <1320777250-23263-1-git-send-email-sboyd@codeaurora.org>
MSM timers don't support an interrupt enable/disable bit.
Therefore, when the timer is free running it's possible for the
count to wrap and the match value to match again even though a
set_next_event() call hasn't been made since the last match.
Workaround the lack of an interrupt enable bit by explicitly
stopping the timer in the interrupt handler when the clockevent
is in ONESHOT mode. This should prevent any possibility of the
timer wrapping and matching more than once per set_next_event().
Signed-off-by: Stephen Boyd <sboyd@codeaurora.org>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: Marc Zyngier <marc.zyngier@arm.com>
---
arch/arm/mach-msm/timer.c | 25 ++++++++++++++++++++-----
1 files changed, 20 insertions(+), 5 deletions(-)
diff --git a/arch/arm/mach-msm/timer.c b/arch/arm/mach-msm/timer.c
index 405e8a9..9f3671a 100644
--- a/arch/arm/mach-msm/timer.c
+++ b/arch/arm/mach-msm/timer.c
@@ -81,11 +81,20 @@ enum {
static struct msm_clock msm_clocks[];
+static struct msm_clock *clockevent_to_clock(struct clock_event_device *evt);
+
static irqreturn_t msm_timer_interrupt(int irq, void *dev_id)
{
struct clock_event_device *evt = *(struct clock_event_device **)dev_id;
if (evt->event_handler == NULL)
return IRQ_HANDLED;
+ /* Stop the timer tick */
+ if (evt->mode == CLOCK_EVT_MODE_ONESHOT) {
+ struct msm_clock *clock = clockevent_to_clock(evt);
+ u32 ctrl = readl_relaxed(clock->regbase + TIMER_ENABLE);
+ ctrl &= ~TIMER_ENABLE_EN;
+ writel_relaxed(ctrl, clock->regbase + TIMER_ENABLE);
+ }
evt->event_handler(evt);
return IRQ_HANDLED;
}
@@ -118,10 +127,12 @@ static int msm_timer_set_next_event(unsigned long cycles,
struct clock_event_device *evt)
{
struct msm_clock *clock = clockevent_to_clock(evt);
- uint32_t now = readl(clock->local_counter);
- uint32_t alarm = now + (cycles << clock->shift);
+ u32 match = cycles << clock->shift;
+ u32 ctrl = readl_relaxed(clock->regbase + TIMER_ENABLE);
- writel(alarm, clock->regbase + TIMER_MATCH_VAL);
+ writel_relaxed(0, clock->regbase + TIMER_CLEAR);
+ writel_relaxed(match, clock->regbase + TIMER_MATCH_VAL);
+ writel_relaxed(ctrl | TIMER_ENABLE_EN, clock->regbase + TIMER_ENABLE);
return 0;
}
@@ -129,19 +140,23 @@ static void msm_timer_set_mode(enum clock_event_mode mode,
struct clock_event_device *evt)
{
struct msm_clock *clock = clockevent_to_clock(evt);
+ u32 ctrl;
+
+ ctrl = readl_relaxed(clock->regbase + TIMER_ENABLE);
+ ctrl &= ~(TIMER_ENABLE_EN | TIMER_ENABLE_CLR_ON_MATCH_EN);
switch (mode) {
case CLOCK_EVT_MODE_RESUME:
case CLOCK_EVT_MODE_PERIODIC:
break;
case CLOCK_EVT_MODE_ONESHOT:
- writel(TIMER_ENABLE_EN, clock->regbase + TIMER_ENABLE);
+ /* Timer is enabled in set_next_event */
break;
case CLOCK_EVT_MODE_UNUSED:
case CLOCK_EVT_MODE_SHUTDOWN:
- writel(0, clock->regbase + TIMER_ENABLE);
break;
}
+ writel_relaxed(ctrl, clock->regbase + TIMER_ENABLE);
}
static struct msm_clock msm_clocks[] = {
--
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
next prev parent reply other threads:[~2011-11-08 18:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-11-08 18:34 [PATCH 0/8] MSM timer fixes and cleanups Stephen Boyd
2011-11-08 18:34 ` [PATCH 1/8] msm: timer: Tighten #ifdef for local timer support Stephen Boyd
2011-11-08 18:34 ` [PATCH 2/8] msm: timer: Cleanup #includes and #defines Stephen Boyd
2011-11-08 18:34 ` [PATCH 3/8] msm: timer: Use GPT for clockevents and DGT for clocksource Stephen Boyd
2011-11-08 18:34 ` Stephen Boyd [this message]
2011-11-08 18:34 ` [PATCH 5/8] msm: timer: Remove msm_clocks[] and simplify code Stephen Boyd
2011-11-08 18:34 ` [PATCH 6/8] msm: timer: Remove SoC specific #ifdefs Stephen Boyd
2011-11-08 18:34 ` [PATCH 7/8] msm: timer: Setup interrupt after registering clockevent Stephen Boyd
2011-11-08 18:34 ` [PATCH 8/8] msm: timer: Use clockevents_config_and_register() Stephen Boyd
2011-11-10 18:33 ` [PATCH 0/8] MSM timer fixes and cleanups David Brown
2011-11-10 19:12 ` Stephen Boyd
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=1320777250-23263-5-git-send-email-sboyd@codeaurora.org \
--to=sboyd@codeaurora.org \
--cc=linux-arm-kernel@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;
as well as URLs for NNTP newsgroup(s).