Skip to content

Commit 42fb906

Browse files
xingrzkartben
authored andcommitted
drivers: timer: riscv_machine_timer: Use reg-names to access registers
This commit updates the riscv_machine_timer driver to resolve MTIME and MTIMECMP register addresses by their `reg-names` instead of relying on index order. This improves clarity and robustness in DTS bindings, and is a prerequisite for handling cases where not both MTIME and MTIMECMP registers are present or accessible. Signed-off-by: Chen Xingyu <hi@xingrz.me>
1 parent 7db4b5e commit 42fb906

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

drivers/timer/riscv_machine_timer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@
1616

1717
#define DT_DRV_COMPAT riscv_machine_timer
1818

19-
#define MTIME_REG DT_INST_REG_ADDR_BY_IDX(0, 0)
20-
#define MTIMECMP_REG DT_INST_REG_ADDR_BY_IDX(0, 1)
19+
#define MTIME_REG DT_INST_REG_ADDR_BY_NAME(0, mtime)
20+
#define MTIMECMP_REG DT_INST_REG_ADDR_BY_NAME(0, mtimecmp)
2121
#define TIMER_IRQN DT_INST_IRQN(0)
2222

2323
#define CYC_PER_TICK (uint32_t)(sys_clock_hw_cycles_per_sec() / CONFIG_SYS_CLOCK_TICKS_PER_SEC)

dts/bindings/timer/riscv,machine-timer.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,7 @@ include: base.yaml
1010
properties:
1111
reg:
1212
required: true
13+
reg-names:
14+
required: true
1315
interrupts-extended:
1416
required: true

0 commit comments

Comments
 (0)