 i, OPL4_DAMP_BIT);
	spin_unlock_irqrestore(&opl4->reg_lock, flags);

	INIT_LIST_HEAD(&opl4->off_voices);
	INIT_LIST_HEAD(&opl4->on_voices);
	memset(opl4->voices, 0, sizeof(opl4->voices));
	for (i = 0; i < OPL4_MAX_VOICES; i++) {
		opl4->voices[i].number = i;
		list_add_tail(&opl4->voices[i].list, &opl4->off_voices);
	}

	snd_midi_channel_set_clear(opl4->chset);
}

/*
 * Shuts down all voices.
 */
void snd_opl4_synth_shutdown(struct snd_opl4 *opl4)
{
	unsigned long flags;
	int i;

	spin_lock_irqsave(&opl4->reg_lock, flags);
	for (i = 0; i < OPL4_MAX_VOICES; i++)
		snd_opl4_write(opl4, OPL4_REG_MISC + i,
			       opl4->voices[i].reg_misc & ~OPL4_KEY_ON_BIT);
	spin_unlock_irqrestore(&opl4->reg_lock, flags);
}

/*
 * Executes the callback for all voices playing the specified note.
 */
static void snd_opl4_do_for_note(struct snd_opl4 *opl4, int note, struct snd_midi_channel *chan,
				 void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice))
{
	int i;
	unsigned long flags;
	struct opl4_voice *voice;

	spin_lock_irqsave(&opl4->reg_lock, flags);
	for (i = 0; i < OPL4_MAX_VOICES; i++) {
		voice = &opl4->voices[i];
		if (voice->chan == chan && voice->note == note) {
			func(opl4, voice);
		}
	}
	spin_unlock_irqrestore(&opl4->reg_lock, flags);
}

/*
 * Executes the callback for all voices of to the specified channel.
 */
static void snd_opl4_do_for_channel(struct snd_opl4 *opl4,
				    struct snd_midi_channel *chan,
				    void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice))
{
	int i;
	unsigned long flags;
	struct opl4_voice *voice;

	spin_lock_irqsave(&opl4->reg_lock, flags);
	for (i = 0; i < OPL4_MAX_VOICES; i++) {
		voice = &opl4->voices[i];
		if (voice->chan == chan) {
			func(opl4, voice);
		}
	}
	spin_unlock_irqrestore(&opl4->reg_lock, flags);
}

/*
 * Executes the callback for all active voices.
 */
static void snd_opl4_do_for_all(struct snd_opl4 *opl4,
				void (*func)(struct snd_opl4 *opl4, struct opl4_voice *voice))
{
	int i;
	unsigned long flags;
	struct opl4_voice *voice;

	spin_lock_irqsave