1 /* SPDX-License-Identifier: GPL-2.0-only */
4 #include <console/console.h>
5 #include <device/device.h>
6 #include <device/mdio.h>
9 const struct mdio_bus_operations
*dev_get_mdio_ops(struct device
*dev
)
11 if (!dev
|| !dev
->ops
|| !dev
->ops
->ops_mdio
) {
12 printk(BIOS_ERR
, "Could not get MDIO operations.\n");
16 return dev
->ops
->ops_mdio
;
19 uint16_t mdio_read(struct device
*dev
, uint8_t offset
)
21 const struct mdio_bus_operations
*mdio_ops
;
22 struct device
*parent
= dev
->upstream
->dev
;
24 assert(dev
->path
.type
== DEVICE_PATH_MDIO
);
25 mdio_ops
= dev_get_mdio_ops(parent
);
28 return mdio_ops
->read(parent
, dev
->path
.mdio
.addr
, offset
);
30 void mdio_write(struct device
*dev
, uint8_t offset
, uint16_t val
)
32 const struct mdio_bus_operations
*mdio_ops
;
33 struct device
*parent
= dev
->upstream
->dev
;
35 assert(dev
->path
.type
== DEVICE_PATH_MDIO
);
36 mdio_ops
= dev_get_mdio_ops(parent
);
39 mdio_ops
->write(parent
, dev
->path
.mdio
.addr
, offset
, val
);