Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2001, 2002, MontaVista Software Inc. |
| 3 | * Author: Jun Sun, jsun@mvista.com or jsun@junsun.net |
| 4 | * Copyright (c) 2003 Maciej W. Rozycki |
| 5 | * |
| 6 | * include/asm-mips/time.h |
| 7 | * header file for the new style time.c file and time services. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify it |
| 10 | * under the terms of the GNU General Public License as published by the |
| 11 | * Free Software Foundation; either version 2 of the License, or (at your |
| 12 | * option) any later version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | */ |
| 14 | #ifndef _ASM_TIME_H |
| 15 | #define _ASM_TIME_H |
| 16 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <linux/rtc.h> |
Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 18 | #include <linux/spinlock.h> |
Ralf Baechle | 93c846f | 2007-10-19 08:13:08 +0100 | [diff] [blame] | 19 | #include <linux/clockchips.h> |
Atsushi Nemoto | 0059856 | 2006-11-12 00:10:28 +0900 | [diff] [blame] | 20 | #include <linux/clocksource.h> |
Atsushi Nemoto | 53c2df2 | 2005-11-03 01:01:15 +0900 | [diff] [blame] | 21 | |
| 22 | extern spinlock_t rtc_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | |
| 24 | /* |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 25 | * RTC ops. By default, they point to weak no-op RTC functions. |
Yoichi Yuasa | d23ee8f | 2006-03-27 01:16:33 -0800 | [diff] [blame] | 26 | * rtc_mips_set_time - reverse the above translation and set time to RTC. |
| 27 | * rtc_mips_set_mmss - similar to rtc_set_time, but only min and sec need |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * to be set. Used by RTC sync-up. |
| 29 | */ |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 30 | extern int rtc_mips_set_time(unsigned long); |
| 31 | extern int rtc_mips_set_mmss(unsigned long); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | * board specific routines required by time_init(). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | */ |
Ralf Baechle | 4b55048 | 2007-10-11 23:46:08 +0100 | [diff] [blame] | 36 | extern void plat_time_init(void); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * mips_hpt_frequency - must be set if you intend to use an R4k-compatible |
Yoichi Yuasa | c966234 | 2007-12-09 21:19:36 +0900 | [diff] [blame] | 40 | * counter as a timer interrupt source. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | */ |
| 42 | extern unsigned int mips_hpt_frequency; |
| 43 | |
Ralf Baechle | 91a2fcc | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 44 | /* |
| 45 | * The performance counter IRQ on MIPS is a close relative to the timer IRQ |
| 46 | * so it lives here. |
| 47 | */ |
| 48 | extern int (*perf_irq)(void); |
| 49 | |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 50 | /* |
| 51 | * Initialize the calling CPU's compare interrupt as clockevent device |
| 52 | */ |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 53 | #ifdef CONFIG_CEVT_R4K_LIB |
Ralf Baechle | 38760d4 | 2007-10-29 14:23:43 +0000 | [diff] [blame] | 54 | extern unsigned int __weak get_c0_compare_int(void); |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 55 | extern int r4k_clockevent_init(void); |
| 56 | #endif |
| 57 | |
Ralf Baechle | 5aa85c9 | 2007-11-21 16:39:44 +0000 | [diff] [blame] | 58 | static inline int mips_clockevent_init(void) |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 59 | { |
Kevin D. Kissell | bcf1180 | 2009-03-31 13:10:32 +0200 | [diff] [blame] | 60 | #ifdef CONFIG_MIPS_MT_SMTC |
| 61 | extern int smtc_clockevent_init(void); |
| 62 | |
| 63 | return smtc_clockevent_init(); |
Ralf Baechle | 592e527 | 2009-04-06 00:31:22 +0200 | [diff] [blame] | 64 | #elif defined(CONFIG_CEVT_R4K) |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 65 | return r4k_clockevent_init(); |
| 66 | #else |
Ralf Baechle | 5aa85c9 | 2007-11-21 16:39:44 +0000 | [diff] [blame] | 67 | return -ENXIO; |
Ralf Baechle | 42f7754 | 2007-10-18 17:48:11 +0100 | [diff] [blame] | 68 | #endif |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 69 | } |
Ralf Baechle | 7bcf771 | 2007-10-11 23:46:09 +0100 | [diff] [blame] | 70 | |
Ralf Baechle | 940f6b4 | 2007-11-24 22:33:28 +0000 | [diff] [blame] | 71 | /* |
| 72 | * Initialize the count register as a clocksource |
| 73 | */ |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 74 | #ifdef CONFIG_CSRC_R4K_LIB |
| 75 | extern int init_r4k_clocksource(void); |
| 76 | #endif |
| 77 | |
Ralf Baechle | 69e634f | 2008-03-12 13:58:10 +0000 | [diff] [blame] | 78 | static inline int init_mips_clocksource(void) |
Ralf Baechle | 940f6b4 | 2007-11-24 22:33:28 +0000 | [diff] [blame] | 79 | { |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 80 | #ifdef CONFIG_CSRC_R4K |
| 81 | return init_r4k_clocksource(); |
| 82 | #else |
Ralf Baechle | 69e634f | 2008-03-12 13:58:10 +0000 | [diff] [blame] | 83 | return 0; |
Ralf Baechle | 940f6b4 | 2007-11-24 22:33:28 +0000 | [diff] [blame] | 84 | #endif |
Manuel Lauss | 779e7d4 | 2008-12-21 09:26:22 +0100 | [diff] [blame] | 85 | } |
Ralf Baechle | 940f6b4 | 2007-11-24 22:33:28 +0000 | [diff] [blame] | 86 | |
Thomas Gleixner | e3a4fab | 2009-11-11 14:05:34 +0000 | [diff] [blame] | 87 | static inline void clocksource_set_clock(struct clocksource *cs, |
| 88 | unsigned int clock) |
| 89 | { |
| 90 | clocksource_calc_mult_shift(cs, clock, 4); |
| 91 | } |
| 92 | |
| 93 | static inline void clockevent_set_clock(struct clock_event_device *cd, |
| 94 | unsigned int clock) |
| 95 | { |
| 96 | clockevents_calc_mult_shift(cd, clock, 4); |
| 97 | } |
Ralf Baechle | 93c846f | 2007-10-19 08:13:08 +0100 | [diff] [blame] | 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | #endif /* _ASM_TIME_H */ |