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