Lines Matching +full:rtc +full:-
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
48 * Helpers for time-of-day clocks. This is useful for architectures that need
50 * code more machine-independent.
78 "Enable debug printing of RTC clock I/O; 1=reads, 2=writes, 3=both.");
83 "Trigger one-time IO on RTC clocks; 1=read (and discard), 2=write");
88 0, "Disallow adjusting time-of-day clock");
95 * the clock's resolution, which is useful mainly on clocks with a whole-second
126 SX_SYSINIT(rtc_list_lock_init, &rtc_list_lock, "rtc list");
137 struct rtc_instance *rtc; in settime_task_func() local
140 rtc = arg; in settime_task_func()
141 if (!(rtc->flags & CLOCKF_SETTIME_NO_TS)) { in settime_task_func()
143 if (!(rtc->flags & CLOCKF_SETTIME_NO_ADJ)) { in settime_task_func()
144 ts.tv_sec -= utc_offset(); in settime_task_func()
145 timespecadd(&ts, &rtc->resadj, &ts); in settime_task_func()
151 error = CLOCK_SETTIME(rtc->clockdev, &ts); in settime_task_func()
153 device_printf(rtc->clockdev, "CLOCK_SETTIME error %d\n", error); in settime_task_func()
213 struct rtc_instance *rtc, *newrtc; in clock_register_flags() local
216 newrtc->clockdev = clockdev; in clock_register_flags()
217 newrtc->resolution = (int)resolution; in clock_register_flags()
218 newrtc->flags = flags; in clock_register_flags()
219 newrtc->schedns = 0; in clock_register_flags()
220 newrtc->resadj.tv_sec = newrtc->resolution / 2 / 1000000; in clock_register_flags()
221 newrtc->resadj.tv_nsec = newrtc->resolution / 2 % 1000000 * 1000; in clock_register_flags()
222 TIMEOUT_TASK_INIT(taskqueue_thread, &newrtc->stask, 0, in clock_register_flags()
229 LIST_FOREACH(rtc, &rtc_list, rtc_entries) { in clock_register_flags()
230 if (rtc->resolution > newrtc->resolution) { in clock_register_flags()
231 LIST_INSERT_BEFORE(rtc, newrtc, rtc_entries); in clock_register_flags()
233 } else if (LIST_NEXT(rtc, rtc_entries) == NULL) { in clock_register_flags()
234 LIST_INSERT_AFTER(rtc, newrtc, rtc_entries); in clock_register_flags()
242 "registered as a time-of-day clock, resolution %d.%6.6ds\n", in clock_register_flags()
243 newrtc->resolution / 1000000, newrtc->resolution % 1000000); in clock_register_flags()
256 struct rtc_instance *rtc, *tmp; in clock_unregister() local
259 LIST_FOREACH_SAFE(rtc, &rtc_list, rtc_entries, tmp) { in clock_unregister()
260 if (rtc->clockdev == clockdev) { in clock_unregister()
261 LIST_REMOVE(rtc, rtc_entries); in clock_unregister()
266 if (rtc != NULL) { in clock_unregister()
267 taskqueue_cancel_timeout(taskqueue_thread, &rtc->stask, NULL); in clock_unregister()
268 taskqueue_drain_timeout(taskqueue_thread, &rtc->stask); in clock_unregister()
269 free(rtc, M_DEVBUF); in clock_unregister()
276 struct rtc_instance *rtc; in clock_schedule() local
279 LIST_FOREACH(rtc, &rtc_list, rtc_entries) { in clock_schedule()
280 if (rtc->clockdev == clockdev) { in clock_schedule()
281 rtc->schedns = offsetns; in clock_schedule()
291 struct rtc_instance *rtc; in read_clocks() local
296 LIST_FOREACH(rtc, &rtc_list, rtc_entries) { in read_clocks()
297 if ((error = CLOCK_GETTIME(rtc->clockdev, ts)) != 0) in read_clocks()
299 if (ts->tv_sec < 0 || ts->tv_nsec < 0) { in read_clocks()
303 if (!(rtc->flags & CLOCKF_GETTIME_NO_ADJ)) { in read_clocks()
304 timespecadd(ts, &rtc->resadj, ts); in read_clocks()
305 ts->tv_sec += utc_offset(); in read_clocks()
309 device_printf(rtc->clockdev, in read_clocks()
325 * non-zero. The 'base' time is potentially highly inaccurate, such as the last
326 * known good value of the system clock, or even a filesystem last-updated
346 printf("Warning: no time-of-day clock registered, "); in inittodr()
349 printf("Warning: bad time from time-of-day clock, "); in inittodr()
352 printf("Error reading time-of-day clock (%d), ", error); in inittodr()
356 ts.tv_sec = (base > 0) ? base : -1; in inittodr()
377 struct rtc_instance *rtc; in resettodr() local
385 LIST_FOREACH(rtc, &rtc_list, rtc_entries) { in resettodr()
386 if (rtc->schedns != 0) { in resettodr()
388 waitns = rtc->schedns - now.tv_nsec; in resettodr()
395 &rtc->stask, -sbt, 0, C_PREL(31)); in resettodr()
408 if (error != 0 || req->newptr == NULL) in sysctl_clock_do_io()
414 printf("No registered RTC clocks\n"); in sysctl_clock_do_io()