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 04/42] sh-pfc: Merge PFC core and gpio
Date: Wed, 21 Nov 2012 03:27:05 +0100	[thread overview]
Message-ID: <1353464863-10281-5-git-send-email-laurent.pinchart+renesas@ideasonboard.com> (raw)
In-Reply-To: <1353464863-10281-1-git-send-email-laurent.pinchart+renesas@ideasonboard.com>

The PFC core calls the gpio module gpiochip registration in its
register_sh_pfc() function, itself called at arch initialization time.
If the gpio module isn't present then the gpiochip will never be
registered.

As the gpio module can only be present at arch initialization time if
it's builtin, there's no point in allowing to build it as a module. Make
it a boolean option, and initialize it synchronously with the core if
selected.

Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
---
 drivers/sh/pfc/Kconfig  |    2 +-
 drivers/sh/pfc/Makefile |    4 ++-
 drivers/sh/pfc/core.c   |   23 +++++--------
 drivers/sh/pfc/core.h   |    4 ++
 drivers/sh/pfc/gpio.c   |   79 +++++------------------------------------------
 5 files changed, 25 insertions(+), 87 deletions(-)

diff --git a/drivers/sh/pfc/Kconfig b/drivers/sh/pfc/Kconfig
index f33d82a..eaeabc5 100644
--- a/drivers/sh/pfc/Kconfig
+++ b/drivers/sh/pfc/Kconfig
@@ -11,7 +11,7 @@ config SH_PFC
 	def_bool y
 
 config GPIO_SH_PFC
-	tristate "SuperH PFC GPIO support"
+	bool "SuperH PFC GPIO support"
 	depends on SH_PFC && GPIOLIB
 	help
 	  This enables support for GPIOs within the SoC's pin function
diff --git a/drivers/sh/pfc/Makefile b/drivers/sh/pfc/Makefile
index ce6fae3..6315cf3 100644
--- a/drivers/sh/pfc/Makefile
+++ b/drivers/sh/pfc/Makefile
@@ -1,3 +1,5 @@
 sh-pfc-objs			= core.o pinctrl.o
+ifeq ($(CONFIG_GPIO_SH_PFC),y)
+sh-pfc-objs			+= gpio.o
+endif
 obj-y				+= sh-pfc.o
-obj-$(CONFIG_GPIO_SH_PFC)	+= gpio.o
diff --git a/drivers/sh/pfc/core.c b/drivers/sh/pfc/core.c
index 30e33db..f8f458b 100644
--- a/drivers/sh/pfc/core.c
+++ b/drivers/sh/pfc/core.c
@@ -149,7 +149,6 @@ int sh_pfc_read_bit(struct pinmux_data_reg *dr, unsigned long in_pos)
 
 	return (gpio_read_raw_reg(dr->mapped_reg, dr->reg_width) >> pos) & 1;
 }
-EXPORT_SYMBOL_GPL(sh_pfc_read_bit);
 
 void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos,
 		      unsigned long value)
@@ -169,7 +168,6 @@ void sh_pfc_write_bit(struct pinmux_data_reg *dr, unsigned long in_pos,
 
 	gpio_write_raw_reg(dr->mapped_reg, dr->reg_width, dr->reg_shadow);
 }
-EXPORT_SYMBOL_GPL(sh_pfc_write_bit);
 
 static void config_reg_helper(struct sh_pfc *pfc,
 			      struct pinmux_cfg_reg *crp,
@@ -307,7 +305,6 @@ int sh_pfc_get_data_reg(struct sh_pfc *pfc, unsigned gpio,
 	*bitp = n;
 	return 0;
 }
-EXPORT_SYMBOL_GPL(sh_pfc_get_data_reg);
 
 static int get_config_reg(struct sh_pfc *pfc, pinmux_enum_t enum_id,
 			  struct pinmux_cfg_reg **crp,
@@ -384,7 +381,6 @@ int sh_pfc_gpio_to_enum(struct sh_pfc *pfc, unsigned gpio, int pos,
 	pr_err("cannot locate data/mark enum_id for gpio %d\n", gpio);
 	return -1;
 }
-EXPORT_SYMBOL_GPL(sh_pfc_gpio_to_enum);
 
 int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
 		       int cfg_mode)
@@ -500,7 +496,6 @@ int sh_pfc_config_gpio(struct sh_pfc *pfc, unsigned gpio, int pinmux_type,
 
 int register_sh_pfc(struct sh_pfc_platform_data *pdata)
 {
-	int (*initroutine)(struct sh_pfc *) = NULL;
 	int ret;
 
 	/*
@@ -531,24 +526,20 @@ int register_sh_pfc(struct sh_pfc_platform_data *pdata)
 	if (unlikely(ret != 0))
 		goto err;
 
+#ifdef CONFIG_GPIO_SH_PFC
 	/*
 	 * Then the GPIO chip
 	 */
-	initroutine = symbol_request(sh_pfc_register_gpiochip);
-	if (initroutine) {
-		ret = (*initroutine)(&sh_pfc);
-		symbol_put_addr(initroutine);
-
+	ret = sh_pfc_register_gpiochip(&sh_pfc);
+	if (unlikely(ret != 0)) {
 		/*
 		 * If the GPIO chip fails to come up we still leave the
 		 * PFC state as it is, given that there are already
 		 * extant users of it that have succeeded by this point.
 		 */
-		if (unlikely(ret != 0)) {
-			pr_notice("failed to init GPIO chip, ignoring...\n");
-			ret = 0;
-		}
+		pr_notice("failed to init GPIO chip, ignoring...\n");
 	}
+#endif
 
 	pr_info("%s support registered\n", sh_pfc.pdata->name);
 
@@ -560,3 +551,7 @@ err:
 
 	return ret;
 }
+
+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 b07ae25..f3032b2 100644
--- a/drivers/sh/pfc/core.h
+++ b/drivers/sh/pfc/core.h
@@ -20,14 +20,18 @@ struct pfc_window {
 	unsigned long size;
 };
 
+struct sh_pfc_chip;
+
 struct sh_pfc {
 	struct sh_pfc_platform_data *pdata;
 	spinlock_t lock;
 
 	struct pfc_window *window;
+	struct sh_pfc_chip *gpio;
 };
 
 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);
 
diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c
index 94c5489..91ea4c9 100644
--- a/drivers/sh/pfc/gpio.c
+++ b/drivers/sh/pfc/gpio.c
@@ -15,7 +15,6 @@
 #include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <linux/module.h>
-#include <linux/platform_device.h>
 #include <linux/pinctrl/consumer.h>
 #include <linux/sh_pfc.h>
 
@@ -152,44 +151,23 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
 	sh_pfc_gpio_setup(chip);
 
 	ret = gpiochip_add(&chip->gpio_chip);
-	if (unlikely(ret < 0))
+	if (unlikely(ret < 0)) {
 		kfree(chip);
+		return ret;
+	}
+
+	pfc->gpio = chip;
 
 	pr_info("%s handling gpio %d -> %d\n",
 		pfc->pdata->name, pfc->pdata->first_gpio,
 		pfc->pdata->last_gpio);
 
-	return ret;
-}
-EXPORT_SYMBOL_GPL(sh_pfc_register_gpiochip);
-
-static int sh_pfc_gpio_match(struct gpio_chip *gc, void *data)
-{
-	return !!strstr(gc->label, data);
-}
-
-static int __devinit sh_pfc_gpio_probe(struct platform_device *pdev)
-{
-	struct sh_pfc_chip *chip;
-	struct gpio_chip *gc;
-
-	gc = gpiochip_find("_pfc", sh_pfc_gpio_match);
-	if (unlikely(!gc)) {
-		pr_err("Cant find gpio chip\n");
-		return -ENODEV;
-	}
-
-	chip = gpio_to_pfc_chip(gc);
-	platform_set_drvdata(pdev, chip);
-
-	pr_info("attaching to GPIO chip %s\n", chip->pfc->pdata->name);
-
 	return 0;
 }
 
-static int __devexit sh_pfc_gpio_remove(struct platform_device *pdev)
+int __exit sh_pfc_unregister_gpiochip(struct sh_pfc *pfc)
 {
-	struct sh_pfc_chip *chip = platform_get_drvdata(pdev);
+	struct sh_pfc_chip *chip = pfc->gpio;
 	int ret;
 
 	ret = gpiochip_remove(&chip->gpio_chip);
@@ -197,47 +175,6 @@ static int __devexit sh_pfc_gpio_remove(struct platform_device *pdev)
 		return ret;
 
 	kfree(chip);
+	pfc->gpio = NULL;
 	return 0;
 }
-
-static struct platform_driver sh_pfc_gpio_driver = {
-	.probe		= sh_pfc_gpio_probe,
-	.remove		= __devexit_p(sh_pfc_gpio_remove),
-	.driver		= {
-		.name	= KBUILD_MODNAME,
-		.owner	= THIS_MODULE,
-	},
-};
-
-static struct platform_device sh_pfc_gpio_device = {
-	.name		= KBUILD_MODNAME,
-	.id		= -1,
-};
-
-static int __init sh_pfc_gpio_init(void)
-{
-	int rc;
-
-	rc = platform_driver_register(&sh_pfc_gpio_driver);
-	if (likely(!rc)) {
-		rc = platform_device_register(&sh_pfc_gpio_device);
-		if (unlikely(rc))
-			platform_driver_unregister(&sh_pfc_gpio_driver);
-	}
-
-	return rc;
-}
-
-static void __exit sh_pfc_gpio_exit(void)
-{
-	platform_device_unregister(&sh_pfc_gpio_device);
-	platform_driver_unregister(&sh_pfc_gpio_driver);
-}
-
-module_init(sh_pfc_gpio_init);
-module_exit(sh_pfc_gpio_exit);
-
-MODULE_AUTHOR("Magnus Damm, Paul Mundt");
-MODULE_DESCRIPTION("GPIO driver for SuperH pin function controller");
-MODULE_LICENSE("GPL v2");
-MODULE_ALIAS("platform:pfc-gpio");
-- 
1.7.8.6


  parent reply	other threads:[~2012-11-21  2:37 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 ` Laurent Pinchart [this message]
2012-11-21  2:27 ` [PATCH 05/42] sh-pfc: Move platform device and driver to the core Laurent Pinchart
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-5-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).