irq.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * IRQ is a type of interrupt controller used on recent Intel SoC.
  4. *
  5. * Copyright 2019 Google LLC
  6. */
  7. #ifndef __irq_H
  8. #define __irq_H
  9. /*
  10. * Interrupt controller types available. You can find a particular one with
  11. * irq_first_device_type()
  12. */
  13. enum irq_dev_t {
  14. X86_IRQT_BASE, /* Base controller */
  15. X86_IRQT_ITSS, /* ITSS controller, e.g. on APL */
  16. X86_IRQT_ACPI_GPE, /* ACPI General-Purpose Events controller */
  17. SANDBOX_IRQT_BASE, /* Sandbox testing */
  18. };
  19. /**
  20. * struct irq - A single irq line handled by an interrupt controller
  21. *
  22. * @dev: IRQ device that handles this irq
  23. * @id: ID to identify this irq with the device
  24. */
  25. struct irq {
  26. struct udevice *dev;
  27. ulong id;
  28. };
  29. /**
  30. * struct irq_ops - Operations for the IRQ
  31. *
  32. * Each IRQ device can handle mulitple IRQ lines
  33. */
  34. struct irq_ops {
  35. /**
  36. * route_pmc_gpio_gpe() - Get the GPIO for an event
  37. *
  38. * @dev: IRQ device
  39. * @pmc_gpe_num: Event number to check
  40. * @returns GPIO for the event, or -ENOENT if none
  41. */
  42. int (*route_pmc_gpio_gpe)(struct udevice *dev, uint pmc_gpe_num);
  43. /**
  44. * set_polarity() - Set the IRQ polarity
  45. *
  46. * @dev: IRQ device
  47. * @irq: Interrupt number to set
  48. * @active_low: true if active low, false for active high
  49. * @return 0 if OK, -EINVAL if @irq is invalid
  50. */
  51. int (*set_polarity)(struct udevice *dev, uint irq, bool active_low);
  52. /**
  53. * snapshot_polarities() - record IRQ polarities for later restore
  54. *
  55. * @dev: IRQ device
  56. * @return 0
  57. */
  58. int (*snapshot_polarities)(struct udevice *dev);
  59. /**
  60. * restore_polarities() - restore IRQ polarities
  61. *
  62. * @dev: IRQ device
  63. * @return 0
  64. */
  65. int (*restore_polarities)(struct udevice *dev);
  66. /**
  67. * read_and_clear() - get the value of an interrupt and clear it
  68. *
  69. * Clears the interrupt if pending
  70. *
  71. * @irq: IRQ line
  72. * @return 0 if interrupt is not pending, 1 if it was (and so has been
  73. * cleared), -ve on error
  74. */
  75. int (*read_and_clear)(struct irq *irq);
  76. /**
  77. * of_xlate - Translate a client's device-tree (OF) irq specifier.
  78. *
  79. * The irq core calls this function as the first step in implementing
  80. * a client's irq_get_by_*() call.
  81. *
  82. * If this function pointer is set to NULL, the irq core will use a
  83. * default implementation, which assumes #interrupt-cells = <1>, and
  84. * that the DT cell contains a simple integer irq ID.
  85. *
  86. * @irq: The irq struct to hold the translation result.
  87. * @args: The irq specifier values from device tree.
  88. * @return 0 if OK, or a negative error code.
  89. */
  90. int (*of_xlate)(struct irq *irq, struct ofnode_phandle_args *args);
  91. /**
  92. * request - Request a translated irq.
  93. *
  94. * The irq core calls this function as the second step in
  95. * implementing a client's irq_get_by_*() call, following a successful
  96. * xxx_xlate() call, or as the only step in implementing a client's
  97. * irq_request() call.
  98. *
  99. * @irq: The irq struct to request; this has been fille in by
  100. * a previoux xxx_xlate() function call, or by the caller
  101. * of irq_request().
  102. * @return 0 if OK, or a negative error code.
  103. */
  104. int (*request)(struct irq *irq);
  105. /**
  106. * free - Free a previously requested irq.
  107. *
  108. * This is the implementation of the client irq_free() API.
  109. *
  110. * @irq: The irq to free.
  111. * @return 0 if OK, or a negative error code.
  112. */
  113. int (*free)(struct irq *irq);
  114. };
  115. #define irq_get_ops(dev) ((struct irq_ops *)(dev)->driver->ops)
  116. /**
  117. * irq_route_pmc_gpio_gpe() - Get the GPIO for an event
  118. *
  119. * @dev: IRQ device
  120. * @pmc_gpe_num: Event number to check
  121. * @returns GPIO for the event, or -ENOENT if none
  122. */
  123. int irq_route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num);
  124. /**
  125. * irq_set_polarity() - Set the IRQ polarity
  126. *
  127. * @dev: IRQ device
  128. * @irq: Interrupt number to set
  129. * @active_low: true if active low, false for active high
  130. * @return 0 if OK, -EINVAL if @irq is invalid
  131. */
  132. int irq_set_polarity(struct udevice *dev, uint irq, bool active_low);
  133. /**
  134. * irq_snapshot_polarities() - record IRQ polarities for later restore
  135. *
  136. * @dev: IRQ device
  137. * @return 0
  138. */
  139. int irq_snapshot_polarities(struct udevice *dev);
  140. /**
  141. * irq_restore_polarities() - restore IRQ polarities
  142. *
  143. * @dev: IRQ device
  144. * @return 0
  145. */
  146. int irq_restore_polarities(struct udevice *dev);
  147. /**
  148. * read_and_clear() - get the value of an interrupt and clear it
  149. *
  150. * Clears the interrupt if pending
  151. *
  152. * @dev: IRQ device
  153. * @return 0 if interrupt is not pending, 1 if it was (and so has been
  154. * cleared), -ve on error
  155. */
  156. int irq_read_and_clear(struct irq *irq);
  157. /**
  158. * irq_get_by_index - Get/request an irq by integer index.
  159. *
  160. * This looks up and requests an irq. The index is relative to the client
  161. * device; each device is assumed to have n irqs associated with it somehow,
  162. * and this function finds and requests one of them. The mapping of client
  163. * device irq indices to provider irqs may be via device-tree
  164. * properties, board-provided mapping tables, or some other mechanism.
  165. *
  166. * @dev: The client device.
  167. * @index: The index of the irq to request, within the client's list of
  168. * irqs.
  169. * @irq: A pointer to a irq struct to initialise.
  170. * @return 0 if OK, or a negative error code.
  171. */
  172. int irq_get_by_index(struct udevice *dev, int index, struct irq *irq);
  173. /**
  174. * irq_request - Request a irq by provider-specific ID.
  175. *
  176. * This requests a irq using a provider-specific ID. Generally, this function
  177. * should not be used, since irq_get_by_index/name() provide an interface that
  178. * better separates clients from intimate knowledge of irq providers.
  179. * However, this function may be useful in core SoC-specific code.
  180. *
  181. * @dev: The irq provider device.
  182. * @irq: A pointer to a irq struct to initialise. The caller must
  183. * have already initialised any field in this struct which the
  184. * irq provider uses to identify the irq.
  185. * @return 0 if OK, or a negative error code.
  186. */
  187. int irq_request(struct udevice *dev, struct irq *irq);
  188. /**
  189. * irq_free - Free a previously requested irq.
  190. *
  191. * @irq: A irq struct that was previously successfully requested by
  192. * irq_request/get_by_*().
  193. * @return 0 if OK, or a negative error code.
  194. */
  195. int irq_free(struct irq *irq);
  196. /**
  197. * irq_first_device_type() - Get a particular interrupt controller
  198. *
  199. * On success this returns an activated interrupt device.
  200. *
  201. * @type: Type to find
  202. * @devp: Returns the device, if found
  203. * @return 0 if OK, -ENODEV if not found, other -ve error if uclass failed to
  204. * probe
  205. */
  206. int irq_first_device_type(enum irq_dev_t type, struct udevice **devp);
  207. #endif