Skip to content

Commit 949b9ee

Browse files
committed
[nrf fromlist] drivers: gpio: nrfx: add support for ports with pad on FAST_ACTIVE1
This patch allows to _safely_ configure GPIO ports that have their pad on FAST_ACTIVE1 domain. Upstream PR #: 80291 Signed-off-by: Gerard Marull-Paretas <[email protected]> (cherry picked from commit a11b279d6de0a7137bd14360f4d414c3ef15aa97)
1 parent af697f3 commit 949b9ee

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

drivers/gpio/gpio_nrfx.c

Lines changed: 48 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414

1515
#include <zephyr/drivers/gpio/gpio_utils.h>
1616

17+
#ifdef CONFIG_SOC_NRF54H20_GPD
18+
#include <nrf/gpd.h>
19+
#endif
20+
1721
struct gpio_nrfx_data {
1822
/* gpio_driver_data needs to be first */
1923
struct gpio_driver_data common;
@@ -27,6 +31,9 @@ struct gpio_nrfx_cfg {
2731
uint32_t edge_sense;
2832
uint8_t port_num;
2933
nrfx_gpiote_t gpiote;
34+
#ifdef CONFIG_SOC_NRF54H20_GPD
35+
uint8_t pad_pd;
36+
#endif
3037
};
3138

3239
static inline struct gpio_nrfx_data *get_port_data(const struct device *port)
@@ -58,6 +65,7 @@ static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags)
5865
static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
5966
gpio_flags_t flags)
6067
{
68+
int ret = 0;
6169
nrfx_err_t err = NRFX_SUCCESS;
6270
uint8_t ch;
6371
bool free_ch = false;
@@ -95,6 +103,17 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
95103
return -EINVAL;
96104
}
97105

106+
#ifdef CONFIG_SOC_NRF54H20_GPD
107+
if (cfg->pad_pd == NRF_GPD_FAST_ACTIVE1) {
108+
ret = nrf_gpd_request(NRF_GPD_FAST_ACTIVE1);
109+
if (ret < 0) {
110+
return ret;
111+
}
112+
113+
nrf_gpio_port_retain_clear(cfg->port, BIT(pin));
114+
}
115+
#endif
116+
98117
if (flags & GPIO_OUTPUT_INIT_HIGH) {
99118
nrf_gpio_port_out_set(cfg->port, BIT(pin));
100119
} else if (flags & GPIO_OUTPUT_INIT_LOW) {
@@ -110,7 +129,8 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
110129
: NRF_GPIO_PIN_INPUT_DISCONNECT;
111130

112131
nrf_gpio_reconfigure(abs_pin, &dir, &input, &pull, &drive, NULL);
113-
return 0;
132+
133+
goto end;
114134
}
115135

116136
/* Get the GPIOTE channel associated with this pin, if any. It needs
@@ -137,7 +157,8 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
137157
err = nrfx_gpiote_input_configure(&cfg->gpiote,
138158
abs_pin, &input_pin_config);
139159
if (err != NRFX_SUCCESS) {
140-
return -EINVAL;
160+
ret = -EINVAL;
161+
goto end;
141162
}
142163
}
143164

@@ -162,7 +183,8 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
162183
}
163184

164185
if (err != NRFX_SUCCESS) {
165-
return -EINVAL;
186+
ret = -EINVAL;
187+
goto end;
166188
}
167189
}
168190

@@ -171,7 +193,20 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
171193
__ASSERT_NO_MSG(err == NRFX_SUCCESS);
172194
}
173195

174-
return 0;
196+
end:
197+
#ifdef CONFIG_SOC_NRF54H20_GPD
198+
if (cfg->pad_pd == NRF_GPD_FAST_ACTIVE1) {
199+
if (flags & GPIO_OUTPUT) {
200+
nrf_gpio_port_retain_set(cfg->port, BIT(pin));
201+
}
202+
203+
ret = nrf_gpd_release(NRF_GPD_FAST_ACTIVE1);
204+
if (ret < 0) {
205+
return ret;
206+
}
207+
}
208+
#endif
209+
return ret;
175210
}
176211

177212
static int gpio_nrfx_port_get_raw(const struct device *port,
@@ -450,6 +485,14 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = {
450485
"Please enable GPIOTE instance for used GPIO port!")), \
451486
())
452487

488+
#ifdef CONFIG_SOC_NRF54H20_GPD
489+
#define PAD_PD(inst) \
490+
.pad_pd = DT_INST_PHA_BY_NAME_OR(inst, power_domains, pad, id, \
491+
NRF_GPD_SLOW_MAIN),
492+
#else
493+
#define PAD_PD(inst)
494+
#endif
495+
453496
#define GPIO_NRF_DEVICE(id) \
454497
GPIOTE_CHECK(id); \
455498
static const struct gpio_nrfx_cfg gpio_nrfx_p##id##_cfg = { \
@@ -461,6 +504,7 @@ static const struct gpio_driver_api gpio_nrfx_drv_api_funcs = {
461504
.port_num = DT_INST_PROP(id, port), \
462505
.edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0), \
463506
.gpiote = GPIOTE_INSTANCE(id), \
507+
PAD_PD(id) \
464508
}; \
465509
\
466510
static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \

0 commit comments

Comments
 (0)