Deleted Added
full compact
atrtc.c (54890) atrtc.c (55098)
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz and Don Ahn.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: @(#)clock.c 7.2 (Berkeley) 5/12/91
1/*-
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * William Jolitz and Don Ahn.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 *
36 * from: @(#)clock.c 7.2 (Berkeley) 5/12/91
37 * $FreeBSD: head/sys/isa/atrtc.c 54890 1999-12-20 15:11:31Z peter $
37 * $FreeBSD: head/sys/isa/atrtc.c 55098 1999-12-25 15:30:31Z bde $
38 */
39
40/*
41 * Routines to handle clock hardware.
42 */
43
44/*
45 * inittodr, settodr and support routines written

--- 499 unchanged lines hidden (view full) ---

545/*
546 * RTC support routines
547 */
548
549int
550rtcin(reg)
551 int reg;
552{
38 */
39
40/*
41 * Routines to handle clock hardware.
42 */
43
44/*
45 * inittodr, settodr and support routines written

--- 499 unchanged lines hidden (view full) ---

545/*
546 * RTC support routines
547 */
548
549int
550rtcin(reg)
551 int reg;
552{
553 int s;
553 u_char val;
554
554 u_char val;
555
556 s = splhigh();
555 outb(IO_RTC, reg);
556 inb(0x84);
557 val = inb(IO_RTC + 1);
558 inb(0x84);
557 outb(IO_RTC, reg);
558 inb(0x84);
559 val = inb(IO_RTC + 1);
560 inb(0x84);
561 splx(s);
559 return (val);
560}
561
562static __inline void
563writertc(u_char reg, u_char val)
564{
562 return (val);
563}
564
565static __inline void
566writertc(u_char reg, u_char val)
567{
568 int s;
569
570 s = splhigh();
565 inb(0x84);
566 outb(IO_RTC, reg);
567 inb(0x84);
568 outb(IO_RTC + 1, val);
569 inb(0x84); /* XXX work around wrong order in rtcin() */
571 inb(0x84);
572 outb(IO_RTC, reg);
573 inb(0x84);
574 outb(IO_RTC + 1, val);
575 inb(0x84); /* XXX work around wrong order in rtcin() */
576 splx(s);
570}
571
572static __inline int
573readrtc(int port)
574{
575 return(bcd2bin(rtcin(port)));
576}
577

--- 264 unchanged lines hidden (view full) ---

842 }
843
844 /* Look if we have a RTC present and the time is valid */
845 if (!(rtcin(RTC_STATUSD) & RTCSD_PWR))
846 goto wrong_time;
847
848 /* wait for time update to complete */
849 /* If RTCSA_TUP is zero, we have at least 244us before next update */
577}
578
579static __inline int
580readrtc(int port)
581{
582 return(bcd2bin(rtcin(port)));
583}
584

--- 264 unchanged lines hidden (view full) ---

849 }
850
851 /* Look if we have a RTC present and the time is valid */
852 if (!(rtcin(RTC_STATUSD) & RTCSD_PWR))
853 goto wrong_time;
854
855 /* wait for time update to complete */
856 /* If RTCSA_TUP is zero, we have at least 244us before next update */
850 while (rtcin(RTC_STATUSA) & RTCSA_TUP);
857 s = splhigh();
858 while (rtcin(RTC_STATUSA) & RTCSA_TUP) {
859 splx(s);
860 s = splhigh();
861 }
851
852 days = 0;
853#ifdef USE_RTC_CENTURY
854 year = readrtc(RTC_YEAR) + readrtc(RTC_CENTURY) * 100;
855#else
856 year = readrtc(RTC_YEAR) + 1900;
857 if (year < 1970)
858 year += 100;
859#endif
862
863 days = 0;
864#ifdef USE_RTC_CENTURY
865 year = readrtc(RTC_YEAR) + readrtc(RTC_CENTURY) * 100;
866#else
867 year = readrtc(RTC_YEAR) + 1900;
868 if (year < 1970)
869 year += 100;
870#endif
860 if (year < 1970)
871 if (year < 1970) {
872 splx(s);
861 goto wrong_time;
873 goto wrong_time;
874 }
862 month = readrtc(RTC_MONTH);
863 for (m = 1; m < month; m++)
864 days += daysinmonth[m-1];
865 if ((month > 2) && LEAPYEAR(year))
866 days ++;
867 days += readrtc(RTC_DAY) - 1;
868 yd = days;
869 for (y = 1970; y < year; y++)

--- 5 unchanged lines hidden (view full) ---

875 /* sec now contains the number of seconds, since Jan 1 1970,
876 in the local time zone */
877
878 sec += tz.tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
879
880 y = time_second - sec;
881 if (y <= -2 || y >= 2) {
882 /* badly off, adjust it */
875 month = readrtc(RTC_MONTH);
876 for (m = 1; m < month; m++)
877 days += daysinmonth[m-1];
878 if ((month > 2) && LEAPYEAR(year))
879 days ++;
880 days += readrtc(RTC_DAY) - 1;
881 yd = days;
882 for (y = 1970; y < year; y++)

--- 5 unchanged lines hidden (view full) ---

888 /* sec now contains the number of seconds, since Jan 1 1970,
889 in the local time zone */
890
891 sec += tz.tz_minuteswest * 60 + (wall_cmos_clock ? adjkerntz : 0);
892
893 y = time_second - sec;
894 if (y <= -2 || y >= 2) {
895 /* badly off, adjust it */
883 s = splclock();
884 ts.tv_sec = sec;
885 ts.tv_nsec = 0;
886 set_timecounter(&ts);
896 ts.tv_sec = sec;
897 ts.tv_nsec = 0;
898 set_timecounter(&ts);
887 splx(s);
888 }
899 }
900 splx(s);
889 return;
890
891wrong_time:
892 printf("Invalid time in real time clock.\n");
893 printf("Check and reset the date immediately!\n");
894}
895
896/*

--- 304 unchanged lines hidden ---
901 return;
902
903wrong_time:
904 printf("Invalid time in real time clock.\n");
905 printf("Check and reset the date immediately!\n");
906}
907
908/*

--- 304 unchanged lines hidden ---