1 /* $NetBSD: mcclock.c,v 1.11 1998/04/19 07:50:25 jonathan Exp $ */
7 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
10 * Author: Chris G. Demetriou
12 * Permission to use, copy, modify and distribute this software and
13 * its documentation is hereby granted, provided that both the copyright
14 * notice and this permission notice appear in all copies of the
15 * software, derivative works or modified versions, and any portions
16 * thereof, and that both notices appear in supporting documentation.
18 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
19 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
20 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
22 * Carnegie Mellon requests users of this software to return to
24 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
25 * School of Computer Science
26 * Carnegie Mellon University
27 * Pittsburgh PA 15213-3890
29 * any improvements or extensions that they make and grant Carnegie the
30 * rights to redistribute these changes.
33 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
38 #include <machine/clockvar.h>
39 #include <dev/dec/mcclockvar.h>
40 #include <dev/dec/mc146818reg.h>
43 * XXX rate is machine-dependent.
46 #define MC_DEFAULTRATE MC_RATE_1024_Hz
49 #define MC_DEFAULTRATE MC_RATE_256_Hz
53 mcclock_attach(device_t dev)
55 /* Turn interrupts off, just in case. */
56 MCCLOCK_WRITE(dev, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
62 mcclock_init(device_t dev)
64 MCCLOCK_WRITE(dev, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE);
65 MCCLOCK_WRITE(dev, MC_REGB,
66 MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR);
70 * Get the time of day, based on the clock's value and/or the base value.
73 mcclock_get(device_t dev, time_t base, struct clocktime *ct)
79 MC146818_GETTOD(dev, ®s)
82 ct->sec = regs[MC_SEC];
83 ct->min = regs[MC_MIN];
84 ct->hour = regs[MC_HOUR];
85 ct->dow = regs[MC_DOW];
86 ct->day = regs[MC_DOM];
87 ct->mon = regs[MC_MONTH];
88 ct->year = regs[MC_YEAR];
92 * Reset the TODR based on the time value.
95 mcclock_set(device_t dev, struct clocktime *ct)
101 MC146818_GETTOD(dev, ®s);
104 regs[MC_SEC] = ct->sec;
105 regs[MC_MIN] = ct->min;
106 regs[MC_HOUR] = ct->hour;
107 regs[MC_DOW] = ct->dow;
108 regs[MC_DOM] = ct->day;
109 regs[MC_MONTH] = ct->mon;
110 regs[MC_YEAR] = ct->year;
113 MC146818_PUTTOD(dev, ®s);
118 mcclock_getsecs(device_t dev, int *secp)
120 int timeout = 100000000;
126 if (!(MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP)) {
127 sec = MCCLOCK_READ(dev, MC_SEC);