xref: /netbsd/sys/dev/ofisa/ess_ofisa.c (revision c4a72b64)
1 /*	$NetBSD: ess_ofisa.c,v 1.11 2002/10/02 16:34:28 thorpej Exp $	*/
2 
3 /*-
4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9  * NASA Ames Research Center.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. All advertising materials mentioning features or use of this software
20  *    must display the following acknowledgement:
21  *	This product includes software developed by the NetBSD
22  *	Foundation, Inc. and its contributors.
23  * 4. Neither the name of The NetBSD Foundation nor the names of its
24  *    contributors may be used to endorse or promote products derived
25  *    from this software without specific prior written permission.
26  *
27  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37  * POSSIBILITY OF SUCH DAMAGE.
38  */
39 
40 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: ess_ofisa.c,v 1.11 2002/10/02 16:34:28 thorpej Exp $");
42 
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 
47 #include <machine/bus.h>
48 #include <machine/intr.h>
49 
50 #include <sys/audioio.h>
51 #include <dev/audio_if.h>
52 #include <dev/mulaw.h>
53 
54 #include <dev/ofw/openfirm.h>
55 #include <dev/isa/isavar.h>
56 #include <dev/ofisa/ofisavar.h>
57 
58 #include <dev/isa/essreg.h>
59 #include <dev/isa/essvar.h>
60 
61 int	ess_ofisa_match __P((struct device *, struct cfdata *, void *));
62 void	ess_ofisa_attach __P((struct device *, struct device *, void *));
63 
64 CFATTACH_DECL(ess_ofisa, sizeof(struct ess_softc),
65     ess_ofisa_match, ess_ofisa_attach, NULL, NULL);
66 
67 int
68 ess_ofisa_match(parent, cf, aux)
69 	struct device *parent;
70 	struct cfdata *cf;
71 	void *aux;
72 {
73 	struct ofisa_attach_args *aa = aux;
74 	static const char *const compatible_strings[] = {
75 		"ESST,es1887-codec",		/* ESS 1887 */
76 		"ESST,es1888-codec",		/* ESS 1888 */
77 		"ESST,es888-codec",		/* ESS 888 */
78 		NULL,
79 	};
80 	int rv = 0;
81 
82 	/* XXX table */
83 	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) {
84 		rv = 10;
85 	}
86 
87 	return (rv);
88 }
89 
90 void
91 ess_ofisa_attach(parent, self, aux)
92 	struct device *parent, *self;
93 	void *aux;
94 {
95 	struct ess_softc *sc = (void *)self;
96 	struct ofisa_attach_args *aa = aux;
97 	struct ofisa_reg_desc reg;
98 	struct ofisa_intr_desc intr[2];
99 	struct ofisa_dma_desc dma[2];
100 	int n, ndrq;
101 	char *model;
102 
103 	/*
104 	 * We're living on an OFW.  We have to ask the OFW what our
105 	 * registers and interrupts properties look like.
106 	 *
107 	 * We expect:
108 	 *
109 	 *	1      i/o register region
110 	 *	1 or 2 interrupts
111 	 *	2      dma channels
112 	 */
113 
114 	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
115 	if (n != 1) {
116 		printf(": error getting register data\n");
117 		return;
118 	}
119 	if (reg.type != OFISA_REG_TYPE_IO) {
120 		printf(": register type not i/o\n");
121 		return;
122 	}
123 	if (reg.len != ESS_NPORT) {
124 		printf(": weird register size (%lu, expected %d)\n",
125 		    (unsigned long)reg.len, ESS_NPORT);
126 		return;
127 	}
128 
129 	n = ofisa_intr_get(aa->oba.oba_phandle, intr, 2);
130 	if (n == 1) {
131 		sc->sc_audio1.irq = intr[0].irq;
132 		sc->sc_audio1.ist = intr[0].share;
133 		sc->sc_audio2.irq = intr[0].irq;
134 		sc->sc_audio2.ist = intr[0].share;
135 	} else if (n == 2) {
136 		sc->sc_audio1.irq = intr[0].irq;
137 		sc->sc_audio1.ist = intr[0].share;
138 		sc->sc_audio2.irq = intr[1].irq;
139 		sc->sc_audio2.ist = intr[1].share;
140 	} else {
141 		printf(": error getting interrupt data\n");
142 		return;
143 	}
144 
145 	ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
146 	if (ndrq != 2) {
147 		printf(": error getting DMA data\n");
148 		return;
149 	}
150 	sc->sc_audio1.drq = dma[0].drq;
151 	sc->sc_audio2.drq = dma[1].drq;
152 
153 	sc->sc_ic = aa->ic;
154 
155 	sc->sc_iot = aa->iot;
156 	sc->sc_iobase = reg.addr;
157 	if (bus_space_map(sc->sc_iot, sc->sc_iobase, reg.len, 0,
158 	    &sc->sc_ioh)) {
159 		printf(": unable to map register space\n");
160 		return;
161 	}
162 
163 	/*
164 	 * The Shark firmware doesn't program the ESS ISA address registers.
165 	 * Do that here instead of inside essmatch() since we want to defer
166 	 * to the firmware on other platforms.
167 	 */
168 	if (ess_config_addr(sc))
169 		return;
170 	if (essmatch(sc) == 0) {
171 		printf(": essmatch failed\n");
172 		return;
173 	}
174 
175 	n = OF_getproplen(aa->oba.oba_phandle, "model");
176 	if (n > 0) {
177 		model = alloca(n);
178 		if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n)
179 			printf(": %s\n%s", model, sc->sc_dev.dv_xname);
180 	}
181 
182 	essattach(sc);
183 }
184