sb_ofisa.c revision 1.6
11.6Slukem/*	$NetBSD: sb_ofisa.c,v 1.6 2001/11/13 07:29:45 lukem Exp $	*/
21.1Sthorpej
31.1Sthorpej/*-
41.1Sthorpej * Copyright (c) 1998 The NetBSD Foundation, Inc.
51.1Sthorpej * All rights reserved.
61.1Sthorpej *
71.1Sthorpej * This code is derived from software contributed to The NetBSD Foundation
81.1Sthorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
91.1Sthorpej * NASA Ames Research Center.
101.1Sthorpej *
111.1Sthorpej * Redistribution and use in source and binary forms, with or without
121.1Sthorpej * modification, are permitted provided that the following conditions
131.1Sthorpej * are met:
141.1Sthorpej * 1. Redistributions of source code must retain the above copyright
151.1Sthorpej *    notice, this list of conditions and the following disclaimer.
161.1Sthorpej * 2. Redistributions in binary form must reproduce the above copyright
171.1Sthorpej *    notice, this list of conditions and the following disclaimer in the
181.1Sthorpej *    documentation and/or other materials provided with the distribution.
191.1Sthorpej * 3. All advertising materials mentioning features or use of this software
201.1Sthorpej *    must display the following acknowledgement:
211.1Sthorpej *	This product includes software developed by the NetBSD
221.1Sthorpej *	Foundation, Inc. and its contributors.
231.1Sthorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
241.1Sthorpej *    contributors may be used to endorse or promote products derived
251.1Sthorpej *    from this software without specific prior written permission.
261.1Sthorpej *
271.1Sthorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
281.1Sthorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
291.1Sthorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
301.1Sthorpej * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
311.1Sthorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
321.1Sthorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
331.1Sthorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
341.1Sthorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
351.1Sthorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
361.1Sthorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
371.1Sthorpej * POSSIBILITY OF SUCH DAMAGE.
381.1Sthorpej */
391.6Slukem
401.6Slukem#include <sys/cdefs.h>
411.6Slukem__KERNEL_RCSID(0, "$NetBSD: sb_ofisa.c,v 1.6 2001/11/13 07:29:45 lukem Exp $");
421.1Sthorpej
431.1Sthorpej#include <sys/param.h>
441.1Sthorpej#include <sys/systm.h>
451.1Sthorpej#include <sys/device.h>
461.1Sthorpej
471.1Sthorpej#include <machine/bus.h>
481.1Sthorpej#include <machine/intr.h>
491.1Sthorpej
501.1Sthorpej#include <sys/audioio.h>
511.1Sthorpej#include <dev/audio_if.h>
521.3Sthorpej#include <dev/midi_if.h>
531.1Sthorpej#include <dev/mulaw.h>
541.1Sthorpej
551.1Sthorpej#include <dev/ofw/openfirm.h>
561.1Sthorpej#include <dev/isa/isavar.h>
571.1Sthorpej#include <dev/ofisa/ofisavar.h>
581.1Sthorpej
591.1Sthorpej#include <dev/isa/sbreg.h>
601.1Sthorpej#include <dev/isa/sbvar.h>
611.1Sthorpej#include <dev/isa/sbdspvar.h>
621.1Sthorpej
631.1Sthorpejint	sb_ofisa_match __P((struct device *, struct cfdata *, void *));
641.1Sthorpejvoid	sb_ofisa_attach __P((struct device *, struct device *, void *));
651.1Sthorpej
661.1Sthorpejstruct cfattach sb_ofisa_ca = {
671.1Sthorpej	sizeof(struct sbdsp_softc), sb_ofisa_match, sb_ofisa_attach
681.1Sthorpej};
691.1Sthorpej
701.1Sthorpejint
711.1Sthorpejsb_ofisa_match(parent, cf, aux)
721.1Sthorpej	struct device *parent;
731.1Sthorpej	struct cfdata *cf;
741.1Sthorpej	void *aux;
751.1Sthorpej{
761.1Sthorpej	struct ofisa_attach_args *aa = aux;
771.1Sthorpej	const char *compatible_strings[] = {
781.1Sthorpej		"pnpPNP,b000",			/* generic SB 1.5 */
791.1Sthorpej		"pnpPNP,b001",			/* generic SB 2.0 */
801.1Sthorpej		"pnpPNP,b002",			/* generic SB Pro */
811.1Sthorpej		"pnpPNP,b003",			/* generic SB 16 */
821.1Sthorpej		NULL,
831.1Sthorpej	};
841.1Sthorpej	int rv = 0;
851.1Sthorpej
861.1Sthorpej	if (of_compatible(aa->oba.oba_phandle, compatible_strings) != -1) {
871.1Sthorpej		/*
881.1Sthorpej		 * Use a low match priority so that a more specific driver
891.1Sthorpej		 * can match, e.g. a native ESS driver.
901.1Sthorpej		 */
911.1Sthorpej		rv = 1;
921.1Sthorpej	}
931.1Sthorpej
941.1Sthorpej	return (rv);
951.1Sthorpej}
961.1Sthorpej
971.1Sthorpejvoid
981.1Sthorpejsb_ofisa_attach(parent, self, aux)
991.1Sthorpej	struct device *parent, *self;
1001.1Sthorpej	void *aux;
1011.1Sthorpej{
1021.1Sthorpej	struct sbdsp_softc *sc = (void *)self;
1031.1Sthorpej	struct ofisa_attach_args *aa = aux;
1041.1Sthorpej	struct ofisa_reg_desc reg;
1051.1Sthorpej	struct ofisa_intr_desc intr;
1061.1Sthorpej	struct ofisa_dma_desc dma[2];
1071.1Sthorpej	int n, ndrq;
1081.2Sthorpej	char *model;
1091.1Sthorpej
1101.1Sthorpej	/*
1111.1Sthorpej	 * We're living on an OFW.  We have to ask the OFW what our
1121.1Sthorpej	 * registers and interrupts properties look like.
1131.1Sthorpej	 *
1141.1Sthorpej	 * We expect:
1151.1Sthorpej	 *
1161.1Sthorpej	 *	1 i/o register region
1171.1Sthorpej	 *	1 interrupt
1181.1Sthorpej	 *	1 or 2 dma channels
1191.1Sthorpej	 */
1201.1Sthorpej
1211.1Sthorpej	n = ofisa_reg_get(aa->oba.oba_phandle, &reg, 1);
1221.1Sthorpej	if (n != 1) {
1231.1Sthorpej		printf(": error getting register data\n");
1241.1Sthorpej		return;
1251.1Sthorpej	}
1261.1Sthorpej	if (reg.type != OFISA_REG_TYPE_IO) {
1271.1Sthorpej		printf(": register type not i/o\n");
1281.1Sthorpej		return;
1291.1Sthorpej	}
1301.1Sthorpej	if (reg.len != SB_NPORT && reg.len != SBP_NPORT) {
1311.1Sthorpej		printf(": weird register size (%lu, expected %d or %d)\n",
1321.1Sthorpej		    (unsigned long)reg.len, SB_NPORT, SBP_NPORT);
1331.1Sthorpej		return;
1341.1Sthorpej	}
1351.1Sthorpej
1361.1Sthorpej	n = ofisa_intr_get(aa->oba.oba_phandle, &intr, 1);
1371.1Sthorpej	if (n != 1) {
1381.1Sthorpej		printf(": error getting interrupt data\n");
1391.1Sthorpej		return;
1401.1Sthorpej	}
1411.1Sthorpej
1421.1Sthorpej	ndrq = ofisa_dma_get(aa->oba.oba_phandle, dma, 2);
1431.1Sthorpej	if (ndrq != 1 && ndrq != 2) {
1441.1Sthorpej		printf(": error getting DMA data\n");
1451.1Sthorpej		return;
1461.1Sthorpej	}
1471.1Sthorpej
1481.1Sthorpej	sc->sc_ic = aa->ic;
1491.1Sthorpej
1501.1Sthorpej	sc->sc_iot = aa->iot;
1511.4Smycroft	if (bus_space_map(sc->sc_iot, reg.addr, reg.len, 0, &sc->sc_ioh)) {
1521.1Sthorpej		printf(": unable to map register space\n");
1531.1Sthorpej		return;
1541.1Sthorpej	}
1551.1Sthorpej
1561.4Smycroft	/* XXX These are only for setting chip configuration registers. */
1571.4Smycroft	sc->sc_iobase = reg.addr;
1581.1Sthorpej	sc->sc_irq = intr.irq;
1591.1Sthorpej
1601.1Sthorpej	sc->sc_drq8 = DRQUNK;
1611.1Sthorpej	sc->sc_drq16 = DRQUNK;
1621.1Sthorpej
1631.1Sthorpej	for (n = 0; n < ndrq; n++) {
1641.1Sthorpej		/* XXX check mode? */
1651.1Sthorpej		switch (dma[n].width) {
1661.1Sthorpej		case 8:
1671.1Sthorpej			if (sc->sc_drq8 == DRQUNK)
1681.1Sthorpej				sc->sc_drq8 = dma[n].drq;
1691.1Sthorpej			break;
1701.1Sthorpej		case 16:
1711.1Sthorpej			if (sc->sc_drq16 == DRQUNK)
1721.1Sthorpej				sc->sc_drq16 = dma[n].drq;
1731.1Sthorpej			break;
1741.1Sthorpej		default:
1751.1Sthorpej			printf(": weird DMA width %d\n", dma[n].width);
1761.1Sthorpej			return;
1771.1Sthorpej		}
1781.1Sthorpej	}
1791.1Sthorpej
1801.1Sthorpej	if (sc->sc_drq8 == DRQUNK) {
1811.1Sthorpej		printf(": no 8-bit DMA channel\n");
1821.1Sthorpej		return;
1831.1Sthorpej	}
1841.1Sthorpej
1851.1Sthorpej	if (sbmatch(sc) == 0) {
1861.1Sthorpej		printf(": sbmatch failed\n");
1871.1Sthorpej		return;
1881.1Sthorpej	}
1891.4Smycroft
1901.5Sthorpej	sc->sc_ih = isa_intr_establish(aa->ic, intr.irq, IST_EDGE, IPL_AUDIO,
1911.4Smycroft	    sbdsp_intr, sc);
1921.1Sthorpej
1931.2Sthorpej	n = OF_getproplen(aa->oba.oba_phandle, "model");
1941.2Sthorpej	if (n > 0) {
1951.2Sthorpej		model = alloca(n);
1961.2Sthorpej		if (OF_getprop(aa->oba.oba_phandle, "model", model, n) == n)
1971.2Sthorpej			printf(": %s\n%s", model, sc->sc_dev.dv_xname);
1981.2Sthorpej	}
1991.1Sthorpej
2001.1Sthorpej	sbattach(sc);
2011.1Sthorpej}
202