Skip to content

Commit 52f48fe

Browse files
author
Stephen Warren
committed
pinctrl: tegra: refactor probe handling
Rather than having a single tegra-pinctrl driver that determines whether it's running on Tegra20 or Tegra30, instead have separate drivers for each that call into utility functions to implement the majority of the driver. This change is based on review feedback of the SPEAr pinctrl driver, which had originally copied to Tegra driver structure. This requires that the two drivers have unique names. Update a couple spots in arch/arm/mach-tegra for the name change. Signed-off-by: Stephen Warren <swarren@nvidia.com> Acked-by: Linus Walleij <linus.walleij@linaro.org>
1 parent ecc295b commit 52f48fe

6 files changed

Lines changed: 91 additions & 96 deletions

File tree

‎arch/arm/mach-tegra/board-pinmux.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
#include <mach/pinconf-tegra.h>
2121

22-
#define PINMUX_DEV "tegra-pinmux"
22+
#define PINMUX_DEV "tegra20-pinctrl"
2323

2424
#define TEGRA_MAP_MUX(_group_, _function_) \
2525
PIN_MAP_MUX_GROUP_HOG_DEFAULT(PINMUX_DEV, _group_, _function_)

‎arch/arm/mach-tegra/devices.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ static struct resource pinmux_resource[] = {
110110
};
111111

112112
struct platform_device tegra_pinmux_device = {
113-
.name = "tegra-pinmux",
113+
.name = "tegra20-pinctrl",
114114
.id = -1,
115115
.resource = pinmux_resource,
116116
.num_resources = ARRAY_SIZE(pinmux_resource),

‎drivers/pinctrl/pinctrl-tegra.c‎

Lines changed: 12 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Driver for the NVIDIA Tegra pinmux
33
*
4-
* Copyright (c) 2011, NVIDIA CORPORATION. All rights reserved.
4+
* Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
55
*
66
* Derived from code:
77
* Copyright (C) 2010 Google, Inc.
@@ -22,7 +22,8 @@
2222
#include <linux/init.h>
2323
#include <linux/io.h>
2424
#include <linux/module.h>
25-
#include <linux/of_device.h>
25+
#include <linux/of.h>
26+
#include <linux/platform_device.h>
2627
#include <linux/pinctrl/machine.h>
2728
#include <linux/pinctrl/pinctrl.h>
2829
#include <linux/pinctrl/pinmux.h>
@@ -31,10 +32,9 @@
3132

3233
#include <mach/pinconf-tegra.h>
3334

35+
#include "core.h"
3436
#include "pinctrl-tegra.h"
3537

36-
#define DRIVER_NAME "tegra-pinmux"
37-
3838
struct tegra_pmx {
3939
struct device *dev;
4040
struct pinctrl_dev *pctl;
@@ -87,7 +87,7 @@ static void tegra_pinctrl_pin_dbg_show(struct pinctrl_dev *pctldev,
8787
struct seq_file *s,
8888
unsigned offset)
8989
{
90-
seq_printf(s, " " DRIVER_NAME);
90+
seq_printf(s, " %s", dev_name(pctldev->dev));
9191
}
9292

9393
static int reserve_map(struct pinctrl_map **map, unsigned *reserved_maps,
@@ -589,60 +589,29 @@ static struct pinctrl_gpio_range tegra_pinctrl_gpio_range = {
589589
};
590590

591591
static struct pinctrl_desc tegra_pinctrl_desc = {
592-
.name = DRIVER_NAME,
593592
.pctlops = &tegra_pinctrl_ops,
594593
.pmxops = &tegra_pinmux_ops,
595594
.confops = &tegra_pinconf_ops,
596595
.owner = THIS_MODULE,
597596
};
598597

599-
static struct of_device_id tegra_pinctrl_of_match[] __devinitdata = {
600-
#ifdef CONFIG_PINCTRL_TEGRA20
601-
{
602-
.compatible = "nvidia,tegra20-pinmux",
603-
.data = tegra20_pinctrl_init,
604-
},
605-
#endif
606-
#ifdef CONFIG_PINCTRL_TEGRA30
607-
{
608-
.compatible = "nvidia,tegra30-pinmux",
609-
.data = tegra30_pinctrl_init,
610-
},
611-
#endif
612-
{},
613-
};
614-
615-
static int __devinit tegra_pinctrl_probe(struct platform_device *pdev)
598+
int __devinit tegra_pinctrl_probe(struct platform_device *pdev,
599+
const struct tegra_pinctrl_soc_data *soc_data)
616600
{
617-
const struct of_device_id *match;
618-
tegra_pinctrl_soc_initf initf = NULL;
619601
struct tegra_pmx *pmx;
620602
struct resource *res;
621603
int i;
622604

623-
match = of_match_device(tegra_pinctrl_of_match, &pdev->dev);
624-
if (match)
625-
initf = (tegra_pinctrl_soc_initf)match->data;
626-
#ifdef CONFIG_PINCTRL_TEGRA20
627-
if (!initf)
628-
initf = tegra20_pinctrl_init;
629-
#endif
630-
if (!initf) {
631-
dev_err(&pdev->dev,
632-
"Could not determine SoC-specific init func\n");
633-
return -EINVAL;
634-
}
635-
636605
pmx = devm_kzalloc(&pdev->dev, sizeof(*pmx), GFP_KERNEL);
637606
if (!pmx) {
638607
dev_err(&pdev->dev, "Can't alloc tegra_pmx\n");
639608
return -ENOMEM;
640609
}
641610
pmx->dev = &pdev->dev;
642-
643-
(*initf)(&pmx->soc);
611+
pmx->soc = soc_data;
644612

645613
tegra_pinctrl_gpio_range.npins = pmx->soc->ngpios;
614+
tegra_pinctrl_desc.name = dev_name(&pdev->dev);
646615
tegra_pinctrl_desc.pins = pmx->soc->pins;
647616
tegra_pinctrl_desc.npins = pmx->soc->npins;
648617

@@ -697,8 +666,9 @@ static int __devinit tegra_pinctrl_probe(struct platform_device *pdev)
697666

698667
return 0;
699668
}
669+
EXPORT_SYMBOL_GPL(tegra_pinctrl_probe);
700670

701-
static int __devexit tegra_pinctrl_remove(struct platform_device *pdev)
671+
int __devexit tegra_pinctrl_remove(struct platform_device *pdev)
702672
{
703673
struct tegra_pmx *pmx = platform_get_drvdata(pdev);
704674

@@ -707,30 +677,4 @@ static int __devexit tegra_pinctrl_remove(struct platform_device *pdev)
707677

708678
return 0;
709679
}
710-
711-
static struct platform_driver tegra_pinctrl_driver = {
712-
.driver = {
713-
.name = DRIVER_NAME,
714-
.owner = THIS_MODULE,
715-
.of_match_table = tegra_pinctrl_of_match,
716-
},
717-
.probe = tegra_pinctrl_probe,
718-
.remove = __devexit_p(tegra_pinctrl_remove),
719-
};
720-
721-
static int __init tegra_pinctrl_init(void)
722-
{
723-
return platform_driver_register(&tegra_pinctrl_driver);
724-
}
725-
arch_initcall(tegra_pinctrl_init);
726-
727-
static void __exit tegra_pinctrl_exit(void)
728-
{
729-
platform_driver_unregister(&tegra_pinctrl_driver);
730-
}
731-
module_exit(tegra_pinctrl_exit);
732-
733-
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
734-
MODULE_DESCRIPTION("NVIDIA Tegra pinctrl driver");
735-
MODULE_LICENSE("GPL v2");
736-
MODULE_DEVICE_TABLE(of, tegra_pinctrl_of_match);
680+
EXPORT_SYMBOL_GPL(tegra_pinctrl_remove);

‎drivers/pinctrl/pinctrl-tegra.h‎

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -139,25 +139,8 @@ struct tegra_pinctrl_soc_data {
139139
unsigned ngroups;
140140
};
141141

142-
/**
143-
* tegra_pinctrl_soc_initf() - Retrieve pin controller details for a SoC.
144-
* @soc_data: This pointer must be updated to point at a struct containing
145-
* details of the SoC.
146-
*/
147-
typedef void (*tegra_pinctrl_soc_initf)(
148-
const struct tegra_pinctrl_soc_data **soc_data);
149-
150-
/**
151-
* tegra20_pinctrl_init() - Retrieve pin controller details for Tegra20
152-
* @soc_data: This pointer will be updated to point at a struct containing
153-
* details of Tegra20's pin controller.
154-
*/
155-
void tegra20_pinctrl_init(const struct tegra_pinctrl_soc_data **soc_data);
156-
/**
157-
* tegra30_pinctrl_init() - Retrieve pin controller details for Tegra20
158-
* @soc_data: This pointer will be updated to point at a struct containing
159-
* details of Tegra30's pin controller.
160-
*/
161-
void tegra30_pinctrl_init(const struct tegra_pinctrl_soc_data **soc_data);
142+
int tegra_pinctrl_probe(struct platform_device *pdev,
143+
const struct tegra_pinctrl_soc_data *soc_data);
144+
int tegra_pinctrl_remove(struct platform_device *pdev);
162145

163146
#endif

‎drivers/pinctrl/pinctrl-tegra20.c‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Pinctrl data for the NVIDIA Tegra20 pinmux
33
*
4-
* Copyright (c) 2011, NVIDIA CORPORATION. All rights reserved.
4+
* Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
55
*
66
* Derived from code:
77
* Copyright (C) 2010 Google, Inc.
@@ -17,6 +17,8 @@
1717
* more details.
1818
*/
1919

20+
#include <linux/module.h>
21+
#include <linux/of.h>
2022
#include <linux/platform_device.h>
2123
#include <linux/pinctrl/pinctrl.h>
2224
#include <linux/pinctrl/pinmux.h>
@@ -2854,7 +2856,39 @@ static const struct tegra_pinctrl_soc_data tegra20_pinctrl = {
28542856
.ngroups = ARRAY_SIZE(tegra20_groups),
28552857
};
28562858

2857-
void __devinit tegra20_pinctrl_init(const struct tegra_pinctrl_soc_data **soc)
2859+
static int __devinit tegra20_pinctrl_probe(struct platform_device *pdev)
28582860
{
2859-
*soc = &tegra20_pinctrl;
2861+
return tegra_pinctrl_probe(pdev, &tegra20_pinctrl);
28602862
}
2863+
2864+
static struct of_device_id tegra20_pinctrl_of_match[] __devinitdata = {
2865+
{ .compatible = "nvidia,tegra20-pinmux", },
2866+
{ },
2867+
};
2868+
2869+
static struct platform_driver tegra20_pinctrl_driver = {
2870+
.driver = {
2871+
.name = "tegra20-pinctrl",
2872+
.owner = THIS_MODULE,
2873+
.of_match_table = tegra20_pinctrl_of_match,
2874+
},
2875+
.probe = tegra20_pinctrl_probe,
2876+
.remove = __devexit_p(tegra_pinctrl_remove),
2877+
};
2878+
2879+
static int __init tegra20_pinctrl_init(void)
2880+
{
2881+
return platform_driver_register(&tegra20_pinctrl_driver);
2882+
}
2883+
arch_initcall(tegra20_pinctrl_init);
2884+
2885+
static void __exit tegra20_pinctrl_exit(void)
2886+
{
2887+
platform_driver_unregister(&tegra20_pinctrl_driver);
2888+
}
2889+
module_exit(tegra20_pinctrl_exit);
2890+
2891+
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
2892+
MODULE_DESCRIPTION("NVIDIA Tegra20 pinctrl driver");
2893+
MODULE_LICENSE("GPL v2");
2894+
MODULE_DEVICE_TABLE(of, tegra20_pinctrl_of_match);

‎drivers/pinctrl/pinctrl-tegra30.c‎

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Pinctrl data for the NVIDIA Tegra30 pinmux
33
*
4-
* Copyright (c) 2011, NVIDIA CORPORATION. All rights reserved.
4+
* Copyright (c) 2011-2012, NVIDIA CORPORATION. All rights reserved.
55
*
66
* This program is free software; you can redistribute it and/or modify it
77
* under the terms and conditions of the GNU General Public License,
@@ -13,6 +13,8 @@
1313
* more details.
1414
*/
1515

16+
#include <linux/module.h>
17+
#include <linux/of.h>
1618
#include <linux/platform_device.h>
1719
#include <linux/pinctrl/pinctrl.h>
1820
#include <linux/pinctrl/pinmux.h>
@@ -3720,7 +3722,39 @@ static const struct tegra_pinctrl_soc_data tegra30_pinctrl = {
37203722
.ngroups = ARRAY_SIZE(tegra30_groups),
37213723
};
37223724

3723-
void __devinit tegra30_pinctrl_init(const struct tegra_pinctrl_soc_data **soc)
3725+
static int __devinit tegra30_pinctrl_probe(struct platform_device *pdev)
37243726
{
3725-
*soc = &tegra30_pinctrl;
3727+
return tegra_pinctrl_probe(pdev, &tegra30_pinctrl);
37263728
}
3729+
3730+
static struct of_device_id tegra30_pinctrl_of_match[] __devinitdata = {
3731+
{ .compatible = "nvidia,tegra30-pinmux", },
3732+
{ },
3733+
};
3734+
3735+
static struct platform_driver tegra30_pinctrl_driver = {
3736+
.driver = {
3737+
.name = "tegra30-pinctrl",
3738+
.owner = THIS_MODULE,
3739+
.of_match_table = tegra30_pinctrl_of_match,
3740+
},
3741+
.probe = tegra30_pinctrl_probe,
3742+
.remove = __devexit_p(tegra_pinctrl_remove),
3743+
};
3744+
3745+
static int __init tegra30_pinctrl_init(void)
3746+
{
3747+
return platform_driver_register(&tegra30_pinctrl_driver);
3748+
}
3749+
arch_initcall(tegra30_pinctrl_init);
3750+
3751+
static void __exit tegra30_pinctrl_exit(void)
3752+
{
3753+
platform_driver_unregister(&tegra30_pinctrl_driver);
3754+
}
3755+
module_exit(tegra30_pinctrl_exit);
3756+
3757+
MODULE_AUTHOR("Stephen Warren <swarren@nvidia.com>");
3758+
MODULE_DESCRIPTION("NVIDIA Tegra30 pinctrl driver");
3759+
MODULE_LICENSE("GPL v2");
3760+
MODULE_DEVICE_TABLE(of, tegra30_pinctrl_of_match);

0 commit comments

Comments
 (0)