162306a36Sopenharmony_ci/* 262306a36Sopenharmony_ci * Local definitions for the OPL4 driver 362306a36Sopenharmony_ci * 462306a36Sopenharmony_ci * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de> 562306a36Sopenharmony_ci * All rights reserved. 662306a36Sopenharmony_ci * 762306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 862306a36Sopenharmony_ci * modification, are permitted provided that the following conditions 962306a36Sopenharmony_ci * are met: 1062306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 1162306a36Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 1262306a36Sopenharmony_ci * without modification. 1362306a36Sopenharmony_ci * 2. The name of the author may not be used to endorse or promote products 1462306a36Sopenharmony_ci * derived from this software without specific prior written permission. 1562306a36Sopenharmony_ci * 1662306a36Sopenharmony_ci * Alternatively, this software may be distributed and/or modified under the 1762306a36Sopenharmony_ci * terms of the GNU General Public License as published by the Free Software 1862306a36Sopenharmony_ci * Foundation; either version 2 of the License, or (at your option) any later 1962306a36Sopenharmony_ci * version. 2062306a36Sopenharmony_ci * 2162306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 2262306a36Sopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2362306a36Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2462306a36Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 2562306a36Sopenharmony_ci * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2662306a36Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2762306a36Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2862306a36Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2962306a36Sopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 3062306a36Sopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3162306a36Sopenharmony_ci * SUCH DAMAGE. 3262306a36Sopenharmony_ci */ 3362306a36Sopenharmony_ci 3462306a36Sopenharmony_ci#ifndef __OPL4_LOCAL_H 3562306a36Sopenharmony_ci#define __OPL4_LOCAL_H 3662306a36Sopenharmony_ci 3762306a36Sopenharmony_ci#include <sound/opl4.h> 3862306a36Sopenharmony_ci 3962306a36Sopenharmony_ci/* 4062306a36Sopenharmony_ci * Register numbers 4162306a36Sopenharmony_ci */ 4262306a36Sopenharmony_ci 4362306a36Sopenharmony_ci#define OPL4_REG_TEST0 0x00 4462306a36Sopenharmony_ci#define OPL4_REG_TEST1 0x01 4562306a36Sopenharmony_ci 4662306a36Sopenharmony_ci#define OPL4_REG_MEMORY_CONFIGURATION 0x02 4762306a36Sopenharmony_ci#define OPL4_MODE_BIT 0x01 4862306a36Sopenharmony_ci#define OPL4_MTYPE_BIT 0x02 4962306a36Sopenharmony_ci#define OPL4_TONE_HEADER_MASK 0x1c 5062306a36Sopenharmony_ci#define OPL4_DEVICE_ID_MASK 0xe0 5162306a36Sopenharmony_ci 5262306a36Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_HIGH 0x03 5362306a36Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_MID 0x04 5462306a36Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_LOW 0x05 5562306a36Sopenharmony_ci#define OPL4_REG_MEMORY_DATA 0x06 5662306a36Sopenharmony_ci 5762306a36Sopenharmony_ci/* 5862306a36Sopenharmony_ci * Offsets to the register banks for voices. To get the 5962306a36Sopenharmony_ci * register number just add the voice number to the bank offset. 6062306a36Sopenharmony_ci * 6162306a36Sopenharmony_ci * Wave Table Number low bits (0x08 to 0x1F) 6262306a36Sopenharmony_ci */ 6362306a36Sopenharmony_ci#define OPL4_REG_TONE_NUMBER 0x08 6462306a36Sopenharmony_ci 6562306a36Sopenharmony_ci/* Wave Table Number high bit, F-Number low bits (0x20 to 0x37) */ 6662306a36Sopenharmony_ci#define OPL4_REG_F_NUMBER 0x20 6762306a36Sopenharmony_ci#define OPL4_TONE_NUMBER_BIT8 0x01 6862306a36Sopenharmony_ci#define OPL4_F_NUMBER_LOW_MASK 0xfe 6962306a36Sopenharmony_ci 7062306a36Sopenharmony_ci/* F-Number high bits, Octave, Pseudo-Reverb (0x38 to 0x4F) */ 7162306a36Sopenharmony_ci#define OPL4_REG_OCTAVE 0x38 7262306a36Sopenharmony_ci#define OPL4_F_NUMBER_HIGH_MASK 0x07 7362306a36Sopenharmony_ci#define OPL4_BLOCK_MASK 0xf0 7462306a36Sopenharmony_ci#define OPL4_PSEUDO_REVERB_BIT 0x08 7562306a36Sopenharmony_ci 7662306a36Sopenharmony_ci/* Total Level, Level Direct (0x50 to 0x67) */ 7762306a36Sopenharmony_ci#define OPL4_REG_LEVEL 0x50 7862306a36Sopenharmony_ci#define OPL4_TOTAL_LEVEL_MASK 0xfe 7962306a36Sopenharmony_ci#define OPL4_LEVEL_DIRECT_BIT 0x01 8062306a36Sopenharmony_ci 8162306a36Sopenharmony_ci/* Key On, Damp, LFO RST, CH, Panpot (0x68 to 0x7F) */ 8262306a36Sopenharmony_ci#define OPL4_REG_MISC 0x68 8362306a36Sopenharmony_ci#define OPL4_KEY_ON_BIT 0x80 8462306a36Sopenharmony_ci#define OPL4_DAMP_BIT 0x40 8562306a36Sopenharmony_ci#define OPL4_LFO_RESET_BIT 0x20 8662306a36Sopenharmony_ci#define OPL4_OUTPUT_CHANNEL_BIT 0x10 8762306a36Sopenharmony_ci#define OPL4_PAN_POT_MASK 0x0f 8862306a36Sopenharmony_ci 8962306a36Sopenharmony_ci/* LFO, VIB (0x80 to 0x97) */ 9062306a36Sopenharmony_ci#define OPL4_REG_LFO_VIBRATO 0x80 9162306a36Sopenharmony_ci#define OPL4_LFO_FREQUENCY_MASK 0x38 9262306a36Sopenharmony_ci#define OPL4_VIBRATO_DEPTH_MASK 0x07 9362306a36Sopenharmony_ci#define OPL4_CHORUS_SEND_MASK 0xc0 /* ML only */ 9462306a36Sopenharmony_ci 9562306a36Sopenharmony_ci/* Attack / Decay 1 rate (0x98 to 0xAF) */ 9662306a36Sopenharmony_ci#define OPL4_REG_ATTACK_DECAY1 0x98 9762306a36Sopenharmony_ci#define OPL4_ATTACK_RATE_MASK 0xf0 9862306a36Sopenharmony_ci#define OPL4_DECAY1_RATE_MASK 0x0f 9962306a36Sopenharmony_ci 10062306a36Sopenharmony_ci/* Decay level / 2 rate (0xB0 to 0xC7) */ 10162306a36Sopenharmony_ci#define OPL4_REG_LEVEL_DECAY2 0xb0 10262306a36Sopenharmony_ci#define OPL4_DECAY_LEVEL_MASK 0xf0 10362306a36Sopenharmony_ci#define OPL4_DECAY2_RATE_MASK 0x0f 10462306a36Sopenharmony_ci 10562306a36Sopenharmony_ci/* Release rate / Rate correction (0xC8 to 0xDF) */ 10662306a36Sopenharmony_ci#define OPL4_REG_RELEASE_CORRECTION 0xc8 10762306a36Sopenharmony_ci#define OPL4_RELEASE_RATE_MASK 0x0f 10862306a36Sopenharmony_ci#define OPL4_RATE_INTERPOLATION_MASK 0xf0 10962306a36Sopenharmony_ci 11062306a36Sopenharmony_ci/* AM (0xE0 to 0xF7) */ 11162306a36Sopenharmony_ci#define OPL4_REG_TREMOLO 0xe0 11262306a36Sopenharmony_ci#define OPL4_TREMOLO_DEPTH_MASK 0x07 11362306a36Sopenharmony_ci#define OPL4_REVERB_SEND_MASK 0xe0 /* ML only */ 11462306a36Sopenharmony_ci 11562306a36Sopenharmony_ci/* Mixer */ 11662306a36Sopenharmony_ci#define OPL4_REG_MIX_CONTROL_FM 0xf8 11762306a36Sopenharmony_ci#define OPL4_REG_MIX_CONTROL_PCM 0xf9 11862306a36Sopenharmony_ci#define OPL4_MIX_LEFT_MASK 0x07 11962306a36Sopenharmony_ci#define OPL4_MIX_RIGHT_MASK 0x38 12062306a36Sopenharmony_ci 12162306a36Sopenharmony_ci#define OPL4_REG_ATC 0xfa 12262306a36Sopenharmony_ci#define OPL4_ATC_BIT 0x01 /* ???, ML only */ 12362306a36Sopenharmony_ci 12462306a36Sopenharmony_ci/* bits in the OPL3 Status register */ 12562306a36Sopenharmony_ci#define OPL4_STATUS_BUSY 0x01 12662306a36Sopenharmony_ci#define OPL4_STATUS_LOAD 0x02 12762306a36Sopenharmony_ci 12862306a36Sopenharmony_ci 12962306a36Sopenharmony_ci#define OPL4_MAX_VOICES 24 13062306a36Sopenharmony_ci 13162306a36Sopenharmony_ci#define SNDRV_SEQ_DEV_ID_OPL4 "opl4-synth" 13262306a36Sopenharmony_ci 13362306a36Sopenharmony_ci 13462306a36Sopenharmony_cistruct opl4_sound { 13562306a36Sopenharmony_ci u16 tone; 13662306a36Sopenharmony_ci s16 pitch_offset; 13762306a36Sopenharmony_ci u8 key_scaling; 13862306a36Sopenharmony_ci s8 panpot; 13962306a36Sopenharmony_ci u8 vibrato; 14062306a36Sopenharmony_ci u8 tone_attenuate; 14162306a36Sopenharmony_ci u8 volume_factor; 14262306a36Sopenharmony_ci u8 reg_lfo_vibrato; 14362306a36Sopenharmony_ci u8 reg_attack_decay1; 14462306a36Sopenharmony_ci u8 reg_level_decay2; 14562306a36Sopenharmony_ci u8 reg_release_correction; 14662306a36Sopenharmony_ci u8 reg_tremolo; 14762306a36Sopenharmony_ci}; 14862306a36Sopenharmony_ci 14962306a36Sopenharmony_cistruct opl4_region { 15062306a36Sopenharmony_ci u8 key_min, key_max; 15162306a36Sopenharmony_ci struct opl4_sound sound; 15262306a36Sopenharmony_ci}; 15362306a36Sopenharmony_ci 15462306a36Sopenharmony_cistruct opl4_region_ptr { 15562306a36Sopenharmony_ci int count; 15662306a36Sopenharmony_ci const struct opl4_region *regions; 15762306a36Sopenharmony_ci}; 15862306a36Sopenharmony_ci 15962306a36Sopenharmony_cistruct opl4_voice { 16062306a36Sopenharmony_ci struct list_head list; 16162306a36Sopenharmony_ci int number; 16262306a36Sopenharmony_ci struct snd_midi_channel *chan; 16362306a36Sopenharmony_ci int note; 16462306a36Sopenharmony_ci int velocity; 16562306a36Sopenharmony_ci const struct opl4_sound *sound; 16662306a36Sopenharmony_ci u8 level_direct; 16762306a36Sopenharmony_ci u8 reg_f_number; 16862306a36Sopenharmony_ci u8 reg_misc; 16962306a36Sopenharmony_ci u8 reg_lfo_vibrato; 17062306a36Sopenharmony_ci}; 17162306a36Sopenharmony_ci 17262306a36Sopenharmony_cistruct snd_opl4 { 17362306a36Sopenharmony_ci unsigned long fm_port; 17462306a36Sopenharmony_ci unsigned long pcm_port; 17562306a36Sopenharmony_ci struct resource *res_fm_port; 17662306a36Sopenharmony_ci struct resource *res_pcm_port; 17762306a36Sopenharmony_ci unsigned short hardware; 17862306a36Sopenharmony_ci spinlock_t reg_lock; 17962306a36Sopenharmony_ci struct snd_card *card; 18062306a36Sopenharmony_ci 18162306a36Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 18262306a36Sopenharmony_ci struct snd_info_entry *proc_entry; 18362306a36Sopenharmony_ci int memory_access; 18462306a36Sopenharmony_ci#endif 18562306a36Sopenharmony_ci struct mutex access_mutex; 18662306a36Sopenharmony_ci 18762306a36Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_SEQUENCER) 18862306a36Sopenharmony_ci int used; 18962306a36Sopenharmony_ci 19062306a36Sopenharmony_ci int seq_dev_num; 19162306a36Sopenharmony_ci int seq_client; 19262306a36Sopenharmony_ci struct snd_seq_device *seq_dev; 19362306a36Sopenharmony_ci 19462306a36Sopenharmony_ci struct snd_midi_channel_set *chset; 19562306a36Sopenharmony_ci struct opl4_voice voices[OPL4_MAX_VOICES]; 19662306a36Sopenharmony_ci struct list_head off_voices; 19762306a36Sopenharmony_ci struct list_head on_voices; 19862306a36Sopenharmony_ci#endif 19962306a36Sopenharmony_ci}; 20062306a36Sopenharmony_ci 20162306a36Sopenharmony_ci/* opl4_lib.c */ 20262306a36Sopenharmony_civoid snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value); 20362306a36Sopenharmony_ciu8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg); 20462306a36Sopenharmony_civoid snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size); 20562306a36Sopenharmony_civoid snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size); 20662306a36Sopenharmony_ci 20762306a36Sopenharmony_ci/* opl4_mixer.c */ 20862306a36Sopenharmony_ciint snd_opl4_create_mixer(struct snd_opl4 *opl4); 20962306a36Sopenharmony_ci 21062306a36Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 21162306a36Sopenharmony_ci/* opl4_proc.c */ 21262306a36Sopenharmony_ciint snd_opl4_create_proc(struct snd_opl4 *opl4); 21362306a36Sopenharmony_civoid snd_opl4_free_proc(struct snd_opl4 *opl4); 21462306a36Sopenharmony_ci#else 21562306a36Sopenharmony_cistatic inline int snd_opl4_create_proc(struct snd_opl4 *opl4) { return 0; } 21662306a36Sopenharmony_cistatic inline void snd_opl4_free_proc(struct snd_opl4 *opl4) {} 21762306a36Sopenharmony_ci#endif 21862306a36Sopenharmony_ci 21962306a36Sopenharmony_ci/* opl4_seq.c */ 22062306a36Sopenharmony_ciextern int volume_boost; 22162306a36Sopenharmony_ci 22262306a36Sopenharmony_ci/* opl4_synth.c */ 22362306a36Sopenharmony_civoid snd_opl4_synth_reset(struct snd_opl4 *opl4); 22462306a36Sopenharmony_civoid snd_opl4_synth_shutdown(struct snd_opl4 *opl4); 22562306a36Sopenharmony_civoid snd_opl4_note_on(void *p, int note, int vel, struct snd_midi_channel *chan); 22662306a36Sopenharmony_civoid snd_opl4_note_off(void *p, int note, int vel, struct snd_midi_channel *chan); 22762306a36Sopenharmony_civoid snd_opl4_terminate_note(void *p, int note, struct snd_midi_channel *chan); 22862306a36Sopenharmony_civoid snd_opl4_control(void *p, int type, struct snd_midi_channel *chan); 22962306a36Sopenharmony_civoid snd_opl4_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset); 23062306a36Sopenharmony_ci 23162306a36Sopenharmony_ci/* yrw801.c */ 23262306a36Sopenharmony_ciint snd_yrw801_detect(struct snd_opl4 *opl4); 23362306a36Sopenharmony_ciextern const struct opl4_region_ptr snd_yrw801_regions[]; 23462306a36Sopenharmony_ci 23562306a36Sopenharmony_ci#endif /* __OPL4_LOCAL_H */ 236