1 /*	$OpenBSD: auxreg.c,v 1.11 2003/06/02 23:27:55 millert Exp $	*/
2 /*	$NetBSD: auxreg.c,v 1.21 1997/05/24 20:15:59 pk Exp $ */
3 
4 /*
5  * Copyright (c) 1992, 1993
6  *	The Regents of the University of California.  All rights reserved.
7  *
8  * This software was developed by the Computer Systems Engineering group
9  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
10  * contributed to Berkeley.
11  *
12  * All advertising materials mentioning features or use of this software
13  * must display the following acknowledgement:
14  *	This product includes software developed by the University of
15  *	California, Lawrence Berkeley Laboratory.
16  *
17  * Redistribution and use in source and binary forms, with or without
18  * modification, are permitted provided that the following conditions
19  * are met:
20  * 1. Redistributions of source code must retain the above copyright
21  *    notice, this list of conditions and the following disclaimer.
22  * 2. Redistributions in binary form must reproduce the above copyright
23  *    notice, this list of conditions and the following disclaimer in the
24  *    documentation and/or other materials provided with the distribution.
25  * 3. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  *	@(#)auxreg.c	8.1 (Berkeley) 6/11/93
42  */
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/device.h>
47 #include <sys/kernel.h>
48 #include <sys/timeout.h>
49 
50 #include <machine/autoconf.h>
51 
52 #include <sparc/sparc/vaddrs.h>
53 #include <sparc/sparc/auxioreg.h>
54 
55 static int auxregmatch(struct device *, void *, void *);
56 static void auxregattach(struct device *, struct device *, void *);
57 
58 struct cfattach auxreg_ca = {
59 	sizeof(struct device), auxregmatch, auxregattach
60 };
61 
62 struct cfdriver auxreg_cd = {
63 	0, "auxreg", DV_DULL
64 };
65 
66 volatile u_char *auxio_reg;	/* Copy of AUXIO_REG */
67 u_char auxio_regval;
68 extern int sparc_led_blink;	/* from machdep */
69 struct timeout sparc_led_to;
70 
71 void
led_blink(zero)72 led_blink(zero)
73 	void *zero;
74 {
75 	int s;
76 
77 	/* Don't do anything if there's no auxreg, ok? */
78 	if (auxio_reg == 0)
79 		return;
80 
81 	if (!sparc_led_blink) {
82 		/* If blink has been disabled, make sure it goes back on... */
83 		s = splhigh();
84 		LED_ON;
85 		splx(s);
86 
87 		return;
88 	}
89 
90 	s = splhigh();
91 	LED_FLIP;
92 	splx(s);
93 	/*
94 	 * Blink rate is:
95 	 *	full cycle every second if completely idle (loadav = 0)
96 	 *	full cycle every 2 seconds if loadav = 1
97 	 *	full cycle every 3 seconds if loadav = 2
98 	 * etc.
99 	 */
100 	s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
101 
102 	timeout_add(&sparc_led_to, s);
103 }
104 
105 /*
106  * The OPENPROM calls this "auxiliary-io".
107  */
108 static int
auxregmatch(parent,cf,aux)109 auxregmatch(parent, cf, aux)
110 	struct device *parent;
111 	void *cf, *aux;
112 {
113 	register struct confargs *ca = aux;
114 
115 	switch (cputyp) {
116 	    case CPU_SUN4:
117 		return (0);
118 	    case CPU_SUN4C:
119 		return (strcmp("auxiliary-io", ca->ca_ra.ra_name) == 0);
120 	    case CPU_SUN4M:
121 		return (strcmp("auxio", ca->ca_ra.ra_name) == 0);
122 	    default:
123 		panic("auxregmatch");
124 	}
125 }
126 
127 /* ARGSUSED */
128 static void
auxregattach(parent,self,aux)129 auxregattach(parent, self, aux)
130 	struct device *parent, *self;
131 	void *aux;
132 {
133 	struct confargs *ca = aux;
134 	struct romaux *ra = &ca->ca_ra;
135 
136 	(void)mapdev(ra->ra_reg, AUXREG_VA, 0, sizeof(long));
137 	if (CPU_ISSUN4M) {
138 		auxio_reg = AUXIO4M_REG;
139 		auxio_regval = *AUXIO4M_REG | AUXIO4M_MB1;
140 	} else {
141 		auxio_reg = AUXIO4C_REG;
142 		auxio_regval = *AUXIO4C_REG | AUXIO4C_FEJ | AUXIO4C_MB1;
143 	}
144 
145 	printf("\n");
146 
147 	timeout_set(&sparc_led_to, led_blink, NULL);
148 	/* In case it's initialized to true... */
149 	if (sparc_led_blink)
150 		led_blink((caddr_t)0);
151 }
152 
153 unsigned int
auxregbisc(bis,bic)154 auxregbisc(bis, bic)
155 	int bis, bic;
156 {
157 	register int s;
158 
159 	if (auxio_reg == 0)
160 		/*
161 		 * Not all machines have an `aux' register; devices that
162 		 * depend on it should not get configured if it's absent.
163 		 */
164 		panic("no aux register");
165 
166 	s = splhigh();
167 	auxio_regval = (auxio_regval | bis) & ~bic;
168 	*auxio_reg = auxio_regval;
169 	splx(s);
170 	return (auxio_regval);
171 }
172