From 712311f56e2f9fec0124ca7903078dc180abf81c Mon Sep 17 00:00:00 2001 From: Peichao Wang Date: Sat, 18 Apr 2020 08:25:53 +0800 Subject: soc/amd/common/block/gpio: add API for gpio override table This function adds support for gpio_configure_pads_with_override which: 1. Takes as input two GPIO tables -- base config table and override config table 2. Configures each pad in base config by first checking if there is a config available for the pad in override config table. If yes, then uses the one from override config table. Else, uses the base config to configure the pad. BUG=b:153456574 TEST=Build and boot dalboz BRANCH=none Signed-off-by: peichao.wang Change-Id: I07bfe82827d1f7aea9fcc96574d6deab9e91d503 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/coreboot/+/2153423 Reviewed-by: Furquan Shaikh Commit-Queue: Furquan Shaikh Tested-by: Furquan Shaikh Reviewed-on: https://review.coreboot.org/c/coreboot/+/41576 Reviewed-by: Furquan Shaikh Tested-by: build bot (Jenkins) --- src/soc/amd/common/block/gpio_banks/gpio.c | 33 ++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/soc/amd/common/block/gpio_banks/gpio.c') 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); + } +} -- cgit v1.2.3