Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * linux/arch/m68k/amiga/amisound.c
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * amiga sound driver for Linux/m68k
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * This file is subject to the terms and conditions of the GNU General Public
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * License.  See the file COPYING in the main directory of this archive
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * for more details.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/timer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <asm/amigahw.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) static unsigned short *snd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) static const signed char sine_data[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	0,  39,  75,  103,  121,  127,  121,  103,  75,  39,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	0, -39, -75, -103, -121, -127, -121, -103, -75, -39
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DATA_SIZE	ARRAY_SIZE(sine_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #define custom amiga_custom
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)      * The minimum period for audio may be modified by the frame buffer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)      * device since it depends on htotal (for OCS/ECS/AGA)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) volatile unsigned short amiga_audio_min_period = 124; /* Default for pre-OCS */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) EXPORT_SYMBOL(amiga_audio_min_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define MAX_PERIOD	(65535)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39)     /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40)      *	Current period (set by dmasound.c)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41)      */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) unsigned short amiga_audio_period = MAX_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) EXPORT_SYMBOL(amiga_audio_period);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static unsigned long clock_constant;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) void __init amiga_init_sound(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	static struct resource beep_res = { .name = "Beep" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	snd_data = amiga_chip_alloc_res(sizeof(sine_data), &beep_res);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	if (!snd_data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		pr_crit("amiga init_sound: failed to allocate chipmem\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	memcpy (snd_data, sine_data, sizeof(sine_data));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	/* setup divisor */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	clock_constant = (amiga_colorclock+DATA_SIZE/2)/DATA_SIZE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	/* without amifb, turn video off and enable high quality sound */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) #ifndef CONFIG_FB_AMIGA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	amifb_video_off();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) static void nosound(struct timer_list *unused);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) static DEFINE_TIMER(sound_timer, nosound);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) void amiga_mksound( unsigned int hz, unsigned int ticks )
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	if (!snd_data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	del_timer( &sound_timer );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	if (hz > 20 && hz < 32767) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 		unsigned long period = (clock_constant / hz);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		if (period < amiga_audio_min_period)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			period = amiga_audio_min_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 		if (period > MAX_PERIOD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			period = MAX_PERIOD;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		/* setup pointer to data, period, length and volume */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		custom.aud[2].audlc = snd_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		custom.aud[2].audlen = sizeof(sine_data)/2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		custom.aud[2].audper = (unsigned short)period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		custom.aud[2].audvol = 32; /* 50% of maxvol */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 		if (ticks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			sound_timer.expires = jiffies + ticks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			add_timer( &sound_timer );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 		/* turn on DMA for audio channel 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		custom.dmacon = DMAF_SETCLR | DMAF_AUD2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 		nosound( 0 );
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) static void nosound(struct timer_list *unused)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	/* turn off DMA for audio channel 2 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 	custom.dmacon = DMAF_AUD2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	/* restore period to previous value after beeping */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	custom.aud[2].audper = amiga_audio_period;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) }