Skip to content

Commit 2a129da

Browse files
committed
[nrf fromlist] 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. Upstream PR #: 80291 Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit f17e6221fe8c5adbef3e68a0fda285ffd59b8a93)
1 parent 949b9ee commit 2a129da

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

soc/nordic/nrf54h/gpd/gpd.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <zephyr/spinlock.h>
1313
#include <zephyr/sys/util.h>
1414

15+
#include <hal/nrf_gpio.h>
1516
#include <nrf/gpd.h>
1617
#include <nrfs_gdpwr.h>
1718
#include <nrfs_backend_ipc_service.h>
@@ -211,6 +212,33 @@ int nrf_gpd_release(uint8_t id)
211212
return onoff_release(&gpd_mgr->mgr);
212213
}
213214

215+
int nrf_gpd_retain_pins_set(const struct pinctrl_dev_config *pcfg, bool retain)
216+
{
217+
const struct pinctrl_state *state;
218+
int ret;
219+
220+
ret = pinctrl_lookup_state(pcfg, PINCTRL_STATE_DEFAULT, &state);
221+
if (ret < 0) {
222+
return ret;
223+
}
224+
225+
for (uint8_t i = 0U; i < state->pin_cnt; i++) {
226+
uint32_t pin = NRF_GET_PIN(state->pins[i]);
227+
228+
if (pin == NRF_PIN_DISCONNECTED) {
229+
continue;
230+
}
231+
232+
if (retain) {
233+
nrf_gpio_pin_retain_set(pin);
234+
} else {
235+
nrf_gpio_pin_retain_clear(pin);
236+
}
237+
}
238+
239+
return 0;
240+
}
241+
214242
static int nrf_gpd_pre_init(void)
215243
{
216244
int ret;

soc/nordic/nrf54h/gpd/include/nrf/gpd.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdint.h>
1010

1111
#include <zephyr/dt-bindings/power/nordic-nrf-gpd.h>
12+
#include <zephyr/drivers/pinctrl.h>
1213

1314
/**
1415
* @brief Request a global power domain.
@@ -30,4 +31,15 @@ int nrf_gpd_request(uint8_t id);
3031
*/
3132
int nrf_gpd_release(uint8_t id);
3233

34+
/**
35+
* @brief Retain set/clear a set of pins.
36+
*
37+
* @param pcfg Device pin configuration.
38+
* @param retain Retain or not.
39+
*
40+
* @retval 0 If the request was successful.
41+
* @retval -errno If the request was not successful.
42+
*/
43+
int nrf_gpd_retain_pins_set(const struct pinctrl_dev_config *pcfg, bool retain);
44+
3345
#endif /* ZEPHYR_SOC_NORDIC_NRF54H_GPD_INCLUDE_NRF_GPD_H_ */

0 commit comments

Comments
 (0)