blob: 00ce0f08d6ee5c134f3fc3d06c8599d10a967562 [file] [log] [blame]
Sean Anderson52a1db72020-10-25 21:46:58 -04001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
4 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5 */
6
7#include <common.h>
8#include <clk.h>
9#include <dm.h>
10#include <timer.h>
11#include <asm/io.h>
12#include <linux/err.h>
13
14/* mtime register */
15#define MTIME_REG(base) ((ulong)(base) + 0xbff8)
16
17static u64 sifive_clint_get_count(struct udevice *dev)
18{
19 return readq((void __iomem *)MTIME_REG(dev->priv));
20}
21
22static const struct timer_ops sifive_clint_ops = {
23 .get_count = sifive_clint_get_count,
24};
25
26static int sifive_clint_probe(struct udevice *dev)
27{
28 dev->priv = dev_read_addr_ptr(dev);
29 if (!dev->priv)
30 return -EINVAL;
31
32 return timer_timebase_fallback(dev);
33}
34
35static const struct udevice_id sifive_clint_ids[] = {
36 { .compatible = "riscv,clint0" },
37 { }
38};
39
40U_BOOT_DRIVER(sifive_clint) = {
41 .name = "sifive_clint",
42 .id = UCLASS_TIMER,
43 .of_match = sifive_clint_ids,
44 .probe = sifive_clint_probe,
45 .ops = &sifive_clint_ops,
46 .flags = DM_FLAG_PRE_RELOC,
47};