LCOV - code coverage report
Current view: top level - zephyr/drivers - mdio.h Coverage Total Hit
Test: new.info Lines: 100.0 % 7 7
Test Date: 2025-09-05 20:47:19

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

Generated by: LCOV version 2.0-1