coreboot/src/device/mdio.c
Arthur Heymans 7fcd4d58ec device/device.h: Rename busses for clarity
This renames bus to upstream and link_list to downstream.

Signed-off-by: Arthur Heymans <arthur@aheymans.xyz>
Change-Id: I80a81b6b8606e450ff180add9439481ec28c2420
Reviewed-on: https://review.coreboot.org/c/coreboot/+/78330
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
2024-01-31 10:36:39 +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->upstream->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->upstream->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);
}