usb_phy.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (c) 2017 - 2021, Broadcom
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef USB_PHY_H
  7. #define USB_PHY_H
  8. #include <stdint.h>
  9. #include <common/debug.h>
  10. #include <drivers/delay_timer.h>
  11. #include <lib/mmio.h>
  12. #include <platform_def.h>
  13. #define DRDU2_U2PLL_NDIV_FRAC_OFFSET 0x0U
  14. #define DRDU2_U2PLL_NDIV_INT 0x4U
  15. #define DRDU2_U2PLL_CTRL 0x8U
  16. #define DRDU2_U2PLL_LOCK BIT(6U)
  17. #define DRDU2_U2PLL_RESETB BIT(5U)
  18. #define DRDU2_U2PLL_PDIV_MASK 0xFU
  19. #define DRDU2_U2PLL_PDIV_OFFSET 1U
  20. #define DRDU2_U2PLL_SUSPEND_EN BIT(0U)
  21. #define DRDU2_PHY_CTRL 0x0CU
  22. #define DRDU2_U2IDDQ BIT(30U)
  23. #define DRDU2_U2SOFT_RST_N BIT(29U)
  24. #define DRDU2_U2PHY_ON_FLAG BIT(22U)
  25. #define DRDU2_U2PHY_PCTL_MASK 0xFFFFU
  26. #define DRDU2_U2PHY_PCTL_OFFSET 6U
  27. #define DRDU2_U2PHY_RESETB BIT(5U)
  28. #define DRDU2_U2PHY_ISO BIT(4U)
  29. #define DRDU2_U2AFE_BG_PWRDWNB BIT(3U)
  30. #define DRDU2_U2AFE_PLL_PWRDWNB BIT(2U)
  31. #define DRDU2_U2AFE_LDO_PWRDWNB BIT(1U)
  32. #define DRDU2_U2CTRL_CORERDY BIT(0U)
  33. #define DRDU2_STRAP_CTRL 0x18U
  34. #define DRDU2_FORCE_HOST_MODE BIT(5U)
  35. #define DRDU2_FORCE_DEVICE_MODE BIT(4U)
  36. #define BDC_USB_STP_SPD_MASK 0x7U
  37. #define BDC_USB_STP_SPD_OFFSET 0U
  38. #define DRDU2_PWR_CTRL 0x1CU
  39. #define DRDU2_U2PHY_DFE_SWITCH_PWROKIN_I BIT(2U)
  40. #define DRDU2_U2PHY_DFE_SWITCH_PWRONIN_I BIT(1U)
  41. #define DRDU2_SOFT_RESET_CTRL 0x20U
  42. #define DRDU2_BDC_AXI_SOFT_RST_N BIT(0U)
  43. #define USB3H_U2PLL_NDIV_FRAC 0x4U
  44. #define USB3H_U2PLL_NDIV_INT 0x8U
  45. #define USB3H_U2PLL_CTRL 0xCU
  46. #define USB3H_U2PLL_LOCK BIT(6U)
  47. #define USB3H_U2PLL_RESETB BIT(5U)
  48. #define USB3H_U2PLL_PDIV_MASK 0xFU
  49. #define USB3H_U2PLL_PDIV_OFFSET 1U
  50. #define USB3H_U2PHY_CTRL 0x10U
  51. #define USB3H_U2PHY_ON_FLAG 22U
  52. #define USB3H_U2PHY_PCTL_MASK 0xFFFFU
  53. #define USB3H_U2PHY_PCTL_OFFSET 6U
  54. #define USB3H_U2PHY_IDDQ BIT(29U)
  55. #define USB3H_U2PHY_RESETB BIT(5U)
  56. #define USB3H_U2PHY_ISO BIT(4U)
  57. #define USB3H_U2AFE_BG_PWRDWNB BIT(3U)
  58. #define USB3H_U2AFE_PLL_PWRDWNB BIT(2U)
  59. #define USB3H_U2AFE_LDO_PWRDWNB BIT(1U)
  60. #define USB3H_U2CTRL_CORERDY BIT(0U)
  61. #define USB3H_U3PHY_CTRL 0x14U
  62. #define USB3H_U3SOFT_RST_N BIT(30U)
  63. #define USB3H_U3MDIO_RESETB_I BIT(29U)
  64. #define USB3H_U3POR_RESET_I BIT(28U)
  65. #define USB3H_U3PHY_PCTL_MASK 0xFFFFU
  66. #define USB3H_U3PHY_PCTL_OFFSET 2U
  67. #define USB3H_U3PHY_RESETB BIT(1U)
  68. #define USB3H_U3PHY_PLL_CTRL 0x18U
  69. #define USB3H_U3PLL_REFCLK_MASK 0x7U
  70. #define USB3H_U3PLL_REFCLK_OFFSET 4U
  71. #define USB3H_U3PLL_SS_LOCK BIT(3U)
  72. #define USB3H_U3PLL_SEQ_START BIT(2U)
  73. #define USB3H_U3SSPLL_SUSPEND_EN BIT(1U)
  74. #define USB3H_U3PLL_RESETB BIT(0U)
  75. #define USB3H_PWR_CTRL 0x28U
  76. #define USB3H_PWR_CTRL_OVERRIDE_I_R 4U
  77. #define USB3H_PWR_CTRL_U2PHY_DFE_SWITCH_PWROKIN BIT(11U)
  78. #define USB3H_PWR_CTRL_U2PHY_DFE_SWITCH_PWRONIN BIT(10U)
  79. #define USB3H_SOFT_RESET_CTRL 0x2CU
  80. #define USB3H_XHC_AXI_SOFT_RST_N BIT(1U)
  81. #define USB3H_PHY_PWR_CTRL 0x38U
  82. #define USB3H_DISABLE_USB30_P0 BIT(2U)
  83. #define USB3H_DISABLE_EUSB_P1 BIT(1U)
  84. #define USB3H_DISABLE_EUSB_P0 BIT(0U)
  85. #define DRDU3_U2PLL_NDIV_FRAC 0x4U
  86. #define DRDU3_U2PLL_NDIV_INT 0x8U
  87. #define DRDU3_U2PLL_CTRL 0xCU
  88. #define DRDU3_U2PLL_LOCK BIT(6U)
  89. #define DRDU3_U2PLL_RESETB BIT(5U)
  90. #define DRDU3_U2PLL_PDIV_MASK 0xFU
  91. #define DRDU3_U2PLL_PDIV_OFFSET 1U
  92. #define DRDU3_U2PHY_CTRL 0x10U
  93. #define DRDU3_U2PHY_IDDQ BIT(29U)
  94. #define DRDU3_U2PHY_ON_FLAG BIT(22U)
  95. #define DRDU3_U2PHY_PCTL_MASK 0xFFFFU
  96. #define DRDU3_U2PHY_PCTL_OFFSET 6U
  97. #define DRDU3_U2PHY_RESETB BIT(5U)
  98. #define DRDU3_U2PHY_ISO BIT(4U)
  99. #define DRDU3_U2AFE_BG_PWRDWNB BIT(3U)
  100. #define DRDU3_U2AFE_PLL_PWRDWNB BIT(2U)
  101. #define DRDU3_U2AFE_LDO_PWRDWNB BIT(1U)
  102. #define DRDU3_U2CTRL_CORERDY BIT(0U)
  103. #define DRDU3_U3PHY_CTRL 0x14U
  104. #define DRDU3_U3XHC_SOFT_RST_N BIT(31U)
  105. #define DRDU3_U3BDC_SOFT_RST_N BIT(30U)
  106. #define DRDU3_U3MDIO_RESETB_I BIT(29U)
  107. #define DRDU3_U3POR_RESET_I BIT(28U)
  108. #define DRDU3_U3PHY_PCTL_MASK 0xFFFFU
  109. #define DRDU3_U3PHY_PCTL_OFFSET 2U
  110. #define DRDU3_U3PHY_RESETB BIT(1U)
  111. #define DRDU3_U3PHY_PLL_CTRL 0x18U
  112. #define DRDU3_U3PLL_REFCLK_MASK 0x7U
  113. #define DRDU3_U3PLL_REFCLK_OFFSET 4U
  114. #define DRDU3_U3PLL_SS_LOCK BIT(3U)
  115. #define DRDU3_U3PLL_SEQ_START BIT(2U)
  116. #define DRDU3_U3SSPLL_SUSPEND_EN BIT(1U)
  117. #define DRDU3_U3PLL_RESETB BIT(0U)
  118. #define DRDU3_STRAP_CTRL 0x28U
  119. #define BDC_USB_STP_SPD_MASK 0x7U
  120. #define BDC_USB_STP_SPD_OFFSET 0U
  121. #define BDC_USB_STP_SPD_SS 0x0U
  122. #define BDC_USB_STP_SPD_HS 0x2U
  123. #define DRDU3_PWR_CTRL 0x2cU
  124. #define DRDU3_U2PHY_DFE_SWITCH_PWROKIN BIT(12U)
  125. #define DRDU3_U2PHY_DFE_SWITCH_PWRONIN BIT(11U)
  126. #define DRDU3_PWR_CTRL_OVERRIDE_I_R 4U
  127. #define DRDU3_SOFT_RESET_CTRL 0x30U
  128. #define DRDU3_XHC_AXI_SOFT_RST_N BIT(1U)
  129. #define DRDU3_BDC_AXI_SOFT_RST_N BIT(0U)
  130. #define DRDU3_PHY_PWR_CTRL 0x3cU
  131. #define DRDU3_DISABLE_USB30_P0 BIT(2U)
  132. #define DRDU3_DISABLE_EUSB_P1 BIT(1U)
  133. #define DRDU3_DISABLE_EUSB_P0 BIT(0U)
  134. #define PLL_REFCLK_PAD 0x0U
  135. #define PLL_REFCLK_25MHZ 0x1U
  136. #define PLL_REFCLK_96MHZ 0x2U
  137. #define PLL_REFCLK_INTERNAL 0x3U
  138. /* USB PLL lock time out for 10 ms */
  139. #define PLL_LOCK_RETRY_COUNT 10000U
  140. #define U2PLL_NDIV_INT_VAL 0x13U
  141. #define U2PLL_NDIV_FRAC_VAL 0x1005U
  142. #define U2PLL_PDIV_VAL 0x1U
  143. /*
  144. * Using external FSM
  145. * BIT-3:2: device mode; mode is not effect
  146. * BIT-1: soft reset active low
  147. */
  148. #define U2PHY_PCTL_VAL 0x0003U
  149. /* Non-driving signal low */
  150. #define U2PHY_PCTL_NON_DRV_LOW 0x0002U
  151. #define U3PHY_PCTL_VAL 0x0006U
  152. #define MAX_NR_PORTS 3U
  153. #define USB3H_DRDU2_PHY 1U
  154. #define DRDU3_PHY 2U
  155. #define USB_HOST_MODE 1U
  156. #define USB_DEV_MODE 2U
  157. #define USB3SS_PORT 0U
  158. #define DRDU2_PORT 1U
  159. #define USB3HS_PORT 2U
  160. #define DRD3SS_PORT 0U
  161. #define DRD3HS_PORT 1U
  162. #define SR_USB_PHY_COUNT 2U
  163. #define DRDU3_PIPE_CTRL 0x68500000U
  164. #define DRDU3H_XHC_REGS_CPLIVER 0x68501000U
  165. #define USB3H_PIPE_CTRL 0x68510000U
  166. #define DRD2U3H_XHC_REGS_CPLIVER 0x68511000U
  167. #define DRDU2_U2PLL_NDIV_FRAC 0x68520000U
  168. #define AXI_DEBUG_CTRL 0x68500038U
  169. #define AXI_DBG_CTRL_SSPHY_DRD_MODE_DISABLE BIT(12U)
  170. #define USB3H_DEBUG_CTRL 0x68510034U
  171. #define USB3H_DBG_CTRL_SSPHY_DRD_MODE_DISABLE BIT(7U)
  172. typedef struct _usb_phy_port usb_phy_port_t;
  173. typedef struct {
  174. uint32_t drdu2reg;
  175. uint32_t usb3hreg;
  176. uint32_t drdu3reg;
  177. uint32_t phy_id;
  178. uint32_t ports_enabled;
  179. uint32_t initialized;
  180. usb_phy_port_t *phy_port;
  181. } usb_phy_t;
  182. struct _usb_phy_port {
  183. uint32_t port_id;
  184. uint32_t mode;
  185. uint32_t enabled;
  186. usb_phy_t *p;
  187. };
  188. struct u2_phy_ext_fsm {
  189. uint32_t pll_ctrl_reg;
  190. uint32_t phy_ctrl_reg;
  191. uint32_t phy_iddq;
  192. uint32_t pwr_ctrl_reg;
  193. uint32_t pwr_okin;
  194. uint32_t pwr_onin;
  195. };
  196. #endif /* USB_PHY_H */