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