summaryrefslogtreecommitdiff
path: root/lib/utils/timer/fdt_timer_plmt.c
blob: e8be91b902cb98a6f4678fdfabd356e3b9df6232 (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
/*
 * SPDX-License-Identifier: BSD-2-Clause
 *
 * Copyright (c) 2022 Andes Technology Corporation
 *
 * Authors:
 *   Yu Chien Peter Lin <peterlin@andestech.com>
 */

#include <sbi_utils/fdt/fdt_helper.h>
#include <sbi_utils/timer/fdt_timer.h>
#include <sbi_utils/timer/andes_plmt.h>

extern struct plmt_data plmt;

static int fdt_plmt_cold_timer_init(void *fdt, int nodeoff,
				    const struct fdt_match *match)
{
	int rc;
	unsigned long plmt_base;

	rc = fdt_parse_plmt_node(fdt, nodeoff, &plmt_base, &plmt.size,
				 &plmt.hart_count);
	if (rc)
		return rc;

	plmt.time_val = (u64 *)plmt_base;
	plmt.time_cmp = (u64 *)(plmt_base + 0x8);

	rc = fdt_parse_timebase_frequency(fdt, &plmt.timer_freq);
	if (rc)
		return rc;

	rc = plmt_cold_timer_init(&plmt);
	if (rc)
		return rc;

	return 0;
}

static const struct fdt_match timer_plmt_match[] = {
	{ .compatible = "andestech,plmt0" },
	{},
};

struct fdt_timer fdt_timer_plmt = {
	.match_table = timer_plmt_match,
	.cold_init   = fdt_plmt_cold_timer_init,
	.warm_init   = plmt_warm_timer_init,
	.exit	     = NULL,
};