fsl_phy.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /*
  2. * Copyright (c) 2016, Freescale Semiconductor, Inc.
  3. * Copyright 2016-2017 NXP
  4. *
  5. * Redistribution and use in source and binary forms, with or without modification,
  6. * are permitted provided that the following conditions are met:
  7. *
  8. * o Redistributions of source code must retain the above copyright notice, this list
  9. * of conditions and the following disclaimer.
  10. *
  11. * o Redistributions in binary form must reproduce the above copyright notice, this
  12. * list of conditions and the following disclaimer in the documentation and/or
  13. * other materials provided with the distribution.
  14. *
  15. * o Neither the name of the copyright holder nor the names of its
  16. * contributors may be used to endorse or promote products derived from this
  17. * software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  20. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  21. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  22. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
  23. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  24. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  25. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
  26. * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  27. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  28. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  29. */
  30. #ifndef _FSL_PHY_H_
  31. #define _FSL_PHY_H_
  32. #include "fsl_enet.h"
  33. /*!
  34. * @addtogroup phy_driver
  35. * @{
  36. */
  37. /*******************************************************************************
  38. * Definitions
  39. ******************************************************************************/
  40. /*! @brief PHY driver version */
  41. #define FSL_PHY_DRIVER_VERSION (MAKE_VERSION(2, 0, 0)) /*!< Version 2.0.0. */
  42. /*! @brief Defines the PHY registers. */
  43. #define PHY_BASICCONTROL_REG 0x00U /*!< The PHY basic control register. */
  44. #define PHY_BASICSTATUS_REG 0x01U /*!< The PHY basic status register. */
  45. #define PHY_ID1_REG 0x02U /*!< The PHY ID one register. */
  46. #define PHY_ID2_REG 0x03U /*!< The PHY ID two register. */
  47. #define PHY_AUTONEG_ADVERTISE_REG 0x04U /*!< The PHY auto-negotiate advertise register. */
  48. #define PHY_SEPCIAL_CONTROL_REG 0x1FU /*!< The PHY control two register. */
  49. #define PHY_CONTROL_ID1 0x07U /*!< The PHY ID1*/
  50. /*! @brief Defines the mask flag in basic control register. */
  51. #define PHY_BCTL_DUPLEX_MASK 0x0100U /*!< The PHY duplex bit mask. */
  52. #define PHY_BCTL_RESTART_AUTONEG_MASK 0x0200U /*!< The PHY restart auto negotiation mask. */
  53. #define PHY_BCTL_AUTONEG_MASK 0x1000U /*!< The PHY auto negotiation bit mask. */
  54. #define PHY_BCTL_SPEED_MASK 0x2000U /*!< The PHY speed bit mask. */
  55. #define PHY_BCTL_LOOP_MASK 0x4000U /*!< The PHY loop bit mask. */
  56. #define PHY_BCTL_RESET_MASK 0x8000U /*!< The PHY reset bit mask. */
  57. /*!@brief Defines the mask flag of operation mode in special control register*/
  58. #define PHY_SPECIALCTL_AUTONEGDONE_MASK 0x1000U /*!< The PHY auto-negotiation complete mask. */
  59. #define PHY_SPECIALCTL_DUPLEX_MASK 0x0010U /*!< The PHY duplex mask. */
  60. #define PHY_SPECIALCTL_100SPEED_MASK 0x0008U /*!< The PHY speed mask. */
  61. #define PHY_SPECIALCTL_10SPEED_MASK 0x0004U /*!< The PHY speed mask. */
  62. #define PHY_SPECIALCTL_SPEEDUPLX_MASK 0x001cU /*!< The PHY speed and duplex mask. */
  63. /*! @brief Defines the mask flag in basic status register. */
  64. #define PHY_BSTATUS_LINKSTATUS_MASK 0x0004U /*!< The PHY link status mask. */
  65. /*! @brief Defines the mask flag in PHY auto-negotiation advertise register. */
  66. #define PHY_ALL_CAPABLE_MASK 0x1e0U
  67. /*! @brief Defines the PHY status. */
  68. enum _phy_status
  69. {
  70. kStatus_PHY_SMIVisitTimeout = MAKE_STATUS(kStatusGroup_PHY, 0), /*!< ENET PHY SMI visit timeout. */
  71. };
  72. /*! @brief Defines the PHY link speed. This is align with the speed for ENET MAC. */
  73. typedef enum _phy_speed {
  74. kPHY_Speed10M = 0U, /*!< ENET PHY 10M speed. */
  75. kPHY_Speed100M /*!< ENET PHY 100M speed. */
  76. } phy_speed_t;
  77. /*! @brief Defines the PHY link duplex. */
  78. typedef enum _phy_duplex {
  79. kPHY_HalfDuplex = 0U, /*!< ENET PHY half duplex. */
  80. kPHY_FullDuplex /*!< ENET PHY full duplex. */
  81. } phy_duplex_t;
  82. /*******************************************************************************
  83. * API
  84. ******************************************************************************/
  85. #if defined(__cplusplus)
  86. extern "C" {
  87. #endif
  88. /*!
  89. * @name PHY Driver
  90. * @{
  91. */
  92. /*!
  93. * @brief Initializes PHY.
  94. *
  95. * This function initialize the SMI interface and initialize PHY.
  96. * The SMI is the MII management interface between PHY and MAC, which should be
  97. * firstly initialized before any other operation for PHY.
  98. *
  99. * @param base ENET peripheral base address.
  100. * @param phyAddr The PHY address.
  101. * @param srcClock_Hz The module clock frequency - system clock for MII management interface - SMI.
  102. * @retval kStatus_Success PHY initialize success
  103. * @retval kStatus_Fail PHY initialize fail
  104. */
  105. status_t PHY_Init(ENET_Type *base, uint32_t phyAddr, uint32_t srcClock_Hz);
  106. /*!
  107. * @brief PHY Write function. This function write data over the SMI to
  108. * the specified PHY register. This function is called by all PHY interfaces.
  109. *
  110. * @param base ENET peripheral base address.
  111. * @param phyAddr The PHY address.
  112. * @param phyReg The PHY register.
  113. * @param data The data written to the PHY register.
  114. * @retval kStatus_Success PHY write success
  115. * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out
  116. */
  117. status_t PHY_Write(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t data);
  118. /*!
  119. * @brief PHY Read function. This interface read data over the SMI from the
  120. * specified PHY register. This function is called by all PHY interfaces.
  121. *
  122. * @param base ENET peripheral base address.
  123. * @param phyAddr The PHY address.
  124. * @param phyReg The PHY register.
  125. * @param dataPtr The address to store the data read from the PHY register.
  126. * @retval kStatus_Success PHY read success
  127. * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out
  128. */
  129. status_t PHY_Read(ENET_Type *base, uint32_t phyAddr, uint32_t phyReg, uint32_t *dataPtr);
  130. /*!
  131. * @brief Gets the PHY link status.
  132. *
  133. * @param base ENET peripheral base address.
  134. * @param phyAddr The PHY address.
  135. * @param status The link up or down status of the PHY.
  136. * - true the link is up.
  137. * - false the link is down.
  138. * @retval kStatus_Success PHY get link status success
  139. * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out
  140. */
  141. status_t PHY_GetLinkStatus(ENET_Type *base, uint32_t phyAddr, bool *status);
  142. /*!
  143. * @brief Gets the PHY link speed and duplex.
  144. *
  145. * @param base ENET peripheral base address.
  146. * @param phyAddr The PHY address.
  147. * @param speed The address of PHY link speed.
  148. * @param duplex The link duplex of PHY.
  149. * @retval kStatus_Success PHY get link speed and duplex success
  150. * @retval kStatus_PHY_SMIVisitTimeout PHY SMI visit time out
  151. */
  152. status_t PHY_GetLinkSpeedDuplex(ENET_Type *base, uint32_t phyAddr, phy_speed_t *speed, phy_duplex_t *duplex);
  153. /* @} */
  154. #if defined(__cplusplus)
  155. }
  156. #endif
  157. /*! @}*/
  158. #endif /* _FSL_PHY_H_ */