Skip to content

Commit 3c30d57

Browse files
committed
ALSA: sparc/dbri: 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 4baca4b commit 3c30d57

1 file changed

Lines changed: 109 additions & 123 deletions

File tree

sound/sparc/dbri.c

Lines changed: 109 additions & 123 deletions
Original file line numberDiff line numberDiff line change
@@ -758,40 +758,38 @@ static void dbri_initialize(struct snd_dbri *dbri)
758758
u32 dvma_addr = (u32)dbri->dma_dvma;
759759
s32 *cmd;
760760
u32 dma_addr;
761-
unsigned long flags;
762761
int n;
763762

764-
spin_lock_irqsave(&dbri->lock, flags);
765-
766-
dbri_reset(dbri);
763+
scoped_guard(spinlock_irqsave, &dbri->lock) {
764+
dbri_reset(dbri);
767765

768-
/* Initialize pipes */
769-
for (n = 0; n < DBRI_NO_PIPES; n++)
770-
dbri->pipes[n].desc = dbri->pipes[n].first_desc = -1;
766+
/* Initialize pipes */
767+
for (n = 0; n < DBRI_NO_PIPES; n++)
768+
dbri->pipes[n].desc = dbri->pipes[n].first_desc = -1;
771769

772-
spin_lock_init(&dbri->cmdlock);
773-
/*
774-
* Initialize the interrupt ring buffer.
775-
*/
776-
dma_addr = dvma_addr + dbri_dma_off(intr, 0);
777-
dbri->dma->intr[0] = dma_addr;
778-
dbri->dbri_irqp = 1;
779-
/*
780-
* Set up the interrupt queue
781-
*/
782-
spin_lock(&dbri->cmdlock);
783-
cmd = dbri->cmdptr = dbri->dma->cmd;
784-
*(cmd++) = DBRI_CMD(D_IIQ, 0, 0);
785-
*(cmd++) = dma_addr;
786-
*(cmd++) = DBRI_CMD(D_PAUSE, 0, 0);
787-
dbri->cmdptr = cmd;
788-
*(cmd++) = DBRI_CMD(D_WAIT, 1, 0);
789-
*(cmd++) = DBRI_CMD(D_WAIT, 1, 0);
790-
dma_addr = dvma_addr + dbri_dma_off(cmd, 0);
791-
sbus_writel(dma_addr, dbri->regs + REG8);
792-
spin_unlock(&dbri->cmdlock);
770+
spin_lock_init(&dbri->cmdlock);
771+
/*
772+
* Initialize the interrupt ring buffer.
773+
*/
774+
dma_addr = dvma_addr + dbri_dma_off(intr, 0);
775+
dbri->dma->intr[0] = dma_addr;
776+
dbri->dbri_irqp = 1;
777+
/*
778+
* Set up the interrupt queue
779+
*/
780+
scoped_guard(spinlock, &dbri->cmdlock) {
781+
cmd = dbri->cmdptr = dbri->dma->cmd;
782+
*(cmd++) = DBRI_CMD(D_IIQ, 0, 0);
783+
*(cmd++) = dma_addr;
784+
*(cmd++) = DBRI_CMD(D_PAUSE, 0, 0);
785+
dbri->cmdptr = cmd;
786+
*(cmd++) = DBRI_CMD(D_WAIT, 1, 0);
787+
*(cmd++) = DBRI_CMD(D_WAIT, 1, 0);
788+
dma_addr = dvma_addr + dbri_dma_off(cmd, 0);
789+
sbus_writel(dma_addr, dbri->regs + REG8);
790+
}
791+
}
793792

794-
spin_unlock_irqrestore(&dbri->lock, flags);
795793
dbri_cmdwait(dbri);
796794
}
797795

@@ -1002,7 +1000,6 @@ static void unlink_time_slot(struct snd_dbri *dbri, int pipe,
10021000
static void xmit_fixed(struct snd_dbri *dbri, int pipe, unsigned int data)
10031001
{
10041002
s32 *cmd;
1005-
unsigned long flags;
10061003

10071004
if (pipe < 16 || pipe > DBRI_MAX_PIPE) {
10081005
printk(KERN_ERR "DBRI: xmit_fixed: Illegal pipe number\n");
@@ -1037,9 +1034,10 @@ static void xmit_fixed(struct snd_dbri *dbri, int pipe, unsigned int data)
10371034
*(cmd++) = data;
10381035
*(cmd++) = DBRI_CMD(D_PAUSE, 0, 0);
10391036

1040-
spin_lock_irqsave(&dbri->lock, flags);
1041-
dbri_cmdsend(dbri, cmd, 3);
1042-
spin_unlock_irqrestore(&dbri->lock, flags);
1037+
scoped_guard(spinlock_irqsave, &dbri->lock) {
1038+
dbri_cmdsend(dbri, cmd, 3);
1039+
}
1040+
10431041
dbri_cmdwait(dbri);
10441042

10451043
}
@@ -1317,33 +1315,31 @@ to the DBRI via the CHI interface and few of the DBRI's PIO pins.
13171315
*/
13181316
static void cs4215_setup_pipes(struct snd_dbri *dbri)
13191317
{
1320-
unsigned long flags;
1321-
1322-
spin_lock_irqsave(&dbri->lock, flags);
1323-
/*
1324-
* Data mode:
1325-
* Pipe 4: Send timeslots 1-4 (audio data)
1326-
* Pipe 20: Send timeslots 5-8 (part of ctrl data)
1327-
* Pipe 6: Receive timeslots 1-4 (audio data)
1328-
* Pipe 21: Receive timeslots 6-7. We can only receive 20 bits via
1329-
* interrupt, and the rest of the data (slot 5 and 8) is
1330-
* not relevant for us (only for doublechecking).
1331-
*
1332-
* Control mode:
1333-
* Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1334-
* Pipe 18: Receive timeslot 1 (clb).
1335-
* Pipe 19: Receive timeslot 7 (version).
1336-
*/
1318+
scoped_guard(spinlock_irqsave, &dbri->lock) {
1319+
/*
1320+
* Data mode:
1321+
* Pipe 4: Send timeslots 1-4 (audio data)
1322+
* Pipe 20: Send timeslots 5-8 (part of ctrl data)
1323+
* Pipe 6: Receive timeslots 1-4 (audio data)
1324+
* Pipe 21: Receive timeslots 6-7. We can only receive 20 bits via
1325+
* interrupt, and the rest of the data (slot 5 and 8) is
1326+
* not relevant for us (only for doublechecking).
1327+
*
1328+
* Control mode:
1329+
* Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1330+
* Pipe 18: Receive timeslot 1 (clb).
1331+
* Pipe 19: Receive timeslot 7 (version).
1332+
*/
13371333

1338-
setup_pipe(dbri, 4, D_SDP_MEM | D_SDP_TO_SER | D_SDP_MSB);
1339-
setup_pipe(dbri, 20, D_SDP_FIXED | D_SDP_TO_SER | D_SDP_MSB);
1340-
setup_pipe(dbri, 6, D_SDP_MEM | D_SDP_FROM_SER | D_SDP_MSB);
1341-
setup_pipe(dbri, 21, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
1334+
setup_pipe(dbri, 4, D_SDP_MEM | D_SDP_TO_SER | D_SDP_MSB);
1335+
setup_pipe(dbri, 20, D_SDP_FIXED | D_SDP_TO_SER | D_SDP_MSB);
1336+
setup_pipe(dbri, 6, D_SDP_MEM | D_SDP_FROM_SER | D_SDP_MSB);
1337+
setup_pipe(dbri, 21, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
13421338

1343-
setup_pipe(dbri, 17, D_SDP_FIXED | D_SDP_TO_SER | D_SDP_MSB);
1344-
setup_pipe(dbri, 18, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
1345-
setup_pipe(dbri, 19, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
1346-
spin_unlock_irqrestore(&dbri->lock, flags);
1339+
setup_pipe(dbri, 17, D_SDP_FIXED | D_SDP_TO_SER | D_SDP_MSB);
1340+
setup_pipe(dbri, 18, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
1341+
setup_pipe(dbri, 19, D_SDP_FIXED | D_SDP_FROM_SER | D_SDP_MSB);
1342+
}
13471343

13481344
dbri_cmdwait(dbri);
13491345
}
@@ -1418,7 +1414,6 @@ static void cs4215_open(struct snd_dbri *dbri)
14181414
{
14191415
int data_width;
14201416
u32 tmp;
1421-
unsigned long flags;
14221417

14231418
dprintk(D_MM, "cs4215_open: %d channels, %d bits\n",
14241419
dbri->mm.channels, dbri->mm.precision);
@@ -1443,35 +1438,35 @@ static void cs4215_open(struct snd_dbri *dbri)
14431438
* bits. The CS4215, it seems, observes TSIN (the delayed signal)
14441439
* even if it's the CHI master. Don't ask me...
14451440
*/
1446-
spin_lock_irqsave(&dbri->lock, flags);
1447-
tmp = sbus_readl(dbri->regs + REG0);
1448-
tmp &= ~(D_C); /* Disable CHI */
1449-
sbus_writel(tmp, dbri->regs + REG0);
1441+
scoped_guard(spinlock_irqsave, &dbri->lock) {
1442+
tmp = sbus_readl(dbri->regs + REG0);
1443+
tmp &= ~(D_C); /* Disable CHI */
1444+
sbus_writel(tmp, dbri->regs + REG0);
14501445

1451-
/* Switch CS4215 to data mode - set PIO3 to 1 */
1452-
sbus_writel(D_ENPIO | D_PIO1 | D_PIO3 |
1453-
(dbri->mm.onboard ? D_PIO0 : D_PIO2), dbri->regs + REG2);
1446+
/* Switch CS4215 to data mode - set PIO3 to 1 */
1447+
sbus_writel(D_ENPIO | D_PIO1 | D_PIO3 |
1448+
(dbri->mm.onboard ? D_PIO0 : D_PIO2), dbri->regs + REG2);
14541449

1455-
reset_chi(dbri, CHIslave, 128);
1450+
reset_chi(dbri, CHIslave, 128);
14561451

1457-
/* Note: this next doesn't work for 8-bit stereo, because the two
1458-
* channels would be on timeslots 1 and 3, with 2 and 4 idle.
1459-
* (See CS4215 datasheet Fig 15)
1460-
*
1461-
* DBRI non-contiguous mode would be required to make this work.
1462-
*/
1463-
data_width = dbri->mm.channels * dbri->mm.precision;
1452+
/* Note: this next doesn't work for 8-bit stereo, because the two
1453+
* channels would be on timeslots 1 and 3, with 2 and 4 idle.
1454+
* (See CS4215 datasheet Fig 15)
1455+
*
1456+
* DBRI non-contiguous mode would be required to make this work.
1457+
*/
1458+
data_width = dbri->mm.channels * dbri->mm.precision;
14641459

1465-
link_time_slot(dbri, 4, 16, 16, data_width, dbri->mm.offset);
1466-
link_time_slot(dbri, 20, 4, 16, 32, dbri->mm.offset + 32);
1467-
link_time_slot(dbri, 6, 16, 16, data_width, dbri->mm.offset);
1468-
link_time_slot(dbri, 21, 6, 16, 16, dbri->mm.offset + 40);
1460+
link_time_slot(dbri, 4, 16, 16, data_width, dbri->mm.offset);
1461+
link_time_slot(dbri, 20, 4, 16, 32, dbri->mm.offset + 32);
1462+
link_time_slot(dbri, 6, 16, 16, data_width, dbri->mm.offset);
1463+
link_time_slot(dbri, 21, 6, 16, 16, dbri->mm.offset + 40);
14691464

1470-
/* FIXME: enable CHI after _setdata? */
1471-
tmp = sbus_readl(dbri->regs + REG0);
1472-
tmp |= D_C; /* Enable CHI */
1473-
sbus_writel(tmp, dbri->regs + REG0);
1474-
spin_unlock_irqrestore(&dbri->lock, flags);
1465+
/* FIXME: enable CHI after _setdata? */
1466+
tmp = sbus_readl(dbri->regs + REG0);
1467+
tmp |= D_C; /* Enable CHI */
1468+
sbus_writel(tmp, dbri->regs + REG0);
1469+
}
14751470

14761471
cs4215_setdata(dbri, 0);
14771472
}
@@ -1483,7 +1478,6 @@ static int cs4215_setctrl(struct snd_dbri *dbri)
14831478
{
14841479
int i, val;
14851480
u32 tmp;
1486-
unsigned long flags;
14871481

14881482
/* FIXME - let the CPU do something useful during these delays */
14891483

@@ -1520,34 +1514,34 @@ static int cs4215_setctrl(struct snd_dbri *dbri)
15201514
* done in hardware by a TI 248 that delays the DBRI->4215
15211515
* frame sync signal by eight clock cycles. Anybody know why?
15221516
*/
1523-
spin_lock_irqsave(&dbri->lock, flags);
1524-
tmp = sbus_readl(dbri->regs + REG0);
1525-
tmp &= ~D_C; /* Disable CHI */
1526-
sbus_writel(tmp, dbri->regs + REG0);
1527-
1528-
reset_chi(dbri, CHImaster, 128);
1529-
1530-
/*
1531-
* Control mode:
1532-
* Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1533-
* Pipe 18: Receive timeslot 1 (clb).
1534-
* Pipe 19: Receive timeslot 7 (version).
1535-
*/
1517+
scoped_guard(spinlock_irqsave, &dbri->lock) {
1518+
tmp = sbus_readl(dbri->regs + REG0);
1519+
tmp &= ~D_C; /* Disable CHI */
1520+
sbus_writel(tmp, dbri->regs + REG0);
1521+
1522+
reset_chi(dbri, CHImaster, 128);
1523+
1524+
/*
1525+
* Control mode:
1526+
* Pipe 17: Send timeslots 1-4 (slots 5-8 are read only)
1527+
* Pipe 18: Receive timeslot 1 (clb).
1528+
* Pipe 19: Receive timeslot 7 (version).
1529+
*/
15361530

1537-
link_time_slot(dbri, 17, 16, 16, 32, dbri->mm.offset);
1538-
link_time_slot(dbri, 18, 16, 16, 8, dbri->mm.offset);
1539-
link_time_slot(dbri, 19, 18, 16, 8, dbri->mm.offset + 48);
1540-
spin_unlock_irqrestore(&dbri->lock, flags);
1531+
link_time_slot(dbri, 17, 16, 16, 32, dbri->mm.offset);
1532+
link_time_slot(dbri, 18, 16, 16, 8, dbri->mm.offset);
1533+
link_time_slot(dbri, 19, 18, 16, 8, dbri->mm.offset + 48);
1534+
}
15411535

15421536
/* Wait for the chip to echo back CLB (Control Latch Bit) as zero */
15431537
dbri->mm.ctrl[0] &= ~CS4215_CLB;
15441538
xmit_fixed(dbri, 17, *(int *)dbri->mm.ctrl);
15451539

1546-
spin_lock_irqsave(&dbri->lock, flags);
1547-
tmp = sbus_readl(dbri->regs + REG0);
1548-
tmp |= D_C; /* Enable CHI */
1549-
sbus_writel(tmp, dbri->regs + REG0);
1550-
spin_unlock_irqrestore(&dbri->lock, flags);
1540+
scoped_guard(spinlock_irqsave, &dbri->lock) {
1541+
tmp = sbus_readl(dbri->regs + REG0);
1542+
tmp |= D_C; /* Enable CHI */
1543+
sbus_writel(tmp, dbri->regs + REG0);
1544+
}
15511545

15521546
for (i = 10; ((dbri->mm.status & 0xe4) != 0x20); --i)
15531547
msleep_interruptible(1);
@@ -1709,15 +1703,14 @@ static void xmit_descs(struct snd_dbri *dbri)
17091703
struct dbri_streaminfo *info;
17101704
u32 dvma_addr;
17111705
s32 *cmd;
1712-
unsigned long flags;
17131706
int first_td;
17141707

17151708
if (dbri == NULL)
17161709
return; /* Disabled */
17171710

17181711
dvma_addr = (u32)dbri->dma_dvma;
17191712
info = &dbri->stream_info[DBRI_REC];
1720-
spin_lock_irqsave(&dbri->lock, flags);
1713+
guard(spinlock_irqsave)(&dbri->lock);
17211714

17221715
if (info->pipe >= 0) {
17231716
first_td = dbri->pipes[info->pipe].first_desc;
@@ -1760,8 +1753,6 @@ static void xmit_descs(struct snd_dbri *dbri)
17601753
dbri->pipes[info->pipe].desc = first_td;
17611754
}
17621755
}
1763-
1764-
spin_unlock_irqrestore(&dbri->lock, flags);
17651756
}
17661757

17671758
/* transmission_complete_intr()
@@ -1932,7 +1923,7 @@ static irqreturn_t snd_dbri_interrupt(int irq, void *dev_id)
19321923

19331924
if (dbri == NULL)
19341925
return IRQ_NONE;
1935-
spin_lock(&dbri->lock);
1926+
guard(spinlock)(&dbri->lock);
19361927

19371928
/*
19381929
* Read it, so the interrupt goes away.
@@ -1977,8 +1968,6 @@ static irqreturn_t snd_dbri_interrupt(int irq, void *dev_id)
19771968

19781969
dbri_process_interrupt_buffer(dbri);
19791970

1980-
spin_unlock(&dbri->lock);
1981-
19821971
return IRQ_HANDLED;
19831972
}
19841973

@@ -2046,17 +2035,16 @@ static int snd_dbri_open(struct snd_pcm_substream *substream)
20462035
struct snd_dbri *dbri = snd_pcm_substream_chip(substream);
20472036
struct snd_pcm_runtime *runtime = substream->runtime;
20482037
struct dbri_streaminfo *info = DBRI_STREAM(dbri, substream);
2049-
unsigned long flags;
20502038

20512039
dprintk(D_USR, "open audio output.\n");
20522040
runtime->hw = snd_dbri_pcm_hw;
20532041

2054-
spin_lock_irqsave(&dbri->lock, flags);
2055-
info->substream = substream;
2056-
info->offset = 0;
2057-
info->dvma_buffer = 0;
2058-
info->pipe = -1;
2059-
spin_unlock_irqrestore(&dbri->lock, flags);
2042+
scoped_guard(spinlock_irqsave, &dbri->lock) {
2043+
info->substream = substream;
2044+
info->offset = 0;
2045+
info->dvma_buffer = 0;
2046+
info->pipe = -1;
2047+
}
20602048

20612049
snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
20622050
snd_hw_rule_format, NULL, SNDRV_PCM_HW_PARAM_FORMAT,
@@ -2160,7 +2148,7 @@ static int snd_dbri_prepare(struct snd_pcm_substream *substream)
21602148
else
21612149
info->pipe = 6; /* Receive pipe */
21622150

2163-
spin_lock_irq(&dbri->lock);
2151+
guard(spinlock_irq)(&dbri->lock);
21642152
info->offset = 0;
21652153

21662154
/* Setup the all the transmit/receive descriptors to cover the
@@ -2169,8 +2157,6 @@ static int snd_dbri_prepare(struct snd_pcm_substream *substream)
21692157
ret = setup_descs(dbri, DBRI_STREAMNO(substream),
21702158
snd_pcm_lib_period_bytes(substream));
21712159

2172-
spin_unlock_irq(&dbri->lock);
2173-
21742160
dprintk(D_USR, "prepare audio output. %d bytes\n", info->size);
21752161
return ret;
21762162
}

0 commit comments

Comments
 (0)