diff options
author | Linus Walleij <linus.walleij@linaro.org> | 2011-11-24 12:27:15 -0500 |
---|---|---|
committer | Linus Walleij <linus.walleij@linaro.org> | 2012-03-12 17:49:02 -0400 |
commit | 394349f7789fdfcdc74b61afcac84046535c40b7 (patch) | |
tree | 20dd88e7a1f2dba0a1c227f53960013bf956fa43 /drivers/pinctrl | |
parent | 70b36378d44d7f5e62458a830b1a9bb1c570f28a (diff) |
pinctrl: introduce generic pin config
This is a split-off from the earlier patch set which adds generic
pin configuration for the pin controllers that want it. Since
we may have a system with mixed generic and custom pin controllers,
we pass a boolean in the pin controller ops vtable to indicate
if it is generic.
ChangeLog v1->v5:
- Follow parent patch versioning number system.
- Document the semantic meaning of return values from pin config
get functions, so we can iterate over pins and check their
properties from debugfs as part of the generic config code.
- Use proper cast functions in the generic debugfs pin config
file.
- Expand generic config to optionally cover groups too.
ChangeLog v5->v6:
- Update to match underlying changes.
ChangeLog v6->v7:
- Drop DRIVE_OFF parameter, use bias high impedance for this
- Delete argument for drive modes push-pull, od and os. These
are now just state transitions.
- Delete slew rate rising/falling due to discussions on on
proper semantics
- Drop config wakeup, struct irq_chip does this for now, add
back if need be.
- Set PIN_CONFIG_END to 0x7fff making room for custom config
parameters from 0x8000 and up.
- Prefix accessor functions with pinconf_
Diffstat (limited to 'drivers/pinctrl')
-rw-r--r-- | drivers/pinctrl/Kconfig | 4 | ||||
-rw-r--r-- | drivers/pinctrl/Makefile | 1 | ||||
-rw-r--r-- | drivers/pinctrl/pinconf-generic.c | 120 | ||||
-rw-r--r-- | drivers/pinctrl/pinconf.c | 6 | ||||
-rw-r--r-- | drivers/pinctrl/pinconf.h | 43 |
5 files changed, 170 insertions, 4 deletions
diff --git a/drivers/pinctrl/Kconfig b/drivers/pinctrl/Kconfig index c6d29ff61d7e..07f3d8d38580 100644 --- a/drivers/pinctrl/Kconfig +++ b/drivers/pinctrl/Kconfig | |||
@@ -17,6 +17,10 @@ config PINMUX | |||
17 | config PINCONF | 17 | config PINCONF |
18 | bool "Support pin configuration controllers" | 18 | bool "Support pin configuration controllers" |
19 | 19 | ||
20 | config GENERIC_PINCONF | ||
21 | bool | ||
22 | select PINCONF | ||
23 | |||
20 | config DEBUG_PINCTRL | 24 | config DEBUG_PINCTRL |
21 | bool "Debug PINCTRL calls" | 25 | bool "Debug PINCTRL calls" |
22 | depends on DEBUG_KERNEL | 26 | depends on DEBUG_KERNEL |
diff --git a/drivers/pinctrl/Makefile b/drivers/pinctrl/Makefile index 754329b9c611..6d4150b4eced 100644 --- a/drivers/pinctrl/Makefile +++ b/drivers/pinctrl/Makefile | |||
@@ -5,6 +5,7 @@ ccflags-$(CONFIG_DEBUG_PINCTRL) += -DDEBUG | |||
5 | obj-$(CONFIG_PINCTRL) += core.o | 5 | obj-$(CONFIG_PINCTRL) += core.o |
6 | obj-$(CONFIG_PINMUX) += pinmux.o | 6 | obj-$(CONFIG_PINMUX) += pinmux.o |
7 | obj-$(CONFIG_PINCONF) += pinconf.o | 7 | obj-$(CONFIG_PINCONF) += pinconf.o |
8 | obj-$(CONFIG_GENERIC_PINCONF) += pinconf-generic.o | ||
8 | obj-$(CONFIG_PINCTRL_PXA3xx) += pinctrl-pxa3xx.o | 9 | obj-$(CONFIG_PINCTRL_PXA3xx) += pinctrl-pxa3xx.o |
9 | obj-$(CONFIG_PINCTRL_MMP2) += pinctrl-mmp2.o | 10 | obj-$(CONFIG_PINCTRL_MMP2) += pinctrl-mmp2.o |
10 | obj-$(CONFIG_PINCTRL_PXA168) += pinctrl-pxa168.o | 11 | obj-$(CONFIG_PINCTRL_PXA168) += pinctrl-pxa168.o |
diff --git a/drivers/pinctrl/pinconf-generic.c b/drivers/pinctrl/pinconf-generic.c new file mode 100644 index 000000000000..33fbaeaa65dd --- /dev/null +++ b/drivers/pinctrl/pinconf-generic.c | |||
@@ -0,0 +1,120 @@ | |||
1 | /* | ||
2 | * Core driver for the generic pin config portions of the pin control subsystem | ||
3 | * | ||
4 | * Copyright (C) 2011 ST-Ericsson SA | ||
5 | * Written on behalf of Linaro for ST-Ericsson | ||
6 | * | ||
7 | * Author: Linus Walleij <linus.walleij@linaro.org> | ||
8 | * | ||
9 | * License terms: GNU General Public License (GPL) version 2 | ||
10 | */ | ||
11 | |||
12 | #define pr_fmt(fmt) "generic pinconfig core: " fmt | ||
13 | |||
14 | #include <linux/kernel.h> | ||
15 | #include <linux/init.h> | ||
16 | #include <linux/device.h> | ||
17 | #include <linux/slab.h> | ||
18 | #include <linux/debugfs.h> | ||
19 | #include <linux/seq_file.h> | ||
20 | #include <linux/pinctrl/pinctrl.h> | ||
21 | #include <linux/pinctrl/pinconf.h> | ||
22 | #include <linux/pinctrl/pinconf-generic.h> | ||
23 | #include "core.h" | ||
24 | #include "pinconf.h" | ||
25 | |||
26 | #ifdef CONFIG_DEBUG_FS | ||
27 | |||
28 | struct pin_config_item { | ||
29 | const enum pin_config_param param; | ||
30 | const char * const display; | ||
31 | const char * const format; | ||
32 | }; | ||
33 | |||
34 | #define PCONFDUMP(a, b, c) { .param = a, .display = b, .format = c } | ||
35 | |||
36 | struct pin_config_item conf_items[] = { | ||
37 | PCONFDUMP(PIN_CONFIG_BIAS_DISABLE, "input bias disabled", NULL), | ||
38 | PCONFDUMP(PIN_CONFIG_BIAS_HIGH_IMPEDANCE, "input bias high impedance", NULL), | ||
39 | PCONFDUMP(PIN_CONFIG_BIAS_PULL_UP, "input bias pull up", NULL), | ||
40 | PCONFDUMP(PIN_CONFIG_BIAS_PULL_DOWN, "input bias pull down", NULL), | ||
41 | PCONFDUMP(PIN_CONFIG_DRIVE_PUSH_PULL, "output drive push pull", NULL), | ||
42 | PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_DRAIN, "output drive open drain", NULL), | ||
43 | PCONFDUMP(PIN_CONFIG_DRIVE_OPEN_SOURCE, "output drive open source", NULL), | ||
44 | PCONFDUMP(PIN_CONFIG_INPUT_SCHMITT, "input schmitt trigger", NULL), | ||
45 | PCONFDUMP(PIN_CONFIG_INPUT_DEBOUNCE, "input debounce", "time units"), | ||
46 | PCONFDUMP(PIN_CONFIG_POWER_SOURCE, "pin power source", "selector"), | ||
47 | PCONFDUMP(PIN_CONFIG_LOW_POWER_MODE, "pin low power", "mode"), | ||
48 | }; | ||
49 | |||
50 | void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev, | ||
51 | struct seq_file *s, unsigned pin) | ||
52 | { | ||
53 | const struct pinconf_ops *ops = pctldev->desc->confops; | ||
54 | int i; | ||
55 | |||
56 | if (!ops->is_generic) | ||
57 | return; | ||
58 | |||
59 | for(i = 0; i < ARRAY_SIZE(conf_items); i++) { | ||
60 | unsigned long config; | ||
61 | int ret; | ||
62 | |||
63 | /* We want to check out this parameter */ | ||
64 | config = pinconf_to_config_packed(conf_items[i].param, 0); | ||
65 | ret = pin_config_get_for_pin(pctldev, pin, &config); | ||
66 | /* These are legal errors */ | ||
67 | if (ret == -EINVAL || ret == -ENOTSUPP) | ||
68 | continue; | ||
69 | if (ret) { | ||
70 | seq_printf(s, "ERROR READING CONFIG SETTING %d ", i); | ||
71 | continue; | ||
72 | } | ||
73 | /* Space between multiple configs */ | ||
74 | seq_puts(s, " "); | ||
75 | seq_puts(s, conf_items[i].display); | ||
76 | /* Print unit if available */ | ||
77 | if (conf_items[i].format && | ||
78 | pinconf_to_config_argument(config) != 0) | ||
79 | seq_printf(s, " (%u %s)", | ||
80 | pinconf_to_config_argument(config), | ||
81 | conf_items[i].format); | ||
82 | } | ||
83 | } | ||
84 | |||
85 | void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, | ||
86 | struct seq_file *s, const char *gname) | ||
87 | { | ||
88 | const struct pinconf_ops *ops = pctldev->desc->confops; | ||
89 | int i; | ||
90 | |||
91 | if (!ops->is_generic) | ||
92 | return; | ||
93 | |||
94 | for(i = 0; i < ARRAY_SIZE(conf_items); i++) { | ||
95 | unsigned long config; | ||
96 | int ret; | ||
97 | |||
98 | /* We want to check out this parameter */ | ||
99 | config = pinconf_to_config_packed(conf_items[i].param, 0); | ||
100 | ret = pin_config_group_get(dev_name(pctldev->dev), gname, | ||
101 | &config); | ||
102 | /* These are legal errors */ | ||
103 | if (ret == -EINVAL || ret == -ENOTSUPP) | ||
104 | continue; | ||
105 | if (ret) { | ||
106 | seq_printf(s, "ERROR READING CONFIG SETTING %d ", i); | ||
107 | continue; | ||
108 | } | ||
109 | /* Space between multiple configs */ | ||
110 | seq_puts(s, " "); | ||
111 | seq_puts(s, conf_items[i].display); | ||
112 | /* Print unit if available */ | ||
113 | if (conf_items[i].format && config != 0) | ||
114 | seq_printf(s, " (%u %s)", | ||
115 | pinconf_to_config_argument(config), | ||
116 | conf_items[i].format); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | #endif | ||
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c index b40ac1b4fb17..7321e8601294 100644 --- a/drivers/pinctrl/pinconf.c +++ b/drivers/pinctrl/pinconf.c | |||
@@ -54,7 +54,7 @@ int pinconf_validate_map(struct pinctrl_map const *map, int i) | |||
54 | return 0; | 54 | return 0; |
55 | } | 55 | } |
56 | 56 | ||
57 | static int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, | 57 | int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, |
58 | unsigned long *config) | 58 | unsigned long *config) |
59 | { | 59 | { |
60 | const struct pinconf_ops *ops = pctldev->desc->confops; | 60 | const struct pinconf_ops *ops = pctldev->desc->confops; |
@@ -439,6 +439,8 @@ static void pinconf_dump_pin(struct pinctrl_dev *pctldev, | |||
439 | { | 439 | { |
440 | const struct pinconf_ops *ops = pctldev->desc->confops; | 440 | const struct pinconf_ops *ops = pctldev->desc->confops; |
441 | 441 | ||
442 | /* no-op when not using generic pin config */ | ||
443 | pinconf_generic_dump_pin(pctldev, s, pin); | ||
442 | if (ops && ops->pin_config_dbg_show) | 444 | if (ops && ops->pin_config_dbg_show) |
443 | ops->pin_config_dbg_show(pctldev, s, pin); | 445 | ops->pin_config_dbg_show(pctldev, s, pin); |
444 | } | 446 | } |
@@ -482,6 +484,8 @@ static void pinconf_dump_group(struct pinctrl_dev *pctldev, | |||
482 | { | 484 | { |
483 | const struct pinconf_ops *ops = pctldev->desc->confops; | 485 | const struct pinconf_ops *ops = pctldev->desc->confops; |
484 | 486 | ||
487 | /* no-op when not using generic pin config */ | ||
488 | pinconf_generic_dump_group(pctldev, s, gname); | ||
485 | if (ops && ops->pin_config_group_dbg_show) | 489 | if (ops && ops->pin_config_group_dbg_show) |
486 | ops->pin_config_group_dbg_show(pctldev, s, selector); | 490 | ops->pin_config_group_dbg_show(pctldev, s, selector); |
487 | } | 491 | } |
diff --git a/drivers/pinctrl/pinconf.h b/drivers/pinctrl/pinconf.h index 0ded227661a5..54510de5e8c6 100644 --- a/drivers/pinctrl/pinconf.h +++ b/drivers/pinctrl/pinconf.h | |||
@@ -14,20 +14,26 @@ | |||
14 | #ifdef CONFIG_PINCONF | 14 | #ifdef CONFIG_PINCONF |
15 | 15 | ||
16 | int pinconf_check_ops(struct pinctrl_dev *pctldev); | 16 | int pinconf_check_ops(struct pinctrl_dev *pctldev); |
17 | |||
18 | int pinconf_validate_map(struct pinctrl_map const *map, int i); | 17 | int pinconf_validate_map(struct pinctrl_map const *map, int i); |
19 | |||
20 | int pinconf_map_to_setting(struct pinctrl_map const *map, | 18 | int pinconf_map_to_setting(struct pinctrl_map const *map, |
21 | struct pinctrl_setting *setting); | 19 | struct pinctrl_setting *setting); |
22 | void pinconf_free_setting(struct pinctrl_setting const *setting); | 20 | void pinconf_free_setting(struct pinctrl_setting const *setting); |
23 | int pinconf_apply_setting(struct pinctrl_setting const *setting); | 21 | int pinconf_apply_setting(struct pinctrl_setting const *setting); |
24 | |||
25 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map); | 22 | void pinconf_show_map(struct seq_file *s, struct pinctrl_map const *map); |
26 | void pinconf_show_setting(struct seq_file *s, | 23 | void pinconf_show_setting(struct seq_file *s, |
27 | struct pinctrl_setting const *setting); | 24 | struct pinctrl_setting const *setting); |
28 | void pinconf_init_device_debugfs(struct dentry *devroot, | 25 | void pinconf_init_device_debugfs(struct dentry *devroot, |
29 | struct pinctrl_dev *pctldev); | 26 | struct pinctrl_dev *pctldev); |
30 | 27 | ||
28 | /* | ||
29 | * You will only be interested in these if you're using PINCONF | ||
30 | * so don't supply any stubs for these. | ||
31 | */ | ||
32 | int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin, | ||
33 | unsigned long *config); | ||
34 | int pin_config_group_get(const char *dev_name, const char *pin_group, | ||
35 | unsigned long *config); | ||
36 | |||
31 | #else | 37 | #else |
32 | 38 | ||
33 | static inline int pinconf_check_ops(struct pinctrl_dev *pctldev) | 39 | static inline int pinconf_check_ops(struct pinctrl_dev *pctldev) |
@@ -71,3 +77,34 @@ static inline void pinconf_init_device_debugfs(struct dentry *devroot, | |||
71 | } | 77 | } |
72 | 78 | ||
73 | #endif | 79 | #endif |
80 | |||
81 | /* | ||
82 | * The following functions are available if the driver uses the generic | ||
83 | * pin config. | ||
84 | */ | ||
85 | |||
86 | #ifdef CONFIG_GENERIC_PINCONF | ||
87 | |||
88 | void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev, | ||
89 | struct seq_file *s, unsigned pin); | ||
90 | |||
91 | void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, | ||
92 | struct seq_file *s, const char *gname); | ||
93 | |||
94 | #else | ||
95 | |||
96 | static inline void pinconf_generic_dump_pin(struct pinctrl_dev *pctldev, | ||
97 | struct seq_file *s, | ||
98 | unsigned pin) | ||
99 | { | ||
100 | return; | ||
101 | } | ||
102 | |||
103 | static inline void pinconf_generic_dump_group(struct pinctrl_dev *pctldev, | ||
104 | struct seq_file *s, | ||
105 | const char *gname) | ||
106 | { | ||
107 | return; | ||
108 | } | ||
109 | |||
110 | #endif | ||