]> git.baikalelectronics.ru Git - arm-tf.git/commitdiff
stm32mp1: shared resources: count GPIOZ bank pins
authorEtienne Carriere <etienne.carriere@st.com>
Wed, 13 May 2020 08:13:54 +0000 (10:13 +0200)
committerEtienne Carriere <etienne.carriere@st.com>
Tue, 23 Jun 2020 07:17:33 +0000 (09:17 +0200)
Get number of pins in the GPIOZ bank with helper function
fdt_get_gpio_bank_pin_count(). Save the value in RAM to prevent
parsing the FDT several time for the same information.

Change-Id: Ie68e300804461ffce09914100a7d2962116023b5
Signed-off-by: Etienne Carriere <etienne.carriere@st.com>
plat/st/stm32mp1/stm32mp1_shared_resources.c

index a68615298319c10ed548ba8ce67caf499fb39357..18606818cb75869b07ae283806bc7de5536ea20c 100644 (file)
@@ -4,8 +4,45 @@
  * SPDX-License-Identifier: BSD-3-Clause
  */
 
+#include <assert.h>
+#include <stdint.h>
+
+#include <platform_def.h>
+
+#include <common/debug.h>
+#include <drivers/st/stm32_gpio.h>
+
 #include <stm32mp_shared_resources.h>
 
+/* GPIOZ pin count is saved in RAM to prevent parsing FDT several times */
+static int8_t gpioz_nbpin = -1;
+
+static unsigned int get_gpio_nbpin(unsigned int bank)
+{
+       if (bank != GPIO_BANK_Z) {
+               int count = fdt_get_gpio_bank_pin_count(bank);
+
+               assert((count >= 0) || (count <= (GPIO_PIN_MAX + 1)));
+
+               return (unsigned int)count;
+       }
+
+       if (gpioz_nbpin < 0) {
+               int count = fdt_get_gpio_bank_pin_count(GPIO_BANK_Z);
+
+               assert((count == 0) || (count == STM32MP_GPIOZ_PIN_MAX_COUNT));
+
+               gpioz_nbpin = count;
+       }
+
+       return (unsigned int)gpioz_nbpin;
+}
+
+static unsigned int __unused get_gpioz_nbpin(void)
+{
+       return get_gpio_nbpin(GPIO_BANK_Z);
+}
+
 /* Currently allow full access by non-secure to platform clock services */
 bool stm32mp_nsec_can_access_clock(unsigned long clock_id)
 {