xref: /freebsd/sys/isa/rtc.h (revision 51369649b03ece2aed3eb61b0c8214b9aa5b2fa2)
15b81b6b3SRodney W. Grimes /*-
2*51369649SPedro F. Giffuni  * SPDX-License-Identifier: BSD-3-Clause
3*51369649SPedro F. Giffuni  *
45b81b6b3SRodney W. Grimes  * Copyright (c) 1990 The Regents of the University of California.
55b81b6b3SRodney W. Grimes  * All rights reserved.
65b81b6b3SRodney W. Grimes  *
75b81b6b3SRodney W. Grimes  * This code is derived from software contributed to Berkeley by
85b81b6b3SRodney W. Grimes  * William Jolitz.
95b81b6b3SRodney W. Grimes  *
105b81b6b3SRodney W. Grimes  * Redistribution and use in source and binary forms, with or without
115b81b6b3SRodney W. Grimes  * modification, are permitted provided that the following conditions
125b81b6b3SRodney W. Grimes  * are met:
135b81b6b3SRodney W. Grimes  * 1. Redistributions of source code must retain the above copyright
145b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer.
155b81b6b3SRodney W. Grimes  * 2. Redistributions in binary form must reproduce the above copyright
165b81b6b3SRodney W. Grimes  *    notice, this list of conditions and the following disclaimer in the
175b81b6b3SRodney W. Grimes  *    documentation and/or other materials provided with the distribution.
18fbbd9655SWarner Losh  * 3. Neither the name of the University nor the names of its contributors
195b81b6b3SRodney W. Grimes  *    may be used to endorse or promote products derived from this software
205b81b6b3SRodney W. Grimes  *    without specific prior written permission.
215b81b6b3SRodney W. Grimes  *
225b81b6b3SRodney W. Grimes  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
235b81b6b3SRodney W. Grimes  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
245b81b6b3SRodney W. Grimes  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
255b81b6b3SRodney W. Grimes  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
265b81b6b3SRodney W. Grimes  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
275b81b6b3SRodney W. Grimes  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
285b81b6b3SRodney W. Grimes  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
295b81b6b3SRodney W. Grimes  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
305b81b6b3SRodney W. Grimes  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
315b81b6b3SRodney W. Grimes  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
325b81b6b3SRodney W. Grimes  * SUCH DAMAGE.
335b81b6b3SRodney W. Grimes  *
346f78ca60SRodney W. Grimes  *	from: @(#)rtc.h	7.1 (Berkeley) 5/12/91
35c3aac50fSPeter Wemm  * $FreeBSD$
365b81b6b3SRodney W. Grimes  */
375b81b6b3SRodney W. Grimes 
3813c0dce6SGarrett Wollman #ifndef _I386_ISA_RTC_H_
3913c0dce6SGarrett Wollman #define _I386_ISA_RTC_H_ 1
4013c0dce6SGarrett Wollman 
415b81b6b3SRodney W. Grimes /*
423bc7e565SPoul-Henning Kamp  * MC146818 RTC Register locations
435b81b6b3SRodney W. Grimes  */
445b81b6b3SRodney W. Grimes 
455b81b6b3SRodney W. Grimes #define RTC_SEC		0x00	/* seconds */
465b81b6b3SRodney W. Grimes #define RTC_SECALRM	0x01	/* seconds alarm */
475b81b6b3SRodney W. Grimes #define RTC_MIN		0x02	/* minutes */
485b81b6b3SRodney W. Grimes #define RTC_MINALRM	0x03	/* minutes alarm */
495b81b6b3SRodney W. Grimes #define RTC_HRS		0x04	/* hours */
505b81b6b3SRodney W. Grimes #define RTC_HRSALRM	0x05	/* hours alarm */
515b81b6b3SRodney W. Grimes #define RTC_WDAY	0x06	/* week day */
525b81b6b3SRodney W. Grimes #define RTC_DAY		0x07	/* day of month */
535b81b6b3SRodney W. Grimes #define RTC_MONTH	0x08	/* month of year */
545b81b6b3SRodney W. Grimes #define RTC_YEAR	0x09	/* month of year */
558ea83850SGarrett Wollman 
565b81b6b3SRodney W. Grimes #define RTC_STATUSA	0x0a	/* status register A */
575b81b6b3SRodney W. Grimes #define  RTCSA_TUP	 0x80	/* time update, don't look now */
583bc7e565SPoul-Henning Kamp #define  RTCSA_RESET	 0x70	/* reset divider */
598ea83850SGarrett Wollman #define  RTCSA_DIVIDER   0x20   /* divider correct for 32768 Hz */
603bc7e565SPoul-Henning Kamp #define  RTCSA_8192      0x03	/* 8192 Hz interrupt */
618ea83850SGarrett Wollman #define  RTCSA_4096      0x04
628ea83850SGarrett Wollman #define  RTCSA_2048      0x05
638ea83850SGarrett Wollman #define  RTCSA_1024      0x06	/* default for profiling */
648ea83850SGarrett Wollman #define  RTCSA_PROF      RTCSA_1024
658ea83850SGarrett Wollman #define  RTC_PROFRATE    1024
668ea83850SGarrett Wollman #define  RTCSA_512       0x07
678ea83850SGarrett Wollman #define  RTCSA_256       0x08
688ea83850SGarrett Wollman #define  RTCSA_128       0x09
698ea83850SGarrett Wollman #define  RTCSA_NOPROF	 RTCSA_128
708ea83850SGarrett Wollman #define  RTC_NOPROFRATE  128
718ea83850SGarrett Wollman #define  RTCSA_64        0x0a
723bc7e565SPoul-Henning Kamp #define  RTCSA_32        0x0b	/* 32 Hz interrupt */
735b81b6b3SRodney W. Grimes 
745b81b6b3SRodney W. Grimes #define RTC_STATUSB	0x0b	/* status register B */
753bc7e565SPoul-Henning Kamp #define	 RTCSB_DST	 0x01	/* USA Daylight Savings Time enable */
767b915aa6SAndrey A. Chernov #define	 RTCSB_24HR	 0x02	/* 0 = 12 hours, 1 = 24	hours */
777b915aa6SAndrey A. Chernov #define	 RTCSB_BCD	 0x04	/* 0 = BCD, 1 =	Binary coded time */
787b915aa6SAndrey A. Chernov #define	 RTCSB_SQWE	 0x08	/* 1 = output sqare wave at SQW	pin */
797b915aa6SAndrey A. Chernov #define	 RTCSB_UINTR	 0x10	/* 1 = enable update-ended interrupt */
807b915aa6SAndrey A. Chernov #define	 RTCSB_AINTR	 0x20	/* 1 = enable alarm interrupt */
817b915aa6SAndrey A. Chernov #define	 RTCSB_PINTR	 0x40	/* 1 = enable periodic clock interrupt */
828ea83850SGarrett Wollman #define  RTCSB_HALT      0x80	/* stop clock updates */
835b81b6b3SRodney W. Grimes 
845b81b6b3SRodney W. Grimes #define RTC_INTR	0x0c	/* status register C (R) interrupt source */
855b81b6b3SRodney W. Grimes #define  RTCIR_UPDATE	 0x10	/* update intr */
865b81b6b3SRodney W. Grimes #define  RTCIR_ALARM	 0x20	/* alarm intr */
875b81b6b3SRodney W. Grimes #define  RTCIR_PERIOD	 0x40	/* periodic intr */
885b81b6b3SRodney W. Grimes #define  RTCIR_INT	 0x80	/* interrupt output signal */
895b81b6b3SRodney W. Grimes 
905b81b6b3SRodney W. Grimes #define RTC_STATUSD	0x0d	/* status register D (R) Lost Power */
913bc7e565SPoul-Henning Kamp #define  RTCSD_PWR	 0x80	/* clock power OK */
925b81b6b3SRodney W. Grimes 
935b81b6b3SRodney W. Grimes #define RTC_DIAG	0x0e	/* status register E - bios diagnostic */
945b81b6b3SRodney W. Grimes #define RTCDG_BITS	"\020\010clock_battery\007ROM_cksum\006config_unit\005memory_size\004fixed_disk\003invalid_time"
955b81b6b3SRodney W. Grimes 
965b81b6b3SRodney W. Grimes #define RTC_RESET	0x0f	/* status register F - reset code byte */
975b81b6b3SRodney W. Grimes #define	 RTCRS_RST	 0x00		/* normal reset */
985b81b6b3SRodney W. Grimes #define	 RTCRS_LOAD	 0x04		/* load system */
995b81b6b3SRodney W. Grimes 
1005b81b6b3SRodney W. Grimes #define RTC_FDISKETTE	0x10	/* diskette drive type in upper/lower nibble */
1015b81b6b3SRodney W. Grimes #define	 RTCFDT_NONE	 0		/* none present */
1025b81b6b3SRodney W. Grimes #define	 RTCFDT_360K	 0x10		/* 360K */
1035b81b6b3SRodney W. Grimes #define	 RTCFDT_12M	 0x20		/* 1.2M */
104159569a4SAndrey A. Chernov #define  RTCFDT_720K     0x30           /* 720K */
1055b81b6b3SRodney W. Grimes #define	 RTCFDT_144M	 0x40		/* 1.44M */
10686a727d9SJoerg Wunsch #define  RTCFDT_288M_1   0x50		/* 2.88M, some BIOSes */
107290dd077SJoerg Wunsch #define	 RTCFDT_288M	 0x60		/* 2.88M */
1085b81b6b3SRodney W. Grimes 
1095b81b6b3SRodney W. Grimes #define RTC_BASELO	0x15	/* low byte of basemem size */
1105b81b6b3SRodney W. Grimes #define RTC_BASEHI	0x16	/* high byte of basemem size */
1115b81b6b3SRodney W. Grimes #define RTC_EXTLO	0x17	/* low byte of extended mem size */
1125b81b6b3SRodney W. Grimes #define RTC_EXTHI	0x18	/* low byte of extended mem size */
1135b81b6b3SRodney W. Grimes 
1147b915aa6SAndrey A. Chernov #define	RTC_CENTURY	0x32	/* current century */
1157e82012aSPoul-Henning Kamp 
1167e82012aSPoul-Henning Kamp #ifdef _KERNEL
1177e82012aSPoul-Henning Kamp extern  struct mtx clock_lock;
118b524a315SIan Lepore extern  struct mtx atrtc_time_lock;
1191703f2b4SAlexander Motin extern	int atrtcclock_disable;
1207e82012aSPoul-Henning Kamp int	rtcin(int reg);
1217e82012aSPoul-Henning Kamp void	atrtc_restore(void);
1227e82012aSPoul-Henning Kamp void	writertc(int reg, u_char val);
1237e82012aSPoul-Henning Kamp #endif
1247e82012aSPoul-Henning Kamp 
12513c0dce6SGarrett Wollman #endif /* _I386_ISA_RTC_H_ */
126