blob: db2cf86f638a1b016b8bd1d8f5ae2acc8e16c716 [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 Glass0fd3d912020-12-22 19:30:28 -070015#include <dm/device-internal.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
Sean Anderson8af7bb92020-10-07 14:37:44 -040021static u64 andes_plmt_get_count(struct udevice *dev)
Rick Chena1f24872019-04-02 15:56:40 +080022{
Simon Glass0fd3d912020-12-22 19:30:28 -070023 return readq((void __iomem *)MTIME_REG(dev_get_priv(dev)));
Rick Chena1f24872019-04-02 15:56:40 +080024}
25
Sean Andersone86463f2020-09-28 10:52:24 -040026static const struct timer_ops andes_plmt_ops = {
27 .get_count = andes_plmt_get_count,
28};
29
30static int andes_plmt_probe(struct udevice *dev)
31{
Simon Glass0fd3d912020-12-22 19:30:28 -070032 dev_set_priv(dev, dev_read_addr_ptr(dev));
33 if (!dev_get_priv(dev))
Sean Andersone86463f2020-09-28 10:52:24 -040034 return -EINVAL;
35
36 return timer_timebase_fallback(dev);
37}
38
Rick Chena1f24872019-04-02 15:56:40 +080039static const struct udevice_id andes_plmt_ids[] = {
Sean Andersone86463f2020-09-28 10:52:24 -040040 { .compatible = "riscv,plmt0" },
Rick Chena1f24872019-04-02 15:56:40 +080041 { }
42};
43
44U_BOOT_DRIVER(andes_plmt) = {
45 .name = "andes_plmt",
Sean Andersone86463f2020-09-28 10:52:24 -040046 .id = UCLASS_TIMER,
Rick Chena1f24872019-04-02 15:56:40 +080047 .of_match = andes_plmt_ids,
Sean Andersone86463f2020-09-28 10:52:24 -040048 .ops = &andes_plmt_ops,
49 .probe = andes_plmt_probe,
Rick Chena1f24872019-04-02 15:56:40 +080050 .flags = DM_FLAG_PRE_RELOC,
51};