asc.c revision 1.6 1 /* $NetBSD: asc.c,v 1.6 1994/10/26 08:46:02 cgd 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 asc_setbellparams(
91 int freq,
92 int length,
93 int volume)
94 {
95 /* I only perform these checks for sanity. */
96 /* I suppose someone might want a bell that rings */
97 /* all day, but then the can make kernel mods themselves. */
98
99 if(freq < 10 || freq > 40000)
100 return(EINVAL);
101 if(length < 0 || length > 3600)
102 return(EINVAL);
103 if(volume < 0 || volume > 100)
104 return(EINVAL);
105
106 bell_freq = freq;
107 bell_length = length;
108 bell_volume = volume;
109
110 return(0);
111 }
112
113
114 int asc_getbellparams(
115 int *freq,
116 int *length,
117 int *volume)
118 {
119 *freq = bell_freq;
120 *length = bell_length;
121 *volume = bell_volume;
122
123 return(0);
124 }
125
126
127 void asc_bellstop(
128 int param)
129 {
130 if(bell_ringing > 1000 || bell_ringing < 0)
131 panic("bell got out of synch?????");
132 if(--bell_ringing == 0){
133 ASCBase[0x801] = 0;
134 }
135 /* disable ASC */
136 }
137
138
139 int asc_ringbell()
140 {
141 int i;
142 unsigned long freq;
143
144 if(bell_ringing == 0){
145 for(i = 0; i < 0x800; i++)
146 ASCBase[i] = 0;
147
148 for(i = 0; i < 256;i++){
149 ASCBase[i] = i / 4;
150 ASCBase[i + 512] = i / 4;
151 ASCBase[i + 1024] = i / 4;
152 ASCBase[i + 1536] = i / 4;
153 }/* up part of wave, four voices ? */
154 for(i = 0; i < 256;i++){
155 ASCBase[i + 256] = 0x3f - (i / 4);
156 ASCBase[i + 768] = 0x3f - (i / 4);
157 ASCBase[i + 1280] = 0x3f - (i / 4);
158 ASCBase[i + 1792] = 0x3f - (i / 4);
159 }/* down part of wave, four voices ? */
160
161 /* Fix this. Need to find exact ASC sampling freq */
162 freq = 65536 * bell_freq / 466;
163
164 /* printf("beep: from %d, %02x %02x %02x %02x\n", cur_beep.freq,
165 (freq >> 24) & 0xff, (freq >> 16) & 0xff,
166 (freq >> 8) & 0xff, (freq) & 0xff);*/
167 for(i = 0; i < 8; i++){
168 ASCBase[0x814 + 8 * i] = (freq >> 24) & 0xff;
169 ASCBase[0x815 + 8 * i] = (freq >> 16) & 0xff;
170 ASCBase[0x816 + 8 * i] = (freq >> 8) & 0xff;
171 ASCBase[0x817 + 8 * i] = (freq) & 0xff;
172 }/* frequency; should put cur_beep.freq in here somewhere. */
173
174 ASCBase[0x807] = 3; /* 44 ? */
175 ASCBase[0x806] = 255 * bell_volume / 100;
176 ASCBase[0x805] = 0;
177 ASCBase[0x80f] = 0;
178 ASCBase[0x802] = 2; /* sampled */
179 ASCBase[0x801] = 2; /* enable sampled */
180 }
181
182 bell_ringing++;
183 timeout((void *) asc_bellstop, 0, bell_length);
184 }
185