Home | History | Annotate | Line # | Download | only in isa
rtc.c revision 1.1.4.2
      1  1.1.4.2  yamt /*	$NetBSD: rtc.c,v 1.1.4.2 2009/06/20 07:20:12 yamt Exp $	*/
      2  1.1.4.2  yamt 
      3  1.1.4.2  yamt /*-
      4  1.1.4.2  yamt  * Copyright (c) 1990 The Regents of the University of California.
      5  1.1.4.2  yamt  * All rights reserved.
      6  1.1.4.2  yamt  *
      7  1.1.4.2  yamt  * This code is derived from software contributed to Berkeley by
      8  1.1.4.2  yamt  * William Jolitz and Don Ahn.
      9  1.1.4.2  yamt  *
     10  1.1.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     11  1.1.4.2  yamt  * modification, are permitted provided that the following conditions
     12  1.1.4.2  yamt  * are met:
     13  1.1.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     14  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     15  1.1.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     18  1.1.4.2  yamt  * 3. Neither the name of the University nor the names of its contributors
     19  1.1.4.2  yamt  *    may be used to endorse or promote products derived from this software
     20  1.1.4.2  yamt  *    without specific prior written permission.
     21  1.1.4.2  yamt  *
     22  1.1.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     23  1.1.4.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     24  1.1.4.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     25  1.1.4.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     26  1.1.4.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27  1.1.4.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     28  1.1.4.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29  1.1.4.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30  1.1.4.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31  1.1.4.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32  1.1.4.2  yamt  * SUCH DAMAGE.
     33  1.1.4.2  yamt  *
     34  1.1.4.2  yamt  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
     35  1.1.4.2  yamt  */
     36  1.1.4.2  yamt /*-
     37  1.1.4.2  yamt  * Copyright (c) 1993, 1994 Charles M. Hannum.
     38  1.1.4.2  yamt  *
     39  1.1.4.2  yamt  * This code is derived from software contributed to Berkeley by
     40  1.1.4.2  yamt  * William Jolitz and Don Ahn.
     41  1.1.4.2  yamt  *
     42  1.1.4.2  yamt  * Redistribution and use in source and binary forms, with or without
     43  1.1.4.2  yamt  * modification, are permitted provided that the following conditions
     44  1.1.4.2  yamt  * are met:
     45  1.1.4.2  yamt  * 1. Redistributions of source code must retain the above copyright
     46  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer.
     47  1.1.4.2  yamt  * 2. Redistributions in binary form must reproduce the above copyright
     48  1.1.4.2  yamt  *    notice, this list of conditions and the following disclaimer in the
     49  1.1.4.2  yamt  *    documentation and/or other materials provided with the distribution.
     50  1.1.4.2  yamt  * 3. All advertising materials mentioning features or use of this software
     51  1.1.4.2  yamt  *    must display the following acknowledgement:
     52  1.1.4.2  yamt  *	This product includes software developed by the University of
     53  1.1.4.2  yamt  *	California, Berkeley and its contributors.
     54  1.1.4.2  yamt  * 4. Neither the name of the University nor the names of its contributors
     55  1.1.4.2  yamt  *    may be used to endorse or promote products derived from this software
     56  1.1.4.2  yamt  *    without specific prior written permission.
     57  1.1.4.2  yamt  *
     58  1.1.4.2  yamt  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     59  1.1.4.2  yamt  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     60  1.1.4.2  yamt  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     61  1.1.4.2  yamt  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     62  1.1.4.2  yamt  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     63  1.1.4.2  yamt  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     64  1.1.4.2  yamt  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     65  1.1.4.2  yamt  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     66  1.1.4.2  yamt  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     67  1.1.4.2  yamt  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     68  1.1.4.2  yamt  * SUCH DAMAGE.
     69  1.1.4.2  yamt  *
     70  1.1.4.2  yamt  *	@(#)clock.c	7.2 (Berkeley) 5/12/91
     71  1.1.4.2  yamt  */
     72  1.1.4.2  yamt /*
     73  1.1.4.2  yamt  * Mach Operating System
     74  1.1.4.2  yamt  * Copyright (c) 1991,1990,1989 Carnegie Mellon University
     75  1.1.4.2  yamt  * All Rights Reserved.
     76  1.1.4.2  yamt  *
     77  1.1.4.2  yamt  * Permission to use, copy, modify and distribute this software and its
     78  1.1.4.2  yamt  * documentation is hereby granted, provided that both the copyright
     79  1.1.4.2  yamt  * notice and this permission notice appear in all copies of the
     80  1.1.4.2  yamt  * software, derivative works or modified versions, and any portions
     81  1.1.4.2  yamt  * thereof, and that both notices appear in supporting documentation.
     82  1.1.4.2  yamt  *
     83  1.1.4.2  yamt  * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
     84  1.1.4.2  yamt  * CONDITION.  CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
     85  1.1.4.2  yamt  * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
     86  1.1.4.2  yamt  *
     87  1.1.4.2  yamt  * Carnegie Mellon requests users of this software to return to
     88  1.1.4.2  yamt  *
     89  1.1.4.2  yamt  *  Software Distribution Coordinator  or  Software.Distribution (at) CS.CMU.EDU
     90  1.1.4.2  yamt  *  School of Computer Science
     91  1.1.4.2  yamt  *  Carnegie Mellon University
     92  1.1.4.2  yamt  *  Pittsburgh PA 15213-3890
     93  1.1.4.2  yamt  *
     94  1.1.4.2  yamt  * any improvements or extensions that they make and grant Carnegie Mellon
     95  1.1.4.2  yamt  * the rights to redistribute these changes.
     96  1.1.4.2  yamt  */
     97  1.1.4.2  yamt /*
     98  1.1.4.2  yamt   Copyright 1988, 1989 by Intel Corporation, Santa Clara, California.
     99  1.1.4.2  yamt 
    100  1.1.4.2  yamt 		All Rights Reserved
    101  1.1.4.2  yamt 
    102  1.1.4.2  yamt Permission to use, copy, modify, and distribute this software and
    103  1.1.4.2  yamt its documentation for any purpose and without fee is hereby
    104  1.1.4.2  yamt granted, provided that the above copyright notice appears in all
    105  1.1.4.2  yamt copies and that both the copyright notice and this permission notice
    106  1.1.4.2  yamt appear in supporting documentation, and that the name of Intel
    107  1.1.4.2  yamt not be used in advertising or publicity pertaining to distribution
    108  1.1.4.2  yamt of the software without specific, written prior permission.
    109  1.1.4.2  yamt 
    110  1.1.4.2  yamt INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
    111  1.1.4.2  yamt INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
    112  1.1.4.2  yamt IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
    113  1.1.4.2  yamt CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
    114  1.1.4.2  yamt LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
    115  1.1.4.2  yamt NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
    116  1.1.4.2  yamt WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
    117  1.1.4.2  yamt */
    118  1.1.4.2  yamt 
    119  1.1.4.2  yamt /*
    120  1.1.4.2  yamt  * Primitive RTC chip routines.
    121  1.1.4.2  yamt  */
    122  1.1.4.2  yamt 
    123  1.1.4.2  yamt #include <sys/cdefs.h>
    124  1.1.4.2  yamt __KERNEL_RCSID(0, "$NetBSD: rtc.c,v 1.1.4.2 2009/06/20 07:20:12 yamt Exp $");
    125  1.1.4.2  yamt 
    126  1.1.4.2  yamt #include <sys/param.h>
    127  1.1.4.2  yamt #include <sys/systm.h>
    128  1.1.4.2  yamt #include <sys/time.h>
    129  1.1.4.2  yamt #include <sys/timetc.h>
    130  1.1.4.2  yamt #include <sys/kernel.h>
    131  1.1.4.2  yamt 
    132  1.1.4.2  yamt #include <dev/isa/isareg.h>
    133  1.1.4.2  yamt #include <dev/isa/isavar.h>
    134  1.1.4.2  yamt #include <i386/isa/nvram.h>
    135  1.1.4.2  yamt 
    136  1.1.4.2  yamt #include <machine/pio.h>
    137  1.1.4.2  yamt 
    138  1.1.4.2  yamt #include <dev/ic/mc146818reg.h>
    139  1.1.4.2  yamt #include <x86/rtc.h>
    140  1.1.4.2  yamt 
    141  1.1.4.2  yamt #ifndef __x86_64__
    142  1.1.4.2  yamt #include "mca.h"
    143  1.1.4.2  yamt #endif
    144  1.1.4.2  yamt #if NMCA > 0
    145  1.1.4.2  yamt #include <machine/mca_machdep.h>	/* for MCA_system */
    146  1.1.4.2  yamt #endif
    147  1.1.4.2  yamt 
    148  1.1.4.2  yamt static void	rtcinit(void);
    149  1.1.4.2  yamt static int	rtcget(mc_todregs *);
    150  1.1.4.2  yamt static void	rtcput(mc_todregs *);
    151  1.1.4.2  yamt static int	cmoscheck(void);
    152  1.1.4.2  yamt static int	clock_expandyear(int);
    153  1.1.4.2  yamt 
    154  1.1.4.2  yamt /* XXX use sc? */
    155  1.1.4.2  yamt u_int
    156  1.1.4.2  yamt mc146818_read(void *sc, u_int reg)
    157  1.1.4.2  yamt {
    158  1.1.4.2  yamt 
    159  1.1.4.2  yamt 	outb(IO_RTC, reg);
    160  1.1.4.2  yamt 	return (inb(IO_RTC+1));
    161  1.1.4.2  yamt }
    162  1.1.4.2  yamt 
    163  1.1.4.2  yamt void
    164  1.1.4.2  yamt mc146818_write(void *sc, u_int reg, u_int datum)
    165  1.1.4.2  yamt {
    166  1.1.4.2  yamt 
    167  1.1.4.2  yamt 	outb(IO_RTC, reg);
    168  1.1.4.2  yamt 	outb(IO_RTC+1, datum);
    169  1.1.4.2  yamt }
    170  1.1.4.2  yamt 
    171  1.1.4.2  yamt static void
    172  1.1.4.2  yamt rtcinit(void)
    173  1.1.4.2  yamt {
    174  1.1.4.2  yamt 	static int first_rtcopen_ever = 1;
    175  1.1.4.2  yamt 
    176  1.1.4.2  yamt 	if (!first_rtcopen_ever)
    177  1.1.4.2  yamt 		return;
    178  1.1.4.2  yamt 	first_rtcopen_ever = 0;
    179  1.1.4.2  yamt 
    180  1.1.4.2  yamt 	mc146818_write(NULL, MC_REGA,			/* XXX softc */
    181  1.1.4.2  yamt 	    MC_BASE_32_KHz | MC_RATE_1024_Hz);
    182  1.1.4.2  yamt 	mc146818_write(NULL, MC_REGB, MC_REGB_24HR);	/* XXX softc */
    183  1.1.4.2  yamt }
    184  1.1.4.2  yamt 
    185  1.1.4.2  yamt static int
    186  1.1.4.2  yamt rtcget(mc_todregs *regs)
    187  1.1.4.2  yamt {
    188  1.1.4.2  yamt 
    189  1.1.4.2  yamt 	rtcinit();
    190  1.1.4.2  yamt 	if ((mc146818_read(NULL, MC_REGD) & MC_REGD_VRT) == 0) /* XXX softc */
    191  1.1.4.2  yamt 		return (-1);
    192  1.1.4.2  yamt 	MC146818_GETTOD(NULL, regs);			/* XXX softc */
    193  1.1.4.2  yamt 	return (0);
    194  1.1.4.2  yamt }
    195  1.1.4.2  yamt 
    196  1.1.4.2  yamt static void
    197  1.1.4.2  yamt rtcput(mc_todregs *regs)
    198  1.1.4.2  yamt {
    199  1.1.4.2  yamt 
    200  1.1.4.2  yamt 	rtcinit();
    201  1.1.4.2  yamt 	MC146818_PUTTOD(NULL, regs);			/* XXX softc */
    202  1.1.4.2  yamt }
    203  1.1.4.2  yamt 
    204  1.1.4.2  yamt /*
    205  1.1.4.2  yamt  * check whether the CMOS layout is "standard"-like (ie, not PS/2-like),
    206  1.1.4.2  yamt  * to be called at splclock()
    207  1.1.4.2  yamt  */
    208  1.1.4.2  yamt static int
    209  1.1.4.2  yamt cmoscheck(void)
    210  1.1.4.2  yamt {
    211  1.1.4.2  yamt 	int i;
    212  1.1.4.2  yamt 	unsigned short cksum = 0;
    213  1.1.4.2  yamt 
    214  1.1.4.2  yamt 	for (i = 0x10; i <= 0x2d; i++)
    215  1.1.4.2  yamt 		cksum += mc146818_read(NULL, i); /* XXX softc */
    216  1.1.4.2  yamt 
    217  1.1.4.2  yamt 	return (cksum == (mc146818_read(NULL, 0x2e) << 8)
    218  1.1.4.2  yamt 			  + mc146818_read(NULL, 0x2f));
    219  1.1.4.2  yamt }
    220  1.1.4.2  yamt 
    221  1.1.4.2  yamt #if NMCA > 0
    222  1.1.4.2  yamt /*
    223  1.1.4.2  yamt  * Check whether the CMOS layout is PS/2 like, to be called at splclock().
    224  1.1.4.2  yamt  */
    225  1.1.4.2  yamt static int cmoscheckps2(void);
    226  1.1.4.2  yamt static int
    227  1.1.4.2  yamt cmoscheckps2(void)
    228  1.1.4.2  yamt {
    229  1.1.4.2  yamt #if 0
    230  1.1.4.2  yamt 	/* Disabled until I find out the CRC checksum algorithm IBM uses */
    231  1.1.4.2  yamt 	int i;
    232  1.1.4.2  yamt 	unsigned short cksum = 0;
    233  1.1.4.2  yamt 
    234  1.1.4.2  yamt 	for (i = 0x10; i <= 0x31; i++)
    235  1.1.4.2  yamt 		cksum += mc146818_read(NULL, i); /* XXX softc */
    236  1.1.4.2  yamt 
    237  1.1.4.2  yamt 	return (cksum == (mc146818_read(NULL, 0x32) << 8)
    238  1.1.4.2  yamt 			  + mc146818_read(NULL, 0x33));
    239  1.1.4.2  yamt #else
    240  1.1.4.2  yamt 	/* Check 'incorrect checksum' bit of IBM PS/2 Diagnostic Status Byte */
    241  1.1.4.2  yamt 	return ((mc146818_read(NULL, NVRAM_DIAG) & (1<<6)) == 0);
    242  1.1.4.2  yamt #endif
    243  1.1.4.2  yamt }
    244  1.1.4.2  yamt #endif /* NMCA > 0 */
    245  1.1.4.2  yamt 
    246  1.1.4.2  yamt /*
    247  1.1.4.2  yamt  * patchable to control century byte handling:
    248  1.1.4.2  yamt  * 1: always update
    249  1.1.4.2  yamt  * -1: never touch
    250  1.1.4.2  yamt  * 0: try to figure out itself
    251  1.1.4.2  yamt  */
    252  1.1.4.2  yamt int rtc_update_century = 0;
    253  1.1.4.2  yamt 
    254  1.1.4.2  yamt /*
    255  1.1.4.2  yamt  * Expand a two-digit year as read from the clock chip
    256  1.1.4.2  yamt  * into full width.
    257  1.1.4.2  yamt  * Being here, deal with the CMOS century byte.
    258  1.1.4.2  yamt  */
    259  1.1.4.2  yamt static int centb = NVRAM_CENTURY;
    260  1.1.4.2  yamt static int
    261  1.1.4.2  yamt clock_expandyear(int clockyear)
    262  1.1.4.2  yamt {
    263  1.1.4.2  yamt 	int s, clockcentury, cmoscentury;
    264  1.1.4.2  yamt 
    265  1.1.4.2  yamt 	clockcentury = (clockyear < 70) ? 20 : 19;
    266  1.1.4.2  yamt 	clockyear += 100 * clockcentury;
    267  1.1.4.2  yamt 
    268  1.1.4.2  yamt 	if (rtc_update_century < 0)
    269  1.1.4.2  yamt 		return (clockyear);
    270  1.1.4.2  yamt 
    271  1.1.4.2  yamt 	s = splclock();
    272  1.1.4.2  yamt 	if (cmoscheck())
    273  1.1.4.2  yamt 		cmoscentury = mc146818_read(NULL, NVRAM_CENTURY);
    274  1.1.4.2  yamt #if NMCA > 0
    275  1.1.4.2  yamt 	else if (MCA_system && cmoscheckps2())
    276  1.1.4.2  yamt 		cmoscentury = mc146818_read(NULL, (centb = 0x37));
    277  1.1.4.2  yamt #endif
    278  1.1.4.2  yamt 	else
    279  1.1.4.2  yamt 		cmoscentury = 0;
    280  1.1.4.2  yamt 	splx(s);
    281  1.1.4.2  yamt 	if (!cmoscentury) {
    282  1.1.4.2  yamt #ifdef DIAGNOSTIC
    283  1.1.4.2  yamt 		printf("clock: unknown CMOS layout\n");
    284  1.1.4.2  yamt #endif
    285  1.1.4.2  yamt 		return (clockyear);
    286  1.1.4.2  yamt 	}
    287  1.1.4.2  yamt 	cmoscentury = bcdtobin(cmoscentury);
    288  1.1.4.2  yamt 
    289  1.1.4.2  yamt 	if (cmoscentury != clockcentury) {
    290  1.1.4.2  yamt 		/* XXX note: saying "century is 20" might confuse the naive. */
    291  1.1.4.2  yamt 		printf("WARNING: NVRAM century is %d but RTC year is %d\n",
    292  1.1.4.2  yamt 		       cmoscentury, clockyear);
    293  1.1.4.2  yamt 
    294  1.1.4.2  yamt 		/* Kludge to roll over century. */
    295  1.1.4.2  yamt 		if ((rtc_update_century > 0) ||
    296  1.1.4.2  yamt 		    ((cmoscentury == 19) && (clockcentury == 20) &&
    297  1.1.4.2  yamt 		     (clockyear == 2000))) {
    298  1.1.4.2  yamt 			printf("WARNING: Setting NVRAM century to %d\n",
    299  1.1.4.2  yamt 			       clockcentury);
    300  1.1.4.2  yamt 			s = splclock();
    301  1.1.4.2  yamt 			mc146818_write(NULL, centb, bintobcd(clockcentury));
    302  1.1.4.2  yamt 			splx(s);
    303  1.1.4.2  yamt 		}
    304  1.1.4.2  yamt 	} else if (cmoscentury == 19 && rtc_update_century == 0)
    305  1.1.4.2  yamt 		rtc_update_century = 1; /* will update later in resettodr() */
    306  1.1.4.2  yamt 
    307  1.1.4.2  yamt 	return (clockyear);
    308  1.1.4.2  yamt }
    309  1.1.4.2  yamt 
    310  1.1.4.2  yamt int
    311  1.1.4.2  yamt rtc_get_ymdhms(todr_chip_handle_t tch, struct clock_ymdhms *dt)
    312  1.1.4.2  yamt {
    313  1.1.4.2  yamt 	int s;
    314  1.1.4.2  yamt 	mc_todregs rtclk;
    315  1.1.4.2  yamt 
    316  1.1.4.2  yamt 	s = splclock();
    317  1.1.4.2  yamt 	if (rtcget(&rtclk)) {
    318  1.1.4.2  yamt 		splx(s);
    319  1.1.4.2  yamt 		return -1;
    320  1.1.4.2  yamt 	}
    321  1.1.4.2  yamt 	splx(s);
    322  1.1.4.2  yamt 
    323  1.1.4.2  yamt 	dt->dt_sec = bcdtobin(rtclk[MC_SEC]);
    324  1.1.4.2  yamt 	dt->dt_min = bcdtobin(rtclk[MC_MIN]);
    325  1.1.4.2  yamt 	dt->dt_hour = bcdtobin(rtclk[MC_HOUR]);
    326  1.1.4.2  yamt 	dt->dt_day = bcdtobin(rtclk[MC_DOM]);
    327  1.1.4.2  yamt 	dt->dt_mon = bcdtobin(rtclk[MC_MONTH]);
    328  1.1.4.2  yamt 	dt->dt_year = clock_expandyear(bcdtobin(rtclk[MC_YEAR]));
    329  1.1.4.2  yamt 
    330  1.1.4.2  yamt 	return 0;
    331  1.1.4.2  yamt }
    332  1.1.4.2  yamt 
    333  1.1.4.2  yamt int
    334  1.1.4.2  yamt rtc_set_ymdhms(todr_chip_handle_t tch, struct clock_ymdhms *dt)
    335  1.1.4.2  yamt {
    336  1.1.4.2  yamt 	mc_todregs rtclk;
    337  1.1.4.2  yamt 	int century;
    338  1.1.4.2  yamt 	int s;
    339  1.1.4.2  yamt 
    340  1.1.4.2  yamt 	s = splclock();
    341  1.1.4.2  yamt 	if (rtcget(&rtclk))
    342  1.1.4.2  yamt 		memset(&rtclk, 0, sizeof(rtclk));
    343  1.1.4.2  yamt 	splx(s);
    344  1.1.4.2  yamt 
    345  1.1.4.2  yamt 	rtclk[MC_SEC] = bintobcd(dt->dt_sec);
    346  1.1.4.2  yamt 	rtclk[MC_MIN] = bintobcd(dt->dt_min);
    347  1.1.4.2  yamt 	rtclk[MC_HOUR] = bintobcd(dt->dt_hour);
    348  1.1.4.2  yamt 	rtclk[MC_DOW] = dt->dt_wday + 1;
    349  1.1.4.2  yamt 	rtclk[MC_YEAR] = bintobcd(dt->dt_year % 100);
    350  1.1.4.2  yamt 	rtclk[MC_MONTH] = bintobcd(dt->dt_mon);
    351  1.1.4.2  yamt 	rtclk[MC_DOM] = bintobcd(dt->dt_day);
    352  1.1.4.2  yamt 
    353  1.1.4.2  yamt #ifdef DEBUG_CLOCK
    354  1.1.4.2  yamt 	printf("setclock: %x/%x/%x %x:%x:%x\n", rtclk[MC_YEAR], rtclk[MC_MONTH],
    355  1.1.4.2  yamt 	   rtclk[MC_DOM], rtclk[MC_HOUR], rtclk[MC_MIN], rtclk[MC_SEC]);
    356  1.1.4.2  yamt #endif
    357  1.1.4.2  yamt 	s = splclock();
    358  1.1.4.2  yamt 	rtcput(&rtclk);
    359  1.1.4.2  yamt 	if (rtc_update_century > 0) {
    360  1.1.4.2  yamt 		century = bintobcd(dt->dt_year / 100);
    361  1.1.4.2  yamt 		mc146818_write(NULL, centb, century); /* XXX softc */
    362  1.1.4.2  yamt 	}
    363  1.1.4.2  yamt 	splx(s);
    364  1.1.4.2  yamt 	return 0;
    365  1.1.4.2  yamt 
    366  1.1.4.2  yamt }
    367  1.1.4.2  yamt 
    368  1.1.4.2  yamt void
    369  1.1.4.2  yamt rtc_register(void)
    370  1.1.4.2  yamt {
    371  1.1.4.2  yamt 	static struct todr_chip_handle	tch;
    372  1.1.4.2  yamt 	tch.todr_gettime_ymdhms = rtc_get_ymdhms;
    373  1.1.4.2  yamt 	tch.todr_settime_ymdhms = rtc_set_ymdhms;
    374  1.1.4.2  yamt 	tch.todr_setwen = NULL;
    375  1.1.4.2  yamt 
    376  1.1.4.2  yamt 	todr_attach(&tch);
    377  1.1.4.2  yamt }
    378  1.1.4.2  yamt 
    379