asc.c revision 1.15 1 1.14 briggs /* $NetBSD: asc.c,v 1.15 1996/12/16 16:17:02 scottr 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.15 scottr static int ascmatch __P((struct device *, struct cfdata *, 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.15 scottr ascmatch(parent, cf, aux)
77 1.15 scottr struct device *parent;
78 1.15 scottr struct cfdata *cf;
79 1.15 scottr void *aux;
80 1.5 briggs {
81 1.14 briggs if (badbaddr((unsigned char *) ASCBase))
82 1.14 briggs return 0;
83 1.5 briggs return 1;
84 1.5 briggs }
85 1.1 briggs
86 1.5 briggs static void
87 1.5 briggs ascattach(parent, dev, aux)
88 1.7 briggs struct device *parent, *dev;
89 1.7 briggs void *aux;
90 1.1 briggs {
91 1.13 christos printf(" Apple sound chip.\n");
92 1.14 briggs asc_configured = 1;
93 1.1 briggs }
94 1.1 briggs
95 1.7 briggs int
96 1.11 briggs asc_setbellparams(freq, length, volume)
97 1.11 briggs int freq;
98 1.11 briggs int length;
99 1.11 briggs int volume;
100 1.1 briggs {
101 1.14 briggs if (!asc_configured) return (ENODEV);
102 1.14 briggs
103 1.1 briggs /* I only perform these checks for sanity. */
104 1.1 briggs /* I suppose someone might want a bell that rings */
105 1.1 briggs /* all day, but then the can make kernel mods themselves. */
106 1.1 briggs
107 1.7 briggs if (freq < 10 || freq > 40000)
108 1.7 briggs return (EINVAL);
109 1.7 briggs if (length < 0 || length > 3600)
110 1.7 briggs return (EINVAL);
111 1.7 briggs if (volume < 0 || volume > 100)
112 1.7 briggs return (EINVAL);
113 1.1 briggs
114 1.1 briggs bell_freq = freq;
115 1.1 briggs bell_length = length;
116 1.1 briggs bell_volume = volume;
117 1.1 briggs
118 1.7 briggs return (0);
119 1.1 briggs }
120 1.1 briggs
121 1.1 briggs
122 1.7 briggs int
123 1.11 briggs asc_getbellparams(freq, length, volume)
124 1.11 briggs int *freq;
125 1.11 briggs int *length;
126 1.11 briggs int *volume;
127 1.1 briggs {
128 1.14 briggs if (!asc_configured) return (ENODEV);
129 1.14 briggs
130 1.1 briggs *freq = bell_freq;
131 1.1 briggs *length = bell_length;
132 1.1 briggs *volume = bell_volume;
133 1.1 briggs
134 1.7 briggs return (0);
135 1.1 briggs }
136 1.1 briggs
137 1.1 briggs
138 1.7 briggs void
139 1.11 briggs asc_bellstop(param)
140 1.11 briggs int param;
141 1.1 briggs {
142 1.14 briggs if (!asc_configured) return;
143 1.14 briggs
144 1.7 briggs if (bell_ringing > 1000 || bell_ringing < 0)
145 1.1 briggs panic("bell got out of synch?????");
146 1.7 briggs if (--bell_ringing == 0) {
147 1.1 briggs ASCBase[0x801] = 0;
148 1.1 briggs }
149 1.1 briggs /* disable ASC */
150 1.1 briggs }
151 1.1 briggs
152 1.1 briggs
153 1.7 briggs int
154 1.7 briggs asc_ringbell()
155 1.1 briggs {
156 1.7 briggs int i;
157 1.1 briggs unsigned long freq;
158 1.14 briggs
159 1.14 briggs if (!asc_configured) return (ENODEV);
160 1.1 briggs
161 1.7 briggs if (bell_ringing == 0) {
162 1.7 briggs for (i = 0; i < 0x800; i++)
163 1.1 briggs ASCBase[i] = 0;
164 1.7 briggs
165 1.7 briggs for (i = 0; i < 256; i++) {
166 1.1 briggs ASCBase[i] = i / 4;
167 1.1 briggs ASCBase[i + 512] = i / 4;
168 1.1 briggs ASCBase[i + 1024] = i / 4;
169 1.1 briggs ASCBase[i + 1536] = i / 4;
170 1.7 briggs } /* up part of wave, four voices ? */
171 1.7 briggs for (i = 0; i < 256; i++) {
172 1.1 briggs ASCBase[i + 256] = 0x3f - (i / 4);
173 1.1 briggs ASCBase[i + 768] = 0x3f - (i / 4);
174 1.1 briggs ASCBase[i + 1280] = 0x3f - (i / 4);
175 1.1 briggs ASCBase[i + 1792] = 0x3f - (i / 4);
176 1.7 briggs } /* down part of wave, four voices ? */
177 1.1 briggs
178 1.7 briggs /* Fix this. Need to find exact ASC sampling freq */
179 1.1 briggs freq = 65536 * bell_freq / 466;
180 1.1 briggs
181 1.13 christos /* printf("beep: from %d, %02x %02x %02x %02x\n",
182 1.7 briggs * cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
183 1.7 briggs * (freq >> 8) & 0xff, (freq) & 0xff); */
184 1.7 briggs for (i = 0; i < 8; i++) {
185 1.1 briggs ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
186 1.1 briggs ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
187 1.1 briggs ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
188 1.1 briggs ASCBase[0x817 + 8 * i] = (freq) & 0xff;
189 1.7 briggs } /* frequency; should put cur_beep.freq in here
190 1.7 briggs * somewhere. */
191 1.7 briggs
192 1.7 briggs ASCBase[0x807] = 3; /* 44 ? */
193 1.1 briggs ASCBase[0x806] = 255 * bell_volume / 100;
194 1.7 briggs ASCBase[0x805] = 0;
195 1.7 briggs ASCBase[0x80f] = 0;
196 1.7 briggs ASCBase[0x802] = 2; /* sampled */
197 1.7 briggs ASCBase[0x801] = 2; /* enable sampled */
198 1.1 briggs }
199 1.1 briggs bell_ringing++;
200 1.3 briggs timeout((void *) asc_bellstop, 0, bell_length);
201 1.11 briggs
202 1.11 briggs return 0;
203 1.1 briggs }
204