blob: a7e90ca992c6b5eebe1afb5ece6d54aa2318b488 [file] [log] [blame]
Rick Chena1f24872019-04-02 15:56:40 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019, Rick Chen <rick@andestech.com>
4 *
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.
8 */
9
10#include <common.h>
11#include <dm.h>
12#include <regmap.h>
13#include <syscon.h>
14#include <asm/io.h>
15#include <asm/syscon.h>
Simon Glass61b29b82020-02-03 07:36:15 -070016#include <linux/err.h>
Rick Chena1f24872019-04-02 15:56:40 +080017
18/* mtime register */
19#define MTIME_REG(base) ((ulong)(base))
20
21DECLARE_GLOBAL_DATA_PTR;
22
23#define PLMT_BASE_GET(void) \
24 do { \
25 long *ret; \
26 \
27 if (!gd->arch.plmt) { \
28 ret = syscon_get_first_range(RISCV_SYSCON_PLMT); \
29 if (IS_ERR(ret)) \
30 return PTR_ERR(ret); \
31 gd->arch.plmt = ret; \
32 } \
33 } while (0)
34
35int riscv_get_time(u64 *time)
36{
37 PLMT_BASE_GET();
38
39 *time = readq((void __iomem *)MTIME_REG(gd->arch.plmt));
40
41 return 0;
42}
43
44static const struct udevice_id andes_plmt_ids[] = {
45 { .compatible = "riscv,plmt0", .data = RISCV_SYSCON_PLMT },
46 { }
47};
48
49U_BOOT_DRIVER(andes_plmt) = {
50 .name = "andes_plmt",
51 .id = UCLASS_SYSCON,
52 .of_match = andes_plmt_ids,
53 .flags = DM_FLAG_PRE_RELOC,
54};