blob: 279e3c5326e3a4e65bf6f86556ea984a69d0ca9c [file] [log] [blame]
Linus Walleij394349f2011-11-24 18:27:15 +01001/*
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
Linus Walleij394349f2011-11-24 18:27:15 +010015/**
16 * enum pin_config_param - possible pin configuration parameters
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090017 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
18 * weakly drives the last value on a tristate bus, also known as a "bus
19 * holder", "bus keeper" or "repeater". This allows another device on the
20 * bus to change the value by driving the bus high or low and switching to
21 * tristate. The argument is ignored.
Linus Walleij394349f2011-11-24 18:27:15 +010022 * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
23 * transition from say pull-up to pull-down implies that you disable
24 * pull-up in the process, this setting disables all biasing.
25 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
26 * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
27 * On output pins this effectively disconnects the pin, which is useful
28 * if for example some other pin is going to drive the signal connected
29 * to it for a while. Pins used for input are usually always high
30 * impedance.
Linus Walleij394349f2011-11-24 18:27:15 +010031 * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
32 * impedance to GROUND). If the argument is != 0 pull-down is enabled,
Linus Walleij5ca33532013-06-16 12:43:06 +020033 * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
Heiko Stübner7970cb72013-06-06 16:44:25 +020034 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
Heiko Stübner70637a62013-06-25 14:55:42 +020035 * on embedded knowledge of the controller hardware, like current mux
36 * function. The pull direction and possibly strength too will normally
37 * be decided completely inside the hardware block and not be readable
38 * from the kernel side.
Linus Walleij5ca33532013-06-16 12:43:06 +020039 * If the argument is != 0 pull up/down is enabled, if it is 0, the
40 * configuration is ignored. The proper way to disable it is to use
41 * @PIN_CONFIG_BIAS_DISABLE.
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090042 * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
43 * impedance to VDD). If the argument is != 0 pull-up is enabled,
44 * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
Jacopo Mondi8c58f1a2017-04-05 16:07:19 +020045 * @PIN_CONFIG_BIDIRECTIONAL: the pin will be configured to allow simultaneous
46 * input and output operations.
Linus Walleij394349f2011-11-24 18:27:15 +010047 * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
48 * collector) which means it is usually wired with other output ports
Laurent Pinchart63ad9cb2013-04-23 15:28:38 +020049 * which are then pulled up with an external resistor. Setting this
50 * config will enable open drain mode, the argument is ignored.
Linus Walleij394349f2011-11-24 18:27:15 +010051 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
Geert Uytterhoeven0d378992014-09-03 20:01:55 +020052 * (open emitter). Setting this config will enable open source mode, the
Linus Walleij394349f2011-11-24 18:27:15 +010053 * argument is ignored.
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090054 * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
55 * low, this is the most typical case and is typically achieved with two
56 * active transistors on the output. Setting this config will enable
57 * push-pull mode, the argument is ignored.
Laurent Pinchart63ad9cb2013-04-23 15:28:38 +020058 * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
59 * passed as argument. The argument is in mA.
Linus Walleij394349f2011-11-24 18:27:15 +010060 * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
61 * which means it will wait for signals to settle when reading inputs. The
Heiko Stübner256aeb62013-06-25 14:56:11 +020062 * argument gives the debounce time in usecs. Setting the
Linus Walleij394349f2011-11-24 18:27:15 +010063 * argument to zero turns debouncing off.
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090064 * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
65 * affect the pin's ability to drive output. 1 enables input, 0 disables
66 * input.
67 * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
68 * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
69 * the threshold value is given on a custom format as argument when
70 * setting pins to this mode.
71 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
72 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
73 * schmitt-trigger mode is disabled.
Linus Walleij394349f2011-11-24 18:27:15 +010074 * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
75 * operation, if several modes of operation are supported these can be
76 * passed in the argument on a custom form, else just use argument 1
77 * to indicate low power mode, argument 0 turns low power mode off.
Linus Walleije9c94892013-11-25 15:43:37 +010078 * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument
79 * 1 to indicate high level, argument 0 to indicate low level. (Please
80 * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
81 * discussion around this parameter.)
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090082 * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
83 * supplies, the argument to this parameter (on a custom format) tells
84 * the driver which alternative power source to use.
85 * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
86 * this parameter (on a custom format) tells the driver which alternative
87 * slew rate to use.
Linus Walleij394349f2011-11-24 18:27:15 +010088 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
89 * you need to pass in custom configurations to the pin controller, use
90 * PIN_CONFIG_END+1 as the base offset.
Mika Westerberg58957d22017-01-23 15:34:32 +030091 * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
92 * presented using the packed format.
Linus Walleij394349f2011-11-24 18:27:15 +010093 */
94enum pin_config_param {
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +090095 PIN_CONFIG_BIAS_BUS_HOLD,
Linus Walleij394349f2011-11-24 18:27:15 +010096 PIN_CONFIG_BIAS_DISABLE,
97 PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
Linus Walleij394349f2011-11-24 18:27:15 +010098 PIN_CONFIG_BIAS_PULL_DOWN,
Heiko Stübner7970cb72013-06-06 16:44:25 +020099 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +0900100 PIN_CONFIG_BIAS_PULL_UP,
Jacopo Mondi8c58f1a2017-04-05 16:07:19 +0200101 PIN_CONFIG_BIDIRECTIONAL,
Linus Walleij394349f2011-11-24 18:27:15 +0100102 PIN_CONFIG_DRIVE_OPEN_DRAIN,
103 PIN_CONFIG_DRIVE_OPEN_SOURCE,
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +0900104 PIN_CONFIG_DRIVE_PUSH_PULL,
Maxime Ripardf868ef92013-01-08 22:43:12 +0100105 PIN_CONFIG_DRIVE_STRENGTH,
Linus Walleij394349f2011-11-24 18:27:15 +0100106 PIN_CONFIG_INPUT_DEBOUNCE,
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +0900107 PIN_CONFIG_INPUT_ENABLE,
108 PIN_CONFIG_INPUT_SCHMITT,
109 PIN_CONFIG_INPUT_SCHMITT_ENABLE,
Linus Walleij394349f2011-11-24 18:27:15 +0100110 PIN_CONFIG_LOW_POWER_MODE,
Linus Walleij483f33f2013-01-04 17:57:40 +0100111 PIN_CONFIG_OUTPUT,
Masahiro Yamada3c4b23d2015-09-30 21:07:17 +0900112 PIN_CONFIG_POWER_SOURCE,
113 PIN_CONFIG_SLEW_RATE,
Mika Westerberg58957d22017-01-23 15:34:32 +0300114 PIN_CONFIG_END = 0x7F,
115 PIN_CONFIG_MAX = 0xFF,
Linus Walleij394349f2011-11-24 18:27:15 +0100116};
117
118/*
119 * Helpful configuration macro to be used in tables etc.
120 */
Mika Westerberg58957d22017-01-23 15:34:32 +0300121#define PIN_CONF_PACKED(p, a) ((a << 8) | ((unsigned long) p & 0xffUL))
Linus Walleij394349f2011-11-24 18:27:15 +0100122
123/*
124 * The following inlines stuffs a configuration parameter and data value
125 * into and out of an unsigned long argument, as used by the generic pin config
Mika Westerberg58957d22017-01-23 15:34:32 +0300126 * system. We put the parameter in the lower 8 bits and the argument in the
127 * upper 24 bits.
Linus Walleij394349f2011-11-24 18:27:15 +0100128 */
129
130static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
131{
Mika Westerberg58957d22017-01-23 15:34:32 +0300132 return (enum pin_config_param) (config & 0xffUL);
Linus Walleij394349f2011-11-24 18:27:15 +0100133}
134
Mika Westerberg58957d22017-01-23 15:34:32 +0300135static inline u32 pinconf_to_config_argument(unsigned long config)
Linus Walleij394349f2011-11-24 18:27:15 +0100136{
Mika Westerberg58957d22017-01-23 15:34:32 +0300137 return (u32) ((config >> 8) & 0xffffffUL);
Linus Walleij394349f2011-11-24 18:27:15 +0100138}
139
140static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
Mika Westerberg58957d22017-01-23 15:34:32 +0300141 u32 argument)
Linus Walleij394349f2011-11-24 18:27:15 +0100142{
143 return PIN_CONF_PACKED(param, argument);
144}
145
Mika Westerberg2956b5d2017-01-23 15:34:34 +0300146#ifdef CONFIG_GENERIC_PINCONF
147
148#ifdef CONFIG_DEBUG_FS
149#define PCONFDUMP(a, b, c, d) { \
150 .param = a, .display = b, .format = c, .has_arg = d \
151 }
152
153struct pin_config_item {
154 const enum pin_config_param param;
155 const char * const display;
156 const char * const format;
157 bool has_arg;
158};
159#endif /* CONFIG_DEBUG_FS */
160
Linus Walleij0d74d4a2013-08-15 21:38:49 +0200161#ifdef CONFIG_OF
162
163#include <linux/device.h>
Laxman Dewangan3287c242013-08-21 16:53:37 +0530164#include <linux/pinctrl/machine.h>
Linus Walleij0d74d4a2013-08-15 21:38:49 +0200165struct pinctrl_dev;
166struct pinctrl_map;
167
Linus Walleijf684e4a2015-01-12 00:45:55 +0100168struct pinconf_generic_params {
Soren Brinkmanndd4d01f2015-01-09 07:43:46 -0800169 const char * const property;
170 enum pin_config_param param;
171 u32 default_value;
172};
173
Laxman Dewangane81c8f12013-08-06 18:42:34 +0530174int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
175 struct device_node *np, struct pinctrl_map **map,
Laxman Dewangan3287c242013-08-21 16:53:37 +0530176 unsigned *reserved_maps, unsigned *num_maps,
177 enum pinctrl_map_type type);
Laxman Dewangane81c8f12013-08-06 18:42:34 +0530178int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
179 struct device_node *np_config, struct pinctrl_map **map,
Laxman Dewangan3287c242013-08-21 16:53:37 +0530180 unsigned *num_maps, enum pinctrl_map_type type);
Jon Hunter8dfebf52016-06-17 13:03:40 +0100181void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
182 struct pinctrl_map *map, unsigned num_maps);
Laxman Dewangan3287c242013-08-21 16:53:37 +0530183
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}
Linus Walleij0d74d4a2013-08-15 21:38:49 +0200199
Soren Brinkmann31c89c92015-01-09 07:43:45 -0800200static 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}
Linus Walleij0d74d4a2013-08-15 21:38:49 +0200211#endif
212
Linus Walleij394349f2011-11-24 18:27:15 +0100213#endif /* CONFIG_GENERIC_PINCONF */
214
215#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */