Home | History | Annotate | Line # | Download | only in isapnp
mpu_isapnp.c revision 1.17.38.1
      1  1.17.38.1      yamt /*	$NetBSD: mpu_isapnp.c,v 1.17.38.1 2012/04/17 00:07:40 yamt Exp $	*/
      2        1.5     lukem 
      3        1.5     lukem #include <sys/cdefs.h>
      4  1.17.38.1      yamt __KERNEL_RCSID(0, "$NetBSD: mpu_isapnp.c,v 1.17.38.1 2012/04/17 00:07:40 yamt Exp $");
      5        1.5     lukem 
      6        1.1   mycroft #include "midi.h"
      7        1.1   mycroft 
      8        1.1   mycroft #include <sys/param.h>
      9        1.1   mycroft #include <sys/systm.h>
     10        1.1   mycroft #include <sys/errno.h>
     11        1.1   mycroft #include <sys/ioctl.h>
     12        1.1   mycroft #include <sys/syslog.h>
     13        1.1   mycroft #include <sys/device.h>
     14        1.1   mycroft #include <sys/proc.h>
     15       1.16        ad #include <sys/bus.h>
     16        1.1   mycroft #include <sys/audioio.h>
     17  1.17.38.1      yamt 
     18        1.1   mycroft #include <dev/audio_if.h>
     19        1.1   mycroft #include <dev/midi_if.h>
     20        1.1   mycroft #include <dev/mulaw.h>
     21        1.1   mycroft 
     22        1.1   mycroft #include <dev/isa/isavar.h>
     23        1.1   mycroft #include <dev/isa/isadmavar.h>
     24        1.1   mycroft 
     25        1.1   mycroft #include <dev/isapnp/isapnpreg.h>
     26        1.1   mycroft #include <dev/isapnp/isapnpvar.h>
     27        1.1   mycroft #include <dev/isapnp/isapnpdevs.h>
     28        1.1   mycroft 
     29        1.4  augustss #include <dev/ic/mpuvar.h>
     30        1.1   mycroft 
     31       1.17   xtraeme static int	mpu_isapnp_match(device_t, cfdata_t, void *);
     32       1.17   xtraeme static void	mpu_isapnp_attach(device_t, device_t, void *);
     33        1.1   mycroft 
     34        1.1   mycroft struct mpu_isapnp_softc {
     35        1.1   mycroft 	void *sc_ih;
     36  1.17.38.1      yamt 	kmutex_t sc_lock;
     37        1.1   mycroft 
     38        1.1   mycroft 	struct mpu_softc sc_mpu;
     39        1.1   mycroft };
     40        1.1   mycroft 
     41       1.17   xtraeme CFATTACH_DECL_NEW(mpu_isapnp, sizeof(struct mpu_isapnp_softc),
     42        1.8   thorpej     mpu_isapnp_match, mpu_isapnp_attach, NULL, NULL);
     43        1.1   mycroft 
     44       1.17   xtraeme static int
     45       1.17   xtraeme mpu_isapnp_match(device_t parent, cfdata_t match, void *aux)
     46        1.1   mycroft {
     47        1.3   mycroft 	int pri, variant;
     48        1.2   mycroft 
     49        1.3   mycroft 	pri = isapnp_devmatch(aux, &isapnp_mpu_devinfo, &variant);
     50        1.3   mycroft 	if (pri && variant > 0)
     51        1.3   mycroft 		pri = 0;
     52       1.17   xtraeme 	return pri;
     53        1.1   mycroft }
     54        1.1   mycroft 
     55       1.17   xtraeme static void
     56       1.17   xtraeme mpu_isapnp_attach(device_t parent, device_t self, void *aux)
     57        1.1   mycroft {
     58       1.12   thorpej 	struct mpu_isapnp_softc *sc = device_private(self);
     59        1.1   mycroft 	struct isapnp_attach_args *ipa = aux;
     60        1.1   mycroft 
     61       1.17   xtraeme 	aprint_normal("\n");
     62        1.1   mycroft 
     63        1.1   mycroft 	if (isapnp_config(ipa->ipa_iot, ipa->ipa_memt, ipa)) {
     64       1.17   xtraeme 		aprint_error_dev(self, "error in region allocation\n");
     65        1.1   mycroft 		return;
     66        1.1   mycroft 	}
     67        1.1   mycroft 
     68  1.17.38.1      yamt 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_AUDIO);
     69  1.17.38.1      yamt 
     70        1.1   mycroft 	sc->sc_mpu.iot = ipa->ipa_iot;
     71        1.1   mycroft 	sc->sc_mpu.ioh = ipa->ipa_io[0].h;
     72  1.17.38.1      yamt 	sc->sc_mpu.lock = &sc->sc_lock;
     73  1.17.38.1      yamt 
     74  1.17.38.1      yamt 	mutex_enter(&sc->sc_lock);
     75        1.1   mycroft 
     76        1.1   mycroft 	if (!mpu_find(&sc->sc_mpu)) {
     77       1.17   xtraeme 		aprint_error_dev(self, "find failed\n");
     78  1.17.38.1      yamt 		mutex_exit(&sc->sc_lock);
     79  1.17.38.1      yamt 		mutex_destroy(&sc->sc_lock);
     80        1.1   mycroft 		return;
     81        1.1   mycroft 	}
     82        1.1   mycroft 
     83  1.17.38.1      yamt 	mutex_exit(&sc->sc_lock);
     84  1.17.38.1      yamt 
     85       1.17   xtraeme 	aprint_normal_dev(self, "%s %s\n", ipa->ipa_devident,
     86        1.1   mycroft 	       ipa->ipa_devclass);
     87        1.1   mycroft 
     88       1.13  christos 	sc->sc_mpu.model = "Roland MPU-401 MIDI UART";
     89       1.13  christos 
     90       1.17   xtraeme 	midi_attach_mi(&mpu_midi_hw_if, &sc->sc_mpu, self);
     91        1.1   mycroft 
     92        1.1   mycroft 	sc->sc_ih = isa_intr_establish(ipa->ipa_ic, ipa->ipa_irq[0].num,
     93        1.1   mycroft 	    ipa->ipa_irq[0].type, IPL_AUDIO, mpu_intr, &sc->sc_mpu);
     94        1.1   mycroft }
     95