summaryrefslogtreecommitdiff
path: root/src/soc/intel/common/block/gpio/gpio.c
diff options
context:
space:
mode:
authorTim Wawrzynczak <twawrzynczak@chromium.org>2021-05-03 12:14:01 -0600
committerTim Wawrzynczak <twawrzynczak@chromium.org>2021-05-06 04:11:59 +0000
commit629ddfd265afed7a5198ddbe58aef66297be4c61 (patch)
tree502f41005f621a0469697ba0a33fdae2133fc297 /src/soc/intel/common/block/gpio/gpio.c
parentcea4f92e4a2f12d09eef3a8052493786b4e9e18e (diff)
soc/intel/common: Add virtual wire mapping entries to GPIO communities
Some SoCs may define virtual wire entries for certain GPIOs. This patch allows SoC code to provide the mappings from GPIO pads to virtual wire indexes and bits when they are provided. Also a function `gpio_get_vw_info` is added to return this information. Change-Id: I87adf0ca06cb5b7969bb2c258d6daebd44bb9748 Signed-off-by: Tim Wawrzynczak <twawrzynczak@chromium.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/52588 Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Diffstat (limited to 'src/soc/intel/common/block/gpio/gpio.c')
-rw-r--r--src/soc/intel/common/block/gpio/gpio.c24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/soc/intel/common/block/gpio/gpio.c b/src/soc/intel/common/block/gpio/gpio.c
index 4398c9fb62..db7654537a 100644
--- a/src/soc/intel/common/block/gpio/gpio.c
+++ b/src/soc/intel/common/block/gpio/gpio.c
@@ -763,3 +763,27 @@ static void snapshot_cleanup(void *unused)
BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_EXIT, snapshot_cleanup, NULL);
BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, snapshot_cleanup, NULL);
+
+bool gpio_get_vw_info(gpio_t pad, unsigned int *vw_index, unsigned int *vw_bit)
+{
+ const struct pad_community *comm;
+ unsigned int offset = 0;
+ size_t i;
+
+ comm = gpio_get_community(pad);
+ for (i = 0; i < comm->num_vw_entries; i++) {
+ if (pad >= comm->vw_entries[i].first_pad && pad <= comm->vw_entries[i].last_pad)
+ break;
+
+ offset += 1 + comm->vw_entries[i].last_pad - comm->vw_entries[i].first_pad;
+ }
+
+ if (i == comm->num_vw_entries)
+ return false;
+
+ offset += pad - comm->vw_entries[i].first_pad;
+ *vw_index = comm->vw_base + offset / 8;
+ *vw_bit = offset % 8;
+
+ return true;
+}