home *** CD-ROM | disk | FTP | other *** search
- /*
- * %Z% %M% %I% %D% %Q%
- *
- * Copyright (C) The Santa Cruz Operation, 1985, 1986.
- * This Module contains Proprietary Information of
- * The Santa Cruz Operation and should be treated as Confidential.
- *
- */
-
- /*
- * Real Time Clock driver for the SCO Generic 286 port.
- *
- * This driver is the real time clock interface into the
- * Motorola MC146818 Real-time Clock/CMOS Ram Chip.
- *
- * The bytes in the RT/CMOS chip hold date entries in packed binary
- * coded decimal form. The driver interface to the user is via a
- * ascii characters which are converted to/from packed bcd storage.
- *
- * cmos.h and rtc.h merged for linkkit purposes
- */
-
- #include "../h/param.h"
- #include "../h/types.h"
- #include "../h/sysmacros.h"
- #include "../h/signal.h"
- #include "../h/errno.h"
- #include "../h/dir.h"
- #include "../h/seg.h"
- #include "../h/page.h"
- #include "../h/user.h"
-
- /* real time clock byte specification defines, used to be rtc.h */
-
- #define SECONDS 0x0
- #define SECONDALARM 0x1
- #define MINUTES 0x2
- #define MINUTEALARM 0x3
- #define HOURS 0x4
- #define HOURALARM 0x5
- #define DAYOFWEEK 0x6
- #define DATEOFMONTH 0x7
- #define MONTH 0x8
- #define YEAR 0x9
- #define STATUSA 0xA
- #define STATUSB 0xB
- #define STATUSC 0xC
- #define STATUSD 0xD
-
- /* packed binary coded decimal size of date string */
-
- #define PCKBCDSIZ 5
-
- /* character string size of date string */
-
- #define CHRSTRSIZ (PCKBCDSIZ * 2)
-
- /* parts (in order) that make up the date string read/written by driver */
-
- char dateparts[PCKBCDSIZ] = {
- MONTH,
- DATEOFMONTH,
- HOURS,
- MINUTES,
- YEAR,
- };
-
- /* real time clock status register A defines */
-
- #define RTCUIP 0x80 /* update in progress */
-
- /* real time clock status register B defines */
-
- #define CLKOFF 0x80 /* disable time updating */
- #define MODE24 0x02 /* 24 hour mode */
- #define DAYSAV 0x01 /* daylight savings time */
-
- /* ascii defines */
-
- #define ASCIIZERO 0x30
-
- /* nibble from byte extraction */
-
- #define LONIBBLE(ch) ((ch) & 0xF)
- #define HINIBBLE(ch) (((ch) >> 4) & 0xF)
-
- /* bcd nibble packing */
-
- #define PACKLOBCD(ch) (((ch) - ASCIIZERO) & 0xF)
- #define PACKHIBCD(ch) ((((ch) - ASCIIZERO) << 4) & 0xF0)
-
- /* end of rtc.h definitions */
-
- /* MOTOROLA MC146818 RealTime Clock/RAM System Information, ie cmos.h */
-
- /* Ports for interacting with chip at */
-
- #define CMOSADDR 0x70 /* Use to select RAM address */
- #define CMOSDATA 0x71 /* R/W data */
-
- /* Number of cmos bytes */
-
- #define CMOSSIZE 0x40 /* 64 addressable bytes in chip */
-
- /* Addresses of interest */
-
- #define CMOSFDT 0x10 /* Floppy Disk Type */
- #define CMOSHDT 0x12 /* Hard Disk Type; bits 7-4 are 1st drive */
- #define CMOSEQP 0x14 /* Diskette, Video, and CoProcessor info */
-
- /* Shifts of interest */
-
- #define VID_SHFT 4 /* Shift display type bits into 0-3 */
-
- /* end of cmos.h */
-
- unsigned char rtcgetb();
-
- /*
- * rtcread - read real time clock.
- */
- rtcread()
- {
- register int i;
- char datestr[CHRSTRSIZ];
-
- rtcgets(datestr);
- while ((i = u.u_offset) < CHRSTRSIZ && u.u_count > 0) {
- if (passc(datestr[i]) == -1)
- return;
- }
- }
-
- /*
- * rtcwrite - write real time clock.
- */
- rtcwrite()
- {
- register int i;
- char datestr[CHRSTRSIZ];
-
- if (u.u_count < CHRSTRSIZ) {
- u.u_error = EFAULT;
- return;
- }
- for (i = 0; i < CHRSTRSIZ; i++) {
- if ((datestr[i] = cpass()) == -1)
- return;
- }
- rtcputs(datestr);
- }
-
- /*
- * rtcgets - real time clock get string.
- *
- * read the real time clock bcd chars and convert
- * to an ascii string datestr.
- */
- rtcgets(datestr)
- register char *datestr;
- {
- register char bcdch;
- register int i;
-
- for (i = 0; i < PCKBCDSIZ; i++) {
- bcdch = rtcgetb(dateparts[i]);
- *(datestr++) = HINIBBLE(bcdch) + ASCIIZERO;
- *(datestr++) = LONIBBLE(bcdch) + ASCIIZERO;
- }
- }
-
- /*
- * rtcputs - real time clock put string.
- *
- * take ascii string datestr, convert to packed bcd, and set the clock.
- */
- rtcputs(datestr)
- char *datestr;
- {
- register char bcdch;
- register int i;
-
- rtcputb(STATUSB, CLKOFF|MODE24|DAYSAV); /* stop the clock */
-
- for (i = 0; i < PCKBCDSIZ; i++) {
- bcdch = PACKHIBCD(*(datestr++));
- bcdch |= PACKLOBCD(*(datestr++));
- rtcputb(dateparts[i],bcdch);
- }
- rtcputb(STATUSB, MODE24|DAYSAV); /* start the clock */
- }
-
- /*
- * rtcgetb - real time clock get byte.
- *
- * get a byte from the real time clock specified by rtcbyte.
- */
- unsigned char
- rtcgetb(rtcbyte)
- unsigned char rtcbyte;
- {
- do {
- outb(CMOSADDR, STATUSA);
- } while ((inb(CMOSDATA)) & RTCUIP);
-
- outb(CMOSADDR, rtcbyte);
- return(inb(CMOSDATA));
- }
-
- /*
- * rtcputb - real time clock put byte.
- *
- * set the packed bcd byte "ch" specified by rtcbyte in the clock.
- */
- rtcputb(rtcbyte, ch)
- unsigned char rtcbyte, ch;
- {
- outb(CMOSADDR, rtcbyte);
- outb(CMOSDATA, ch);
- }
-