core.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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. * @dt_maps: the mapping table chunks dynamically parsed from device tree for
  52. * this device, if any
  53. */
  54. struct pinctrl {
  55. struct list_head node;
  56. struct device *dev;
  57. struct list_head states;
  58. struct pinctrl_state *state;
  59. struct list_head dt_maps;
  60. };
  61. /**
  62. * struct pinctrl_state - a pinctrl state for a device
  63. * @node: list not for struct pinctrl's @states field
  64. * @name: the name of this state
  65. * @settings: a list of settings for this state
  66. */
  67. struct pinctrl_state {
  68. struct list_head node;
  69. const char *name;
  70. struct list_head settings;
  71. };
  72. /**
  73. * struct pinctrl_setting_mux - setting data for MAP_TYPE_MUX_GROUP
  74. * @group: the group selector to program
  75. * @func: the function selector to program
  76. */
  77. struct pinctrl_setting_mux {
  78. unsigned group;
  79. unsigned func;
  80. };
  81. /**
  82. * struct pinctrl_setting_configs - setting data for MAP_TYPE_CONFIGS_*
  83. * @group_or_pin: the group selector or pin ID to program
  84. * @configs: a pointer to an array of config parameters/values to program into
  85. * hardware. Each individual pin controller defines the format and meaning
  86. * of config parameters.
  87. * @num_configs: the number of entries in array @configs
  88. */
  89. struct pinctrl_setting_configs {
  90. unsigned group_or_pin;
  91. unsigned long *configs;
  92. unsigned num_configs;
  93. };
  94. /**
  95. * struct pinctrl_setting - an individual mux or config setting
  96. * @node: list node for struct pinctrl_settings's @settings field
  97. * @type: the type of setting
  98. * @pctldev: pin control device handling to be programmed. Not used for
  99. * PIN_MAP_TYPE_DUMMY_STATE.
  100. * @dev_name: the name of the device using this state
  101. * @data: Data specific to the setting type
  102. */
  103. struct pinctrl_setting {
  104. struct list_head node;
  105. enum pinctrl_map_type type;
  106. struct pinctrl_dev *pctldev;
  107. const char *dev_name;
  108. union {
  109. struct pinctrl_setting_mux mux;
  110. struct pinctrl_setting_configs configs;
  111. } data;
  112. };
  113. /**
  114. * struct pin_desc - pin descriptor for each physical pin in the arch
  115. * @pctldev: corresponding pin control device
  116. * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
  117. * datasheet or such
  118. * @dynamic_name: if the name of this pin was dynamically allocated
  119. * @mux_usecount: If zero, the pin is not claimed, and @owner should be NULL.
  120. * If non-zero, this pin is claimed by @owner. This field is an integer
  121. * rather than a boolean, since pinctrl_get() might process multiple
  122. * mapping table entries that refer to, and hence claim, the same group
  123. * or pin, and each of these will increment the @usecount.
  124. * @mux_owner: The name of device that called pinctrl_get().
  125. * @mux_setting: The most recent selected mux setting for this pin, if any.
  126. * @gpio_owner: If pinctrl_request_gpio() was called for this pin, this is
  127. * the name of the GPIO that "owns" this pin.
  128. */
  129. struct pin_desc {
  130. struct pinctrl_dev *pctldev;
  131. const char *name;
  132. bool dynamic_name;
  133. /* These fields only added when supporting pinmux drivers */
  134. #ifdef CONFIG_PINMUX
  135. unsigned mux_usecount;
  136. const char *mux_owner;
  137. const struct pinctrl_setting_mux *mux_setting;
  138. const char *gpio_owner;
  139. #endif
  140. };
  141. struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
  142. int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
  143. const char *pin_get_name(struct pinctrl_dev *pctldev, const unsigned pin);
  144. int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  145. const char *pin_group);
  146. static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
  147. unsigned int pin)
  148. {
  149. return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
  150. }
  151. int pinctrl_register_map(struct pinctrl_map const *maps, unsigned num_maps,
  152. bool dup, bool locked);
  153. void pinctrl_unregister_map(struct pinctrl_map const *map);
  154. extern struct mutex pinctrl_mutex;
  155. extern struct list_head pinctrldev_list;