1
2
3
4
5
6
7
8
9
10
11
12#include <linux/sched.h>
13#include <linux/timer.h>
14
15#include <asm/macintosh.h>
16#include <asm/mac_asc.h>
17
18static int mac_asc_inited;
19
20
21
22static __u8 mac_asc_wave_tab[ 0x800 ];
23
24
25
26
27
28static const signed char sine_data[] = {
29 0, 39, 75, 103, 121, 127, 121, 103, 75, 39,
30 0, -39, -75, -103, -121, -127, -121, -103, -75, -39
31};
32
33
34
35
36static volatile __u8* mac_asc_regs = ( void* )0x50F14000;
37
38
39
40
41static unsigned long mac_asc_samplespersec = 11050;
42static int mac_bell_duration;
43static unsigned long mac_bell_phase;
44static unsigned long mac_bell_phasepersample;
45
46
47
48
49static void mac_init_asc( void );
50static void mac_nosound( unsigned long );
51static void mac_quadra_start_bell( unsigned int, unsigned int, unsigned int );
52static void mac_quadra_ring_bell( unsigned long );
53static void mac_av_start_bell( unsigned int, unsigned int, unsigned int );
54static void ( *mac_special_bell )( unsigned int, unsigned int, unsigned int );
55
56
57
58
59static DEFINE_TIMER(mac_sound_timer, mac_nosound, 0, 0);
60
61
62
63
64
65static void mac_init_asc( void )
66{
67 int i;
68
69
70
71
72
73
74
75
76
77 switch ( macintosh_config->ident )
78 {
79 case MAC_MODEL_IIFX:
80
81
82
83 mac_asc_regs = ( void* )0x50010000;
84 break;
85
86
87
88
89 case MAC_MODEL_Q630:
90 case MAC_MODEL_P475:
91 mac_special_bell = mac_quadra_start_bell;
92 mac_asc_samplespersec = 22150;
93 break;
94 case MAC_MODEL_C660:
95 case MAC_MODEL_Q840:
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121 mac_special_bell = mac_av_start_bell;
122 break;
123 case MAC_MODEL_Q650:
124 case MAC_MODEL_Q700:
125 case MAC_MODEL_Q800:
126 case MAC_MODEL_Q900:
127 case MAC_MODEL_Q950:
128
129
130
131 mac_special_bell = NULL;
132 break;
133 default:
134
135
136
137 mac_special_bell = NULL;
138 break;
139 }
140
141
142
143
144
145 for ( i = 0; i < 0x400; i++ )
146 {
147 mac_asc_wave_tab[ i ] = i / 4;
148 mac_asc_wave_tab[ i + 0x400 ] = 0xFF - i / 4;
149 }
150 mac_asc_inited = 1;
151}
152
153
154
155
156
157
158
159
160
161
162void mac_mksound( unsigned int freq, unsigned int length )
163{
164 __u32 cfreq = ( freq << 5 ) / 468;
165 __u32 flags;
166 int i;
167
168 if ( mac_special_bell == NULL )
169 {
170
171 return;
172 }
173
174 if ( !mac_asc_inited )
175 mac_init_asc();
176
177 if ( mac_special_bell )
178 {
179 mac_special_bell( freq, length, 128 );
180 return;
181 }
182
183 if ( freq < 20 || freq > 20000 || length == 0 )
184 {
185 mac_nosound( 0 );
186 return;
187 }
188
189 local_irq_save(flags);
190
191 del_timer( &mac_sound_timer );
192
193 for ( i = 0; i < 0x800; i++ )
194 mac_asc_regs[ i ] = 0;
195 for ( i = 0; i < 0x800; i++ )
196 mac_asc_regs[ i ] = mac_asc_wave_tab[ i ];
197
198 for ( i = 0; i < 8; i++ )
199 *( __u32* )( ( __u32 )mac_asc_regs + ASC_CONTROL + 0x814 + 8 * i ) = cfreq;
200
201 mac_asc_regs[ 0x807 ] = 0;
202 mac_asc_regs[ ASC_VOLUME ] = 128;
203 mac_asc_regs[ 0x805 ] = 0;
204 mac_asc_regs[ 0x80F ] = 0;
205 mac_asc_regs[ ASC_MODE ] = ASC_MODE_SAMPLE;
206 mac_asc_regs[ ASC_ENABLE ] = ASC_ENABLE_SAMPLE;
207
208 mac_sound_timer.expires = jiffies + length;
209 add_timer( &mac_sound_timer );
210
211 local_irq_restore(flags);
212}
213
214
215
216
217static void mac_nosound( unsigned long ignored )
218{
219 mac_asc_regs[ ASC_ENABLE ] = 0;
220}
221
222
223
224
225static void mac_quadra_start_bell( unsigned int freq, unsigned int length, unsigned int volume )
226{
227 __u32 flags;
228
229
230 if ( mac_bell_duration > 0 )
231 {
232 mac_bell_duration += length;
233 return;
234 }
235
236 mac_bell_duration = length;
237 mac_bell_phase = 0;
238 mac_bell_phasepersample = ( freq * sizeof( mac_asc_wave_tab ) ) / mac_asc_samplespersec;
239
240
241 local_irq_save(flags);
242
243
244 mac_asc_regs[ 0x806 ] = volume;
245
246
247 if ( mac_asc_regs[ 0x801 ] != 1 )
248 {
249
250 mac_asc_regs[ 0x807 ] = 0;
251
252 mac_asc_regs[ 0x802 ] = 0;
253
254 mac_asc_regs[ 0x801 ] = 1;
255 mac_asc_regs[ 0x803 ] |= 0x80;
256 mac_asc_regs[ 0x803 ] &= 0x7F;
257 }
258
259 mac_sound_timer.function = mac_quadra_ring_bell;
260 mac_sound_timer.expires = jiffies + 1;
261 add_timer( &mac_sound_timer );
262
263 local_irq_restore(flags);
264}
265
266
267
268
269
270
271static void mac_quadra_ring_bell( unsigned long ignored )
272{
273 int i, count = mac_asc_samplespersec / HZ;
274 __u32 flags;
275
276
277
278
279
280
281
282
283 local_irq_save(flags);
284
285 del_timer( &mac_sound_timer );
286
287 if ( mac_bell_duration-- > 0 )
288 {
289 for ( i = 0; i < count; i++ )
290 {
291 mac_bell_phase += mac_bell_phasepersample;
292 mac_asc_regs[ 0 ] = mac_asc_wave_tab[ mac_bell_phase & ( sizeof( mac_asc_wave_tab ) - 1 ) ];
293 }
294 mac_sound_timer.expires = jiffies + 1;
295 add_timer( &mac_sound_timer );
296 }
297 else
298 mac_asc_regs[ 0x801 ] = 0;
299
300 local_irq_restore(flags);
301}
302
303
304
305
306static void mac_av_start_bell( unsigned int freq, unsigned int length, unsigned int volume )
307{
308}
309