No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / alpha / tlsb / mcclock_tlsb.c
blob3e2fd83df3f760750ff74e77325460e5b29d7a5a
1 /* $NetBSD: mcclock_tlsb.c,v 1.15 2008/03/28 19:05:49 tsutsui Exp $ */
3 /*
4 * Copyright (c) 1997 by Matthew Jacob
5 * NASA AMES Research Center.
6 * All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice immediately at the beginning of the file, without modification,
13 * this list of conditions, and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
33 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */
35 __KERNEL_RCSID(0, "$NetBSD: mcclock_tlsb.c,v 1.15 2008/03/28 19:05:49 tsutsui Exp $");
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
42 #include <machine/bus.h>
44 #include <alpha/tlsb/gbusvar.h>
46 #include <alpha/tlsb/tlsbreg.h> /* XXX */
48 #include <dev/clock_subr.h>
50 #include <dev/ic/mc146818reg.h>
51 #include <dev/ic/mc146818var.h>
53 #include <alpha/alpha/mcclockvar.h>
55 #include "ioconf.h"
57 #define KV(_addr) ((void *)ALPHA_PHYS_TO_K0SEG((_addr)))
59 * Registers are 64 bytes apart (and 1 byte wide)
61 #define REGSHIFT 6
63 struct mcclock_tlsb_softc {
64 struct mc146818_softc sc_mc146818;
65 unsigned long regbase;
68 int mcclock_tlsb_match(device_t, cfdata_t, void *);
69 void mcclock_tlsb_attach(device_t, device_t, void *);
71 CFATTACH_DECL_NEW(mcclock_tlsb, sizeof(struct mcclock_tlsb_softc),
72 mcclock_tlsb_match, mcclock_tlsb_attach, NULL, NULL);
74 static void mcclock_tlsb_write(struct mc146818_softc *, u_int, u_int);
75 static u_int mcclock_tlsb_read(struct mc146818_softc *, u_int);
78 int
79 mcclock_tlsb_match(device_t parent, cfdata_t cf, void *aux)
81 struct gbus_attach_args *ga = aux;
83 if (strcmp(ga->ga_name, mcclock_cd.cd_name))
84 return (0);
85 return (1);
88 void
89 mcclock_tlsb_attach(device_t parent, device_t self, void *aux)
91 struct mcclock_tlsb_softc *tsc = device_private(self);
92 struct gbus_attach_args *ga = aux;
93 struct mc146818_softc *sc = &tsc->sc_mc146818;
95 /* XXX Should be bus.h'd, so we can accommodate the kn7aa. */
96 tsc->regbase = TLSB_GBUS_BASE + ga->ga_offset;
98 sc->sc_dev = self;
99 sc->sc_mcread = mcclock_tlsb_read;
100 sc->sc_mcwrite = mcclock_tlsb_write;
102 mcclock_attach(sc);
105 static void
106 mcclock_tlsb_write(struct mc146818_softc *sc, u_int reg, u_int val)
108 struct mcclock_tlsb_softc *tsc = (void *)sc;
109 unsigned char *ptr = (unsigned char *)
110 KV(tsc->regbase + (reg << REGSHIFT));
112 *ptr = val;
115 static u_int
116 mcclock_tlsb_read(struct mc146818_softc *sc, u_int reg)
118 struct mcclock_tlsb_softc *tsc = (void *)sc;
119 unsigned char *ptr = (unsigned char *)
120 KV(tsc->regbase + (reg << REGSHIFT));
122 return *ptr;