blob: 39ac40bca75479c1772f81494331f993c695684e [file] [log] [blame]
Mario Scheithauer67f63e72022-11-02 15:57:10 +01001/* SPDX-License-Identifier: GPL-2.0-only */
2
Werner Zeh49ec39f2022-11-15 08:27:19 +01003#include <assert.h>
Mario Scheithauer67f63e72022-11-02 15:57:10 +01004#include <console/console.h>
5#include <device/device.h>
6#include <device/mdio.h>
7#include <stddef.h>
8
9const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev)
10{
11 if (!dev || !dev->ops || !dev->ops->ops_mdio) {
12 printk(BIOS_ERR, "Could not get MDIO operations.\n");
13 return NULL;
14 }
15
16 return dev->ops->ops_mdio;
17}
Werner Zeh49ec39f2022-11-15 08:27:19 +010018
19uint16_t mdio_read(struct device *dev, uint8_t offset)
20{
21 const struct mdio_bus_operations *mdio_ops;
22 struct device *parent = dev->bus->dev;
23
24 assert(dev->path.type == DEVICE_PATH_MDIO);
25 mdio_ops = dev_get_mdio_ops(parent);
26 if (!mdio_ops)
27 return 0;
28 return mdio_ops->read(parent, dev->path.mdio.addr, offset);
29}
30void mdio_write(struct device *dev, uint8_t offset, uint16_t val)
31{
32 const struct mdio_bus_operations *mdio_ops;
33 struct device *parent = dev->bus->dev;
34
35 assert(dev->path.type == DEVICE_PATH_MDIO);
36 mdio_ops = dev_get_mdio_ops(parent);
37 if (!mdio_ops)
38 return;
39 mdio_ops->write(parent, dev->path.mdio.addr, offset, val);
40}