xref: /netbsd-src/sys/arch/sparc64/dev/auxio_ebus.c (revision 82d56013d7b633d116a93943de88e08335357a7c)
1 /*	$NetBSD: auxio_ebus.c,v 1.6 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_ebus.c,v 1.6 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_ebus_match(device_t, cfdata_t, void *);
57 static void	auxio_ebus_attach(device_t, device_t, void *);
58 
59 CFATTACH_DECL_NEW(auxio_ebus, sizeof(struct auxio_softc),
60     auxio_ebus_match, auxio_ebus_attach, NULL, NULL);
61 
62 static int
63 auxio_ebus_match(device_t parent, cfdata_t cf, void *aux)
64 {
65 	struct ebus_attach_args *ea = aux;
66 
67 	return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
68 }
69 
70 static void
71 auxio_ebus_attach(device_t parent, device_t self, void *aux)
72 {
73 	struct auxio_softc *sc = device_private(self);
74 	struct ebus_attach_args *ea = aux;
75 
76 	sc->sc_dev = self;
77 	sc->sc_tag = ea->ea_bustag;
78 
79 	if (ea->ea_nreg < 1) {
80 		printf(": no registers??\n");
81 		return;
82 	}
83 
84 	sc->sc_flags = AUXIO_EBUS;
85 	if (ea->ea_nreg != 5) {
86 		printf(": not 5 (%d) registers, only setting led",
87 		    ea->ea_nreg);
88 		sc->sc_flags |= AUXIO_LEDONLY;
89 	} else if (ea->ea_nvaddr == 5) {
90 		sparc_promaddr_to_handle(sc->sc_tag,
91 			ea->ea_vaddr[1], &sc->sc_pci);
92 		sparc_promaddr_to_handle(sc->sc_tag,
93 			ea->ea_vaddr[2], &sc->sc_freq);
94 		sparc_promaddr_to_handle(sc->sc_tag,
95 			ea->ea_vaddr[3], &sc->sc_scsi);
96 		sparc_promaddr_to_handle(sc->sc_tag,
97 			ea->ea_vaddr[4], &sc->sc_temp);
98 	} else {
99 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[1]),
100 			ea->ea_reg[1].size, 0, &sc->sc_pci);
101 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[2]),
102 			ea->ea_reg[2].size, 0, &sc->sc_freq);
103 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[3]),
104 			ea->ea_reg[3].size, 0, &sc->sc_scsi);
105 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[4]),
106 			ea->ea_reg[4].size, 0, &sc->sc_temp);
107 	}
108 
109 	if (ea->ea_nvaddr > 0) {
110 		sparc_promaddr_to_handle(sc->sc_tag,
111 			ea->ea_vaddr[0], &sc->sc_led);
112 	} else {
113 		bus_space_map(sc->sc_tag, EBUS_ADDR_FROM_REG(&ea->ea_reg[0]),
114 			ea->ea_reg[0].size, 0, &sc->sc_led);
115 	}
116 
117 	auxio_attach_common(sc);
118 }
119