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