Skip to content

Commit 44df8a7

Browse files
Wolfram Sangwsakernel
authored andcommitted
i2c: sh_mobile: update to new DMAENGINE API when terminating
dmaengine_terminate_all() is deprecated. When converting the existing calls, it turned out that the termination in the DMA setup and callback were superfluous and only a side effect of simply calling rcar_i2c_cleanup_dma(). As either no DMA transfers have been submitted yet or the last one has successfully completed, there is nothing to terminate and we can leave it out. So, merge the DMA unmap and cleanup function to save some code. Then, add a flag if the new cleanup function needs to terminate DMA. This is only the case for the erorr handling in the main thread, so we can finally switch from dmaengine_terminate_all() to dmaengine_terminate_sync() here. Signed-off-by: Wolfram Sang <[email protected]> Signed-off-by: Wolfram Sang <[email protected]>
1 parent a5f7cf9 commit 44df8a7

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

drivers/i2c/busses/i2c-sh_mobile.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -442,34 +442,26 @@ static irqreturn_t sh_mobile_i2c_isr(int irq, void *dev_id)
442442
return IRQ_HANDLED;
443443
}
444444

445-
static void sh_mobile_i2c_dma_unmap(struct sh_mobile_i2c_data *pd)
445+
static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd, bool terminate)
446446
{
447447
struct dma_chan *chan = pd->dma_direction == DMA_FROM_DEVICE
448448
? pd->dma_rx : pd->dma_tx;
449449

450+
/* only allowed from thread context! */
451+
if (terminate)
452+
dmaengine_terminate_sync(chan);
453+
450454
dma_unmap_single(chan->device->dev, sg_dma_address(&pd->sg),
451455
pd->msg->len, pd->dma_direction);
452456

453457
pd->dma_direction = DMA_NONE;
454458
}
455459

456-
static void sh_mobile_i2c_cleanup_dma(struct sh_mobile_i2c_data *pd)
457-
{
458-
if (pd->dma_direction == DMA_NONE)
459-
return;
460-
else if (pd->dma_direction == DMA_FROM_DEVICE)
461-
dmaengine_terminate_sync(pd->dma_rx);
462-
else if (pd->dma_direction == DMA_TO_DEVICE)
463-
dmaengine_terminate_sync(pd->dma_tx);
464-
465-
sh_mobile_i2c_dma_unmap(pd);
466-
}
467-
468460
static void sh_mobile_i2c_dma_callback(void *data)
469461
{
470462
struct sh_mobile_i2c_data *pd = data;
471463

472-
sh_mobile_i2c_dma_unmap(pd);
464+
sh_mobile_i2c_cleanup_dma(pd, false);
473465
pd->pos = pd->msg->len;
474466
pd->stop_after_dma = true;
475467

@@ -549,7 +541,7 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
549541
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
550542
if (!txdesc) {
551543
dev_dbg(pd->dev, "dma prep slave sg failed, using PIO\n");
552-
sh_mobile_i2c_cleanup_dma(pd);
544+
sh_mobile_i2c_cleanup_dma(pd, false);
553545
return;
554546
}
555547

@@ -559,7 +551,7 @@ static void sh_mobile_i2c_xfer_dma(struct sh_mobile_i2c_data *pd)
559551
cookie = dmaengine_submit(txdesc);
560552
if (dma_submit_error(cookie)) {
561553
dev_dbg(pd->dev, "submitting dma failed, using PIO\n");
562-
sh_mobile_i2c_cleanup_dma(pd);
554+
sh_mobile_i2c_cleanup_dma(pd, false);
563555
return;
564556
}
565557

@@ -698,7 +690,7 @@ static int sh_mobile_xfer(struct sh_mobile_i2c_data *pd,
698690
if (!time_left) {
699691
dev_err(pd->dev, "Transfer request timed out\n");
700692
if (pd->dma_direction != DMA_NONE)
701-
sh_mobile_i2c_cleanup_dma(pd);
693+
sh_mobile_i2c_cleanup_dma(pd, true);
702694

703695
err = -ETIMEDOUT;
704696
break;

0 commit comments

Comments
 (0)