auxio.c revision 1.19 1 1.19 mrg /* $NetBSD: auxio.c,v 1.19 2008/05/29 14:51:26 mrg Exp $ */
2 1.1 mrg
3 1.1 mrg /*
4 1.2 mrg * 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 *
16 1.1 mrg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 1.1 mrg * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 1.1 mrg * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 1.1 mrg * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 1.1 mrg * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 1.1 mrg * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 1.1 mrg * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 1.1 mrg * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 1.1 mrg * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 1.1 mrg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 1.1 mrg * SUCH DAMAGE.
27 1.1 mrg */
28 1.1 mrg
29 1.1 mrg /*
30 1.2 mrg * AUXIO registers support on the sbus & ebus2, used for the floppy driver
31 1.2 mrg * and to control the system LED, for the BLINK option.
32 1.1 mrg */
33 1.11 lukem
34 1.11 lukem #include <sys/cdefs.h>
35 1.19 mrg __KERNEL_RCSID(0, "$NetBSD: auxio.c,v 1.19 2008/05/29 14:51:26 mrg Exp $");
36 1.10 heas
37 1.10 heas #include "opt_auxio.h"
38 1.1 mrg
39 1.1 mrg #include <sys/param.h>
40 1.1 mrg #include <sys/systm.h>
41 1.2 mrg #include <sys/kernel.h>
42 1.2 mrg #include <sys/callout.h>
43 1.1 mrg #include <sys/errno.h>
44 1.1 mrg #include <sys/device.h>
45 1.1 mrg #include <sys/malloc.h>
46 1.1 mrg
47 1.1 mrg #include <machine/autoconf.h>
48 1.1 mrg #include <machine/cpu.h>
49 1.1 mrg
50 1.2 mrg #include <dev/ebus/ebusreg.h>
51 1.4 mrg #include <dev/ebus/ebusvar.h>
52 1.1 mrg #include <sparc64/dev/sbusvar.h>
53 1.1 mrg #include <sparc64/dev/auxioreg.h>
54 1.16 jnemeth #include <sparc64/dev/auxiovar.h>
55 1.2 mrg
56 1.2 mrg /*
57 1.2 mrg * on sun4u, auxio exists with one register (LED) on the sbus, and 5
58 1.2 mrg * registers on the ebus2 (pci) (LED, PCIMODE, FREQUENCY, SCSI
59 1.2 mrg * OSCILLATOR, and TEMP SENSE.
60 1.2 mrg */
61 1.2 mrg
62 1.2 mrg struct auxio_softc {
63 1.2 mrg struct device sc_dev;
64 1.2 mrg
65 1.2 mrg /* parent's tag */
66 1.2 mrg bus_space_tag_t sc_tag;
67 1.2 mrg
68 1.2 mrg /* handles to the various auxio regsiter sets */
69 1.2 mrg bus_space_handle_t sc_led;
70 1.2 mrg bus_space_handle_t sc_pci;
71 1.2 mrg bus_space_handle_t sc_freq;
72 1.2 mrg bus_space_handle_t sc_scsi;
73 1.2 mrg bus_space_handle_t sc_temp;
74 1.2 mrg
75 1.2 mrg int sc_flags;
76 1.2 mrg #define AUXIO_LEDONLY 0x1
77 1.2 mrg #define AUXIO_EBUS 0x2
78 1.2 mrg #define AUXIO_SBUS 0x4
79 1.2 mrg };
80 1.1 mrg
81 1.1 mrg #define AUXIO_ROM_NAME "auxio"
82 1.1 mrg
83 1.2 mrg void auxio_attach_common(struct auxio_softc *);
84 1.2 mrg int auxio_ebus_match(struct device *, struct cfdata *, void *);
85 1.2 mrg void auxio_ebus_attach(struct device *, struct device *, void *);
86 1.2 mrg int auxio_sbus_match(struct device *, struct cfdata *, void *);
87 1.2 mrg void auxio_sbus_attach(struct device *, struct device *, void *);
88 1.1 mrg
89 1.8 thorpej CFATTACH_DECL(auxio_ebus, sizeof(struct auxio_softc),
90 1.9 thorpej auxio_ebus_match, auxio_ebus_attach, NULL, NULL);
91 1.8 thorpej
92 1.8 thorpej CFATTACH_DECL(auxio_sbus, sizeof(struct auxio_softc),
93 1.9 thorpej auxio_sbus_match, auxio_sbus_attach, NULL, NULL);
94 1.1 mrg
95 1.16 jnemeth extern struct cfdriver auxio_cd;
96 1.16 jnemeth
97 1.2 mrg #ifdef BLINK
98 1.17 ad static callout_t blink_ch;
99 1.2 mrg static void auxio_blink(void *);
100 1.2 mrg
101 1.12 mrg /* let someone disable it if it's already turned on; XXX sysctl? */
102 1.12 mrg int do_blink = 1;
103 1.12 mrg
104 1.2 mrg static void
105 1.15 cdi auxio_blink(void *x)
106 1.2 mrg {
107 1.2 mrg struct auxio_softc *sc = x;
108 1.2 mrg int s;
109 1.15 cdi uint32_t led;
110 1.2 mrg
111 1.12 mrg if (do_blink == 0)
112 1.12 mrg return;
113 1.12 mrg
114 1.2 mrg s = splhigh();
115 1.2 mrg if (sc->sc_flags & AUXIO_EBUS)
116 1.2 mrg led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0));
117 1.2 mrg else
118 1.2 mrg led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0);
119 1.13 bouyer
120 1.13 bouyer led = led ^ AUXIO_LED_LED;
121 1.2 mrg if (sc->sc_flags & AUXIO_EBUS)
122 1.2 mrg bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led));
123 1.2 mrg else
124 1.2 mrg bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led);
125 1.2 mrg splx(s);
126 1.2 mrg
127 1.2 mrg /*
128 1.2 mrg * Blink rate is:
129 1.2 mrg * full cycle every second if completely idle (loadav = 0)
130 1.2 mrg * full cycle every 2 seconds if loadav = 1
131 1.2 mrg * full cycle every 3 seconds if loadav = 2
132 1.2 mrg * etc.
133 1.2 mrg */
134 1.2 mrg s = (((averunnable.ldavg[0] + FSCALE) * hz) >> (FSHIFT + 1));
135 1.2 mrg callout_reset(&blink_ch, s, auxio_blink, sc);
136 1.2 mrg }
137 1.2 mrg #endif
138 1.2 mrg
139 1.2 mrg void
140 1.15 cdi auxio_attach_common(struct auxio_softc *sc)
141 1.2 mrg {
142 1.3 pooka #ifdef BLINK
143 1.2 mrg static int do_once = 1;
144 1.2 mrg
145 1.2 mrg /* only start one blinker */
146 1.2 mrg if (do_once) {
147 1.17 ad callout_init(&blink_ch, 0);
148 1.2 mrg auxio_blink(sc);
149 1.2 mrg do_once = 0;
150 1.2 mrg }
151 1.2 mrg #endif
152 1.2 mrg printf("\n");
153 1.2 mrg }
154 1.2 mrg
155 1.1 mrg int
156 1.15 cdi auxio_ebus_match(struct device *parent, struct cfdata *cf, void *aux)
157 1.1 mrg {
158 1.1 mrg struct ebus_attach_args *ea = aux;
159 1.1 mrg
160 1.1 mrg return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
161 1.1 mrg }
162 1.1 mrg
163 1.1 mrg void
164 1.15 cdi auxio_ebus_attach(struct device *parent, struct device *self, void *aux)
165 1.1 mrg {
166 1.1 mrg struct auxio_softc *sc = (struct auxio_softc *)self;
167 1.1 mrg struct ebus_attach_args *ea = aux;
168 1.1 mrg
169 1.5 eeh sc->sc_tag = ea->ea_bustag;
170 1.5 eeh
171 1.5 eeh if (ea->ea_nreg < 1) {
172 1.1 mrg printf(": no registers??\n");
173 1.1 mrg return;
174 1.1 mrg }
175 1.1 mrg
176 1.5 eeh if (ea->ea_nreg != 5) {
177 1.1 mrg printf(": not 5 (%d) registers, only setting led",
178 1.4 mrg ea->ea_nreg);
179 1.1 mrg sc->sc_flags = AUXIO_LEDONLY|AUXIO_EBUS;
180 1.5 eeh } else if (ea->ea_nvaddr == 5) {
181 1.5 eeh sc->sc_flags = AUXIO_EBUS;
182 1.5 eeh
183 1.5 eeh sparc_promaddr_to_handle(sc->sc_tag,
184 1.5 eeh ea->ea_vaddr[1], &sc->sc_pci);
185 1.5 eeh sparc_promaddr_to_handle(sc->sc_tag,
186 1.5 eeh ea->ea_vaddr[2], &sc->sc_freq);
187 1.5 eeh sparc_promaddr_to_handle(sc->sc_tag,
188 1.5 eeh ea->ea_vaddr[3], &sc->sc_scsi);
189 1.5 eeh sparc_promaddr_to_handle(sc->sc_tag,
190 1.5 eeh ea->ea_vaddr[4], &sc->sc_temp);
191 1.1 mrg } else {
192 1.1 mrg sc->sc_flags = AUXIO_EBUS;
193 1.5 eeh bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
194 1.5 eeh ea->ea_reg[1].size, 0, &sc->sc_pci);
195 1.5 eeh bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
196 1.5 eeh ea->ea_reg[2].size, 0, &sc->sc_freq);
197 1.5 eeh bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
198 1.5 eeh ea->ea_reg[3].size, 0, &sc->sc_scsi);
199 1.5 eeh bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
200 1.5 eeh ea->ea_reg[4].size, 0, &sc->sc_temp);
201 1.1 mrg }
202 1.5 eeh
203 1.5 eeh if (ea->ea_nvaddr > 0) {
204 1.5 eeh sparc_promaddr_to_handle(sc->sc_tag,
205 1.5 eeh ea->ea_vaddr[0], &sc->sc_led);
206 1.5 eeh } else {
207 1.5 eeh bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
208 1.5 eeh ea->ea_reg[0].size, 0, &sc->sc_led);
209 1.6 eeh }
210 1.1 mrg
211 1.2 mrg auxio_attach_common(sc);
212 1.1 mrg }
213 1.1 mrg
214 1.1 mrg int
215 1.15 cdi auxio_sbus_match(struct device *parent, struct cfdata *cf, void *aux)
216 1.1 mrg {
217 1.1 mrg struct sbus_attach_args *sa = aux;
218 1.1 mrg
219 1.1 mrg return (strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0);
220 1.1 mrg }
221 1.1 mrg
222 1.1 mrg void
223 1.15 cdi auxio_sbus_attach(struct device *parent, struct device *self, void *aux)
224 1.1 mrg {
225 1.1 mrg struct auxio_softc *sc = (struct auxio_softc *)self;
226 1.1 mrg struct sbus_attach_args *sa = aux;
227 1.1 mrg
228 1.5 eeh sc->sc_tag = sa->sa_bustag;
229 1.5 eeh
230 1.5 eeh if (sa->sa_nreg < 1) {
231 1.1 mrg printf(": no registers??\n");
232 1.1 mrg return;
233 1.1 mrg }
234 1.1 mrg
235 1.5 eeh if (sa->sa_nreg != 1) {
236 1.2 mrg printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
237 1.2 mrg sa->sa_npromvaddrs);
238 1.1 mrg return;
239 1.1 mrg }
240 1.1 mrg
241 1.1 mrg /* sbus auxio only has one set of registers */
242 1.1 mrg sc->sc_flags = AUXIO_LEDONLY|AUXIO_SBUS;
243 1.5 eeh if (sa->sa_npromvaddrs > 0) {
244 1.5 eeh sbus_promaddr_to_handle(sc->sc_tag,
245 1.5 eeh sa->sa_promvaddr, &sc->sc_led);
246 1.5 eeh } else {
247 1.5 eeh sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
248 1.5 eeh sa->sa_size, 0, &sc->sc_led);
249 1.5 eeh }
250 1.1 mrg
251 1.2 mrg auxio_attach_common(sc);
252 1.1 mrg }
253 1.16 jnemeth
254 1.16 jnemeth int
255 1.16 jnemeth auxio_fd_control(u_int32_t bits)
256 1.16 jnemeth {
257 1.16 jnemeth struct auxio_softc *sc;
258 1.16 jnemeth u_int32_t led;
259 1.16 jnemeth
260 1.16 jnemeth if (auxio_cd.cd_ndevs == 0) {
261 1.16 jnemeth return ENXIO;
262 1.16 jnemeth }
263 1.16 jnemeth
264 1.16 jnemeth /*
265 1.16 jnemeth * XXX This does not handle > 1 auxio correctly.
266 1.16 jnemeth * We'll assume the floppy drive is tied to first auxio found.
267 1.16 jnemeth */
268 1.16 jnemeth sc = (struct auxio_softc *)auxio_cd.cd_devs[0];
269 1.16 jnemeth if (sc->sc_flags & AUXIO_EBUS)
270 1.16 jnemeth led = le32toh(bus_space_read_4(sc->sc_tag, sc->sc_led, 0));
271 1.16 jnemeth else
272 1.16 jnemeth led = bus_space_read_1(sc->sc_tag, sc->sc_led, 0);
273 1.16 jnemeth
274 1.16 jnemeth led = (led & ~AUXIO_LED_FLOPPY_MASK) | bits;
275 1.16 jnemeth
276 1.16 jnemeth if (sc->sc_flags & AUXIO_EBUS)
277 1.16 jnemeth bus_space_write_4(sc->sc_tag, sc->sc_led, 0, htole32(led));
278 1.16 jnemeth else
279 1.16 jnemeth bus_space_write_1(sc->sc_tag, sc->sc_led, 0, led);
280 1.16 jnemeth
281 1.16 jnemeth return 0;
282 1.16 jnemeth }
283