diff options
Diffstat (limited to 'arch/sparc/kernel/time_32.c')
-rw-r--r-- | arch/sparc/kernel/time_32.c | 116 |
1 files changed, 25 insertions, 91 deletions
diff --git a/arch/sparc/kernel/time_32.c b/arch/sparc/kernel/time_32.c index 5b2f595fe65b..0d4c09b15efc 100644 --- a/arch/sparc/kernel/time_32.c +++ b/arch/sparc/kernel/time_32.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/platform_device.h> | 35 | #include <linux/platform_device.h> |
36 | 36 | ||
37 | #include <asm/oplib.h> | 37 | #include <asm/oplib.h> |
38 | #include <asm/timex.h> | ||
38 | #include <asm/timer.h> | 39 | #include <asm/timer.h> |
39 | #include <asm/system.h> | 40 | #include <asm/system.h> |
40 | #include <asm/irq.h> | 41 | #include <asm/irq.h> |
@@ -51,7 +52,6 @@ DEFINE_SPINLOCK(rtc_lock); | |||
51 | EXPORT_SYMBOL(rtc_lock); | 52 | EXPORT_SYMBOL(rtc_lock); |
52 | 53 | ||
53 | static int set_rtc_mmss(unsigned long); | 54 | static int set_rtc_mmss(unsigned long); |
54 | static int sbus_do_settimeofday(struct timespec *tv); | ||
55 | 55 | ||
56 | unsigned long profile_pc(struct pt_regs *regs) | 56 | unsigned long profile_pc(struct pt_regs *regs) |
57 | { | 57 | { |
@@ -76,6 +76,8 @@ EXPORT_SYMBOL(profile_pc); | |||
76 | 76 | ||
77 | __volatile__ unsigned int *master_l10_counter; | 77 | __volatile__ unsigned int *master_l10_counter; |
78 | 78 | ||
79 | u32 (*do_arch_gettimeoffset)(void); | ||
80 | |||
79 | /* | 81 | /* |
80 | * timer_interrupt() needs to keep up the real-time clock, | 82 | * timer_interrupt() needs to keep up the real-time clock, |
81 | * as well as call the "do_timer()" routine every clocktick | 83 | * as well as call the "do_timer()" routine every clocktick |
@@ -196,35 +198,14 @@ static int __init clock_init(void) | |||
196 | { | 198 | { |
197 | return of_register_driver(&clock_driver, &of_platform_bus_type); | 199 | return of_register_driver(&clock_driver, &of_platform_bus_type); |
198 | } | 200 | } |
199 | |||
200 | /* Must be after subsys_initcall() so that busses are probed. Must | 201 | /* Must be after subsys_initcall() so that busses are probed. Must |
201 | * be before device_initcall() because things like the RTC driver | 202 | * be before device_initcall() because things like the RTC driver |
202 | * need to see the clock registers. | 203 | * need to see the clock registers. |
203 | */ | 204 | */ |
204 | fs_initcall(clock_init); | 205 | fs_initcall(clock_init); |
205 | 206 | ||
206 | static void __init sbus_time_init(void) | ||
207 | { | ||
208 | |||
209 | BTFIXUPSET_CALL(bus_do_settimeofday, sbus_do_settimeofday, BTFIXUPCALL_NORM); | ||
210 | btfixup(); | ||
211 | |||
212 | sparc_init_timers(timer_interrupt); | ||
213 | } | ||
214 | |||
215 | void __init time_init(void) | ||
216 | { | ||
217 | #ifdef CONFIG_PCI | ||
218 | extern void pci_time_init(void); | ||
219 | if (pcic_present()) { | ||
220 | pci_time_init(); | ||
221 | return; | ||
222 | } | ||
223 | #endif | ||
224 | sbus_time_init(); | ||
225 | } | ||
226 | 207 | ||
227 | static inline unsigned long do_gettimeoffset(void) | 208 | u32 sbus_do_gettimeoffset(void) |
228 | { | 209 | { |
229 | unsigned long val = *master_l10_counter; | 210 | unsigned long val = *master_l10_counter; |
230 | unsigned long usec = (val >> 10) & 0x1fffff; | 211 | unsigned long usec = (val >> 10) & 0x1fffff; |
@@ -233,86 +214,39 @@ static inline unsigned long do_gettimeoffset(void) | |||
233 | if (val & 0x80000000) | 214 | if (val & 0x80000000) |
234 | usec += 1000000 / HZ; | 215 | usec += 1000000 / HZ; |
235 | 216 | ||
236 | return usec; | 217 | return usec * 1000; |
237 | } | 218 | } |
238 | 219 | ||
239 | /* Ok, my cute asm atomicity trick doesn't work anymore. | ||
240 | * There are just too many variables that need to be protected | ||
241 | * now (both members of xtime, et al.) | ||
242 | */ | ||
243 | void do_gettimeofday(struct timeval *tv) | ||
244 | { | ||
245 | unsigned long flags; | ||
246 | unsigned long seq; | ||
247 | unsigned long usec, sec; | ||
248 | unsigned long max_ntp_tick = tick_usec - tickadj; | ||
249 | |||
250 | do { | ||
251 | seq = read_seqbegin_irqsave(&xtime_lock, flags); | ||
252 | usec = do_gettimeoffset(); | ||
253 | |||
254 | /* | ||
255 | * If time_adjust is negative then NTP is slowing the clock | ||
256 | * so make sure not to go into next possible interval. | ||
257 | * Better to lose some accuracy than have time go backwards.. | ||
258 | */ | ||
259 | if (unlikely(time_adjust < 0)) | ||
260 | usec = min(usec, max_ntp_tick); | ||
261 | |||
262 | sec = xtime.tv_sec; | ||
263 | usec += (xtime.tv_nsec / 1000); | ||
264 | } while (read_seqretry_irqrestore(&xtime_lock, seq, flags)); | ||
265 | |||
266 | while (usec >= 1000000) { | ||
267 | usec -= 1000000; | ||
268 | sec++; | ||
269 | } | ||
270 | 220 | ||
271 | tv->tv_sec = sec; | 221 | u32 arch_gettimeoffset(void) |
272 | tv->tv_usec = usec; | ||
273 | } | ||
274 | |||
275 | EXPORT_SYMBOL(do_gettimeofday); | ||
276 | |||
277 | int do_settimeofday(struct timespec *tv) | ||
278 | { | 222 | { |
279 | int ret; | 223 | if (unlikely(!do_arch_gettimeoffset)) |
280 | 224 | return 0; | |
281 | write_seqlock_irq(&xtime_lock); | 225 | return do_arch_gettimeoffset(); |
282 | ret = bus_do_settimeofday(tv); | ||
283 | write_sequnlock_irq(&xtime_lock); | ||
284 | clock_was_set(); | ||
285 | return ret; | ||
286 | } | 226 | } |
287 | 227 | ||
288 | EXPORT_SYMBOL(do_settimeofday); | 228 | static void __init sbus_time_init(void) |
289 | |||
290 | static int sbus_do_settimeofday(struct timespec *tv) | ||
291 | { | 229 | { |
292 | time_t wtm_sec, sec = tv->tv_sec; | 230 | do_arch_gettimeoffset = sbus_do_gettimeoffset; |
293 | long wtm_nsec, nsec = tv->tv_nsec; | ||
294 | 231 | ||
295 | if ((unsigned long)tv->tv_nsec >= NSEC_PER_SEC) | 232 | btfixup(); |
296 | return -EINVAL; | ||
297 | |||
298 | /* | ||
299 | * This is revolting. We need to set "xtime" correctly. However, the | ||
300 | * value in this location is the value at the most recent update of | ||
301 | * wall time. Discover what correction gettimeofday() would have | ||
302 | * made, and then undo it! | ||
303 | */ | ||
304 | nsec -= 1000 * do_gettimeoffset(); | ||
305 | |||
306 | wtm_sec = wall_to_monotonic.tv_sec + (xtime.tv_sec - sec); | ||
307 | wtm_nsec = wall_to_monotonic.tv_nsec + (xtime.tv_nsec - nsec); | ||
308 | 233 | ||
309 | set_normalized_timespec(&xtime, sec, nsec); | 234 | sparc_init_timers(timer_interrupt); |
310 | set_normalized_timespec(&wall_to_monotonic, wtm_sec, wtm_nsec); | 235 | } |
311 | 236 | ||
312 | ntp_clear(); | 237 | void __init time_init(void) |
313 | return 0; | 238 | { |
239 | #ifdef CONFIG_PCI | ||
240 | extern void pci_time_init(void); | ||
241 | if (pcic_present()) { | ||
242 | pci_time_init(); | ||
243 | return; | ||
244 | } | ||
245 | #endif | ||
246 | sbus_time_init(); | ||
314 | } | 247 | } |
315 | 248 | ||
249 | |||
316 | static int set_rtc_mmss(unsigned long secs) | 250 | static int set_rtc_mmss(unsigned long secs) |
317 | { | 251 | { |
318 | struct rtc_device *rtc = rtc_class_open("rtc0"); | 252 | struct rtc_device *rtc = rtc_class_open("rtc0"); |