xref: /netbsd/sys/arch/sparc/sparc/auxreg.c (revision bf9ec67e)
1 /*	$NetBSD: auxreg.c,v 1.29 2002/03/11 16:27:03 pk 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 struct cfattach auxreg_mainbus_ca = {
70 	sizeof(struct device), auxregmatch_mainbus, auxregattach_mainbus
71 };
72 struct cfattach auxreg_obio_ca = {
73 	sizeof(struct device), auxregmatch_obio, auxregattach_obio
74 };
75 
76 #ifdef BLINK
77 static struct callout blink_ch = CALLOUT_INITIALIZER;
78 
79 static void blink __P((void *zero));
80 
81 static void
82 blink(zero)
83 	void *zero;
84 {
85 	register int s;
86 
87 	s = splhigh();
88 	LED_FLIP;
89 	splx(s);
90 	/*
91 	 * Blink rate is:
92 	 *	full cycle every second if completely idle (loadav = 0)
93 	 *	full cycle every 2 seconds if loadav = 1
94 	 *	full cycle every 3 seconds if loadav = 2
95 	 * etc.
96 	 */
97 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
98 	callout_reset(&blink_ch, s, blink, NULL);
99 }
100 #endif
101 
102 /*
103  * The OPENPROM calls this "auxiliary-io" (sun4c) or "auxio" (sun4m).
104  */
105 static int
106 auxregmatch_mainbus(parent, cf, aux)
107 	struct device *parent;
108 	struct cfdata *cf;
109 	void *aux;
110 {
111 	struct mainbus_attach_args *ma = aux;
112 
113 	return (strcmp("auxiliary-io", ma->ma_name) == 0);
114 }
115 
116 static int
117 auxregmatch_obio(parent, cf, aux)
118 	struct device *parent;
119 	struct cfdata *cf;
120 	void *aux;
121 {
122 	union obio_attach_args *uoba = aux;
123 
124 	if (uoba->uoba_isobio4 != 0)
125 		return (0);
126 
127 	return (strcmp("auxio", uoba->uoba_sbus.sa_name) == 0);
128 }
129 
130 /* ARGSUSED */
131 static void
132 auxregattach_mainbus(parent, self, aux)
133 	struct device *parent, *self;
134 	void *aux;
135 {
136 	struct mainbus_attach_args *ma = aux;
137 	bus_space_handle_t bh;
138 
139 	if (bus_space_map2(ma->ma_bustag,
140 			  (bus_addr_t)ma->ma_paddr,
141 			  sizeof(long),
142 			  BUS_SPACE_MAP_LINEAR,
143 			  AUXREG_VA,
144 			  &bh) != 0) {
145 		printf("auxregattach_mainbus: can't map register\n");
146 		return;
147 	}
148 
149 	auxio_reg = AUXIO4C_REG;
150 	auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1;
151 	auxregattach(self);
152 }
153 
154 static void
155 auxregattach_obio(parent, self, aux)
156 	struct device *parent, *self;
157 	void *aux;
158 {
159 	union obio_attach_args *uoba = aux;
160 	struct sbus_attach_args *sa = &uoba->uoba_sbus;
161 	bus_space_handle_t bh;
162 
163 	if (bus_space_map2(sa->sa_bustag,
164 			  BUS_ADDR(sa->sa_slot, sa->sa_offset),
165 			  sizeof(long),
166 			  BUS_SPACE_MAP_LINEAR,
167 			  AUXREG_VA, &bh) != 0) {
168 		printf("auxregattach_obio: can't map register\n");
169 		return;
170 	}
171 
172 	auxio_reg = AUXIO4M_REG;
173 	auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1;
174 	auxregattach(self);
175 }
176 
177 static void
178 auxregattach(self)
179 	struct device *self;
180 {
181 
182 	printf("\n");
183 #ifdef BLINK
184 	blink((caddr_t)0);
185 #else
186 	LED_ON;
187 #endif
188 }
189 
190 unsigned int
191 auxregbisc(bis, bic)
192 	int bis, bic;
193 {
194 	register int s;
195 
196 	if (auxio_reg == 0)
197 		/*
198 		 * Not all machines have an `aux' register; devices that
199 		 * depend on it should not get configured if it's absent.
200 		 */
201 		panic("no aux register");
202 
203 	s = splhigh();
204 	auxio_regval = (auxio_regval | bis) & ~bic;
205 	*auxio_reg = auxio_regval;
206 	splx(s);
207 	return (auxio_regval);
208 }
209