phy-comphy-3700.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. /*
  2. * Copyright (C) 2018-2021 Marvell International Ltd.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. * https://spdx.org/licenses
  6. */
  7. #ifndef PHY_COMPHY_3700_H
  8. #define PHY_COMPHY_3700_H
  9. #define PLL_SET_DELAY_US 600
  10. #define COMPHY_PLL_TIMEOUT 1000
  11. #define REG_16_BIT_MASK 0xFFFF
  12. #define COMPHY_SELECTOR_PHY_REG 0xFC
  13. /* bit0: 0: Lane1 is GbE0; 1: Lane1 is PCIE */
  14. #define COMPHY_SELECTOR_PCIE_GBE0_SEL_BIT BIT(0)
  15. /* bit4: 0: Lane0 is GbE1; 1: Lane0 is USB3 */
  16. #define COMPHY_SELECTOR_USB3_GBE1_SEL_BIT BIT(4)
  17. /* bit8: 0: Lane0 is USB3 instead of GbE1, Lane2 is SATA; 1: Lane2 is USB3 */
  18. #define COMPHY_SELECTOR_USB3_PHY_SEL_BIT BIT(8)
  19. /* SATA PHY register offset */
  20. #define SATAPHY_LANE2_REG_BASE_OFFSET 0x200
  21. /* USB3 PHY offset compared to SATA PHY */
  22. #define USB3PHY_LANE2_REG_BASE_OFFSET 0x200
  23. /* Comphy lane2 indirect access register offset */
  24. #define COMPHY_LANE2_INDIR_ADDR_OFFSET 0x0
  25. #define COMPHY_LANE2_INDIR_DATA_OFFSET 0x4
  26. /* PHY shift to get related register address */
  27. enum {
  28. PCIE = 1,
  29. USB3,
  30. };
  31. #define PCIEPHY_SHFT 2
  32. #define USB3PHY_SHFT 2
  33. #define PHY_SHFT(unit) ((unit == PCIE) ? PCIEPHY_SHFT : USB3PHY_SHFT)
  34. /* PHY register */
  35. #define COMPHY_POWER_PLL_CTRL 0x01
  36. #define PWR_PLL_CTRL_ADDR(unit) (COMPHY_POWER_PLL_CTRL * PHY_SHFT(unit))
  37. #define PU_IVREF_BIT BIT(15)
  38. #define PU_PLL_BIT BIT(14)
  39. #define PU_RX_BIT BIT(13)
  40. #define PU_TX_BIT BIT(12)
  41. #define PU_TX_INTP_BIT BIT(11)
  42. #define PU_DFE_BIT BIT(10)
  43. #define RESET_DTL_RX_BIT BIT(9)
  44. #define PLL_LOCK_BIT BIT(8)
  45. #define REF_FREF_SEL_OFFSET 0
  46. #define REF_FREF_SEL_MASK (0x1F << REF_FREF_SEL_OFFSET)
  47. #define REF_FREF_SEL_SERDES_25MHZ (0x1 << REF_FREF_SEL_OFFSET)
  48. #define REF_FREF_SEL_SERDES_40MHZ (0x3 << REF_FREF_SEL_OFFSET)
  49. #define REF_FREF_SEL_SERDES_50MHZ (0x4 << REF_FREF_SEL_OFFSET)
  50. #define REF_FREF_SEL_PCIE_USB3_25MHZ (0x2 << REF_FREF_SEL_OFFSET)
  51. #define REF_FREF_SEL_PCIE_USB3_40MHZ (0x3 << REF_FREF_SEL_OFFSET)
  52. #define PHY_MODE_OFFSET 5
  53. #define PHY_MODE_MASK (7 << PHY_MODE_OFFSET)
  54. #define PHY_MODE_SATA (0x0 << PHY_MODE_OFFSET)
  55. #define PHY_MODE_PCIE (0x3 << PHY_MODE_OFFSET)
  56. #define PHY_MODE_SGMII (0x4 << PHY_MODE_OFFSET)
  57. #define PHY_MODE_USB3 (0x5 << PHY_MODE_OFFSET)
  58. #define COMPHY_KVCO_CAL_CTRL 0x02
  59. #define KVCO_CAL_CTRL_ADDR(unit) (COMPHY_KVCO_CAL_CTRL * PHY_SHFT(unit))
  60. #define USE_MAX_PLL_RATE_BIT BIT(12)
  61. #define SPEED_PLL_OFFSET 2
  62. #define SPEED_PLL_MASK (0x3F << SPEED_PLL_OFFSET)
  63. #define SPEED_PLL_VALUE_16 (0x10 << SPEED_PLL_OFFSET)
  64. #define COMPHY_DIG_LOOPBACK_EN 0x23
  65. #define DIG_LOOPBACK_EN_ADDR(unit) (COMPHY_DIG_LOOPBACK_EN * \
  66. PHY_SHFT(unit))
  67. #define SEL_DATA_WIDTH_OFFSET 10
  68. #define SEL_DATA_WIDTH_MASK (0x3 << SEL_DATA_WIDTH_OFFSET)
  69. #define DATA_WIDTH_10BIT (0x0 << SEL_DATA_WIDTH_OFFSET)
  70. #define DATA_WIDTH_20BIT (0x1 << SEL_DATA_WIDTH_OFFSET)
  71. #define DATA_WIDTH_40BIT (0x2 << SEL_DATA_WIDTH_OFFSET)
  72. #define PLL_READY_TX_BIT BIT(4)
  73. #define COMPHY_SYNC_PATTERN 0x24
  74. #define SYNC_PATTERN_ADDR(unit) (COMPHY_SYNC_PATTERN * PHY_SHFT(unit))
  75. #define TXD_INVERT_BIT BIT(10)
  76. #define RXD_INVERT_BIT BIT(11)
  77. #define COMPHY_SYNC_MASK_GEN 0x25
  78. #define PHY_GEN_MAX_OFFSET 10
  79. #define PHY_GEN_MAX_MASK (3 << PHY_GEN_MAX_OFFSET)
  80. #define PHY_GEN_MAX_USB3_5G (1 << PHY_GEN_MAX_OFFSET)
  81. #define COMPHY_ISOLATION_CTRL 0x26
  82. #define ISOLATION_CTRL_ADDR(unit) (COMPHY_ISOLATION_REG * PHY_SHFT(unit))
  83. #define PHY_ISOLATE_MODE BIT(15)
  84. #define COMPHY_GEN2_SET2 0x3e
  85. #define GEN2_SET2_ADDR(unit) (COMPHY_GEN2_SET2 * PHY_SHFT(unit))
  86. #define GS2_TX_SSC_AMP_VALUE_20 BIT(14)
  87. #define GS2_TX_SSC_AMP_OFF 9
  88. #define GS2_TX_SSC_AMP_LEN 7
  89. #define GS2_TX_SSC_AMP_MASK (((1 << GS2_TX_SSC_AMP_LEN) - 1) << \
  90. GS2_TX_SSC_AMP_OFF)
  91. #define GS2_VREG_RXTX_MAS_ISET_OFF 7
  92. #define GS2_VREG_RXTX_MAS_ISET_60U (0 << GS2_VREG_RXTX_MAS_ISET_OFF)
  93. #define GS2_VREG_RXTX_MAS_ISET_80U (1 << GS2_VREG_RXTX_MAS_ISET_OFF)
  94. #define GS2_VREG_RXTX_MAS_ISET_100U (2 << GS2_VREG_RXTX_MAS_ISET_OFF)
  95. #define GS2_VREG_RXTX_MAS_ISET_120U (3 << GS2_VREG_RXTX_MAS_ISET_OFF)
  96. #define GS2_VREG_RXTX_MAS_ISET_MASK (BIT(7) | BIT(8))
  97. #define GS2_RSVD_6_0_OFF 0
  98. #define GS2_RSVD_6_0_LEN 7
  99. #define GS2_RSVD_6_0_MASK (((1 << GS2_RSVD_6_0_LEN) - 1) << \
  100. GS2_RSVD_6_0_OFF)
  101. #define COMPHY_GEN3_SET2 0x3f
  102. #define GEN3_SET2_ADDR(unit) (COMPHY_GEN3_SET2 * PHY_SHFT(unit))
  103. #define COMPHY_IDLE_SYNC_EN 0x48
  104. #define IDLE_SYNC_EN_ADDR(unit) (COMPHY_IDLE_SYNC_EN * PHY_SHFT(unit))
  105. #define IDLE_SYNC_EN BIT(12)
  106. #define IDLE_SYNC_EN_DEFAULT_VALUE 0x60
  107. #define COMPHY_MISC_CTRL0 0x4F
  108. #define MISC_CTRL0_ADDR(unit) (COMPHY_MISC_CTRL0 * PHY_SHFT(unit))
  109. #define CLK100M_125M_EN BIT(4)
  110. #define TXDCLK_2X_SEL BIT(6)
  111. #define CLK500M_EN BIT(7)
  112. #define PHY_REF_CLK_SEL BIT(10)
  113. #define MISC_CTRL0_DEFAULT_VALUE 0xA00D
  114. #define COMPHY_MISC_CTRL1 0x73
  115. #define MISC_CTRL1_ADDR(unit) (COMPHY_MISC_CTRL1 * PHY_SHFT(unit))
  116. #define SEL_BITS_PCIE_FORCE BIT(15)
  117. #define COMPHY_GEN2_SET3 0x112
  118. #define GS3_FFE_CAP_SEL_MASK 0xF
  119. #define GS3_FFE_CAP_SEL_VALUE 0xF
  120. #define COMPHY_LANE_CFG0 0x180
  121. #define LANE_CFG0_ADDR(unit) (COMPHY_LANE_CFG0 * PHY_SHFT(unit))
  122. #define PRD_TXDEEMPH0_MASK BIT(0)
  123. #define PRD_TXMARGIN_MASK (BIT(1) | BIT(2) | BIT(3))
  124. #define PRD_TXSWING_MASK BIT(4)
  125. #define CFG_TX_ALIGN_POS_MASK (BIT(5) | BIT(6) | BIT(7) | BIT(8))
  126. #define COMPHY_LANE_CFG1 0x181
  127. #define LANE_CFG1_ADDR(unit) (COMPHY_LANE_CFG1 * PHY_SHFT(unit))
  128. #define PRD_TXDEEMPH1_MASK BIT(15)
  129. #define USE_MAX_PLL_RATE_EN BIT(9)
  130. #define TX_DET_RX_MODE BIT(6)
  131. #define GEN2_TX_DATA_DLY_MASK (BIT(3) | BIT(4))
  132. #define GEN2_TX_DATA_DLY_DEFT (2 << 3)
  133. #define TX_ELEC_IDLE_MODE_EN BIT(0)
  134. #define COMPHY_LANE_STAT1 0x183
  135. #define LANE_STAT1_ADDR(unit) (COMPHY_LANE_STAT1 * PHY_SHFT(unit))
  136. #define TXDCLK_PCLK_EN BIT(0)
  137. #define COMPHY_LANE_CFG4 0x188
  138. #define LANE_CFG4_ADDR(unit) (COMPHY_LANE_CFG4 * PHY_SHFT(unit))
  139. #define SPREAD_SPECTRUM_CLK_EN BIT(7)
  140. #define COMPHY_RST_CLK_CTRL 0x1C1
  141. #define RST_CLK_CTRL_ADDR(unit) (COMPHY_RST_CLK_CTRL * PHY_SHFT(unit))
  142. #define SOFT_RESET BIT(0)
  143. #define MODE_CORE_CLK_FREQ_SEL BIT(9)
  144. #define MODE_PIPE_WIDTH_32 BIT(3)
  145. #define MODE_REFDIV_OFFSET 4
  146. #define MODE_REFDIV_LEN 2
  147. #define MODE_REFDIV_MASK (0x3 << MODE_REFDIV_OFFSET)
  148. #define MODE_REFDIV_BY_4 (0x2 << MODE_REFDIV_OFFSET)
  149. #define COMPHY_TEST_MODE_CTRL 0x1C2
  150. #define TEST_MODE_CTRL_ADDR(unit) (COMPHY_TEST_MODE_CTRL * PHY_SHFT(unit))
  151. #define MODE_MARGIN_OVERRIDE BIT(2)
  152. #define COMPHY_CLK_SRC_LO 0x1C3
  153. #define CLK_SRC_LO_ADDR(unit) (COMPHY_CLK_SRC_LO * PHY_SHFT(unit))
  154. #define MODE_CLK_SRC BIT(0)
  155. #define BUNDLE_PERIOD_SEL BIT(1)
  156. #define BUNDLE_PERIOD_SCALE_MASK (BIT(2) | BIT(3))
  157. #define BUNDLE_SAMPLE_CTRL BIT(4)
  158. #define PLL_READY_DLY_MASK (BIT(5) | BIT(6) | BIT(7))
  159. #define CFG_SEL_20B BIT(15)
  160. #define COMPHY_PWR_MGM_TIM1 0x1D0
  161. #define PWR_MGM_TIM1_ADDR(unit) (COMPHY_PWR_MGM_TIM1 * PHY_SHFT(unit))
  162. #define CFG_PM_OSCCLK_WAIT_OFF 12
  163. #define CFG_PM_OSCCLK_WAIT_LEN 4
  164. #define CFG_PM_OSCCLK_WAIT_MASK (((1 << CFG_PM_OSCCLK_WAIT_LEN) - 1) \
  165. << CFG_PM_OSCCLK_WAIT_OFF)
  166. #define CFG_PM_RXDEN_WAIT_OFF 8
  167. #define CFG_PM_RXDEN_WAIT_LEN 4
  168. #define CFG_PM_RXDEN_WAIT_MASK (((1 << CFG_PM_RXDEN_WAIT_LEN) - 1) \
  169. << CFG_PM_RXDEN_WAIT_OFF)
  170. #define CFG_PM_RXDEN_WAIT_1_UNIT (1 << CFG_PM_RXDEN_WAIT_OFF)
  171. #define CFG_PM_RXDLOZ_WAIT_OFF 0
  172. #define CFG_PM_RXDLOZ_WAIT_LEN 8
  173. #define CFG_PM_RXDLOZ_WAIT_MASK (((1 << CFG_PM_RXDLOZ_WAIT_LEN) - 1) \
  174. << CFG_PM_RXDLOZ_WAIT_OFF)
  175. #define CFG_PM_RXDLOZ_WAIT_7_UNIT (7 << CFG_PM_RXDLOZ_WAIT_OFF)
  176. #define CFG_PM_RXDLOZ_WAIT_12_UNIT (0xC << CFG_PM_RXDLOZ_WAIT_OFF)
  177. /*
  178. * This register is not from PHY lane register space. It only exists in the
  179. * indirect register space, before the actual PHY lane 2 registers. So the
  180. * offset is absolute, not relative to SATAPHY_LANE2_REG_BASE_OFFSET.
  181. * It is used only for SATA PHY initialization.
  182. */
  183. #define COMPHY_RESERVED_REG 0x0E
  184. #define PHYCTRL_FRM_PIN_BIT BIT(13)
  185. /* SGMII */
  186. #define COMPHY_PHY_CFG1_OFFSET(lane) ((1 - (lane)) * 0x28)
  187. #define PIN_PU_IVREF_BIT BIT(1)
  188. #define PIN_RESET_CORE_BIT BIT(11)
  189. #define PIN_RESET_COMPHY_BIT BIT(12)
  190. #define PIN_PU_PLL_BIT BIT(16)
  191. #define PIN_PU_RX_BIT BIT(17)
  192. #define PIN_PU_TX_BIT BIT(18)
  193. #define PIN_TX_IDLE_BIT BIT(19)
  194. #define GEN_RX_SEL_OFFSET 22
  195. #define GEN_RX_SEL_MASK (0xF << GEN_RX_SEL_OFFSET)
  196. #define GEN_TX_SEL_OFFSET 26
  197. #define GEN_TX_SEL_MASK (0xF << GEN_TX_SEL_OFFSET)
  198. #define PHY_RX_INIT_BIT BIT(30)
  199. #define SD_SPEED_1_25_G 0x6
  200. #define SD_SPEED_3_125_G 0x8
  201. /* COMPHY status reg:
  202. * lane0: USB3/GbE1 PHY Status 1
  203. * lane1: PCIe/GbE0 PHY Status 1
  204. */
  205. #define COMPHY_PHY_STATUS_OFFSET(lane) (0x18 + (1 - (lane)) * 0x28)
  206. #define PHY_RX_INIT_DONE_BIT BIT(0)
  207. #define PHY_PLL_READY_RX_BIT BIT(2)
  208. #define PHY_PLL_READY_TX_BIT BIT(3)
  209. #define SGMIIPHY_ADDR(off, base) ((((off) & 0x00007FF) * 2) + (base))
  210. #define MAX_LANE_NR 3
  211. /* comphy API */
  212. int mvebu_3700_comphy_is_pll_locked(uint8_t comphy_index, uint32_t comphy_mode);
  213. int mvebu_3700_comphy_power_off(uint8_t comphy_index, uint32_t comphy_mode);
  214. int mvebu_3700_comphy_power_on(uint8_t comphy_index, uint32_t comphy_mode);
  215. #endif /* PHY_COMPHY_3700_H */