From d0f2cf3b148df75d5cbbd42dfa18012043e5d1f4 Mon Sep 17 00:00:00 2001 From: Fabien Dessenne Date: Tue, 21 Sep 2021 11:32:30 +0200 Subject: [PATCH] feat(st): get pin_count from the gpio-ranges property The "ngpios" property is deprecated and may be removed. Use the "gpio-ranges" property where the last parameter of that property is the number of available pins within that range. Signed-off-by: Fabien Dessenne Change-Id: I28295412c7cb1246fc753cff0d447b6fdcdc4c0f --- plat/st/common/stm32mp_dt.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/plat/st/common/stm32mp_dt.c b/plat/st/common/stm32mp_dt.c index cf6c6e728..ea7157157 100644 --- a/plat/st/common/stm32mp_dt.c +++ b/plat/st/common/stm32mp_dt.c @@ -404,6 +404,9 @@ int fdt_get_gpio_bank_pin_count(unsigned int bank) fdt_for_each_subnode(node, fdt, pinctrl_node) { const fdt32_t *cuint; + int pin_count; + int len; + int i; if (fdt_getprop(fdt, node, "gpio-controller", NULL) == NULL) { continue; @@ -422,12 +425,22 @@ int fdt_get_gpio_bank_pin_count(unsigned int bank) return 0; } - cuint = fdt_getprop(fdt, node, "ngpios", NULL); - if (cuint == NULL) { - return -FDT_ERR_NOTFOUND; + /* Parse gpio-ranges with its 4 parameters */ + cuint = fdt_getprop(fdt, node, "gpio-ranges", &len); + len /= sizeof(*cuint); + if ((len % 4) != 0) { + return -FDT_ERR_BADVALUE; + } + + /* Get the last defined gpio line (offset + nb of pins) */ + pin_count = fdt32_to_cpu(*(cuint + 1)) + fdt32_to_cpu(*(cuint + 3)); + for (i = 0; i < len / 4; i++) { + pin_count = MAX(pin_count, (int)(fdt32_to_cpu(*(cuint + 1)) + + fdt32_to_cpu(*(cuint + 3)))); + cuint += 4; } - return (int)fdt32_to_cpu(*cuint); + return pin_count; } return 0; -- 2.39.5