blob: a28c14c1ebf2c17735c122efe1de2d91840f1c68 [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>
Sean Andersone86463f2020-09-28 10:52:24 -04004 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
Rick Chena1f24872019-04-02 15:56:40 +08005 *
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>
Sean Andersone86463f2020-09-28 10:52:24 -040013#include <timer.h>
Rick Chena1f24872019-04-02 15:56:40 +080014#include <asm/io.h>
Simon Glass61b29b82020-02-03 07:36:15 -070015#include <linux/err.h>
Rick Chena1f24872019-04-02 15:56:40 +080016
17/* mtime register */
18#define MTIME_REG(base) ((ulong)(base))
19
Sean Andersone86463f2020-09-28 10:52:24 -040020static int andes_plmt_get_count(struct udevice *dev, u64 *count)
Rick Chena1f24872019-04-02 15:56:40 +080021{
Sean Andersone86463f2020-09-28 10:52:24 -040022 *count = readq((void __iomem *)MTIME_REG(dev->priv));
Rick Chena1f24872019-04-02 15:56:40 +080023
24 return 0;
25}
26
Sean Andersone86463f2020-09-28 10:52:24 -040027static const struct timer_ops andes_plmt_ops = {
28 .get_count = andes_plmt_get_count,
29};
30
31static int andes_plmt_probe(struct udevice *dev)
32{
33 dev->priv = dev_read_addr_ptr(dev);
34 if (!dev->priv)
35 return -EINVAL;
36
37 return timer_timebase_fallback(dev);
38}
39
Rick Chena1f24872019-04-02 15:56:40 +080040static const struct udevice_id andes_plmt_ids[] = {
Sean Andersone86463f2020-09-28 10:52:24 -040041 { .compatible = "riscv,plmt0" },
Rick Chena1f24872019-04-02 15:56:40 +080042 { }
43};
44
45U_BOOT_DRIVER(andes_plmt) = {
46 .name = "andes_plmt",
Sean Andersone86463f2020-09-28 10:52:24 -040047 .id = UCLASS_TIMER,
Rick Chena1f24872019-04-02 15:56:40 +080048 .of_match = andes_plmt_ids,
Sean Andersone86463f2020-09-28 10:52:24 -040049 .ops = &andes_plmt_ops,
50 .probe = andes_plmt_probe,
Rick Chena1f24872019-04-02 15:56:40 +080051 .flags = DM_FLAG_PRE_RELOC,
52};