Skip to content

Commit 9d4530f

Browse files
joelguittetkartben
authored andcommitted
drivers: counter: introduce counter node in esp32 timers
Add counter device tree node to the esp32 timers. Signed-off-by: Joel Guittet <joelguittet@gmail.com>
1 parent 46f7313 commit 9d4530f

File tree

9 files changed

+106
-11
lines changed

9 files changed

+106
-11
lines changed

drivers/counter/counter_esp32_tmr.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7-
#define DT_DRV_COMPAT espressif_esp32_timer
7+
#define DT_DRV_COMPAT espressif_esp32_counter
88

99
#include <esp_clk_tree.h>
1010
#include <driver/timer_types_legacy.h>
@@ -360,10 +360,12 @@ static void counter_esp32_isr(void *arg)
360360
timer_ll_clear_intr_status(data->hal_ctx.dev, TIMER_LL_EVENT_ALARM(data->hal_ctx.timer_id));
361361
}
362362

363+
#define TIMER(idx) DT_INST_PARENT(idx)
364+
363365
#define ESP32_COUNTER_GET_CLK_DIV(idx) \
364-
(((DT_INST_PROP(idx, prescaler) & UINT16_MAX) < 2) \
366+
(((DT_PROP(TIMER(idx), prescaler) & UINT16_MAX) < 2) \
365367
? 2 \
366-
: (DT_INST_PROP(idx, prescaler) & UINT16_MAX))
368+
: (DT_PROP(TIMER(idx), prescaler) & UINT16_MAX))
367369

368370
#define ESP32_COUNTER_INIT(idx) \
369371
\
@@ -382,13 +384,13 @@ static void counter_esp32_isr(void *arg)
382384
.auto_reload = TIMER_AUTORELOAD_DIS, \
383385
.divider = ESP32_COUNTER_GET_CLK_DIV(idx), \
384386
}, \
385-
.clock_dev = DEVICE_DT_GET(DT_INST_CLOCKS_CTLR(idx)), \
386-
.clock_subsys = (clock_control_subsys_t)DT_INST_CLOCKS_CELL(idx, offset), \
387-
.group = DT_INST_PROP(idx, group), \
388-
.index = DT_INST_PROP(idx, index), \
389-
.irq_source = DT_INST_IRQ_BY_IDX(idx, 0, irq), \
390-
.irq_priority = DT_INST_IRQ_BY_IDX(idx, 0, priority), \
391-
.irq_flags = DT_INST_IRQ_BY_IDX(idx, 0, flags)}; \
387+
.clock_dev = DEVICE_DT_GET(DT_CLOCKS_CTLR(TIMER(idx))), \
388+
.clock_subsys = (clock_control_subsys_t)DT_CLOCKS_CELL(TIMER(idx), offset), \
389+
.group = DT_PROP(TIMER(idx), group), \
390+
.index = DT_PROP(TIMER(idx), index), \
391+
.irq_source = DT_IRQ_BY_IDX(TIMER(idx), 0, irq), \
392+
.irq_priority = DT_IRQ_BY_IDX(TIMER(idx), 0, priority), \
393+
.irq_flags = DT_IRQ_BY_IDX(TIMER(idx), 0, flags)}; \
392394
\
393395
DEVICE_DT_INST_DEFINE(idx, counter_esp32_init, NULL, &counter_data_##idx, \
394396
&counter_config_##idx, PRE_KERNEL_1, CONFIG_COUNTER_INIT_PRIORITY, \
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Copyright (c) 2025 Joel Guittet
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
description: ESP32 counters
5+
6+
compatible: "espressif,esp32-counter"
7+
8+
include: base.yaml

dts/riscv/espressif/esp32c2/esp32c2_common.dtsi

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,11 @@
181181
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
182182
interrupt-parent = <&intc>;
183183
status = "disabled";
184+
185+
counter {
186+
compatible = "espressif,esp32-counter";
187+
status = "disabled";
188+
};
184189
};
185190

186191
trng0: trng@3ff700b0 {

dts/riscv/espressif/esp32c3/esp32c3_common.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,11 @@
237237
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
238238
interrupt-parent = <&intc>;
239239
status = "disabled";
240+
241+
counter {
242+
compatible = "espressif,esp32-counter";
243+
status = "disabled";
244+
};
240245
};
241246

242247
timer1: counter@60020000 {
@@ -248,6 +253,11 @@
248253
interrupts = <TG1_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
249254
interrupt-parent = <&intc>;
250255
status = "disabled";
256+
257+
counter {
258+
compatible = "espressif,esp32-counter";
259+
status = "disabled";
260+
};
251261
};
252262

253263
trng0: trng@3ff700b0 {

dts/riscv/espressif/esp32c6/esp32c6_common.dtsi

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@
118118
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
119119
interrupt-parent = <&intc>;
120120
status = "disabled";
121+
122+
counter {
123+
compatible = "espressif,esp32-counter";
124+
status = "disabled";
125+
};
121126
};
122127

123128
timer1: counter@60009000 {
@@ -129,6 +134,11 @@
129134
interrupts = <TG1_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
130135
interrupt-parent = <&intc>;
131136
status = "disabled";
137+
138+
counter {
139+
compatible = "espressif,esp32-counter";
140+
status = "disabled";
141+
};
132142
};
133143

134144
rtc: rtc@600b0000 {

dts/xtensa/espressif/esp32/esp32_common.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,11 @@
452452
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
453453
interrupt-parent = <&intc>;
454454
status = "disabled";
455+
456+
counter {
457+
compatible = "espressif,esp32-counter";
458+
status = "disabled";
459+
};
455460
};
456461

457462
timer1: counter@3ff5f024 {
@@ -463,6 +468,11 @@
463468
interrupts = <TG0_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
464469
interrupt-parent = <&intc>;
465470
status = "disabled";
471+
472+
counter {
473+
compatible = "espressif,esp32-counter";
474+
status = "disabled";
475+
};
466476
};
467477

468478
timer2: counter@3ff60000 {
@@ -474,6 +484,11 @@
474484
interrupts = <TG1_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
475485
interrupt-parent = <&intc>;
476486
status = "disabled";
487+
488+
counter {
489+
compatible = "espressif,esp32-counter";
490+
status = "disabled";
491+
};
477492
};
478493

479494
timer3: counter@3ff60024 {
@@ -485,6 +500,11 @@
485500
interrupts = <TG1_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
486501
interrupt-parent = <&intc>;
487502
status = "disabled";
503+
504+
counter {
505+
compatible = "espressif,esp32-counter";
506+
status = "disabled";
507+
};
488508
};
489509

490510
dac: dac@3ff48800 {

dts/xtensa/espressif/esp32s2/esp32s2_common.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,11 @@
280280
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
281281
interrupt-parent = <&intc>;
282282
status = "disabled";
283+
284+
counter {
285+
compatible = "espressif,esp32-counter";
286+
status = "disabled";
287+
};
283288
};
284289

285290
timer1: counter@3f41f024 {
@@ -291,6 +296,11 @@
291296
interrupts = <TG0_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
292297
interrupt-parent = <&intc>;
293298
status = "disabled";
299+
300+
counter {
301+
compatible = "espressif,esp32-counter";
302+
status = "disabled";
303+
};
294304
};
295305

296306
timer2: counter@3f420000 {
@@ -302,6 +312,11 @@
302312
interrupts = <TG1_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
303313
interrupt-parent = <&intc>;
304314
status = "disabled";
315+
316+
counter {
317+
compatible = "espressif,esp32-counter";
318+
status = "disabled";
319+
};
305320
};
306321

307322
timer3: counter@3f420024 {
@@ -312,6 +327,11 @@
312327
index = <1>;
313328
interrupts = <TG1_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
314329
interrupt-parent = <&intc>;
330+
331+
counter {
332+
compatible = "espressif,esp32-counter";
333+
status = "disabled";
334+
};
315335
};
316336

317337
trng0: trng@3f435110 {

dts/xtensa/espressif/esp32s3/esp32s3_common.dtsi

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,11 @@
415415
interrupts = <TG0_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
416416
interrupt-parent = <&intc>;
417417
status = "disabled";
418+
419+
counter {
420+
compatible = "espressif,esp32-counter";
421+
status = "disabled";
422+
};
418423
};
419424

420425
timer1: counter@6001f024 {
@@ -426,6 +431,11 @@
426431
interrupts = <TG0_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
427432
interrupt-parent = <&intc>;
428433
status = "disabled";
434+
435+
counter {
436+
compatible = "espressif,esp32-counter";
437+
status = "disabled";
438+
};
429439
};
430440

431441
timer2: counter@60020000 {
@@ -437,6 +447,11 @@
437447
interrupts = <TG1_T0_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
438448
interrupt-parent = <&intc>;
439449
status = "disabled";
450+
451+
counter {
452+
compatible = "espressif,esp32-counter";
453+
status = "disabled";
454+
};
440455
};
441456

442457
timer3: counter@60020024 {
@@ -447,6 +462,11 @@
447462
index = <1>;
448463
interrupts = <TG1_T1_LEVEL_INTR_SOURCE IRQ_DEFAULT_PRIORITY 0>;
449464
interrupt-parent = <&intc>;
465+
466+
counter {
467+
compatible = "espressif,esp32-counter";
468+
status = "disabled";
469+
};
450470
};
451471

452472
wdt0: watchdog@6001f048 {

tests/drivers/counter/counter_basic_api/src/test_counter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ static const struct device *const devices[] = {
103103
DEVS_FOR_DT_COMPAT(xlnx_xps_timer_1_00_a)
104104
#endif
105105
#ifdef CONFIG_COUNTER_TMR_ESP32
106-
DEVS_FOR_DT_COMPAT(espressif_esp32_timer)
106+
DEVS_FOR_DT_COMPAT(espressif_esp32_counter)
107107
#endif
108108
#ifdef CONFIG_COUNTER_NXP_S32_SYS_TIMER
109109
DEVS_FOR_DT_COMPAT(nxp_s32_sys_timer)

0 commit comments

Comments
 (0)