Commit 77fc1832 authored by Gerard Marull-Paretas's avatar Gerard Marull-Paretas Committed by Mahesh Mahadevan
Browse files

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: default avatarGerard Marull-Paretas <gerard@teslabs.com>
parent 5e8905bb
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -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;
+12 −0
Original line number Diff line number Diff line
@@ -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_ */