midi_pcppi.c revision 1.12.14.1 1 /* $NetBSD: midi_pcppi.c,v 1.12.14.1 2006/06/07 01:23:10 chap 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 (at) 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.14.1 2006/06/07 01:23:10 chap 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 .close = midi_pcppi_close,
82 .noteon = midi_pcppi_on,
83 .noteoff = midi_pcppi_off,
84 };
85
86 int midi_pcppi_attached = 0; /* Not very nice */
87
88 int
89 midi_pcppi_match(parent, match, aux)
90 struct device *parent;
91 struct cfdata *match;
92 void *aux;
93 {
94 return (!midi_pcppi_attached);
95 }
96
97 void
98 midi_pcppi_attach(parent, self, aux)
99 struct device *parent;
100 struct device *self;
101 void *aux;
102 {
103 struct midi_pcppi_softc *sc = (struct midi_pcppi_softc *)self;
104 struct pcppi_attach_args *pa = (struct pcppi_attach_args *)aux;
105 midisyn *ms;
106
107 ms = &sc->sc_midisyn;
108 ms->mets = &midi_pcppi_hw;
109 strcpy(ms->name, "PC speaker");
110 ms->nvoice = 1;
111 ms->flags = MS_DOALLOC | MS_FREQXLATE;
112 ms->data = pa->pa_cookie;
113
114 midi_pcppi_attached++;
115
116 midisyn_attach(&sc->sc_mididev, ms);
117 midi_attach(&sc->sc_mididev, parent);
118 }
119
120 void
121 midi_pcppi_on(ms, chan, note, vel)
122 midisyn *ms;
123 u_int32_t chan, note, vel;
124 {
125 pcppi_tag_t t = ms->data;
126
127 /*printf("ON %p %d\n", t, MIDISYN_FREQ_TO_HZ(note));*/
128 pcppi_bell(t, MIDISYN_FREQ_TO_HZ(note), MAX_DURATION * hz, 0);
129 }
130
131 void
132 midi_pcppi_off(ms, chan, note, vel)
133 midisyn *ms;
134 u_int32_t chan, note, vel;
135 {
136 pcppi_tag_t t = ms->data;
137
138 /*printf("OFF %p %d\n", t, note >> 16);*/
139 pcppi_bell(t, 0, 0, 0);
140 }
141
142 void
143 midi_pcppi_close(ms)
144 midisyn *ms;
145 {
146 pcppi_tag_t t = ms->data;
147
148 /* Make sure we are quiet. */
149 pcppi_bell(t, 0, 0, 0);
150 }
151