pinctrl.h 6.2 KB

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