aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pinctrl/pinconf.c
diff options
context:
space:
mode:
authorLinus Walleij <linus.walleij@linaro.org>2011-10-19 12:14:33 -0400
committerLinus Walleij <linus.walleij@linaro.org>2012-01-03 03:10:04 -0500
commitae6b4d8588f4fc95520b0e62c4b1f474c82191a9 (patch)
tree3da8e553a6374f02e89b5a6ba52b83f34c3abea2 /drivers/pinctrl/pinconf.c
parentb4e3ac74d5cd4152f2ec6b3280b1ff3428952f7f (diff)
pinctrl: add a pin config interface
This add per-pin and per-group pin config interfaces for biasing, driving and other such electronic properties. The details of passed configurations are passed in an opaque unsigned long which may be dereferences to integer types, structs or lists on either side of the configuration interface. ChangeLog v1->v2: - Clear split of terminology: we now have pin controllers, and those may support two interfaces using vtables: pin multiplexing and pin configuration. - Break out pin configuration to its own C file, controllers may implement only config without mux, and vice versa, so keep each sub-functionality of pin controllers separate. Introduce CONFIG_PINCONF in Kconfig. - Implement some core logic around pin configuration in the pinconf.c file. - Remove UNKNOWN config states, these were just surplus baggage. - Remove FLOAT config state - HIGH_IMPEDANCE should be enough for everyone. - PIN_CONFIG_POWER_SOURCE added to handle switching the power supply for the pin logic between different sources - Explicit DISABLE config enums to turn schmitt-trigger, wakeup etc OFF. - Update documentation to reflect all the recent reasoning. ChangeLog v2->v3: - Twist API around to pass around arrays of config tuples instead of (param, value) pairs everywhere. - Explicit drive strength semantics for push/pull and similar drive modes, this shall be the number of drive stages vs nominal load impedance, which should match the actual electronics used in push/pull CMOS or TTY totempoles. - Drop load capacitance configuration - I probably don't know what I'm doing here so leave it out. - Drop PIN_CONFIG_INPUT_SCHMITT_OFF, instead the argument zero to PIN_CONFIG_INPUT_SCHMITT turns schmitt trigger off. - Drop PIN_CONFIG_NORMAL_POWER_MODE and have a well defined argument to PIN_CONFIG_LOW_POWER_MODE to get out of it instead. - Drop PIN_CONFIG_WAKEUP_ENABLE/DISABLE and just use PIN_CONFIG_WAKEUP with defined value zero to turn wakeup off. - Add PIN_CONFIG_INPUT_DEBOUNCE for configuring debounce time on input lines. - Fix a bug when we tried to configure pins for pin controllers without pinconf support. - Initialized debugfs properly so it works. - Initialize the mutex properly and lock around config tampering sections. - Check the return value from get_initial_config() properly. ChangeLog v3->v4: - Export the pin_config_get(), pin_config_set() and pin_config_group() functions. - Drop the entire concept of just getting initial config and keeping track of pin states internally, instead ask the pins what state they are in. Previous idea was plain wrong, if the device cannot keep track of its state, the driver should do it. - Drop the generic configuration layout, it seems this impose too much restriction on some pin controllers, so let them do things the way they want and split off support for generic config as an optional add-on. ChangeLog v4->v5: - Introduce two symmetric driver calls for group configuration, .pin_config_group_[get|set] and corresponding external calls. - Remove generic semantic meanings of return values from config calls, these belong in the generic config patch. Just pass the return value through instead. - Add a debugfs entry "pinconf-groups" to read status from group configuration only, also slam in a per-group debug callback in the pinconf_ops so custom drivers can display something meaningful for their pins. - Fix some dangling newline. - Drop dangling #else clause. - Update documentation to match the above. ChangeLog v5->v6: - Change to using a pin name as parameter for the [get|set]_config() functions, as suggested by Stephen Warren. This is more natural as names will be what a developer has access to in written documentation etc. ChangeLog v6->v7: - Refactor out by-pin and by-name get/set functions, only expose the by-name functions externally, expose the by-pin functions internally. - Show supported pin control functionality in the debugfs pinctrl-devices file. Acked-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Diffstat (limited to 'drivers/pinctrl/pinconf.c')
-rw-r--r--drivers/pinctrl/pinconf.c302
1 files changed, 302 insertions, 0 deletions
diff --git a/drivers/pinctrl/pinconf.c b/drivers/pinctrl/pinconf.c
new file mode 100644
index 000000000000..9195eefe258a
--- /dev/null
+++ b/drivers/pinctrl/pinconf.c
@@ -0,0 +1,302 @@
1/*
2 * Core driver for the 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#define pr_fmt(fmt) "pinconfig core: " fmt
12
13#include <linux/kernel.h>
14#include <linux/module.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/machine.h>
21#include <linux/pinctrl/pinctrl.h>
22#include <linux/pinctrl/pinconf.h>
23#include "core.h"
24#include "pinconf.h"
25
26int pin_config_get_for_pin(struct pinctrl_dev *pctldev, unsigned pin,
27 unsigned long *config)
28{
29 const struct pinconf_ops *ops = pctldev->desc->confops;
30
31 if (!ops || !ops->pin_config_get) {
32 dev_err(&pctldev->dev, "cannot get pin configuration, missing "
33 "pin_config_get() function in driver\n");
34 return -EINVAL;
35 }
36
37 return ops->pin_config_get(pctldev, pin, config);
38}
39
40/**
41 * pin_config_get() - get the configuration of a single pin parameter
42 * @pctldev: pin controller device for this pin
43 * @name: name of the pin to get the config for
44 * @config: the config pointed to by this argument will be filled in with the
45 * current pin state, it can be used directly by drivers as a numeral, or
46 * it can be dereferenced to any struct.
47 */
48int pin_config_get(struct pinctrl_dev *pctldev, const char *name,
49 unsigned long *config)
50{
51 int pin;
52
53 pin = pin_get_from_name(pctldev, name);
54 if (pin < 0)
55 return pin;
56
57 return pin_config_get_for_pin(pctldev, pin, config);
58}
59EXPORT_SYMBOL(pin_config_get);
60
61int pin_config_set_for_pin(struct pinctrl_dev *pctldev, unsigned pin,
62 unsigned long config)
63{
64 const struct pinconf_ops *ops = pctldev->desc->confops;
65 int ret;
66
67 if (!ops || !ops->pin_config_set) {
68 dev_err(&pctldev->dev, "cannot configure pin, missing "
69 "config function in driver\n");
70 return -EINVAL;
71 }
72
73 ret = ops->pin_config_set(pctldev, pin, config);
74 if (ret) {
75 dev_err(&pctldev->dev,
76 "unable to set pin configuration on pin %d\n", pin);
77 return ret;
78 }
79
80 return 0;
81}
82
83/**
84 * pin_config_set() - set the configuration of a single pin parameter
85 * @pctldev: pin controller device for this pin
86 * @name: name of the pin to set the config for
87 * @config: the config in this argument will contain the desired pin state, it
88 * can be used directly by drivers as a numeral, or it can be dereferenced
89 * to any struct.
90 */
91int pin_config_set(struct pinctrl_dev *pctldev, const char *name,
92 unsigned long config)
93{
94 int pin;
95
96 pin = pin_get_from_name(pctldev, name);
97 if (pin < 0)
98 return pin;
99
100 return pin_config_set_for_pin(pctldev, pin, config);
101}
102EXPORT_SYMBOL(pin_config_set);
103
104int pin_config_group_get(struct pinctrl_dev *pctldev, const char *pin_group,
105 unsigned long *config)
106{
107 const struct pinconf_ops *ops = pctldev->desc->confops;
108 int selector;
109
110 if (!ops || !ops->pin_config_group_get) {
111 dev_err(&pctldev->dev, "cannot get configuration for pin "
112 "group, missing group config get function in "
113 "driver\n");
114 return -EINVAL;
115 }
116
117 selector = pinctrl_get_group_selector(pctldev, pin_group);
118 if (selector < 0)
119 return selector;
120
121 return ops->pin_config_group_get(pctldev, selector, config);
122}
123EXPORT_SYMBOL(pin_config_group_get);
124
125
126int pin_config_group_set(struct pinctrl_dev *pctldev, const char *pin_group,
127 unsigned long config)
128{
129 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
130 const struct pinconf_ops *ops = pctldev->desc->confops;
131 int selector;
132 const unsigned *pins;
133 unsigned num_pins;
134 int ret;
135 int i;
136
137 if (!ops || (!ops->pin_config_group_set && !ops->pin_config_set)) {
138 dev_err(&pctldev->dev, "cannot configure pin group, missing "
139 "config function in driver\n");
140 return -EINVAL;
141 }
142
143 selector = pinctrl_get_group_selector(pctldev, pin_group);
144 if (selector < 0)
145 return selector;
146
147 ret = pctlops->get_group_pins(pctldev, selector, &pins, &num_pins);
148 if (ret) {
149 dev_err(&pctldev->dev, "cannot configure pin group, error "
150 "getting pins\n");
151 return ret;
152 }
153
154 /*
155 * If the pin controller supports handling entire groups we use that
156 * capability.
157 */
158 if (ops->pin_config_group_set) {
159 ret = ops->pin_config_group_set(pctldev, selector, config);
160 /*
161 * If the pin controller prefer that a certain group be handled
162 * pin-by-pin as well, it returns -EAGAIN.
163 */
164 if (ret != -EAGAIN)
165 return ret;
166 }
167
168 /*
169 * If the controller cannot handle entire groups, we configure each pin
170 * individually.
171 */
172 if (!ops->pin_config_set)
173 return 0;
174
175 for (i = 0; i < num_pins; i++) {
176 ret = ops->pin_config_set(pctldev, pins[i], config);
177 if (ret < 0)
178 return ret;
179 }
180
181 return 0;
182}
183EXPORT_SYMBOL(pin_config_group_set);
184
185int pinconf_check_ops(const struct pinconf_ops *ops)
186{
187 /* We must be able to read out pin status */
188 if (!ops->pin_config_get && !ops->pin_config_group_get)
189 return -EINVAL;
190 /* We have to be able to config the pins in SOME way */
191 if (!ops->pin_config_set && !ops->pin_config_group_set)
192 return -EINVAL;
193 return 0;
194}
195
196#ifdef CONFIG_DEBUG_FS
197
198static void pinconf_dump_pin(struct pinctrl_dev *pctldev,
199 struct seq_file *s, int pin)
200{
201 const struct pinconf_ops *ops = pctldev->desc->confops;
202
203 if (ops && ops->pin_config_dbg_show)
204 ops->pin_config_dbg_show(pctldev, s, pin);
205}
206
207static int pinconf_pins_show(struct seq_file *s, void *what)
208{
209 struct pinctrl_dev *pctldev = s->private;
210 unsigned pin;
211
212 seq_puts(s, "Pin config settings per pin\n");
213 seq_puts(s, "Format: pin (name): pinmux setting array\n");
214
215 /* The highest pin number need to be included in the loop, thus <= */
216 for (pin = 0; pin <= pctldev->desc->maxpin; pin++) {
217 struct pin_desc *desc;
218
219 desc = pin_desc_get(pctldev, pin);
220 /* Pin space may be sparse */
221 if (desc == NULL)
222 continue;
223
224 seq_printf(s, "pin %d (%s):", pin,
225 desc->name ? desc->name : "unnamed");
226
227 pinconf_dump_pin(pctldev, s, pin);
228
229 seq_printf(s, "\n");
230 }
231
232 return 0;
233}
234
235static void pinconf_dump_group(struct pinctrl_dev *pctldev,
236 struct seq_file *s, unsigned selector,
237 const char *gname)
238{
239 const struct pinconf_ops *ops = pctldev->desc->confops;
240
241 if (ops && ops->pin_config_group_dbg_show)
242 ops->pin_config_group_dbg_show(pctldev, s, selector);
243}
244
245static int pinconf_groups_show(struct seq_file *s, void *what)
246{
247 struct pinctrl_dev *pctldev = s->private;
248 const struct pinctrl_ops *pctlops = pctldev->desc->pctlops;
249 const struct pinconf_ops *ops = pctldev->desc->confops;
250 unsigned selector = 0;
251
252 if (!ops || !ops->pin_config_group_get)
253 return 0;
254
255 seq_puts(s, "Pin config settings per pin group\n");
256 seq_puts(s, "Format: group (name): pinmux setting array\n");
257
258 while (pctlops->list_groups(pctldev, selector) >= 0) {
259 const char *gname = pctlops->get_group_name(pctldev, selector);
260
261 seq_printf(s, "%u (%s):", selector, gname);
262 pinconf_dump_group(pctldev, s, selector, gname);
263 selector++;
264 }
265
266 return 0;
267}
268
269static int pinconf_pins_open(struct inode *inode, struct file *file)
270{
271 return single_open(file, pinconf_pins_show, inode->i_private);
272}
273
274static int pinconf_groups_open(struct inode *inode, struct file *file)
275{
276 return single_open(file, pinconf_groups_show, inode->i_private);
277}
278
279static const struct file_operations pinconf_pins_ops = {
280 .open = pinconf_pins_open,
281 .read = seq_read,
282 .llseek = seq_lseek,
283 .release = single_release,
284};
285
286static const struct file_operations pinconf_groups_ops = {
287 .open = pinconf_groups_open,
288 .read = seq_read,
289 .llseek = seq_lseek,
290 .release = single_release,
291};
292
293void pinconf_init_device_debugfs(struct dentry *devroot,
294 struct pinctrl_dev *pctldev)
295{
296 debugfs_create_file("pinconf-pins", S_IFREG | S_IRUGO,
297 devroot, pctldev, &pinconf_pins_ops);
298 debugfs_create_file("pinconf-groups", S_IFREG | S_IRUGO,
299 devroot, pctldev, &pinconf_groups_ops);
300}
301
302#endif