1212#include <zephyr/dt-bindings/gpio/nordic-nrf-gpio.h>
1313#include <zephyr/irq.h>
1414#include <zephyr/pm/device.h>
15- #include <zephyr/pm/device_runtime.h>
1615
1716#include <zephyr/drivers/gpio/gpio_utils.h>
1817
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
23- #endif
24-
2518#define GPIOTE_PHANDLE (id ) DT_INST_PHANDLE(id, gpiote_instance)
2619#define GPIOTE_PROP (idx , prop ) DT_PROP(GPIOTE(idx), prop)
2720
@@ -55,9 +48,6 @@ struct gpio_nrfx_cfg {
5548 uint32_t edge_sense ;
5649 uint8_t port_num ;
5750 nrfx_gpiote_t gpiote ;
58- #if GPIO_HAS_PAD_GROUP
59- const struct device * pad_group ;
60- #endif
6151#if defined(GPIOTE_FEATURE_FLAG )
6252 uint32_t flags ;
6353#endif
@@ -78,6 +68,34 @@ static bool has_gpiote(const struct gpio_nrfx_cfg *cfg)
7868 return cfg -> gpiote .p_reg != NULL ;
7969}
8070
71+ #if NRF_GPIO_HAS_RETENTION_SETCLEAR
72+
73+ static void port_retain_set (const struct gpio_nrfx_cfg * cfg , uint32_t mask )
74+ {
75+ nrf_gpio_port_retain_enable (cfg -> port , mask );
76+ }
77+
78+ static void port_retain_clear (const struct gpio_nrfx_cfg * cfg , uint32_t mask )
79+ {
80+ nrf_gpio_port_retain_disable (cfg -> port , mask );
81+ }
82+
83+ #else
84+
85+ static void port_retain_set (const struct gpio_nrfx_cfg * cfg , uint32_t mask )
86+ {
87+ ARG_UNUSED (cfg );
88+ ARG_UNUSED (mask );
89+ }
90+
91+ static void port_retain_clear (const struct gpio_nrfx_cfg * cfg , uint32_t mask )
92+ {
93+ ARG_UNUSED (cfg );
94+ ARG_UNUSED (mask );
95+ }
96+
97+ #endif
98+
8199static nrf_gpio_pin_pull_t get_pull (gpio_flags_t flags )
82100{
83101 if (flags & GPIO_PULL_UP ) {
@@ -100,7 +118,6 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
100118 nrfx_gpiote_pin_t abs_pin = NRF_GPIO_PIN_MAP (cfg -> port_num , pin );
101119 nrf_gpio_pin_pull_t pull = get_pull (flags );
102120 nrf_gpio_pin_drive_t drive ;
103- int pm_ret ;
104121
105122 switch (flags & (NRF_GPIO_DRIVE_MSK | GPIO_OPEN_DRAIN )) {
106123 case NRF_GPIO_DRIVE_S0S1 :
@@ -131,10 +148,7 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
131148 return - EINVAL ;
132149 }
133150
134- ret = pm_device_runtime_get (port );
135- if (ret < 0 ) {
136- return ret ;
137- }
151+ port_retain_clear (cfg , BIT (pin ));
138152
139153 if (flags & GPIO_OUTPUT_INIT_HIGH ) {
140154 nrf_gpio_port_out_set (cfg -> port , BIT (pin ));
@@ -196,6 +210,8 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
196210
197211 err = nrfx_gpiote_output_configure (& cfg -> gpiote ,
198212 abs_pin , & output_config , NULL );
213+
214+ port_retain_set (cfg , BIT (pin ));
199215 } else {
200216 nrfx_gpiote_input_pin_config_t input_pin_config = {
201217 .p_pull_config = & pull ,
@@ -223,11 +239,11 @@ static int gpio_nrfx_pin_configure(const struct device *port, gpio_pin_t pin,
223239 }
224240
225241end :
226- pm_ret = pm_device_runtime_put (port );
227-
228- return (ret != 0 ) ? ret : pm_ret ;
242+ return ret ;
229243}
230244
245+
246+
231247#ifdef CONFIG_GPIO_GET_CONFIG
232248static int gpio_nrfx_pin_get_config (const struct device * port , gpio_pin_t pin ,
233249 gpio_flags_t * flags )
@@ -315,49 +331,37 @@ static int gpio_nrfx_port_set_masked_raw(const struct device *port,
315331 gpio_port_value_t value )
316332{
317333 NRF_GPIO_Type * reg = get_port_cfg (port )-> port ;
318- int ret ;
319334
320335 const uint32_t set_mask = value & mask ;
321336 const uint32_t clear_mask = (~set_mask ) & mask ;
322337
323- ret = pm_device_runtime_get (port );
324- if (ret < 0 ) {
325- return ret ;
326- }
327-
338+ port_retain_clear (get_port_cfg (port ), mask );
328339 nrf_gpio_port_out_set (reg , set_mask );
329340 nrf_gpio_port_out_clear (reg , clear_mask );
330- return pm_device_runtime_put (port );
341+ port_retain_set (get_port_cfg (port ), mask );
342+ return 0 ;
331343}
332344
333345static int gpio_nrfx_port_set_bits_raw (const struct device * port ,
334346 gpio_port_pins_t mask )
335347{
336348 NRF_GPIO_Type * reg = get_port_cfg (port )-> port ;
337- int ret ;
338-
339- ret = pm_device_runtime_get (port );
340- if (ret < 0 ) {
341- return ret ;
342- }
343349
350+ port_retain_clear (get_port_cfg (port ), mask );
344351 nrf_gpio_port_out_set (reg , mask );
345- return pm_device_runtime_put (port );
352+ port_retain_set (get_port_cfg (port ), mask );
353+ return 0 ;
346354}
347355
348356static int gpio_nrfx_port_clear_bits_raw (const struct device * port ,
349357 gpio_port_pins_t mask )
350358{
351359 NRF_GPIO_Type * reg = get_port_cfg (port )-> port ;
352- int ret ;
353-
354- ret = pm_device_runtime_get (port );
355- if (ret < 0 ) {
356- return ret ;
357- }
358360
361+ port_retain_clear (get_port_cfg (port ), mask );
359362 nrf_gpio_port_out_clear (reg , mask );
360- return pm_device_runtime_put (port );
363+ port_retain_set (get_port_cfg (port ), mask );
364+ return 0 ;
361365}
362366
363367static int gpio_nrfx_port_toggle_bits (const struct device * port ,
@@ -367,16 +371,12 @@ static int gpio_nrfx_port_toggle_bits(const struct device *port,
367371 const uint32_t value = nrf_gpio_port_out_read (reg ) ^ mask ;
368372 const uint32_t set_mask = value & mask ;
369373 const uint32_t clear_mask = (~value ) & mask ;
370- int ret ;
371-
372- ret = pm_device_runtime_get (port );
373- if (ret < 0 ) {
374- return ret ;
375- }
376374
375+ port_retain_clear (get_port_cfg (port ), mask );
377376 nrf_gpio_port_out_set (reg , set_mask );
378377 nrf_gpio_port_out_clear (reg , clear_mask );
379- return pm_device_runtime_put (port );
378+ port_retain_set (get_port_cfg (port ), mask );
379+ return 0 ;
380380}
381381
382382#ifdef CONFIG_GPIO_NRFX_INTERRUPT
@@ -580,47 +580,11 @@ static void nrfx_gpio_handler(nrfx_gpiote_pin_t abs_pin,
580580 IRQ_CONNECT(DT_IRQN(node_id), DT_IRQ(node_id, priority), nrfx_isr, \
581581 NRFX_CONCAT(nrfx_gpiote_, DT_PROP(node_id, instance), _irq_handler), 0);
582582
583- static int gpio_nrfx_pm_suspend (const struct device * port )
584- {
585- #if GPIO_HAS_PAD_GROUP
586- const struct gpio_nrfx_cfg * cfg = get_port_cfg (port );
587-
588- return pm_device_runtime_put (cfg -> pad_group );
589- #else
590- ARG_UNUSED (port );
591- return 0 ;
592- #endif
593- }
594-
595- static int gpio_nrfx_pm_resume (const struct device * port )
583+ static int gpio_nrfx_pm_hook (const struct device * port , enum pm_device_action action )
596584{
597- #if GPIO_HAS_PAD_GROUP
598- const struct gpio_nrfx_cfg * cfg = get_port_cfg (port );
599-
600- return pm_device_runtime_get (cfg -> pad_group );
601- #else
602585 ARG_UNUSED (port );
586+ ARG_UNUSED (action );
603587 return 0 ;
604- #endif
605- }
606-
607- static int gpio_nrfx_pm_hook (const struct device * port , enum pm_device_action action )
608- {
609- int ret ;
610-
611- switch (action ) {
612- case PM_DEVICE_ACTION_SUSPEND :
613- ret = gpio_nrfx_pm_suspend (port );
614- break ;
615- case PM_DEVICE_ACTION_RESUME :
616- ret = gpio_nrfx_pm_resume (port );
617- break ;
618- default :
619- ret = - ENOTSUP ;
620- break ;
621- }
622-
623- return ret ;
624588}
625589
626590static int gpio_nrfx_init (const struct device * port )
@@ -687,13 +651,6 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
687651 "Please enable GPIOTE instance for used GPIO port!")), \
688652 ())
689653
690- #if GPIO_HAS_PAD_GROUP
691- #define GPIO_NRF_PAD_GROUP_INIT (id ) \
692- .pad_group = DEVICE_DT_GET(DT_INST_CHILD(id, pad_group)),
693- #else
694- #define GPIO_NRF_PAD_GROUP_INIT (id )
695- #endif
696-
697654#define GPIO_NRF_DEVICE (id ) \
698655 GPIOTE_CHECK(id); \
699656 static const struct gpio_nrfx_cfg gpio_nrfx_p##id##_cfg = { \
@@ -705,7 +662,6 @@ static DEVICE_API(gpio, gpio_nrfx_drv_api_funcs) = {
705662 .port_num = DT_INST_PROP(id, port), \
706663 .edge_sense = DT_INST_PROP_OR(id, sense_edge_mask, 0), \
707664 .gpiote = GPIOTE_INSTANCE(id), \
708- GPIO_NRF_PAD_GROUP_INIT(id) \
709665 IF_ENABLED(GPIOTE_FEATURE_FLAG, \
710666 (.flags = \
711667 (DT_PROP_OR(GPIOTE_PHANDLE(id), no_port_event, 0) ? \
0 commit comments