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