Home | History | Annotate | Line # | Download | only in pnpbios
ym_pnpbios.c revision 1.2
      1 /* $NetBSD: ym_pnpbios.c,v 1.2 1999/11/14 02:15:51 thorpej Exp $ */
      2 /*
      3  * Copyright (c) 1999
      4  *	Matthias Drochner.  All rights reserved.
      5  *	Soren S. Jorvang.  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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #include "mpu_ym.h"
     30 
     31 #include <sys/param.h>
     32 #include <sys/systm.h>
     33 #include <sys/errno.h>
     34 #include <sys/ioctl.h>
     35 #include <sys/syslog.h>
     36 #include <sys/device.h>
     37 #include <sys/proc.h>
     38 
     39 #include <machine/bus.h>
     40 
     41 #include <sys/audioio.h>
     42 #include <dev/audio_if.h>
     43 #include <dev/midi_if.h>
     44 #include <dev/mulaw.h>
     45 
     46 #include <dev/isa/isavar.h>
     47 #include <dev/isa/isadmavar.h>
     48 
     49 #include <i386/pnpbios/pnpbiosvar.h>
     50 
     51 #include <dev/ic/ad1848reg.h>
     52 #include <dev/isa/ad1848var.h>
     53 
     54 #include <dev/ic/cs4231reg.h>
     55 #include <dev/isa/cs4231var.h>
     56 
     57 #include <dev/ic/opl3sa3reg.h>
     58 #include <dev/isa/wssreg.h>
     59 #include <dev/isa/ymvar.h>
     60 
     61 int ym_pnpbios_match __P((struct device *, struct cfdata *, void *));
     62 void ym_pnpbios_attach __P((struct device *, struct device *, void *));
     63 
     64 struct cfattach ym_pnpbios_ca = {
     65 	sizeof(struct ym_softc), ym_pnpbios_match, ym_pnpbios_attach
     66 };
     67 
     68 int
     69 ym_pnpbios_match(parent, match, aux)
     70 	struct device *parent;
     71 	struct cfdata *match;
     72 	void *aux;
     73 {
     74 	struct pnpbiosdev_attach_args *aa = aux;
     75 
     76 	if (strcmp(aa->idstr, "YMH0021"))
     77 		return 0;
     78 
     79 	return 1;
     80 }
     81 
     82 void
     83 ym_pnpbios_attach(parent, self, aux)
     84 	struct device *parent, *self;
     85 	void *aux;
     86 {
     87 	struct ym_softc *sc = (void *)self;
     88 	struct ad1848_softc *ac = &sc->sc_ad1848.sc_ad1848;
     89 	struct pnpbiosdev_attach_args *aa = aux;
     90 
     91 	if (pnpbios_io_map(aa->pbt, aa->resc, 0,
     92 				&sc->sc_iot, &sc->sc_sb_ioh) != 0) {
     93 		printf(": can't map sb i/o space\n");
     94 		return;
     95 	}
     96 	if (pnpbios_io_map(aa->pbt, aa->resc, 1,
     97 				&sc->sc_iot, &sc->sc_ioh) != 0) {
     98 		printf(": can't map sb i/o space\n");
     99 		return;
    100 	}
    101 	if (pnpbios_io_map(aa->pbt, aa->resc, 2,
    102 				&sc->sc_iot, &sc->sc_opl_ioh) != 0) {
    103 		printf(": can't map opl i/o space\n");
    104 		return;
    105 	}
    106 #if NMPU_YM > 0
    107 	if (pnpbios_io_map(aa->pbt, aa->resc, 3,
    108 				&sc->sc_iot, &sc->sc_mpu_ioh) != 0) {
    109 		printf(": can't map mpu i/o space\n");
    110 		return;
    111 	}
    112 #endif
    113 	if (pnpbios_io_map(aa->pbt, aa->resc, 4,
    114 				&sc->sc_iot, &sc->sc_controlioh) != 0) {
    115 		printf(": can't map control i/o space\n");
    116 		return;
    117 	}
    118 
    119 	sc->sc_ic = aa->ic;
    120 
    121 	if (pnpbios_getirqnum(aa->pbt, aa->resc, 0, &sc->ym_irq)) {
    122 		printf(": can't get IRQ\n");
    123 		return;
    124 	}
    125 
    126 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 0, &sc->ym_playdrq)) {
    127 		printf(": can't get DMA channel\n");
    128 		return;
    129 	}
    130 	if (pnpbios_getdmachan(aa->pbt, aa->resc, 1, &sc->ym_recdrq))
    131 		sc->ym_recdrq = -1;
    132 
    133 	printf("\n");
    134 	pnpbios_print_devres(self, aa);
    135 
    136 	printf("%s", self->dv_xname);
    137 
    138 	ac->sc_iot = sc->sc_iot;
    139 	if (bus_space_subregion(sc->sc_iot, sc->sc_ioh, WSS_CODEC, AD1848_NPORT,
    140 	    &ac->sc_ioh)) {
    141 		printf("%s: bus_space_subregion failed\n", self->dv_xname);
    142 		return;
    143 	}
    144 	ac->mode = 2;
    145 	ac->MCE_bit = MODE_CHANGE_ENABLE;
    146 	ac->chip_name = "OPL3-SA3";
    147 
    148 	sc->sc_ad1848.sc_ic  = sc->sc_ic;
    149 
    150 	ym_attach(sc);
    151 }
    152