Import 2.3.50pre1
[davej-history.git] / arch / m68k / amiga / amisound.c
blobfaba5841b4f0c8ddac3ecd4049019446c774b5b8
1 /*
2 * linux/arch/m68k/amiga/amisound.c
4 * amiga sound driver for Linux/m68k
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file COPYING in the main directory of this archive
8 * for more details.
9 */
11 #include <linux/sched.h>
12 #include <linux/timer.h>
13 #include <linux/init.h>
15 #include <asm/system.h>
16 #include <asm/amigahw.h>
18 static u_short *snd_data = NULL;
19 static const signed char sine_data[] = {
20 0, 39, 75, 103, 121, 127, 121, 103, 75, 39,
21 0, -39, -75, -103, -121, -127, -121, -103, -75, -39
23 #define DATA_SIZE (sizeof(sine_data)/sizeof(sine_data[0]))
26 * The minimum period for audio may be modified by the frame buffer
27 * device since it depends on htotal (for OCS/ECS/AGA)
30 volatile u_short amiga_audio_min_period = 124; /* Default for pre-OCS */
32 #define MAX_PERIOD (65535)
36 * Current period (set by dmasound.c)
39 u_short amiga_audio_period = MAX_PERIOD;
41 static u_long clock_constant;
43 void __init amiga_init_sound(void)
45 snd_data = amiga_chip_alloc(sizeof(sine_data), "Beep");
46 if (!snd_data) {
47 printk (KERN_CRIT "amiga init_sound: failed to allocate chipmem\n");
48 return;
50 memcpy (snd_data, sine_data, sizeof(sine_data));
52 /* setup divisor */
53 clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
56 static void nosound( unsigned long ignored );
57 static struct timer_list sound_timer = { NULL, NULL, 0, 0, nosound };
59 void amiga_mksound( unsigned int hz, unsigned int ticks )
61 unsigned long flags;
63 if (!snd_data)
64 return;
66 save_flags(flags);
67 cli();
68 del_timer( &sound_timer );
70 if (hz > 20 && hz < 32767) {
71 u_long period = (clock_constant / hz);
73 if (period < amiga_audio_min_period)
74 period = amiga_audio_min_period;
75 if (period > MAX_PERIOD)
76 period = MAX_PERIOD;
78 /* setup pointer to data, period, length and volume */
79 custom.aud[2].audlc = snd_data;
80 custom.aud[2].audlen = sizeof(sine_data)/2;
81 custom.aud[2].audper = (u_short)period;
82 custom.aud[2].audvol = 32; /* 50% of maxvol */
84 if (ticks) {
85 sound_timer.expires = jiffies + ticks;
86 add_timer( &sound_timer );
89 /* turn on DMA for audio channel 2 */
90 custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
92 restore_flags(flags);
93 return;
94 } else {
95 nosound( 0 );
96 restore_flags(flags);
97 return;
102 static void nosound( unsigned long ignored )
104 /* turn off DMA for audio channel 2 */
105 custom.dmacon = DMAF_AUD2;
106 /* restore period to previous value after beeping */
107 custom.aud[2].audper = amiga_audio_period;