blob: dcd7e5e6b3449ab22b0881f49fd0f14e0f1651c1 [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
Bin Mengb6ee5e12018-12-12 06:12:30 -080011#include <dm.h>
Bin Meng08b8d262023-06-21 23:11:45 +080012#include <regmap.h>
13#include <syscon.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060014#include <asm/global_data.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080015#include <asm/io.h>
Sean Anderson52a1db72020-10-25 21:46:58 -040016#include <asm/smp.h>
Bin Meng08b8d262023-06-21 23:11:45 +080017#include <asm/syscon.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070018#include <linux/err.h>
Bin Mengb6ee5e12018-12-12 06:12:30 -080019
20/* MSIP registers */
21#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
Bin Mengb6ee5e12018-12-12 06:12:30 -080022
23DECLARE_GLOBAL_DATA_PTR;
24
Sean Anderson272ab202020-09-28 10:52:26 -040025int riscv_init_ipi(void)
Bin Mengb6ee5e12018-12-12 06:12:30 -080026{
Sean Anderson272ab202020-09-28 10:52:26 -040027 int ret;
28 struct udevice *dev;
Bin Meng257875d2020-07-19 23:17:07 -070029
Sean Anderson272ab202020-09-28 10:52:26 -040030 ret = uclass_get_device_by_driver(UCLASS_TIMER,
Bin Mengb5f03722023-06-21 23:11:46 +080031 DM_DRIVER_GET(riscv_aclint_timer), &dev);
Sean Anderson272ab202020-09-28 10:52:26 -040032 if (ret)
33 return ret;
34
Bin Meng08b8d262023-06-21 23:11:45 +080035 if (dev_get_driver_data(dev) != 0)
Bin Mengb5f03722023-06-21 23:11:46 +080036 gd->arch.aclint = dev_read_addr_ptr(dev);
Bin Meng08b8d262023-06-21 23:11:45 +080037 else
Bin Mengb5f03722023-06-21 23:11:46 +080038 gd->arch.aclint = syscon_get_first_range(RISCV_SYSCON_ACLINT);
Bin Meng08b8d262023-06-21 23:11:45 +080039
Bin Mengb5f03722023-06-21 23:11:46 +080040 if (!gd->arch.aclint)
Sean Anderson272ab202020-09-28 10:52:26 -040041 return -EINVAL;
Bin Mengb6ee5e12018-12-12 06:12:30 -080042
43 return 0;
44}
45
Sean Anderson272ab202020-09-28 10:52:26 -040046int riscv_send_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080047{
Bin Mengb5f03722023-06-21 23:11:46 +080048 writel(1, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080049
50 return 0;
51}
52
Sean Anderson272ab202020-09-28 10:52:26 -040053int riscv_clear_ipi(int hart)
Bin Mengb6ee5e12018-12-12 06:12:30 -080054{
Bin Mengb5f03722023-06-21 23:11:46 +080055 writel(0, (void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Sean Andersonb1d0cb32020-06-24 06:41:18 -040056
57 return 0;
58}
Bin Mengb6ee5e12018-12-12 06:12:30 -080059
Sean Anderson272ab202020-09-28 10:52:26 -040060int riscv_get_ipi(int hart, int *pending)
Sean Andersonb1d0cb32020-06-24 06:41:18 -040061{
Bin Mengb5f03722023-06-21 23:11:46 +080062 *pending = readl((void __iomem *)MSIP_REG(gd->arch.aclint, hart));
Bin Mengb6ee5e12018-12-12 06:12:30 -080063
64 return 0;
65}
Bin Meng08b8d262023-06-21 23:11:45 +080066
67static const struct udevice_id riscv_aclint_swi_ids[] = {
Bin Mengb5f03722023-06-21 23:11:46 +080068 { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_ACLINT },
Bin Meng08b8d262023-06-21 23:11:45 +080069 { }
70};
71
72U_BOOT_DRIVER(riscv_aclint_swi) = {
73 .name = "riscv_aclint_swi",
74 .id = UCLASS_SYSCON,
75 .of_match = riscv_aclint_swi_ids,
76 .flags = DM_FLAG_PRE_RELOC,
77};