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.
12 #include <asm/arch-armv7/globaltimer.h>
14 struct sti_timer_priv {
15 struct globaltimer *global_timer;
18 static int sti_timer_get_count(struct udevice *dev, u64 *count)
20 struct sti_timer_priv *priv = dev_get_priv(dev);
21 struct globaltimer *global_timer = priv->global_timer;
24 u32 old = readl(&global_timer->cnt_h);
27 low = readl(&global_timer->cnt_l);
28 high = readl(&global_timer->cnt_h);
35 *count = (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);
45 uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
47 /* get arm global timer base address */
48 priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
49 if (!priv->global_timer)
53 writel(0x01, &priv->global_timer->ctl);
58 static const struct timer_ops sti_timer_ops = {
59 .get_count = sti_timer_get_count,
62 static const struct udevice_id sti_timer_ids[] = {
63 { .compatible = "arm,cortex-a9-global-timer" },
67 U_BOOT_DRIVER(sti_timer) = {
70 .of_match = sti_timer_ids,
71 .priv_auto_alloc_size = sizeof(struct sti_timer_priv),
72 .probe = sti_timer_probe,
73 .ops = &sti_timer_ops,