blob: cec86718c7f73566e032c8e59d14d983b3c826c3 [file] [log] [blame]
Rick Chen73766772019-04-02 15:56:40 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (C) 2019, Rick Chen <rick@andestech.com>
Sean Anderson87e6ce52020-09-28 10:52:24 -04004 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
Rick Chen73766772019-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 Anderson87e6ce52020-09-28 10:52:24 -040013#include <timer.h>
Rick Chen73766772019-04-02 15:56:40 +080014#include <asm/io.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070015#include <linux/err.h>
Rick Chen73766772019-04-02 15:56:40 +080016
17/* mtime register */
18#define MTIME_REG(base) ((ulong)(base))
19
Sean Anderson947fc2d2020-10-07 14:37:44 -040020static u64 andes_plmt_get_count(struct udevice *dev)
Sean Anderson87e6ce52020-09-28 10:52:24 -040021{
Sean Anderson947fc2d2020-10-07 14:37:44 -040022 return readq((void __iomem *)MTIME_REG(dev->priv));
Sean Anderson87e6ce52020-09-28 10:52:24 -040023}
Rick Chen73766772019-04-02 15:56:40 +080024
Sean Anderson87e6ce52020-09-28 10:52:24 -040025static const struct timer_ops andes_plmt_ops = {
26 .get_count = andes_plmt_get_count,
27};
Rick Chen73766772019-04-02 15:56:40 +080028
Sean Anderson87e6ce52020-09-28 10:52:24 -040029static int andes_plmt_probe(struct udevice *dev)
30{
31 dev->priv = dev_read_addr_ptr(dev);
32 if (!dev->priv)
33 return -EINVAL;
Rick Chen73766772019-04-02 15:56:40 +080034
Sean Anderson87e6ce52020-09-28 10:52:24 -040035 return timer_timebase_fallback(dev);
Rick Chen73766772019-04-02 15:56:40 +080036}
37
38static const struct udevice_id andes_plmt_ids[] = {
Sean Anderson87e6ce52020-09-28 10:52:24 -040039 { .compatible = "riscv,plmt0" },
Rick Chen73766772019-04-02 15:56:40 +080040 { }
41};
42
43U_BOOT_DRIVER(andes_plmt) = {
44 .name = "andes_plmt",
Sean Anderson87e6ce52020-09-28 10:52:24 -040045 .id = UCLASS_TIMER,
Rick Chen73766772019-04-02 15:56:40 +080046 .of_match = andes_plmt_ids,
Sean Anderson87e6ce52020-09-28 10:52:24 -040047 .ops = &andes_plmt_ops,
48 .probe = andes_plmt_probe,
Rick Chen73766772019-04-02 15:56:40 +080049 .flags = DM_FLAG_PRE_RELOC,
50};