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
This commit is contained in:
parent
af5bb69c5a
commit
f65466eb3a
@ -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_ */
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user