FreeBSD/sys/arm/at91/at91_rtc.c
/*
 * Set the time of day clock based on the value of the struct timespec arg.
 * Return 0 on success, an error number otherwise.
 */
Set the time of day clock based on the value of the struct timespec arg.
Return 0 on success, an error number otherwise.
Set the time of day clock based on the value of the struct timespec arg . Return 0 on success an error number otherwise .
static int
at91_rtc_settime(device_t dev, struct timespec *ts)
{
	struct at91_rtc_softc *sc;
	struct clocktime ct;
	int rv;
	sc = device_get_softc(dev);
	clock_ts_to_ct(ts, &ct);
	while ((RD4(sc, RTC_SR) & RTC_SR_SECEV) == 0)
		cpu_spinwait();
	WR4(sc, RTC_CR, RTC_CR_UPDCAL | RTC_CR_UPDTIM);
	while ((RD4(sc, RTC_SR) & RTC_SR_ACKUPD) == 0)
		cpu_spinwait();
	WR4(sc, RTC_SCCR, RTC_SR_ACKUPD);
	WR4(sc, RTC_TIMR, RTC_TIMR_MK(ct.hour, ct.min, ct.sec));
	WR4(sc, RTC_CALR, RTC_CALR_MK(ct.year, ct.mon, ct.day, ct.dow+1));
	if (RD4(sc, RTC_VER) & (RTC_VER_NVTIM | RTC_VER_NVCAL))
		rv = EINVAL;
	else
		rv = 0;
	WR4(sc, RTC_CR, RD4(sc, RTC_CR) & ~(RTC_CR_UPDCAL | RTC_CR_UPDTIM));
	WR4(sc, RTC_SCCR, RTC_SR_SECEV);
	return (0);
}
static int at91_rtc_settime ( device_t dev , struct timespec * ts ) { struct at91_rtc_softc * sc ; struct clocktime ct ; int rv ; sc = device_get_softc ( dev ) ; clock_ts_to_ct ( ts , & ct ) ; while ( ( RD4 ( sc , RTC_SR ) & RTC_SR_SECEV ) == 0 ) cpu_spinwait ( ) ; WR4 ( sc , RTC_CR , RTC_CR_UPDCAL | RTC_CR_UPDTIM ) ; while ( ( RD4 ( sc , RTC_SR ) & RTC_SR_ACKUPD ) == 0 ) cpu_spinwait ( ) ; WR4 ( sc , RTC_SCCR , RTC_SR_ACKUPD ) ; WR4 ( sc , RTC_TIMR , RTC_TIMR_MK ( ct . hour , ct . min , ct . sec ) ) ; WR4 ( sc , RTC_CALR , RTC_CALR_MK ( ct . year , ct . mon , ct . day , ct . dow + 1 ) ) ; if ( RD4 ( sc , RTC_VER ) & ( RTC_VER_NVTIM | RTC_VER_NVCAL ) ) rv = EINVAL ; else rv = 0 ; WR4 ( sc , RTC_CR , RD4 ( sc , RTC_CR ) & ~ ( RTC_CR_UPDCAL | RTC_CR_UPDTIM ) ) ; WR4 ( sc , RTC_SCCR , RTC_SR_SECEV ) ; return ( 0 ) ; }
Set the time of day clock based on the value of the struct timespec arg.
Set the time of day clock based on the value of the struct timespec arg .
/*
	 * Can't set the clock unless a second has elapsed since we last did so.
	 */ /*
	 * Stop the clocks for an update; wait until hardware is ready.
	 * Clear the update-ready status after it gets asserted (the manual says
	 * to do this before updating the value registers).
	 */ /*
	 * Set the values in the hardware, then check whether the hardware was
	 * happy with them so we can return the correct status.
	 */ /*
	 * Restart the clocks (turn off the update bits).
	 * Clear the second-event bit (because the manual says to).
	 */