ALSA: emu10k1: Use guard() for emu1010 FPGA locking
The snd_emu1010_fpga_lock() and _unlock() call pairs can be simplified gracefully with the introduction of guard(). Only code refactoring, and no functional changes. Signed-off-by: Takashi Iwai <tiwai@suse.de> Link: https://patch.msgid.link/20250829144342.4290-28-tiwai@suse.de
This commit is contained in:
parent
f44f745f75
commit
7c4a379e06
|
@ -1842,8 +1842,7 @@ unsigned int snd_emu10k1_ptr20_read(struct snd_emu10k1 * emu, unsigned int reg,
|
|||
void snd_emu10k1_ptr20_write(struct snd_emu10k1 *emu, unsigned int reg, unsigned int chn, unsigned int data);
|
||||
int snd_emu10k1_spi_write(struct snd_emu10k1 * emu, unsigned int data);
|
||||
int snd_emu10k1_i2c_write(struct snd_emu10k1 *emu, u32 reg, u32 value);
|
||||
static inline void snd_emu1010_fpga_lock(struct snd_emu10k1 *emu) { mutex_lock(&emu->emu1010.lock); };
|
||||
static inline void snd_emu1010_fpga_unlock(struct snd_emu10k1 *emu) { mutex_unlock(&emu->emu1010.lock); };
|
||||
DEFINE_GUARD(snd_emu1010_fpga_lock, struct snd_emu10k1 *, mutex_lock(&(_T)->emu1010.lock), mutex_unlock(&(_T)->emu1010.lock))
|
||||
void snd_emu1010_fpga_write_lock(struct snd_emu10k1 *emu, u32 reg, u32 value);
|
||||
void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value);
|
||||
void snd_emu1010_fpga_read(struct snd_emu10k1 *emu, u32 reg, u32 *value);
|
||||
|
|
|
@ -768,7 +768,7 @@ static void emu1010_work(struct work_struct *work)
|
|||
return;
|
||||
#endif
|
||||
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
|
||||
snd_emu1010_fpga_read(emu, EMU_HANA_IRQ_STATUS, &sts);
|
||||
|
||||
|
@ -779,8 +779,6 @@ static void emu1010_work(struct work_struct *work)
|
|||
|
||||
if (sts & EMU_HANA_IRQ_WCLK_CHANGED)
|
||||
emu1010_clock_event(emu);
|
||||
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
}
|
||||
|
||||
static void emu1010_interrupt(struct snd_emu10k1 *emu)
|
||||
|
@ -814,13 +812,13 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
|
|||
* Proper init follows in snd_emu10k1_init(). */
|
||||
outl(HCFG_LOCKSOUNDCACHE | HCFG_LOCKTANKCACHE_MASK, emu->port + HCFG);
|
||||
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
|
||||
dev_info(emu->card->dev, "emu1010: Loading Hana Firmware\n");
|
||||
err = snd_emu1010_load_firmware(emu, 0, &emu->firmware);
|
||||
if (err < 0) {
|
||||
dev_info(emu->card->dev, "emu1010: Loading Firmware failed\n");
|
||||
goto fail;
|
||||
return err;
|
||||
}
|
||||
|
||||
/* ID, should read & 0x7f = 0x55 when FPGA programmed. */
|
||||
|
@ -830,8 +828,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
|
|||
dev_info(emu->card->dev,
|
||||
"emu1010: Loading Hana Firmware file failed, reg = 0x%x\n",
|
||||
reg);
|
||||
err = -ENODEV;
|
||||
goto fail;
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
dev_info(emu->card->dev, "emu1010: Hana Firmware loaded\n");
|
||||
|
@ -891,9 +888,7 @@ static int snd_emu10k1_emu1010_init(struct snd_emu10k1 *emu)
|
|||
// so it is safe to simply enable the outputs.
|
||||
snd_emu1010_fpga_write(emu, EMU_HANA_UNMUTE, EMU_UNMUTE);
|
||||
|
||||
fail:
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
return err;
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
* Create the EMU10K1 instance
|
||||
|
|
|
@ -662,9 +662,8 @@ static int snd_emu1010_output_source_put(struct snd_kcontrol *kcontrol,
|
|||
change = (emu->emu1010.output_source[channel] != val);
|
||||
if (change) {
|
||||
emu->emu1010.output_source[channel] = val;
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
snd_emu1010_output_source_apply(emu, channel, val);
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
}
|
||||
return change;
|
||||
}
|
||||
|
@ -708,9 +707,8 @@ static int snd_emu1010_input_source_put(struct snd_kcontrol *kcontrol,
|
|||
change = (emu->emu1010.input_source[channel] != val);
|
||||
if (change) {
|
||||
emu->emu1010.input_source[channel] = val;
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
snd_emu1010_input_source_apply(emu, channel, val);
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
}
|
||||
return change;
|
||||
}
|
||||
|
@ -985,7 +983,7 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol,
|
|||
val = ucontrol->value.enumerated.item[0] ;
|
||||
if (val >= emu_ci->num)
|
||||
return -EINVAL;
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
spin_lock_irq(&emu->reg_lock);
|
||||
change = (emu->emu1010.clock_source != val);
|
||||
if (change) {
|
||||
|
@ -1002,7 +1000,6 @@ static int snd_emu1010_clock_source_put(struct snd_kcontrol *kcontrol,
|
|||
} else {
|
||||
spin_unlock_irq(&emu->reg_lock);
|
||||
}
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
return change;
|
||||
}
|
||||
|
||||
|
@ -2330,9 +2327,9 @@ int snd_emu10k1_mixer(struct snd_emu10k1 *emu,
|
|||
for (i = 0; i < emu_ri->n_outs; i++)
|
||||
emu->emu1010.output_source[i] =
|
||||
emu1010_map_source(emu_ri, emu_ri->out_dflts[i]);
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
snd_emu1010_apply_sources(emu);
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
scoped_guard(snd_emu1010_fpga_lock, emu) {
|
||||
snd_emu1010_apply_sources(emu);
|
||||
}
|
||||
|
||||
kctl = emu->ctl_clock_source = snd_ctl_new1(&snd_emu1010_clock_source, emu);
|
||||
err = snd_ctl_add(card, kctl);
|
||||
|
|
|
@ -166,7 +166,7 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
|
|||
u32 value2;
|
||||
|
||||
if (emu->card_capabilities->emu_model) {
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
|
||||
// This represents the S/PDIF lock status on 0404b, which is
|
||||
// kinda weird and unhelpful, because monitoring it via IRQ is
|
||||
|
@ -200,8 +200,6 @@ static void snd_emu10k1_proc_spdif_read(struct snd_info_entry *entry,
|
|||
snd_iprintf(buffer, "\nS/PDIF mode: %s%s\n",
|
||||
value & EMU_HANA_SPDIF_MODE_RX_PRO ? "professional" : "consumer",
|
||||
value & EMU_HANA_SPDIF_MODE_RX_NOCOPY ? ", no copy" : "");
|
||||
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
} else {
|
||||
snd_emu10k1_proc_spdif_status(emu, buffer, "CD-ROM S/PDIF In", CDCS, CDSRCS);
|
||||
snd_emu10k1_proc_spdif_status(emu, buffer, "Optical or Coax S/PDIF In", GPSCS, GPSRCS);
|
||||
|
@ -464,7 +462,7 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
|
|||
u32 value;
|
||||
int i;
|
||||
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
|
||||
snd_iprintf(buffer, "EMU1010 Registers:\n\n");
|
||||
|
||||
|
@ -504,8 +502,6 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
|
|||
snd_emu_proc_emu1010_link_read(emu, buffer, 0x701);
|
||||
}
|
||||
}
|
||||
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
}
|
||||
|
||||
static void snd_emu_proc_io_reg_read(struct snd_info_entry *entry,
|
||||
|
|
|
@ -297,9 +297,8 @@ void snd_emu1010_fpga_write(struct snd_emu10k1 *emu, u32 reg, u32 value)
|
|||
|
||||
void snd_emu1010_fpga_write_lock(struct snd_emu10k1 *emu, u32 reg, u32 value)
|
||||
{
|
||||
snd_emu1010_fpga_lock(emu);
|
||||
guard(snd_emu1010_fpga_lock)(emu);
|
||||
snd_emu1010_fpga_write_locked(emu, reg, value);
|
||||
snd_emu1010_fpga_unlock(emu);
|
||||
}
|
||||
|
||||
void snd_emu1010_fpga_read(struct snd_emu10k1 *emu, u32 reg, u32 *value)
|
||||
|
|
Loading…
Reference in New Issue