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>
93 #if defined(__mc68000__) || defined(CONFIG_APUS)
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>
115 #include <asm/cuda.h>
117 #include "awacs_defs.h"
118 #include <linux/nvram.h>
119 #include <linux/vt_kern.h>
120 #endif /* CONFIG_PPC */
122 #include "dmasound.h"
123 #include <linux/soundcard.h>
125 #define HAS_8BIT_TABLES
128 static int sq_unit
= -1;
129 static int mixer_unit
= -1;
130 static int state_unit
= -1;
131 static int irq_installed
= 0;
133 static char **sound_buffers
= NULL
;
137 extern void atari_microwire_cmd(int cmd
);
138 #endif /* CONFIG_ATARI */
142 * The minimum period for audio depends on htotal (for OCS/ECS/AGA)
143 * (Imported from arch/m68k/amiga/amisound.c)
146 extern volatile u_short amiga_audio_min_period
;
150 * amiga_mksound() should be able to restore the period after beeping
151 * (Imported from arch/m68k/amiga/amisound.c)
154 extern u_short amiga_audio_period
;
161 #define AMI_AUDIO_OFF (DMAF_AUD0 | DMAF_AUD1 | DMAF_AUD2 | DMAF_AUD3)
162 #define AMI_AUDIO_8 (DMAF_SETCLR | DMAF_MASTER | DMAF_AUD0 | DMAF_AUD1)
163 #define AMI_AUDIO_14 (AMI_AUDIO_8 | DMAF_AUD2 | DMAF_AUD3)
165 #endif /* CONFIG_AMIGA */
169 * Interrupt numbers and addresses, obtained from the device tree.
171 static int awacs_irq
, awacs_tx_irq
, awacs_rx_irq
;
172 static volatile struct awacs_regs
*awacs
;
173 static volatile struct dbdma_regs
*awacs_txdma
, *awacs_rxdma
;
174 static int awacs_rate_index
;
175 static int awacs_subframe
;
176 static int awacs_spkr_vol
;
178 static int awacs_revision
;
179 #define AWACS_BURGUNDY 100 /* fake revision # for burgundy */
182 * Space for the DBDMA command blocks.
184 static void *awacs_tx_cmd_space
;
185 static volatile struct dbdma_cmd
*awacs_tx_cmds
;
188 * Cached values of AWACS registers (we can't read them).
189 * Except on the burgundy. XXX
193 #define HAS_16BIT_TABLES
194 #undef HAS_8BIT_TABLES
197 * Stuff for outputting a beep. The values range from -327 to +327
198 * so we can multiply by an amplitude in the range 0..100 to get a
199 * signed short value to put in the output buffer.
201 static short beep_wform
[256] = {
202 0, 40, 79, 117, 153, 187, 218, 245,
203 269, 288, 304, 316, 323, 327, 327, 324,
204 318, 310, 299, 288, 275, 262, 249, 236,
205 224, 213, 204, 196, 190, 186, 183, 182,
206 182, 183, 186, 189, 192, 196, 200, 203,
207 206, 208, 209, 209, 209, 207, 204, 201,
208 197, 193, 188, 183, 179, 174, 170, 166,
209 163, 161, 160, 159, 159, 160, 161, 162,
210 164, 166, 168, 169, 171, 171, 171, 170,
211 169, 167, 163, 159, 155, 150, 144, 139,
212 133, 128, 122, 117, 113, 110, 107, 105,
213 103, 103, 103, 103, 104, 104, 105, 105,
214 105, 103, 101, 97, 92, 86, 78, 68,
215 58, 45, 32, 18, 3, -11, -26, -41,
216 -55, -68, -79, -88, -95, -100, -102, -102,
217 -99, -93, -85, -75, -62, -48, -33, -16,
218 0, 16, 33, 48, 62, 75, 85, 93,
219 99, 102, 102, 100, 95, 88, 79, 68,
220 55, 41, 26, 11, -3, -18, -32, -45,
221 -58, -68, -78, -86, -92, -97, -101, -103,
222 -105, -105, -105, -104, -104, -103, -103, -103,
223 -103, -105, -107, -110, -113, -117, -122, -128,
224 -133, -139, -144, -150, -155, -159, -163, -167,
225 -169, -170, -171, -171, -171, -169, -168, -166,
226 -164, -162, -161, -160, -159, -159, -160, -161,
227 -163, -166, -170, -174, -179, -183, -188, -193,
228 -197, -201, -204, -207, -209, -209, -209, -208,
229 -206, -203, -200, -196, -192, -189, -186, -183,
230 -182, -182, -183, -186, -190, -196, -204, -213,
231 -224, -236, -249, -262, -275, -288, -299, -310,
232 -318, -324, -327, -327, -323, -316, -304, -288,
233 -269, -245, -218, -187, -153, -117, -79, -40,
236 #define BEEP_SPEED 2 /* 22050 Hz sample rate */
237 #define BEEP_BUFLEN 512
238 #define BEEP_VOLUME 15 /* 0 - 100 */
240 static int beep_volume
= BEEP_VOLUME
;
241 static int beep_playing
= 0;
242 static short *beep_buf
;
243 static volatile struct dbdma_cmd
*beep_dbdma_cmd
;
244 static void (*orig_mksound
)(unsigned int, unsigned int);
246 /* Burgundy functions */
247 static void awacs_burgundy_wcw(unsigned addr
,unsigned newval
);
248 static unsigned awacs_burgundy_rcw(unsigned addr
);
249 static void awacs_burgundy_write_volume(unsigned address
, int volume
);
250 static int awacs_burgundy_read_volume(unsigned address
);
251 static void awacs_burgundy_write_mvolume(unsigned address
, int volume
);
252 static int awacs_burgundy_read_mvolume(unsigned address
);
254 #ifdef CONFIG_PMAC_PBOOK
256 * Stuff for restoring after a sleep.
258 static int awacs_sleep_notify(struct notifier_block
*, unsigned long, void *);
259 struct notifier_block awacs_sleep_notifier
= {
262 #endif /* CONFIG_PMAC_PBOOK */
264 #endif /* CONFIG_PPC */
266 /*** Some declarations *******************************************************/
270 #define DMASND_FALCON 2
271 #define DMASND_AMIGA 3
272 #define DMASND_AWACS 4
274 #define MAX_CATCH_RADIUS 10
275 #define MIN_BUFFERS 4
276 #define MIN_BUFSIZE 4
277 #define MAX_BUFSIZE 128 /* Limit for Amiga */
279 static int catchRadius
= 0, numBufs
= 4, bufSize
= 32;
280 MODULE_PARM(catchRadius
, "i");
281 MODULE_PARM(numBufs
, "i");
282 MODULE_PARM(bufSize
, "i");
284 #define arraysize(x) (sizeof(x)/sizeof(*(x)))
285 #define min(x, y) ((x) < (y) ? (x) : (y))
286 #define le2be16(x) (((x)<<8 & 0xff00) | ((x)>>8 & 0x00ff))
287 #define le2be16dbl(x) (((x)<<8 & 0xff00ff00) | ((x)>>8 & 0x00ff00ff))
289 #define IOCTL_IN(arg, ret) \
290 do { int error = get_user(ret, (int *)(arg)); \
291 if (error) return error; \
293 #define IOCTL_OUT(arg, ret) ioctl_return((int *)(arg), ret)
296 /*** Some low level helpers **************************************************/
298 #ifdef HAS_8BIT_TABLES
301 static char ulaw2dma8
[] = {
302 -126, -122, -118, -114, -110, -106, -102, -98,
303 -94, -90, -86, -82, -78, -74, -70, -66,
304 -63, -61, -59, -57, -55, -53, -51, -49,
305 -47, -45, -43, -41, -39, -37, -35, -33,
306 -31, -30, -29, -28, -27, -26, -25, -24,
307 -23, -22, -21, -20, -19, -18, -17, -16,
308 -16, -15, -15, -14, -14, -13, -13, -12,
309 -12, -11, -11, -10, -10, -9, -9, -8,
310 -8, -8, -7, -7, -7, -7, -6, -6,
311 -6, -6, -5, -5, -5, -5, -4, -4,
312 -4, -4, -4, -4, -3, -3, -3, -3,
313 -3, -3, -3, -3, -2, -2, -2, -2,
314 -2, -2, -2, -2, -2, -2, -2, -2,
315 -1, -1, -1, -1, -1, -1, -1, -1,
316 -1, -1, -1, -1, -1, -1, -1, -1,
317 -1, -1, -1, -1, -1, -1, -1, 0,
318 125, 121, 117, 113, 109, 105, 101, 97,
319 93, 89, 85, 81, 77, 73, 69, 65,
320 62, 60, 58, 56, 54, 52, 50, 48,
321 46, 44, 42, 40, 38, 36, 34, 32,
322 30, 29, 28, 27, 26, 25, 24, 23,
323 22, 21, 20, 19, 18, 17, 16, 15,
324 15, 14, 14, 13, 13, 12, 12, 11,
325 11, 10, 10, 9, 9, 8, 8, 7,
326 7, 7, 6, 6, 6, 6, 5, 5,
327 5, 5, 4, 4, 4, 4, 3, 3,
328 3, 3, 3, 3, 2, 2, 2, 2,
329 2, 2, 2, 2, 1, 1, 1, 1,
330 1, 1, 1, 1, 1, 1, 1, 1,
331 0, 0, 0, 0, 0, 0, 0, 0,
332 0, 0, 0, 0, 0, 0, 0, 0,
333 0, 0, 0, 0, 0, 0, 0, 0
338 static char alaw2dma8
[] = {
339 -22, -21, -24, -23, -18, -17, -20, -19,
340 -30, -29, -32, -31, -26, -25, -28, -27,
341 -11, -11, -12, -12, -9, -9, -10, -10,
342 -15, -15, -16, -16, -13, -13, -14, -14,
343 -86, -82, -94, -90, -70, -66, -78, -74,
344 -118, -114, -126, -122, -102, -98, -110, -106,
345 -43, -41, -47, -45, -35, -33, -39, -37,
346 -59, -57, -63, -61, -51, -49, -55, -53,
347 -2, -2, -2, -2, -2, -2, -2, -2,
348 -2, -2, -2, -2, -2, -2, -2, -2,
349 -1, -1, -1, -1, -1, -1, -1, -1,
350 -1, -1, -1, -1, -1, -1, -1, -1,
351 -6, -6, -6, -6, -5, -5, -5, -5,
352 -8, -8, -8, -8, -7, -7, -7, -7,
353 -3, -3, -3, -3, -3, -3, -3, -3,
354 -4, -4, -4, -4, -4, -4, -4, -4,
355 21, 20, 23, 22, 17, 16, 19, 18,
356 29, 28, 31, 30, 25, 24, 27, 26,
357 10, 10, 11, 11, 8, 8, 9, 9,
358 14, 14, 15, 15, 12, 12, 13, 13,
359 86, 82, 94, 90, 70, 66, 78, 74,
360 118, 114, 126, 122, 102, 98, 110, 106,
361 43, 41, 47, 45, 35, 33, 39, 37,
362 59, 57, 63, 61, 51, 49, 55, 53,
363 1, 1, 1, 1, 1, 1, 1, 1,
364 1, 1, 1, 1, 1, 1, 1, 1,
365 0, 0, 0, 0, 0, 0, 0, 0,
366 0, 0, 0, 0, 0, 0, 0, 0,
367 5, 5, 5, 5, 4, 4, 4, 4,
368 7, 7, 7, 7, 6, 6, 6, 6,
369 2, 2, 2, 2, 2, 2, 2, 2,
370 3, 3, 3, 3, 3, 3, 3, 3
372 #endif /* HAS_8BIT_TABLES */
374 #ifdef HAS_16BIT_TABLES
378 static short ulaw2dma16
[] = {
379 -32124, -31100, -30076, -29052, -28028, -27004, -25980, -24956,
380 -23932, -22908, -21884, -20860, -19836, -18812, -17788, -16764,
381 -15996, -15484, -14972, -14460, -13948, -13436, -12924, -12412,
382 -11900, -11388, -10876, -10364, -9852, -9340, -8828, -8316,
383 -7932, -7676, -7420, -7164, -6908, -6652, -6396, -6140,
384 -5884, -5628, -5372, -5116, -4860, -4604, -4348, -4092,
385 -3900, -3772, -3644, -3516, -3388, -3260, -3132, -3004,
386 -2876, -2748, -2620, -2492, -2364, -2236, -2108, -1980,
387 -1884, -1820, -1756, -1692, -1628, -1564, -1500, -1436,
388 -1372, -1308, -1244, -1180, -1116, -1052, -988, -924,
389 -876, -844, -812, -780, -748, -716, -684, -652,
390 -620, -588, -556, -524, -492, -460, -428, -396,
391 -372, -356, -340, -324, -308, -292, -276, -260,
392 -244, -228, -212, -196, -180, -164, -148, -132,
393 -120, -112, -104, -96, -88, -80, -72, -64,
394 -56, -48, -40, -32, -24, -16, -8, 0,
395 32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
396 23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
397 15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
398 11900, 11388, 10876, 10364, 9852, 9340, 8828, 8316,
399 7932, 7676, 7420, 7164, 6908, 6652, 6396, 6140,
400 5884, 5628, 5372, 5116, 4860, 4604, 4348, 4092,
401 3900, 3772, 3644, 3516, 3388, 3260, 3132, 3004,
402 2876, 2748, 2620, 2492, 2364, 2236, 2108, 1980,
403 1884, 1820, 1756, 1692, 1628, 1564, 1500, 1436,
404 1372, 1308, 1244, 1180, 1116, 1052, 988, 924,
405 876, 844, 812, 780, 748, 716, 684, 652,
406 620, 588, 556, 524, 492, 460, 428, 396,
407 372, 356, 340, 324, 308, 292, 276, 260,
408 244, 228, 212, 196, 180, 164, 148, 132,
409 120, 112, 104, 96, 88, 80, 72, 64,
410 56, 48, 40, 32, 24, 16, 8, 0,
415 static short alaw2dma16
[] = {
416 -5504, -5248, -6016, -5760, -4480, -4224, -4992, -4736,
417 -7552, -7296, -8064, -7808, -6528, -6272, -7040, -6784,
418 -2752, -2624, -3008, -2880, -2240, -2112, -2496, -2368,
419 -3776, -3648, -4032, -3904, -3264, -3136, -3520, -3392,
420 -22016, -20992, -24064, -23040, -17920, -16896, -19968, -18944,
421 -30208, -29184, -32256, -31232, -26112, -25088, -28160, -27136,
422 -11008, -10496, -12032, -11520, -8960, -8448, -9984, -9472,
423 -15104, -14592, -16128, -15616, -13056, -12544, -14080, -13568,
424 -344, -328, -376, -360, -280, -264, -312, -296,
425 -472, -456, -504, -488, -408, -392, -440, -424,
426 -88, -72, -120, -104, -24, -8, -56, -40,
427 -216, -200, -248, -232, -152, -136, -184, -168,
428 -1376, -1312, -1504, -1440, -1120, -1056, -1248, -1184,
429 -1888, -1824, -2016, -1952, -1632, -1568, -1760, -1696,
430 -688, -656, -752, -720, -560, -528, -624, -592,
431 -944, -912, -1008, -976, -816, -784, -880, -848,
432 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736,
433 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784,
434 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368,
435 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392,
436 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944,
437 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136,
438 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472,
439 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568,
440 344, 328, 376, 360, 280, 264, 312, 296,
441 472, 456, 504, 488, 408, 392, 440, 424,
442 88, 72, 120, 104, 24, 8, 56, 40,
443 216, 200, 248, 232, 152, 136, 184, 168,
444 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184,
445 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696,
446 688, 656, 752, 720, 560, 528, 624, 592,
447 944, 912, 1008, 976, 816, 784, 880, 848,
449 #endif /* HAS_16BIT_TABLES */
452 #ifdef HAS_14BIT_TABLES
454 /* 14 bit mu-law (LSB) */
456 static char alaw2dma14l
[] = {
457 33, 33, 33, 33, 33, 33, 33, 33,
458 33, 33, 33, 33, 33, 33, 33, 33,
459 33, 33, 33, 33, 33, 33, 33, 33,
460 33, 33, 33, 33, 33, 33, 33, 33,
461 1, 1, 1, 1, 1, 1, 1, 1,
462 1, 1, 1, 1, 1, 1, 1, 1,
463 49, 17, 49, 17, 49, 17, 49, 17,
464 49, 17, 49, 17, 49, 17, 49, 17,
465 41, 57, 9, 25, 41, 57, 9, 25,
466 41, 57, 9, 25, 41, 57, 9, 25,
467 37, 45, 53, 61, 5, 13, 21, 29,
468 37, 45, 53, 61, 5, 13, 21, 29,
469 35, 39, 43, 47, 51, 55, 59, 63,
470 3, 7, 11, 15, 19, 23, 27, 31,
471 34, 36, 38, 40, 42, 44, 46, 48,
472 50, 52, 54, 56, 58, 60, 62, 0,
473 31, 31, 31, 31, 31, 31, 31, 31,
474 31, 31, 31, 31, 31, 31, 31, 31,
475 31, 31, 31, 31, 31, 31, 31, 31,
476 31, 31, 31, 31, 31, 31, 31, 31,
477 63, 63, 63, 63, 63, 63, 63, 63,
478 63, 63, 63, 63, 63, 63, 63, 63,
479 15, 47, 15, 47, 15, 47, 15, 47,
480 15, 47, 15, 47, 15, 47, 15, 47,
481 23, 7, 55, 39, 23, 7, 55, 39,
482 23, 7, 55, 39, 23, 7, 55, 39,
483 27, 19, 11, 3, 59, 51, 43, 35,
484 27, 19, 11, 3, 59, 51, 43, 35,
485 29, 25, 21, 17, 13, 9, 5, 1,
486 61, 57, 53, 49, 45, 41, 37, 33,
487 30, 28, 26, 24, 22, 20, 18, 16,
488 14, 12, 10, 8, 6, 4, 2, 0
491 /* 14 bit A-law (LSB) */
493 static char alaw2dma14l
[] = {
494 32, 32, 32, 32, 32, 32, 32, 32,
495 32, 32, 32, 32, 32, 32, 32, 32,
496 16, 48, 16, 48, 16, 48, 16, 48,
497 16, 48, 16, 48, 16, 48, 16, 48,
498 0, 0, 0, 0, 0, 0, 0, 0,
499 0, 0, 0, 0, 0, 0, 0, 0,
500 0, 0, 0, 0, 0, 0, 0, 0,
501 0, 0, 0, 0, 0, 0, 0, 0,
502 42, 46, 34, 38, 58, 62, 50, 54,
503 10, 14, 2, 6, 26, 30, 18, 22,
504 42, 46, 34, 38, 58, 62, 50, 54,
505 10, 14, 2, 6, 26, 30, 18, 22,
506 40, 56, 8, 24, 40, 56, 8, 24,
507 40, 56, 8, 24, 40, 56, 8, 24,
508 20, 28, 4, 12, 52, 60, 36, 44,
509 20, 28, 4, 12, 52, 60, 36, 44,
510 32, 32, 32, 32, 32, 32, 32, 32,
511 32, 32, 32, 32, 32, 32, 32, 32,
512 48, 16, 48, 16, 48, 16, 48, 16,
513 48, 16, 48, 16, 48, 16, 48, 16,
514 0, 0, 0, 0, 0, 0, 0, 0,
515 0, 0, 0, 0, 0, 0, 0, 0,
516 0, 0, 0, 0, 0, 0, 0, 0,
517 0, 0, 0, 0, 0, 0, 0, 0,
518 22, 18, 30, 26, 6, 2, 14, 10,
519 54, 50, 62, 58, 38, 34, 46, 42,
520 22, 18, 30, 26, 6, 2, 14, 10,
521 54, 50, 62, 58, 38, 34, 46, 42,
522 24, 8, 56, 40, 24, 8, 56, 40,
523 24, 8, 56, 40, 24, 8, 56, 40,
524 44, 36, 60, 52, 12, 4, 28, 20,
525 44, 36, 60, 52, 12, 4, 28, 20
527 #endif /* HAS_14BIT_TABLES */
530 /*** Translations ************************************************************/
534 static ssize_t
ata_ct_law(const u_char
*userPtr
, size_t userCount
,
535 u_char frame
[], ssize_t
*frameUsed
,
537 static ssize_t
ata_ct_s8(const u_char
*userPtr
, size_t userCount
,
538 u_char frame
[], ssize_t
*frameUsed
,
540 static ssize_t
ata_ct_u8(const u_char
*userPtr
, size_t userCount
,
541 u_char frame
[], ssize_t
*frameUsed
,
543 static ssize_t
ata_ct_s16be(const u_char
*userPtr
, size_t userCount
,
544 u_char frame
[], ssize_t
*frameUsed
,
546 static ssize_t
ata_ct_u16be(const u_char
*userPtr
, size_t userCount
,
547 u_char frame
[], ssize_t
*frameUsed
,
549 static ssize_t
ata_ct_s16le(const u_char
*userPtr
, size_t userCount
,
550 u_char frame
[], ssize_t
*frameUsed
,
552 static ssize_t
ata_ct_u16le(const u_char
*userPtr
, size_t userCount
,
553 u_char frame
[], ssize_t
*frameUsed
,
555 static ssize_t
ata_ctx_law(const u_char
*userPtr
, size_t userCount
,
556 u_char frame
[], ssize_t
*frameUsed
,
558 static ssize_t
ata_ctx_s8(const u_char
*userPtr
, size_t userCount
,
559 u_char frame
[], ssize_t
*frameUsed
,
561 static ssize_t
ata_ctx_u8(const u_char
*userPtr
, size_t userCount
,
562 u_char frame
[], ssize_t
*frameUsed
,
564 static ssize_t
ata_ctx_s16be(const u_char
*userPtr
, size_t userCount
,
565 u_char frame
[], ssize_t
*frameUsed
,
567 static ssize_t
ata_ctx_u16be(const u_char
*userPtr
, size_t userCount
,
568 u_char frame
[], ssize_t
*frameUsed
,
570 static ssize_t
ata_ctx_s16le(const u_char
*userPtr
, size_t userCount
,
571 u_char frame
[], ssize_t
*frameUsed
,
573 static ssize_t
ata_ctx_u16le(const u_char
*userPtr
, size_t userCount
,
574 u_char frame
[], ssize_t
*frameUsed
,
576 #endif /* CONFIG_ATARI */
579 static ssize_t
ami_ct_law(const u_char
*userPtr
, size_t userCount
,
580 u_char frame
[], ssize_t
*frameUsed
,
582 static ssize_t
ami_ct_s8(const u_char
*userPtr
, size_t userCount
,
583 u_char frame
[], ssize_t
*frameUsed
,
585 static ssize_t
ami_ct_u8(const u_char
*userPtr
, size_t userCount
,
586 u_char frame
[], ssize_t
*frameUsed
,
588 static ssize_t
ami_ct_s16be(const u_char
*userPtr
, size_t userCount
,
589 u_char frame
[], ssize_t
*frameUsed
,
591 static ssize_t
ami_ct_u16be(const u_char
*userPtr
, size_t userCount
,
592 u_char frame
[], ssize_t
*frameUsed
,
594 static ssize_t
ami_ct_s16le(const u_char
*userPtr
, size_t userCount
,
595 u_char frame
[], ssize_t
*frameUsed
,
597 static ssize_t
ami_ct_u16le(const u_char
*userPtr
, size_t userCount
,
598 u_char frame
[], ssize_t
*frameUsed
,
600 #endif /* CONFIG_AMIGA */
603 static ssize_t
pmac_ct_law(const u_char
*userPtr
, size_t userCount
,
604 u_char frame
[], ssize_t
*frameUsed
,
606 static ssize_t
pmac_ct_s8(const u_char
*userPtr
, size_t userCount
,
607 u_char frame
[], ssize_t
*frameUsed
,
609 static ssize_t
pmac_ct_u8(const u_char
*userPtr
, size_t userCount
,
610 u_char frame
[], ssize_t
*frameUsed
,
612 static ssize_t
pmac_ct_s16(const u_char
*userPtr
, size_t userCount
,
613 u_char frame
[], ssize_t
*frameUsed
,
615 static ssize_t
pmac_ct_u16(const u_char
*userPtr
, size_t userCount
,
616 u_char frame
[], ssize_t
*frameUsed
,
618 static ssize_t
pmac_ctx_law(const u_char
*userPtr
, size_t userCount
,
619 u_char frame
[], ssize_t
*frameUsed
,
621 static ssize_t
pmac_ctx_s8(const u_char
*userPtr
, size_t userCount
,
622 u_char frame
[], ssize_t
*frameUsed
,
624 static ssize_t
pmac_ctx_u8(const u_char
*userPtr
, size_t userCount
,
625 u_char frame
[], ssize_t
*frameUsed
,
627 static ssize_t
pmac_ctx_s16(const u_char
*userPtr
, size_t userCount
,
628 u_char frame
[], ssize_t
*frameUsed
,
630 static ssize_t
pmac_ctx_u16(const u_char
*userPtr
, size_t userCount
,
631 u_char frame
[], ssize_t
*frameUsed
,
633 #endif /* CONFIG_PPC */
635 /*** Machine definitions *****************************************************/
640 void *(*dma_alloc
)(unsigned int, int);
641 void (*dma_free
)(void *, unsigned int);
642 int (*irqinit
)(void);
644 void (*irqcleanup
)(void);
647 void (*silence
)(void);
648 int (*setFormat
)(int);
649 int (*setVolume
)(int);
651 int (*setTreble
)(int);
657 /*** Low level stuff *********************************************************/
661 int format
; /* AFMT_* */
662 int stereo
; /* 0 = mono, 1 = stereo */
663 int size
; /* 8/16 bit*/
664 int speed
; /* speed */
668 ssize_t (*ct_ulaw
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
669 ssize_t (*ct_alaw
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
670 ssize_t (*ct_s8
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
671 ssize_t (*ct_u8
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
672 ssize_t (*ct_s16be
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
673 ssize_t (*ct_u16be
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
674 ssize_t (*ct_s16le
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
675 ssize_t (*ct_u16le
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
);
678 struct sound_settings
{
679 MACHINE mach
; /* machine dependent things */
680 SETTINGS hard
; /* hardware settings */
681 SETTINGS soft
; /* software settings */
682 SETTINGS dsp
; /* /dev/dsp default settings */
683 TRANS
*trans
; /* supported translations */
684 int volume_left
; /* volume (range is machine dependent) */
686 int bass
; /* tone (range is machine dependent) */
689 int minDev
; /* minor device number currently open */
690 #if defined(CONFIG_ATARI) || defined(CONFIG_PPC)
691 int bal
; /* balance factor for expanding (not volume!) */
692 u_long data
; /* data for expanding */
693 #endif /* CONFIG_ATARI */
696 static struct sound_settings sound
;
700 static void *AtaAlloc(unsigned int size
, int flags
);
701 static void AtaFree(void *, unsigned int size
);
702 static int AtaIrqInit(void);
704 static void AtaIrqCleanUp(void);
706 static int AtaSetBass(int bass
);
707 static int AtaSetTreble(int treble
);
708 static void TTSilence(void);
709 static void TTInit(void);
710 static int TTSetFormat(int format
);
711 static int TTSetVolume(int volume
);
712 static int TTSetGain(int gain
);
713 static void FalconSilence(void);
714 static void FalconInit(void);
715 static int FalconSetFormat(int format
);
716 static int FalconSetVolume(int volume
);
717 static void ata_sq_play_next_frame(int index
);
718 static void AtaPlay(void);
719 static void ata_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
);
720 #endif /* CONFIG_ATARI */
723 static void *AmiAlloc(unsigned int size
, int flags
);
724 static void AmiFree(void *, unsigned int);
725 static int AmiIrqInit(void);
727 static void AmiIrqCleanUp(void);
729 static void AmiSilence(void);
730 static void AmiInit(void);
731 static int AmiSetFormat(int format
);
732 static int AmiSetVolume(int volume
);
733 static int AmiSetTreble(int treble
);
734 static void ami_sq_play_next_frame(int index
);
735 static void AmiPlay(void);
736 static void ami_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
);
737 #endif /* CONFIG_AMIGA */
740 static void *PMacAlloc(unsigned int size
, int flags
);
741 static void PMacFree(void *ptr
, unsigned int size
);
742 static int PMacIrqInit(void);
744 static void PMacIrqCleanup(void);
746 static void PMacSilence(void);
747 static void PMacInit(void);
748 static void PMacPlay(void);
749 static int PMacSetFormat(int format
);
750 static int PMacSetVolume(int volume
);
751 static void pmac_awacs_tx_intr(int irq
, void *devid
, struct pt_regs
*regs
);
752 static void pmac_awacs_intr(int irq
, void *devid
, struct pt_regs
*regs
);
753 static void awacs_write(int val
);
754 static int awacs_get_volume(int reg
, int lshift
);
755 static int awacs_volume_setter(int volume
, int n
, int mute
, int lshift
);
756 static void awacs_mksound(unsigned int hz
, unsigned int ticks
);
757 static void awacs_nosound(unsigned long xx
);
758 #endif /* CONFIG_PPC */
760 /*** Mid level stuff *********************************************************/
763 static void sound_silence(void);
764 static void sound_init(void);
765 static int sound_set_format(int format
);
766 static int sound_set_speed(int speed
);
767 static int sound_set_stereo(int stereo
);
768 static int sound_set_volume(int volume
);
770 static int sound_set_bass(int bass
);
771 #endif /* CONFIG_ATARI */
772 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA)
773 static int sound_set_treble(int treble
);
774 #endif /* CONFIG_ATARI || CONFIG_AMIGA */
775 static ssize_t
sound_copy_translate(const u_char
*userPtr
,
777 u_char frame
[], ssize_t
*frameUsed
,
782 * /dev/mixer abstraction
789 static struct sound_mixer mixer
;
792 * Sound queue stuff, the heart of the driver
796 int max_count
, block_size
;
800 /* it shouldn't be necessary to declare any of these volatile */
801 int front
, rear
, count
;
804 * The use of the playing field depends on the hardware
806 * Atari, PMac: The number of frames that are loaded/playing
808 * Amiga: Bit 0 is set: a frame is loaded
809 * Bit 1 is set: a frame is playing
812 wait_queue_head_t write_queue
, open_queue
, sync_queue
;
816 int ignore_int
; /* ++TeSche: used for Falcon */
817 #endif /* CONFIG_ATARI */
819 int block_size_half
, block_size_quarter
;
820 #endif /* CONFIG_AMIGA */
823 static struct sound_queue sq
;
825 #define sq_block_address(i) (sq.buffers[i])
826 #define SIGNAL_RECEIVED (signal_pending(current))
827 #define NON_BLOCKING(open_mode) (open_mode & O_NONBLOCK)
828 #define ONE_SECOND HZ /* in jiffies (100ths of a second) */
829 #define NO_TIME_LIMIT 0xffffffff
830 #define SLEEP(queue, time_limit) \
831 interruptible_sleep_on_timeout(&queue, (time_limit));
832 #define WAKE_UP(queue) (wake_up_interruptible(&queue))
844 static struct sound_state state
;
846 /*** Common stuff ********************************************************/
848 static long long sound_lseek(struct file
*file
, long long offset
, int orig
);
849 static inline int ioctl_return(int *addr
, int value
)
854 return put_user(value
, addr
)? -EFAULT
: 0;
858 /*** Config & Setup **********************************************************/
861 void dmasound_init(void);
862 void dmasound_setup(char *str
, int *ints
);
865 /*** Translations ************************************************************/
868 /* ++TeSche: radically changed for new expanding purposes...
870 * These two routines now deal with copying/expanding/translating the samples
871 * from user space into our buffer at the right frequency. They take care about
872 * how much data there's actually to read, how much buffer space there is and
873 * to convert samples into the right frequency/encoding. They will only work on
874 * complete samples so it may happen they leave some bytes in the input stream
875 * if the user didn't write a multiple of the current sample size. They both
876 * return the number of bytes they've used from both streams so you may detect
877 * such a situation. Luckily all programs should be able to cope with that.
879 * I think I've optimized anything as far as one can do in plain C, all
880 * variables should fit in registers and the loops are really short. There's
881 * one loop for every possible situation. Writing a more generalized and thus
882 * parameterized loop would only produce slower code. Feel free to optimize
883 * this in assembler if you like. :)
885 * I think these routines belong here because they're not yet really hardware
886 * independent, especially the fact that the Falcon can play 16bit samples
887 * only in stereo is hardcoded in both of them!
889 * ++geert: split in even more functions (one per format)
893 static ssize_t
ata_ct_law(const u_char
*userPtr
, size_t userCount
,
894 u_char frame
[], ssize_t
*frameUsed
,
897 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
899 u_char
*p
= &frame
[*frameUsed
];
901 count
= min(userCount
, frameLeft
);
902 if (sound
.soft
.stereo
)
907 if (get_user(data
, userPtr
++))
917 static ssize_t
ata_ct_s8(const u_char
*userPtr
, size_t userCount
,
918 u_char frame
[], ssize_t
*frameUsed
,
922 void *p
= &frame
[*frameUsed
];
924 count
= min(userCount
, frameLeft
);
925 if (sound
.soft
.stereo
)
928 if (copy_from_user(p
, userPtr
, count
))
935 static ssize_t
ata_ct_u8(const u_char
*userPtr
, size_t userCount
,
936 u_char frame
[], ssize_t
*frameUsed
,
941 if (!sound
.soft
.stereo
) {
942 u_char
*p
= &frame
[*frameUsed
];
943 count
= min(userCount
, frameLeft
);
947 if (get_user(data
, userPtr
++))
953 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
954 count
= min(userCount
, frameLeft
)>>1;
958 if (get_user(data
, ((u_short
*)userPtr
)++))
960 *p
++ = data
^ 0x8080;
969 static ssize_t
ata_ct_s16be(const u_char
*userPtr
, size_t userCount
,
970 u_char frame
[], ssize_t
*frameUsed
,
975 if (!sound
.soft
.stereo
) {
976 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
977 count
= min(userCount
, frameLeft
)>>1;
981 if (get_user(data
, ((u_short
*)userPtr
)++))
987 *frameUsed
+= used
*2;
989 void *p
= (u_short
*)&frame
[*frameUsed
];
990 count
= min(userCount
, frameLeft
) & ~3;
992 if (copy_from_user(p
, userPtr
, count
))
1000 static ssize_t
ata_ct_u16be(const u_char
*userPtr
, size_t userCount
,
1001 u_char frame
[], ssize_t
*frameUsed
,
1004 ssize_t count
, used
;
1006 if (!sound
.soft
.stereo
) {
1007 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1008 count
= min(userCount
, frameLeft
)>>1;
1012 if (get_user(data
, ((u_short
*)userPtr
)++))
1019 *frameUsed
+= used
*2;
1021 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1022 count
= min(userCount
, frameLeft
)>>2;
1026 if (get_user(data
, ((u_int
*)userPtr
)++))
1028 *p
++ = data
^ 0x80008000;
1037 static ssize_t
ata_ct_s16le(const u_char
*userPtr
, size_t userCount
,
1038 u_char frame
[], ssize_t
*frameUsed
,
1041 ssize_t count
, used
;
1044 if (!sound
.soft
.stereo
) {
1045 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1046 count
= min(userCount
, frameLeft
)>>1;
1050 if (get_user(data
, ((u_short
*)userPtr
)++))
1052 data
= le2be16(data
);
1057 *frameUsed
+= used
*2;
1059 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1060 count
= min(userCount
, frameLeft
)>>2;
1064 if (get_user(data
, ((u_int
*)userPtr
)++))
1066 data
= le2be16dbl(data
);
1076 static ssize_t
ata_ct_u16le(const u_char
*userPtr
, size_t userCount
,
1077 u_char frame
[], ssize_t
*frameUsed
,
1080 ssize_t count
, used
;
1083 if (!sound
.soft
.stereo
) {
1084 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1085 count
= min(userCount
, frameLeft
)>>1;
1089 if (get_user(data
, ((u_short
*)userPtr
)++))
1091 data
= le2be16(data
) ^ 0x8000;
1095 *frameUsed
+= used
*2;
1097 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1098 count
= min(userCount
, frameLeft
)>>2;
1102 if (get_user(data
, ((u_int
*)userPtr
)++))
1104 data
= le2be16dbl(data
) ^ 0x80008000;
1114 static ssize_t
ata_ctx_law(const u_char
*userPtr
, size_t userCount
,
1115 u_char frame
[], ssize_t
*frameUsed
,
1118 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
1119 /* this should help gcc to stuff everything into registers */
1120 long bal
= sound
.bal
;
1121 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1122 ssize_t used
, usedf
;
1126 if (!sound
.soft
.stereo
) {
1127 u_char
*p
= &frame
[*frameUsed
];
1128 u_char data
= sound
.data
;
1134 if (get_user(c
, userPtr
++))
1146 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1147 u_short data
= sound
.data
;
1148 while (frameLeft
>= 2) {
1153 if (get_user(c
, userPtr
++))
1155 data
= table
[c
] << 8;
1156 if (get_user(c
, userPtr
++))
1170 *frameUsed
+= usedf
-frameLeft
;
1175 static ssize_t
ata_ctx_s8(const u_char
*userPtr
, size_t userCount
,
1176 u_char frame
[], ssize_t
*frameUsed
,
1179 /* this should help gcc to stuff everything into registers */
1180 long bal
= sound
.bal
;
1181 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1182 ssize_t used
, usedf
;
1186 if (!sound
.soft
.stereo
) {
1187 u_char
*p
= &frame
[*frameUsed
];
1188 u_char data
= sound
.data
;
1193 if (get_user(data
, userPtr
++))
1204 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1205 u_short data
= sound
.data
;
1206 while (frameLeft
>= 2) {
1210 if (get_user(data
, ((u_short
*)userPtr
)++))
1223 *frameUsed
+= usedf
-frameLeft
;
1228 static ssize_t
ata_ctx_u8(const u_char
*userPtr
, size_t userCount
,
1229 u_char frame
[], ssize_t
*frameUsed
,
1232 /* this should help gcc to stuff everything into registers */
1233 long bal
= sound
.bal
;
1234 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1235 ssize_t used
, usedf
;
1239 if (!sound
.soft
.stereo
) {
1240 u_char
*p
= &frame
[*frameUsed
];
1241 u_char data
= sound
.data
;
1246 if (get_user(data
, userPtr
++))
1258 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1259 u_short data
= sound
.data
;
1260 while (frameLeft
>= 2) {
1264 if (get_user(data
, ((u_short
*)userPtr
)++))
1278 *frameUsed
+= usedf
-frameLeft
;
1283 static ssize_t
ata_ctx_s16be(const u_char
*userPtr
, size_t userCount
,
1284 u_char frame
[], ssize_t
*frameUsed
,
1287 /* this should help gcc to stuff everything into registers */
1288 long bal
= sound
.bal
;
1289 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1290 ssize_t used
, usedf
;
1294 if (!sound
.soft
.stereo
) {
1295 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1296 u_short data
= sound
.data
;
1297 while (frameLeft
>= 4) {
1301 if (get_user(data
, ((u_short
*)userPtr
)++))
1313 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1314 u_long data
= sound
.data
;
1315 while (frameLeft
>= 4) {
1319 if (get_user(data
, ((u_int
*)userPtr
)++))
1332 *frameUsed
+= usedf
-frameLeft
;
1337 static ssize_t
ata_ctx_u16be(const u_char
*userPtr
, size_t userCount
,
1338 u_char frame
[], ssize_t
*frameUsed
,
1341 /* this should help gcc to stuff everything into registers */
1342 long bal
= sound
.bal
;
1343 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1344 ssize_t used
, usedf
;
1348 if (!sound
.soft
.stereo
) {
1349 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1350 u_short data
= sound
.data
;
1351 while (frameLeft
>= 4) {
1355 if (get_user(data
, ((u_short
*)userPtr
)++))
1368 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1369 u_long data
= sound
.data
;
1370 while (frameLeft
>= 4) {
1374 if (get_user(data
, ((u_int
*)userPtr
)++))
1388 *frameUsed
+= usedf
-frameLeft
;
1393 static ssize_t
ata_ctx_s16le(const u_char
*userPtr
, size_t userCount
,
1394 u_char frame
[], ssize_t
*frameUsed
,
1397 /* this should help gcc to stuff everything into registers */
1398 long bal
= sound
.bal
;
1399 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1400 ssize_t used
, usedf
;
1404 if (!sound
.soft
.stereo
) {
1405 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1406 u_short data
= sound
.data
;
1407 while (frameLeft
>= 4) {
1411 if (get_user(data
, ((u_short
*)userPtr
)++))
1413 data
= le2be16(data
);
1424 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1425 u_long data
= sound
.data
;
1426 while (frameLeft
>= 4) {
1430 if (get_user(data
, ((u_int
*)userPtr
)++))
1432 data
= le2be16dbl(data
);
1444 *frameUsed
+= usedf
-frameLeft
;
1449 static ssize_t
ata_ctx_u16le(const u_char
*userPtr
, size_t userCount
,
1450 u_char frame
[], ssize_t
*frameUsed
,
1453 /* this should help gcc to stuff everything into registers */
1454 long bal
= sound
.bal
;
1455 long hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1456 ssize_t used
, usedf
;
1460 if (!sound
.soft
.stereo
) {
1461 u_short
*p
= (u_short
*)&frame
[*frameUsed
];
1462 u_short data
= sound
.data
;
1463 while (frameLeft
>= 4) {
1467 if (get_user(data
, ((u_short
*)userPtr
)++))
1469 data
= le2be16(data
) ^ 0x8000;
1480 u_long
*p
= (u_long
*)&frame
[*frameUsed
];
1481 u_long data
= sound
.data
;
1482 while (frameLeft
>= 4) {
1486 if (get_user(data
, ((u_int
*)userPtr
)++))
1488 data
= le2be16dbl(data
) ^ 0x80008000;
1500 *frameUsed
+= usedf
-frameLeft
;
1503 #endif /* CONFIG_ATARI */
1507 static ssize_t
ami_ct_law(const u_char
*userPtr
, size_t userCount
,
1508 u_char frame
[], ssize_t
*frameUsed
,
1511 char *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma8
: alaw2dma8
;
1512 ssize_t count
, used
;
1514 if (!sound
.soft
.stereo
) {
1515 u_char
*p
= &frame
[*frameUsed
];
1516 count
= min(userCount
, frameLeft
) & ~1;
1520 if (get_user(data
, userPtr
++))
1526 u_char
*left
= &frame
[*frameUsed
>>1];
1527 u_char
*right
= left
+sq
.block_size_half
;
1528 count
= min(userCount
, frameLeft
)>>1 & ~1;
1532 if (get_user(data
, userPtr
++))
1534 *left
++ = table
[data
];
1535 if (get_user(data
, userPtr
++))
1537 *right
++ = table
[data
];
1546 static ssize_t
ami_ct_s8(const u_char
*userPtr
, size_t userCount
,
1547 u_char frame
[], ssize_t
*frameUsed
, ssize_t frameLeft
)
1549 ssize_t count
, used
;
1551 if (!sound
.soft
.stereo
) {
1552 void *p
= &frame
[*frameUsed
];
1553 count
= min(userCount
, frameLeft
) & ~1;
1555 if (copy_from_user(p
, userPtr
, count
))
1558 u_char
*left
= &frame
[*frameUsed
>>1];
1559 u_char
*right
= left
+sq
.block_size_half
;
1560 count
= min(userCount
, frameLeft
)>>1 & ~1;
1563 if (get_user(*left
++, userPtr
++)
1564 || get_user(*right
++, userPtr
++))
1574 static ssize_t
ami_ct_u8(const u_char
*userPtr
, size_t userCount
,
1575 u_char frame
[], ssize_t
*frameUsed
, ssize_t frameLeft
)
1577 ssize_t count
, used
;
1579 if (!sound
.soft
.stereo
) {
1580 char *p
= &frame
[*frameUsed
];
1581 count
= min(userCount
, frameLeft
) & ~1;
1585 if (get_user(data
, userPtr
++))
1591 u_char
*left
= &frame
[*frameUsed
>>1];
1592 u_char
*right
= left
+sq
.block_size_half
;
1593 count
= min(userCount
, frameLeft
)>>1 & ~1;
1597 if (get_user(data
, userPtr
++))
1599 *left
++ = data
^ 0x80;
1600 if (get_user(data
, userPtr
++))
1602 *right
++ = data
^ 0x80;
1611 static ssize_t
ami_ct_s16be(const u_char
*userPtr
, size_t userCount
,
1612 u_char frame
[], ssize_t
*frameUsed
,
1615 ssize_t count
, used
;
1618 if (!sound
.soft
.stereo
) {
1619 u_char
*high
= &frame
[*frameUsed
>>1];
1620 u_char
*low
= high
+sq
.block_size_half
;
1621 count
= min(userCount
, frameLeft
)>>1 & ~1;
1624 if (get_user(data
, ((u_short
*)userPtr
)++))
1627 *low
++ = (data
>>2) & 0x3f;
1631 u_char
*lefth
= &frame
[*frameUsed
>>2];
1632 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1633 u_char
*righth
= lefth
+sq
.block_size_half
;
1634 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1635 count
= min(userCount
, frameLeft
)>>2 & ~1;
1638 if (get_user(data
, ((u_short
*)userPtr
)++))
1641 *leftl
++ = (data
>>2) & 0x3f;
1642 if (get_user(data
, ((u_short
*)userPtr
)++))
1644 *righth
++ = data
>>8;
1645 *rightl
++ = (data
>>2) & 0x3f;
1654 static ssize_t
ami_ct_u16be(const u_char
*userPtr
, size_t userCount
,
1655 u_char frame
[], ssize_t
*frameUsed
,
1658 ssize_t count
, used
;
1661 if (!sound
.soft
.stereo
) {
1662 u_char
*high
= &frame
[*frameUsed
>>1];
1663 u_char
*low
= high
+sq
.block_size_half
;
1664 count
= min(userCount
, frameLeft
)>>1 & ~1;
1667 if (get_user(data
, ((u_short
*)userPtr
)++))
1671 *low
++ = (data
>>2) & 0x3f;
1675 u_char
*lefth
= &frame
[*frameUsed
>>2];
1676 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1677 u_char
*righth
= lefth
+sq
.block_size_half
;
1678 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1679 count
= min(userCount
, frameLeft
)>>2 & ~1;
1682 if (get_user(data
, ((u_short
*)userPtr
)++))
1686 *leftl
++ = (data
>>2) & 0x3f;
1687 if (get_user(data
, ((u_short
*)userPtr
)++))
1690 *righth
++ = data
>>8;
1691 *rightl
++ = (data
>>2) & 0x3f;
1700 static ssize_t
ami_ct_s16le(const u_char
*userPtr
, size_t userCount
,
1701 u_char frame
[], ssize_t
*frameUsed
,
1704 ssize_t count
, used
;
1707 if (!sound
.soft
.stereo
) {
1708 u_char
*high
= &frame
[*frameUsed
>>1];
1709 u_char
*low
= high
+sq
.block_size_half
;
1710 count
= min(userCount
, frameLeft
)>>1 & ~1;
1713 if (get_user(data
, ((u_short
*)userPtr
)++))
1715 data
= le2be16(data
);
1717 *low
++ = (data
>>2) & 0x3f;
1721 u_char
*lefth
= &frame
[*frameUsed
>>2];
1722 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1723 u_char
*righth
= lefth
+sq
.block_size_half
;
1724 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1725 count
= min(userCount
, frameLeft
)>>2 & ~1;
1728 if (get_user(data
, ((u_short
*)userPtr
)++))
1730 data
= le2be16(data
);
1732 *leftl
++ = (data
>>2) & 0x3f;
1733 if (get_user(data
, ((u_short
*)userPtr
)++))
1735 data
= le2be16(data
);
1736 *righth
++ = data
>>8;
1737 *rightl
++ = (data
>>2) & 0x3f;
1746 static ssize_t
ami_ct_u16le(const u_char
*userPtr
, size_t userCount
,
1747 u_char frame
[], ssize_t
*frameUsed
,
1750 ssize_t count
, used
;
1753 if (!sound
.soft
.stereo
) {
1754 u_char
*high
= &frame
[*frameUsed
>>1];
1755 u_char
*low
= high
+sq
.block_size_half
;
1756 count
= min(userCount
, frameLeft
)>>1 & ~1;
1759 if (get_user(data
, ((u_short
*)userPtr
)++))
1761 data
= le2be16(data
) ^ 0x8000;
1763 *low
++ = (data
>>2) & 0x3f;
1767 u_char
*lefth
= &frame
[*frameUsed
>>2];
1768 u_char
*leftl
= lefth
+sq
.block_size_quarter
;
1769 u_char
*righth
= lefth
+sq
.block_size_half
;
1770 u_char
*rightl
= righth
+sq
.block_size_quarter
;
1771 count
= min(userCount
, frameLeft
)>>2 & ~1;
1774 if (get_user(data
, ((u_short
*)userPtr
)++))
1776 data
= le2be16(data
) ^ 0x8000;
1778 *leftl
++ = (data
>>2) & 0x3f;
1779 if (get_user(data
, ((u_short
*)userPtr
)++))
1781 data
= le2be16(data
) ^ 0x8000;
1782 *righth
++ = data
>>8;
1783 *rightl
++ = (data
>>2) & 0x3f;
1790 #endif /* CONFIG_AMIGA */
1793 static ssize_t
pmac_ct_law(const u_char
*userPtr
, size_t userCount
,
1794 u_char frame
[], ssize_t
*frameUsed
,
1797 short *table
= sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma16
: alaw2dma16
;
1798 ssize_t count
, used
;
1799 short *p
= (short *) &frame
[*frameUsed
];
1800 int val
, stereo
= sound
.soft
.stereo
;
1805 used
= count
= min(userCount
, frameLeft
);
1808 if (get_user(data
, userPtr
++))
1813 if (get_user(data
, userPtr
++))
1820 *frameUsed
+= used
* 4;
1821 return stereo
? used
* 2: used
;
1825 static ssize_t
pmac_ct_s8(const u_char
*userPtr
, size_t userCount
,
1826 u_char frame
[], ssize_t
*frameUsed
,
1829 ssize_t count
, used
;
1830 short *p
= (short *) &frame
[*frameUsed
];
1831 int val
, stereo
= sound
.soft
.stereo
;
1836 used
= count
= min(userCount
, frameLeft
);
1839 if (get_user(data
, userPtr
++))
1844 if (get_user(data
, userPtr
++))
1851 *frameUsed
+= used
* 4;
1852 return stereo
? used
* 2: used
;
1856 static ssize_t
pmac_ct_u8(const u_char
*userPtr
, size_t userCount
,
1857 u_char frame
[], ssize_t
*frameUsed
,
1860 ssize_t count
, used
;
1861 short *p
= (short *) &frame
[*frameUsed
];
1862 int val
, stereo
= sound
.soft
.stereo
;
1867 used
= count
= min(userCount
, frameLeft
);
1870 if (get_user(data
, userPtr
++))
1872 val
= (data
^ 0x80) << 8;
1875 if (get_user(data
, userPtr
++))
1877 val
= (data
^ 0x80) << 8;
1882 *frameUsed
+= used
* 4;
1883 return stereo
? used
* 2: used
;
1887 static ssize_t
pmac_ct_s16(const u_char
*userPtr
, size_t userCount
,
1888 u_char frame
[], ssize_t
*frameUsed
,
1891 ssize_t count
, used
;
1892 int stereo
= sound
.soft
.stereo
;
1893 short *fp
= (short *) &frame
[*frameUsed
];
1896 userCount
>>= (stereo
? 2: 1);
1897 used
= count
= min(userCount
, frameLeft
);
1899 short *up
= (short *) userPtr
;
1902 if (get_user(data
, up
++))
1909 if (copy_from_user(fp
, userPtr
, count
* 4))
1912 *frameUsed
+= used
* 4;
1913 return stereo
? used
* 4: used
* 2;
1916 static ssize_t
pmac_ct_u16(const u_char
*userPtr
, size_t userCount
,
1917 u_char frame
[], ssize_t
*frameUsed
,
1920 ssize_t count
, used
;
1921 int mask
= (sound
.soft
.format
== AFMT_U16_LE
? 0x0080: 0x8000);
1922 int stereo
= sound
.soft
.stereo
;
1923 short *fp
= (short *) &frame
[*frameUsed
];
1924 short *up
= (short *) userPtr
;
1927 userCount
>>= (stereo
? 2: 1);
1928 used
= count
= min(userCount
, frameLeft
);
1931 if (get_user(data
, up
++))
1936 if (get_user(data
, up
++))
1943 *frameUsed
+= used
* 4;
1944 return stereo
? used
* 4: used
* 2;
1948 static ssize_t
pmac_ctx_law(const u_char
*userPtr
, size_t userCount
,
1949 u_char frame
[], ssize_t
*frameUsed
,
1952 unsigned short *table
= (unsigned short *)
1953 (sound
.soft
.format
== AFMT_MU_LAW
? ulaw2dma16
: alaw2dma16
);
1954 unsigned int data
= sound
.data
;
1955 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
1956 int bal
= sound
.bal
;
1957 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
1959 int stereo
= sound
.soft
.stereo
;
1971 if (get_user(c
, userPtr
++))
1975 if (get_user(c
, userPtr
++))
1977 data
= (data
<< 16) + table
[c
];
1979 data
= (data
<< 16) + data
;
1989 *frameUsed
+= (ftotal
- frameLeft
) * 4;
1990 utotal
-= userCount
;
1991 return stereo
? utotal
* 2: utotal
;
1995 static ssize_t
pmac_ctx_s8(const u_char
*userPtr
, size_t userCount
,
1996 u_char frame
[], ssize_t
*frameUsed
,
1999 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2000 unsigned int data
= sound
.data
;
2001 int bal
= sound
.bal
;
2002 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2003 int stereo
= sound
.soft
.stereo
;
2016 if (get_user(c
, userPtr
++))
2020 if (get_user(c
, userPtr
++))
2022 data
= (data
<< 16) + (c
<< 8);
2024 data
= (data
<< 16) + data
;
2034 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2035 utotal
-= userCount
;
2036 return stereo
? utotal
* 2: utotal
;
2040 static ssize_t
pmac_ctx_u8(const u_char
*userPtr
, size_t userCount
,
2041 u_char frame
[], ssize_t
*frameUsed
,
2044 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2045 unsigned int data
= sound
.data
;
2046 int bal
= sound
.bal
;
2047 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2048 int stereo
= sound
.soft
.stereo
;
2061 if (get_user(c
, userPtr
++))
2063 data
= (c
^ 0x80) << 8;
2065 if (get_user(c
, userPtr
++))
2067 data
= (data
<< 16) + ((c
^ 0x80) << 8);
2069 data
= (data
<< 16) + data
;
2079 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2080 utotal
-= userCount
;
2081 return stereo
? utotal
* 2: utotal
;
2085 static ssize_t
pmac_ctx_s16(const u_char
*userPtr
, size_t userCount
,
2086 u_char frame
[], ssize_t
*frameUsed
,
2089 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2090 unsigned int data
= sound
.data
;
2091 unsigned short *up
= (unsigned short *) userPtr
;
2092 int bal
= sound
.bal
;
2093 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2094 int stereo
= sound
.soft
.stereo
;
2098 userCount
>>= (stereo
? 2: 1);
2106 if (get_user(data
, up
++))
2109 if (get_user(c
, up
++))
2111 data
= (data
<< 16) + c
;
2113 data
= (data
<< 16) + data
;
2123 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2124 utotal
-= userCount
;
2125 return stereo
? utotal
* 4: utotal
* 2;
2129 static ssize_t
pmac_ctx_u16(const u_char
*userPtr
, size_t userCount
,
2130 u_char frame
[], ssize_t
*frameUsed
,
2133 int mask
= (sound
.soft
.format
== AFMT_U16_LE
? 0x0080: 0x8000);
2134 unsigned int *p
= (unsigned int *) &frame
[*frameUsed
];
2135 unsigned int data
= sound
.data
;
2136 unsigned short *up
= (unsigned short *) userPtr
;
2137 int bal
= sound
.bal
;
2138 int hSpeed
= sound
.hard
.speed
, sSpeed
= sound
.soft
.speed
;
2139 int stereo
= sound
.soft
.stereo
;
2143 userCount
>>= (stereo
? 2: 1);
2151 if (get_user(data
, up
++))
2155 if (get_user(c
, up
++))
2157 data
= (data
<< 16) + (c
^ mask
);
2159 data
= (data
<< 16) + data
;
2169 *frameUsed
+= (ftotal
- frameLeft
) * 4;
2170 utotal
-= userCount
;
2171 return stereo
? utotal
* 4: utotal
* 2;
2174 #endif /* CONFIG_PPC */
2178 static TRANS transTTNormal
= {
2179 ata_ct_law
, ata_ct_law
, ata_ct_s8
, ata_ct_u8
, NULL
, NULL
, NULL
, NULL
2182 static TRANS transTTExpanding
= {
2183 ata_ctx_law
, ata_ctx_law
, ata_ctx_s8
, ata_ctx_u8
, NULL
, NULL
, NULL
, NULL
2186 static TRANS transFalconNormal
= {
2187 ata_ct_law
, ata_ct_law
, ata_ct_s8
, ata_ct_u8
,
2188 ata_ct_s16be
, ata_ct_u16be
, ata_ct_s16le
, ata_ct_u16le
2191 static TRANS transFalconExpanding
= {
2192 ata_ctx_law
, ata_ctx_law
, ata_ctx_s8
, ata_ctx_u8
,
2193 ata_ctx_s16be
, ata_ctx_u16be
, ata_ctx_s16le
, ata_ctx_u16le
2195 #endif /* CONFIG_ATARI */
2198 static TRANS transAmiga
= {
2199 ami_ct_law
, ami_ct_law
, ami_ct_s8
, ami_ct_u8
,
2200 ami_ct_s16be
, ami_ct_u16be
, ami_ct_s16le
, ami_ct_u16le
2202 #endif /* CONFIG_AMIGA */
2205 static TRANS transAwacsNormal
= {
2206 pmac_ct_law
, pmac_ct_law
, pmac_ct_s8
, pmac_ct_u8
,
2207 pmac_ct_s16
, pmac_ct_u16
, pmac_ct_s16
, pmac_ct_u16
2210 static TRANS transAwacsExpand
= {
2211 pmac_ctx_law
, pmac_ctx_law
, pmac_ctx_s8
, pmac_ctx_u8
,
2212 pmac_ctx_s16
, pmac_ctx_u16
, pmac_ctx_s16
, pmac_ctx_u16
2214 #endif /* CONFIG_PPC */
2216 /*** Low level stuff *********************************************************/
2225 static void *AtaAlloc(unsigned int size
, int flags
)
2227 return( atari_stram_alloc( size
, NULL
, "dmasound" ));
2230 static void AtaFree(void *obj
, unsigned int size
)
2232 atari_stram_free( obj
);
2235 static int __init
AtaIrqInit(void)
2237 /* Set up timer A. Timer A
2238 will receive a signal upon end of playing from the sound
2239 hardware. Furthermore Timer A is able to count events
2240 and will cause an interrupt after a programmed number
2241 of events. So all we need to keep the music playing is
2242 to provide the sound hardware with new data upon
2243 an interrupt from timer A. */
2244 mfp
.tim_ct_a
= 0; /* ++roman: Stop timer before programming! */
2245 mfp
.tim_dt_a
= 1; /* Cause interrupt after first event. */
2246 mfp
.tim_ct_a
= 8; /* Turn on event counting. */
2247 /* Register interrupt handler. */
2248 request_irq(IRQ_MFP_TIMA
, ata_sq_interrupt
, IRQ_TYPE_SLOW
,
2249 "DMA sound", ata_sq_interrupt
);
2250 mfp
.int_en_a
|= 0x20; /* Turn interrupt on. */
2251 mfp
.int_mk_a
|= 0x20;
2256 static void AtaIrqCleanUp(void)
2258 mfp
.tim_ct_a
= 0; /* stop timer */
2259 mfp
.int_en_a
&= ~0x20; /* turn interrupt off */
2260 free_irq(IRQ_MFP_TIMA
, ata_sq_interrupt
);
2265 #define TONE_VOXWARE_TO_DB(v) \
2266 (((v) < 0) ? -12 : ((v) > 100) ? 12 : ((v) - 50) * 6 / 25)
2267 #define TONE_DB_TO_VOXWARE(v) (((v) * 25 + ((v) > 0 ? 5 : -5)) / 6 + 50)
2270 static int AtaSetBass(int bass
)
2272 sound
.bass
= TONE_VOXWARE_TO_DB(bass
);
2273 atari_microwire_cmd(MW_LM1992_BASS(sound
.bass
));
2274 return(TONE_DB_TO_VOXWARE(sound
.bass
));
2278 static int AtaSetTreble(int treble
)
2280 sound
.treble
= TONE_VOXWARE_TO_DB(treble
);
2281 atari_microwire_cmd(MW_LM1992_TREBLE(sound
.treble
));
2282 return(TONE_DB_TO_VOXWARE(sound
.treble
));
2292 static void TTSilence(void)
2294 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2295 atari_microwire_cmd(MW_LM1992_PSG_HIGH
); /* mix in PSG signal 1:1 */
2299 static void TTInit(void)
2302 const int freq
[4] = {50066, 25033, 12517, 6258};
2304 /* search a frequency that fits into the allowed error range */
2307 for (i
= 0; i
< arraysize(freq
); i
++)
2308 /* this isn't as much useful for a TT than for a Falcon, but
2309 * then it doesn't hurt very much to implement it for a TT too.
2311 if ((100 * abs(sound
.soft
.speed
- freq
[i
]) / freq
[i
]) < catchRadius
)
2314 sound
.soft
.speed
= freq
[idx
];
2315 sound
.trans
= &transTTNormal
;
2317 sound
.trans
= &transTTExpanding
;
2320 sound
.hard
= sound
.soft
;
2322 if (sound
.hard
.speed
> 50066) {
2323 /* we would need to squeeze the sound, but we won't do that */
2324 sound
.hard
.speed
= 50066;
2325 mode
= DMASND_MODE_50KHZ
;
2326 sound
.trans
= &transTTNormal
;
2327 } else if (sound
.hard
.speed
> 25033) {
2328 sound
.hard
.speed
= 50066;
2329 mode
= DMASND_MODE_50KHZ
;
2330 } else if (sound
.hard
.speed
> 12517) {
2331 sound
.hard
.speed
= 25033;
2332 mode
= DMASND_MODE_25KHZ
;
2333 } else if (sound
.hard
.speed
> 6258) {
2334 sound
.hard
.speed
= 12517;
2335 mode
= DMASND_MODE_12KHZ
;
2337 sound
.hard
.speed
= 6258;
2338 mode
= DMASND_MODE_6KHZ
;
2341 tt_dmasnd
.mode
= (sound
.hard
.stereo
?
2342 DMASND_MODE_STEREO
: DMASND_MODE_MONO
) |
2343 DMASND_MODE_8BIT
| mode
;
2345 sound
.bal
= -sound
.soft
.speed
;
2349 static int TTSetFormat(int format
)
2351 /* TT sound DMA supports only 8bit modes */
2355 return(sound
.soft
.format
);
2365 sound
.soft
.format
= format
;
2366 sound
.soft
.size
= 8;
2367 if (sound
.minDev
== SND_DEV_DSP
) {
2368 sound
.dsp
.format
= format
;
2377 #define VOLUME_VOXWARE_TO_DB(v) \
2378 (((v) < 0) ? -40 : ((v) > 100) ? 0 : ((v) * 2) / 5 - 40)
2379 #define VOLUME_DB_TO_VOXWARE(v) ((((v) + 40) * 5 + 1) / 2)
2382 static int TTSetVolume(int volume
)
2384 sound
.volume_left
= VOLUME_VOXWARE_TO_DB(volume
& 0xff);
2385 atari_microwire_cmd(MW_LM1992_BALLEFT(sound
.volume_left
));
2386 sound
.volume_right
= VOLUME_VOXWARE_TO_DB((volume
& 0xff00) >> 8);
2387 atari_microwire_cmd(MW_LM1992_BALRIGHT(sound
.volume_right
));
2388 return(VOLUME_DB_TO_VOXWARE(sound
.volume_left
) |
2389 (VOLUME_DB_TO_VOXWARE(sound
.volume_right
) << 8));
2393 #define GAIN_VOXWARE_TO_DB(v) \
2394 (((v) < 0) ? -80 : ((v) > 100) ? 0 : ((v) * 4) / 5 - 80)
2395 #define GAIN_DB_TO_VOXWARE(v) ((((v) + 80) * 5 + 1) / 4)
2397 static int TTSetGain(int gain
)
2399 sound
.gain
= GAIN_VOXWARE_TO_DB(gain
);
2400 atari_microwire_cmd(MW_LM1992_VOLUME(sound
.gain
));
2401 return GAIN_DB_TO_VOXWARE(sound
.gain
);
2411 static void FalconSilence(void)
2413 /* stop playback, set sample rate 50kHz for PSG sound */
2414 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2415 tt_dmasnd
.mode
= DMASND_MODE_50KHZ
| DMASND_MODE_STEREO
| DMASND_MODE_8BIT
;
2416 tt_dmasnd
.int_div
= 0; /* STE compatible divider */
2417 tt_dmasnd
.int_ctrl
= 0x0;
2418 tt_dmasnd
.cbar_src
= 0x0000; /* no matrix inputs */
2419 tt_dmasnd
.cbar_dst
= 0x0000; /* no matrix outputs */
2420 tt_dmasnd
.dac_src
= 1; /* connect ADC to DAC, disconnect matrix */
2421 tt_dmasnd
.adc_src
= 3; /* ADC Input = PSG */
2425 static void FalconInit(void)
2427 int divider
, i
, idx
;
2428 const int freq
[8] = {49170, 32780, 24585, 19668, 16390, 12292, 9834, 8195};
2430 /* search a frequency that fits into the allowed error range */
2433 for (i
= 0; i
< arraysize(freq
); i
++)
2434 /* if we will tolerate 3% error 8000Hz->8195Hz (2.38%) would
2435 * be playable without expanding, but that now a kernel runtime
2438 if ((100 * abs(sound
.soft
.speed
- freq
[i
]) / freq
[i
]) < catchRadius
)
2441 sound
.soft
.speed
= freq
[idx
];
2442 sound
.trans
= &transFalconNormal
;
2444 sound
.trans
= &transFalconExpanding
;
2447 sound
.hard
= sound
.soft
;
2449 if (sound
.hard
.size
== 16) {
2450 /* the Falcon can play 16bit samples only in stereo */
2451 sound
.hard
.stereo
= 1;
2454 if (sound
.hard
.speed
> 49170) {
2455 /* we would need to squeeze the sound, but we won't do that */
2456 sound
.hard
.speed
= 49170;
2458 sound
.trans
= &transFalconNormal
;
2459 } else if (sound
.hard
.speed
> 32780) {
2460 sound
.hard
.speed
= 49170;
2462 } else if (sound
.hard
.speed
> 24585) {
2463 sound
.hard
.speed
= 32780;
2465 } else if (sound
.hard
.speed
> 19668) {
2466 sound
.hard
.speed
= 24585;
2468 } else if (sound
.hard
.speed
> 16390) {
2469 sound
.hard
.speed
= 19668;
2471 } else if (sound
.hard
.speed
> 12292) {
2472 sound
.hard
.speed
= 16390;
2474 } else if (sound
.hard
.speed
> 9834) {
2475 sound
.hard
.speed
= 12292;
2477 } else if (sound
.hard
.speed
> 8195) {
2478 sound
.hard
.speed
= 9834;
2481 sound
.hard
.speed
= 8195;
2484 tt_dmasnd
.int_div
= divider
;
2486 /* Setup Falcon sound DMA for playback */
2487 tt_dmasnd
.int_ctrl
= 0x4; /* Timer A int at play end */
2488 tt_dmasnd
.track_select
= 0x0; /* play 1 track, track 1 */
2489 tt_dmasnd
.cbar_src
= 0x0001; /* DMA(25MHz) --> DAC */
2490 tt_dmasnd
.cbar_dst
= 0x0000;
2491 tt_dmasnd
.rec_track_select
= 0;
2492 tt_dmasnd
.dac_src
= 2; /* connect matrix to DAC */
2493 tt_dmasnd
.adc_src
= 0; /* ADC Input = Mic */
2495 tt_dmasnd
.mode
= (sound
.hard
.stereo
?
2496 DMASND_MODE_STEREO
: DMASND_MODE_MONO
) |
2497 ((sound
.hard
.size
== 8) ?
2498 DMASND_MODE_8BIT
: DMASND_MODE_16BIT
) |
2501 sound
.bal
= -sound
.soft
.speed
;
2505 static int FalconSetFormat(int format
)
2508 /* Falcon sound DMA supports 8bit and 16bit modes */
2512 return(sound
.soft
.format
);
2530 sound
.soft
.format
= format
;
2531 sound
.soft
.size
= size
;
2532 if (sound
.minDev
== SND_DEV_DSP
) {
2533 sound
.dsp
.format
= format
;
2534 sound
.dsp
.size
= sound
.soft
.size
;
2543 /* This is for the Falcon output *attenuation* in 1.5dB steps,
2544 * i.e. output level from 0 to -22.5dB in -1.5dB steps.
2546 #define VOLUME_VOXWARE_TO_ATT(v) \
2547 ((v) < 0 ? 15 : (v) > 100 ? 0 : 15 - (v) * 3 / 20)
2548 #define VOLUME_ATT_TO_VOXWARE(v) (100 - (v) * 20 / 3)
2551 static int FalconSetVolume(int volume
)
2553 sound
.volume_left
= VOLUME_VOXWARE_TO_ATT(volume
& 0xff);
2554 sound
.volume_right
= VOLUME_VOXWARE_TO_ATT((volume
& 0xff00) >> 8);
2555 tt_dmasnd
.output_atten
= sound
.volume_left
<< 8 | sound
.volume_right
<< 4;
2556 return(VOLUME_ATT_TO_VOXWARE(sound
.volume_left
) |
2557 VOLUME_ATT_TO_VOXWARE(sound
.volume_right
) << 8);
2561 static void ata_sq_play_next_frame(int index
)
2565 /* used by AtaPlay() if all doubts whether there really is something
2566 * to be played are already wiped out.
2568 start
= sq_block_address(sq
.front
);
2569 end
= start
+((sq
.count
== index
) ? sq
.rear_size
: sq
.block_size
);
2570 /* end might not be a legal virtual address. */
2571 DMASNDSetEnd(VTOP(end
- 1) + 1);
2572 DMASNDSetBase(VTOP(start
));
2573 /* Since only an even number of samples per frame can
2574 be played, we might lose one byte here. (TO DO) */
2575 sq
.front
= (sq
.front
+1) % sq
.max_count
;
2577 tt_dmasnd
.ctrl
= DMASND_CTRL_ON
| DMASND_CTRL_REPEAT
;
2581 static void AtaPlay(void)
2583 /* ++TeSche: Note that sq.playing is no longer just a flag but holds
2584 * the number of frames the DMA is currently programmed for instead,
2585 * may be 0, 1 (currently being played) or 2 (pre-programmed).
2587 * Changes done to sq.count and sq.playing are a bit more subtle again
2588 * so now I must admit I also prefer disabling the irq here rather
2589 * than considering all possible situations. But the point is that
2590 * disabling the irq doesn't have any bad influence on this version of
2591 * the driver as we benefit from having pre-programmed the DMA
2592 * wherever possible: There's no need to reload the DMA at the exact
2593 * time of an interrupt but only at some time while the pre-programmed
2596 atari_disable_irq(IRQ_MFP_TIMA
);
2598 if (sq
.playing
== 2 || /* DMA is 'full' */
2599 sq
.count
<= 0) { /* nothing to do */
2600 atari_enable_irq(IRQ_MFP_TIMA
);
2604 if (sq
.playing
== 0) {
2605 /* looks like there's nothing 'in' the DMA yet, so try
2606 * to put two frames into it (at least one is available).
2608 if (sq
.count
== 1 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2609 /* hmmm, the only existing frame is not
2610 * yet filled and we're not syncing?
2612 atari_enable_irq(IRQ_MFP_TIMA
);
2615 ata_sq_play_next_frame(1);
2616 if (sq
.count
== 1) {
2617 /* no more frames */
2618 atari_enable_irq(IRQ_MFP_TIMA
);
2621 if (sq
.count
== 2 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2622 /* hmmm, there were two frames, but the second
2623 * one is not yet filled and we're not syncing?
2625 atari_enable_irq(IRQ_MFP_TIMA
);
2628 ata_sq_play_next_frame(2);
2630 /* there's already a frame being played so we may only stuff
2631 * one new into the DMA, but even if this may be the last
2632 * frame existing the previous one is still on sq.count.
2634 if (sq
.count
== 2 && sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2635 /* hmmm, the only existing frame is not
2636 * yet filled and we're not syncing?
2638 atari_enable_irq(IRQ_MFP_TIMA
);
2641 ata_sq_play_next_frame(2);
2643 atari_enable_irq(IRQ_MFP_TIMA
);
2647 static void ata_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
)
2650 /* ++TeSche: if you should want to test this... */
2652 if (sq
.playing
== 2)
2654 /* simulate losing an interrupt */
2660 if (sq
.ignore_int
&& (sound
.mach
.type
== DMASND_FALCON
)) {
2661 /* ++TeSche: Falcon only: ignore first irq because it comes
2662 * immediately after starting a frame. after that, irqs come
2663 * (almost) like on the TT.
2670 /* playing was interrupted and sq_reset() has already cleared
2671 * the sq variables, so better don't do anything here.
2673 WAKE_UP(sq
.sync_queue
);
2677 /* Probably ;) one frame is finished. Well, in fact it may be that a
2678 * pre-programmed one is also finished because there has been a long
2679 * delay in interrupt delivery and we've completely lost one, but
2680 * there's no way to detect such a situation. In such a case the last
2681 * frame will be played more than once and the situation will recover
2682 * as soon as the irq gets through.
2688 tt_dmasnd
.ctrl
= DMASND_CTRL_OFF
;
2692 WAKE_UP(sq
.write_queue
);
2693 /* At least one block of the queue is free now
2694 so wake up a writing process blocked because
2697 if ((sq
.playing
!= 1) || (sq
.count
!= 1))
2698 /* We must be a bit carefully here: sq.count indicates the
2699 * number of buffers used and not the number of frames to
2700 * be played. If sq.count==1 and sq.playing==1 that means
2701 * the only remaining frame was already programmed earlier
2702 * (and is currently running) so we mustn't call AtaPlay()
2703 * here, otherwise we'll play one frame too much.
2707 if (!sq
.playing
) WAKE_UP(sq
.sync_queue
);
2708 /* We are not playing after AtaPlay(), so there
2709 is nothing to play any more. Wake up a process
2710 waiting for audio output to drain. */
2712 #endif /* CONFIG_ATARI */
2722 static void *AmiAlloc(unsigned int size
, int flags
)
2724 return(amiga_chip_alloc((long)size
));
2727 static void AmiFree(void *obj
, unsigned int size
)
2729 amiga_chip_free (obj
);
2732 static int __init
AmiIrqInit(void)
2734 /* turn off DMA for audio channels */
2735 custom
.dmacon
= AMI_AUDIO_OFF
;
2737 /* Register interrupt handler. */
2738 if (request_irq(IRQ_AMIGA_AUD0
, ami_sq_interrupt
, 0,
2739 "DMA sound", ami_sq_interrupt
))
2745 static void AmiIrqCleanUp(void)
2747 /* turn off DMA for audio channels */
2748 custom
.dmacon
= AMI_AUDIO_OFF
;
2749 /* release the interrupt */
2750 free_irq(IRQ_AMIGA_AUD0
, ami_sq_interrupt
);
2754 static void AmiSilence(void)
2756 /* turn off DMA for audio channels */
2757 custom
.dmacon
= AMI_AUDIO_OFF
;
2761 static void AmiInit(void)
2767 if (sound
.soft
.speed
)
2768 period
= amiga_colorclock
/sound
.soft
.speed
-1;
2770 period
= amiga_audio_min_period
;
2771 sound
.hard
= sound
.soft
;
2772 sound
.trans
= &transAmiga
;
2774 if (period
< amiga_audio_min_period
) {
2775 /* we would need to squeeze the sound, but we won't do that */
2776 period
= amiga_audio_min_period
;
2777 } else if (period
> 65535) {
2780 sound
.hard
.speed
= amiga_colorclock
/(period
+1);
2782 for (i
= 0; i
< 4; i
++)
2783 custom
.aud
[i
].audper
= period
;
2784 amiga_audio_period
= period
;
2786 AmiSetTreble(50); /* recommended for newer amiga models */
2790 static int AmiSetFormat(int format
)
2794 /* Amiga sound DMA supports 8bit and 16bit (pseudo 14 bit) modes */
2798 return(sound
.soft
.format
);
2816 sound
.soft
.format
= format
;
2817 sound
.soft
.size
= size
;
2818 if (sound
.minDev
== SND_DEV_DSP
) {
2819 sound
.dsp
.format
= format
;
2820 sound
.dsp
.size
= sound
.soft
.size
;
2828 #define VOLUME_VOXWARE_TO_AMI(v) \
2829 (((v) < 0) ? 0 : ((v) > 100) ? 64 : ((v) * 64)/100)
2830 #define VOLUME_AMI_TO_VOXWARE(v) ((v)*100/64)
2832 static int AmiSetVolume(int volume
)
2834 sound
.volume_left
= VOLUME_VOXWARE_TO_AMI(volume
& 0xff);
2835 custom
.aud
[0].audvol
= sound
.volume_left
;
2836 sound
.volume_right
= VOLUME_VOXWARE_TO_AMI((volume
& 0xff00) >> 8);
2837 custom
.aud
[1].audvol
= sound
.volume_right
;
2838 return(VOLUME_AMI_TO_VOXWARE(sound
.volume_left
) |
2839 (VOLUME_AMI_TO_VOXWARE(sound
.volume_right
) << 8));
2842 static int AmiSetTreble(int treble
)
2844 sound
.treble
= treble
;
2853 #define AMI_PLAY_LOADED 1
2854 #define AMI_PLAY_PLAYING 2
2855 #define AMI_PLAY_MASK 3
2858 static void ami_sq_play_next_frame(int index
)
2860 u_char
*start
, *ch0
, *ch1
, *ch2
, *ch3
;
2863 /* used by AmiPlay() if all doubts whether there really is something
2864 * to be played are already wiped out.
2866 start
= sq_block_address(sq
.front
);
2867 size
= (sq
.count
== index
? sq
.rear_size
: sq
.block_size
)>>1;
2869 if (sound
.hard
.stereo
) {
2871 ch1
= start
+sq
.block_size_half
;
2877 if (sound
.hard
.size
== 8) {
2878 custom
.aud
[0].audlc
= (u_short
*)ZTWO_PADDR(ch0
);
2879 custom
.aud
[0].audlen
= size
;
2880 custom
.aud
[1].audlc
= (u_short
*)ZTWO_PADDR(ch1
);
2881 custom
.aud
[1].audlen
= size
;
2882 custom
.dmacon
= AMI_AUDIO_8
;
2885 custom
.aud
[0].audlc
= (u_short
*)ZTWO_PADDR(ch0
);
2886 custom
.aud
[0].audlen
= size
;
2887 custom
.aud
[1].audlc
= (u_short
*)ZTWO_PADDR(ch1
);
2888 custom
.aud
[1].audlen
= size
;
2889 if (sound
.volume_left
== 64 && sound
.volume_right
== 64) {
2890 /* We can play pseudo 14-bit only with the maximum volume */
2891 ch3
= ch0
+sq
.block_size_quarter
;
2892 ch2
= ch1
+sq
.block_size_quarter
;
2893 custom
.aud
[2].audvol
= 1; /* we are being affected by the beeps */
2894 custom
.aud
[3].audvol
= 1; /* restoring volume here helps a bit */
2895 custom
.aud
[2].audlc
= (u_short
*)ZTWO_PADDR(ch2
);
2896 custom
.aud
[2].audlen
= size
;
2897 custom
.aud
[3].audlc
= (u_short
*)ZTWO_PADDR(ch3
);
2898 custom
.aud
[3].audlen
= size
;
2899 custom
.dmacon
= AMI_AUDIO_14
;
2901 custom
.dmacon
= AMI_AUDIO_8
;
2903 sq
.front
= (sq
.front
+1) % sq
.max_count
;
2904 sq
.playing
|= AMI_PLAY_LOADED
;
2908 static void AmiPlay(void)
2912 custom
.intena
= IF_AUD0
;
2914 if (sq
.playing
& AMI_PLAY_LOADED
) {
2915 /* There's already a frame loaded */
2916 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2920 if (sq
.playing
& AMI_PLAY_PLAYING
)
2921 /* Increase threshold: frame 1 is already being played */
2924 if (sq
.count
< minframes
) {
2926 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2930 if (sq
.count
<= minframes
&& sq
.rear_size
< sq
.block_size
&& !sq
.syncing
) {
2931 /* hmmm, the only existing frame is not
2932 * yet filled and we're not syncing?
2934 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2938 ami_sq_play_next_frame(minframes
);
2940 custom
.intena
= IF_SETCLR
| IF_AUD0
;
2944 static void ami_sq_interrupt(int irq
, void *dummy
, struct pt_regs
*fp
)
2949 /* Playing was interrupted and sq_reset() has already cleared
2950 * the sq variables, so better don't do anything here.
2952 WAKE_UP(sq
.sync_queue
);
2956 if (sq
.playing
& AMI_PLAY_PLAYING
) {
2957 /* We've just finished a frame */
2959 WAKE_UP(sq
.write_queue
);
2962 if (sq
.playing
& AMI_PLAY_LOADED
)
2963 /* Increase threshold: frame 1 is already being played */
2966 /* Shift the flags */
2967 sq
.playing
= (sq
.playing
<<1) & AMI_PLAY_MASK
;
2970 /* No frame is playing, disable audio DMA */
2971 custom
.dmacon
= AMI_AUDIO_OFF
;
2973 if (sq
.count
>= minframes
)
2974 /* Try to play the next frame */
2978 /* Nothing to play anymore.
2979 Wake up a process waiting for audio output to drain. */
2980 WAKE_UP(sq
.sync_queue
);
2982 #endif /* CONFIG_AMIGA */
2987 * PCI PowerMac, with AWACS and DBDMA.
2990 static void *PMacAlloc(unsigned int size
, int flags
)
2992 return kmalloc(size
, flags
);
2995 static void PMacFree(void *ptr
, unsigned int size
)
3000 static int __init
PMacIrqInit(void)
3002 if (request_irq(awacs_irq
, pmac_awacs_intr
, 0, "AWACS", 0)
3003 || request_irq(awacs_tx_irq
, pmac_awacs_tx_intr
, 0, "AWACS out", 0))
3009 static void PMacIrqCleanup(void)
3011 /* turn off output dma */
3012 out_le32(&awacs_txdma
->control
, RUN
<<16);
3013 /* disable interrupts from awacs interface */
3014 out_le32(&awacs
->control
, in_le32(&awacs
->control
) & 0xfff);
3015 free_irq(awacs_irq
, pmac_awacs_intr
);
3016 free_irq(awacs_tx_irq
, pmac_awacs_tx_intr
);
3017 kfree(awacs_tx_cmd_space
);
3020 kd_mksound
= orig_mksound
;
3021 #ifdef CONFIG_PMAC_PBOOK
3022 notifier_chain_unregister(&sleep_notifier_list
, &awacs_sleep_notifier
);
3027 static void PMacSilence(void)
3029 /* turn off output dma */
3030 out_le32(&awacs_txdma
->control
, RUN
<<16);
3033 static int awacs_freqs
[8] = {
3034 44100, 29400, 22050, 17640, 14700, 11025, 8820, 7350
3037 static void PMacInit(void)
3041 switch (sound
.soft
.format
) {
3044 sound
.hard
.format
= AFMT_S16_LE
;
3047 sound
.hard
.format
= AFMT_S16_BE
;
3050 sound
.hard
.stereo
= 1;
3051 sound
.hard
.size
= 16;
3054 * If we have a sample rate which is within catchRadius percent
3055 * of the requested value, we don't have to expand the samples.
3056 * Otherwise choose the next higher rate.
3057 * N.B.: burgundy awacs (iMac and later) only works at 44100 Hz.
3059 i
= (awacs_revision
>= AWACS_BURGUNDY
)? 1: 8;
3061 tolerance
= catchRadius
* awacs_freqs
[--i
] / 100;
3062 } while (sound
.soft
.speed
> awacs_freqs
[i
] + tolerance
&& i
> 0);
3063 if (sound
.soft
.speed
>= awacs_freqs
[i
] - tolerance
)
3064 sound
.trans
= &transAwacsNormal
;
3066 sound
.trans
= &transAwacsExpand
;
3067 sound
.hard
.speed
= awacs_freqs
[i
];
3068 awacs_rate_index
= i
;
3071 /* XXX disable error interrupt on burgundy for now */
3072 out_le32(&awacs
->control
, MASK_IEPC
| (i
<< 8) | 0x11
3073 | (awacs_revision
< AWACS_BURGUNDY
? MASK_IEE
: 0));
3074 awacs_reg
[1] = (awacs_reg
[1] & ~MASK_SAMPLERATE
) | (i
<< 3);
3075 awacs_write(awacs_reg
[1] | MASK_ADDR1
);
3076 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3078 sound
.bal
= -sound
.soft
.speed
;
3081 static int PMacSetFormat(int format
)
3087 return sound
.soft
.format
;
3101 printk(KERN_ERR
"dmasound: unknown format 0x%x, using AFMT_U8\n",
3107 sound
.soft
.format
= format
;
3108 sound
.soft
.size
= size
;
3109 if (sound
.minDev
== SND_DEV_DSP
) {
3110 sound
.dsp
.format
= format
;
3111 sound
.dsp
.size
= size
;
3119 #define AWACS_VOLUME_TO_MASK(x) (15 - ((((x) - 1) * 15) / 99))
3120 #define AWACS_MASK_TO_VOLUME(y) (100 - ((y) * 99 / 15))
3122 static int awacs_get_volume(int reg
, int lshift
)
3126 volume
= AWACS_MASK_TO_VOLUME((reg
>> lshift
) & 0xf);
3127 volume
|= AWACS_MASK_TO_VOLUME(reg
& 0xf) << 8;
3131 static int awacs_volume_setter(int volume
, int n
, int mute
, int lshift
)
3135 if (mute
&& volume
== 0) {
3136 r1
= awacs_reg
[1] | mute
;
3138 r1
= awacs_reg
[1] & ~mute
;
3139 rn
= awacs_reg
[n
] & ~(0xf | (0xf << lshift
));
3140 rn
|= ((AWACS_VOLUME_TO_MASK(volume
& 0xff) & 0xf) << lshift
);
3141 rn
|= AWACS_VOLUME_TO_MASK((volume
>> 8) & 0xff) & 0xf;
3143 awacs_write((n
<< 12) | rn
);
3144 volume
= awacs_get_volume(rn
, lshift
);
3146 if (r1
!= awacs_reg
[1]) {
3148 awacs_write(r1
| MASK_ADDR1
);
3153 static int PMacSetVolume(int volume
)
3155 return awacs_volume_setter(volume
, 2, MASK_AMUTE
, 6);
3158 static void PMacPlay(void)
3160 volatile struct dbdma_cmd
*cp
;
3162 unsigned long flags
;
3164 save_flags(flags
); cli();
3166 /* sound takes precedence over beeps */
3167 out_le32(&awacs_txdma
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16);
3168 out_le32(&awacs
->control
,
3169 (in_le32(&awacs
->control
) & ~0x1f00)
3170 || (awacs_rate_index
<< 8));
3171 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3174 i
= sq
.front
+ sq
.playing
;
3175 if (i
>= sq
.max_count
)
3177 while (sq
.playing
< 2 && sq
.playing
< sq
.count
) {
3178 count
= (sq
.count
== sq
.playing
+ 1)? sq
.rear_size
: sq
.block_size
;
3179 if (count
< sq
.block_size
&& !sq
.syncing
)
3180 /* last block not yet filled, and we're not syncing. */
3182 cp
= &awacs_tx_cmds
[i
];
3183 st_le16(&cp
->req_count
, count
);
3184 st_le16(&cp
->xfer_status
, 0);
3185 if (++i
>= sq
.max_count
)
3187 out_le16(&awacs_tx_cmds
[i
].command
, DBDMA_STOP
);
3188 out_le16(&cp
->command
, OUTPUT_MORE
+ INTR_ALWAYS
);
3189 if (sq
.playing
== 0)
3190 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(cp
));
3191 out_le32(&awacs_txdma
->control
, ((RUN
|WAKE
) << 16) + (RUN
|WAKE
));
3194 restore_flags(flags
);
3198 pmac_awacs_tx_intr(int irq
, void *devid
, struct pt_regs
*regs
)
3202 volatile struct dbdma_cmd
*cp
;
3204 while (sq
.playing
> 0) {
3205 cp
= &awacs_tx_cmds
[i
];
3206 stat
= ld_le16(&cp
->xfer_status
);
3207 if ((stat
& ACTIVE
) == 0)
3208 break; /* this frame is still going */
3211 if (++i
>= sq
.max_count
)
3215 WAKE_UP(sq
.write_queue
);
3221 WAKE_UP(sq
.sync_queue
);
3225 pmac_awacs_intr(int irq
, void *devid
, struct pt_regs
*regs
)
3227 int ctrl
= in_le32(&awacs
->control
);
3229 if (ctrl
& MASK_PORTCHG
) {
3230 /* do something when headphone is plugged/unplugged? */
3232 if (ctrl
& MASK_CNTLERR
) {
3233 int err
= (in_le32(&awacs
->codec_stat
) & MASK_ERRCODE
) >> 16;
3234 if (err
!= 0 && awacs_revision
< AWACS_BURGUNDY
)
3235 printk(KERN_ERR
"AWACS: error %x\n", err
);
3237 /* Writing 1s to the CNTLERR and PORTCHG bits clears them... */
3238 out_le32(&awacs
->control
, ctrl
);
3242 awacs_write(int val
)
3244 if (awacs_revision
>= AWACS_BURGUNDY
)
3246 while (in_le32(&awacs
->codec_ctrl
) & MASK_NEWECMD
)
3247 ; /* XXX should have timeout */
3248 out_le32(&awacs
->codec_ctrl
, val
| (awacs_subframe
<< 22));
3251 static void awacs_nosound(unsigned long xx
)
3253 unsigned long flags
;
3255 save_flags(flags
); cli();
3257 st_le16(&beep_dbdma_cmd
->command
, DBDMA_STOP
);
3260 restore_flags(flags
);
3263 static struct timer_list beep_timer
= {
3264 NULL
, NULL
, 0, 0, awacs_nosound
3267 static void awacs_mksound(unsigned int hz
, unsigned int ticks
)
3269 unsigned long flags
;
3270 int beep_speed
= (awacs_revision
< AWACS_BURGUNDY
)? BEEP_SPEED
: 0;
3271 int srate
= awacs_freqs
[beep_speed
];
3272 int period
, ncycles
, nsamples
;
3275 static int beep_hz_cache
;
3276 static int beep_nsamples_cache
;
3277 static int beep_volume_cache
;
3279 if (hz
<= srate
/ BEEP_BUFLEN
|| hz
> srate
/ 2) {
3281 /* this is a hack for broken X server code */
3285 /* cancel beep currently playing */
3290 save_flags(flags
); cli();
3291 del_timer(&beep_timer
);
3293 beep_timer
.expires
= jiffies
+ ticks
;
3294 add_timer(&beep_timer
);
3296 if (beep_playing
|| sq
.playing
|| beep_buf
== NULL
) {
3297 restore_flags(flags
);
3298 return; /* too hard, sorry :-( */
3301 st_le16(&beep_dbdma_cmd
->command
, OUTPUT_MORE
+ BR_ALWAYS
);
3302 restore_flags(flags
);
3304 if (hz
== beep_hz_cache
&& beep_volume
== beep_volume_cache
) {
3305 nsamples
= beep_nsamples_cache
;
3307 period
= srate
* 256 / hz
; /* fixed point */
3308 ncycles
= BEEP_BUFLEN
* 256 / period
;
3309 nsamples
= (period
* ncycles
) >> 8;
3310 f
= ncycles
* 65536 / nsamples
;
3313 for (i
= 0; i
< nsamples
; ++i
, p
+= 2) {
3314 p
[0] = p
[1] = beep_wform
[j
>> 8] * beep_volume
;
3315 j
= (j
+ f
) & 0xffff;
3318 beep_volume_cache
= beep_volume
;
3319 beep_nsamples_cache
= nsamples
;
3322 st_le16(&beep_dbdma_cmd
->req_count
, nsamples
*4);
3323 st_le16(&beep_dbdma_cmd
->xfer_status
, 0);
3324 st_le32(&beep_dbdma_cmd
->cmd_dep
, virt_to_bus(beep_dbdma_cmd
));
3325 st_le32(&beep_dbdma_cmd
->phy_addr
, virt_to_bus(beep_buf
));
3327 save_flags(flags
); cli();
3328 if (beep_playing
) { /* i.e. haven't been terminated already */
3329 out_le32(&awacs_txdma
->control
, (RUN
|WAKE
|FLUSH
|PAUSE
) << 16);
3330 out_le32(&awacs
->control
,
3331 (in_le32(&awacs
->control
) & ~0x1f00)
3332 | (beep_speed
<< 8));
3333 out_le32(&awacs
->byteswap
, 0);
3334 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(beep_dbdma_cmd
));
3335 out_le32(&awacs_txdma
->control
, RUN
| (RUN
<< 16));
3337 restore_flags(flags
);
3340 #ifdef CONFIG_PMAC_PBOOK
3342 * Save state when going to sleep, restore it afterwards.
3344 static int awacs_sleep_notify(struct notifier_block
*this,
3345 unsigned long code
, void *x
)
3349 /* XXX we should stop any dma in progress when going to sleep
3350 and restart it when we wake. */
3354 out_le32(&awacs
->control
, MASK_IEPC
3355 | (awacs_rate_index
<< 8) | 0x11
3356 | (awacs_revision
< AWACS_BURGUNDY
? MASK_IEE
: 0));
3357 awacs_write(awacs_reg
[0] | MASK_ADDR0
);
3358 awacs_write(awacs_reg
[1] | MASK_ADDR1
);
3359 awacs_write(awacs_reg
[2] | MASK_ADDR2
);
3360 awacs_write(awacs_reg
[4] | MASK_ADDR4
);
3361 out_le32(&awacs
->byteswap
, sound
.hard
.format
!= AFMT_S16_BE
);
3365 #endif /* CONFIG_PMAC_PBOOK */
3368 /* All the burgundy functions: */
3370 /* Waits for busy flag to clear */
3372 awacs_burgundy_busy_wait(void)
3374 while (in_le32(&awacs
->codec_ctrl
) & MASK_NEWECMD
)
3379 awacs_burgundy_extend_wait(void)
3381 while (!(in_le32(&awacs
->codec_stat
) & MASK_EXTEND
))
3383 while (in_le32(&awacs
->codec_stat
) & MASK_EXTEND
)
3388 awacs_burgundy_wcw(unsigned addr
, unsigned val
)
3390 out_le32(&awacs
->codec_ctrl
, addr
+ 0x200c00 + (val
& 0xff));
3391 awacs_burgundy_busy_wait();
3392 out_le32(&awacs
->codec_ctrl
, addr
+ 0x200d00 +((val
>>8) & 0xff));
3393 awacs_burgundy_busy_wait();
3394 out_le32(&awacs
->codec_ctrl
, addr
+ 0x200e00 +((val
>>16) & 0xff));
3395 awacs_burgundy_busy_wait();
3396 out_le32(&awacs
->codec_ctrl
, addr
+ 0x200f00 +((val
>>24) & 0xff));
3397 awacs_burgundy_busy_wait();
3401 awacs_burgundy_rcw(unsigned addr
)
3406 /* should have timeouts here */
3407 save_flags(flags
); cli();
3409 out_le32(&awacs
->codec_ctrl
, addr
+ 0x100000);
3410 awacs_burgundy_busy_wait();
3411 awacs_burgundy_extend_wait();
3412 val
+= (in_le32(&awacs
->codec_stat
) >> 4) & 0xff;
3414 out_le32(&awacs
->codec_ctrl
, addr
+ 0x100100);
3415 awacs_burgundy_busy_wait();
3416 awacs_burgundy_extend_wait();
3417 val
+= ((in_le32(&awacs
->codec_stat
)>>4) & 0xff) <<8;
3419 out_le32(&awacs
->codec_ctrl
, addr
+ 0x100200);
3420 awacs_burgundy_busy_wait();
3421 awacs_burgundy_extend_wait();
3422 val
+= ((in_le32(&awacs
->codec_stat
)>>4) & 0xff) <<16;
3424 out_le32(&awacs
->codec_ctrl
, addr
+ 0x100300);
3425 awacs_burgundy_busy_wait();
3426 awacs_burgundy_extend_wait();
3427 val
+= ((in_le32(&awacs
->codec_stat
)>>4) & 0xff) <<24;
3429 restore_flags(flags
);
3436 awacs_burgundy_wcb(unsigned addr
, unsigned val
)
3438 out_le32(&awacs
->codec_ctrl
, addr
+ 0x300000 + (val
& 0xff));
3439 awacs_burgundy_busy_wait();
3443 awacs_burgundy_rcb(unsigned addr
)
3448 /* should have timeouts here */
3449 save_flags(flags
); cli();
3451 out_le32(&awacs
->codec_ctrl
, addr
+ 0x100000);
3452 awacs_burgundy_busy_wait();
3453 awacs_burgundy_extend_wait();
3454 val
+= (in_le32(&awacs
->codec_stat
) >> 4) & 0xff;
3456 restore_flags(flags
);
3462 awacs_burgundy_check(void)
3464 /* Checks to see the chip is alive and kicking */
3465 int error
= in_le32(&awacs
->codec_ctrl
) & MASK_ERRCODE
;
3467 return error
== 0xf0000;
3471 awacs_burgundy_init(void)
3473 if (awacs_burgundy_check()) {
3474 printk(KERN_WARNING
"AWACS: disabled by MacOS :-(\n");
3478 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_OUTPUTENABLES
,
3479 DEF_BURGUNDY_OUTPUTENABLES
);
3480 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
3481 DEF_BURGUNDY_MORE_OUTPUTENABLES
);
3482 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_OUTPUTSELECTS
,
3483 DEF_BURGUNDY_OUTPUTSELECTS
);
3485 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL21
,
3486 DEF_BURGUNDY_INPSEL21
);
3487 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_INPSEL3
,
3488 DEF_BURGUNDY_INPSEL3
);
3489 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINCD
,
3490 DEF_BURGUNDY_GAINCD
);
3491 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINLINE
,
3492 DEF_BURGUNDY_GAINLINE
);
3493 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMIC
,
3494 DEF_BURGUNDY_GAINMIC
);
3495 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_GAINMODEM
,
3496 DEF_BURGUNDY_GAINMODEM
);
3498 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER
,
3499 DEF_BURGUNDY_ATTENSPEAKER
);
3500 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENLINEOUT
,
3501 DEF_BURGUNDY_ATTENLINEOUT
);
3502 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENHP
,
3503 DEF_BURGUNDY_ATTENHP
);
3505 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_MASTER_VOLUME
,
3506 DEF_BURGUNDY_MASTER_VOLUME
);
3507 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLCD
,
3508 DEF_BURGUNDY_VOLCD
);
3509 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLLINE
,
3510 DEF_BURGUNDY_VOLLINE
);
3511 awacs_burgundy_wcw(MASK_ADDR_BURGUNDY_VOLMIC
,
3512 DEF_BURGUNDY_VOLMIC
);
3517 awacs_burgundy_write_volume(unsigned address
, int volume
)
3519 int hardvolume
,lvolume
,rvolume
;
3521 lvolume
= (volume
& 0xff) ? (volume
& 0xff) + 155 : 0;
3522 rvolume
= ((volume
>>8)&0xff) ? ((volume
>> 8)&0xff ) + 155 : 0;
3524 hardvolume
= lvolume
+ (rvolume
<< 16);
3526 awacs_burgundy_wcw(address
, hardvolume
);
3530 awacs_burgundy_read_volume(unsigned address
)
3532 int softvolume
,wvolume
;
3534 wvolume
= awacs_burgundy_rcw(address
);
3536 softvolume
= (wvolume
& 0xff) - 155;
3537 softvolume
+= (((wvolume
>> 16) & 0xff) - 155)<<8;
3539 return softvolume
> 0 ? softvolume
: 0;
3546 awacs_burgundy_read_mvolume(unsigned address
)
3548 int lvolume
,rvolume
,wvolume
;
3550 wvolume
= awacs_burgundy_rcw(address
);
3554 rvolume
= (wvolume
& 0xff) - 155;
3555 lvolume
= ((wvolume
& 0xff00)>>8) - 155;
3557 return lvolume
+ (rvolume
<< 8);
3562 awacs_burgundy_write_mvolume(unsigned address
, int volume
)
3564 int lvolume
,rvolume
,hardvolume
;
3566 lvolume
= (volume
&0xff) ? (volume
& 0xff) + 155 :0;
3567 rvolume
= ((volume
>>8) & 0xff) ? (volume
>> 8) + 155 :0;
3569 hardvolume
= lvolume
+ (rvolume
<< 8);
3570 hardvolume
+= (hardvolume
<< 16);
3572 awacs_burgundy_wcw(address
, hardvolume
);
3575 /* End burgundy functions */
3581 /* Turn on sound output, needed on G3 desktop powermacs */
3583 awacs_enable_amp(int spkr_vol
)
3585 struct adb_request req
;
3587 awacs_spkr_vol
= spkr_vol
;
3588 if (adb_hardware
!= ADB_VIACUDA
)
3591 /* turn on headphones */
3592 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
,
3594 while (!req
.complete
) cuda_poll();
3595 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
,
3597 while (!req
.complete
) cuda_poll();
3599 /* turn on speaker */
3600 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
,
3601 0x8a, 3, (100 - (spkr_vol
& 0xff)) * 32 / 100);
3602 while (!req
.complete
) cuda_poll();
3603 cuda_request(&req
, NULL
, 5, CUDA_PACKET
, CUDA_GET_SET_IIC
,
3604 0x8a, 5, (100 - ((spkr_vol
>> 8) & 0xff)) * 32 / 100);
3605 while (!req
.complete
) cuda_poll();
3607 cuda_request(&req
, NULL
, 5, CUDA_PACKET
,
3608 CUDA_GET_SET_IIC
, 0x8a, 1, 0x29);
3609 while (!req
.complete
) cuda_poll();
3612 #endif /* CONFIG_PPC */
3614 /*** Machine definitions *****************************************************/
3618 static MACHINE machTT
= {
3619 DMASND_TT
, AtaAlloc
, AtaFree
, AtaIrqInit
,
3623 TTInit
, TTSilence
, TTSetFormat
, TTSetVolume
,
3624 AtaSetBass
, AtaSetTreble
, TTSetGain
,
3628 static MACHINE machFalcon
= {
3629 DMASND_FALCON
, AtaAlloc
, AtaFree
, AtaIrqInit
,
3633 FalconInit
, FalconSilence
, FalconSetFormat
, FalconSetVolume
,
3634 AtaSetBass
, AtaSetTreble
, NULL
,
3637 #endif /* CONFIG_ATARI */
3640 static MACHINE machAmiga
= {
3641 DMASND_AMIGA
, AmiAlloc
, AmiFree
, AmiIrqInit
,
3645 AmiInit
, AmiSilence
, AmiSetFormat
, AmiSetVolume
,
3646 NULL
, AmiSetTreble
, NULL
,
3649 #endif /* CONFIG_AMIGA */
3652 static MACHINE machPMac
= {
3653 DMASND_AWACS
, PMacAlloc
, PMacFree
, PMacIrqInit
,
3657 PMacInit
, PMacSilence
, PMacSetFormat
, PMacSetVolume
,
3658 NULL
, NULL
, NULL
, /* bass, treble, gain */
3661 #endif /* CONFIG_AMIGA */
3664 /*** Mid level stuff *********************************************************/
3667 static void sound_silence(void)
3669 /* update hardware settings one more */
3670 (*sound
.mach
.init
)();
3672 (*sound
.mach
.silence
)();
3676 static void sound_init(void)
3678 (*sound
.mach
.init
)();
3682 static int sound_set_format(int format
)
3684 return(*sound
.mach
.setFormat
)(format
);
3688 static int sound_set_speed(int speed
)
3691 return(sound
.soft
.speed
);
3693 sound
.soft
.speed
= speed
;
3694 (*sound
.mach
.init
)();
3695 if (sound
.minDev
== SND_DEV_DSP
)
3696 sound
.dsp
.speed
= sound
.soft
.speed
;
3698 return(sound
.soft
.speed
);
3702 static int sound_set_stereo(int stereo
)
3705 return(sound
.soft
.stereo
);
3707 stereo
= !!stereo
; /* should be 0 or 1 now */
3709 sound
.soft
.stereo
= stereo
;
3710 if (sound
.minDev
== SND_DEV_DSP
)
3711 sound
.dsp
.stereo
= stereo
;
3712 (*sound
.mach
.init
)();
3718 static int sound_set_volume(int volume
)
3720 return(*sound
.mach
.setVolume
)(volume
);
3725 static int sound_set_bass(int bass
)
3727 return(sound
.mach
.setBass
? (*sound
.mach
.setBass
)(bass
) : 50);
3730 static int sound_set_gain(int gain
)
3732 return sound
.mach
.setGain
? sound
.mach
.setGain(gain
) : 100;
3734 #endif /* CONFIG_ATARI */
3736 #if defined(CONFIG_ATARI) || defined(CONFIG_AMIGA)
3737 static int sound_set_treble(int treble
)
3739 return(sound
.mach
.setTreble
? (*sound
.mach
.setTreble
)(treble
) : 50);
3741 #endif /* CONFIG_ATARI || CONFIG_AMIGA */
3744 static ssize_t
sound_copy_translate(const u_char
*userPtr
,
3746 u_char frame
[], ssize_t
*frameUsed
,
3749 ssize_t (*ct_func
)(const u_char
*, size_t, u_char
*, ssize_t
*, ssize_t
) = NULL
;
3751 switch (sound
.soft
.format
) {
3753 ct_func
= sound
.trans
->ct_ulaw
;
3756 ct_func
= sound
.trans
->ct_alaw
;
3759 ct_func
= sound
.trans
->ct_s8
;
3762 ct_func
= sound
.trans
->ct_u8
;
3765 ct_func
= sound
.trans
->ct_s16be
;
3768 ct_func
= sound
.trans
->ct_u16be
;
3771 ct_func
= sound
.trans
->ct_s16le
;
3774 ct_func
= sound
.trans
->ct_u16le
;
3778 return ct_func(userPtr
, userCount
, frame
, frameUsed
, frameLeft
);
3785 * /dev/mixer abstraction
3789 #define RECLEVEL_VOXWARE_TO_GAIN(v) \
3790 ((v) < 0 ? 0 : (v) > 100 ? 15 : (v) * 3 / 20)
3791 #define RECLEVEL_GAIN_TO_VOXWARE(v) (((v) * 20 + 2) / 3)
3794 static int mixer_open(struct inode
*inode
, struct file
*file
)
3802 static int mixer_release(struct inode
*inode
, struct file
*file
)
3810 static int mixer_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
3814 switch (sound
.mach
.type
) {
3818 case SOUND_MIXER_READ_DEVMASK
:
3819 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_MIC
| SOUND_MASK_SPEAKER
);
3820 case SOUND_MIXER_READ_RECMASK
:
3821 return IOCTL_OUT(arg
, SOUND_MASK_MIC
);
3822 case SOUND_MIXER_READ_STEREODEVS
:
3823 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_MIC
);
3824 case SOUND_MIXER_READ_CAPS
:
3825 return IOCTL_OUT(arg
, SOUND_CAP_EXCL_INPUT
);
3826 case SOUND_MIXER_READ_VOLUME
:
3827 return IOCTL_OUT(arg
,
3828 VOLUME_ATT_TO_VOXWARE(sound
.volume_left
) |
3829 VOLUME_ATT_TO_VOXWARE(sound
.volume_right
) << 8);
3830 case SOUND_MIXER_WRITE_MIC
:
3831 IOCTL_IN(arg
, data
);
3832 tt_dmasnd
.input_gain
=
3833 RECLEVEL_VOXWARE_TO_GAIN(data
& 0xff) << 4 |
3834 RECLEVEL_VOXWARE_TO_GAIN(data
>> 8 & 0xff);
3835 /* fall thru, return set value */
3836 case SOUND_MIXER_READ_MIC
:
3837 return IOCTL_OUT(arg
,
3838 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd
.input_gain
>> 4 & 0xf) |
3839 RECLEVEL_GAIN_TO_VOXWARE(tt_dmasnd
.input_gain
& 0xf) << 8);
3840 case SOUND_MIXER_READ_SPEAKER
:
3844 sound_ym
.rd_data_reg_sel
= 14;
3845 porta
= sound_ym
.rd_data_reg_sel
;
3847 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3849 case SOUND_MIXER_WRITE_VOLUME
:
3850 IOCTL_IN(arg
, data
);
3851 return IOCTL_OUT(arg
, sound_set_volume(data
));
3852 case SOUND_MIXER_WRITE_SPEAKER
:
3855 IOCTL_IN(arg
, data
);
3857 sound_ym
.rd_data_reg_sel
= 14;
3858 porta
= (sound_ym
.rd_data_reg_sel
& ~0x40) |
3859 (data
< 50 ? 0x40 : 0);
3860 sound_ym
.wd_data
= porta
;
3862 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3869 case SOUND_MIXER_READ_DEVMASK
:
3870 return IOCTL_OUT(arg
,
3871 SOUND_MASK_VOLUME
| SOUND_MASK_TREBLE
| SOUND_MASK_BASS
|
3872 (MACH_IS_TT
? SOUND_MASK_SPEAKER
: 0));
3873 case SOUND_MIXER_READ_RECMASK
:
3874 return IOCTL_OUT(arg
, 0);
3875 case SOUND_MIXER_READ_STEREODEVS
:
3876 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
);
3877 case SOUND_MIXER_READ_VOLUME
:
3878 return IOCTL_OUT(arg
,
3879 VOLUME_DB_TO_VOXWARE(sound
.volume_left
) |
3880 (VOLUME_DB_TO_VOXWARE(sound
.volume_right
) << 8));
3881 case SOUND_MIXER_READ_BASS
:
3882 return IOCTL_OUT(arg
, TONE_DB_TO_VOXWARE(sound
.bass
));
3883 case SOUND_MIXER_READ_TREBLE
:
3884 return IOCTL_OUT(arg
, TONE_DB_TO_VOXWARE(sound
.treble
));
3885 case SOUND_MIXER_READ_OGAIN
:
3886 return IOCTL_OUT(arg
, GAIN_DB_TO_VOXWARE(sound
.gain
));
3887 case SOUND_MIXER_READ_SPEAKER
:
3892 sound_ym
.rd_data_reg_sel
= 14;
3893 porta
= sound_ym
.rd_data_reg_sel
;
3895 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3899 case SOUND_MIXER_WRITE_VOLUME
:
3900 IOCTL_IN(arg
, data
);
3901 return IOCTL_OUT(arg
, sound_set_volume(data
));
3902 case SOUND_MIXER_WRITE_BASS
:
3903 IOCTL_IN(arg
, data
);
3904 return IOCTL_OUT(arg
, sound_set_bass(data
));
3905 case SOUND_MIXER_WRITE_TREBLE
:
3906 IOCTL_IN(arg
, data
);
3907 return IOCTL_OUT(arg
, sound_set_treble(data
));
3908 case SOUND_MIXER_WRITE_OGAIN
:
3909 IOCTL_IN(arg
, data
);
3910 return IOCTL_OUT(arg
, sound_set_gain(data
));
3911 case SOUND_MIXER_WRITE_SPEAKER
:
3914 IOCTL_IN(arg
, data
);
3916 sound_ym
.rd_data_reg_sel
= 14;
3917 porta
= (sound_ym
.rd_data_reg_sel
& ~0x40) |
3918 (data
< 50 ? 0x40 : 0);
3919 sound_ym
.wd_data
= porta
;
3921 return IOCTL_OUT(arg
, porta
& 0x40 ? 0 : 100);
3925 #endif /* CONFIG_ATARI */
3930 case SOUND_MIXER_READ_DEVMASK
:
3931 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
| SOUND_MASK_TREBLE
);
3932 case SOUND_MIXER_READ_RECMASK
:
3933 return IOCTL_OUT(arg
, 0);
3934 case SOUND_MIXER_READ_STEREODEVS
:
3935 return IOCTL_OUT(arg
, SOUND_MASK_VOLUME
);
3936 case SOUND_MIXER_READ_VOLUME
:
3937 return IOCTL_OUT(arg
,
3938 VOLUME_AMI_TO_VOXWARE(sound
.volume_left
) |
3939 VOLUME_AMI_TO_VOXWARE(sound
.volume_right
) << 8);
3940 case SOUND_MIXER_WRITE_VOLUME
:
3941 IOCTL_IN(arg
, data
);
3942 return IOCTL_OUT(arg
, sound_set_volume(data
));
3943 case SOUND_MIXER_READ_TREBLE
:
3944 return IOCTL_OUT(arg
, sound
.treble
);
3945 case SOUND_MIXER_WRITE_TREBLE
:
3946 IOCTL_IN(arg
, data
);
3947 return IOCTL_OUT(arg
, sound_set_treble(data
));
3950 #endif /* CONFIG_AMIGA */
3954 if (awacs_revision
<AWACS_BURGUNDY
) { /* Different IOCTLS for burgundy*/
3956 case SOUND_MIXER_READ_DEVMASK
:
3957 data
= SOUND_MASK_VOLUME
| SOUND_MASK_SPEAKER
3958 | SOUND_MASK_LINE
| SOUND_MASK_MIC
3959 | SOUND_MASK_CD
| SOUND_MASK_RECLEV
3960 | SOUND_MASK_ALTPCM
;
3961 return IOCTL_OUT(arg
, data
);
3962 case SOUND_MIXER_READ_RECMASK
:
3963 data
= SOUND_MASK_LINE
| SOUND_MASK_MIC
3965 return IOCTL_OUT(arg
, data
);
3966 case SOUND_MIXER_READ_RECSRC
:
3968 if (awacs_reg
[0] & MASK_MUX_AUDIN
)
3969 data
|= SOUND_MASK_LINE
;
3970 if (awacs_reg
[0] & MASK_MUX_MIC
)
3971 data
|= SOUND_MASK_MIC
;
3972 if (awacs_reg
[0] & MASK_MUX_CD
)
3973 data
|= SOUND_MASK_CD
;
3974 return IOCTL_OUT(arg
, data
);
3975 case SOUND_MIXER_WRITE_RECSRC
:
3976 IOCTL_IN(arg
, data
);
3977 data
&= (SOUND_MASK_LINE
3978 | SOUND_MASK_MIC
| SOUND_MASK_CD
);
3979 awacs_reg
[0] &= ~(MASK_MUX_CD
| MASK_MUX_MIC
3981 if (data
& SOUND_MASK_LINE
)
3982 awacs_reg
[0] |= MASK_MUX_AUDIN
;
3983 if (data
& SOUND_MASK_MIC
)
3984 awacs_reg
[0] |= MASK_MUX_MIC
;
3985 if (data
& SOUND_MASK_CD
)
3986 awacs_reg
[0] |= MASK_MUX_CD
;
3987 awacs_write(awacs_reg
[0] | MASK_ADDR0
);
3988 return IOCTL_OUT(arg
, data
);
3989 case SOUND_MIXER_READ_STEREODEVS
:
3990 data
= SOUND_MASK_VOLUME
| SOUND_MASK_SPEAKER
3991 | SOUND_MASK_RECLEV
;
3992 return IOCTL_OUT(arg
, data
);
3993 case SOUND_MIXER_READ_CAPS
:
3994 return IOCTL_OUT(arg
, 0);
3995 case SOUND_MIXER_READ_VOLUME
:
3996 data
= (awacs_reg
[1] & MASK_AMUTE
)? 0:
3997 awacs_get_volume(awacs_reg
[2], 6);
3998 return IOCTL_OUT(arg
, data
);
3999 case SOUND_MIXER_WRITE_VOLUME
:
4000 IOCTL_IN(arg
, data
);
4001 return IOCTL_OUT(arg
, sound_set_volume(data
));
4002 case SOUND_MIXER_READ_SPEAKER
:
4003 if (awacs_revision
== 3 && adb_hardware
== ADB_VIACUDA
)
4004 data
= awacs_spkr_vol
;
4006 data
= (awacs_reg
[1] & MASK_CMUTE
)? 0:
4007 awacs_get_volume(awacs_reg
[4], 6);
4008 return IOCTL_OUT(arg
, data
);
4009 case SOUND_MIXER_WRITE_SPEAKER
:
4010 IOCTL_IN(arg
, data
);
4011 if (awacs_revision
== 3 && adb_hardware
== ADB_VIACUDA
)
4012 awacs_enable_amp(data
);
4014 data
= awacs_volume_setter(data
, 4, MASK_CMUTE
, 6);
4015 return IOCTL_OUT(arg
, data
);
4016 case SOUND_MIXER_WRITE_ALTPCM
: /* really bell volume */
4017 IOCTL_IN(arg
, data
);
4018 beep_volume
= data
& 0xff;
4020 case SOUND_MIXER_READ_ALTPCM
:
4021 return IOCTL_OUT(arg
, beep_volume
);
4022 case SOUND_MIXER_WRITE_LINE
:
4023 IOCTL_IN(arg
, data
);
4024 awacs_reg
[0] &= ~MASK_MUX_AUDIN
;
4025 if ((data
& 0xff) >= 50)
4026 awacs_reg
[0] |= MASK_MUX_AUDIN
;
4027 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
4029 case SOUND_MIXER_READ_LINE
:
4030 data
= (awacs_reg
[0] & MASK_MUX_AUDIN
)? 100: 0;
4031 return IOCTL_OUT(arg
, data
);
4032 case SOUND_MIXER_WRITE_MIC
:
4033 IOCTL_IN(arg
, data
);
4035 awacs_reg
[0] &= ~(MASK_MUX_MIC
| MASK_GAINLINE
);
4037 awacs_reg
[0] |= MASK_MUX_MIC
;
4039 awacs_reg
[0] |= MASK_GAINLINE
;
4041 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
4043 case SOUND_MIXER_READ_MIC
:
4044 data
= (awacs_reg
[0] & MASK_MUX_MIC
)?
4045 (awacs_reg
[0] & MASK_GAINLINE
? 100: 50): 0;
4046 return IOCTL_OUT(arg
, data
);
4047 case SOUND_MIXER_WRITE_CD
:
4048 IOCTL_IN(arg
, data
);
4049 awacs_reg
[0] &= ~MASK_MUX_CD
;
4050 if ((data
& 0xff) >= 50)
4051 awacs_reg
[0] |= MASK_MUX_CD
;
4052 awacs_write(MASK_ADDR0
| awacs_reg
[0]);
4054 case SOUND_MIXER_READ_CD
:
4055 data
= (awacs_reg
[0] & MASK_MUX_CD
)? 100: 0;
4056 return IOCTL_OUT(arg
, data
);
4057 case SOUND_MIXER_WRITE_RECLEV
:
4058 IOCTL_IN(arg
, data
);
4059 data
= awacs_volume_setter(data
, 0, 0, 4);
4060 return IOCTL_OUT(arg
, data
);
4061 case SOUND_MIXER_READ_RECLEV
:
4062 data
= awacs_get_volume(awacs_reg
[0], 4);
4063 return IOCTL_OUT(arg
, data
);
4067 /* We are, we are, we are... Burgundy or better */
4069 case SOUND_MIXER_READ_DEVMASK
:
4070 data
= SOUND_MASK_VOLUME
| SOUND_MASK_CD
|
4071 SOUND_MASK_LINE
| SOUND_MASK_MIC
|
4072 SOUND_MASK_SPEAKER
| SOUND_MASK_ALTPCM
;
4073 return IOCTL_OUT(arg
, data
);
4074 case SOUND_MIXER_READ_RECMASK
:
4075 data
= SOUND_MASK_LINE
| SOUND_MASK_MIC
4077 return IOCTL_OUT(arg
, data
);
4078 case SOUND_MIXER_READ_RECSRC
:
4080 if (awacs_reg
[0] & MASK_MUX_AUDIN
)
4081 data
|= SOUND_MASK_LINE
;
4082 if (awacs_reg
[0] & MASK_MUX_MIC
)
4083 data
|= SOUND_MASK_MIC
;
4084 if (awacs_reg
[0] & MASK_MUX_CD
)
4085 data
|= SOUND_MASK_CD
;
4086 return IOCTL_OUT(arg
, data
);
4087 case SOUND_MIXER_WRITE_RECSRC
:
4088 IOCTL_IN(arg
, data
);
4089 data
&= (SOUND_MASK_LINE
4090 | SOUND_MASK_MIC
| SOUND_MASK_CD
);
4091 awacs_reg
[0] &= ~(MASK_MUX_CD
| MASK_MUX_MIC
4093 if (data
& SOUND_MASK_LINE
)
4094 awacs_reg
[0] |= MASK_MUX_AUDIN
;
4095 if (data
& SOUND_MASK_MIC
)
4096 awacs_reg
[0] |= MASK_MUX_MIC
;
4097 if (data
& SOUND_MASK_CD
)
4098 awacs_reg
[0] |= MASK_MUX_CD
;
4099 awacs_write(awacs_reg
[0] | MASK_ADDR0
);
4100 return IOCTL_OUT(arg
, data
);
4101 case SOUND_MIXER_READ_STEREODEVS
:
4102 data
= SOUND_MASK_VOLUME
| SOUND_MASK_SPEAKER
4103 | SOUND_MASK_RECLEV
| SOUND_MASK_CD
4105 return IOCTL_OUT(arg
, data
);
4106 case SOUND_MIXER_READ_CAPS
:
4107 return IOCTL_OUT(arg
, 0);
4108 case SOUND_MIXER_WRITE_VOLUME
:
4109 IOCTL_IN(arg
, data
);
4110 awacs_burgundy_write_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME
, data
);
4112 case SOUND_MIXER_READ_VOLUME
:
4113 return IOCTL_OUT(arg
, awacs_burgundy_read_mvolume(MASK_ADDR_BURGUNDY_MASTER_VOLUME
));
4114 case SOUND_MIXER_WRITE_SPEAKER
:
4115 IOCTL_IN(arg
, data
);
4117 if (!(data
& 0xff)) {
4118 /* Mute the left speaker */
4119 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
4120 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
) & ~0x2);
4122 /* Unmute the left speaker */
4123 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
4124 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
) | 0x2);
4126 if (!(data
& 0xff00)) {
4127 /* Mute the right speaker */
4128 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
4129 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
) & ~0x4);
4131 /* Unmute the right speaker */
4132 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
,
4133 awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES
) | 0x4);
4136 data
= (((data
&0xff)*16)/100 > 0xf ? 0xf :
4137 (((data
&0xff)*16)/100)) +
4138 ((((data
>>8)*16)/100 > 0xf ? 0xf :
4139 ((((data
>>8)*16)/100)))<<4);
4141 awacs_burgundy_wcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER
, ~data
);
4143 case SOUND_MIXER_READ_SPEAKER
:
4144 data
= awacs_burgundy_rcb(MASK_ADDR_BURGUNDY_ATTENSPEAKER
);
4145 data
= (((data
& 0xf)*100)/16) + ((((data
>>4)*100)/16)<<8);
4146 return IOCTL_OUT(arg
, ~data
);
4147 case SOUND_MIXER_WRITE_ALTPCM
: /* really bell volume */
4148 IOCTL_IN(arg
, data
);
4149 beep_volume
= data
& 0xff;
4151 case SOUND_MIXER_READ_ALTPCM
:
4152 return IOCTL_OUT(arg
, beep_volume
);
4153 case SOUND_MIXER_WRITE_LINE
:
4154 IOCTL_IN(arg
, data
);
4155 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLLINE
, data
);
4158 case SOUND_MIXER_READ_LINE
:
4159 data
= awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLLINE
);
4160 return IOCTL_OUT(arg
, data
);
4161 case SOUND_MIXER_WRITE_MIC
:
4162 IOCTL_IN(arg
, data
);
4163 /* Mic is mono device */
4164 data
= (data
<< 8) + (data
<< 24);
4165 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLMIC
, data
);
4167 case SOUND_MIXER_READ_MIC
:
4168 data
= awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLMIC
);
4170 return IOCTL_OUT(arg
, data
);
4171 case SOUND_MIXER_WRITE_CD
:
4172 IOCTL_IN(arg
, data
);
4173 awacs_burgundy_write_volume(MASK_ADDR_BURGUNDY_VOLCD
, data
);
4175 case SOUND_MIXER_READ_CD
:
4176 data
= awacs_burgundy_read_volume(MASK_ADDR_BURGUNDY_VOLCD
);
4177 return IOCTL_OUT(arg
, data
);
4178 case SOUND_MIXER_WRITE_RECLEV
:
4179 IOCTL_IN(arg
, data
);
4180 data
= awacs_volume_setter(data
, 0, 0, 4);
4181 return IOCTL_OUT(arg
, data
);
4182 case SOUND_MIXER_READ_RECLEV
:
4183 data
= awacs_get_volume(awacs_reg
[0], 4);
4184 return IOCTL_OUT(arg
, data
);
4185 case SOUND_MIXER_OUTMASK
:
4187 case SOUND_MIXER_OUTSRC
:
4199 static struct file_operations mixer_fops
=
4202 NULL
, /* mixer_read */
4203 NULL
, /* mixer_write */
4204 NULL
, /* mixer_readdir */
4205 NULL
, /* mixer_poll */
4207 NULL
, /* mixer_mmap */
4214 static void __init
mixer_init(void)
4219 mixer_unit
= register_sound_mixer(&mixer_fops
, -1);
4226 switch (sound
.mach
.type
) {
4229 atari_microwire_cmd(MW_LM1992_VOLUME(0));
4230 sound
.volume_left
= 0;
4231 atari_microwire_cmd(MW_LM1992_BALLEFT(0));
4232 sound
.volume_right
= 0;
4233 atari_microwire_cmd(MW_LM1992_BALRIGHT(0));
4234 atari_microwire_cmd(MW_LM1992_TREBLE(0));
4235 atari_microwire_cmd(MW_LM1992_BASS(0));
4238 sound
.volume_left
= (tt_dmasnd
.output_atten
& 0xf00) >> 8;
4239 sound
.volume_right
= (tt_dmasnd
.output_atten
& 0xf0) >> 4;
4241 #endif /* CONFIG_ATARI */
4244 sound
.volume_left
= 64;
4245 sound
.volume_right
= 64;
4246 custom
.aud
[0].audvol
= sound
.volume_left
;
4247 custom
.aud
[3].audvol
= 1; /* For pseudo 14bit */
4248 custom
.aud
[1].audvol
= sound
.volume_right
;
4249 custom
.aud
[2].audvol
= 1; /* For pseudo 14bit */
4252 #endif /* CONFIG_AMIGA */
4258 * Sound queue stuff, the heart of the driver
4262 static int sq_allocate_buffers(void)
4268 sound_buffers
= kmalloc (numBufs
* sizeof(char *), GFP_KERNEL
);
4271 for (i
= 0; i
< numBufs
; i
++) {
4272 sound_buffers
[i
] = sound
.mach
.dma_alloc (bufSize
<< 10, GFP_KERNEL
);
4273 if (!sound_buffers
[i
]) {
4275 sound
.mach
.dma_free (sound_buffers
[i
], bufSize
<< 10);
4276 kfree (sound_buffers
);
4285 static void sq_release_buffers(void)
4289 if (sound_buffers
) {
4290 for (i
= 0; i
< numBufs
; i
++)
4291 sound
.mach
.dma_free (sound_buffers
[i
], bufSize
<< 10);
4292 kfree (sound_buffers
);
4298 static void sq_setup(int numBufs
, int bufSize
, char **buffers
)
4302 volatile struct dbdma_cmd
*cp
;
4303 #endif /* CONFIG_PPC */
4305 sq
.max_count
= numBufs
;
4306 sq
.max_active
= numBufs
;
4307 sq
.block_size
= bufSize
;
4308 sq
.buffers
= buffers
;
4310 sq
.front
= sq
.count
= 0;
4317 #endif /* CONFIG_ATARI */
4319 sq
.block_size_half
= sq
.block_size
>>1;
4320 sq
.block_size_quarter
= sq
.block_size_half
>>1;
4321 #endif /* CONFIG_AMIGA */
4324 memset((void *) cp
, 0, (numBufs
+ 1) * sizeof(struct dbdma_cmd
));
4325 for (i
= 0; i
< numBufs
; ++i
, ++cp
) {
4326 st_le32(&cp
->phy_addr
, virt_to_bus(buffers
[i
]));
4328 st_le16(&cp
->command
, DBDMA_NOP
+ BR_ALWAYS
);
4329 st_le32(&cp
->cmd_dep
, virt_to_bus(awacs_tx_cmds
));
4330 out_le32(&awacs_txdma
->control
, (RUN
|PAUSE
|FLUSH
|WAKE
) << 16);
4331 out_le32(&awacs_txdma
->cmdptr
, virt_to_bus(awacs_tx_cmds
));
4332 #endif /* CONFIG_PPC */
4335 static void sq_play(void)
4337 (*sound
.mach
.play
)();
4341 /* ++TeSche: radically changed this one too */
4343 static ssize_t
sq_write(struct file
*file
, const char *src
, size_t uLeft
,
4346 ssize_t uWritten
= 0;
4348 ssize_t uUsed
, bUsed
, bLeft
;
4350 /* ++TeSche: Is something like this necessary?
4351 * Hey, that's an honest question! Or does any other part of the
4352 * filesystem already checks this situation? I really don't know.
4357 /* The interrupt doesn't start to play the last, incomplete frame.
4358 * Thus we can append to it without disabling the interrupts! (Note
4359 * also that sq.rear isn't affected by the interrupt.)
4362 if (sq
.count
> 0 && (bLeft
= sq
.block_size
-sq
.rear_size
) > 0) {
4363 dest
= sq_block_address(sq
.rear
);
4364 bUsed
= sq
.rear_size
;
4365 uUsed
= sound_copy_translate(src
, uLeft
, dest
, &bUsed
, bLeft
);
4371 sq
.rear_size
= bUsed
;
4375 while (sq
.count
== sq
.max_active
) {
4377 if (NON_BLOCKING(sq
.open_mode
))
4378 return uWritten
> 0 ? uWritten
: -EAGAIN
;
4379 SLEEP(sq
.write_queue
, ONE_SECOND
);
4380 if (SIGNAL_RECEIVED
)
4381 return uWritten
> 0 ? uWritten
: -EINTR
;
4384 /* Here, we can avoid disabling the interrupt by first
4385 * copying and translating the data, and then updating
4386 * the sq variables. Until this is done, the interrupt
4387 * won't see the new frame and we can work on it
4391 dest
= sq_block_address((sq
.rear
+1) % sq
.max_count
);
4393 bLeft
= sq
.block_size
;
4394 uUsed
= sound_copy_translate(src
, uLeft
, dest
, &bUsed
, bLeft
);
4401 sq
.rear
= (sq
.rear
+1) % sq
.max_count
;
4402 sq
.rear_size
= bUsed
;
4405 } while (bUsed
); /* uUsed may have been 0 */
4409 return uUsed
< 0? uUsed
: uWritten
;
4413 static int sq_open(struct inode
*inode
, struct file
*file
)
4420 if (NON_BLOCKING(file
->f_flags
))
4424 SLEEP(sq
.open_queue
, ONE_SECOND
);
4425 if (SIGNAL_RECEIVED
)
4431 rc
= sq_allocate_buffers();
4433 goto err_out_nobusy
;
4434 sq_setup(numBufs
, bufSize
<< 10, sound_buffers
);
4435 sq
.open_mode
= file
->f_flags
;
4438 #endif /* CONFIG_ATARI */
4439 sound
.minDev
= MINOR(inode
->i_rdev
) & 0x0f;
4440 sound
.soft
= sound
.dsp
;
4441 sound
.hard
= sound
.dsp
;
4443 if ((MINOR(inode
->i_rdev
) & 0x0f) == SND_DEV_AUDIO
) {
4444 sound_set_speed(8000);
4445 sound_set_stereo(0);
4446 sound_set_format(AFMT_MU_LAW
);
4451 WAKE_UP(sq
.open_queue
);
4458 static void sq_reset(void)
4463 sq
.front
= (sq
.rear
+1) % sq
.max_count
;
4467 static int sq_fsync(struct file
*filp
, struct dentry
*dentry
)
4472 sq_play(); /* there may be an incomplete frame waiting */
4474 while (sq
.playing
) {
4475 SLEEP(sq
.sync_queue
, ONE_SECOND
);
4476 if (SIGNAL_RECEIVED
) {
4477 /* While waiting for audio output to drain, an
4478 * interrupt occurred. Stop audio output immediately
4479 * and clear the queue. */
4490 static int sq_release(struct inode
*inode
, struct file
*file
)
4495 rc
= sq_fsync(file
, file
->f_dentry
);
4496 sound
.soft
= sound
.dsp
;
4497 sound
.hard
= sound
.dsp
;
4499 sq_release_buffers();
4503 WAKE_UP(sq
.open_queue
);
4504 /* Wake up a process waiting for the queue being released.
4505 * Note: There may be several processes waiting for a call
4506 * to open() returning. */
4512 static int sq_ioctl(struct inode
*inode
, struct file
*file
, u_int cmd
,
4520 case SNDCTL_DSP_RESET
:
4523 case SNDCTL_DSP_POST
:
4524 case SNDCTL_DSP_SYNC
:
4525 return sq_fsync(file
, file
->f_dentry
);
4527 /* ++TeSche: before changing any of these it's
4528 * probably wise to wait until sound playing has
4530 case SNDCTL_DSP_SPEED
:
4531 sq_fsync(file
, file
->f_dentry
);
4532 IOCTL_IN(arg
, data
);
4533 return IOCTL_OUT(arg
, sound_set_speed(data
));
4534 case SNDCTL_DSP_STEREO
:
4535 sq_fsync(file
, file
->f_dentry
);
4536 IOCTL_IN(arg
, data
);
4537 return IOCTL_OUT(arg
, sound_set_stereo(data
));
4538 case SOUND_PCM_WRITE_CHANNELS
:
4539 sq_fsync(file
, file
->f_dentry
);
4540 IOCTL_IN(arg
, data
);
4541 return IOCTL_OUT(arg
, sound_set_stereo(data
-1)+1);
4542 case SNDCTL_DSP_SETFMT
:
4543 sq_fsync(file
, file
->f_dentry
);
4544 IOCTL_IN(arg
, data
);
4545 return IOCTL_OUT(arg
, sound_set_format(data
));
4546 case SNDCTL_DSP_GETFMTS
:
4549 if (sound
.trans
->ct_ulaw
)
4551 if (sound
.trans
->ct_alaw
)
4553 if (sound
.trans
->ct_s8
)
4555 if (sound
.trans
->ct_u8
)
4557 if (sound
.trans
->ct_s16be
)
4559 if (sound
.trans
->ct_u16be
)
4561 if (sound
.trans
->ct_s16le
)
4563 if (sound
.trans
->ct_u16le
)
4566 return IOCTL_OUT(arg
, fmt
);
4567 case SNDCTL_DSP_GETBLKSIZE
:
4568 size
= sq
.block_size
4569 * sound
.soft
.size
* (sound
.soft
.stereo
+ 1)
4570 / (sound
.hard
.size
* (sound
.hard
.stereo
+ 1));
4571 return IOCTL_OUT(arg
, size
);
4572 case SNDCTL_DSP_SUBDIVIDE
:
4574 case SNDCTL_DSP_SETFRAGMENT
:
4575 if (sq
.count
|| sq
.playing
|| sq
.syncing
)
4577 IOCTL_IN(arg
, size
);
4579 if (nbufs
< 2 || nbufs
> numBufs
)
4582 if (size
>= 8 && size
<= 30) {
4584 size
*= sound
.hard
.size
* (sound
.hard
.stereo
+ 1);
4585 size
/= sound
.soft
.size
* (sound
.soft
.stereo
+ 1);
4586 if (size
> (bufSize
<< 10))
4587 size
= bufSize
<< 10;
4589 size
= bufSize
<< 10;
4590 sq_setup(numBufs
, size
, sound_buffers
);
4591 sq
.max_active
= nbufs
;
4595 return mixer_ioctl(inode
, file
, cmd
, arg
);
4602 static struct file_operations sq_fops
=
4607 NULL
, /* sq_readdir */
4617 static void __init
sq_init(void)
4622 sq_unit
= register_sound_dsp(&sq_fops
, -1);
4626 init_waitqueue_head(&sq
.write_queue
);
4627 init_waitqueue_head(&sq
.open_queue
);
4628 init_waitqueue_head(&sq
.sync_queue
);
4631 /* whatever you like as startup mode for /dev/dsp,
4632 * (/dev/audio hasn't got a startup mode). note that
4633 * once changed a new open() will *not* restore these!
4635 sound
.dsp
.format
= AFMT_U8
;
4636 sound
.dsp
.stereo
= 0;
4639 /* set minimum rate possible without expanding */
4640 switch (sound
.mach
.type
) {
4643 sound
.dsp
.speed
= 6258;
4646 sound
.dsp
.speed
= 8195;
4648 #endif /* CONFIG_ATARI */
4651 sound
.dsp
.speed
= 8000;
4653 #endif /* CONFIG_AMIGA */
4656 sound
.dsp
.speed
= 8000;
4658 #endif /* CONFIG_PPC */
4661 /* before the first open to /dev/dsp this wouldn't be set */
4662 sound
.soft
= sound
.dsp
;
4663 sound
.hard
= sound
.dsp
;
4673 /* state.buf should not overflow! */
4675 static int state_open(struct inode
*inode
, struct file
*file
)
4677 char *buffer
= state
.buf
, *mach
= "";
4687 switch (sound
.mach
.type
) {
4693 #endif /* CONFIG_ATARI */
4698 #endif /* CONFIG_AMIGA */
4701 sprintf(mach
, "PowerMac (AWACS rev %d) ", awacs_revision
);
4703 #endif /* CONFIG_PPC */
4705 len
+= sprintf(buffer
+len
, "%sDMA sound driver:\n", mach
);
4707 len
+= sprintf(buffer
+len
, "\tsound.format = 0x%x", sound
.soft
.format
);
4708 switch (sound
.soft
.format
) {
4710 len
+= sprintf(buffer
+len
, " (mu-law)");
4713 len
+= sprintf(buffer
+len
, " (A-law)");
4716 len
+= sprintf(buffer
+len
, " (unsigned 8 bit)");
4719 len
+= sprintf(buffer
+len
, " (signed 8 bit)");
4722 len
+= sprintf(buffer
+len
, " (signed 16 bit big)");
4725 len
+= sprintf(buffer
+len
, " (unsigned 16 bit big)");
4728 len
+= sprintf(buffer
+len
, " (signed 16 bit little)");
4731 len
+= sprintf(buffer
+len
, " (unsigned 16 bit little)");
4734 len
+= sprintf(buffer
+len
, "\n");
4735 len
+= sprintf(buffer
+len
, "\tsound.speed = %dHz (phys. %dHz)\n",
4736 sound
.soft
.speed
, sound
.hard
.speed
);
4737 len
+= sprintf(buffer
+len
, "\tsound.stereo = 0x%x (%s)\n",
4738 sound
.soft
.stereo
, sound
.soft
.stereo
? "stereo" : "mono");
4739 switch (sound
.mach
.type
) {
4742 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %ddB [-40...0]\n",
4744 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %ddB [-40...0]\n",
4745 sound
.volume_right
);
4746 len
+= sprintf(buffer
+len
, "\tsound.bass = %ddB [-12...+12]\n",
4748 len
+= sprintf(buffer
+len
, "\tsound.treble = %ddB [-12...+12]\n",
4752 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %ddB [-22.5...0]\n",
4754 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %ddB [-22.5...0]\n",
4755 sound
.volume_right
);
4757 #endif /* CONFIG_ATARI */
4760 len
+= sprintf(buffer
+len
, "\tsound.volume_left = %d [0...64]\n",
4762 len
+= sprintf(buffer
+len
, "\tsound.volume_right = %d [0...64]\n",
4763 sound
.volume_right
);
4765 #endif /* CONFIG_AMIGA */
4767 len
+= sprintf(buffer
+len
, "\tsq.block_size = %d sq.max_count = %d"
4768 " sq.max_active = %d\n",
4769 sq
.block_size
, sq
.max_count
, sq
.max_active
);
4770 len
+= sprintf(buffer
+len
, "\tsq.count = %d sq.rear_size = %d\n", sq
.count
,
4772 len
+= sprintf(buffer
+len
, "\tsq.playing = %d sq.syncing = %d\n",
4773 sq
.playing
, sq
.syncing
);
4779 static int state_release(struct inode
*inode
, struct file
*file
)
4787 static ssize_t
state_read(struct file
*file
, char *buf
, size_t count
,
4790 int n
= state
.len
- state
.ptr
;
4795 if (copy_to_user(buf
, &state
.buf
[state
.ptr
], n
))
4802 static struct file_operations state_fops
=
4806 NULL
, /* state_write */
4807 NULL
, /* state_readdir */
4808 NULL
, /* state_poll */
4809 NULL
, /* state_ioctl */
4810 NULL
, /* state_mmap */
4817 static void __init
state_init(void)
4822 state_unit
= register_sound_special(&state_fops
, SND_DEV_STATUS
);
4829 /*** Common stuff ********************************************************/
4831 static long long sound_lseek(struct file
*file
, long long offset
, int orig
)
4837 /*** Config & Setup **********************************************************/
4840 void __init
dmasound_init(void)
4844 struct device_node
*np
;
4847 #if defined(__mc68000__) || defined(CONFIG_APUS)
4848 switch (m68k_machtype
) {
4851 if (ATARIHW_PRESENT(PCM_8BIT
)) {
4852 if (ATARIHW_PRESENT(CODEC
))
4853 sound
.mach
= machFalcon
;
4854 else if (ATARIHW_PRESENT(MICROWIRE
))
4855 sound
.mach
= machTT
;
4858 if ((mfp
.int_en_a
& mfp
.int_mk_a
& 0x20) == 0)
4861 printk("DMA sound driver: Timer A interrupt already in use\n");
4865 #endif /* CONFIG_ATARI */
4868 if (AMIGAHW_PRESENT(AMI_AUDIO
)) {
4869 sound
.mach
= machAmiga
;
4873 #endif /* CONFIG_AMIGA */
4875 #endif /* __mc68000__||CONFIG_APUS */
4880 np
= find_devices("awacs");
4883 * powermac G3 models have a node called "davbus"
4884 * with a child called "sound".
4886 struct device_node
*sound
;
4887 np
= find_devices("davbus");
4888 sound
= find_devices("sound");
4889 if (sound
!= 0 && sound
->parent
== np
) {
4891 sfprop
= (int *) get_property(sound
, "sub-frame", 0);
4892 if (sfprop
!= 0 && *sfprop
>= 0 && *sfprop
< 16)
4893 awacs_subframe
= *sfprop
;
4894 if (device_is_compatible(sound
, "burgundy"))
4895 awacs_revision
= AWACS_BURGUNDY
;
4898 if (np
!= NULL
&& np
->n_addrs
>= 3 && np
->n_intrs
>= 3) {
4900 sound
.mach
= machPMac
;
4902 awacs
= (volatile struct awacs_regs
*)
4903 ioremap(np
->addrs
[0].address
, 0x80);
4904 awacs_txdma
= (volatile struct dbdma_regs
*)
4905 ioremap(np
->addrs
[1].address
, 0x100);
4906 awacs_rxdma
= (volatile struct dbdma_regs
*)
4907 ioremap(np
->addrs
[2].address
, 0x100);
4908 awacs_irq
= np
->intrs
[0].line
;
4909 awacs_tx_irq
= np
->intrs
[1].line
;
4910 awacs_rx_irq
= np
->intrs
[2].line
;
4911 awacs_tx_cmd_space
= kmalloc((numBufs
+ 4) * sizeof(struct dbdma_cmd
),
4913 if (awacs_tx_cmd_space
== NULL
) {
4914 printk(KERN_ERR
"DMA sound driver: Not enough buffer memory, driver disabled!\n");
4917 awacs_tx_cmds
= (volatile struct dbdma_cmd
*)
4918 DBDMA_ALIGN(awacs_tx_cmd_space
);
4919 awacs_reg
[0] = MASK_MUX_CD
;
4920 awacs_reg
[1] = MASK_LOOPTHRU
| MASK_PAROUT
;
4921 /* get default volume from nvram */
4922 vol
= (~nvram_read_byte(0x1308) & 7) << 1;
4923 awacs_reg
[2] = vol
+ (vol
<< 6);
4924 awacs_reg
[4] = vol
+ (vol
<< 6);
4925 out_le32(&awacs
->control
, 0x11);
4926 awacs_write(awacs_reg
[0] + MASK_ADDR0
);
4927 awacs_write(awacs_reg
[1] + MASK_ADDR1
);
4928 awacs_write(awacs_reg
[2] + MASK_ADDR2
);
4929 awacs_write(awacs_reg
[4] + MASK_ADDR4
);
4931 /* Initialize recent versions of the awacs */
4932 if (awacs_revision
== 0) {
4934 (in_le32(&awacs
->codec_stat
) >> 12) & 0xf;
4935 if (awacs_revision
== 3) {
4936 awacs_write(0x6000);
4937 awacs_enable_amp(100 * 0x101);
4940 if (awacs_revision
>= AWACS_BURGUNDY
)
4941 awacs_burgundy_init();
4943 /* Initialize beep stuff */
4944 beep_dbdma_cmd
= awacs_tx_cmds
+ (numBufs
+ 1);
4945 orig_mksound
= kd_mksound
;
4946 kd_mksound
= awacs_mksound
;
4947 beep_buf
= (short *) kmalloc(BEEP_BUFLEN
* 4, GFP_KERNEL
);
4948 if (beep_buf
== NULL
)
4949 printk(KERN_WARNING
"dmasound: no memory for "
4951 #ifdef CONFIG_PMAC_PBOOK
4952 notifier_chain_register(&sleep_notifier_list
,
4953 &awacs_sleep_notifier
);
4954 #endif /* CONFIG_PMAC_PBOOK */
4956 #endif /* CONFIG_PPC */
4961 /* Set up sound queue, /dev/audio and /dev/dsp. */
4963 /* Set default settings. */
4966 /* Set up /dev/sndstat. */
4969 /* Set up /dev/mixer. */
4972 if (!sound
.mach
.irqinit()) {
4973 printk(KERN_ERR
"DMA sound driver: Interrupt initialization failed\n");
4980 printk(KERN_INFO
"DMA sound driver installed, using %d buffers of %dk.\n",
4987 #define MAXARGS 8 /* Should be sufficient for now */
4989 void __init
dmasound_setup(char *str
, int *ints
)
4991 /* check the bootstrap parameter for "dmasound=" */
4995 if ((ints
[3] < 0) || (ints
[3] > MAX_CATCH_RADIUS
))
4996 printk("dmasound_setup: illegal catch radius, using default = %d\n", catchRadius
);
4998 catchRadius
= ints
[3];
5001 if (ints
[1] < MIN_BUFFERS
)
5002 printk("dmasound_setup: illegal number of buffers, using default = %d\n", numBufs
);
5005 if (ints
[2] < MIN_BUFSIZE
|| ints
[2] > MAX_BUFSIZE
)
5006 printk("dmasound_setup: illegal buffer size, using default = %d\n", bufSize
);
5013 printk("dmasound_setup: illegal number of arguments\n");
5020 int init_module(void)
5027 void cleanup_module(void)
5029 if (irq_installed
) {
5031 sound
.mach
.irqcleanup();
5034 sq_release_buffers();
5036 if (mixer_unit
>= 0)
5037 unregister_sound_mixer(mixer_unit
);
5038 if (state_unit
>= 0)
5039 unregister_sound_special(state_unit
);
5041 unregister_sound_dsp(sq_unit
);