1 /*
2  * linux/arch/m68k/atari/atasound.c
3  *
4  * ++Geert: Moved almost all stuff to linux/drivers/sound/
5  *
6  * The author of atari_nosound, atari_mksound and atari_microwire_cmd is
7  * unknown. (++roman: That's me... :-)
8  *
9  * This file is subject to the terms and conditions of the GNU General Public
10  * License.  See the file COPYING in the main directory of this archive
11  * for more details.
12  *
13  * 1998-05-31 ++andreas: atari_mksound rewritten to always use the envelope,
14  *			 no timer, atari_nosound removed.
15  *
16  */
17 
18 
19 #include <linux/sched.h>
20 #include <linux/timer.h>
21 #include <linux/major.h>
22 #include <linux/fcntl.h>
23 #include <linux/errno.h>
24 #include <linux/mm.h>
25 #include <linux/module.h>
26 
27 #include <asm/atarihw.h>
28 #include <asm/system.h>
29 #include <asm/irq.h>
30 #include <asm/pgtable.h>
31 #include <asm/atariints.h>
32 
33 
34 /*
35  * stuff from the old atasound.c
36  */
37 
atari_microwire_cmd(int cmd)38 void atari_microwire_cmd (int cmd)
39 {
40 	tt_microwire.mask = 0x7ff;
41 	tt_microwire.data = MW_LM1992_ADDR | cmd;
42 
43 	/* Busy wait for data being completely sent :-( */
44 	while( tt_microwire.mask != 0x7ff)
45 		;
46 }
47 EXPORT_SYMBOL(atari_microwire_cmd);
48 
49 
50 /* PSG base frequency */
51 #define	PSG_FREQ	125000
52 /* PSG envelope base frequency times 10 */
53 #define PSG_ENV_FREQ_10	78125
54 
atari_mksound(unsigned int hz,unsigned int ticks)55 void atari_mksound (unsigned int hz, unsigned int ticks)
56 {
57 	/* Generates sound of some frequency for some number of clock
58 	   ticks.  */
59 	unsigned long flags;
60 	unsigned char tmp;
61 	int period;
62 
63 	local_irq_save(flags);
64 
65 
66 	/* Disable generator A in mixer control.  */
67 	sound_ym.rd_data_reg_sel = 7;
68 	tmp = sound_ym.rd_data_reg_sel;
69 	tmp |= 011;
70 	sound_ym.wd_data = tmp;
71 
72 	if (hz) {
73 	    /* Convert from frequency value to PSG period value (base
74 	       frequency 125 kHz).  */
75 
76 	    period = PSG_FREQ / hz;
77 
78 	    if (period > 0xfff) period = 0xfff;
79 
80 	/* Set generator A frequency to hz.  */
81 	sound_ym.rd_data_reg_sel = 0;
82 	sound_ym.wd_data = period & 0xff;
83 	sound_ym.rd_data_reg_sel = 1;
84 	sound_ym.wd_data = (period >> 8) & 0xf;
85 	if (ticks) {
86 		/* Set length of envelope (max 8 sec).  */
87 		int length = (ticks * PSG_ENV_FREQ_10) / HZ / 10;
88 
89 		if (length > 0xffff) length = 0xffff;
90 		sound_ym.rd_data_reg_sel = 11;
91 		sound_ym.wd_data = length & 0xff;
92 		sound_ym.rd_data_reg_sel = 12;
93 		sound_ym.wd_data = length >> 8;
94 		/* Envelope form: max -> min single.  */
95 		sound_ym.rd_data_reg_sel = 13;
96 		sound_ym.wd_data = 0;
97 		/* Use envelope for generator A.  */
98 		sound_ym.rd_data_reg_sel = 8;
99 		sound_ym.wd_data = 0x10;
100 	} else {
101 		/* Set generator A level to maximum, no envelope.  */
102 		sound_ym.rd_data_reg_sel = 8;
103 		sound_ym.wd_data = 15;
104 	}
105 	/* Turn on generator A in mixer control.  */
106 	sound_ym.rd_data_reg_sel = 7;
107 	tmp &= ~1;
108 	sound_ym.wd_data = tmp;
109 	}
110 	local_irq_restore(flags);
111 }
112