1 /* $NetBSD: rtc.c,v 1.5 2006/03/08 03:29:49 christos Exp $ */
3 * Copyright (c) 1997 Rolf Grossmann
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Rolf Grossmann.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/param.h>
33 #include <next68k/dev/clockreg.h>
34 #include <machine/cpu.h>
35 #include <lib/libsa/stand.h>
36 #include <lib/libsa/net.h>
38 u_char
rtc_read(u_char
);
42 /* ### where shall I put this definition? */
43 #define DELAY(n) { register int N = (n); while (--N > 0); }
45 static volatile u_int
*scr2
= (u_int
*)NEXT_P_SCR2_CON
;
46 static u_char new_clock
;
55 *scr2
= (*scr2
& ~(SCR2_RTDATA
| SCR2_RTCLK
)) | SCR2_RTCE
;
60 tmp
= *scr2
& ~(SCR2_RTDATA
| SCR2_RTCLK
);
66 *scr2
= tmp
| SCR2_RTCLK
;
74 val
= 0; /* should be anyway */
78 tmp
= *scr2
& ~(SCR2_RTDATA
| SCR2_RTCLK
);
80 *scr2
= tmp
| SCR2_RTCLK
;
85 if (*scr2
& SCR2_RTDATA
)
89 *scr2
&= ~(SCR2_RTDATA
|SCR2_RTCLK
|SCR2_RTCE
);
100 val
= rtc_read(RTC_STATUS
);
101 new_clock
= (val
& RTC_NEW_CLOCK
) ? 1 : 0;
110 secs
= rtc_read(RTC_CNTR0
) << 24 |
111 rtc_read(RTC_CNTR1
) << 16 |
112 rtc_read(RTC_CNTR2
) << 8 |
116 #define BCD_DECODE(x) (((x) >> 4) * 10 + ((x) & 0xf))
118 d
= rtc_read(RTC_DAY
);
119 h
= rtc_read(RTC_HRS
);
120 m
= rtc_read(RTC_MIN
);
121 s
= rtc_read(RTC_SEC
);
122 secs
= BCD_DECODE(d
) * (60*60*24) +
123 BCD_DECODE(h
) * (60*60) +