pinctrl-intel.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 <[email protected]>
  7. * Mika Westerberg <[email protected]>
  8. */
  9. #ifndef PINCTRL_INTEL_H
  10. #define PINCTRL_INTEL_H
  11. #include <linux/bits.h>
  12. #include <linux/compiler_types.h>
  13. #include <linux/gpio/driver.h>
  14. #include <linux/irq.h>
  15. #include <linux/kernel.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. * @name: Name of the function
  35. * @groups: An array of groups for this function
  36. * @ngroups: Number of groups in @groups
  37. */
  38. struct intel_function {
  39. const char *name;
  40. const char * const *groups;
  41. size_t ngroups;
  42. };
  43. /**
  44. * struct intel_padgroup - Hardware pad group information
  45. * @reg_num: GPI_IS register number
  46. * @base: Starting pin of this group
  47. * @size: Size of this group (maximum is 32).
  48. * @gpio_base: Starting GPIO base of this group
  49. * @padown_num: PAD_OWN register number (assigned by the core driver)
  50. *
  51. * If pad groups of a community are not the same size, use this structure
  52. * to specify them.
  53. */
  54. struct intel_padgroup {
  55. unsigned int reg_num;
  56. unsigned int base;
  57. unsigned int size;
  58. int gpio_base;
  59. unsigned int padown_num;
  60. };
  61. /**
  62. * enum - Special treatment for GPIO base in pad group
  63. *
  64. * @INTEL_GPIO_BASE_ZERO: force GPIO base to be 0
  65. * @INTEL_GPIO_BASE_NOMAP: no GPIO mapping should be created
  66. * @INTEL_GPIO_BASE_MATCH: matches with starting pin number
  67. */
  68. enum {
  69. INTEL_GPIO_BASE_ZERO = -2,
  70. INTEL_GPIO_BASE_NOMAP = -1,
  71. INTEL_GPIO_BASE_MATCH = 0,
  72. };
  73. /**
  74. * struct intel_community - Intel pin community description
  75. * @barno: MMIO BAR number where registers for this community reside
  76. * @padown_offset: Register offset of PAD_OWN register from @regs. If %0
  77. * then there is no support for owner.
  78. * @padcfglock_offset: Register offset of PADCFGLOCK from @regs. If %0 then
  79. * locking is not supported.
  80. * @hostown_offset: Register offset of HOSTSW_OWN from @regs. If %0 then it
  81. * is assumed that the host owns the pin (rather than
  82. * ACPI).
  83. * @is_offset: Register offset of GPI_IS from @regs.
  84. * @ie_offset: Register offset of GPI_IE from @regs.
  85. * @features: Additional features supported by the hardware
  86. * @pin_base: Starting pin of pins in this community
  87. * @npins: Number of pins in this community
  88. * @gpp_size: Maximum number of pads in each group, such as PADCFGLOCK,
  89. * HOSTSW_OWN, GPI_IS, GPI_IE. Used when @gpps is %NULL.
  90. * @gpp_num_padown_regs: Number of pad registers each pad group consumes at
  91. * minimum. Use %0 if the number of registers can be
  92. * determined by the size of the group.
  93. * @gpps: Pad groups if the controller has variable size pad groups
  94. * @ngpps: Number of pad groups in this community
  95. * @pad_map: Optional non-linear mapping of the pads
  96. * @nirqs: Optional total number of IRQs this community can generate
  97. * @acpi_space_id: Optional address space ID for ACPI OpRegion handler
  98. * @regs: Community specific common registers (reserved for core driver)
  99. * @pad_regs: Community specific pad registers (reserved for core driver)
  100. *
  101. * In some of Intel GPIO host controllers this driver supports each pad group
  102. * is of equal size (except the last one). In that case the driver can just
  103. * fill in @gpp_size field and let the core driver to handle the rest. If
  104. * the controller has pad groups of variable size the client driver can
  105. * pass custom @gpps and @ngpps instead.
  106. */
  107. struct intel_community {
  108. unsigned int barno;
  109. unsigned int padown_offset;
  110. unsigned int padcfglock_offset;
  111. unsigned int hostown_offset;
  112. unsigned int is_offset;
  113. unsigned int ie_offset;
  114. unsigned int features;
  115. unsigned int pin_base;
  116. size_t npins;
  117. unsigned int gpp_size;
  118. unsigned int gpp_num_padown_regs;
  119. const struct intel_padgroup *gpps;
  120. size_t ngpps;
  121. const unsigned int *pad_map;
  122. unsigned short nirqs;
  123. unsigned short acpi_space_id;
  124. /* Reserved for the core driver */
  125. void __iomem *regs;
  126. void __iomem *pad_regs;
  127. };
  128. /* Additional features supported by the hardware */
  129. #define PINCTRL_FEATURE_DEBOUNCE BIT(0)
  130. #define PINCTRL_FEATURE_1K_PD BIT(1)
  131. #define PINCTRL_FEATURE_GPIO_HW_INFO BIT(2)
  132. #define PINCTRL_FEATURE_PWM BIT(3)
  133. #define PINCTRL_FEATURE_BLINK BIT(4)
  134. #define PINCTRL_FEATURE_EXP BIT(5)
  135. /**
  136. * PIN_GROUP - Declare a pin group
  137. * @n: Name of the group
  138. * @p: An array of pins this group consists
  139. * @m: Mode which the pins are put when this group is active. Can be either
  140. * a single integer or an array of integers in which case mode is per
  141. * pin.
  142. */
  143. #define PIN_GROUP(n, p, m) \
  144. { \
  145. .grp = PINCTRL_PINGROUP((n), (p), ARRAY_SIZE((p))), \
  146. .mode = __builtin_choose_expr(__builtin_constant_p((m)), (m), 0), \
  147. .modes = __builtin_choose_expr(__builtin_constant_p((m)), NULL, (m)), \
  148. }
  149. #define FUNCTION(n, g) \
  150. { \
  151. .name = (n), \
  152. .groups = (g), \
  153. .ngroups = ARRAY_SIZE((g)), \
  154. }
  155. /**
  156. * struct intel_pinctrl_soc_data - Intel pin controller per-SoC configuration
  157. * @uid: ACPI _UID for the probe driver use if needed
  158. * @pins: Array if pins this pinctrl controls
  159. * @npins: Number of pins in the array
  160. * @groups: Array of pin groups
  161. * @ngroups: Number of groups in the array
  162. * @functions: Array of functions
  163. * @nfunctions: Number of functions in the array
  164. * @communities: Array of communities this pinctrl handles
  165. * @ncommunities: Number of communities in the array
  166. *
  167. * The @communities is used as a template by the core driver. It will make
  168. * copy of all communities and fill in rest of the information.
  169. */
  170. struct intel_pinctrl_soc_data {
  171. const char *uid;
  172. const struct pinctrl_pin_desc *pins;
  173. size_t npins;
  174. const struct intel_pingroup *groups;
  175. size_t ngroups;
  176. const struct intel_function *functions;
  177. size_t nfunctions;
  178. const struct intel_community *communities;
  179. size_t ncommunities;
  180. };
  181. const struct intel_pinctrl_soc_data *intel_pinctrl_get_soc_data(struct platform_device *pdev);
  182. struct intel_pad_context;
  183. struct intel_community_context;
  184. /**
  185. * struct intel_pinctrl_context - context to be saved during suspend-resume
  186. * @pads: Opaque context per pad (driver dependent)
  187. * @communities: Opaque context per community (driver dependent)
  188. */
  189. struct intel_pinctrl_context {
  190. struct intel_pad_context *pads;
  191. struct intel_community_context *communities;
  192. };
  193. /**
  194. * struct intel_pinctrl - Intel pinctrl private structure
  195. * @dev: Pointer to the device structure
  196. * @lock: Lock to serialize register access
  197. * @pctldesc: Pin controller description
  198. * @pctldev: Pointer to the pin controller device
  199. * @chip: GPIO chip in this pin controller
  200. * @soc: SoC/PCH specific pin configuration data
  201. * @communities: All communities in this pin controller
  202. * @ncommunities: Number of communities in this pin controller
  203. * @context: Configuration saved over system sleep
  204. * @irq: pinctrl/GPIO chip irq number
  205. */
  206. struct intel_pinctrl {
  207. struct device *dev;
  208. raw_spinlock_t lock;
  209. struct pinctrl_desc pctldesc;
  210. struct pinctrl_dev *pctldev;
  211. struct gpio_chip chip;
  212. const struct intel_pinctrl_soc_data *soc;
  213. struct intel_community *communities;
  214. size_t ncommunities;
  215. struct intel_pinctrl_context context;
  216. int irq;
  217. };
  218. int intel_pinctrl_probe_by_hid(struct platform_device *pdev);
  219. int intel_pinctrl_probe_by_uid(struct platform_device *pdev);
  220. #ifdef CONFIG_PM_SLEEP
  221. int intel_pinctrl_suspend_noirq(struct device *dev);
  222. int intel_pinctrl_resume_noirq(struct device *dev);
  223. #endif
  224. #define INTEL_PINCTRL_PM_OPS(_name) \
  225. const struct dev_pm_ops _name = { \
  226. SET_NOIRQ_SYSTEM_SLEEP_PM_OPS(intel_pinctrl_suspend_noirq, \
  227. intel_pinctrl_resume_noirq) \
  228. }
  229. #endif /* PINCTRL_INTEL_H */