sb_ofisa.c revision 1.8
1/*	$NetBSD: sb_ofisa.c,v 1.8 2002/09/27 20:39:35 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: sb_ofisa.c,v 1.8 2002/09/27 20:39:35 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/midi_if.h>
53#include <dev/mulaw.h>
54
55#include <dev/ofw/openfirm.h>
56#include <dev/isa/isavar.h>
57#include <dev/ofisa/ofisavar.h>
58
59#include <dev/isa/sbreg.h>
60#include <dev/isa/sbvar.h>
61#include <dev/isa/sbdspvar.h>
62
63int	sb_ofisa_match __P((struct device *, struct cfdata *, void *));
64void	sb_ofisa_attach __P((struct device *, struct device *, void *));
65
66const struct cfattach sb_ofisa_ca = {
67	sizeof(struct sbdsp_softc), sb_ofisa_match, sb_ofisa_attach
68};
69
70int
71sb_ofisa_match(parent, cf, aux)
72	struct device *parent;
73	struct cfdata *cf;
74	void *aux;
75{
76	struct ofisa_attach_args *aa = aux;
77	static const char *const compatible_strings[] = {
78		"pnpPNP,b000",			/* generic SB 1.5 */
79		"pnpPNP,b001",			/* generic SB 2.0 */
80		"pnpPNP,b002",			/* generic SB Pro */
81		"pnpPNP,b003",			/* generic SB 16 */
82		NULL,
83	};
84	int rv = 0;
85
86	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) {
87		/*
88		 * Use a low match priority so that a more specific driver
89		 * can match, e.g. a native ESS driver.
90		 */
91		rv = 1;
92	}
93
94	return (rv);
95}
96
97void
98sb_ofisa_attach(parent, self, aux)
99	struct device *parent, *self;
100	void *aux;
101{
102	struct sbdsp_softc *sc = (void *)self;
103	struct ofisa_attach_args *aa = aux;
104	struct ofisa_reg_desc reg;
105	struct ofisa_intr_desc intr;
106	struct ofisa_dma_desc dma[2];
107	int n, ndrq;
108	char *model;
109
110	/*
111	 * We're living on an OFW.  We have to ask the OFW what our
112	 * registers and interrupts properties look like.
113	 *
114	 * We expect:
115	 *
116	 *	1 i/o register region
117	 *	1 interrupt
118	 *	1 or 2 dma channels
119	 */
120
121	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
122	if (n != 1) {
123		printf(": error getting register data\n");
124		return;
125	}
126	if (reg.type != OFISA_REG_TYPE_IO) {
127		printf(": register type not i/o\n");
128		return;
129	}
130	if (reg.len != SB_NPORT && reg.len != SBP_NPORT) {
131		printf(": weird register size (%lu, expected %d or %d)\n",
132		    (unsigned long)reg.len, SB_NPORT, SBP_NPORT);
133		return;
134	}
135
136	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
137	if (n != 1) {
138		printf(": error getting interrupt data\n");
139		return;
140	}
141
142	ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
143	if (ndrq != 1 && ndrq != 2) {
144		printf(": error getting DMA data\n");
145		return;
146	}
147
148	sc->sc_ic = aa->ic;
149
150	sc->sc_iot = aa->iot;
151	if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
152		printf(": unable to map register space\n");
153		return;
154	}
155
156	/* XXX These are only for setting chip configuration registers. */
157	sc->sc_iobase = reg.addr;
158	sc->sc_irq = intr.irq;
159
160	sc->sc_drq8 = DRQUNK;
161	sc->sc_drq16 = DRQUNK;
162
163	for (n = 0; n < ndrq; n++) {
164		/* XXX check mode? */
165		switch (dma[n].width) {
166		case 8:
167			if (sc->sc_drq8 == DRQUNK)
168				sc->sc_drq8 = dma[n].drq;
169			break;
170		case 16:
171			if (sc->sc_drq16 == DRQUNK)
172				sc->sc_drq16 = dma[n].drq;
173			break;
174		default:
175			printf(": weird DMA width %d\n", dma[n].width);
176			return;
177		}
178	}
179
180	if (sc->sc_drq8 == DRQUNK) {
181		printf(": no 8-bit DMA channel\n");
182		return;
183	}
184
185	if (sbmatch(sc) == 0) {
186		printf(": sbmatch failed\n");
187		return;
188	}
189
190	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, IST_EDGE, IPL_AUDIO,
191	    sbdsp_intr, sc);
192
193	n = OF_getproplen(aa->oba.oba_phandle, "model");
194	if (n > 0) {
195		model = alloca(n);
196		if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n)
197			printf(": %s\n%s", model, sc->sc_dev.dv_xname);
198	}
199
200	sbattach(sc);
201}
202