From 4d3e81ce0d945255a0942cc48129152116decc13 Mon Sep 17 00:00:00 2001 From: Karol Trzcinski Date: Tue, 18 Feb 2020 09:38:00 +0100 Subject: [PATCH 1/2] dw_dma: Align argument list Keep code style consistent. Signed-off-by: Karol Trzcinski --- src/drivers/dw/dma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/drivers/dw/dma.c b/src/drivers/dw/dma.c index 30a4a212b042..4e0f157a6761 100644 --- a/src/drivers/dw/dma.c +++ b/src/drivers/dw/dma.c @@ -404,7 +404,7 @@ static int dw_dma_stop(struct dma_chan_data *channel) /* now we wait for FIFO to be empty */ ret = poll_for_register_delay(dma_base(dma) + - DW_CFG_LOW(channel->index), + DW_CFG_LOW(channel->index), DW_CFGL_FIFO_EMPTY, DW_CFGL_FIFO_EMPTY, DW_DMA_TIMEOUT); From 9aff15cee2ecdf9c54a34d9cfc482314602deace Mon Sep 17 00:00:00 2001 From: Karol Trzcinski Date: Thu, 19 Mar 2020 16:07:55 +0100 Subject: [PATCH 2/2] dw_dma: Split DMA pause and stop command Data after pause command should be kept compatible to omit pop noise on output. The solution may be waiting for FIFO empty but it takes to long - up to 1 processing period time. Another - introduced - solution is to stop draining new data from buffer after pause, but keeping dma connection with dai up to release command. In this place waiting for FIFO empty shouldn't take so much time, so system agent won't panic and data will be consistent. Signed-off-by: Karol Trzcinski --- src/audio/dai.c | 7 +++++-- src/drivers/dw/dma.c | 29 +++++++++++++++++++++++++++-- src/drivers/intel/cavs/hda-dma.c | 4 ++-- 3 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/audio/dai.c b/src/audio/dai.c index 2a28df4de723..1158ed940692 100644 --- a/src/audio/dai.c +++ b/src/audio/dai.c @@ -620,12 +620,15 @@ static int dai_comp_trigger(struct comp_dev *dev, int cmd) dd->xrun = 1; /* fallthrough */ - case COMP_TRIGGER_PAUSE: case COMP_TRIGGER_STOP: - comp_dbg(dev, "dai_comp_trigger(), PAUSE/STOP"); + comp_dbg(dev, "dai_comp_trigger(), STOP"); ret = dma_stop(dd->chan); dai_trigger(dd->dai, cmd, dev->direction); break; + case COMP_TRIGGER_PAUSE: + comp_dbg(dev, "dai_comp_trigger(), PAUSE"); + ret = dma_pause(dd->chan); + dai_trigger(dd->dai, cmd, dev->direction); default: break; } diff --git a/src/drivers/dw/dma.c b/src/drivers/dw/dma.c index 4e0f157a6761..34a20078910d 100644 --- a/src/drivers/dw/dma.c +++ b/src/drivers/dw/dma.c @@ -72,6 +72,8 @@ static const uint32_t burst_elems[] = {1, 2, 4, 8}; #define DW_DMA_BUFFER_PERIOD_COUNT 2 #endif +static int dw_dma_stop(struct dma_chan_data *channel); + static void dw_dma_interrupt_mask(struct dma_chan_data *channel) { /* mask block, transfer and error interrupts for channel */ @@ -266,7 +268,8 @@ static int dw_dma_start(struct dma_chan_data *channel) irq_local_disable(flags); /* check if channel idle, disabled and ready */ - if (channel->status != COMP_STATE_PREPARE || + if ((channel->status != COMP_STATE_PREPARE && + channel->status != COMP_STATE_PAUSED) || (dma_reg_read(dma, DW_DMA_CHAN_EN) & DW_CHAN(channel->index))) { trace_dwdma_error("dw_dma_start() error: dma %d channel %d " "not ready ena 0x%x status 0x%x", @@ -334,16 +337,32 @@ static int dw_dma_start(struct dma_chan_data *channel) static int dw_dma_release(struct dma_chan_data *channel) { struct dw_dma_chan_data *dw_chan = dma_chan_get_data(channel); + struct dma *dma = channel->dma; uint32_t flags; + int ret; trace_dwdma("dw_dma_release(): dma %d channel %d release", channel->dma->plat_data.id, channel->index); irq_local_disable(flags); + /* now we wait for FIFO to be empty */ + ret = poll_for_register_delay(dma_base(dma) + + DW_CFG_LOW(channel->index), + DW_CFGL_FIFO_EMPTY, + DW_CFGL_FIFO_EMPTY, + DW_DMA_TIMEOUT); + /* get next lli for proper release */ dw_chan->lli_current = (struct dw_lli *)dw_chan->lli_current->llp; + /* prepare to start */ + dw_dma_stop(channel); + + if (ret < 0) + trace_dwdma_error("dw_dma_release() error: dma %d channel %d timeout", + dma->plat_data.id, channel->index); + irq_local_enable(flags); return 0; @@ -351,6 +370,8 @@ static int dw_dma_release(struct dma_chan_data *channel) static int dw_dma_pause(struct dma_chan_data *channel) { + struct dw_dma_chan_data *dw_chan = dma_chan_get_data(channel); + struct dma *dma = channel->dma; uint32_t flags; trace_dwdma("dw_dma_pause(): dma %d channel %d pause", @@ -361,6 +382,9 @@ static int dw_dma_pause(struct dma_chan_data *channel) if (channel->status != COMP_STATE_ACTIVE) goto out; + dma_reg_write(dma, DW_CFG_LOW(channel->index), + dw_chan->cfg_lo | DW_CFGL_SUSPEND); + /* pause the channel */ channel->status = COMP_STATE_PAUSED; @@ -392,7 +416,8 @@ static int dw_dma_stop(struct dma_chan_data *channel) irq_local_disable(flags); - if (channel->status != COMP_STATE_ACTIVE) + if (channel->status != COMP_STATE_ACTIVE && + channel->status != COMP_STATE_PAUSED) goto out; #if CONFIG_DMA_SUSPEND_DRAIN diff --git a/src/drivers/intel/cavs/hda-dma.c b/src/drivers/intel/cavs/hda-dma.c index 19aef1b8fede..d828f23138d2 100644 --- a/src/drivers/intel/cavs/hda-dma.c +++ b/src/drivers/intel/cavs/hda-dma.c @@ -517,8 +517,8 @@ static int hda_dma_pause(struct dma_chan_data *channel) if (channel->status != COMP_STATE_ACTIVE) goto out; - /* pause the channel */ - channel->status = COMP_STATE_PAUSED; + /* stop the channel */ + hda_dma_stop(channel); out: irq_local_enable(flags);