clock.c revision 1.8.2.6 1 1.8.2.6 yamt /* $NetBSD: clock.c,v 1.8.2.6 2007/12/07 17:26:57 yamt Exp $ */
2 1.8.2.2 yamt
3 1.8.2.2 yamt /*-
4 1.8.2.2 yamt * Copyright (c) 1990 The Regents of the University of California.
5 1.8.2.2 yamt * All rights reserved.
6 1.8.2.2 yamt *
7 1.8.2.2 yamt * This code is derived from software contributed to Berkeley by
8 1.8.2.2 yamt * William Jolitz and Don Ahn.
9 1.8.2.2 yamt *
10 1.8.2.2 yamt * Redistribution and use in source and binary forms, with or without
11 1.8.2.2 yamt * modification, are permitted provided that the following conditions
12 1.8.2.2 yamt * are met:
13 1.8.2.2 yamt * 1. Redistributions of source code must retain the above copyright
14 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer.
15 1.8.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
16 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer in the
17 1.8.2.2 yamt * documentation and/or other materials provided with the distribution.
18 1.8.2.2 yamt * 3. Neither the name of the University nor the names of its contributors
19 1.8.2.2 yamt * may be used to endorse or promote products derived from this software
20 1.8.2.2 yamt * without specific prior written permission.
21 1.8.2.2 yamt *
22 1.8.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 1.8.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 1.8.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 1.8.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 1.8.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 1.8.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 1.8.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 1.8.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 1.8.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 1.8.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 1.8.2.2 yamt * SUCH DAMAGE.
33 1.8.2.2 yamt *
34 1.8.2.2 yamt * @(#)clock.c 7.2 (Berkeley) 5/12/91
35 1.8.2.2 yamt */
36 1.8.2.2 yamt /*-
37 1.8.2.2 yamt * Copyright (c) 1993, 1994 Charles M. Hannum.
38 1.8.2.2 yamt *
39 1.8.2.2 yamt * This code is derived from software contributed to Berkeley by
40 1.8.2.2 yamt * William Jolitz and Don Ahn.
41 1.8.2.2 yamt *
42 1.8.2.2 yamt * Redistribution and use in source and binary forms, with or without
43 1.8.2.2 yamt * modification, are permitted provided that the following conditions
44 1.8.2.2 yamt * are met:
45 1.8.2.2 yamt * 1. Redistributions of source code must retain the above copyright
46 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer.
47 1.8.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
48 1.8.2.2 yamt * notice, this list of conditions and the following disclaimer in the
49 1.8.2.2 yamt * documentation and/or other materials provided with the distribution.
50 1.8.2.2 yamt * 3. All advertising materials mentioning features or use of this software
51 1.8.2.2 yamt * must display the following acknowledgement:
52 1.8.2.2 yamt * This product includes software developed by the University of
53 1.8.2.2 yamt * California, Berkeley and its contributors.
54 1.8.2.2 yamt * 4. Neither the name of the University nor the names of its contributors
55 1.8.2.2 yamt * may be used to endorse or promote products derived from this software
56 1.8.2.2 yamt * without specific prior written permission.
57 1.8.2.2 yamt *
58 1.8.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.8.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.8.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.8.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.8.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.8.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.8.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.8.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.8.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.8.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.8.2.2 yamt * SUCH DAMAGE.
69 1.8.2.2 yamt *
70 1.8.2.2 yamt * @(#)clock.c 7.2 (Berkeley) 5/12/91
71 1.8.2.2 yamt */
72 1.8.2.2 yamt /*
73 1.8.2.2 yamt * Mach Operating System
74 1.8.2.2 yamt * Copyright (c) 1991,1990,1989 Carnegie Mellon University
75 1.8.2.2 yamt * All Rights Reserved.
76 1.8.2.2 yamt *
77 1.8.2.2 yamt * Permission to use, copy, modify and distribute this software and its
78 1.8.2.2 yamt * documentation is hereby granted, provided that both the copyright
79 1.8.2.2 yamt * notice and this permission notice appear in all copies of the
80 1.8.2.2 yamt * software, derivative works or modified versions, and any portions
81 1.8.2.2 yamt * thereof, and that both notices appear in supporting documentation.
82 1.8.2.2 yamt *
83 1.8.2.2 yamt * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
84 1.8.2.2 yamt * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
85 1.8.2.2 yamt * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
86 1.8.2.2 yamt *
87 1.8.2.2 yamt * Carnegie Mellon requests users of this software to return to
88 1.8.2.2 yamt *
89 1.8.2.2 yamt * Software Distribution Coordinator or Software.Distribution (at) CS.CMU.EDU
90 1.8.2.2 yamt * School of Computer Science
91 1.8.2.2 yamt * Carnegie Mellon University
92 1.8.2.2 yamt * Pittsburgh PA 15213-3890
93 1.8.2.2 yamt *
94 1.8.2.2 yamt * any improvements or extensions that they make and grant Carnegie Mellon
95 1.8.2.2 yamt * the rights to redistribute these changes.
96 1.8.2.2 yamt */
97 1.8.2.2 yamt /*
98 1.8.2.2 yamt Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
99 1.8.2.2 yamt
100 1.8.2.2 yamt All Rights Reserved
101 1.8.2.2 yamt
102 1.8.2.2 yamt Permission to use, copy, modify, and distribute this software and
103 1.8.2.2 yamt its documentation for any purpose and without fee is hereby
104 1.8.2.2 yamt granted, provided that the above copyright notice appears in all
105 1.8.2.2 yamt copies and that both the copyright notice and this permission notice
106 1.8.2.2 yamt appear in supporting documentation, and that the name of Intel
107 1.8.2.2 yamt not be used in advertising or publicity pertaining to distribution
108 1.8.2.2 yamt of the software without specific, written prior permission.
109 1.8.2.2 yamt
110 1.8.2.2 yamt INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
111 1.8.2.2 yamt INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
112 1.8.2.2 yamt IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
113 1.8.2.2 yamt CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
114 1.8.2.2 yamt LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
115 1.8.2.2 yamt NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
116 1.8.2.2 yamt WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
117 1.8.2.2 yamt */
118 1.8.2.2 yamt
119 1.8.2.2 yamt /*
120 1.8.2.2 yamt * Primitive clock interrupt routines.
121 1.8.2.2 yamt */
122 1.8.2.2 yamt
123 1.8.2.2 yamt #include <sys/cdefs.h>
124 1.8.2.6 yamt __KERNEL_RCSID(0, "$NetBSD: clock.c,v 1.8.2.6 2007/12/07 17:26:57 yamt Exp $");
125 1.8.2.2 yamt
126 1.8.2.2 yamt /* #define CLOCKDEBUG */
127 1.8.2.2 yamt /* #define CLOCK_PARANOIA */
128 1.8.2.2 yamt
129 1.8.2.2 yamt #include "opt_multiprocessor.h"
130 1.8.2.2 yamt #include "opt_ntp.h"
131 1.8.2.2 yamt
132 1.8.2.2 yamt #include <sys/param.h>
133 1.8.2.2 yamt #include <sys/systm.h>
134 1.8.2.2 yamt #include <sys/time.h>
135 1.8.2.2 yamt #include <sys/timetc.h>
136 1.8.2.2 yamt #include <sys/kernel.h>
137 1.8.2.2 yamt #include <sys/device.h>
138 1.8.2.3 yamt #include <sys/mutex.h>
139 1.8.2.2 yamt
140 1.8.2.2 yamt #include <machine/cpu.h>
141 1.8.2.2 yamt #include <machine/intr.h>
142 1.8.2.2 yamt #include <machine/pio.h>
143 1.8.2.2 yamt #include <machine/cpufunc.h>
144 1.8.2.2 yamt
145 1.8.2.2 yamt #include <dev/isa/isareg.h>
146 1.8.2.2 yamt #include <dev/isa/isavar.h>
147 1.8.2.2 yamt #include <dev/ic/mc146818reg.h>
148 1.8.2.2 yamt #include <dev/ic/i8253reg.h>
149 1.8.2.2 yamt #include <i386/isa/nvram.h>
150 1.8.2.2 yamt #include <x86/x86/tsc.h>
151 1.8.2.2 yamt #include <dev/clock_subr.h>
152 1.8.2.2 yamt #include <machine/specialreg.h>
153 1.8.2.2 yamt
154 1.8.2.2 yamt #include "config_time.h" /* for CONFIG_TIME */
155 1.8.2.2 yamt
156 1.8.2.2 yamt #ifndef __x86_64__
157 1.8.2.2 yamt #include "mca.h"
158 1.8.2.2 yamt #endif
159 1.8.2.2 yamt #if NMCA > 0
160 1.8.2.2 yamt #include <machine/mca_machdep.h> /* for MCA_system */
161 1.8.2.2 yamt #endif
162 1.8.2.2 yamt
163 1.8.2.2 yamt #include "pcppi.h"
164 1.8.2.2 yamt #if (NPCPPI > 0)
165 1.8.2.2 yamt #include <dev/isa/pcppivar.h>
166 1.8.2.2 yamt
167 1.8.2.2 yamt int sysbeepmatch(struct device *, struct cfdata *, void *);
168 1.8.2.2 yamt void sysbeepattach(struct device *, struct device *, void *);
169 1.8.2.2 yamt
170 1.8.2.2 yamt CFATTACH_DECL(sysbeep, sizeof(struct device),
171 1.8.2.2 yamt sysbeepmatch, sysbeepattach, NULL, NULL);
172 1.8.2.2 yamt
173 1.8.2.2 yamt static int ppi_attached;
174 1.8.2.2 yamt static pcppi_tag_t ppicookie;
175 1.8.2.2 yamt #endif /* PCPPI */
176 1.8.2.2 yamt
177 1.8.2.2 yamt #ifdef CLOCKDEBUG
178 1.8.2.2 yamt int clock_debug = 0;
179 1.8.2.2 yamt #define DPRINTF(arg) if (clock_debug) printf arg
180 1.8.2.2 yamt #else
181 1.8.2.2 yamt #define DPRINTF(arg)
182 1.8.2.2 yamt #endif
183 1.8.2.2 yamt
184 1.8.2.4 yamt /* Used by lapic.c */
185 1.8.2.4 yamt unsigned int gettick(void);
186 1.8.2.2 yamt void sysbeep(int, int);
187 1.8.2.2 yamt static void tickle_tc(void);
188 1.8.2.2 yamt
189 1.8.2.2 yamt static int clockintr(void *, struct intrframe *);
190 1.8.2.2 yamt static void rtcinit(void);
191 1.8.2.2 yamt static int rtcget(mc_todregs *);
192 1.8.2.2 yamt static void rtcput(mc_todregs *);
193 1.8.2.2 yamt
194 1.8.2.2 yamt static int cmoscheck(void);
195 1.8.2.2 yamt
196 1.8.2.2 yamt static int clock_expandyear(int);
197 1.8.2.2 yamt
198 1.8.2.4 yamt static unsigned int gettick_broken_latch(void);
199 1.8.2.2 yamt
200 1.8.2.2 yamt static volatile uint32_t i8254_lastcount;
201 1.8.2.2 yamt static volatile uint32_t i8254_offset;
202 1.8.2.2 yamt static volatile int i8254_ticked;
203 1.8.2.2 yamt
204 1.8.2.3 yamt /* to protect TC timer variables */
205 1.8.2.3 yamt static __cpu_simple_lock_t tmr_lock = __SIMPLELOCK_UNLOCKED;
206 1.8.2.2 yamt
207 1.8.2.2 yamt inline u_int mc146818_read(void *, u_int);
208 1.8.2.2 yamt inline void mc146818_write(void *, u_int, u_int);
209 1.8.2.2 yamt
210 1.8.2.2 yamt u_int i8254_get_timecount(struct timecounter *);
211 1.8.2.2 yamt static void rtc_register(void);
212 1.8.2.2 yamt
213 1.8.2.2 yamt static struct timecounter i8254_timecounter = {
214 1.8.2.2 yamt i8254_get_timecount, /* get_timecount */
215 1.8.2.2 yamt 0, /* no poll_pps */
216 1.8.2.2 yamt ~0u, /* counter_mask */
217 1.8.2.2 yamt TIMER_FREQ, /* frequency */
218 1.8.2.2 yamt "i8254", /* name */
219 1.8.2.2 yamt 100, /* quality */
220 1.8.2.2 yamt NULL, /* prev */
221 1.8.2.2 yamt NULL, /* next */
222 1.8.2.2 yamt };
223 1.8.2.2 yamt
224 1.8.2.2 yamt /* XXX use sc? */
225 1.8.2.2 yamt inline u_int
226 1.8.2.2 yamt mc146818_read(void *sc, u_int reg)
227 1.8.2.2 yamt {
228 1.8.2.2 yamt
229 1.8.2.2 yamt outb(IO_RTC, reg);
230 1.8.2.2 yamt return (inb(IO_RTC+1));
231 1.8.2.2 yamt }
232 1.8.2.2 yamt
233 1.8.2.2 yamt /* XXX use sc? */
234 1.8.2.2 yamt inline void
235 1.8.2.2 yamt mc146818_write(void *sc, u_int reg, u_int datum)
236 1.8.2.2 yamt {
237 1.8.2.2 yamt
238 1.8.2.2 yamt outb(IO_RTC, reg);
239 1.8.2.2 yamt outb(IO_RTC+1, datum);
240 1.8.2.2 yamt }
241 1.8.2.2 yamt
242 1.8.2.2 yamt u_long rtclock_tval; /* i8254 reload value for countdown */
243 1.8.2.2 yamt int rtclock_init = 0;
244 1.8.2.2 yamt
245 1.8.2.2 yamt int clock_broken_latch = 0;
246 1.8.2.2 yamt
247 1.8.2.2 yamt #ifdef CLOCK_PARANOIA
248 1.8.2.2 yamt static int ticks[6];
249 1.8.2.2 yamt #endif
250 1.8.2.2 yamt /*
251 1.8.2.2 yamt * i8254 latch check routine:
252 1.8.2.2 yamt * National Geode (formerly Cyrix MediaGX) has a serious bug in
253 1.8.2.2 yamt * its built-in i8254-compatible clock module.
254 1.8.2.2 yamt * machdep sets the variable 'clock_broken_latch' to indicate it.
255 1.8.2.2 yamt */
256 1.8.2.2 yamt
257 1.8.2.4 yamt static unsigned int
258 1.8.2.2 yamt gettick_broken_latch(void)
259 1.8.2.2 yamt {
260 1.8.2.2 yamt int v1, v2, v3;
261 1.8.2.2 yamt int w1, w2, w3;
262 1.8.2.6 yamt int s;
263 1.8.2.2 yamt
264 1.8.2.2 yamt /* Don't want someone screwing with the counter while we're here. */
265 1.8.2.6 yamt s = splhigh();
266 1.8.2.6 yamt __cpu_simple_lock(&tmr_lock);
267 1.8.2.2 yamt v1 = inb(IO_TIMER1+TIMER_CNTR0);
268 1.8.2.2 yamt v1 |= inb(IO_TIMER1+TIMER_CNTR0) << 8;
269 1.8.2.2 yamt v2 = inb(IO_TIMER1+TIMER_CNTR0);
270 1.8.2.2 yamt v2 |= inb(IO_TIMER1+TIMER_CNTR0) << 8;
271 1.8.2.2 yamt v3 = inb(IO_TIMER1+TIMER_CNTR0);
272 1.8.2.2 yamt v3 |= inb(IO_TIMER1+TIMER_CNTR0) << 8;
273 1.8.2.6 yamt __cpu_simple_unlock(&tmr_lock);
274 1.8.2.6 yamt splx(s);
275 1.8.2.2 yamt
276 1.8.2.2 yamt #ifdef CLOCK_PARANOIA
277 1.8.2.2 yamt if (clock_debug) {
278 1.8.2.2 yamt ticks[0] = ticks[3];
279 1.8.2.2 yamt ticks[1] = ticks[4];
280 1.8.2.2 yamt ticks[2] = ticks[5];
281 1.8.2.2 yamt ticks[3] = v1;
282 1.8.2.2 yamt ticks[4] = v2;
283 1.8.2.2 yamt ticks[5] = v3;
284 1.8.2.2 yamt }
285 1.8.2.2 yamt #endif
286 1.8.2.2 yamt
287 1.8.2.2 yamt if (v1 >= v2 && v2 >= v3 && v1 - v3 < 0x200)
288 1.8.2.2 yamt return (v2);
289 1.8.2.2 yamt
290 1.8.2.2 yamt #define _swap_val(a, b) do { \
291 1.8.2.2 yamt int c = a; \
292 1.8.2.2 yamt a = b; \
293 1.8.2.2 yamt b = c; \
294 1.8.2.2 yamt } while (0)
295 1.8.2.2 yamt
296 1.8.2.2 yamt /*
297 1.8.2.2 yamt * sort v1 v2 v3
298 1.8.2.2 yamt */
299 1.8.2.2 yamt if (v1 < v2)
300 1.8.2.2 yamt _swap_val(v1, v2);
301 1.8.2.2 yamt if (v2 < v3)
302 1.8.2.2 yamt _swap_val(v2, v3);
303 1.8.2.2 yamt if (v1 < v2)
304 1.8.2.2 yamt _swap_val(v1, v2);
305 1.8.2.2 yamt
306 1.8.2.2 yamt /*
307 1.8.2.2 yamt * compute the middle value
308 1.8.2.2 yamt */
309 1.8.2.2 yamt
310 1.8.2.2 yamt if (v1 - v3 < 0x200)
311 1.8.2.2 yamt return (v2);
312 1.8.2.2 yamt
313 1.8.2.2 yamt w1 = v2 - v3;
314 1.8.2.2 yamt w2 = v3 - v1 + rtclock_tval;
315 1.8.2.2 yamt w3 = v1 - v2;
316 1.8.2.2 yamt if (w1 >= w2) {
317 1.8.2.2 yamt if (w1 >= w3)
318 1.8.2.2 yamt return (v1);
319 1.8.2.2 yamt } else {
320 1.8.2.2 yamt if (w2 >= w3)
321 1.8.2.2 yamt return (v2);
322 1.8.2.2 yamt }
323 1.8.2.2 yamt return (v3);
324 1.8.2.2 yamt }
325 1.8.2.2 yamt
326 1.8.2.2 yamt /* minimal initialization, enough for delay() */
327 1.8.2.2 yamt void
328 1.8.2.2 yamt initrtclock(u_long freq)
329 1.8.2.2 yamt {
330 1.8.2.2 yamt u_long tval;
331 1.8.2.3 yamt
332 1.8.2.2 yamt /*
333 1.8.2.2 yamt * Compute timer_count, the count-down count the timer will be
334 1.8.2.2 yamt * set to. Also, correctly round
335 1.8.2.2 yamt * this by carrying an extra bit through the division.
336 1.8.2.2 yamt */
337 1.8.2.2 yamt tval = (freq * 2) / (u_long) hz;
338 1.8.2.2 yamt tval = (tval / 2) + (tval & 0x1);
339 1.8.2.2 yamt
340 1.8.2.2 yamt /* initialize 8254 clock */
341 1.8.2.2 yamt outb(IO_TIMER1+TIMER_MODE, TIMER_SEL0|TIMER_RATEGEN|TIMER_16BIT);
342 1.8.2.2 yamt
343 1.8.2.2 yamt /* Correct rounding will buy us a better precision in timekeeping */
344 1.8.2.2 yamt outb(IO_TIMER1+TIMER_CNTR0, tval % 256);
345 1.8.2.2 yamt outb(IO_TIMER1+TIMER_CNTR0, tval / 256);
346 1.8.2.2 yamt
347 1.8.2.2 yamt rtclock_tval = tval ? tval : 0xFFFF;
348 1.8.2.2 yamt rtclock_init = 1;
349 1.8.2.2 yamt }
350 1.8.2.2 yamt
351 1.8.2.2 yamt void
352 1.8.2.2 yamt startrtclock(void)
353 1.8.2.2 yamt {
354 1.8.2.2 yamt int s;
355 1.8.2.2 yamt
356 1.8.2.2 yamt if (!rtclock_init)
357 1.8.2.2 yamt initrtclock(TIMER_FREQ);
358 1.8.2.2 yamt
359 1.8.2.2 yamt /* Check diagnostic status */
360 1.8.2.2 yamt if ((s = mc146818_read(NULL, NVRAM_DIAG)) != 0) { /* XXX softc */
361 1.8.2.2 yamt char bits[128];
362 1.8.2.2 yamt printf("RTC BIOS diagnostic error %s\n",
363 1.8.2.2 yamt bitmask_snprintf(s, NVRAM_DIAG_BITS, bits, sizeof(bits)));
364 1.8.2.2 yamt }
365 1.8.2.2 yamt
366 1.8.2.2 yamt tc_init(&i8254_timecounter);
367 1.8.2.2 yamt
368 1.8.2.2 yamt init_TSC();
369 1.8.2.2 yamt rtc_register();
370 1.8.2.2 yamt }
371 1.8.2.2 yamt
372 1.8.2.3 yamt /*
373 1.8.2.6 yamt * Must be called at splsched().
374 1.8.2.3 yamt */
375 1.8.2.2 yamt static void
376 1.8.2.2 yamt tickle_tc(void)
377 1.8.2.2 yamt {
378 1.8.2.2 yamt #if defined(MULTIPROCESSOR)
379 1.8.2.2 yamt struct cpu_info *ci = curcpu();
380 1.8.2.2 yamt /*
381 1.8.2.2 yamt * If we are not the primary CPU, we're not allowed to do
382 1.8.2.2 yamt * any more work.
383 1.8.2.2 yamt */
384 1.8.2.2 yamt if (CPU_IS_PRIMARY(ci) == 0)
385 1.8.2.2 yamt return;
386 1.8.2.2 yamt #endif
387 1.8.2.2 yamt if (rtclock_tval && timecounter->tc_get_timecount == i8254_get_timecount) {
388 1.8.2.3 yamt __cpu_simple_lock(&tmr_lock);
389 1.8.2.2 yamt if (i8254_ticked)
390 1.8.2.2 yamt i8254_ticked = 0;
391 1.8.2.2 yamt else {
392 1.8.2.2 yamt i8254_offset += rtclock_tval;
393 1.8.2.2 yamt i8254_lastcount = 0;
394 1.8.2.2 yamt }
395 1.8.2.3 yamt __cpu_simple_unlock(&tmr_lock);
396 1.8.2.2 yamt }
397 1.8.2.2 yamt
398 1.8.2.2 yamt }
399 1.8.2.2 yamt
400 1.8.2.2 yamt static int
401 1.8.2.2 yamt clockintr(void *arg, struct intrframe *frame)
402 1.8.2.2 yamt {
403 1.8.2.2 yamt tickle_tc();
404 1.8.2.2 yamt
405 1.8.2.2 yamt hardclock((struct clockframe *)frame);
406 1.8.2.2 yamt
407 1.8.2.2 yamt #if NMCA > 0
408 1.8.2.2 yamt if (MCA_system) {
409 1.8.2.2 yamt /* Reset PS/2 clock interrupt by asserting bit 7 of port 0x61 */
410 1.8.2.2 yamt outb(0x61, inb(0x61) | 0x80);
411 1.8.2.2 yamt }
412 1.8.2.2 yamt #endif
413 1.8.2.2 yamt return -1;
414 1.8.2.2 yamt }
415 1.8.2.2 yamt
416 1.8.2.2 yamt u_int
417 1.8.2.2 yamt i8254_get_timecount(struct timecounter *tc)
418 1.8.2.2 yamt {
419 1.8.2.2 yamt u_int count;
420 1.8.2.6 yamt uint16_t rdval;
421 1.8.2.6 yamt int s;
422 1.8.2.2 yamt
423 1.8.2.2 yamt /* Don't want someone screwing with the counter while we're here. */
424 1.8.2.6 yamt s = splhigh();
425 1.8.2.3 yamt __cpu_simple_lock(&tmr_lock);
426 1.8.2.2 yamt /* Select timer0 and latch counter value. */
427 1.8.2.2 yamt outb(IO_TIMER1 + TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
428 1.8.2.6 yamt /* insb to make the read atomic */
429 1.8.2.6 yamt insb(IO_TIMER1+TIMER_CNTR0, &rdval, 2);
430 1.8.2.6 yamt count = rtclock_tval - rdval;
431 1.8.2.2 yamt if (rtclock_tval && (count < i8254_lastcount || !i8254_ticked)) {
432 1.8.2.2 yamt i8254_ticked = 1;
433 1.8.2.2 yamt i8254_offset += rtclock_tval;
434 1.8.2.2 yamt }
435 1.8.2.2 yamt i8254_lastcount = count;
436 1.8.2.2 yamt count += i8254_offset;
437 1.8.2.3 yamt __cpu_simple_unlock(&tmr_lock);
438 1.8.2.6 yamt splx(s);
439 1.8.2.3 yamt
440 1.8.2.2 yamt return (count);
441 1.8.2.2 yamt }
442 1.8.2.2 yamt
443 1.8.2.4 yamt unsigned int
444 1.8.2.2 yamt gettick(void)
445 1.8.2.2 yamt {
446 1.8.2.6 yamt uint16_t rdval;
447 1.8.2.6 yamt int s;
448 1.8.2.6 yamt
449 1.8.2.2 yamt if (clock_broken_latch)
450 1.8.2.2 yamt return (gettick_broken_latch());
451 1.8.2.2 yamt
452 1.8.2.2 yamt /* Don't want someone screwing with the counter while we're here. */
453 1.8.2.6 yamt s = splhigh();
454 1.8.2.6 yamt __cpu_simple_lock(&tmr_lock);
455 1.8.2.2 yamt /* Select counter 0 and latch it. */
456 1.8.2.2 yamt outb(IO_TIMER1+TIMER_MODE, TIMER_SEL0 | TIMER_LATCH);
457 1.8.2.6 yamt /* insb to make the read atomic */
458 1.8.2.6 yamt insb(IO_TIMER1+TIMER_CNTR0, &rdval, 2);
459 1.8.2.6 yamt __cpu_simple_unlock(&tmr_lock);
460 1.8.2.6 yamt splx(s);
461 1.8.2.6 yamt
462 1.8.2.6 yamt return rdval;
463 1.8.2.2 yamt }
464 1.8.2.2 yamt
465 1.8.2.2 yamt /*
466 1.8.2.2 yamt * Wait approximately `n' microseconds.
467 1.8.2.2 yamt * Relies on timer 1 counting down from (TIMER_FREQ / hz) at TIMER_FREQ Hz.
468 1.8.2.2 yamt * Note: timer had better have been programmed before this is first used!
469 1.8.2.2 yamt * (Note that we use `rate generator' mode, which counts at 1:1; `square
470 1.8.2.2 yamt * wave' mode counts at 2:1).
471 1.8.2.2 yamt * Don't rely on this being particularly accurate.
472 1.8.2.2 yamt */
473 1.8.2.2 yamt void
474 1.8.2.4 yamt i8254_delay(unsigned int n)
475 1.8.2.2 yamt {
476 1.8.2.4 yamt unsigned int cur_tick, initial_tick;
477 1.8.2.4 yamt int remaining;
478 1.8.2.2 yamt static const int delaytab[26] = {
479 1.8.2.2 yamt 0, 2, 3, 4, 5, 6, 7, 9, 10, 11,
480 1.8.2.2 yamt 12, 13, 15, 16, 17, 18, 19, 21, 22, 23,
481 1.8.2.2 yamt 24, 25, 27, 28, 29, 30,
482 1.8.2.2 yamt };
483 1.8.2.2 yamt
484 1.8.2.2 yamt /* allow DELAY() to be used before startrtclock() */
485 1.8.2.2 yamt if (!rtclock_init)
486 1.8.2.2 yamt initrtclock(TIMER_FREQ);
487 1.8.2.2 yamt
488 1.8.2.2 yamt /*
489 1.8.2.2 yamt * Read the counter first, so that the rest of the setup overhead is
490 1.8.2.2 yamt * counted.
491 1.8.2.2 yamt */
492 1.8.2.4 yamt initial_tick = gettick();
493 1.8.2.2 yamt
494 1.8.2.2 yamt if (n <= 25)
495 1.8.2.4 yamt remaining = delaytab[n];
496 1.8.2.4 yamt else if (n <= UINT_MAX / TIMER_FREQ) {
497 1.8.2.2 yamt /*
498 1.8.2.4 yamt * For unsigned arithmetic, division can be replaced with
499 1.8.2.4 yamt * multiplication with the inverse and a shift.
500 1.8.2.2 yamt */
501 1.8.2.4 yamt remaining = n * TIMER_FREQ / 1000000;
502 1.8.2.4 yamt } else {
503 1.8.2.4 yamt /* This is a very long delay.
504 1.8.2.4 yamt * Being slow here doesn't matter.
505 1.8.2.2 yamt */
506 1.8.2.4 yamt remaining = (unsigned long long) n * TIMER_FREQ / 1000000;
507 1.8.2.2 yamt }
508 1.8.2.2 yamt
509 1.8.2.4 yamt while (remaining > 0) {
510 1.8.2.2 yamt #ifdef CLOCK_PARANOIA
511 1.8.2.2 yamt int delta;
512 1.8.2.4 yamt cur_tick = gettick();
513 1.8.2.4 yamt if (cur_tick > initial_tick)
514 1.8.2.4 yamt delta = rtclock_tval - (cur_tick - initial_tick);
515 1.8.2.2 yamt else
516 1.8.2.4 yamt delta = initial_tick - cur_tick;
517 1.8.2.2 yamt if (delta < 0 || delta >= rtclock_tval / 2) {
518 1.8.2.2 yamt DPRINTF(("delay: ignore ticks %.4x-%.4x",
519 1.8.2.4 yamt initial_tick, cur_tick));
520 1.8.2.2 yamt if (clock_broken_latch) {
521 1.8.2.2 yamt DPRINTF((" (%.4x %.4x %.4x %.4x %.4x %.4x)\n",
522 1.8.2.2 yamt ticks[0], ticks[1], ticks[2],
523 1.8.2.2 yamt ticks[3], ticks[4], ticks[5]));
524 1.8.2.2 yamt } else {
525 1.8.2.2 yamt DPRINTF(("\n"));
526 1.8.2.2 yamt }
527 1.8.2.2 yamt } else
528 1.8.2.4 yamt remaining -= delta;
529 1.8.2.2 yamt #else
530 1.8.2.4 yamt cur_tick = gettick();
531 1.8.2.4 yamt if (cur_tick > initial_tick)
532 1.8.2.4 yamt remaining -= rtclock_tval - (cur_tick - initial_tick);
533 1.8.2.2 yamt else
534 1.8.2.4 yamt remaining -= initial_tick - cur_tick;
535 1.8.2.2 yamt #endif
536 1.8.2.4 yamt initial_tick = cur_tick;
537 1.8.2.2 yamt }
538 1.8.2.2 yamt }
539 1.8.2.2 yamt
540 1.8.2.2 yamt #if (NPCPPI > 0)
541 1.8.2.2 yamt int
542 1.8.2.2 yamt sysbeepmatch(struct device *parent, struct cfdata *match,
543 1.8.2.2 yamt void *aux)
544 1.8.2.2 yamt {
545 1.8.2.2 yamt return (!ppi_attached);
546 1.8.2.2 yamt }
547 1.8.2.2 yamt
548 1.8.2.2 yamt void
549 1.8.2.2 yamt sysbeepattach(struct device *parent, struct device *self,
550 1.8.2.2 yamt void *aux)
551 1.8.2.2 yamt {
552 1.8.2.2 yamt aprint_naive("\n");
553 1.8.2.2 yamt aprint_normal("\n");
554 1.8.2.2 yamt
555 1.8.2.2 yamt ppicookie = ((struct pcppi_attach_args *)aux)->pa_cookie;
556 1.8.2.2 yamt ppi_attached = 1;
557 1.8.2.2 yamt }
558 1.8.2.2 yamt #endif
559 1.8.2.2 yamt
560 1.8.2.2 yamt void
561 1.8.2.2 yamt sysbeep(int pitch, int period)
562 1.8.2.2 yamt {
563 1.8.2.2 yamt #if (NPCPPI > 0)
564 1.8.2.2 yamt if (ppi_attached)
565 1.8.2.2 yamt pcppi_bell(ppicookie, pitch, period, 0);
566 1.8.2.2 yamt #endif
567 1.8.2.2 yamt }
568 1.8.2.2 yamt
569 1.8.2.2 yamt void
570 1.8.2.2 yamt i8254_initclocks(void)
571 1.8.2.2 yamt {
572 1.8.2.2 yamt
573 1.8.2.2 yamt /*
574 1.8.2.2 yamt * XXX If you're doing strange things with multiple clocks, you might
575 1.8.2.2 yamt * want to keep track of clock handlers.
576 1.8.2.2 yamt */
577 1.8.2.2 yamt (void)isa_intr_establish(NULL, 0, IST_PULSE, IPL_CLOCK,
578 1.8.2.2 yamt (int (*)(void *))clockintr, 0);
579 1.8.2.2 yamt }
580 1.8.2.2 yamt
581 1.8.2.2 yamt static void
582 1.8.2.2 yamt rtcinit(void)
583 1.8.2.2 yamt {
584 1.8.2.2 yamt static int first_rtcopen_ever = 1;
585 1.8.2.2 yamt
586 1.8.2.2 yamt if (!first_rtcopen_ever)
587 1.8.2.2 yamt return;
588 1.8.2.2 yamt first_rtcopen_ever = 0;
589 1.8.2.2 yamt
590 1.8.2.2 yamt mc146818_write(NULL, MC_REGA, /* XXX softc */
591 1.8.2.2 yamt MC_BASE_32_KHz | MC_RATE_1024_Hz);
592 1.8.2.2 yamt mc146818_write(NULL, MC_REGB, MC_REGB_24HR); /* XXX softc */
593 1.8.2.2 yamt }
594 1.8.2.2 yamt
595 1.8.2.2 yamt static int
596 1.8.2.2 yamt rtcget(mc_todregs *regs)
597 1.8.2.2 yamt {
598 1.8.2.2 yamt
599 1.8.2.2 yamt rtcinit();
600 1.8.2.2 yamt if ((mc146818_read(NULL, MC_REGD) & MC_REGD_VRT) == 0) /* XXX softc */
601 1.8.2.2 yamt return (-1);
602 1.8.2.2 yamt MC146818_GETTOD(NULL, regs); /* XXX softc */
603 1.8.2.2 yamt return (0);
604 1.8.2.2 yamt }
605 1.8.2.2 yamt
606 1.8.2.2 yamt static void
607 1.8.2.2 yamt rtcput(mc_todregs *regs)
608 1.8.2.2 yamt {
609 1.8.2.2 yamt
610 1.8.2.2 yamt rtcinit();
611 1.8.2.2 yamt MC146818_PUTTOD(NULL, regs); /* XXX softc */
612 1.8.2.2 yamt }
613 1.8.2.2 yamt
614 1.8.2.2 yamt /*
615 1.8.2.2 yamt * check whether the CMOS layout is "standard"-like (ie, not PS/2-like),
616 1.8.2.2 yamt * to be called at splclock()
617 1.8.2.2 yamt */
618 1.8.2.2 yamt static int
619 1.8.2.2 yamt cmoscheck(void)
620 1.8.2.2 yamt {
621 1.8.2.2 yamt int i;
622 1.8.2.2 yamt unsigned short cksum = 0;
623 1.8.2.2 yamt
624 1.8.2.2 yamt for (i = 0x10; i <= 0x2d; i++)
625 1.8.2.2 yamt cksum += mc146818_read(NULL, i); /* XXX softc */
626 1.8.2.2 yamt
627 1.8.2.2 yamt return (cksum == (mc146818_read(NULL, 0x2e) << 8)
628 1.8.2.2 yamt + mc146818_read(NULL, 0x2f));
629 1.8.2.2 yamt }
630 1.8.2.2 yamt
631 1.8.2.2 yamt #if NMCA > 0
632 1.8.2.2 yamt /*
633 1.8.2.2 yamt * Check whether the CMOS layout is PS/2 like, to be called at splclock().
634 1.8.2.2 yamt */
635 1.8.2.2 yamt static int cmoscheckps2(void);
636 1.8.2.2 yamt static int
637 1.8.2.2 yamt cmoscheckps2(void)
638 1.8.2.2 yamt {
639 1.8.2.2 yamt #if 0
640 1.8.2.2 yamt /* Disabled until I find out the CRC checksum algorithm IBM uses */
641 1.8.2.2 yamt int i;
642 1.8.2.2 yamt unsigned short cksum = 0;
643 1.8.2.2 yamt
644 1.8.2.2 yamt for (i = 0x10; i <= 0x31; i++)
645 1.8.2.2 yamt cksum += mc146818_read(NULL, i); /* XXX softc */
646 1.8.2.2 yamt
647 1.8.2.2 yamt return (cksum == (mc146818_read(NULL, 0x32) << 8)
648 1.8.2.2 yamt + mc146818_read(NULL, 0x33));
649 1.8.2.2 yamt #else
650 1.8.2.2 yamt /* Check 'incorrect checksum' bit of IBM PS/2 Diagnostic Status Byte */
651 1.8.2.2 yamt return ((mc146818_read(NULL, NVRAM_DIAG) & (1<<6)) == 0);
652 1.8.2.2 yamt #endif
653 1.8.2.2 yamt }
654 1.8.2.2 yamt #endif /* NMCA > 0 */
655 1.8.2.2 yamt
656 1.8.2.2 yamt /*
657 1.8.2.2 yamt * patchable to control century byte handling:
658 1.8.2.2 yamt * 1: always update
659 1.8.2.2 yamt * -1: never touch
660 1.8.2.2 yamt * 0: try to figure out itself
661 1.8.2.2 yamt */
662 1.8.2.2 yamt int rtc_update_century = 0;
663 1.8.2.2 yamt
664 1.8.2.2 yamt /*
665 1.8.2.2 yamt * Expand a two-digit year as read from the clock chip
666 1.8.2.2 yamt * into full width.
667 1.8.2.2 yamt * Being here, deal with the CMOS century byte.
668 1.8.2.2 yamt */
669 1.8.2.2 yamt static int centb = NVRAM_CENTURY;
670 1.8.2.2 yamt static int
671 1.8.2.2 yamt clock_expandyear(int clockyear)
672 1.8.2.2 yamt {
673 1.8.2.2 yamt int s, clockcentury, cmoscentury;
674 1.8.2.2 yamt
675 1.8.2.2 yamt clockcentury = (clockyear < 70) ? 20 : 19;
676 1.8.2.2 yamt clockyear += 100 * clockcentury;
677 1.8.2.2 yamt
678 1.8.2.2 yamt if (rtc_update_century < 0)
679 1.8.2.2 yamt return (clockyear);
680 1.8.2.2 yamt
681 1.8.2.2 yamt s = splclock();
682 1.8.2.2 yamt if (cmoscheck())
683 1.8.2.2 yamt cmoscentury = mc146818_read(NULL, NVRAM_CENTURY);
684 1.8.2.2 yamt #if NMCA > 0
685 1.8.2.2 yamt else if (MCA_system && cmoscheckps2())
686 1.8.2.2 yamt cmoscentury = mc146818_read(NULL, (centb = 0x37));
687 1.8.2.2 yamt #endif
688 1.8.2.2 yamt else
689 1.8.2.2 yamt cmoscentury = 0;
690 1.8.2.2 yamt splx(s);
691 1.8.2.2 yamt if (!cmoscentury) {
692 1.8.2.2 yamt #ifdef DIAGNOSTIC
693 1.8.2.2 yamt printf("clock: unknown CMOS layout\n");
694 1.8.2.2 yamt #endif
695 1.8.2.2 yamt return (clockyear);
696 1.8.2.2 yamt }
697 1.8.2.2 yamt cmoscentury = bcdtobin(cmoscentury);
698 1.8.2.2 yamt
699 1.8.2.2 yamt if (cmoscentury != clockcentury) {
700 1.8.2.2 yamt /* XXX note: saying "century is 20" might confuse the naive. */
701 1.8.2.2 yamt printf("WARNING: NVRAM century is %d but RTC year is %d\n",
702 1.8.2.2 yamt cmoscentury, clockyear);
703 1.8.2.2 yamt
704 1.8.2.2 yamt /* Kludge to roll over century. */
705 1.8.2.2 yamt if ((rtc_update_century > 0) ||
706 1.8.2.2 yamt ((cmoscentury == 19) && (clockcentury == 20) &&
707 1.8.2.2 yamt (clockyear == 2000))) {
708 1.8.2.2 yamt printf("WARNING: Setting NVRAM century to %d\n",
709 1.8.2.2 yamt clockcentury);
710 1.8.2.2 yamt s = splclock();
711 1.8.2.2 yamt mc146818_write(NULL, centb, bintobcd(clockcentury));
712 1.8.2.2 yamt splx(s);
713 1.8.2.2 yamt }
714 1.8.2.2 yamt } else if (cmoscentury == 19 && rtc_update_century == 0)
715 1.8.2.2 yamt rtc_update_century = 1; /* will update later in resettodr() */
716 1.8.2.2 yamt
717 1.8.2.2 yamt return (clockyear);
718 1.8.2.2 yamt }
719 1.8.2.2 yamt
720 1.8.2.2 yamt static int
721 1.8.2.2 yamt rtc_get_ymdhms(todr_chip_handle_t tch, struct clock_ymdhms *dt)
722 1.8.2.2 yamt {
723 1.8.2.2 yamt int s;
724 1.8.2.2 yamt mc_todregs rtclk;
725 1.8.2.2 yamt
726 1.8.2.2 yamt s = splclock();
727 1.8.2.2 yamt if (rtcget(&rtclk)) {
728 1.8.2.2 yamt splx(s);
729 1.8.2.2 yamt return -1;
730 1.8.2.2 yamt }
731 1.8.2.2 yamt splx(s);
732 1.8.2.2 yamt
733 1.8.2.2 yamt dt->dt_sec = bcdtobin(rtclk[MC_SEC]);
734 1.8.2.2 yamt dt->dt_min = bcdtobin(rtclk[MC_MIN]);
735 1.8.2.2 yamt dt->dt_hour = bcdtobin(rtclk[MC_HOUR]);
736 1.8.2.2 yamt dt->dt_day = bcdtobin(rtclk[MC_DOM]);
737 1.8.2.2 yamt dt->dt_mon = bcdtobin(rtclk[MC_MONTH]);
738 1.8.2.2 yamt dt->dt_year = clock_expandyear(bcdtobin(rtclk[MC_YEAR]));
739 1.8.2.2 yamt
740 1.8.2.2 yamt return 0;
741 1.8.2.2 yamt }
742 1.8.2.2 yamt
743 1.8.2.2 yamt static int
744 1.8.2.2 yamt rtc_set_ymdhms(todr_chip_handle_t tch, struct clock_ymdhms *dt)
745 1.8.2.2 yamt {
746 1.8.2.2 yamt mc_todregs rtclk;
747 1.8.2.2 yamt int century;
748 1.8.2.2 yamt int s;
749 1.8.2.2 yamt
750 1.8.2.2 yamt s = splclock();
751 1.8.2.2 yamt if (rtcget(&rtclk))
752 1.8.2.2 yamt memset(&rtclk, 0, sizeof(rtclk));
753 1.8.2.2 yamt splx(s);
754 1.8.2.2 yamt
755 1.8.2.2 yamt rtclk[MC_SEC] = bintobcd(dt->dt_sec);
756 1.8.2.2 yamt rtclk[MC_MIN] = bintobcd(dt->dt_min);
757 1.8.2.2 yamt rtclk[MC_HOUR] = bintobcd(dt->dt_hour);
758 1.8.2.2 yamt rtclk[MC_DOW] = dt->dt_wday + 1;
759 1.8.2.2 yamt rtclk[MC_YEAR] = bintobcd(dt->dt_year % 100);
760 1.8.2.2 yamt rtclk[MC_MONTH] = bintobcd(dt->dt_mon);
761 1.8.2.2 yamt rtclk[MC_DOM] = bintobcd(dt->dt_day);
762 1.8.2.2 yamt
763 1.8.2.2 yamt #ifdef DEBUG_CLOCK
764 1.8.2.2 yamt printf("setclock: %x/%x/%x %x:%x:%x\n", rtclk[MC_YEAR], rtclk[MC_MONTH],
765 1.8.2.2 yamt rtclk[MC_DOM], rtclk[MC_HOUR], rtclk[MC_MIN], rtclk[MC_SEC]);
766 1.8.2.2 yamt #endif
767 1.8.2.2 yamt s = splclock();
768 1.8.2.2 yamt rtcput(&rtclk);
769 1.8.2.2 yamt if (rtc_update_century > 0) {
770 1.8.2.2 yamt century = bintobcd(dt->dt_year / 100);
771 1.8.2.2 yamt mc146818_write(NULL, centb, century); /* XXX softc */
772 1.8.2.2 yamt }
773 1.8.2.2 yamt splx(s);
774 1.8.2.2 yamt return 0;
775 1.8.2.2 yamt
776 1.8.2.2 yamt }
777 1.8.2.2 yamt
778 1.8.2.2 yamt static void
779 1.8.2.2 yamt rtc_register(void)
780 1.8.2.2 yamt {
781 1.8.2.2 yamt static struct todr_chip_handle tch;
782 1.8.2.2 yamt tch.todr_gettime_ymdhms = rtc_get_ymdhms;
783 1.8.2.2 yamt tch.todr_settime_ymdhms = rtc_set_ymdhms;
784 1.8.2.2 yamt tch.todr_setwen = NULL;
785 1.8.2.2 yamt
786 1.8.2.2 yamt todr_attach(&tch);
787 1.8.2.2 yamt }
788 1.8.2.2 yamt
789 1.8.2.2 yamt void
790 1.8.2.2 yamt setstatclockrate(int arg)
791 1.8.2.2 yamt {
792 1.8.2.2 yamt }
793