xref: /netbsd-src/sys/arch/sparc64/dev/auxio.c (revision 3b01aba77a7a698587faaae455bbfe740923c1f5)
1 /*	$NetBSD: auxio.c,v 1.1 2000/04/15 03:08:13 mrg Exp $	*/
2 
3 /*
4  * Copyright (c) 2000 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  * 3. The name of the author may not be used to endorse or promote products
16  *    derived from this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  */
30 
31 /*
32  * AUXIO registers support on the sbus & ebus2.
33  */
34 
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/errno.h>
38 #include <sys/device.h>
39 #include <sys/malloc.h>
40 
41 #include <machine/autoconf.h>
42 #include <machine/cpu.h>
43 
44 #include <sparc64/dev/ebusreg.h>
45 #include <sparc64/dev/ebusvar.h>
46 #include <sparc64/dev/sbusvar.h>
47 #include <sparc64/dev/auxioreg.h>
48 #include <sparc64/dev/auxiovar.h>
49 
50 #define	AUXIO_ROM_NAME		"auxio"
51 
52 /*
53  * ebus code.
54  */
55 int	auxio_ebus_match __P((struct device *, struct cfdata *, void *));
56 void	auxio_ebus_attach __P((struct device *, struct device *, void *));
57 int	auxio_sbus_match __P((struct device *, struct cfdata *, void *));
58 void	auxio_sbus_attach __P((struct device *, struct device *, void *));
59 
60 struct cfattach auxio_ebus_ca = {
61 	sizeof(struct auxio_softc), auxio_ebus_match, auxio_ebus_attach
62 };
63 
64 struct cfattach auxio_sbus_ca = {
65 	sizeof(struct auxio_softc), auxio_sbus_match, auxio_sbus_attach
66 };
67 
68 int
69 auxio_ebus_match(parent, cf, aux)
70 	struct device *parent;
71 	struct cfdata *cf;
72 	void *aux;
73 {
74 	struct ebus_attach_args *ea = aux;
75 
76 	return (strcmp(AUXIO_ROM_NAME, ea->ea_name) == 0);
77 }
78 
79 void
80 auxio_ebus_attach(parent, self, aux)
81 	struct device *parent, *self;
82 	void *aux;
83 {
84 	struct auxio_softc *sc = (struct auxio_softc *)self;
85 	struct ebus_attach_args *ea = aux;
86 
87 	if (ea->ea_nregs < 1 || ea->ea_nvaddrs < 1) {
88 		printf(": no registers??\n");
89 		return;
90 	}
91 
92 	if (ea->ea_nregs != 5 || ea->ea_nvaddrs != 5) {
93 		printf(": not 5 (%d) registers, only setting led",
94 		    ea->ea_nregs);
95 		sc->sc_flags = AUXIO_LEDONLY|AUXIO_EBUS;
96 	} else {
97 		sc->sc_flags = AUXIO_EBUS;
98 		sc->sc_registers.auxio_pci = (u_int32_t *)(u_long)ea->ea_vaddrs[1];
99 		sc->sc_registers.auxio_freq = (u_int32_t *)(u_long)ea->ea_vaddrs[2];
100 		sc->sc_registers.auxio_scsi = (u_int32_t *)(u_long)ea->ea_vaddrs[3];
101 		sc->sc_registers.auxio_temp = (u_int32_t *)(u_long)ea->ea_vaddrs[4];
102 	}
103 	sc->sc_registers.auxio_led = (u_int32_t *)(u_long)ea->ea_vaddrs[0];
104 
105 	if (!auxio_reg)
106 		auxio_reg = (u_char *)(u_long)ea->ea_vaddrs[0];
107 
108 	printf("\n");
109 }
110 
111 int
112 auxio_sbus_match(parent, cf, aux)
113 	struct device *parent;
114 	struct cfdata *cf;
115 	void *aux;
116 {
117 	struct sbus_attach_args *sa = aux;
118 
119 	return (strcmp(AUXIO_ROM_NAME, sa->sa_name) == 0);
120 }
121 
122 void
123 auxio_sbus_attach(parent, self, aux)
124 	struct device *parent, *self;
125 	void *aux;
126 {
127 	struct auxio_softc *sc = (struct auxio_softc *)self;
128 	struct sbus_attach_args *sa = aux;
129 
130 	if (sa->sa_nreg < 1 || sa->sa_npromvaddrs < 1) {
131 		printf(": no registers??\n");
132 		return;
133 	}
134 
135 	if (sa->sa_nreg != 1 || sa->sa_npromvaddrs != 1) {
136 		printf(": not 1 (%d/%d) registers??", sa->sa_nreg, sa->sa_npromvaddrs);
137 		return;
138 	}
139 
140 	/* sbus auxio only has one set of registers */
141 	sc->sc_flags = AUXIO_LEDONLY|AUXIO_SBUS;
142 	sc->sc_registers.auxio_led = (u_int32_t *)(u_long)sa->sa_promvaddr;
143 
144 	if (!auxio_reg)
145 		auxio_reg = (u_char *)(u_long)sa->sa_promvaddr;
146 
147 	printf("\n");
148 }
149 
150 /*
151  * old interface; used by fd driver for now
152  */
153 unsigned int
154 auxregbisc(bis, bic)
155 	int bis, bic;
156 {
157 	register int v, s = splhigh();
158 
159 	v = *auxio_reg;
160 	*auxio_reg = ((v | bis) & ~bic) | AUXIO_LED_MB1;
161 	splx(s);
162 	return v;
163 }
164