1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2009 Faraday Technology
4 * Po-Yu Chuang <ratbert@faraday-tech.com>
6 * 23/08/2022 Port to DM
13 #include <dm/ofnode.h>
14 #include <faraday/fttmr010.h>
15 #include <asm/global_data.h>
17 #define TIMER_LOAD_VAL 0xffffffff
19 struct fttmr010_timer_priv {
20 struct fttmr010 __iomem *regs;
23 static u64 fttmr010_timer_get_count(struct udevice *dev)
25 struct fttmr010_timer_priv *priv = dev_get_priv(dev);
26 struct fttmr010 *tmr = priv->regs;
27 u32 now = TIMER_LOAD_VAL - readl(&tmr->timer3_counter);
29 /* increment tbu if tbl has rolled over */
30 if (now < gd->arch.tbl)
34 return ((u64)gd->arch.tbu << 32) | gd->arch.tbl;
37 static int fttmr010_timer_probe(struct udevice *dev)
39 struct fttmr010_timer_priv *priv = dev_get_priv(dev);
43 priv->regs = dev_read_addr_ptr(dev);
48 debug("Faraday FTTMR010 timer revision 0x%08X\n", readl(&tmr->revision));
54 writel(TIMER_LOAD_VAL, &tmr->timer3_load);
55 writel(TIMER_LOAD_VAL, &tmr->timer3_counter);
56 writel(0, &tmr->timer3_match1);
57 writel(0, &tmr->timer3_match2);
59 /* we don't want timer to issue interrupts */
60 writel(FTTMR010_TM3_MATCH1 |
62 FTTMR010_TM3_OVERFLOW,
63 &tmr->interrupt_mask);
66 cr |= FTTMR010_TM3_CLOCK; /* use external clock */
67 cr |= FTTMR010_TM3_ENABLE;
76 static const struct timer_ops fttmr010_timer_ops = {
77 .get_count = fttmr010_timer_get_count,
80 static const struct udevice_id fttmr010_timer_ids[] = {
81 { .compatible = "faraday,fttmr010-timer" },
85 U_BOOT_DRIVER(fttmr010_timer) = {
86 .name = "fttmr010_timer",
88 .of_match = fttmr010_timer_ids,
89 .priv_auto = sizeof(struct fttmr010_timer_priv),
90 .probe = fttmr010_timer_probe,
91 .ops = &fttmr010_timer_ops,