1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2017, STMicroelectronics - All Rights Reserved
4 * Author(s): Patrice Chotard, <patrice.chotard@st.com> for STMicroelectronics.
11 #include <linux/err.h>
14 #include <asm/arch-armv7/globaltimer.h>
16 struct sti_timer_priv {
17 struct globaltimer *global_timer;
20 static u64 sti_timer_get_count(struct udevice *dev)
22 struct sti_timer_priv *priv = dev_get_priv(dev);
23 struct globaltimer *global_timer = priv->global_timer;
26 u32 old = readl(&global_timer->cnt_h);
29 low = readl(&global_timer->cnt_l);
30 high = readl(&global_timer->cnt_h);
37 return (u64)((timer << 32) | low);
40 static int sti_timer_probe(struct udevice *dev)
42 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
43 struct sti_timer_priv *priv = dev_get_priv(dev);
48 /* get arm global timer base address */
49 priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
50 if (!priv->global_timer)
53 err = clk_get_by_index(dev, 0, &clk);
55 ret = clk_get_rate(&clk);
56 if (IS_ERR_VALUE(ret))
58 uc_priv->clock_rate = ret;
60 uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
64 writel(0x01, &priv->global_timer->ctl);
69 static const struct timer_ops sti_timer_ops = {
70 .get_count = sti_timer_get_count,
73 static const struct udevice_id sti_timer_ids[] = {
74 { .compatible = "arm,cortex-a9-global-timer" },
78 U_BOOT_DRIVER(sti_timer) = {
81 .of_match = sti_timer_ids,
82 .priv_auto = sizeof(struct sti_timer_priv),
83 .probe = sti_timer_probe,
84 .ops = &sti_timer_ops,