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