Skip to content

Commit 4b8dc5f

Browse files
Raffael Rostagnokartben
authored andcommitted
drivers: esp32: Update for shared intc
Drivers update to use shared interrupt allocator for Xtensa and RISCV devices. Signed-off-by: Raffael Rostagno <[email protected]> Signed-off-by: Sylvio Alves <[email protected]>
1 parent 034c0cb commit 4b8dc5f

File tree

11 files changed

+35
-139
lines changed

11 files changed

+35
-139
lines changed

drivers/counter/counter_esp32_rtc.c

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
/*
2-
* Copyright (c) 2022 Espressif Systems (Shanghai) Co., Ltd.
2+
* Copyright (c) 2022-2025 Espressif Systems (Shanghai) Co., Ltd.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#define DT_DRV_COMPAT espressif_esp32_rtc_timer
88

9-
/*
10-
* Include esp-idf headers first to avoid
11-
* redefining BIT() macro
12-
*/
139
#include "soc/rtc_cntl_reg.h"
1410
#include "soc/rtc.h"
1511
#include <esp_rom_sys.h>
@@ -21,22 +17,11 @@
2117
#include <zephyr/kernel.h>
2218
#include <zephyr/drivers/clock_control.h>
2319
#include <zephyr/drivers/clock_control/esp32_clock_control.h>
24-
25-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
26-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
27-
#else
2820
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
29-
#endif
3021

3122
#include <zephyr/logging/log.h>
3223
LOG_MODULE_REGISTER(esp32_counter_rtc, CONFIG_COUNTER_LOG_LEVEL);
3324

34-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3)
35-
#define ESP32_COUNTER_RTC_ISR_HANDLER isr_handler_t
36-
#else
37-
#define ESP32_COUNTER_RTC_ISR_HANDLER intr_handler_t
38-
#endif
39-
4025
static void counter_esp32_isr(void *arg);
4126

4227
struct counter_esp32_config {
@@ -65,9 +50,10 @@ static int counter_esp32_init(const struct device *dev)
6550
&data->clk_src_freq);
6651

6752
flags = ESP_PRIO_TO_FLAGS(cfg->irq_priority) | ESP_INT_FLAGS_CHECK(cfg->irq_flags) |
68-
ESP_INTR_FLAG_SHARED;
53+
ESP_INTR_FLAG_SHARED;
54+
6955
ret = esp_intr_alloc(cfg->irq_source, flags,
70-
(ESP32_COUNTER_RTC_ISR_HANDLER)counter_esp32_isr, (void *)dev, NULL);
56+
(intr_handler_t)counter_esp32_isr, (void *)dev, NULL);
7157

7258
if (ret != 0) {
7359
LOG_ERR("could not allocate interrupt (err %d)", ret);
@@ -246,6 +232,6 @@ DEVICE_DT_INST_DEFINE(0,
246232
NULL,
247233
&counter_data,
248234
&counter_config,
249-
POST_KERNEL,
235+
PRE_KERNEL_2,
250236
CONFIG_COUNTER_INIT_PRIORITY,
251237
&rtc_timer_esp32_api);

drivers/counter/counter_esp32_tmr.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
2+
* Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -14,22 +14,12 @@
1414
#include <zephyr/drivers/counter.h>
1515
#include <zephyr/drivers/clock_control.h>
1616
#include <zephyr/kernel.h>
17-
#if defined(CONFIG_RISCV)
18-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
19-
#else
2017
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
21-
#endif
2218
#include <zephyr/device.h>
2319
#include <zephyr/logging/log.h>
2420

2521
LOG_MODULE_REGISTER(esp32_counter, CONFIG_COUNTER_LOG_LEVEL);
2622

27-
#if defined(CONFIG_RISCV)
28-
#define ISR_HANDLER isr_handler_t
29-
#else
30-
#define ISR_HANDLER intr_handler_t
31-
#endif
32-
3323
static void counter_esp32_isr(void *arg);
3424

3525
typedef bool (*timer_isr_t)(void *);
@@ -97,7 +87,7 @@ static int counter_esp32_init(const struct device *dev)
9787
int ret = esp_intr_alloc(cfg->irq_source,
9888
ESP_PRIO_TO_FLAGS(cfg->irq_priority) |
9989
ESP_INT_FLAGS_CHECK(cfg->irq_flags),
100-
(ISR_HANDLER)counter_esp32_isr, (void *)dev, NULL);
90+
(intr_handler_t)counter_esp32_isr, (void *)dev, NULL);
10191

10292
if (ret != 0) {
10393
LOG_ERR("could not allocate interrupt (err %d)", ret);

drivers/dma/dma_esp32_gdma.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,13 @@ LOG_MODULE_REGISTER(dma_esp32_gdma, CONFIG_DMA_LOG_LEVEL);
1616

1717
#include <soc.h>
1818
#include <esp_memory_utils.h>
19+
#include <soc/soc_memory_types.h>
1920
#include <errno.h>
2021
#include <zephyr/kernel.h>
2122
#include <zephyr/drivers/dma.h>
2223
#include <zephyr/drivers/dma/dma_esp32.h>
2324
#include <zephyr/drivers/clock_control.h>
24-
#if defined(CONFIG_SOC_SERIES_ESP32C3) || defined(CONFIG_SOC_SERIES_ESP32C6)
25-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
26-
#else
2725
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
28-
#endif
29-
30-
#if defined(CONFIG_SOC_SERIES_ESP32C3) || defined(CONFIG_SOC_SERIES_ESP32C6)
31-
#define ISR_HANDLER isr_handler_t
32-
#else
33-
#define ISR_HANDLER intr_handler_t
34-
#endif
3526

3627
#define DMA_MAX_CHANNEL SOC_GDMA_PAIRS_PER_GROUP
3728

@@ -61,7 +52,10 @@ struct dma_esp32_channel {
6152
int periph_id;
6253
dma_callback_t cb;
6354
void *user_data;
64-
dma_descriptor_t desc_list[CONFIG_DMA_ESP32_MAX_DESCRIPTOR_NUM];
55+
dma_descriptor_t desc;
56+
#if defined(CONFIG_SOC_SERIES_ESP32S3)
57+
intr_handle_t *intr_handle;
58+
#endif
6559
};
6660

6761
struct dma_esp32_config {
@@ -546,7 +540,7 @@ static int dma_esp32_configure_irq(const struct device *dev)
546540
int ret = esp_intr_alloc(irq_cfg[i].irq_source,
547541
ESP_PRIO_TO_FLAGS(irq_cfg[i].irq_priority) |
548542
ESP_INT_FLAGS_CHECK(irq_cfg[i].irq_flags) | ESP_INTR_FLAG_IRAM,
549-
(ISR_HANDLER)config->irq_handlers[i],
543+
(intr_handler_t)config->irq_handlers[i],
550544
(void *)dev,
551545
NULL);
552546
if (ret != 0) {

drivers/gpio/gpio_esp32.c

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2017 Intel Corporation
3-
* Copyright (c) 2021 Espressif Systems (Shanghai) Co., Ltd.
3+
* Copyright (c) 2021-2025 Espressif Systems (Shanghai) Co., Ltd.
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
@@ -20,13 +20,7 @@
2020
#include <zephyr/device.h>
2121
#include <zephyr/drivers/gpio.h>
2222
#include <zephyr/dt-bindings/gpio/espressif-esp32-gpio.h>
23-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
24-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
25-
defined(CONFIG_SOC_SERIES_ESP32C6)
26-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
27-
#else
2823
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
29-
#endif
3024
#include <zephyr/kernel.h>
3125
#include <zephyr/sys/util.h>
3226

@@ -42,7 +36,6 @@ LOG_MODULE_REGISTER(gpio_esp32, CONFIG_LOG_DEFAULT_LEVEL);
4236
#define out_w1tc out_w1tc.val
4337
/* arch_curr_cpu() is not available for riscv based chips */
4438
#define CPU_ID() 0
45-
#define ISR_HANDLER isr_handler_t
4639
#elif CONFIG_SOC_SERIES_ESP32C3
4740
/* gpio structs in esp32c3 series are different from xtensa ones */
4841
#define out out.data
@@ -51,7 +44,6 @@ LOG_MODULE_REGISTER(gpio_esp32, CONFIG_LOG_DEFAULT_LEVEL);
5144
#define out_w1tc out_w1tc.val
5245
/* arch_curr_cpu() is not available for riscv based chips */
5346
#define CPU_ID() 0
54-
#define ISR_HANDLER isr_handler_t
5547
#elif defined(CONFIG_SOC_SERIES_ESP32C6)
5648
/* gpio structs in esp32c6 are also different */
5749
#define out out.out_data_orig
@@ -60,10 +52,8 @@ LOG_MODULE_REGISTER(gpio_esp32, CONFIG_LOG_DEFAULT_LEVEL);
6052
#define out_w1tc out_w1tc.val
6153
/* arch_curr_cpu() is not available for riscv based chips */
6254
#define CPU_ID() 0
63-
#define ISR_HANDLER isr_handler_t
6455
#else
6556
#define CPU_ID() arch_curr_cpu()->id
66-
#define ISR_HANDLER intr_handler_t
6757
#endif
6858

6959
#ifndef SOC_GPIO_SUPPORT_RTC_INDEPENDENT
@@ -482,8 +472,9 @@ static int gpio_esp32_init(const struct device *dev)
482472
if (!isr_connected) {
483473
int ret = esp_intr_alloc(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, irq),
484474
ESP_PRIO_TO_FLAGS(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, priority)) |
485-
ESP_INT_FLAGS_CHECK(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, flags)),
486-
(ISR_HANDLER)gpio_esp32_isr,
475+
ESP_INT_FLAGS_CHECK(DT_IRQ_BY_IDX(DT_NODELABEL(gpio0), 0, flags)) |
476+
ESP_INTR_FLAG_IRAM,
477+
(intr_handler_t)gpio_esp32_isr,
487478
(void *)dev,
488479
NULL);
489480

drivers/pwm/pwm_mc_esp32.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
2+
* Copyright (c) 2024-2025 Espressif Systems (Shanghai) Co., Ltd.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -19,21 +19,11 @@
1919
#include <zephyr/drivers/clock_control.h>
2020
#include <esp_clk_tree.h>
2121
#ifdef CONFIG_PWM_CAPTURE
22-
#if defined(CONFIG_RISCV)
23-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
24-
#else
2522
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
26-
#endif
2723
#endif /* CONFIG_PWM_CAPTURE */
2824
#include <zephyr/logging/log.h>
2925
LOG_MODULE_REGISTER(mcpwm_esp32, CONFIG_PWM_LOG_LEVEL);
3026

31-
#if defined(CONFIG_RISCV)
32-
#define ISR_HANDLER isr_handler_t
33-
#else
34-
#define ISR_HANDLER intr_handler_t
35-
#endif
36-
3727
#ifdef CONFIG_PWM_CAPTURE
3828
#define SKIP_IRQ_NUM 4U
3929
#define CAP_INT_MASK 7U
@@ -554,7 +544,7 @@ static DEVICE_API(pwm, mcpwm_esp32_api) = {
554544
ESP_PRIO_TO_FLAGS(DT_INST_IRQ_BY_IDX(idx, 0, priority)) | \
555545
ESP_INT_FLAGS_CHECK(DT_INST_IRQ_BY_IDX(idx, 0, flags)) | \
556546
ESP_INTR_FLAG_IRAM, \
557-
(ISR_HANDLER)mcpwm_esp32_isr, (void *)dev, NULL); \
547+
(intr_handler_t)mcpwm_esp32_isr, (void *)dev, NULL); \
558548
return ret; \
559549
}
560550
#define CAPTURE_INIT(idx) .irq_config_func = mcpwm_esp32_irq_config_func_##idx

drivers/serial/serial_esp32_usb.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/*
22
* Copyright (c) 2022 Libre Solar Technologies GmbH
3+
* Copyright (c) 2025 Espressif Systems (Shanghai) Co., Ltd.
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
@@ -13,21 +14,11 @@
1314
#include <errno.h>
1415
#include <soc.h>
1516
#include <zephyr/drivers/uart.h>
16-
#if defined(CONFIG_SOC_SERIES_ESP32C3) || defined(CONFIG_SOC_SERIES_ESP32C6)
17-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
18-
#else
1917
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
20-
#endif
2118
#include <zephyr/drivers/clock_control.h>
2219
#include <zephyr/sys/util.h>
2320
#include <esp_attr.h>
2421

25-
#if defined(CONFIG_SOC_SERIES_ESP32C3) || defined(CONFIG_SOC_SERIES_ESP32C6)
26-
#define ISR_HANDLER isr_handler_t
27-
#else
28-
#define ISR_HANDLER intr_handler_t
29-
#endif
30-
3122
/*
3223
* Timeout after which the poll_out function stops waiting for space in the tx fifo.
3324
*
@@ -113,7 +104,7 @@ static int serial_esp32_usb_init(const struct device *dev)
113104
ret = esp_intr_alloc(config->irq_source,
114105
ESP_PRIO_TO_FLAGS(config->irq_priority) |
115106
ESP_INT_FLAGS_CHECK(config->irq_flags),
116-
(ISR_HANDLER)serial_esp32_usb_isr,
107+
(intr_handler_t)serial_esp32_usb_isr,
117108
(void *)dev, NULL);
118109
#endif
119110
return ret;

drivers/serial/uart_esp32.c

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*
22
* Copyright (c) 2019 Mohamed ElShahawi ([email protected])
3-
* Copyright (c) 2023 Espressif Systems (Shanghai) Co., Ltd.
3+
* Copyright (c) 2023-2025 Espressif Systems (Shanghai) Co., Ltd.
44
*
55
* SPDX-License-Identifier: Apache-2.0
66
*/
@@ -51,13 +51,7 @@
5151
#include <soc.h>
5252
#include <zephyr/drivers/uart.h>
5353

54-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
55-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
56-
defined(CONFIG_SOC_SERIES_ESP32C6)
57-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
58-
#else
5954
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
60-
#endif
6155

6256
#include <zephyr/drivers/clock_control.h>
6357
#include <errno.h>
@@ -67,14 +61,6 @@
6761

6862
LOG_MODULE_REGISTER(uart_esp32, CONFIG_UART_LOG_LEVEL);
6963

70-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || \
71-
defined(CONFIG_SOC_SERIES_ESP32C3) || \
72-
defined(CONFIG_SOC_SERIES_ESP32C6)
73-
#define ISR_HANDLER isr_handler_t
74-
#else
75-
#define ISR_HANDLER intr_handler_t
76-
#endif
77-
7864
struct uart_esp32_config {
7965
const struct device *clock_dev;
8066
const struct pinctrl_dev_config *pcfg;
@@ -962,7 +948,7 @@ static int uart_esp32_init(const struct device *dev)
962948
ret = esp_intr_alloc(config->irq_source,
963949
ESP_PRIO_TO_FLAGS(config->irq_priority) |
964950
ESP_INT_FLAGS_CHECK(config->irq_flags),
965-
(ISR_HANDLER)uart_esp32_isr,
951+
(intr_handler_t)uart_esp32_isr,
966952
(void *)dev,
967953
NULL);
968954
if (ret < 0) {
@@ -1071,7 +1057,7 @@ static DEVICE_API(uart, uart_esp32_api) = {
10711057
ESP_UART_UHCI_INIT(idx)}; \
10721058
\
10731059
DEVICE_DT_INST_DEFINE(idx, uart_esp32_init, NULL, &uart_esp32_data_##idx, \
1074-
&uart_esp32_cfg_port_##idx, PRE_KERNEL_1, \
1060+
&uart_esp32_cfg_port_##idx, PRE_KERNEL_2, \
10751061
CONFIG_SERIAL_INIT_PRIORITY, &uart_esp32_api);
10761062

10771063
DT_INST_FOREACH_STATUS_OKAY(ESP32_UART_INIT);

drivers/spi/spi_esp32_spim.c

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020 Espressif Systems (Shanghai) Co., Ltd.
2+
* Copyright (c) 2020-2025 Espressif Systems (Shanghai) Co., Ltd.
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -17,13 +17,7 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL);
1717
#include <soc.h>
1818
#include <esp_memory_utils.h>
1919
#include <zephyr/drivers/spi.h>
20-
#include <zephyr/drivers/spi/rtio.h>
21-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3) || \
22-
defined(CONFIG_SOC_SERIES_ESP32C6)
23-
#include <zephyr/drivers/interrupt_controller/intc_esp32c3.h>
24-
#else
2520
#include <zephyr/drivers/interrupt_controller/intc_esp32.h>
26-
#endif
2721
#ifdef SOC_GDMA_SUPPORTED
2822
#include <hal/gdma_hal.h>
2923
#include <hal/gdma_ll.h>
@@ -32,13 +26,6 @@ LOG_MODULE_REGISTER(esp32_spi, CONFIG_SPI_LOG_LEVEL);
3226
#include "spi_context.h"
3327
#include "spi_esp32_spim.h"
3428

35-
#if defined(CONFIG_SOC_SERIES_ESP32C2) || defined(CONFIG_SOC_SERIES_ESP32C3) || \
36-
defined(CONFIG_SOC_SERIES_ESP32C6)
37-
#define ISR_HANDLER isr_handler_t
38-
#else
39-
#define ISR_HANDLER intr_handler_t
40-
#endif
41-
4229
#define SPI_DMA_MAX_BUFFER_SIZE 4092
4330

4431
static bool spi_esp32_transfer_ongoing(struct spi_esp32_data *data)
@@ -250,7 +237,7 @@ static int spi_esp32_init(const struct device *dev)
250237
err = esp_intr_alloc(cfg->irq_source,
251238
ESP_PRIO_TO_FLAGS(cfg->irq_priority) |
252239
ESP_INT_FLAGS_CHECK(cfg->irq_flags) | ESP_INTR_FLAG_IRAM,
253-
(ISR_HANDLER)spi_esp32_isr,
240+
(intr_handler_t)spi_esp32_isr,
254241
(void *)dev,
255242
NULL);
256243

0 commit comments

Comments
 (0)