1 /*
2 * Copyright 2020-2021 NXP
3 * All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7 #ifndef _FSL_MDIO_H_
8 #define _FSL_MDIO_H_
9
10 #include "fsl_common.h"
11
12 /*******************************************************************************
13 * Definitions
14 ******************************************************************************/
15
16 /*! @brief Defines the timeout macro. */
17 #if defined(MDIO_TIMEOUT_COUNT_NUMBER) && MDIO_TIMEOUT_COUNT_NUMBER
18 #define MDIO_TIMEOUT_COUNT MDIO_TIMEOUT_COUNT_NUMBER
19 #endif
20
21 /*! @brief Defines the PHY status. */
22 enum _mdio_status
23 {
24 kStatus_PHY_SMIVisitTimeout = MAKE_STATUS(kStatusGroup_PHY, 0), /*!< ENET PHY SMI visit timeout. */
25 };
26
27 typedef struct _mdio_operations mdio_operations_t;
28
29 /*! @brief MDIO resource. */
30 typedef struct _mdio_resource
31 {
32 void *base; /*!< ENET Ip register base. */
33 uint32_t csrClock_Hz; /*!< ENET CSR clock. */
34 } mdio_resource_t;
35
36 /*! @brief MDIO handle. */
37 typedef struct _mdio_handle
38 {
39 mdio_resource_t resource;
40 const mdio_operations_t *ops;
41 } mdio_handle_t;
42
43 /*! @brief Camera receiver operations. */
44 struct _mdio_operations
45 {
46 void (*mdioInit)(mdio_handle_t *handle); /*!< MDIO interface init. */
47 status_t (*mdioWrite)(mdio_handle_t *handle,
48 uint32_t phyAddr,
49 uint32_t devAddr,
50 uint32_t data); /*!< IEEE 802.3 Clause 22 MDIO write data. */
51 status_t (*mdioRead)(mdio_handle_t *handle,
52 uint32_t phyAddr,
53 uint32_t devAddr,
54 uint32_t *dataPtr); /*!< IEEE 802.3 Clause 22 MDIO read data. */
55 status_t (*mdioWriteExt)(mdio_handle_t *handle,
56 uint32_t phyAddr,
57 uint32_t devAddr,
58 uint32_t data); /*!< IEEE 802.3 Clause 45 MDIO write data. */
59 status_t (*mdioReadExt)(mdio_handle_t *handle,
60 uint32_t phyAddr,
61 uint32_t devAddr,
62 uint32_t *dataPtr); /*!< IEEE 802.3 Clause 45 MDIO read data. */
63 };
64
65 /*******************************************************************************
66 * API
67 ******************************************************************************/
68
69 #if defined(__cplusplus)
70 extern "C" {
71 #endif
72 /*!
73 * @name MDIO Driver
74 * @{
75 */
76
77 /*!
78 * @brief MDIO Write function. This function write data over the SMI to
79 * the specified MDIO register. This function is called by all MDIO interfaces.
80 *
81 * @param handle MDIO device handle.
82 * @retval kStatus_Success MDIO write success
83 * @retval kStatus_MDIO_SMIVisitTimeout MDIO SMI visit time out
84 */
MDIO_Init(mdio_handle_t * handle)85 static inline void MDIO_Init(mdio_handle_t *handle)
86 {
87 handle->ops->mdioInit(handle);
88 }
89
90 /*!
91 * @brief MDIO Write function. This function write data over the SMI to
92 * the specified MDIO register. This function is called by all MDIO interfaces.
93 *
94 * @param handle MDIO device handle.
95 * @param phyAddr MDIO PHY address handle.
96 * @param devAddr The PHY device register.
97 * @param data The data written to the MDIO register.
98 * @retval kStatus_Success MDIO write success
99 * @retval kStatus_MDIO_SMIVisitTimeout MDIO SMI visit time out
100 */
MDIO_Write(mdio_handle_t * handle,uint32_t phyAddr,uint32_t devAddr,uint32_t data)101 static inline status_t MDIO_Write(mdio_handle_t *handle, uint32_t phyAddr, uint32_t devAddr, uint32_t data)
102 {
103 return handle->ops->mdioWrite(handle, phyAddr, devAddr, data);
104 }
105
106 /*!
107 * @brief MDIO Read function. This interface read data over the SMI from the
108 * specified MDIO register. This function is called by all MDIO interfaces.
109 *
110 * @param handle MDIO device handle.
111 * @param phyAddr MDIO PHY address handle.
112 * @param devAddr The PHY device register.
113 * @param dataPtr The address to store the data read from the MDIO register.
114 * @retval kStatus_Success MDIO read success
115 * @retval kStatus_MDIO_SMIVisitTimeout MDIO SMI visit time out
116 */
MDIO_Read(mdio_handle_t * handle,uint32_t phyAddr,uint32_t devAddr,uint32_t * dataPtr)117 static inline status_t MDIO_Read(mdio_handle_t *handle, uint32_t phyAddr, uint32_t devAddr, uint32_t *dataPtr)
118 {
119 return handle->ops->mdioRead(handle, phyAddr, devAddr, dataPtr);
120 }
121
122 /* @} */
123
124 #if defined(__cplusplus)
125 }
126 #endif
127
128 #endif
129