pinctrl-intel.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Core pinctrl/GPIO driver for Intel GPIO controllers
  4. *
  5. * Copyright (C) 2015, Intel Corporation
  6. * Authors: Mathias Nyman <mathias.nyman@linux.intel.com>
  7. * Mika Westerberg <mika.westerberg@linux.intel.com>
  8. */
  9. #ifndef PINCTRL_INTEL_H
  10. #define PINCTRL_INTEL_H
  11. #include <linux/array_size.h>
  12. #include <linux/bits.h>
  13. #include <linux/compiler_types.h>
  14. #include <linux/gpio/driver.h>
  15. #include <linux/irq.h>
  16. #include <linux/pm.h>
  17. #include <linux/pinctrl/pinctrl.h>
  18. #include <linux/spinlock_types.h>
  19. struct platform_device;
  20. struct device;
  21. /**
  22. * struct intel_pingroup - Description about group of pins
  23. * @grp: Generic data of the pin group (name and pins)
  24. * @mode: Native mode in which the group is muxed out @pins. Used if @modes is %NULL.
  25. * @modes: If not %NULL this will hold mode for each pin in @pins
  26. */
  27. struct intel_pingroup {
  28. struct pingroup grp;
  29. unsigned short mode;
  30. const unsigned int *modes;
  31. };
  32. /**
  33. * struct intel_function - Description about a function
  34. * @func: Generic data of the pin function (name and groups of pins)
  35. */
  36. struct intel_function {
  37. struct pinfunction func;
  38. };
  39. #define INTEL_PINCTRL_MAX_GPP_SIZE 32
  40. /**
  41. * struct intel_padgroup - Hardware pad group information
  42. * @reg_num: GPI_IS register number
  43. * @base: Starting pin of this group
  44. * @size: Size of this group (maximum is %INTEL_PINCTRL_MAX_GPP_SIZE).
  45. * @gpio_base: Starting GPIO base of this group
  46. * @padown_num: PAD_OWN register number (assigned by the core driver)
  47. *
  48. * If pad groups of a community are not the same size, use this structure
  49. * to specify them.
  50. */
  51. struct intel_padgroup {
  52. unsigned int reg_num;
  53. unsigned int base;
  54. unsigned int size;
  55. int gpio_base;
  56. unsigned int padown_num;
  57. };
  58. /**
  59. * enum - Special treatment for GPIO base in pad group
  60. *
  61. * @INTEL_GPIO_BASE_ZERO: force GPIO base to be 0
  62. * @INTEL_GPIO_BASE_NOMAP: no GPIO mapping should be created
  63. * @INTEL_GPIO_BASE_MATCH: matches with starting pin number
  64. */
  65. enum {
  66. INTEL_GPIO_BASE_ZERO = -2,
  67. INTEL_GPIO_BASE_NOMAP = -1,
  68. INTEL_GPIO_BASE_MATCH = 0,
  69. };
  70. /**
  71. * struct intel_community - Intel pin community description
  72. * @barno: MMIO BAR number where registers for this community reside
  73. * @padown_offset: Register offset of PAD_OWN register from @regs. If %0
  74. * then there is no support for owner.
  75. * @padcfglock_offset: Register offset of PADCFGLOCK from @regs. If %0 then
  76. * locking is not supported.
  77. * @hostown_offset: Register offset of HOSTSW_OWN from @regs. If %0 then it
  78. * is assumed that the host owns the pin (rather than
  79. * ACPI).
  80. * @is_offset: Register offset of GPI_IS from @regs.
  81. * @ie_offset: Register offset of GPI_IE from @regs.
  82. * @features: Additional features supported by the hardware
  83. * @pin_base: Starting pin of pins in this community
  84. * @npins: Number of pins in this community
  85. * @gpp_size: Maximum number of pads in each group, such as PADCFGLOCK,
  86. * HOSTSW_OWN, GPI_IS, GPI_IE. Used when @gpps is %NULL.
  87. * @gpp_num_padown_regs: Number of pad registers each pad group consumes at
  88. * minimum. Used when @gpps is %NULL.
  89. * @gpps: Pad groups if the controller has variable size pad groups
  90. * @ngpps: Number of pad groups in this community
  91. * @pad_map: Optional non-linear mapping of the pads
  92. * @nirqs: Optional total number of IRQs this community can generate
  93. * @acpi_space_id: Optional address space ID for ACPI OpRegion handler
  94. * @regs: Community specific common registers (reserved for core driver)
  95. * @pad_regs: Community specific pad registers (reserved for core driver)
  96. *
  97. * In older Intel GPIO host controllers, this driver supports, each pad group
  98. * is of equal size (except the last one). In that case the driver can just
  99. * fill in @gpp_size and @gpp_num_padown_regs fields and let the core driver
  100. * to handle the rest.
  101. *
  102. * In newer Intel GPIO host controllers each pad group is of variable size,
  103. * so the client driver can pass custom @gpps and @ngpps instead.
  104. */
  105. struct intel_community {
  106. unsigned int barno;
  107. unsigned int padown_offset;
  108. unsigned int padcfglock_offset;
  109. unsigned int hostown_offset;
  110. unsigned int is_offset;
  111. unsigned int ie_offset;
  112. unsigned int features;
  113. unsigned int pin_base;
  114. size_t npins;
  115. unsigned int gpp_size;
  116. unsigned int gpp_num_padown_regs;
  117. const struct intel_padgroup *gpps;
  118. size_t ngpps;
  119. const unsigned int *pad_map;
  120. unsigned short nirqs;
  121. unsigned short acpi_space_id;
  122. /* Reserved for the core driver */
  123. void __iomem *regs;
  124. void __iomem *pad_regs;
  125. };
  126. /* Additional features supported by the hardware */
  127. #define PINCTRL_FEATURE_DEBOUNCE BIT(0)
  128. #define PINCTRL_FEATURE_1K_PD BIT(1)
  129. #define PINCTRL_FEATURE_GPIO_HW_INFO BIT(2)
  130. #define PINCTRL_FEATURE_PWM BIT(3)
  131. #define PINCTRL_FEATURE_BLINK BIT(4)
  132. #define PINCTRL_FEATURE_EXP BIT(5)
  133. #define __INTEL_COMMUNITY(b, s, e, g, n, gs, gn, soc) \
  134. { \
  135. .barno = (b), \
  136. .padown_offset = soc ## _PAD_OWN, \
  137. .padcfglock_offset = soc ## _PADCFGLOCK, \
  138. .hostown_offset = soc ## _HOSTSW_OWN, \
  139. .is_offset = soc ## _GPI_IS, \
  140. .ie_offset = soc ## _GPI_IE, \
  141. .gpp_size = (gs), \
  142. .gpp_num_padown_regs = (gn), \
  143. .pin_base = (s), \
  144. .npins = ((e) - (s) + 1), \
  145. .gpps = (g), \
  146. .ngpps = (n), \
  147. }
  148. #define INTEL_COMMUNITY_GPPS(b, s, e, g, soc) \
  149. __INTEL_COMMUNITY(b, s, e, g, ARRAY_SIZE(g), 0, 0, soc)
  150. #define INTEL_COMMUNITY_SIZE(b, s, e, gs, gn, soc) \
  151. __INTEL_COMMUNITY(b, s, e, NULL, 0, gs, gn, soc)
  152. /**
  153. * PIN_GROUP - Declare a pin group
  154. * @n: Name of the group
  155. * @p: An array of pins this group consists
  156. * @m: Mode which the pins are put when this group is active. Can be either
  157. * a single integer or an array of integers in which case mode is per
  158. * pin.
  159. */
  160. #define PIN_GROUP(n, p, m) \
  161. { \
  162. .grp = PINCTRL_PINGROUP((n), (p), ARRAY_SIZE((p))), \
  163. .mode = __builtin_choose_expr(__builtin_constant_p((m)), (m), 0), \
  164. .modes = __builtin_choose_expr(__builtin_constant_p((m)), NULL, (m)), \
  165. }
  166. #define PIN_GROUP_GPIO(n, p, m) \
  167. PIN_GROUP(n, p, m), \
  168. PIN_GROUP(n "_gpio", p, 0)
  169. #define FUNCTION(n, g) \
  170. { \
  171. .func = PINCTRL_PINFUNCTION((n), (g), ARRAY_SIZE(g)), \
  172. }
  173. /**
  174. * struct intel_pinctrl_soc_data - Intel pin controller per-SoC configuration
  175. * @uid: ACPI _UID for the probe driver use if needed
  176. * @pins: Array if pins this pinctrl controls
  177. * @npins: Number of pins in the array
  178. * @groups: Array of pin groups
  179. * @ngroups: Number of groups in the array
  180. * @functions: Array of functions
  181. * @nfunctions: Number of functions in the array
  182. * @communities: Array of communities this pinctrl handles
  183. * @ncommunities: Number of communities in the array
  184. *
  185. * The @communities is used as a template by the core driver. It will make
  186. * copy of all communities and fill in rest of the information.
  187. */
  188. struct intel_pinctrl_soc_data {
  189. const char *uid;
  190. const struct pinctrl_pin_desc *pins;
  191. size_t npins;
  192. const struct intel_pingroup *groups;
  193. size_t ngroups;
  194. const struct intel_function *functions;
  195. size_t nfunctions;
  196. const struct intel_community *communities;
  197. size_t ncommunities;
  198. };
  199. const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev);
  200. struct intel_pad_context;
  201. struct intel_community_context;
  202. /**
  203. * struct intel_pinctrl_context - context to be saved during suspend-resume
  204. * @pads: Opaque context per pad (driver dependent)
  205. * @communities: Opaque context per community (driver dependent)
  206. */
  207. struct intel_pinctrl_context {
  208. struct intel_pad_context *pads;
  209. struct intel_community_context *communities;
  210. };
  211. /**
  212. * struct intel_pinctrl - Intel pinctrl private structure
  213. * @dev: Pointer to the device structure
  214. * @lock: Lock to serialize register access
  215. * @pctldesc: Pin controller description
  216. * @pctldev: Pointer to the pin controller device
  217. * @chip: GPIO chip in this pin controller
  218. * @soc: SoC/PCH specific pin configuration data
  219. * @communities: All communities in this pin controller
  220. * @ncommunities: Number of communities in this pin controller
  221. * @context: Configuration saved over system sleep
  222. * @irq: pinctrl/GPIO chip irq number
  223. */
  224. struct intel_pinctrl {
  225. struct device *dev;
  226. raw_spinlock_t lock;
  227. struct pinctrl_desc pctldesc;
  228. struct pinctrl_dev *pctldev;
  229. struct gpio_chip chip;
  230. const struct intel_pinctrl_soc_data *soc;
  231. struct intel_community *communities;
  232. size_t ncommunities;
  233. struct intel_pinctrl_context context;
  234. int irq;
  235. };
  236. int intel_pinctrl_probe(struct platform_device *pdev,
  237. const struct intel_pinctrl_soc_data *soc_data);
  238. int intel_pinctrl_probe_by_hid(struct platform_device *pdev);
  239. int intel_pinctrl_probe_by_uid(struct platform_device *pdev);
  240. extern const struct dev_pm_ops intel_pinctrl_pm_ops;
  241. const struct intel_community *intel_get_community(const struct intel_pinctrl *pctrl,
  242. unsigned int pin);
  243. int intel_get_groups_count(struct pinctrl_dev *pctldev);
  244. const char *intel_get_group_name(struct pinctrl_dev *pctldev, unsigned int group);
  245. int intel_get_group_pins(struct pinctrl_dev *pctldev, unsigned int group,
  246. const unsigned int **pins, unsigned int *npins);
  247. int intel_get_functions_count(struct pinctrl_dev *pctldev);
  248. const char *intel_get_function_name(struct pinctrl_dev *pctldev, unsigned int function);
  249. int intel_get_function_groups(struct pinctrl_dev *pctldev, unsigned int function,
  250. const char * const **groups, unsigned int * const ngroups);
  251. #endif /* PINCTRL_INTEL_H */