summaryrefslogtreecommitdiff
path: root/drivers/timer/ast_ibex_timer.c
blob: 261839661e9d37ea78d06b2f787b2de7e198f4ae (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
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (c) 2024 Aspeed Technology Inc.
 */

#include <asm/csr.h>
#include <asm/io.h>
#include <dm.h>
#include <errno.h>
#include <timer.h>

#define CSR_MCYCLE	0xb00
#define CSR_MCYCLEH	0xb80

static u64 ast_ibex_timer_get_count(struct udevice *dev)
{
	uint32_t cnt_l, cnt_h;

	cnt_l = csr_read(CSR_MCYCLE);
	cnt_h = csr_read(CSR_MCYCLEH);

	return ((uint64_t)cnt_h << 32) | cnt_l;
}

static int ast_ibex_timer_probe(struct udevice *dev)
{
	return 0;
}

static const struct timer_ops ast_ibex_timer_ops = {
	.get_count = ast_ibex_timer_get_count,
};

static const struct udevice_id ast_ibex_timer_ids[] = {
	{ .compatible = "aspeed,ast2700-ibex-timer" },
	{ }
};

U_BOOT_DRIVER(ast_ibex_timer) = {
	.name = "ast_ibex_timer",
	.id = UCLASS_TIMER,
	.of_match = ast_ibex_timer_ids,
	.probe = ast_ibex_timer_probe,
	.ops = &ast_ibex_timer_ops,
};