pinctrl.h 6.7 KB

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