]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/linux/pinctrl/pinconf-generic.h
pinctrl: Allow configuration of pins from gpiolib based drivers
[mirror_ubuntu-artful-kernel.git] / include / linux / pinctrl / pinconf-generic.h
CommitLineData
394349f7
LW
1/*
2 * Interface the generic pinconfig portions of the pinctrl subsystem
3 *
4 * Copyright (C) 2011 ST-Ericsson SA
5 * Written on behalf of Linaro for ST-Ericsson
6 * This interface is used in the core to keep track of pins.
7 *
8 * Author: Linus Walleij <linus.walleij@linaro.org>
9 *
10 * License terms: GNU General Public License (GPL) version 2
11 */
12#ifndef __LINUX_PINCTRL_PINCONF_GENERIC_H
13#define __LINUX_PINCTRL_PINCONF_GENERIC_H
14
15/*
16 * You shouldn't even be able to compile with these enums etc unless you're
17 * using generic pin config. That is why this is defined out.
18 */
19#ifdef CONFIG_GENERIC_PINCONF
20
21/**
22 * enum pin_config_param - possible pin configuration parameters
3c4b23dd
MY
23 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
24 * weakly drives the last value on a tristate bus, also known as a "bus
25 * holder", "bus keeper" or "repeater". This allows another device on the
26 * bus to change the value by driving the bus high or low and switching to
27 * tristate. The argument is ignored.
394349f7
LW
28 * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
29 * transition from say pull-up to pull-down implies that you disable
30 * pull-up in the process, this setting disables all biasing.
31 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
32 * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
33 * On output pins this effectively disconnects the pin, which is useful
34 * if for example some other pin is going to drive the signal connected
35 * to it for a while. Pins used for input are usually always high
36 * impedance.
394349f7
LW
37 * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
38 * impedance to GROUND). If the argument is != 0 pull-down is enabled,
5ca3353b 39 * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
7970cb77 40 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
70637a6d
HS
41 * on embedded knowledge of the controller hardware, like current mux
42 * function. The pull direction and possibly strength too will normally
43 * be decided completely inside the hardware block and not be readable
44 * from the kernel side.
5ca3353b
LW
45 * If the argument is != 0 pull up/down is enabled, if it is 0, the
46 * configuration is ignored. The proper way to disable it is to use
47 * @PIN_CONFIG_BIAS_DISABLE.
3c4b23dd
MY
48 * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
49 * impedance to VDD). If the argument is != 0 pull-up is enabled,
50 * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
394349f7
LW
51 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
52 * collector) which means it is usually wired with other output ports
63ad9cbf
LP
53 * which are then pulled up with an external resistor. Setting this
54 * config will enable open drain mode, the argument is ignored.
394349f7 55 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
0d378993 56 * (open emitter). Setting this config will enable open source mode, the
394349f7 57 * argument is ignored.
3c4b23dd
MY
58 * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
59 * low, this is the most typical case and is typically achieved with two
60 * active transistors on the output. Setting this config will enable
61 * push-pull mode, the argument is ignored.
63ad9cbf
LP
62 * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
63 * passed as argument. The argument is in mA.
3c4b23dd
MY
64 * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
65 * which means it will wait for signals to settle when reading inputs. The
66 * argument gives the debounce time in usecs. Setting the
67 * argument to zero turns debouncing off.
8ba3f4d0
SY
68 * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
69 * affect the pin's ability to drive output. 1 enables input, 0 disables
70 * input.
394349f7
LW
71 * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
72 * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
73 * the threshold value is given on a custom format as argument when
2ccb0bcf 74 * setting pins to this mode.
3c4b23dd
MY
75 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
76 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
77 * schmitt-trigger mode is disabled.
394349f7
LW
78 * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
79 * operation, if several modes of operation are supported these can be
80 * passed in the argument on a custom form, else just use argument 1
81 * to indicate low power mode, argument 0 turns low power mode off.
e9c9489f
LW
82 * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument
83 * 1 to indicate high level, argument 0 to indicate low level. (Please
84 * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
85 * discussion around this parameter.)
3c4b23dd
MY
86 * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
87 * supplies, the argument to this parameter (on a custom format) tells
88 * the driver which alternative power source to use.
89 * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
90 * this parameter (on a custom format) tells the driver which alternative
91 * slew rate to use.
394349f7
LW
92 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
93 * you need to pass in custom configurations to the pin controller, use
94 * PIN_CONFIG_END+1 as the base offset.
58957d2e
MW
95 * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
96 * presented using the packed format.
394349f7
LW
97 */
98enum pin_config_param {
3c4b23dd 99 PIN_CONFIG_BIAS_BUS_HOLD,
394349f7
LW
100 PIN_CONFIG_BIAS_DISABLE,
101 PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
394349f7 102 PIN_CONFIG_BIAS_PULL_DOWN,
7970cb77 103 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
3c4b23dd 104 PIN_CONFIG_BIAS_PULL_UP,
394349f7
LW
105 PIN_CONFIG_DRIVE_OPEN_DRAIN,
106 PIN_CONFIG_DRIVE_OPEN_SOURCE,
3c4b23dd 107 PIN_CONFIG_DRIVE_PUSH_PULL,
f868ef99 108 PIN_CONFIG_DRIVE_STRENGTH,
3c4b23dd 109 PIN_CONFIG_INPUT_DEBOUNCE,
8ba3f4d0 110 PIN_CONFIG_INPUT_ENABLE,
394349f7 111 PIN_CONFIG_INPUT_SCHMITT,
3c4b23dd 112 PIN_CONFIG_INPUT_SCHMITT_ENABLE,
394349f7 113 PIN_CONFIG_LOW_POWER_MODE,
483f33f6 114 PIN_CONFIG_OUTPUT,
3c4b23dd
MY
115 PIN_CONFIG_POWER_SOURCE,
116 PIN_CONFIG_SLEW_RATE,
58957d2e
MW
117 PIN_CONFIG_END = 0x7F,
118 PIN_CONFIG_MAX = 0xFF,
394349f7
LW
119};
120
dd4d01f7
SB
121#ifdef CONFIG_DEBUG_FS
122#define PCONFDUMP(a, b, c, d) { .param = a, .display = b, .format = c, \
123 .has_arg = d }
124
125struct pin_config_item {
126 const enum pin_config_param param;
127 const char * const display;
128 const char * const format;
129 bool has_arg;
130};
131#endif /* CONFIG_DEBUG_FS */
132
394349f7
LW
133/*
134 * Helpful configuration macro to be used in tables etc.
135 */
58957d2e 136#define PIN_CONF_PACKED(p, a) ((a << 8) | ((unsigned long) p & 0xffUL))
394349f7
LW
137
138/*
139 * The following inlines stuffs a configuration parameter and data value
140 * into and out of an unsigned long argument, as used by the generic pin config
58957d2e
MW
141 * system. We put the parameter in the lower 8 bits and the argument in the
142 * upper 24 bits.
394349f7
LW
143 */
144
145static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
146{
58957d2e 147 return (enum pin_config_param) (config & 0xffUL);
394349f7
LW
148}
149
58957d2e 150static inline u32 pinconf_to_config_argument(unsigned long config)
394349f7 151{
58957d2e 152 return (u32) ((config >> 8) & 0xffffffUL);
394349f7
LW
153}
154
155static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
58957d2e 156 u32 argument)
394349f7
LW
157{
158 return PIN_CONF_PACKED(param, argument);
159}
160
0d74d4a1
LW
161#ifdef CONFIG_OF
162
163#include <linux/device.h>
3287c240 164#include <linux/pinctrl/machine.h>
0d74d4a1
LW
165struct pinctrl_dev;
166struct pinctrl_map;
167
f684e4ac 168struct pinconf_generic_params {
dd4d01f7
SB
169 const char * const property;
170 enum pin_config_param param;
171 u32 default_value;
172};
173
e81c8f18
LD
174int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
175 struct device_node *np, struct pinctrl_map **map,
3287c240
LD
176 unsigned *reserved_maps, unsigned *num_maps,
177 enum pinctrl_map_type type);
e81c8f18
LD
178int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
179 struct device_node *np_config, struct pinctrl_map **map,
3287c240 180 unsigned *num_maps, enum pinctrl_map_type type);
8dfebf57
JH
181void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
182 struct pinctrl_map *map, unsigned num_maps);
3287c240
LD
183
184static inline int pinconf_generic_dt_node_to_map_group(
185 struct pinctrl_dev *pctldev, struct device_node *np_config,
186 struct pinctrl_map **map, unsigned *num_maps)
187{
188 return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
189 PIN_MAP_TYPE_CONFIGS_GROUP);
190}
191
192static inline int pinconf_generic_dt_node_to_map_pin(
193 struct pinctrl_dev *pctldev, struct device_node *np_config,
194 struct pinctrl_map **map, unsigned *num_maps)
195{
196 return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
197 PIN_MAP_TYPE_CONFIGS_PIN);
198}
0d74d4a1 199
31c89c95
SB
200static inline int pinconf_generic_dt_node_to_map_all(
201 struct pinctrl_dev *pctldev, struct device_node *np_config,
202 struct pinctrl_map **map, unsigned *num_maps)
203{
204 /*
205 * passing the type as PIN_MAP_TYPE_INVALID causes the underlying parser
206 * to infer the map type from the DT properties used.
207 */
208 return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
209 PIN_MAP_TYPE_INVALID);
210}
0d74d4a1
LW
211#endif
212
394349f7
LW
213#endif /* CONFIG_GENERIC_PINCONF */
214
215#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */