sh-pfc: Merge PFC core and gpio
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>
Sat, 15 Dec 2012 22:50:46 +0000 (23:50 +0100)
committerSimon Horman <horms+renesas@verge.net.au>
Fri, 25 Jan 2013 00:24:21 +0000 (09:24 +0900)
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>
Acked-by: Paul Mundt <lethal@linux-sh.org>
Acked-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Simon Horman <horms+renesas@verge.net.au>
drivers/sh/pfc/Kconfig
drivers/sh/pfc/Makefile
drivers/sh/pfc/core.c
drivers/sh/pfc/core.h
drivers/sh/pfc/gpio.c

index f33d82a38b4bd9dedef2b22a1df65d9b232a11c6..eaeabc58bb06690f393b9c533ddcb690990fd2f1 100644 (file)
@@ -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
index ce6fae353844c625f9b11b4170f2bcd41b279223..6315cf35b34d4ab4889a36daa91dcda5791a5193 100644 (file)
@@ -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
index 30e33db7a2dc3c389a44eb7fff8397b4b78dfc9e..541099613a21d92352dc484f1a5fc460f5706143 100644 (file)
@@ -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, Laurent Pinchart");
+MODULE_DESCRIPTION("Pin Control and GPIO driver for SuperH pin function controller");
+MODULE_LICENSE("GPL v2");
index b07ae259c0eb29b73111674ecd2f2d7b463a1135..f3032b232fb00cf3b95a2f25b344b883aa878719 100644 (file)
@@ -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);
 
index 565b366c909ff5fbe1f35bfcaa3fc6f8e8aa5d8f..d8b0c74a950d7975dd73867058efa83f7a284b9d 100644 (file)
@@ -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 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 sh_pfc_gpio_remove(struct platform_device *pdev)
+int 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 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         = 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");