Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Local definitions for the OPL4 driver
0003  *
0004  * Copyright (c) 2003 by Clemens Ladisch <clemens@ladisch.de>
0005  * All rights reserved.
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions, and the following disclaimer,
0012  *    without modification.
0013  * 2. The name of the author may not be used to endorse or promote products
0014  *    derived from this software without specific prior written permission.
0015  *
0016  * Alternatively, this software may be distributed and/or modified under the
0017  * terms of the GNU General Public License as published by the Free Software
0018  * Foundation; either version 2 of the License, or (at your option) any later
0019  * version.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
0022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
0025  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
0026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
0027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
0028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
0029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
0030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
0031  * SUCH DAMAGE.
0032  */
0033 
0034 #ifndef __OPL4_LOCAL_H
0035 #define __OPL4_LOCAL_H
0036 
0037 #include <sound/opl4.h>
0038 
0039 /*
0040  * Register numbers
0041  */
0042 
0043 #define OPL4_REG_TEST0          0x00
0044 #define OPL4_REG_TEST1          0x01
0045 
0046 #define OPL4_REG_MEMORY_CONFIGURATION   0x02
0047 #define   OPL4_MODE_BIT         0x01
0048 #define   OPL4_MTYPE_BIT        0x02
0049 #define   OPL4_TONE_HEADER_MASK     0x1c
0050 #define   OPL4_DEVICE_ID_MASK       0xe0
0051 
0052 #define OPL4_REG_MEMORY_ADDRESS_HIGH    0x03
0053 #define OPL4_REG_MEMORY_ADDRESS_MID 0x04
0054 #define OPL4_REG_MEMORY_ADDRESS_LOW 0x05
0055 #define OPL4_REG_MEMORY_DATA        0x06
0056 
0057 /*
0058  * Offsets to the register banks for voices. To get the
0059  * register number just add the voice number to the bank offset.
0060  *
0061  * Wave Table Number low bits (0x08 to 0x1F)
0062  */
0063 #define OPL4_REG_TONE_NUMBER        0x08
0064 
0065 /* Wave Table Number high bit, F-Number low bits (0x20 to 0x37) */
0066 #define OPL4_REG_F_NUMBER       0x20
0067 #define   OPL4_TONE_NUMBER_BIT8     0x01
0068 #define   OPL4_F_NUMBER_LOW_MASK    0xfe
0069 
0070 /* F-Number high bits, Octave, Pseudo-Reverb (0x38 to 0x4F) */
0071 #define OPL4_REG_OCTAVE         0x38
0072 #define   OPL4_F_NUMBER_HIGH_MASK   0x07
0073 #define   OPL4_BLOCK_MASK       0xf0
0074 #define   OPL4_PSEUDO_REVERB_BIT    0x08
0075 
0076 /* Total Level, Level Direct (0x50 to 0x67) */
0077 #define OPL4_REG_LEVEL          0x50
0078 #define   OPL4_TOTAL_LEVEL_MASK     0xfe
0079 #define   OPL4_LEVEL_DIRECT_BIT     0x01
0080 
0081 /* Key On, Damp, LFO RST, CH, Panpot (0x68 to 0x7F) */
0082 #define OPL4_REG_MISC           0x68
0083 #define   OPL4_KEY_ON_BIT       0x80
0084 #define   OPL4_DAMP_BIT         0x40
0085 #define   OPL4_LFO_RESET_BIT        0x20
0086 #define   OPL4_OUTPUT_CHANNEL_BIT   0x10
0087 #define   OPL4_PAN_POT_MASK     0x0f
0088 
0089 /* LFO, VIB (0x80 to 0x97) */
0090 #define OPL4_REG_LFO_VIBRATO        0x80
0091 #define   OPL4_LFO_FREQUENCY_MASK   0x38
0092 #define   OPL4_VIBRATO_DEPTH_MASK   0x07
0093 #define   OPL4_CHORUS_SEND_MASK     0xc0 /* ML only */
0094 
0095 /* Attack / Decay 1 rate (0x98 to 0xAF) */
0096 #define OPL4_REG_ATTACK_DECAY1      0x98
0097 #define   OPL4_ATTACK_RATE_MASK     0xf0
0098 #define   OPL4_DECAY1_RATE_MASK     0x0f
0099 
0100 /* Decay level / 2 rate (0xB0 to 0xC7) */
0101 #define OPL4_REG_LEVEL_DECAY2       0xb0
0102 #define   OPL4_DECAY_LEVEL_MASK     0xf0
0103 #define   OPL4_DECAY2_RATE_MASK     0x0f
0104 
0105 /* Release rate / Rate correction (0xC8 to 0xDF) */
0106 #define OPL4_REG_RELEASE_CORRECTION 0xc8
0107 #define   OPL4_RELEASE_RATE_MASK    0x0f
0108 #define   OPL4_RATE_INTERPOLATION_MASK  0xf0
0109 
0110 /* AM (0xE0 to 0xF7) */
0111 #define OPL4_REG_TREMOLO        0xe0
0112 #define   OPL4_TREMOLO_DEPTH_MASK   0x07
0113 #define   OPL4_REVERB_SEND_MASK     0xe0 /* ML only */
0114 
0115 /* Mixer */
0116 #define OPL4_REG_MIX_CONTROL_FM     0xf8
0117 #define OPL4_REG_MIX_CONTROL_PCM    0xf9
0118 #define   OPL4_MIX_LEFT_MASK        0x07
0119 #define   OPL4_MIX_RIGHT_MASK       0x38
0120 
0121 #define OPL4_REG_ATC            0xfa
0122 #define   OPL4_ATC_BIT          0x01 /* ???, ML only */
0123 
0124 /* bits in the OPL3 Status register */
0125 #define OPL4_STATUS_BUSY        0x01
0126 #define OPL4_STATUS_LOAD        0x02
0127 
0128 
0129 #define OPL4_MAX_VOICES 24
0130 
0131 #define SNDRV_SEQ_DEV_ID_OPL4 "opl4-synth"
0132 
0133 
0134 struct opl4_sound {
0135     u16 tone;
0136     s16 pitch_offset;
0137     u8 key_scaling;
0138     s8 panpot;
0139     u8 vibrato;
0140     u8 tone_attenuate;
0141     u8 volume_factor;
0142     u8 reg_lfo_vibrato;
0143     u8 reg_attack_decay1;
0144     u8 reg_level_decay2;
0145     u8 reg_release_correction;
0146     u8 reg_tremolo;
0147 };
0148 
0149 struct opl4_region {
0150     u8 key_min, key_max;
0151     struct opl4_sound sound;
0152 };
0153 
0154 struct opl4_region_ptr {
0155     int count;
0156     const struct opl4_region *regions;
0157 };
0158 
0159 struct opl4_voice {
0160     struct list_head list;
0161     int number;
0162     struct snd_midi_channel *chan;
0163     int note;
0164     int velocity;
0165     const struct opl4_sound *sound;
0166     u8 level_direct;
0167     u8 reg_f_number;
0168     u8 reg_misc;
0169     u8 reg_lfo_vibrato;
0170 };
0171 
0172 struct snd_opl4 {
0173     unsigned long fm_port;
0174     unsigned long pcm_port;
0175     struct resource *res_fm_port;
0176     struct resource *res_pcm_port;
0177     unsigned short hardware;
0178     spinlock_t reg_lock;
0179     struct snd_card *card;
0180 
0181 #ifdef CONFIG_SND_PROC_FS
0182     struct snd_info_entry *proc_entry;
0183     int memory_access;
0184 #endif
0185     struct mutex access_mutex;
0186 
0187 #if IS_ENABLED(CONFIG_SND_SEQUENCER)
0188     int used;
0189 
0190     int seq_dev_num;
0191     int seq_client;
0192     struct snd_seq_device *seq_dev;
0193 
0194     struct snd_midi_channel_set *chset;
0195     struct opl4_voice voices[OPL4_MAX_VOICES];
0196     struct list_head off_voices;
0197     struct list_head on_voices;
0198 #endif
0199 };
0200 
0201 /* opl4_lib.c */
0202 void snd_opl4_write(struct snd_opl4 *opl4, u8 reg, u8 value);
0203 u8 snd_opl4_read(struct snd_opl4 *opl4, u8 reg);
0204 void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size);
0205 void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size);
0206 
0207 /* opl4_mixer.c */
0208 int snd_opl4_create_mixer(struct snd_opl4 *opl4);
0209 
0210 #ifdef CONFIG_SND_PROC_FS
0211 /* opl4_proc.c */
0212 int snd_opl4_create_proc(struct snd_opl4 *opl4);
0213 void snd_opl4_free_proc(struct snd_opl4 *opl4);
0214 #else
0215 static inline int snd_opl4_create_proc(struct snd_opl4 *opl4) { return 0; }
0216 static inline void snd_opl4_free_proc(struct snd_opl4 *opl4) {}
0217 #endif
0218 
0219 /* opl4_seq.c */
0220 extern int volume_boost;
0221 
0222 /* opl4_synth.c */
0223 void snd_opl4_synth_reset(struct snd_opl4 *opl4);
0224 void snd_opl4_synth_shutdown(struct snd_opl4 *opl4);
0225 void snd_opl4_note_on(void *p, int note, int vel, struct snd_midi_channel *chan);
0226 void snd_opl4_note_off(void *p, int note, int vel, struct snd_midi_channel *chan);
0227 void snd_opl4_terminate_note(void *p, int note, struct snd_midi_channel *chan);
0228 void snd_opl4_control(void *p, int type, struct snd_midi_channel *chan);
0229 void snd_opl4_sysex(void *p, unsigned char *buf, int len, int parsed, struct snd_midi_channel_set *chset);
0230 
0231 /* yrw801.c */
0232 int snd_yrw801_detect(struct snd_opl4 *opl4);
0233 extern const struct opl4_region_ptr snd_yrw801_regions[];
0234 
0235 #endif /* __OPL4_LOCAL_H */