xref: /netbsd/sys/arch/sparc/sparc/auxreg.c (revision c4a72b64)
1 /*	$NetBSD: auxreg.c,v 1.32 2002/10/02 16:02:09 thorpej Exp $ */
2 
3 /*
4  * Copyright (c) 1992, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This software was developed by the Computer Systems Engineering group
8  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
9  * contributed to Berkeley.
10  *
11  * All advertising materials mentioning features or use of this software
12  * must display the following acknowledgement:
13  *	This product includes software developed by the University of
14  *	California, Lawrence Berkeley Laboratory.
15  *
16  * Redistribution and use in source and binary forms, with or without
17  * modification, are permitted provided that the following conditions
18  * are met:
19  * 1. Redistributions of source code must retain the above copyright
20  *    notice, this list of conditions and the following disclaimer.
21  * 2. Redistributions in binary form must reproduce the above copyright
22  *    notice, this list of conditions and the following disclaimer in the
23  *    documentation and/or other materials provided with the distribution.
24  * 3. All advertising materials mentioning features or use of this software
25  *    must display the following acknowledgement:
26  *	This product includes software developed by the University of
27  *	California, Berkeley and its contributors.
28  * 4. Neither the name of the University nor the names of its contributors
29  *    may be used to endorse or promote products derived from this software
30  *    without specific prior written permission.
31  *
32  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
33  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
34  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
35  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
36  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
40  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
41  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
42  * SUCH DAMAGE.
43  *
44  *	@(#)auxreg.c	8.1 (Berkeley) 6/11/93
45  */
46 
47 #include "opt_blink.h"
48 
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/callout.h>
52 #include <sys/device.h>
53 #include <sys/kernel.h>
54 
55 #include <machine/autoconf.h>
56 
57 #include <sparc/sparc/vaddrs.h>
58 #include <sparc/sparc/auxreg.h>
59 
60 static int auxregmatch_mainbus __P((struct device *, struct cfdata *, void *));
61 static int auxregmatch_obio __P((struct device *, struct cfdata *, void *));
62 static void auxregattach_mainbus
63 		__P((struct device *, struct device *, void *));
64 static void auxregattach_obio
65 		__P((struct device *, struct device *, void *));
66 
67 static void auxregattach __P((struct device *));
68 
69 CFATTACH_DECL(auxreg_mainbus, sizeof(struct device),
70     auxregmatch_mainbus, auxregattach_mainbus, NULL, NULL);
71 
72 CFATTACH_DECL(auxreg_obio, sizeof(struct device),
73     auxregmatch_obio, auxregattach_obio, NULL, NULL);
74 
75 #ifdef BLINK
76 static struct callout blink_ch = CALLOUT_INITIALIZER;
77 
78 static void blink __P((void *zero));
79 
80 static void
81 blink(zero)
82 	void *zero;
83 {
84 	register int s;
85 
86 	s = splhigh();
87 	LED_FLIP;
88 	splx(s);
89 	/*
90 	 * Blink rate is:
91 	 *	full cycle every second if completely idle (loadav = 0)
92 	 *	full cycle every 2 seconds if loadav = 1
93 	 *	full cycle every 3 seconds if loadav = 2
94 	 * etc.
95 	 */
96 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
97 	callout_reset(&blink_ch, s, blink, NULL);
98 }
99 #endif
100 
101 /*
102  * The OPENPROM calls this "auxiliary-io" (sun4c) or "auxio" (sun4m).
103  */
104 static int
105 auxregmatch_mainbus(parent, cf, aux)
106 	struct device *parent;
107 	struct cfdata *cf;
108 	void *aux;
109 {
110 	struct mainbus_attach_args *ma = aux;
111 
112 	return (strcmp("auxiliary-io", ma->ma_name) == 0);
113 }
114 
115 static int
116 auxregmatch_obio(parent, cf, aux)
117 	struct device *parent;
118 	struct cfdata *cf;
119 	void *aux;
120 {
121 	union obio_attach_args *uoba = aux;
122 
123 	if (uoba->uoba_isobio4 != 0)
124 		return (0);
125 
126 	return (strcmp("auxio", uoba->uoba_sbus.sa_name) == 0);
127 }
128 
129 /* ARGSUSED */
130 static void
131 auxregattach_mainbus(parent, self, aux)
132 	struct device *parent, *self;
133 	void *aux;
134 {
135 	struct mainbus_attach_args *ma = aux;
136 	bus_space_handle_t bh;
137 
138 	if (bus_space_map2(ma->ma_bustag,
139 			  (bus_addr_t)ma->ma_paddr,
140 			  sizeof(long),
141 			  BUS_SPACE_MAP_LINEAR,
142 			  AUXREG_VA,
143 			  &bh) != 0) {
144 		printf("auxregattach_mainbus: can't map register\n");
145 		return;
146 	}
147 
148 	auxio_reg = AUXIO4C_REG;
149 	auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1;
150 	auxregattach(self);
151 }
152 
153 static void
154 auxregattach_obio(parent, self, aux)
155 	struct device *parent, *self;
156 	void *aux;
157 {
158 	union obio_attach_args *uoba = aux;
159 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
160 	bus_space_handle_t bh;
161 
162 	if (bus_space_map2(sa->sa_bustag,
163 			  BUS_ADDR(sa->sa_slot, sa->sa_offset),
164 			  sizeof(long),
165 			  BUS_SPACE_MAP_LINEAR,
166 			  AUXREG_VA, &bh) != 0) {
167 		printf("auxregattach_obio: can't map register\n");
168 		return;
169 	}
170 
171 	auxio_reg = AUXIO4M_REG;
172 	auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1;
173 	auxregattach(self);
174 }
175 
176 static void
177 auxregattach(self)
178 	struct device *self;
179 {
180 
181 	printf("\n");
182 #ifdef BLINK
183 	blink((caddr_t)0);
184 #else
185 	LED_ON;
186 #endif
187 }
188 
189 unsigned int
190 auxregbisc(bis, bic)
191 	int bis, bic;
192 {
193 	register int s;
194 
195 	if (auxio_reg == 0)
196 		/*
197 		 * Not all machines have an `aux' register; devices that
198 		 * depend on it should not get configured if it's absent.
199 		 */
200 		panic("no aux register");
201 
202 	s = splhigh();
203 	auxio_regval = (auxio_regval | bis) & ~bic;
204 	*auxio_reg = auxio_regval;
205 	splx(s);
206 	return (auxio_regval);
207 }
208