1 /* $FreeBSD: src/sys/dev/dec/mcclock.c,v 1.5.2.2 2001/12/17 14:03:15 gallatin Exp $ */
2 /* $NetBSD: mcclock.c,v 1.11 1998/04/19 07:50:25 jonathan Exp $ */
5 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
8 * Author: Chris G. Demetriou
10 * Permission to use, copy, modify and distribute this software and
11 * its documentation is hereby granted, provided that both the copyright
12 * notice and this permission notice appear in all copies of the
13 * software, derivative works or modified versions, and any portions
14 * thereof, and that both notices appear in supporting documentation.
16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
20 * Carnegie Mellon requests users of this software to return to
22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
23 * School of Computer Science
24 * Carnegie Mellon University
25 * Pittsburgh PA 15213-3890
27 * any improvements or extensions that they make and grant Carnegie the
28 * rights to redistribute these changes.
31 #include <sys/param.h>
32 #include <sys/kernel.h>
33 #include <sys/systm.h>
36 #include <machine/clockvar.h>
37 #include <dev/dec/mcclockvar.h>
38 #include <dev/dec/mc146818reg.h>
41 * XXX rate is machine-dependent.
44 #define MC_DEFAULTRATE MC_RATE_1024_Hz
47 #define MC_DEFAULTRATE MC_RATE_256_Hz
51 mcclock_attach(device_t dev)
53 /* Turn interrupts off, just in case. */
54 MCCLOCK_WRITE(dev, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
60 mcclock_init(device_t dev)
62 MCCLOCK_WRITE(dev, MC_REGA, MC_BASE_32_KHz | MC_DEFAULTRATE);
63 MCCLOCK_WRITE(dev, MC_REGB,
64 MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR);
68 * Get the time of day, based on the clock's value and/or the base value.
71 mcclock_get(device_t dev, time_t base, struct clocktime *ct)
77 MC146818_GETTOD(dev, ®s)
80 ct->sec = regs[MC_SEC];
81 ct->min = regs[MC_MIN];
82 ct->hour = regs[MC_HOUR];
83 ct->dow = regs[MC_DOW];
84 ct->day = regs[MC_DOM];
85 ct->mon = regs[MC_MONTH];
86 ct->year = regs[MC_YEAR];
90 * Reset the TODR based on the time value.
93 mcclock_set(device_t dev, struct clocktime *ct)
99 MC146818_GETTOD(dev, ®s);
102 regs[MC_SEC] = ct->sec;
103 regs[MC_MIN] = ct->min;
104 regs[MC_HOUR] = ct->hour;
105 regs[MC_DOW] = ct->dow;
106 regs[MC_DOM] = ct->day;
107 regs[MC_MONTH] = ct->mon;
108 regs[MC_YEAR] = ct->year;
111 MC146818_PUTTOD(dev, ®s);
116 mcclock_getsecs(device_t dev, int *secp)
118 int timeout = 100000000;
124 if (!(MCCLOCK_READ(dev, MC_REGA) & MC_REGA_UIP)) {
125 sec = MCCLOCK_READ(dev, MC_SEC);