1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2009 Faraday Technology
6 * 23/08/2022 Port to DM
12 #include <dm/ofnode.h>
13 #include <faraday/fttmr010.h>
14 #include <asm/global_data.h>
16 #define TIMER_LOAD_VAL 0xffffffff
18 struct fttmr010_timer_priv {
19 struct fttmr010 __iomem *regs;
22 static u64 fttmr010_timer_get_count(struct udevice *dev)
24 struct fttmr010_timer_priv *priv = dev_get_priv(dev);
25 struct fttmr010 *tmr = priv->regs;
26 u32 now = TIMER_LOAD_VAL - readl(&tmr->timer3_counter);
28 /* increment tbu if tbl has rolled over */
29 if (now < gd->arch.tbl)
33 return ((u64)gd->arch.tbu << 32) | gd->arch.tbl;
36 static int fttmr010_timer_probe(struct udevice *dev)
38 struct fttmr010_timer_priv *priv = dev_get_priv(dev);
42 priv->regs = dev_read_addr_ptr(dev);
47 debug("Faraday FTTMR010 timer revision 0x%08X\n", readl(&tmr->revision));
53 writel(TIMER_LOAD_VAL, &tmr->timer3_load);
54 writel(TIMER_LOAD_VAL, &tmr->timer3_counter);
55 writel(0, &tmr->timer3_match1);
56 writel(0, &tmr->timer3_match2);
58 /* we don't want timer to issue interrupts */
59 writel(FTTMR010_TM3_MATCH1 |
61 FTTMR010_TM3_OVERFLOW,
62 &tmr->interrupt_mask);
65 cr |= FTTMR010_TM3_CLOCK; /* use external clock */
66 cr |= FTTMR010_TM3_ENABLE;
75 static const struct timer_ops fttmr010_timer_ops = {
76 .get_count = fttmr010_timer_get_count,
79 static const struct udevice_id fttmr010_timer_ids[] = {
80 { .compatible = "faraday,fttmr010-timer" },
84 U_BOOT_DRIVER(fttmr010_timer) = {
85 .name = "fttmr010_timer",
87 .of_match = fttmr010_timer_ids,
88 .priv_auto = sizeof(struct fttmr010_timer_priv),
89 .probe = fttmr010_timer_probe,
90 .ops = &fttmr010_timer_ops,