summaryrefslogtreecommitdiff
path: root/drivers/timer/gxp-timer.c
blob: 6f316bc8c5c41dca5ef38eb6c6439cdb445c90e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// SPDX-License-Identifier: GPL-2.0
/*
 * GXP timer driver
 *
 * (C) Copyright 2022 Hewlett Packard Enterprise Development LP.
 * Author: Nick Hawkins <nick.hawkins@hpe.com>
 * Author: Jean-Marie Verdun <verdun@hpe.com>
 */

#include <clk.h>
#include <dm.h>
#include <timer.h>
#include <asm/io.h>

#define USTIMELO	0x18
#define USTIMEHI	0x1C

struct gxp_timer_priv {
	void __iomem *base;
};

static u64 gxp_timer_get_count(struct udevice *dev)
{
	struct gxp_timer_priv *priv = dev_get_priv(dev);
	u64 val;

	val = readl(priv->base + USTIMEHI);
	val = (val << 32) | readl(priv->base + USTIMELO);

	return val;
}

static int gxp_timer_probe(struct udevice *dev)
{
	struct timer_dev_priv *uc_priv = dev_get_uclass_priv(dev);
	struct gxp_timer_priv *priv = dev_get_priv(dev);

	priv->base = dev_read_addr_ptr(dev);
	if (!priv->base)
		return -ENOENT;

	uc_priv->clock_rate = 1000000;

	return 0;
}

static const struct timer_ops gxp_timer_ops = {
	.get_count = gxp_timer_get_count,
};

static const struct udevice_id gxp_timer_ids[] = {
	{ .compatible = "hpe,gxp-timer" },
	{}
};

U_BOOT_DRIVER(gxp_timer) = {
	.name = "gxp-timer",
	.id = UCLASS_TIMER,
	.of_match = gxp_timer_ids,
	.priv_auto = sizeof(struct gxp_timer_priv),
	.probe = gxp_timer_probe,
	.ops = &gxp_timer_ops,
	.flags = DM_FLAG_PRE_RELOC,
};