2021-05-03 02:49:04 +02:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* @brief Public APIs for MDIO drivers.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2021 IP-Logix Inc.
|
2023-07-08 19:52:20 +02:00
|
|
|
* Copyright 2023 NXP
|
2021-05-03 02:49:04 +02:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
#ifndef ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
|
|
|
|
#define ZEPHYR_INCLUDE_DRIVERS_MDIO_H_
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief MDIO Interface
|
|
|
|
* @defgroup mdio_interface MDIO Interface
|
|
|
|
* @ingroup io_interfaces
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
#include <zephyr/types.h>
|
2022-04-21 06:07:09 +02:00
|
|
|
#include <zephyr/device.h>
|
2024-01-25 23:22:52 +01:00
|
|
|
#include <errno.h>
|
2021-05-03 02:49:04 +02:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @cond INTERNAL_HIDDEN
|
|
|
|
*
|
|
|
|
* These are for internal use only, so skip these in
|
|
|
|
* public documentation.
|
|
|
|
*/
|
|
|
|
__subsystem struct mdio_driver_api {
|
|
|
|
/** Enable the MDIO bus device */
|
|
|
|
void (*bus_enable)(const struct device *dev);
|
|
|
|
|
|
|
|
/** Disable the MDIO bus device */
|
|
|
|
void (*bus_disable)(const struct device *dev);
|
|
|
|
|
|
|
|
/** Read data from MDIO bus */
|
2023-07-08 19:52:20 +02:00
|
|
|
int (*read)(const struct device *dev, uint8_t prtad, uint8_t regad,
|
2021-05-03 02:49:04 +02:00
|
|
|
uint16_t *data);
|
|
|
|
|
|
|
|
/** Write data to MDIO bus */
|
2023-07-08 19:52:20 +02:00
|
|
|
int (*write)(const struct device *dev, uint8_t prtad, uint8_t regad,
|
2021-05-03 02:49:04 +02:00
|
|
|
uint16_t data);
|
2023-08-18 10:58:09 +02:00
|
|
|
|
|
|
|
/** Read data from MDIO bus using Clause 45 access */
|
|
|
|
int (*read_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
|
|
|
|
uint16_t regad, uint16_t *data);
|
|
|
|
|
|
|
|
/** Write data to MDIO bus using Clause 45 access */
|
|
|
|
int (*write_c45)(const struct device *dev, uint8_t prtad, uint8_t devad,
|
|
|
|
uint16_t regad, uint16_t data);
|
2021-05-03 02:49:04 +02:00
|
|
|
};
|
|
|
|
/**
|
|
|
|
* @endcond
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Enable MDIO bus
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
__syscall void mdio_bus_enable(const struct device *dev);
|
|
|
|
|
|
|
|
static inline void z_impl_mdio_bus_enable(const struct device *dev)
|
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
2024-04-22 18:03:42 +02:00
|
|
|
if (api->bus_enable != NULL) {
|
|
|
|
api->bus_enable(dev);
|
|
|
|
}
|
2021-05-03 02:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Disable MDIO bus and tri-state drivers
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
__syscall void mdio_bus_disable(const struct device *dev);
|
|
|
|
|
|
|
|
static inline void z_impl_mdio_bus_disable(const struct device *dev)
|
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
2024-04-22 18:03:42 +02:00
|
|
|
if (api->bus_disable != NULL) {
|
|
|
|
api->bus_disable(dev);
|
|
|
|
}
|
2021-05-03 02:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Read from MDIO Bus
|
|
|
|
*
|
|
|
|
* This routine provides a generic interface to perform a read on the
|
|
|
|
* MDIO bus.
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
* @param[in] prtad Port address
|
2023-07-08 19:52:20 +02:00
|
|
|
* @param[in] regad Register address
|
2021-05-03 02:49:04 +02:00
|
|
|
* @param data Pointer to receive read data
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval -EIO General input / output error.
|
|
|
|
* @retval -ETIMEDOUT If transaction timedout on the bus
|
2023-08-18 10:58:09 +02:00
|
|
|
* @retval -ENOSYS if read is not supported
|
2021-05-03 02:49:04 +02:00
|
|
|
*/
|
2023-07-08 19:52:20 +02:00
|
|
|
__syscall int mdio_read(const struct device *dev, uint8_t prtad, uint8_t regad,
|
2021-05-03 02:49:04 +02:00
|
|
|
uint16_t *data);
|
|
|
|
|
|
|
|
static inline int z_impl_mdio_read(const struct device *dev, uint8_t prtad,
|
2023-07-08 19:52:20 +02:00
|
|
|
uint8_t regad, uint16_t *data)
|
2021-05-03 02:49:04 +02:00
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
2023-08-18 10:58:09 +02:00
|
|
|
if (api->read == NULL) {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2023-07-08 19:52:20 +02:00
|
|
|
return api->read(dev, prtad, regad, data);
|
2021-05-03 02:49:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Write to MDIO bus
|
|
|
|
*
|
|
|
|
* This routine provides a generic interface to perform a write on the
|
|
|
|
* MDIO bus.
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
* @param[in] prtad Port address
|
2023-07-08 19:52:20 +02:00
|
|
|
* @param[in] regad Register address
|
2021-05-03 02:49:04 +02:00
|
|
|
* @param[in] data Data to write
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval -EIO General input / output error.
|
|
|
|
* @retval -ETIMEDOUT If transaction timedout on the bus
|
2023-08-18 10:58:09 +02:00
|
|
|
* @retval -ENOSYS if write is not supported
|
2021-05-03 02:49:04 +02:00
|
|
|
*/
|
2023-07-08 19:52:20 +02:00
|
|
|
__syscall int mdio_write(const struct device *dev, uint8_t prtad, uint8_t regad,
|
2021-05-03 02:49:04 +02:00
|
|
|
uint16_t data);
|
|
|
|
|
|
|
|
static inline int z_impl_mdio_write(const struct device *dev, uint8_t prtad,
|
2023-07-08 19:52:20 +02:00
|
|
|
uint8_t regad, uint16_t data)
|
2021-05-03 02:49:04 +02:00
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
2023-08-18 10:58:09 +02:00
|
|
|
if (api->write == NULL) {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
2023-07-08 19:52:20 +02:00
|
|
|
return api->write(dev, prtad, regad, data);
|
2021-05-03 02:49:04 +02:00
|
|
|
}
|
|
|
|
|
2023-08-18 10:58:09 +02:00
|
|
|
/**
|
|
|
|
* @brief Read from MDIO Bus using Clause 45 access
|
|
|
|
*
|
|
|
|
* This routine provides an interface to perform a read on the MDIO bus using
|
|
|
|
* IEEE 802.3 Clause 45 access.
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
* @param[in] prtad Port address
|
|
|
|
* @param[in] devad Device address
|
|
|
|
* @param[in] regad Register address
|
|
|
|
* @param data Pointer to receive read data
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval -EIO General input / output error.
|
|
|
|
* @retval -ETIMEDOUT If transaction timedout on the bus
|
|
|
|
* @retval -ENOSYS if write using Clause 45 access is not supported
|
|
|
|
*/
|
|
|
|
__syscall int mdio_read_c45(const struct device *dev, uint8_t prtad,
|
|
|
|
uint8_t devad, uint16_t regad, uint16_t *data);
|
|
|
|
|
|
|
|
static inline int z_impl_mdio_read_c45(const struct device *dev, uint8_t prtad,
|
|
|
|
uint8_t devad, uint16_t regad,
|
|
|
|
uint16_t *data)
|
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
|
|
|
if (api->read_c45 == NULL) {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return api->read_c45(dev, prtad, devad, regad, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Write to MDIO bus using Clause 45 access
|
|
|
|
*
|
|
|
|
* This routine provides an interface to perform a write on the MDIO bus using
|
|
|
|
* IEEE 802.3 Clause 45 access.
|
|
|
|
*
|
|
|
|
* @param[in] dev Pointer to the device structure for the controller
|
|
|
|
* @param[in] prtad Port address
|
|
|
|
* @param[in] devad Device address
|
|
|
|
* @param[in] regad Register address
|
|
|
|
* @param[in] data Data to write
|
|
|
|
*
|
|
|
|
* @retval 0 If successful.
|
|
|
|
* @retval -EIO General input / output error.
|
|
|
|
* @retval -ETIMEDOUT If transaction timedout on the bus
|
|
|
|
* @retval -ENOSYS if write using Clause 45 access is not supported
|
|
|
|
*/
|
|
|
|
__syscall int mdio_write_c45(const struct device *dev, uint8_t prtad,
|
|
|
|
uint8_t devad, uint16_t regad, uint16_t data);
|
|
|
|
|
|
|
|
static inline int z_impl_mdio_write_c45(const struct device *dev, uint8_t prtad,
|
|
|
|
uint8_t devad, uint16_t regad,
|
|
|
|
uint16_t data)
|
|
|
|
{
|
|
|
|
const struct mdio_driver_api *api =
|
|
|
|
(const struct mdio_driver_api *)dev->api;
|
|
|
|
|
|
|
|
if (api->write_c45 == NULL) {
|
|
|
|
return -ENOSYS;
|
|
|
|
}
|
|
|
|
|
|
|
|
return api->write_c45(dev, prtad, devad, regad, data);
|
|
|
|
}
|
|
|
|
|
2021-05-03 02:49:04 +02:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2024-01-24 10:35:04 +01:00
|
|
|
#include <zephyr/syscalls/mdio.h>
|
2021-05-03 02:49:04 +02:00
|
|
|
|
|
|
|
#endif /* ZEPHYR_INCLUDE_DRIVERS_MDIO_H_ */
|