Skip to content

Commit 4c68062

Browse files
committed
ALSA: sparc/amd7930: 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>
1 parent 02d0aba commit 4c68062

1 file changed

Lines changed: 45 additions & 69 deletions

File tree

sound/sparc/amd7930.c

Lines changed: 45 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -346,34 +346,25 @@ static struct snd_amd7930 *amd7930_list;
346346
/* Idle the AMD7930 chip. The amd->lock is not held. */
347347
static __inline__ void amd7930_idle(struct snd_amd7930 *amd)
348348
{
349-
unsigned long flags;
350-
351-
spin_lock_irqsave(&amd->lock, flags);
349+
guard(spinlock_irqsave)(&amd->lock);
352350
sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
353351
sbus_writeb(0, amd->regs + AMD7930_DR);
354-
spin_unlock_irqrestore(&amd->lock, flags);
355352
}
356353

357354
/* Enable chip interrupts. The amd->lock is not held. */
358355
static __inline__ void amd7930_enable_ints(struct snd_amd7930 *amd)
359356
{
360-
unsigned long flags;
361-
362-
spin_lock_irqsave(&amd->lock, flags);
357+
guard(spinlock_irqsave)(&amd->lock);
363358
sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
364359
sbus_writeb(AM_INIT_ACTIVE, amd->regs + AMD7930_DR);
365-
spin_unlock_irqrestore(&amd->lock, flags);
366360
}
367361

368362
/* Disable chip interrupts. The amd->lock is not held. */
369363
static __inline__ void amd7930_disable_ints(struct snd_amd7930 *amd)
370364
{
371-
unsigned long flags;
372-
373-
spin_lock_irqsave(&amd->lock, flags);
365+
guard(spinlock_irqsave)(&amd->lock);
374366
sbus_writeb(AMR_INIT, amd->regs + AMD7930_CR);
375367
sbus_writeb(AM_INIT_ACTIVE | AM_INIT_DISABLE_INTS, amd->regs + AMD7930_DR);
376-
spin_unlock_irqrestore(&amd->lock, flags);
377368
}
378369

379370
/* Commit amd7930_map settings to the hardware.
@@ -497,34 +488,33 @@ static irqreturn_t snd_amd7930_interrupt(int irq, void *dev_id)
497488
unsigned int elapsed;
498489
u8 ir;
499490

500-
spin_lock(&amd->lock);
501-
502-
elapsed = 0;
503-
504-
ir = sbus_readb(amd->regs + AMD7930_IR);
505-
if (ir & AMR_IR_BBUF) {
506-
u8 byte;
507-
508-
if (amd->flags & AMD7930_FLAG_PLAYBACK) {
509-
if (amd->p_left > 0) {
510-
byte = *(amd->p_cur++);
511-
amd->p_left--;
512-
sbus_writeb(byte, amd->regs + AMD7930_BBTB);
513-
if (amd->p_left == 0)
514-
elapsed |= AMD7930_FLAG_PLAYBACK;
515-
} else
516-
sbus_writeb(0, amd->regs + AMD7930_BBTB);
517-
} else if (amd->flags & AMD7930_FLAG_CAPTURE) {
518-
byte = sbus_readb(amd->regs + AMD7930_BBRB);
519-
if (amd->c_left > 0) {
520-
*(amd->c_cur++) = byte;
521-
amd->c_left--;
522-
if (amd->c_left == 0)
523-
elapsed |= AMD7930_FLAG_CAPTURE;
491+
scoped_guard(spinlock, &amd->lock) {
492+
elapsed = 0;
493+
494+
ir = sbus_readb(amd->regs + AMD7930_IR);
495+
if (ir & AMR_IR_BBUF) {
496+
u8 byte;
497+
498+
if (amd->flags & AMD7930_FLAG_PLAYBACK) {
499+
if (amd->p_left > 0) {
500+
byte = *(amd->p_cur++);
501+
amd->p_left--;
502+
sbus_writeb(byte, amd->regs + AMD7930_BBTB);
503+
if (amd->p_left == 0)
504+
elapsed |= AMD7930_FLAG_PLAYBACK;
505+
} else
506+
sbus_writeb(0, amd->regs + AMD7930_BBTB);
507+
} else if (amd->flags & AMD7930_FLAG_CAPTURE) {
508+
byte = sbus_readb(amd->regs + AMD7930_BBRB);
509+
if (amd->c_left > 0) {
510+
*(amd->c_cur++) = byte;
511+
amd->c_left--;
512+
if (amd->c_left == 0)
513+
elapsed |= AMD7930_FLAG_CAPTURE;
514+
}
524515
}
525516
}
526517
}
527-
spin_unlock(&amd->lock);
528518

529519
if (elapsed & AMD7930_FLAG_PLAYBACK)
530520
snd_pcm_period_elapsed(amd->playback_substream);
@@ -536,10 +526,9 @@ static irqreturn_t snd_amd7930_interrupt(int irq, void *dev_id)
536526

537527
static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int cmd)
538528
{
539-
unsigned long flags;
540529
int result = 0;
541530

542-
spin_lock_irqsave(&amd->lock, flags);
531+
guard(spinlock_irqsave)(&amd->lock);
543532
if (cmd == SNDRV_PCM_TRIGGER_START) {
544533
if (!(amd->flags & flag)) {
545534
amd->flags |= flag;
@@ -559,7 +548,6 @@ static int snd_amd7930_trigger(struct snd_amd7930 *amd, unsigned int flag, int c
559548
} else {
560549
result = -EINVAL;
561550
}
562-
spin_unlock_irqrestore(&amd->lock, flags);
563551

564552
return result;
565553
}
@@ -583,10 +571,9 @@ static int snd_amd7930_playback_prepare(struct snd_pcm_substream *substream)
583571
struct snd_amd7930 *amd = snd_pcm_substream_chip(substream);
584572
struct snd_pcm_runtime *runtime = substream->runtime;
585573
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
586-
unsigned long flags;
587574
u8 new_mmr1;
588575

589-
spin_lock_irqsave(&amd->lock, flags);
576+
guard(spinlock_irqsave)(&amd->lock);
590577

591578
amd->flags |= AMD7930_FLAG_PLAYBACK;
592579

@@ -605,8 +592,6 @@ static int snd_amd7930_playback_prepare(struct snd_pcm_substream *substream)
605592
__amd7930_update_map(amd);
606593
}
607594

608-
spin_unlock_irqrestore(&amd->lock, flags);
609-
610595
return 0;
611596
}
612597

@@ -615,10 +600,9 @@ static int snd_amd7930_capture_prepare(struct snd_pcm_substream *substream)
615600
struct snd_amd7930 *amd = snd_pcm_substream_chip(substream);
616601
struct snd_pcm_runtime *runtime = substream->runtime;
617602
unsigned int size = snd_pcm_lib_buffer_bytes(substream);
618-
unsigned long flags;
619603
u8 new_mmr1;
620604

621-
spin_lock_irqsave(&amd->lock, flags);
605+
guard(spinlock_irqsave)(&amd->lock);
622606

623607
amd->flags |= AMD7930_FLAG_CAPTURE;
624608

@@ -637,8 +621,6 @@ static int snd_amd7930_capture_prepare(struct snd_pcm_substream *substream)
637621
__amd7930_update_map(amd);
638622
}
639623

640-
spin_unlock_irqrestore(&amd->lock, flags);
641-
642624
return 0;
643625
}
644626

@@ -805,7 +787,6 @@ static int snd_amd7930_get_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem
805787
static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem_value *ucontrol)
806788
{
807789
struct snd_amd7930 *amd = snd_kcontrol_chip(kctl);
808-
unsigned long flags;
809790
int type = kctl->private_value;
810791
int *swval, change;
811792

@@ -822,7 +803,7 @@ static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem
822803
break;
823804
}
824805

825-
spin_lock_irqsave(&amd->lock, flags);
806+
guard(spinlock_irqsave)(&amd->lock);
826807

827808
if (*swval != ucontrol->value.integer.value[0]) {
828809
*swval = ucontrol->value.integer.value[0] & 0xff;
@@ -831,8 +812,6 @@ static int snd_amd7930_put_volume(struct snd_kcontrol *kctl, struct snd_ctl_elem
831812
} else
832813
change = 0;
833814

834-
spin_unlock_irqrestore(&amd->lock, flags);
835-
836815
return change;
837816
}
838817

@@ -921,7 +900,6 @@ static int snd_amd7930_create(struct snd_card *card,
921900
struct snd_amd7930 **ramd)
922901
{
923902
struct snd_amd7930 *amd;
924-
unsigned long flags;
925903
int err;
926904

927905
*ramd = NULL;
@@ -955,25 +933,23 @@ static int snd_amd7930_create(struct snd_card *card,
955933

956934
amd7930_enable_ints(amd);
957935

958-
spin_lock_irqsave(&amd->lock, flags);
959-
960-
amd->rgain = 128;
961-
amd->pgain = 200;
962-
amd->mgain = 0;
963-
964-
memset(&amd->map, 0, sizeof(amd->map));
965-
amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER |
966-
AM_MAP_MMR1_GR | AM_MAP_MMR1_STG);
967-
amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB);
936+
scoped_guard(spinlock_irqsave, &amd->lock) {
937+
amd->rgain = 128;
938+
amd->pgain = 200;
939+
amd->mgain = 0;
968940

969-
__amd7930_update_map(amd);
941+
memset(&amd->map, 0, sizeof(amd->map));
942+
amd->map.mmr1 = (AM_MAP_MMR1_GX | AM_MAP_MMR1_GER |
943+
AM_MAP_MMR1_GR | AM_MAP_MMR1_STG);
944+
amd->map.mmr2 = (AM_MAP_MMR2_LS | AM_MAP_MMR2_AINB);
970945

971-
/* Always MUX audio (Ba) to channel Bb. */
972-
sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR);
973-
sbus_writeb(AM_MUX_CHANNEL_Ba | (AM_MUX_CHANNEL_Bb << 4),
974-
amd->regs + AMD7930_DR);
946+
__amd7930_update_map(amd);
975947

976-
spin_unlock_irqrestore(&amd->lock, flags);
948+
/* Always MUX audio (Ba) to channel Bb. */
949+
sbus_writeb(AMR_MUX_MCR1, amd->regs + AMD7930_CR);
950+
sbus_writeb(AM_MUX_CHANNEL_Ba | (AM_MUX_CHANNEL_Bb << 4),
951+
amd->regs + AMD7930_DR);
952+
}
977953

978954
err = snd_device_new(card, SNDRV_DEV_LOWLEVEL,
979955
amd, &snd_amd7930_dev_ops);

0 commit comments

Comments
 (0)