Annotation of sys/arch/alpha/alpha/mcclock.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mcclock.c,v 1.5 2002/03/14 01:26:26 millert Exp $ */
! 2: /* $NetBSD: mcclock.c,v 1.4 1996/10/13 02:59:41 christos Exp $ */
! 3:
! 4: /*
! 5: * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University.
! 6: * All rights reserved.
! 7: *
! 8: * Author: Chris G. Demetriou
! 9: *
! 10: * Permission to use, copy, modify and distribute this software and
! 11: * its documentation is hereby granted, provided that both the copyright
! 12: * notice and this permission notice appear in all copies of the
! 13: * software, derivative works or modified versions, and any portions
! 14: * thereof, and that both notices appear in supporting documentation.
! 15: *
! 16: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
! 17: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND
! 18: * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
! 19: *
! 20: * Carnegie Mellon requests users of this software to return to
! 21: *
! 22: * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
! 23: * School of Computer Science
! 24: * Carnegie Mellon University
! 25: * Pittsburgh PA 15213-3890
! 26: *
! 27: * any improvements or extensions that they make and grant Carnegie the
! 28: * rights to redistribute these changes.
! 29: */
! 30:
! 31: #include <sys/param.h>
! 32: #include <sys/kernel.h>
! 33: #include <sys/systm.h>
! 34: #include <sys/device.h>
! 35:
! 36: #include <alpha/alpha/clockvar.h>
! 37: #include <alpha/alpha/mcclockvar.h>
! 38: #include <dev/ic/mc146818reg.h>
! 39:
! 40: struct cfdriver mcclock_cd = {
! 41: NULL, "mcclock", DV_DULL,
! 42: };
! 43:
! 44: void mcclock_init(struct device *);
! 45: void mcclock_get(struct device *, time_t, struct clocktime *);
! 46: void mcclock_set(struct device *, struct clocktime *);
! 47:
! 48: const struct clockfns mcclock_clockfns = {
! 49: mcclock_init, mcclock_get, mcclock_set,
! 50: };
! 51:
! 52: #define mc146818_write(dev, reg, datum) \
! 53: (*(dev)->sc_busfns->mc_bf_write)(dev, reg, datum)
! 54: #define mc146818_read(dev, reg) \
! 55: (*(dev)->sc_busfns->mc_bf_read)(dev, reg)
! 56:
! 57: void
! 58: mcclock_attach(sc, busfns)
! 59: struct mcclock_softc *sc;
! 60: const struct mcclock_busfns *busfns;
! 61: {
! 62:
! 63: printf(": mc146818 or compatible");
! 64:
! 65: sc->sc_busfns = busfns;
! 66:
! 67: /* Turn interrupts off, just in case. */
! 68: mc146818_write(sc, MC_REGB, MC_REGB_BINARY | MC_REGB_24HR);
! 69:
! 70: clockattach(&sc->sc_dev, &mcclock_clockfns);
! 71: }
! 72:
! 73: void
! 74: mcclock_init(dev)
! 75: struct device *dev;
! 76: {
! 77: struct mcclock_softc *sc = (struct mcclock_softc *)dev;
! 78:
! 79: mc146818_write(sc, MC_REGA, MC_BASE_32_KHz | MC_RATE_1024_Hz);
! 80: mc146818_write(sc, MC_REGB,
! 81: MC_REGB_PIE | MC_REGB_SQWE | MC_REGB_BINARY | MC_REGB_24HR);
! 82: }
! 83:
! 84: /*
! 85: * Get the time of day, based on the clock's value and/or the base value.
! 86: */
! 87: void
! 88: mcclock_get(dev, base, ct)
! 89: struct device *dev;
! 90: time_t base;
! 91: struct clocktime *ct;
! 92: {
! 93: struct mcclock_softc *sc = (struct mcclock_softc *)dev;
! 94: mc_todregs regs;
! 95: int s;
! 96:
! 97: s = splclock();
! 98: MC146818_GETTOD(sc, ®s)
! 99: splx(s);
! 100:
! 101: ct->sec = regs[MC_SEC];
! 102: ct->min = regs[MC_MIN];
! 103: ct->hour = regs[MC_HOUR];
! 104: ct->dow = regs[MC_DOW];
! 105: ct->day = regs[MC_DOM];
! 106: ct->mon = regs[MC_MONTH];
! 107: ct->year = regs[MC_YEAR];
! 108: }
! 109:
! 110: /*
! 111: * Reset the TODR based on the time value.
! 112: */
! 113: void
! 114: mcclock_set(dev, ct)
! 115: struct device *dev;
! 116: struct clocktime *ct;
! 117: {
! 118: struct mcclock_softc *sc = (struct mcclock_softc *)dev;
! 119: mc_todregs regs;
! 120: int s;
! 121:
! 122: s = splclock();
! 123: MC146818_GETTOD(sc, ®s);
! 124: splx(s);
! 125:
! 126: regs[MC_SEC] = ct->sec;
! 127: regs[MC_MIN] = ct->min;
! 128: regs[MC_HOUR] = ct->hour;
! 129: regs[MC_DOW] = ct->dow;
! 130: regs[MC_DOM] = ct->day;
! 131: regs[MC_MONTH] = ct->mon;
! 132: regs[MC_YEAR] = ct->year;
! 133:
! 134: s = splclock();
! 135: MC146818_PUTTOD(sc, ®s);
! 136: splx(s);
! 137: }
CVSweb