auxio.c revision 1.1.10.3 1 /* $NetBSD: auxio.c,v 1.1.10.3 2002/10/10 18:36:31 jdolecek Exp $ */
2
3 /*
4 * Copyright (c) 2000, 2001 Matthew R. Green
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 */
30
31 /*
32 * AUXIO registers support on the sbus & ebus2, used for the floppy driver
33 * and to control the system LED, for the BLINK option.
34 */
35
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/callout.h>
40 #include <sys/errno.h>
41 #include <sys/device.h>
42 #include <sys/malloc.h>
43
44 #include <machine/autoconf.h>
45 #include <machine/cpu.h>
46
47 #include <dev/ebus/ebusreg.h>
48 #include <dev/ebus/ebusvar.h>
49 #include <sparc64/dev/sbusvar.h>
50 #include <sparc64/dev/auxioreg.h>
51
52 /*
53 * on sun4u, auxio exists with one register (LED) on the sbus, and 5
54 * registers on the ebus2 (pci) (LED, PCIMODE, FREQUENCY, SCSI
55 * OSCILLATOR, and TEMP SENSE.
56 */
57
58 struct auxio_softc {
59 struct device sc_dev;
60
61 /* parent's tag */
62 bus_space_tag_t sc_tag;
63
64 /* handles to the various auxio regsiter sets */
65 bus_space_handle_t sc_led;
66 bus_space_handle_t sc_pci;
67 bus_space_handle_t sc_freq;
68 bus_space_handle_t sc_scsi;
69 bus_space_handle_t sc_temp;
70
71 int sc_flags;
72 #define AUXIO_LEDONLY 0x1
73 #define AUXIO_EBUS 0x2
74 #define AUXIO_SBUS 0x4
75 };
76
77 #define AUXIO_ROM_NAME "auxio"
78
79 void auxio_attach_common(struct auxio_softc *);
80 int auxio_ebus_match(struct device *, struct cfdata *, void *);
81 void auxio_ebus_attach(struct device *, struct device *, void *);
82 int auxio_sbus_match(struct device *, struct cfdata *, void *);
83 void auxio_sbus_attach(struct device *, struct device *, void *);
84
85 CFATTACH_DECL(auxio_ebus, sizeof(struct auxio_softc),
86 auxio_ebus_match, auxio_ebus_attach, NULL, NULL);
87
88 CFATTACH_DECL(auxio_sbus, sizeof(struct auxio_softc),
89 auxio_sbus_match, auxio_sbus_attach, NULL, NULL);
90
91 #ifdef BLINK
92 static struct callout blink_ch = CALLOUT_INITIALIZER;
93
94 static void auxio_blink(void *);
95
96 static void
97 auxio_blink(x)
98 void *x;
99 {
100 struct auxio_softc *sc = x;
101 int s;
102 u_int32_t led;
103
104 s = splhigh();
105 if (sc->sc_flags & AUXIO_EBUS)
106 led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0));
107 else
108 led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0);
109 if (led & AUXIO_LED_LED)
110 led = 0;
111 else
112 led = AUXIO_LED_LED;
113 if (sc->sc_flags & AUXIO_EBUS)
114 bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led));
115 else
116 bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led);
117 splx(s);
118
119 /*
120 * Blink rate is:
121 * full cycle every second if completely idle (loadav = 0)
122 * full cycle every 2 seconds if loadav = 1
123 * full cycle every 3 seconds if loadav = 2
124 * etc.
125 */
126 s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
127 callout_reset(&blink_ch, s, auxio_blink, sc);
128 }
129 #endif
130
131 void
132 auxio_attach_common(sc)
133 struct auxio_softc *sc;
134 {
135 #ifdef BLINK
136 static int do_once = 1;
137
138 /* only start one blinker */
139 if (do_once) {
140 auxio_blink(sc);
141 do_once = 0;
142 }
143 #endif
144 printf("\n");
145 }
146
147 int
148 auxio_ebus_match(parent, cf, aux)
149 struct device *parent;
150 struct cfdata *cf;
151 void *aux;
152 {
153 struct ebus_attach_args *ea = aux;
154
155 return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
156 }
157
158 void
159 auxio_ebus_attach(parent, self, aux)
160 struct device *parent, *self;
161 void *aux;
162 {
163 struct auxio_softc *sc = (struct auxio_softc *)self;
164 struct ebus_attach_args *ea = aux;
165
166 sc->sc_tag = ea->ea_bustag;
167
168 if (ea->ea_nreg < 1) {
169 printf(": no registers??\n");
170 return;
171 }
172
173 if (ea->ea_nreg != 5) {
174 printf(": not 5 (%d) registers, only setting led",
175 ea->ea_nreg);
176 sc->sc_flags = AUXIO_LEDONLY|AUXIO_EBUS;
177 } else if (ea->ea_nvaddr == 5) {
178 sc->sc_flags = AUXIO_EBUS;
179
180 sparc_promaddr_to_handle(sc->sc_tag,
181 ea->ea_vaddr[1], &sc->sc_pci);
182 sparc_promaddr_to_handle(sc->sc_tag,
183 ea->ea_vaddr[2], &sc->sc_freq);
184 sparc_promaddr_to_handle(sc->sc_tag,
185 ea->ea_vaddr[3], &sc->sc_scsi);
186 sparc_promaddr_to_handle(sc->sc_tag,
187 ea->ea_vaddr[4], &sc->sc_temp);
188 } else {
189 sc->sc_flags = AUXIO_EBUS;
190 bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
191 ea->ea_reg[1].size, 0, &sc->sc_pci);
192 bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
193 ea->ea_reg[2].size, 0, &sc->sc_freq);
194 bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
195 ea->ea_reg[3].size, 0, &sc->sc_scsi);
196 bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
197 ea->ea_reg[4].size, 0, &sc->sc_temp);
198 }
199
200 if (ea->ea_nvaddr > 0) {
201 sparc_promaddr_to_handle(sc->sc_tag,
202 ea->ea_vaddr[0], &sc->sc_led);
203 } else {
204 bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
205 ea->ea_reg[0].size, 0, &sc->sc_led);
206 }
207
208 auxio_attach_common(sc);
209 }
210
211 int
212 auxio_sbus_match(parent, cf, aux)
213 struct device *parent;
214 struct cfdata *cf;
215 void *aux;
216 {
217 struct sbus_attach_args *sa = aux;
218
219 return (strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0);
220 }
221
222 void
223 auxio_sbus_attach(parent, self, aux)
224 struct device *parent, *self;
225 void *aux;
226 {
227 struct auxio_softc *sc = (struct auxio_softc *)self;
228 struct sbus_attach_args *sa = aux;
229
230 sc->sc_tag = sa->sa_bustag;
231
232 if (sa->sa_nreg < 1) {
233 printf(": no registers??\n");
234 return;
235 }
236
237 if (sa->sa_nreg != 1) {
238 printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
239 sa->sa_npromvaddrs);
240 return;
241 }
242
243 /* sbus auxio only has one set of registers */
244 sc->sc_flags = AUXIO_LEDONLY|AUXIO_SBUS;
245 if (sa->sa_npromvaddrs > 0) {
246 sbus_promaddr_to_handle(sc->sc_tag,
247 sa->sa_promvaddr, &sc->sc_led);
248 } else {
249 sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
250 sa->sa_size, 0, &sc->sc_led);
251 }
252
253 auxio_attach_common(sc);
254 }
255