aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh/pfc/pinctrl.c
diff options
context:
space:
mode:
authorLaurent Pinchart <laurent.pinchart+renesas@ideasonboard.com>2012-12-15 17:50:47 -0500
committerSimon Horman <horms+renesas@verge.net.au>2013-01-24 19:24:21 -0500
commitc6193eacda6d50c405b0d484f5f2577ff9068a13 (patch)
treed736dd1e72bd85664698e7dcecc461fd1d991bef /drivers/sh/pfc/pinctrl.c
parent6f6a4a683be97837f3baae443aacd2b0e6162b10 (diff)
sh-pfc: Move platform device and driver to the core
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> 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/pinctrl.c')
-rw-r--r--drivers/sh/pfc/pinctrl.c100
1 files changed, 25 insertions, 75 deletions
diff --git a/drivers/sh/pfc/pinctrl.c b/drivers/sh/pfc/pinctrl.c
index 6f0f58bd3f87..2fc873137ce8 100644
--- a/drivers/sh/pfc/pinctrl.c
+++ b/drivers/sh/pfc/pinctrl.c
@@ -7,8 +7,8 @@
7 * License. See the file "COPYING" in the main directory of this archive 7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details. 8 * for more details.
9 */ 9 */
10#define DRV_NAME "pinctrl-sh_pfc"
11 10
11#define DRV_NAME "sh-pfc"
12#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt 12#define pr_fmt(fmt) KBUILD_MODNAME " pinctrl: " fmt
13 13
14#include <linux/init.h> 14#include <linux/init.h>
@@ -17,7 +17,6 @@
17#include <linux/err.h> 17#include <linux/err.h>
18#include <linux/slab.h> 18#include <linux/slab.h>
19#include <linux/spinlock.h> 19#include <linux/spinlock.h>
20#include <linux/platform_device.h>
21#include <linux/pinctrl/consumer.h> 20#include <linux/pinctrl/consumer.h>
22#include <linux/pinctrl/pinctrl.h> 21#include <linux/pinctrl/pinctrl.h>
23#include <linux/pinctrl/pinconf.h> 22#include <linux/pinctrl/pinconf.h>
@@ -39,8 +38,6 @@ struct sh_pfc_pinctrl {
39 spinlock_t lock; 38 spinlock_t lock;
40}; 39};
41 40
42static struct sh_pfc_pinctrl *sh_pfc_pmx;
43
44static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev) 41static int sh_pfc_get_groups_count(struct pinctrl_dev *pctldev)
45{ 42{
46 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev); 43 struct sh_pfc_pinctrl *pmx = pinctrl_dev_get_drvdata(pctldev);
@@ -421,28 +418,31 @@ static int sh_pfc_map_functions(struct sh_pfc *pfc, struct sh_pfc_pinctrl *pmx)
421 return 0; 418 return 0;
422} 419}
423 420
424static int sh_pfc_pinctrl_probe(struct platform_device *pdev) 421int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
425{ 422{
426 struct sh_pfc *pfc; 423 struct sh_pfc_pinctrl *pmx;
427 int ret; 424 int ret;
428 425
429 if (unlikely(!sh_pfc_pmx)) 426 pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
430 return -ENODEV; 427 if (unlikely(!pmx))
428 return -ENOMEM;
429
430 spin_lock_init(&pmx->lock);
431 431
432 pfc = sh_pfc_pmx->pfc; 432 pmx->pfc = pfc;
433 pfc->pinctrl = pmx;
433 434
434 ret = sh_pfc_map_gpios(pfc, sh_pfc_pmx); 435 ret = sh_pfc_map_gpios(pfc, pmx);
435 if (unlikely(ret != 0)) 436 if (unlikely(ret != 0))
436 return ret; 437 return ret;
437 438
438 ret = sh_pfc_map_functions(pfc, sh_pfc_pmx); 439 ret = sh_pfc_map_functions(pfc, pmx);
439 if (unlikely(ret != 0)) 440 if (unlikely(ret != 0))
440 goto free_pads; 441 goto free_pads;
441 442
442 sh_pfc_pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, &pdev->dev, 443 pmx->pctl = pinctrl_register(&sh_pfc_pinctrl_desc, pfc->dev, pmx);
443 sh_pfc_pmx); 444 if (IS_ERR(pmx->pctl)) {
444 if (IS_ERR(sh_pfc_pmx->pctl)) { 445 ret = PTR_ERR(pmx->pctl);
445 ret = PTR_ERR(sh_pfc_pmx->pctl);
446 goto free_functions; 446 goto free_functions;
447 } 447 }
448 448
@@ -451,79 +451,29 @@ static int sh_pfc_pinctrl_probe(struct platform_device *pdev)
451 sh_pfc_gpio_range.base = pfc->pdata->first_gpio; 451 sh_pfc_gpio_range.base = pfc->pdata->first_gpio;
452 sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio; 452 sh_pfc_gpio_range.pin_base = pfc->pdata->first_gpio;
453 453
454 pinctrl_add_gpio_range(sh_pfc_pmx->pctl, &sh_pfc_gpio_range); 454 pinctrl_add_gpio_range(pmx->pctl, &sh_pfc_gpio_range);
455
456 platform_set_drvdata(pdev, sh_pfc_pmx);
457 455
458 return 0; 456 return 0;
459 457
460free_functions: 458free_functions:
461 kfree(sh_pfc_pmx->functions); 459 kfree(pmx->functions);
462free_pads: 460free_pads:
463 kfree(sh_pfc_pmx->pads); 461 kfree(pmx->pads);
464 kfree(sh_pfc_pmx); 462 kfree(pmx);
465 463
466 return ret; 464 return ret;
467} 465}
468 466
469static int sh_pfc_pinctrl_remove(struct platform_device *pdev) 467int sh_pfc_unregister_pinctrl(struct sh_pfc *pfc)
470{ 468{
471 struct sh_pfc_pinctrl *pmx = platform_get_drvdata(pdev); 469 struct sh_pfc_pinctrl *pmx = pfc->pinctrl;
472 470
473 pinctrl_unregister(pmx->pctl); 471 pinctrl_unregister(pmx->pctl);
474 472
475 platform_set_drvdata(pdev, NULL); 473 kfree(pmx->functions);
476 474 kfree(pmx->pads);
477 kfree(sh_pfc_pmx->functions); 475 kfree(pmx);
478 kfree(sh_pfc_pmx->pads);
479 kfree(sh_pfc_pmx);
480 476
477 pfc->pinctrl = NULL;
481 return 0; 478 return 0;
482} 479}
483
484static struct platform_driver sh_pfc_pinctrl_driver = {
485 .probe = sh_pfc_pinctrl_probe,
486 .remove = sh_pfc_pinctrl_remove,
487 .driver = {
488 .name = DRV_NAME,
489 .owner = THIS_MODULE,
490 },
491};
492
493static struct platform_device sh_pfc_pinctrl_device = {
494 .name = DRV_NAME,
495 .id = -1,
496};
497
498static int sh_pfc_pinctrl_init(void)
499{
500 int rc;
501
502 rc = platform_driver_register(&sh_pfc_pinctrl_driver);
503 if (likely(!rc)) {
504 rc = platform_device_register(&sh_pfc_pinctrl_device);
505 if (unlikely(rc))
506 platform_driver_unregister(&sh_pfc_pinctrl_driver);
507 }
508
509 return rc;
510}
511
512int sh_pfc_register_pinctrl(struct sh_pfc *pfc)
513{
514 sh_pfc_pmx = kzalloc(sizeof(struct sh_pfc_pinctrl), GFP_KERNEL);
515 if (unlikely(!sh_pfc_pmx))
516 return -ENOMEM;
517
518 spin_lock_init(&sh_pfc_pmx->lock);
519
520 sh_pfc_pmx->pfc = pfc;
521
522 return sh_pfc_pinctrl_init();
523}
524
525static void __exit sh_pfc_pinctrl_exit(void)
526{
527 platform_driver_unregister(&sh_pfc_pinctrl_driver);
528}
529module_exit(sh_pfc_pinctrl_exit);