|
| 1 | +/** |
| 2 | + * @file |
| 3 | + * |
| 4 | + * @brief Public APIs for MDIO drivers. |
| 5 | + */ |
| 6 | + |
| 7 | +/* |
| 8 | + * Copyright (c) 2021 IP-Logix Inc. |
| 9 | + * |
| 10 | + * SPDX-License-Identifier: Apache-2.0 |
| 11 | + */ |
| 12 | +#ifndef ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ |
| 13 | +#define ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ |
| 14 | + |
| 15 | +/** |
| 16 | + * @brief MDIO Interface |
| 17 | + * @defgroup mdio_interface MDIO Interface |
| 18 | + * @ingroup io_interfaces |
| 19 | + * @{ |
| 20 | + */ |
| 21 | +#include <zephyr/types.h> |
| 22 | +#include <device.h> |
| 23 | + |
| 24 | +#ifdef __cplusplus |
| 25 | +extern "C" { |
| 26 | +#endif |
| 27 | + |
| 28 | +/** |
| 29 | + * @cond INTERNAL_HIDDEN |
| 30 | + * |
| 31 | + * These are for internal use only, so skip these in |
| 32 | + * public documentation. |
| 33 | + */ |
| 34 | + |
| 35 | +/** Order of items in this enum must match the `protocol` dts binding */ |
| 36 | +enum MDIO_PROTOCOL { |
| 37 | + CLAUSE_22 = 0, |
| 38 | + CLAUSE_45 = 1, |
| 39 | + MICREL_SMI = 2, |
| 40 | +}; |
| 41 | + |
| 42 | +__subsystem struct mdio_driver_api { |
| 43 | + /** Enable the MDIO bus device */ |
| 44 | + void (*bus_enable)(const struct device *dev); |
| 45 | + |
| 46 | + /** Disable the MDIO bus device */ |
| 47 | + void (*bus_disable)(const struct device *dev); |
| 48 | + |
| 49 | + /** Read data from MDIO bus */ |
| 50 | + int (*read)(const struct device *dev, uint8_t prtad, uint8_t devad, |
| 51 | + uint16_t *data); |
| 52 | + |
| 53 | + /** Write data to MDIO bus */ |
| 54 | + int (*write)(const struct device *dev, uint8_t prtad, uint8_t devad, |
| 55 | + uint16_t data); |
| 56 | +}; |
| 57 | +/** |
| 58 | + * @endcond |
| 59 | + */ |
| 60 | + |
| 61 | +/** |
| 62 | + * @brief Enable MDIO bus |
| 63 | + * |
| 64 | + * @param[in] dev Pointer to the device structure for the controller |
| 65 | + * |
| 66 | + */ |
| 67 | +__syscall void mdio_bus_enable(const struct device *dev); |
| 68 | + |
| 69 | +static inline void z_impl_mdio_bus_enable(const struct device *dev) |
| 70 | +{ |
| 71 | + const struct mdio_driver_api *api = |
| 72 | + (const struct mdio_driver_api *)dev->api; |
| 73 | + |
| 74 | + return api->bus_enable(dev); |
| 75 | +} |
| 76 | + |
| 77 | +/** |
| 78 | + * @brief Disable MDIO bus and tri-state drivers |
| 79 | + * |
| 80 | + * @param[in] dev Pointer to the device structure for the controller |
| 81 | + * |
| 82 | + */ |
| 83 | +__syscall void mdio_bus_disable(const struct device *dev); |
| 84 | + |
| 85 | +static inline void z_impl_mdio_bus_disable(const struct device *dev) |
| 86 | +{ |
| 87 | + const struct mdio_driver_api *api = |
| 88 | + (const struct mdio_driver_api *)dev->api; |
| 89 | + |
| 90 | + return api->bus_disable(dev); |
| 91 | +} |
| 92 | + |
| 93 | +/** |
| 94 | + * @brief Read from MDIO Bus |
| 95 | + * |
| 96 | + * This routine provides a generic interface to perform a read on the |
| 97 | + * MDIO bus. |
| 98 | + * |
| 99 | + * @param[in] dev Pointer to the device structure for the controller |
| 100 | + * @param[in] prtad Port address |
| 101 | + * @param[in] devad Device address |
| 102 | + * @param data Pointer to receive read data |
| 103 | + * |
| 104 | + * @retval 0 If successful. |
| 105 | + * @retval -EIO General input / output error. |
| 106 | + * @retval -ETIMEDOUT If transaction timedout on the bus |
| 107 | + */ |
| 108 | +__syscall int mdio_read(const struct device *dev, uint8_t prtad, uint8_t devad, |
| 109 | + uint16_t *data); |
| 110 | + |
| 111 | +static inline int z_impl_mdio_read(const struct device *dev, uint8_t prtad, |
| 112 | + uint8_t devad, uint16_t *data) |
| 113 | +{ |
| 114 | + const struct mdio_driver_api *api = |
| 115 | + (const struct mdio_driver_api *)dev->api; |
| 116 | + |
| 117 | + return api->read(dev, prtad, devad, data); |
| 118 | +} |
| 119 | + |
| 120 | + |
| 121 | +/** |
| 122 | + * @brief Write to MDIO bus |
| 123 | + * |
| 124 | + * This routine provides a generic interface to perform a write on the |
| 125 | + * MDIO bus. |
| 126 | + * |
| 127 | + * @param[in] dev Pointer to the device structure for the controller |
| 128 | + * @param[in] prtad Port address |
| 129 | + * @param[in] devad Device address |
| 130 | + * @param[in] data Data to write |
| 131 | + * |
| 132 | + * @retval 0 If successful. |
| 133 | + * @retval -EIO General input / output error. |
| 134 | + * @retval -ETIMEDOUT If transaction timedout on the bus |
| 135 | + */ |
| 136 | +__syscall int mdio_write(const struct device *dev, uint8_t prtad, uint8_t devad, |
| 137 | + uint16_t data); |
| 138 | + |
| 139 | +static inline int z_impl_mdio_write(const struct device *dev, uint8_t prtad, |
| 140 | + uint8_t devad, uint16_t data) |
| 141 | +{ |
| 142 | + const struct mdio_driver_api *api = |
| 143 | + (const struct mdio_driver_api *)dev->api; |
| 144 | + |
| 145 | + return api->write(dev, prtad, devad, data); |
| 146 | +} |
| 147 | + |
| 148 | +#ifdef __cplusplus |
| 149 | +} |
| 150 | +#endif |
| 151 | + |
| 152 | +/** |
| 153 | + * @} |
| 154 | + */ |
| 155 | + |
| 156 | +#include <syscalls/mdio.h> |
| 157 | + |
| 158 | +#endif /* ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ */ |
0 commit comments