1 /*
2  * Copyright 2022 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*****************************************************************************
8  * PHY RTL8201 driver change log
9  *****************************************************************************/
10 
11 /*!
12 @page driver_log Driver Change Log
13 
14 @section phyrtl8201 PHYRTL8201
15   The current PHYRTL8201 driver version is 2.0.0.
16 
17   - 2.0.0
18     - Initial version.
19 */
20 
21 #ifndef _FSL_PHYRTL8201_H_
22 #define _FSL_PHYRTL8201_H_
23 
24 #include "fsl_phy.h"
25 
26 /*!
27  * @addtogroup phy_driver
28  * @{
29  */
30 
31 /*******************************************************************************
32  * Definitions
33  ******************************************************************************/
34 
35 /*! @brief PHY driver version */
36 #define FSL_PHY_DRIVER_VERSION (MAKE_VERSION(2, 0, 0))
37 
38 /*! @brief PHY operations structure. */
39 extern const phy_operations_t phyrtl8201_ops;
40 
41 typedef struct _phy_rtl8201_resource
42 {
43     mdioWrite write;
44     mdioRead read;
45     mdioWriteExt writeExt;
46     mdioReadExt readExt;
47 } phy_rtl8201_resource_t;
48 
49 /*******************************************************************************
50  * API
51  ******************************************************************************/
52 
53 #if defined(__cplusplus)
54 extern "C" {
55 #endif
56 
57 /*!
58  * @name PHY Driver
59  * @{
60  */
61 
62 /*!
63  * @brief Initializes PHY.
64  * This function initializes PHY.
65  *
66  * @param handle  PHY device handle.
67  * @param config  PHY configuration.
68  * @retval kStatus_Success  PHY initialization succeeds
69  * @retval kStatus_Fail  PHY initialization fails
70  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
71  */
72 status_t PHY_RTL8201_Init(phy_handle_t *handle, const phy_config_t *config);
73 
74 /*!
75  * @brief PHY Write function.
76  * This function writes data over the MDIO to the specified PHY register.
77  *
78  * @param handle  PHY device handle.
79  * @param phyReg  The PHY register.
80  * @param data    The data written to the PHY register.
81  * @retval kStatus_Success     PHY write success
82  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
83  */
84 status_t PHY_RTL8201_Write(phy_handle_t *handle, uint8_t phyReg, uint16_t data);
85 
86 /*!
87  * @brief PHY Read function.
88  * This interface reads data over the MDIO from the specified PHY register.
89  *
90  * @param handle  PHY device handle.
91  * @param phyReg  The PHY register.
92  * @param pData   The address to store the data read from the PHY register.
93  * @retval kStatus_Success  PHY read success
94  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
95  */
96 status_t PHY_RTL8201_Read(phy_handle_t *handle, uint8_t phyReg, uint16_t *pData);
97 
98 /*!
99  * @brief Gets the PHY auto-negotiation status.
100  *
101  * @param handle  PHY device handle.
102  * @param status  The auto-negotiation status of the PHY.
103  *         - true the auto-negotiation is over.
104  *         - false the auto-negotiation is on-going or not started.
105  * @retval kStatus_Success  PHY gets status success
106  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
107  */
108 status_t PHY_RTL8201_GetAutoNegotiationStatus(phy_handle_t *handle, bool *status);
109 
110 /*!
111  * @brief Gets the PHY link status.
112  *
113  * @param handle   PHY device handle.
114  * @param status   The link up or down status of the PHY.
115  *         - true the link is up.
116  *         - false the link is down.
117  * @retval kStatus_Success   PHY gets link status success
118  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
119  */
120 status_t PHY_RTL8201_GetLinkStatus(phy_handle_t *handle, bool *status);
121 
122 /*!
123  * @brief Gets the PHY link speed and duplex.
124  *
125  * @brief This function gets the speed and duplex mode of PHY. User can give one of speed
126  * and duplex address paramter and set the other as NULL if only wants to get one of them.
127  *
128  * @param handle   PHY device handle.
129  * @param speed    The address of PHY link speed.
130  * @param duplex   The link duplex of PHY.
131  * @retval kStatus_Success   PHY gets link speed and duplex success
132  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
133  */
134 status_t PHY_RTL8201_GetLinkSpeedDuplex(phy_handle_t *handle, phy_speed_t *speed, phy_duplex_t *duplex);
135 
136 /*!
137  * @brief Sets the PHY link speed and duplex.
138  *
139  * @param handle   PHY device handle.
140  * @param speed    Specified PHY link speed.
141  * @param duplex   Specified PHY link duplex.
142  * @retval kStatus_Success   PHY gets status success
143  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
144  */
145 status_t PHY_RTL8201_SetLinkSpeedDuplex(phy_handle_t *handle, phy_speed_t speed, phy_duplex_t duplex);
146 
147 /*!
148  * @brief Enables/disables PHY loopback.
149  *
150  * @param handle   PHY device handle.
151  * @param mode     The loopback mode to be enabled, please see "phy_loop_t".
152  * All loopback modes should not be set together, when one loopback mode is set
153  * another should be disabled.
154  * @param speed    PHY speed for loopback mode.
155  * @param enable   True to enable, false to disable.
156  * @retval kStatus_Success  PHY loopback success
157  * @retval kStatus_PHY_MDIOVisitTimeout  PHY MDIO visit time out
158  */
159 status_t PHY_RTL8201_EnableLoopback(phy_handle_t *handle, phy_loop_t mode, phy_speed_t speed, bool enable);
160 
161 /* @} */
162 
163 #if defined(__cplusplus)
164 }
165 #endif
166 
167 /*! @}*/
168 
169 #endif /* _FSL_PHYRTL8201_H_ */
170