asc.c revision 1.10 1 1.10 thorpej /* $NetBSD: asc.c,v 1.10 1996/03/17 01:33:20 thorpej 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.5 briggs #include <machine/cpu.h>
48 1.1 briggs
49 1.1 briggs
50 1.1 briggs /* Global ASC location */
51 1.7 briggs volatile unsigned char *ASCBase = (unsigned char *) 0x14000;
52 1.1 briggs
53 1.1 briggs
54 1.1 briggs /* bell support data */
55 1.1 briggs static int bell_freq = 1880;
56 1.1 briggs static int bell_length = 10;
57 1.1 briggs static int bell_volume = 100;
58 1.1 briggs static int bell_ringing = 0;
59 1.1 briggs
60 1.8 briggs static int ascprobe __P((struct device *, struct cfdata *, void *));
61 1.8 briggs static void ascattach __P((struct device *, struct device *, void *));
62 1.8 briggs extern int matchbyname __P((struct device *, void *, void *));
63 1.5 briggs
64 1.10 thorpej struct cfattach asc_ca = {
65 1.10 thorpej sizeof(struct device), matchbyname, ascattach
66 1.10 thorpej };
67 1.10 thorpej
68 1.10 thorpej struct cfdriver asc_cd = {
69 1.10 thorpej NULL, "asc", DV_DULL, NULL, 0
70 1.10 thorpej };
71 1.5 briggs
72 1.5 briggs static int
73 1.5 briggs ascprobe(parent, cf, aux)
74 1.7 briggs struct device *parent;
75 1.7 briggs struct cfdata *cf;
76 1.7 briggs void *aux;
77 1.5 briggs {
78 1.10 thorpej if (strcmp(*((char **) aux), asc_cd.cd_name))
79 1.5 briggs return 0;
80 1.1 briggs
81 1.5 briggs return 1;
82 1.5 briggs }
83 1.1 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.5 briggs printf(" Apple sound chip.\n");
91 1.1 briggs }
92 1.1 briggs
93 1.7 briggs int
94 1.7 briggs asc_setbellparams(
95 1.7 briggs int freq,
96 1.7 briggs int length,
97 1.7 briggs int volume)
98 1.1 briggs {
99 1.1 briggs /* I only perform these checks for sanity. */
100 1.1 briggs /* I suppose someone might want a bell that rings */
101 1.1 briggs /* all day, but then the can make kernel mods themselves. */
102 1.1 briggs
103 1.7 briggs if (freq < 10 || freq > 40000)
104 1.7 briggs return (EINVAL);
105 1.7 briggs if (length < 0 || length > 3600)
106 1.7 briggs return (EINVAL);
107 1.7 briggs if (volume < 0 || volume > 100)
108 1.7 briggs return (EINVAL);
109 1.1 briggs
110 1.1 briggs bell_freq = freq;
111 1.1 briggs bell_length = length;
112 1.1 briggs bell_volume = volume;
113 1.1 briggs
114 1.7 briggs return (0);
115 1.1 briggs }
116 1.1 briggs
117 1.1 briggs
118 1.7 briggs int
119 1.7 briggs asc_getbellparams(
120 1.7 briggs int *freq,
121 1.7 briggs int *length,
122 1.7 briggs int *volume)
123 1.1 briggs {
124 1.1 briggs *freq = bell_freq;
125 1.1 briggs *length = bell_length;
126 1.1 briggs *volume = bell_volume;
127 1.1 briggs
128 1.7 briggs return (0);
129 1.1 briggs }
130 1.1 briggs
131 1.1 briggs
132 1.7 briggs void
133 1.7 briggs asc_bellstop(
134 1.7 briggs int param)
135 1.1 briggs {
136 1.7 briggs if (bell_ringing > 1000 || bell_ringing < 0)
137 1.1 briggs panic("bell got out of synch?????");
138 1.7 briggs if (--bell_ringing == 0) {
139 1.1 briggs ASCBase[0x801] = 0;
140 1.1 briggs }
141 1.1 briggs /* disable ASC */
142 1.1 briggs }
143 1.1 briggs
144 1.1 briggs
145 1.7 briggs int
146 1.7 briggs asc_ringbell()
147 1.1 briggs {
148 1.7 briggs int i;
149 1.1 briggs unsigned long freq;
150 1.1 briggs
151 1.7 briggs if (bell_ringing == 0) {
152 1.7 briggs for (i = 0; i < 0x800; i++)
153 1.1 briggs ASCBase[i] = 0;
154 1.7 briggs
155 1.7 briggs for (i = 0; i < 256; i++) {
156 1.1 briggs ASCBase[i] = i / 4;
157 1.1 briggs ASCBase[i + 512] = i / 4;
158 1.1 briggs ASCBase[i + 1024] = i / 4;
159 1.1 briggs ASCBase[i + 1536] = i / 4;
160 1.7 briggs } /* up part of wave, four voices ? */
161 1.7 briggs for (i = 0; i < 256; i++) {
162 1.1 briggs ASCBase[i + 256] = 0x3f - (i / 4);
163 1.1 briggs ASCBase[i + 768] = 0x3f - (i / 4);
164 1.1 briggs ASCBase[i + 1280] = 0x3f - (i / 4);
165 1.1 briggs ASCBase[i + 1792] = 0x3f - (i / 4);
166 1.7 briggs } /* down part of wave, four voices ? */
167 1.1 briggs
168 1.7 briggs /* Fix this. Need to find exact ASC sampling freq */
169 1.1 briggs freq = 65536 * bell_freq / 466;
170 1.1 briggs
171 1.7 briggs /* printf("beep: from %d, %02x %02x %02x %02x\n",
172 1.7 briggs * cur_beep.freq, (freq >> 24) & 0xff, (freq >> 16) & 0xff,
173 1.7 briggs * (freq >> 8) & 0xff, (freq) & 0xff); */
174 1.7 briggs for (i = 0; i < 8; i++) {
175 1.1 briggs ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
176 1.1 briggs ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
177 1.1 briggs ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
178 1.1 briggs ASCBase[0x817 + 8 * i] = (freq) & 0xff;
179 1.7 briggs } /* frequency; should put cur_beep.freq in here
180 1.7 briggs * somewhere. */
181 1.7 briggs
182 1.7 briggs ASCBase[0x807] = 3; /* 44 ? */
183 1.1 briggs ASCBase[0x806] = 255 * bell_volume / 100;
184 1.7 briggs ASCBase[0x805] = 0;
185 1.7 briggs ASCBase[0x80f] = 0;
186 1.7 briggs ASCBase[0x802] = 2; /* sampled */
187 1.7 briggs ASCBase[0x801] = 2; /* enable sampled */
188 1.1 briggs }
189 1.1 briggs bell_ringing++;
190 1.3 briggs timeout((void *) asc_bellstop, 0, bell_length);
191 1.1 briggs }
192