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