// 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>
#include <dm.h>
#include <regmap.h>
#include <syscon.h>
#include <asm/io.h>
#include <asm/syscon.h>
#include <linux/err.h>

/* 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;

int riscv_get_time(u64 *time)
{
	/* ensure timer register base has a sane value */
	riscv_init_ipi();

	*time = readq((void __iomem *)MTIME_REG(gd->arch.clint));

	return 0;
}

int riscv_set_timecmp(int hart, u64 cmp)
{
	/* ensure timer register base has a sane value */
	riscv_init_ipi();

	writeq(cmp, (void __iomem *)MTIMECMP_REG(gd->arch.clint, hart));

	return 0;
}

int riscv_init_ipi(void)
{
	if (!gd->arch.clint) {
		long *ret = syscon_get_first_range(RISCV_SYSCON_CLINT);

		if (IS_ERR(ret))
			return PTR_ERR(ret);
		gd->arch.clint = ret;
	}

	return 0;
}

int riscv_send_ipi(int hart)
{
	writel(1, (void __iomem *)MSIP_REG(gd->arch.clint, hart));

	return 0;
}

int riscv_clear_ipi(int hart)
{
	writel(0, (void __iomem *)MSIP_REG(gd->arch.clint, hart));

	return 0;
}

int riscv_get_ipi(int hart, int *pending)
{
	*pending = readl((void __iomem *)MSIP_REG(gd->arch.clint, hart));

	return 0;
}

static const struct udevice_id sifive_clint_ids[] = {
	{ .compatible = "riscv,clint0", .data = RISCV_SYSCON_CLINT },
	{ }
};

U_BOOT_DRIVER(sifive_clint) = {
	.name		= "sifive_clint",
	.id		= UCLASS_SYSCON,
	.of_match	= sifive_clint_ids,
	.flags		= DM_FLAG_PRE_RELOC,
};
