1 /* $NetBSD: mcclock_tlsb.c,v 1.8 1998/05/13 02:50:29 thorpej Exp $ */
3 * Copyright (c) 1997, 2000 by Matthew Jacob
4 * NASA AMES Research Center.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice immediately at the beginning of the file, without modification,
12 * this list of conditions, and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <sys/cdefs.h>
31 __FBSDID("$FreeBSD$");
33 #include <sys/param.h>
34 #include <sys/kernel.h>
35 #include <sys/systm.h>
36 #include <sys/module.h>
39 #include <machine/clockvar.h>
40 #include <dev/dec/mcclockvar.h>
42 #include <alpha/tlsb/gbusvar.h>
44 #include <alpha/tlsb/tlsbreg.h> /* XXX */
46 #include <dev/dec/mc146818reg.h>
48 #define KV(_addr) ((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
50 * Registers are 64 bytes apart (and 1 byte wide)
54 struct mcclock_tlsb_softc {
55 unsigned long regbase;
58 static int mcclock_tlsb_probe(device_t dev);
59 static int mcclock_tlsb_attach(device_t dev);
60 static void mcclock_tlsb_write(device_t, u_int, u_int);
61 static u_int mcclock_tlsb_read(device_t, u_int);
63 static device_method_t mcclock_tlsb_methods[] = {
64 /* Device interface */
65 DEVMETHOD(device_probe, mcclock_tlsb_probe),
66 DEVMETHOD(device_attach, mcclock_tlsb_attach),
68 /* mcclock interface */
69 DEVMETHOD(mcclock_write, mcclock_tlsb_write),
70 DEVMETHOD(mcclock_read, mcclock_tlsb_read),
73 DEVMETHOD(clock_init, mcclock_init),
74 DEVMETHOD(clock_get, mcclock_get),
75 DEVMETHOD(clock_set, mcclock_set),
76 DEVMETHOD(clock_getsecs, mcclock_getsecs),
81 static driver_t mcclock_tlsb_driver = {
82 "mcclock", mcclock_tlsb_methods, sizeof(struct mcclock_tlsb_softc),
85 static devclass_t mcclock_devclass;
88 mcclock_tlsb_probe(device_t dev)
90 device_set_desc(dev, "MC146818A real time clock");
95 mcclock_tlsb_attach(device_t dev)
97 struct mcclock_tlsb_softc *sc = device_get_softc(dev);
99 /* XXX Should be bus.h'd, so we can accomodate the kn7aa. */
101 sc->regbase = TLSB_GBUS_BASE + gbus_get_offset(dev);
108 mcclock_tlsb_write(device_t dev, u_int reg, u_int val)
110 struct mcclock_tlsb_softc *sc = device_get_softc(dev);
111 unsigned char *ptr = (unsigned char *)
112 KV(sc->regbase + (reg << REGSHIFT));
117 mcclock_tlsb_read(device_t dev, u_int reg)
119 struct mcclock_tlsb_softc *sc = device_get_softc(dev);
120 unsigned char *ptr = (unsigned char *)
121 KV(sc->regbase + (reg << REGSHIFT));
125 DRIVER_MODULE(mcclock, gbus, mcclock_tlsb_driver, mcclock_devclass, 0, 0);