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