Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 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 |
| 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 Hogan | a2df426 | 2013-05-24 17:21:12 +0100 | [diff] [blame] | 32 | * @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 Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 37 | * @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, |
Linus Walleij | 5ca3353 | 2013-06-16 12:43:06 +0200 | [diff] [blame] | 39 | * if it is 0, pull-up is total, i.e. the pin is connected to VDD. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 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, |
Linus Walleij | 5ca3353 | 2013-06-16 12:43:06 +0200 | [diff] [blame] | 42 | * if it is 0, pull-down is total, i.e. the pin is connected to GROUND. |
Heiko Stübner | 7970cb7 | 2013-06-06 16:44:25 +0200 | [diff] [blame] | 43 | * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based |
Heiko Stübner | 70637a6 | 2013-06-25 14:55:42 +0200 | [diff] [blame] | 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. |
Linus Walleij | 5ca3353 | 2013-06-16 12:43:06 +0200 | [diff] [blame] | 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. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 51 | * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and |
| 52 | * low, this is the most typical case and is typically achieved with two |
Laurent Pinchart | 63ad9cb | 2013-04-23 15:28:38 +0200 | [diff] [blame] | 53 | * active transistors on the output. Setting this config will enable |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 54 | * push-pull mode, the argument is ignored. |
| 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 |
Laurent Pinchart | 63ad9cb | 2013-04-23 15:28:38 +0200 | [diff] [blame] | 57 | * which are then pulled up with an external resistor. Setting this |
| 58 | * config will enable open drain mode, the argument is ignored. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 59 | * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source |
Laurent Pinchart | 63ad9cb | 2013-04-23 15:28:38 +0200 | [diff] [blame] | 60 | * (open emitter). Setting this config will enable open drain mode, the |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 61 | * argument is ignored. |
Laurent Pinchart | 63ad9cb | 2013-04-23 15:28:38 +0200 | [diff] [blame] | 62 | * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current |
| 63 | * passed as argument. The argument is in mA. |
Sherman Yin | 8ba3f4d | 2013-12-11 10:37:17 -0800 | [diff] [blame] | 64 | * @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. |
Haojian Zhuang | ea27c39 | 2013-02-12 01:10:57 +0800 | [diff] [blame] | 67 | * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin. |
| 68 | * If the argument != 0, schmitt-trigger mode is enabled. If it's 0, |
| 69 | * schmitt-trigger mode is disabled. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 70 | * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in |
| 71 | * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis, |
| 72 | * the threshold value is given on a custom format as argument when |
Haojian Zhuang | 2ccb0bc | 2012-11-15 16:36:33 +0800 | [diff] [blame] | 73 | * setting pins to this mode. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 74 | * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode, |
| 75 | * which means it will wait for signals to settle when reading inputs. The |
Heiko Stübner | 256aeb6 | 2013-06-25 14:56:11 +0200 | [diff] [blame] | 76 | * argument gives the debounce time in usecs. Setting the |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 77 | * argument to zero turns debouncing off. |
| 78 | * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power |
| 79 | * supplies, the argument to this parameter (on a custom format) tells |
| 80 | * the driver which alternative power source to use. |
Haojian Zhuang | 684697c | 2013-01-18 15:31:15 +0800 | [diff] [blame] | 81 | * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to |
Linus Walleij | 5ca3353 | 2013-06-16 12:43:06 +0200 | [diff] [blame] | 82 | * this parameter (on a custom format) tells the driver which alternative |
| 83 | * slew rate to use. |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 84 | * @PIN_CONFIG_LOW_POWER_MODE: this will configure the pin for low power |
| 85 | * operation, if several modes of operation are supported these can be |
| 86 | * passed in the argument on a custom form, else just use argument 1 |
| 87 | * to indicate low power mode, argument 0 turns low power mode off. |
Linus Walleij | e9c9489 | 2013-11-25 15:43:37 +0100 | [diff] [blame] | 88 | * @PIN_CONFIG_OUTPUT: this will configure the pin as an output. Use argument |
| 89 | * 1 to indicate high level, argument 0 to indicate low level. (Please |
| 90 | * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a |
| 91 | * discussion around this parameter.) |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 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. |
| 95 | */ |
| 96 | enum pin_config_param { |
| 97 | PIN_CONFIG_BIAS_DISABLE, |
| 98 | PIN_CONFIG_BIAS_HIGH_IMPEDANCE, |
James Hogan | a2df426 | 2013-05-24 17:21:12 +0100 | [diff] [blame] | 99 | PIN_CONFIG_BIAS_BUS_HOLD, |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 100 | PIN_CONFIG_BIAS_PULL_UP, |
| 101 | PIN_CONFIG_BIAS_PULL_DOWN, |
Heiko Stübner | 7970cb7 | 2013-06-06 16:44:25 +0200 | [diff] [blame] | 102 | PIN_CONFIG_BIAS_PULL_PIN_DEFAULT, |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 103 | PIN_CONFIG_DRIVE_PUSH_PULL, |
| 104 | PIN_CONFIG_DRIVE_OPEN_DRAIN, |
| 105 | PIN_CONFIG_DRIVE_OPEN_SOURCE, |
Maxime Ripard | f868ef9 | 2013-01-08 22:43:12 +0100 | [diff] [blame] | 106 | PIN_CONFIG_DRIVE_STRENGTH, |
Sherman Yin | 8ba3f4d | 2013-12-11 10:37:17 -0800 | [diff] [blame] | 107 | PIN_CONFIG_INPUT_ENABLE, |
Haojian Zhuang | ea27c39 | 2013-02-12 01:10:57 +0800 | [diff] [blame] | 108 | PIN_CONFIG_INPUT_SCHMITT_ENABLE, |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 109 | PIN_CONFIG_INPUT_SCHMITT, |
| 110 | PIN_CONFIG_INPUT_DEBOUNCE, |
| 111 | PIN_CONFIG_POWER_SOURCE, |
Haojian Zhuang | 684697c | 2013-01-18 15:31:15 +0800 | [diff] [blame] | 112 | PIN_CONFIG_SLEW_RATE, |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 113 | PIN_CONFIG_LOW_POWER_MODE, |
Linus Walleij | 483f33f | 2013-01-04 17:57:40 +0100 | [diff] [blame] | 114 | PIN_CONFIG_OUTPUT, |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 115 | PIN_CONFIG_END = 0x7FFF, |
| 116 | }; |
| 117 | |
| 118 | /* |
| 119 | * Helpful configuration macro to be used in tables etc. |
| 120 | */ |
| 121 | #define PIN_CONF_PACKED(p, a) ((a << 16) | ((unsigned long) p & 0xffffUL)) |
| 122 | |
| 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 |
| 126 | * system. We put the parameter in the lower 16 bits and the argument in the |
| 127 | * upper 16 bits. |
| 128 | */ |
| 129 | |
| 130 | static inline enum pin_config_param pinconf_to_config_param(unsigned long config) |
| 131 | { |
| 132 | return (enum pin_config_param) (config & 0xffffUL); |
| 133 | } |
| 134 | |
| 135 | static inline u16 pinconf_to_config_argument(unsigned long config) |
| 136 | { |
| 137 | return (enum pin_config_param) ((config >> 16) & 0xffffUL); |
| 138 | } |
| 139 | |
| 140 | static inline unsigned long pinconf_to_config_packed(enum pin_config_param param, |
| 141 | u16 argument) |
| 142 | { |
| 143 | return PIN_CONF_PACKED(param, argument); |
| 144 | } |
| 145 | |
Linus Walleij | 0d74d4a | 2013-08-15 21:38:49 +0200 | [diff] [blame] | 146 | #ifdef CONFIG_OF |
| 147 | |
| 148 | #include <linux/device.h> |
Laxman Dewangan | 3287c24 | 2013-08-21 16:53:37 +0530 | [diff] [blame] | 149 | #include <linux/pinctrl/machine.h> |
Linus Walleij | 0d74d4a | 2013-08-15 21:38:49 +0200 | [diff] [blame] | 150 | struct pinctrl_dev; |
| 151 | struct pinctrl_map; |
| 152 | |
Laxman Dewangan | e81c8f1 | 2013-08-06 18:42:34 +0530 | [diff] [blame] | 153 | int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev, |
| 154 | struct device_node *np, struct pinctrl_map **map, |
Laxman Dewangan | 3287c24 | 2013-08-21 16:53:37 +0530 | [diff] [blame] | 155 | unsigned *reserved_maps, unsigned *num_maps, |
| 156 | enum pinctrl_map_type type); |
Laxman Dewangan | e81c8f1 | 2013-08-06 18:42:34 +0530 | [diff] [blame] | 157 | int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev, |
| 158 | struct device_node *np_config, struct pinctrl_map **map, |
Laxman Dewangan | 3287c24 | 2013-08-21 16:53:37 +0530 | [diff] [blame] | 159 | unsigned *num_maps, enum pinctrl_map_type type); |
| 160 | |
| 161 | static inline int pinconf_generic_dt_node_to_map_group( |
| 162 | struct pinctrl_dev *pctldev, struct device_node *np_config, |
| 163 | struct pinctrl_map **map, unsigned *num_maps) |
| 164 | { |
| 165 | return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps, |
| 166 | PIN_MAP_TYPE_CONFIGS_GROUP); |
| 167 | } |
| 168 | |
| 169 | static inline int pinconf_generic_dt_node_to_map_pin( |
| 170 | struct pinctrl_dev *pctldev, struct device_node *np_config, |
| 171 | struct pinctrl_map **map, unsigned *num_maps) |
| 172 | { |
| 173 | return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps, |
| 174 | PIN_MAP_TYPE_CONFIGS_PIN); |
| 175 | } |
Linus Walleij | 0d74d4a | 2013-08-15 21:38:49 +0200 | [diff] [blame] | 176 | |
| 177 | #endif |
| 178 | |
Linus Walleij | 394349f | 2011-11-24 18:27:15 +0100 | [diff] [blame] | 179 | #endif /* CONFIG_GENERIC_PINCONF */ |
| 180 | |
| 181 | #endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */ |