soc: nordic: nrf54h: gpd: add API to set/clear pin retention

This API needs to be called by FAST peripherals before/after
disabling/enabling them.

Signed-off-by: Gerard Marull-Paretas <gerard@teslabs.com>
This commit is contained in:
Gerard Marull-Paretas 2024-10-29 10:25:25 +01:00 committed by Mahesh Mahadevan
commit 77fc18327a
2 changed files with 41 additions and 0 deletions

View file

@ -12,6 +12,7 @@
#include <zephyr/spinlock.h>
#include <zephyr/sys/util.h>
#include <hal/nrf_gpio.h>
#include <nrf/gpd.h>
#include <nrfs_gdpwr.h>
#include <nrfs_backend_ipc_service.h>
@ -207,6 +208,34 @@ int nrf_gpd_release(uint8_t id)
return onoff_release(&gpd_mgr->mgr);
}
int nrf_gpd_retain_pins_set(const struct pinctrl_dev_config *pcfg, bool retain)
{
const struct pinctrl_state *state;
int ret;
ret = pinctrl_lookup_state(pcfg, PINCTRL_STATE_DEFAULT, &state);
if (ret < 0) {
return ret;
}
for (uint8_t i = 0U; i < state->pin_cnt; i++) {
uint32_t pin = NRF_GET_PIN(state->pins[i]);
NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&pin);
if (pin == NRF_PIN_DISCONNECTED) {
continue;
}
if (retain) {
reg->RETAINSET = BIT(pin);
} else {
reg->RETAINCLR = BIT(pin);
}
}
return 0;
}
static int nrf_gpd_pre_init(void)
{
int ret;

View file

@ -9,6 +9,7 @@
#include <stdint.h>
#include <zephyr/dt-bindings/power/nordic-nrf-gpd.h>
#include <zephyr/drivers/pinctrl.h>
/**
* @brief Request a global power domain.
@ -30,4 +31,15 @@ int nrf_gpd_request(uint8_t id);
*/
int nrf_gpd_release(uint8_t id);
/**
* @brief Retain set/clear a set of pins.
*
* @param pcfg Device pin configuration.
* @param retain Retain or not.
*
* @retval 0 If the request was successful.
* @retval -errno If the request was not successful.
*/
int nrf_gpd_retain_pins_set(const struct pinctrl_dev_config *pcfg, bool retain);
#endif /* ZEPHYR_SOC_NORDIC_NRF54H_GPD_INCLUDE_NRF_GPD_H_ */