Annotation of sys/arch/sgi/sgi/clock_md.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: clock_md.c,v 1.8 2005/01/31 21:25:21 grange Exp $ */
! 2:
! 3: /*
! 4: * Copyright (c) 2001-2004 Opsycon AB (www.opsycon.se / www.opsycon.com)
! 5: *
! 6: * Redistribution and use in source and binary forms, with or without
! 7: * modification, are permitted provided that the following conditions
! 8: * are met:
! 9: * 1. Redistributions of source code must retain the above copyright
! 10: * notice, this list of conditions and the following disclaimer.
! 11: * 2. Redistributions in binary form must reproduce the above copyright
! 12: * notice, this list of conditions and the following disclaimer in the
! 13: * documentation and/or other materials provided with the distribution.
! 14: *
! 15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
! 16: * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
! 18: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
! 19: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
! 20: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
! 21: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
! 23: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
! 24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
! 25: * SUCH DAMAGE.
! 26: *
! 27: */
! 28:
! 29: #include <sys/param.h>
! 30: #include <sys/kernel.h>
! 31: #include <sys/systm.h>
! 32: #include <sys/device.h>
! 33:
! 34: #include <machine/autoconf.h>
! 35: #include <machine/bus.h>
! 36:
! 37: #include <mips64/archtype.h>
! 38: #include <mips64/dev/clockvar.h>
! 39:
! 40: #include <sgi/localbus/macebus.h>
! 41:
! 42: extern int clockmatch(struct device *, void *, void *);
! 43: extern void clockattach(struct device *, struct device *, void *);
! 44: extern void clock_int5_init(struct clock_softc *);
! 45: extern int clock_started;
! 46:
! 47: #define FROMBCD(x) (((x) >> 4) * 10 + ((x) & 0xf))
! 48: #define TOBCD(x) (((x) / 10 * 16) + ((x) % 10))
! 49:
! 50: struct cfattach clock_macebus_ca = {
! 51: sizeof(struct clock_softc), clockmatch, clockattach
! 52: };
! 53: struct cfattach clock_xbowmux_ca = {
! 54: sizeof(struct clock_softc), clockmatch, clockattach
! 55: };
! 56:
! 57:
! 58: void ds1687_get(struct clock_softc *, time_t, struct tod_time *);
! 59: void ds1687_set(struct clock_softc *, struct tod_time *);
! 60:
! 61: void
! 62: md_clk_attach(parent, self, aux)
! 63: struct device *parent;
! 64: struct device *self;
! 65: void *aux;
! 66: {
! 67: struct clock_softc *sc = (struct clock_softc *)self;
! 68: struct confargs *ca;
! 69:
! 70: ca = aux;
! 71:
! 72: switch (sys_config.system_type) {
! 73: case SGI_O2:
! 74: sc->sc_clock.clk_get = ds1687_get;
! 75: sc->sc_clock.clk_set = ds1687_set;
! 76: sc->sc_clock.clk_init = clock_int5_init;
! 77: sc->sc_clock.clk_hz = 100;
! 78: sc->sc_clock.clk_profhz = 100;
! 79: sc->sc_clock.clk_stathz = 0; /* XXX no stat clock yet */
! 80: sc->sc_clk_t = ca->ca_iot;
! 81: if (bus_space_map(sc->sc_clk_t, MACE_ISA_RTC_OFFS, 128*256, 0,
! 82: &sc->sc_clk_h))
! 83: printf("UH!? Can't map clock device!\n");
! 84: printf(": TOD with DS1687,");
! 85: break;
! 86:
! 87: case SGI_O200:
! 88: sc->sc_clock.clk_init = clock_int5_init;
! 89: sc->sc_clock.clk_hz = 100;
! 90: sc->sc_clock.clk_profhz = 100;
! 91: sc->sc_clock.clk_stathz = 0; /* XXX no stat clock yet */
! 92: printf("TODO set up clock.");
! 93: break;
! 94:
! 95: default:
! 96: printf("don't know how to set up clock.");
! 97: }
! 98: }
! 99:
! 100:
! 101: /*
! 102: * Dallas clock driver.
! 103: */
! 104: void
! 105: ds1687_get(sc, base, ct)
! 106: struct clock_softc *sc;
! 107: time_t base;
! 108: struct tod_time *ct;
! 109: {
! 110: bus_space_tag_t clk_t = sc->sc_clk_t;
! 111: bus_space_handle_t clk_h = sc->sc_clk_h;
! 112: int tmp12, century;
! 113:
! 114: /* Select bank 1 */
! 115: tmp12 = bus_space_read_1(clk_t, clk_h, 12);
! 116: bus_space_write_1(clk_t, clk_h, 12, tmp12 | 0x10);
! 117:
! 118: /* Wait for no update in progress */
! 119: while (bus_space_read_1(clk_t, clk_h, 12) & 0x80)
! 120: /* Do nothing */;
! 121:
! 122: ct->sec = FROMBCD(bus_space_read_1(clk_t, clk_h, 0));
! 123: ct->min = FROMBCD(bus_space_read_1(clk_t, clk_h, 2));
! 124: ct->hour = FROMBCD(bus_space_read_1(clk_t, clk_h, 4));
! 125: ct->day = FROMBCD(bus_space_read_1(clk_t, clk_h, 7));
! 126: ct->mon = FROMBCD(bus_space_read_1(clk_t, clk_h, 8));
! 127: ct->year = FROMBCD(bus_space_read_1(clk_t, clk_h, 9));
! 128: century = FROMBCD(bus_space_read_1(clk_t, clk_h, 72));
! 129:
! 130: bus_space_write_1(clk_t, clk_h, 12, tmp12 | 0x10);
! 131:
! 132: ct->year += 100 * (century - 19);
! 133: }
! 134:
! 135: void
! 136: ds1687_set(sc, ct)
! 137: struct clock_softc *sc;
! 138: struct tod_time *ct;
! 139: {
! 140: bus_space_tag_t clk_t = sc->sc_clk_t;
! 141: bus_space_handle_t clk_h = sc->sc_clk_h;
! 142: int year, century, tmp12, tmp13;
! 143:
! 144: century = ct->year / 100 + 19;
! 145: year = ct->year % 100;
! 146:
! 147: /* Select bank 1 */
! 148: tmp12 = bus_space_read_1(clk_t, clk_h, 12);
! 149: bus_space_write_1(clk_t, clk_h, 12, tmp12 | 0x10);
! 150:
! 151: /* Stop update */
! 152: tmp13 = bus_space_read_1(clk_t, clk_h, 13);
! 153: bus_space_write_1(clk_t, clk_h, 13, tmp13 | 0x80);
! 154:
! 155: bus_space_write_1(clk_t, clk_h, 0, TOBCD(ct->sec));
! 156: bus_space_write_1(clk_t, clk_h, 2, TOBCD(ct->min));
! 157: bus_space_write_1(clk_t, clk_h, 4, TOBCD(ct->hour));
! 158: bus_space_write_1(clk_t, clk_h, 6, TOBCD(ct->dow));
! 159: bus_space_write_1(clk_t, clk_h, 7, TOBCD(ct->day));
! 160: bus_space_write_1(clk_t, clk_h, 8, TOBCD(ct->mon));
! 161: bus_space_write_1(clk_t, clk_h, 9, TOBCD(year));
! 162: bus_space_write_1(clk_t, clk_h, 72, TOBCD(century));
! 163:
! 164: bus_space_write_1(clk_t, clk_h, 12, tmp12);
! 165: bus_space_write_1(clk_t, clk_h, 13, tmp13);
! 166: }
CVSweb