public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: Viresh Kumar <viresh.linux@gmail.com>,
	Vinod Koul <vinod.koul@intel.com>,
	spear-devel@list.st.com, linux-kernel@vger.kernel.org,
	Hein Tibosch <hein_tibosch@yahoo.es>
Cc: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Subject: [PATCHv2 6/6] dw_dmac: introduce software emulation of LLP transfers
Date: Fri, 21 Sep 2012 15:05:49 +0300	[thread overview]
Message-ID: <1348229149-29040-7-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <1348229149-29040-1-git-send-email-andriy.shevchenko@linux.intel.com>

Some controllers have the reduced functionality where the LLP multi block
transfers are not supported. This patch introduces a support of such
controllers. In case of memory copy or scatter-gather lists it emulates LLP
transfers via bunch of the regular single block ones.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/dma/dw_dmac.c      |   99 ++++++++++++++++++++++++++++++++++++++++++--
 drivers/dma/dw_dmac_regs.h |    6 +++
 2 files changed, 101 insertions(+), 4 deletions(-)

diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c
index d47b76a..47b9b3e 100644
--- a/drivers/dma/dw_dmac.c
+++ b/drivers/dma/dw_dmac.c
@@ -234,10 +234,29 @@ static inline void dwc_chan_disable(struct dw_dma *dw, struct dw_dma_chan *dwc)
 
 /*----------------------------------------------------------------------*/
 
+/* Perform single block transfer */
+static inline void dwc_do_single_block(struct dw_dma_chan *dwc,
+				       struct dw_desc *desc)
+{
+	struct dw_dma	*dw = to_dw_dma(dwc->chan.device);
+	u32		ctllo;
+
+	/* Software emulation of LLP mode relies on interrupts to continue
+	 * multi block transfer. */
+	ctllo = desc->lli.ctllo | DWC_CTLL_INT_EN;
+
+	channel_writel(dwc, SAR, desc->lli.sar);
+	channel_writel(dwc, DAR, desc->lli.dar);
+	channel_writel(dwc, CTL_LO, ctllo);
+	channel_writel(dwc, CTL_HI, desc->lli.ctlhi);
+	channel_set_bit(dw, CH_EN, dwc->mask);
+}
+
 /* Called with dwc->lock held and bh disabled */
 static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
 {
 	struct dw_dma	*dw = to_dw_dma(dwc->chan.device);
+	unsigned long	was_soft_llp;
 
 	/* ASSERT:  channel is idle */
 	if (dma_readl(dw, CH_EN) & dwc->mask) {
@@ -249,6 +268,26 @@ static void dwc_dostart(struct dw_dma_chan *dwc, struct dw_desc *first)
 		return;
 	}
 
+	if (dwc->nollp) {
+		was_soft_llp = test_and_set_bit(DW_DMA_IS_SOFT_LLP,
+						&dwc->flags);
+		if (was_soft_llp) {
+			dev_err(chan2dev(&dwc->chan),
+				"BUG: Attempted to start new LLP transfer "
+				"inside ongoing one\n");
+			return;
+		}
+
+		dwc_initialize(dwc);
+
+		dwc->tx_list = &first->tx_list;
+		dwc->tx_node_active = first->tx_list.next;
+
+		dwc_do_single_block(dwc, first);
+
+		return;
+	}
+
 	dwc_initialize(dwc);
 
 	channel_writel(dwc, LLP, first->txd.phys);
@@ -560,8 +599,36 @@ static void dw_dma_tasklet(unsigned long data)
 			dwc_handle_cyclic(dw, dwc, status_err, status_xfer);
 		else if (status_err & (1 << i))
 			dwc_handle_error(dw, dwc);
-		else if (status_xfer & (1 << i))
+		else if (status_xfer & (1 << i)) {
+			unsigned long flags;
+
+			spin_lock_irqsave(&dwc->lock, flags);
+			if (test_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags)) {
+				if (dwc->tx_node_active != dwc->tx_list) {
+					struct dw_desc *desc =
+						list_entry(dwc->tx_node_active,
+							   struct dw_desc,
+							   desc_node);
+
+					dma_writel(dw, CLEAR.XFER, dwc->mask);
+
+					/* move pointer to next descriptor */
+					dwc->tx_node_active =
+						dwc->tx_node_active->next;
+
+					dwc_do_single_block(dwc, desc);
+
+					spin_unlock_irqrestore(&dwc->lock, flags);
+					continue;
+				} else {
+					/* we are done here */
+					clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
+				}
+			}
+			spin_unlock_irqrestore(&dwc->lock, flags);
+
 			dwc_scan_descriptors(dw, dwc);
+		}
 	}
 
 	/*
@@ -964,6 +1031,8 @@ static int dwc_control(struct dma_chan *chan, enum dma_ctrl_cmd cmd,
 	} else if (cmd == DMA_TERMINATE_ALL) {
 		spin_lock_irqsave(&dwc->lock, flags);
 
+		clear_bit(DW_DMA_IS_SOFT_LLP, &dwc->flags);
+
 		dwc_chan_disable(dw, dwc);
 
 		dwc->paused = false;
@@ -1206,6 +1275,13 @@ struct dw_cyclic_desc *dw_dma_cyclic_prep(struct dma_chan *chan,
 	unsigned long			flags;
 
 	spin_lock_irqsave(&dwc->lock, flags);
+	if (dwc->nollp) {
+		spin_unlock_irqrestore(&dwc->lock, flags);
+		dev_dbg(chan2dev(&dwc->chan),
+				"channel doesn't support LLP transfers\n");
+		return ERR_PTR(-EINVAL);
+	}
+
 	if (!list_empty(&dwc->queue) || !list_empty(&dwc->active_list)) {
 		spin_unlock_irqrestore(&dwc->lock, flags);
 		dev_dbg(chan2dev(&dwc->chan),
@@ -1473,6 +1549,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
 	INIT_LIST_HEAD(&dw->dma.channels);
 	for (i = 0; i < nr_channels; i++) {
 		struct dw_dma_chan	*dwc = &dw->chan[i];
+		int			r = nr_channels - i - 1;
 
 		dwc->chan.device = &dw->dma;
 		dma_cookie_init(&dwc->chan);
@@ -1484,7 +1561,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
 
 		/* 7 is highest priority & 0 is lowest. */
 		if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING)
-			dwc->priority = nr_channels - i - 1;
+			dwc->priority = r;
 		else
 			dwc->priority = i;
 
@@ -1501,14 +1578,28 @@ static int __devinit dw_probe(struct platform_device *pdev)
 		dwc->dw = dw;
 
 		/* hardware configuration */
-		if (autocfg)
+		if (autocfg) {
+			unsigned int dwc_params;
+
+			dwc_params = dma_read_byaddr(regs + r * sizeof(u32),
+						     DWC_PARAMS);
+
 			/* Decode maximum block size for given channel. The
 			 * stored 4 bit value represents blocks from 0x00 for 3
 			 * up to 0x0a for 4095. */
 			dwc->block_size =
 				(4 << ((max_blk_size >> 4 * i) & 0xf)) - 1;
-		else
+			dwc->nollp =
+				(dwc_params >> DWC_PARAMS_MBLK_EN & 0x1) == 0;
+		} else {
 			dwc->block_size = pdata->block_size;
+
+			/* Check if channel supports multi block transfer */
+			channel_writel(dwc, LLP, 0xfffffffc);
+			dwc->nollp =
+				(channel_readl(dwc, LLP) & 0xfffffffc) == 0;
+			channel_writel(dwc, LLP, 0);
+		}
 	}
 
 	/* Clear all interrupts on all channels. */
diff --git a/drivers/dma/dw_dmac_regs.h b/drivers/dma/dw_dmac_regs.h
index 06f0391..ff39fa6 100644
--- a/drivers/dma/dw_dmac_regs.h
+++ b/drivers/dma/dw_dmac_regs.h
@@ -172,6 +172,7 @@ struct dw_dma_regs {
 
 enum dw_dmac_flags {
 	DW_DMA_IS_CYCLIC = 0,
+	DW_DMA_IS_SOFT_LLP = 1,
 };
 
 struct dw_dma_chan {
@@ -182,6 +183,10 @@ struct dw_dma_chan {
 	bool			paused;
 	bool			initialized;
 
+	/* software emulation of the LLP transfers */
+	struct list_head	*tx_list;
+	struct list_head	*tx_node_active;
+
 	spinlock_t		lock;
 
 	/* these other elements are all protected by lock */
@@ -195,6 +200,7 @@ struct dw_dma_chan {
 
 	/* hardware configuration */
 	unsigned int		block_size;
+	bool			nollp;
 
 	/* configuration passed via DMA_SLAVE_CONFIG */
 	struct dma_slave_config dma_sconfig;
-- 
1.7.10.4


  parent reply	other threads:[~2012-09-21 12:06 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-17  7:39 [PATCH 0/7] dw_dmac: introduce autoconfiguration Andy Shevchenko
2012-09-17  7:39 ` [PATCH 1/7] dw_dmac: mark dwc_dump_chan_regs as inline Andy Shevchenko
2012-09-18  6:35   ` viresh kumar
2012-09-17  7:39 ` [PATCH 2/7] dw_dmac: fill optional encoded parameters in register structure Andy Shevchenko
2012-09-18  6:39   ` viresh kumar
2012-09-18  6:55     ` Andy Shevchenko
2012-09-18  7:59       ` viresh kumar
2012-09-20  9:30         ` Andy Shevchenko
2012-09-20  9:32           ` viresh kumar
2012-09-20  9:51             ` Andy Shevchenko
2012-09-17  7:39 ` [PATCH 3/7] dw_dmac: get number of channels from hardware if possible Andy Shevchenko
2012-09-18  6:50   ` viresh kumar
2012-09-20  9:35     ` Andy Shevchenko
2012-09-20  9:40       ` viresh kumar
2012-09-21  6:04         ` viresh kumar
2012-09-17  7:39 ` [PATCH 4/7] dw_dmac: autoconfigure block_size or use platform data Andy Shevchenko
2012-09-18  6:57   ` viresh kumar
2012-09-20  9:38     ` Andy Shevchenko
2012-09-17  7:39 ` [PATCH 5/7] dw_dmac: autoconfigure data_width or get it via " Andy Shevchenko
2012-09-18  7:11   ` viresh kumar
2012-09-20  9:42     ` Andy Shevchenko
2012-09-20  9:46       ` viresh kumar
2012-09-20  9:53         ` Andy Shevchenko
2012-09-17  7:39 ` [PATCH 6/7] dw_dmac: check if controller supports LLP Andy Shevchenko
2012-09-18  7:13   ` viresh kumar
2012-09-20  9:43     ` Andy Shevchenko
2012-09-17  7:39 ` [PATCH 7/7] dw_dmac: introduce software emulation of LLP transfers Andy Shevchenko
2012-09-18  7:17   ` viresh kumar
2012-09-20  9:46     ` Andy Shevchenko
2012-09-17 16:50 ` [PATCH 0/7] dw_dmac: introduce autoconfiguration Hein Tibosch
2012-09-18  6:11 ` Hein Tibosch
2012-09-18  7:18   ` viresh kumar
2012-09-20  9:48   ` Andy Shevchenko
2012-09-21 12:05 ` [PATCHv2 0/6] " Andy Shevchenko
2012-09-21 12:05   ` [PATCHv2 1/6] dw_dmac: mark dwc_dump_chan_regs as inline Andy Shevchenko
2012-09-21 12:05   ` [PATCHv2 2/6] dw_dmac: fill optional encoded parameters in register structure Andy Shevchenko
2012-09-21 13:55     ` viresh kumar
2012-09-21 12:05   ` [PATCHv2 3/6] dw_dmac: get number of channels from hardware if possible Andy Shevchenko
2012-09-21 13:56     ` viresh kumar
2012-09-21 12:05   ` [PATCHv2 4/6] dw_dmac: autoconfigure block_size or use platform data Andy Shevchenko
2012-09-21 14:00     ` viresh kumar
2012-09-21 15:09       ` Andy Shevchenko
2012-09-21 15:30         ` Viresh Kumar
2012-09-21 12:05   ` [PATCHv2 5/6] dw_dmac: autoconfigure data_width or get it via " Andy Shevchenko
2012-09-21 14:02     ` viresh kumar
2012-09-25 11:39       ` [PATCHv3] " Andy Shevchenko
2012-09-26  3:29         ` viresh kumar
2012-09-27 10:06         ` Vinod Koul
2012-09-27 10:33           ` Vinod Koul
2012-09-27 13:10             ` Andy Shevchenko
2012-10-01  9:04             ` Andy Shevchenko
2012-10-01  9:45               ` Vinod Koul
2012-10-01 10:07                 ` Andy Shevchenko
2012-09-27 14:00           ` Andy Shevchenko
2012-09-27 14:27             ` Vinod Koul
2012-09-21 12:05   ` Andy Shevchenko [this message]
2012-09-21 14:03     ` [PATCHv2 6/6] dw_dmac: introduce software emulation of LLP transfers viresh kumar
2012-09-27 10:05   ` [PATCHv2 0/6] dw_dmac: introduce autoconfiguration Vinod Koul

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1348229149-29040-7-git-send-email-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=hein_tibosch@yahoo.es \
    --cc=linux-kernel@vger.kernel.org \
    --cc=spear-devel@list.st.com \
    --cc=vinod.koul@intel.com \
    --cc=viresh.linux@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox