18c2ecf20Sopenharmony_ci/* 28c2ecf20Sopenharmony_ci * Local definitions for the OPL4 driver 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de> 58c2ecf20Sopenharmony_ci * All rights reserved. 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Redistribution and use in source and binary forms, with or without 88c2ecf20Sopenharmony_ci * modification, are permitted provided that the following conditions 98c2ecf20Sopenharmony_ci * are met: 108c2ecf20Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright 118c2ecf20Sopenharmony_ci * notice, this list of conditions, and the following disclaimer, 128c2ecf20Sopenharmony_ci * without modification. 138c2ecf20Sopenharmony_ci * 2. The name of the author may not be used to endorse or promote products 148c2ecf20Sopenharmony_ci * derived from this software without specific prior written permission. 158c2ecf20Sopenharmony_ci * 168c2ecf20Sopenharmony_ci * Alternatively, this software may be distributed and/or modified under the 178c2ecf20Sopenharmony_ci * terms of the GNU General Public License as published by the Free Software 188c2ecf20Sopenharmony_ci * Foundation; either version 2 of the License, or (at your option) any later 198c2ecf20Sopenharmony_ci * version. 208c2ecf20Sopenharmony_ci * 218c2ecf20Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 228c2ecf20Sopenharmony_ci * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 238c2ecf20Sopenharmony_ci * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 248c2ecf20Sopenharmony_ci * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 258c2ecf20Sopenharmony_ci * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 268c2ecf20Sopenharmony_ci * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 278c2ecf20Sopenharmony_ci * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 288c2ecf20Sopenharmony_ci * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 298c2ecf20Sopenharmony_ci * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 308c2ecf20Sopenharmony_ci * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 318c2ecf20Sopenharmony_ci * SUCH DAMAGE. 328c2ecf20Sopenharmony_ci */ 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_ci#ifndef __OPL4_LOCAL_H 358c2ecf20Sopenharmony_ci#define __OPL4_LOCAL_H 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci#include <sound/opl4.h> 388c2ecf20Sopenharmony_ci 398c2ecf20Sopenharmony_ci/* 408c2ecf20Sopenharmony_ci * Register numbers 418c2ecf20Sopenharmony_ci */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#define OPL4_REG_TEST0 0x00 448c2ecf20Sopenharmony_ci#define OPL4_REG_TEST1 0x01 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci#define OPL4_REG_MEMORY_CONFIGURATION 0x02 478c2ecf20Sopenharmony_ci#define OPL4_MODE_BIT 0x01 488c2ecf20Sopenharmony_ci#define OPL4_MTYPE_BIT 0x02 498c2ecf20Sopenharmony_ci#define OPL4_TONE_HEADER_MASK 0x1c 508c2ecf20Sopenharmony_ci#define OPL4_DEVICE_ID_MASK 0xe0 518c2ecf20Sopenharmony_ci 528c2ecf20Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_HIGH 0x03 538c2ecf20Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_MID 0x04 548c2ecf20Sopenharmony_ci#define OPL4_REG_MEMORY_ADDRESS_LOW 0x05 558c2ecf20Sopenharmony_ci#define OPL4_REG_MEMORY_DATA 0x06 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_ci/* 588c2ecf20Sopenharmony_ci * Offsets to the register banks for voices. To get the 598c2ecf20Sopenharmony_ci * register number just add the voice number to the bank offset. 608c2ecf20Sopenharmony_ci * 618c2ecf20Sopenharmony_ci * Wave Table Number low bits (0x08 to 0x1F) 628c2ecf20Sopenharmony_ci */ 638c2ecf20Sopenharmony_ci#define OPL4_REG_TONE_NUMBER 0x08 648c2ecf20Sopenharmony_ci 658c2ecf20Sopenharmony_ci/* Wave Table Number high bit, F-Number low bits (0x20 to 0x37) */ 668c2ecf20Sopenharmony_ci#define OPL4_REG_F_NUMBER 0x20 678c2ecf20Sopenharmony_ci#define OPL4_TONE_NUMBER_BIT8 0x01 688c2ecf20Sopenharmony_ci#define OPL4_F_NUMBER_LOW_MASK 0xfe 698c2ecf20Sopenharmony_ci 708c2ecf20Sopenharmony_ci/* F-Number high bits, Octave, Pseudo-Reverb (0x38 to 0x4F) */ 718c2ecf20Sopenharmony_ci#define OPL4_REG_OCTAVE 0x38 728c2ecf20Sopenharmony_ci#define OPL4_F_NUMBER_HIGH_MASK 0x07 738c2ecf20Sopenharmony_ci#define OPL4_BLOCK_MASK 0xf0 748c2ecf20Sopenharmony_ci#define OPL4_PSEUDO_REVERB_BIT 0x08 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci/* Total Level, Level Direct (0x50 to 0x67) */ 778c2ecf20Sopenharmony_ci#define OPL4_REG_LEVEL 0x50 788c2ecf20Sopenharmony_ci#define OPL4_TOTAL_LEVEL_MASK 0xfe 798c2ecf20Sopenharmony_ci#define OPL4_LEVEL_DIRECT_BIT 0x01 808c2ecf20Sopenharmony_ci 818c2ecf20Sopenharmony_ci/* Key On, Damp, LFO RST, CH, Panpot (0x68 to 0x7F) */ 828c2ecf20Sopenharmony_ci#define OPL4_REG_MISC 0x68 838c2ecf20Sopenharmony_ci#define OPL4_KEY_ON_BIT 0x80 848c2ecf20Sopenharmony_ci#define OPL4_DAMP_BIT 0x40 858c2ecf20Sopenharmony_ci#define OPL4_LFO_RESET_BIT 0x20 868c2ecf20Sopenharmony_ci#define OPL4_OUTPUT_CHANNEL_BIT 0x10 878c2ecf20Sopenharmony_ci#define OPL4_PAN_POT_MASK 0x0f 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_ci/* LFO, VIB (0x80 to 0x97) */ 908c2ecf20Sopenharmony_ci#define OPL4_REG_LFO_VIBRATO 0x80 918c2ecf20Sopenharmony_ci#define OPL4_LFO_FREQUENCY_MASK 0x38 928c2ecf20Sopenharmony_ci#define OPL4_VIBRATO_DEPTH_MASK 0x07 938c2ecf20Sopenharmony_ci#define OPL4_CHORUS_SEND_MASK 0xc0 /* ML only */ 948c2ecf20Sopenharmony_ci 958c2ecf20Sopenharmony_ci/* Attack / Decay 1 rate (0x98 to 0xAF) */ 968c2ecf20Sopenharmony_ci#define OPL4_REG_ATTACK_DECAY1 0x98 978c2ecf20Sopenharmony_ci#define OPL4_ATTACK_RATE_MASK 0xf0 988c2ecf20Sopenharmony_ci#define OPL4_DECAY1_RATE_MASK 0x0f 998c2ecf20Sopenharmony_ci 1008c2ecf20Sopenharmony_ci/* Decay level / 2 rate (0xB0 to 0xC7) */ 1018c2ecf20Sopenharmony_ci#define OPL4_REG_LEVEL_DECAY2 0xb0 1028c2ecf20Sopenharmony_ci#define OPL4_DECAY_LEVEL_MASK 0xf0 1038c2ecf20Sopenharmony_ci#define OPL4_DECAY2_RATE_MASK 0x0f 1048c2ecf20Sopenharmony_ci 1058c2ecf20Sopenharmony_ci/* Release rate / Rate correction (0xC8 to 0xDF) */ 1068c2ecf20Sopenharmony_ci#define OPL4_REG_RELEASE_CORRECTION 0xc8 1078c2ecf20Sopenharmony_ci#define OPL4_RELEASE_RATE_MASK 0x0f 1088c2ecf20Sopenharmony_ci#define OPL4_RATE_INTERPOLATION_MASK 0xf0 1098c2ecf20Sopenharmony_ci 1108c2ecf20Sopenharmony_ci/* AM (0xE0 to 0xF7) */ 1118c2ecf20Sopenharmony_ci#define OPL4_REG_TREMOLO 0xe0 1128c2ecf20Sopenharmony_ci#define OPL4_TREMOLO_DEPTH_MASK 0x07 1138c2ecf20Sopenharmony_ci#define OPL4_REVERB_SEND_MASK 0xe0 /* ML only */ 1148c2ecf20Sopenharmony_ci 1158c2ecf20Sopenharmony_ci/* Mixer */ 1168c2ecf20Sopenharmony_ci#define OPL4_REG_MIX_CONTROL_FM 0xf8 1178c2ecf20Sopenharmony_ci#define OPL4_REG_MIX_CONTROL_PCM 0xf9 1188c2ecf20Sopenharmony_ci#define OPL4_MIX_LEFT_MASK 0x07 1198c2ecf20Sopenharmony_ci#define OPL4_MIX_RIGHT_MASK 0x38 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci#define OPL4_REG_ATC 0xfa 1228c2ecf20Sopenharmony_ci#define OPL4_ATC_BIT 0x01 /* ???, ML only */ 1238c2ecf20Sopenharmony_ci 1248c2ecf20Sopenharmony_ci/* bits in the OPL3 Status register */ 1258c2ecf20Sopenharmony_ci#define OPL4_STATUS_BUSY 0x01 1268c2ecf20Sopenharmony_ci#define OPL4_STATUS_LOAD 0x02 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci#define OPL4_MAX_VOICES 24 1308c2ecf20Sopenharmony_ci 1318c2ecf20Sopenharmony_ci#define SNDRV_SEQ_DEV_ID_OPL4 "opl4-synth" 1328c2ecf20Sopenharmony_ci 1338c2ecf20Sopenharmony_ci 1348c2ecf20Sopenharmony_cistruct opl4_sound { 1358c2ecf20Sopenharmony_ci u16 tone; 1368c2ecf20Sopenharmony_ci s16 pitch_offset; 1378c2ecf20Sopenharmony_ci u8 key_scaling; 1388c2ecf20Sopenharmony_ci s8 panpot; 1398c2ecf20Sopenharmony_ci u8 vibrato; 1408c2ecf20Sopenharmony_ci u8 tone_attenuate; 1418c2ecf20Sopenharmony_ci u8 volume_factor; 1428c2ecf20Sopenharmony_ci u8 reg_lfo_vibrato; 1438c2ecf20Sopenharmony_ci u8 reg_attack_decay1; 1448c2ecf20Sopenharmony_ci u8 reg_level_decay2; 1458c2ecf20Sopenharmony_ci u8 reg_release_correction; 1468c2ecf20Sopenharmony_ci u8 reg_tremolo; 1478c2ecf20Sopenharmony_ci}; 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistruct opl4_region { 1508c2ecf20Sopenharmony_ci u8 key_min, key_max; 1518c2ecf20Sopenharmony_ci struct opl4_sound sound; 1528c2ecf20Sopenharmony_ci}; 1538c2ecf20Sopenharmony_ci 1548c2ecf20Sopenharmony_cistruct opl4_region_ptr { 1558c2ecf20Sopenharmony_ci int count; 1568c2ecf20Sopenharmony_ci const struct opl4_region *regions; 1578c2ecf20Sopenharmony_ci}; 1588c2ecf20Sopenharmony_ci 1598c2ecf20Sopenharmony_cistruct opl4_voice { 1608c2ecf20Sopenharmony_ci struct list_head list; 1618c2ecf20Sopenharmony_ci int number; 1628c2ecf20Sopenharmony_ci struct snd_midi_channel *chan; 1638c2ecf20Sopenharmony_ci int note; 1648c2ecf20Sopenharmony_ci int velocity; 1658c2ecf20Sopenharmony_ci const struct opl4_sound *sound; 1668c2ecf20Sopenharmony_ci u8 level_direct; 1678c2ecf20Sopenharmony_ci u8 reg_f_number; 1688c2ecf20Sopenharmony_ci u8 reg_misc; 1698c2ecf20Sopenharmony_ci u8 reg_lfo_vibrato; 1708c2ecf20Sopenharmony_ci}; 1718c2ecf20Sopenharmony_ci 1728c2ecf20Sopenharmony_cistruct snd_opl4 { 1738c2ecf20Sopenharmony_ci unsigned long fm_port; 1748c2ecf20Sopenharmony_ci unsigned long pcm_port; 1758c2ecf20Sopenharmony_ci struct resource *res_fm_port; 1768c2ecf20Sopenharmony_ci struct resource *res_pcm_port; 1778c2ecf20Sopenharmony_ci unsigned short hardware; 1788c2ecf20Sopenharmony_ci spinlock_t reg_lock; 1798c2ecf20Sopenharmony_ci struct snd_card *card; 1808c2ecf20Sopenharmony_ci 1818c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 1828c2ecf20Sopenharmony_ci struct snd_info_entry *proc_entry; 1838c2ecf20Sopenharmony_ci int memory_access; 1848c2ecf20Sopenharmony_ci#endif 1858c2ecf20Sopenharmony_ci struct mutex access_mutex; 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci#if IS_ENABLED(CONFIG_SND_SEQUENCER) 1888c2ecf20Sopenharmony_ci int used; 1898c2ecf20Sopenharmony_ci 1908c2ecf20Sopenharmony_ci int seq_dev_num; 1918c2ecf20Sopenharmony_ci int seq_client; 1928c2ecf20Sopenharmony_ci struct snd_seq_device *seq_dev; 1938c2ecf20Sopenharmony_ci 1948c2ecf20Sopenharmony_ci struct snd_midi_channel_set *chset; 1958c2ecf20Sopenharmony_ci struct opl4_voice voices[OPL4_MAX_VOICES]; 1968c2ecf20Sopenharmony_ci struct list_head off_voices; 1978c2ecf20Sopenharmony_ci struct list_head on_voices; 1988c2ecf20Sopenharmony_ci#endif 1998c2ecf20Sopenharmony_ci}; 2008c2ecf20Sopenharmony_ci 2018c2ecf20Sopenharmony_ci/* opl4_lib.c */ 2028c2ecf20Sopenharmony_civoid snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value); 2038c2ecf20Sopenharmony_ciu8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg); 2048c2ecf20Sopenharmony_civoid snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size); 2058c2ecf20Sopenharmony_civoid snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size); 2068c2ecf20Sopenharmony_ci 2078c2ecf20Sopenharmony_ci/* opl4_mixer.c */ 2088c2ecf20Sopenharmony_ciint snd_opl4_create_mixer(struct snd_opl4 *opl4); 2098c2ecf20Sopenharmony_ci 2108c2ecf20Sopenharmony_ci#ifdef CONFIG_SND_PROC_FS 2118c2ecf20Sopenharmony_ci/* opl4_proc.c */ 2128c2ecf20Sopenharmony_ciint snd_opl4_create_proc(struct snd_opl4 *opl4); 2138c2ecf20Sopenharmony_civoid snd_opl4_free_proc(struct snd_opl4 *opl4); 2148c2ecf20Sopenharmony_ci#else 2158c2ecf20Sopenharmony_cistatic inline int snd_opl4_create_proc(struct snd_opl4 *opl4) { return 0; } 2168c2ecf20Sopenharmony_cistatic inline void snd_opl4_free_proc(struct snd_opl4 *opl4) {} 2178c2ecf20Sopenharmony_ci#endif 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci/* opl4_seq.c */ 2208c2ecf20Sopenharmony_ciextern int volume_boost; 2218c2ecf20Sopenharmony_ci 2228c2ecf20Sopenharmony_ci/* opl4_synth.c */ 2238c2ecf20Sopenharmony_civoid snd_opl4_synth_reset(struct snd_opl4 *opl4); 2248c2ecf20Sopenharmony_civoid snd_opl4_synth_shutdown(struct snd_opl4 *opl4); 2258c2ecf20Sopenharmony_civoid snd_opl4_note_on(void *p, int note, int vel, struct snd_midi_channel *chan); 2268c2ecf20Sopenharmony_civoid snd_opl4_note_off(void *p, int note, int vel, struct snd_midi_channel *chan); 2278c2ecf20Sopenharmony_civoid snd_opl4_terminate_note(void *p, int note, struct snd_midi_channel *chan); 2288c2ecf20Sopenharmony_civoid snd_opl4_control(void *p, int type, struct snd_midi_channel *chan); 2298c2ecf20Sopenharmony_civoid snd_opl4_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset); 2308c2ecf20Sopenharmony_ci 2318c2ecf20Sopenharmony_ci/* yrw801.c */ 2328c2ecf20Sopenharmony_ciint snd_yrw801_detect(struct snd_opl4 *opl4); 2338c2ecf20Sopenharmony_ciextern const struct opl4_region_ptr snd_yrw801_regions[]; 2348c2ecf20Sopenharmony_ci 2358c2ecf20Sopenharmony_ci#endif /* __OPL4_LOCAL_H */ 236