From 49ec39fa7f05c4a3d320b5a60593108e1affb19f Mon Sep 17 00:00:00 2001 From: Werner Zeh Date: Tue, 15 Nov 2022 08:27:19 +0100 Subject: [PATCH] device/mdio: Provide helper functions for read and write This patch provides helper functions to read or write a register via the MDIO bus. They can be used from drivers to easily access registers on the MDIO bus. Change-Id: I293d93435d27269a071b4b9b94a1b55307c575a7 Signed-off-by: Werner Zeh Reviewed-on: https://review.coreboot.org/c/coreboot/+/69611 Reviewed-by: Angel Pons Reviewed-by: Arthur Heymans Tested-by: build bot (Jenkins) --- src/device/mdio.c | 24 ++++++++++++++++++++++++ src/include/device/mdio.h | 3 +++ 2 files changed, 27 insertions(+) diff --git a/src/device/mdio.c b/src/device/mdio.c index 9f560e6bdf..39ac40bca7 100644 --- a/src/device/mdio.c +++ b/src/device/mdio.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include #include @@ -14,3 +15,26 @@ const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev) return dev->ops->ops_mdio; } + +uint16_t mdio_read(struct device *dev, uint8_t offset) +{ + const struct mdio_bus_operations *mdio_ops; + struct device *parent = dev->bus->dev; + + assert(dev->path.type == DEVICE_PATH_MDIO); + mdio_ops = dev_get_mdio_ops(parent); + if (!mdio_ops) + return 0; + return mdio_ops->read(parent, dev->path.mdio.addr, offset); +} +void mdio_write(struct device *dev, uint8_t offset, uint16_t val) +{ + const struct mdio_bus_operations *mdio_ops; + struct device *parent = dev->bus->dev; + + assert(dev->path.type == DEVICE_PATH_MDIO); + mdio_ops = dev_get_mdio_ops(parent); + if (!mdio_ops) + return; + mdio_ops->write(parent, dev->path.mdio.addr, offset, val); +} diff --git a/src/include/device/mdio.h b/src/include/device/mdio.h index 39e60f582d..44ce48b7f3 100644 --- a/src/include/device/mdio.h +++ b/src/include/device/mdio.h @@ -14,4 +14,7 @@ struct mdio_bus_operations { /* Helper for getting mdio operations from a device */ const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev); +uint16_t mdio_read(struct device *dev, uint8_t offset); +void mdio_write(struct device *dev, uint8_t offset, uint16_t val); + #endif /* __DEVICE_MDIO_H__ */