pinconf-generic.h 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  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 <[email protected]>
  10. */
  11. #ifndef __LINUX_PINCTRL_PINCONF_GENERIC_H
  12. #define __LINUX_PINCTRL_PINCONF_GENERIC_H
  13. #include <linux/device.h>
  14. #include <linux/pinctrl/machine.h>
  15. struct pinctrl_dev;
  16. struct pinctrl_map;
  17. /**
  18. * enum pin_config_param - possible pin configuration parameters
  19. * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
  20. * weakly drives the last value on a tristate bus, also known as a "bus
  21. * holder", "bus keeper" or "repeater". This allows another device on the
  22. * bus to change the value by driving the bus high or low and switching to
  23. * tristate. The argument is ignored.
  24. * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
  25. * transition from say pull-up to pull-down implies that you disable
  26. * pull-up in the process, this setting disables all biasing.
  27. * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
  28. * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
  29. * On output pins this effectively disconnects the pin, which is useful
  30. * if for example some other pin is going to drive the signal connected
  31. * to it for a while. Pins used for input are usually always high
  32. * impedance.
  33. * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
  34. * impedance to GROUND). If the argument is != 0 pull-down is enabled,
  35. * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
  36. * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
  37. * on embedded knowledge of the controller hardware, like current mux
  38. * function. The pull direction and possibly strength too will normally
  39. * be decided completely inside the hardware block and not be readable
  40. * from the kernel side.
  41. * If the argument is != 0 pull up/down is enabled, if it is 0, the
  42. * configuration is ignored. The proper way to disable it is to use
  43. * @PIN_CONFIG_BIAS_DISABLE.
  44. * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
  45. * impedance to VDD). If the argument is != 0 pull-up is enabled,
  46. * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
  47. * @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
  49. * which are then pulled up with an external resistor. Setting this
  50. * config will enable open drain mode, the argument is ignored.
  51. * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
  52. * (open emitter). Setting this config will enable open source mode, the
  53. * argument is ignored.
  54. * @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.
  58. * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
  59. * passed as argument. The argument is in mA.
  60. * @PIN_CONFIG_DRIVE_STRENGTH_UA: the pin will sink or source at most the current
  61. * passed as argument. The argument is in uA.
  62. * @PIN_CONFIG_INPUT_DEBOUNCE: this will configure the pin to debounce mode,
  63. * which means it will wait for signals to settle when reading inputs. The
  64. * argument gives the debounce time in usecs. Setting the
  65. * argument to zero turns debouncing off.
  66. * @PIN_CONFIG_INPUT_ENABLE: enable the pin's input. Note that this does not
  67. * affect the pin's ability to drive output. 1 enables input, 0 disables
  68. * input.
  69. * @PIN_CONFIG_INPUT_SCHMITT: this will configure an input pin to run in
  70. * schmitt-trigger mode. If the schmitt-trigger has adjustable hysteresis,
  71. * the threshold value is given on a custom format as argument when
  72. * setting pins to this mode.
  73. * @PIN_CONFIG_INPUT_SCHMITT_ENABLE: control schmitt-trigger mode on the pin.
  74. * If the argument != 0, schmitt-trigger mode is enabled. If it's 0,
  75. * schmitt-trigger mode is disabled.
  76. * @PIN_CONFIG_MODE_LOW_POWER: this will configure the pin for low power
  77. * operation, if several modes of operation are supported these can be
  78. * passed in the argument on a custom form, else just use argument 1
  79. * to indicate low power mode, argument 0 turns low power mode off.
  80. * @PIN_CONFIG_MODE_PWM: this will configure the pin for PWM
  81. * @PIN_CONFIG_OUTPUT: this will configure the pin as an output and drive a
  82. * value on the line. Use argument 1 to indicate high level, argument 0 to
  83. * indicate low level. (Please see Documentation/driver-api/pin-control.rst,
  84. * section "GPIO mode pitfalls" for a discussion around this parameter.)
  85. * @PIN_CONFIG_OUTPUT_ENABLE: this will enable the pin's output mode
  86. * without driving a value there. For most platforms this reduces to
  87. * enable the output buffers and then let the pin controller current
  88. * configuration (eg. the currently selected mux function) drive values on
  89. * the line. Use argument 1 to enable output mode, argument 0 to disable
  90. * it.
  91. * @PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS: this will configure the output impedance
  92. * of the pin with the value passed as argument. The argument is in ohms.
  93. * @PIN_CONFIG_PERSIST_STATE: retain pin state across sleep or controller reset
  94. * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
  95. * supplies, the argument to this parameter (on a custom format) tells
  96. * the driver which alternative power source to use.
  97. * @PIN_CONFIG_SKEW_DELAY: if the pin has programmable skew rate (on inputs)
  98. * or latch delay (on outputs) this parameter (in a custom format)
  99. * specifies the clock skew or latch delay. It typically controls how
  100. * many double inverters are put in front of the line.
  101. * @PIN_CONFIG_SLEEP_HARDWARE_STATE: indicate this is sleep related state.
  102. * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
  103. * this parameter (on a custom format) tells the driver which alternative
  104. * slew rate to use.
  105. * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
  106. * you need to pass in custom configurations to the pin controller, use
  107. * PIN_CONFIG_END+1 as the base offset.
  108. * @PIN_CONFIG_MAX: this is the maximum configuration value that can be
  109. * presented using the packed format.
  110. */
  111. enum pin_config_param {
  112. PIN_CONFIG_BIAS_BUS_HOLD,
  113. PIN_CONFIG_BIAS_DISABLE,
  114. PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
  115. PIN_CONFIG_BIAS_PULL_DOWN,
  116. PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
  117. PIN_CONFIG_BIAS_PULL_UP,
  118. PIN_CONFIG_DRIVE_OPEN_DRAIN,
  119. PIN_CONFIG_DRIVE_OPEN_SOURCE,
  120. PIN_CONFIG_DRIVE_PUSH_PULL,
  121. PIN_CONFIG_DRIVE_STRENGTH,
  122. PIN_CONFIG_DRIVE_STRENGTH_UA,
  123. PIN_CONFIG_INPUT_DEBOUNCE,
  124. PIN_CONFIG_INPUT_ENABLE,
  125. PIN_CONFIG_INPUT_SCHMITT,
  126. PIN_CONFIG_INPUT_SCHMITT_ENABLE,
  127. PIN_CONFIG_MODE_LOW_POWER,
  128. PIN_CONFIG_MODE_PWM,
  129. PIN_CONFIG_OUTPUT,
  130. PIN_CONFIG_OUTPUT_ENABLE,
  131. PIN_CONFIG_OUTPUT_IMPEDANCE_OHMS,
  132. PIN_CONFIG_PERSIST_STATE,
  133. PIN_CONFIG_POWER_SOURCE,
  134. PIN_CONFIG_SKEW_DELAY,
  135. PIN_CONFIG_SLEEP_HARDWARE_STATE,
  136. PIN_CONFIG_SLEW_RATE,
  137. PIN_CONFIG_END = 0x7F,
  138. PIN_CONFIG_MAX = 0xFF,
  139. };
  140. /*
  141. * Helpful configuration macro to be used in tables etc.
  142. */
  143. #define PIN_CONF_PACKED(p, a) ((a << 8) | ((unsigned long) p & 0xffUL))
  144. /*
  145. * The following inlines stuffs a configuration parameter and data value
  146. * into and out of an unsigned long argument, as used by the generic pin config
  147. * system. We put the parameter in the lower 8 bits and the argument in the
  148. * upper 24 bits.
  149. */
  150. static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
  151. {
  152. return (enum pin_config_param) (config & 0xffUL);
  153. }
  154. static inline u32 pinconf_to_config_argument(unsigned long config)
  155. {
  156. return (u32) ((config >> 8) & 0xffffffUL);
  157. }
  158. static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
  159. u32 argument)
  160. {
  161. return PIN_CONF_PACKED(param, argument);
  162. }
  163. #define PCONFDUMP(a, b, c, d) { \
  164. .param = a, .display = b, .format = c, .has_arg = d \
  165. }
  166. struct pin_config_item {
  167. const enum pin_config_param param;
  168. const char * const display;
  169. const char * const format;
  170. bool has_arg;
  171. };
  172. struct pinconf_generic_params {
  173. const char * const property;
  174. enum pin_config_param param;
  175. u32 default_value;
  176. };
  177. int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  178. struct device_node *np, struct pinctrl_map **map,
  179. unsigned *reserved_maps, unsigned *num_maps,
  180. enum pinctrl_map_type type);
  181. int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
  182. struct device_node *np_config, struct pinctrl_map **map,
  183. unsigned *num_maps, enum pinctrl_map_type type);
  184. void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
  185. struct pinctrl_map *map, unsigned num_maps);
  186. static inline int pinconf_generic_dt_node_to_map_group(
  187. struct pinctrl_dev *pctldev, struct device_node *np_config,
  188. struct pinctrl_map **map, unsigned *num_maps)
  189. {
  190. return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
  191. PIN_MAP_TYPE_CONFIGS_GROUP);
  192. }
  193. static inline int pinconf_generic_dt_node_to_map_pin(
  194. struct pinctrl_dev *pctldev, struct device_node *np_config,
  195. struct pinctrl_map **map, unsigned *num_maps)
  196. {
  197. return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
  198. PIN_MAP_TYPE_CONFIGS_PIN);
  199. }
  200. static 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. }
  211. #endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */