1 /*
2  * Copyright 2020-2023 NXP
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 /*****************************************************************************
8  * PHY RTL8211F driver change log
9  *****************************************************************************/
10 
11 /*!
12 @page driver_log Driver Change Log
13 
14 @section phyrtl8211 PHYRTL8211F
15   The current PHYRTL8211F driver version is 2.0.0.
16 
17   - 2.0.0
18     - Initial version.
19 */
20 
21 #ifndef _FSL_PHYRTL8211F_H_
22 #define _FSL_PHYRTL8211F_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 typedef struct _phy_rtl8211f_resource
39 {
40     mdioWrite write;
41     mdioRead read;
42 } phy_rtl8211f_resource_t;
43 
44 extern const phy_operations_t phyrtl8211f_ops;
45 
46 /*******************************************************************************
47  * API
48  ******************************************************************************/
49 
50 #if defined(__cplusplus)
51 extern "C" {
52 #endif
53 
54 /*!
55  * @name PHY Driver
56  * @{
57  */
58 
59 /*!
60  * @brief Initializes PHY.
61  * This function initializes PHY.
62  *
63  * @param handle  PHY device handle.
64  * @param config  PHY configuration.
65  * @retval kStatus_Success  PHY initialization succeeds
66  * @retval kStatus_Fail  PHY initialization fails
67  * @retval kStatus_Timeout  PHY MDIO visit time out
68  */
69 status_t PHY_RTL8211F_Init(phy_handle_t *handle, const phy_config_t *config);
70 
71 /*!
72  * @brief PHY Write function.
73  * This function writes data over the MDIO to the specified PHY register.
74  *
75  * @param handle  PHY device handle.
76  * @param phyReg  The PHY register.
77  * @param data    The data written to the PHY register.
78  * @retval kStatus_Success     PHY write success
79  * @retval kStatus_Timeout  PHY MDIO visit time out
80  */
81 status_t PHY_RTL8211F_Write(phy_handle_t *handle, uint8_t phyReg, uint16_t data);
82 
83 /*!
84  * @brief PHY Read function.
85  * This interface reads data over the MDIO from the specified PHY register.
86  *
87  * @param handle  PHY device handle.
88  * @param phyReg  The PHY register.
89  * @param pData   The address to store the data read from the PHY register.
90  * @retval kStatus_Success  PHY read success
91  * @retval kStatus_Timeout  PHY MDIO visit time out
92  */
93 status_t PHY_RTL8211F_Read(phy_handle_t *handle, uint8_t phyReg, uint16_t *pData);
94 
95 /*!
96  * @brief Gets the PHY auto-negotiation status.
97  *
98  * @param handle  PHY device handle.
99  * @param status  The auto-negotiation status of the PHY.
100  *         - true the auto-negotiation is over.
101  *         - false the auto-negotiation is on-going or not started.
102  * @retval kStatus_Success  PHY gets status success
103  * @retval kStatus_Timeout  PHY MDIO visit time out
104  */
105 status_t PHY_RTL8211F_GetAutoNegotiationStatus(phy_handle_t *handle, bool *status);
106 
107 /*!
108  * @brief Gets the PHY link status.
109  *
110  * @param handle   PHY device handle.
111  * @param status   The link up or down status of the PHY.
112  *         - true the link is up.
113  *         - false the link is down.
114  * @retval kStatus_Success   PHY gets link status success
115  * @retval kStatus_Timeout  PHY MDIO visit time out
116  */
117 status_t PHY_RTL8211F_GetLinkStatus(phy_handle_t *handle, bool *status);
118 
119 /*!
120  * @brief Gets the PHY link speed and duplex.
121  *
122  * @brief This function gets the speed and duplex mode of PHY. User can give one of speed
123  * and duplex address paramter and set the other as NULL if only wants to get one of them.
124  *
125  * @param handle   PHY device handle.
126  * @param speed    The address of PHY link speed.
127  * @param duplex   The link duplex of PHY.
128  * @retval kStatus_Success   PHY gets link speed and duplex success
129  * @retval kStatus_Timeout  PHY MDIO visit time out
130  */
131 status_t PHY_RTL8211F_GetLinkSpeedDuplex(phy_handle_t *handle, phy_speed_t *speed, phy_duplex_t *duplex);
132 
133 /*!
134  * @brief Sets the PHY link speed and duplex.
135  *
136  * @param handle   PHY device handle.
137  * @param speed    Specified PHY link speed.
138  * @param duplex   Specified PHY link duplex.
139  * @retval kStatus_Success   PHY gets status success
140  * @retval kStatus_Timeout  PHY MDIO visit time out
141  */
142 status_t PHY_RTL8211F_SetLinkSpeedDuplex(phy_handle_t *handle, phy_speed_t speed, phy_duplex_t duplex);
143 
144 /*!
145  * @brief Enables/Disables PHY loopback.
146  *
147  * @param handle   PHY device handle.
148  * @param mode     The loopback mode to be enabled, please see "phy_loop_t".
149  * All loopback modes should not be set together, when one loopback mode is set
150  * another should be disabled.
151  * @param speed    PHY speed for loopback mode.
152  * @param enable   True to enable, false to disable.
153  * @retval kStatus_Success  PHY loopback success
154  * @retval kStatus_Timeout  PHY MDIO visit time out
155  */
156 status_t PHY_RTL8211F_EnableLoopback(phy_handle_t *handle, phy_loop_t mode, phy_speed_t speed, bool enable);
157 
158 /*!
159  * @brief Enables/Disables PHY link management interrupt.
160  *
161  * This function controls link status change interrupt.
162  *
163  * @param handle  PHY device handle.
164  * @param type    PHY interrupt type.
165  * @retval kStatus_Success  PHY enables/disables interrupt success
166  * @retval kStatus_Timeout  PHY MDIO visit time out
167  */
168 status_t PHY_RTL8211F_EnableLinkInterrupt(phy_handle_t *handle, phy_interrupt_type_t type);
169 
170 /*!
171  * @brief Clears PHY interrupt status.
172  *
173  * @param handle  PHY device handle.
174  * @retval kStatus_Success  PHY read and clear interrupt success
175  * @retval kStatus_Timeout  PHY MDIO visit time out
176  */
177 status_t PHY_RTL8211F_ClearInterrupt(phy_handle_t *handle);
178 
179 /* @} */
180 
181 #if defined(__cplusplus)
182 }
183 #endif
184 
185 /*! @}*/
186 
187 #endif /* _FSL_PHY_H_ */
188