pinctrl.h 5.8 KB

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