xref: /netbsd/sys/arch/alpha/tlsb/mcclock_tlsb.c (revision c4a72b64)
1 /* $NetBSD: mcclock_tlsb.c,v 1.10 2002/10/02 04:06:40 thorpej Exp $ */
2 
3 /*
4  * Copyright (c) 1997 by Matthew Jacob
5  * NASA AMES Research Center.
6  * All rights reserved.
7  *
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.
19  *
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.
31  */
32 
33 #include <sys/cdefs.h>			/* RCS ID & Copyright macro defns */
34 
35 __KERNEL_RCSID(0, "$NetBSD: mcclock_tlsb.c,v 1.10 2002/10/02 04:06:40 thorpej Exp $");
36 
37 #include <sys/param.h>
38 #include <sys/kernel.h>
39 #include <sys/systm.h>
40 #include <sys/device.h>
41 
42 #include <machine/bus.h>
43 
44 #include <dev/dec/clockvar.h>
45 #include <dev/dec/mcclockvar.h>
46 
47 #include <alpha/tlsb/gbusvar.h>
48 
49 #include <alpha/tlsb/tlsbreg.h>		/* XXX */
50 
51 #include <dev/ic/mc146818reg.h>
52 
53 #define	KV(_addr)	((caddr_t)ALPHA_PHYS_TO_K0SEG((_addr)))
54 /*
55  * Registers are 64 bytes apart (and 1 byte wide)
56  */
57 #define	REGSHIFT	6
58 
59 struct mcclock_tlsb_softc {
60 	struct mcclock_softc	sc_mcclock;
61 	unsigned long regbase;
62 };
63 
64 int	mcclock_tlsb_match __P((struct device *, struct cfdata *, void *));
65 void	mcclock_tlsb_attach __P((struct device *, struct device *, void *));
66 
67 CFATTACH_DECL(mcclock_tlsb, sizeof (struct mcclock_tlsb_softc),
68     mcclock_tlsb_match, mcclock_tlsb_attach, NULL, NULL);
69 
70 extern struct cfdriver mcclock_cd;
71 
72 static void	mcclock_tlsb_write __P((struct mcclock_softc *, u_int, u_int));
73 static u_int	mcclock_tlsb_read __P((struct mcclock_softc *, u_int));
74 
75 const struct mcclock_busfns mcclock_tlsb_busfns = {
76 	mcclock_tlsb_write, mcclock_tlsb_read,
77 };
78 
79 int
80 mcclock_tlsb_match(parent, match, aux)
81 	struct device *parent;
82 	struct cfdata *match;
83 	void *aux;
84 {
85 	struct gbus_attach_args *ga = aux;
86 	if (strcmp(ga->ga_name, mcclock_cd.cd_name))
87 		return (0);
88 	return (1);
89 }
90 
91 void
92 mcclock_tlsb_attach(parent, self, aux)
93 	struct device *parent, *self;
94 	void *aux;
95 {
96 	struct mcclock_tlsb_softc *sc = (struct mcclock_tlsb_softc *)self;
97 	struct gbus_attach_args *ga = aux;
98 
99 	/* XXX Should be bus.h'd, so we can accomodate the kn7aa. */
100 	sc->regbase = TLSB_GBUS_BASE + ga->ga_offset;
101 
102 	mcclock_attach(&sc->sc_mcclock, &mcclock_tlsb_busfns);
103 }
104 
105 static void
106 mcclock_tlsb_write(mcsc, reg, val)
107 	struct mcclock_softc *mcsc;
108 	u_int reg, val;
109 {
110 	struct mcclock_tlsb_softc *sc = (struct mcclock_tlsb_softc *)mcsc;
111 	unsigned char *ptr = (unsigned char *)
112 		KV(sc->regbase + (reg << REGSHIFT));
113 	*ptr = val;
114 }
115 
116 static u_int
117 mcclock_tlsb_read(mcsc, reg)
118 	struct mcclock_softc *mcsc;
119 	u_int reg;
120 {
121 	struct mcclock_tlsb_softc *sc = (struct mcclock_tlsb_softc *)mcsc;
122 	unsigned char *ptr = (unsigned char *)
123 		KV(sc->regbase + (reg << REGSHIFT));
124 	return *ptr;
125 }
126