ARM: 6153/1: nomadik MTU to use dynamic shift and mult assignment

This removes the hard-coded shift values for the MTU timer, since
the different platforms using this has very different running
frequencies doing this dynamically is a better idea. Also take
this opportunity to make a more through shutdown of the MTU
clockevent when requested.

Acked-by: Alessandro Rubini <rubini@unipv.it>
Signed-off-by: Linus Walleij <linus.walleij@stericsson.com>
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
This commit is contained in:
Linus Walleij 2010-06-01 08:26:49 +01:00 committed by Russell King
parent f6aa01c2b8
commit 2917947a67
2 changed files with 16 additions and 4 deletions

View File

@ -1,6 +1,12 @@
#ifndef __PLAT_MTU_H #ifndef __PLAT_MTU_H
#define __PLAT_MTU_H #define __PLAT_MTU_H
/*
* Guaranteed runtime conversion range in seconds for
* the clocksource and clockevent.
*/
#define MTU_MIN_RANGE 4
/* should be set by the platform code */ /* should be set by the platform code */
extern void __iomem *mtu_base; extern void __iomem *mtu_base;

View File

@ -42,7 +42,6 @@ static struct clocksource nmdk_clksrc = {
.rating = 200, .rating = 200,
.read = nmdk_read_timer_dummy, .read = nmdk_read_timer_dummy,
.mask = CLOCKSOURCE_MASK(32), .mask = CLOCKSOURCE_MASK(32),
.shift = 20,
.flags = CLOCK_SOURCE_IS_CONTINUOUS, .flags = CLOCK_SOURCE_IS_CONTINUOUS,
}; };
@ -82,6 +81,12 @@ static void nmdk_clkevt_mode(enum clock_event_mode mode,
case CLOCK_EVT_MODE_UNUSED: case CLOCK_EVT_MODE_UNUSED:
/* disable irq */ /* disable irq */
writel(0, mtu_base + MTU_IMSC); writel(0, mtu_base + MTU_IMSC);
/* disable timer */
cr = readl(mtu_base + MTU_CR(1));
cr &= ~MTU_CRn_ENA;
writel(cr, mtu_base + MTU_CR(1));
/* load some high default value */
writel(0xffffffff, mtu_base + MTU_LR(1));
break; break;
case CLOCK_EVT_MODE_RESUME: case CLOCK_EVT_MODE_RESUME:
break; break;
@ -98,7 +103,6 @@ static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev)
static struct clock_event_device nmdk_clkevt = { static struct clock_event_device nmdk_clkevt = {
.name = "mtu_1", .name = "mtu_1",
.features = CLOCK_EVT_FEAT_ONESHOT, .features = CLOCK_EVT_FEAT_ONESHOT,
.shift = 32,
.rating = 200, .rating = 200,
.set_mode = nmdk_clkevt_mode, .set_mode = nmdk_clkevt_mode,
.set_next_event = nmdk_clkevt_next, .set_next_event = nmdk_clkevt_next,
@ -151,6 +155,7 @@ void __init nmdk_timer_init(void)
} else { } else {
cr |= MTU_CRn_PRESCALE_1; cr |= MTU_CRn_PRESCALE_1;
} }
clocksource_calc_mult_shift(&nmdk_clksrc, rate, MTU_MIN_RANGE);
/* Timer 0 is the free running clocksource */ /* Timer 0 is the free running clocksource */
writel(cr, mtu_base + MTU_CR(0)); writel(cr, mtu_base + MTU_CR(0));
@ -158,7 +163,6 @@ void __init nmdk_timer_init(void)
writel(0, mtu_base + MTU_BGLR(0)); writel(0, mtu_base + MTU_BGLR(0));
writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0)); writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));
nmdk_clksrc.mult = clocksource_hz2mult(rate, nmdk_clksrc.shift);
/* Now the scheduling clock is ready */ /* Now the scheduling clock is ready */
nmdk_clksrc.read = nmdk_read_timer; nmdk_clksrc.read = nmdk_read_timer;
@ -175,8 +179,10 @@ void __init nmdk_timer_init(void)
} else { } else {
cr |= MTU_CRn_PRESCALE_1; cr |= MTU_CRn_PRESCALE_1;
} }
clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE);
writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */ writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */
nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift);
nmdk_clkevt.max_delta_ns = nmdk_clkevt.max_delta_ns =
clockevent_delta2ns(0xffffffff, &nmdk_clkevt); clockevent_delta2ns(0xffffffff, &nmdk_clkevt);
nmdk_clkevt.min_delta_ns = nmdk_clkevt.min_delta_ns =