1 /* $NetBSD: midi_pcppi.c,v 1.12 2005/12/11 12:22:03 christos 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/cdefs.h> 40 __KERNEL_RCSID(0, "$NetBSD: midi_pcppi.c,v 1.12 2005/12/11 12:22:03 christos Exp $"); 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/kernel.h> 45 #include <sys/errno.h> 46 #include <sys/device.h> 47 #include <sys/malloc.h> 48 #include <sys/proc.h> 49 #include <sys/conf.h> 50 #include <sys/select.h> 51 #include <sys/audioio.h> 52 #include <sys/midiio.h> 53 54 #include <machine/bus.h> 55 56 #include <dev/isa/pcppivar.h> 57 58 #include <dev/audio_if.h> 59 #include <dev/midi_if.h> 60 #include <dev/midivar.h> 61 #include <dev/midisynvar.h> 62 63 #define MAX_DURATION 30 /* turn off sound automagically after 30 s */ 64 65 struct midi_pcppi_softc { 66 struct midi_softc sc_mididev; 67 midisyn sc_midisyn; 68 }; 69 70 int midi_pcppi_match(struct device *, struct cfdata *, void *); 71 void midi_pcppi_attach(struct device *, struct device *, void *); 72 73 void midi_pcppi_on (midisyn *, u_int32_t, u_int32_t, u_int32_t); 74 void midi_pcppi_off (midisyn *, u_int32_t, u_int32_t, u_int32_t); 75 void midi_pcppi_close(midisyn *); 76 77 CFATTACH_DECL(midi_pcppi, sizeof(struct midi_pcppi_softc), 78 midi_pcppi_match, midi_pcppi_attach, NULL, NULL); 79 80 struct midisyn_methods midi_pcppi_hw = { 81 0, /* open */ 82 midi_pcppi_close, 83 0, /* ioctl */ 84 0, /* allocv */ 85 midi_pcppi_on, 86 midi_pcppi_off, 87 0, 88 0, 89 0, 90 0, 91 0, 92 0, 93 }; 94 95 int midi_pcppi_attached = 0; /* Not very nice */ 96 97 int 98 midi_pcppi_match(parent, match, aux) 99 struct device *parent; 100 struct cfdata *match; 101 void *aux; 102 { 103 return (!midi_pcppi_attached); 104 } 105 106 void 107 midi_pcppi_attach(parent, self, aux) 108 struct device *parent; 109 struct device *self; 110 void *aux; 111 { 112 struct midi_pcppi_softc *sc = (struct midi_pcppi_softc *)self; 113 struct pcppi_attach_args *pa = (struct pcppi_attach_args *)aux; 114 midisyn *ms; 115 116 ms = &sc->sc_midisyn; 117 ms->mets = &midi_pcppi_hw; 118 strcpy(ms->name, "PC speaker"); 119 ms->nvoice = 1; 120 ms->flags = MS_DOALLOC | MS_FREQXLATE; 121 ms->data = pa->pa_cookie; 122 123 midi_pcppi_attached++; 124 125 midisyn_attach(&sc->sc_mididev, ms); 126 midi_attach(&sc->sc_mididev, parent); 127 } 128 129 void 130 midi_pcppi_on(ms, chan, note, vel) 131 midisyn *ms; 132 u_int32_t chan, note, vel; 133 { 134 pcppi_tag_t t = ms->data; 135 136 /*printf("ON %p %d\n", t, MIDISYN_FREQ_TO_HZ(note));*/ 137 pcppi_bell(t, MIDISYN_FREQ_TO_HZ(note), MAX_DURATION * hz, 0); 138 } 139 140 void 141 midi_pcppi_off(ms, chan, note, vel) 142 midisyn *ms; 143 u_int32_t chan, note, vel; 144 { 145 pcppi_tag_t t = ms->data; 146 147 /*printf("OFF %p %d\n", t, note >> 16);*/ 148 pcppi_bell(t, 0, 0, 0); 149 } 150 151 void 152 midi_pcppi_close(ms) 153 midisyn *ms; 154 { 155 pcppi_tag_t t = ms->data; 156 157 /* Make sure we are quiet. */ 158 pcppi_bell(t, 0, 0, 0); 159 } 160