Skip to content

Commit

Permalink
dmaengine: dw: enable and disable controller when needed
Browse files Browse the repository at this point in the history
Enable controller automatically whenever first user requires for a channel and
disable it when the last user gone.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Vinod Koul <vinod.koul@intel.com>
  • Loading branch information
Andy Shevchenko authored and Vinod Koul committed Oct 15, 2014
1 parent 2540f74 commit 99d9bf4
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 25 deletions.
60 changes: 35 additions & 25 deletions drivers/dma/dw/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,31 @@ static void dwc_issue_pending(struct dma_chan *chan)
spin_unlock_irqrestore(&dwc->lock, flags);
}

/*----------------------------------------------------------------------*/

static void dw_dma_off(struct dw_dma *dw)
{
int i;

dma_writel(dw, CFG, 0);

channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask);
channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask);
channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);

while (dma_readl(dw, CFG) & DW_CFG_DMA_EN)
cpu_relax();

for (i = 0; i < dw->dma.chancnt; i++)
dw->chan[i].initialized = false;
}

static void dw_dma_on(struct dw_dma *dw)
{
dma_writel(dw, CFG, DW_CFG_DMA_EN);
}

static int dwc_alloc_chan_resources(struct dma_chan *chan)
{
struct dw_dma_chan *dwc = to_dw_dma_chan(chan);
Expand All @@ -1118,6 +1143,11 @@ static int dwc_alloc_chan_resources(struct dma_chan *chan)
* doesn't mean what you think it means), and status writeback.
*/

/* Enable controller here if needed */
if (!dw->in_use)
dw_dma_on(dw);
dw->in_use |= dwc->mask;

spin_lock_irqsave(&dwc->lock, flags);
i = dwc->descs_allocated;
while (dwc->descs_allocated < NR_DESCS_PER_CHANNEL) {
Expand Down Expand Up @@ -1182,6 +1212,11 @@ static void dwc_free_chan_resources(struct dma_chan *chan)

spin_unlock_irqrestore(&dwc->lock, flags);

/* Disable controller in case it was a last user */
dw->in_use &= ~dwc->mask;
if (!dw->in_use)
dw_dma_off(dw);

list_for_each_entry_safe(desc, _desc, &list, desc_node) {
dev_vdbg(chan2dev(chan), " freeing descriptor %p\n", desc);
dma_pool_free(dw->desc_pool, desc, desc->txd.phys);
Expand Down Expand Up @@ -1452,29 +1487,6 @@ EXPORT_SYMBOL(dw_dma_cyclic_free);

/*----------------------------------------------------------------------*/

static void dw_dma_off(struct dw_dma *dw)
{
int i;

dma_writel(dw, CFG, 0);

channel_clear_bit(dw, MASK.XFER, dw->all_chan_mask);
channel_clear_bit(dw, MASK.SRC_TRAN, dw->all_chan_mask);
channel_clear_bit(dw, MASK.DST_TRAN, dw->all_chan_mask);
channel_clear_bit(dw, MASK.ERROR, dw->all_chan_mask);

while (dma_readl(dw, CFG) & DW_CFG_DMA_EN)
cpu_relax();

for (i = 0; i < dw->dma.chancnt; i++)
dw->chan[i].initialized = false;
}

static void dw_dma_on(struct dw_dma *dw)
{
dma_writel(dw, CFG, DW_CFG_DMA_EN);
}

int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
{
struct dw_dma *dw;
Expand Down Expand Up @@ -1648,8 +1660,6 @@ int dw_dma_probe(struct dw_dma_chip *chip, struct dw_dma_platform_data *pdata)
dw->dma.device_tx_status = dwc_tx_status;
dw->dma.device_issue_pending = dwc_issue_pending;

dw_dma_on(dw);

err = dma_async_device_register(&dw->dma);
if (err)
goto err_dma_register;
Expand Down
1 change: 1 addition & 0 deletions drivers/dma/dw/regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ struct dw_dma {
/* channels */
struct dw_dma_chan *chan;
u8 all_chan_mask;
u8 in_use;

/* hardware configuration */
unsigned char nr_masters;
Expand Down

0 comments on commit 99d9bf4

Please sign in to comment.