1 /* $NetBSD: auxio_sbus.c,v 1.2 2023/12/20 05:33:58 thorpej 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.2 2023/12/20 05:33:58 thorpej 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
46 #include <machine/autoconf.h>
47 #include <machine/cpu.h>
48
49 #include <dev/ebus/ebusreg.h>
50 #include <dev/ebus/ebusvar.h>
51 #include <dev/sbus/sbusvar.h>
52 #include <sparc64/dev/auxioreg.h>
53 #include <sparc64/dev/auxiovar.h>
54
55 static int auxio_sbus_match(device_t, cfdata_t, void *);
56 static void auxio_sbus_attach(device_t, device_t, void *);
57
58 CFATTACH_DECL_NEW(auxio_sbus, sizeof(struct auxio_softc),
59 auxio_sbus_match, auxio_sbus_attach, NULL, NULL);
60
61 static int
auxio_sbus_match(device_t parent,cfdata_t cf,void * aux)62 auxio_sbus_match(device_t parent, cfdata_t cf, void *aux)
63 {
64 struct sbus_attach_args *sa = aux;
65
66 return strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0;
67 }
68
69 static void
auxio_sbus_attach(device_t parent,device_t self,void * aux)70 auxio_sbus_attach(device_t parent, device_t self, void *aux)
71 {
72 struct auxio_softc *sc = device_private(self);
73 struct sbus_attach_args *sa = aux;
74
75 sc->sc_dev = self;
76 sc->sc_tag = sa->sa_bustag;
77
78 if (sa->sa_nreg < 1) {
79 printf(": no registers??\n");
80 return;
81 }
82
83 if (sa->sa_nreg != 1) {
84 printf(": not 1 (%d/%d) registers??", sa->sa_nreg,
85 sa->sa_npromvaddrs);
86 return;
87 }
88
89 /* sbus auxio only has one set of registers */
90 sc->sc_flags = AUXIO_LEDONLY;
91 if (sa->sa_npromvaddrs > 0) {
92 sbus_promaddr_to_handle(sc->sc_tag,
93 sa->sa_promvaddr, &sc->sc_led);
94 } else {
95 sbus_bus_map(sc->sc_tag, sa->sa_slot, sa->sa_offset,
96 sa->sa_size, 0, &sc->sc_led);
97 }
98
99 auxio_attach_common(sc);
100 }
101