coreboot-kgpe-d16/src/device/mdio.c
Werner Zeh 49ec39fa7f 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 <werner.zeh@siemens.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/69611
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
Reviewed-by: Arthur Heymans <arthur@aheymans.xyz>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2022-11-24 05:58:28 +00:00

40 lines
1 KiB
C

/* SPDX-License-Identifier: GPL-2.0-only */
#include <assert.h>
#include <console/console.h>
#include <device/device.h>
#include <device/mdio.h>
#include <stddef.h>
const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev)
{
if (!dev || !dev->ops || !dev->ops->ops_mdio) {
printk(BIOS_ERR, "Could not get MDIO operations.\n");
return NULL;
}
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);
}