Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions drivers/misc/rp1-pio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1002,18 +1002,21 @@ static void rp1_pio_sm_dma_flush_rx(struct dma_info *dma)
dma_free_coherent(dma_dev, len, buf, dma_addr);
}

static void rp1_pio_sm_dma_free(struct device *dev, struct dma_info *dma)
static void rp1_pio_sm_dma_free(struct dma_info *dma)
{
/* The buffers were allocated for the DMA controller, so free them there */
struct device *dma_dev = dma->chan->device->dev;

dmaengine_terminate_all(dma->chan);
if (dma->cyclic) {
dma->buf_count = 0;
dma_free_coherent(dev, ROUND_UP(dma->buf_size, PAGE_SIZE),
dma_free_coherent(dma_dev, ROUND_UP(dma->buf_size, PAGE_SIZE),
dma->bufs[0].buf,
dma->bufs[0].dma_addr);
} else {
while (dma->buf_count > 0) {
dma->buf_count--;
dma_free_coherent(dev, ROUND_UP(dma->buf_size, PAGE_SIZE),
dma_free_coherent(dma_dev, ROUND_UP(dma->buf_size, PAGE_SIZE),
dma->bufs[dma->buf_count].buf,
dma->bufs[dma->buf_count].dma_addr);
}
Expand Down Expand Up @@ -1068,7 +1071,7 @@ static int rp1_pio_sm_config_xfer_internal(struct rp1_pio_client *client, uint s

/* dma_release_channel() sleeps, so free the old channel outside the lock. */
if (reconfigure)
rp1_pio_sm_dma_free(dev, dma);
rp1_pio_sm_dma_free(dma);

sema_init(&dma->buf_sem, 0);

Expand Down Expand Up @@ -1098,7 +1101,7 @@ static int rp1_pio_sm_config_xfer_internal(struct rp1_pio_client *client, uint s

if (cyclic) {
dma->buf_size = buf_size * buf_count;
dma->buf_count = buf_count;
dma->buf_count = 0;
/* Round up the allocations */
buf_size = ROUND_UP(dma->buf_size, PAGE_SIZE);

Expand All @@ -1113,6 +1116,8 @@ static int rp1_pio_sm_config_xfer_internal(struct rp1_pio_client *client, uint s
}
sg_init_table(&dbi->sgl, 1);
sg_dma_address(&dbi->sgl) = dbi->dma_addr;
dma->buf_count = buf_count;
dma->cyclic = cyclic;
} else {
dma->buf_size = buf_size;
/* Round up the allocations */
Expand Down Expand Up @@ -1182,6 +1187,7 @@ static int rp1_pio_sm_config_xfer_internal(struct rp1_pio_client *client, uint s
DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
if (!desc) {
dev_err(dev, "DMA preparation failed\n");
ret = -EIO;
goto err_dma_free;
}

Expand All @@ -1193,13 +1199,12 @@ static int rp1_pio_sm_config_xfer_internal(struct rp1_pio_client *client, uint s
if (ret < 0)
goto err_dma_free;

dma->cyclic = cyclic;
dma_async_issue_pending(dma->chan);
}
return 0;

err_dma_free:
rp1_pio_sm_dma_free(dev, dma);
rp1_pio_sm_dma_free(dma);

err_unclaim:
spin_lock(&pio->lock);
Expand Down Expand Up @@ -1712,7 +1717,7 @@ void rp1_pio_close(struct rp1_pio_client *client)
/* The SMs have been disabled, so this is safe */
if ((i & 1) == RP1_PIO_DIR_FROM_SM)
rp1_pio_sm_dma_flush_rx(dma);
rp1_pio_sm_dma_free(&pio->pdev->dev, dma);
rp1_pio_sm_dma_free(dma);
}
}

Expand Down
Loading