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.
13 #include <asm/arch-armv7/globaltimer.h>
15 DECLARE_GLOBAL_DATA_PTR;
17 struct sti_timer_priv {
18 struct globaltimer *global_timer;
21 static int sti_timer_get_count(struct udevice *dev, u64 *count)
23 struct sti_timer_priv *priv = dev_get_priv(dev);
24 struct globaltimer *global_timer = priv->global_timer;
27 u32 old = readl(&global_timer->cnt_h);
30 low = readl(&global_timer->cnt_l);
31 high = readl(&global_timer->cnt_h);
38 *count = (u64)((timer << 32) | low);
43 static int sti_timer_probe(struct udevice *dev)
45 struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
46 struct sti_timer_priv *priv = dev_get_priv(dev);
49 uc_priv->clock_rate = CONFIG_SYS_HZ_CLOCK;
51 /* get arm global timer base address */
52 addr = fdtdec_get_addr(gd->fdt_blob, dev_of_offset(dev), "reg");
53 priv->global_timer = (struct globaltimer *)addr;
56 writel(0x01, &priv->global_timer->ctl);
61 static const struct timer_ops sti_timer_ops = {
62 .get_count = sti_timer_get_count,
65 static const struct udevice_id sti_timer_ids[] = {
66 { .compatible = "arm,cortex-a9-global-timer" },
70 U_BOOT_DRIVER(sti_timer) = {
73 .of_match = sti_timer_ids,
74 .priv_auto_alloc_size = sizeof(struct sti_timer_priv),
75 .probe = sti_timer_probe,
76 .ops = &sti_timer_ops,
77 .flags = DM_FLAG_PRE_RELOC,