1*a07f7c80Stsutsui /* $NetBSD: clock.c,v 1.6 2008/01/12 09:54:33 tsutsui Exp $ */
20b036e11Schuck
30b036e11Schuck /*
40b036e11Schuck * Copyright (c) 1992, 1993
50b036e11Schuck * The Regents of the University of California. All rights reserved.
6aad01611Sagc *
7aad01611Sagc * This software was developed by the Computer Systems Engineering group
8aad01611Sagc * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9aad01611Sagc * contributed to Berkeley.
10aad01611Sagc *
11aad01611Sagc * All advertising materials mentioning features or use of this software
12aad01611Sagc * must display the following acknowledgement:
13aad01611Sagc * This product includes software developed by the University of
14aad01611Sagc * California, Lawrence Berkeley Laboratory.
15aad01611Sagc *
16aad01611Sagc * Redistribution and use in source and binary forms, with or without
17aad01611Sagc * modification, are permitted provided that the following conditions
18aad01611Sagc * are met:
19aad01611Sagc * 1. Redistributions of source code must retain the above copyright
20aad01611Sagc * notice, this list of conditions and the following disclaimer.
21aad01611Sagc * 2. Redistributions in binary form must reproduce the above copyright
22aad01611Sagc * notice, this list of conditions and the following disclaimer in the
23aad01611Sagc * documentation and/or other materials provided with the distribution.
24aad01611Sagc * 3. Neither the name of the University nor the names of its contributors
25aad01611Sagc * may be used to endorse or promote products derived from this software
26aad01611Sagc * without specific prior written permission.
27aad01611Sagc *
28aad01611Sagc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
29aad01611Sagc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30aad01611Sagc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31aad01611Sagc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
32aad01611Sagc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33aad01611Sagc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34aad01611Sagc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35aad01611Sagc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36aad01611Sagc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37aad01611Sagc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38aad01611Sagc * SUCH DAMAGE.
39aad01611Sagc *
40aad01611Sagc * @(#)clock.c 8.1 (Berkeley) 6/11/93
41aad01611Sagc */
42aad01611Sagc
43aad01611Sagc /*
440b036e11Schuck * Copyright (c) 1994 Gordon W. Ross
450b036e11Schuck * Copyright (c) 1993 Adam Glass
460b036e11Schuck *
470b036e11Schuck * This software was developed by the Computer Systems Engineering group
480b036e11Schuck * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
490b036e11Schuck * contributed to Berkeley.
500b036e11Schuck *
510b036e11Schuck * All advertising materials mentioning features or use of this software
520b036e11Schuck * must display the following acknowledgement:
530b036e11Schuck * This product includes software developed by the University of
540b036e11Schuck * California, Lawrence Berkeley Laboratory.
550b036e11Schuck *
560b036e11Schuck * Redistribution and use in source and binary forms, with or without
570b036e11Schuck * modification, are permitted provided that the following conditions
580b036e11Schuck * are met:
590b036e11Schuck * 1. Redistributions of source code must retain the above copyright
600b036e11Schuck * notice, this list of conditions and the following disclaimer.
610b036e11Schuck * 2. Redistributions in binary form must reproduce the above copyright
620b036e11Schuck * notice, this list of conditions and the following disclaimer in the
630b036e11Schuck * documentation and/or other materials provided with the distribution.
640b036e11Schuck * 3. All advertising materials mentioning features or use of this software
650b036e11Schuck * must display the following acknowledgement:
660b036e11Schuck * This product includes software developed by the University of
670b036e11Schuck * California, Berkeley and its contributors.
680b036e11Schuck * 4. Neither the name of the University nor the names of its contributors
690b036e11Schuck * may be used to endorse or promote products derived from this software
700b036e11Schuck * without specific prior written permission.
710b036e11Schuck *
720b036e11Schuck * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
730b036e11Schuck * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
740b036e11Schuck * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
750b036e11Schuck * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
760b036e11Schuck * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
770b036e11Schuck * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
780b036e11Schuck * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
790b036e11Schuck * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
800b036e11Schuck * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
810b036e11Schuck * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
820b036e11Schuck * SUCH DAMAGE.
830b036e11Schuck *
840b036e11Schuck * @(#)clock.c 8.1 (Berkeley) 6/11/93
850b036e11Schuck */
860b036e11Schuck
870b036e11Schuck /*
880b036e11Schuck * Clock driver.
890b036e11Schuck */
900b036e11Schuck
910b036e11Schuck #include "sboot.h"
920b036e11Schuck #include "clockreg.h"
93921705c3Sjdolecek
94921705c3Sjdolecek #include <machine/prom.h>
95921705c3Sjdolecek #include "libsa.h"
96921705c3Sjdolecek
970b036e11Schuck static struct clockreg *clockreg = (struct clockreg *)CLOCK_ADDR;
980b036e11Schuck
990b036e11Schuck /*
1000b036e11Schuck * Set up the system's time, given a `reasonable' time value.
1010b036e11Schuck */
time(void)102*a07f7c80Stsutsui u_long time(void)
1030b036e11Schuck {
104a84a6744Sscw struct clockreg *cl = clockreg;
1050b036e11Schuck int sec, min, hour, day, mon, year;
1060b036e11Schuck
1070b036e11Schuck cl->cl_csr |= CLK_READ; /* enable read (stop time) */
1080b036e11Schuck sec = cl->cl_sec;
1090b036e11Schuck min = cl->cl_min;
1100b036e11Schuck hour = cl->cl_hour;
1110b036e11Schuck day = cl->cl_mday;
1120b036e11Schuck mon = cl->cl_month;
1130b036e11Schuck year = cl->cl_year;
1140b036e11Schuck cl->cl_csr &= ~CLK_READ; /* time wears on */
115*a07f7c80Stsutsui return chiptotime(sec, min, hour, day, mon, year);
1160b036e11Schuck }
117