]> Git Repo - J-u-boot.git/blame - drivers/timer/andes_plmt_timer.c
Merge branch '2021-12-27-CONFIG-migrations' into next
[J-u-boot.git] / drivers / timer / andes_plmt_timer.c
CommitLineData
a1f24875
RC
1// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019, Rick Chen <[email protected]>
e86463f8 4 * Copyright (C) 2020, Sean Anderson <[email protected]>
a1f24875
RC
5 *
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.
9 */
10
11#include <common.h>
12#include <dm.h>
e86463f8 13#include <timer.h>
a1f24875 14#include <asm/io.h>
0fd3d911 15#include <dm/device-internal.h>
61b29b82 16#include <linux/err.h>
a1f24875
RC
17
18/* mtime register */
19#define MTIME_REG(base) ((ulong)(base))
20
bc8d12bf 21static u64 notrace andes_plmt_get_count(struct udevice *dev)
a1f24875 22{
0fd3d911 23 return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
a1f24875
RC
24}
25
bc8d12bf
PP
26#if CONFIG_IS_ENABLED(RISCV_MMODE) && IS_ENABLED(CONFIG_TIMER_EARLY)
27/**
28 * timer_early_get_rate() - Get the timer rate before driver model
29 */
30unsigned long notrace timer_early_get_rate(void)
31{
32 return RISCV_MMODE_TIMER_FREQ;
33}
34
35/**
36 * timer_early_get_count() - Get the timer count before driver model
37 *
38 */
39u64 notrace timer_early_get_count(void)
40{
41 return readq((void __iomem *)MTIME_REG(RISCV_MMODE_TIMERBASE));
42}
43#endif
44
e86463f8
SA
45static const struct timer_ops andes_plmt_ops = {
46 .get_count = andes_plmt_get_count,
47};
48
49static int andes_plmt_probe(struct udevice *dev)
50{
0fd3d911
SG
51 dev_set_priv(dev, dev_read_addr_ptr(dev));
52 if (!dev_get_priv(dev))
e86463f8
SA
53 return -EINVAL;
54
55 return timer_timebase_fallback(dev);
56}
57
a1f24875 58static const struct udevice_id andes_plmt_ids[] = {
e86463f8 59 { .compatible = "riscv,plmt0" },
a1f24875
RC
60 { }
61};
62
63U_BOOT_DRIVER(andes_plmt) = {
64 .name = "andes_plmt",
e86463f8 65 .id = UCLASS_TIMER,
a1f24875 66 .of_match = andes_plmt_ids,
e86463f8
SA
67 .ops = &andes_plmt_ops,
68 .probe = andes_plmt_probe,
a1f24875
RC
69 .flags = DM_FLAG_PRE_RELOC,
70};
This page took 0.147292 seconds and 4 git commands to generate.