1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2019, Rick Chen <rick@andestech.com>
4 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
6 * U-Boot syscon driver for Andes's Platform Level Machine Timer (PLMT).
7 * The PLMT block holds memory-mapped mtime register
8 * associated with timer tick.
15 #include <dm/device-internal.h>
16 #include <linux/err.h>
19 #define MTIME_REG(base) ((ulong)(base))
21 static u64 notrace andes_plmt_get_count(struct udevice *dev)
23 return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
26 #if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY)
28 * timer_early_get_rate() - Get the timer rate before driver model
30 unsigned long notrace timer_early_get_rate(void)
32 return RISCV_MMODE_TIMER_FREQ;
36 * timer_early_get_count() - Get the timer count before driver model
39 u64 notrace timer_early_get_count(void)
41 return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
45 static const struct timer_ops andes_plmt_ops = {
46 .get_count = andes_plmt_get_count,
49 static int andes_plmt_probe(struct udevice *dev)
51 dev_set_priv(dev, dev_read_addr_ptr(dev));
52 if (!dev_get_priv(dev))
55 return timer_timebase_fallback(dev);
58 static const struct udevice_id andes_plmt_ids[] = {
59 { .compatible = "andestech,plmt0" },
63 U_BOOT_DRIVER(andes_plmt) = {
66 .of_match = andes_plmt_ids,
67 .ops = &andes_plmt_ops,
68 .probe = andes_plmt_probe,
69 .flags = DM_FLAG_PRE_RELOC,