linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data
@ 2013-06-18 15:46 Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 2/4] drivers: bus: imx-weim: Simplify error path Alexander Shiyan
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Alexander Shiyan @ 2013-06-18 15:46 UTC (permalink / raw)
  To: linux-arm-kernel

Driver uses only probe function so no reason to keep variables
in private driver data.

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/bus/imx-weim.c | 41 ++++++++++++++---------------------------
 1 file changed, 14 insertions(+), 27 deletions(-)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 349f14e..0c0e6fe 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -12,11 +12,6 @@
 #include <linux/io.h>
 #include <linux/of_device.h>
 
-struct imx_weim {
-	void __iomem *base;
-	struct clk *clk;
-};
-
 static const struct of_device_id weim_id_table[] = {
 	{ .compatible = "fsl,imx6q-weim", },
 	{}
@@ -27,10 +22,8 @@ MODULE_DEVICE_TABLE(of, weim_id_table);
 #define CS_REG_RANGE  0x18
 
 /* Parse and set the timing for this device. */
-static int
-weim_timing_setup(struct platform_device *pdev, struct device_node *np)
+static int weim_timing_setup(struct device_node *np, void __iomem *base)
 {
-	struct imx_weim *weim = platform_get_drvdata(pdev);
 	u32 value[CS_TIMING_LEN];
 	u32 cs_idx;
 	int ret;
@@ -52,11 +45,11 @@ weim_timing_setup(struct platform_device *pdev, struct device_node *np)
 
 	/* set the timing for WEIM */
 	for (i = 0; i < CS_TIMING_LEN; i++)
-		writel(value[i], weim->base + cs_idx * CS_REG_RANGE + i * 4);
+		writel(value[i], base + cs_idx * CS_REG_RANGE + i * 4);
 	return 0;
 }
 
-static int weim_parse_dt(struct platform_device *pdev)
+static int weim_parse_dt(struct platform_device *pdev, void __iomem *base)
 {
 	struct device_node *child;
 	int ret;
@@ -65,7 +58,7 @@ static int weim_parse_dt(struct platform_device *pdev)
 		if (!child->name)
 			continue;
 
-		ret = weim_timing_setup(pdev, child);
+		ret = weim_timing_setup(child, base);
 		if (ret) {
 			dev_err(&pdev->dev, "%s set timing failed.\n",
 				child->full_name);
@@ -82,38 +75,32 @@ static int weim_parse_dt(struct platform_device *pdev)
 
 static int weim_probe(struct platform_device *pdev)
 {
-	struct imx_weim *weim;
 	struct resource *res;
+	struct clk *clk;
+	void __iomem *base;
 	int ret = -EINVAL;
 
-	weim = devm_kzalloc(&pdev->dev, sizeof(*weim), GFP_KERNEL);
-	if (!weim) {
-		ret = -ENOMEM;
-		goto weim_err;
-	}
-	platform_set_drvdata(pdev, weim);
-
 	/* get the resource */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
-	weim->base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(weim->base)) {
-		ret = PTR_ERR(weim->base);
+	base = devm_ioremap_resource(&pdev->dev, res);
+	if (IS_ERR(base)) {
+		ret = PTR_ERR(base);
 		goto weim_err;
 	}
 
 	/* get the clock */
-	weim->clk = devm_clk_get(&pdev->dev, NULL);
-	if (IS_ERR(weim->clk))
+	clk = devm_clk_get(&pdev->dev, NULL);
+	if (IS_ERR(clk))
 		goto weim_err;
 
-	ret = clk_prepare_enable(weim->clk);
+	ret = clk_prepare_enable(clk);
 	if (ret)
 		goto weim_err;
 
 	/* parse the device node */
-	ret = weim_parse_dt(pdev);
+	ret = weim_parse_dt(pdev, base);
 	if (ret) {
-		clk_disable_unprepare(weim->clk);
+		clk_disable_unprepare(clk);
 		goto weim_err;
 	}
 
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/4] drivers: bus: imx-weim: Simplify error path
  2013-06-18 15:46 [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
@ 2013-06-18 15:46 ` Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 3/4] drivers: bus: imx-weim: use module_platform_driver_probe() Alexander Shiyan
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2013-06-18 15:46 UTC (permalink / raw)
  To: linux-arm-kernel


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/bus/imx-weim.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 0c0e6fe..0f4b081 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -78,36 +78,30 @@ static int weim_probe(struct platform_device *pdev)
 	struct resource *res;
 	struct clk *clk;
 	void __iomem *base;
-	int ret = -EINVAL;
+	int ret;
 
 	/* get the resource */
 	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
 	base = devm_ioremap_resource(&pdev->dev, res);
-	if (IS_ERR(base)) {
-		ret = PTR_ERR(base);
-		goto weim_err;
-	}
+	if (IS_ERR(base))
+		return PTR_ERR(base);
 
 	/* get the clock */
 	clk = devm_clk_get(&pdev->dev, NULL);
 	if (IS_ERR(clk))
-		goto weim_err;
+		return PTR_ERR(clk);
 
 	ret = clk_prepare_enable(clk);
 	if (ret)
-		goto weim_err;
+		return ret;
 
 	/* parse the device node */
 	ret = weim_parse_dt(pdev, base);
-	if (ret) {
+	if (ret)
 		clk_disable_unprepare(clk);
-		goto weim_err;
-	}
-
-	dev_info(&pdev->dev, "WEIM driver registered.\n");
-	return 0;
+	else
+		dev_info(&pdev->dev, "Driver registered.\n");
 
-weim_err:
 	return ret;
 }
 
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 3/4] drivers: bus: imx-weim: use module_platform_driver_probe()
  2013-06-18 15:46 [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 2/4] drivers: bus: imx-weim: Simplify error path Alexander Shiyan
@ 2013-06-18 15:46 ` Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 4/4] drivers: bus: imx-weim: Preparation driver to support different CPUs Alexander Shiyan
  2013-06-19  4:19 ` [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
  3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2013-06-18 15:46 UTC (permalink / raw)
  To: linux-arm-kernel

Driver should be called only once at startup, so code converted
to using module_platform_driver_probe().

Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/bus/imx-weim.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index 0f4b081..f872924 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -22,7 +22,7 @@ MODULE_DEVICE_TABLE(of, weim_id_table);
 #define CS_REG_RANGE  0x18
 
 /* Parse and set the timing for this device. */
-static int weim_timing_setup(struct device_node *np, void __iomem *base)
+static int __init weim_timing_setup(struct device_node *np, void __iomem *base)
 {
 	u32 value[CS_TIMING_LEN];
 	u32 cs_idx;
@@ -49,7 +49,8 @@ static int weim_timing_setup(struct device_node *np, void __iomem *base)
 	return 0;
 }
 
-static int weim_parse_dt(struct platform_device *pdev, void __iomem *base)
+static int __init weim_parse_dt(struct platform_device *pdev,
+				void __iomem *base)
 {
 	struct device_node *child;
 	int ret;
@@ -73,7 +74,7 @@ static int weim_parse_dt(struct platform_device *pdev, void __iomem *base)
 	return ret;
 }
 
-static int weim_probe(struct platform_device *pdev)
+static int __init weim_probe(struct platform_device *pdev)
 {
 	struct resource *res;
 	struct clk *clk;
@@ -110,10 +111,9 @@ static struct platform_driver weim_driver = {
 		.name = "imx-weim",
 		.of_match_table = weim_id_table,
 	},
-	.probe   = weim_probe,
 };
+module_platform_driver_probe(weim_driver, weim_probe);
 
-module_platform_driver(weim_driver);
 MODULE_AUTHOR("Freescale Semiconductor Inc.");
 MODULE_DESCRIPTION("i.MX EIM Controller Driver");
 MODULE_LICENSE("GPL");
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 4/4] drivers: bus: imx-weim: Preparation driver to support different CPUs
  2013-06-18 15:46 [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 2/4] drivers: bus: imx-weim: Simplify error path Alexander Shiyan
  2013-06-18 15:46 ` [PATCH 3/4] drivers: bus: imx-weim: use module_platform_driver_probe() Alexander Shiyan
@ 2013-06-18 15:46 ` Alexander Shiyan
  2013-06-19  4:19 ` [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
  3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2013-06-18 15:46 UTC (permalink / raw)
  To: linux-arm-kernel


Signed-off-by: Alexander Shiyan <shc_work@mail.ru>
---
 drivers/bus/imx-weim.c | 37 +++++++++++++++++++++++++------------
 1 file changed, 25 insertions(+), 12 deletions(-)

diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c
index f872924..5c78ce5 100644
--- a/drivers/bus/imx-weim.c
+++ b/drivers/bus/imx-weim.c
@@ -12,19 +12,29 @@
 #include <linux/io.h>
 #include <linux/of_device.h>
 
+struct imx_weim_devtype {
+	unsigned int	cs_max_num;
+	unsigned int	cs_regs_count;
+	unsigned int	cs_stride;
+};
+
+static const struct imx_weim_devtype imx6q_weim_devtype = {
+      .cs_max_num	= 3,
+      .cs_regs_count	= 6,
+      .cs_stride	= 0x18,
+};
+
 static const struct of_device_id weim_id_table[] = {
-	{ .compatible = "fsl,imx6q-weim", },
-	{}
+	{ .compatible = "fsl,imx6q-weim", .data = &imx6q_weim_devtype, },
+	{ }
 };
 MODULE_DEVICE_TABLE(of, weim_id_table);
 
-#define CS_TIMING_LEN 6
-#define CS_REG_RANGE  0x18
-
 /* Parse and set the timing for this device. */
-static int __init weim_timing_setup(struct device_node *np, void __iomem *base)
+static int __init weim_timing_setup(struct device_node *np, void __iomem *base,
+				    const struct imx_weim_devtype *devtype)
 {
-	u32 value[CS_TIMING_LEN];
+	u32 value[devtype->cs_regs_count];
 	u32 cs_idx;
 	int ret;
 	int i;
@@ -35,23 +45,26 @@ static int __init weim_timing_setup(struct device_node *np, void __iomem *base)
 		return ret;
 
 	/* The weim has four chip selects. */
-	if (cs_idx > 3)
+	if (cs_idx > devtype->cs_max_num)
 		return -EINVAL;
 
 	ret = of_property_read_u32_array(np, "fsl,weim-cs-timing",
-					value, CS_TIMING_LEN);
+					 value, devtype->cs_regs_count);
 	if (ret)
 		return ret;
 
 	/* set the timing for WEIM */
-	for (i = 0; i < CS_TIMING_LEN; i++)
-		writel(value[i], base + cs_idx * CS_REG_RANGE + i * 4);
+	for (i = 0; i < devtype->cs_regs_count; i++)
+		writel(value[i], base + cs_idx * devtype->cs_stride + i * 4);
+
 	return 0;
 }
 
 static int __init weim_parse_dt(struct platform_device *pdev,
 				void __iomem *base)
 {
+	const struct of_device_id *of_id = of_match_device(weim_id_table, &pdev->dev);
+	const struct imx_weim_devtype *devtype = of_id->data;
 	struct device_node *child;
 	int ret;
 
@@ -59,7 +72,7 @@ static int __init weim_parse_dt(struct platform_device *pdev,
 		if (!child->name)
 			continue;
 
-		ret = weim_timing_setup(child, base);
+		ret = weim_timing_setup(child, base, devtype);
 		if (ret) {
 			dev_err(&pdev->dev, "%s set timing failed.\n",
 				child->full_name);
-- 
1.8.1.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data
  2013-06-18 15:46 [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
                   ` (2 preceding siblings ...)
  2013-06-18 15:46 ` [PATCH 4/4] drivers: bus: imx-weim: Preparation driver to support different CPUs Alexander Shiyan
@ 2013-06-19  4:19 ` Alexander Shiyan
  3 siblings, 0 replies; 5+ messages in thread
From: Alexander Shiyan @ 2013-06-19  4:19 UTC (permalink / raw)
  To: linux-arm-kernel

> Driver uses only probe function so no reason to keep variables
> in private driver data.
> 
> Signed-off-by: Alexander Shiyan <shc_work@mail.ru>

Please review this series only. Later, I would send a second version
with the addition of support for the entire i.MX series.
Thanks.

---

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-06-19  4:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-18 15:46 [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan
2013-06-18 15:46 ` [PATCH 2/4] drivers: bus: imx-weim: Simplify error path Alexander Shiyan
2013-06-18 15:46 ` [PATCH 3/4] drivers: bus: imx-weim: use module_platform_driver_probe() Alexander Shiyan
2013-06-18 15:46 ` [PATCH 4/4] drivers: bus: imx-weim: Preparation driver to support different CPUs Alexander Shiyan
2013-06-19  4:19 ` [PATCH 1/4] drivers: bus: imx-weim: Remove private driver data Alexander Shiyan

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).