Kyösti Mälkki has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/43050 )
Change subject: soc/amd/common: Refactor program_gpios() for overrides ......................................................................
soc/amd/common: Refactor program_gpios() for overrides
Some GPIO listed in override_cfg may not be programmed.
Change-Id: Ia8e47b2a278a1887db5406c1f863ddafa6a68675 Signed-off-by: Kyösti Mälkki kyosti.malkki@gmail.com --- M src/soc/amd/common/block/gpio_banks/gpio.c 1 file changed, 20 insertions(+), 36 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/50/43050/1
diff --git a/src/soc/amd/common/block/gpio_banks/gpio.c b/src/soc/amd/common/block/gpio_banks/gpio.c index b52d7f1..1019d79 100644 --- a/src/soc/amd/common/block/gpio_banks/gpio.c +++ b/src/soc/amd/common/block/gpio_banks/gpio.c @@ -189,7 +189,16 @@
void program_gpios(const struct soc_amd_gpio *gpio_list_ptr, size_t size) { - size_t i; + return gpio_configure_pads_with_override(gpio_list_ptr, size, NULL, 0); +} + +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) +{ + const struct soc_amd_gpio *c; + size_t i, j;
/* * Disable blocking wake/interrupt status generation while updating @@ -203,8 +212,16 @@ */ master_switch_clr(GPIO_MASK_STS_EN | GPIO_INTERRUPT_EN);
- for (i = 0; i < size; i++) - set_single_gpio(&gpio_list_ptr[i]); + for (i = 0; i < base_num_pads; i++) { + c = &base_cfg[i]; + for (j = 0; override_cfg && j < override_num_pads; j++) { + if (c->gpio == override_cfg[j].gpio) { + c = &override_cfg[j]; + break; + } + } + set_single_gpio(c); + }
/* * Re-enable interrupt status generation. @@ -229,36 +246,3 @@
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); - } -}