Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 3 | * Copyright (C) 2020, Sean Anderson <seanga2@gmail.com> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 4 | * 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 Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame^] | 13 | #include <regmap.h> |
| 14 | #include <syscon.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 16 | #include <asm/io.h> |
Sean Anderson | 47d7e3b | 2020-10-25 21:46:58 -0400 | [diff] [blame] | 17 | #include <asm/smp.h> |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame^] | 18 | #include <asm/syscon.h> |
Simon Glass | 61b29b8 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 19 | #include <linux/err.h> |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 20 | |
| 21 | /* MSIP registers */ |
| 22 | #define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4) |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 26 | int riscv_init_ipi(void) |
| 27 | { |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 28 | int ret; |
| 29 | struct udevice *dev; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 30 | |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 31 | ret = uclass_get_device_by_driver(UCLASS_TIMER, |
Simon Glass | 65e25be | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 32 | DM_DRIVER_GET(sifive_clint), &dev); |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 33 | if (ret) |
| 34 | return ret; |
| 35 | |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame^] | 36 | if (dev_get_driver_data(dev) != 0) |
| 37 | gd->arch.clint = dev_read_addr_ptr(dev); |
| 38 | else |
| 39 | gd->arch.clint = syscon_get_first_range(RISCV_SYSCON_CLINT); |
| 40 | |
Sean Anderson | e5ca9a7 | 2020-09-28 10:52:26 -0400 | [diff] [blame] | 41 | if (!gd->arch.clint) |
| 42 | return -EINVAL; |
Sean Anderson | 40686c3 | 2020-06-24 06:41:18 -0400 | [diff] [blame] | 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 47 | int riscv_send_ipi(int hart) |
| 48 | { |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 49 | writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
| 54 | int riscv_clear_ipi(int hart) |
| 55 | { |
Bin Meng | 644a3cd | 2018-12-12 06:12:30 -0800 | [diff] [blame] | 56 | writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 57 | |
| 58 | return 0; |
| 59 | } |
| 60 | |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 61 | int riscv_get_ipi(int hart, int *pending) |
| 62 | { |
Lukas Auer | 8b3e97b | 2019-12-08 23:28:50 +0100 | [diff] [blame] | 63 | *pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart)); |
| 64 | |
| 65 | return 0; |
| 66 | } |
Bin Meng | 7f1a30f | 2023-06-21 23:11:45 +0800 | [diff] [blame^] | 67 | |
| 68 | static const struct udevice_id riscv_aclint_swi_ids[] = { |
| 69 | { .compatible = "riscv,aclint-mswi", .data = RISCV_SYSCON_CLINT }, |
| 70 | { } |
| 71 | }; |
| 72 | |
| 73 | U_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 | }; |