Zephyr API Documentation  3.6.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
mdio.h
Go to the documentation of this file.
1
7/*
8 * Copyright (c) 2021 IP-Logix Inc.
9 * Copyright 2023 NXP
10 *
11 * SPDX-License-Identifier: Apache-2.0
12 */
13#ifndef ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
14#define ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
15
22#include <zephyr/types.h>
23#include <zephyr/device.h>
24#include <errno.h>
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
36__subsystem struct mdio_driver_api {
38 void (*bus_enable)(const struct device *dev);
39
41 void (*bus_disable)(const struct device *dev);
42
44 int (*read)(const struct device *dev, uint8_t prtad, uint8_t regad,
45 uint16_t *data);
46
48 int (*write)(const struct device *dev, uint8_t prtad, uint8_t regad,
49 uint16_t data);
50
52 int (*read_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
53 uint16_t regad, uint16_t *data);
54
56 int (*write_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
57 uint16_t regad, uint16_t data);
58};
69__syscall void mdio_bus_enable(const struct device *dev);
70
71static inline void z_impl_mdio_bus_enable(const struct device *dev)
72{
73 const struct mdio_driver_api *api =
74 (const struct mdio_driver_api *)dev->api;
75
76 api->bus_enable(dev);
77}
78
85__syscall void mdio_bus_disable(const struct device *dev);
86
87static inline void z_impl_mdio_bus_disable(const struct device *dev)
88{
89 const struct mdio_driver_api *api =
90 (const struct mdio_driver_api *)dev->api;
91
92 api->bus_disable(dev);
93}
94
111__syscall int mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad,
112 uint16_t *data);
113
114static inline int z_impl_mdio_read(const struct device *dev, uint8_t prtad,
115 uint8_t regad, uint16_t *data)
116{
117 const struct mdio_driver_api *api =
118 (const struct mdio_driver_api *)dev->api;
119
120 if (api->read == NULL) {
121 return -ENOSYS;
122 }
123
124 return api->read(dev, prtad, regad, data);
125}
126
127
144__syscall int mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad,
145 uint16_t data);
146
147static inline int z_impl_mdio_write(const struct device *dev, uint8_t prtad,
148 uint8_t regad, uint16_t data)
149{
150 const struct mdio_driver_api *api =
151 (const struct mdio_driver_api *)dev->api;
152
153 if (api->write == NULL) {
154 return -ENOSYS;
155 }
156
157 return api->write(dev, prtad, regad, data);
158}
159
177__syscall int mdio_read_c45(const struct device *dev, uint8_t prtad,
178 uint8_t devad, uint16_t regad, uint16_t *data);
179
180static inline int z_impl_mdio_read_c45(const struct device *dev, uint8_t prtad,
181 uint8_t devad, uint16_t regad,
182 uint16_t *data)
183{
184 const struct mdio_driver_api *api =
185 (const struct mdio_driver_api *)dev->api;
186
187 if (api->read_c45 == NULL) {
188 return -ENOSYS;
189 }
190
191 return api->read_c45(dev, prtad, devad, regad, data);
192}
193
211__syscall int mdio_write_c45(const struct device *dev, uint8_t prtad,
212 uint8_t devad, uint16_t regad, uint16_t data);
213
214static inline int z_impl_mdio_write_c45(const struct device *dev, uint8_t prtad,
215 uint8_t devad, uint16_t regad,
216 uint16_t data)
217{
218 const struct mdio_driver_api *api =
219 (const struct mdio_driver_api *)dev->api;
220
221 if (api->write_c45 == NULL) {
222 return -ENOSYS;
223 }
224
225 return api->write_c45(dev, prtad, devad, regad, data);
226}
227
228#ifdef __cplusplus
229}
230#endif
231
236#include <syscalls/mdio.h>
237
238#endif /* ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ */
System error numbers.
int mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad, uint16_t data)
Write to MDIO bus.
void mdio_bus_enable(const struct device *dev)
Enable MDIO bus.
int mdio_read_c45(const struct device *dev, uint8_t prtad, uint8_t devad, uint16_t regad, uint16_t *data)
Read from MDIO Bus using Clause 45 access.
void mdio_bus_disable(const struct device *dev)
Disable MDIO bus and tri-state drivers.
int mdio_write_c45(const struct device *dev, uint8_t prtad, uint8_t devad, uint16_t regad, uint16_t data)
Write to MDIO bus using Clause 45 access.
int mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad, uint16_t *data)
Read from MDIO Bus.
#define ENOSYS
Function not implemented.
Definition: errno.h:83
__UINT8_TYPE__ uint8_t
Definition: stdint.h:88
__UINT16_TYPE__ uint16_t
Definition: stdint.h:89
Runtime device structure (in ROM) per driver instance.
Definition: device.h:399
const void * api
Address of the API structure exposed by the device instance.
Definition: device.h:405