diff options
Diffstat (limited to 'arch/xtensa/kernel/time.c')
-rw-r--r-- | arch/xtensa/kernel/time.c | 131 |
1 files changed, 26 insertions, 105 deletions
diff --git a/arch/xtensa/kernel/time.c b/arch/xtensa/kernel/time.c index 8df1e842f6d4..8848120d291b 100644 --- a/arch/xtensa/kernel/time.c +++ b/arch/xtensa/kernel/time.c | |||
@@ -14,7 +14,7 @@ | |||
14 | 14 | ||
15 | #include <linux/errno.h> | 15 | #include <linux/errno.h> |
16 | #include <linux/time.h> | 16 | #include <linux/time.h> |
17 | #include <linux/timex.h> | 17 | #include <linux/clocksource.h> |
18 | #include <linux/interrupt.h> | 18 | #include <linux/interrupt.h> |
19 | #include <linux/module.h> | 19 | #include <linux/module.h> |
20 | #include <linux/init.h> | 20 | #include <linux/init.h> |
@@ -25,27 +25,31 @@ | |||
25 | #include <asm/timex.h> | 25 | #include <asm/timex.h> |
26 | #include <asm/platform.h> | 26 | #include <asm/platform.h> |
27 | 27 | ||
28 | |||
29 | DEFINE_SPINLOCK(rtc_lock); | ||
30 | EXPORT_SYMBOL(rtc_lock); | ||
31 | |||
32 | |||
33 | #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT | 28 | #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT |
34 | unsigned long ccount_per_jiffy; /* per 1/HZ */ | 29 | unsigned long ccount_per_jiffy; /* per 1/HZ */ |
35 | unsigned long nsec_per_ccount; /* nsec per ccount increment */ | 30 | unsigned long nsec_per_ccount; /* nsec per ccount increment */ |
36 | #endif | 31 | #endif |
37 | 32 | ||
38 | static long last_rtc_update = 0; | 33 | static cycle_t ccount_read(void) |
39 | |||
40 | /* | ||
41 | * Scheduler clock - returns current tim in nanosec units. | ||
42 | */ | ||
43 | |||
44 | unsigned long long sched_clock(void) | ||
45 | { | 34 | { |
46 | return (unsigned long long)jiffies * (1000000000 / HZ); | 35 | return (cycle_t)get_ccount(); |
47 | } | 36 | } |
48 | 37 | ||
38 | static struct clocksource ccount_clocksource = { | ||
39 | .name = "ccount", | ||
40 | .rating = 200, | ||
41 | .read = ccount_read, | ||
42 | .mask = CLOCKSOURCE_MASK(32), | ||
43 | /* | ||
44 | * With a shift of 22 the lower limit of the cpu clock is | ||
45 | * 1MHz, where NSEC_PER_CCOUNT is 1000 or a bit less than | ||
46 | * 2^10: Since we have 32 bits and the multiplicator can | ||
47 | * already take up as much as 10 bits, this leaves us with | ||
48 | * remaining upper 22 bits. | ||
49 | */ | ||
50 | .shift = 22, | ||
51 | }; | ||
52 | |||
49 | static irqreturn_t timer_interrupt(int irq, void *dev_id); | 53 | static irqreturn_t timer_interrupt(int irq, void *dev_id); |
50 | static struct irqaction timer_irqaction = { | 54 | static struct irqaction timer_irqaction = { |
51 | .handler = timer_interrupt, | 55 | .handler = timer_interrupt, |
@@ -55,11 +59,11 @@ static struct irqaction timer_irqaction = { | |||
55 | 59 | ||
56 | void __init time_init(void) | 60 | void __init time_init(void) |
57 | { | 61 | { |
58 | time_t sec_o, sec_n = 0; | 62 | xtime.tv_nsec = 0; |
63 | xtime.tv_sec = read_persistent_clock(); | ||
59 | 64 | ||
60 | /* The platform must provide a function to calibrate the processor | 65 | set_normalized_timespec(&wall_to_monotonic, |
61 | * speed for the CALIBRATE. | 66 | -xtime.tv_sec, -xtime.tv_nsec); |
62 | */ | ||
63 | 67 | ||
64 | #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT | 68 | #ifdef CONFIG_XTENSA_CALIBRATE_CCOUNT |
65 | printk("Calibrating CPU frequency "); | 69 | printk("Calibrating CPU frequency "); |
@@ -67,19 +71,10 @@ void __init time_init(void) | |||
67 | printk("%d.%02d MHz\n", (int)ccount_per_jiffy/(1000000/HZ), | 71 | printk("%d.%02d MHz\n", (int)ccount_per_jiffy/(1000000/HZ), |
68 | (int)(ccount_per_jiffy/(10000/HZ))%100); | 72 | (int)(ccount_per_jiffy/(10000/HZ))%100); |
69 | #endif | 73 | #endif |
70 | 74 | ccount_clocksource.mult = | |
71 | /* Set time from RTC (if provided) */ | 75 | clocksource_hz2mult(CCOUNT_PER_JIFFY * HZ, |
72 | 76 | ccount_clocksource.shift); | |
73 | if (platform_get_rtc_time(&sec_o) == 0) | 77 | clocksource_register(&ccount_clocksource); |
74 | while (platform_get_rtc_time(&sec_n)) | ||
75 | if (sec_o != sec_n) | ||
76 | break; | ||
77 | |||
78 | xtime.tv_nsec = 0; | ||
79 | last_rtc_update = xtime.tv_sec = sec_n; | ||
80 | |||
81 | set_normalized_timespec(&wall_to_monotonic, | ||
82 | -xtime.tv_sec, -xtime.tv_nsec); | ||
83 | 78 | ||
84 | /* Initialize the linux timer interrupt. */ | 79 | /* Initialize the linux timer interrupt. */ |
85 | 80 | ||
@@ -87,69 +82,6 @@ void __init time_init(void) | |||
87 | set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY); | 82 | set_linux_timer(get_ccount() + CCOUNT_PER_JIFFY); |
88 | } | 83 | } |
89 | 84 | ||
90 | |||
91 | int do_settimeofday(struct timespec *tv) | ||
92 | { | ||
93 | time_t wtm_sec, sec = tv->tv_sec; | ||
94 | long wtm_nsec, nsec = tv->tv_nsec; | ||
95 | unsigned long delta; | ||
96 | |||
97 | if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) | ||
98 | return -EINVAL; | ||
99 | |||
100 | write_seqlock_irq(&xtime_lock); | ||
101 | |||
102 | /* This is revolting. We need to set "xtime" correctly. However, the | ||
103 | * value in this location is the value at the most recent update of | ||
104 | * wall time. Discover what correction gettimeofday() would have | ||
105 | * made, and then undo it! | ||
106 | */ | ||
107 | |||
108 | delta = CCOUNT_PER_JIFFY; | ||
109 | delta += get_ccount() - get_linux_timer(); | ||
110 | nsec -= delta * NSEC_PER_CCOUNT; | ||
111 | |||
112 | wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec); | ||
113 | wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec); | ||
114 | |||
115 | set_normalized_timespec(&xtime, sec, nsec); | ||
116 | set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); | ||
117 | |||
118 | ntp_clear(); | ||
119 | write_sequnlock_irq(&xtime_lock); | ||
120 | return 0; | ||
121 | } | ||
122 | |||
123 | EXPORT_SYMBOL(do_settimeofday); | ||
124 | |||
125 | |||
126 | void do_gettimeofday(struct timeval *tv) | ||
127 | { | ||
128 | unsigned long flags; | ||
129 | unsigned long volatile sec, usec, delta, seq; | ||
130 | |||
131 | do { | ||
132 | seq = read_seqbegin_irqsave(&xtime_lock, flags); | ||
133 | |||
134 | sec = xtime.tv_sec; | ||
135 | usec = (xtime.tv_nsec / NSEC_PER_USEC); | ||
136 | |||
137 | delta = get_linux_timer() - get_ccount(); | ||
138 | |||
139 | } while (read_seqretry_irqrestore(&xtime_lock, seq, flags)); | ||
140 | |||
141 | usec += (((unsigned long) CCOUNT_PER_JIFFY - delta) | ||
142 | * (unsigned long) NSEC_PER_CCOUNT) / NSEC_PER_USEC; | ||
143 | |||
144 | for (; usec >= 1000000; sec++, usec -= 1000000) | ||
145 | ; | ||
146 | |||
147 | tv->tv_sec = sec; | ||
148 | tv->tv_usec = usec; | ||
149 | } | ||
150 | |||
151 | EXPORT_SYMBOL(do_gettimeofday); | ||
152 | |||
153 | /* | 85 | /* |
154 | * The timer interrupt is called HZ times per second. | 86 | * The timer interrupt is called HZ times per second. |
155 | */ | 87 | */ |
@@ -178,16 +110,6 @@ again: | |||
178 | next += CCOUNT_PER_JIFFY; | 110 | next += CCOUNT_PER_JIFFY; |
179 | set_linux_timer(next); | 111 | set_linux_timer(next); |
180 | 112 | ||
181 | if (ntp_synced() && | ||
182 | xtime.tv_sec - last_rtc_update >= 659 && | ||
183 | abs((xtime.tv_nsec/1000)-(1000000-1000000/HZ))<5000000/HZ) { | ||
184 | |||
185 | if (platform_set_rtc_time(xtime.tv_sec+1) == 0) | ||
186 | last_rtc_update = xtime.tv_sec+1; | ||
187 | else | ||
188 | /* Do it again in 60 s */ | ||
189 | last_rtc_update += 60; | ||
190 | } | ||
191 | write_sequnlock(&xtime_lock); | 113 | write_sequnlock(&xtime_lock); |
192 | } | 114 | } |
193 | 115 | ||
@@ -213,4 +135,3 @@ void __cpuinit calibrate_delay(void) | |||
213 | (loops_per_jiffy/(10000/HZ)) % 100); | 135 | (loops_per_jiffy/(10000/HZ)) % 100); |
214 | } | 136 | } |
215 | #endif | 137 | #endif |
216 | |||