auxio_sbus.c revision 1.1 1 /* $NetBSD: auxio_sbus.c,v 1.1 2015/10/06 16:40:36 martin Exp $ */
2
3 /*
4 * Copyright (c) 2000, 2001, 2015 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 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 /*
30 * AUXIO registers support on the sbus & ebus2, used for the floppy driver
31 * and to control the system LED, for the BLINK option.
32 */
33
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: auxio_sbus.c,v 1.1 2015/10/06 16:40:36 martin Exp $");
36
37 #include "opt_auxio.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/kernel.h>
42 #include <sys/callout.h>
43 #include <sys/errno.h>
44 #include <sys/device.h>
45 #include <sys/malloc.h>
46
47 #include <machine/autoconf.h>
48 #include <machine/cpu.h>
49
50 #include <dev/ebus/ebusreg.h>
51 #include <dev/ebus/ebusvar.h>
52 #include <dev/sbus/sbusvar.h>
53 #include <sparc64/dev/auxioreg.h>
54 #include <sparc64/dev/auxiovar.h>
55
56 static int auxio_sbus_match(device_t, cfdata_t, void *);
57 static void auxio_sbus_attach(device_t, device_t, void *);
58
59 CFATTACH_DECL_NEW(auxio_sbus, sizeof(struct auxio_softc),
60 auxio_sbus_match, auxio_sbus_attach, NULL, NULL);
61
62 static int
63 auxio_sbus_match(device_t parent, cfdata_t cf, void *aux)
64 {
65 struct sbus_attach_args *sa = aux;
66
67 return strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0;
68 }
69
70 static void
71 auxio_sbus_attach(device_t parent, device_t self, void *aux)
72 {
73 struct auxio_softc *sc = device_private(self);
74 struct sbus_attach_args *sa = aux;
75
76 sc->sc_dev = self;
77 sc->sc_tag = sa->sa_bustag;
78
79 if (sa->sa_nreg < 1) {
80 printf(": no registers??\n");
81 return;
82 }
83
84 if (sa->sa_nreg != 1) {
85 printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
86 sa->sa_npromvaddrs);
87 return;
88 }
89
90 /* sbus auxio only has one set of registers */
91 sc->sc_flags = AUXIO_LEDONLY;
92 if (sa->sa_npromvaddrs > 0) {
93 sbus_promaddr_to_handle(sc->sc_tag,
94 sa->sa_promvaddr, &sc->sc_led);
95 } else {
96 sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
97 sa->sa_size, 0, &sc->sc_led);
98 }
99
100 auxio_attach_common(sc);
101 }
102