diff options
Diffstat (limited to 'sound/isa/sb/sb16_csp.c')
-rw-r--r-- | sound/isa/sb/sb16_csp.c | 219 |
1 files changed, 93 insertions, 126 deletions
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c index 7034072c80d4..9ad71a9fc18d 100644 --- a/sound/isa/sb/sb16_csp.c +++ b/sound/isa/sb/sb16_csp.c @@ -265,14 +265,10 @@ static int snd_sb_csp_release(struct snd_hwdep * hw, struct file *file) */ static int snd_sb_csp_use(struct snd_sb_csp * p) { - mutex_lock(&p->access_mutex); - if (p->used) { - mutex_unlock(&p->access_mutex); + guard(mutex)(&p->access_mutex); + if (p->used) return -EAGAIN; - } p->used++; - mutex_unlock(&p->access_mutex); - return 0; } @@ -282,10 +278,8 @@ static int snd_sb_csp_use(struct snd_sb_csp * p) */ static int snd_sb_csp_unuse(struct snd_sb_csp * p) { - mutex_lock(&p->access_mutex); + guard(mutex)(&p->access_mutex); p->used--; - mutex_unlock(&p->access_mutex); - return 0; } @@ -307,7 +301,6 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p, __le32 item_type; struct desc_header funcdesc_h; - unsigned long flags; int err; if (copy_from_user(&info, mcode, sizeof(info))) @@ -435,10 +428,9 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p, p->acc_rates = le16_to_cpu(funcdesc_h.flags_rates); /* Decouple CSP from IRQ and DMAREQ lines */ - spin_lock_irqsave(&p->chip->reg_lock, flags); + guard(spinlock_irqsave)(&p->chip->reg_lock); set_mode_register(p->chip, 0xfc); set_mode_register(p->chip, 0x00); - spin_unlock_irqrestore(&p->chip->reg_lock, flags); /* finished loading successfully */ p->running = SNDRV_SB_CSP_ST_LOADED; /* set LOADED flag */ @@ -548,10 +540,8 @@ static int set_mode_register(struct snd_sb *chip, unsigned char mode) static int csp_detect(struct snd_sb *chip, int *version) { unsigned char csp_test1, csp_test2; - unsigned long flags; - int result = -ENODEV; - spin_lock_irqsave(&chip->reg_lock, flags); + guard(spinlock_irqsave)(&chip->reg_lock); set_codec_parameter(chip, 0x00, 0x00); set_mode_register(chip, 0xfc); /* 0xfc = ?? */ @@ -560,23 +550,21 @@ static int csp_detect(struct snd_sb *chip, int *version) set_register(chip, 0x83, ~csp_test1); csp_test2 = read_register(chip, 0x83); if (csp_test2 != (csp_test1 ^ 0xff)) - goto __fail; + return -ENODEV; set_register(chip, 0x83, csp_test1); csp_test2 = read_register(chip, 0x83); if (csp_test2 != csp_test1) - goto __fail; + return -ENODEV; set_mode_register(chip, 0x00); /* 0x00 = ? */ *version = get_version(chip); snd_sbdsp_reset(chip); /* reset DSP after getversion! */ if (*version >= 0x10 && *version <= 0x1f) - result = 0; /* valid version id */ + return 0; /* valid version id */ - __fail: - spin_unlock_irqrestore(&chip->reg_lock, flags); - return result; + return -ENODEV; } /* @@ -614,14 +602,12 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int { int status, i; int err; - int result = -EIO; - unsigned long flags; - spin_lock_irqsave(&p->chip->reg_lock, flags); + guard(spinlock_irqsave)(&p->chip->reg_lock); snd_sbdsp_command(p->chip, 0x01); /* CSP download command */ if (snd_sbdsp_get_byte(p->chip)) { dev_dbg(p->chip->card->dev, "%s: Download command failed\n", __func__); - goto __fail; + return -EIO; } /* Send CSP low byte (size - 1) */ snd_sbdsp_command(p->chip, (unsigned char)(size - 1)); @@ -631,10 +617,10 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int /* load from kernel space */ while (size--) { if (!snd_sbdsp_command(p->chip, *buf++)) - goto __fail; + return -EIO; } if (snd_sbdsp_get_byte(p->chip)) - goto __fail; + return -EIO; if (load_flags & SNDRV_SB_CSP_LOAD_INITBLOCK) { i = 0; @@ -650,7 +636,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int dev_dbg(p->chip->card->dev, "%s: Microcode initialization failed\n", __func__); - goto __fail; + return -EIO; } } else { /* @@ -658,24 +644,21 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int * Start CSP chip if no 16bit DMA channel is set - some kind * of autorun or perhaps a bugfix? */ - spin_lock(&p->chip->mixer_lock); - status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP); - spin_unlock(&p->chip->mixer_lock); + scoped_guard(spinlock, &p->chip->mixer_lock) { + status = snd_sbmixer_read(p->chip, SB_DSP4_DMASETUP); + } if (!(status & (SB_DMASETUP_DMA7 | SB_DMASETUP_DMA6 | SB_DMASETUP_DMA5))) { err = (set_codec_parameter(p->chip, 0xaa, 0x00) || set_codec_parameter(p->chip, 0xff, 0x00)); snd_sbdsp_reset(p->chip); /* really! */ if (err) - goto __fail; + return -EIO; set_mode_register(p->chip, 0xc0); /* c0 = STOP */ set_mode_register(p->chip, 0x70); /* 70 = RUN */ } } - result = 0; - __fail: - spin_unlock_irqrestore(&p->chip->reg_lock, flags); - return result; + return 0; } static int snd_sb_csp_load_user(struct snd_sb_csp * p, const unsigned char __user *buf, int size, int load_flags) @@ -722,7 +705,6 @@ static int snd_sb_csp_firmware_load(struct snd_sb_csp *p, int index, int flags) */ static int snd_sb_csp_autoload(struct snd_sb_csp * p, snd_pcm_format_t pcm_sfmt, int play_rec_mode) { - unsigned long flags; int err = 0; /* if CSP is running or manually loaded then exit */ @@ -763,10 +745,9 @@ static int snd_sb_csp_autoload(struct snd_sb_csp * p, snd_pcm_format_t pcm_sfmt, default: /* Decouple CSP from IRQ and DMAREQ lines */ if (p->running & SNDRV_SB_CSP_ST_AUTO) { - spin_lock_irqsave(&p->chip->reg_lock, flags); + guard(spinlock_irqsave)(&p->chip->reg_lock); set_mode_register(p->chip, 0xfc); set_mode_register(p->chip, 0x00); - spin_unlock_irqrestore(&p->chip->reg_lock, flags); p->running = 0; /* clear autoloaded flag */ } return -EINVAL; @@ -798,7 +779,6 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel unsigned char s_type; /* sample type */ unsigned char mixL, mixR; int result = -EIO; - unsigned long flags; if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) { dev_dbg(dev, "%s: Microcode not loaded\n", __func__); @@ -818,55 +798,54 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel } /* Mute PCM volume */ - spin_lock_irqsave(&p->chip->mixer_lock, flags); - mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); - mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); - spin_unlock_irqrestore(&p->chip->mixer_lock, flags); - - spin_lock(&p->chip->reg_lock); - set_mode_register(p->chip, 0xc0); /* c0 = STOP */ - set_mode_register(p->chip, 0x70); /* 70 = RUN */ - - s_type = 0x00; - if (channels == SNDRV_SB_CSP_MONO) - s_type = 0x11; /* 000n 000n (n = 1 if mono) */ - if (sample_width == SNDRV_SB_CSP_SAMPLE_8BIT) - s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ - - if (set_codec_parameter(p->chip, 0x81, s_type)) { - dev_dbg(dev, "%s: Set sample type command failed\n", __func__); - goto __fail; + scoped_guard(spinlock_irqsave, &p->chip->mixer_lock) { + mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); + mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); } - if (set_codec_parameter(p->chip, 0x80, 0x00)) { - dev_dbg(dev, "%s: Codec start command failed\n", __func__); - goto __fail; - } - p->run_width = sample_width; - p->run_channels = channels; - p->running |= SNDRV_SB_CSP_ST_RUNNING; + scoped_guard(spinlock, &p->chip->reg_lock) { + set_mode_register(p->chip, 0xc0); /* c0 = STOP */ + set_mode_register(p->chip, 0x70); /* 70 = RUN */ - if (p->mode & SNDRV_SB_CSP_MODE_QSOUND) { - set_codec_parameter(p->chip, 0xe0, 0x01); - /* enable QSound decoder */ - set_codec_parameter(p->chip, 0x00, 0xff); - set_codec_parameter(p->chip, 0x01, 0xff); - p->running |= SNDRV_SB_CSP_ST_QSOUND; - /* set QSound startup value */ - snd_sb_csp_qsound_transfer(p); - } - result = 0; + s_type = 0x00; + if (channels == SNDRV_SB_CSP_MONO) + s_type = 0x11; /* 000n 000n (n = 1 if mono) */ + if (sample_width == SNDRV_SB_CSP_SAMPLE_8BIT) + s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ - __fail: - spin_unlock(&p->chip->reg_lock); + if (set_codec_parameter(p->chip, 0x81, s_type)) { + dev_dbg(dev, "%s: Set sample type command failed\n", __func__); + break; + } + if (set_codec_parameter(p->chip, 0x80, 0x00)) { + dev_dbg(dev, "%s: Codec start command failed\n", __func__); + break; + } + p->run_width = sample_width; + p->run_channels = channels; + + p->running |= SNDRV_SB_CSP_ST_RUNNING; + + if (p->mode & SNDRV_SB_CSP_MODE_QSOUND) { + set_codec_parameter(p->chip, 0xe0, 0x01); + /* enable QSound decoder */ + set_codec_parameter(p->chip, 0x00, 0xff); + set_codec_parameter(p->chip, 0x01, 0xff); + p->running |= SNDRV_SB_CSP_ST_QSOUND; + /* set QSound startup value */ + snd_sb_csp_qsound_transfer(p); + } + result = 0; + } /* restore PCM volume */ - spin_lock_irqsave(&p->chip->mixer_lock, flags); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); - spin_unlock_irqrestore(&p->chip->mixer_lock, flags); + if (result < 0) { + guard(spinlock_irqsave)(&p->chip->mixer_lock); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); + } return result; } @@ -878,36 +857,35 @@ static int snd_sb_csp_stop(struct snd_sb_csp * p) { int result; unsigned char mixL, mixR; - unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_RUNNING)) return 0; /* Mute PCM volume */ - spin_lock_irqsave(&p->chip->mixer_lock, flags); - mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); - mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); - spin_unlock_irqrestore(&p->chip->mixer_lock, flags); - - spin_lock(&p->chip->reg_lock); - if (p->running & SNDRV_SB_CSP_ST_QSOUND) { - set_codec_parameter(p->chip, 0xe0, 0x01); - /* disable QSound decoder */ - set_codec_parameter(p->chip, 0x00, 0x00); - set_codec_parameter(p->chip, 0x01, 0x00); + scoped_guard(spinlock_irqsave, &p->chip->mixer_lock) { + mixL = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV); + mixR = snd_sbmixer_read(p->chip, SB_DSP4_PCM_DEV + 1); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL & 0x7); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR & 0x7); + } + + scoped_guard(spinlock, &p->chip->reg_lock) { + if (p->running & SNDRV_SB_CSP_ST_QSOUND) { + set_codec_parameter(p->chip, 0xe0, 0x01); + /* disable QSound decoder */ + set_codec_parameter(p->chip, 0x00, 0x00); + set_codec_parameter(p->chip, 0x01, 0x00); - p->running &= ~SNDRV_SB_CSP_ST_QSOUND; + p->running &= ~SNDRV_SB_CSP_ST_QSOUND; + } + result = set_mode_register(p->chip, 0xc0); /* c0 = STOP */ } - result = set_mode_register(p->chip, 0xc0); /* c0 = STOP */ - spin_unlock(&p->chip->reg_lock); /* restore PCM volume */ - spin_lock_irqsave(&p->chip->mixer_lock, flags); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); - snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); - spin_unlock_irqrestore(&p->chip->mixer_lock, flags); + scoped_guard(spinlock_irqsave, &p->chip->mixer_lock) { + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV, mixL); + snd_sbmixer_write(p->chip, SB_DSP4_PCM_DEV + 1, mixR); + } if (!(result)) p->running &= ~(SNDRV_SB_CSP_ST_PAUSED | SNDRV_SB_CSP_ST_RUNNING); @@ -920,14 +898,13 @@ static int snd_sb_csp_stop(struct snd_sb_csp * p) static int snd_sb_csp_pause(struct snd_sb_csp * p) { int result; - unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_RUNNING)) return -EBUSY; - spin_lock_irqsave(&p->chip->reg_lock, flags); - result = set_codec_parameter(p->chip, 0x80, 0xff); - spin_unlock_irqrestore(&p->chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &p->chip->reg_lock) { + result = set_codec_parameter(p->chip, 0x80, 0xff); + } if (!(result)) p->running |= SNDRV_SB_CSP_ST_PAUSED; @@ -940,14 +917,13 @@ static int snd_sb_csp_pause(struct snd_sb_csp * p) static int snd_sb_csp_restart(struct snd_sb_csp * p) { int result; - unsigned long flags; if (!(p->running & SNDRV_SB_CSP_ST_PAUSED)) return -EBUSY; - spin_lock_irqsave(&p->chip->reg_lock, flags); - result = set_codec_parameter(p->chip, 0x80, 0x00); - spin_unlock_irqrestore(&p->chip->reg_lock, flags); + scoped_guard(spinlock_irqsave, &p->chip->reg_lock) { + result = set_codec_parameter(p->chip, 0x80, 0x00); + } if (!(result)) p->running &= ~SNDRV_SB_CSP_ST_PAUSED; @@ -973,15 +949,13 @@ static int snd_sb_qsound_switch_get(struct snd_kcontrol *kcontrol, struct snd_ct static int snd_sb_qsound_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change; unsigned char nval; nval = ucontrol->value.integer.value[0] & 0x01; - spin_lock_irqsave(&p->q_lock, flags); + guard(spinlock_irqsave)(&p->q_lock); change = p->q_enabled != nval; p->q_enabled = nval; - spin_unlock_irqrestore(&p->q_lock, flags); return change; } @@ -997,19 +971,16 @@ static int snd_sb_qsound_space_info(struct snd_kcontrol *kcontrol, struct snd_ct static int snd_sb_qsound_space_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); - unsigned long flags; - spin_lock_irqsave(&p->q_lock, flags); + guard(spinlock_irqsave)(&p->q_lock); ucontrol->value.integer.value[0] = p->qpos_left; ucontrol->value.integer.value[1] = p->qpos_right; - spin_unlock_irqrestore(&p->q_lock, flags); return 0; } static int snd_sb_qsound_space_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) { struct snd_sb_csp *p = snd_kcontrol_chip(kcontrol); - unsigned long flags; int change; unsigned char nval1, nval2; @@ -1019,12 +990,11 @@ static int snd_sb_qsound_space_put(struct snd_kcontrol *kcontrol, struct snd_ctl nval2 = ucontrol->value.integer.value[1]; if (nval2 > SNDRV_SB_CSP_QSOUND_MAX_RIGHT) nval2 = SNDRV_SB_CSP_QSOUND_MAX_RIGHT; - spin_lock_irqsave(&p->q_lock, flags); + guard(spinlock_irqsave)(&p->q_lock); change = p->qpos_left != nval1 || p->qpos_right != nval2; p->qpos_left = nval1; p->qpos_right = nval2; p->qpos_changed = change; - spin_unlock_irqrestore(&p->q_lock, flags); return change; } @@ -1080,7 +1050,6 @@ static int snd_sb_qsound_build(struct snd_sb_csp * p) static void snd_sb_qsound_destroy(struct snd_sb_csp * p) { struct snd_card *card; - unsigned long flags; if (snd_BUG_ON(!p)) return; @@ -1093,9 +1062,8 @@ static void snd_sb_qsound_destroy(struct snd_sb_csp * p) p->qsound_space = NULL; /* cancel pending transfer of QSound parameters */ - spin_lock_irqsave (&p->q_lock, flags); + guard(spinlock_irqsave)(&p->q_lock); p->qpos_changed = 0; - spin_unlock_irqrestore (&p->q_lock, flags); } /* @@ -1106,7 +1074,7 @@ static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p) { int err = -ENXIO; - spin_lock(&p->q_lock); + guard(spinlock)(&p->q_lock); if (p->running & SNDRV_SB_CSP_ST_QSOUND) { set_codec_parameter(p->chip, 0xe0, 0x01); /* left channel */ @@ -1118,7 +1086,6 @@ static int snd_sb_csp_qsound_transfer(struct snd_sb_csp * p) err = 0; } p->qpos_changed = 0; - spin_unlock(&p->q_lock); return err; } |