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