static inline int snd_rme9652_use_is_exclusive(struct snd_rme9652 *rme9652)
{
- unsigned long flags;
- int ret = 1;
-
- spin_lock_irqsave(&rme9652->lock, flags);
+ guard(spinlock_irqsave)(&rme9652->lock);
if ((rme9652->playback_pid != rme9652->capture_pid) &&
- (rme9652->playback_pid >= 0) && (rme9652->capture_pid >= 0)) {
- ret = 0;
- }
- spin_unlock_irqrestore(&rme9652->lock, flags);
- return ret;
+ (rme9652->playback_pid >= 0) && (rme9652->capture_pid >= 0))
+ return 0;
+ return 1;
}
static inline int rme9652_adat_sample_rate(struct snd_rme9652 *rme9652)
int restart = 0;
int n;
- spin_lock_irq(&s->lock);
+ guard(spinlock_irq)(&s->lock);
restart = s->running;
if (restart)
if (restart)
rme9652_start(s);
- spin_unlock_irq(&s->lock);
-
return 0;
}
is to flag rate changes in the read/write routines.
*/
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
xrate = rme9652_adat_sample_rate(rme9652);
switch (rate) {
rate = RME9652_DS | RME9652_freq;
break;
default:
- spin_unlock_irq(&rme9652->lock);
return -EINVAL;
}
- if (reject_if_open && (rme9652->capture_pid >= 0 || rme9652->playback_pid >= 0)) {
- spin_unlock_irq(&rme9652->lock);
+ if (reject_if_open && (rme9652->capture_pid >= 0 || rme9652->playback_pid >= 0))
return -EBUSY;
- }
restart = rme9652->running;
if (restart)
}
}
- spin_unlock_irq(&rme9652->lock);
return 0;
}
u32 val;
val = snd_rme9652_convert_from_aes(&ucontrol->value.iec958);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = val != rme9652->creg_spdif;
rme9652->creg_spdif = val;
- spin_unlock_irq(&rme9652->lock);
return change;
}
u32 val;
val = snd_rme9652_convert_from_aes(&ucontrol->value.iec958);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = val != rme9652->creg_spdif_stream;
rme9652->creg_spdif_stream = val;
rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby | RME9652_EMP);
rme9652_write(rme9652, RME9652_control_register, rme9652->control_register |= val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.enumerated.item[0] = rme9652_adat1_in(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
if (!snd_rme9652_use_is_exclusive(rme9652))
return -EBUSY;
val = ucontrol->value.enumerated.item[0] % 2;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = val != rme9652_adat1_in(rme9652);
if (change)
rme9652_set_adat1_input(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.enumerated.item[0] = rme9652_spdif_in(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
if (!snd_rme9652_use_is_exclusive(rme9652))
return -EBUSY;
val = ucontrol->value.enumerated.item[0] % 3;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = val != rme9652_spdif_in(rme9652);
if (change)
rme9652_set_spdif_input(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.integer.value[0] = rme9652_spdif_out(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
if (!snd_rme9652_use_is_exclusive(rme9652))
return -EBUSY;
val = ucontrol->value.integer.value[0] & 1;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = (int)val != rme9652_spdif_out(rme9652);
rme9652_set_spdif_output(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.enumerated.item[0] = rme9652_sync_mode(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
unsigned int val;
val = ucontrol->value.enumerated.item[0] % 3;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = (int)val != rme9652_sync_mode(rme9652);
rme9652_set_sync_mode(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.enumerated.item[0] = rme9652_sync_pref(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
return -EBUSY;
max = rme9652->ss_channels == RME9652_NCHANNELS ? 4 : 3;
val = ucontrol->value.enumerated.item[0] % max;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = (int)val != rme9652_sync_pref(rme9652);
rme9652_set_sync_pref(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return change;
}
thru_bits |= 1 << chn;
}
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = thru_bits ^ rme9652->thru_bits;
if (change) {
for (chn = 0; chn < rme9652->ss_channels; ++chn) {
rme9652_set_thru(rme9652,chn,thru_bits&(1<<chn));
}
}
- spin_unlock_irq(&rme9652->lock);
return !!change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.integer.value[0] = rme9652->passthru;
- spin_unlock_irq(&rme9652->lock);
return 0;
}
return -EBUSY;
val = ucontrol->value.integer.value[0] & 1;
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
change = (ucontrol->value.integer.value[0] != rme9652->passthru);
if (change)
err = rme9652_set_passthru(rme9652, val);
- spin_unlock_irq(&rme9652->lock);
return err ? err : change;
}
{
struct snd_rme9652 *rme9652 = snd_kcontrol_chip(kcontrol);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
ucontrol->value.integer.value[0] = rme9652_spdif_sample_rate(rme9652);
- spin_unlock_irq(&rme9652->lock);
return 0;
}
pid_t this_pid;
pid_t other_pid;
- spin_lock_irq(&rme9652->lock);
-
- if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
- rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby | RME9652_EMP);
- rme9652_write(rme9652, RME9652_control_register, rme9652->control_register |= rme9652->creg_spdif_stream);
- this_pid = rme9652->playback_pid;
- other_pid = rme9652->capture_pid;
- } else {
- this_pid = rme9652->capture_pid;
- other_pid = rme9652->playback_pid;
- }
-
- if ((other_pid > 0) && (this_pid != other_pid)) {
-
- /* The other stream is open, and not by the same
- task as this one. Make sure that the parameters
- that matter are the same.
- */
+ scoped_guard(spinlock_irq, &rme9652->lock) {
- if ((int)params_rate(params) !=
- rme9652_adat_sample_rate(rme9652)) {
- spin_unlock_irq(&rme9652->lock);
- _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
- return -EBUSY;
+ if (substream->pstr->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ rme9652->control_register &= ~(RME9652_PRO | RME9652_Dolby | RME9652_EMP);
+ rme9652_write(rme9652, RME9652_control_register, rme9652->control_register |= rme9652->creg_spdif_stream);
+ this_pid = rme9652->playback_pid;
+ other_pid = rme9652->capture_pid;
+ } else {
+ this_pid = rme9652->capture_pid;
+ other_pid = rme9652->playback_pid;
}
- if (params_period_size(params) != rme9652->period_bytes / 4) {
- spin_unlock_irq(&rme9652->lock);
- _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
- return -EBUSY;
- }
+ if ((other_pid > 0) && (this_pid != other_pid)) {
- /* We're fine. */
+ /* The other stream is open, and not by the same
+ task as this one. Make sure that the parameters
+ that matter are the same.
+ */
- spin_unlock_irq(&rme9652->lock);
- return 0;
+ if ((int)params_rate(params) !=
+ rme9652_adat_sample_rate(rme9652)) {
+ _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_RATE);
+ return -EBUSY;
+ }
- } else {
- spin_unlock_irq(&rme9652->lock);
+ if (params_period_size(params) != rme9652->period_bytes / 4) {
+ _snd_pcm_hw_param_setempty(params, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
+ return -EBUSY;
+ }
+
+ /* We're fine. */
+ return 0;
+ }
}
/* how to make sure that the rate matches an externally-set one ?
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
struct snd_pcm_substream *other;
int running;
- spin_lock(&rme9652->lock);
+
+ guard(spinlock)(&rme9652->lock);
running = rme9652->running;
switch (cmd) {
case SNDRV_PCM_TRIGGER_START:
break;
default:
snd_BUG();
- spin_unlock(&rme9652->lock);
return -EINVAL;
}
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
else if (rme9652->running && !running)
rme9652_stop(rme9652);
rme9652->running = running;
- spin_unlock(&rme9652->lock);
return 0;
}
static int snd_rme9652_prepare(struct snd_pcm_substream *substream)
{
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
- unsigned long flags;
- spin_lock_irqsave(&rme9652->lock, flags);
+ guard(spinlock_irqsave)(&rme9652->lock);
if (!rme9652->running)
rme9652_reset_hw_pointer(rme9652);
- spin_unlock_irqrestore(&rme9652->lock, flags);
return 0;
}
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
- spin_lock_irq(&rme9652->lock);
+ scoped_guard(spinlock_irq, &rme9652->lock) {
+ snd_pcm_set_sync(substream);
- snd_pcm_set_sync(substream);
+ runtime->hw = snd_rme9652_playback_subinfo;
+ snd_pcm_set_runtime_buffer(substream, &rme9652->playback_dma_buf);
- runtime->hw = snd_rme9652_playback_subinfo;
- snd_pcm_set_runtime_buffer(substream, &rme9652->playback_dma_buf);
+ if (rme9652->capture_substream == NULL) {
+ rme9652_stop(rme9652);
+ rme9652_set_thru(rme9652, -1, 0);
+ }
- if (rme9652->capture_substream == NULL) {
- rme9652_stop(rme9652);
- rme9652_set_thru(rme9652, -1, 0);
+ rme9652->playback_pid = current->pid;
+ rme9652->playback_substream = substream;
}
- rme9652->playback_pid = current->pid;
- rme9652->playback_substream = substream;
-
- spin_unlock_irq(&rme9652->lock);
-
snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_period_sizes);
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
{
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
- spin_lock_irq(&rme9652->lock);
-
- rme9652->playback_pid = -1;
- rme9652->playback_substream = NULL;
-
- spin_unlock_irq(&rme9652->lock);
+ scoped_guard(spinlock_irq, &rme9652->lock) {
+ rme9652->playback_pid = -1;
+ rme9652->playback_substream = NULL;
+ }
rme9652->spdif_ctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_INACTIVE;
snd_ctl_notify(rme9652->card, SNDRV_CTL_EVENT_MASK_VALUE |
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
struct snd_pcm_runtime *runtime = substream->runtime;
- spin_lock_irq(&rme9652->lock);
+ scoped_guard(spinlock_irq, &rme9652->lock) {
+ snd_pcm_set_sync(substream);
- snd_pcm_set_sync(substream);
+ runtime->hw = snd_rme9652_capture_subinfo;
+ snd_pcm_set_runtime_buffer(substream, &rme9652->capture_dma_buf);
- runtime->hw = snd_rme9652_capture_subinfo;
- snd_pcm_set_runtime_buffer(substream, &rme9652->capture_dma_buf);
+ if (rme9652->playback_substream == NULL) {
+ rme9652_stop(rme9652);
+ rme9652_set_thru(rme9652, -1, 0);
+ }
- if (rme9652->playback_substream == NULL) {
- rme9652_stop(rme9652);
- rme9652_set_thru(rme9652, -1, 0);
+ rme9652->capture_pid = current->pid;
+ rme9652->capture_substream = substream;
}
- rme9652->capture_pid = current->pid;
- rme9652->capture_substream = substream;
-
- spin_unlock_irq(&rme9652->lock);
-
snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, &hw_constraints_period_sizes);
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
{
struct snd_rme9652 *rme9652 = snd_pcm_substream_chip(substream);
- spin_lock_irq(&rme9652->lock);
+ guard(spinlock_irq)(&rme9652->lock);
rme9652->capture_pid = -1;
rme9652->capture_substream = NULL;
- spin_unlock_irq(&rme9652->lock);
return 0;
}