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