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>
19 static unsigned short *snd_data
;
20 static const signed char sine_data
[] = {
21 0, 39, 75, 103, 121, 127, 121, 103, 75, 39,
22 0, -39, -75, -103, -121, -127, -121, -103, -75, -39
24 #define DATA_SIZE ARRAY_SIZE(sine_data)
26 #define custom amiga_custom
29 * The minimum period for audio may be modified by the frame buffer
30 * device since it depends on htotal (for OCS/ECS/AGA)
33 volatile unsigned short amiga_audio_min_period
= 124; /* Default for pre-OCS */
34 EXPORT_SYMBOL(amiga_audio_min_period
);
36 #define MAX_PERIOD (65535)
40 * Current period (set by dmasound.c)
43 unsigned short amiga_audio_period
= MAX_PERIOD
;
44 EXPORT_SYMBOL(amiga_audio_period
);
46 static unsigned long clock_constant
;
48 void __init
amiga_init_sound(void)
50 static struct resource beep_res
= { .name
= "Beep" };
52 snd_data
= amiga_chip_alloc_res(sizeof(sine_data
), &beep_res
);
54 pr_crit("amiga init_sound: failed to allocate chipmem\n");
57 memcpy (snd_data
, sine_data
, sizeof(sine_data
));
60 clock_constant
= (amiga_colorclock
+DATA_SIZE
/2)/DATA_SIZE
;
62 /* without amifb, turn video off and enable high quality sound */
63 #ifndef CONFIG_FB_AMIGA
68 static void nosound(struct timer_list
*unused
);
69 static DEFINE_TIMER(sound_timer
, nosound
);
71 void amiga_mksound( unsigned int hz
, unsigned int ticks
)
78 local_irq_save(flags
);
79 del_timer( &sound_timer
);
81 if (hz
> 20 && hz
< 32767) {
82 unsigned long period
= (clock_constant
/ hz
);
84 if (period
< amiga_audio_min_period
)
85 period
= amiga_audio_min_period
;
86 if (period
> MAX_PERIOD
)
89 /* setup pointer to data, period, length and volume */
90 custom
.aud
[2].audlc
= snd_data
;
91 custom
.aud
[2].audlen
= sizeof(sine_data
)/2;
92 custom
.aud
[2].audper
= (unsigned short)period
;
93 custom
.aud
[2].audvol
= 32; /* 50% of maxvol */
96 sound_timer
.expires
= jiffies
+ ticks
;
97 add_timer( &sound_timer
);
100 /* turn on DMA for audio channel 2 */
101 custom
.dmacon
= DMAF_SETCLR
| DMAF_AUD2
;
106 local_irq_restore(flags
);
110 static void nosound(struct timer_list
*unused
)
112 /* turn off DMA for audio channel 2 */
113 custom
.dmacon
= DMAF_AUD2
;
114 /* restore period to previous value after beeping */
115 custom
.aud
[2].audper
= amiga_audio_period
;