Skip to content

Commit 77fc183

Browse files
gmarullmmahadevan108
authored andcommitted
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 <[email protected]>
1 parent 5e8905b commit 77fc183

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

soc/nordic/nrf54h/gpd/gpd.c

Lines changed: 29 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>
@@ -207,6 +208,34 @@ int nrf_gpd_release(uint8_t id)
207208
return onoff_release(&gpd_mgr->mgr);
208209
}
209210

211+
int nrf_gpd_retain_pins_set(const struct pinctrl_dev_config *pcfg, bool retain)
212+
{
213+
const struct pinctrl_state *state;
214+
int ret;
215+
216+
ret = pinctrl_lookup_state(pcfg, PINCTRL_STATE_DEFAULT, &state);
217+
if (ret < 0) {
218+
return ret;
219+
}
220+
221+
for (uint8_t i = 0U; i < state->pin_cnt; i++) {
222+
uint32_t pin = NRF_GET_PIN(state->pins[i]);
223+
NRF_GPIO_Type *reg = nrf_gpio_pin_port_decode(&pin);
224+
225+
if (pin == NRF_PIN_DISCONNECTED) {
226+
continue;
227+
}
228+
229+
if (retain) {
230+
reg->RETAINSET = BIT(pin);
231+
} else {
232+
reg->RETAINCLR = BIT(pin);
233+
}
234+
}
235+
236+
return 0;
237+
}
238+
210239
static int nrf_gpd_pre_init(void)
211240
{
212241
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)