2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2017-02-21 12:37:05 +00:00
|
|
|
/*
|
2017-10-23 07:53:57 +00:00
|
|
|
* Copyright (C) 2017, STMicroelectronics - All Rights Reserved
|
2020-12-02 17:47:30 +00:00
|
|
|
* Author(s): Patrice Chotard, <patrice.chotard@foss.st.com> for STMicroelectronics.
|
2022-08-24 04:44:32 +00:00
|
|
|
*
|
|
|
|
* ARM Cortext A9 global timer driver
|
2017-02-21 12:37:05 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-03-13 22:42:44 +00:00
|
|
|
#include <clk.h>
|
2017-02-21 12:37:05 +00:00
|
|
|
#include <timer.h>
|
2020-03-13 22:42:44 +00:00
|
|
|
#include <linux/err.h>
|
2017-02-21 12:37:05 +00:00
|
|
|
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch-armv7/globaltimer.h>
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
struct arm_global_timer_priv {
|
2017-02-21 12:37:05 +00:00
|
|
|
struct globaltimer *global_timer;
|
|
|
|
};
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
static u64 arm_global_timer_get_count(struct udevice *dev)
|
2017-02-21 12:37:05 +00:00
|
|
|
{
|
2022-08-24 04:44:32 +00:00
|
|
|
struct arm_global_timer_priv *priv = dev_get_priv(dev);
|
2017-02-21 12:37:05 +00:00
|
|
|
struct globaltimer *global_timer = priv->global_timer;
|
|
|
|
u32 low, high;
|
|
|
|
u64 timer;
|
|
|
|
u32 old = readl(&global_timer->cnt_h);
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
low = readl(&global_timer->cnt_l);
|
|
|
|
high = readl(&global_timer->cnt_h);
|
|
|
|
if (old == high)
|
|
|
|
break;
|
|
|
|
else
|
|
|
|
old = high;
|
|
|
|
}
|
|
|
|
timer = high;
|
2020-10-07 18:37:44 +00:00
|
|
|
return (u64)((timer << 32) | low);
|
2017-02-21 12:37:05 +00:00
|
|
|
}
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
static int arm_global_timer_probe(struct udevice *dev)
|
2017-02-21 12:37:05 +00:00
|
|
|
{
|
|
|
|
struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
|
2022-08-24 04:44:32 +00:00
|
|
|
struct arm_global_timer_priv *priv = dev_get_priv(dev);
|
2020-03-13 22:42:44 +00:00
|
|
|
struct clk clk;
|
|
|
|
int err;
|
|
|
|
ulong ret;
|
2017-02-21 12:37:05 +00:00
|
|
|
|
|
|
|
/* get arm global timer base address */
|
2020-03-13 22:42:43 +00:00
|
|
|
priv->global_timer = (struct globaltimer *)dev_read_addr_ptr(dev);
|
|
|
|
if (!priv->global_timer)
|
|
|
|
return -ENOENT;
|
2017-02-21 12:37:05 +00:00
|
|
|
|
2020-03-13 22:42:44 +00:00
|
|
|
err = clk_get_by_index(dev, 0, &clk);
|
|
|
|
if (!err) {
|
|
|
|
ret = clk_get_rate(&clk);
|
|
|
|
if (IS_ERR_VALUE(ret))
|
|
|
|
return ret;
|
|
|
|
uc_priv->clock_rate = ret;
|
|
|
|
} else {
|
2022-11-16 18:10:41 +00:00
|
|
|
uc_priv->clock_rate = CFG_SYS_HZ_CLOCK;
|
2020-03-13 22:42:44 +00:00
|
|
|
}
|
|
|
|
|
2017-02-21 12:37:05 +00:00
|
|
|
/* init timer */
|
|
|
|
writel(0x01, &priv->global_timer->ctl);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
static const struct timer_ops arm_global_timer_ops = {
|
|
|
|
.get_count = arm_global_timer_get_count,
|
2017-02-21 12:37:05 +00:00
|
|
|
};
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
static const struct udevice_id arm_global_timer_ids[] = {
|
2017-02-21 12:37:05 +00:00
|
|
|
{ .compatible = "arm,cortex-a9-global-timer" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
2022-08-24 04:44:32 +00:00
|
|
|
U_BOOT_DRIVER(arm_global_timer) = {
|
|
|
|
.name = "arm_global_timer",
|
2017-02-21 12:37:05 +00:00
|
|
|
.id = UCLASS_TIMER,
|
2022-08-24 04:44:32 +00:00
|
|
|
.of_match = arm_global_timer_ids,
|
|
|
|
.priv_auto = sizeof(struct arm_global_timer_priv),
|
|
|
|
.probe = arm_global_timer_probe,
|
|
|
|
.ops = &arm_global_timer_ops,
|
2017-02-21 12:37:05 +00:00
|
|
|
};
|