summaryrefslogtreecommitdiff
path: root/arch/arm/mach-tegra/localtimer.c
blob: 528bd8ed7d798cf2b43df3c823e29a5e2f941ddf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
 *  arch/arm/mach-tegra/localtimer.c
 *
 *  Copyright (C) 2002 ARM Ltd.
 *  All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 */
#include <linux/init.h>
#include <linux/smp.h>
#include <linux/clockchips.h>
#include <asm/irq.h>
#include <asm/smp_twd.h>
#include <asm/localtimer.h>

#ifdef CONFIG_USE_ARM_TWD_PRESCALER
#define CPU_FREQ_SCALE_SHIFT   24
#define CPU_FREQ_SCALE_DIVIDER (0x1 << CPU_FREQ_SCALE_SHIFT)
#define CPU_FREQ_SCALE_INIT    125
extern unsigned long twd_prescaler;
#endif

/*
 * Setup the local clock events for a CPU.
 */
void __cpuinit local_timer_setup(struct clock_event_device *evt)
{
#ifdef CONFIG_USE_ARM_TWD_PRESCALER
	if (!twd_prescaler) {
		twd_prescaler = CPU_FREQ_SCALE_INIT - 1;
		smp_wmb();
	}
#endif
	evt->irq = IRQ_LOCALTIMER;
	twd_timer_setup(evt);
}

#ifdef CONFIG_USE_ARM_TWD_PRESCALER
/*
 * Find new prescaler value for cpu frequency changes, so that local timer
 * input frequency is kept at calibration level. Save new value in shadow
 * variable - do not update h/w.
 */
void local_timer_rescale(unsigned long cpu_freq_khz)
{
	static unsigned long cpu_freq_scale_mult = 0;
	unsigned long scale;

	/* 1st call at boot/calibration frequency */
	if (cpu_freq_scale_mult == 0) {
		cpu_freq_scale_mult = ((twd_prescaler + 1) <<
			CPU_FREQ_SCALE_SHIFT) / cpu_freq_khz;
		printk("Local timer scaling factor %lu, shift %d\n",
                       cpu_freq_scale_mult, CPU_FREQ_SCALE_SHIFT);
		return;
	}

	scale = (unsigned long)((((uint64_t)cpu_freq_khz * cpu_freq_scale_mult)
			+ CPU_FREQ_SCALE_DIVIDER -1) >> CPU_FREQ_SCALE_SHIFT);
	twd_prescaler = scale - 1;
}
#endif