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