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