2018-12-12 14:12:30 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright (C) 2018, Bin Meng <bmeng.cn@gmail.com>
|
|
|
|
*
|
|
|
|
* U-Boot syscon driver for SiFive's Core Local Interruptor (CLINT).
|
|
|
|
* The CLINT block holds memory-mapped control and status registers
|
|
|
|
* associated with software and timer interrupts.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-09-28 14:52:26 +00:00
|
|
|
#include <clk.h>
|
2018-12-12 14:12:30 +00:00
|
|
|
#include <dm.h>
|
2020-09-28 14:52:26 +00:00
|
|
|
#include <timer.h>
|
2018-12-12 14:12:30 +00:00
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/syscon.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
/* MSIP registers */
|
|
|
|
#define MSIP_REG(base, hart) ((ulong)(base) + (hart) * 4)
|
|
|
|
/* mtime compare register */
|
|
|
|
#define MTIMECMP_REG(base, hart) ((ulong)(base) + 0x4000 + (hart) * 8)
|
|
|
|
/* mtime register */
|
|
|
|
#define MTIME_REG(base) ((ulong)(base) + 0xbff8)
|
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_init_ipi(void)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
int ret;
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_TIMER,
|
|
|
|
DM_GET_DRIVER(sifive_clint), &dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2020-07-20 06:17:07 +00:00
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
gd->arch.clint = dev_read_addr_ptr(dev);
|
|
|
|
if (!gd->arch.clint)
|
|
|
|
return -EINVAL;
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_send_ipi(int hart)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_clear_ipi(int hart)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2020-06-24 10:41:18 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2018-12-12 14:12:30 +00:00
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
int riscv_get_ipi(int hart, int *pending)
|
2020-06-24 10:41:18 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
*pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
static int sifive_clint_get_count(struct udevice *dev, u64 *count)
|
2018-12-12 14:12:30 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
*count = readq((void __iomem *)MTIME_REG(dev->priv));
|
2018-12-12 14:12:30 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
static const struct timer_ops sifive_clint_ops = {
|
|
|
|
.get_count = sifive_clint_get_count,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int sifive_clint_probe(struct udevice *dev)
|
2019-12-08 22:28:50 +00:00
|
|
|
{
|
2020-09-28 14:52:26 +00:00
|
|
|
dev->priv = dev_read_addr_ptr(dev);
|
|
|
|
if (!dev->priv)
|
|
|
|
return -EINVAL;
|
2019-12-08 22:28:50 +00:00
|
|
|
|
2020-09-28 14:52:26 +00:00
|
|
|
return timer_timebase_fallback(dev);
|
2019-12-08 22:28:50 +00:00
|
|
|
}
|
|
|
|
|
2018-12-12 14:12:30 +00:00
|
|
|
static const struct udevice_id sifive_clint_ids[] = {
|
2020-09-28 14:52:26 +00:00
|
|
|
{ .compatible = "riscv,clint0" },
|
2018-12-12 14:12:30 +00:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(sifive_clint) = {
|
|
|
|
.name = "sifive_clint",
|
2020-09-28 14:52:26 +00:00
|
|
|
.id = UCLASS_TIMER,
|
2018-12-12 14:12:30 +00:00
|
|
|
.of_match = sifive_clint_ids,
|
2020-09-28 14:52:26 +00:00
|
|
|
.probe = sifive_clint_probe,
|
|
|
|
.ops = &sifive_clint_ops,
|
2018-12-12 14:12:30 +00:00
|
|
|
.flags = DM_FLAG_PRE_RELOC,
|
|
|
|
};
|