diff --git a/drivers/counter/counter_esp32_tmr.c b/drivers/counter/counter_esp32_tmr.c index be634906b30..b3fbc54c4bc 100644 --- a/drivers/counter/counter_esp32_tmr.c +++ b/drivers/counter/counter_esp32_tmr.c @@ -4,7 +4,7 @@ * SPDX-License-Identifier: Apache-2.0 */ -#define DT_DRV_COMPAT espressif_esp32_timer +#define DT_DRV_COMPAT espressif_esp32_counter #include #include @@ -360,10 +360,12 @@ static void counter_esp32_isr(void *arg) timer_ll_clear_intr_status(data->hal_ctx.dev, TIMER_LL_EVENT_ALARM(data->hal_ctx.timer_id)); } +#define TIMER(idx) DT_INST_PARENT(idx) + #define ESP32_COUNTER_GET_CLK_DIV(idx) \ - (((DT_INST_PROP(idx, prescaler) & UINT16_MAX) < 2) \ + (((DT_PROP(TIMER(idx), prescaler) & UINT16_MAX) < 2) \ ? 2 \ - : (DT_INST_PROP(idx, prescaler) & UINT16_MAX)) + : (DT_PROP(TIMER(idx), prescaler) & UINT16_MAX)) #define ESP32_COUNTER_INIT(idx) \ \ @@ -382,13 +384,13 @@ static void counter_esp32_isr(void *arg) .auto_reload = TIMER_AUTORELOAD_DIS, \ .divider = ESP32_COUNTER_GET_CLK_DIV(idx), \ }, \ - .clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \ - .clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \ - .group = DT_INST_PROP(idx, group), \ - .index = DT_INST_PROP(idx, index), \ - .irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \ - .irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \ - .irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags)}; \ + .clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(TIMER(idx))), \ + .clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(TIMER(idx), offset), \ + .group = DT_PROP(TIMER(idx), group), \ + .index = DT_PROP(TIMER(idx), index), \ + .irq_source = DT_IRQ_BY_IDX(TIMER(idx), 0, irq), \ + .irq_priority = DT_IRQ_BY_IDX(TIMER(idx), 0, priority), \ + .irq_flags = DT_IRQ_BY_IDX(TIMER(idx), 0, flags)}; \ \ DEVICE_DT_INST_DEFINE(idx, counter_esp32_init, NULL, &counter_data_##idx, \ &counter_config_##idx, PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \ diff --git a/dts/bindings/counter/espressif,esp32-counter.yaml b/dts/bindings/counter/espressif,esp32-counter.yaml new file mode 100644 index 00000000000..f82e77b7a62 --- /dev/null +++ b/dts/bindings/counter/espressif,esp32-counter.yaml @@ -0,0 +1,8 @@ +# Copyright (c) 2025 Joel Guittet +# SPDX-License-Identifier: Apache-2.0 + +description: ESP32 counters + +compatible: "espressif,esp32-counter" + +include: base.yaml diff --git a/dts/riscv/espressif/esp32c2/esp32c2_common.dtsi b/dts/riscv/espressif/esp32c2/esp32c2_common.dtsi index 1d8a34e471d..fc1d2f716f9 100644 --- a/dts/riscv/espressif/esp32c2/esp32c2_common.dtsi +++ b/dts/riscv/espressif/esp32c2/esp32c2_common.dtsi @@ -181,6 +181,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; trng0: trng@3ff700b0 { diff --git a/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi b/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi index 7c8eee5e99a..496be904557 100644 --- a/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi +++ b/dts/riscv/espressif/esp32c3/esp32c3_common.dtsi @@ -237,6 +237,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer1: counter@60020000 { @@ -248,6 +253,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; trng0: trng@3ff700b0 { diff --git a/dts/riscv/espressif/esp32c6/esp32c6_common.dtsi b/dts/riscv/espressif/esp32c6/esp32c6_common.dtsi index d8533123cd4..0914da26dec 100644 --- a/dts/riscv/espressif/esp32c6/esp32c6_common.dtsi +++ b/dts/riscv/espressif/esp32c6/esp32c6_common.dtsi @@ -118,6 +118,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer1: counter@60009000 { @@ -129,6 +134,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; rtc: rtc@600b0000 { diff --git a/dts/xtensa/espressif/esp32/esp32_common.dtsi b/dts/xtensa/espressif/esp32/esp32_common.dtsi index 0842e7e1170..40534f7acee 100644 --- a/dts/xtensa/espressif/esp32/esp32_common.dtsi +++ b/dts/xtensa/espressif/esp32/esp32_common.dtsi @@ -452,6 +452,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer1: counter@3ff5f024 { @@ -463,6 +468,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer2: counter@3ff60000 { @@ -474,6 +484,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer3: counter@3ff60024 { @@ -485,6 +500,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; dac: dac@3ff48800 { diff --git a/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi b/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi index 4c3fcbc3c38..a50f7edc5c8 100644 --- a/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi +++ b/dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi @@ -280,6 +280,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer1: counter@3f41f024 { @@ -291,6 +296,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer2: counter@3f420000 { @@ -302,6 +312,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer3: counter@3f420024 { @@ -312,6 +327,11 @@ index = <1>; interrupts = ; interrupt-parent = <&intc>; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; trng0: trng@3f435110 { diff --git a/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi b/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi index 1f4f046df4d..f539c0c0efb 100644 --- a/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi +++ b/dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi @@ -415,6 +415,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer1: counter@6001f024 { @@ -426,6 +431,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer2: counter@60020000 { @@ -437,6 +447,11 @@ interrupts = ; interrupt-parent = <&intc>; status = "disabled"; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; timer3: counter@60020024 { @@ -447,6 +462,11 @@ index = <1>; interrupts = ; interrupt-parent = <&intc>; + + counter { + compatible = "espressif,esp32-counter"; + status = "disabled"; + }; }; wdt0: watchdog@6001f048 { diff --git a/tests/drivers/counter/counter_basic_api/src/test_counter.c b/tests/drivers/counter/counter_basic_api/src/test_counter.c index 1daebb7ff4f..e2d7a645ff4 100644 --- a/tests/drivers/counter/counter_basic_api/src/test_counter.c +++ b/tests/drivers/counter/counter_basic_api/src/test_counter.c @@ -103,7 +103,7 @@ static const struct device *const devices[] = { DEVS_FOR_DT_COMPAT(xlnx_xps_timer_1_00_a) #endif #ifdef CONFIG_COUNTER_TMR_ESP32 - DEVS_FOR_DT_COMPAT(espressif_esp32_timer) + DEVS_FOR_DT_COMPAT(espressif_esp32_counter) #endif #ifdef CONFIG_COUNTER_NXP_S32_SYS_TIMER DEVS_FOR_DT_COMPAT(nxp_s32_sys_timer)