summaryrefslogtreecommitdiff
path: root/src/device
diff options
context:
space:
mode:
Diffstat (limited to 'src/device')
-rw-r--r--src/device/Makefile.inc2
-rw-r--r--src/device/device_const.c3
-rw-r--r--src/device/device_util.c6
-rw-r--r--src/device/gpio.c21
4 files changed, 32 insertions, 0 deletions
diff --git a/src/device/Makefile.inc b/src/device/Makefile.inc
index bb125afb8f..808648d4b4 100644
--- a/src/device/Makefile.inc
+++ b/src/device/Makefile.inc
@@ -63,3 +63,5 @@ ramstage-$(CONFIG_RESOURCE_ALLOCATOR_V3) += resource_allocator_v3.c
ramstage-$(CONFIG_RESOURCE_ALLOCATOR_V4) += resource_allocator_v4.c
ramstage-$(CONFIG_XHCI_UTILS) += xhci.c
+
+ramstage-y += gpio.c
diff --git a/src/device/device_const.c b/src/device/device_const.c
index 2dc583ca27..5288a743b6 100644
--- a/src/device/device_const.c
+++ b/src/device/device_const.c
@@ -162,6 +162,9 @@ static int path_eq(const struct device_path *path1,
case DEVICE_PATH_LPC:
equal = (path1->lpc.addr == path2->lpc.addr);
break;
+ case DEVICE_PATH_GPIO:
+ equal = (path1->gpio.id == path2->gpio.id);
+ 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 452a87bf14..0bce26a99e 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -130,6 +130,9 @@ u32 dev_path_encode(const struct device *dev)
case DEVICE_PATH_USB:
ret |= dev->path.usb.port_type << 8 | dev->path.usb.port_id;
break;
+ case DEVICE_PATH_GPIO:
+ ret |= dev->path.gpio.id;
+ 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)
snprintf(buffer, sizeof(buffer), "LPC: %08lx",
dev->path.lpc.addr);
break;
+ case DEVICE_PATH_GPIO:
+ snprintf(buffer, sizeof(buffer), "GPIO: %d", dev->path.gpio.id);
+ break;
default:
printk(BIOS_ERR, "Unknown device path type: %d\n",
dev->path.type);
diff --git a/src/device/gpio.c b/src/device/gpio.c
new file mode 100644
index 0000000000..5e71497024
--- /dev/null
+++ b/src/device/gpio.c
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <console/console.h>
+#include <device/device.h>
+#include <device/gpio.h>
+
+const struct gpio_operations *dev_get_gpio_ops(struct device *dev)
+{
+ if (!dev) {
+ printk(BIOS_ERR, "Could not get gpio operations, device is NULL.");
+ return NULL;
+ } else if (!dev->ops) {
+ printk(BIOS_ERR, "Could not get gpio operations, dev->ops is NULL.");
+ return NULL;
+ } else if (!dev->ops->ops_gpio) {
+ printk(BIOS_ERR, "Could not get gpio operations, ops_gpio is NULL.");
+ return NULL;
+ }
+
+ return dev->ops->ops_gpio;
+}