Line data Source code
1 1 : /*
2 : * Copyright (c) 2021 IP-Logix Inc.
3 : * Copyright 2023 NXP
4 : *
5 : * SPDX-License-Identifier: Apache-2.0
6 : */
7 :
8 : /**
9 : * @file
10 : * @ingroup mdio_interface
11 : * @brief Main header file for MDIO (Management Data Input/Output) driver API.
12 : */
13 :
14 : #ifndef ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
15 : #define ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
16 :
17 : /**
18 : * @brief Interfaces for Management Data Input/Output (MDIO) controllers.
19 : * @defgroup mdio_interface MDIO
20 : * @ingroup io_interfaces
21 : * @{
22 : */
23 : #include <zephyr/types.h>
24 : #include <zephyr/device.h>
25 : #include <errno.h>
26 :
27 : #ifdef __cplusplus
28 : extern "C" {
29 : #endif
30 :
31 : /**
32 : * @cond INTERNAL_HIDDEN
33 : *
34 : * These are for internal use only, so skip these in
35 : * public documentation.
36 : */
37 : __subsystem struct mdio_driver_api {
38 : /** Enable the MDIO bus device */
39 : void (*bus_enable)(const struct device *dev);
40 :
41 : /** Disable the MDIO bus device */
42 : void (*bus_disable)(const struct device *dev);
43 :
44 : /** Read data from MDIO bus */
45 : int (*read)(const struct device *dev, uint8_t prtad, uint8_t regad,
46 : uint16_t *data);
47 :
48 : /** Write data to MDIO bus */
49 : int (*write)(const struct device *dev, uint8_t prtad, uint8_t regad,
50 : uint16_t data);
51 :
52 : /** Read data from MDIO bus using Clause 45 access */
53 : int (*read_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
54 : uint16_t regad, uint16_t *data);
55 :
56 : /** Write data to MDIO bus using Clause 45 access */
57 : int (*write_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
58 : uint16_t regad, uint16_t data);
59 : };
60 : /**
61 : * @endcond
62 : */
63 :
64 : /**
65 : * @brief Enable MDIO bus
66 : *
67 : * @param[in] dev Pointer to the device structure for the controller
68 : *
69 : */
70 1 : __syscall void mdio_bus_enable(const struct device *dev);
71 :
72 : static inline void z_impl_mdio_bus_enable(const struct device *dev)
73 : {
74 : if (DEVICE_API_GET(mdio, dev)->bus_enable != NULL) {
75 : DEVICE_API_GET(mdio, dev)->bus_enable(dev);
76 : }
77 : }
78 :
79 : /**
80 : * @brief Disable MDIO bus and tri-state drivers
81 : *
82 : * @param[in] dev Pointer to the device structure for the controller
83 : *
84 : */
85 1 : __syscall void mdio_bus_disable(const struct device *dev);
86 :
87 : static inline void z_impl_mdio_bus_disable(const struct device *dev)
88 : {
89 : if (DEVICE_API_GET(mdio, dev)->bus_disable != NULL) {
90 : DEVICE_API_GET(mdio, dev)->bus_disable(dev);
91 : }
92 : }
93 :
94 : /**
95 : * @brief Read from MDIO Bus
96 : *
97 : * This routine provides a generic interface to perform a read on the
98 : * MDIO bus.
99 : *
100 : * @param[in] dev Pointer to the device structure for the controller
101 : * @param[in] prtad Port address
102 : * @param[in] regad Register address
103 : * @param data Pointer to receive read data
104 : *
105 : * @retval 0 If successful.
106 : * @retval -EIO General input / output error.
107 : * @retval -ETIMEDOUT If transaction timedout on the bus
108 : * @retval -ENOSYS if read is not supported
109 : */
110 1 : __syscall int mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad,
111 : uint16_t *data);
112 :
113 : static inline int z_impl_mdio_read(const struct device *dev, uint8_t prtad,
114 : uint8_t regad, uint16_t *data)
115 : {
116 : if (DEVICE_API_GET(mdio, dev)->read == NULL) {
117 : return -ENOSYS;
118 : }
119 :
120 : return DEVICE_API_GET(mdio, dev)->read(dev, prtad, regad, data);
121 : }
122 :
123 :
124 : /**
125 : * @brief Write to MDIO bus
126 : *
127 : * This routine provides a generic interface to perform a write on the
128 : * MDIO bus.
129 : *
130 : * @param[in] dev Pointer to the device structure for the controller
131 : * @param[in] prtad Port address
132 : * @param[in] regad Register address
133 : * @param[in] data Data to write
134 : *
135 : * @retval 0 If successful.
136 : * @retval -EIO General input / output error.
137 : * @retval -ETIMEDOUT If transaction timedout on the bus
138 : * @retval -ENOSYS if write is not supported
139 : */
140 1 : __syscall int mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad,
141 : uint16_t data);
142 :
143 : static inline int z_impl_mdio_write(const struct device *dev, uint8_t prtad,
144 : uint8_t regad, uint16_t data)
145 : {
146 : if (DEVICE_API_GET(mdio, dev)->write == NULL) {
147 : return -ENOSYS;
148 : }
149 :
150 : return DEVICE_API_GET(mdio, dev)->write(dev, prtad, regad, data);
151 : }
152 :
153 : /**
154 : * @brief Read from MDIO Bus using Clause 45 access
155 : *
156 : * This routine provides an interface to perform a read on the MDIO bus using
157 : * IEEE 802.3 Clause 45 access.
158 : *
159 : * @param[in] dev Pointer to the device structure for the controller
160 : * @param[in] prtad Port address
161 : * @param[in] devad Device address
162 : * @param[in] regad Register address
163 : * @param data Pointer to receive read data
164 : *
165 : * @retval 0 If successful.
166 : * @retval -EIO General input / output error.
167 : * @retval -ETIMEDOUT If transaction timedout on the bus
168 : * @retval -ENOSYS if write using Clause 45 access is not supported
169 : */
170 1 : __syscall int mdio_read_c45(const struct device *dev, uint8_t prtad,
171 : uint8_t devad, uint16_t regad, uint16_t *data);
172 :
173 : static inline int z_impl_mdio_read_c45(const struct device *dev, uint8_t prtad,
174 : uint8_t devad, uint16_t regad,
175 : uint16_t *data)
176 : {
177 : if (DEVICE_API_GET(mdio, dev)->read_c45 == NULL) {
178 : return -ENOSYS;
179 : }
180 :
181 : return DEVICE_API_GET(mdio, dev)->read_c45(dev, prtad, devad, regad, data);
182 : }
183 :
184 : /**
185 : * @brief Write to MDIO bus using Clause 45 access
186 : *
187 : * This routine provides an interface to perform a write on the MDIO bus using
188 : * IEEE 802.3 Clause 45 access.
189 : *
190 : * @param[in] dev Pointer to the device structure for the controller
191 : * @param[in] prtad Port address
192 : * @param[in] devad Device address
193 : * @param[in] regad Register address
194 : * @param[in] data Data to write
195 : *
196 : * @retval 0 If successful.
197 : * @retval -EIO General input / output error.
198 : * @retval -ETIMEDOUT If transaction timedout on the bus
199 : * @retval -ENOSYS if write using Clause 45 access is not supported
200 : */
201 1 : __syscall int mdio_write_c45(const struct device *dev, uint8_t prtad,
202 : uint8_t devad, uint16_t regad, uint16_t data);
203 :
204 : static inline int z_impl_mdio_write_c45(const struct device *dev, uint8_t prtad,
205 : uint8_t devad, uint16_t regad,
206 : uint16_t data)
207 : {
208 : if (DEVICE_API_GET(mdio, dev)->write_c45 == NULL) {
209 : return -ENOSYS;
210 : }
211 :
212 : return DEVICE_API_GET(mdio, dev)->write_c45(dev, prtad, devad, regad, data);
213 : }
214 :
215 : #ifdef __cplusplus
216 : }
217 : #endif
218 :
219 : /**
220 : * @}
221 : */
222 :
223 : #include <zephyr/syscalls/mdio.h>
224 :
225 : #endif /* ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ */
|