Skip to content

Commit 95015ed

Browse files
inter
1 parent 05d5a9d commit 95015ed

File tree

17 files changed

+340
-212
lines changed

17 files changed

+340
-212
lines changed

drivers/gpio/gpio_nrfx.c

Lines changed: 15 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@
1616

1717
#include <zephyr/drivers/gpio/gpio_utils.h>
1818

19-
#ifdef CONFIG_SOC_NRF54H20_GPD
20-
#include <nrf/gpd.h>
19+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_gpio_pad_group)
20+
#define NRF_GPIO_HAS_PAD_GROUP 1
21+
#else
22+
#define NRF_GPIO_HAS_PAD_GROUP 0
2123
#endif
2224

2325
struct gpio_nrfx_data {
@@ -33,8 +35,8 @@ struct gpio_nrfx_cfg {
3335
uint32_t edge_sense;
3436
uint8_t port_num;
3537
nrfx_gpiote_t gpiote;
36-
#ifdef CONFIG_SOC_NRF54H20_GPD
37-
uint8_t pad_pd;
38+
#if NRF_GPIO_HAS_PAD_GROUP
39+
const struct device *pad_group;
3840
#endif
3941
};
4042

@@ -64,30 +66,6 @@ static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags)
6466
return NRF_GPIO_PIN_NOPULL;
6567
}
6668

67-
static void gpio_nrfx_gpd_retain_set(const struct device *port, uint32_t mask)
68-
{
69-
#ifdef CONFIG_SOC_NRF54H20_GPD
70-
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
71-
72-
nrf_gpio_port_retain_enable(cfg->port, mask);
73-
#else
74-
ARG_UNUSED(port);
75-
ARG_UNUSED(mask);
76-
#endif
77-
}
78-
79-
static void gpio_nrfx_gpd_retain_clear(const struct device *port, uint32_t mask)
80-
{
81-
#ifdef CONFIG_SOC_NRF54H20_GPD
82-
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
83-
84-
nrf_gpio_port_retain_disable(cfg->port, mask);
85-
#else
86-
ARG_UNUSED(port);
87-
ARG_UNUSED(mask);
88-
#endif
89-
}
90-
9169
static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
9270
gpio_flags_t flags)
9371
{
@@ -134,8 +112,6 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
134112
return ret;
135113
}
136114

137-
gpio_nrfx_gpd_retain_clear(port, BIT(pin));
138-
139115
if (flags & GPIO_OUTPUT_INIT_HIGH) {
140116
nrf_gpio_port_out_set(cfg->port, BIT(pin));
141117
} else if (flags & GPIO_OUTPUT_INIT_LOW) {
@@ -216,7 +192,6 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
216192
}
217193

218194
end:
219-
gpio_nrfx_gpd_retain_set(port, BIT(pin));
220195
return pm_device_runtime_put(port);
221196
}
222197

@@ -317,10 +292,8 @@ static int gpio_nrfx_port_set_masked_raw(const struct device *port,
317292
return ret;
318293
}
319294

320-
gpio_nrfx_gpd_retain_clear(port, mask);
321295
nrf_gpio_port_out_set(reg, set_mask);
322296
nrf_gpio_port_out_clear(reg, clear_mask);
323-
gpio_nrfx_gpd_retain_set(port, mask);
324297
return pm_device_runtime_put(port);
325298
}
326299

@@ -335,9 +308,7 @@ static int gpio_nrfx_port_set_bits_raw(const struct device *port,
335308
return ret;
336309
}
337310

338-
gpio_nrfx_gpd_retain_clear(port, mask);
339311
nrf_gpio_port_out_set(reg, mask);
340-
gpio_nrfx_gpd_retain_set(port, mask);
341312
return pm_device_runtime_put(port);
342313
}
343314

@@ -352,9 +323,7 @@ static int gpio_nrfx_port_clear_bits_raw(const struct device *port,
352323
return ret;
353324
}
354325

355-
gpio_nrfx_gpd_retain_clear(port, mask);
356326
nrf_gpio_port_out_clear(reg, mask);
357-
gpio_nrfx_gpd_retain_set(port, mask);
358327
return pm_device_runtime_put(port);
359328
}
360329

@@ -372,10 +341,8 @@ static int gpio_nrfx_port_toggle_bits(const struct device *port,
372341
return ret;
373342
}
374343

375-
gpio_nrfx_gpd_retain_clear(port, mask);
376344
nrf_gpio_port_out_set(reg, set_mask);
377345
nrf_gpio_port_out_clear(reg, clear_mask);
378-
gpio_nrfx_gpd_retain_set(port, mask);
379346
return pm_device_runtime_put(port);
380347
}
381348

@@ -546,14 +513,10 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin,
546513

547514
static int gpio_nrfx_pm_suspend(const struct device *port)
548515
{
549-
#ifdef CONFIG_SOC_NRF54H20_GPD
516+
#if NRF_GPIO_HAS_PAD_GROUP
550517
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
551518

552-
if (cfg->pad_pd != NRF_GPD_FAST_ACTIVE1) {
553-
return 0;
554-
}
555-
556-
return nrf_gpd_release(NRF_GPD_FAST_ACTIVE1);
519+
return pm_device_runtime_put(cfg->pad_group);
557520
#else
558521
ARG_UNUSED(port);
559522
return 0;
@@ -562,14 +525,10 @@ static int gpio_nrfx_pm_suspend(const struct device *port)
562525

563526
static int gpio_nrfx_pm_resume(const struct device *port)
564527
{
565-
#ifdef CONFIG_SOC_NRF54H20_GPD
528+
#if NRF_GPIO_HAS_PAD_GROUP
566529
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
567530

568-
if (cfg->pad_pd != NRF_GPD_FAST_ACTIVE1) {
569-
return 0;
570-
}
571-
572-
return nrf_gpd_request(NRF_GPD_FAST_ACTIVE1);
531+
return pm_device_runtime_get(cfg->pad_group);
573532
#else
574533
ARG_UNUSED(port);
575534
return 0;
@@ -660,12 +619,11 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
660619
"Please enable GPIOTE instance for used GPIO port!")), \
661620
())
662621

663-
#ifdef CONFIG_SOC_NRF54H20_GPD
664-
#define PAD_PD(inst) \
665-
.pad_pd = DT_INST_PHA_BY_NAME_OR(inst, power_domains, pad, id, \
666-
NRF_GPD_SLOW_MAIN),
622+
#if NRF_GPIO_HAS_PAD_GROUP
623+
#define GPIO_NRF_PAD_GROUP_INIT(id) \
624+
.pad_group = DEVICE_DT_GET(DT_INST_CHILD(id, pad_group)),
667625
#else
668-
#define PAD_PD(inst)
626+
#define GPIO_NRF_PAD_GROUP_INIT(id)
669627
#endif
670628

671629
#define GPIO_NRF_DEVICE(id) \
@@ -679,7 +637,7 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
679637
.port_num = DT_INST_PROP(id, port), \
680638
.edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0), \
681639
.gpiote = GPIOTE_INSTANCE(id), \
682-
PAD_PD(id) \
640+
GPIO_NRF_PAD_GROUP_INIT(id) \
683641
}; \
684642
\
685643
static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \

drivers/pinctrl/pinctrl_nrf.c

Lines changed: 38 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -111,89 +111,63 @@ static const nrf_gpio_pin_drive_t drive_modes[NRF_DRIVE_COUNT] = {
111111
#define NRF_PSEL_TDM(reg, line) ((NRF_TDM_Type *)reg)->PSEL.line
112112
#endif
113113

114-
#define PAD_PD_EXISTS(node_id) \
115-
COND_CODE_1( \
116-
DT_NODE_EXISTS(node_id), \
117-
(DT_NODE_HAS_PROP(node_id, power_domains)), \
118-
(0) \
119-
)
120-
121-
#define PAD_PD_DEV_GET_OR_NULL(node_id) \
122-
COND_CODE_1( \
123-
DT_NODE_EXISTS(node_id), \
124-
(DEVICE_DT_GET_OR_NULL(DT_PHANDLE(node_id, power_domains))), \
125-
(NULL) \
126-
)
127-
128-
#define PORTS_HAVE_PD \
129-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p0)) || \
130-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p1)) || \
131-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p2)) || \
132-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p3)) || \
133-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p4)) || \
134-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p5)) || \
135-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p6)) || \
136-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p7)) || \
137-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p8)) || \
138-
PAD_PD_EXISTS(DT_NODELABEL(pad_group_p9))
139-
140-
#if PORTS_HAVE_PD
141-
142-
static const struct device *const pad_pd_devs[] = {
143-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p0)),
144-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p1)),
145-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p2)),
146-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p3)),
147-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p4)),
148-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p5)),
149-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p6)),
150-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p7)),
151-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p8)),
152-
PAD_PD_DEV_GET_OR_NULL(DT_NODELABEL(pad_group_p9)),
114+
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_gpio_pad_group)
115+
#define NRF_GPIO_HAS_PAD_GROUP 1
116+
#else
117+
#define NRF_GPIO_HAS_PAD_GROUP 0
118+
#endif
119+
120+
#if NRF_GPIO_HAS_PAD_GROUP
121+
122+
static const struct device *const pad_groups[] = {
123+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group0)),
124+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group1)),
125+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group2)),
126+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group3)),
127+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group4)),
128+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group5)),
129+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group6)),
130+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group7)),
131+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group8)),
132+
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(gpio_pad_group9)),
153133
};
154134

155-
static atomic_t pad_pd_masks[ARRAY_SIZE(pad_pd_devs)];
135+
static atomic_t pad_group_masks[ARRAY_SIZE(pad_groups)];
156136

157-
static int pad_pd_request_pin(uint16_t pin_number)
137+
static int pad_group_request_pin(uint16_t pin_number)
158138
{
159139
uint8_t port_number = NRF_GET_PORT(pin_number);
160-
uint16_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
161-
const struct device *pad_pd_dev = pad_pd_devs[port_number];
162-
atomic_t *pad_pd_mask = &pad_pd_masks[port_number];
140+
uint8_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
141+
const struct device *pad_group = pad_groups[port_number];
142+
atomic_t *pad_group_mask = &pad_group_masks[port_number];
163143

164-
if (atomic_test_and_set_bit(pad_pd_mask, port_pin_number)) {
144+
if (atomic_test_and_set_bit(pad_group_mask, port_pin_number)) {
165145
/* already requested */
166146
return 0;
167147
}
168148

169-
if (pm_device_runtime_get(pad_pd_dev)) {
170-
atomic_clear_bit(pad_pd_mask, port_pin_number);
149+
if (pm_device_runtime_get(pad_group)) {
150+
atomic_clear_bit(pad_group_mask, port_pin_number);
171151
return -EIO;
172152
}
173153

174-
/* power domain now active, retain can be disabled */
175-
nrf_gpio_pin_retain_disable(pin_number);
176154
return 0;
177155
}
178156

179-
static int pad_pd_release_pin(uint16_t pin_number)
157+
static int pad_group_release_pin(uint16_t pin_number)
180158
{
181159
uint8_t port_number = NRF_GET_PORT(pin_number);
182-
uint16_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
183-
const struct device *pad_pd_dev = pad_pd_devs[port_number];
184-
atomic_t *pad_pd_mask = &pad_pd_masks[port_number];
160+
uint8_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
161+
const struct device *pad_group = pad_groups[port_number];
162+
atomic_t *pad_group_mask = &pad_group_masks[port_number];
185163

186-
if (!atomic_test_and_clear_bit(pad_pd_mask, port_pin_number)) {
164+
if (!atomic_test_and_clear_bit(pad_group_mask, port_pin_number)) {
187165
/* already released */
188166
return 0;
189167
}
190168

191-
/* power domain may become inactive, retain shall be enabled */
192-
nrf_gpio_pin_retain_enable(pin_number);
193-
194-
if (pm_device_runtime_put(pad_pd_dev)) {
195-
nrf_gpio_pin_retain_disable(pin_number);
196-
atomic_set_bit(pad_pd_mask, port_pin_number);
169+
if (pm_device_runtime_put(pad_group)) {
170+
atomic_set_bit(pad_group_mask, port_pin_number);
197171
return -EIO;
198172
}
199173

@@ -202,13 +176,13 @@ static int pad_pd_release_pin(uint16_t pin_number)
202176

203177
#else
204178

205-
static int pad_pd_request_pin(uint16_t pin_number)
179+
static int pad_group_request_pin(uint16_t pin_number)
206180
{
207181
ARG_UNUSED(pin_number);
208182
return 0;
209183
}
210184

211-
static int pad_pd_release_pin(uint16_t pin_number)
185+
static int pad_group_release_pin(uint16_t pin_number)
212186
{
213187
ARG_UNUSED(pin_number);
214188
return 0;
@@ -590,7 +564,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
590564
uint32_t pin = psel;
591565

592566
/* enable pin */
593-
pad_pd_request_pin(pin);
567+
pad_group_request_pin(pin);
594568
port_pin_clock_set(pin, NRF_GET_CLOCKPIN_ENABLE(pins[i]));
595569

596570
if (write != NO_WRITE) {
@@ -609,7 +583,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
609583

610584
if (NRF_GET_LP(pins[i]) == NRF_LP_ENABLE) {
611585
/* disable pin */
612-
pad_pd_release_pin(pin);
586+
pad_group_release_pin(pin);
613587
port_pin_clock_set(pin, false);
614588
}
615589
}

drivers/power_domain/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@ zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_INTEL_ADSP power_domain_intel_a
99
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_NXP_SCU power_domain_nxp_scu.c)
1010
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_NRFS_GDPWR power_domain_nrfs_gdpwr.c)
1111
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_NRFS_SWEXT power_domain_nrfs_swext.c)
12+
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_NRF_GPIO_PAD_GROUP power_domain_nrf_gpio_pad_group.c)
1213
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_SOC_PM_STATE power_domain_soc_state_change.c)
1314
zephyr_library_sources_ifdef(CONFIG_POWER_DOMAIN_TISCI power_domain_tisci.c)

drivers/power_domain/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,5 +125,6 @@ endif #POWER_DOMAIN_TISCI
125125

126126
rsource "Kconfig.nrfs_swext"
127127
rsource "Kconfig.nrfs_gdpwr"
128+
rsource "Kconfig.nrf_gpio_pad_group"
128129

129130
endif
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
config POWER_DOMAIN_NRF_GPIO_PAD_GROUP
5+
bool "NRFS Global Domain Power Request driver"
6+
depends on DT_HAS_NORDIC_NRF_GPIO_PAD_GROUP_ENABLED
7+
default y

0 commit comments

Comments
 (0)