ALSA: ens137x: 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/20250829144342.4290-7-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2025-08-29 16:42:41 +02:00
parent d701303bf4
commit d062d6977e
1 changed files with 138 additions and 165 deletions

View File

@ -799,13 +799,13 @@ static int snd_ensoniq_trigger(struct snd_pcm_substream *substream, int cmd)
} else if (s == ensoniq->capture_substream) } else if (s == ensoniq->capture_substream)
return -EINVAL; return -EINVAL;
} }
spin_lock(&ensoniq->reg_lock); scoped_guard(spinlock, &ensoniq->reg_lock) {
if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH) if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH)
ensoniq->sctrl |= what; ensoniq->sctrl |= what;
else else
ensoniq->sctrl &= ~what; ensoniq->sctrl &= ~what;
outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL)); outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
spin_unlock(&ensoniq->reg_lock); }
break; break;
} }
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
@ -825,13 +825,13 @@ static int snd_ensoniq_trigger(struct snd_pcm_substream *substream, int cmd)
snd_pcm_trigger_done(s, substream); snd_pcm_trigger_done(s, substream);
} }
} }
spin_lock(&ensoniq->reg_lock); scoped_guard(spinlock, &ensoniq->reg_lock) {
if (cmd == SNDRV_PCM_TRIGGER_START) if (cmd == SNDRV_PCM_TRIGGER_START)
ensoniq->ctrl |= what; ensoniq->ctrl |= what;
else else
ensoniq->ctrl &= ~what; ensoniq->ctrl &= ~what;
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock(&ensoniq->reg_lock); }
break; break;
} }
default: default:
@ -856,36 +856,36 @@ static int snd_ensoniq_playback1_prepare(struct snd_pcm_substream *substream)
mode |= 0x02; mode |= 0x02;
if (runtime->channels > 1) if (runtime->channels > 1)
mode |= 0x01; mode |= 0x01;
spin_lock_irq(&ensoniq->reg_lock); scoped_guard(spinlock_irq, &ensoniq->reg_lock) {
ensoniq->ctrl &= ~ES_DAC1_EN; ensoniq->ctrl &= ~ES_DAC1_EN;
#ifdef CHIP1371 #ifdef CHIP1371
/* 48k doesn't need SRC (it breaks AC3-passthru) */ /* 48k doesn't need SRC (it breaks AC3-passthru) */
if (runtime->rate == 48000) if (runtime->rate == 48000)
ensoniq->ctrl |= ES_1373_BYPASS_P1; ensoniq->ctrl |= ES_1373_BYPASS_P1;
else else
ensoniq->ctrl &= ~ES_1373_BYPASS_P1; ensoniq->ctrl &= ~ES_1373_BYPASS_P1;
#endif #endif
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
outl(runtime->dma_addr, ES_REG(ensoniq, DAC1_FRAME)); outl(runtime->dma_addr, ES_REG(ensoniq, DAC1_FRAME));
outl((ensoniq->p1_dma_size >> 2) - 1, ES_REG(ensoniq, DAC1_SIZE)); outl((ensoniq->p1_dma_size >> 2) - 1, ES_REG(ensoniq, DAC1_SIZE));
ensoniq->sctrl &= ~(ES_P1_LOOP_SEL | ES_P1_PAUSE | ES_P1_SCT_RLD | ES_P1_MODEM); ensoniq->sctrl &= ~(ES_P1_LOOP_SEL | ES_P1_PAUSE | ES_P1_SCT_RLD | ES_P1_MODEM);
ensoniq->sctrl |= ES_P1_INT_EN | ES_P1_MODEO(mode); ensoniq->sctrl |= ES_P1_INT_EN | ES_P1_MODEO(mode);
outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL)); outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
outl((ensoniq->p1_period_size >> snd_ensoniq_sample_shift[mode]) - 1, outl((ensoniq->p1_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
ES_REG(ensoniq, DAC1_COUNT)); ES_REG(ensoniq, DAC1_COUNT));
#ifdef CHIP1370 #ifdef CHIP1370
ensoniq->ctrl &= ~ES_1370_WTSRSELM; ensoniq->ctrl &= ~ES_1370_WTSRSELM;
switch (runtime->rate) { switch (runtime->rate) {
case 5512: ensoniq->ctrl |= ES_1370_WTSRSEL(0); break; case 5512: ensoniq->ctrl |= ES_1370_WTSRSEL(0); break;
case 11025: ensoniq->ctrl |= ES_1370_WTSRSEL(1); break; case 11025: ensoniq->ctrl |= ES_1370_WTSRSEL(1); break;
case 22050: ensoniq->ctrl |= ES_1370_WTSRSEL(2); break; case 22050: ensoniq->ctrl |= ES_1370_WTSRSEL(2); break;
case 44100: ensoniq->ctrl |= ES_1370_WTSRSEL(3); break; case 44100: ensoniq->ctrl |= ES_1370_WTSRSEL(3); break;
default: snd_BUG(); default: snd_BUG();
} }
#endif #endif
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock_irq(&ensoniq->reg_lock); }
#ifndef CHIP1370 #ifndef CHIP1370
snd_es1371_dac1_rate(ensoniq, runtime->rate); snd_es1371_dac1_rate(ensoniq, runtime->rate);
#endif #endif
@ -904,28 +904,28 @@ static int snd_ensoniq_playback2_prepare(struct snd_pcm_substream *substream)
mode |= 0x02; mode |= 0x02;
if (runtime->channels > 1) if (runtime->channels > 1)
mode |= 0x01; mode |= 0x01;
spin_lock_irq(&ensoniq->reg_lock); scoped_guard(spinlock_irq, &ensoniq->reg_lock) {
ensoniq->ctrl &= ~ES_DAC2_EN; ensoniq->ctrl &= ~ES_DAC2_EN;
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
outl(runtime->dma_addr, ES_REG(ensoniq, DAC2_FRAME)); outl(runtime->dma_addr, ES_REG(ensoniq, DAC2_FRAME));
outl((ensoniq->p2_dma_size >> 2) - 1, ES_REG(ensoniq, DAC2_SIZE)); outl((ensoniq->p2_dma_size >> 2) - 1, ES_REG(ensoniq, DAC2_SIZE));
ensoniq->sctrl &= ~(ES_P2_LOOP_SEL | ES_P2_PAUSE | ES_P2_DAC_SEN | ensoniq->sctrl &= ~(ES_P2_LOOP_SEL | ES_P2_PAUSE | ES_P2_DAC_SEN |
ES_P2_END_INCM | ES_P2_ST_INCM | ES_P2_MODEM); ES_P2_END_INCM | ES_P2_ST_INCM | ES_P2_MODEM);
ensoniq->sctrl |= ES_P2_INT_EN | ES_P2_MODEO(mode) | ensoniq->sctrl |= ES_P2_INT_EN | ES_P2_MODEO(mode) |
ES_P2_END_INCO(mode & 2 ? 2 : 1) | ES_P2_ST_INCO(0); ES_P2_END_INCO(mode & 2 ? 2 : 1) | ES_P2_ST_INCO(0);
outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL)); outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
outl((ensoniq->p2_period_size >> snd_ensoniq_sample_shift[mode]) - 1, outl((ensoniq->p2_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
ES_REG(ensoniq, DAC2_COUNT)); ES_REG(ensoniq, DAC2_COUNT));
#ifdef CHIP1370 #ifdef CHIP1370
if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_CAPTURE)) { if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_CAPTURE)) {
ensoniq->ctrl &= ~ES_1370_PCLKDIVM; ensoniq->ctrl &= ~ES_1370_PCLKDIVM;
ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate)); ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate));
ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_PLAY2; ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_PLAY2;
} }
#endif #endif
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock_irq(&ensoniq->reg_lock); }
#ifndef CHIP1370 #ifndef CHIP1370
snd_es1371_dac2_rate(ensoniq, runtime->rate); snd_es1371_dac2_rate(ensoniq, runtime->rate);
#endif #endif
@ -944,26 +944,26 @@ static int snd_ensoniq_capture_prepare(struct snd_pcm_substream *substream)
mode |= 0x02; mode |= 0x02;
if (runtime->channels > 1) if (runtime->channels > 1)
mode |= 0x01; mode |= 0x01;
spin_lock_irq(&ensoniq->reg_lock); scoped_guard(spinlock_irq, &ensoniq->reg_lock) {
ensoniq->ctrl &= ~ES_ADC_EN; ensoniq->ctrl &= ~ES_ADC_EN;
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
outl(runtime->dma_addr, ES_REG(ensoniq, ADC_FRAME)); outl(runtime->dma_addr, ES_REG(ensoniq, ADC_FRAME));
outl((ensoniq->c_dma_size >> 2) - 1, ES_REG(ensoniq, ADC_SIZE)); outl((ensoniq->c_dma_size >> 2) - 1, ES_REG(ensoniq, ADC_SIZE));
ensoniq->sctrl &= ~(ES_R1_LOOP_SEL | ES_R1_MODEM); ensoniq->sctrl &= ~(ES_R1_LOOP_SEL | ES_R1_MODEM);
ensoniq->sctrl |= ES_R1_INT_EN | ES_R1_MODEO(mode); ensoniq->sctrl |= ES_R1_INT_EN | ES_R1_MODEO(mode);
outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL)); outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
outl((ensoniq->c_period_size >> snd_ensoniq_sample_shift[mode]) - 1, outl((ensoniq->c_period_size >> snd_ensoniq_sample_shift[mode]) - 1,
ES_REG(ensoniq, ADC_COUNT)); ES_REG(ensoniq, ADC_COUNT));
#ifdef CHIP1370 #ifdef CHIP1370
if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_PLAY2)) { if (!(ensoniq->u.es1370.pclkdiv_lock & ES_MODE_PLAY2)) {
ensoniq->ctrl &= ~ES_1370_PCLKDIVM; ensoniq->ctrl &= ~ES_1370_PCLKDIVM;
ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate)); ensoniq->ctrl |= ES_1370_PCLKDIVO(ES_1370_SRTODIV(runtime->rate));
ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_CAPTURE; ensoniq->u.es1370.pclkdiv_lock |= ES_MODE_CAPTURE;
} }
#endif #endif
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock_irq(&ensoniq->reg_lock); }
#ifndef CHIP1370 #ifndef CHIP1370
snd_es1371_adc_rate(ensoniq, runtime->rate); snd_es1371_adc_rate(ensoniq, runtime->rate);
#endif #endif
@ -975,16 +975,14 @@ static snd_pcm_uframes_t snd_ensoniq_playback1_pointer(struct snd_pcm_substream
struct ensoniq *ensoniq = snd_pcm_substream_chip(substream); struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
size_t ptr; size_t ptr;
spin_lock(&ensoniq->reg_lock); guard(spinlock)(&ensoniq->reg_lock);
if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC1_EN) { if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC1_EN) {
outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC1_SIZE))); ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC1_SIZE)));
ptr = bytes_to_frames(substream->runtime, ptr); return bytes_to_frames(substream->runtime, ptr);
} else { } else {
ptr = 0; return 0;
} }
spin_unlock(&ensoniq->reg_lock);
return ptr;
} }
static snd_pcm_uframes_t snd_ensoniq_playback2_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t snd_ensoniq_playback2_pointer(struct snd_pcm_substream *substream)
@ -992,16 +990,14 @@ static snd_pcm_uframes_t snd_ensoniq_playback2_pointer(struct snd_pcm_substream
struct ensoniq *ensoniq = snd_pcm_substream_chip(substream); struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
size_t ptr; size_t ptr;
spin_lock(&ensoniq->reg_lock); guard(spinlock)(&ensoniq->reg_lock);
if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC2_EN) { if (inl(ES_REG(ensoniq, CONTROL)) & ES_DAC2_EN) {
outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_DAC), ES_REG(ensoniq, MEM_PAGE));
ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC2_SIZE))); ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, DAC2_SIZE)));
ptr = bytes_to_frames(substream->runtime, ptr); return bytes_to_frames(substream->runtime, ptr);
} else { } else {
ptr = 0; return 0;
} }
spin_unlock(&ensoniq->reg_lock);
return ptr;
} }
static snd_pcm_uframes_t snd_ensoniq_capture_pointer(struct snd_pcm_substream *substream) static snd_pcm_uframes_t snd_ensoniq_capture_pointer(struct snd_pcm_substream *substream)
@ -1009,16 +1005,14 @@ static snd_pcm_uframes_t snd_ensoniq_capture_pointer(struct snd_pcm_substream *s
struct ensoniq *ensoniq = snd_pcm_substream_chip(substream); struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
size_t ptr; size_t ptr;
spin_lock(&ensoniq->reg_lock); guard(spinlock)(&ensoniq->reg_lock);
if (inl(ES_REG(ensoniq, CONTROL)) & ES_ADC_EN) { if (inl(ES_REG(ensoniq, CONTROL)) & ES_ADC_EN) {
outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE)); outl(ES_MEM_PAGEO(ES_PAGE_ADC), ES_REG(ensoniq, MEM_PAGE));
ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, ADC_SIZE))); ptr = ES_REG_FCURR_COUNTI(inl(ES_REG(ensoniq, ADC_SIZE)));
ptr = bytes_to_frames(substream->runtime, ptr); return bytes_to_frames(substream->runtime, ptr);
} else { } else {
ptr = 0; return 0;
} }
spin_unlock(&ensoniq->reg_lock);
return ptr;
} }
static const struct snd_pcm_hardware snd_ensoniq_playback1 = static const struct snd_pcm_hardware snd_ensoniq_playback1 =
@ -1096,10 +1090,10 @@ static int snd_ensoniq_playback1_open(struct snd_pcm_substream *substream)
ensoniq->playback1_substream = substream; ensoniq->playback1_substream = substream;
runtime->hw = snd_ensoniq_playback1; runtime->hw = snd_ensoniq_playback1;
snd_pcm_set_sync(substream); snd_pcm_set_sync(substream);
spin_lock_irq(&ensoniq->reg_lock); scoped_guard(spinlock_irq, &ensoniq->reg_lock) {
if (ensoniq->spdif && ensoniq->playback2_substream == NULL) if (ensoniq->spdif && ensoniq->playback2_substream == NULL)
ensoniq->spdif_stream = ensoniq->spdif_default; ensoniq->spdif_stream = ensoniq->spdif_default;
spin_unlock_irq(&ensoniq->reg_lock); }
#ifdef CHIP1370 #ifdef CHIP1370
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&snd_es1370_hw_constraints_rates); &snd_es1370_hw_constraints_rates);
@ -1119,10 +1113,10 @@ static int snd_ensoniq_playback2_open(struct snd_pcm_substream *substream)
ensoniq->playback2_substream = substream; ensoniq->playback2_substream = substream;
runtime->hw = snd_ensoniq_playback2; runtime->hw = snd_ensoniq_playback2;
snd_pcm_set_sync(substream); snd_pcm_set_sync(substream);
spin_lock_irq(&ensoniq->reg_lock); scoped_guard(spinlock_irq, &ensoniq->reg_lock) {
if (ensoniq->spdif && ensoniq->playback1_substream == NULL) if (ensoniq->spdif && ensoniq->playback1_substream == NULL)
ensoniq->spdif_stream = ensoniq->spdif_default; ensoniq->spdif_stream = ensoniq->spdif_default;
spin_unlock_irq(&ensoniq->reg_lock); }
#ifdef CHIP1370 #ifdef CHIP1370
snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, snd_pcm_hw_constraint_ratnums(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
&snd_es1370_hw_constraints_clock); &snd_es1370_hw_constraints_clock);
@ -1166,12 +1160,11 @@ static int snd_ensoniq_playback2_close(struct snd_pcm_substream *substream)
struct ensoniq *ensoniq = snd_pcm_substream_chip(substream); struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
ensoniq->playback2_substream = NULL; ensoniq->playback2_substream = NULL;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
#ifdef CHIP1370 #ifdef CHIP1370
ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_PLAY2; ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_PLAY2;
#endif #endif
ensoniq->mode &= ~ES_MODE_PLAY2; ensoniq->mode &= ~ES_MODE_PLAY2;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1180,12 +1173,11 @@ static int snd_ensoniq_capture_close(struct snd_pcm_substream *substream)
struct ensoniq *ensoniq = snd_pcm_substream_chip(substream); struct ensoniq *ensoniq = snd_pcm_substream_chip(substream);
ensoniq->capture_substream = NULL; ensoniq->capture_substream = NULL;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
#ifdef CHIP1370 #ifdef CHIP1370
ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_CAPTURE; ensoniq->u.es1370.pclkdiv_lock &= ~ES_MODE_CAPTURE;
#endif #endif
ensoniq->mode &= ~ES_MODE_CAPTURE; ensoniq->mode &= ~ES_MODE_CAPTURE;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1307,12 +1299,12 @@ static int snd_ens1373_spdif_default_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&ensoniq->reg_lock);
guard(spinlock_irq)(&ensoniq->reg_lock);
ucontrol->value.iec958.status[0] = (ensoniq->spdif_default >> 0) & 0xff; ucontrol->value.iec958.status[0] = (ensoniq->spdif_default >> 0) & 0xff;
ucontrol->value.iec958.status[1] = (ensoniq->spdif_default >> 8) & 0xff; ucontrol->value.iec958.status[1] = (ensoniq->spdif_default >> 8) & 0xff;
ucontrol->value.iec958.status[2] = (ensoniq->spdif_default >> 16) & 0xff; ucontrol->value.iec958.status[2] = (ensoniq->spdif_default >> 16) & 0xff;
ucontrol->value.iec958.status[3] = (ensoniq->spdif_default >> 24) & 0xff; ucontrol->value.iec958.status[3] = (ensoniq->spdif_default >> 24) & 0xff;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1327,13 +1319,12 @@ static int snd_ens1373_spdif_default_put(struct snd_kcontrol *kcontrol,
((u32)ucontrol->value.iec958.status[1] << 8) | ((u32)ucontrol->value.iec958.status[1] << 8) |
((u32)ucontrol->value.iec958.status[2] << 16) | ((u32)ucontrol->value.iec958.status[2] << 16) |
((u32)ucontrol->value.iec958.status[3] << 24); ((u32)ucontrol->value.iec958.status[3] << 24);
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
change = ensoniq->spdif_default != val; change = ensoniq->spdif_default != val;
ensoniq->spdif_default = val; ensoniq->spdif_default = val;
if (change && ensoniq->playback1_substream == NULL && if (change && ensoniq->playback1_substream == NULL &&
ensoniq->playback2_substream == NULL) ensoniq->playback2_substream == NULL)
outl(val, ES_REG(ensoniq, CHANNEL_STATUS)); outl(val, ES_REG(ensoniq, CHANNEL_STATUS));
spin_unlock_irq(&ensoniq->reg_lock);
return change; return change;
} }
@ -1351,12 +1342,12 @@ static int snd_ens1373_spdif_stream_get(struct snd_kcontrol *kcontrol,
struct snd_ctl_elem_value *ucontrol) struct snd_ctl_elem_value *ucontrol)
{ {
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&ensoniq->reg_lock);
guard(spinlock_irq)(&ensoniq->reg_lock);
ucontrol->value.iec958.status[0] = (ensoniq->spdif_stream >> 0) & 0xff; ucontrol->value.iec958.status[0] = (ensoniq->spdif_stream >> 0) & 0xff;
ucontrol->value.iec958.status[1] = (ensoniq->spdif_stream >> 8) & 0xff; ucontrol->value.iec958.status[1] = (ensoniq->spdif_stream >> 8) & 0xff;
ucontrol->value.iec958.status[2] = (ensoniq->spdif_stream >> 16) & 0xff; ucontrol->value.iec958.status[2] = (ensoniq->spdif_stream >> 16) & 0xff;
ucontrol->value.iec958.status[3] = (ensoniq->spdif_stream >> 24) & 0xff; ucontrol->value.iec958.status[3] = (ensoniq->spdif_stream >> 24) & 0xff;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1371,13 +1362,12 @@ static int snd_ens1373_spdif_stream_put(struct snd_kcontrol *kcontrol,
((u32)ucontrol->value.iec958.status[1] << 8) | ((u32)ucontrol->value.iec958.status[1] << 8) |
((u32)ucontrol->value.iec958.status[2] << 16) | ((u32)ucontrol->value.iec958.status[2] << 16) |
((u32)ucontrol->value.iec958.status[3] << 24); ((u32)ucontrol->value.iec958.status[3] << 24);
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
change = ensoniq->spdif_stream != val; change = ensoniq->spdif_stream != val;
ensoniq->spdif_stream = val; ensoniq->spdif_stream = val;
if (change && (ensoniq->playback1_substream != NULL || if (change && (ensoniq->playback1_substream != NULL ||
ensoniq->playback2_substream != NULL)) ensoniq->playback2_substream != NULL))
outl(val, ES_REG(ensoniq, CHANNEL_STATUS)); outl(val, ES_REG(ensoniq, CHANNEL_STATUS));
spin_unlock_irq(&ensoniq->reg_lock);
return change; return change;
} }
@ -1392,9 +1382,8 @@ static int snd_es1371_spdif_get(struct snd_kcontrol *kcontrol,
{ {
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
ucontrol->value.integer.value[0] = ensoniq->ctrl & ES_1373_SPDIF_THRU ? 1 : 0; ucontrol->value.integer.value[0] = ensoniq->ctrl & ES_1373_SPDIF_THRU ? 1 : 0;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1407,7 +1396,7 @@ static int snd_es1371_spdif_put(struct snd_kcontrol *kcontrol,
nval1 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_THRU : 0; nval1 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_THRU : 0;
nval2 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_EN : 0; nval2 = ucontrol->value.integer.value[0] ? ES_1373_SPDIF_EN : 0;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
change = (ensoniq->ctrl & ES_1373_SPDIF_THRU) != nval1; change = (ensoniq->ctrl & ES_1373_SPDIF_THRU) != nval1;
ensoniq->ctrl &= ~ES_1373_SPDIF_THRU; ensoniq->ctrl &= ~ES_1373_SPDIF_THRU;
ensoniq->ctrl |= nval1; ensoniq->ctrl |= nval1;
@ -1415,7 +1404,6 @@ static int snd_es1371_spdif_put(struct snd_kcontrol *kcontrol,
ensoniq->cssr |= nval2; ensoniq->cssr |= nval2;
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
outl(ensoniq->cssr, ES_REG(ensoniq, STATUS)); outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
spin_unlock_irq(&ensoniq->reg_lock);
return change; return change;
} }
@ -1455,12 +1443,11 @@ static int snd_es1373_rear_get(struct snd_kcontrol *kcontrol,
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
int val = 0; int val = 0;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
if ((ensoniq->cssr & (ES_1373_REAR_BIT27|ES_1373_REAR_BIT26| if ((ensoniq->cssr & (ES_1373_REAR_BIT27|ES_1373_REAR_BIT26|
ES_1373_REAR_BIT24)) == ES_1373_REAR_BIT26) ES_1373_REAR_BIT24)) == ES_1373_REAR_BIT26)
val = 1; val = 1;
ucontrol->value.integer.value[0] = val; ucontrol->value.integer.value[0] = val;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1473,13 +1460,12 @@ static int snd_es1373_rear_put(struct snd_kcontrol *kcontrol,
nval1 = ucontrol->value.integer.value[0] ? nval1 = ucontrol->value.integer.value[0] ?
ES_1373_REAR_BIT26 : (ES_1373_REAR_BIT27|ES_1373_REAR_BIT24); ES_1373_REAR_BIT26 : (ES_1373_REAR_BIT27|ES_1373_REAR_BIT24);
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
change = (ensoniq->cssr & (ES_1373_REAR_BIT27| change = (ensoniq->cssr & (ES_1373_REAR_BIT27|
ES_1373_REAR_BIT26|ES_1373_REAR_BIT24)) != nval1; ES_1373_REAR_BIT26|ES_1373_REAR_BIT24)) != nval1;
ensoniq->cssr &= ~(ES_1373_REAR_BIT27|ES_1373_REAR_BIT26|ES_1373_REAR_BIT24); ensoniq->cssr &= ~(ES_1373_REAR_BIT27|ES_1373_REAR_BIT26|ES_1373_REAR_BIT24);
ensoniq->cssr |= nval1; ensoniq->cssr |= nval1;
outl(ensoniq->cssr, ES_REG(ensoniq, STATUS)); outl(ensoniq->cssr, ES_REG(ensoniq, STATUS));
spin_unlock_irq(&ensoniq->reg_lock);
return change; return change;
} }
@ -1500,11 +1486,10 @@ static int snd_es1373_line_get(struct snd_kcontrol *kcontrol,
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
int val = 0; int val = 0;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
if (ensoniq->ctrl & ES_1371_GPIO_OUT(4)) if (ensoniq->ctrl & ES_1371_GPIO_OUT(4))
val = 1; val = 1;
ucontrol->value.integer.value[0] = val; ucontrol->value.integer.value[0] = val;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1515,7 +1500,7 @@ static int snd_es1373_line_put(struct snd_kcontrol *kcontrol,
int changed; int changed;
unsigned int ctrl; unsigned int ctrl;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
ctrl = ensoniq->ctrl; ctrl = ensoniq->ctrl;
if (ucontrol->value.integer.value[0]) if (ucontrol->value.integer.value[0])
ensoniq->ctrl |= ES_1371_GPIO_OUT(4); /* switch line-in -> rear out */ ensoniq->ctrl |= ES_1371_GPIO_OUT(4); /* switch line-in -> rear out */
@ -1524,7 +1509,6 @@ static int snd_es1373_line_put(struct snd_kcontrol *kcontrol,
changed = (ctrl != ensoniq->ctrl); changed = (ctrl != ensoniq->ctrl);
if (changed) if (changed)
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock_irq(&ensoniq->reg_lock);
return changed; return changed;
} }
@ -1660,9 +1644,8 @@ static int snd_ensoniq_control_get(struct snd_kcontrol *kcontrol,
struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol); struct ensoniq *ensoniq = snd_kcontrol_chip(kcontrol);
int mask = kcontrol->private_value; int mask = kcontrol->private_value;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
ucontrol->value.integer.value[0] = ensoniq->ctrl & mask ? 1 : 0; ucontrol->value.integer.value[0] = ensoniq->ctrl & mask ? 1 : 0;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -1675,12 +1658,11 @@ static int snd_ensoniq_control_put(struct snd_kcontrol *kcontrol,
int change; int change;
nval = ucontrol->value.integer.value[0] ? mask : 0; nval = ucontrol->value.integer.value[0] ? mask : 0;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
change = (ensoniq->ctrl & mask) != nval; change = (ensoniq->ctrl & mask) != nval;
ensoniq->ctrl &= ~mask; ensoniq->ctrl &= ~mask;
ensoniq->ctrl |= nval; ensoniq->ctrl |= nval;
outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl, ES_REG(ensoniq, CONTROL));
spin_unlock_irq(&ensoniq->reg_lock);
return change; return change;
} }
@ -2074,19 +2056,19 @@ static void snd_ensoniq_midi_interrupt(struct ensoniq * ensoniq)
if (rmidi == NULL) if (rmidi == NULL)
return; return;
/* do Rx at first */ /* do Rx at first */
spin_lock(&ensoniq->reg_lock); scoped_guard(spinlock, &ensoniq->reg_lock) {
mask = ensoniq->uartm & ES_MODE_INPUT ? ES_RXRDY : 0; mask = ensoniq->uartm & ES_MODE_INPUT ? ES_RXRDY : 0;
while (mask) { while (mask) {
status = inb(ES_REG(ensoniq, UART_STATUS)); status = inb(ES_REG(ensoniq, UART_STATUS));
if ((status & mask) == 0) if ((status & mask) == 0)
break; break;
byte = inb(ES_REG(ensoniq, UART_DATA)); byte = inb(ES_REG(ensoniq, UART_DATA));
snd_rawmidi_receive(ensoniq->midi_input, &byte, 1); snd_rawmidi_receive(ensoniq->midi_input, &byte, 1);
}
} }
spin_unlock(&ensoniq->reg_lock);
/* do Tx at second */ /* do Tx at second */
spin_lock(&ensoniq->reg_lock); guard(spinlock)(&ensoniq->reg_lock);
mask = ensoniq->uartm & ES_MODE_OUTPUT ? ES_TXRDY : 0; mask = ensoniq->uartm & ES_MODE_OUTPUT ? ES_TXRDY : 0;
while (mask) { while (mask) {
status = inb(ES_REG(ensoniq, UART_STATUS)); status = inb(ES_REG(ensoniq, UART_STATUS));
@ -2100,14 +2082,13 @@ static void snd_ensoniq_midi_interrupt(struct ensoniq * ensoniq)
outb(byte, ES_REG(ensoniq, UART_DATA)); outb(byte, ES_REG(ensoniq, UART_DATA));
} }
} }
spin_unlock(&ensoniq->reg_lock);
} }
static int snd_ensoniq_midi_input_open(struct snd_rawmidi_substream *substream) static int snd_ensoniq_midi_input_open(struct snd_rawmidi_substream *substream)
{ {
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
ensoniq->uartm |= ES_MODE_INPUT; ensoniq->uartm |= ES_MODE_INPUT;
ensoniq->midi_input = substream; ensoniq->midi_input = substream;
if (!(ensoniq->uartm & ES_MODE_OUTPUT)) { if (!(ensoniq->uartm & ES_MODE_OUTPUT)) {
@ -2115,7 +2096,6 @@ static int snd_ensoniq_midi_input_open(struct snd_rawmidi_substream *substream)
outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL));
} }
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -2123,7 +2103,7 @@ static int snd_ensoniq_midi_input_close(struct snd_rawmidi_substream *substream)
{ {
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
if (!(ensoniq->uartm & ES_MODE_OUTPUT)) { if (!(ensoniq->uartm & ES_MODE_OUTPUT)) {
outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL));
@ -2132,7 +2112,6 @@ static int snd_ensoniq_midi_input_close(struct snd_rawmidi_substream *substream)
} }
ensoniq->midi_input = NULL; ensoniq->midi_input = NULL;
ensoniq->uartm &= ~ES_MODE_INPUT; ensoniq->uartm &= ~ES_MODE_INPUT;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -2140,7 +2119,7 @@ static int snd_ensoniq_midi_output_open(struct snd_rawmidi_substream *substream)
{ {
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
ensoniq->uartm |= ES_MODE_OUTPUT; ensoniq->uartm |= ES_MODE_OUTPUT;
ensoniq->midi_output = substream; ensoniq->midi_output = substream;
if (!(ensoniq->uartm & ES_MODE_INPUT)) { if (!(ensoniq->uartm & ES_MODE_INPUT)) {
@ -2148,7 +2127,6 @@ static int snd_ensoniq_midi_output_open(struct snd_rawmidi_substream *substream)
outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl |= ES_UART_EN, ES_REG(ensoniq, CONTROL));
} }
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
@ -2156,7 +2134,7 @@ static int snd_ensoniq_midi_output_close(struct snd_rawmidi_substream *substream
{ {
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
spin_lock_irq(&ensoniq->reg_lock); guard(spinlock_irq)(&ensoniq->reg_lock);
if (!(ensoniq->uartm & ES_MODE_INPUT)) { if (!(ensoniq->uartm & ES_MODE_INPUT)) {
outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc = 0, ES_REG(ensoniq, UART_CONTROL));
outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL)); outl(ensoniq->ctrl &= ~ES_UART_EN, ES_REG(ensoniq, CONTROL));
@ -2165,17 +2143,15 @@ static int snd_ensoniq_midi_output_close(struct snd_rawmidi_substream *substream
} }
ensoniq->midi_output = NULL; ensoniq->midi_output = NULL;
ensoniq->uartm &= ~ES_MODE_OUTPUT; ensoniq->uartm &= ~ES_MODE_OUTPUT;
spin_unlock_irq(&ensoniq->reg_lock);
return 0; return 0;
} }
static void snd_ensoniq_midi_input_trigger(struct snd_rawmidi_substream *substream, int up) static void snd_ensoniq_midi_input_trigger(struct snd_rawmidi_substream *substream, int up)
{ {
unsigned long flags;
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
int idx; int idx;
spin_lock_irqsave(&ensoniq->reg_lock, flags); guard(spinlock_irqsave)(&ensoniq->reg_lock);
if (up) { if (up) {
if ((ensoniq->uartc & ES_RXINTEN) == 0) { if ((ensoniq->uartc & ES_RXINTEN) == 0) {
/* empty input FIFO */ /* empty input FIFO */
@ -2190,16 +2166,14 @@ static void snd_ensoniq_midi_input_trigger(struct snd_rawmidi_substream *substre
outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
} }
} }
spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
} }
static void snd_ensoniq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up) static void snd_ensoniq_midi_output_trigger(struct snd_rawmidi_substream *substream, int up)
{ {
unsigned long flags;
struct ensoniq *ensoniq = substream->rmidi->private_data; struct ensoniq *ensoniq = substream->rmidi->private_data;
unsigned char byte; unsigned char byte;
spin_lock_irqsave(&ensoniq->reg_lock, flags); guard(spinlock_irqsave)(&ensoniq->reg_lock);
if (up) { if (up) {
if (ES_TXINTENI(ensoniq->uartc) == 0) { if (ES_TXINTENI(ensoniq->uartc) == 0) {
ensoniq->uartc |= ES_TXINTENO(1); ensoniq->uartc |= ES_TXINTENO(1);
@ -2220,7 +2194,6 @@ static void snd_ensoniq_midi_output_trigger(struct snd_rawmidi_substream *substr
outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL)); outb(ensoniq->uartc, ES_REG(ensoniq, UART_CONTROL));
} }
} }
spin_unlock_irqrestore(&ensoniq->reg_lock, flags);
} }
static const struct snd_rawmidi_ops snd_ensoniq_midi_output = static const struct snd_rawmidi_ops snd_ensoniq_midi_output =
@ -2271,17 +2244,17 @@ static irqreturn_t snd_audiopci_interrupt(int irq, void *dev_id)
if (!(status & ES_INTR)) if (!(status & ES_INTR))
return IRQ_NONE; return IRQ_NONE;
spin_lock(&ensoniq->reg_lock); scoped_guard(spinlock, &ensoniq->reg_lock) {
sctrl = ensoniq->sctrl; sctrl = ensoniq->sctrl;
if (status & ES_DAC1) if (status & ES_DAC1)
sctrl &= ~ES_P1_INT_EN; sctrl &= ~ES_P1_INT_EN;
if (status & ES_DAC2) if (status & ES_DAC2)
sctrl &= ~ES_P2_INT_EN; sctrl &= ~ES_P2_INT_EN;
if (status & ES_ADC) if (status & ES_ADC)
sctrl &= ~ES_R1_INT_EN; sctrl &= ~ES_R1_INT_EN;
outl(sctrl, ES_REG(ensoniq, SERIAL)); outl(sctrl, ES_REG(ensoniq, SERIAL));
outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL)); outl(ensoniq->sctrl, ES_REG(ensoniq, SERIAL));
spin_unlock(&ensoniq->reg_lock); }
if (status & ES_UART) if (status & ES_UART)
snd_ensoniq_midi_interrupt(ensoniq); snd_ensoniq_midi_interrupt(ensoniq);