linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
To: linux-kernel@vger.kernel.org
Cc: Paul Mundt <lethal@linux-sh.org>,
	Magnus Damm <magnus.damm@gmail.com>,
	Simon Horman <horms@verge.net.au>,
	Linus Walleij <linus.walleij@linaro.org>,
	Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>,
	Phil Edworthy <phil.edworthy@renesas.com>,
	Nobuhiro Iwamatsu <nobuhiro.iwamatsu.yj@renesas.com>
Subject: [PATCH 05/42] sh-pfc: Move platform device and driver to the core
Date: Wed, 21 Nov 2012 03:27:06 +0100	[thread overview]
Message-ID: <1353464863-10281-6-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1353464863-10281-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

The pinctrl module registers both a platform device and a platform
driver. The only purpose of this awkward construction is to have a
device to pass to the pinctrl registration function.

As a first step to get rid of this hack, move the platform device and
driver from the pinctrl module to the core. The platform device will
then be moved to arch code.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/sh/pfc/core.c    |  101 +++++++++++++++++++++++++++++++++++++--------
 drivers/sh/pfc/core.h    |    4 ++
 drivers/sh/pfc/gpio.c    |    3 +-
 drivers/sh/pfc/pinctrl.c |  100 +++++++++++----------------------------------
 4 files changed, 114 insertions(+), 94 deletions(-)

diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c
index f8f458b..3593de5 100644
--- a/drivers/sh/pfc/core.c
+++ b/drivers/sh/pfc/core.c
@@ -8,6 +8,8 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
+
+#define DRV_NAME "sh-pfc"
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
 #include <linux/errno.h>
@@ -20,11 +22,10 @@
 #include <linux/slab.h>
 #include <linux/ioport.h>
 #include <linux/pinctrl/machine.h>
+#include <linux/platform_device.h>
 
 #include "core.h"
 
-static struct sh_pfc sh_pfc __read_mostly;
-
 static void pfc_iounmap(struct sh_pfc *pfc)
 {
 	int k;
@@ -494,8 +495,10 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
 	return -1;
 }
 
-int register_sh_pfc(struct sh_pfc_platform_data *pdata)
+static int sh_pfc_probe(struct platform_device *pdev)
 {
+	struct sh_pfc_platform_data *pdata = pdev->dev.platform_data;
+	struct sh_pfc *pfc;
 	int ret;
 
 	/*
@@ -503,26 +506,29 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata)
 	 */
 	BUILD_BUG_ON(PINMUX_FLAG_TYPE > ((1 << PINMUX_FLAG_DBIT_SHIFT) - 1));
 
-	if (sh_pfc.pdata)
-		return -EBUSY;
+	if (pdata == NULL)
+		return -ENODEV;
 
-	sh_pfc.pdata = pdata;
+	pfc = devm_kzalloc(&pdev->dev, sizeof(pfc), GFP_KERNEL);
+	if (pfc == NULL)
+		return -ENOMEM;
 
-	ret = pfc_ioremap(&sh_pfc);
-	if (unlikely(ret < 0)) {
-		sh_pfc.pdata = NULL;
+	pfc->pdata = pdata;
+	pfc->dev = &pdev->dev;
+
+	ret = pfc_ioremap(pfc);
+	if (unlikely(ret < 0))
 		return ret;
-	}
 
-	spin_lock_init(&sh_pfc.lock);
+	spin_lock_init(&pfc->lock);
 
 	pinctrl_provide_dummies();
-	setup_data_regs(&sh_pfc);
+	setup_data_regs(pfc);
 
 	/*
 	 * Initialize pinctrl bindings first
 	 */
-	ret = sh_pfc_register_pinctrl(&sh_pfc);
+	ret = sh_pfc_register_pinctrl(pfc);
 	if (unlikely(ret != 0))
 		goto err;
 
@@ -530,7 +536,7 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata)
 	/*
 	 * Then the GPIO chip
 	 */
-	ret = sh_pfc_register_gpiochip(&sh_pfc);
+	ret = sh_pfc_register_gpiochip(pfc);
 	if (unlikely(ret != 0)) {
 		/*
 		 * If the GPIO chip fails to come up we still leave the
@@ -541,17 +547,76 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata)
 	}
 #endif
 
-	pr_info("%s support registered\n", sh_pfc.pdata->name);
+	platform_set_drvdata(pdev, pfc);
+
+	pr_info("%s support registered\n", pdata->name);
 
 	return 0;
 
 err:
-	pfc_iounmap(&sh_pfc);
-	sh_pfc.pdata = NULL;
-
+	pfc_iounmap(pfc);
 	return ret;
 }
 
+static int __devexit sh_pfc_remove(struct platform_device *pdev)
+{
+	struct sh_pfc *pfc = platform_get_drvdata(pdev);
+
+#ifdef CONFIG_GPIO_SH_PFC
+	sh_pfc_unregister_gpiochip(pfc);
+#endif
+	sh_pfc_unregister_pinctrl(pfc);
+
+	pfc_iounmap(pfc);
+
+	platform_set_drvdata(pdev, NULL);
+
+	return 0;
+}
+
+static const struct platform_device_id sh_pfc_id_table[] = {
+	{ "sh-pfc", 0 },
+	{ },
+};
+MODULE_DEVICE_TABLE(platform, sh_pfc_id_table);
+
+static struct platform_driver sh_pfc_driver = {
+	.probe		= sh_pfc_probe,
+	.remove		= __devexit_p(sh_pfc_remove),
+	.id_table	= sh_pfc_id_table,
+	.driver		= {
+		.name	= DRV_NAME,
+		.owner	= THIS_MODULE,
+	},
+};
+
+static struct platform_device sh_pfc_device = {
+	.name		= DRV_NAME,
+	.id		= -1,
+};
+
+int __init register_sh_pfc(struct sh_pfc_platform_data *pdata)
+{
+	int rc;
+
+	sh_pfc_device.dev.platform_data = pdata;
+
+	rc = platform_driver_register(&sh_pfc_driver);
+	if (likely(!rc)) {
+		rc = platform_device_register(&sh_pfc_device);
+		if (unlikely(rc))
+			platform_driver_unregister(&sh_pfc_driver);
+	}
+
+	return rc;
+}
+
+static void __exit sh_pfc_exit(void)
+{
+	platform_driver_unregister(&sh_pfc_driver);
+}
+module_exit(sh_pfc_exit);
+
 MODULE_AUTHOR("Magnus Damm, Paul Mundt");
 MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
 MODULE_LICENSE("GPL v2");
diff --git a/drivers/sh/pfc/core.h b/drivers/sh/pfc/core.h
index f3032b2..1287b3e 100644
--- a/drivers/sh/pfc/core.h
+++ b/drivers/sh/pfc/core.h
@@ -21,19 +21,23 @@ struct pfc_window {
 };
 
 struct sh_pfc_chip;
+struct sh_pfc_pinctrl;
 
 struct sh_pfc {
+	struct device *dev;
 	struct sh_pfc_platform_data *pdata;
 	spinlock_t lock;
 
 	struct pfc_window *window;
 	struct sh_pfc_chip *gpio;
+	struct sh_pfc_pinctrl *pinctrl;
 };
 
 int sh_pfc_register_gpiochip(struct sh_pfc *pfc);
 int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc);
 
 int sh_pfc_register_pinctrl(struct sh_pfc *pfc);
+int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc);
 
 int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos);
 void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos,
diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c
index 91ea4c9..f22d43a 100644
--- a/drivers/sh/pfc/gpio.c
+++ b/drivers/sh/pfc/gpio.c
@@ -8,7 +8,8 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
-#define pr_fmt(fmt) "sh_pfc " KBUILD_MODNAME ": " fmt
+
+#define pr_fmt(fmt) KBUILD_MODNAME " gpio: " fmt
 
 #include <linux/init.h>
 #include <linux/gpio.h>
diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c
index 0bde9fa..1c93e3c 100644
--- a/drivers/sh/pfc/pinctrl.c
+++ b/drivers/sh/pfc/pinctrl.c
@@ -7,8 +7,8 @@
  * License.  See the file "COPYING" in the main directory of this archive
  * for more details.
  */
-#define DRV_NAME "pinctrl-sh_pfc"
 
+#define DRV_NAME "sh-pfc"
 #define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
 
 #include <linux/init.h>
@@ -17,7 +17,6 @@
 #include <linux/err.h>
 #include <linux/slab.h>
 #include <linux/spinlock.h>
-#include <linux/platform_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/pinctrl/pinctrl.h>
 #include <linux/pinctrl/pinconf.h>
@@ -39,8 +38,6 @@ struct sh_pfc_pinctrl {
 	spinlock_t lock;
 };
 
-static struct sh_pfc_pinctrl *sh_pfc_pmx;
-
 static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
 {
 	struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
@@ -423,28 +420,31 @@ static int __devinit sh_pfc_map_functions(struct sh_pfc *pfc,
 	return 0;
 }
 
-static int __devinit sh_pfc_pinctrl_probe(struct platform_device *pdev)
+int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
 {
-	struct sh_pfc *pfc;
+	struct sh_pfc_pinctrl *pmx;
 	int ret;
 
-	if (unlikely(!sh_pfc_pmx))
-		return -ENODEV;
+	pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
+	if (unlikely(!pmx))
+		return -ENOMEM;
+
+	spin_lock_init(&pmx->lock);
 
-	pfc = sh_pfc_pmx->pfc;
+	pmx->pfc = pfc;
+	pfc->pinctrl = pmx;
 
-	ret = sh_pfc_map_gpios(pfc, sh_pfc_pmx);
+	ret = sh_pfc_map_gpios(pfc, pmx);
 	if (unlikely(ret != 0))
 		return ret;
 
-	ret = sh_pfc_map_functions(pfc, sh_pfc_pmx);
+	ret = sh_pfc_map_functions(pfc, pmx);
 	if (unlikely(ret != 0))
 		goto free_pads;
 
-	sh_pfc_pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, &pdev->dev,
-					    sh_pfc_pmx);
-	if (IS_ERR(sh_pfc_pmx->pctl)) {
-		ret = PTR_ERR(sh_pfc_pmx->pctl);
+	pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
+	if (IS_ERR(pmx->pctl)) {
+		ret = PTR_ERR(pmx->pctl);
 		goto free_functions;
 	}
 
@@ -453,79 +453,29 @@ static int __devinit sh_pfc_pinctrl_probe(struct platform_device *pdev)
 	sh_pfc_gpio_range.base = pfc->pdata->first_gpio;
 	sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio;
 
-	pinctrl_add_gpio_range(sh_pfc_pmx->pctl, &sh_pfc_gpio_range);
-
-	platform_set_drvdata(pdev, sh_pfc_pmx);
+	pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
 
 	return 0;
 
 free_functions:
-	kfree(sh_pfc_pmx->functions);
+	kfree(pmx->functions);
 free_pads:
-	kfree(sh_pfc_pmx->pads);
-	kfree(sh_pfc_pmx);
+	kfree(pmx->pads);
+	kfree(pmx);
 
 	return ret;
 }
 
-static int __devexit sh_pfc_pinctrl_remove(struct platform_device *pdev)
+int __devexit sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
 {
-	struct sh_pfc_pinctrl *pmx = platform_get_drvdata(pdev);
+	struct sh_pfc_pinctrl *pmx = pfc->pinctrl;
 
 	pinctrl_unregister(pmx->pctl);
 
-	platform_set_drvdata(pdev, NULL);
-
-	kfree(sh_pfc_pmx->functions);
-	kfree(sh_pfc_pmx->pads);
-	kfree(sh_pfc_pmx);
+	kfree(pmx->functions);
+	kfree(pmx->pads);
+	kfree(pmx);
 
+	pfc->pinctrl = NULL;
 	return 0;
 }
-
-static struct platform_driver sh_pfc_pinctrl_driver = {
-	.probe		= sh_pfc_pinctrl_probe,
-	.remove		= __devexit_p(sh_pfc_pinctrl_remove),
-	.driver		= {
-		.name	= DRV_NAME,
-		.owner	= THIS_MODULE,
-	},
-};
-
-static struct platform_device sh_pfc_pinctrl_device = {
-	.name		= DRV_NAME,
-	.id		= -1,
-};
-
-static int sh_pfc_pinctrl_init(void)
-{
-	int rc;
-
-	rc = platform_driver_register(&sh_pfc_pinctrl_driver);
-	if (likely(!rc)) {
-		rc = platform_device_register(&sh_pfc_pinctrl_device);
-		if (unlikely(rc))
-			platform_driver_unregister(&sh_pfc_pinctrl_driver);
-	}
-
-	return rc;
-}
-
-int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
-{
-	sh_pfc_pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
-	if (unlikely(!sh_pfc_pmx))
-		return -ENOMEM;
-
-	spin_lock_init(&sh_pfc_pmx->lock);
-
-	sh_pfc_pmx->pfc = pfc;
-
-	return sh_pfc_pinctrl_init();
-}
-
-static void __exit sh_pfc_pinctrl_exit(void)
-{
-	platform_driver_unregister(&sh_pfc_pinctrl_driver);
-}
-module_exit(sh_pfc_pinctrl_exit);
-- 
1.7.8.6


  parent reply	other threads:[~2012-11-21  2:26 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-21  2:27 [PATCH 00/42] SH pin control and GPIO rework Laurent Pinchart
2012-11-21  2:27 ` [PATCH 01/42] sh-pfc: Split platform data from the sh_pfc structure Laurent Pinchart
2012-11-21  2:27 ` [PATCH 02/42] sh-pfc: Move private definitions and declarations to private header Laurent Pinchart
2012-11-21  2:27 ` [PATCH 03/42] sh-pfc: Merge PFC core and pinctrl Laurent Pinchart
2012-11-21  2:27 ` [PATCH 04/42] sh-pfc: Merge PFC core and gpio Laurent Pinchart
2012-11-21  2:27 ` Laurent Pinchart [this message]
2012-11-21  2:27 ` [PATCH 06/42] sh-pfc: Let the compiler decide whether to inline functions Laurent Pinchart
2012-11-21  2:27 ` [PATCH 07/42] sh-pfc: Remove check for impossible error condition Laurent Pinchart
2012-11-21  2:27 ` [PATCH 08/42] sh-pfc: Sort headers alphabetically Laurent Pinchart
2012-11-21  2:27 ` [PATCH 09/42] sh-pfc: Split platform device and platform driver registration Laurent Pinchart
2012-11-21  2:27 ` [PATCH 10/42] sh-pfc: Support passing resources through platform device Laurent Pinchart
2012-11-21  2:27 ` [PATCH 11/42] ARM: shmobile: Register PFC " Laurent Pinchart
2012-11-21  5:16   ` Simon Horman
2012-11-21 12:43     ` Laurent Pinchart
2012-11-26  1:02       ` Simon Horman
2012-11-26 10:34         ` Laurent Pinchart
2012-11-27  2:26           ` Simon Horman
2012-11-27 11:19             ` Laurent Pinchart
2012-11-28  0:58               ` Simon Horman
2012-11-21  2:27 ` [PATCH 12/42] SH: " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 13/42] sh-pfc: Remove platform device registration Laurent Pinchart
2012-11-21  2:27 ` [PATCH 14/42] sh-pfc: Remove unused resource and num_resources platform data fields Laurent Pinchart
2012-11-21  2:27 ` [PATCH 15/42] ARM: shmobile: Select PINCTRL Laurent Pinchart
2012-11-21  2:27 ` [PATCH 16/42] sh: Select PINCTRL for CPU subtypes that require it Laurent Pinchart
2012-11-21  2:27 ` [PATCH 17/42] sh-pfc: Move driver from drivers/sh/ to drivers/pinctrl/ Laurent Pinchart
2012-11-21  3:28   ` viresh kumar
2012-11-21 13:17     ` Laurent Pinchart
2012-11-21  2:27 ` [PATCH 18/42] sh-pfc: Support pinmux info in driver data instead of platform data Laurent Pinchart
2012-11-21  2:27 ` [PATCH 19/42] sh-pfc: Add r8a7740 pinmux support Laurent Pinchart
2012-11-21  2:27 ` [PATCH 20/42] sh-pfc: Add r8a7779 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 21/42] sh-pfc: Add sh7367 " Laurent Pinchart
2012-11-22  4:56   ` Nobuhiro Iwamatsu
2012-11-21  2:27 ` [PATCH 22/42] sh-pfc: Add sh7372 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 23/42] sh-pfc: Add sh7377 " Laurent Pinchart
2012-11-22  4:55   ` Nobuhiro Iwamatsu
2012-11-22 11:12     ` Laurent Pinchart
2012-11-21  2:27 ` [PATCH 24/42] sh-pfc: Add sh73a0 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 25/42] ARM: shmobile: pfc: Use driver-provided pinmux info Laurent Pinchart
2012-11-21  2:27 ` [PATCH 26/42] sh-pfc: Add sh7203 pinmux support Laurent Pinchart
2012-11-21  2:27 ` [PATCH 27/42] sh-pfc: Add sh7264 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 28/42] sh-pfc: Add sh7269 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 29/42] sh-pfc: Add sh7720 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 30/42] sh-pfc: Add sh7722 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 31/42] sh-pfc: Add sh7723 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 32/42] sh-pfc: Add sh7724 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 33/42] sh-pfc: Add sh7734 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 34/42] sh-pfc: Add sh7757 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 35/42] sh-pfc: Add sh7785 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 36/42] sh-pfc: Add sh7786 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 37/42] sh-pfc: Add shx3 " Laurent Pinchart
2012-11-21  2:27 ` [PATCH 39/42] sh-pfc: Remove pinmux_info definition Laurent Pinchart
2012-11-21  2:27 ` [PATCH 40/42] sh-pfc: Move sh_pfc.h from include/linux/ to driver directory Laurent Pinchart
2012-11-21  2:27 ` [PATCH 41/42] ARM: shmobile: r8a7740: Add pin control resources Laurent Pinchart
2012-11-21  2:27 ` [PATCH 42/42] ARM: shmobile: sh7372: " Laurent Pinchart
2012-11-21  4:23 ` [PATCH 00/42] SH pin control and GPIO rework Paul Mundt
2012-11-21 14:51 ` Linus Walleij

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=1353464863-10281-6-git-send-email-laurent.pinchart+renesas@ideasonboard.com \
    --to=laurent.pinchart+renesas@ideasonboard.com \
    --cc=horms@verge.net.au \
    --cc=kuninori.morimoto.gx@renesas.com \
    --cc=lethal@linux-sh.org \
    --cc=linus.walleij@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=nobuhiro.iwamatsu.yj@renesas.com \
    --cc=phil.edworthy@renesas.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;
as well as URLs for NNTP newsgroup(s).