pinconf-generic.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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. * You shouldn't even be able to compile with these enums etc unless you're
  16. * using generic pin config. That is why this is defined out.
  17. */
  18. #ifdef CONFIG_GENERIC_PINCONF
  19. /**
  20. * enum pin_config_param - possible pin configuration parameters
  21. * @PIN_CONFIG_BIAS_BUS_HOLD: the pin will be set to weakly latch so that it
  22. * weakly drives the last value on a tristate bus, also known as a "bus
  23. * holder", "bus keeper" or "repeater". This allows another device on the
  24. * bus to change the value by driving the bus high or low and switching to
  25. * tristate. The argument is ignored.
  26. * @PIN_CONFIG_BIAS_DISABLE: disable any pin bias on the pin, a
  27. * transition from say pull-up to pull-down implies that you disable
  28. * pull-up in the process, this setting disables all biasing.
  29. * @PIN_CONFIG_BIAS_HIGH_IMPEDANCE: the pin will be set to a high impedance
  30. * mode, also know as "third-state" (tristate) or "high-Z" or "floating".
  31. * On output pins this effectively disconnects the pin, which is useful
  32. * if for example some other pin is going to drive the signal connected
  33. * to it for a while. Pins used for input are usually always high
  34. * impedance.
  35. * @PIN_CONFIG_BIAS_PULL_DOWN: the pin will be pulled down (usually with high
  36. * impedance to GROUND). If the argument is != 0 pull-down is enabled,
  37. * if it is 0, pull-down is total, i.e. the pin is connected to GROUND.
  38. * @PIN_CONFIG_BIAS_PULL_PIN_DEFAULT: the pin will be pulled up or down based
  39. * on embedded knowledge of the controller hardware, like current mux
  40. * function. The pull direction and possibly strength too will normally
  41. * be decided completely inside the hardware block and not be readable
  42. * from the kernel side.
  43. * If the argument is != 0 pull up/down is enabled, if it is 0, the
  44. * configuration is ignored. The proper way to disable it is to use
  45. * @PIN_CONFIG_BIAS_DISABLE.
  46. * @PIN_CONFIG_BIAS_PULL_UP: the pin will be pulled up (usually with high
  47. * impedance to VDD). If the argument is != 0 pull-up is enabled,
  48. * if it is 0, pull-up is total, i.e. the pin is connected to VDD.
  49. * @PIN_CONFIG_DRIVE_OPEN_DRAIN: the pin will be driven with open drain (open
  50. * collector) which means it is usually wired with other output ports
  51. * which are then pulled up with an external resistor. Setting this
  52. * config will enable open drain mode, the argument is ignored.
  53. * @PIN_CONFIG_DRIVE_OPEN_SOURCE: the pin will be driven with open source
  54. * (open emitter). Setting this config will enable open source mode, the
  55. * argument is ignored.
  56. * @PIN_CONFIG_DRIVE_PUSH_PULL: the pin will be driven actively high and
  57. * low, this is the most typical case and is typically achieved with two
  58. * active transistors on the output. Setting this config will enable
  59. * push-pull mode, the argument is ignored.
  60. * @PIN_CONFIG_DRIVE_STRENGTH: the pin will sink or source at most the current
  61. * passed as argument. The argument is in mA.
  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_LOW_POWER_MODE: 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_OUTPUT: this will configure the pin as an output. Use argument
  81. * 1 to indicate high level, argument 0 to indicate low level. (Please
  82. * see Documentation/pinctrl.txt, section "GPIO mode pitfalls" for a
  83. * discussion around this parameter.)
  84. * @PIN_CONFIG_POWER_SOURCE: if the pin can select between different power
  85. * supplies, the argument to this parameter (on a custom format) tells
  86. * the driver which alternative power source to use.
  87. * @PIN_CONFIG_SLEW_RATE: if the pin can select slew rate, the argument to
  88. * this parameter (on a custom format) tells the driver which alternative
  89. * slew rate to use.
  90. * @PIN_CONFIG_END: this is the last enumerator for pin configurations, if
  91. * you need to pass in custom configurations to the pin controller, use
  92. * PIN_CONFIG_END+1 as the base offset.
  93. */
  94. enum pin_config_param {
  95. PIN_CONFIG_BIAS_BUS_HOLD,
  96. PIN_CONFIG_BIAS_DISABLE,
  97. PIN_CONFIG_BIAS_HIGH_IMPEDANCE,
  98. PIN_CONFIG_BIAS_PULL_DOWN,
  99. PIN_CONFIG_BIAS_PULL_PIN_DEFAULT,
  100. PIN_CONFIG_BIAS_PULL_UP,
  101. PIN_CONFIG_DRIVE_OPEN_DRAIN,
  102. PIN_CONFIG_DRIVE_OPEN_SOURCE,
  103. PIN_CONFIG_DRIVE_PUSH_PULL,
  104. PIN_CONFIG_DRIVE_STRENGTH,
  105. PIN_CONFIG_INPUT_DEBOUNCE,
  106. PIN_CONFIG_INPUT_ENABLE,
  107. PIN_CONFIG_INPUT_SCHMITT,
  108. PIN_CONFIG_INPUT_SCHMITT_ENABLE,
  109. PIN_CONFIG_LOW_POWER_MODE,
  110. PIN_CONFIG_OUTPUT,
  111. PIN_CONFIG_POWER_SOURCE,
  112. PIN_CONFIG_SLEW_RATE,
  113. PIN_CONFIG_END = 0x7FFF,
  114. };
  115. #ifdef CONFIG_DEBUG_FS
  116. #define PCONFDUMP(a, b, c, d) { .param = a, .display = b, .format = c, \
  117. .has_arg = d }
  118. struct pin_config_item {
  119. const enum pin_config_param param;
  120. const char * const display;
  121. const char * const format;
  122. bool has_arg;
  123. };
  124. #endif /* CONFIG_DEBUG_FS */
  125. /*
  126. * Helpful configuration macro to be used in tables etc.
  127. */
  128. #define PIN_CONF_PACKED(p, a) ((a << 16) | ((unsigned long) p & 0xffffUL))
  129. /*
  130. * The following inlines stuffs a configuration parameter and data value
  131. * into and out of an unsigned long argument, as used by the generic pin config
  132. * system. We put the parameter in the lower 16 bits and the argument in the
  133. * upper 16 bits.
  134. */
  135. static inline enum pin_config_param pinconf_to_config_param(unsigned long config)
  136. {
  137. return (enum pin_config_param) (config & 0xffffUL);
  138. }
  139. static inline u16 pinconf_to_config_argument(unsigned long config)
  140. {
  141. return (enum pin_config_param) ((config >> 16) & 0xffffUL);
  142. }
  143. static inline unsigned long pinconf_to_config_packed(enum pin_config_param param,
  144. u16 argument)
  145. {
  146. return PIN_CONF_PACKED(param, argument);
  147. }
  148. #ifdef CONFIG_OF
  149. #include <linux/device.h>
  150. #include <linux/pinctrl/machine.h>
  151. struct pinctrl_dev;
  152. struct pinctrl_map;
  153. struct pinconf_generic_params {
  154. const char * const property;
  155. enum pin_config_param param;
  156. u32 default_value;
  157. };
  158. int pinconf_generic_dt_subnode_to_map(struct pinctrl_dev *pctldev,
  159. struct device_node *np, struct pinctrl_map **map,
  160. unsigned *reserved_maps, unsigned *num_maps,
  161. enum pinctrl_map_type type);
  162. int pinconf_generic_dt_node_to_map(struct pinctrl_dev *pctldev,
  163. struct device_node *np_config, struct pinctrl_map **map,
  164. unsigned *num_maps, enum pinctrl_map_type type);
  165. void pinconf_generic_dt_free_map(struct pinctrl_dev *pctldev,
  166. struct pinctrl_map *map, unsigned num_maps);
  167. static inline int pinconf_generic_dt_node_to_map_group(
  168. struct pinctrl_dev *pctldev, struct device_node *np_config,
  169. struct pinctrl_map **map, unsigned *num_maps)
  170. {
  171. return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
  172. PIN_MAP_TYPE_CONFIGS_GROUP);
  173. }
  174. static inline int pinconf_generic_dt_node_to_map_pin(
  175. struct pinctrl_dev *pctldev, struct device_node *np_config,
  176. struct pinctrl_map **map, unsigned *num_maps)
  177. {
  178. return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
  179. PIN_MAP_TYPE_CONFIGS_PIN);
  180. }
  181. static inline int pinconf_generic_dt_node_to_map_all(
  182. struct pinctrl_dev *pctldev, struct device_node *np_config,
  183. struct pinctrl_map **map, unsigned *num_maps)
  184. {
  185. /*
  186. * passing the type as PIN_MAP_TYPE_INVALID causes the underlying parser
  187. * to infer the map type from the DT properties used.
  188. */
  189. return pinconf_generic_dt_node_to_map(pctldev, np_config, map, num_maps,
  190. PIN_MAP_TYPE_INVALID);
  191. }
  192. #endif
  193. #endif /* CONFIG_GENERIC_PINCONF */
  194. #endif /* __LINUX_PINCTRL_PINCONF_GENERIC_H */