core.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /*
  2. * Core private header for the pin control subsystem
  3. *
  4. * Copyright (C) 2011 ST-Ericsson SA
  5. * Written on behalf of Linaro for ST-Ericsson
  6. *
  7. * Author: Linus Walleij <linus.walleij@linaro.org>
  8. *
  9. * License terms: GNU General Public License (GPL) version 2
  10. */
  11. #include <linux/mutex.h>
  12. #include <linux/radix-tree.h>
  13. #include <linux/pinctrl/pinconf.h>
  14. #include <linux/pinctrl/machine.h>
  15. struct pinctrl_gpio_range;
  16. /**
  17. * struct pinctrl_dev - pin control class device
  18. * @node: node to include this pin controller in the global pin controller list
  19. * @desc: the pin controller descriptor supplied when initializing this pin
  20. * controller
  21. * @pin_desc_tree: each pin descriptor for this pin controller is stored in
  22. * this radix tree
  23. * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
  24. * ranges are added to this list at runtime
  25. * @dev: the device entry for this pin controller
  26. * @owner: module providing the pin controller, used for refcounting
  27. * @driver_data: driver data for drivers registering to the pin controller
  28. * subsystem
  29. * @p: result of pinctrl_get() for this device
  30. * @device_root: debugfs root for this device
  31. */
  32. struct pinctrl_dev {
  33. struct list_head node;
  34. struct pinctrl_desc *desc;
  35. struct radix_tree_root pin_desc_tree;
  36. struct list_head gpio_ranges;
  37. struct device *dev;
  38. struct module *owner;
  39. void *driver_data;
  40. struct pinctrl *p;
  41. #ifdef CONFIG_DEBUG_FS
  42. struct dentry *device_root;
  43. #endif
  44. };
  45. /**
  46. * struct pinctrl - per-device pin control state holder
  47. * @node: global list node
  48. * @dev: the device using this pin control handle
  49. * @states: a list of states for this device
  50. * @state: the current state
  51. */
  52. struct pinctrl {
  53. struct list_head node;
  54. struct device *dev;
  55. struct list_head states;
  56. struct pinctrl_state *state;
  57. };
  58. /**
  59. * struct pinctrl_state - a pinctrl state for a device
  60. * @node: list not for struct pinctrl's @states field
  61. * @name: the name of this state
  62. * @settings: a list of settings for this state
  63. */
  64. struct pinctrl_state {
  65. struct list_head node;
  66. const char *name;
  67. struct list_head settings;
  68. };
  69. /**
  70. * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP
  71. * @group: the group selector to program
  72. * @func: the function selector to program
  73. */
  74. struct pinctrl_setting_mux {
  75. unsigned group;
  76. unsigned func;
  77. };
  78. /**
  79. * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_*
  80. * @group_or_pin: the group selector or pin ID to program
  81. * @configs: a pointer to an array of config parameters/values to program into
  82. * hardware. Each individual pin controller defines the format and meaning
  83. * of config parameters.
  84. * @num_configs: the number of entries in array @configs
  85. */
  86. struct pinctrl_setting_configs {
  87. unsigned group_or_pin;
  88. unsigned long *configs;
  89. unsigned num_configs;
  90. };
  91. /**
  92. * struct pinctrl_setting - an individual mux or config setting
  93. * @node: list node for struct pinctrl_settings's @settings field
  94. * @type: the type of setting
  95. * @pctldev: pin control device handling to be programmed
  96. * @data: Data specific to the setting type
  97. */
  98. struct pinctrl_setting {
  99. struct list_head node;
  100. enum pinctrl_map_type type;
  101. struct pinctrl_dev *pctldev;
  102. union {
  103. struct pinctrl_setting_mux mux;
  104. struct pinctrl_setting_configs configs;
  105. } data;
  106. };
  107. /**
  108. * struct pin_desc - pin descriptor for each physical pin in the arch
  109. * @pctldev: corresponding pin control device
  110. * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
  111. * datasheet or such
  112. * @dynamic_name: if the name of this pin was dynamically allocated
  113. * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL.
  114. * If non-zero, this pin is claimed by @owner. This field is an integer
  115. * rather than a boolean, since pinctrl_get() might process multiple
  116. * mapping table entries that refer to, and hence claim, the same group
  117. * or pin, and each of these will increment the @usecount.
  118. * @mux_owner: The name of device that called pinctrl_get().
  119. * @mux_setting: The most recent selected mux setting for this pin, if any.
  120. * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is
  121. * the name of the GPIO that "owns" this pin.
  122. */
  123. struct pin_desc {
  124. struct pinctrl_dev *pctldev;
  125. const char *name;
  126. bool dynamic_name;
  127. /* These fields only added when supporting pinmux drivers */
  128. #ifdef CONFIG_PINMUX
  129. unsigned mux_usecount;
  130. const char *mux_owner;
  131. const struct pinctrl_setting_mux *mux_setting;
  132. const char *gpio_owner;
  133. #endif
  134. };
  135. struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
  136. int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
  137. int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  138. const char *pin_group);
  139. static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
  140. unsigned int pin)
  141. {
  142. return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
  143. }
  144. extern struct mutex pinctrl_mutex;