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