glue.h 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * glue.h - DesignWare USB3 DRD glue header
  4. */
  5. #ifndef __DRIVERS_USB_DWC3_GLUE_H
  6. #define __DRIVERS_USB_DWC3_GLUE_H
  7. #include <linux/types.h>
  8. #include "core.h"
  9. /**
  10. * dwc3_properties: DWC3 core properties
  11. * @gsbuscfg0_reqinfo: Value to be programmed in the GSBUSCFG0.REQINFO field
  12. */
  13. struct dwc3_properties {
  14. u32 gsbuscfg0_reqinfo;
  15. };
  16. #define DWC3_DEFAULT_PROPERTIES ((struct dwc3_properties){ \
  17. .gsbuscfg0_reqinfo = DWC3_GSBUSCFG0_REQINFO_UNSPECIFIED, \
  18. })
  19. /**
  20. * dwc3_probe_data: Initialization parameters passed to dwc3_core_probe()
  21. * @dwc: Reference to dwc3 context structure
  22. * @res: resource for the DWC3 core mmio region
  23. * @ignore_clocks_and_resets: clocks and resets defined for the device should
  24. * be ignored by the DWC3 core, as they are managed by the glue
  25. * @skip_core_init_mode: Skip the finial initialization of the target mode, as
  26. * it must be managed by the glue
  27. * @properties: dwc3 software manage properties
  28. */
  29. struct dwc3_probe_data {
  30. struct dwc3 *dwc;
  31. struct resource *res;
  32. bool ignore_clocks_and_resets;
  33. bool skip_core_init_mode;
  34. struct dwc3_properties properties;
  35. };
  36. /**
  37. * dwc3_core_probe - Initialize the core dwc3 driver
  38. * @data: Initialization and configuration parameters for the controller
  39. *
  40. * Initializes the DesignWare USB3 core driver by setting up resources,
  41. * registering interrupts, performing hardware setup, and preparing
  42. * the controller for operation in the appropriate mode (host, gadget,
  43. * or OTG). This is the main initialization function called by glue
  44. * layer drivers to set up the core controller.
  45. *
  46. * Return: 0 on success, negative error code on failure
  47. */
  48. int dwc3_core_probe(const struct dwc3_probe_data *data);
  49. /**
  50. * dwc3_core_remove - Deinitialize and remove the core dwc3 driver
  51. * @dwc: Pointer to DWC3 controller context
  52. *
  53. * Cleans up resources and disables the dwc3 core driver. This should be called
  54. * during driver removal or when the glue layer needs to shut down the
  55. * controller completely.
  56. */
  57. void dwc3_core_remove(struct dwc3 *dwc);
  58. /*
  59. * The following callbacks are provided for glue drivers to call from their
  60. * own pm callbacks provided in struct dev_pm_ops. Glue drivers can perform
  61. * platform-specific work before or after calling these functions and delegate
  62. * the core suspend/resume operations to the core driver.
  63. */
  64. int dwc3_runtime_suspend(struct dwc3 *dwc);
  65. int dwc3_runtime_resume(struct dwc3 *dwc);
  66. int dwc3_runtime_idle(struct dwc3 *dwc);
  67. int dwc3_pm_suspend(struct dwc3 *dwc);
  68. int dwc3_pm_resume(struct dwc3 *dwc);
  69. void dwc3_pm_complete(struct dwc3 *dwc);
  70. int dwc3_pm_prepare(struct dwc3 *dwc);
  71. /* All of the following functions must only be used with skip_core_init_mode */
  72. /**
  73. * dwc3_core_init - Initialize DWC3 core hardware
  74. * @dwc: Pointer to DWC3 controller context
  75. *
  76. * Configures and initializes the core hardware, usually done by dwc3_core_probe.
  77. * This function is provided for platforms that use skip_core_init_mode and need
  78. * to finalize the core initialization after some platform-specific setup.
  79. * It must only be called when using skip_core_init_mode and before
  80. * dwc3_host_init or dwc3_gadget_init.
  81. *
  82. * Return: 0 on success, negative error code on failure
  83. */
  84. int dwc3_core_init(struct dwc3 *dwc);
  85. /**
  86. * dwc3_core_exit - Shut down DWC3 core hardware
  87. * @dwc: Pointer to DWC3 controller context
  88. *
  89. * Disables and cleans up the core hardware state. This is usually handled
  90. * internally by dwc3 and must only be called when using skip_core_init_mode
  91. * and only after dwc3_core_init. Afterwards, dwc3_core_init may be called
  92. * again.
  93. */
  94. void dwc3_core_exit(struct dwc3 *dwc);
  95. /**
  96. * dwc3_host_init - Initialize host mode operation
  97. * @dwc: Pointer to DWC3 controller context
  98. *
  99. * Initializes the controller for USB host mode operation, usually done by
  100. * dwc3_core_probe or from within the dwc3 USB role switch callback.
  101. * This function is provided for platforms that use skip_core_init_mode and need
  102. * to finalize the host initialization after some platform-specific setup.
  103. * It must not be called before dwc3_core_init or when skip_core_init_mode is
  104. * not used. It must also not be called when gadget or host mode has already
  105. * been initialized.
  106. *
  107. * Return: 0 on success, negative error code on failure
  108. */
  109. int dwc3_host_init(struct dwc3 *dwc);
  110. /**
  111. * dwc3_host_exit - Shut down host mode operation
  112. * @dwc: Pointer to DWC3 controller context
  113. *
  114. * Disables and cleans up host mode resources, usually done by
  115. * the dwc3 USB role switch callback before switching controller mode.
  116. * It must only be called when skip_core_init_mode is used and only after
  117. * dwc3_host_init.
  118. */
  119. void dwc3_host_exit(struct dwc3 *dwc);
  120. /**
  121. * dwc3_gadget_init - Initialize gadget mode operation
  122. * @dwc: Pointer to DWC3 controller context
  123. *
  124. * Initializes the controller for USB gadget mode operation, usually done by
  125. * dwc3_core_probe or from within the dwc3 USB role switch callback. This
  126. * function is provided for platforms that use skip_core_init_mode and need to
  127. * finalize the gadget initialization after some platform-specific setup.
  128. * It must not be called before dwc3_core_init or when skip_core_init_mode is
  129. * not used. It must also not be called when gadget or host mode has already
  130. * been initialized.
  131. *
  132. * Return: 0 on success, negative error code on failure
  133. */
  134. int dwc3_gadget_init(struct dwc3 *dwc);
  135. /**
  136. * dwc3_gadget_exit - Shut down gadget mode operation
  137. * @dwc: Pointer to DWC3 controller context
  138. *
  139. * Disables and cleans up gadget mode resources, usually done by
  140. * the dwc3 USB role switch callback before switching controller mode.
  141. * It must only be called when skip_core_init_mode is used and only after
  142. * dwc3_gadget_init.
  143. */
  144. void dwc3_gadget_exit(struct dwc3 *dwc);
  145. /**
  146. * dwc3_enable_susphy - Control SUSPHY status for all USB ports
  147. * @dwc: Pointer to DWC3 controller context
  148. * @enable: True to enable SUSPHY, false to disable
  149. *
  150. * Enables or disables the USB3 PHY SUSPEND and USB2 PHY SUSPHY feature for
  151. * all available ports.
  152. * This is usually handled by the dwc3 core code and should only be used
  153. * when skip_core_init_mode is used and the glue layer needs to manage SUSPHY
  154. * settings itself, e.g., due to platform-specific requirements during mode
  155. * switches.
  156. */
  157. void dwc3_enable_susphy(struct dwc3 *dwc, bool enable);
  158. /**
  159. * dwc3_set_prtcap - Set the USB controller PRTCAP mode
  160. * @dwc: Pointer to DWC3 controller context
  161. * @mode: Target mode, must be one of DWC3_GCTL_PRTCAP_{HOST,DEVICE,OTG}
  162. * @ignore_susphy: If true, skip disabling the SUSPHY and keep the current state
  163. *
  164. * Updates PRTCAP of the controller and current_dr_role inside the dwc3
  165. * structure. For DRD controllers, this also disables SUSPHY unless explicitly
  166. * told to skip via the ignore_susphy parameter.
  167. *
  168. * This is usually handled by the dwc3 core code and should only be used
  169. * when skip_core_init_mode is used and the glue layer needs to manage mode
  170. * transitions itself due to platform-specific requirements. It must be called
  171. * with the correct mode before calling dwc3_host_init or dwc3_gadget_init.
  172. */
  173. void dwc3_set_prtcap(struct dwc3 *dwc, u32 mode, bool ignore_susphy);
  174. #endif