Skip to content

RFC: LiteSDCard: Add support for DMA/data completion interrupts #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Prev Previous commit
mmc: litex_mmc: add IRQ support for DMA data xfers
Add support for utilizing interrupts generated by LiteSDCard when
DMA data transfers complete.

Signed-off-by: Gabriel Somlo <[email protected]>
  • Loading branch information
gsomlo committed Oct 14, 2023
commit b695ceef171f388711104a5481ce9e79870df32f
25 changes: 23 additions & 2 deletions drivers/mmc/host/litex_mmc.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ struct litex_mmc_host {
dma_addr_t dma;

struct completion cmd_done;
struct completion data_done;
int irq;

unsigned int ref_clk;
Expand Down Expand Up @@ -255,6 +256,18 @@ static irqreturn_t litex_mmc_interrupt(int irq, void *arg)
complete(&host->cmd_done);
}

/* Check for DMA read completed */
if (pending & SDIRQ_SD_TO_MEM_DONE) {
handled |= SDIRQ_SD_TO_MEM_DONE;
complete(&host->data_done);
}

/* Check for DMA write completed */
if (pending & SDIRQ_MEM_TO_SD_DONE) {
handled |= SDIRQ_MEM_TO_SD_DONE;
complete(&host->data_done);
}

if (handled) {
/* Acknowledge handled interrupts */
litex_write32(host->sdirq + LITEX_IRQ_PENDING, handled);
Expand Down Expand Up @@ -369,6 +382,9 @@ static void litex_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
return;
}

if (host->irq > 0)
reinit_completion(&host->data_done);

litex_mmc_do_dma(host, data, &len, &direct, &transfer);
}

Expand All @@ -384,6 +400,8 @@ static void litex_mmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
u8 evt;

/* Wait for completion of (read or write) DMA transfer */
if (host->irq > 0)
wait_for_completion(&host->data_done);
cmd->error = readx_poll_timeout(litex_read8, reg,
evt, evt & SD_BIT_DONE,
SD_SLEEP_US, SD_TIMEOUT_US);
Expand Down Expand Up @@ -507,11 +525,14 @@ static int litex_mmc_irq_init(struct platform_device *pdev,

/* Clear & enable interrupts */
litex_write32(host->sdirq + LITEX_IRQ_PENDING,
SDIRQ_CARD_DETECT | SDIRQ_CMD_DONE);
SDIRQ_CARD_DETECT | SDIRQ_CMD_DONE |
SDIRQ_SD_TO_MEM_DONE | SDIRQ_MEM_TO_SD_DONE);
litex_write32(host->sdirq + LITEX_IRQ_ENABLE,
SDIRQ_CARD_DETECT | SDIRQ_CMD_DONE);
SDIRQ_CARD_DETECT | SDIRQ_CMD_DONE |
SDIRQ_SD_TO_MEM_DONE | SDIRQ_MEM_TO_SD_DONE);

init_completion(&host->cmd_done);
init_completion(&host->data_done);

return 0;

Expand Down