1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
|
/* $OpenBSD: mcclock.c,v 1.3 1996/10/30 22:38:16 niklas Exp $ */
/* $NetBSD: mcclock.c,v 1.4 1996/10/13 02:59:41 christos Exp $ */
/*
* Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
* All rights reserved.
*
* Author: Chris G. Demetriou
*
* Permission to use, copy, modify and distribute this software and
* its documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
* FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include <sys/param.h>
#include <sys/kernel.h>
#include <sys/systm.h>
#include <sys/device.h>
#include <alpha/alpha/clockvar.h>
#include <alpha/alpha/mcclockvar.h>
#include <dev/ic/mc146818reg.h>
struct cfdriver mcclock_cd = {
NULL, "mcclock", DV_DULL,
};
void mcclock_init __P((struct device *));
void mcclock_get __P((struct device *, time_t, struct clocktime *));
void mcclock_set __P((struct device *, struct clocktime *));
const struct clockfns mcclock_clockfns = {
mcclock_init, mcclock_get, mcclock_set,
};
#define mc146818_write(dev, reg, datum) \
(*(dev)->sc_busfns->mc_bf_write)(dev, reg, datum)
#define mc146818_read(dev, reg) \
(*(dev)->sc_busfns->mc_bf_read)(dev, reg)
void
mcclock_attach(sc, busfns)
struct mcclock_softc *sc;
const struct mcclock_busfns *busfns;
{
printf(": mc146818 or compatible");
sc->sc_busfns = busfns;
/* Turn interrupts off, just in case. */
mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
clockattach(&sc->sc_dev, &mcclock_clockfns);
}
void
mcclock_init(dev)
struct device *dev;
{
struct mcclock_softc *sc = (struct mcclock_softc *)dev;
mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);
mc146818_write(sc, MC_REGB,
MC_REGB_PIE | MC_REGB_BINARY | MC_REGB_24HR);
}
/*
* Get the time of day, based on the clock's value and/or the base value.
*/
void
mcclock_get(dev, base, ct)
struct device *dev;
time_t base;
struct clocktime *ct;
{
struct mcclock_softc *sc = (struct mcclock_softc *)dev;
mc_todregs regs;
int s;
s = splclock();
MC146818_GETTOD(sc, ®s)
splx(s);
ct->sec = regs[MC_SEC];
ct->min = regs[MC_MIN];
ct->hour = regs[MC_HOUR];
ct->dow = regs[MC_DOW];
ct->day = regs[MC_DOM];
ct->mon = regs[MC_MONTH];
ct->year = regs[MC_YEAR];
}
/*
* Reset the TODR based on the time value.
*/
void
mcclock_set(dev, ct)
struct device *dev;
struct clocktime *ct;
{
struct mcclock_softc *sc = (struct mcclock_softc *)dev;
mc_todregs regs;
int s;
s = splclock();
MC146818_GETTOD(sc, ®s);
splx(s);
regs[MC_SEC] = ct->sec;
regs[MC_MIN] = ct->min;
regs[MC_HOUR] = ct->hour;
regs[MC_DOW] = ct->dow;
regs[MC_DOM] = ct->day;
regs[MC_MONTH] = ct->mon;
regs[MC_YEAR] = ct->year;
s = splclock();
MC146818_PUTTOD(sc, ®s);
splx(s);
}
|