Skip to content

Commit 2f3a5ab

Browse files
committed
[nrf fromlist] drivers: spi: nrf: align to nrfx_gpiote with extracted control block
GPIOTE driver instances are no longer defined within nrfx. Upstream PR #: 98527 Signed-off-by: Nikodem Kastelik <[email protected]>
1 parent e7f089c commit 2f3a5ab

File tree

4 files changed

+25
-23
lines changed

4 files changed

+25
-23
lines changed

drivers/spi/spi_nrfx_common.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#include "spi_nrfx_common.h"
88
#include <zephyr/kernel.h>
99

10-
int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin)
10+
int spi_nrfx_wake_init(nrfx_gpiote_t *gpiote, uint32_t wake_pin)
1111
{
1212
nrf_gpio_pin_pull_t pull_config = NRF_GPIO_PIN_PULLDOWN;
1313
uint8_t ch;
@@ -20,23 +20,23 @@ int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin)
2020
.p_trigger_config = &trigger_config,
2121
.p_handler_config = NULL,
2222
};
23-
nrfx_err_t res;
23+
int res;
2424

2525
res = nrfx_gpiote_channel_alloc(gpiote, &ch);
26-
if (res != NRFX_SUCCESS) {
27-
return -ENODEV;
26+
if (res < 0) {
27+
return res;
2828
}
2929

3030
res = nrfx_gpiote_input_configure(gpiote, wake_pin, &input_config);
31-
if (res != NRFX_SUCCESS) {
31+
if (res < 0) {
3232
nrfx_gpiote_channel_free(gpiote, ch);
33-
return -EIO;
33+
return res;
3434
}
3535

3636
return 0;
3737
}
3838

39-
int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin)
39+
int spi_nrfx_wake_request(nrfx_gpiote_t *gpiote, uint32_t wake_pin)
4040
{
4141
nrf_gpiote_event_t trigger_event = nrfx_gpiote_in_event_get(gpiote, wake_pin);
4242
uint32_t start_cycles;

drivers/spi/spi_nrfx_common.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@
99

1010
#include <stdint.h>
1111
#include <nrfx_gpiote.h>
12+
#include <gpiote_nrfx.h>
13+
#include <zephyr/drivers/gpio/gpio_nrf.h>
1214

1315
#define WAKE_PIN_NOT_USED UINT32_MAX
1416

15-
#define WAKE_GPIOTE_INSTANCE(node_id) \
16-
COND_CODE_1(DT_NODE_HAS_PROP(node_id, wake_gpios), \
17-
(NRFX_GPIOTE_INSTANCE( \
18-
NRF_DT_GPIOTE_INST(node_id, wake_gpios))), \
19-
({0}))
17+
#define WAKE_GPIOTE_NODE(node_id) \
18+
COND_CODE_1(DT_NODE_HAS_PROP(node_id, wake_gpios), \
19+
(&GPIOTE_NRFX_INST_BY_NODE(DT_PHANDLE(DT_PHANDLE(node_id, wake_gpios), \
20+
gpiote_instance))), \
21+
(NULL))
2022

21-
int spi_nrfx_wake_init(const nrfx_gpiote_t *gpiote, uint32_t wake_pin);
22-
int spi_nrfx_wake_request(const nrfx_gpiote_t *gpiote, uint32_t wake_pin);
23+
int spi_nrfx_wake_init(nrfx_gpiote_t *gpiote, uint32_t wake_pin);
24+
int spi_nrfx_wake_request(nrfx_gpiote_t *gpiote, uint32_t wake_pin);
2325

2426
#endif /* ZEPHYR_DRIVERS_SPI_NRFX_COMMON_H_ */

drivers/spi/spi_nrfx_spi.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ struct spi_nrfx_config {
3131
nrfx_spi_config_t def_config;
3232
void (*irq_connect)(void);
3333
const struct pinctrl_dev_config *pcfg;
34+
nrfx_gpiote_t *wake_gpiote;
3435
uint32_t wake_pin;
35-
nrfx_gpiote_t wake_gpiote;
3636
};
3737

3838
static void event_handler(const nrfx_spi_evt_t *p_event, void *p_context);
@@ -241,7 +241,7 @@ static int transceive(const struct device *dev,
241241
dev_data->busy = true;
242242

243243
if (dev_config->wake_pin != WAKE_PIN_NOT_USED) {
244-
error = spi_nrfx_wake_request(&dev_config->wake_gpiote,
244+
error = spi_nrfx_wake_request(dev_config->wake_gpiote,
245245
dev_config->wake_pin);
246246
if (error == -ETIMEDOUT) {
247247
LOG_WRN("Waiting for WAKE acknowledgment timed out");
@@ -395,7 +395,7 @@ static int spi_nrfx_init(const struct device *dev)
395395
}
396396

397397
if (dev_config->wake_pin != WAKE_PIN_NOT_USED) {
398-
err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin);
398+
err = spi_nrfx_wake_init(dev_config->wake_gpiote, dev_config->wake_pin);
399399
if (err == -ENODEV) {
400400
LOG_ERR("Failed to allocate GPIOTE channel for WAKE");
401401
return err;
@@ -458,9 +458,9 @@ static int spi_nrfx_init(const struct device *dev)
458458
}, \
459459
.irq_connect = irq_connect##idx, \
460460
.pcfg = PINCTRL_DT_DEV_CONFIG_GET(SPI(idx)), \
461+
.wake_gpiote = WAKE_GPIOTE_NODE(SPI(idx)), \
461462
.wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(SPI(idx), wake_gpios, \
462463
WAKE_PIN_NOT_USED), \
463-
.wake_gpiote = WAKE_GPIOTE_INSTANCE(SPI(idx)), \
464464
}; \
465465
BUILD_ASSERT(!DT_NODE_HAS_PROP(SPI(idx), wake_gpios) || \
466466
!(DT_GPIO_FLAGS(SPI(idx), wake_gpios) & GPIO_ACTIVE_LOW), \

drivers/spi/spi_nrfx_spim.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,8 @@ struct spi_nrfx_config {
102102
void (*irq_connect)(void);
103103
uint16_t max_chunk_len;
104104
const struct pinctrl_dev_config *pcfg;
105+
nrfx_gpiote_t *wake_gpiote;
105106
uint32_t wake_pin;
106-
nrfx_gpiote_t wake_gpiote;
107107
#ifdef SPIM_ANY_FAST
108108
const struct device *clk_dev;
109109
struct nrf_clock_spec clk_spec;
@@ -512,7 +512,7 @@ static int transceive(const struct device *dev,
512512
dev_data->busy = true;
513513

514514
if (dev_config->wake_pin != WAKE_PIN_NOT_USED) {
515-
error = spi_nrfx_wake_request(&dev_config->wake_gpiote,
515+
error = spi_nrfx_wake_request(dev_config->wake_gpiote,
516516
dev_config->wake_pin);
517517
if (error == -ETIMEDOUT) {
518518
LOG_WRN("Waiting for WAKE acknowledgment timed out");
@@ -709,7 +709,7 @@ static int spi_nrfx_init(const struct device *dev)
709709
(void)pinctrl_apply_state(dev_config->pcfg, PINCTRL_STATE_SLEEP);
710710

711711
if (dev_config->wake_pin != WAKE_PIN_NOT_USED) {
712-
err = spi_nrfx_wake_init(&dev_config->wake_gpiote, dev_config->wake_pin);
712+
err = spi_nrfx_wake_init(dev_config->wake_gpiote, dev_config->wake_pin);
713713
if (err == -ENODEV) {
714714
LOG_ERR("Failed to allocate GPIOTE channel for WAKE");
715715
return err;
@@ -808,13 +808,13 @@ static int spi_nrfx_deinit(const struct device *dev)
808808
SPI_NRFX_SPIM_EXTENDED_CONFIG(inst) \
809809
}, \
810810
.irq_connect = irq_connect##inst, \
811-
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
812811
.max_chunk_len = BIT_MASK( \
813812
DT_INST_PROP(inst, easydma_maxcnt_bits)), \
813+
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
814+
.wake_gpiote = WAKE_GPIOTE_NODE(DT_DRV_INST(inst)), \
814815
.wake_pin = NRF_DT_GPIOS_TO_PSEL_OR(DT_DRV_INST(inst), \
815816
wake_gpios, \
816817
WAKE_PIN_NOT_USED), \
817-
.wake_gpiote = WAKE_GPIOTE_INSTANCE(DT_DRV_INST(inst)), \
818818
IF_ENABLED(SPIM_ANY_FAST, \
819819
(.clk_dev = DEVICE_DT_GET_OR_NULL( \
820820
DT_CLOCKS_CTLR(DT_DRV_INST(inst))), \

0 commit comments

Comments
 (0)