Home | History | Annotate | Line # | Download | only in isa
midi_pcppi.c revision 1.3
      1 /*	$NetBSD: midi_pcppi.c,v 1.3 1998/08/17 21:16:14 augustss Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1998 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * Author: Lennart Augustsson
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. All advertising materials mentioning features or use of this software
     18  *    must display the following acknowledgement:
     19  *        This product includes software developed by the NetBSD
     20  *        Foundation, Inc. and its contributors.
     21  * 4. Neither the name of The NetBSD Foundation nor the names of its
     22  *    contributors may be used to endorse or promote products derived
     23  *    from this software without specific prior written permission.
     24  *
     25  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     26  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     29  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  * POSSIBILITY OF SUCH DAMAGE.
     36  */
     37 
     38 #include <sys/param.h>
     39 #include <sys/systm.h>
     40 #include <sys/kernel.h>
     41 #include <sys/errno.h>
     42 #include <sys/device.h>
     43 #include <sys/malloc.h>
     44 #include <sys/proc.h>
     45 #include <sys/conf.h>
     46 #include <sys/select.h>
     47 #include <sys/audioio.h>
     48 #include <sys/midiio.h>
     49 
     50 #include <dev/isa/pcppivar.h>
     51 
     52 #include <dev/audio_if.h>
     53 #include <dev/midi_if.h>
     54 #include <dev/midivar.h>
     55 #include <dev/midisynvar.h>
     56 
     57 #define MAX_DURATION 30		/* turn off sound automagically after 30 s */
     58 
     59 struct midi_pcppi_softc {
     60 	struct midi_softc sc_mididev;
     61 	midisyn sc_midisyn;
     62 };
     63 
     64 int	midi_pcppi_match __P((struct device *, struct cfdata *, void *));
     65 void	midi_pcppi_attach __P((struct device *, struct device *, void *));
     66 
     67 void	midi_pcppi_on    __P((midisyn *, u_int32_t, u_int32_t, u_int32_t));
     68 void	midi_pcppi_off   __P((midisyn *, u_int32_t, u_int32_t, u_int32_t));
     69 void	midi_pcppi_close __P((midisyn *));
     70 
     71 struct cfattach midi_pcppi_ca = {
     72 	sizeof(struct midi_pcppi_softc), midi_pcppi_match, midi_pcppi_attach
     73 };
     74 
     75 struct midisyn_methods midi_pcppi_hw = {
     76 	0,			/* open */
     77 	midi_pcppi_close,
     78 	0,			/* ioctl */
     79 	0,			/* allocv */
     80 	midi_pcppi_on,
     81 	midi_pcppi_off,
     82 	0,
     83 	0,
     84 	0,
     85 	0,
     86 	0,
     87 	0,
     88 };
     89 
     90 int midi_pcppi_attached = 0;	/* Not very nice */
     91 
     92 int
     93 midi_pcppi_match(parent, match, aux)
     94 	struct device *parent;
     95 	struct cfdata *match;
     96 	void *aux;
     97 {
     98 	return (!midi_pcppi_attached);
     99 }
    100 
    101 void
    102 midi_pcppi_attach(parent, self, aux)
    103 	struct device *parent;
    104 	struct device *self;
    105 	void *aux;
    106 {
    107 	struct midi_pcppi_softc *sc = (struct midi_pcppi_softc *)self;
    108 	struct pcppi_attach_args *pa = (struct pcppi_attach_args *)aux;
    109 	midisyn *ms;
    110 
    111 	ms = &sc->sc_midisyn;
    112 	ms->mets = &midi_pcppi_hw;
    113 	strcpy(ms->name, "PC speaker");
    114 	ms->nvoice = 1;
    115 	ms->flags = MS_DOALLOC | MS_FREQXLATE;
    116 	ms->data = pa->pa_cookie;
    117 
    118 	midi_pcppi_attached++;
    119 
    120 	midisyn_attach(&sc->sc_mididev, ms);
    121 	midi_attach(&sc->sc_mididev, parent);
    122 }
    123 
    124 void
    125 midi_pcppi_on(ms, chan, note, vel)
    126 	midisyn *ms;
    127 	u_int32_t chan, note, vel;
    128 {
    129 	pcppi_tag_t t = ms->data;
    130 
    131 	/*printf("ON  %p %d\n", t, MIDISYN_FREQ_TO_HZ(note));*/
    132 	pcppi_bell(t, MIDISYN_FREQ_TO_HZ(note), MAX_DURATION * hz, 0);
    133 }
    134 
    135 void
    136 midi_pcppi_off(ms, chan, note, vel)
    137 	midisyn *ms;
    138 	u_int32_t chan, note, vel;
    139 {
    140 	pcppi_tag_t t = ms->data;
    141 
    142 	/*printf("OFF %p %d\n", t, note >> 16);*/
    143 	pcppi_bell(t, 0, 0, 0);
    144 }
    145 
    146 void
    147 midi_pcppi_close(ms)
    148 	midisyn *ms;
    149 {
    150 	pcppi_tag_t t = ms->data;
    151 
    152 	/* Make sure we are quiet. */
    153 	pcppi_bell(t, 0, 0, 0);
    154 }
    155