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
11 #include <linux/jiffies.h>
12 #include <linux/timer.h>
13 #include <linux/init.h>
14 #include <linux/string.h>
15 #include <linux/module.h>
17 #include <asm/amigahw.h>
21 static unsigned short *snd_data;
22 static const signed char sine_data[] = {
23 0, 39, 75, 103, 121, 127, 121, 103, 75, 39,
24 0, -39, -75, -103, -121, -127, -121, -103, -75, -39
26 #define DATA_SIZE ARRAY_SIZE(sine_data)
28 #define custom amiga_custom
31 * The minimum period for audio may be modified by the frame buffer
32 * device since it depends on htotal (for OCS/ECS/AGA)
35 volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
36 EXPORT_SYMBOL(amiga_audio_min_period);
38 #define MAX_PERIOD (65535)
42 * Current period (set by dmasound.c)
45 unsigned short amiga_audio_period = MAX_PERIOD;
46 EXPORT_SYMBOL(amiga_audio_period);
48 static unsigned long clock_constant;
50 void __init amiga_init_sound(void)
52 static struct resource beep_res = { .name = "Beep" };
54 snd_data = amiga_chip_alloc_res(sizeof(sine_data), &beep_res);
56 pr_crit("amiga init_sound: failed to allocate chipmem\n");
59 memcpy (snd_data, sine_data, sizeof(sine_data));
62 clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
64 /* without amifb, turn video off and enable high quality sound */
65 #ifndef CONFIG_FB_AMIGA
70 static void nosound(struct timer_list *unused);
71 static DEFINE_TIMER(sound_timer, nosound);
73 void amiga_mksound( unsigned int hz, unsigned int ticks )
80 local_irq_save(flags);
81 del_timer( &sound_timer );
83 if (hz > 20 && hz < 32767) {
84 unsigned long period = (clock_constant / hz);
86 if (period < amiga_audio_min_period)
87 period = amiga_audio_min_period;
88 if (period > MAX_PERIOD)
91 /* setup pointer to data, period, length and volume */
92 custom.aud[2].audlc = snd_data;
93 custom.aud[2].audlen = sizeof(sine_data)/2;
94 custom.aud[2].audper = (unsigned short)period;
95 custom.aud[2].audvol = 32; /* 50% of maxvol */
98 sound_timer.expires = jiffies + ticks;
99 add_timer( &sound_timer );
102 /* turn on DMA for audio channel 2 */
103 custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
108 local_irq_restore(flags);
112 static void nosound(struct timer_list *unused)
114 /* turn off DMA for audio channel 2 */
115 custom.dmacon = DMAF_AUD2;
116 /* restore period to previous value after beeping */
117 custom.aud[2].audper = amiga_audio_period;