/*1* linux/arch/m68k/atari/atasound.c2*3* ++Geert: Moved almost all stuff to linux/drivers/sound/4*5* The author of atari_nosound, atari_mksound and atari_microwire_cmd is6* unknown. (++roman: That's me... :-)7*8* This file is subject to the terms and conditions of the GNU General Public9* License. See the file COPYING in the main directory of this archive10* for more details.11*12* 1998-05-31 ++andreas: atari_mksound rewritten to always use the envelope,13* no timer, atari_nosound removed.14*15*/161718#include <linux/sched.h>19#include <linux/timer.h>20#include <linux/major.h>21#include <linux/fcntl.h>22#include <linux/errno.h>23#include <linux/mm.h>24#include <linux/module.h>2526#include <asm/atarihw.h>27#include <asm/system.h>28#include <asm/irq.h>29#include <asm/pgtable.h>30#include <asm/atariints.h>313233/*34* stuff from the old atasound.c35*/3637void atari_microwire_cmd (int cmd)38{39tt_microwire.mask = 0x7ff;40tt_microwire.data = MW_LM1992_ADDR | cmd;4142/* Busy wait for data being completely sent :-( */43while( tt_microwire.mask != 0x7ff)44;45}46EXPORT_SYMBOL(atari_microwire_cmd);474849/* PSG base frequency */50#define PSG_FREQ 12500051/* PSG envelope base frequency times 10 */52#define PSG_ENV_FREQ_10 781255354void atari_mksound (unsigned int hz, unsigned int ticks)55{56/* Generates sound of some frequency for some number of clock57ticks. */58unsigned long flags;59unsigned char tmp;60int period;6162local_irq_save(flags);636465/* Disable generator A in mixer control. */66sound_ym.rd_data_reg_sel = 7;67tmp = sound_ym.rd_data_reg_sel;68tmp |= 011;69sound_ym.wd_data = tmp;7071if (hz) {72/* Convert from frequency value to PSG period value (base73frequency 125 kHz). */7475period = PSG_FREQ / hz;7677if (period > 0xfff) period = 0xfff;7879/* Set generator A frequency to hz. */80sound_ym.rd_data_reg_sel = 0;81sound_ym.wd_data = period & 0xff;82sound_ym.rd_data_reg_sel = 1;83sound_ym.wd_data = (period >> 8) & 0xf;84if (ticks) {85/* Set length of envelope (max 8 sec). */86int length = (ticks * PSG_ENV_FREQ_10) / HZ / 10;8788if (length > 0xffff) length = 0xffff;89sound_ym.rd_data_reg_sel = 11;90sound_ym.wd_data = length & 0xff;91sound_ym.rd_data_reg_sel = 12;92sound_ym.wd_data = length >> 8;93/* Envelope form: max -> min single. */94sound_ym.rd_data_reg_sel = 13;95sound_ym.wd_data = 0;96/* Use envelope for generator A. */97sound_ym.rd_data_reg_sel = 8;98sound_ym.wd_data = 0x10;99} else {100/* Set generator A level to maximum, no envelope. */101sound_ym.rd_data_reg_sel = 8;102sound_ym.wd_data = 15;103}104/* Turn on generator A in mixer control. */105sound_ym.rd_data_reg_sel = 7;106tmp &= ~1;107sound_ym.wd_data = tmp;108}109local_irq_restore(flags);110}111112113