From 70ac98da780f7085d8c5f0e89bd0438a7f286d20 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sat, 29 Jun 2013 08:27:50 +0400 Subject: drivers: bus: imx-weim: Remove private driver data Driver uses only probe function so no reason to keep variables in private driver data. Signed-off-by: Alexander Shiyan Signed-off-by: Shawn Guo --- drivers/bus/imx-weim.c | 41 ++++++++++++++--------------------------- 1 file changed, 14 insertions(+), 27 deletions(-) (limited to 'drivers/bus') diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 349f14e886b7..0c0e6fea129f 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -12,11 +12,6 @@ #include #include -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; } -- cgit v1.2.3 From b2d1fb7332f2bb8c0630f224d8e2151c0e157004 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sat, 29 Jun 2013 08:27:51 +0400 Subject: drivers: bus: imx-weim: Simplify error path Signed-off-by: Alexander Shiyan Signed-off-by: Shawn Guo --- drivers/bus/imx-weim.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'drivers/bus') diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 0c0e6fea129f..0f4b08112afb 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; } -- cgit v1.2.3 From 29e54970c2681ad621d13df739d0cddf052acf9d Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sat, 29 Jun 2013 08:27:52 +0400 Subject: drivers: bus: imx-weim: use module_platform_driver_probe() Driver should be called only once at startup, so code converted to using module_platform_driver_probe(). Signed-off-by: Alexander Shiyan Signed-off-by: Shawn Guo --- drivers/bus/imx-weim.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'drivers/bus') diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index 0f4b08112afb..f8729247e48e 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"); -- cgit v1.2.3 From fc608c745cf71a7abb673d891104597120042f21 Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sat, 29 Jun 2013 08:27:53 +0400 Subject: drivers: bus: imx-weim: Add missing platform_driver.owner field Signed-off-by: Alexander Shiyan Signed-off-by: Shawn Guo --- drivers/bus/imx-weim.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/bus') diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index f8729247e48e..dc860a411343 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -108,8 +108,9 @@ static int __init weim_probe(struct platform_device *pdev) static struct platform_driver weim_driver = { .driver = { - .name = "imx-weim", - .of_match_table = weim_id_table, + .name = "imx-weim", + .owner = THIS_MODULE, + .of_match_table = weim_id_table, }, }; module_platform_driver_probe(weim_driver, weim_probe); -- cgit v1.2.3 From 3f98b6baad63b181da4e859d81953e88ce8a50ec Mon Sep 17 00:00:00 2001 From: Alexander Shiyan Date: Sat, 29 Jun 2013 08:27:54 +0400 Subject: drivers: bus: imx-weim: Add support for i.MX1/21/25/27/31/35/50/51/53 This patch adds WEIM support for all i.MX CPUs supported by the kernel. Signed-off-by: Alexander Shiyan Signed-off-by: Shawn Guo --- drivers/bus/Kconfig | 3 +-- drivers/bus/imx-weim.c | 69 ++++++++++++++++++++++++++++++++++++++------------ 2 files changed, 54 insertions(+), 18 deletions(-) (limited to 'drivers/bus') diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig index 1f70e84b442c..552373c4e362 100644 --- a/drivers/bus/Kconfig +++ b/drivers/bus/Kconfig @@ -8,10 +8,9 @@ config IMX_WEIM bool "Freescale EIM DRIVER" depends on ARCH_MXC help - Driver for i.MX6 WEIM controller. + Driver for i.MX WEIM controller. The WEIM(Wireless External Interface Module) works like a bus. You can attach many different devices on it, such as NOR, onenand. - But now, we only support the Parallel NOR. config MVEBU_MBUS bool diff --git a/drivers/bus/imx-weim.c b/drivers/bus/imx-weim.c index dc860a411343..3ef58c8dbf11 100644 --- a/drivers/bus/imx-weim.c +++ b/drivers/bus/imx-weim.c @@ -12,46 +12,83 @@ #include #include +struct imx_weim_devtype { + unsigned int cs_count; + unsigned int cs_regs_count; + unsigned int cs_stride; +}; + +static const struct imx_weim_devtype imx1_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 2, + .cs_stride = 0x08, +}; + +static const struct imx_weim_devtype imx27_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 3, + .cs_stride = 0x10, +}; + +static const struct imx_weim_devtype imx50_weim_devtype = { + .cs_count = 4, + .cs_regs_count = 6, + .cs_stride = 0x18, +}; + +static const struct imx_weim_devtype imx51_weim_devtype = { + .cs_count = 6, + .cs_regs_count = 6, + .cs_stride = 0x18, +}; + static const struct of_device_id weim_id_table[] = { - { .compatible = "fsl,imx6q-weim", }, - {} + /* i.MX1/21 */ + { .compatible = "fsl,imx1-weim", .data = &imx1_weim_devtype, }, + /* i.MX25/27/31/35 */ + { .compatible = "fsl,imx27-weim", .data = &imx27_weim_devtype, }, + /* i.MX50/53/6Q */ + { .compatible = "fsl,imx50-weim", .data = &imx50_weim_devtype, }, + { .compatible = "fsl,imx6q-weim", .data = &imx50_weim_devtype, }, + /* i.MX51 */ + { .compatible = "fsl,imx51-weim", .data = &imx51_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 cs_idx; - int ret; - int i; + u32 cs_idx, value[devtype->cs_regs_count]; + int i, ret; /* get the CS index from this child node's "reg" property. */ ret = of_property_read_u32(np, "reg", &cs_idx); if (ret) return ret; - /* The weim has four chip selects. */ - if (cs_idx > 3) + if (cs_idx >= devtype->cs_count) 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 +96,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); -- cgit v1.2.3