1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019, Rick Chen <rick@andestech.com>
5 * U-Boot syscon driver for Andes's Platform Level Machine Timer (PLMT).
6 * The PLMT block holds memory-mapped mtime register
7 * associated with timer tick.
15 #include <asm/syscon.h>
18 #define MTIME_REG(base) ((ulong)(base))
20 DECLARE_GLOBAL_DATA_PTR;
22 #define PLMT_BASE_GET(void) \
26 if (!gd->arch.plmt) { \
27 ret = syscon_get_first_range(RISCV_SYSCON_PLMT); \
29 return PTR_ERR(ret); \
30 gd->arch.plmt = ret; \
34 int riscv_get_time(u64 *time)
38 *time = readq((void __iomem *)MTIME_REG(gd->arch.plmt));
43 static const struct udevice_id andes_plmt_ids[] = {
44 { .compatible = "riscv,plmt0", .data = RISCV_SYSCON_PLMT },
48 U_BOOT_DRIVER(andes_plmt) = {
51 .of_match = andes_plmt_ids,
52 .flags = DM_FLAG_PRE_RELOC,