pinctrl.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Interface 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_PINCTRL_H
  12. #define __LINUX_PINCTRL_PINCTRL_H
  13. #include <linux/radix-tree.h>
  14. #include <linux/list.h>
  15. #include <linux/seq_file.h>
  16. #include <linux/pinctrl/pinctrl-state.h>
  17. #include <linux/pinctrl/devinfo.h>
  18. struct device;
  19. struct pinctrl_dev;
  20. struct pinctrl_map;
  21. struct pinmux_ops;
  22. struct pinconf_ops;
  23. struct pin_config_item;
  24. struct gpio_chip;
  25. struct device_node;
  26. /**
  27. * struct pingroup - provides information on pingroup
  28. * @name: a name for pingroup
  29. * @pins: an array of pins in the pingroup
  30. * @npins: number of pins in the pingroup
  31. */
  32. struct pingroup {
  33. const char *name;
  34. const unsigned int *pins;
  35. size_t npins;
  36. };
  37. /* Convenience macro to define a single named or anonymous pingroup */
  38. #define PINCTRL_PINGROUP(_name, _pins, _npins) \
  39. (struct pingroup){ \
  40. .name = _name, \
  41. .pins = _pins, \
  42. .npins = _npins, \
  43. }
  44. /**
  45. * struct pinctrl_pin_desc - boards/machines provide information on their
  46. * pins, pads or other muxable units in this struct
  47. * @number: unique pin number from the global pin number space
  48. * @name: a name for this pin
  49. * @drv_data: driver-defined per-pin data. pinctrl core does not touch this
  50. */
  51. struct pinctrl_pin_desc {
  52. unsigned number;
  53. const char *name;
  54. void *drv_data;
  55. };
  56. /* Convenience macro to define a single named or anonymous pin descriptor */
  57. #define PINCTRL_PIN(a, b) { .number = a, .name = b }
  58. #define PINCTRL_PIN_ANON(a) { .number = a }
  59. /**
  60. * struct pinctrl_gpio_range - each pin controller can provide subranges of
  61. * the GPIO number space to be handled by the controller
  62. * @node: list node for internal use
  63. * @name: a name for the chip in this range
  64. * @id: an ID number for the chip in this range
  65. * @base: base offset of the GPIO range
  66. * @pin_base: base pin number of the GPIO range if pins == NULL
  67. * @npins: number of pins in the GPIO range, including the base number
  68. * @pins: enumeration of pins in GPIO range or NULL
  69. * @gc: an optional pointer to a gpio_chip
  70. */
  71. struct pinctrl_gpio_range {
  72. struct list_head node;
  73. const char *name;
  74. unsigned int id;
  75. unsigned int base;
  76. unsigned int pin_base;
  77. unsigned int npins;
  78. unsigned const *pins;
  79. struct gpio_chip *gc;
  80. };
  81. /**
  82. * struct pinctrl_ops - global pin control operations, to be implemented by
  83. * pin controller drivers.
  84. * @get_groups_count: Returns the count of total number of groups registered.
  85. * @get_group_name: return the group name of the pin group
  86. * @get_group_pins: return an array of pins corresponding to a certain
  87. * group selector @pins, and the size of the array in @num_pins
  88. * @pin_dbg_show: optional debugfs display hook that will provide per-device
  89. * info for a certain pin in debugfs
  90. * @dt_node_to_map: parse a device tree "pin configuration node", and create
  91. * mapping table entries for it. These are returned through the @map and
  92. * @num_maps output parameters. This function is optional, and may be
  93. * omitted for pinctrl drivers that do not support device tree.
  94. * @dt_free_map: free mapping table entries created via @dt_node_to_map. The
  95. * top-level @map pointer must be freed, along with any dynamically
  96. * allocated members of the mapping table entries themselves. This
  97. * function is optional, and may be omitted for pinctrl drivers that do
  98. * not support device tree.
  99. */
  100. struct pinctrl_ops {
  101. int (*get_groups_count) (struct pinctrl_dev *pctldev);
  102. const char *(*get_group_name) (struct pinctrl_dev *pctldev,
  103. unsigned selector);
  104. int (*get_group_pins) (struct pinctrl_dev *pctldev,
  105. unsigned selector,
  106. const unsigned **pins,
  107. unsigned *num_pins);
  108. void (*pin_dbg_show) (struct pinctrl_dev *pctldev, struct seq_file *s,
  109. unsigned offset);
  110. int (*dt_node_to_map) (struct pinctrl_dev *pctldev,
  111. struct device_node *np_config,
  112. struct pinctrl_map **map, unsigned *num_maps);
  113. void (*dt_free_map) (struct pinctrl_dev *pctldev,
  114. struct pinctrl_map *map, unsigned num_maps);
  115. };
  116. /**
  117. * struct pinctrl_desc - pin controller descriptor, register this to pin
  118. * control subsystem
  119. * @name: name for the pin controller
  120. * @pins: an array of pin descriptors describing all the pins handled by
  121. * this pin controller
  122. * @npins: number of descriptors in the array, usually just ARRAY_SIZE()
  123. * of the pins field above
  124. * @pctlops: pin control operation vtable, to support global concepts like
  125. * grouping of pins, this is optional.
  126. * @pmxops: pinmux operations vtable, if you support pinmuxing in your driver
  127. * @confops: pin config operations vtable, if you support pin configuration in
  128. * your driver
  129. * @owner: module providing the pin controller, used for refcounting
  130. * @num_custom_params: Number of driver-specific custom parameters to be parsed
  131. * from the hardware description
  132. * @custom_params: List of driver_specific custom parameters to be parsed from
  133. * the hardware description
  134. * @custom_conf_items: Information how to print @params in debugfs, must be
  135. * the same size as the @custom_params, i.e. @num_custom_params
  136. * @link_consumers: If true create a device link between pinctrl and its
  137. * consumers (i.e. the devices requesting pin control states). This is
  138. * sometimes necessary to ascertain the right suspend/resume order for
  139. * example.
  140. */
  141. struct pinctrl_desc {
  142. const char *name;
  143. const struct pinctrl_pin_desc *pins;
  144. unsigned int npins;
  145. const struct pinctrl_ops *pctlops;
  146. const struct pinmux_ops *pmxops;
  147. const struct pinconf_ops *confops;
  148. struct module *owner;
  149. #ifdef CONFIG_GENERIC_PINCONF
  150. unsigned int num_custom_params;
  151. const struct pinconf_generic_params *custom_params;
  152. const struct pin_config_item *custom_conf_items;
  153. #endif
  154. bool link_consumers;
  155. };
  156. /* External interface to pin controller */
  157. extern int pinctrl_register_and_init(struct pinctrl_desc *pctldesc,
  158. struct device *dev, void *driver_data,
  159. struct pinctrl_dev **pctldev);
  160. extern int pinctrl_enable(struct pinctrl_dev *pctldev);
  161. /* Please use pinctrl_register_and_init() and pinctrl_enable() instead */
  162. extern struct pinctrl_dev *pinctrl_register(struct pinctrl_desc *pctldesc,
  163. struct device *dev, void *driver_data);
  164. extern void pinctrl_unregister(struct pinctrl_dev *pctldev);
  165. extern int devm_pinctrl_register_and_init(struct device *dev,
  166. struct pinctrl_desc *pctldesc,
  167. void *driver_data,
  168. struct pinctrl_dev **pctldev);
  169. /* Please use devm_pinctrl_register_and_init() instead */
  170. extern struct pinctrl_dev *devm_pinctrl_register(struct device *dev,
  171. struct pinctrl_desc *pctldesc,
  172. void *driver_data);
  173. extern void devm_pinctrl_unregister(struct device *dev,
  174. struct pinctrl_dev *pctldev);
  175. extern void pinctrl_add_gpio_range(struct pinctrl_dev *pctldev,
  176. struct pinctrl_gpio_range *range);
  177. extern void pinctrl_add_gpio_ranges(struct pinctrl_dev *pctldev,
  178. struct pinctrl_gpio_range *ranges,
  179. unsigned nranges);
  180. extern void pinctrl_remove_gpio_range(struct pinctrl_dev *pctldev,
  181. struct pinctrl_gpio_range *range);
  182. extern struct pinctrl_dev *pinctrl_find_and_add_gpio_range(const char *devname,
  183. struct pinctrl_gpio_range *range);
  184. extern struct pinctrl_gpio_range *
  185. pinctrl_find_gpio_range_from_pin(struct pinctrl_dev *pctldev,
  186. unsigned int pin);
  187. extern int pinctrl_get_group_pins(struct pinctrl_dev *pctldev,
  188. const char *pin_group, const unsigned **pins,
  189. unsigned *num_pins);
  190. #if IS_ENABLED(CONFIG_OF) && IS_ENABLED(CONFIG_PINCTRL)
  191. extern struct pinctrl_dev *of_pinctrl_get(struct device_node *np);
  192. #else
  193. static inline
  194. struct pinctrl_dev *of_pinctrl_get(struct device_node *np)
  195. {
  196. return NULL;
  197. }
  198. #endif /* CONFIG_OF */
  199. extern const char *pinctrl_dev_get_name(struct pinctrl_dev *pctldev);
  200. extern const char *pinctrl_dev_get_devname(struct pinctrl_dev *pctldev);
  201. extern void *pinctrl_dev_get_drvdata(struct pinctrl_dev *pctldev);
  202. #endif /* __LINUX_PINCTRL_PINCTRL_H */