core.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. * @state: the state name passed to pinctrl_get()
  49. * @usecount: the number of active users of this pin controller setting, used
  50. * to keep track of nested use cases
  51. * @settings: a list of settings for this device/state
  52. */
  53. struct pinctrl {
  54. struct list_head node;
  55. struct device *dev;
  56. const char *state;
  57. unsigned usecount;
  58. struct list_head settings;
  59. };
  60. /**
  61. * struct pinctrl_setting - an individual mux setting
  62. * @node: list node for struct pinctrl's @settings field
  63. * @pctldev: pin control device handling to be programmed
  64. * @group_selector: the group selector to program
  65. * @func_selector: the function selector to program
  66. */
  67. struct pinctrl_setting {
  68. struct list_head node;
  69. struct pinctrl_dev *pctldev;
  70. unsigned group_selector;
  71. unsigned func_selector;
  72. };
  73. /**
  74. * struct pin_desc - pin descriptor for each physical pin in the arch
  75. * @pctldev: corresponding pin control device
  76. * @name: a name for the pin, e.g. the name of the pin/pad/finger on a
  77. * datasheet or such
  78. * @dynamic_name: if the name of this pin was dynamically allocated
  79. * @usecount: If zero, the pin is not claimed, and @owner should be NULL.
  80. * If non-zero, this pin is claimed by @owner. This field is an integer
  81. * rather than a boolean, since pinctrl_get() might process multiple
  82. * mapping table entries that refer to, and hence claim, the same group
  83. * or pin, and each of these will increment the @usecount.
  84. * @owner: The name of the entity owning the pin. Typically, this is the name
  85. * of the device that called pinctrl_get(). Alternatively, it may be the
  86. * name of the GPIO passed to pinctrl_request_gpio().
  87. */
  88. struct pin_desc {
  89. struct pinctrl_dev *pctldev;
  90. const char *name;
  91. bool dynamic_name;
  92. /* These fields only added when supporting pinmux drivers */
  93. #ifdef CONFIG_PINMUX
  94. unsigned usecount;
  95. const char *owner;
  96. #endif
  97. };
  98. struct pinctrl_dev *get_pinctrl_dev_from_devname(const char *dev_name);
  99. int pin_get_from_name(struct pinctrl_dev *pctldev, const char *name);
  100. int pinctrl_get_group_selector(struct pinctrl_dev *pctldev,
  101. const char *pin_group);
  102. static inline struct pin_desc *pin_desc_get(struct pinctrl_dev *pctldev,
  103. unsigned int pin)
  104. {
  105. return radix_tree_lookup(&pctldev->pin_desc_tree, pin);
  106. }
  107. extern struct mutex pinctrl_mutex;