Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 482c67ea authored by Andy Shevchenko's avatar Andy Shevchenko Committed by Vinod Koul
Browse files

dw_dmac: get number of channels from hardware if possible



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: default avatarAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Acked-by: default avatarViresh Kumar <viresh.kumar@linaro.org>
Signed-off-by: default avatarVinod Koul <vinod.koul@linux.intel.com>
parent 2a9fe9ae
Loading
Loading
Loading
Loading
+23 −10
Original line number Original line Diff line number Diff line
@@ -1379,6 +1379,10 @@ static int __devinit dw_probe(struct platform_device *pdev)
	struct resource		*io;
	struct resource		*io;
	struct dw_dma		*dw;
	struct dw_dma		*dw;
	size_t			size;
	size_t			size;
	void __iomem		*regs;
	bool			autocfg;
	unsigned int		dw_params;
	unsigned int		nr_channels;
	int			irq;
	int			irq;
	int			err;
	int			err;
	int			i;
	int			i;
@@ -1395,23 +1399,32 @@ static int __devinit dw_probe(struct platform_device *pdev)
	if (irq < 0)
	if (irq < 0)
		return irq;
		return irq;


	size = sizeof(struct dw_dma);
	regs = devm_request_and_ioremap(&pdev->dev, io);
	size += pdata->nr_channels * sizeof(struct dw_dma_chan);
	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);
	dw = devm_kzalloc(&pdev->dev, size, GFP_KERNEL);
	if (!dw)
	if (!dw)
		return -ENOMEM;
		return -ENOMEM;


	dw->regs = devm_request_and_ioremap(&pdev->dev, io);
	if (!dw->regs)
		return -EBUSY;

	dw->clk = devm_clk_get(&pdev->dev, "hclk");
	dw->clk = devm_clk_get(&pdev->dev, "hclk");
	if (IS_ERR(dw->clk))
	if (IS_ERR(dw->clk))
		return PTR_ERR(dw->clk);
		return PTR_ERR(dw->clk);
	clk_prepare_enable(dw->clk);
	clk_prepare_enable(dw->clk);


	dw->regs = regs;

	/* Calculate all channel mask before DMA setup */
	/* 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 */
	/* force dma off, just in case */
	dw_dma_off(dw);
	dw_dma_off(dw);
@@ -1429,7 +1442,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
	tasklet_init(&dw->tasklet, dw_dma_tasklet, (unsigned long)dw);
	tasklet_init(&dw->tasklet, dw_dma_tasklet, (unsigned long)dw);


	INIT_LIST_HEAD(&dw->dma.channels);
	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];
		struct dw_dma_chan	*dwc = &dw->chan[i];


		dwc->chan.device = &dw->dma;
		dwc->chan.device = &dw->dma;
@@ -1442,7 +1455,7 @@ static int __devinit dw_probe(struct platform_device *pdev)


		/* 7 is highest priority & 0 is lowest. */
		/* 7 is highest priority & 0 is lowest. */
		if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING)
		if (pdata->chan_priority == CHAN_PRIORITY_ASCENDING)
			dwc->priority = pdata->nr_channels - i - 1;
			dwc->priority = nr_channels - i - 1;
		else
		else
			dwc->priority = i;
			dwc->priority = i;


@@ -1483,7 +1496,7 @@ static int __devinit dw_probe(struct platform_device *pdev)
	dma_writel(dw, CFG, DW_CFG_DMA_EN);
	dma_writel(dw, CFG, DW_CFG_DMA_EN);


	printk(KERN_INFO "%s: DesignWare DMA Controller, %d channels\n",
	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);
	dma_async_device_register(&dw->dma);