diff mbox series

[v3,5/8] dmaengine: fsl-edma: add drvdata for vf610

Message ID 20190529090848.34350-6-yibin.gong@nxp.com (mailing list archive)
State New, archived
Headers show
Series add edma2 for i.mx7ulp | expand

Commit Message

Robin Gong May 29, 2019, 9:08 a.m. UTC
From: Robin Gong <yibin.gong@nxp.com>

There are some differences between vf610 and next i.mx7ulp. Put such
differences into static driver data for distiguish easily in driver.

Signed-off-by: Robin Gong <yibin.gong@nxp.com>
---
 drivers/dma/fsl-edma-common.h | 10 ++++++++++
 drivers/dma/fsl-edma.c        | 36 +++++++++++++++++++++++++++---------
 2 files changed, 37 insertions(+), 9 deletions(-)

Comments

Vinod Koul June 4, 2019, 12:33 p.m. UTC | #1
On 29-05-19, 17:08, yibin.gong@nxp.com wrote:

> @@ -205,8 +228,9 @@ static int fsl_edma_probe(struct platform_device *pdev)
>  	if (!fsl_edma)
>  		return -ENOMEM;
>  
> -	fsl_edma->version = v1;
> -	fsl_edma->dmamux_nr = DMAMUX_NR;
> +	fsl_edma->drvdata = drvdata;
> +	fsl_edma->version = drvdata->version;
> +	fsl_edma->dmamux_nr = drvdata->dmamuxs;

And can we avoid the duplication here, you have version and dmamuxs
represented in two places. But right now it looks logical so the removal
should be done after this series
Robin Gong June 5, 2019, 2:25 a.m. UTC | #2
On 二, 2019-06-04 at 18:03 +0530, Vinod Koul wrote:
> On 29-05-19, 17:08, yibin.gong@nxp.com wrote:
> 
> > 
> > @@ -205,8 +228,9 @@ static int fsl_edma_probe(struct
> > platform_device *pdev)
> >  	if (!fsl_edma)
> >  		return -ENOMEM;
> >  
> > -	fsl_edma->version = v1;
> > -	fsl_edma->dmamux_nr = DMAMUX_NR;
> > +	fsl_edma->drvdata = drvdata;
> > +	fsl_edma->version = drvdata->version;
> > +	fsl_edma->dmamux_nr = drvdata->dmamuxs;
> And can we avoid the duplication here, you have version and dmamuxs
> represented in two places. But right now it looks logical so the
> removal
> should be done after this series
To avoid more code changes in other edma driver such as mcf-edma.c and
fsl-edma-common.c(replace all version/dmamux_nr with new
'drvdata'),meanwhile, no board to test mcf-edma so I keep
'version'/'dmamux' here in the last minute. But if you stick, I would
try to refine it in next version. 
>
diff mbox series

Patch

diff --git a/drivers/dma/fsl-edma-common.h b/drivers/dma/fsl-edma-common.h
index 21a9cfd..014ab74 100644
--- a/drivers/dma/fsl-edma-common.h
+++ b/drivers/dma/fsl-edma-common.h
@@ -7,6 +7,7 @@ 
 #define _FSL_EDMA_COMMON_H_
 
 #include <linux/dma-direction.h>
+#include <linux/platform_device.h>
 #include "virt-dma.h"
 
 #define EDMA_CR_EDBG		BIT(1)
@@ -140,6 +141,14 @@  enum edma_version {
 	v2, /* 64ch Coldfire */
 };
 
+struct fsl_edma_drvdata {
+	enum edma_version	version;
+	u32	dmamuxs;
+	bool	has_dmaclk;
+	int	(*setup_irq)(struct platform_device *pdev,
+			     struct fsl_edma_engine *fsl_edma);
+};
+
 struct fsl_edma_engine {
 	struct dma_device	dma_dev;
 	void __iomem		*membase;
@@ -147,6 +156,7 @@  struct fsl_edma_engine {
 	struct clk		*muxclk[DMAMUX_NR];
 	u32			dmamux_nr;
 	struct mutex		fsl_edma_mutex;
+	const struct fsl_edma_drvdata *drvdata;
 	u32			n_chans;
 	int			txirq;
 	int			errirq;
diff --git a/drivers/dma/fsl-edma.c b/drivers/dma/fsl-edma.c
index 7b65ef4..cf18301 100644
--- a/drivers/dma/fsl-edma.c
+++ b/drivers/dma/fsl-edma.c
@@ -184,16 +184,39 @@  static void fsl_disable_clocks(struct fsl_edma_engine *fsl_edma, int nr_clocks)
 		clk_disable_unprepare(fsl_edma->muxclk[i]);
 }
 
+static struct fsl_edma_drvdata vf610_data = {
+	.version = v1,
+	.dmamuxs = DMAMUX_NR,
+	.has_dmaclk = false,
+	.setup_irq = fsl_edma_irq_init,
+};
+
+static const struct of_device_id fsl_edma_dt_ids[] = {
+	{ .compatible = "fsl,vf610-edma", .data = &vf610_data},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(of, fsl_edma_dt_ids);
+
 static int fsl_edma_probe(struct platform_device *pdev)
 {
+	const struct of_device_id *of_id =
+			of_match_device(fsl_edma_dt_ids, &pdev->dev);
 	struct device_node *np = pdev->dev.of_node;
 	struct fsl_edma_engine *fsl_edma;
+	const struct fsl_edma_drvdata *drvdata = NULL;
 	struct fsl_edma_chan *fsl_chan;
 	struct edma_regs *regs;
 	struct resource *res;
 	int len, chans;
 	int ret, i;
 
+	if (of_id)
+		drvdata = of_id->data;
+	if (!drvdata) {
+		dev_err(&pdev->dev, "unable to find driver data\n");
+		return -EINVAL;
+	}
+
 	ret = of_property_read_u32(np, "dma-channels", &chans);
 	if (ret) {
 		dev_err(&pdev->dev, "Can't get dma-channels.\n");
@@ -205,8 +228,9 @@  static int fsl_edma_probe(struct platform_device *pdev)
 	if (!fsl_edma)
 		return -ENOMEM;
 
-	fsl_edma->version = v1;
-	fsl_edma->dmamux_nr = DMAMUX_NR;
+	fsl_edma->drvdata = drvdata;
+	fsl_edma->version = drvdata->version;
+	fsl_edma->dmamux_nr = drvdata->dmamuxs;
 	fsl_edma->n_chans = chans;
 	mutex_init(&fsl_edma->fsl_edma_mutex);
 
@@ -264,7 +288,7 @@  static int fsl_edma_probe(struct platform_device *pdev)
 	}
 
 	edma_writel(fsl_edma, ~0, regs->intl);
-	ret = fsl_edma_irq_init(pdev, fsl_edma);
+	ret = fsl_edma->drvdata->setup_irq(pdev, fsl_edma);
 	if (ret)
 		return ret;
 
@@ -383,12 +407,6 @@  static const struct dev_pm_ops fsl_edma_pm_ops = {
 	.resume_early   = fsl_edma_resume_early,
 };
 
-static const struct of_device_id fsl_edma_dt_ids[] = {
-	{ .compatible = "fsl,vf610-edma", },
-	{ /* sentinel */ }
-};
-MODULE_DEVICE_TABLE(of, fsl_edma_dt_ids);
-
 static struct platform_driver fsl_edma_driver = {
 	.driver		= {
 		.name	= "fsl-edma",