[ARM] twd: Always calibrate local timer

Change-Id: I075f883739d0eeea3b6b10da003119431cf3c2d2
Signed-off-by: Colin Cross <ccross@android.com>
This commit is contained in:
Colin Cross 2010-09-21 23:12:19 -07:00
parent 97460a796b
commit 0d2beae104

View File

@ -112,48 +112,49 @@ static void __cpuinit twd_calibrate_rate(unsigned long target_rate,
* If this is the first time round, we need to work out how fast
* the timer ticks
*/
if (twd_timer_rate == 0) {
printk(KERN_INFO "Calibrating local timer... ");
printk(KERN_INFO "Calibrating local timer... ");
/* Wait for a tick to start */
waitjiffies = get_jiffies_64() + 1;
/* Wait for a tick to start */
waitjiffies = get_jiffies_64() + 1;
while (get_jiffies_64() < waitjiffies)
udelay(10);
while (get_jiffies_64() < waitjiffies)
udelay(10);
/* OK, now the tick has started, let's get the timer going */
waitjiffies += 5;
/* OK, now the tick has started, let's get the timer going */
waitjiffies += 5;
/* enable, no interrupt or reload */
__raw_writel(0x1, twd_base + TWD_TIMER_CONTROL);
/* enable, no interrupt or reload */
__raw_writel(0x1, twd_base + TWD_TIMER_CONTROL);
/* maximum value */
__raw_writel(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
/* maximum value */
__raw_writel(0xFFFFFFFFU, twd_base + TWD_TIMER_COUNTER);
while (get_jiffies_64() < waitjiffies)
udelay(10);
while (get_jiffies_64() < waitjiffies)
udelay(10);
count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
count = __raw_readl(twd_base + TWD_TIMER_COUNTER);
twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
twd_timer_rate = (0xFFFFFFFFU - count) * (HZ / 5);
/*
* If a target rate has been requested, adjust the TWD prescaler
* to get the closest lower frequency.
*/
if (target_rate) {
twd_periphclk_prescaler = periphclk_prescaler;
twd_target_rate = target_rate;
/*
* If a target rate has been requested, adjust the TWD prescaler
* to get the closest lower frequency.
*/
if (target_rate) {
twd_periphclk_prescaler = periphclk_prescaler;
twd_target_rate = target_rate;
cpu_rate = twd_timer_rate * periphclk_prescaler;
twd_timer_rate = twd_target_rate;
twd_recalc_prescaler(cpu_rate);
}
printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
printk("%lu.%02luMHz, setting to ",
twd_timer_rate / 1000000,
(twd_timer_rate / 10000) % 100);
cpu_rate = twd_timer_rate * periphclk_prescaler;
twd_timer_rate = twd_target_rate;
twd_recalc_prescaler(cpu_rate);
}
printk("%lu.%02luMHz.\n", twd_timer_rate / 1000000,
(twd_timer_rate / 10000) % 100);
load = twd_timer_rate / HZ;
__raw_writel(load, twd_base + TWD_TIMER_LOAD);