1 // SPDX-License-Identifier: GPL-2.0+
3 * Designware APB Timer driver
5 * Copyright (C) 2018 Marek Vasut <marex@denx.de>
14 #include <asm/arch/timer.h>
16 #define DW_APB_LOAD_VAL 0x0
17 #define DW_APB_CURR_VAL 0x4
18 #define DW_APB_CTRL 0x8
20 DECLARE_GLOBAL_DATA_PTR;
22 struct dw_apb_timer_priv {
26 static int dw_apb_timer_get_count(struct udevice *dev, u64 *count)
28 struct dw_apb_timer_priv *priv = dev_get_priv(dev);
31 * The DW APB counter counts down, but this function
32 * requires the count to be incrementing. Invert the
35 *count = ~readl(priv->regs + DW_APB_CURR_VAL);
40 static int dw_apb_timer_probe(struct udevice *dev)
42 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
43 struct dw_apb_timer_priv *priv = dev_get_priv(dev);
47 ret = clk_get_by_index(dev, 0, &clk);
51 uc_priv->clock_rate = clk_get_rate(&clk);
56 writel(0xffffffff, priv->regs + DW_APB_LOAD_VAL);
57 writel(0xffffffff, priv->regs + DW_APB_CURR_VAL);
58 setbits_le32(priv->regs + DW_APB_CTRL, 0x3);
63 static int dw_apb_timer_ofdata_to_platdata(struct udevice *dev)
65 struct dw_apb_timer_priv *priv = dev_get_priv(dev);
67 priv->regs = dev_read_addr(dev);
72 static const struct timer_ops dw_apb_timer_ops = {
73 .get_count = dw_apb_timer_get_count,
76 static const struct udevice_id dw_apb_timer_ids[] = {
77 { .compatible = "snps,dw-apb-timer" },
81 U_BOOT_DRIVER(dw_apb_timer) = {
82 .name = "dw_apb_timer",
84 .ops = &dw_apb_timer_ops,
85 .probe = dw_apb_timer_probe,
86 .of_match = dw_apb_timer_ids,
87 .ofdata_to_platdata = dw_apb_timer_ofdata_to_platdata,
88 .priv_auto_alloc_size = sizeof(struct dw_apb_timer_priv),