From 0852af215b6178b8b8a44c77f2bf0575e0427ef4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Krzysztof=20Chru=C5=9Bci=C5=84ski?= Date: Fri, 15 Nov 2024 15:25:05 +0100 Subject: [PATCH] drivers: pinctrl: nrf: Optimize access to gpd service MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Request and release global power domain only once during setup of pins. Request and release involves communication over IPC and it should be avoided if possible. For example if there are 4 pins (like in UART) where GPD is requested we can limit number of request/release operations fourfold. Signed-off-by: Krzysztof Chruściński --- drivers/pinctrl/pinctrl_nrf.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/pinctrl/pinctrl_nrf.c b/drivers/pinctrl/pinctrl_nrf.c index 1e80de8fe67..1e587d08b62 100644 --- a/drivers/pinctrl/pinctrl_nrf.c +++ b/drivers/pinctrl/pinctrl_nrf.c @@ -97,6 +97,10 @@ static const nrf_gpio_pin_drive_t drive_modes[NRF_DRIVE_COUNT] = { int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, uintptr_t reg) { +#ifdef CONFIG_SOC_NRF54H20_GPD + bool gpd_requested = false; +#endif + for (uint8_t i = 0U; i < pin_cnt; i++) { nrf_gpio_pin_drive_t drive; uint8_t drive_idx = NRF_GET_DRIVE(pins[i]); @@ -357,13 +361,17 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, #ifdef CONFIG_SOC_NRF54H20_GPD if (NRF_GET_GPD_FAST_ACTIVE1(pins[i]) == 1U) { - int ret; uint32_t d_pin = pin; NRF_GPIO_Type *port = nrf_gpio_pin_port_decode(&d_pin); - ret = nrf_gpd_request(NRF_GPD_SLOW_ACTIVE); - if (ret < 0) { - return ret; + if (!gpd_requested) { + int ret; + + ret = nrf_gpd_request(NRF_GPD_SLOW_ACTIVE); + if (ret < 0) { + return ret; + } + gpd_requested = true; } port->RETAINCLR = BIT(d_pin); @@ -387,20 +395,26 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt, #endif #ifdef CONFIG_SOC_NRF54H20_GPD if (NRF_GET_GPD_FAST_ACTIVE1(pins[i]) == 1U) { - int ret; uint32_t d_pin = pin; NRF_GPIO_Type *port = nrf_gpio_pin_port_decode(&d_pin); port->RETAINSET = BIT(d_pin); - ret = nrf_gpd_release(NRF_GPD_SLOW_ACTIVE); - if (ret < 0) { - return ret; - } } #endif /* CONFIG_SOC_NRF54H20_GPD */ } } +#ifdef CONFIG_SOC_NRF54H20_GPD + if (gpd_requested) { + int ret; + + ret = nrf_gpd_release(NRF_GPD_SLOW_ACTIVE); + if (ret < 0) { + return ret; + } + } +#endif + return 0; }