summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/device/Makefile.inc1
-rw-r--r--src/device/device_const.c4
-rw-r--r--src/device/device_util.c6
-rw-r--r--src/device/mdio.c16
-rw-r--r--src/include/device/device.h2
-rw-r--r--src/include/device/mdio.h17
-rw-r--r--src/include/device/path.h7
7 files changed, 53 insertions, 0 deletions
diff --git a/src/device/Makefile.inc b/src/device/Makefile.inc
index 28acd73879..3018ef9626 100644
--- a/src/device/Makefile.inc
+++ b/src/device/Makefile.inc
@@ -64,3 +64,4 @@ ramstage-y += resource_allocator_v4.c
ramstage-$(CONFIG_XHCI_UTILS) += xhci.c
ramstage-y += gpio.c
+ramstage-y += mdio.c
diff --git a/src/device/device_const.c b/src/device/device_const.c
index a40d0b05b9..a63a629344 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -147,6 +147,10 @@ static int path_eq(const struct device_path *path1,
case DEVICE_PATH_GPIO:
equal = (path1->gpio.id == path2->gpio.id);
break;
+ case DEVICE_PATH_MDIO:
+ equal = (path1->mdio.addr == path2->mdio.addr);
+ break;
+
default:
printk(BIOS_ERR, "Unknown device type: %d\n", path1->type);
break;
diff --git a/src/device/device_util.c b/src/device/device_util.c
index 9beb2ce8e2..c5e03f2079 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -135,6 +135,9 @@ u32 dev_path_encode(const struct device *dev)
case DEVICE_PATH_GPIO:
ret |= dev->path.gpio.id;
break;
+ case DEVICE_PATH_MDIO:
+ ret |= dev->path.mdio.addr;
+ break;
case DEVICE_PATH_NONE:
case DEVICE_PATH_MMIO: /* don't care */
default:
@@ -223,6 +226,9 @@ const char *dev_path(const struct device *dev)
case DEVICE_PATH_GPIO:
snprintf(buffer, sizeof(buffer), "GPIO: %d", dev->path.gpio.id);
break;
+ case DEVICE_PATH_MDIO:
+ snprintf(buffer, sizeof(buffer), "MDIO: %02x", dev->path.mdio.addr);
+ break;
default:
printk(BIOS_ERR, "Unknown device path type: %d\n",
dev->path.type);
diff --git a/src/device/mdio.c b/src/device/mdio.c
new file mode 100644
index 0000000000..9f560e6bdf
--- /dev/null
+++ b/src/device/mdio.c
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#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;
+}
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 0f9c39f17e..8b1dde1109 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -20,6 +20,7 @@ struct pnp_mode_ops;
struct spi_bus_operations;
struct usb_bus_operations;
struct gpio_operations;
+struct mdio_bus_operations;
/* Chip operations */
struct chip_operations {
@@ -67,6 +68,7 @@ struct device_operations {
const struct smbus_bus_operations *ops_smbus_bus;
const struct pnp_mode_ops *ops_pnp_mode;
const struct gpio_operations *ops_gpio;
+ const struct mdio_bus_operations *ops_mdio;
};
/**
diff --git a/src/include/device/mdio.h b/src/include/device/mdio.h
new file mode 100644
index 0000000000..39e60f582d
--- /dev/null
+++ b/src/include/device/mdio.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#ifndef __DEVICE_MDIO_H__
+#define __DEVICE_MDIO_H__
+
+#include <device/device.h>
+#include <types.h>
+
+struct mdio_bus_operations {
+ uint16_t (*read)(struct device *dev, uint8_t phy_adr, uint8_t reg_adr);
+ void (*write)(struct device *dev, uint8_t phy_adr, uint8_t reg_adr, uint16_t data);
+};
+
+/* Helper for getting mdio operations from a device */
+const struct mdio_bus_operations *dev_get_mdio_ops(struct device *dev);
+
+#endif /* __DEVICE_MDIO_H__ */
diff --git a/src/include/device/path.h b/src/include/device/path.h
index 1be7e7299f..28c932ad8e 100644
--- a/src/include/device/path.h
+++ b/src/include/device/path.h
@@ -22,6 +22,7 @@ enum device_path_type {
DEVICE_PATH_USB,
DEVICE_PATH_MMIO,
DEVICE_PATH_GPIO,
+ DEVICE_PATH_MDIO,
/*
* When adding path types to this table, please also update the
@@ -46,6 +47,7 @@ enum device_path_type {
"DEVICE_PATH_USB", \
"DEVICE_PATH_MMIO", \
"DEVICE_PATH_GPIO", \
+ "DEVICE_PATH_MDIO", \
}
struct domain_path {
@@ -112,6 +114,10 @@ struct gpio_path {
unsigned int id;
};
+struct mdio_path {
+ unsigned int addr;
+};
+
struct device_path {
enum device_path_type type;
union {
@@ -129,6 +135,7 @@ struct device_path {
struct usb_path usb;
struct mmio_path mmio;
struct gpio_path gpio;
+ struct mdio_path mdio;
};
};