Linux Audio

Check our new training course

Loading...
  1/* SPDX-License-Identifier: GPL-2.0-or-later */
  2#ifndef __SOUND_OPL3_H
  3#define __SOUND_OPL3_H
  4
  5/*
  6 * Definitions of the OPL-3 registers.
  7 *
  8 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
  9 *                  Hannu Savolainen 1993-1996
 10 *
 11 *      The OPL-3 mode is switched on by writing 0x01, to the offset 5
 12 *      of the right side.
 13 *
 14 *      Another special register at the right side is at offset 4. It contains
 15 *      a bit mask defining which voices are used as 4 OP voices.
 16 *
 17 *      The percussive mode is implemented in the left side only.
 18 *
 19 *      With the above exceptions the both sides can be operated independently.
 20 *      
 21 *      A 4 OP voice can be created by setting the corresponding
 22 *      bit at offset 4 of the right side.
 23 *
 24 *      For example setting the rightmost bit (0x01) changes the
 25 *      first voice on the right side to the 4 OP mode. The fourth
 26 *      voice is made inaccessible.
 27 *
 28 *      If a voice is set to the 2 OP mode, it works like 2 OP modes
 29 *      of the original YM3812 (AdLib). In addition the voice can 
 30 *      be connected the left, right or both stereo channels. It can
 31 *      even be left unconnected. This works with 4 OP voices also.
 32 *
 33 *      The stereo connection bits are located in the FEEDBACK_CONNECTION
 34 *      register of the voice (0xC0-0xC8). In 4 OP voices these bits are
 35 *      in the second half of the voice.
 36 */
 37
 38#include <sound/core.h>
 39#include <sound/hwdep.h>
 40#include <sound/timer.h>
 41#include <sound/seq_midi_emul.h>
 42#include <sound/seq_oss.h>
 43#include <sound/seq_oss_legacy.h>
 44#include <sound/seq_device.h>
 45#include <sound/asound_fm.h>
 46
 47/*
 48 *    Register numbers for the global registers
 49 */
 50
 51#define OPL3_REG_TEST			0x01
 52#define   OPL3_ENABLE_WAVE_SELECT	0x20
 53
 54#define OPL3_REG_TIMER1			0x02
 55#define OPL3_REG_TIMER2			0x03
 56#define OPL3_REG_TIMER_CONTROL		0x04	/* Left side */
 57#define   OPL3_IRQ_RESET		0x80
 58#define   OPL3_TIMER1_MASK		0x40
 59#define   OPL3_TIMER2_MASK		0x20
 60#define   OPL3_TIMER1_START		0x01
 61#define   OPL3_TIMER2_START		0x02
 62
 63#define OPL3_REG_CONNECTION_SELECT	0x04	/* Right side */
 64#define   OPL3_LEFT_4OP_0		0x01
 65#define   OPL3_LEFT_4OP_1		0x02
 66#define   OPL3_LEFT_4OP_2		0x04
 67#define   OPL3_RIGHT_4OP_0		0x08
 68#define   OPL3_RIGHT_4OP_1		0x10
 69#define   OPL3_RIGHT_4OP_2		0x20
 70
 71#define OPL3_REG_MODE			0x05	/* Right side */
 72#define   OPL3_OPL3_ENABLE		0x01	/* OPL3 mode */
 73#define   OPL3_OPL4_ENABLE		0x02	/* OPL4 mode */
 74
 75#define OPL3_REG_KBD_SPLIT		0x08	/* Left side */
 76#define   OPL3_COMPOSITE_SINE_WAVE_MODE	0x80	/* Don't use with OPL-3? */
 77#define   OPL3_KEYBOARD_SPLIT		0x40
 78
 79#define OPL3_REG_PERCUSSION		0xbd	/* Left side only */
 80#define   OPL3_TREMOLO_DEPTH		0x80
 81#define   OPL3_VIBRATO_DEPTH		0x40
 82#define	  OPL3_PERCUSSION_ENABLE	0x20
 83#define   OPL3_BASSDRUM_ON		0x10
 84#define   OPL3_SNAREDRUM_ON		0x08
 85#define   OPL3_TOMTOM_ON		0x04
 86#define   OPL3_CYMBAL_ON		0x02
 87#define   OPL3_HIHAT_ON			0x01
 88
 89/*
 90 *    Offsets to the register banks for operators. To get the
 91 *      register number just add the operator offset to the bank offset
 92 *
 93 *      AM/VIB/EG/KSR/Multiple (0x20 to 0x35)
 94 */
 95#define OPL3_REG_AM_VIB			0x20
 96#define   OPL3_TREMOLO_ON		0x80
 97#define   OPL3_VIBRATO_ON		0x40
 98#define   OPL3_SUSTAIN_ON		0x20
 99#define   OPL3_KSR			0x10	/* Key scaling rate */
100#define   OPL3_MULTIPLE_MASK		0x0f	/* Frequency multiplier */
101
102 /*
103  *   KSL/Total level (0x40 to 0x55)
104  */
105#define OPL3_REG_KSL_LEVEL		0x40
106#define   OPL3_KSL_MASK			0xc0	/* Envelope scaling bits */
107#define   OPL3_TOTAL_LEVEL_MASK		0x3f	/* Strength (volume) of OP */
108
109/*
110 *    Attack / Decay rate (0x60 to 0x75)
111 */
112#define OPL3_REG_ATTACK_DECAY		0x60
113#define   OPL3_ATTACK_MASK		0xf0
114#define   OPL3_DECAY_MASK		0x0f
115
116/*
117 * Sustain level / Release rate (0x80 to 0x95)
118 */
119#define OPL3_REG_SUSTAIN_RELEASE	0x80
120#define   OPL3_SUSTAIN_MASK		0xf0
121#define   OPL3_RELEASE_MASK		0x0f
122
123/*
124 * Wave select (0xE0 to 0xF5)
125 */
126#define OPL3_REG_WAVE_SELECT		0xe0
127#define   OPL3_WAVE_SELECT_MASK		0x07
128
129/*
130 *    Offsets to the register banks for voices. Just add to the
131 *      voice number to get the register number.
132 *
133 *      F-Number low bits (0xA0 to 0xA8).
134 */
135#define OPL3_REG_FNUM_LOW		0xa0
136
137/*
138 *    F-number high bits / Key on / Block (octave) (0xB0 to 0xB8)
139 */
140#define OPL3_REG_KEYON_BLOCK		0xb0
141#define	  OPL3_KEYON_BIT		0x20
142#define	  OPL3_BLOCKNUM_MASK		0x1c
143#define   OPL3_FNUM_HIGH_MASK		0x03
144
145/*
146 *    Feedback / Connection (0xc0 to 0xc8)
147 *
148 *      These registers have two new bits when the OPL-3 mode
149 *      is selected. These bits controls connecting the voice
150 *      to the stereo channels. For 4 OP voices this bit is
151 *      defined in the second half of the voice (add 3 to the
152 *      register offset).
153 *
154 *      For 4 OP voices the connection bit is used in the
155 *      both halves (gives 4 ways to connect the operators).
156 */
157#define OPL3_REG_FEEDBACK_CONNECTION	0xc0
158#define   OPL3_FEEDBACK_MASK		0x0e	/* Valid just for 1st OP of a voice */
159#define   OPL3_CONNECTION_BIT		0x01
160/*
161 *    In the 4 OP mode there is four possible configurations how the
162 *      operators can be connected together (in 2 OP modes there is just
163 *      AM or FM). The 4 OP connection mode is defined by the rightmost
164 *      bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halves.
165 *
166 *      First half      Second half     Mode
167 *
168 *                                       +---+
169 *                                       v   |
170 *      0               0               >+-1-+--2--3--4-->
171 *
172 *
173 *                                      
174 *                                       +---+
175 *                                       |   |
176 *      0               1               >+-1-+--2-+
177 *                                                |->
178 *                                      >--3----4-+
179 *                                      
180 *                                       +---+
181 *                                       |   |
182 *      1               0               >+-1-+-----+
183 *                                                 |->
184 *                                      >--2--3--4-+
185 *
186 *                                       +---+
187 *                                       |   |
188 *      1               1               >+-1-+--+
189 *                                              |
190 *                                      >--2--3-+->
191 *                                              |
192 *                                      >--4----+
193 */
194#define   OPL3_STEREO_BITS		0x30	/* OPL-3 only */
195#define     OPL3_VOICE_TO_LEFT		0x10
196#define     OPL3_VOICE_TO_RIGHT		0x20
197
198/*
199
200 */
201
202#define OPL3_LEFT		0x0000
203#define OPL3_RIGHT		0x0100
204
205#define OPL3_HW_AUTO		0x0000
206#define OPL3_HW_OPL2		0x0200
207#define OPL3_HW_OPL3		0x0300
208#define OPL3_HW_OPL3_SV		0x0301	/* S3 SonicVibes */
209#define OPL3_HW_OPL3_CS		0x0302	/* CS4232/CS4236+ */
210#define OPL3_HW_OPL3_FM801	0x0303	/* FM801 */
211#define OPL3_HW_OPL3_CS4281	0x0304	/* CS4281 */
212#define OPL3_HW_OPL4		0x0400	/* YMF278B/YMF295 */
213#define OPL3_HW_OPL4_ML		0x0401	/* YMF704/YMF721 */
214#define OPL3_HW_MASK		0xff00
215
216#define MAX_OPL2_VOICES		9
217#define MAX_OPL3_VOICES		18
218
219struct snd_opl3;
220
221/*
222 * Instrument record, aka "Patch"
223 */
224
225/* FM operator */
226struct fm_operator {
227	unsigned char am_vib;
228	unsigned char ksl_level;
229	unsigned char attack_decay;
230	unsigned char sustain_release;
231	unsigned char wave_select;
232} __attribute__((packed));
233
234/* Instrument data */
235struct fm_instrument {
236	struct fm_operator op[4];
237	unsigned char feedback_connection[2];
238	unsigned char echo_delay;
239	unsigned char echo_atten;
240	unsigned char chorus_spread;
241	unsigned char trnsps;
242	unsigned char fix_dur;
243	unsigned char modes;
244	unsigned char fix_key;
245};
246
247/* type */
248#define FM_PATCH_OPL2	0x01		/* OPL2 2 operators FM instrument */
249#define FM_PATCH_OPL3	0x02		/* OPL3 4 operators FM instrument */
250
251/* Instrument record */
252struct fm_patch {
253	unsigned char prog;
254	unsigned char bank;
255	unsigned char type;
256	struct fm_instrument inst;
257	char name[24];
258	struct fm_patch *next;
259};
260
261
262/*
263 * A structure to keep track of each hardware voice
264 */
265struct snd_opl3_voice {
266	int  state;		/* status */
267#define SNDRV_OPL3_ST_OFF		0	/* Not playing */
268#define SNDRV_OPL3_ST_ON_2OP	1	/* 2op voice is allocated */
269#define SNDRV_OPL3_ST_ON_4OP	2	/* 4op voice is allocated */
270#define SNDRV_OPL3_ST_NOT_AVAIL	-1	/* voice is not available */
271
272	unsigned int time;	/* An allocation time */
273	unsigned char note;	/* Note currently assigned to this voice */
274
275	unsigned long note_off;	/* note-off time */
276	int note_off_check;	/* check note-off time */
277
278	unsigned char keyon_reg;	/* KON register shadow */
279
280	struct snd_midi_channel *chan;	/* Midi channel for this note */
281};
282
283struct snd_opl3 {
284	unsigned long l_port;
285	unsigned long r_port;
286	struct resource *res_l_port;
287	struct resource *res_r_port;
288	unsigned short hardware;
289	/* hardware access */
290	void (*command) (struct snd_opl3 * opl3, unsigned short cmd, unsigned char val);
291	unsigned short timer_enable;
292	int seq_dev_num;	/* sequencer device number */
293	struct snd_timer *timer1;
294	struct snd_timer *timer2;
295	spinlock_t timer_lock;
296
297	void *private_data;
298	void (*private_free)(struct snd_opl3 *);
299
300	struct snd_hwdep *hwdep;
301	spinlock_t reg_lock;
302	struct snd_card *card;		/* The card that this belongs to */
303	unsigned char fm_mode;		/* OPL mode, see SNDRV_DM_FM_MODE_XXX */
304	unsigned char rhythm;		/* percussion mode flag */
305	unsigned char max_voices;	/* max number of voices */
306#if IS_ENABLED(CONFIG_SND_SEQUENCER)
307#define SNDRV_OPL3_MODE_SYNTH 0		/* OSS - voices allocated by application */
308#define SNDRV_OPL3_MODE_SEQ 1		/* ALSA - driver handles voice allocation */
309	int synth_mode;			/* synth mode */
310	int seq_client;
311
312	struct snd_seq_device *seq_dev;	/* sequencer device */
313	struct snd_midi_channel_set * chset;
314
315#if IS_ENABLED(CONFIG_SND_SEQUENCER_OSS)
316	struct snd_seq_device *oss_seq_dev;	/* OSS sequencer device */
317	struct snd_midi_channel_set * oss_chset;
318#endif
319 
320#define OPL3_PATCH_HASH_SIZE	32
321	struct fm_patch *patch_table[OPL3_PATCH_HASH_SIZE];
322
323	struct snd_opl3_voice voices[MAX_OPL3_VOICES]; /* Voices (OPL3 'channel') */
324	int use_time;			/* allocation counter */
325
326	unsigned short connection_reg;	/* connection reg shadow */
327	unsigned char drum_reg;		/* percussion reg shadow */
328
329	spinlock_t voice_lock;		/* Lock for voice access */
330
331	struct timer_list tlist;	/* timer for note-offs and effects */
332	int sys_timer_status;		/* system timer run status */
333	spinlock_t sys_timer_lock;	/* Lock for system timer access */
334#endif
335};
336
337/* opl3.c */
338void snd_opl3_interrupt(struct snd_hwdep * hw);
339int snd_opl3_new(struct snd_card *card, unsigned short hardware,
340		 struct snd_opl3 **ropl3);
341int snd_opl3_init(struct snd_opl3 *opl3);
342int snd_opl3_create(struct snd_card *card,
343		    unsigned long l_port, unsigned long r_port,
344		    unsigned short hardware,
345		    int integrated,
346		    struct snd_opl3 ** opl3);
347int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev);
348int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device,
349		       struct snd_hwdep ** rhwdep);
350
351/* opl3_synth */
352int snd_opl3_open(struct snd_hwdep * hw, struct file *file);
353int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
354		   unsigned int cmd, unsigned long arg);
355int snd_opl3_release(struct snd_hwdep * hw, struct file *file);
356
357void snd_opl3_reset(struct snd_opl3 * opl3);
358
359#if IS_ENABLED(CONFIG_SND_SEQUENCER)
360long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count,
361		    loff_t *offset);
362int snd_opl3_load_patch(struct snd_opl3 *opl3,
363			int prog, int bank, int type,
364			const char *name,
365			const unsigned char *ext,
366			const unsigned char *data);
367struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank,
368				     int create_patch);
369void snd_opl3_clear_patches(struct snd_opl3 *opl3);
370#else
371#define snd_opl3_write	NULL
372static inline void snd_opl3_clear_patches(struct snd_opl3 *opl3) {}
373#endif
374
375#endif /* __SOUND_OPL3_H */
  1#ifndef __SOUND_OPL3_H
  2#define __SOUND_OPL3_H
  3
  4/*
  5 * Definitions of the OPL-3 registers.
  6 *
  7 * Copyright (c) by Jaroslav Kysela <perex@perex.cz>,
  8 *                  Hannu Savolainen 1993-1996
  9 *
 10 *
 11 *      The OPL-3 mode is switched on by writing 0x01, to the offset 5
 12 *      of the right side.
 13 *
 14 *      Another special register at the right side is at offset 4. It contains
 15 *      a bit mask defining which voices are used as 4 OP voices.
 16 *
 17 *      The percussive mode is implemented in the left side only.
 18 *
 19 *      With the above exceptions the both sides can be operated independently.
 20 *      
 21 *      A 4 OP voice can be created by setting the corresponding
 22 *      bit at offset 4 of the right side.
 23 *
 24 *      For example setting the rightmost bit (0x01) changes the
 25 *      first voice on the right side to the 4 OP mode. The fourth
 26 *      voice is made inaccessible.
 27 *
 28 *      If a voice is set to the 2 OP mode, it works like 2 OP modes
 29 *      of the original YM3812 (AdLib). In addition the voice can 
 30 *      be connected the left, right or both stereo channels. It can
 31 *      even be left unconnected. This works with 4 OP voices also.
 32 *
 33 *      The stereo connection bits are located in the FEEDBACK_CONNECTION
 34 *      register of the voice (0xC0-0xC8). In 4 OP voices these bits are
 35 *      in the second half of the voice.
 36 *
 37 *
 38 *   This program is free software; you can redistribute it and/or modify
 39 *   it under the terms of the GNU General Public License as published by
 40 *   the Free Software Foundation; either version 2 of the License, or
 41 *   (at your option) any later version.
 42 *
 43 *   This program is distributed in the hope that it will be useful,
 44 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 45 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 46 *   GNU General Public License for more details.
 47 *
 48 *   You should have received a copy of the GNU General Public License
 49 *   along with this program; if not, write to the Free Software
 50 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 51 *
 52 */
 53
 54#include <sound/core.h>
 55#include <sound/hwdep.h>
 56#include <sound/timer.h>
 57#include <sound/seq_midi_emul.h>
 58#ifdef CONFIG_SND_SEQUENCER_OSS
 59#include <sound/seq_oss.h>
 60#include <sound/seq_oss_legacy.h>
 61#endif
 62#include <sound/seq_device.h>
 63#include <sound/asound_fm.h>
 64
 65/*
 66 *    Register numbers for the global registers
 67 */
 68
 69#define OPL3_REG_TEST			0x01
 70#define   OPL3_ENABLE_WAVE_SELECT	0x20
 71
 72#define OPL3_REG_TIMER1			0x02
 73#define OPL3_REG_TIMER2			0x03
 74#define OPL3_REG_TIMER_CONTROL		0x04	/* Left side */
 75#define   OPL3_IRQ_RESET		0x80
 76#define   OPL3_TIMER1_MASK		0x40
 77#define   OPL3_TIMER2_MASK		0x20
 78#define   OPL3_TIMER1_START		0x01
 79#define   OPL3_TIMER2_START		0x02
 80
 81#define OPL3_REG_CONNECTION_SELECT	0x04	/* Right side */
 82#define   OPL3_LEFT_4OP_0		0x01
 83#define   OPL3_LEFT_4OP_1		0x02
 84#define   OPL3_LEFT_4OP_2		0x04
 85#define   OPL3_RIGHT_4OP_0		0x08
 86#define   OPL3_RIGHT_4OP_1		0x10
 87#define   OPL3_RIGHT_4OP_2		0x20
 88
 89#define OPL3_REG_MODE			0x05	/* Right side */
 90#define   OPL3_OPL3_ENABLE		0x01	/* OPL3 mode */
 91#define   OPL3_OPL4_ENABLE		0x02	/* OPL4 mode */
 92
 93#define OPL3_REG_KBD_SPLIT		0x08	/* Left side */
 94#define   OPL3_COMPOSITE_SINE_WAVE_MODE	0x80	/* Don't use with OPL-3? */
 95#define   OPL3_KEYBOARD_SPLIT		0x40
 96
 97#define OPL3_REG_PERCUSSION		0xbd	/* Left side only */
 98#define   OPL3_TREMOLO_DEPTH		0x80
 99#define   OPL3_VIBRATO_DEPTH		0x40
100#define	  OPL3_PERCUSSION_ENABLE	0x20
101#define   OPL3_BASSDRUM_ON		0x10
102#define   OPL3_SNAREDRUM_ON		0x08
103#define   OPL3_TOMTOM_ON		0x04
104#define   OPL3_CYMBAL_ON		0x02
105#define   OPL3_HIHAT_ON			0x01
106
107/*
108 *    Offsets to the register banks for operators. To get the
109 *      register number just add the operator offset to the bank offset
110 *
111 *      AM/VIB/EG/KSR/Multiple (0x20 to 0x35)
112 */
113#define OPL3_REG_AM_VIB			0x20
114#define   OPL3_TREMOLO_ON		0x80
115#define   OPL3_VIBRATO_ON		0x40
116#define   OPL3_SUSTAIN_ON		0x20
117#define   OPL3_KSR			0x10	/* Key scaling rate */
118#define   OPL3_MULTIPLE_MASK		0x0f	/* Frequency multiplier */
119
120 /*
121  *   KSL/Total level (0x40 to 0x55)
122  */
123#define OPL3_REG_KSL_LEVEL		0x40
124#define   OPL3_KSL_MASK			0xc0	/* Envelope scaling bits */
125#define   OPL3_TOTAL_LEVEL_MASK		0x3f	/* Strength (volume) of OP */
126
127/*
128 *    Attack / Decay rate (0x60 to 0x75)
129 */
130#define OPL3_REG_ATTACK_DECAY		0x60
131#define   OPL3_ATTACK_MASK		0xf0
132#define   OPL3_DECAY_MASK		0x0f
133
134/*
135 * Sustain level / Release rate (0x80 to 0x95)
136 */
137#define OPL3_REG_SUSTAIN_RELEASE	0x80
138#define   OPL3_SUSTAIN_MASK		0xf0
139#define   OPL3_RELEASE_MASK		0x0f
140
141/*
142 * Wave select (0xE0 to 0xF5)
143 */
144#define OPL3_REG_WAVE_SELECT		0xe0
145#define   OPL3_WAVE_SELECT_MASK		0x07
146
147/*
148 *    Offsets to the register banks for voices. Just add to the
149 *      voice number to get the register number.
150 *
151 *      F-Number low bits (0xA0 to 0xA8).
152 */
153#define OPL3_REG_FNUM_LOW		0xa0
154
155/*
156 *    F-number high bits / Key on / Block (octave) (0xB0 to 0xB8)
157 */
158#define OPL3_REG_KEYON_BLOCK		0xb0
159#define	  OPL3_KEYON_BIT		0x20
160#define	  OPL3_BLOCKNUM_MASK		0x1c
161#define   OPL3_FNUM_HIGH_MASK		0x03
162
163/*
164 *    Feedback / Connection (0xc0 to 0xc8)
165 *
166 *      These registers have two new bits when the OPL-3 mode
167 *      is selected. These bits controls connecting the voice
168 *      to the stereo channels. For 4 OP voices this bit is
169 *      defined in the second half of the voice (add 3 to the
170 *      register offset).
171 *
172 *      For 4 OP voices the connection bit is used in the
173 *      both halves (gives 4 ways to connect the operators).
174 */
175#define OPL3_REG_FEEDBACK_CONNECTION	0xc0
176#define   OPL3_FEEDBACK_MASK		0x0e	/* Valid just for 1st OP of a voice */
177#define   OPL3_CONNECTION_BIT		0x01
178/*
179 *    In the 4 OP mode there is four possible configurations how the
180 *      operators can be connected together (in 2 OP modes there is just
181 *      AM or FM). The 4 OP connection mode is defined by the rightmost
182 *      bit of the FEEDBACK_CONNECTION (0xC0-0xC8) on the both halves.
183 *
184 *      First half      Second half     Mode
185 *
186 *                                       +---+
187 *                                       v   |
188 *      0               0               >+-1-+--2--3--4-->
189 *
190 *
191 *                                      
192 *                                       +---+
193 *                                       |   |
194 *      0               1               >+-1-+--2-+
195 *                                                |->
196 *                                      >--3----4-+
197 *                                      
198 *                                       +---+
199 *                                       |   |
200 *      1               0               >+-1-+-----+
201 *                                                 |->
202 *                                      >--2--3--4-+
203 *
204 *                                       +---+
205 *                                       |   |
206 *      1               1               >+-1-+--+
207 *                                              |
208 *                                      >--2--3-+->
209 *                                              |
210 *                                      >--4----+
211 */
212#define   OPL3_STEREO_BITS		0x30	/* OPL-3 only */
213#define     OPL3_VOICE_TO_LEFT		0x10
214#define     OPL3_VOICE_TO_RIGHT		0x20
215
216/*
217
218 */
219
220#define OPL3_LEFT		0x0000
221#define OPL3_RIGHT		0x0100
222
223#define OPL3_HW_AUTO		0x0000
224#define OPL3_HW_OPL2		0x0200
225#define OPL3_HW_OPL3		0x0300
226#define OPL3_HW_OPL3_SV		0x0301	/* S3 SonicVibes */
227#define OPL3_HW_OPL3_CS		0x0302	/* CS4232/CS4236+ */
228#define OPL3_HW_OPL3_FM801	0x0303	/* FM801 */
229#define OPL3_HW_OPL3_CS4281	0x0304	/* CS4281 */
230#define OPL3_HW_OPL4		0x0400	/* YMF278B/YMF295 */
231#define OPL3_HW_OPL4_ML		0x0401	/* YMF704/YMF721 */
232#define OPL3_HW_MASK		0xff00
233
234#define MAX_OPL2_VOICES		9
235#define MAX_OPL3_VOICES		18
236
237struct snd_opl3;
238
239/*
240 * Instrument record, aka "Patch"
241 */
242
243/* FM operator */
244struct fm_operator {
245	unsigned char am_vib;
246	unsigned char ksl_level;
247	unsigned char attack_decay;
248	unsigned char sustain_release;
249	unsigned char wave_select;
250} __attribute__((packed));
251
252/* Instrument data */
253struct fm_instrument {
254	struct fm_operator op[4];
255	unsigned char feedback_connection[2];
256	unsigned char echo_delay;
257	unsigned char echo_atten;
258	unsigned char chorus_spread;
259	unsigned char trnsps;
260	unsigned char fix_dur;
261	unsigned char modes;
262	unsigned char fix_key;
263};
264
265/* type */
266#define FM_PATCH_OPL2	0x01		/* OPL2 2 operators FM instrument */
267#define FM_PATCH_OPL3	0x02		/* OPL3 4 operators FM instrument */
268
269/* Instrument record */
270struct fm_patch {
271	unsigned char prog;
272	unsigned char bank;
273	unsigned char type;
274	struct fm_instrument inst;
275	char name[24];
276	struct fm_patch *next;
277};
278
279
280/*
281 * A structure to keep track of each hardware voice
282 */
283struct snd_opl3_voice {
284	int  state;		/* status */
285#define SNDRV_OPL3_ST_OFF		0	/* Not playing */
286#define SNDRV_OPL3_ST_ON_2OP	1	/* 2op voice is allocated */
287#define SNDRV_OPL3_ST_ON_4OP	2	/* 4op voice is allocated */
288#define SNDRV_OPL3_ST_NOT_AVAIL	-1	/* voice is not available */
289
290	unsigned int time;	/* An allocation time */
291	unsigned char note;	/* Note currently assigned to this voice */
292
293	unsigned long note_off;	/* note-off time */
294	int note_off_check;	/* check note-off time */
295
296	unsigned char keyon_reg;	/* KON register shadow */
297
298	struct snd_midi_channel *chan;	/* Midi channel for this note */
299};
300
301struct snd_opl3 {
302	unsigned long l_port;
303	unsigned long r_port;
304	struct resource *res_l_port;
305	struct resource *res_r_port;
306	unsigned short hardware;
307	/* hardware access */
308	void (*command) (struct snd_opl3 * opl3, unsigned short cmd, unsigned char val);
309	unsigned short timer_enable;
310	int seq_dev_num;	/* sequencer device number */
311	struct snd_timer *timer1;
312	struct snd_timer *timer2;
313	spinlock_t timer_lock;
314
315	void *private_data;
316	void (*private_free)(struct snd_opl3 *);
317
318	struct snd_hwdep *hwdep;
319	spinlock_t reg_lock;
320	struct snd_card *card;		/* The card that this belongs to */
321	unsigned char fm_mode;		/* OPL mode, see SNDRV_DM_FM_MODE_XXX */
322	unsigned char rhythm;		/* percussion mode flag */
323	unsigned char max_voices;	/* max number of voices */
324#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
325#define SNDRV_OPL3_MODE_SYNTH 0		/* OSS - voices allocated by application */
326#define SNDRV_OPL3_MODE_SEQ 1		/* ALSA - driver handles voice allocation */
327	int synth_mode;			/* synth mode */
328	int seq_client;
329
330	struct snd_seq_device *seq_dev;	/* sequencer device */
331	struct snd_midi_channel_set * chset;
332
333#ifdef CONFIG_SND_SEQUENCER_OSS
334	struct snd_seq_device *oss_seq_dev;	/* OSS sequencer device */
335	struct snd_midi_channel_set * oss_chset;
336#endif
337 
338#define OPL3_PATCH_HASH_SIZE	32
339	struct fm_patch *patch_table[OPL3_PATCH_HASH_SIZE];
340
341	struct snd_opl3_voice voices[MAX_OPL3_VOICES]; /* Voices (OPL3 'channel') */
342	int use_time;			/* allocation counter */
343
344	unsigned short connection_reg;	/* connection reg shadow */
345	unsigned char drum_reg;		/* percussion reg shadow */
346
347	spinlock_t voice_lock;		/* Lock for voice access */
348
349	struct timer_list tlist;	/* timer for note-offs and effects */
350	int sys_timer_status;		/* system timer run status */
351	spinlock_t sys_timer_lock;	/* Lock for system timer access */
352#endif
353};
354
355/* opl3.c */
356void snd_opl3_interrupt(struct snd_hwdep * hw);
357int snd_opl3_new(struct snd_card *card, unsigned short hardware,
358		 struct snd_opl3 **ropl3);
359int snd_opl3_init(struct snd_opl3 *opl3);
360int snd_opl3_create(struct snd_card *card,
361		    unsigned long l_port, unsigned long r_port,
362		    unsigned short hardware,
363		    int integrated,
364		    struct snd_opl3 ** opl3);
365int snd_opl3_timer_new(struct snd_opl3 * opl3, int timer1_dev, int timer2_dev);
366int snd_opl3_hwdep_new(struct snd_opl3 * opl3, int device, int seq_device,
367		       struct snd_hwdep ** rhwdep);
368
369/* opl3_synth */
370int snd_opl3_open(struct snd_hwdep * hw, struct file *file);
371int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
372		   unsigned int cmd, unsigned long arg);
373int snd_opl3_release(struct snd_hwdep * hw, struct file *file);
374
375void snd_opl3_reset(struct snd_opl3 * opl3);
376
377#if defined(CONFIG_SND_SEQUENCER) || defined(CONFIG_SND_SEQUENCER_MODULE)
378long snd_opl3_write(struct snd_hwdep *hw, const char __user *buf, long count,
379		    loff_t *offset);
380int snd_opl3_load_patch(struct snd_opl3 *opl3,
381			int prog, int bank, int type,
382			const char *name,
383			const unsigned char *ext,
384			const unsigned char *data);
385struct fm_patch *snd_opl3_find_patch(struct snd_opl3 *opl3, int prog, int bank,
386				     int create_patch);
387void snd_opl3_clear_patches(struct snd_opl3 *opl3);
388#else
389#define snd_opl3_write	NULL
390static inline void snd_opl3_clear_patches(struct snd_opl3 *opl3) {}
391#endif
392
393#endif /* __SOUND_OPL3_H */