SG2042: add virtual global timer device driver

Add a virtual global timer device driver. It uses a global timer
register as timer counter, and it uses mtimecmp CSR of clint as
interrupt source.
Using this virtul timer resolves dual way timer sync issue.
On dual way system, we should enable this driver and on single way
system, we should use standard risc-v clint timer.

1. Add a virtual global timer device driver, it is probed by fdt

	sg2042-global-mtimer@70300101c0 {
		compatible = "sophgo,sg2042-global-mtimer";
		reg = < 0x00000070 0x300101c0 0x00000000 0x00000008
			0x00000070 0xac000000 0x00000000 0x00200000>;
		clock-frequency = <50000000 50000000>;
	};

Its compatible should be "sophgo,sg2042-global-mtimer".
And the first region delcared in reg prop is the address of global
timer. The second region delcared in reg prop is the base of clint
timers.
The first clock in clock-frequency is the actual frequency of global
timer, the second clock is the actual frequency of clint timer.

2. Add a quirk in platform specific code.
Add a function sbi_platform_force_emulate_time_csr, it indicates if
opensbi should skip time CSR detection and make software in
supervisor and user mode use emulated time CSR.

Signed-off-by: Chao Wei <chao.wei@sophgo.com>
This commit is contained in:
Chao Wei
2025-10-13 17:17:43 +08:00
committed by xingxg2022
parent 506f47f9fa
commit 6eef399cfc
13 changed files with 293 additions and 6 deletions

View File

@@ -19,6 +19,11 @@ config FDT_TIMER_PLMT
select TIMER_PLMT
default n
config FDT_TIMER_SG2042_GMT
bool "SOPHGO SG2042 global mtimer FDT driver"
select TIMER_SG2042_GMT
default n
endif
config TIMER_MTIMER
@@ -29,4 +34,8 @@ config TIMER_PLMT
bool "Andes PLMT support"
default n
config TIMER_SG2042_GMT
bool "SOPHGO SG2042 GMT support"
default n
endmenu