core.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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. struct pinctrl_gpio_range;
  15. /**
  16. * struct pinctrl_dev - pin control class device
  17. * @node: node to include this pin controller in the global pin controller list
  18. * @desc: the pin controller descriptor supplied when initializing this pin
  19. * controller
  20. * @pin_desc_tree: each pin descriptor for this pin controller is stored in
  21. * this radix tree
  22. * @gpio_ranges: a list of GPIO ranges that is handled by this pin controller,
  23. * ranges are added to this list at runtime
  24. * @dev: the device entry for this pin controller
  25. * @owner: module providing the pin controller, used for refcounting
  26. * @driver_data: driver data for drivers registering to the pin controller
  27. * subsystem
  28. * @p: result of pinctrl_get() for this device
  29. * @device_root: debugfs root for this device
  30. */
  31. struct pinctrl_dev {
  32. struct list_head node;
  33. struct pinctrl_desc *desc;
  34. struct radix_tree_root pin_desc_tree;
  35. struct list_head gpio_ranges;
  36. struct device *dev;
  37. struct module *owner;
  38. void *driver_data;
  39. struct pinctrl *p;
  40. #ifdef CONFIG_DEBUG_FS
  41. struct dentry *device_root;
  42. #endif
  43. };
  44. /**
  45. * struct pinctrl - per-device pin control state holder
  46. * @node: global list node
  47. * @dev: the device using this pin control handle
  48. * @states: a list of states for this device
  49. * @state: the current state
  50. */
  51. struct pinctrl {
  52. struct list_head node;
  53. struct device *dev;
  54. struct list_head states;
  55. struct pinctrl_state *state;
  56. };
  57. /**
  58. * struct pinctrl_state - a pinctrl state for a device
  59. * @node: list not for struct pinctrl's @states field
  60. * @name: the name of this state
  61. * @settings: a list of settings for this state
  62. */
  63. struct pinctrl_state {
  64. struct list_head node;
  65. const char *name;
  66. struct list_head settings;
  67. };
  68. /**
  69. * struct pinctrl_setting - an individual mux setting
  70. * @node: list node for struct pinctrl_settings's @settings field
  71. * @pctldev: pin control device handling to be programmed
  72. * @group_selector: the group selector to program
  73. * @func_selector: the function selector to program
  74. */
  75. struct pinctrl_setting {
  76. struct list_head node;
  77. struct pinctrl_dev *pctldev;
  78. unsigned group_selector;
  79. unsigned func_selector;
  80. };
  81. /**
  82. * struct pin_desc - pin descriptor for each physical pin in the arch
  83. * @pctldev: corresponding pin control device
  84. * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
  85. * datasheet or such
  86. * @dynamic_name: if the name of this pin was dynamically allocated
  87. * @usecount: If zero, the pin is not claimed, and @owner should be NULL.
  88. * If non-zero, this pin is claimed by @owner. This field is an integer
  89. * rather than a boolean, since pinctrl_get() might process multiple
  90. * mapping table entries that refer to, and hence claim, the same group
  91. * or pin, and each of these will increment the @usecount.
  92. * @owner: The name of the entity owning the pin. Typically, this is the name
  93. * of the device that called pinctrl_get(). Alternatively, it may be the
  94. * name of the GPIO passed to pinctrl_request_gpio().
  95. */
  96. struct pin_desc {
  97. struct pinctrl_dev *pctldev;
  98. const char *name;
  99. bool dynamic_name;
  100. /* These fields only added when supporting pinmux drivers */
  101. #ifdef CONFIG_PINMUX
  102. unsigned usecount;
  103. const char *owner;
  104. #endif
  105. };
  106. struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
  107. int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
  108. int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  109. const char *pin_group);
  110. static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
  111. unsigned int pin)
  112. {
  113. return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
  114. }
  115. extern struct mutex pinctrl_mutex;