blob: 90b8e128cb162506e6d97e715be32547c183a025 [file] [log] [blame]
Bin Mengb6ee5e12018-12-12 06:12:30 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
Sean Anderson52a1db72020-10-25 21:46:58 -04003 * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com>
Bin Mengb6ee5e12018-12-12 06:12:30 -08004 * Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
5 *
6 * U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT).
7 * The CLINT block holds memory-mapped control and status registers
8 * associated with software and timer interrupts.
9 */
10
11#include <common.h>
12#include <dm.h>
Bin Meng08b8d262023-06-21 23:11:45 +080013#include <regmap.h>
14#include <syscon.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080016#include <asm/io.h>
Sean Anderson52a1db72020-10-25 21:46:58 -040017#include <asm/smp.h>
Bin Meng08b8d262023-06-21 23:11:45 +080018#include <asm/syscon.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070019#include <linux/err.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080020
21/* MSIP registers */
22#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Mengb6ee5e12018-12-12 06:12:30 -080023
24DECLARE_GLOBAL_DATA_PTR;
25
Sean Anderson272ab202020-09-28 10:52:26 -040026int riscv_init_ipi(void)
Bin Mengb6ee5e12018-12-12 06:12:30 -080027{
Sean Anderson272ab202020-09-28 10:52:26 -040028 int ret;
29 struct udevice *dev;
Bin Meng257875d2020-07-19 23:17:07 -070030
Sean Anderson272ab202020-09-28 10:52:26 -040031 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Bin Mengb5f03722023-06-21 23:11:46 +080032 DM_DRIVER_GET(riscv_aclint_timer), &dev);
Sean Anderson272ab202020-09-28 10:52:26 -040033 if (ret)
34 return ret;
35
Bin Meng08b8d262023-06-21 23:11:45 +080036 if (dev_get_driver_data(dev) != 0)
Bin Mengb5f03722023-06-21 23:11:46 +080037 gd->arch.aclint = dev_read_addr_ptr(dev);
Bin Meng08b8d262023-06-21 23:11:45 +080038 else
Bin Mengb5f03722023-06-21 23:11:46 +080039 gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT);
Bin Meng08b8d262023-06-21 23:11:45 +080040
Bin Mengb5f03722023-06-21 23:11:46 +080041 if (!gd->arch.aclint)
Sean Anderson272ab202020-09-28 10:52:26 -040042 return -EINVAL;
Bin Mengb6ee5e12018-12-12 06:12:30 -080043
44 return 0;
45}
46
Sean Anderson272ab202020-09-28 10:52:26 -040047int riscv_send_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080048{
Bin Mengb5f03722023-06-21 23:11:46 +080049 writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080050
51 return 0;
52}
53
Sean Anderson272ab202020-09-28 10:52:26 -040054int riscv_clear_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080055{
Bin Mengb5f03722023-06-21 23:11:46 +080056 writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Sean Andersonb1d0cb32020-06-24 06:41:18 -040057
58 return 0;
59}
Bin Mengb6ee5e12018-12-12 06:12:30 -080060
Sean Anderson272ab202020-09-28 10:52:26 -040061int riscv_get_ipi(int hart, int *pending)
Sean Andersonb1d0cb32020-06-24 06:41:18 -040062{
Bin Mengb5f03722023-06-21 23:11:46 +080063 *pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080064
65 return 0;
66}
Bin Meng08b8d262023-06-21 23:11:45 +080067
68static const struct udevice_id riscv_aclint_swi_ids[] = {
Bin Mengb5f03722023-06-21 23:11:46 +080069 { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT },
Bin Meng08b8d262023-06-21 23:11:45 +080070 { }
71};
72
73U_BOOT_DRIVER(riscv_aclint_swi) = {
74 .name = "riscv_aclint_swi",
75 .id = UCLASS_SYSCON,
76 .of_match = riscv_aclint_swi_ids,
77 .flags = DM_FLAG_PRE_RELOC,
78};