aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh/pfc/gpio.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2012-12-15 17:50:46 -0500
committerSimon Horman <horms+renesas@verge.net.au>2013-01-24 19:24:21 -0500
commit6f6a4a683be97837f3baae443aacd2b0e6162b10 (patch)
treef1a3970e00dfd46df21769c11c7d795ebd192c25 /drivers/sh/pfc/gpio.c
parentf9492fda70c87b410e61675095212dc806bdf615 (diff)
sh-pfc: Merge PFC core and gpio
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>
Diffstat (limited to 'drivers/sh/pfc/gpio.c')
-rw-r--r--drivers/sh/pfc/gpio.c79
1 files changed, 8 insertions, 71 deletions
diff --git a/drivers/sh/pfc/gpio.c b/drivers/sh/pfc/gpio.c
index 565b366c909f..d8b0c74a950d 100644
--- a/drivers/sh/pfc/gpio.c
+++ b/drivers/sh/pfc/gpio.c
@@ -15,7 +15,6 @@
15#include <linux/slab.h> 15#include <linux/slab.h>
16#include <linux/spinlock.h> 16#include <linux/spinlock.h>
17#include <linux/module.h> 17#include <linux/module.h>
18#include <linux/platform_device.h>
19#include <linux/pinctrl/consumer.h> 18#include <linux/pinctrl/consumer.h>
20#include <linux/sh_pfc.h> 19#include <linux/sh_pfc.h>
21 20
@@ -152,44 +151,23 @@ int sh_pfc_register_gpiochip(struct sh_pfc *pfc)
152 sh_pfc_gpio_setup(chip); 151 sh_pfc_gpio_setup(chip);
153 152
154 ret = gpiochip_add(&chip->gpio_chip); 153 ret = gpiochip_add(&chip->gpio_chip);
155 if (unlikely(ret < 0)) 154 if (unlikely(ret < 0)) {
156 kfree(chip); 155 kfree(chip);
156 return ret;
157 }
158
159 pfc->gpio = chip;
157 160
158 pr_info("%s handling gpio %d -> %d\n", 161 pr_info("%s handling gpio %d -> %d\n",
159 pfc->pdata->name, pfc->pdata->first_gpio, 162 pfc->pdata->name, pfc->pdata->first_gpio,
160 pfc->pdata->last_gpio); 163 pfc->pdata->last_gpio);
161 164
162 return ret;
163}
164EXPORT_SYMBOL_GPL(sh_pfc_register_gpiochip);
165
166static int sh_pfc_gpio_match(struct gpio_chip *gc, void *data)
167{
168 return !!strstr(gc->label, data);
169}
170
171static int sh_pfc_gpio_probe(struct platform_device *pdev)
172{
173 struct sh_pfc_chip *chip;
174 struct gpio_chip *gc;
175
176 gc = gpiochip_find("_pfc", sh_pfc_gpio_match);
177 if (unlikely(!gc)) {
178 pr_err("Cant find gpio chip\n");
179 return -ENODEV;
180 }
181
182 chip = gpio_to_pfc_chip(gc);
183 platform_set_drvdata(pdev, chip);
184
185 pr_info("attaching to GPIO chip %s\n", chip->pfc->pdata->name);
186
187 return 0; 165 return 0;
188} 166}
189 167
190static int sh_pfc_gpio_remove(struct platform_device *pdev) 168int sh_pfc_unregister_gpiochip(struct sh_pfc *pfc)
191{ 169{
192 struct sh_pfc_chip *chip = platform_get_drvdata(pdev); 170 struct sh_pfc_chip *chip = pfc->gpio;
193 int ret; 171 int ret;
194 172
195 ret = gpiochip_remove(&chip->gpio_chip); 173 ret = gpiochip_remove(&chip->gpio_chip);
@@ -197,47 +175,6 @@ static int sh_pfc_gpio_remove(struct platform_device *pdev)
197 return ret; 175 return ret;
198 176
199 kfree(chip); 177 kfree(chip);
178 pfc->gpio = NULL;
200 return 0; 179 return 0;
201} 180}
202
203static struct platform_driver sh_pfc_gpio_driver = {
204 .probe = sh_pfc_gpio_probe,
205 .remove = sh_pfc_gpio_remove,
206 .driver = {
207 .name = KBUILD_MODNAME,
208 .owner = THIS_MODULE,
209 },
210};
211
212static struct platform_device sh_pfc_gpio_device = {
213 .name = KBUILD_MODNAME,
214 .id = -1,
215};
216
217static int __init sh_pfc_gpio_init(void)
218{
219 int rc;
220
221 rc = platform_driver_register(&sh_pfc_gpio_driver);
222 if (likely(!rc)) {
223 rc = platform_device_register(&sh_pfc_gpio_device);
224 if (unlikely(rc))
225 platform_driver_unregister(&sh_pfc_gpio_driver);
226 }
227
228 return rc;
229}
230
231static void __exit sh_pfc_gpio_exit(void)
232{
233 platform_device_unregister(&sh_pfc_gpio_device);
234 platform_driver_unregister(&sh_pfc_gpio_driver);
235}
236
237module_init(sh_pfc_gpio_init);
238module_exit(sh_pfc_gpio_exit);
239
240MODULE_AUTHOR("Magnus Damm, Paul Mundt");
241MODULE_DESCRIPTION("GPIO driver for SuperH pin function controller");
242MODULE_LICENSE("GPL v2");
243MODULE_ALIAS("platform:pfc-gpio");