/*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/irq.h>28#include <asm/atariints.h>2930#include "atari.h"3132/*33* stuff from the old atasound.c34*/3536void atari_microwire_cmd (int cmd)37{38tt_microwire.mask = 0x7ff;39tt_microwire.data = MW_LM1992_ADDR | cmd;4041/* Busy wait for data being completely sent :-( */42while( tt_microwire.mask != 0x7ff)43;44}45EXPORT_SYMBOL(atari_microwire_cmd);464748/* PSG base frequency */49#define PSG_FREQ 12500050/* PSG envelope base frequency times 10 */51#define PSG_ENV_FREQ_10 781255253void atari_mksound (unsigned int hz, unsigned int ticks)54{55/* Generates sound of some frequency for some number of clock56ticks. */57unsigned long flags;58unsigned char tmp;59int period;6061local_irq_save(flags);626364/* Disable generator A in mixer control. */65sound_ym.rd_data_reg_sel = 7;66tmp = sound_ym.rd_data_reg_sel;67tmp |= 011;68sound_ym.wd_data = tmp;6970if (hz) {71/* Convert from frequency value to PSG period value (base72frequency 125 kHz). */7374period = PSG_FREQ / hz;7576if (period > 0xfff) period = 0xfff;7778/* Set generator A frequency to hz. */79sound_ym.rd_data_reg_sel = 0;80sound_ym.wd_data = period & 0xff;81sound_ym.rd_data_reg_sel = 1;82sound_ym.wd_data = (period >> 8) & 0xf;83if (ticks) {84/* Set length of envelope (max 8 sec). */85int length = (ticks * PSG_ENV_FREQ_10) / HZ / 10;8687if (length > 0xffff) length = 0xffff;88sound_ym.rd_data_reg_sel = 11;89sound_ym.wd_data = length & 0xff;90sound_ym.rd_data_reg_sel = 12;91sound_ym.wd_data = length >> 8;92/* Envelope form: max -> min single. */93sound_ym.rd_data_reg_sel = 13;94sound_ym.wd_data = 0;95/* Use envelope for generator A. */96sound_ym.rd_data_reg_sel = 8;97sound_ym.wd_data = 0x10;98} else {99/* Set generator A level to maximum, no envelope. */100sound_ym.rd_data_reg_sel = 8;101sound_ym.wd_data = 15;102}103/* Turn on generator A in mixer control. */104sound_ym.rd_data_reg_sel = 7;105tmp &= ~1;106sound_ym.wd_data = tmp;107}108local_irq_restore(flags);109}110111112