Skip to content

Commit 5e7028a

Browse files
[nrf fromlist] drivers: pinctrl: nrf: simplify pin retention
GPIO pad power domain management is not neccesary if the quirky cross domain feature is handled at the application level. Replace it with directly setting/clearing pin retention, as hardware will force power domains on automatically. Upstream PR #: 97452 Signed-off-by: Bjarki Arge Andreasen <[email protected]>
1 parent a9e1626 commit 5e7028a

File tree

1 file changed

+10
-63
lines changed

1 file changed

+10
-63
lines changed

drivers/pinctrl/pinctrl_nrf.c

Lines changed: 10 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*/
66

77
#include <zephyr/drivers/pinctrl.h>
8-
#include <zephyr/pm/device_runtime.h>
98
#include <zephyr/sys/atomic.h>
109

1110
#include <hal/nrf_gpio.h>
@@ -111,75 +110,23 @@ static const nrf_gpio_pin_drive_t drive_modes[NRF_DRIVE_COUNT] = {
111110
#define NRF_PSEL_TDM(reg, line) ((NRF_TDM_Type *)reg)->PSEL.line
112111
#endif
113112

114-
#if DT_HAS_COMPAT_STATUS_OKAY(nordic_nrf_gpio_pad_group)
115-
#define GPIO_HAS_PAD_GROUP 1
116-
#else
117-
#define GPIO_HAS_PAD_GROUP 0
118-
#endif
119-
120-
#if GPIO_HAS_PAD_GROUP
121-
122-
#define GPIO_PAD_GROUP_GET_OR_NULL(idx, _) \
123-
DEVICE_DT_GET_OR_NULL(DT_NODELABEL(_CONCAT(gpio_pad_group, idx)))
124-
125-
static const struct device *const pad_groups[] = {
126-
LISTIFY(10, GPIO_PAD_GROUP_GET_OR_NULL, (,))
127-
};
128-
129-
static atomic_t pad_group_masks[ARRAY_SIZE(pad_groups)];
130-
131-
static int pad_group_request_pin(uint16_t pin_number)
132-
{
133-
uint8_t port_number = NRF_GET_PORT(pin_number);
134-
uint8_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
135-
const struct device *pad_group = pad_groups[port_number];
136-
atomic_t *pad_group_mask = &pad_group_masks[port_number];
137-
138-
if (atomic_test_and_set_bit(pad_group_mask, port_pin_number)) {
139-
/* already requested */
140-
return 0;
141-
}
142-
143-
if (pm_device_runtime_get(pad_group)) {
144-
atomic_clear_bit(pad_group_mask, port_pin_number);
145-
return -EIO;
146-
}
147-
148-
return 0;
149-
}
113+
#if NRF_GPIO_HAS_RETENTION_SETCLEAR
150114

151-
static int pad_group_release_pin(uint16_t pin_number)
115+
static void port_pin_retain_set(uint16_t pin_number, bool enable)
152116
{
153-
uint8_t port_number = NRF_GET_PORT(pin_number);
154-
uint8_t port_pin_number = NRF_GET_PORT_PIN(pin_number);
155-
const struct device *pad_group = pad_groups[port_number];
156-
atomic_t *pad_group_mask = &pad_group_masks[port_number];
157-
158-
if (!atomic_test_and_clear_bit(pad_group_mask, port_pin_number)) {
159-
/* already released */
160-
return 0;
161-
}
162-
163-
if (pm_device_runtime_put(pad_group)) {
164-
atomic_set_bit(pad_group_mask, port_pin_number);
165-
return -EIO;
117+
if (enable) {
118+
nrf_gpio_pin_retain_enable(pin_number);
119+
} else {
120+
nrf_gpio_pin_retain_disable(pin_number);
166121
}
167-
168-
return 0;
169122
}
170123

171124
#else
172125

173-
static int pad_group_request_pin(uint16_t pin_number)
126+
static void port_pin_retain_set(uint16_t pin_number, bool enable)
174127
{
175128
ARG_UNUSED(pin_number);
176-
return 0;
177-
}
178-
179-
static int pad_group_release_pin(uint16_t pin_number)
180-
{
181-
ARG_UNUSED(pin_number);
182-
return 0;
129+
ARG_UNUSED(enable);
183130
}
184131

185132
#endif
@@ -610,7 +557,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
610557
uint32_t pin = psel;
611558

612559
/* enable pin */
613-
pad_group_request_pin(pin);
560+
port_pin_retain_set(pin, false);
614561

615562
if (write != NO_WRITE) {
616563
nrf_gpio_pin_write(pin, write);
@@ -628,7 +575,7 @@ int pinctrl_configure_pins(const pinctrl_soc_pin_t *pins, uint8_t pin_cnt,
628575

629576
if (NRF_GET_LP(pins[i]) == NRF_LP_ENABLE) {
630577
/* disable pin and pin clock */
631-
pad_group_release_pin(pin);
578+
port_pin_retain_set(pin, true);
632579
port_pin_clock_set(pin, false);
633580
} else {
634581
/* configure pin clock */

0 commit comments

Comments
 (0)