blob: 201e68de2d115eb398bc2f1febfb1817dc50d17a [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
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
23 * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
24 * transition from say pull-up to pull-down implies that you disable
25 * pull-up in the process, this setting disables all biasing.
26 * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
27 * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
28 * On output pins this effectively disconnects the pin, which is useful
29 * if for example some other pin is going to drive the signal connected
30 * to it for a while. Pins used for input are usually always high
31 * impedance.
James Hogan5a585d42013-05-24 17:21:12 +010032 * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
33 * weakly drives the last value on a tristate bus, also known as a "bus
34 * holder", "bus keeper" or "repeater". This allows another device on the
35 * bus to change the value by driving the bus high or low and switching to
36 * tristate. The argument is ignored.
Linus Walleij394349f2011-11-24 18:27:15 +010037 * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
38 * impedance to VDD). If the argument is != 0 pull-up is enabled,
39 * if it is 0, pull-up is disabled.
40 * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
41 * impedance to GROUND). If the argument is != 0 pull-down is enabled,
42 * if it is 0, pull-down is disabled.
Heiko Stübnerfd08eab2013-06-06 16:44:25 +020043 * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
44 * on embedded knowledge of the controller, like current mux function.
45 * If the argument is != 0 pull up/down is enabled, if it is 0,
46 * the pull is disabled.
Linus Walleij394349f2011-11-24 18:27:15 +010047 * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
48 * low, this is the most typical case and is typically achieved with two
Laurent Pinchart63ad9cb2013-04-23 15:28:38 +020049 * active transistors on the output. Setting this config will enable
Linus Walleij394349f2011-11-24 18:27:15 +010050 * push-pull mode, the argument is ignored.
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
Laurent Pinchart63ad9cb2013-04-23 15:28:38 +020053 * which are then pulled up with an external resistor. Setting this
54 * config will enable open drain mode, the argument is ignored.
Linus Walleij394349f2011-11-24 18:27:15 +010055 * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
Laurent Pinchart63ad9cb2013-04-23 15:28:38 +020056 * (open emitter). Setting this config will enable open drain mode, the
Linus Walleij394349f2011-11-24 18:27:15 +010057 * 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.
Sherman Yin150e48f2013-12-11 10:37:17 -080060 * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
61 * affect the pin's ability to drive output. 1 enables input, 0 disables
62 * input.
Haojian Zhuangea27c392013-02-12 01:10:57 +080063 * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
64 * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
65 * schmitt-trigger mode is disabled.
Linus Walleij394349f2011-11-24 18:27:15 +010066 * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
67 * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
68 * the threshold value is given on a custom format as argument when
Haojian Zhuang2ccb0bc2012-11-15 16:36:33 +080069 * setting pins to this mode.
Linus Walleij394349f2011-11-24 18:27:15 +010070 * @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
Heiko Stübner6d27cf92013-06-25 14:56:11 +020072 * argument gives the debounce time in usecs. Setting the
Linus Walleij394349f2011-11-24 18:27:15 +010073 * argument to zero turns debouncing off.
74 * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
75 * supplies, the argument to this parameter (on a custom format) tells
76 * the driver which alternative power source to use.
Haojian Zhuang684697c2013-01-18 15:31:15 +080077 * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
78 * this parameter (on a custom format) tells the driver which alternative
79 * slew rate to use.
Linus Walleij394349f2011-11-24 18:27:15 +010080 * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power
81 * operation, if several modes of operation are supported these can be
82 * passed in the argument on a custom form, else just use argument 1
83 * to indicate low power mode, argument 0 turns low power mode off.
Linus Walleij483f33f2013-01-04 17:57:40 +010084 * @PIN_CONFIG_OUTPUT: this will configure the pin in output, use argument
85 * 1 to indicate high level, argument 0 to indicate low level.
Linus Walleij394349f2011-11-24 18:27:15 +010086 * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
87 * you need to pass in custom configurations to the pin controller, use
88 * PIN_CONFIG_END+1 as the base offset.
89 */
90enum pin_config_param {
91 PIN_CONFIG_BIAS_DISABLE,
92 PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
James Hogan5a585d42013-05-24 17:21:12 +010093 PIN_CONFIG_BIAS_BUS_HOLD,
Linus Walleij394349f2011-11-24 18:27:15 +010094 PIN_CONFIG_BIAS_PULL_UP,
95 PIN_CONFIG_BIAS_PULL_DOWN,
Heiko Stübnerfd08eab2013-06-06 16:44:25 +020096 PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
Linus Walleij394349f2011-11-24 18:27:15 +010097 PIN_CONFIG_DRIVE_PUSH_PULL,
98 PIN_CONFIG_DRIVE_OPEN_DRAIN,
99 PIN_CONFIG_DRIVE_OPEN_SOURCE,
Maxime Ripardf868ef92013-01-08 22:43:12 +0100100 PIN_CONFIG_DRIVE_STRENGTH,
Sherman Yin150e48f2013-12-11 10:37:17 -0800101 PIN_CONFIG_INPUT_ENABLE,
Haojian Zhuangea27c392013-02-12 01:10:57 +0800102 PIN_CONFIG_INPUT_SCHMITT_ENABLE,
Linus Walleij394349f2011-11-24 18:27:15 +0100103 PIN_CONFIG_INPUT_SCHMITT,
104 PIN_CONFIG_INPUT_DEBOUNCE,
105 PIN_CONFIG_POWER_SOURCE,
Haojian Zhuang684697c2013-01-18 15:31:15 +0800106 PIN_CONFIG_SLEW_RATE,
Linus Walleij394349f2011-11-24 18:27:15 +0100107 PIN_CONFIG_LOW_POWER_MODE,
Linus Walleij483f33f2013-01-04 17:57:40 +0100108 PIN_CONFIG_OUTPUT,
Linus Walleij394349f2011-11-24 18:27:15 +0100109 PIN_CONFIG_END = 0x7FFF,
110};
111
112/*
113 * Helpful configuration macro to be used in tables etc.
114 */
115#define PIN_CONF_PACKED(p, a) ((a << 16) | ((unsigned long) p & 0xffffUL))
116
117/*
118 * The following inlines stuffs a configuration parameter and data value
119 * into and out of an unsigned long argument, as used by the generic pin config
120 * system. We put the parameter in the lower 16 bits and the argument in the
121 * upper 16 bits.
122 */
123
124static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
125{
126 return (enum pin_config_param) (config & 0xffffUL);
127}
128
129static inline u16 pinconf_to_config_argument(unsigned long config)
130{
131 return (enum pin_config_param) ((config >> 16) & 0xffffUL);
132}
133
134static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
135 u16 argument)
136{
137 return PIN_CONF_PACKED(param, argument);
138}
139
Linus Walleijedfee602013-08-15 21:38:49 +0200140#ifdef CONFIG_OF
141
142#include <linux/device.h>
Mark Brown270cfc42014-04-04 21:39:02 +0100143#include <linux/pinctrl/machine.h>
Linus Walleijedfee602013-08-15 21:38:49 +0200144struct pinctrl_dev;
145struct pinctrl_map;
146
Mark Brown270cfc42014-04-04 21:39:02 +0100147int pinconf_generic_dt_subnode_to_map_new(struct pinctrl_dev *pctldev,
Laxman Dewangan9ce1c712013-08-06 18:42:34 +0530148 struct device_node *np, struct pinctrl_map **map,
Mark Brown270cfc42014-04-04 21:39:02 +0100149 unsigned *reserved_maps, unsigned *num_maps,
150 enum pinctrl_map_type type);
151int pinconf_generic_dt_node_to_map_new(struct pinctrl_dev *pctldev,
Laxman Dewangan9ce1c712013-08-06 18:42:34 +0530152 struct device_node *np_config, struct pinctrl_map **map,
Mark Brown270cfc42014-04-04 21:39:02 +0100153 unsigned *num_maps, enum pinctrl_map_type type);
154
155static inline int pinconf_generic_dt_node_to_map_group(
156 struct pinctrl_dev *pctldev, struct device_node *np_config,
157 struct pinctrl_map **map, unsigned *num_maps)
158{
159 return pinconf_generic_dt_node_to_map_new(pctldev, np_config, map, num_maps,
160 PIN_MAP_TYPE_CONFIGS_GROUP);
161}
162
163static inline int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
164 struct device_node *np, struct pinctrl_map **map,
165 unsigned *reserved_maps, unsigned *num_maps)
166{
167 return pinconf_generic_dt_subnode_to_map_new(pctldev, np, map,
168 reserved_maps, num_maps,
169 PIN_MAP_TYPE_CONFIGS_PIN);
170}
171
172static inline int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
173 struct device_node *np_config, struct pinctrl_map **map,
174 unsigned *num_maps)
175{
176 return pinconf_generic_dt_node_to_map_new(pctldev, np_config,
177 map, num_maps,
178 PIN_MAP_TYPE_CONFIGS_PIN);
179}
180
181
182static inline int pinconf_generic_dt_node_to_map_pin(
183 struct pinctrl_dev *pctldev, struct device_node *np_config,
184 struct pinctrl_map **map, unsigned *num_maps)
185{
186 return pinconf_generic_dt_node_to_map_new(pctldev, np_config, map, num_maps,
187 PIN_MAP_TYPE_CONFIGS_PIN);
188}
Linus Walleijedfee602013-08-15 21:38:49 +0200189
190#endif
191
Linus Walleij394349f2011-11-24 18:27:15 +0100192#endif /* CONFIG_GENERIC_PINCONF */
193
194#endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */