diff options
author | royger <royger@FreeBSD.org> | 2016-05-02 16:14:55 +0000 |
---|---|---|
committer | royger <royger@FreeBSD.org> | 2016-05-02 16:14:55 +0000 |
commit | 390486acbcadb84e981b41ec5a2b6bc195263755 (patch) | |
tree | fe8088a33470fbb3d4f9f85491544c571d41d1b0 | |
parent | 43a683d6cb38305051e653f4d695413c60438230 (diff) | |
download | FreeBSD-src-390486acbcadb84e981b41ec5a2b6bc195263755.zip FreeBSD-src-390486acbcadb84e981b41ec5a2b6bc195263755.tar.gz |
atrtc: export function to set RTC
This is going to be used by the Xen clock on Dom0 in order to set the RTC of
the host. The current logic in atrtc_settime is moved to atrtc_set and the
unused device_t parameter is removed from the atrtc_set function call so it
can be safely used by other callers.
Sponsored by: Citrix Systems R&D
Reviewed by: kib, jhb
Differential revision: https://reviews.freebsd.org/D6067
-rw-r--r-- | sys/isa/rtc.h | 1 | ||||
-rw-r--r-- | sys/x86/isa/atrtc.c | 49 |
2 files changed, 29 insertions, 21 deletions
diff --git a/sys/isa/rtc.h b/sys/isa/rtc.h index 8d86981..5c5a341 100644 --- a/sys/isa/rtc.h +++ b/sys/isa/rtc.h @@ -117,6 +117,7 @@ extern int atrtcclock_disable; int rtcin(int reg); void atrtc_restore(void); void writertc(int reg, u_char val); +void atrtc_set(struct timespec *ts); #endif #endif /* _I386_ISA_RTC_H_ */ diff --git a/sys/x86/isa/atrtc.c b/sys/x86/isa/atrtc.c index c1e796f..27fa127 100644 --- a/sys/x86/isa/atrtc.c +++ b/sys/x86/isa/atrtc.c @@ -151,6 +151,33 @@ atrtc_restore(void) rtcin(RTC_INTR); } +void +atrtc_set(struct timespec *ts) +{ + struct clocktime ct; + + clock_ts_to_ct(ts, &ct); + + /* Disable RTC updates and interrupts. */ + writertc(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR); + + writertc(RTC_SEC, bin2bcd(ct.sec)); /* Write back Seconds */ + writertc(RTC_MIN, bin2bcd(ct.min)); /* Write back Minutes */ + writertc(RTC_HRS, bin2bcd(ct.hour)); /* Write back Hours */ + + writertc(RTC_WDAY, ct.dow + 1); /* Write back Weekday */ + writertc(RTC_DAY, bin2bcd(ct.day)); /* Write back Day */ + writertc(RTC_MONTH, bin2bcd(ct.mon)); /* Write back Month */ + writertc(RTC_YEAR, bin2bcd(ct.year % 100)); /* Write back Year */ +#ifdef USE_RTC_CENTURY + writertc(RTC_CENTURY, bin2bcd(ct.year / 100)); /* ... and Century */ +#endif + + /* Re-enable RTC updates and interrupts. */ + writertc(RTC_STATUSB, rtc_statusb); + rtcin(RTC_INTR); +} + /********************************************************************** * RTC driver for subr_rtc */ @@ -297,28 +324,8 @@ atrtc_resume(device_t dev) static int atrtc_settime(device_t dev __unused, struct timespec *ts) { - struct clocktime ct; - - clock_ts_to_ct(ts, &ct); - - /* Disable RTC updates and interrupts. */ - writertc(RTC_STATUSB, RTCSB_HALT | RTCSB_24HR); - - writertc(RTC_SEC, bin2bcd(ct.sec)); /* Write back Seconds */ - writertc(RTC_MIN, bin2bcd(ct.min)); /* Write back Minutes */ - writertc(RTC_HRS, bin2bcd(ct.hour)); /* Write back Hours */ - writertc(RTC_WDAY, ct.dow + 1); /* Write back Weekday */ - writertc(RTC_DAY, bin2bcd(ct.day)); /* Write back Day */ - writertc(RTC_MONTH, bin2bcd(ct.mon)); /* Write back Month */ - writertc(RTC_YEAR, bin2bcd(ct.year % 100)); /* Write back Year */ -#ifdef USE_RTC_CENTURY - writertc(RTC_CENTURY, bin2bcd(ct.year / 100)); /* ... and Century */ -#endif - - /* Reenable RTC updates and interrupts. */ - writertc(RTC_STATUSB, rtc_statusb); - rtcin(RTC_INTR); + atrtc_set(ts); return (0); } |