mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 18:13:41 +02:00
ALSA: opl4: Use guard() for spin locks
Clean up the code using guard() for spin locks. Merely code refactoring, and no behavior change. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250829150026.6379-7-tiwai@suse.de
This commit is contained in:
parent
45451eb5d1
commit
72a3017077
|
|
@ -47,10 +47,9 @@ EXPORT_SYMBOL(snd_opl4_read);
|
|||
|
||||
void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size)
|
||||
{
|
||||
unsigned long flags;
|
||||
u8 memcfg;
|
||||
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
|
||||
memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
|
||||
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
|
||||
|
|
@ -65,18 +64,15 @@ void snd_opl4_read_memory(struct snd_opl4 *opl4, char *buf, int offset, int size
|
|||
insb(opl4->pcm_port + 1, buf, size);
|
||||
|
||||
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
|
||||
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(snd_opl4_read_memory);
|
||||
|
||||
void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, int size)
|
||||
{
|
||||
unsigned long flags;
|
||||
u8 memcfg;
|
||||
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
|
||||
memcfg = snd_opl4_read(opl4, OPL4_REG_MEMORY_CONFIGURATION);
|
||||
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg | OPL4_MODE_BIT);
|
||||
|
|
@ -91,8 +87,6 @@ void snd_opl4_write_memory(struct snd_opl4 *opl4, const char *buf, int offset, i
|
|||
outsb(opl4->pcm_port + 1, buf, size);
|
||||
|
||||
snd_opl4_write(opl4, OPL4_REG_MEMORY_CONFIGURATION, memcfg);
|
||||
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
}
|
||||
|
||||
EXPORT_SYMBOL(snd_opl4_write_memory);
|
||||
|
|
|
|||
|
|
@ -19,13 +19,11 @@ static int snd_opl4_ctl_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_
|
|||
static int snd_opl4_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
|
||||
unsigned long flags;
|
||||
u8 reg = kcontrol->private_value;
|
||||
u8 value;
|
||||
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
value = snd_opl4_read(opl4, reg);
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
ucontrol->value.integer.value[0] = 7 - (value & 7);
|
||||
ucontrol->value.integer.value[1] = 7 - ((value >> 3) & 7);
|
||||
return 0;
|
||||
|
|
@ -34,16 +32,14 @@ static int snd_opl4_ctl_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_v
|
|||
static int snd_opl4_ctl_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
|
||||
{
|
||||
struct snd_opl4 *opl4 = snd_kcontrol_chip(kcontrol);
|
||||
unsigned long flags;
|
||||
u8 reg = kcontrol->private_value;
|
||||
u8 value, old_value;
|
||||
|
||||
value = (7 - (ucontrol->value.integer.value[0] & 7)) |
|
||||
((7 - (ucontrol->value.integer.value[1] & 7)) << 3);
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
old_value = snd_opl4_read(opl4, reg);
|
||||
snd_opl4_write(opl4, reg, value);
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
return value != old_value;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -272,13 +272,12 @@ static const unsigned char snd_opl4_volume_table[128] = {
|
|||
*/
|
||||
void snd_opl4_synth_reset(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_DAMP_BIT);
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
scoped_guard(spinlock_irqsave, &opl4->reg_lock) {
|
||||
for (i = 0; i < OPL4_MAX_VOICES; i++)
|
||||
snd_opl4_write(opl4, OPL4_REG_MISC + i, OPL4_DAMP_BIT);
|
||||
}
|
||||
|
||||
INIT_LIST_HEAD(&opl4->off_voices);
|
||||
INIT_LIST_HEAD(&opl4->on_voices);
|
||||
|
|
@ -296,14 +295,12 @@ void snd_opl4_synth_reset(struct snd_opl4 *opl4)
|
|||
*/
|
||||
void snd_opl4_synth_shutdown(struct snd_opl4 *opl4)
|
||||
{
|
||||
unsigned long flags;
|
||||
int i;
|
||||
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -313,17 +310,15 @@ static void snd_opl4_do_for_note(struct snd_opl4 *opl4, int note, struct snd_mid
|
|||
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);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -334,17 +329,15 @@ static void snd_opl4_do_for_channel(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(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
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);
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -354,16 +347,14 @@ 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(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
for (i = 0; i < OPL4_MAX_VOICES; i++) {
|
||||
voice = &opl4->voices[i];
|
||||
if (voice->chan)
|
||||
func(opl4, voice);
|
||||
}
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
}
|
||||
|
||||
static void snd_opl4_update_volume(struct snd_opl4 *opl4, struct opl4_voice *voice)
|
||||
|
|
@ -486,7 +477,6 @@ void snd_opl4_note_on(void *private_data, int note, int vel, struct snd_midi_cha
|
|||
struct opl4_voice *voice[2];
|
||||
const struct opl4_sound *sound[2];
|
||||
int voices = 0, i;
|
||||
unsigned long flags;
|
||||
|
||||
/* determine the number of voices and voice parameters */
|
||||
i = chan->drum_channel ? 0x80 : (chan->midi_program & 0x7f);
|
||||
|
|
@ -501,41 +491,41 @@ void snd_opl4_note_on(void *private_data, int note, int vel, struct snd_midi_cha
|
|||
}
|
||||
|
||||
/* allocate and initialize the needed voices */
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i] = snd_opl4_get_voice(opl4);
|
||||
list_move_tail(&voice[i]->list, &opl4->on_voices);
|
||||
voice[i]->chan = chan;
|
||||
voice[i]->note = note;
|
||||
voice[i]->velocity = vel & 0x7f;
|
||||
voice[i]->sound = sound[i];
|
||||
}
|
||||
scoped_guard(spinlock_irqsave, &opl4->reg_lock) {
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i] = snd_opl4_get_voice(opl4);
|
||||
list_move_tail(&voice[i]->list, &opl4->on_voices);
|
||||
voice[i]->chan = chan;
|
||||
voice[i]->note = note;
|
||||
voice[i]->velocity = vel & 0x7f;
|
||||
voice[i]->sound = sound[i];
|
||||
}
|
||||
|
||||
/* set tone number (triggers header loading) */
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i]->reg_f_number =
|
||||
(sound[i]->tone >> 8) & OPL4_TONE_NUMBER_BIT8;
|
||||
snd_opl4_write(opl4, OPL4_REG_F_NUMBER + voice[i]->number,
|
||||
voice[i]->reg_f_number);
|
||||
snd_opl4_write(opl4, OPL4_REG_TONE_NUMBER + voice[i]->number,
|
||||
sound[i]->tone & 0xff);
|
||||
}
|
||||
/* set tone number (triggers header loading) */
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i]->reg_f_number =
|
||||
(sound[i]->tone >> 8) & OPL4_TONE_NUMBER_BIT8;
|
||||
snd_opl4_write(opl4, OPL4_REG_F_NUMBER + voice[i]->number,
|
||||
voice[i]->reg_f_number);
|
||||
snd_opl4_write(opl4, OPL4_REG_TONE_NUMBER + voice[i]->number,
|
||||
sound[i]->tone & 0xff);
|
||||
}
|
||||
|
||||
/* set parameters which can be set while loading */
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i]->reg_misc = OPL4_LFO_RESET_BIT;
|
||||
snd_opl4_update_pan(opl4, voice[i]);
|
||||
snd_opl4_update_pitch(opl4, voice[i]);
|
||||
voice[i]->level_direct = OPL4_LEVEL_DIRECT_BIT;
|
||||
snd_opl4_update_volume(opl4, voice[i]);
|
||||
/* set parameters which can be set while loading */
|
||||
for (i = 0; i < voices; i++) {
|
||||
voice[i]->reg_misc = OPL4_LFO_RESET_BIT;
|
||||
snd_opl4_update_pan(opl4, voice[i]);
|
||||
snd_opl4_update_pitch(opl4, voice[i]);
|
||||
voice[i]->level_direct = OPL4_LEVEL_DIRECT_BIT;
|
||||
snd_opl4_update_volume(opl4, voice[i]);
|
||||
}
|
||||
}
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
|
||||
/* wait for completion of loading */
|
||||
snd_opl4_wait_for_wave_headers(opl4);
|
||||
|
||||
/* set remaining parameters */
|
||||
spin_lock_irqsave(&opl4->reg_lock, flags);
|
||||
guard(spinlock_irqsave)(&opl4->reg_lock);
|
||||
for (i = 0; i < voices; i++) {
|
||||
snd_opl4_update_tone_parameters(opl4, voice[i]);
|
||||
voice[i]->reg_lfo_vibrato = voice[i]->sound->reg_lfo_vibrato;
|
||||
|
|
@ -549,7 +539,6 @@ void snd_opl4_note_on(void *private_data, int note, int vel, struct snd_midi_cha
|
|||
snd_opl4_write(opl4, OPL4_REG_MISC + voice[i]->number,
|
||||
voice[i]->reg_misc);
|
||||
}
|
||||
spin_unlock_irqrestore(&opl4->reg_lock, flags);
|
||||
}
|
||||
|
||||
static void snd_opl4_voice_off(struct snd_opl4 *opl4, struct opl4_voice *voice)
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user