1
0
mirror of https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git synced 2026-01-11 17:10:13 +00:00

ALSA: ymfpci: 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-62-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2025-08-29 16:43:36 +02:00
parent dde5decc43
commit 8c0cb47e26

View File

@ -159,26 +159,21 @@ static u32 snd_ymfpci_calc_lpfQ(u32 rate)
static void snd_ymfpci_hw_start(struct snd_ymfpci *chip) static void snd_ymfpci_hw_start(struct snd_ymfpci *chip)
{ {
unsigned long flags; guard(spinlock_irqsave)(&chip->reg_lock);
spin_lock_irqsave(&chip->reg_lock, flags);
if (chip->start_count++ > 0) if (chip->start_count++ > 0)
goto __end; return;
snd_ymfpci_writel(chip, YDSXGR_MODE, snd_ymfpci_writel(chip, YDSXGR_MODE,
snd_ymfpci_readl(chip, YDSXGR_MODE) | 3); snd_ymfpci_readl(chip, YDSXGR_MODE) | 3);
chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1; chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1;
__end:
spin_unlock_irqrestore(&chip->reg_lock, flags);
} }
static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip) static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
{ {
unsigned long flags;
long timeout = 1000; long timeout = 1000;
spin_lock_irqsave(&chip->reg_lock, flags); guard(spinlock_irqsave)(&chip->reg_lock);
if (--chip->start_count > 0) if (--chip->start_count > 0)
goto __end; return;
snd_ymfpci_writel(chip, YDSXGR_MODE, snd_ymfpci_writel(chip, YDSXGR_MODE,
snd_ymfpci_readl(chip, YDSXGR_MODE) & ~3); snd_ymfpci_readl(chip, YDSXGR_MODE) & ~3);
while (timeout-- > 0) { while (timeout-- > 0) {
@ -189,8 +184,6 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
atomic_set(&chip->interrupt_sleep_count, 0); atomic_set(&chip->interrupt_sleep_count, 0);
wake_up(&chip->interrupt_sleep); wake_up(&chip->interrupt_sleep);
} }
__end:
spin_unlock_irqrestore(&chip->reg_lock, flags);
} }
/* /*
@ -239,7 +232,6 @@ static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip,
enum snd_ymfpci_voice_type type, int pair, enum snd_ymfpci_voice_type type, int pair,
struct snd_ymfpci_voice **rvoice) struct snd_ymfpci_voice **rvoice)
{ {
unsigned long flags;
int result; int result;
if (snd_BUG_ON(!rvoice)) if (snd_BUG_ON(!rvoice))
@ -247,7 +239,7 @@ static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip,
if (snd_BUG_ON(pair && type != YMFPCI_PCM)) if (snd_BUG_ON(pair && type != YMFPCI_PCM))
return -EINVAL; return -EINVAL;
spin_lock_irqsave(&chip->voice_lock, flags); guard(spinlock_irqsave)(&chip->voice_lock);
for (;;) { for (;;) {
result = voice_alloc(chip, type, pair, rvoice); result = voice_alloc(chip, type, pair, rvoice);
if (result == 0 || type != YMFPCI_PCM) if (result == 0 || type != YMFPCI_PCM)
@ -255,18 +247,15 @@ static int snd_ymfpci_voice_alloc(struct snd_ymfpci *chip,
/* TODO: synth/midi voice deallocation */ /* TODO: synth/midi voice deallocation */
break; break;
} }
spin_unlock_irqrestore(&chip->voice_lock, flags);
return result; return result;
} }
static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voice *pvoice) static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voice *pvoice)
{ {
unsigned long flags;
if (snd_BUG_ON(!pvoice)) if (snd_BUG_ON(!pvoice))
return -EINVAL; return -EINVAL;
snd_ymfpci_hw_stop(chip); snd_ymfpci_hw_stop(chip);
spin_lock_irqsave(&chip->voice_lock, flags); guard(spinlock_irqsave)(&chip->voice_lock);
if (pvoice->number == chip->src441_used) { if (pvoice->number == chip->src441_used) {
chip->src441_used = -1; chip->src441_used = -1;
pvoice->ypcm->use_441_slot = 0; pvoice->ypcm->use_441_slot = 0;
@ -274,7 +263,6 @@ static int snd_ymfpci_voice_free(struct snd_ymfpci *chip, struct snd_ymfpci_voic
pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0; pvoice->use = pvoice->pcm = pvoice->synth = pvoice->midi = 0;
pvoice->ypcm = NULL; pvoice->ypcm = NULL;
pvoice->interrupt = NULL; pvoice->interrupt = NULL;
spin_unlock_irqrestore(&chip->voice_lock, flags);
return 0; return 0;
} }
@ -292,7 +280,7 @@ static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_
return; return;
if (ypcm->substream == NULL) if (ypcm->substream == NULL)
return; return;
spin_lock(&chip->reg_lock); guard(spinlock)(&chip->reg_lock);
if (ypcm->running) { if (ypcm->running) {
pos = le32_to_cpu(voice->bank[chip->active_bank].start); pos = le32_to_cpu(voice->bank[chip->active_bank].start);
if (pos < ypcm->last_pos) if (pos < ypcm->last_pos)
@ -334,7 +322,6 @@ static void snd_ymfpci_pcm_interrupt(struct snd_ymfpci *chip, struct snd_ymfpci_
ypcm->update_pcm_vol--; ypcm->update_pcm_vol--;
} }
} }
spin_unlock(&chip->reg_lock);
} }
static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream) static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream)
@ -344,7 +331,7 @@ static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream
struct snd_ymfpci *chip = ypcm->chip; struct snd_ymfpci *chip = ypcm->chip;
u32 pos, delta; u32 pos, delta;
spin_lock(&chip->reg_lock); guard(spinlock)(&chip->reg_lock);
if (ypcm->running) { if (ypcm->running) {
pos = le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift; pos = le32_to_cpu(chip->bank_capture[ypcm->capture_bank_number][chip->active_bank]->start) >> ypcm->shift;
if (pos < ypcm->last_pos) if (pos < ypcm->last_pos)
@ -366,7 +353,6 @@ static void snd_ymfpci_pcm_capture_interrupt(struct snd_pcm_substream *substream
spin_lock(&chip->reg_lock); spin_lock(&chip->reg_lock);
} }
} }
spin_unlock(&chip->reg_lock);
} }
static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream, static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream,
@ -377,11 +363,9 @@ static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream,
struct snd_kcontrol *kctl = NULL; struct snd_kcontrol *kctl = NULL;
int result = 0; int result = 0;
spin_lock(&chip->reg_lock); guard(spinlock)(&chip->reg_lock);
if (ypcm->voices[0] == NULL) { if (ypcm->voices[0] == NULL)
result = -EINVAL; return -EINVAL;
goto __unlock;
}
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@ -405,11 +389,8 @@ static int snd_ymfpci_playback_trigger(struct snd_pcm_substream *substream,
ypcm->running = 0; ypcm->running = 0;
break; break;
default: default:
result = -EINVAL; return -EINVAL;
break;
} }
__unlock:
spin_unlock(&chip->reg_lock);
if (kctl) if (kctl)
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id); snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_INFO, &kctl->id);
return result; return result;
@ -422,7 +403,7 @@ static int snd_ymfpci_capture_trigger(struct snd_pcm_substream *substream,
int result = 0; int result = 0;
u32 tmp; u32 tmp;
spin_lock(&chip->reg_lock); guard(spinlock)(&chip->reg_lock);
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
@ -442,7 +423,6 @@ static int snd_ymfpci_capture_trigger(struct snd_pcm_substream *substream,
result = -EINVAL; result = -EINVAL;
break; break;
} }
spin_unlock(&chip->reg_lock);
return result; return result;
} }
@ -489,7 +469,6 @@ static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm *ypcm, unsigned int
unsigned int nbank; unsigned int nbank;
__le32 vol_left, vol_right; __le32 vol_left, vol_right;
u8 use_left, use_right; u8 use_left, use_right;
unsigned long flags;
if (snd_BUG_ON(!voice)) if (snd_BUG_ON(!voice))
return; return;
@ -509,26 +488,26 @@ static void snd_ymfpci_pcm_init_voice(struct snd_ymfpci_pcm *ypcm, unsigned int
vol_left = cpu_to_le32(0x40000000); vol_left = cpu_to_le32(0x40000000);
vol_right = cpu_to_le32(0x40000000); vol_right = cpu_to_le32(0x40000000);
} }
spin_lock_irqsave(&ypcm->chip->voice_lock, flags); scoped_guard(spinlock_irqsave, &ypcm->chip->voice_lock) {
format = runtime->channels == 2 ? 0x00010000 : 0; format = runtime->channels == 2 ? 0x00010000 : 0;
if (snd_pcm_format_width(runtime->format) == 8) if (snd_pcm_format_width(runtime->format) == 8)
format |= 0x80000000; format |= 0x80000000;
else if (ypcm->chip->device_id == PCI_DEVICE_ID_YAMAHA_754 && else if (ypcm->chip->device_id == PCI_DEVICE_ID_YAMAHA_754 &&
runtime->rate == 44100 && runtime->channels == 2 && runtime->rate == 44100 && runtime->channels == 2 &&
voiceidx == 0 && (ypcm->chip->src441_used == -1 || voiceidx == 0 && (ypcm->chip->src441_used == -1 ||
ypcm->chip->src441_used == voice->number)) { ypcm->chip->src441_used == voice->number)) {
ypcm->chip->src441_used = voice->number; ypcm->chip->src441_used = voice->number;
ypcm->use_441_slot = 1; ypcm->use_441_slot = 1;
format |= 0x10000000; format |= 0x10000000;
}
if (ypcm->chip->src441_used == voice->number &&
(format & 0x10000000) == 0) {
ypcm->chip->src441_used = -1;
ypcm->use_441_slot = 0;
}
if (runtime->channels == 2 && (voiceidx & 1) != 0)
format |= 1;
} }
if (ypcm->chip->src441_used == voice->number &&
(format & 0x10000000) == 0) {
ypcm->chip->src441_used = -1;
ypcm->use_441_slot = 0;
}
if (runtime->channels == 2 && (voiceidx & 1) != 0)
format |= 1;
spin_unlock_irqrestore(&ypcm->chip->voice_lock, flags);
for (nbank = 0; nbank < 2; nbank++) { for (nbank = 0; nbank < 2; nbank++) {
bank = &voice->bank[nbank]; bank = &voice->bank[nbank];
memset(bank, 0, sizeof(*bank)); memset(bank, 0, sizeof(*bank));
@ -596,19 +575,18 @@ static int snd_ymfpci_ac3_init(struct snd_ymfpci *chip)
chip->bank_effect[4][0]->loop_end = chip->bank_effect[4][0]->loop_end =
chip->bank_effect[4][1]->loop_end = cpu_to_le32(1024); chip->bank_effect[4][1]->loop_end = cpu_to_le32(1024);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT,
snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) | 3 << 3); snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) | 3 << 3);
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
static int snd_ymfpci_ac3_done(struct snd_ymfpci *chip) static int snd_ymfpci_ac3_done(struct snd_ymfpci *chip)
{ {
spin_lock_irq(&chip->reg_lock); scoped_guard(spinlock_irq, &chip->reg_lock) {
snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT, snd_ymfpci_writel(chip, YDSXGR_MAPOFEFFECT,
snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) & ~(3 << 3)); snd_ymfpci_readl(chip, YDSXGR_MAPOFEFFECT) & ~(3 << 3));
spin_unlock_irq(&chip->reg_lock); }
// snd_ymfpci_irq_wait(chip); // snd_ymfpci_irq_wait(chip);
if (chip->ac3_tmp_base.area) { if (chip->ac3_tmp_base.area) {
snd_dma_free_pages(&chip->ac3_tmp_base); snd_dma_free_pages(&chip->ac3_tmp_base);
@ -778,28 +756,28 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
status = snd_ymfpci_readl(chip, YDSXGR_STATUS); status = snd_ymfpci_readl(chip, YDSXGR_STATUS);
if (status & 0x80000000) { if (status & 0x80000000) {
chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1; chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT) & 1;
spin_lock(&chip->voice_lock); scoped_guard(spinlock, &chip->voice_lock) {
for (nvoice = 0; nvoice < YDSXG_PLAYBACK_VOICES; nvoice++) { for (nvoice = 0; nvoice < YDSXG_PLAYBACK_VOICES; nvoice++) {
voice = &chip->voices[nvoice]; voice = &chip->voices[nvoice];
if (voice->interrupt) if (voice->interrupt)
voice->interrupt(chip, voice); voice->interrupt(chip, voice);
} }
for (nvoice = 0; nvoice < YDSXG_CAPTURE_VOICES; nvoice++) { for (nvoice = 0; nvoice < YDSXG_CAPTURE_VOICES; nvoice++) {
if (chip->capture_substream[nvoice]) if (chip->capture_substream[nvoice])
snd_ymfpci_pcm_capture_interrupt(chip->capture_substream[nvoice]); snd_ymfpci_pcm_capture_interrupt(chip->capture_substream[nvoice]);
} }
#if 0 #if 0
for (nvoice = 0; nvoice < YDSXG_EFFECT_VOICES; nvoice++) { for (nvoice = 0; nvoice < YDSXG_EFFECT_VOICES; nvoice++) {
if (chip->effect_substream[nvoice]) if (chip->effect_substream[nvoice])
snd_ymfpci_pcm_effect_interrupt(chip->effect_substream[nvoice]); snd_ymfpci_pcm_effect_interrupt(chip->effect_substream[nvoice]);
} }
#endif #endif
spin_unlock(&chip->voice_lock); }
spin_lock(&chip->reg_lock); scoped_guard(spinlock, &chip->reg_lock) {
snd_ymfpci_writel(chip, YDSXGR_STATUS, 0x80000000); snd_ymfpci_writel(chip, YDSXGR_STATUS, 0x80000000);
mode = snd_ymfpci_readl(chip, YDSXGR_MODE) | 2; mode = snd_ymfpci_readl(chip, YDSXGR_MODE) | 2;
snd_ymfpci_writel(chip, YDSXGR_MODE, mode); snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
spin_unlock(&chip->reg_lock); }
if (atomic_read(&chip->interrupt_sleep_count)) { if (atomic_read(&chip->interrupt_sleep_count)) {
atomic_set(&chip->interrupt_sleep_count, 0); atomic_set(&chip->interrupt_sleep_count, 0);
@ -936,12 +914,11 @@ static int snd_ymfpci_playback_open(struct snd_pcm_substream *substream)
ypcm->output_front = 1; ypcm->output_front = 1;
ypcm->output_rear = chip->mode_dup4ch ? 1 : 0; ypcm->output_rear = chip->mode_dup4ch ? 1 : 0;
ypcm->swap_rear = 0; ypcm->swap_rear = 0;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
if (ypcm->output_rear) { if (ypcm->output_rear) {
ymfpci_open_extension(chip); ymfpci_open_extension(chip);
chip->rear_opened++; chip->rear_opened++;
} }
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
@ -959,14 +936,14 @@ static int snd_ymfpci_playback_spdif_open(struct snd_pcm_substream *substream)
ypcm->output_front = 0; ypcm->output_front = 0;
ypcm->output_rear = 1; ypcm->output_rear = 1;
ypcm->swap_rear = 1; ypcm->swap_rear = 1;
spin_lock_irq(&chip->reg_lock); scoped_guard(spinlock_irq, &chip->reg_lock) {
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL,
snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) | 2); snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) | 2);
ymfpci_open_extension(chip); ymfpci_open_extension(chip);
chip->spdif_pcm_bits = chip->spdif_bits; chip->spdif_pcm_bits = chip->spdif_bits;
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits);
chip->spdif_opened++; chip->spdif_opened++;
spin_unlock_irq(&chip->reg_lock); }
chip->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE; chip->spdif_pcm_ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
@ -988,10 +965,9 @@ static int snd_ymfpci_playback_4ch_open(struct snd_pcm_substream *substream)
ypcm->output_front = 0; ypcm->output_front = 0;
ypcm->output_rear = 1; ypcm->output_rear = 1;
ypcm->swap_rear = 0; ypcm->swap_rear = 0;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
ymfpci_open_extension(chip); ymfpci_open_extension(chip);
chip->rear_opened++; chip->rear_opened++;
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
@ -1048,12 +1024,12 @@ static int snd_ymfpci_playback_close(struct snd_pcm_substream *substream)
struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data;
spin_lock_irq(&chip->reg_lock); scoped_guard(spinlock_irq, &chip->reg_lock) {
if (ypcm->output_rear && chip->rear_opened > 0) { if (ypcm->output_rear && chip->rear_opened > 0) {
chip->rear_opened--; chip->rear_opened--;
ymfpci_close_extension(chip); ymfpci_close_extension(chip);
}
} }
spin_unlock_irq(&chip->reg_lock);
return snd_ymfpci_playback_close_1(substream); return snd_ymfpci_playback_close_1(substream);
} }
@ -1061,13 +1037,13 @@ static int snd_ymfpci_playback_spdif_close(struct snd_pcm_substream *substream)
{ {
struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
spin_lock_irq(&chip->reg_lock); scoped_guard(spinlock_irq, &chip->reg_lock) {
chip->spdif_opened = 0; chip->spdif_opened = 0;
ymfpci_close_extension(chip); ymfpci_close_extension(chip);
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL, snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTCTRL,
snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & ~2); snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & ~2);
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits);
spin_unlock_irq(&chip->reg_lock); }
chip->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE; chip->spdif_pcm_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE | snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE |
SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id); SNDRV_CTL_EVENT_MASK_INFO, &chip->spdif_pcm_ctl->id);
@ -1078,12 +1054,12 @@ static int snd_ymfpci_playback_4ch_close(struct snd_pcm_substream *substream)
{ {
struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
spin_lock_irq(&chip->reg_lock); scoped_guard(spinlock_irq, &chip->reg_lock) {
if (chip->rear_opened > 0) { if (chip->rear_opened > 0) {
chip->rear_opened--; chip->rear_opened--;
ymfpci_close_extension(chip); ymfpci_close_extension(chip);
}
} }
spin_unlock_irq(&chip->reg_lock);
return snd_ymfpci_playback_close_1(substream); return snd_ymfpci_playback_close_1(substream);
} }
@ -1264,11 +1240,10 @@ static int snd_ymfpci_spdif_default_get(struct snd_kcontrol *kcontrol,
{ {
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
ucontrol->value.iec958.status[0] = (chip->spdif_bits >> 0) & 0xff; ucontrol->value.iec958.status[0] = (chip->spdif_bits >> 0) & 0xff;
ucontrol->value.iec958.status[1] = (chip->spdif_bits >> 8) & 0xff; ucontrol->value.iec958.status[1] = (chip->spdif_bits >> 8) & 0xff;
ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000;
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
@ -1281,12 +1256,11 @@ static int snd_ymfpci_spdif_default_put(struct snd_kcontrol *kcontrol,
val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) |
(ucontrol->value.iec958.status[1] << 8); (ucontrol->value.iec958.status[1] << 8);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
change = chip->spdif_bits != val; change = chip->spdif_bits != val;
chip->spdif_bits = val; chip->spdif_bits = val;
if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 1) && chip->pcm_spdif == NULL) if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 1) && chip->pcm_spdif == NULL)
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_bits);
spin_unlock_irq(&chip->reg_lock);
return change; return change;
} }
@ -1311,10 +1285,9 @@ static int snd_ymfpci_spdif_mask_get(struct snd_kcontrol *kcontrol,
{ {
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
ucontrol->value.iec958.status[0] = 0x3e; ucontrol->value.iec958.status[0] = 0x3e;
ucontrol->value.iec958.status[1] = 0xff; ucontrol->value.iec958.status[1] = 0xff;
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
@ -1339,11 +1312,10 @@ static int snd_ymfpci_spdif_stream_get(struct snd_kcontrol *kcontrol,
{ {
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
ucontrol->value.iec958.status[0] = (chip->spdif_pcm_bits >> 0) & 0xff; ucontrol->value.iec958.status[0] = (chip->spdif_pcm_bits >> 0) & 0xff;
ucontrol->value.iec958.status[1] = (chip->spdif_pcm_bits >> 8) & 0xff; ucontrol->value.iec958.status[1] = (chip->spdif_pcm_bits >> 8) & 0xff;
ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000; ucontrol->value.iec958.status[3] = IEC958_AES3_CON_FS_48000;
spin_unlock_irq(&chip->reg_lock);
return 0; return 0;
} }
@ -1356,12 +1328,11 @@ static int snd_ymfpci_spdif_stream_put(struct snd_kcontrol *kcontrol,
val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) | val = ((ucontrol->value.iec958.status[0] & 0x3e) << 0) |
(ucontrol->value.iec958.status[1] << 8); (ucontrol->value.iec958.status[1] << 8);
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
change = chip->spdif_pcm_bits != val; change = chip->spdif_pcm_bits != val;
chip->spdif_pcm_bits = val; chip->spdif_pcm_bits = val;
if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 2)) if ((snd_ymfpci_readw(chip, YDSXGR_SPDIFOUTCTRL) & 2))
snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits); snd_ymfpci_writew(chip, YDSXGR_SPDIFOUTSTATUS, chip->spdif_pcm_bits);
spin_unlock_irq(&chip->reg_lock);
return change; return change;
} }
@ -1387,9 +1358,8 @@ static int snd_ymfpci_drec_source_get(struct snd_kcontrol *kcontrol, struct snd_
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
u16 reg; u16 reg;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
spin_unlock_irq(&chip->reg_lock);
if (!(reg & 0x100)) if (!(reg & 0x100))
value->value.enumerated.item[0] = 0; value->value.enumerated.item[0] = 0;
else else
@ -1402,14 +1372,13 @@ static int snd_ymfpci_drec_source_put(struct snd_kcontrol *kcontrol, struct snd_
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
u16 reg, old_reg; u16 reg, old_reg;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
old_reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL); old_reg = snd_ymfpci_readw(chip, YDSXGR_GLOBALCTRL);
if (value->value.enumerated.item[0] == 0) if (value->value.enumerated.item[0] == 0)
reg = old_reg & ~0x100; reg = old_reg & ~0x100;
else else
reg = (old_reg & ~0x300) | 0x100 | ((value->value.enumerated.item[0] == 2) << 9); reg = (old_reg & ~0x300) | 0x100 | ((value->value.enumerated.item[0] == 2) << 9);
snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, reg); snd_ymfpci_writew(chip, YDSXGR_GLOBALCTRL, reg);
spin_unlock_irq(&chip->reg_lock);
return reg != old_reg; return reg != old_reg;
} }
@ -1469,12 +1438,11 @@ static int snd_ymfpci_put_single(struct snd_kcontrol *kcontrol,
} }
val = (ucontrol->value.integer.value[0] & mask); val = (ucontrol->value.integer.value[0] & mask);
val <<= shift; val <<= shift;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
oval = snd_ymfpci_readl(chip, reg); oval = snd_ymfpci_readl(chip, reg);
val = (oval & ~(mask << shift)) | val; val = (oval & ~(mask << shift)) | val;
change = val != oval; change = val != oval;
snd_ymfpci_writel(chip, reg, val); snd_ymfpci_writel(chip, reg, val);
spin_unlock_irq(&chip->reg_lock);
return change; return change;
} }
@ -1510,9 +1478,8 @@ static int snd_ymfpci_get_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e
if (reg < 0x80 || reg >= 0xc0) if (reg < 0x80 || reg >= 0xc0)
return -EINVAL; return -EINVAL;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
val = snd_ymfpci_readl(chip, reg); val = snd_ymfpci_readl(chip, reg);
spin_unlock_irq(&chip->reg_lock);
ucontrol->value.integer.value[0] = (val >> shift_left) & mask; ucontrol->value.integer.value[0] = (val >> shift_left) & mask;
ucontrol->value.integer.value[1] = (val >> shift_right) & mask; ucontrol->value.integer.value[1] = (val >> shift_right) & mask;
return 0; return 0;
@ -1532,12 +1499,11 @@ static int snd_ymfpci_put_double(struct snd_kcontrol *kcontrol, struct snd_ctl_e
val2 = ucontrol->value.integer.value[1] & mask; val2 = ucontrol->value.integer.value[1] & mask;
val1 <<= shift_left; val1 <<= shift_left;
val2 <<= shift_right; val2 <<= shift_right;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
oval = snd_ymfpci_readl(chip, reg); oval = snd_ymfpci_readl(chip, reg);
val1 = (oval & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2; val1 = (oval & ~((mask << shift_left) | (mask << shift_right))) | val1 | val2;
change = val1 != oval; change = val1 != oval;
snd_ymfpci_writel(chip, reg, val1); snd_ymfpci_writel(chip, reg, val1);
spin_unlock_irq(&chip->reg_lock);
return change; return change;
} }
@ -1552,12 +1518,11 @@ static int snd_ymfpci_put_nativedacvol(struct snd_kcontrol *kcontrol,
value = ucontrol->value.integer.value[0] & 0x3fff; value = ucontrol->value.integer.value[0] & 0x3fff;
value |= (ucontrol->value.integer.value[1] & 0x3fff) << 16; value |= (ucontrol->value.integer.value[1] & 0x3fff) << 16;
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
oval = snd_ymfpci_readl(chip, reg); oval = snd_ymfpci_readl(chip, reg);
change = value != oval; change = value != oval;
snd_ymfpci_writel(chip, reg, value); snd_ymfpci_writel(chip, reg, value);
snd_ymfpci_writel(chip, reg2, value); snd_ymfpci_writel(chip, reg2, value);
spin_unlock_irq(&chip->reg_lock);
return change; return change;
} }
@ -1629,9 +1594,8 @@ YMFPCI_SINGLE(SNDRV_CTL_NAME_IEC958("Loop",NONE,NONE), 0, YDSXGR_SPDIFINCTRL, 4)
static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin) static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin)
{ {
u16 reg, mode; u16 reg, mode;
unsigned long flags;
spin_lock_irqsave(&chip->reg_lock, flags); guard(spinlock_irqsave)(&chip->reg_lock);
reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE); reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE);
reg &= ~(1 << (pin + 8)); reg &= ~(1 << (pin + 8));
reg |= (1 << pin); reg |= (1 << pin);
@ -1642,23 +1606,20 @@ static int snd_ymfpci_get_gpio_out(struct snd_ymfpci *chip, int pin)
snd_ymfpci_writew(chip, YDSXGR_GPIOTYPECONFIG, mode); snd_ymfpci_writew(chip, YDSXGR_GPIOTYPECONFIG, mode);
snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8))); snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8)));
mode = snd_ymfpci_readw(chip, YDSXGR_GPIOINSTATUS); mode = snd_ymfpci_readw(chip, YDSXGR_GPIOINSTATUS);
spin_unlock_irqrestore(&chip->reg_lock, flags);
return (mode >> pin) & 1; return (mode >> pin) & 1;
} }
static int snd_ymfpci_set_gpio_out(struct snd_ymfpci *chip, int pin, int enable) static int snd_ymfpci_set_gpio_out(struct snd_ymfpci *chip, int pin, int enable)
{ {
u16 reg; u16 reg;
unsigned long flags;
spin_lock_irqsave(&chip->reg_lock, flags); guard(spinlock_irqsave)(&chip->reg_lock);
reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE); reg = snd_ymfpci_readw(chip, YDSXGR_GPIOFUNCENABLE);
reg &= ~(1 << pin); reg &= ~(1 << pin);
reg &= ~(1 << (pin + 8)); reg &= ~(1 << (pin + 8));
snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg); snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg);
snd_ymfpci_writew(chip, YDSXGR_GPIOOUTCTRL, enable << pin); snd_ymfpci_writew(chip, YDSXGR_GPIOOUTCTRL, enable << pin);
snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8))); snd_ymfpci_writew(chip, YDSXGR_GPIOFUNCENABLE, reg | (1 << (pin + 8)));
spin_unlock_irqrestore(&chip->reg_lock, flags);
return 0; return 0;
} }
@ -1726,7 +1687,6 @@ static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol *kcontrol,
struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol); struct snd_ymfpci *chip = snd_kcontrol_chip(kcontrol);
unsigned int subs = kcontrol->id.subdevice; unsigned int subs = kcontrol->id.subdevice;
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
unsigned long flags;
if (ucontrol->value.integer.value[0] != chip->pcm_mixer[subs].left || if (ucontrol->value.integer.value[0] != chip->pcm_mixer[subs].left ||
ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) { ucontrol->value.integer.value[1] != chip->pcm_mixer[subs].right) {
@ -1738,13 +1698,12 @@ static int snd_ymfpci_pcm_vol_put(struct snd_kcontrol *kcontrol,
chip->pcm_mixer[subs].right = 0x8000; chip->pcm_mixer[subs].right = 0x8000;
substream = (struct snd_pcm_substream *)kcontrol->private_value; substream = (struct snd_pcm_substream *)kcontrol->private_value;
spin_lock_irqsave(&chip->voice_lock, flags); guard(spinlock_irqsave)(&chip->voice_lock);
if (substream->runtime && substream->runtime->private_data) { if (substream->runtime && substream->runtime->private_data) {
struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data; struct snd_ymfpci_pcm *ypcm = substream->runtime->private_data;
if (!ypcm->use_441_slot) if (!ypcm->use_441_slot)
ypcm->update_pcm_vol = 2; ypcm->update_pcm_vol = 2;
} }
spin_unlock_irqrestore(&chip->voice_lock, flags);
return 1; return 1;
} }
return 0; return 0;
@ -1884,11 +1843,10 @@ int snd_ymfpci_mixer(struct snd_ymfpci *chip, int rear_switch)
static int snd_ymfpci_timer_start(struct snd_timer *timer) static int snd_ymfpci_timer_start(struct snd_timer *timer)
{ {
struct snd_ymfpci *chip; struct snd_ymfpci *chip;
unsigned long flags;
unsigned int count; unsigned int count;
chip = snd_timer_chip(timer); chip = snd_timer_chip(timer);
spin_lock_irqsave(&chip->reg_lock, flags); guard(spinlock_irqsave)(&chip->reg_lock);
if (timer->sticks > 1) { if (timer->sticks > 1) {
chip->timer_ticks = timer->sticks; chip->timer_ticks = timer->sticks;
count = timer->sticks - 1; count = timer->sticks - 1;
@ -1902,19 +1860,16 @@ static int snd_ymfpci_timer_start(struct snd_timer *timer)
} }
snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count); snd_ymfpci_writew(chip, YDSXGR_TIMERCOUNT, count);
snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03); snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x03);
spin_unlock_irqrestore(&chip->reg_lock, flags);
return 0; return 0;
} }
static int snd_ymfpci_timer_stop(struct snd_timer *timer) static int snd_ymfpci_timer_stop(struct snd_timer *timer)
{ {
struct snd_ymfpci *chip; struct snd_ymfpci *chip;
unsigned long flags;
chip = snd_timer_chip(timer); chip = snd_timer_chip(timer);
spin_lock_irqsave(&chip->reg_lock, flags); guard(spinlock_irqsave)(&chip->reg_lock);
snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x00); snd_ymfpci_writeb(chip, YDSXGR_TIMERCTRL, 0x00);
spin_unlock_irqrestore(&chip->reg_lock, flags);
return 0; return 0;
} }
@ -2273,10 +2228,9 @@ static int snd_ymfpci_resume(struct device *dev)
/* start hw again */ /* start hw again */
if (chip->start_count > 0) { if (chip->start_count > 0) {
spin_lock_irq(&chip->reg_lock); guard(spinlock_irq)(&chip->reg_lock);
snd_ymfpci_writel(chip, YDSXGR_MODE, chip->saved_ydsxgr_mode); snd_ymfpci_writel(chip, YDSXGR_MODE, chip->saved_ydsxgr_mode);
chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT); chip->active_bank = snd_ymfpci_readl(chip, YDSXGR_CTRLSELECT);
spin_unlock_irq(&chip->reg_lock);
} }
snd_power_change_state(card, SNDRV_CTL_POWER_D0); snd_power_change_state(card, SNDRV_CTL_POWER_D0);
return 0; return 0;