0001
0002 #ifndef __SOUND_OPL3_H
0003 #define __SOUND_OPL3_H
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038 #include <sound/core.h>
0039 #include <sound/hwdep.h>
0040 #include <sound/timer.h>
0041 #include <sound/seq_midi_emul.h>
0042 #include <sound/seq_oss.h>
0043 #include <sound/seq_oss_legacy.h>
0044 #include <sound/seq_device.h>
0045 #include <sound/asound_fm.h>
0046
0047
0048
0049
0050
0051 #define OPL3_REG_TEST 0x01
0052 #define OPL3_ENABLE_WAVE_SELECT 0x20
0053
0054 #define OPL3_REG_TIMER1 0x02
0055 #define OPL3_REG_TIMER2 0x03
0056 #define OPL3_REG_TIMER_CONTROL 0x04
0057 #define OPL3_IRQ_RESET 0x80
0058 #define OPL3_TIMER1_MASK 0x40
0059 #define OPL3_TIMER2_MASK 0x20
0060 #define OPL3_TIMER1_START 0x01
0061 #define OPL3_TIMER2_START 0x02
0062
0063 #define OPL3_REG_CONNECTION_SELECT 0x04
0064 #define OPL3_LEFT_4OP_0 0x01
0065 #define OPL3_LEFT_4OP_1 0x02
0066 #define OPL3_LEFT_4OP_2 0x04
0067 #define OPL3_RIGHT_4OP_0 0x08
0068 #define OPL3_RIGHT_4OP_1 0x10
0069 #define OPL3_RIGHT_4OP_2 0x20
0070
0071 #define OPL3_REG_MODE 0x05
0072 #define OPL3_OPL3_ENABLE 0x01
0073 #define OPL3_OPL4_ENABLE 0x02
0074
0075 #define OPL3_REG_KBD_SPLIT 0x08
0076 #define OPL3_COMPOSITE_SINE_WAVE_MODE 0x80
0077 #define OPL3_KEYBOARD_SPLIT 0x40
0078
0079 #define OPL3_REG_PERCUSSION 0xbd
0080 #define OPL3_TREMOLO_DEPTH 0x80
0081 #define OPL3_VIBRATO_DEPTH 0x40
0082 #define OPL3_PERCUSSION_ENABLE 0x20
0083 #define OPL3_BASSDRUM_ON 0x10
0084 #define OPL3_SNAREDRUM_ON 0x08
0085 #define OPL3_TOMTOM_ON 0x04
0086 #define OPL3_CYMBAL_ON 0x02
0087 #define OPL3_HIHAT_ON 0x01
0088
0089
0090
0091
0092
0093
0094
0095 #define OPL3_REG_AM_VIB 0x20
0096 #define OPL3_TREMOLO_ON 0x80
0097 #define OPL3_VIBRATO_ON 0x40
0098 #define OPL3_SUSTAIN_ON 0x20
0099 #define OPL3_KSR 0x10
0100 #define OPL3_MULTIPLE_MASK 0x0f
0101
0102
0103
0104
0105 #define OPL3_REG_KSL_LEVEL 0x40
0106 #define OPL3_KSL_MASK 0xc0
0107 #define OPL3_TOTAL_LEVEL_MASK 0x3f
0108
0109
0110
0111
0112 #define OPL3_REG_ATTACK_DECAY 0x60
0113 #define OPL3_ATTACK_MASK 0xf0
0114 #define OPL3_DECAY_MASK 0x0f
0115
0116
0117
0118
0119 #define OPL3_REG_SUSTAIN_RELEASE 0x80
0120 #define OPL3_SUSTAIN_MASK 0xf0
0121 #define OPL3_RELEASE_MASK 0x0f
0122
0123
0124
0125
0126 #define OPL3_REG_WAVE_SELECT 0xe0
0127 #define OPL3_WAVE_SELECT_MASK 0x07
0128
0129
0130
0131
0132
0133
0134
0135 #define OPL3_REG_FNUM_LOW 0xa0
0136
0137
0138
0139
0140 #define OPL3_REG_KEYON_BLOCK 0xb0
0141 #define OPL3_KEYON_BIT 0x20
0142 #define OPL3_BLOCKNUM_MASK 0x1c
0143 #define OPL3_FNUM_HIGH_MASK 0x03
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157 #define OPL3_REG_FEEDBACK_CONNECTION 0xc0
0158 #define OPL3_FEEDBACK_MASK 0x0e
0159 #define OPL3_CONNECTION_BIT 0x01
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194 #define OPL3_STEREO_BITS 0x30
0195 #define OPL3_VOICE_TO_LEFT 0x10
0196 #define OPL3_VOICE_TO_RIGHT 0x20
0197
0198
0199
0200
0201
0202 #define OPL3_LEFT 0x0000
0203 #define OPL3_RIGHT 0x0100
0204
0205 #define OPL3_HW_AUTO 0x0000
0206 #define OPL3_HW_OPL2 0x0200
0207 #define OPL3_HW_OPL3 0x0300
0208 #define OPL3_HW_OPL3_SV 0x0301
0209 #define OPL3_HW_OPL3_CS 0x0302
0210 #define OPL3_HW_OPL3_FM801 0x0303
0211 #define OPL3_HW_OPL3_CS4281 0x0304
0212 #define OPL3_HW_OPL4 0x0400
0213 #define OPL3_HW_OPL4_ML 0x0401
0214 #define OPL3_HW_MASK 0xff00
0215
0216 #define MAX_OPL2_VOICES 9
0217 #define MAX_OPL3_VOICES 18
0218
0219 struct snd_opl3;
0220
0221
0222
0223
0224
0225
0226 struct fm_operator {
0227 unsigned char am_vib;
0228 unsigned char ksl_level;
0229 unsigned char attack_decay;
0230 unsigned char sustain_release;
0231 unsigned char wave_select;
0232 } __attribute__((packed));
0233
0234
0235 struct fm_instrument {
0236 struct fm_operator op[4];
0237 unsigned char feedback_connection[2];
0238 unsigned char echo_delay;
0239 unsigned char echo_atten;
0240 unsigned char chorus_spread;
0241 unsigned char trnsps;
0242 unsigned char fix_dur;
0243 unsigned char modes;
0244 unsigned char fix_key;
0245 };
0246
0247
0248 #define FM_PATCH_OPL2 0x01
0249 #define FM_PATCH_OPL3 0x02
0250
0251
0252 struct fm_patch {
0253 unsigned char prog;
0254 unsigned char bank;
0255 unsigned char type;
0256 struct fm_instrument inst;
0257 char name[24];
0258 struct fm_patch *next;
0259 };
0260
0261
0262
0263
0264
0265 struct snd_opl3_voice {
0266 int state;
0267 #define SNDRV_OPL3_ST_OFF 0
0268 #define SNDRV_OPL3_ST_ON_2OP 1
0269 #define SNDRV_OPL3_ST_ON_4OP 2
0270 #define SNDRV_OPL3_ST_NOT_AVAIL -1
0271
0272 unsigned int time;
0273 unsigned char note;
0274
0275 unsigned long note_off;
0276 int note_off_check;
0277
0278 unsigned char keyon_reg;
0279
0280 struct snd_midi_channel *chan;
0281 };
0282
0283 struct snd_opl3 {
0284 unsigned long l_port;
0285 unsigned long r_port;
0286 struct resource *res_l_port;
0287 struct resource *res_r_port;
0288 unsigned short hardware;
0289
0290 void (*command) (struct snd_opl3 * opl3, unsigned short cmd, unsigned char val);
0291 unsigned short timer_enable;
0292 int seq_dev_num;
0293 struct snd_timer *timer1;
0294 struct snd_timer *timer2;
0295 spinlock_t timer_lock;
0296
0297 void *private_data;
0298 void (*private_free)(struct snd_opl3 *);
0299
0300 struct snd_hwdep *hwdep;
0301 spinlock_t reg_lock;
0302 struct snd_card *card;
0303 unsigned char fm_mode;
0304 unsigned char rhythm;
0305 unsigned char max_voices;
0306 #if IS_ENABLED(CONFIG_SND_SEQUENCER)
0307 #define SNDRV_OPL3_MODE_SYNTH 0
0308 #define SNDRV_OPL3_MODE_SEQ 1
0309 int synth_mode;
0310 int seq_client;
0311
0312 struct snd_seq_device *seq_dev;
0313 struct snd_midi_channel_set * chset;
0314
0315 #if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
0316 struct snd_seq_device *oss_seq_dev;
0317 struct snd_midi_channel_set * oss_chset;
0318 #endif
0319
0320 #define OPL3_PATCH_HASH_SIZE 32
0321 struct fm_patch *patch_table[OPL3_PATCH_HASH_SIZE];
0322
0323 struct snd_opl3_voice voices[MAX_OPL3_VOICES];
0324 int use_time;
0325
0326 unsigned short connection_reg;
0327 unsigned char drum_reg;
0328
0329 spinlock_t voice_lock;
0330
0331 struct timer_list tlist;
0332 int sys_timer_status;
0333 spinlock_t sys_timer_lock;
0334 #endif
0335 };
0336
0337
0338 void snd_opl3_interrupt(struct snd_hwdep * hw);
0339 int snd_opl3_new(struct snd_card *card, unsigned short hardware,
0340 struct snd_opl3 **ropl3);
0341 int snd_opl3_init(struct snd_opl3 *opl3);
0342 int snd_opl3_create(struct snd_card *card,
0343 unsigned long l_port, unsigned long r_port,
0344 unsigned short hardware,
0345 int integrated,
0346 struct snd_opl3 ** opl3);
0347 int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev);
0348 int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device,
0349 struct snd_hwdep ** rhwdep);
0350
0351
0352 int snd_opl3_open(struct snd_hwdep * hw, struct file *file);
0353 int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
0354 unsigned int cmd, unsigned long arg);
0355 int snd_opl3_release(struct snd_hwdep * hw, struct file *file);
0356
0357 void snd_opl3_reset(struct snd_opl3 * opl3);
0358
0359 #if IS_ENABLED(CONFIG_SND_SEQUENCER)
0360 long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count,
0361 loff_t *offset);
0362 int snd_opl3_load_patch(struct snd_opl3 *opl3,
0363 int prog, int bank, int type,
0364 const char *name,
0365 const unsigned char *ext,
0366 const unsigned char *data);
0367 struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank,
0368 int create_patch);
0369 void snd_opl3_clear_patches(struct snd_opl3 *opl3);
0370 #else
0371 #define snd_opl3_write NULL
0372 static inline void snd_opl3_clear_patches(struct snd_opl3 *opl3) {}
0373 #endif
0374
0375 #endif