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 3/6] dw_dmac: get number of channels from hardware if possible
Date: Fri, 21 Sep 2012 15:05:46 +0300	[thread overview]
Message-ID: <1348229149-29040-4-git-send-email-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <1348229149-29040-1-git-send-email-andriy.shevchenko@linux.intel.com>

In case the controller has the encoded parameters feature enabled the driver
will use it to get the number of channels. In the future it will be used for
the other important parameters as well.

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/dma/dw_dmac.c |   33 +++++++++++++++++++++++----------
 1 file changed, 23 insertions(+), 10 deletions(-)

diff --git a/drivers/dma/dw_dmac.c b/drivers/dma/dw_dmac.c
index 2272f79..c964f6e 100644
--- a/drivers/dma/dw_dmac.c
+++ b/drivers/dma/dw_dmac.c
@@ -1381,6 +1381,10 @@ static int __devinit dw_probe(struct platform_device *pdev)
 	struct resource		*io;
 	struct dw_dma		*dw;
 	size_t			size;
+	void __iomem		*regs;
+	bool			autocfg;
+	unsigned int		dw_params;
+	unsigned int		nr_channels;
 	int			irq;
 	int			err;
 	int			i;
@@ -1397,23 +1401,32 @@ static int __devinit dw_probe(struct platform_device *pdev)
 	if (irq < 0)
 		return irq;
 
-	size = sizeof(struct dw_dma);
-	size += pdata->nr_channels * sizeof(struct dw_dma_chan);
+	regs = devm_request_and_ioremap(&pdev->dev, io);
+	if (!regs)
+		return -EBUSY;
+
+	dw_params = dma_read_byaddr(regs, DW_PARAMS);
+	autocfg = dw_params >> DW_PARAMS_EN & 0x1;
+
+	if (autocfg)
+		nr_channels = (dw_params >> DW_PARAMS_NR_CHAN & 0x7) + 1;
+	else
+		nr_channels = pdata->nr_channels;
+
+	size = sizeof(struct dw_dma) + nr_channels * sizeof(struct dw_dma_chan);
 	dw = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
 	if (!dw)
 		return -ENOMEM;
 
-	dw->regs = devm_request_and_ioremap(&pdev->dev, io);
-	if (!dw->regs)
-		return -EBUSY;
-
 	dw->clk = devm_clk_get(&pdev->dev, "hclk");
 	if (IS_ERR(dw->clk))
 		return PTR_ERR(dw->clk);
 	clk_prepare_enable(dw->clk);
 
+	dw->regs = regs;
+
 	/* Calculate all channel mask before DMA setup */
-	dw->all_chan_mask = (1 << pdata->nr_channels) - 1;
+	dw->all_chan_mask = (1 << nr_channels) - 1;
 
 	/* force dma off, just in case */
 	dw_dma_off(dw);
@@ -1431,7 +1444,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
 	tasklet_init(&dw->tasklet, dw_dma_tasklet, (unsigned long)dw);
 
 	INIT_LIST_HEAD(&dw->dma.channels);
-	for (i = 0; i < pdata->nr_channels; i++) {
+	for (i = 0; i < nr_channels; i++) {
 		struct dw_dma_chan	*dwc = &dw->chan[i];
 
 		dwc->chan.device = &dw->dma;
@@ -1444,7 +1457,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 = pdata->nr_channels - i - 1;
+			dwc->priority = nr_channels - i - 1;
 		else
 			dwc->priority = i;
 
@@ -1485,7 +1498,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
 	dma_writel(dw, CFG, DW_CFG_DMA_EN);
 
 	printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n",
-			dev_name(&pdev->dev), pdata->nr_channels);
+			dev_name(&pdev->dev), nr_channels);
 
 	dma_async_device_register(&dw->dma);
 
-- 
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   ` Andy Shevchenko [this message]
2012-09-21 13:56     ` [PATCHv2 3/6] dw_dmac: get number of channels from hardware if possible 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   ` [PATCHv2 6/6] dw_dmac: introduce software emulation of LLP transfers Andy Shevchenko
2012-09-21 14:03     ` 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-4-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