Skip to content

Commit 88d003b

Browse files
drivers: power_domain: introduce nrf_gpio_pad_group
Introduce the NRF GPIO Pad Group device driver and binding. The pad group device represents the GPIO pads (pins), contrary to a GPIO controller, which is one of the many devices which can be muxed to pads in the pad group. The pad group belong to a power domain, which is not neccesarily the same power domain as devices being muxed to the pads, like GPIO or UART. If no ACTIVE device is using any of the pads in the pad group, the pad groups power domain may be SUSPENDED. Before the pad groups power domain is SUSPENDED, pad config retention must be enabled to prevent the pads from loosing their state. That's what this device driver manages. Once retained, the pad configs and outputs are locked, even when their power domain is SUSPENDED. Signed-off-by: Bjarki Arge Andreasen <bjarki.andreasen@nordicsemi.no>
1 parent 0aecde7 commit 88d003b

File tree

5 files changed

+134
-0
lines changed

5 files changed

+134
-0
lines changed

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_gdpwr"
127127
rsource "Kconfig.nrfs_swext"
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
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#define DT_DRV_COMPAT nordic_nrf_gpio_pad_group
8+
9+
#include <zephyr/kernel.h>
10+
#include <zephyr/device.h>
11+
#include <zephyr/pm/device.h>
12+
#include <zephyr/logging/log.h>
13+
14+
#include <hal/nrf_gpio.h>
15+
16+
LOG_MODULE_REGISTER(nrf_gpio_pad_group, CONFIG_POWER_DOMAIN_LOG_LEVEL);
17+
18+
struct nrf_port_retain_config {
19+
NRF_GPIO_Type *regs;
20+
uint32_t retain_mask;
21+
};
22+
23+
static void nrf_port_retain_driver_turn_off(const struct device *dev)
24+
{
25+
const struct nrf_port_retain_config *dev_config = dev->config;
26+
27+
LOG_DBG("%s pads 0x%08x retain %s", dev->name, dev_config->retain_mask, "enable");
28+
nrf_gpio_port_retain_enable(dev_config->regs, dev_config->retain_mask);
29+
}
30+
31+
static void nrf_port_retain_driver_turn_on(const struct device *dev)
32+
{
33+
const struct nrf_port_retain_config *dev_config = dev->config;
34+
35+
LOG_DBG("%s pads 0x%08x retain %s", dev->name, dev_config->retain_mask, "disable");
36+
nrf_gpio_port_retain_disable(dev_config->regs, dev_config->retain_mask);
37+
}
38+
39+
static int nrf_port_retain_driver_pm_action(const struct device *dev,
40+
enum pm_device_action action)
41+
{
42+
switch (action) {
43+
case PM_DEVICE_ACTION_TURN_OFF:
44+
nrf_port_retain_driver_turn_off(dev);
45+
break;
46+
47+
case PM_DEVICE_ACTION_TURN_ON:
48+
nrf_port_retain_driver_turn_on(dev);
49+
break;
50+
51+
default:
52+
break;
53+
};
54+
55+
return 0;
56+
}
57+
58+
static int nrf_port_retain_driver_init(const struct device *dev)
59+
{
60+
return pm_device_driver_init(dev, nrf_port_retain_driver_pm_action);
61+
}
62+
63+
#define NRF_GPIO_PAD_GROUP_DEFINE(inst) \
64+
static const struct nrf_port_retain_config _CONCAT(config, inst) = { \
65+
.regs = (NRF_GPIO_Type *)DT_REG_ADDR(DT_INST_PARENT(inst)), \
66+
.retain_mask = DT_PROP_OR(inst, retain_mask, UINT32_MAX), \
67+
}; \
68+
\
69+
PM_DEVICE_DT_INST_DEFINE(inst, nrf_port_retain_driver_pm_action); \
70+
\
71+
DEVICE_DT_INST_DEFINE( \
72+
inst, \
73+
nrf_port_retain_driver_init, \
74+
PM_DEVICE_DT_INST_GET(inst), \
75+
NULL, \
76+
&_CONCAT(config, inst), \
77+
PRE_KERNEL_1, \
78+
UTIL_INC(CONFIG_GPIO_INIT_PRIORITY), \
79+
NULL \
80+
);
81+
82+
DT_INST_FOREACH_STATUS_OKAY(NRF_GPIO_PAD_GROUP_DEFINE)
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Copyright 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: |
5+
Nordic nRF GPIO pad group.
6+
7+
The GPIO pad group describes the pads (package
8+
pins of the SoC) the GPIO controller manages.
9+
10+
The pads may be in a different power domain than
11+
the GPIO controller, and may require enabling
12+
retention to preserve the GPIO configuration if
13+
the power domain is suspended.
14+
15+
The GPIO pad group is a child node of the GPIO
16+
controller which manages the the pad group,
17+
named pad-group. The pad group's nodelabel is
18+
named gpio_pad_group<GPIO number>.
19+
20+
Example layout:
21+
22+
gpio0: gpio@938000 {
23+
compatible = "nordic,nrf-gpio";
24+
25+
...
26+
27+
gpio_pad_group0: pad-group {
28+
compatible = "nordic,nrf-gpio-pad-group";
29+
power-domains = <&gdpwr_slow_main>;
30+
retain-mask = <0xFFF>;
31+
};
32+
};
33+
34+
compatible: "nordic,nrf-gpio-pad-group"
35+
36+
include: base.yaml
37+
38+
properties:
39+
retain-mask:
40+
type: int
41+
description: |
42+
Mask of pins which shall be retained if pad
43+
group's power domain is powered off.

0 commit comments

Comments
 (0)