Skip to content

Commit a5f7cf9

Browse files
Wolfram Sangwsakernel
authored andcommitted
i2c: rcar: 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 interrupt handlers was 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 ac18935 commit a5f7cf9

File tree

1 file changed

+9
-17
lines changed

1 file changed

+9
-17
lines changed

drivers/i2c/busses/i2c-rcar.c

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -367,11 +367,15 @@ static void rcar_i2c_next_msg(struct rcar_i2c_priv *priv)
367367
rcar_i2c_prepare_msg(priv);
368368
}
369369

370-
static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
370+
static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv, bool terminate)
371371
{
372372
struct dma_chan *chan = priv->dma_direction == DMA_FROM_DEVICE
373373
? priv->dma_rx : priv->dma_tx;
374374

375+
/* only allowed from thread context! */
376+
if (terminate)
377+
dmaengine_terminate_sync(chan);
378+
375379
dma_unmap_single(chan->device->dev, sg_dma_address(&priv->sg),
376380
sg_dma_len(&priv->sg), priv->dma_direction);
377381

@@ -386,25 +390,13 @@ static void rcar_i2c_dma_unmap(struct rcar_i2c_priv *priv)
386390
rcar_i2c_write(priv, ICDMAER, 0);
387391
}
388392

389-
static void rcar_i2c_cleanup_dma(struct rcar_i2c_priv *priv)
390-
{
391-
if (priv->dma_direction == DMA_NONE)
392-
return;
393-
else if (priv->dma_direction == DMA_FROM_DEVICE)
394-
dmaengine_terminate_all(priv->dma_rx);
395-
else if (priv->dma_direction == DMA_TO_DEVICE)
396-
dmaengine_terminate_all(priv->dma_tx);
397-
398-
rcar_i2c_dma_unmap(priv);
399-
}
400-
401393
static void rcar_i2c_dma_callback(void *data)
402394
{
403395
struct rcar_i2c_priv *priv = data;
404396

405397
priv->pos += sg_dma_len(&priv->sg);
406398

407-
rcar_i2c_dma_unmap(priv);
399+
rcar_i2c_cleanup_dma(priv, false);
408400
}
409401

410402
static bool rcar_i2c_dma(struct rcar_i2c_priv *priv)
@@ -456,7 +448,7 @@ static bool rcar_i2c_dma(struct rcar_i2c_priv *priv)
456448
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
457449
if (!txdesc) {
458450
dev_dbg(dev, "dma prep slave sg failed, using PIO\n");
459-
rcar_i2c_cleanup_dma(priv);
451+
rcar_i2c_cleanup_dma(priv, false);
460452
return false;
461453
}
462454

@@ -466,7 +458,7 @@ static bool rcar_i2c_dma(struct rcar_i2c_priv *priv)
466458
cookie = dmaengine_submit(txdesc);
467459
if (dma_submit_error(cookie)) {
468460
dev_dbg(dev, "submitting dma failed, using PIO\n");
469-
rcar_i2c_cleanup_dma(priv);
461+
rcar_i2c_cleanup_dma(priv, false);
470462
return false;
471463
}
472464

@@ -846,7 +838,7 @@ static int rcar_i2c_master_xfer(struct i2c_adapter *adap,
846838

847839
/* cleanup DMA if it couldn't complete properly due to an error */
848840
if (priv->dma_direction != DMA_NONE)
849-
rcar_i2c_cleanup_dma(priv);
841+
rcar_i2c_cleanup_dma(priv, true);
850842

851843
if (!time_left) {
852844
rcar_i2c_init(priv);

0 commit comments

Comments
 (0)