]> Git Repo - u-boot.git/blob - arch/riscv/lib/sifive_clint.c
riscv: Clean up IPI initialization code
[u-boot.git] / arch / riscv / lib / sifive_clint.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (C) 2018, Bin Meng <[email protected]>
4  *
5  * U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT).
6  * The CLINT block holds memory-mapped control and status registers
7  * associated with software and timer interrupts.
8  */
9
10 #include <common.h>
11 #include <dm.h>
12 #include <regmap.h>
13 #include <syscon.h>
14 #include <asm/io.h>
15 #include <asm/syscon.h>
16 #include <linux/err.h>
17
18 /* MSIP registers */
19 #define MSIP_REG(base, hart)            ((ulong)(base) + (hart) * 4)
20 /* mtime compare register */
21 #define MTIMECMP_REG(base, hart)        ((ulong)(base) + 0x4000 + (hart) * 8)
22 /* mtime register */
23 #define MTIME_REG(base)                 ((ulong)(base) + 0xbff8)
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 int riscv_get_time(u64 *time)
28 {
29         *time = readq((void __iomem *)MTIME_REG(gd->arch.clint));
30
31         return 0;
32 }
33
34 int riscv_set_timecmp(int hart, u64 cmp)
35 {
36         writeq(cmp, (void __iomem *)MTIMECMP_REG(gd->arch.clint, hart));
37
38         return 0;
39 }
40
41 int riscv_init_ipi(void)
42 {
43         long *ret = syscon_get_first_range(RISCV_SYSCON_CLINT);
44
45         if (IS_ERR(ret))
46                 return PTR_ERR(ret);
47         gd->arch.clint = ret;
48
49         return 0;
50 }
51
52 int riscv_send_ipi(int hart)
53 {
54         writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
55
56         return 0;
57 }
58
59 int riscv_clear_ipi(int hart)
60 {
61         writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
62
63         return 0;
64 }
65
66 int riscv_get_ipi(int hart, int *pending)
67 {
68         *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
69
70         return 0;
71 }
72
73 static const struct udevice_id sifive_clint_ids[] = {
74         { .compatible = "riscv,clint0", .data = RISCV_SYSCON_CLINT },
75         { }
76 };
77
78 U_BOOT_DRIVER(sifive_clint) = {
79         .name           = "sifive_clint",
80         .id             = UCLASS_SYSCON,
81         .of_match       = sifive_clint_ids,
82         .flags          = DM_FLAG_PRE_RELOC,
83 };
This page took 0.0317 seconds and 4 git commands to generate.