aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--arch/arm/lib/delay.c26
-rw-r--r--drivers/clocksource/tegra20_timer.c13
-rw-r--r--init/calibrate.c11
3 files changed, 46 insertions, 4 deletions
diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
index 5306de350133..312d43eb686a 100644
--- a/arch/arm/lib/delay.c
+++ b/arch/arm/lib/delay.c
@@ -19,6 +19,7 @@
19 * Author: Will Deacon <will.deacon@arm.com> 19 * Author: Will Deacon <will.deacon@arm.com>
20 */ 20 */
21 21
22#include <linux/clocksource.h>
22#include <linux/delay.h> 23#include <linux/delay.h>
23#include <linux/init.h> 24#include <linux/init.h>
24#include <linux/kernel.h> 25#include <linux/kernel.h>
@@ -36,6 +37,7 @@ struct arm_delay_ops arm_delay_ops = {
36 37
37static const struct delay_timer *delay_timer; 38static const struct delay_timer *delay_timer;
38static bool delay_calibrated; 39static bool delay_calibrated;
40static u64 delay_res;
39 41
40int read_current_timer(unsigned long *timer_val) 42int read_current_timer(unsigned long *timer_val)
41{ 43{
@@ -47,6 +49,11 @@ int read_current_timer(unsigned long *timer_val)
47} 49}
48EXPORT_SYMBOL_GPL(read_current_timer); 50EXPORT_SYMBOL_GPL(read_current_timer);
49 51
52static inline u64 cyc_to_ns(u64 cyc, u32 mult, u32 shift)
53{
54 return (cyc * mult) >> shift;
55}
56
50static void __timer_delay(unsigned long cycles) 57static void __timer_delay(unsigned long cycles)
51{ 58{
52 cycles_t start = get_cycles(); 59 cycles_t start = get_cycles();
@@ -69,18 +76,24 @@ static void __timer_udelay(unsigned long usecs)
69 76
70void __init register_current_timer_delay(const struct delay_timer *timer) 77void __init register_current_timer_delay(const struct delay_timer *timer)
71{ 78{
72 if (!delay_calibrated) { 79 u32 new_mult, new_shift;
73 pr_info("Switching to timer-based delay loop\n"); 80 u64 res;
81
82 clocks_calc_mult_shift(&new_mult, &new_shift, timer->freq,
83 NSEC_PER_SEC, 3600);
84 res = cyc_to_ns(1ULL, new_mult, new_shift);
85
86 if (!delay_calibrated && (!delay_res || (res < delay_res))) {
87 pr_info("Switching to timer-based delay loop, resolution %lluns\n", res);
74 delay_timer = timer; 88 delay_timer = timer;
75 lpj_fine = timer->freq / HZ; 89 lpj_fine = timer->freq / HZ;
90 delay_res = res;
76 91
77 /* cpufreq may scale loops_per_jiffy, so keep a private copy */ 92 /* cpufreq may scale loops_per_jiffy, so keep a private copy */
78 arm_delay_ops.ticks_per_jiffy = lpj_fine; 93 arm_delay_ops.ticks_per_jiffy = lpj_fine;
79 arm_delay_ops.delay = __timer_delay; 94 arm_delay_ops.delay = __timer_delay;
80 arm_delay_ops.const_udelay = __timer_const_udelay; 95 arm_delay_ops.const_udelay = __timer_const_udelay;
81 arm_delay_ops.udelay = __timer_udelay; 96 arm_delay_ops.udelay = __timer_udelay;
82
83 delay_calibrated = true;
84 } else { 97 } else {
85 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n"); 98 pr_info("Ignoring duplicate/late registration of read_current_timer delay\n");
86 } 99 }
@@ -91,3 +104,8 @@ unsigned long calibrate_delay_is_known(void)
91 delay_calibrated = true; 104 delay_calibrated = true;
92 return lpj_fine; 105 return lpj_fine;
93} 106}
107
108void calibration_delay_done(void)
109{
110 delay_calibrated = true;
111}
diff --git a/drivers/clocksource/tegra20_timer.c b/drivers/clocksource/tegra20_timer.c
index d1869f02051c..d2616ef16770 100644
--- a/drivers/clocksource/tegra20_timer.c
+++ b/drivers/clocksource/tegra20_timer.c
@@ -27,6 +27,7 @@
27#include <linux/of_address.h> 27#include <linux/of_address.h>
28#include <linux/of_irq.h> 28#include <linux/of_irq.h>
29#include <linux/sched_clock.h> 29#include <linux/sched_clock.h>
30#include <linux/delay.h>
30 31
31#include <asm/mach/time.h> 32#include <asm/mach/time.h>
32#include <asm/smp_twd.h> 33#include <asm/smp_twd.h>
@@ -53,6 +54,8 @@ static void __iomem *rtc_base;
53static struct timespec persistent_ts; 54static struct timespec persistent_ts;
54static u64 persistent_ms, last_persistent_ms; 55static u64 persistent_ms, last_persistent_ms;
55 56
57static struct delay_timer tegra_delay_timer;
58
56#define timer_writel(value, reg) \ 59#define timer_writel(value, reg) \
57 __raw_writel(value, timer_reg_base + (reg)) 60 __raw_writel(value, timer_reg_base + (reg))
58#define timer_readl(reg) \ 61#define timer_readl(reg) \
@@ -139,6 +142,11 @@ static void tegra_read_persistent_clock(struct timespec *ts)
139 *ts = *tsp; 142 *ts = *tsp;
140} 143}
141 144
145static unsigned long tegra_delay_timer_read_counter_long(void)
146{
147 return readl(timer_reg_base + TIMERUS_CNTR_1US);
148}
149
142static irqreturn_t tegra_timer_interrupt(int irq, void *dev_id) 150static irqreturn_t tegra_timer_interrupt(int irq, void *dev_id)
143{ 151{
144 struct clock_event_device *evt = (struct clock_event_device *)dev_id; 152 struct clock_event_device *evt = (struct clock_event_device *)dev_id;
@@ -206,6 +214,11 @@ static void __init tegra20_init_timer(struct device_node *np)
206 BUG(); 214 BUG();
207 } 215 }
208 216
217 tegra_delay_timer.read_current_timer =
218 tegra_delay_timer_read_counter_long;
219 tegra_delay_timer.freq = 1000000;
220 register_current_timer_delay(&tegra_delay_timer);
221
209 ret = setup_irq(tegra_timer_irq.irq, &tegra_timer_irq); 222 ret = setup_irq(tegra_timer_irq.irq, &tegra_timer_irq);
210 if (ret) { 223 if (ret) {
211 pr_err("Failed to register timer IRQ: %d\n", ret); 224 pr_err("Failed to register timer IRQ: %d\n", ret);
diff --git a/init/calibrate.c b/init/calibrate.c
index 520702db9acc..ce635dccf3d9 100644
--- a/init/calibrate.c
+++ b/init/calibrate.c
@@ -262,6 +262,15 @@ unsigned long __attribute__((weak)) calibrate_delay_is_known(void)
262 return 0; 262 return 0;
263} 263}
264 264
265/*
266 * Indicate the cpu delay calibration is done. This can be used by
267 * architectures to stop accepting delay timer registrations after this point.
268 */
269
270void __attribute__((weak)) calibration_delay_done(void)
271{
272}
273
265void calibrate_delay(void) 274void calibrate_delay(void)
266{ 275{
267 unsigned long lpj; 276 unsigned long lpj;
@@ -301,4 +310,6 @@ void calibrate_delay(void)
301 310
302 loops_per_jiffy = lpj; 311 loops_per_jiffy = lpj;
303 printed = true; 312 printed = true;
313
314 calibration_delay_done();
304} 315}