fgmac_phy.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * Copyright : (C) 2022 Phytium Information Technology, Inc.
  3. * All Rights Reserved.
  4. *
  5. * This program is OPEN SOURCE software: you can redistribute it and/or modify it
  6. * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
  7. * either version 1.0 of the License, or (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
  10. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. * See the Phytium Public License for more details.
  12. *
  13. *
  14. * FilePath: fgmac_phy.h
  15. * Date: 2022-04-06 14:46:52
  16. * LastEditTime: 2022-04-06 14:46:58
  17. * Description:  This file is for
  18. *
  19. * Modify History:
  20. * Ver   Who        Date         Changes
  21. * ----- ------     --------    --------------------------------------
  22. */
  23. #ifndef DRIVERS_ETH_FGMAC_PHY_H
  24. #define DRIVERS_ETH_FGMAC_PHY_H
  25. #ifdef __cplusplus
  26. extern "C"
  27. {
  28. #endif
  29. /***************************** Include Files *********************************/
  30. #include "ftypes.h"
  31. #include "fassert.h"
  32. #include "fkernel.h"
  33. #include "fgmac.h"
  34. /************************** Constant Definitions *****************************/
  35. #define FGMAC_PHY_MAX_NUM 32U
  36. /* Generic MII registers. */
  37. #define FGMAC_PHY_MII_CTRL_REG 0x00 /* Basic mode control register */
  38. #define FGMAC_PHY_MII_STATUS_REG 0x01 /* Basic mode status register */
  39. #define FGMAC_PHY_MII_PHYSID1_REG 0x02 /* PHYS ID 1 */
  40. #define FGMAC_PHY_MII_PHYSID2_REG 0x03 /* PHYS ID 2 */
  41. #define FGMAC_PHY_MII_AUTONEG_REG 0x04 /* Advertisement control reg */
  42. #define FGMAC_PHY_MII_LP_REG 0x05 /* Link partner ability reg */
  43. #define FGMAC_PHY_MII_AUTONEG_EX_REG 0x06 /* Expansion register */
  44. #define FGMAC_PHY_MII_NEXT_PAGE_REG 0x07 /* Next Page Transmit Register */
  45. #define FGMAC_PHY_MII_LP_NEXT_PAGE_REG 0x08 /* Link Partner Next Page Register */
  46. #define FGMAC_PHY_MII_CTRL1000_REG 0x09 /* 1000BASE-T control */
  47. #define FGMAC_PHY_MII_STAT1000_REG 0x0a /* 1000BASE-T status */
  48. #define FGMAC_PHY_MII_MMD_CTRL_REG 0x0d /* MMD Access Control Register */
  49. #define FGMAC_PHY_MII_MMD_DATA_REG 0x0e /* MMD Access Data Register */
  50. #define FGMAC_PHY_MII_ESTATUS_REG 0x0f /* Extended Status */
  51. #define FGMAC_PHY_MII_FUNC_CONTROL_REG 0x10 /* Function control */
  52. #define FGMAC_PHY_MII_PHY_SPECIAL_REG 0x11 /* PHY-specific status */
  53. #define FGMAC_PHY_MII_DCOUNTER_REG 0x12 /* Disconnect counter */
  54. #define FGMAC_PHY_MII_FCSCOUNTER_REG 0x13 /* False carrier counter */
  55. #define FGMAC_PHY_MII_NWAYTEST_REG 0x14 /* N-way auto-neg test reg */
  56. #define FGMAC_PHY_MII_RERRCOUNTER_REG 0x15 /* Receive error counter */
  57. #define FGMAC_PHY_MII_SREVISION_REG 0x16 /* Silicon revision */
  58. #define FGMAC_PHY_MII_RESV1_REG 0x17 /* Reserved... */
  59. #define FGMAC_PHY_MII_LBRERROR_REG 0x18 /* Lpback, rx, bypass error */
  60. #define FGMAC_PHY_MII_PHYADDR_REG 0x19 /* PHY address */
  61. #define FGMAC_PHY_MII_RESV2_REG 0x1a /* Reserved... */
  62. #define FGMAC_PHY_MII_TPISTATUS_REG 0x1b /* TPI status for 10mbps */
  63. #define FGMAC_PHY_MII_NCONFIG_REG 0x1c /* Network interface config */
  64. #define FGMAC_PHY_ID1 (0xffff)
  65. #define FGMAC_PHY_ID2 (0xffff)
  66. /* Basic mode control register */
  67. #define FGMAC_PHY_MII_CR_RES GENMASK(5, 0) /* Unused... */
  68. #define FGMAC_PHY_MII_CR_SPEED_SEL_MSB BIT(6) /* MSB of Speed (1000) */
  69. #define FGMAC_PHY_MII_CR_COLLISION_TEST BIT(7) /* Collision test */
  70. #define FGMAC_PHY_MII_CR_DUPLEX_MODE BIT(8) /* Full duplex */
  71. #define FGMAC_PHY_MII_CR_RESTART_AUTO_NEGO BIT(9) /* Auto negotiation restart */
  72. #define FGMAC_PHY_MII_CR_ISOLATE BIT(10) /* Isolate data paths from MII */
  73. #define FGMAC_PHY_MII_CR_POWER_DOWN BIT(11) /* Enable low power state */
  74. #define FGMAC_PHY_MII_CR_AUTO_NEGOT BIT(12) /* Enable auto negotiation */
  75. #define FGMAC_PHY_MII_CR_SPEED_SEL_LSB BIT(13) /* Select 100Mbps */
  76. #define FGMAC_PHY_MII_CR_LOOPBACK BIT(14) /* TXD loopback bits */
  77. #define FGMAC_PHY_MII_CR_RESET BIT(15) /* Reset to default state */
  78. #define FGMAC_PHY_MII_CR_FULLDUPLEX_1000M ((u16)0x2140U) /* Set the full-duplex mode at 1000 Mb/s */
  79. #define FGMAC_PHY_MII_CR_HALFDUPLEX_1000M ((u16)0x2040U) /* Set the half-duplex mode at 1000 Mb/s */
  80. #define FGMAC_PHY_MII_CR_FULLDUPLEX_100M ((u16)0x2100U) /* Set the full-duplex mode at 100 Mb/s */
  81. #define FGMAC_PHY_MII_CR_HALFDUPLEX_100M ((u16)0x2000U) /* Set the half-duplex mode at 100 Mb/s */
  82. #define FGMAC_PHY_MII_CR_FULLDUPLEX_10M ((u16)0x0100U) /* Set the full-duplex mode at 10 Mb/s */
  83. #define FGMAC_PHY_MII_CR_HALFDUPLEX_10M ((u16)0x0000U) /* Set the half-duplex mode at 10 Mb/s */
  84. /* Basic mode status register. */
  85. #define FGMAC_PHY_MII_SR_EXT_CAP BIT(0) /* Ext-reg capability */
  86. #define FGMAC_PHY_MII_SR_JCD BIT(1) /* Jabber detected */
  87. #define FGMAC_PHY_MII_SR_LSTATUS BIT(2) /* Link status */
  88. #define FGMAC_PHY_MII_SR_AUTO_NEGOT BIT(3) /* Able to do auto-negotiation */
  89. #define FGMAC_PHY_MII_SR_REMOTE_FAULT BIT(4) /* Remote fault detected */
  90. #define FGMAC_PHY_MII_SR_AUTO_NEGOT_COMPLETE BIT(5) /* Auto-negotiation complete */
  91. #define FGMAC_PHY_MII_SR_MF_PREAM BIT(6) /* MF Preamble Suppression */
  92. #define FGMAC_PHY_MII_SR_EXT_STATUS BIT(8) /* Extended Status in R15 */
  93. #define FGMAC_PHY_MII_SR_100HALF2 BIT(9) /* Can do 100BASE-T2 HDX */
  94. #define FGMAC_PHY_MII_SR_100FULL2 BIT(10) /* Can do 100BASE-T2 FDX */
  95. #define FGMAC_PHY_MII_SR_10HALF BIT(11) /* Can do 10mbps, half-duplex */
  96. #define FGMAC_PHY_MII_SR_10FULL BIT(12) /* Can do 10mbps, full-duplex */
  97. #define FGMAC_PHY_MII_SR_100HALF BIT(13) /* Can do 100mbps, half-duplex */
  98. #define FGMAC_PHY_MII_SR_100FULL BIT(14) /* Can do 100mbps, full-duplex */
  99. #define FGMAC_PHY_MII_SR_100BASE4 BIT(15) /* Can do 100mbps, 4k packets */
  100. /* MII_STAT1000 masks */
  101. #define FGMAC_PHY_MII_1000BTSR_MSCF BIT(15) /* Master/Slave Configuration Fault */
  102. #define FGMAC_PHY_MII_1000BTSR_MSCR BIT(14) /* Master/Slave Configuration Resolution */
  103. #define FGMAC_PHY_MII_1000BTSR_LRS BIT(13) /* Local Receiver Status */
  104. #define FGMAC_PHY_MII_1000BTSR_RRS BIT(12) /* Remote Receiver Status */
  105. #define FGMAC_PHY_MII_1000BTSR_1000FD BIT(11) /* Full Duplex Capability */
  106. #define FGMAC_PHY_MII_1000BTSR_1000HD BIT(10) /* Half Duplex Capability */
  107. #define FGMAC_PHY_MII_1000BTSR_IDLE_ERR_CNT GENMASK(7, 0) /* MSB of Idle Error Counter */
  108. /* Link partner ability register. */
  109. #define FGMAC_PHY_MII_LPA_SELECT GENMASK(4, 0) /* Selector Field */
  110. #define FGMAC_PHY_MII_LPA_10HALF BIT(5) /* 10BASE-T half-duplex capable */
  111. #define FGMAC_PHY_MII_LPA_10FULL BIT(6) /* 10BASE-T full-duplex capable */
  112. #define FGMAC_PHY_MII_LPA_1000TXHALF BIT(7) /* 100BASE-TX half-duplex capable */
  113. #define FGMAC_PHY_MII_LPA_1000TXFULL BIT(8) /* 100BASE-TX full-duplex capable */
  114. #define FGMAC_PHY_MII_LPA_T4 BIT(9) /* 100BASE-T4 capable */
  115. #define FGMAC_PHY_MII_LPA_PAUSE BIT(10) /* capable of pause operation */
  116. #define FGMAC_PHY_MII_LPA_ASY_PAUSE BIT(11) /* asymmetric pause */
  117. #define FGMAC_PHY_MII_LPA_REMOTE_FAULT BIT(13) /* Remote Fault */
  118. #define FGMAC_PHY_MII_LPA_ACK BIT(14) /* Acknowledge */
  119. #define FGMAC_PHY_MII_LPA_NEXT_PAGE BIT(15) /* capable of next page */
  120. /* Expansion register for auto-negotiation. */
  121. #define FGMAC_PHY_MII_ESTATUS_1000_XFULL BIT(15) /* Can do 1000BX Full */
  122. #define FGMAC_PHY_MII_ESTATUS_1000_XHALF BIT(14) /* Can do 1000BX Half */
  123. #define FGMAC_PHY_MII_ESTATUS_1000_TFULL BIT(13) /* Can do 1000BT Full */
  124. #define FGMAC_PHY_MII_ESTATUS_1000_THALF BIT(12) /* Can do 1000BT Half */
  125. #define FGMAC_PHY_MII_ESTATUS_MASK (FGMAC_PHY_MII_ESTATUS_1000_XFULL | FGMAC_PHY_MII_ESTATUS_1000_XHALF | \
  126. FGMAC_PHY_MII_ESTATUS_1000_TFULL | FGMAC_PHY_MII_ESTATUS_1000_THALF)
  127. #define FGMAC_PHY_MII_ESTATUS_FULL_MASK (FGMAC_PHY_MII_ESTATUS_1000_XFULL | FGMAC_PHY_MII_ESTATUS_1000_TFULL)
  128. #define FGMAC_PHY_SPECIFIC_STATUS_SPEED_MASK GENMASK(15, 14)
  129. #define FGMAC_PHY_SPECIFIC_STATUS_SPEED_1000M (2L << 14)
  130. #define FGMAC_PHY_SPECIFIC_STATUS_SPEED_100M (1L << 14)
  131. #define FGMAC_PHY_SPECIFIC_STATUS_SPEED_10M (0L << 14)
  132. #define FGMAC_PHY_SPECIFIC_STATUS_DUPLEX_MASK BIT(13)
  133. enum
  134. {
  135. FGMAC_PHY_AUTONEGOTIATION_DISABLE = 0,
  136. FGMAC_PHY_AUTONEGOTIATION_ENABLE
  137. };
  138. enum
  139. {
  140. FGMAC_PHY_MODE_HALFDUPLEX = 0,
  141. FGMAC_PHY_MODE_FULLDUPLEX = 1
  142. };
  143. /* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
  144. enum
  145. {
  146. FGMAC_PHY_SPEED_10 = 10,
  147. FGMAC_PHY_SPEED_100 = 100,
  148. FGMAC_PHY_SPEED_1000 = 1000,
  149. FGMAC_PHY_SPEED_2500 = 2500,
  150. FGMAC_PHY_SPEED_10000 = 10000
  151. };
  152. enum
  153. {
  154. FGMAC_PHY_MII_ADDR_CR_60_100MHZ = (0b0000),
  155. FGMAC_PHY_MII_ADDR_CR_100_150MHZ = (0b0001),
  156. FGMAC_PHY_MII_ADDR_CR_23_35MHZ = (0b0010),
  157. FGMAC_PHY_MII_ADDR_CR_35_60MHZ = (0b0011),
  158. FGMAC_PHY_MII_ADDR_CR_150_250MHZ = (0b0100),
  159. FGMAC_PHY_MII_ADDR_CR_250_300MHZ = (0b0101)
  160. };
  161. /**************************** Type Definitions *******************************/
  162. /**
  163. * This typedef contains driver instance data. The user is required to allocate a
  164. * variable of this type for every device in the system. A pointer
  165. * to a variable of this type is then passed to the driver API functions.
  166. */
  167. /************************** Variable Definitions *****************************/
  168. /***************** Macros (Inline Functions) Definitions *********************/
  169. /************************** Function Prototypes ******************************/
  170. /* init phy device */
  171. FError FGmacPhyCfgInitialize(FGmac *instance_p);
  172. /* write phy register */
  173. FError FGmacWritePhyReg(FGmac *instance_p, u32 phy_address, u16 phy_reg, u16 phy_reg_val);
  174. /* read phy register */
  175. FError FGmacReadPhyReg(FGmac *instance_p, u32 phy_address, u16 phy_reg, u16 *phy_reg_val_p);
  176. FError FGmacPhyCfgDeInitialize(FGmac *instance_p);
  177. FError FGmacPhyAwaken(FGmac *instance_p);
  178. #ifdef __cplusplus
  179. }
  180. #endif
  181. #endif