mirror of
https://github.com/torvalds/linux.git
synced 2025-12-01 07:26:02 +07:00
ALSA: ppc: 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>
This commit is contained in:
@@ -137,13 +137,11 @@ static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
|
|||||||
int reg = kcontrol->private_value & 0xff;
|
int reg = kcontrol->private_value & 0xff;
|
||||||
int lshift = (kcontrol->private_value >> 8) & 0xff;
|
int lshift = (kcontrol->private_value >> 8) & 0xff;
|
||||||
int inverted = (kcontrol->private_value >> 16) & 1;
|
int inverted = (kcontrol->private_value >> 16) & 1;
|
||||||
unsigned long flags;
|
|
||||||
int vol[2];
|
int vol[2];
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
|
vol[0] = (chip->awacs_reg[reg] >> lshift) & 0xf;
|
||||||
vol[1] = chip->awacs_reg[reg] & 0xf;
|
vol[1] = chip->awacs_reg[reg] & 0xf;
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
if (inverted) {
|
if (inverted) {
|
||||||
vol[0] = 0x0f - vol[0];
|
vol[0] = 0x0f - vol[0];
|
||||||
vol[1] = 0x0f - vol[1];
|
vol[1] = 0x0f - vol[1];
|
||||||
@@ -161,7 +159,6 @@ static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
|
|||||||
int lshift = (kcontrol->private_value >> 8) & 0xff;
|
int lshift = (kcontrol->private_value >> 8) & 0xff;
|
||||||
int inverted = (kcontrol->private_value >> 16) & 1;
|
int inverted = (kcontrol->private_value >> 16) & 1;
|
||||||
int val, oldval;
|
int val, oldval;
|
||||||
unsigned long flags;
|
|
||||||
unsigned int vol[2];
|
unsigned int vol[2];
|
||||||
|
|
||||||
vol[0] = ucontrol->value.integer.value[0];
|
vol[0] = ucontrol->value.integer.value[0];
|
||||||
@@ -174,14 +171,13 @@ static int snd_pmac_awacs_put_volume(struct snd_kcontrol *kcontrol,
|
|||||||
}
|
}
|
||||||
vol[0] &= 0x0f;
|
vol[0] &= 0x0f;
|
||||||
vol[1] &= 0x0f;
|
vol[1] &= 0x0f;
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
oldval = chip->awacs_reg[reg];
|
oldval = chip->awacs_reg[reg];
|
||||||
val = oldval & ~(0xf | (0xf << lshift));
|
val = oldval & ~(0xf | (0xf << lshift));
|
||||||
val |= vol[0] << lshift;
|
val |= vol[0] << lshift;
|
||||||
val |= vol[1];
|
val |= vol[1];
|
||||||
if (oldval != val)
|
if (oldval != val)
|
||||||
snd_pmac_awacs_write_reg(chip, reg, val);
|
snd_pmac_awacs_write_reg(chip, reg, val);
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return oldval != reg;
|
return oldval != reg;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,11 +200,9 @@ static int snd_pmac_awacs_get_switch(struct snd_kcontrol *kcontrol,
|
|||||||
int shift = (kcontrol->private_value >> 8) & 0xff;
|
int shift = (kcontrol->private_value >> 8) & 0xff;
|
||||||
int invert = (kcontrol->private_value >> 16) & 1;
|
int invert = (kcontrol->private_value >> 16) & 1;
|
||||||
int val;
|
int val;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
val = (chip->awacs_reg[reg] >> shift) & 1;
|
val = (chip->awacs_reg[reg] >> shift) & 1;
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
if (invert)
|
if (invert)
|
||||||
val = 1 - val;
|
val = 1 - val;
|
||||||
ucontrol->value.integer.value[0] = val;
|
ucontrol->value.integer.value[0] = val;
|
||||||
@@ -224,16 +218,14 @@ static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
|
|||||||
int invert = (kcontrol->private_value >> 16) & 1;
|
int invert = (kcontrol->private_value >> 16) & 1;
|
||||||
int mask = 1 << shift;
|
int mask = 1 << shift;
|
||||||
int val, changed;
|
int val, changed;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
val = chip->awacs_reg[reg] & ~mask;
|
val = chip->awacs_reg[reg] & ~mask;
|
||||||
if (ucontrol->value.integer.value[0] != invert)
|
if (ucontrol->value.integer.value[0] != invert)
|
||||||
val |= mask;
|
val |= mask;
|
||||||
changed = chip->awacs_reg[reg] != val;
|
changed = chip->awacs_reg[reg] != val;
|
||||||
if (changed)
|
if (changed)
|
||||||
snd_pmac_awacs_write_reg(chip, reg, val);
|
snd_pmac_awacs_write_reg(chip, reg, val);
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -541,14 +533,12 @@ static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
|
|||||||
{
|
{
|
||||||
struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
|
struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
|
||||||
int val = 0;
|
int val = 0;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
if (chip->awacs_reg[6] & MASK_MIC_BOOST)
|
if (chip->awacs_reg[6] & MASK_MIC_BOOST)
|
||||||
val |= 2;
|
val |= 2;
|
||||||
if (chip->awacs_reg[0] & MASK_GAINLINE)
|
if (chip->awacs_reg[0] & MASK_GAINLINE)
|
||||||
val |= 1;
|
val |= 1;
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
ucontrol->value.integer.value[0] = val;
|
ucontrol->value.integer.value[0] = val;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -559,9 +549,8 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
|
|||||||
struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
|
struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
|
||||||
int changed = 0;
|
int changed = 0;
|
||||||
int val0, val6;
|
int val0, val6;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
|
val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
|
||||||
val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
|
val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
|
||||||
if (ucontrol->value.integer.value[0] & 1)
|
if (ucontrol->value.integer.value[0] & 1)
|
||||||
@@ -576,7 +565,6 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
|
|||||||
snd_pmac_awacs_write_reg(chip, 6, val6);
|
snd_pmac_awacs_write_reg(chip, 6, val6);
|
||||||
changed = 1;
|
changed = 1;
|
||||||
}
|
}
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
|
|||||||
{
|
{
|
||||||
struct snd_pmac *chip;
|
struct snd_pmac *chip;
|
||||||
struct pmac_beep *beep;
|
struct pmac_beep *beep;
|
||||||
unsigned long flags;
|
|
||||||
int beep_speed = 0;
|
int beep_speed = 0;
|
||||||
int srate;
|
int srate;
|
||||||
int period, ncycles, nsamples;
|
int period, ncycles, nsamples;
|
||||||
@@ -112,10 +111,9 @@ static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
|
|||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (! hz) {
|
if (! hz) {
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
if (beep->running)
|
if (beep->running)
|
||||||
snd_pmac_beep_stop(chip);
|
snd_pmac_beep_stop(chip);
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -125,13 +123,11 @@ static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
|
|||||||
if (hz <= srate / BEEP_BUFLEN || hz > srate / 2)
|
if (hz <= srate / BEEP_BUFLEN || hz > srate / 2)
|
||||||
hz = 1000;
|
hz = 1000;
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
scoped_guard(spinlock_irqsave, &chip->reg_lock) {
|
||||||
if (chip->playback.running || chip->capture.running || beep->running) {
|
if (chip->playback.running || chip->capture.running || beep->running)
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
beep->running = 1;
|
beep->running = 1;
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
}
|
||||||
|
|
||||||
if (hz == beep->hz && beep->volume == beep->volume_play) {
|
if (hz == beep->hz && beep->volume == beep->volume_play) {
|
||||||
nsamples = beep->nsamples;
|
nsamples = beep->nsamples;
|
||||||
@@ -151,9 +147,8 @@ static int snd_pmac_beep_event(struct input_dev *dev, unsigned int type,
|
|||||||
beep->nsamples = nsamples;
|
beep->nsamples = nsamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
snd_pmac_beep_dma_start(chip, beep->nsamples * 4, beep->addr, beep_speed);
|
snd_pmac_beep_dma_start(chip, beep->nsamples * 4, beep->addr, beep_speed);
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -59,9 +59,8 @@ static unsigned
|
|||||||
snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
|
snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
|
||||||
{
|
{
|
||||||
unsigned val = 0;
|
unsigned val = 0;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
|
|
||||||
out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
|
out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
|
||||||
snd_pmac_burgundy_busy_wait(chip);
|
snd_pmac_burgundy_busy_wait(chip);
|
||||||
@@ -83,8 +82,6 @@ snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
|
|||||||
snd_pmac_burgundy_extend_wait(chip);
|
snd_pmac_burgundy_extend_wait(chip);
|
||||||
val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24;
|
val += ((in_le32(&chip->awacs->codec_stat)>>4) & 0xff) <<24;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -100,17 +97,14 @@ static unsigned
|
|||||||
snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
|
snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
|
||||||
{
|
{
|
||||||
unsigned val = 0;
|
unsigned val = 0;
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
guard(spinlock_irqsave)(&chip->reg_lock);
|
||||||
|
|
||||||
out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
|
out_le32(&chip->awacs->codec_ctrl, addr + 0x100000);
|
||||||
snd_pmac_burgundy_busy_wait(chip);
|
snd_pmac_burgundy_busy_wait(chip);
|
||||||
snd_pmac_burgundy_extend_wait(chip);
|
snd_pmac_burgundy_extend_wait(chip);
|
||||||
val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
|
val += (in_le32(&chip->awacs->codec_stat) >> 4) & 0xff;
|
||||||
|
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
|
||||||
|
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -206,14 +206,14 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
|
|||||||
* common to many PowerBook G3 systems and random noise otherwise
|
* common to many PowerBook G3 systems and random noise otherwise
|
||||||
* captured on iBook2's about every third time. -ReneR
|
* captured on iBook2's about every third time. -ReneR
|
||||||
*/
|
*/
|
||||||
spin_lock_irq(&chip->reg_lock);
|
scoped_guard(spinlock_irq, &chip->reg_lock) {
|
||||||
snd_pmac_dma_stop(rec);
|
snd_pmac_dma_stop(rec);
|
||||||
chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
|
chip->extra_dma.cmds->command = cpu_to_le16(DBDMA_STOP);
|
||||||
snd_pmac_dma_set_command(rec, &chip->extra_dma);
|
snd_pmac_dma_set_command(rec, &chip->extra_dma);
|
||||||
snd_pmac_dma_run(rec, RUN);
|
snd_pmac_dma_run(rec, RUN);
|
||||||
spin_unlock_irq(&chip->reg_lock);
|
}
|
||||||
mdelay(5);
|
mdelay(5);
|
||||||
spin_lock_irq(&chip->reg_lock);
|
scoped_guard(spinlock_irq, &chip->reg_lock) {
|
||||||
/* continuous DMA memory type doesn't provide the physical address,
|
/* continuous DMA memory type doesn't provide the physical address,
|
||||||
* so we need to resolve the address here...
|
* so we need to resolve the address here...
|
||||||
*/
|
*/
|
||||||
@@ -231,7 +231,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
|
|||||||
|
|
||||||
snd_pmac_dma_stop(rec);
|
snd_pmac_dma_stop(rec);
|
||||||
snd_pmac_dma_set_command(rec, &rec->cmd);
|
snd_pmac_dma_set_command(rec, &rec->cmd);
|
||||||
spin_unlock_irq(&chip->reg_lock);
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -253,7 +253,7 @@ static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec,
|
|||||||
return -EBUSY;
|
return -EBUSY;
|
||||||
command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ?
|
command = (subs->stream == SNDRV_PCM_STREAM_PLAYBACK ?
|
||||||
OUTPUT_MORE : INPUT_MORE) + INTR_ALWAYS;
|
OUTPUT_MORE : INPUT_MORE) + INTR_ALWAYS;
|
||||||
spin_lock(&chip->reg_lock);
|
scoped_guard(spinlock, &chip->reg_lock) {
|
||||||
snd_pmac_beep_stop(chip);
|
snd_pmac_beep_stop(chip);
|
||||||
snd_pmac_pcm_set_format(chip);
|
snd_pmac_pcm_set_format(chip);
|
||||||
for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++)
|
for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++)
|
||||||
@@ -262,17 +262,17 @@ static int snd_pmac_pcm_trigger(struct snd_pmac *chip, struct pmac_stream *rec,
|
|||||||
(void)in_le32(&rec->dma->status);
|
(void)in_le32(&rec->dma->status);
|
||||||
snd_pmac_dma_run(rec, RUN|WAKE);
|
snd_pmac_dma_run(rec, RUN|WAKE);
|
||||||
rec->running = 1;
|
rec->running = 1;
|
||||||
spin_unlock(&chip->reg_lock);
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SNDRV_PCM_TRIGGER_STOP:
|
case SNDRV_PCM_TRIGGER_STOP:
|
||||||
case SNDRV_PCM_TRIGGER_SUSPEND:
|
case SNDRV_PCM_TRIGGER_SUSPEND:
|
||||||
spin_lock(&chip->reg_lock);
|
scoped_guard(spinlock, &chip->reg_lock) {
|
||||||
rec->running = 0;
|
rec->running = 0;
|
||||||
snd_pmac_dma_stop(rec);
|
snd_pmac_dma_stop(rec);
|
||||||
for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++)
|
for (i = 0, cp = rec->cmd.cmds; i < rec->nperiods; i++, cp++)
|
||||||
out_le16(&cp->command, DBDMA_STOP);
|
out_le16(&cp->command, DBDMA_STOP);
|
||||||
spin_unlock(&chip->reg_lock);
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -1321,14 +1321,12 @@ int snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
|
|||||||
|
|
||||||
void snd_pmac_suspend(struct snd_pmac *chip)
|
void snd_pmac_suspend(struct snd_pmac *chip)
|
||||||
{
|
{
|
||||||
unsigned long flags;
|
|
||||||
|
|
||||||
snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
|
snd_power_change_state(chip->card, SNDRV_CTL_POWER_D3hot);
|
||||||
if (chip->suspend)
|
if (chip->suspend)
|
||||||
chip->suspend(chip);
|
chip->suspend(chip);
|
||||||
spin_lock_irqsave(&chip->reg_lock, flags);
|
scoped_guard(spinlock_irqsave, &chip->reg_lock) {
|
||||||
snd_pmac_beep_stop(chip);
|
snd_pmac_beep_stop(chip);
|
||||||
spin_unlock_irqrestore(&chip->reg_lock, flags);
|
}
|
||||||
if (chip->irq >= 0)
|
if (chip->irq >= 0)
|
||||||
disable_irq(chip->irq);
|
disable_irq(chip->irq);
|
||||||
if (chip->tx_irq >= 0)
|
if (chip->tx_irq >= 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user