summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/soc/amd/common/block/gpio_banks/gpio.c33
-rw-r--r--src/soc/amd/common/block/include/amdblocks/gpio_banks.h15
2 files changed, 48 insertions, 0 deletions
diff --git a/src/soc/amd/common/block/gpio_banks/gpio.c b/src/soc/amd/common/block/gpio_banks/gpio.c
index 2d4558f17f..81ea72528c 100644
--- a/src/soc/amd/common/block/gpio_banks/gpio.c
+++ b/src/soc/amd/common/block/gpio_banks/gpio.c
@@ -294,3 +294,36 @@ int gpio_interrupt_status(gpio_t gpio)
return 0;
}
+
+/*
+ * This function checks to see if there is an override config present for the
+ * provided pad_config. If no override config is present, then the input config
+ * is returned. Else, it returns the override config.
+ */
+static const struct soc_amd_gpio *gpio_get_config(const struct soc_amd_gpio *c,
+ const struct soc_amd_gpio *override_cfg_table,
+ size_t num)
+{
+ size_t i;
+ if (override_cfg_table == NULL)
+ return c;
+ for (i = 0; i < num; i++) {
+ if (c->gpio == override_cfg_table[i].gpio)
+ return override_cfg_table + i;
+ }
+ return c;
+}
+void gpio_configure_pads_with_override(const struct soc_amd_gpio *base_cfg,
+ size_t base_num_pads,
+ const struct soc_amd_gpio *override_cfg,
+ size_t override_num_pads)
+{
+ size_t i;
+ const struct soc_amd_gpio *c;
+
+ for (i = 0; i < base_num_pads; i++) {
+ c = gpio_get_config(base_cfg + i, override_cfg,
+ override_num_pads);
+ program_gpios(c, 1);
+ }
+}
diff --git a/src/soc/amd/common/block/include/amdblocks/gpio_banks.h b/src/soc/amd/common/block/include/amdblocks/gpio_banks.h
index b603e2ddd1..572e639f70 100644
--- a/src/soc/amd/common/block/include/amdblocks/gpio_banks.h
+++ b/src/soc/amd/common/block/include/amdblocks/gpio_banks.h
@@ -276,6 +276,21 @@ enum {
typedef uint32_t gpio_t;
+/*
+ * gpio_configure_pads_with_override accepts as input two GPIO tables:
+ * 1. Base config
+ * 2. Override config
+ *
+ * This function configures raw pads in base config and applies override in
+ * override config if any. Thus, for every GPIO_x in base config, this function
+ * looks up the GPIO in override config and if it is present there, then applies
+ * the configuration from override config.
+ */
+void gpio_configure_pads_with_override(const struct soc_amd_gpio *base_cfg,
+ size_t base_num_pads,
+ const struct soc_amd_gpio *override_cfg,
+ size_t override_num_pads);
+
/* Get the address of the control register of a particular pin */
uintptr_t gpio_get_address(gpio_t gpio_num);