2 /* linux/drivers/sound/dmasound.c */
6 OSS/Free compatible Atari TT/Falcon and Amiga DMA sound driver for Linux/m68k
7 Extended to support Power Macintosh for Linux/ppc by Paul Mackerras
9 (c) 1995 by Michael Schlueter & Michael Marte
11 Michael Schlueter (michael@duck.syd.de) did the basic structure of the VFS
12 interface and the u-law to signed byte conversion.
14 Michael Marte (marte@informatik.uni-muenchen.de) did the sound queue,
15 /dev/mixer, /dev/sndstat and complemented the VFS interface. He would like
17 Michael Schlueter for initial ideas and documentation on the MFP and
18 the DMA sound hardware.
19 Therapy? for their CD 'Troublegum' which really made me rock.
21 /dev/sndstat is based on code by Hannu Savolainen, the author of the
22 VoxWare family of drivers.
24 This file is subject to the terms and conditions of the GNU General Public
25 License. See the file COPYING in the main directory of this archive
29 1995/8/25 first release
31 1995/9/02 ++roman: fixed atari_stram_alloc() call, the timer programming
32 and several race conditions
34 1995/9/14 ++roman: After some discussion with Michael Schlueter, revised
35 the interrupt disabling
36 Slightly speeded up U8->S8 translation by using long
37 operations where possible
38 Added 4:3 interpolation for /dev/audio
40 1995/9/20 ++TeSche: Fixed a bug in sq_write and changed /dev/audio
41 converting to play at 12517Hz instead of 6258Hz.
43 1995/9/23 ++TeSche: Changed sq_interrupt() and sq_play() to pre-program
44 the DMA for another frame while there's still one
45 running. This allows the IRQ response to be
46 arbitrarily delayed and playing will still continue.
48 1995/10/14 ++Guenther_Kelleter@ac3.maus.de, ++TeSche: better support for
49 Falcon audio (the Falcon doesn't raise an IRQ at the
50 end of a frame, but at the beginning instead!). uses
51 'if (codec_dma)' in lots of places to simply switch
52 between Falcon and TT code.
54 1995/11/06 ++TeSche: started introducing a hardware abstraction scheme
55 (may perhaps also serve for Amigas?), can now play
56 samples at almost all frequencies by means of a more
57 generalized expand routine, takes a good deal of care
58 to cut data only at sample sizes, buffer size is now
59 a kernel runtime option, implemented fsync() & several
61 ++Guenther: useful hints and bug fixes, cross-checked it for
64 1996/3/9 ++geert: support added for Amiga, A-law, 16-bit little endian.
65 Unification to drivers/sound/dmasound.c.
67 1996/4/6 ++Martin Mitchell: updated to 1.3 kernel.
69 1996/6/13 ++topi: fixed things that were broken (mainly the amiga
70 14-bit routines), /dev/sndstat shows now the real
71 hardware frequency, the lowpass filter is disabled
74 1996/9/25 ++geert: modularization
76 1998-06-10 ++andreas: converted to use sound_core
81 #include <linux/module.h>
82 #include <linux/sched.h>
83 #include <linux/timer.h>
84 #include <linux/major.h>
85 #include <linux/config.h>
86 #include <linux/fcntl.h>
87 #include <linux/errno.h>
89 #include <linux/malloc.h>
90 #include <linux/sound.h>
91 #include <linux/init.h>
94 #include <asm/setup.h>
96 #include <asm/system.h>
98 #include <asm/pgtable.h>
99 #include <asm/uaccess.h>
102 #include <asm/atarihw.h>
103 #include <asm/atariints.h>
104 #include <asm/atari_stram.h>
105 #endif /* CONFIG_ATARI */
107 #include <asm/amigahw.h>
108 #include <asm/amigaints.h>
109 #endif /* CONFIG_AMIGA */
111 #include <asm/prom.h>
113 #include <asm/dbdma.h>
114 #ifdef CONFIG_PMAC_PBOOK
117 #endif /* CONFIG_PMAC_PBOOK */
118 #include "awacs_defs.h"
119 #include <linux/nvram.h>
120 #include <linux/vt_kern.h>
121 #endif /* CONFIG_PMAC */
123 #include "dmasound.h"
124 #include <linux/soundcard.h>
126 #define HAS_8BIT_TABLES
129 static int sq_unit
= -1;
130 static int mixer_unit
= -1;
131 static int state_unit
= -1;
132 static int irq_installed
= 0;
134 static char **sound_buffers
= NULL
;
138 extern void atari_microwire_cmd(int cmd
);
139 #endif /* CONFIG_ATARI */
143 * The minimum period for audio depends on htotal (for OCS/ECS/AGA)
144 * (Imported from arch/m68k/amiga/amisound.c)
147 extern volatile u_short amiga_audio_min_period
;
151 * amiga_mksound() should be able to restore the period after beeping
152 * (Imported from arch/m68k/amiga/amisound.c)
155 extern u_short amiga_audio_period
;
162 #define AMI_AUDIO_OFF (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
163 #define AMI_AUDIO_8 (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
164 #define AMI_AUDIO_14 (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
166 #endif /* CONFIG_AMIGA */
170 * Interrupt numbers and addresses, obtained from the device tree.
172 static int awacs_irq
, awacs_tx_irq
, awacs_rx_irq
;
173 static volatile struct awacs_regs
*awacs
;
174 static volatile struct dbdma_regs
*awacs_txdma
, *awacs_rxdma
;
175 static int awacs_rate_index
;
176 static int awacs_subframe
;
179 * Space for the DBDMA command blocks.
181 static void *awacs_tx_cmd_space
;
182 static volatile struct dbdma_cmd
*awacs_tx_cmds
;
185 * Cached values of AWACS registers (we can't read them).
189 #define HAS_16BIT_TABLES
190 #undef HAS_8BIT_TABLES
193 * Stuff for outputting a beep. The values range from -327 to +327
194 * so we can multiply by an amplitude in the range 0..100 to get a
195 * signed short value to put in the output buffer.
197 static short beep_wform
[256] = {
198 0, 40, 79, 117, 153, 187, 218, 245,
199 269, 288, 304, 316, 323, 327, 327, 324,
200 318, 310, 299, 288, 275, 262, 249, 236,
201 224, 213, 204, 196, 190, 186, 183, 182,
202 182, 183, 186, 189, 192, 196, 200, 203,
203 206, 208, 209, 209, 209, 207, 204, 201,
204 197, 193, 188, 183, 179, 174, 170, 166,
205 163, 161, 160, 159, 159, 160, 161, 162,
206 164, 166, 168, 169, 171, 171, 171, 170,
207 169, 167, 163, 159, 155, 150, 144, 139,
208 133, 128, 122, 117, 113, 110, 107, 105,
209 103, 103, 103, 103, 104, 104, 105, 105,
210 105, 103, 101, 97, 92, 86, 78, 68,
211 58, 45, 32, 18, 3, -11, -26, -41,
212 -55, -68, -79, -88, -95, -100, -102, -102,
213 -99, -93, -85, -75, -62, -48, -33, -16,
214 0, 16, 33, 48, 62, 75, 85, 93,
215 99, 102, 102, 100, 95, 88, 79, 68,
216 55, 41, 26, 11, -3, -18, -32, -45,
217 -58, -68, -78, -86, -92, -97, -101, -103,
218 -105, -105, -105, -104, -104, -103, -103, -103,
219 -103, -105, -107, -110, -113, -117, -122, -128,
220 -133, -139, -144, -150, -155, -159, -163, -167,
221 -169, -170, -171, -171, -171, -169, -168, -166,
222 -164, -162, -161, -160, -159, -159, -160, -161,
223 -163, -166, -170, -174, -179, -183, -188, -193,
224 -197, -201, -204, -207, -209, -209, -209, -208,
225 -206, -203, -200, -196, -192, -189, -186, -183,
226 -182, -182, -183, -186, -190, -196, -204, -213,
227 -224, -236, -249, -262, -275, -288, -299, -310,
228 -318, -324, -327, -327, -323, -316, -304, -288,
229 -269, -245, -218, -187, -153, -117, -79, -40,
232 #define BEEP_SPEED 2 /* 22050 Hz sample rate */
233 #define BEEP_BUFLEN 512
234 #define BEEP_VOLUME 15 /* 0 - 100 */
236 static int beep_volume
= BEEP_VOLUME
;
237 static int beep_playing
= 0;
238 static short *beep_buf
;
239 static volatile struct dbdma_cmd
*beep_dbdma_cmd
;
240 static void (*orig_mksound
)(unsigned int, unsigned int);
242 #ifdef CONFIG_PMAC_PBOOK
244 * Stuff for restoring after a sleep.
246 static int awacs_sleep_notify(struct notifier_block
*, unsigned long, void *);
247 struct notifier_block awacs_sleep_notifier
= {
250 #endif /* CONFIG_PMAC_PBOOK */
252 #endif /* CONFIG_PMAC */
254 /*** Some declarations *******************************************************/
258 #define DMASND_FALCON 2
259 #define DMASND_AMIGA 3
260 #define DMASND_AWACS 4
262 #define MAX_CATCH_RADIUS 10
263 #define MIN_BUFFERS 4
264 #define MIN_BUFSIZE 4
265 #define MAX_BUFSIZE 128 /* Limit for Amiga */
267 static int catchRadius
= 0, numBufs
= 4, bufSize
= 32;
268 MODULE_PARM(catchRadius
, "i");
269 MODULE_PARM(numBufs
, "i");
270 MODULE_PARM(bufSize
, "i");
272 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
273 #define min(x, y) ((x) < (y) ? (x) : (y))
274 #define le2be16(x) (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
275 #define le2be16dbl(x) (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
277 #define IOCTL_IN(arg, ret) \
278 do { int error = get_user(ret, (int *)(arg)); \
279 if (error) return error; \
281 #define IOCTL_OUT(arg, ret) ioctl_return((int *)(arg), ret)
284 /*** Some low level helpers **************************************************/
286 #ifdef HAS_8BIT_TABLES
289 static char ulaw2dma8
[] = {
290 -126, -122, -118, -114, -110, -106, -102, -98,
291 -94, -90, -86, -82, -78, -74, -70, -66,
292 -63, -61, -59, -57, -55, -53, -51, -49,
293 -47, -45, -43, -41, -39, -37, -35, -33,
294 -31, -30, -29, -28, -27, -26, -25, -24,
295 -23, -22, -21, -20, -19, -18, -17, -16,
296 -16, -15, -15, -14, -14, -13, -13, -12,
297 -12, -11, -11, -10, -10, -9, -9, -8,
298 -8, -8, -7, -7, -7, -7, -6, -6,
299 -6, -6, -5, -5, -5, -5, -4, -4,
300 -4, -4, -4, -4, -3, -3, -3, -3,
301 -3, -3, -3, -3, -2, -2, -2, -2,
302 -2, -2, -2, -2, -2, -2, -2, -2,
303 -1, -1, -1, -1, -1, -1, -1, -1,
304 -1, -1, -1, -1, -1, -1, -1, -1,
305 -1, -1, -1, -1, -1, -1, -1, 0,
306 125, 121, 117, 113, 109, 105, 101, 97,
307 93, 89, 85, 81, 77, 73, 69, 65,
308 62, 60, 58, 56, 54, 52, 50, 48,
309 46, 44, 42, 40, 38, 36, 34, 32,
310 30, 29, 28, 27, 26, 25, 24, 23,
311 22, 21, 20, 19, 18, 17, 16, 15,
312 15, 14, 14, 13, 13, 12, 12, 11,
313 11, 10, 10, 9, 9, 8, 8, 7,
314 7, 7, 6, 6, 6, 6, 5, 5,
315 5, 5, 4, 4, 4, 4, 3, 3,
316 3, 3, 3, 3, 2, 2, 2, 2,
317 2, 2, 2, 2, 1, 1, 1, 1,
318 1, 1, 1, 1, 1, 1, 1, 1,
319 0, 0, 0, 0, 0, 0, 0, 0,
320 0, 0, 0, 0, 0, 0, 0, 0,
321 0, 0, 0, 0, 0, 0, 0, 0
326 static char alaw2dma8
[] = {
327 -22, -21, -24, -23, -18, -17, -20, -19,
328 -30, -29, -32, -31, -26, -25, -28, -27,
329 -11, -11, -12, -12, -9, -9, -10, -10,
330 -15, -15, -16, -16, -13, -13, -14, -14,
331 -86, -82, -94, -90, -70, -66, -78, -74,
332 -118, -114, -126, -122, -102, -98, -110, -106,
333 -43, -41, -47, -45, -35, -33, -39, -37,
334 -59, -57, -63, -61, -51, -49, -55, -53,
335 -2, -2, -2, -2, -2, -2, -2, -2,
336 -2, -2, -2, -2, -2, -2, -2, -2,
337 -1, -1, -1, -1, -1, -1, -1, -1,
338 -1, -1, -1, -1, -1, -1, -1, -1,
339 -6, -6, -6, -6, -5, -5, -5, -5,
340 -8, -8, -8, -8, -7, -7, -7, -7,
341 -3, -3, -3, -3, -3, -3, -3, -3,
342 -4, -4, -4, -4, -4, -4, -4, -4,
343 21, 20, 23, 22, 17, 16, 19, 18,
344 29, 28, 31, 30, 25, 24, 27, 26,
345 10, 10, 11, 11, 8, 8, 9, 9,
346 14, 14, 15, 15, 12, 12, 13, 13,
347 86, 82, 94, 90, 70, 66, 78, 74,
348 118, 114, 126, 122, 102, 98, 110, 106,
349 43, 41, 47, 45, 35, 33, 39, 37,
350 59, 57, 63, 61, 51, 49, 55, 53,
351 1, 1, 1, 1, 1, 1, 1, 1,
352 1, 1, 1, 1, 1, 1, 1, 1,
353 0, 0, 0, 0, 0, 0, 0, 0,
354 0, 0, 0, 0, 0, 0, 0, 0,
355 5, 5, 5, 5, 4, 4, 4, 4,
356 7, 7, 7, 7, 6, 6, 6, 6,
357 2, 2, 2, 2, 2, 2, 2, 2,
358 3, 3, 3, 3, 3, 3, 3, 3
360 #endif /* HAS_8BIT_TABLES */
362 #ifdef HAS_16BIT_TABLES
366 static short ulaw2dma16
[] = {
367 -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
368 -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
369 -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
370 -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
371 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
372 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
373 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
374 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
375 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
376 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
377 -876, -844, -812, -780, -748, -716, -684, -652,
378 -620, -588, -556, -524, -492, -460, -428, -396,
379 -372, -356, -340, -324, -308, -292, -276, -260,
380 -244, -228, -212, -196, -180, -164, -148, -132,
381 -120, -112, -104, -96, -88, -80, -72, -64,
382 -56, -48, -40, -32, -24, -16, -8, 0,
383 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
384 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
385 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
386 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
387 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
388 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
389 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
390 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
391 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
392 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
393 876, 844, 812, 780, 748, 716, 684, 652,
394 620, 588, 556, 524, 492, 460, 428, 396,
395 372, 356, 340, 324, 308, 292, 276, 260,
396 244, 228, 212, 196, 180, 164, 148, 132,
397 120, 112, 104, 96, 88, 80, 72, 64,
398 56, 48, 40, 32, 24, 16, 8, 0,
403 static short alaw2dma16
[] = {
404 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
405 -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
406 -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
407 -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
408 -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
409 -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
410 -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472,
411 -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
412 -344, -328, -376, -360, -280, -264, -312, -296,
413 -472, -456, -504, -488, -408, -392, -440, -424,
414 -88, -72, -120, -104, -24, -8, -56, -40,
415 -216, -200, -248, -232, -152, -136, -184, -168,
416 -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
417 -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
418 -688, -656, -752, -720, -560, -528, -624, -592,
419 -944, -912, -1008, -976, -816, -784, -880, -848,
420 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
421 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
422 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
423 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
424 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
425 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
426 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
427 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
428 344, 328, 376, 360, 280, 264, 312, 296,
429 472, 456, 504, 488, 408, 392, 440, 424,
430 88, 72, 120, 104, 24, 8, 56, 40,
431 216, 200, 248, 232, 152, 136, 184, 168,
432 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
433 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
434 688, 656, 752, 720, 560, 528, 624, 592,
435 944, 912, 1008, 976, 816, 784, 880, 848,
437 #endif /* HAS_16BIT_TABLES */
440 #ifdef HAS_14BIT_TABLES
442 /* 14 bit mu-law (LSB) */
444 static char alaw2dma14l
[] = {
445 33, 33, 33, 33, 33, 33, 33, 33,
446 33, 33, 33, 33, 33, 33, 33, 33,
447 33, 33, 33, 33, 33, 33, 33, 33,
448 33, 33, 33, 33, 33, 33, 33, 33,
449 1, 1, 1, 1, 1, 1, 1, 1,
450 1, 1, 1, 1, 1, 1, 1, 1,
451 49, 17, 49, 17, 49, 17, 49, 17,
452 49, 17, 49, 17, 49, 17, 49, 17,
453 41, 57, 9, 25, 41, 57, 9, 25,
454 41, 57, 9, 25, 41, 57, 9, 25,
455 37, 45, 53, 61, 5, 13, 21, 29,
456 37, 45, 53, 61, 5, 13, 21, 29,
457 35, 39, 43, 47, 51, 55, 59, 63,
458 3, 7, 11, 15, 19, 23, 27, 31,
459 34, 36, 38, 40, 42, 44, 46, 48,
460 50, 52, 54, 56, 58, 60, 62, 0,
461 31, 31, 31, 31, 31, 31, 31, 31,
462 31, 31, 31, 31, 31, 31, 31, 31,
463 31, 31, 31, 31, 31, 31, 31, 31,
464 31, 31, 31, 31, 31, 31, 31, 31,
465 63, 63, 63, 63, 63, 63, 63, 63,
466 63, 63, 63, 63, 63, 63, 63, 63,
467 15, 47, 15, 47, 15, 47, 15, 47,
468 15, 47, 15, 47, 15, 47, 15, 47,
469 23, 7, 55, 39, 23, 7, 55, 39,
470 23, 7, 55, 39, 23, 7, 55, 39,
471 27, 19, 11, 3, 59, 51, 43, 35,
472 27, 19, 11, 3, 59, 51, 43, 35,
473 29, 25, 21, 17, 13, 9, 5, 1,
474 61, 57, 53, 49, 45, 41, 37, 33,
475 30, 28, 26, 24, 22, 20, 18, 16,
476 14, 12, 10, 8, 6, 4, 2, 0
479 /* 14 bit A-law (LSB) */
481 static char alaw2dma14l
[] = {
482 32, 32, 32, 32, 32, 32, 32, 32,
483 32, 32, 32, 32, 32, 32, 32, 32,
484 16, 48, 16, 48, 16, 48, 16, 48,
485 16, 48, 16, 48, 16, 48, 16, 48,
486 0, 0, 0, 0, 0, 0, 0, 0,
487 0, 0, 0, 0, 0, 0, 0, 0,
488 0, 0, 0, 0, 0, 0, 0, 0,
489 0, 0, 0, 0, 0, 0, 0, 0,
490 42, 46, 34, 38, 58, 62, 50, 54,
491 10, 14, 2, 6, 26, 30, 18, 22,
492 42, 46, 34, 38, 58, 62, 50, 54,
493 10, 14, 2, 6, 26, 30, 18, 22,
494 40, 56, 8, 24, 40, 56, 8, 24,
495 40, 56, 8, 24, 40, 56, 8, 24,
496 20, 28, 4, 12, 52, 60, 36, 44,
497 20, 28, 4, 12, 52, 60, 36, 44,
498 32, 32, 32, 32, 32, 32, 32, 32,
499 32, 32, 32, 32, 32, 32, 32, 32,
500 48, 16, 48, 16, 48, 16, 48, 16,
501 48, 16, 48, 16, 48, 16, 48, 16,
502 0, 0, 0, 0, 0, 0, 0, 0,
503 0, 0, 0, 0, 0, 0, 0, 0,
504 0, 0, 0, 0, 0, 0, 0, 0,
505 0, 0, 0, 0, 0, 0, 0, 0,
506 22, 18, 30, 26, 6, 2, 14, 10,
507 54, 50, 62, 58, 38, 34, 46, 42,
508 22, 18, 30, 26, 6, 2, 14, 10,
509 54, 50, 62, 58, 38, 34, 46, 42,
510 24, 8, 56, 40, 24, 8, 56, 40,
511 24, 8, 56, 40, 24, 8, 56, 40,
512 44, 36, 60, 52, 12, 4, 28, 20,
513 44, 36, 60, 52, 12, 4, 28, 20
515 #endif /* HAS_14BIT_TABLES */
518 /*** Translations ************************************************************/
522 static ssize_t
ata_ct_law(const u_char
*userPtr
, size_t userCount
,
523 u_char frame
[], ssize_t
*frameUsed
,
525 static ssize_t
ata_ct_s8(const u_char
*userPtr
, size_t userCount
,
526 u_char frame
[], ssize_t
*frameUsed
,
528 static ssize_t
ata_ct_u8(const u_char
*userPtr
, size_t userCount
,
529 u_char frame
[], ssize_t
*frameUsed
,
531 static ssize_t
ata_ct_s16be(const u_char
*userPtr
, size_t userCount
,
532 u_char frame
[], ssize_t
*frameUsed
,
534 static ssize_t
ata_ct_u16be(const u_char
*userPtr
, size_t userCount
,
535 u_char frame
[], ssize_t
*frameUsed
,
537 static ssize_t
ata_ct_s16le(const u_char
*userPtr
, size_t userCount
,
538 u_char frame
[], ssize_t
*frameUsed
,
540 static ssize_t
ata_ct_u16le(const u_char
*userPtr
, size_t userCount
,
541 u_char frame
[], ssize_t
*frameUsed
,
543 static ssize_t
ata_ctx_law(const u_char
*userPtr
, size_t userCount
,
544 u_char frame
[], ssize_t
*frameUsed
,
546 static ssize_t
ata_ctx_s8(const u_char
*userPtr
, size_t userCount
,
547 u_char frame
[], ssize_t
*frameUsed
,
549 static ssize_t
ata_ctx_u8(const u_char
*userPtr
, size_t userCount
,
550 u_char frame
[], ssize_t
*frameUsed
,
552 static ssize_t
ata_ctx_s16be(const u_char
*userPtr
, size_t userCount
,
553 u_char frame
[], ssize_t
*frameUsed
,
555 static ssize_t
ata_ctx_u16be(const u_char
*userPtr
, size_t userCount
,
556 u_char frame
[], ssize_t
*frameUsed
,
558 static ssize_t
ata_ctx_s16le(const u_char
*userPtr
, size_t userCount
,
559 u_char frame
[], ssize_t
*frameUsed
,
561 static ssize_t
ata_ctx_u16le(const u_char
*userPtr
, size_t userCount
,
562 u_char frame
[], ssize_t
*frameUsed
,
564 #endif /* CONFIG_ATARI */
567 static ssize_t
ami_ct_law(const u_char
*userPtr
, size_t userCount
,
568 u_char frame
[], ssize_t
*frameUsed
,
570 static ssize_t
ami_ct_s8(const u_char
*userPtr
, size_t userCount
,
571 u_char frame
[], ssize_t
*frameUsed
,
573 static ssize_t
ami_ct_u8(const u_char
*userPtr
, size_t userCount
,
574 u_char frame
[], ssize_t
*frameUsed
,
576 static ssize_t
ami_ct_s16be(const u_char
*userPtr
, size_t userCount
,
577 u_char frame
[], ssize_t
*frameUsed
,
579 static ssize_t
ami_ct_u16be(const u_char
*userPtr
, size_t userCount
,
580 u_char frame
[], ssize_t
*frameUsed
,
582 static ssize_t
ami_ct_s16le(const u_char
*userPtr
, size_t userCount
,
583 u_char frame
[], ssize_t
*frameUsed
,
585 static ssize_t
ami_ct_u16le(const u_char
*userPtr
, size_t userCount
,
586 u_char frame
[], ssize_t
*frameUsed
,
588 #endif /* CONFIG_AMIGA */
591 static ssize_t
pmac_ct_law(const u_char
*userPtr
, size_t userCount
,
592 u_char frame
[], ssize_t
*frameUsed
,
594 static ssize_t
pmac_ct_s8(const u_char
*userPtr
, size_t userCount
,
595 u_char frame
[], ssize_t
*frameUsed
,
597 static ssize_t
pmac_ct_u8(const u_char
*userPtr
, size_t userCount
,
598 u_char frame
[], ssize_t
*frameUsed
,
600 static ssize_t
pmac_ct_s16(const u_char
*userPtr
, size_t userCount
,
601 u_char frame
[], ssize_t
*frameUsed
,
603 static ssize_t
pmac_ct_u16(const u_char
*userPtr
, size_t userCount
,
604 u_char frame
[], ssize_t
*frameUsed
,
606 static ssize_t
pmac_ctx_law(const u_char
*userPtr
, size_t userCount
,
607 u_char frame
[], ssize_t
*frameUsed
,
609 static ssize_t
pmac_ctx_s8(const u_char
*userPtr
, size_t userCount
,
610 u_char frame
[], ssize_t
*frameUsed
,
612 static ssize_t
pmac_ctx_u8(const u_char
*userPtr
, size_t userCount
,
613 u_char frame
[], ssize_t
*frameUsed
,
615 static ssize_t
pmac_ctx_s16(const u_char
*userPtr
, size_t userCount
,
616 u_char frame
[], ssize_t
*frameUsed
,
618 static ssize_t
pmac_ctx_u16(const u_char
*userPtr
, size_t userCount
,
619 u_char frame
[], ssize_t
*frameUsed
,
621 #endif /* CONFIG_PMAC */
623 /*** Machine definitions *****************************************************/
628 void *(*dma_alloc
)(unsigned int, int);
629 void (*dma_free
)(void *, unsigned int);
630 int (*irqinit
)(void);
632 void (*irqcleanup
)(void);
635 void (*silence
)(void);
636 int (*setFormat
)(int);
637 int (*setVolume
)(int);
639 int (*setTreble
)(int);
645 /*** Low level stuff *********************************************************/
649 int format
; /* AFMT_* */
650 int stereo
; /* 0 = mono, 1 = stereo */
651 int size
; /* 8/16 bit*/
652 int speed
; /* speed */
656 ssize_t (*ct_ulaw
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
657 ssize_t (*ct_alaw
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
658 ssize_t (*ct_s8
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
659 ssize_t (*ct_u8
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
660 ssize_t (*ct_s16be
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
661 ssize_t (*ct_u16be
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
662 ssize_t (*ct_s16le
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
663 ssize_t (*ct_u16le
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
666 struct sound_settings
{
667 MACHINE mach
; /* machine dependent things */
668 SETTINGS hard
; /* hardware settings */
669 SETTINGS soft
; /* software settings */
670 SETTINGS dsp
; /* /dev/dsp default settings */
671 TRANS
*trans
; /* supported translations */
672 int volume_left
; /* volume (range is machine dependent) */
674 int bass
; /* tone (range is machine dependent) */
677 int minDev
; /* minor device number currently open */
678 #if defined(CONFIG_ATARI) || defined(CONFIG_PMAC)
679 int bal
; /* balance factor for expanding (not volume!) */
680 u_long data
; /* data for expanding */
681 #endif /* CONFIG_ATARI */
684 static struct sound_settings sound
;
688 static void *AtaAlloc(unsigned int size
, int flags
) __init
;
689 static void AtaFree(void *, unsigned int size
) __init
;
690 static int AtaIrqInit(void) __init
;
692 static void AtaIrqCleanUp(void);
694 static int AtaSetBass(int bass
);
695 static int AtaSetTreble(int treble
);
696 static void TTSilence(void);
697 static void TTInit(void);
698 static int TTSetFormat(int format
);
699 static int TTSetVolume(int volume
);
700 static int TTSetGain(int gain
);
701 static void FalconSilence(void);
702 static void FalconInit(void);
703 static int FalconSetFormat(int format
);
704 static int FalconSetVolume(int volume
);
705 static void ata_sq_play_next_frame(int index
);
706 static void AtaPlay(void);
707 static void ata_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
);
708 #endif /* CONFIG_ATARI */
711 static void *AmiAlloc(unsigned int size
, int flags
) __init
;
712 static void AmiFree(void *, unsigned int) __init
;
713 static int AmiIrqInit(void) __init
;
715 static void AmiIrqCleanUp(void);
717 static void AmiSilence(void);
718 static void AmiInit(void);
719 static int AmiSetFormat(int format
);
720 static int AmiSetVolume(int volume
);
721 static int AmiSetTreble(int treble
);
722 static void ami_sq_play_next_frame(int index
);
723 static void AmiPlay(void);
724 static void ami_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
);
725 #endif /* CONFIG_AMIGA */
728 static void *PMacAlloc(unsigned int size
, int flags
) __init
;
729 static void PMacFree(void *ptr
, unsigned int size
) __init
;
730 static int PMacIrqInit(void) __init
;
732 static void PMacIrqCleanup(void);
734 static void PMacSilence(void);
735 static void PMacInit(void);
736 static void PMacPlay(void);
737 static int PMacSetFormat(int format
);
738 static int PMacSetVolume(int volume
);
739 static void pmac_awacs_tx_intr(int irq
, void *devid
, struct pt_regs
*regs
);
740 static void pmac_awacs_intr(int irq
, void *devid
, struct pt_regs
*regs
);
741 static void awacs_write(int val
);
742 static int awacs_get_volume(int reg
, int lshift
);
743 static int awacs_volume_setter(int volume
, int n
, int mute
, int lshift
);
744 static void awacs_mksound(unsigned int hz
, unsigned int ticks
);
745 static void awacs_nosound(unsigned long xx
);
746 #endif /* CONFIG_PMAC */
748 /*** Mid level stuff *********************************************************/
751 static void sound_silence(void);
752 static void sound_init(void);
753 static int sound_set_format(int format
);
754 static int sound_set_speed(int speed
);
755 static int sound_set_stereo(int stereo
);
756 static int sound_set_volume(int volume
);
758 static int sound_set_bass(int bass
);
759 #endif /* CONFIG_ATARI */
760 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA)
761 static int sound_set_treble(int treble
);
762 #endif /* CONFIG_ATARI || CONFIG_AMIGA */
763 static ssize_t
sound_copy_translate(const u_char
*userPtr
,
765 u_char frame
[], ssize_t
*frameUsed
,
770 * /dev/mixer abstraction
777 static struct sound_mixer mixer
;
780 * Sound queue stuff, the heart of the driver
784 int max_count
, block_size
;
788 /* it shouldn't be necessary to declare any of these volatile */
789 int front
, rear
, count
;
792 * The use of the playing field depends on the hardware
794 * Atari, PMac: The number of frames that are loaded/playing
796 * Amiga: Bit 0 is set: a frame is loaded
797 * Bit 1 is set: a frame is playing
800 struct wait_queue
*write_queue
, *open_queue
, *sync_queue
;
804 int ignore_int
; /* ++TeSche: used for Falcon */
805 #endif /* CONFIG_ATARI */
807 int block_size_half
, block_size_quarter
;
808 #endif /* CONFIG_AMIGA */
811 static struct sound_queue sq
;
813 #define sq_block_address(i) (sq.buffers[i])
814 #define SIGNAL_RECEIVED (signal_pending(current))
815 #define NON_BLOCKING(open_mode) (open_mode & O_NONBLOCK)
816 #define ONE_SECOND HZ /* in jiffies (100ths of a second) */
817 #define NO_TIME_LIMIT 0xffffffff
818 #define SLEEP(queue, time_limit) \
819 current->timeout = jiffies+(time_limit); \
820 interruptible_sleep_on(&queue);
821 #define WAKE_UP(queue) (wake_up_interruptible(&queue))
833 static struct sound_state state
;
835 /*** Common stuff ********************************************************/
837 static long long sound_lseek(struct file
*file
, long long offset
, int orig
);
838 static inline int ioctl_return(int *addr
, int value
)
843 return put_user(value
, addr
)? -EFAULT
: 0;
847 /*** Config & Setup **********************************************************/
850 void dmasound_init(void);
851 void dmasound_setup(char *str
, int *ints
);
854 /*** Translations ************************************************************/
857 /* ++TeSche: radically changed for new expanding purposes...
859 * These two routines now deal with copying/expanding/translating the samples
860 * from user space into our buffer at the right frequency. They take care about
861 * how much data there's actually to read, how much buffer space there is and
862 * to convert samples into the right frequency/encoding. They will only work on
863 * complete samples so it may happen they leave some bytes in the input stream
864 * if the user didn't write a multiple of the current sample size. They both
865 * return the number of bytes they've used from both streams so you may detect
866 * such a situation. Luckily all programs should be able to cope with that.
868 * I think I've optimized anything as far as one can do in plain C, all
869 * variables should fit in registers and the loops are really short. There's
870 * one loop for every possible situation. Writing a more generalized and thus
871 * parameterized loop would only produce slower code. Feel free to optimize
872 * this in assembler if you like. :)
874 * I think these routines belong here because they're not yet really hardware
875 * independent, especially the fact that the Falcon can play 16bit samples
876 * only in stereo is hardcoded in both of them!
878 * ++geert: split in even more functions (one per format)
882 static ssize_t
ata_ct_law(const u_char
*userPtr
, size_t userCount
,
883 u_char frame
[], ssize_t
*frameUsed
,
886 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
888 u_char
*p
= &frame
[*frameUsed
];
890 count
= min(userCount
, frameLeft
);
891 if (sound
.soft
.stereo
)
896 if (get_user(data
, userPtr
++))
906 static ssize_t
ata_ct_s8(const u_char
*userPtr
, size_t userCount
,
907 u_char frame
[], ssize_t
*frameUsed
,
911 void *p
= &frame
[*frameUsed
];
913 count
= min(userCount
, frameLeft
);
914 if (sound
.soft
.stereo
)
917 if (copy_from_user(p
, userPtr
, count
))
924 static ssize_t
ata_ct_u8(const u_char
*userPtr
, size_t userCount
,
925 u_char frame
[], ssize_t
*frameUsed
,
930 if (!sound
.soft
.stereo
) {
931 u_char
*p
= &frame
[*frameUsed
];
932 count
= min(userCount
, frameLeft
);
936 if (get_user(data
, userPtr
++))
942 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
943 count
= min(userCount
, frameLeft
)>>1;
947 if (get_user(data
, ((u_short
*)userPtr
)++))
949 *p
++ = data
^ 0x8080;
958 static ssize_t
ata_ct_s16be(const u_char
*userPtr
, size_t userCount
,
959 u_char frame
[], ssize_t
*frameUsed
,
964 if (!sound
.soft
.stereo
) {
965 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
966 count
= min(userCount
, frameLeft
)>>1;
970 if (get_user(data
, ((u_short
*)userPtr
)++))
976 *frameUsed
+= used
*2;
978 void *p
= (u_short
*)&frame
[*frameUsed
];
979 count
= min(userCount
, frameLeft
) & ~3;
981 if (copy_from_user(p
, userPtr
, count
))
989 static ssize_t
ata_ct_u16be(const u_char
*userPtr
, size_t userCount
,
990 u_char frame
[], ssize_t
*frameUsed
,
995 if (!sound
.soft
.stereo
) {
996 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
997 count
= min(userCount
, frameLeft
)>>1;
1001 if (get_user(data
, ((u_short
*)userPtr
)++))
1008 *frameUsed
+= used
*2;
1010 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1011 count
= min(userCount
, frameLeft
)>>2;
1015 if (get_user(data
, ((u_int
*)userPtr
)++))
1017 *p
++ = data
^ 0x80008000;
1026 static ssize_t
ata_ct_s16le(const u_char
*userPtr
, size_t userCount
,
1027 u_char frame
[], ssize_t
*frameUsed
,
1030 ssize_t count
, used
;
1033 if (!sound
.soft
.stereo
) {
1034 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1035 count
= min(userCount
, frameLeft
)>>1;
1039 if (get_user(data
, ((u_short
*)userPtr
)++))
1041 data
= le2be16(data
);
1046 *frameUsed
+= used
*2;
1048 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1049 count
= min(userCount
, frameLeft
)>>2;
1053 if (get_user(data
, ((u_int
*)userPtr
)++))
1055 data
= le2be16dbl(data
);
1065 static ssize_t
ata_ct_u16le(const u_char
*userPtr
, size_t userCount
,
1066 u_char frame
[], ssize_t
*frameUsed
,
1069 ssize_t count
, used
;
1072 if (!sound
.soft
.stereo
) {
1073 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1074 count
= min(userCount
, frameLeft
)>>1;
1078 if (get_user(data
, ((u_short
*)userPtr
)++))
1080 data
= le2be16(data
) ^ 0x8000;
1084 *frameUsed
+= used
*2;
1086 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1087 count
= min(userCount
, frameLeft
)>>2;
1091 if (get_user(data
, ((u_int
*)userPtr
)++))
1093 data
= le2be16dbl(data
) ^ 0x80008000;
1103 static ssize_t
ata_ctx_law(const u_char
*userPtr
, size_t userCount
,
1104 u_char frame
[], ssize_t
*frameUsed
,
1107 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
1108 /* this should help gcc to stuff everything into registers */
1109 long bal
= sound
.bal
;
1110 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1111 ssize_t used
, usedf
;
1115 if (!sound
.soft
.stereo
) {
1116 u_char
*p
= &frame
[*frameUsed
];
1117 u_char data
= sound
.data
;
1123 if (get_user(c
, userPtr
++))
1135 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1136 u_short data
= sound
.data
;
1137 while (frameLeft
>= 2) {
1142 if (get_user(c
, userPtr
++))
1144 data
= table
[c
] << 8;
1145 if (get_user(c
, userPtr
++))
1159 *frameUsed
+= usedf
-frameLeft
;
1164 static ssize_t
ata_ctx_s8(const u_char
*userPtr
, size_t userCount
,
1165 u_char frame
[], ssize_t
*frameUsed
,
1168 /* this should help gcc to stuff everything into registers */
1169 long bal
= sound
.bal
;
1170 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1171 ssize_t used
, usedf
;
1175 if (!sound
.soft
.stereo
) {
1176 u_char
*p
= &frame
[*frameUsed
];
1177 u_char data
= sound
.data
;
1182 if (get_user(data
, userPtr
++))
1193 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1194 u_short data
= sound
.data
;
1195 while (frameLeft
>= 2) {
1199 if (get_user(data
, ((u_short
*)userPtr
)++))
1212 *frameUsed
+= usedf
-frameLeft
;
1217 static ssize_t
ata_ctx_u8(const u_char
*userPtr
, size_t userCount
,
1218 u_char frame
[], ssize_t
*frameUsed
,
1221 /* this should help gcc to stuff everything into registers */
1222 long bal
= sound
.bal
;
1223 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1224 ssize_t used
, usedf
;
1228 if (!sound
.soft
.stereo
) {
1229 u_char
*p
= &frame
[*frameUsed
];
1230 u_char data
= sound
.data
;
1235 if (get_user(data
, userPtr
++))
1247 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1248 u_short data
= sound
.data
;
1249 while (frameLeft
>= 2) {
1253 if (get_user(data
, ((u_short
*)userPtr
)++))
1267 *frameUsed
+= usedf
-frameLeft
;
1272 static ssize_t
ata_ctx_s16be(const u_char
*userPtr
, size_t userCount
,
1273 u_char frame
[], ssize_t
*frameUsed
,
1276 /* this should help gcc to stuff everything into registers */
1277 long bal
= sound
.bal
;
1278 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1279 ssize_t used
, usedf
;
1283 if (!sound
.soft
.stereo
) {
1284 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1285 u_short data
= sound
.data
;
1286 while (frameLeft
>= 4) {
1290 if (get_user(data
, ((u_short
*)userPtr
)++))
1302 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1303 u_long data
= sound
.data
;
1304 while (frameLeft
>= 4) {
1308 if (get_user(data
, ((u_int
*)userPtr
)++))
1321 *frameUsed
+= usedf
-frameLeft
;
1326 static ssize_t
ata_ctx_u16be(const u_char
*userPtr
, size_t userCount
,
1327 u_char frame
[], ssize_t
*frameUsed
,
1330 /* this should help gcc to stuff everything into registers */
1331 long bal
= sound
.bal
;
1332 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1333 ssize_t used
, usedf
;
1337 if (!sound
.soft
.stereo
) {
1338 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1339 u_short data
= sound
.data
;
1340 while (frameLeft
>= 4) {
1344 if (get_user(data
, ((u_short
*)userPtr
)++))
1357 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1358 u_long data
= sound
.data
;
1359 while (frameLeft
>= 4) {
1363 if (get_user(data
, ((u_int
*)userPtr
)++))
1377 *frameUsed
+= usedf
-frameLeft
;
1382 static ssize_t
ata_ctx_s16le(const u_char
*userPtr
, size_t userCount
,
1383 u_char frame
[], ssize_t
*frameUsed
,
1386 /* this should help gcc to stuff everything into registers */
1387 long bal
= sound
.bal
;
1388 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1389 ssize_t used
, usedf
;
1393 if (!sound
.soft
.stereo
) {
1394 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1395 u_short data
= sound
.data
;
1396 while (frameLeft
>= 4) {
1400 if (get_user(data
, ((u_short
*)userPtr
)++))
1402 data
= le2be16(data
);
1413 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1414 u_long data
= sound
.data
;
1415 while (frameLeft
>= 4) {
1419 if (get_user(data
, ((u_int
*)userPtr
)++))
1421 data
= le2be16dbl(data
);
1433 *frameUsed
+= usedf
-frameLeft
;
1438 static ssize_t
ata_ctx_u16le(const u_char
*userPtr
, size_t userCount
,
1439 u_char frame
[], ssize_t
*frameUsed
,
1442 /* this should help gcc to stuff everything into registers */
1443 long bal
= sound
.bal
;
1444 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1445 ssize_t used
, usedf
;
1449 if (!sound
.soft
.stereo
) {
1450 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1451 u_short data
= sound
.data
;
1452 while (frameLeft
>= 4) {
1456 if (get_user(data
, ((u_short
*)userPtr
)++))
1458 data
= le2be16(data
) ^ 0x8000;
1469 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1470 u_long data
= sound
.data
;
1471 while (frameLeft
>= 4) {
1475 if (get_user(data
, ((u_int
*)userPtr
)++))
1477 data
= le2be16dbl(data
) ^ 0x80008000;
1489 *frameUsed
+= usedf
-frameLeft
;
1492 #endif /* CONFIG_ATARI */
1496 static ssize_t
ami_ct_law(const u_char
*userPtr
, size_t userCount
,
1497 u_char frame
[], ssize_t
*frameUsed
,
1500 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
1501 ssize_t count
, used
;
1503 if (!sound
.soft
.stereo
) {
1504 u_char
*p
= &frame
[*frameUsed
];
1505 count
= min(userCount
, frameLeft
) & ~1;
1509 if (get_user(data
, userPtr
++))
1515 u_char
*left
= &frame
[*frameUsed
>>1];
1516 u_char
*right
= left
+sq
.block_size_half
;
1517 count
= min(userCount
, frameLeft
)>>1 & ~1;
1521 if (get_user(data
, userPtr
++))
1523 *left
++ = table
[data
];
1524 if (get_user(data
, userPtr
++))
1526 *right
++ = table
[data
];
1535 static ssize_t
ami_ct_s8(const u_char
*userPtr
, size_t userCount
,
1536 u_char frame
[], ssize_t
*frameUsed
, ssize_t frameLeft
)
1538 ssize_t count
, used
;
1540 if (!sound
.soft
.stereo
) {
1541 void *p
= &frame
[*frameUsed
];
1542 count
= min(userCount
, frameLeft
) & ~1;
1544 if (copy_from_user(p
, userPtr
, count
))
1547 u_char
*left
= &frame
[*frameUsed
>>1];
1548 u_char
*right
= left
+sq
.block_size_half
;
1549 count
= min(userCount
, frameLeft
)>>1 & ~1;
1552 if (get_user(*left
++, userPtr
++)
1553 || get_user(*right
++, userPtr
++))
1563 static ssize_t
ami_ct_u8(const u_char
*userPtr
, size_t userCount
,
1564 u_char frame
[], ssize_t
*frameUsed
, ssize_t frameLeft
)
1566 ssize_t count
, used
;
1568 if (!sound
.soft
.stereo
) {
1569 char *p
= &frame
[*frameUsed
];
1570 count
= min(userCount
, frameLeft
) & ~1;
1574 if (get_user(data
, userPtr
++))
1580 u_char
*left
= &frame
[*frameUsed
>>1];
1581 u_char
*right
= left
+sq
.block_size_half
;
1582 count
= min(userCount
, frameLeft
)>>1 & ~1;
1586 if (get_user(data
, userPtr
++))
1588 *left
++ = data
^ 0x80;
1589 if (get_user(data
, userPtr
++))
1591 *right
++ = data
^ 0x80;
1600 static ssize_t
ami_ct_s16be(const u_char
*userPtr
, size_t userCount
,
1601 u_char frame
[], ssize_t
*frameUsed
,
1604 ssize_t count
, used
;
1607 if (!sound
.soft
.stereo
) {
1608 u_char
*high
= &frame
[*frameUsed
>>1];
1609 u_char
*low
= high
+sq
.block_size_half
;
1610 count
= min(userCount
, frameLeft
)>>1 & ~1;
1613 if (get_user(data
, ((u_short
*)userPtr
)++))
1616 *low
++ = (data
>>2) & 0x3f;
1620 u_char
*lefth
= &frame
[*frameUsed
>>2];
1621 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1622 u_char
*righth
= lefth
+sq
.block_size_half
;
1623 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1624 count
= min(userCount
, frameLeft
)>>2 & ~1;
1627 if (get_user(data
, ((u_short
*)userPtr
)++))
1630 *leftl
++ = (data
>>2) & 0x3f;
1631 if (get_user(data
, ((u_short
*)userPtr
)++))
1633 *righth
++ = data
>>8;
1634 *rightl
++ = (data
>>2) & 0x3f;
1643 static ssize_t
ami_ct_u16be(const u_char
*userPtr
, size_t userCount
,
1644 u_char frame
[], ssize_t
*frameUsed
,
1647 ssize_t count
, used
;
1650 if (!sound
.soft
.stereo
) {
1651 u_char
*high
= &frame
[*frameUsed
>>1];
1652 u_char
*low
= high
+sq
.block_size_half
;
1653 count
= min(userCount
, frameLeft
)>>1 & ~1;
1656 if (get_user(data
, ((u_short
*)userPtr
)++))
1660 *low
++ = (data
>>2) & 0x3f;
1664 u_char
*lefth
= &frame
[*frameUsed
>>2];
1665 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1666 u_char
*righth
= lefth
+sq
.block_size_half
;
1667 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1668 count
= min(userCount
, frameLeft
)>>2 & ~1;
1671 if (get_user(data
, ((u_short
*)userPtr
)++))
1675 *leftl
++ = (data
>>2) & 0x3f;
1676 if (get_user(data
, ((u_short
*)userPtr
)++))
1679 *righth
++ = data
>>8;
1680 *rightl
++ = (data
>>2) & 0x3f;
1689 static ssize_t
ami_ct_s16le(const u_char
*userPtr
, size_t userCount
,
1690 u_char frame
[], ssize_t
*frameUsed
,
1693 ssize_t count
, used
;
1696 if (!sound
.soft
.stereo
) {
1697 u_char
*high
= &frame
[*frameUsed
>>1];
1698 u_char
*low
= high
+sq
.block_size_half
;
1699 count
= min(userCount
, frameLeft
)>>1 & ~1;
1702 if (get_user(data
, ((u_short
*)userPtr
)++))
1704 data
= le2be16(data
);
1706 *low
++ = (data
>>2) & 0x3f;
1710 u_char
*lefth
= &frame
[*frameUsed
>>2];
1711 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1712 u_char
*righth
= lefth
+sq
.block_size_half
;
1713 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1714 count
= min(userCount
, frameLeft
)>>2 & ~1;
1717 if (get_user(data
, ((u_short
*)userPtr
)++))
1719 data
= le2be16(data
);
1721 *leftl
++ = (data
>>2) & 0x3f;
1722 if (get_user(data
, ((u_short
*)userPtr
)++))
1724 data
= le2be16(data
);
1725 *righth
++ = data
>>8;
1726 *rightl
++ = (data
>>2) & 0x3f;
1735 static ssize_t
ami_ct_u16le(const u_char
*userPtr
, size_t userCount
,
1736 u_char frame
[], ssize_t
*frameUsed
,
1739 ssize_t count
, used
;
1742 if (!sound
.soft
.stereo
) {
1743 u_char
*high
= &frame
[*frameUsed
>>1];
1744 u_char
*low
= high
+sq
.block_size_half
;
1745 count
= min(userCount
, frameLeft
)>>1 & ~1;
1748 if (get_user(data
, ((u_short
*)userPtr
)++))
1750 data
= le2be16(data
) ^ 0x8000;
1752 *low
++ = (data
>>2) & 0x3f;
1756 u_char
*lefth
= &frame
[*frameUsed
>>2];
1757 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1758 u_char
*righth
= lefth
+sq
.block_size_half
;
1759 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1760 count
= min(userCount
, frameLeft
)>>2 & ~1;
1763 if (get_user(data
, ((u_short
*)userPtr
)++))
1765 data
= le2be16(data
) ^ 0x8000;
1767 *leftl
++ = (data
>>2) & 0x3f;
1768 if (get_user(data
, ((u_short
*)userPtr
)++))
1770 data
= le2be16(data
) ^ 0x8000;
1771 *righth
++ = data
>>8;
1772 *rightl
++ = (data
>>2) & 0x3f;
1779 #endif /* CONFIG_AMIGA */
1782 static ssize_t
pmac_ct_law(const u_char
*userPtr
, size_t userCount
,
1783 u_char frame
[], ssize_t
*frameUsed
,
1786 short *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma16
: alaw2dma16
;
1787 ssize_t count
, used
;
1788 short *p
= (short *) &frame
[*frameUsed
];
1789 int val
, stereo
= sound
.soft
.stereo
;
1794 used
= count
= min(userCount
, frameLeft
);
1797 if (get_user(data
, userPtr
++))
1802 if (get_user(data
, userPtr
++))
1809 *frameUsed
+= used
* 4;
1810 return stereo
? used
* 2: used
;
1814 static ssize_t
pmac_ct_s8(const u_char
*userPtr
, size_t userCount
,
1815 u_char frame
[], ssize_t
*frameUsed
,
1818 ssize_t count
, used
;
1819 short *p
= (short *) &frame
[*frameUsed
];
1820 int val
, stereo
= sound
.soft
.stereo
;
1825 used
= count
= min(userCount
, frameLeft
);
1828 if (get_user(data
, userPtr
++))
1833 if (get_user(data
, userPtr
++))
1840 *frameUsed
+= used
* 4;
1841 return stereo
? used
* 2: used
;
1845 static ssize_t
pmac_ct_u8(const u_char
*userPtr
, size_t userCount
,
1846 u_char frame
[], ssize_t
*frameUsed
,
1849 ssize_t count
, used
;
1850 short *p
= (short *) &frame
[*frameUsed
];
1851 int val
, stereo
= sound
.soft
.stereo
;
1856 used
= count
= min(userCount
, frameLeft
);
1859 if (get_user(data
, userPtr
++))
1861 val
= (data
^ 0x80) << 8;
1864 if (get_user(data
, userPtr
++))
1866 val
= (data
^ 0x80) << 8;
1871 *frameUsed
+= used
* 4;
1872 return stereo
? used
* 2: used
;
1876 static ssize_t
pmac_ct_s16(const u_char
*userPtr
, size_t userCount
,
1877 u_char frame
[], ssize_t
*frameUsed
,
1880 ssize_t count
, used
;
1881 int stereo
= sound
.soft
.stereo
;
1882 short *fp
= (short *) &frame
[*frameUsed
];
1885 userCount
>>= (stereo
? 2: 1);
1886 used
= count
= min(userCount
, frameLeft
);
1888 short *up
= (short *) userPtr
;
1891 if (get_user(data
, up
++))
1898 if (copy_from_user(fp
, userPtr
, count
* 4))
1901 *frameUsed
+= used
* 4;
1902 return stereo
? used
* 4: used
* 2;
1905 static ssize_t
pmac_ct_u16(const u_char
*userPtr
, size_t userCount
,
1906 u_char frame
[], ssize_t
*frameUsed
,
1909 ssize_t count
, used
;
1910 int mask
= (sound
.soft
.format
== AFMT_U16_LE
? 0x0080: 0x8000);
1911 int stereo
= sound
.soft
.stereo
;
1912 short *fp
= (short *) &frame
[*frameUsed
];
1913 short *up
= (short *) userPtr
;
1916 userCount
>>= (stereo
? 2: 1);
1917 used
= count
= min(userCount
, frameLeft
);
1920 if (get_user(data
, up
++))
1925 if (get_user(data
, up
++))
1932 *frameUsed
+= used
* 4;
1933 return stereo
? used
* 4: used
* 2;
1937 static ssize_t
pmac_ctx_law(const u_char
*userPtr
, size_t userCount
,
1938 u_char frame
[], ssize_t
*frameUsed
,
1941 unsigned short *table
= (unsigned short *)
1942 (sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma16
: alaw2dma16
);
1943 unsigned int data
= sound
.data
;
1944 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
1945 int bal
= sound
.bal
;
1946 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1948 int stereo
= sound
.soft
.stereo
;
1960 if (get_user(c
, userPtr
++))
1964 if (get_user(c
, userPtr
++))
1966 data
= (data
<< 16) + table
[c
];
1968 data
= (data
<< 16) + data
;
1978 *frameUsed
+= (ftotal
- frameLeft
) * 4;
1979 utotal
-= userCount
;
1980 return stereo
? utotal
* 2: utotal
;
1984 static ssize_t
pmac_ctx_s8(const u_char
*userPtr
, size_t userCount
,
1985 u_char frame
[], ssize_t
*frameUsed
,
1988 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
1989 unsigned int data
= sound
.data
;
1990 int bal
= sound
.bal
;
1991 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1992 int stereo
= sound
.soft
.stereo
;
2005 if (get_user(c
, userPtr
++))
2009 if (get_user(c
, userPtr
++))
2011 data
= (data
<< 16) + (c
<< 8);
2013 data
= (data
<< 16) + data
;
2023 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2024 utotal
-= userCount
;
2025 return stereo
? utotal
* 2: utotal
;
2029 static ssize_t
pmac_ctx_u8(const u_char
*userPtr
, size_t userCount
,
2030 u_char frame
[], ssize_t
*frameUsed
,
2033 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2034 unsigned int data
= sound
.data
;
2035 int bal
= sound
.bal
;
2036 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2037 int stereo
= sound
.soft
.stereo
;
2050 if (get_user(c
, userPtr
++))
2052 data
= (c
^ 0x80) << 8;
2054 if (get_user(c
, userPtr
++))
2056 data
= (data
<< 16) + ((c
^ 0x80) << 8);
2058 data
= (data
<< 16) + data
;
2068 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2069 utotal
-= userCount
;
2070 return stereo
? utotal
* 2: utotal
;
2074 static ssize_t
pmac_ctx_s16(const u_char
*userPtr
, size_t userCount
,
2075 u_char frame
[], ssize_t
*frameUsed
,
2078 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2079 unsigned int data
= sound
.data
;
2080 unsigned short *up
= (unsigned short *) userPtr
;
2081 int bal
= sound
.bal
;
2082 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2083 int stereo
= sound
.soft
.stereo
;
2096 if (get_user(data
, up
++))
2099 if (get_user(c
, up
++))
2101 data
= (data
<< 16) + c
;
2103 data
= (data
<< 16) + data
;
2113 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2114 utotal
-= userCount
;
2115 return stereo
? utotal
* 4: utotal
* 2;
2119 static ssize_t
pmac_ctx_u16(const u_char
*userPtr
, size_t userCount
,
2120 u_char frame
[], ssize_t
*frameUsed
,
2123 int mask
= (sound
.soft
.format
== AFMT_U16_LE
? 0x0080: 0x8000);
2124 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2125 unsigned int data
= sound
.data
;
2126 unsigned short *up
= (unsigned short *) userPtr
;
2127 int bal
= sound
.bal
;
2128 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2129 int stereo
= sound
.soft
.stereo
;
2142 if (get_user(data
, up
++))
2146 if (get_user(c
, up
++))
2148 data
= (data
<< 16) + (c
^ mask
);
2150 data
= (data
<< 16) + data
;
2160 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2161 utotal
-= userCount
;
2162 return stereo
? utotal
* 4: utotal
* 2;
2165 #endif /* CONFIG_PMAC */
2169 static TRANS transTTNormal
= {
2170 ata_ct_law
, ata_ct_law
, ata_ct_s8
, ata_ct_u8
, NULL
, NULL
, NULL
, NULL
2173 static TRANS transTTExpanding
= {
2174 ata_ctx_law
, ata_ctx_law
, ata_ctx_s8
, ata_ctx_u8
, NULL
, NULL
, NULL
, NULL
2177 static TRANS transFalconNormal
= {
2178 ata_ct_law
, ata_ct_law
, ata_ct_s8
, ata_ct_u8
,
2179 ata_ct_s16be
, ata_ct_u16be
, ata_ct_s16le
, ata_ct_u16le
2182 static TRANS transFalconExpanding
= {
2183 ata_ctx_law
, ata_ctx_law
, ata_ctx_s8
, ata_ctx_u8
,
2184 ata_ctx_s16be
, ata_ctx_u16be
, ata_ctx_s16le
, ata_ctx_u16le
2186 #endif /* CONFIG_ATARI */
2189 static TRANS transAmiga
= {
2190 ami_ct_law
, ami_ct_law
, ami_ct_s8
, ami_ct_u8
,
2191 ami_ct_s16be
, ami_ct_u16be
, ami_ct_s16le
, ami_ct_u16le
2193 #endif /* CONFIG_AMIGA */
2196 static TRANS transAwacsNormal
= {
2197 pmac_ct_law
, pmac_ct_law
, pmac_ct_s8
, pmac_ct_u8
,
2198 pmac_ct_s16
, pmac_ct_u16
, pmac_ct_s16
, pmac_ct_u16
2201 static TRANS transAwacsExpand
= {
2202 pmac_ctx_law
, pmac_ctx_law
, pmac_ctx_s8
, pmac_ctx_u8
,
2203 pmac_ctx_s16
, pmac_ctx_u16
, pmac_ctx_s16
, pmac_ctx_u16
2205 #endif /* CONFIG_PMAC */
2207 /*** Low level stuff *********************************************************/
2216 static void *AtaAlloc(unsigned int size
, int flags
)
2218 return( atari_stram_alloc( size
, NULL
, "dmasound" ));
2221 static void AtaFree(void *obj
, unsigned int size
)
2223 atari_stram_free( obj
);
2226 static int AtaIrqInit(void)
2228 /* Set up timer A. Timer A
2229 will receive a signal upon end of playing from the sound
2230 hardware. Furthermore Timer A is able to count events
2231 and will cause an interrupt after a programmed number
2232 of events. So all we need to keep the music playing is
2233 to provide the sound hardware with new data upon
2234 an interrupt from timer A. */
2235 mfp
.tim_ct_a
= 0; /* ++roman: Stop timer before programming! */
2236 mfp
.tim_dt_a
= 1; /* Cause interrupt after first event. */
2237 mfp
.tim_ct_a
= 8; /* Turn on event counting. */
2238 /* Register interrupt handler. */
2239 request_irq(IRQ_MFP_TIMA
, ata_sq_interrupt
, IRQ_TYPE_SLOW
,
2240 "DMA sound", ata_sq_interrupt
);
2241 mfp
.int_en_a
|= 0x20; /* Turn interrupt on. */
2242 mfp
.int_mk_a
|= 0x20;
2247 static void AtaIrqCleanUp(void)
2249 mfp
.tim_ct_a
= 0; /* stop timer */
2250 mfp
.int_en_a
&= ~0x20; /* turn interrupt off */
2251 free_irq(IRQ_MFP_TIMA
, ata_sq_interrupt
);
2256 #define TONE_VOXWARE_TO_DB(v) \
2257 (((v) < 0) ? -12 : ((v) > 100) ? 12 : ((v) - 50) * 6 / 25)
2258 #define TONE_DB_TO_VOXWARE(v) (((v) * 25 + ((v) > 0 ? 5 : -5)) / 6 + 50)
2261 static int AtaSetBass(int bass
)
2263 sound
.bass
= TONE_VOXWARE_TO_DB(bass
);
2264 atari_microwire_cmd(MW_LM1992_BASS(sound
.bass
));
2265 return(TONE_DB_TO_VOXWARE(sound
.bass
));
2269 static int AtaSetTreble(int treble
)
2271 sound
.treble
= TONE_VOXWARE_TO_DB(treble
);
2272 atari_microwire_cmd(MW_LM1992_TREBLE(sound
.treble
));
2273 return(TONE_DB_TO_VOXWARE(sound
.treble
));
2283 static void TTSilence(void)
2285 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2286 atari_microwire_cmd(MW_LM1992_PSG_HIGH
); /* mix in PSG signal 1:1 */
2290 static void TTInit(void)
2293 const int freq
[4] = {50066, 25033, 12517, 6258};
2295 /* search a frequency that fits into the allowed error range */
2298 for (i
= 0; i
< arraysize(freq
); i
++)
2299 /* this isn't as much useful for a TT than for a Falcon, but
2300 * then it doesn't hurt very much to implement it for a TT too.
2302 if ((100 * abs(sound
.soft
.speed
- freq
[i
]) / freq
[i
]) < catchRadius
)
2305 sound
.soft
.speed
= freq
[idx
];
2306 sound
.trans
= &transTTNormal
;
2308 sound
.trans
= &transTTExpanding
;
2311 sound
.hard
= sound
.soft
;
2313 if (sound
.hard
.speed
> 50066) {
2314 /* we would need to squeeze the sound, but we won't do that */
2315 sound
.hard
.speed
= 50066;
2316 mode
= DMASND_MODE_50KHZ
;
2317 sound
.trans
= &transTTNormal
;
2318 } else if (sound
.hard
.speed
> 25033) {
2319 sound
.hard
.speed
= 50066;
2320 mode
= DMASND_MODE_50KHZ
;
2321 } else if (sound
.hard
.speed
> 12517) {
2322 sound
.hard
.speed
= 25033;
2323 mode
= DMASND_MODE_25KHZ
;
2324 } else if (sound
.hard
.speed
> 6258) {
2325 sound
.hard
.speed
= 12517;
2326 mode
= DMASND_MODE_12KHZ
;
2328 sound
.hard
.speed
= 6258;
2329 mode
= DMASND_MODE_6KHZ
;
2332 tt_dmasnd
.mode
= (sound
.hard
.stereo
?
2333 DMASND_MODE_STEREO
: DMASND_MODE_MONO
) |
2334 DMASND_MODE_8BIT
| mode
;
2336 sound
.bal
= -sound
.soft
.speed
;
2340 static int TTSetFormat(int format
)
2342 /* TT sound DMA supports only 8bit modes */
2346 return(sound
.soft
.format
);
2356 sound
.soft
.format
= format
;
2357 sound
.soft
.size
= 8;
2358 if (sound
.minDev
== SND_DEV_DSP
) {
2359 sound
.dsp
.format
= format
;
2368 #define VOLUME_VOXWARE_TO_DB(v) \
2369 (((v) < 0) ? -40 : ((v) > 100) ? 0 : ((v) * 2) / 5 - 40)
2370 #define VOLUME_DB_TO_VOXWARE(v) ((((v) + 40) * 5 + 1) / 2)
2373 static int TTSetVolume(int volume
)
2375 sound
.volume_left
= VOLUME_VOXWARE_TO_DB(volume
& 0xff);
2376 atari_microwire_cmd(MW_LM1992_BALLEFT(sound
.volume_left
));
2377 sound
.volume_right
= VOLUME_VOXWARE_TO_DB((volume
& 0xff00) >> 8);
2378 atari_microwire_cmd(MW_LM1992_BALRIGHT(sound
.volume_right
));
2379 return(VOLUME_DB_TO_VOXWARE(sound
.volume_left
) |
2380 (VOLUME_DB_TO_VOXWARE(sound
.volume_right
) << 8));
2384 #define GAIN_VOXWARE_TO_DB(v) \
2385 (((v) < 0) ? -80 : ((v) > 100) ? 0 : ((v) * 4) / 5 - 80)
2386 #define GAIN_DB_TO_VOXWARE(v) ((((v) + 80) * 5 + 1) / 4)
2388 static int TTSetGain(int gain
)
2390 sound
.gain
= GAIN_VOXWARE_TO_DB(gain
);
2391 atari_microwire_cmd(MW_LM1992_VOLUME(sound
.gain
));
2392 return GAIN_DB_TO_VOXWARE(sound
.gain
);
2402 static void FalconSilence(void)
2404 /* stop playback, set sample rate 50kHz for PSG sound */
2405 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2406 tt_dmasnd
.mode
= DMASND_MODE_50KHZ
| DMASND_MODE_STEREO
| DMASND_MODE_8BIT
;
2407 tt_dmasnd
.int_div
= 0; /* STE compatible divider */
2408 tt_dmasnd
.int_ctrl
= 0x0;
2409 tt_dmasnd
.cbar_src
= 0x0000; /* no matrix inputs */
2410 tt_dmasnd
.cbar_dst
= 0x0000; /* no matrix outputs */
2411 tt_dmasnd
.dac_src
= 1; /* connect ADC to DAC, disconnect matrix */
2412 tt_dmasnd
.adc_src
= 3; /* ADC Input = PSG */
2416 static void FalconInit(void)
2418 int divider
, i
, idx
;
2419 const int freq
[8] = {49170, 32780, 24585, 19668, 16390, 12292, 9834, 8195};
2421 /* search a frequency that fits into the allowed error range */
2424 for (i
= 0; i
< arraysize(freq
); i
++)
2425 /* if we will tolerate 3% error 8000Hz->8195Hz (2.38%) would
2426 * be playable without expanding, but that now a kernel runtime
2429 if ((100 * abs(sound
.soft
.speed
- freq
[i
]) / freq
[i
]) < catchRadius
)
2432 sound
.soft
.speed
= freq
[idx
];
2433 sound
.trans
= &transFalconNormal
;
2435 sound
.trans
= &transFalconExpanding
;
2438 sound
.hard
= sound
.soft
;
2440 if (sound
.hard
.size
== 16) {
2441 /* the Falcon can play 16bit samples only in stereo */
2442 sound
.hard
.stereo
= 1;
2445 if (sound
.hard
.speed
> 49170) {
2446 /* we would need to squeeze the sound, but we won't do that */
2447 sound
.hard
.speed
= 49170;
2449 sound
.trans
= &transFalconNormal
;
2450 } else if (sound
.hard
.speed
> 32780) {
2451 sound
.hard
.speed
= 49170;
2453 } else if (sound
.hard
.speed
> 24585) {
2454 sound
.hard
.speed
= 32780;
2456 } else if (sound
.hard
.speed
> 19668) {
2457 sound
.hard
.speed
= 24585;
2459 } else if (sound
.hard
.speed
> 16390) {
2460 sound
.hard
.speed
= 19668;
2462 } else if (sound
.hard
.speed
> 12292) {
2463 sound
.hard
.speed
= 16390;
2465 } else if (sound
.hard
.speed
> 9834) {
2466 sound
.hard
.speed
= 12292;
2468 } else if (sound
.hard
.speed
> 8195) {
2469 sound
.hard
.speed
= 9834;
2472 sound
.hard
.speed
= 8195;
2475 tt_dmasnd
.int_div
= divider
;
2477 /* Setup Falcon sound DMA for playback */
2478 tt_dmasnd
.int_ctrl
= 0x4; /* Timer A int at play end */
2479 tt_dmasnd
.track_select
= 0x0; /* play 1 track, track 1 */
2480 tt_dmasnd
.cbar_src
= 0x0001; /* DMA(25MHz) --> DAC */
2481 tt_dmasnd
.cbar_dst
= 0x0000;
2482 tt_dmasnd
.rec_track_select
= 0;
2483 tt_dmasnd
.dac_src
= 2; /* connect matrix to DAC */
2484 tt_dmasnd
.adc_src
= 0; /* ADC Input = Mic */
2486 tt_dmasnd
.mode
= (sound
.hard
.stereo
?
2487 DMASND_MODE_STEREO
: DMASND_MODE_MONO
) |
2488 ((sound
.hard
.size
== 8) ?
2489 DMASND_MODE_8BIT
: DMASND_MODE_16BIT
) |
2492 sound
.bal
= -sound
.soft
.speed
;
2496 static int FalconSetFormat(int format
)
2499 /* Falcon sound DMA supports 8bit and 16bit modes */
2503 return(sound
.soft
.format
);
2521 sound
.soft
.format
= format
;
2522 sound
.soft
.size
= size
;
2523 if (sound
.minDev
== SND_DEV_DSP
) {
2524 sound
.dsp
.format
= format
;
2525 sound
.dsp
.size
= sound
.soft
.size
;
2534 /* This is for the Falcon output *attenuation* in 1.5dB steps,
2535 * i.e. output level from 0 to -22.5dB in -1.5dB steps.
2537 #define VOLUME_VOXWARE_TO_ATT(v) \
2538 ((v) < 0 ? 15 : (v) > 100 ? 0 : 15 - (v) * 3 / 20)
2539 #define VOLUME_ATT_TO_VOXWARE(v) (100 - (v) * 20 / 3)
2542 static int FalconSetVolume(int volume
)
2544 sound
.volume_left
= VOLUME_VOXWARE_TO_ATT(volume
& 0xff);
2545 sound
.volume_right
= VOLUME_VOXWARE_TO_ATT((volume
& 0xff00) >> 8);
2546 tt_dmasnd
.output_atten
= sound
.volume_left
<< 8 | sound
.volume_right
<< 4;
2547 return(VOLUME_ATT_TO_VOXWARE(sound
.volume_left
) |
2548 VOLUME_ATT_TO_VOXWARE(sound
.volume_right
) << 8);
2552 static void ata_sq_play_next_frame(int index
)
2556 /* used by AtaPlay() if all doubts whether there really is something
2557 * to be played are already wiped out.
2559 start
= sq_block_address(sq
.front
);
2560 end
= start
+((sq
.count
== index
) ? sq
.rear_size
: sq
.block_size
);
2561 /* end might not be a legal virtual address. */
2562 DMASNDSetEnd(VTOP(end
- 1) + 1);
2563 DMASNDSetBase(VTOP(start
));
2564 /* Since only an even number of samples per frame can
2565 be played, we might lose one byte here. (TO DO) */
2566 sq
.front
= (sq
.front
+1) % sq
.max_count
;
2568 tt_dmasnd
.ctrl
= DMASND_CTRL_ON
| DMASND_CTRL_REPEAT
;
2572 static void AtaPlay(void)
2574 /* ++TeSche: Note that sq.playing is no longer just a flag but holds
2575 * the number of frames the DMA is currently programmed for instead,
2576 * may be 0, 1 (currently being played) or 2 (pre-programmed).
2578 * Changes done to sq.count and sq.playing are a bit more subtle again
2579 * so now I must admit I also prefer disabling the irq here rather
2580 * than considering all possible situations. But the point is that
2581 * disabling the irq doesn't have any bad influence on this version of
2582 * the driver as we benefit from having pre-programmed the DMA
2583 * wherever possible: There's no need to reload the DMA at the exact
2584 * time of an interrupt but only at some time while the pre-programmed
2587 atari_disable_irq(IRQ_MFP_TIMA
);
2589 if (sq
.playing
== 2 || /* DMA is 'full' */
2590 sq
.count
<= 0) { /* nothing to do */
2591 atari_enable_irq(IRQ_MFP_TIMA
);
2595 if (sq
.playing
== 0) {
2596 /* looks like there's nothing 'in' the DMA yet, so try
2597 * to put two frames into it (at least one is available).
2599 if (sq
.count
== 1 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2600 /* hmmm, the only existing frame is not
2601 * yet filled and we're not syncing?
2603 atari_enable_irq(IRQ_MFP_TIMA
);
2606 ata_sq_play_next_frame(1);
2607 if (sq
.count
== 1) {
2608 /* no more frames */
2609 atari_enable_irq(IRQ_MFP_TIMA
);
2612 if (sq
.count
== 2 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2613 /* hmmm, there were two frames, but the second
2614 * one is not yet filled and we're not syncing?
2616 atari_enable_irq(IRQ_MFP_TIMA
);
2619 ata_sq_play_next_frame(2);
2621 /* there's already a frame being played so we may only stuff
2622 * one new into the DMA, but even if this may be the last
2623 * frame existing the previous one is still on sq.count.
2625 if (sq
.count
== 2 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2626 /* hmmm, the only existing frame is not
2627 * yet filled and we're not syncing?
2629 atari_enable_irq(IRQ_MFP_TIMA
);
2632 ata_sq_play_next_frame(2);
2634 atari_enable_irq(IRQ_MFP_TIMA
);
2638 static void ata_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
)
2641 /* ++TeSche: if you should want to test this... */
2643 if (sq
.playing
== 2)
2645 /* simulate losing an interrupt */
2651 if (sq
.ignore_int
&& (sound
.mach
.type
== DMASND_FALCON
)) {
2652 /* ++TeSche: Falcon only: ignore first irq because it comes
2653 * immediately after starting a frame. after that, irqs come
2654 * (almost) like on the TT.
2661 /* playing was interrupted and sq_reset() has already cleared
2662 * the sq variables, so better don't do anything here.
2664 WAKE_UP(sq
.sync_queue
);
2668 /* Probably ;) one frame is finished. Well, in fact it may be that a
2669 * pre-programmed one is also finished because there has been a long
2670 * delay in interrupt delivery and we've completely lost one, but
2671 * there's no way to detect such a situation. In such a case the last
2672 * frame will be played more than once and the situation will recover
2673 * as soon as the irq gets through.
2679 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2683 WAKE_UP(sq
.write_queue
);
2684 /* At least one block of the queue is free now
2685 so wake up a writing process blocked because
2688 if ((sq
.playing
!= 1) || (sq
.count
!= 1))
2689 /* We must be a bit carefully here: sq.count indicates the
2690 * number of buffers used and not the number of frames to
2691 * be played. If sq.count==1 and sq.playing==1 that means
2692 * the only remaining frame was already programmed earlier
2693 * (and is currently running) so we mustn't call AtaPlay()
2694 * here, otherwise we'll play one frame too much.
2698 if (!sq
.playing
) WAKE_UP(sq
.sync_queue
);
2699 /* We are not playing after AtaPlay(), so there
2700 is nothing to play any more. Wake up a process
2701 waiting for audio output to drain. */
2703 #endif /* CONFIG_ATARI */
2713 static void *AmiAlloc(unsigned int size
, int flags
)
2715 return(amiga_chip_alloc((long)size
));
2718 static void AmiFree(void *obj
, unsigned int size
)
2720 amiga_chip_free (obj
);
2723 static int AmiIrqInit(void)
2725 /* turn off DMA for audio channels */
2726 custom
.dmacon
= AMI_AUDIO_OFF
;
2728 /* Register interrupt handler. */
2729 if (request_irq(IRQ_AMIGA_AUD0
, ami_sq_interrupt
, 0,
2730 "DMA sound", ami_sq_interrupt
))
2736 static void AmiIrqCleanUp(void)
2738 /* turn off DMA for audio channels */
2739 custom
.dmacon
= AMI_AUDIO_OFF
;
2740 /* release the interrupt */
2741 free_irq(IRQ_AMIGA_AUD0
, ami_sq_interrupt
);
2745 static void AmiSilence(void)
2747 /* turn off DMA for audio channels */
2748 custom
.dmacon
= AMI_AUDIO_OFF
;
2752 static void AmiInit(void)
2758 if (sound
.soft
.speed
)
2759 period
= amiga_colorclock
/sound
.soft
.speed
-1;
2761 period
= amiga_audio_min_period
;
2762 sound
.hard
= sound
.soft
;
2763 sound
.trans
= &transAmiga
;
2765 if (period
< amiga_audio_min_period
) {
2766 /* we would need to squeeze the sound, but we won't do that */
2767 period
= amiga_audio_min_period
;
2768 } else if (period
> 65535) {
2771 sound
.hard
.speed
= amiga_colorclock
/(period
+1);
2773 for (i
= 0; i
< 4; i
++)
2774 custom
.aud
[i
].audper
= period
;
2775 amiga_audio_period
= period
;
2777 AmiSetTreble(50); /* recommended for newer amiga models */
2781 static int AmiSetFormat(int format
)
2785 /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
2789 return(sound
.soft
.format
);
2807 sound
.soft
.format
= format
;
2808 sound
.soft
.size
= size
;
2809 if (sound
.minDev
== SND_DEV_DSP
) {
2810 sound
.dsp
.format
= format
;
2811 sound
.dsp
.size
= sound
.soft
.size
;
2819 #define VOLUME_VOXWARE_TO_AMI(v) \
2820 (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
2821 #define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
2823 static int AmiSetVolume(int volume
)
2825 sound
.volume_left
= VOLUME_VOXWARE_TO_AMI(volume
& 0xff);
2826 custom
.aud
[0].audvol
= sound
.volume_left
;
2827 sound
.volume_right
= VOLUME_VOXWARE_TO_AMI((volume
& 0xff00) >> 8);
2828 custom
.aud
[1].audvol
= sound
.volume_right
;
2829 return(VOLUME_AMI_TO_VOXWARE(sound
.volume_left
) |
2830 (VOLUME_AMI_TO_VOXWARE(sound
.volume_right
) << 8));
2833 static int AmiSetTreble(int treble
)
2835 sound
.treble
= treble
;
2844 #define AMI_PLAY_LOADED 1
2845 #define AMI_PLAY_PLAYING 2
2846 #define AMI_PLAY_MASK 3
2849 static void ami_sq_play_next_frame(int index
)
2851 u_char
*start
, *ch0
, *ch1
, *ch2
, *ch3
;
2854 /* used by AmiPlay() if all doubts whether there really is something
2855 * to be played are already wiped out.
2857 start
= sq_block_address(sq
.front
);
2858 size
= (sq
.count
== index
? sq
.rear_size
: sq
.block_size
)>>1;
2860 if (sound
.hard
.stereo
) {
2862 ch1
= start
+sq
.block_size_half
;
2868 if (sound
.hard
.size
== 8) {
2869 custom
.aud
[0].audlc
= (u_short
*)ZTWO_PADDR(ch0
);
2870 custom
.aud
[0].audlen
= size
;
2871 custom
.aud
[1].audlc
= (u_short
*)ZTWO_PADDR(ch1
);
2872 custom
.aud
[1].audlen
= size
;
2873 custom
.dmacon
= AMI_AUDIO_8
;
2876 custom
.aud
[0].audlc
= (u_short
*)ZTWO_PADDR(ch0
);
2877 custom
.aud
[0].audlen
= size
;
2878 custom
.aud
[1].audlc
= (u_short
*)ZTWO_PADDR(ch1
);
2879 custom
.aud
[1].audlen
= size
;
2880 if (sound
.volume_left
== 64 && sound
.volume_right
== 64) {
2881 /* We can play pseudo 14-bit only with the maximum volume */
2882 ch3
= ch0
+sq
.block_size_quarter
;
2883 ch2
= ch1
+sq
.block_size_quarter
;
2884 custom
.aud
[2].audvol
= 1; /* we are being affected by the beeps */
2885 custom
.aud
[3].audvol
= 1; /* restoring volume here helps a bit */
2886 custom
.aud
[2].audlc
= (u_short
*)ZTWO_PADDR(ch2
);
2887 custom
.aud
[2].audlen
= size
;
2888 custom
.aud
[3].audlc
= (u_short
*)ZTWO_PADDR(ch3
);
2889 custom
.aud
[3].audlen
= size
;
2890 custom
.dmacon
= AMI_AUDIO_14
;
2892 custom
.dmacon
= AMI_AUDIO_8
;
2894 sq
.front
= (sq
.front
+1) % sq
.max_count
;
2895 sq
.playing
|= AMI_PLAY_LOADED
;
2899 static void AmiPlay(void)
2903 custom
.intena
= IF_AUD0
;
2905 if (sq
.playing
& AMI_PLAY_LOADED
) {
2906 /* There's already a frame loaded */
2907 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2911 if (sq
.playing
& AMI_PLAY_PLAYING
)
2912 /* Increase threshold: frame 1 is already being played */
2915 if (sq
.count
< minframes
) {
2917 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2921 if (sq
.count
<= minframes
&& sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2922 /* hmmm, the only existing frame is not
2923 * yet filled and we're not syncing?
2925 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2929 ami_sq_play_next_frame(minframes
);
2931 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2935 static void ami_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
)
2940 /* Playing was interrupted and sq_reset() has already cleared
2941 * the sq variables, so better don't do anything here.
2943 WAKE_UP(sq
.sync_queue
);
2947 if (sq
.playing
& AMI_PLAY_PLAYING
) {
2948 /* We've just finished a frame */
2950 WAKE_UP(sq
.write_queue
);
2953 if (sq
.playing
& AMI_PLAY_LOADED
)
2954 /* Increase threshold: frame 1 is already being played */
2957 /* Shift the flags */
2958 sq
.playing
= (sq
.playing
<<1) & AMI_PLAY_MASK
;
2961 /* No frame is playing, disable audio DMA */
2962 custom
.dmacon
= AMI_AUDIO_OFF
;
2964 if (sq
.count
>= minframes
)
2965 /* Try to play the next frame */
2969 /* Nothing to play anymore.
2970 Wake up a process waiting for audio output to drain. */
2971 WAKE_UP(sq
.sync_queue
);
2973 #endif /* CONFIG_AMIGA */
2978 * PCI PowerMac, with AWACS and DBDMA.
2981 static void *PMacAlloc(unsigned int size
, int flags
)
2983 return kmalloc(size
, flags
);
2986 static void PMacFree(void *ptr
, unsigned int size
)
2991 static int PMacIrqInit(void)
2993 if (request_irq(awacs_irq
, pmac_awacs_intr
, 0, "AWACS", 0)
2994 || request_irq(awacs_tx_irq
, pmac_awacs_tx_intr
, 0, "AWACS out", 0))
3000 static void PMacIrqCleanup(void)
3002 /* turn off output dma */
3003 out_le32(&awacs_txdma
->control
, RUN
<<16);
3004 /* disable interrupts from awacs interface */
3005 out_le32(&awacs
->control
, in_le32(&awacs
->control
) & 0xfff);
3006 free_irq(awacs_irq
, pmac_awacs_intr
);
3007 free_irq(awacs_tx_irq
, pmac_awacs_tx_intr
);
3008 kfree(awacs_tx_cmd_space
);
3011 kd_mksound
= orig_mksound
;
3015 static void PMacSilence(void)
3017 /* turn off output dma */
3018 out_le32(&awacs_txdma
->control
, RUN
<<16);
3021 static int awacs_freqs
[8] = {
3022 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
3025 static void PMacInit(void)
3029 switch (sound
.soft
.format
) {
3032 sound
.hard
.format
= AFMT_S16_LE
;
3035 sound
.hard
.format
= AFMT_S16_BE
;
3038 sound
.hard
.stereo
= 1;
3039 sound
.hard
.size
= 16;
3042 * If we have a sample rate which is within catchRadius percent
3043 * of the requested value, we don't have to expand the samples.
3044 * Otherwise choose the next higher rate.
3048 tolerance
= catchRadius
* awacs_freqs
[--i
] / 100;
3049 } while (sound
.soft
.speed
> awacs_freqs
[i
] + tolerance
&& i
> 0);
3050 if (sound
.soft
.speed
>= awacs_freqs
[i
] - tolerance
)
3051 sound
.trans
= &transAwacsNormal
;
3053 sound
.trans
= &transAwacsExpand
;
3054 sound
.hard
.speed
= awacs_freqs
[i
];
3055 awacs_rate_index
= i
;
3058 out_le32(&awacs
->control
, MASK_IEPC
| MASK_IEE
| (i
<< 8) | 0x11);
3059 awacs_reg
[1] = (awacs_reg
[1] & ~MASK_SAMPLERATE
) | (i
<< 3);
3060 awacs_write(awacs_reg
[1] | MASK_ADDR1
);
3061 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3063 sound
.bal
= -sound
.soft
.speed
;
3066 static int PMacSetFormat(int format
)
3072 return sound
.soft
.format
;
3086 printk(KERN_ERR
"dmasound: unknown format 0x%x, using AFMT_U8\n",
3092 sound
.soft
.format
= format
;
3093 sound
.soft
.size
= size
;
3094 if (sound
.minDev
== SND_DEV_DSP
) {
3095 sound
.dsp
.format
= format
;
3096 sound
.dsp
.size
= size
;
3104 #define AWACS_VOLUME_TO_MASK(x) (15 - ((((x) - 1) * 15) / 99))
3105 #define AWACS_MASK_TO_VOLUME(y) (100 - ((y) * 99 / 15))
3107 static int awacs_get_volume(int reg
, int lshift
)
3111 volume
= AWACS_MASK_TO_VOLUME((reg
>> lshift
) & 0xf);
3112 volume
|= AWACS_MASK_TO_VOLUME(reg
& 0xf) << 8;
3116 static int awacs_volume_setter(int volume
, int n
, int mute
, int lshift
)
3120 if (mute
&& volume
== 0) {
3121 r1
= awacs_reg
[1] | mute
;
3123 r1
= awacs_reg
[1] & ~mute
;
3124 rn
= awacs_reg
[n
] & ~(0xf | (0xf << lshift
));
3125 rn
|= ((AWACS_VOLUME_TO_MASK(volume
& 0xff) & 0xf) << lshift
);
3126 rn
|= AWACS_VOLUME_TO_MASK((volume
>> 8) & 0xff) & 0xf;
3128 awacs_write((n
<< 12) | rn
);
3129 volume
= awacs_get_volume(rn
, lshift
);
3131 if (r1
!= awacs_reg
[1]) {
3133 awacs_write(r1
| MASK_ADDR1
);
3138 static int PMacSetVolume(int volume
)
3140 return awacs_volume_setter(volume
, 2, MASK_AMUTE
, 6);
3143 static void PMacPlay(void)
3145 volatile struct dbdma_cmd
*cp
;
3147 unsigned long flags
;
3149 save_flags(flags
); cli();
3151 /* sound takes precedence over beeps */
3152 out_le32(&awacs_txdma
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16);
3153 out_le32(&awacs
->control
,
3154 (in_le32(&awacs
->control
) & ~0x1f00)
3155 || (awacs_rate_index
<< 8));
3156 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3159 i
= sq
.front
+ sq
.playing
;
3160 if (i
>= sq
.max_count
)
3162 while (sq
.playing
< 2 && sq
.playing
< sq
.count
) {
3163 count
= (sq
.count
== sq
.playing
+ 1)? sq
.rear_size
: sq
.block_size
;
3164 if (count
< sq
.block_size
&& !sq
.syncing
)
3165 /* last block not yet filled, and we're not syncing. */
3167 cp
= &awacs_tx_cmds
[i
];
3168 st_le16(&cp
->req_count
, count
);
3169 st_le16(&cp
->xfer_status
, 0);
3170 if (++i
>= sq
.max_count
)
3172 out_le16(&awacs_tx_cmds
[i
].command
, DBDMA_STOP
);
3173 out_le16(&cp
->command
, OUTPUT_MORE
+ INTR_ALWAYS
);
3174 if (sq
.playing
== 0)
3175 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(cp
));
3176 out_le32(&awacs_txdma
->control
, ((RUN
|WAKE
) << 16) + (RUN
|WAKE
));
3179 restore_flags(flags
);
3183 pmac_awacs_tx_intr(int irq
, void *devid
, struct pt_regs
*regs
)
3187 volatile struct dbdma_cmd
*cp
;
3189 while (sq
.playing
> 0) {
3190 cp
= &awacs_tx_cmds
[i
];
3191 stat
= ld_le16(&cp
->xfer_status
);
3192 if ((stat
& ACTIVE
) == 0)
3193 break; /* this frame is still going */
3196 if (++i
>= sq
.max_count
)
3200 WAKE_UP(sq
.write_queue
);
3206 WAKE_UP(sq
.sync_queue
);
3210 pmac_awacs_intr(int irq
, void *devid
, struct pt_regs
*regs
)
3212 int ctrl
= in_le32(&awacs
->control
);
3214 if (ctrl
& MASK_PORTCHG
) {
3215 /* do something when headphone is plugged/unplugged? */
3217 if (ctrl
& MASK_CNTLERR
) {
3218 printk(KERN_ERR
"AWACS: error, status = %x\n",
3219 in_le32(&awacs
->codec_stat
));
3221 /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */
3222 out_le32(&awacs
->control
, ctrl
);
3226 awacs_write(int val
)
3228 while (in_le32(&awacs
->codec_ctrl
) & MASK_NEWECMD
)
3229 ; /* XXX should have timeout */
3230 out_le32(&awacs
->codec_ctrl
, val
);
3233 static void awacs_nosound(unsigned long xx
)
3235 unsigned long flags
;
3237 save_flags(flags
); cli();
3239 st_le16(&beep_dbdma_cmd
->command
, DBDMA_STOP
);
3242 restore_flags(flags
);
3245 static struct timer_list beep_timer
= {
3246 NULL
, NULL
, 0, 0, awacs_nosound
3249 static void awacs_mksound(unsigned int hz
, unsigned int ticks
)
3251 unsigned long flags
;
3252 int srate
= awacs_freqs
[BEEP_SPEED
];
3253 int period
, ncycles
, nsamples
;
3256 static int beep_hz_cache
;
3257 static int beep_nsamples_cache
;
3258 static int beep_volume_cache
;
3260 if (hz
<= srate
/ BEEP_BUFLEN
|| hz
> srate
/ 2) {
3262 /* this is a hack for broken X server code */
3266 /* cancel beep currently playing */
3271 save_flags(flags
); cli();
3272 del_timer(&beep_timer
);
3274 beep_timer
.expires
= jiffies
+ ticks
;
3275 add_timer(&beep_timer
);
3277 if (beep_playing
|| sq
.playing
|| beep_buf
== NULL
) {
3278 restore_flags(flags
);
3279 return; /* too hard, sorry :-( */
3282 st_le16(&beep_dbdma_cmd
->command
, OUTPUT_MORE
+ BR_ALWAYS
);
3283 restore_flags(flags
);
3285 if (hz
== beep_hz_cache
&& beep_volume
== beep_volume_cache
) {
3286 nsamples
= beep_nsamples_cache
;
3288 period
= srate
* 256 / hz
; /* fixed point */
3289 ncycles
= BEEP_BUFLEN
* 256 / period
;
3290 nsamples
= (period
* ncycles
) >> 8;
3291 f
= ncycles
* 65536 / nsamples
;
3294 for (i
= 0; i
< nsamples
; ++i
, p
+= 2) {
3295 p
[0] = p
[1] = beep_wform
[j
>> 8] * beep_volume
;
3296 j
= (j
+ f
) & 0xffff;
3299 beep_volume_cache
= beep_volume
;
3300 beep_nsamples_cache
= nsamples
;
3303 st_le16(&beep_dbdma_cmd
->req_count
, nsamples
*4);
3304 st_le16(&beep_dbdma_cmd
->xfer_status
, 0);
3305 st_le32(&beep_dbdma_cmd
->cmd_dep
, virt_to_bus(beep_dbdma_cmd
));
3306 st_le32(&beep_dbdma_cmd
->phy_addr
, virt_to_bus(beep_buf
));
3308 save_flags(flags
); cli();
3309 if (beep_playing
) { /* i.e. haven't been terminated already */
3310 out_le32(&awacs_txdma
->control
, (RUN
|WAKE
|FLUSH
|PAUSE
) << 16);
3311 out_le32(&awacs
->control
,
3312 (in_le32(&awacs
->control
) & ~0x1f00)
3313 | (BEEP_SPEED
<< 8));
3314 out_le32(&awacs
->byteswap
, 0);
3315 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(beep_dbdma_cmd
));
3316 out_le32(&awacs_txdma
->control
, RUN
| (RUN
<< 16));
3318 restore_flags(flags
);
3321 #ifdef CONFIG_PMAC_PBOOK
3323 * Save state when going to sleep, restore it afterwards.
3325 static int awacs_sleep_notify(struct notifier_block
*this,
3326 unsigned long code
, void *x
)
3330 /* XXX we should stop any dma in progress when going to sleep
3331 and restart it when we wake. */
3335 out_le32(&awacs
->control
, MASK_IEPC
| MASK_IEE
|
3336 (awacs_rate_index
<< 8) | 0x11);
3337 awacs_write(awacs_reg
[0] | MASK_ADDR0
);
3338 awacs_write(awacs_reg
[1] | MASK_ADDR1
);
3339 awacs_write(awacs_reg
[2] | MASK_ADDR2
);
3340 awacs_write(awacs_reg
[4] | MASK_ADDR4
);
3341 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3345 #endif /* CONFIG_PMAC_PBOOK */
3347 #endif /* CONFIG_PMAC */
3349 /*** Machine definitions *****************************************************/
3353 static MACHINE machTT
= {
3354 DMASND_TT
, AtaAlloc
, AtaFree
, AtaIrqInit
,
3358 TTInit
, TTSilence
, TTSetFormat
, TTSetVolume
,
3359 AtaSetBass
, AtaSetTreble
, TTSetGain
,
3363 static MACHINE machFalcon
= {
3364 DMASND_FALCON
, AtaAlloc
, AtaFree
, AtaIrqInit
,
3368 FalconInit
, FalconSilence
, FalconSetFormat
, FalconSetVolume
,
3369 AtaSetBass
, AtaSetTreble
, NULL
,
3372 #endif /* CONFIG_ATARI */
3375 static MACHINE machAmiga
= {
3376 DMASND_AMIGA
, AmiAlloc
, AmiFree
, AmiIrqInit
,
3380 AmiInit
, AmiSilence
, AmiSetFormat
, AmiSetVolume
,
3381 NULL
, AmiSetTreble
, NULL
,
3384 #endif /* CONFIG_AMIGA */
3387 static MACHINE machPMac
= {
3388 DMASND_AWACS
, PMacAlloc
, PMacFree
, PMacIrqInit
,
3392 PMacInit
, PMacSilence
, PMacSetFormat
, PMacSetVolume
,
3393 NULL
, NULL
, NULL
, /* bass, treble, gain */
3396 #endif /* CONFIG_AMIGA */
3399 /*** Mid level stuff *********************************************************/
3402 static void sound_silence(void)
3404 /* update hardware settings one more */
3405 (*sound
.mach
.init
)();
3407 (*sound
.mach
.silence
)();
3411 static void sound_init(void)
3413 (*sound
.mach
.init
)();
3417 static int sound_set_format(int format
)
3419 return(*sound
.mach
.setFormat
)(format
);
3423 static int sound_set_speed(int speed
)
3426 return(sound
.soft
.speed
);
3428 sound
.soft
.speed
= speed
;
3429 (*sound
.mach
.init
)();
3430 if (sound
.minDev
== SND_DEV_DSP
)
3431 sound
.dsp
.speed
= sound
.soft
.speed
;
3433 return(sound
.soft
.speed
);
3437 static int sound_set_stereo(int stereo
)
3440 return(sound
.soft
.stereo
);
3442 stereo
= !!stereo
; /* should be 0 or 1 now */
3444 sound
.soft
.stereo
= stereo
;
3445 if (sound
.minDev
== SND_DEV_DSP
)
3446 sound
.dsp
.stereo
= stereo
;
3447 (*sound
.mach
.init
)();
3453 static int sound_set_volume(int volume
)
3455 return(*sound
.mach
.setVolume
)(volume
);
3460 static int sound_set_bass(int bass
)
3462 return(sound
.mach
.setBass
? (*sound
.mach
.setBass
)(bass
) : 50);
3465 static int sound_set_gain(int gain
)
3467 return sound
.mach
.setGain
? sound
.mach
.setGain(gain
) : 100;
3469 #endif /* CONFIG_ATARI */
3471 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA)
3472 static int sound_set_treble(int treble
)
3474 return(sound
.mach
.setTreble
? (*sound
.mach
.setTreble
)(treble
) : 50);
3476 #endif /* CONFIG_ATARI || CONFIG_AMIGA */
3479 static ssize_t
sound_copy_translate(const u_char
*userPtr
,
3481 u_char frame
[], ssize_t
*frameUsed
,
3484 ssize_t (*ct_func
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
) = NULL
;
3486 switch (sound
.soft
.format
) {
3488 ct_func
= sound
.trans
->ct_ulaw
;
3491 ct_func
= sound
.trans
->ct_alaw
;
3494 ct_func
= sound
.trans
->ct_s8
;
3497 ct_func
= sound
.trans
->ct_u8
;
3500 ct_func
= sound
.trans
->ct_s16be
;
3503 ct_func
= sound
.trans
->ct_u16be
;
3506 ct_func
= sound
.trans
->ct_s16le
;
3509 ct_func
= sound
.trans
->ct_u16le
;
3513 return ct_func(userPtr
, userCount
, frame
, frameUsed
, frameLeft
);
3520 * /dev/mixer abstraction
3524 #define RECLEVEL_VOXWARE_TO_GAIN(v) \
3525 ((v) < 0 ? 0 : (v) > 100 ? 15 : (v) * 3 / 20)
3526 #define RECLEVEL_GAIN_TO_VOXWARE(v) (((v) * 20 + 2) / 3)
3529 static int mixer_open(struct inode
*inode
, struct file
*file
)
3537 static int mixer_release(struct inode
*inode
, struct file
*file
)
3545 static int mixer_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
3549 switch (sound
.mach
.type
) {
3553 case SOUND_MIXER_READ_DEVMASK
:
3554 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_MIC
| SOUND_MASK_SPEAKER
);
3555 case SOUND_MIXER_READ_RECMASK
:
3556 return IOCTL_OUT(arg
, SOUND_MASK_MIC
);
3557 case SOUND_MIXER_READ_STEREODEVS
:
3558 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_MIC
);
3559 case SOUND_MIXER_READ_CAPS
:
3560 return IOCTL_OUT(arg
, SOUND_CAP_EXCL_INPUT
);
3561 case SOUND_MIXER_READ_VOLUME
:
3562 return IOCTL_OUT(arg
,
3563 VOLUME_ATT_TO_VOXWARE(sound
.volume_left
) |
3564 VOLUME_ATT_TO_VOXWARE(sound
.volume_right
) << 8);
3565 case SOUND_MIXER_WRITE_MIC
:
3566 IOCTL_IN(arg
, data
);
3567 tt_dmasnd
.input_gain
=
3568 RECLEVEL_VOXWARE_TO_GAIN(data
& 0xff) << 4 |
3569 RECLEVEL_VOXWARE_TO_GAIN(data
>> 8 & 0xff);
3570 /* fall thru, return set value */
3571 case SOUND_MIXER_READ_MIC
:
3572 return IOCTL_OUT(arg
,
3573 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd
.input_gain
>> 4 & 0xf) |
3574 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd
.input_gain
& 0xf) << 8);
3575 case SOUND_MIXER_READ_SPEAKER
:
3579 sound_ym
.rd_data_reg_sel
= 14;
3580 porta
= sound_ym
.rd_data_reg_sel
;
3582 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3584 case SOUND_MIXER_WRITE_VOLUME
:
3585 IOCTL_IN(arg
, data
);
3586 return IOCTL_OUT(arg
, sound_set_volume(data
));
3587 case SOUND_MIXER_WRITE_SPEAKER
:
3590 IOCTL_IN(arg
, data
);
3592 sound_ym
.rd_data_reg_sel
= 14;
3593 porta
= (sound_ym
.rd_data_reg_sel
& ~0x40) |
3594 (data
< 50 ? 0x40 : 0);
3595 sound_ym
.wd_data
= porta
;
3597 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3604 case SOUND_MIXER_READ_DEVMASK
:
3605 return IOCTL_OUT(arg
,
3606 SOUND_MASK_VOLUME
| SOUND_MASK_TREBLE
| SOUND_MASK_BASS
|
3607 (MACH_IS_TT
? SOUND_MASK_SPEAKER
: 0));
3608 case SOUND_MIXER_READ_RECMASK
:
3609 return IOCTL_OUT(arg
, 0);
3610 case SOUND_MIXER_READ_STEREODEVS
:
3611 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
);
3612 case SOUND_MIXER_READ_VOLUME
:
3613 return IOCTL_OUT(arg
,
3614 VOLUME_DB_TO_VOXWARE(sound
.volume_left
) |
3615 (VOLUME_DB_TO_VOXWARE(sound
.volume_right
) << 8));
3616 case SOUND_MIXER_READ_BASS
:
3617 return IOCTL_OUT(arg
, TONE_DB_TO_VOXWARE(sound
.bass
));
3618 case SOUND_MIXER_READ_TREBLE
:
3619 return IOCTL_OUT(arg
, TONE_DB_TO_VOXWARE(sound
.treble
));
3620 case SOUND_MIXER_READ_OGAIN
:
3621 return IOCTL_OUT(arg
, GAIN_DB_TO_VOXWARE(sound
.gain
));
3622 case SOUND_MIXER_READ_SPEAKER
:
3627 sound_ym
.rd_data_reg_sel
= 14;
3628 porta
= sound_ym
.rd_data_reg_sel
;
3630 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3634 case SOUND_MIXER_WRITE_VOLUME
:
3635 IOCTL_IN(arg
, data
);
3636 return IOCTL_OUT(arg
, sound_set_volume(data
));
3637 case SOUND_MIXER_WRITE_BASS
:
3638 IOCTL_IN(arg
, data
);
3639 return IOCTL_OUT(arg
, sound_set_bass(data
));
3640 case SOUND_MIXER_WRITE_TREBLE
:
3641 IOCTL_IN(arg
, data
);
3642 return IOCTL_OUT(arg
, sound_set_treble(data
));
3643 case SOUND_MIXER_WRITE_OGAIN
:
3644 IOCTL_IN(arg
, data
);
3645 return IOCTL_OUT(arg
, sound_set_gain(data
));
3646 case SOUND_MIXER_WRITE_SPEAKER
:
3649 IOCTL_IN(arg
, data
);
3651 sound_ym
.rd_data_reg_sel
= 14;
3652 porta
= (sound_ym
.rd_data_reg_sel
& ~0x40) |
3653 (data
< 50 ? 0x40 : 0);
3654 sound_ym
.wd_data
= porta
;
3656 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3660 #endif /* CONFIG_ATARI */
3665 case SOUND_MIXER_READ_DEVMASK
:
3666 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_TREBLE
);
3667 case SOUND_MIXER_READ_RECMASK
:
3668 return IOCTL_OUT(arg
, 0);
3669 case SOUND_MIXER_READ_STEREODEVS
:
3670 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
);
3671 case SOUND_MIXER_READ_VOLUME
:
3672 return IOCTL_OUT(arg
,
3673 VOLUME_AMI_TO_VOXWARE(sound
.volume_left
) |
3674 VOLUME_AMI_TO_VOXWARE(sound
.volume_right
) << 8);
3675 case SOUND_MIXER_WRITE_VOLUME
:
3676 IOCTL_IN(arg
, data
);
3677 return IOCTL_OUT(arg
, sound_set_volume(data
));
3678 case SOUND_MIXER_READ_TREBLE
:
3679 return IOCTL_OUT(arg
, sound
.treble
);
3680 case SOUND_MIXER_WRITE_TREBLE
:
3681 IOCTL_IN(arg
, data
);
3682 return IOCTL_OUT(arg
, sound_set_treble(data
));
3685 #endif /* CONFIG_AMIGA */
3690 case SOUND_MIXER_READ_DEVMASK
:
3691 data
= SOUND_MASK_VOLUME
| SOUND_MASK_SPEAKER
3692 | SOUND_MASK_LINE
| SOUND_MASK_MIC
3693 | SOUND_MASK_CD
| SOUND_MASK_RECLEV
3694 | SOUND_MASK_ALTPCM
;
3695 return IOCTL_OUT(arg
, data
);
3696 case SOUND_MIXER_READ_RECMASK
:
3697 data
= SOUND_MASK_LINE
| SOUND_MASK_MIC
3699 return IOCTL_OUT(arg
, data
);
3700 case SOUND_MIXER_READ_RECSRC
:
3702 if (awacs_reg
[0] & MASK_MUX_AUDIN
)
3703 data
|= SOUND_MASK_LINE
;
3704 if (awacs_reg
[0] & MASK_MUX_MIC
)
3705 data
|= SOUND_MASK_MIC
;
3706 if (awacs_reg
[0] & MASK_MUX_CD
)
3707 data
|= SOUND_MASK_CD
;
3708 return IOCTL_OUT(arg
, data
);
3709 case SOUND_MIXER_WRITE_RECSRC
:
3710 IOCTL_IN(arg
, data
);
3711 data
&= (SOUND_MASK_LINE
3712 | SOUND_MASK_MIC
| SOUND_MASK_CD
);
3713 awacs_reg
[0] &= ~(MASK_MUX_CD
| MASK_MUX_MIC
3715 if (data
& SOUND_MASK_LINE
)
3716 awacs_reg
[0] |= MASK_MUX_AUDIN
;
3717 if (data
& SOUND_MASK_MIC
)
3718 awacs_reg
[0] |= MASK_MUX_MIC
;
3719 if (data
& SOUND_MASK_CD
)
3720 awacs_reg
[0] |= MASK_MUX_CD
;
3721 awacs_write(awacs_reg
[0] | MASK_ADDR0
);
3722 return IOCTL_OUT(arg
, data
);
3723 case SOUND_MIXER_READ_STEREODEVS
:
3724 data
= SOUND_MASK_VOLUME
| SOUND_MASK_SPEAKER
3725 | SOUND_MASK_RECLEV
;
3726 return IOCTL_OUT(arg
, data
);
3727 case SOUND_MIXER_READ_CAPS
:
3728 return IOCTL_OUT(arg
, 0);
3729 case SOUND_MIXER_READ_VOLUME
:
3730 data
= (awacs_reg
[1] & MASK_AMUTE
)? 0:
3731 awacs_get_volume(awacs_reg
[2], 6);
3732 return IOCTL_OUT(arg
, data
);
3733 case SOUND_MIXER_WRITE_VOLUME
:
3734 IOCTL_IN(arg
, data
);
3735 return IOCTL_OUT(arg
, sound_set_volume(data
));
3736 case SOUND_MIXER_READ_SPEAKER
:
3737 data
= (awacs_reg
[1] & MASK_CMUTE
)? 0:
3738 awacs_get_volume(awacs_reg
[4], 6);
3739 return IOCTL_OUT(arg
, data
);
3740 case SOUND_MIXER_WRITE_SPEAKER
:
3741 IOCTL_IN(arg
, data
);
3742 data
= awacs_volume_setter(data
, 4, MASK_CMUTE
, 6);
3743 return IOCTL_OUT(arg
, data
);
3744 case SOUND_MIXER_WRITE_ALTPCM
: /* really bell volume */
3745 IOCTL_IN(arg
, data
);
3746 beep_volume
= data
& 0xff;
3748 case SOUND_MIXER_READ_ALTPCM
:
3749 return IOCTL_OUT(arg
, beep_volume
);
3750 case SOUND_MIXER_WRITE_LINE
:
3751 IOCTL_IN(arg
, data
);
3752 awacs_reg
[0] &= ~MASK_MUX_AUDIN
;
3753 if ((data
& 0xff) >= 50)
3754 awacs_reg
[0] |= MASK_MUX_AUDIN
;
3755 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
3757 case SOUND_MIXER_READ_LINE
:
3758 data
= (awacs_reg
[0] & MASK_MUX_AUDIN
)? 100: 0;
3759 return IOCTL_OUT(arg
, data
);
3760 case SOUND_MIXER_WRITE_MIC
:
3761 IOCTL_IN(arg
, data
);
3763 awacs_reg
[0] &= ~(MASK_MUX_MIC
| MASK_GAINLINE
);
3765 awacs_reg
[0] |= MASK_MUX_MIC
;
3767 awacs_reg
[0] |= MASK_GAINLINE
;
3769 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
3771 case SOUND_MIXER_READ_MIC
:
3772 data
= (awacs_reg
[0] & MASK_MUX_MIC
)?
3773 (awacs_reg
[0] & MASK_GAINLINE
? 100: 50): 0;
3774 return IOCTL_OUT(arg
, data
);
3775 case SOUND_MIXER_WRITE_CD
:
3776 IOCTL_IN(arg
, data
);
3777 awacs_reg
[0] &= ~MASK_MUX_CD
;
3778 if ((data
& 0xff) >= 50)
3779 awacs_reg
[0] |= MASK_MUX_CD
;
3780 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
3782 case SOUND_MIXER_READ_CD
:
3783 data
= (awacs_reg
[0] & MASK_MUX_CD
)? 100: 0;
3784 return IOCTL_OUT(arg
, data
);
3785 case SOUND_MIXER_WRITE_RECLEV
:
3786 IOCTL_IN(arg
, data
);
3787 data
= awacs_volume_setter(data
, 0, 0, 4);
3788 return IOCTL_OUT(arg
, data
);
3789 case SOUND_MIXER_READ_RECLEV
:
3790 data
= awacs_get_volume(awacs_reg
[0], 4);
3791 return IOCTL_OUT(arg
, data
);
3801 static struct file_operations mixer_fops
=
3804 NULL
, /* mixer_read */
3805 NULL
, /* mixer_write */
3806 NULL
, /* mixer_readdir */
3807 NULL
, /* mixer_poll */
3809 NULL
, /* mixer_mmap */
3816 __initfunc(static void mixer_init(void))
3821 mixer_unit
= register_sound_mixer(&mixer_fops
);
3828 switch (sound
.mach
.type
) {
3831 atari_microwire_cmd(MW_LM1992_VOLUME(0));
3832 sound
.volume_left
= 0;
3833 atari_microwire_cmd(MW_LM1992_BALLEFT(0));
3834 sound
.volume_right
= 0;
3835 atari_microwire_cmd(MW_LM1992_BALRIGHT(0));
3836 atari_microwire_cmd(MW_LM1992_TREBLE(0));
3837 atari_microwire_cmd(MW_LM1992_BASS(0));
3840 sound
.volume_left
= (tt_dmasnd
.output_atten
& 0xf00) >> 8;
3841 sound
.volume_right
= (tt_dmasnd
.output_atten
& 0xf0) >> 4;
3843 #endif /* CONFIG_ATARI */
3846 sound
.volume_left
= 64;
3847 sound
.volume_right
= 64;
3848 custom
.aud
[0].audvol
= sound
.volume_left
;
3849 custom
.aud
[3].audvol
= 1; /* For pseudo 14bit */
3850 custom
.aud
[1].audvol
= sound
.volume_right
;
3851 custom
.aud
[2].audvol
= 1; /* For pseudo 14bit */
3854 #endif /* CONFIG_AMIGA */
3860 * Sound queue stuff, the heart of the driver
3864 static void sq_setup(int numBufs
, int bufSize
, char **buffers
)
3868 volatile struct dbdma_cmd
*cp
;
3869 #endif /* CONFIG_PMAC */
3871 sq
.max_count
= numBufs
;
3872 sq
.max_active
= numBufs
;
3873 sq
.block_size
= bufSize
;
3874 sq
.buffers
= buffers
;
3876 sq
.front
= sq
.count
= 0;
3878 sq
.write_queue
= sq
.open_queue
= sq
.sync_queue
= 0;
3886 #endif /* CONFIG_ATARI */
3888 sq
.block_size_half
= sq
.block_size
>>1;
3889 sq
.block_size_quarter
= sq
.block_size_half
>>1;
3890 #endif /* CONFIG_AMIGA */
3893 memset((void *) cp
, 0, (numBufs
+ 1) * sizeof(struct dbdma_cmd
));
3894 for (i
= 0; i
< numBufs
; ++i
, ++cp
) {
3895 st_le32(&cp
->phy_addr
, virt_to_bus(buffers
[i
]));
3897 st_le16(&cp
->command
, DBDMA_NOP
+ BR_ALWAYS
);
3898 st_le32(&cp
->cmd_dep
, virt_to_bus(awacs_tx_cmds
));
3899 out_le32(&awacs_txdma
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16);
3900 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(awacs_tx_cmds
));
3901 #endif /* CONFIG_PMAC */
3904 static void sq_play(void)
3906 (*sound
.mach
.play
)();
3910 /* ++TeSche: radically changed this one too */
3912 static ssize_t
sq_write(struct file
*file
, const char *src
, size_t uLeft
,
3915 ssize_t uWritten
= 0;
3917 ssize_t uUsed
, bUsed
, bLeft
;
3919 /* ++TeSche: Is something like this necessary?
3920 * Hey, that's an honest question! Or does any other part of the
3921 * filesystem already checks this situation? I really don't know.
3926 /* The interrupt doesn't start to play the last, incomplete frame.
3927 * Thus we can append to it without disabling the interrupts! (Note
3928 * also that sq.rear isn't affected by the interrupt.)
3931 if (sq
.count
> 0 && (bLeft
= sq
.block_size
-sq
.rear_size
) > 0) {
3932 dest
= sq_block_address(sq
.rear
);
3933 bUsed
= sq
.rear_size
;
3934 uUsed
= sound_copy_translate(src
, uLeft
, dest
, &bUsed
, bLeft
);
3940 sq
.rear_size
= bUsed
;
3944 while (sq
.count
== sq
.max_active
) {
3946 if (NON_BLOCKING(sq
.open_mode
))
3947 return uWritten
> 0 ? uWritten
: -EAGAIN
;
3948 SLEEP(sq
.write_queue
, ONE_SECOND
);
3949 if (SIGNAL_RECEIVED
)
3950 return uWritten
> 0 ? uWritten
: -EINTR
;
3953 /* Here, we can avoid disabling the interrupt by first
3954 * copying and translating the data, and then updating
3955 * the sq variables. Until this is done, the interrupt
3956 * won't see the new frame and we can work on it
3960 dest
= sq_block_address((sq
.rear
+1) % sq
.max_count
);
3962 bLeft
= sq
.block_size
;
3963 uUsed
= sound_copy_translate(src
, uLeft
, dest
, &bUsed
, bLeft
);
3970 sq
.rear
= (sq
.rear
+1) % sq
.max_count
;
3971 sq
.rear_size
= bUsed
;
3974 } while (bUsed
); /* uUsed may have been 0 */
3978 return uUsed
< 0? uUsed
: uWritten
;
3982 static int sq_open(struct inode
*inode
, struct file
*file
)
3989 if (NON_BLOCKING(file
->f_flags
))
3993 SLEEP(sq
.open_queue
, ONE_SECOND
);
3994 if (SIGNAL_RECEIVED
)
3999 sq_setup(numBufs
, bufSize
<< 10, sound_buffers
);
4000 sq
.open_mode
= file
->f_flags
;
4004 #endif /* CONFIG_ATARI */
4005 sound
.minDev
= MINOR(inode
->i_rdev
) & 0x0f;
4006 sound
.soft
= sound
.dsp
;
4007 sound
.hard
= sound
.dsp
;
4009 if ((MINOR(inode
->i_rdev
) & 0x0f) == SND_DEV_AUDIO
) {
4010 sound_set_speed(8000);
4011 sound_set_stereo(0);
4012 sound_set_format(AFMT_MU_LAW
);
4021 static void sq_reset(void)
4026 sq
.front
= (sq
.rear
+1) % sq
.max_count
;
4030 static int sq_fsync(struct file
*filp
, struct dentry
*dentry
)
4035 sq_play(); /* there may be an incomplete frame waiting */
4037 while (sq
.playing
) {
4038 SLEEP(sq
.sync_queue
, ONE_SECOND
);
4039 if (SIGNAL_RECEIVED
) {
4040 /* While waiting for audio output to drain, an
4041 * interrupt occurred. Stop audio output immediately
4042 * and clear the queue. */
4053 static int sq_release(struct inode
*inode
, struct file
*file
)
4057 rc
= sq_fsync(file
, file
->f_dentry
);
4059 WAKE_UP(sq
.open_queue
);
4060 /* Wake up a process waiting for the queue being released.
4061 * Note: There may be several processes waiting for a call
4062 * to open() returning. */
4064 sound
.soft
= sound
.dsp
;
4065 sound
.hard
= sound
.dsp
;
4073 static int sq_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
4081 case SNDCTL_DSP_RESET
:
4084 case SNDCTL_DSP_POST
:
4085 case SNDCTL_DSP_SYNC
:
4086 return sq_fsync(file
, file
->f_dentry
);
4088 /* ++TeSche: before changing any of these it's
4089 * probably wise to wait until sound playing has
4091 case SNDCTL_DSP_SPEED
:
4092 sq_fsync(file
, file
->f_dentry
);
4093 IOCTL_IN(arg
, data
);
4094 return IOCTL_OUT(arg
, sound_set_speed(data
));
4095 case SNDCTL_DSP_STEREO
:
4096 sq_fsync(file
, file
->f_dentry
);
4097 IOCTL_IN(arg
, data
);
4098 return IOCTL_OUT(arg
, sound_set_stereo(data
));
4099 case SOUND_PCM_WRITE_CHANNELS
:
4100 sq_fsync(file
, file
->f_dentry
);
4101 IOCTL_IN(arg
, data
);
4102 return IOCTL_OUT(arg
, sound_set_stereo(data
-1)+1);
4103 case SNDCTL_DSP_SETFMT
:
4104 sq_fsync(file
, file
->f_dentry
);
4105 IOCTL_IN(arg
, data
);
4106 return IOCTL_OUT(arg
, sound_set_format(data
));
4107 case SNDCTL_DSP_GETFMTS
:
4110 if (sound
.trans
->ct_ulaw
)
4112 if (sound
.trans
->ct_alaw
)
4114 if (sound
.trans
->ct_s8
)
4116 if (sound
.trans
->ct_u8
)
4118 if (sound
.trans
->ct_s16be
)
4120 if (sound
.trans
->ct_u16be
)
4122 if (sound
.trans
->ct_s16le
)
4124 if (sound
.trans
->ct_u16le
)
4127 return IOCTL_OUT(arg
, fmt
);
4128 case SNDCTL_DSP_GETBLKSIZE
:
4129 size
= sq
.block_size
4130 * sound
.soft
.size
* (sound
.soft
.stereo
+ 1)
4131 / (sound
.hard
.size
* (sound
.hard
.stereo
+ 1));
4132 return IOCTL_OUT(arg
, size
);
4133 case SNDCTL_DSP_SUBDIVIDE
:
4135 case SNDCTL_DSP_SETFRAGMENT
:
4136 if (sq
.count
|| sq
.playing
|| sq
.syncing
)
4138 IOCTL_IN(arg
, size
);
4140 if (nbufs
< 2 || nbufs
> numBufs
)
4143 if (size
>= 8 && size
<= 30) {
4145 size
*= sound
.hard
.size
* (sound
.hard
.stereo
+ 1);
4146 size
/= sound
.soft
.size
* (sound
.soft
.stereo
+ 1);
4147 if (size
> (bufSize
<< 10))
4148 size
= bufSize
<< 10;
4150 size
= bufSize
<< 10;
4151 sq_setup(numBufs
, size
, sound_buffers
);
4152 sq
.max_active
= nbufs
;
4156 return mixer_ioctl(inode
, file
, cmd
, arg
);
4163 static struct file_operations sq_fops
=
4168 NULL
, /* sq_readdir */
4178 __initfunc(static void sq_init(void))
4183 sq_unit
= register_sound_dsp(&sq_fops
);
4187 /* whatever you like as startup mode for /dev/dsp,
4188 * (/dev/audio hasn't got a startup mode). note that
4189 * once changed a new open() will *not* restore these!
4191 sound
.dsp
.format
= AFMT_U8
;
4192 sound
.dsp
.stereo
= 0;
4195 /* set minimum rate possible without expanding */
4196 switch (sound
.mach
.type
) {
4199 sound
.dsp
.speed
= 6258;
4202 sound
.dsp
.speed
= 8195;
4204 #endif /* CONFIG_ATARI */
4207 sound
.dsp
.speed
= 8000;
4209 #endif /* CONFIG_AMIGA */
4212 sound
.dsp
.speed
= 8000;
4214 #endif /* CONFIG_PMAC */
4217 /* before the first open to /dev/dsp this wouldn't be set */
4218 sound
.soft
= sound
.dsp
;
4219 sound
.hard
= sound
.dsp
;
4229 /* state.buf should not overflow! */
4231 static int state_open(struct inode
*inode
, struct file
*file
)
4233 char *buffer
= state
.buf
, *mach
= "";
4243 switch (sound
.mach
.type
) {
4249 #endif /* CONFIG_ATARI */
4254 #endif /* CONFIG_AMIGA */
4259 #endif /* CONFIG_PMAC */
4261 len
+= sprintf(buffer
+len
, "%sDMA sound driver:\n", mach
);
4263 len
+= sprintf(buffer
+len
, "\tsound.format = 0x%x", sound
.soft
.format
);
4264 switch (sound
.soft
.format
) {
4266 len
+= sprintf(buffer
+len
, " (mu-law)");
4269 len
+= sprintf(buffer
+len
, " (A-law)");
4272 len
+= sprintf(buffer
+len
, " (unsigned 8 bit)");
4275 len
+= sprintf(buffer
+len
, " (signed 8 bit)");
4278 len
+= sprintf(buffer
+len
, " (signed 16 bit big)");
4281 len
+= sprintf(buffer
+len
, " (unsigned 16 bit big)");
4284 len
+= sprintf(buffer
+len
, " (signed 16 bit little)");
4287 len
+= sprintf(buffer
+len
, " (unsigned 16 bit little)");
4290 len
+= sprintf(buffer
+len
, "\n");
4291 len
+= sprintf(buffer
+len
, "\tsound.speed = %dHz (phys. %dHz)\n",
4292 sound
.soft
.speed
, sound
.hard
.speed
);
4293 len
+= sprintf(buffer
+len
, "\tsound.stereo = 0x%x (%s)\n",
4294 sound
.soft
.stereo
, sound
.soft
.stereo
? "stereo" : "mono");
4295 switch (sound
.mach
.type
) {
4298 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %ddB [-40...0]\n",
4300 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %ddB [-40...0]\n",
4301 sound
.volume_right
);
4302 len
+= sprintf(buffer
+len
, "\tsound.bass = %ddB [-12...+12]\n",
4304 len
+= sprintf(buffer
+len
, "\tsound.treble = %ddB [-12...+12]\n",
4308 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %ddB [-22.5...0]\n",
4310 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %ddB [-22.5...0]\n",
4311 sound
.volume_right
);
4313 #endif /* CONFIG_ATARI */
4316 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %d [0...64]\n",
4318 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %d [0...64]\n",
4319 sound
.volume_right
);
4321 #endif /* CONFIG_AMIGA */
4323 len
+= sprintf(buffer
+len
, "\tsq.block_size = %d sq.max_count = %d"
4324 " sq.max_active = %d\n",
4325 sq
.block_size
, sq
.max_count
, sq
.max_active
);
4326 len
+= sprintf(buffer
+len
, "\tsq.count = %d sq.rear_size = %d\n", sq
.count
,
4328 len
+= sprintf(buffer
+len
, "\tsq.playing = %d sq.syncing = %d\n",
4329 sq
.playing
, sq
.syncing
);
4335 static int state_release(struct inode
*inode
, struct file
*file
)
4343 static ssize_t
state_read(struct file
*file
, char *buf
, size_t count
,
4346 int n
= state
.len
- state
.ptr
;
4351 if (copy_to_user(buf
, &state
.buf
[state
.ptr
], n
))
4358 static struct file_operations state_fops
=
4362 NULL
, /* state_write */
4363 NULL
, /* state_readdir */
4364 NULL
, /* state_poll */
4365 NULL
, /* state_ioctl */
4366 NULL
, /* state_mmap */
4373 __initfunc(static void state_init(void))
4378 state_unit
= register_sound_special(&state_fops
, SND_DEV_STATUS
);
4385 /*** Common stuff ********************************************************/
4387 static long long sound_lseek(struct file
*file
, long long offset
, int orig
)
4393 /*** Config & Setup **********************************************************/
4396 __initfunc(void dmasound_init(void))
4401 struct device_node
*np
;
4405 switch (m68k_machtype
) {
4408 if (ATARIHW_PRESENT(PCM_8BIT
)) {
4409 if (ATARIHW_PRESENT(CODEC
))
4410 sound
.mach
= machFalcon
;
4411 else if (ATARIHW_PRESENT(MICROWIRE
))
4412 sound
.mach
= machTT
;
4415 if ((mfp
.int_en_a
& mfp
.int_mk_a
& 0x20) == 0)
4418 printk("DMA sound driver: Timer A interrupt already in use\n");
4422 #endif /* CONFIG_ATARI */
4425 if (AMIGAHW_PRESENT(AMI_AUDIO
)) {
4426 sound
.mach
= machAmiga
;
4430 #endif /* CONFIG_AMIGA */
4432 #endif /* __mc68000__ */
4436 np
= find_devices("awacs");
4439 * powermac G3 models have a node called "davbus"
4440 * with a child called "sound".
4442 struct device_node
*sound
;
4443 np
= find_devices("davbus");
4444 sound
= find_devices("sound");
4445 if (sound
!= 0 && sound
->parent
== np
) {
4447 sfprop
= (int *) get_property(sound
, "sub-frame", 0);
4448 if (sfprop
!= 0 && *sfprop
>= 0 && *sfprop
< 16)
4449 awacs_subframe
= *sfprop
;
4452 if (np
!= NULL
&& np
->n_addrs
>= 3 && np
->n_intrs
>= 3) {
4454 sound
.mach
= machPMac
;
4456 awacs
= (volatile struct awacs_regs
*)
4457 ioremap(np
->addrs
[0].address
, 0x80);
4458 awacs_txdma
= (volatile struct dbdma_regs
*)
4459 ioremap(np
->addrs
[1].address
, 0x100);
4460 awacs_rxdma
= (volatile struct dbdma_regs
*)
4461 ioremap(np
->addrs
[2].address
, 0x100);
4462 awacs_irq
= np
->intrs
[0].line
;
4463 awacs_tx_irq
= np
->intrs
[1].line
;
4464 awacs_rx_irq
= np
->intrs
[2].line
;
4465 awacs_tx_cmd_space
= kmalloc((numBufs
+ 4) * sizeof(struct dbdma_cmd
),
4467 if (awacs_tx_cmd_space
== NULL
)
4469 awacs_tx_cmds
= (volatile struct dbdma_cmd
*)
4470 DBDMA_ALIGN(awacs_tx_cmd_space
);
4471 awacs_reg
[0] = MASK_MUX_CD
;
4472 awacs_reg
[1] = MASK_LOOPTHRU
| MASK_PAROUT
;
4473 /* get default volume from nvram */
4474 vol
= (~nvram_read_byte(0x1308) & 7) << 1;
4475 awacs_reg
[2] = vol
+ (vol
<< 6);
4476 awacs_reg
[4] = vol
+ (vol
<< 6);
4477 out_le32(&awacs
->control
, 0x11);
4478 awacs_write(awacs_reg
[0] + MASK_ADDR0
);
4479 awacs_write(awacs_reg
[1] + MASK_ADDR1
);
4480 awacs_write(awacs_reg
[2] + MASK_ADDR2
);
4481 awacs_write(awacs_reg
[4] + MASK_ADDR4
);
4483 /* Initialize beep stuff */
4484 beep_dbdma_cmd
= awacs_tx_cmds
+ (numBufs
+ 1);
4485 orig_mksound
= kd_mksound
;
4486 kd_mksound
= awacs_mksound
;
4487 beep_buf
= (short *) kmalloc(BEEP_BUFLEN
* 2, GFP_KERNEL
);
4488 if (beep_buf
== NULL
)
4489 printk(KERN_WARNING
"dmasound: no memory for "
4491 #ifdef CONFIG_PMAC_PBOOK
4492 notifier_chain_register(&sleep_notifier_list
,
4493 &awacs_sleep_notifier
);
4494 #endif /* CONFIG_PMAC_PBOOK */
4496 #endif /* CONFIG_PMAC */
4501 /* Set up sound queue, /dev/audio and /dev/dsp. */
4502 sound_buffers
= kmalloc (numBufs
* sizeof(char *), GFP_KERNEL
);
4503 if (!sound_buffers
) {
4505 printk("DMA sound driver: Not enough buffer memory, driver disabled!\n");
4508 for (i
= 0; i
< numBufs
; i
++) {
4509 sound_buffers
[i
] = sound
.mach
.dma_alloc (bufSize
<< 10, GFP_KERNEL
);
4510 if (!sound_buffers
[i
]) {
4512 sound
.mach
.dma_free (sound_buffers
[i
], bufSize
<< 10);
4513 kfree (sound_buffers
);
4519 sq_setup(numBufs
, bufSize
<< 10, sound_buffers
);
4521 /* Set default settings. */
4524 /* Set up /dev/sndstat. */
4527 /* Set up /dev/mixer. */
4530 if (!sound
.mach
.irqinit()) {
4531 printk("DMA sound driver: Interrupt initialization failed\n");
4538 printk("DMA sound driver installed, using %d buffers of %dk.\n", numBufs
,
4545 #define MAXARGS 8 /* Should be sufficient for now */
4547 __initfunc(void dmasound_setup(char *str
, int *ints
))
4549 /* check the bootstrap parameter for "dmasound=" */
4553 if ((ints
[3] < 0) || (ints
[3] > MAX_CATCH_RADIUS
))
4554 printk("dmasound_setup: illegal catch radius, using default = %d\n", catchRadius
);
4556 catchRadius
= ints
[3];
4559 if (ints
[1] < MIN_BUFFERS
)
4560 printk("dmasound_setup: illegal number of buffers, using default = %d\n", numBufs
);
4563 if (ints
[2] < MIN_BUFSIZE
|| ints
[2] > MAX_BUFSIZE
)
4564 printk("dmasound_setup: illegal buffer size, using default = %d\n", bufSize
);
4571 printk("dmasound_setup: illegal number of arguments\n");
4578 int init_module(void)
4585 void cleanup_module(void)
4589 if (irq_installed
) {
4591 sound
.mach
.irqcleanup();
4594 if (sound_buffers
) {
4595 for (i
= 0; i
< numBufs
; i
++)
4596 sound
.mach
.dma_free(sound_buffers
[i
], bufSize
<< 10);
4597 kfree(sound_buffers
);
4600 if (mixer_unit
>= 0)
4601 unregister_sound_mixer(mixer_unit
);
4602 if (state_unit
>= 0)
4603 unregister_sound_special(state_unit
);
4605 unregister_sound_dsp(sq_unit
);