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