Skip to content

Commit adf9462

Browse files
[nrf fromtree] soc: nordic: nrf54h: transition from gpd to zephyr pinctrl and pds
Transition nrf54h away from the soc specific gpd (global power domain) driver which mixed power domains, pinctrl and gpio pin retention into a non scalable solution, forcing soc specific logic to bleed into nrf drivers. The new solution uses zephyrs PM_DEVICE based power domains to properly model the hardware layout of device and pin power domains, and moves pin retention logic out of drivers into pinctrl and gpio, which are the components which manage pins (pads). Signed-off-by: Bjarki Arge Andreasen <[email protected]> (cherry picked from commit 2b0d1ae)
1 parent e3736fc commit adf9462

27 files changed

+586
-373
lines changed

drivers/can/can_nrf.c

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@
1717
#include <zephyr/drivers/pinctrl.h>
1818
#include <zephyr/irq.h>
1919

20-
#ifdef CONFIG_SOC_NRF54H20_GPD
21-
#include <nrf/gpd.h>
22-
#endif
23-
2420
/* nRF CAN wrapper offsets */
2521
#define CAN_TASKS_START offsetof(NRF_CAN_Type, TASKS_START)
2622
#define CAN_EVENTS_CORE_0 offsetof(NRF_CAN_Type, EVENTS_CORE[0])
@@ -187,13 +183,6 @@ static int can_nrf_init(const struct device *dev)
187183
sys_write32(CAN_INTEN_CORE0_Msk | CAN_INTEN_CORE1_Msk, config->wrapper + CAN_INTEN);
188184
sys_write32(1U, config->wrapper + CAN_TASKS_START);
189185

190-
#ifdef CONFIG_SOC_NRF54H20_GPD
191-
ret = nrf_gpd_retain_pins_set(config->pcfg, false);
192-
if (ret < 0) {
193-
return ret;
194-
}
195-
#endif
196-
197186
config->irq_configure();
198187

199188
ret = can_mcan_configure_mram(dev, config->mrba, config->mram);

drivers/counter/counter_nrfx_timer.c

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -35,23 +35,9 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME, LOG_LEVEL);
3535
#define MAYBE_CONST_CONFIG const
3636
#endif
3737

38-
#ifdef CONFIG_SOC_NRF54H20_GPD
39-
#include <nrf/gpd.h>
40-
41-
#define NRF_CLOCKS_INSTANCE_IS_FAST(node) \
42-
COND_CODE_1(DT_NODE_HAS_PROP(node, power_domains), \
43-
(IS_EQ(DT_PHA(node, power_domains, id), NRF_GPD_FAST_ACTIVE1)), \
44-
(0))
45-
46-
/* Macro must resolve to literal 0 or 1 */
47-
#define INSTANCE_IS_FAST(idx) NRF_CLOCKS_INSTANCE_IS_FAST(DT_DRV_INST(idx))
48-
49-
#define INSTANCE_IS_FAST_OR(idx) INSTANCE_IS_FAST(idx) ||
50-
51-
#if (DT_INST_FOREACH_STATUS_OKAY(INSTANCE_IS_FAST_OR) 0)
38+
#if NRF_DT_INST_ANY_IS_FAST
5239
#define COUNTER_ANY_FAST 1
5340
#endif
54-
#endif
5541

5642
struct counter_nrfx_data {
5743
counter_top_callback_t top_cb;
@@ -474,13 +460,13 @@ static DEVICE_API(counter, counter_nrfx_driver_api) = {
474460
* which is using nrfs (IPC) are initialized later.
475461
*/
476462
#define TIMER_INIT_LEVEL(idx) \
477-
COND_CODE_1(INSTANCE_IS_FAST(idx), (POST_KERNEL), (PRE_KERNEL_1))
463+
COND_CODE_1(NRF_DT_INST_IS_FAST(idx), (POST_KERNEL), (PRE_KERNEL_1))
478464

479465
/* Get initialization priority of an instance. Instances that requires clock control
480466
* which is using nrfs (IPC) are initialized later.
481467
*/
482468
#define TIMER_INIT_PRIO(idx) \
483-
COND_CODE_1(INSTANCE_IS_FAST(idx), \
469+
COND_CODE_1(NRF_DT_INST_IS_FAST(idx), \
484470
(UTIL_INC(CONFIG_CLOCK_CONTROL_NRF_HSFLL_GLOBAL_INIT_PRIORITY)), \
485471
(CONFIG_COUNTER_INIT_PRIORITY))
486472

@@ -536,7 +522,7 @@ static DEVICE_API(counter, counter_nrfx_driver_api) = {
536522
}, \
537523
.ch_data = counter##idx##_ch_data, \
538524
.timer = (NRF_TIMER_Type *)DT_INST_REG_ADDR(idx), \
539-
IF_ENABLED(INSTANCE_IS_FAST(idx), \
525+
IF_ENABLED(NRF_DT_INST_IS_FAST(idx), \
540526
(.clk_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(DT_DRV_INST(idx))), \
541527
.clk_spec = { \
542528
.frequency = NRF_PERIPH_GET_FREQUENCY(DT_DRV_INST(idx)), \

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 GPIO_HAS_PAD_GROUP 1
21+
#else
22+
#define GPIO_HAS_PAD_GROUP 0
2123
#endif
2224

2325
#define GPIOTE_PHANDLE(id) DT_INST_PHANDLE(id, gpiote_instance)
@@ -56,8 +58,8 @@ struct gpio_nrfx_cfg {
5658
#if defined(GPIOTE_FEATURE_FLAG)
5759
uint32_t flags;
5860
#endif
59-
#ifdef CONFIG_SOC_NRF54H20_GPD
60-
uint8_t pad_pd;
61+
#if GPIO_HAS_PAD_GROUP
62+
const struct device *pad_group;
6163
#endif
6264
};
6365

@@ -87,30 +89,6 @@ static nrf_gpio_pin_pull_t get_pull(gpio_flags_t flags)
8789
return NRF_GPIO_PIN_NOPULL;
8890
}
8991

90-
static void gpio_nrfx_gpd_retain_set(const struct device *port, uint32_t mask)
91-
{
92-
#ifdef CONFIG_SOC_NRF54H20_GPD
93-
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
94-
95-
nrf_gpio_port_retain_enable(cfg->port, mask);
96-
#else
97-
ARG_UNUSED(port);
98-
ARG_UNUSED(mask);
99-
#endif
100-
}
101-
102-
static void gpio_nrfx_gpd_retain_clear(const struct device *port, uint32_t mask)
103-
{
104-
#ifdef CONFIG_SOC_NRF54H20_GPD
105-
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
106-
107-
nrf_gpio_port_retain_disable(cfg->port, mask);
108-
#else
109-
ARG_UNUSED(port);
110-
ARG_UNUSED(mask);
111-
#endif
112-
}
113-
11492
static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
11593
gpio_flags_t flags)
11694
{
@@ -157,8 +135,6 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
157135
return ret;
158136
}
159137

160-
gpio_nrfx_gpd_retain_clear(port, BIT(pin));
161-
162138
if (flags & GPIO_OUTPUT_INIT_HIGH) {
163139
nrf_gpio_port_out_set(cfg->port, BIT(pin));
164140
} else if (flags & GPIO_OUTPUT_INIT_LOW) {
@@ -246,7 +222,6 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
246222
}
247223

248224
end:
249-
gpio_nrfx_gpd_retain_set(port, BIT(pin));
250225
int pm_ret = pm_device_runtime_put(port);
251226

252227
return (ret != 0) ? ret : pm_ret;
@@ -349,10 +324,8 @@ static int gpio_nrfx_port_set_masked_raw(const struct device *port,
349324
return ret;
350325
}
351326

352-
gpio_nrfx_gpd_retain_clear(port, mask);
353327
nrf_gpio_port_out_set(reg, set_mask);
354328
nrf_gpio_port_out_clear(reg, clear_mask);
355-
gpio_nrfx_gpd_retain_set(port, mask);
356329
return pm_device_runtime_put(port);
357330
}
358331

@@ -367,9 +340,7 @@ static int gpio_nrfx_port_set_bits_raw(const struct device *port,
367340
return ret;
368341
}
369342

370-
gpio_nrfx_gpd_retain_clear(port, mask);
371343
nrf_gpio_port_out_set(reg, mask);
372-
gpio_nrfx_gpd_retain_set(port, mask);
373344
return pm_device_runtime_put(port);
374345
}
375346

@@ -384,9 +355,7 @@ static int gpio_nrfx_port_clear_bits_raw(const struct device *port,
384355
return ret;
385356
}
386357

387-
gpio_nrfx_gpd_retain_clear(port, mask);
388358
nrf_gpio_port_out_clear(reg, mask);
389-
gpio_nrfx_gpd_retain_set(port, mask);
390359
return pm_device_runtime_put(port);
391360
}
392361

@@ -404,10 +373,8 @@ static int gpio_nrfx_port_toggle_bits(const struct device *port,
404373
return ret;
405374
}
406375

407-
gpio_nrfx_gpd_retain_clear(port, mask);
408376
nrf_gpio_port_out_set(reg, set_mask);
409377
nrf_gpio_port_out_clear(reg, clear_mask);
410-
gpio_nrfx_gpd_retain_set(port, mask);
411378
return pm_device_runtime_put(port);
412379
}
413380

@@ -614,14 +581,10 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin,
614581

615582
static int gpio_nrfx_pm_suspend(const struct device *port)
616583
{
617-
#ifdef CONFIG_SOC_NRF54H20_GPD
584+
#if GPIO_HAS_PAD_GROUP
618585
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
619586

620-
if (cfg->pad_pd != NRF_GPD_FAST_ACTIVE1) {
621-
return 0;
622-
}
623-
624-
return nrf_gpd_release(NRF_GPD_FAST_ACTIVE1);
587+
return pm_device_runtime_put(cfg->pad_group);
625588
#else
626589
ARG_UNUSED(port);
627590
return 0;
@@ -630,14 +593,10 @@ static int gpio_nrfx_pm_suspend(const struct device *port)
630593

631594
static int gpio_nrfx_pm_resume(const struct device *port)
632595
{
633-
#ifdef CONFIG_SOC_NRF54H20_GPD
596+
#if GPIO_HAS_PAD_GROUP
634597
const struct gpio_nrfx_cfg *cfg = get_port_cfg(port);
635598

636-
if (cfg->pad_pd != NRF_GPD_FAST_ACTIVE1) {
637-
return 0;
638-
}
639-
640-
return nrf_gpd_request(NRF_GPD_FAST_ACTIVE1);
599+
return pm_device_runtime_get(cfg->pad_group);
641600
#else
642601
ARG_UNUSED(port);
643602
return 0;
@@ -727,12 +686,11 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
727686
"Please enable GPIOTE instance for used GPIO port!")), \
728687
())
729688

730-
#ifdef CONFIG_SOC_NRF54H20_GPD
731-
#define PAD_PD(inst) \
732-
.pad_pd = DT_INST_PHA_BY_NAME_OR(inst, power_domains, pad, id, \
733-
NRF_GPD_SLOW_MAIN),
689+
#if GPIO_HAS_PAD_GROUP
690+
#define GPIO_NRF_PAD_GROUP_INIT(id) \
691+
.pad_group = DEVICE_DT_GET(DT_INST_CHILD(id, pad_group)),
734692
#else
735-
#define PAD_PD(inst)
693+
#define GPIO_NRF_PAD_GROUP_INIT(id)
736694
#endif
737695

738696
#define GPIO_NRF_DEVICE(id) \
@@ -753,7 +711,7 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
753711
(DT_PROP_OR(GPIOTE_PHANDLE(id), fixed_channels_supported, 0) ? \
754712
GPIOTE_FLAG_FIXED_CHAN : 0),) \
755713
) \
756-
PAD_PD(id) \
714+
GPIO_NRF_PAD_GROUP_INIT(id) \
757715
}; \
758716
\
759717
static struct gpio_nrfx_data gpio_nrfx_p##id##_data; \

0 commit comments

Comments
 (0)