asc.c revision 1.14 1 1.14 briggs /* $NetBSD: asc.c,v 1.14 1996/11/09 17:26:26 briggs Exp $ */
2 1.6 cgd
3 1.1 briggs /*-
4 1.1 briggs * Copyright (C) 1993 Allen K. Briggs, Chris P. Caputo,
5 1.1 briggs * Michael L. Finch, Bradley A. Grantham, and
6 1.1 briggs * Lawrence A. Kesteloot
7 1.1 briggs * All rights reserved.
8 1.1 briggs *
9 1.1 briggs * Redistribution and use in source and binary forms, with or without
10 1.1 briggs * modification, are permitted provided that the following conditions
11 1.1 briggs * are met:
12 1.1 briggs * 1. Redistributions of source code must retain the above copyright
13 1.1 briggs * notice, this list of conditions and the following disclaimer.
14 1.1 briggs * 2. Redistributions in binary form must reproduce the above copyright
15 1.1 briggs * notice, this list of conditions and the following disclaimer in the
16 1.1 briggs * documentation and/or other materials provided with the distribution.
17 1.1 briggs * 3. All advertising materials mentioning features or use of this software
18 1.1 briggs * must display the following acknowledgement:
19 1.1 briggs * This product includes software developed by the Alice Group.
20 1.1 briggs * 4. The names of the Alice Group or any of its members may not be used
21 1.1 briggs * to endorse or promote products derived from this software without
22 1.1 briggs * specific prior written permission.
23 1.1 briggs *
24 1.1 briggs * THIS SOFTWARE IS PROVIDED BY THE ALICE GROUP ``AS IS'' AND ANY EXPRESS OR
25 1.1 briggs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 1.1 briggs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
27 1.1 briggs * IN NO EVENT SHALL THE ALICE GROUP BE LIABLE FOR ANY DIRECT, INDIRECT,
28 1.1 briggs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
29 1.1 briggs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
30 1.1 briggs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
31 1.1 briggs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 1.1 briggs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33 1.1 briggs * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 1.1 briggs */
35 1.1 briggs
36 1.1 briggs /*
37 1.1 briggs * ASC driver code and asc_ringbell() support
38 1.1 briggs */
39 1.1 briggs
40 1.1 briggs #include <sys/types.h>
41 1.8 briggs #include <sys/cdefs.h>
42 1.1 briggs #include <sys/errno.h>
43 1.3 briggs #include <sys/time.h>
44 1.1 briggs #include <sys/systm.h>
45 1.1 briggs #include <sys/param.h>
46 1.5 briggs #include <sys/device.h>
47 1.14 briggs
48 1.14 briggs #include <machine/autoconf.h>
49 1.5 briggs #include <machine/cpu.h>
50 1.1 briggs
51 1.11 briggs #include "ascvar.h"
52 1.1 briggs
53 1.1 briggs /* Global ASC location */
54 1.7 briggs volatile unsigned char *ASCBase = (unsigned char *) 0x14000;
55 1.1 briggs
56 1.1 briggs
57 1.1 briggs /* bell support data */
58 1.14 briggs static int asc_configured = 0;
59 1.1 briggs static int bell_freq = 1880;
60 1.1 briggs static int bell_length = 10;
61 1.1 briggs static int bell_volume = 100;
62 1.1 briggs static int bell_ringing = 0;
63 1.1 briggs
64 1.11 briggs static int ascmatch __P((struct device *, void *, void *));
65 1.8 briggs static void ascattach __P((struct device *, struct device *, void *));
66 1.5 briggs
67 1.10 thorpej struct cfattach asc_ca = {
68 1.11 briggs sizeof(struct device), ascmatch, ascattach
69 1.10 thorpej };
70 1.10 thorpej
71 1.10 thorpej struct cfdriver asc_cd = {
72 1.10 thorpej NULL, "asc", DV_DULL, NULL, 0
73 1.10 thorpej };
74 1.5 briggs
75 1.5 briggs static int
76 1.11 briggs ascmatch(pdp, match, auxp)
77 1.11 briggs struct device *pdp;
78 1.11 briggs void *match, *auxp;
79 1.5 briggs {
80 1.14 briggs if (badbaddr((unsigned char *) ASCBase))
81 1.14 briggs return 0;
82 1.5 briggs return 1;
83 1.5 briggs }
84 1.1 briggs
85 1.5 briggs static void
86 1.5 briggs ascattach(parent, dev, aux)
87 1.7 briggs struct device *parent, *dev;
88 1.7 briggs void *aux;
89 1.1 briggs {
90 1.13 christos printf(" Apple sound chip.\n");
91 1.14 briggs asc_configured = 1;
92 1.1 briggs }
93 1.1 briggs
94 1.7 briggs int
95 1.11 briggs asc_setbellparams(freq, length, volume)
96 1.11 briggs int freq;
97 1.11 briggs int length;
98 1.11 briggs int volume;
99 1.1 briggs {
100 1.14 briggs if (!asc_configured) return (ENODEV);
101 1.14 briggs
102 1.1 briggs /* I only perform these checks for sanity. */
103 1.1 briggs /* I suppose someone might want a bell that rings */
104 1.1 briggs /* all day, but then the can make kernel mods themselves. */
105 1.1 briggs
106 1.7 briggs if (freq < 10 || freq > 40000)
107 1.7 briggs return (EINVAL);
108 1.7 briggs if (length < 0 || length > 3600)
109 1.7 briggs return (EINVAL);
110 1.7 briggs if (volume < 0 || volume > 100)
111 1.7 briggs return (EINVAL);
112 1.1 briggs
113 1.1 briggs bell_freq = freq;
114 1.1 briggs bell_length = length;
115 1.1 briggs bell_volume = volume;
116 1.1 briggs
117 1.7 briggs return (0);
118 1.1 briggs }
119 1.1 briggs
120 1.1 briggs
121 1.7 briggs int
122 1.11 briggs asc_getbellparams(freq, length, volume)
123 1.11 briggs int *freq;
124 1.11 briggs int *length;
125 1.11 briggs int *volume;
126 1.1 briggs {
127 1.14 briggs if (!asc_configured) return (ENODEV);
128 1.14 briggs
129 1.1 briggs *freq = bell_freq;
130 1.1 briggs *length = bell_length;
131 1.1 briggs *volume = bell_volume;
132 1.1 briggs
133 1.7 briggs return (0);
134 1.1 briggs }
135 1.1 briggs
136 1.1 briggs
137 1.7 briggs void
138 1.11 briggs asc_bellstop(param)
139 1.11 briggs int param;
140 1.1 briggs {
141 1.14 briggs if (!asc_configured) return;
142 1.14 briggs
143 1.7 briggs if (bell_ringing > 1000 || bell_ringing < 0)
144 1.1 briggs panic("bell got out of synch?????");
145 1.7 briggs if (--bell_ringing == 0) {
146 1.1 briggs ASCBase[0x801] = 0;
147 1.1 briggs }
148 1.1 briggs /* disable ASC */
149 1.1 briggs }
150 1.1 briggs
151 1.1 briggs
152 1.7 briggs int
153 1.7 briggs asc_ringbell()
154 1.1 briggs {
155 1.7 briggs int i;
156 1.1 briggs unsigned long freq;
157 1.14 briggs
158 1.14 briggs if (!asc_configured) return (ENODEV);
159 1.1 briggs
160 1.7 briggs if (bell_ringing == 0) {
161 1.7 briggs for (i = 0; i < 0x800; i++)
162 1.1 briggs ASCBase[i] = 0;
163 1.7 briggs
164 1.7 briggs for (i = 0; i < 256; i++) {
165 1.1 briggs ASCBase[i] = i / 4;
166 1.1 briggs ASCBase[i + 512] = i / 4;
167 1.1 briggs ASCBase[i + 1024] = i / 4;
168 1.1 briggs ASCBase[i + 1536] = i / 4;
169 1.7 briggs } /* up part of wave, four voices ? */
170 1.7 briggs for (i = 0; i < 256; i++) {
171 1.1 briggs ASCBase[i + 256] = 0x3f - (i / 4);
172 1.1 briggs ASCBase[i + 768] = 0x3f - (i / 4);
173 1.1 briggs ASCBase[i + 1280] = 0x3f - (i / 4);
174 1.1 briggs ASCBase[i + 1792] = 0x3f - (i / 4);
175 1.7 briggs } /* down part of wave, four voices ? */
176 1.1 briggs
177 1.7 briggs /* Fix this. Need to find exact ASC sampling freq */
178 1.1 briggs freq = 65536 * bell_freq / 466;
179 1.1 briggs
180 1.13 christos /* printf("beep: from %d, %02x %02x %02x %02x\n",
181 1.7 briggs * cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
182 1.7 briggs * (freq >> 8) & 0xff, (freq) & 0xff); */
183 1.7 briggs for (i = 0; i < 8; i++) {
184 1.1 briggs ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
185 1.1 briggs ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
186 1.1 briggs ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
187 1.1 briggs ASCBase[0x817 + 8 * i] = (freq) & 0xff;
188 1.7 briggs } /* frequency; should put cur_beep.freq in here
189 1.7 briggs * somewhere. */
190 1.7 briggs
191 1.7 briggs ASCBase[0x807] = 3; /* 44 ? */
192 1.1 briggs ASCBase[0x806] = 255 * bell_volume / 100;
193 1.7 briggs ASCBase[0x805] = 0;
194 1.7 briggs ASCBase[0x80f] = 0;
195 1.7 briggs ASCBase[0x802] = 2; /* sampled */
196 1.7 briggs ASCBase[0x801] = 2; /* enable sampled */
197 1.1 briggs }
198 1.1 briggs bell_ringing++;
199 1.3 briggs timeout((void *) asc_bellstop, 0, bell_length);
200 1.11 briggs
201 1.11 briggs return 0;
202 1.1 briggs }
203