Skip to content

Commit 79434f9

Browse files
nxpfranklivinodkoul
authored andcommitted
dmaengine: fsl-edma: move common IRQ handler to common.c
Move the common part of IRQ handler from fsl-edma-main.c and mcf-edma-main.c to fsl-edma-common.c. This eliminates redundant code, as the both files contains mostly identical code. Signed-off-by: Frank Li <Frank.Li@nxp.com> Link: https://lore.kernel.org/r/20230821161617.2142561-6-Frank.Li@nxp.com Signed-off-by: Vinod Koul <vkoul@kernel.org>
1 parent c26e611 commit 79434f9

File tree

4 files changed

+37
-56
lines changed

4 files changed

+37
-56
lines changed

drivers/dma/fsl-edma-common.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,32 @@
4242

4343
#define EDMA_TCD 0x1000
4444

45+
void fsl_edma_tx_chan_handler(struct fsl_edma_chan *fsl_chan)
46+
{
47+
spin_lock(&fsl_chan->vchan.lock);
48+
49+
if (!fsl_chan->edesc) {
50+
/* terminate_all called before */
51+
spin_unlock(&fsl_chan->vchan.lock);
52+
return;
53+
}
54+
55+
if (!fsl_chan->edesc->iscyclic) {
56+
list_del(&fsl_chan->edesc->vdesc.node);
57+
vchan_cookie_complete(&fsl_chan->edesc->vdesc);
58+
fsl_chan->edesc = NULL;
59+
fsl_chan->status = DMA_COMPLETE;
60+
fsl_chan->idle = true;
61+
} else {
62+
vchan_cyclic_callback(&fsl_chan->edesc->vdesc);
63+
}
64+
65+
if (!fsl_chan->edesc)
66+
fsl_edma_xfer_desc(fsl_chan);
67+
68+
spin_unlock(&fsl_chan->vchan.lock);
69+
}
70+
4571
static void fsl_edma_enable_request(struct fsl_edma_chan *fsl_chan)
4672
{
4773
struct edma_regs *regs = &fsl_chan->edma->regs;

drivers/dma/fsl-edma-common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,13 @@ static inline struct fsl_edma_desc *to_fsl_edma_desc(struct virt_dma_desc *vd)
219219
return container_of(vd, struct fsl_edma_desc, vdesc);
220220
}
221221

222+
static inline void fsl_edma_err_chan_handler(struct fsl_edma_chan *fsl_chan)
223+
{
224+
fsl_chan->status = DMA_ERROR;
225+
fsl_chan->idle = true;
226+
}
227+
228+
void fsl_edma_tx_chan_handler(struct fsl_edma_chan *fsl_chan);
222229
void fsl_edma_disable_request(struct fsl_edma_chan *fsl_chan);
223230
void fsl_edma_chan_mux(struct fsl_edma_chan *fsl_chan,
224231
unsigned int slot, bool enable);

drivers/dma/fsl-edma-main.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id)
3333
struct fsl_edma_engine *fsl_edma = dev_id;
3434
unsigned int intr, ch;
3535
struct edma_regs *regs = &fsl_edma->regs;
36-
struct fsl_edma_chan *fsl_chan;
3736

3837
intr = edma_readl(fsl_edma, regs->intl);
3938
if (!intr)
@@ -42,31 +41,7 @@ static irqreturn_t fsl_edma_tx_handler(int irq, void *dev_id)
4241
for (ch = 0; ch < fsl_edma->n_chans; ch++) {
4342
if (intr & (0x1 << ch)) {
4443
edma_writeb(fsl_edma, EDMA_CINT_CINT(ch), regs->cint);
45-
46-
fsl_chan = &fsl_edma->chans[ch];
47-
48-
spin_lock(&fsl_chan->vchan.lock);
49-
50-
if (!fsl_chan->edesc) {
51-
/* terminate_all called before */
52-
spin_unlock(&fsl_chan->vchan.lock);
53-
continue;
54-
}
55-
56-
if (!fsl_chan->edesc->iscyclic) {
57-
list_del(&fsl_chan->edesc->vdesc.node);
58-
vchan_cookie_complete(&fsl_chan->edesc->vdesc);
59-
fsl_chan->edesc = NULL;
60-
fsl_chan->status = DMA_COMPLETE;
61-
fsl_chan->idle = true;
62-
} else {
63-
vchan_cyclic_callback(&fsl_chan->edesc->vdesc);
64-
}
65-
66-
if (!fsl_chan->edesc)
67-
fsl_edma_xfer_desc(fsl_chan);
68-
69-
spin_unlock(&fsl_chan->vchan.lock);
44+
fsl_edma_tx_chan_handler(&fsl_edma->chans[ch]);
7045
}
7146
}
7247
return IRQ_HANDLED;
@@ -86,8 +61,7 @@ static irqreturn_t fsl_edma_err_handler(int irq, void *dev_id)
8661
if (err & (0x1 << ch)) {
8762
fsl_edma_disable_request(&fsl_edma->chans[ch]);
8863
edma_writeb(fsl_edma, EDMA_CERR_CERR(ch), regs->cerr);
89-
fsl_edma->chans[ch].status = DMA_ERROR;
90-
fsl_edma->chans[ch].idle = true;
64+
fsl_edma_err_chan_handler(&fsl_edma->chans[ch]);
9165
}
9266
}
9367
return IRQ_HANDLED;

drivers/dma/mcf-edma-main.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ static irqreturn_t mcf_edma_tx_handler(int irq, void *dev_id)
1919
struct fsl_edma_engine *mcf_edma = dev_id;
2020
struct edma_regs *regs = &mcf_edma->regs;
2121
unsigned int ch;
22-
struct fsl_edma_chan *mcf_chan;
2322
u64 intmap;
2423

2524
intmap = ioread32(regs->inth);
@@ -31,31 +30,7 @@ static irqreturn_t mcf_edma_tx_handler(int irq, void *dev_id)
3130
for (ch = 0; ch < mcf_edma->n_chans; ch++) {
3231
if (intmap & BIT(ch)) {
3332
iowrite8(EDMA_MASK_CH(ch), regs->cint);
34-
35-
mcf_chan = &mcf_edma->chans[ch];
36-
37-
spin_lock(&mcf_chan->vchan.lock);
38-
39-
if (!mcf_chan->edesc) {
40-
/* terminate_all called before */
41-
spin_unlock(&mcf_chan->vchan.lock);
42-
continue;
43-
}
44-
45-
if (!mcf_chan->edesc->iscyclic) {
46-
list_del(&mcf_chan->edesc->vdesc.node);
47-
vchan_cookie_complete(&mcf_chan->edesc->vdesc);
48-
mcf_chan->edesc = NULL;
49-
mcf_chan->status = DMA_COMPLETE;
50-
mcf_chan->idle = true;
51-
} else {
52-
vchan_cyclic_callback(&mcf_chan->edesc->vdesc);
53-
}
54-
55-
if (!mcf_chan->edesc)
56-
fsl_edma_xfer_desc(mcf_chan);
57-
58-
spin_unlock(&mcf_chan->vchan.lock);
33+
fsl_edma_tx_chan_handler(&mcf_edma->chans[ch]);
5934
}
6035
}
6136

@@ -76,8 +51,7 @@ static irqreturn_t mcf_edma_err_handler(int irq, void *dev_id)
7651
if (err & BIT(ch)) {
7752
fsl_edma_disable_request(&mcf_edma->chans[ch]);
7853
iowrite8(EDMA_CERR_CERR(ch), regs->cerr);
79-
mcf_edma->chans[ch].status = DMA_ERROR;
80-
mcf_edma->chans[ch].idle = true;
54+
fsl_edma_err_chan_handler(&mcf_edma->chans[ch]);
8155
}
8256
}
8357

0 commit comments

Comments
 (0)