mirror of
https://github.com/riscv-software-src/opensbi.git
synced 2026-06-17 16:41:19 +01:00
lib: utils/reset: Add litex SoC reset driver
Litex SoC controller supports reboot function by toggling the first bit of the ctrl register. Add a reset driver so other software can use it. Signed-off-by: Inochi Amaoto <inochiama@gmail.com> Reviewed-by: Anup Patel <anup@brainfault.org> Link: https://lore.kernel.org/r/20260529085234.1682842-1-inochiama@gmail.com Signed-off-by: Anup Patel <anup@brainfault.org>
This commit is contained in:
committed by
Anup Patel
parent
9c9767504d
commit
dec9141a77
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*
|
||||
* Copyright (c) 2026 Inochi Amaoto <inochiama@gmail.com>
|
||||
*/
|
||||
|
||||
#include <libfdt.h>
|
||||
#include <sbi/riscv_io.h>
|
||||
#include <sbi/sbi_error.h>
|
||||
#include <sbi/sbi_system.h>
|
||||
#include <sbi_utils/fdt/fdt_driver.h>
|
||||
#include <sbi_utils/fdt/fdt_helper.h>
|
||||
|
||||
#define RESET_CTRL 0x0
|
||||
|
||||
static volatile u32 *litex_soc_base;
|
||||
|
||||
static int litex_reset_check(u32 type, u32 reason)
|
||||
{
|
||||
switch (type) {
|
||||
case SBI_SRST_RESET_TYPE_COLD_REBOOT:
|
||||
case SBI_SRST_RESET_TYPE_WARM_REBOOT:
|
||||
return 255;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void litex_do_reset(u32 type, u32 reason)
|
||||
{
|
||||
writel_relaxed(0x1, litex_soc_base + RESET_CTRL);
|
||||
}
|
||||
|
||||
static struct sbi_system_reset_device litex_reset = {
|
||||
.name = "litex-reset",
|
||||
.system_reset_check = litex_reset_check,
|
||||
.system_reset = litex_do_reset
|
||||
};
|
||||
|
||||
static int litex_reset_init(const void *fdt, int nodeoff,
|
||||
const struct fdt_match *match)
|
||||
{
|
||||
uint64_t reg_addr;
|
||||
int rc;
|
||||
|
||||
rc = fdt_get_node_addr_size(fdt, nodeoff, 0, ®_addr, NULL);
|
||||
if (rc < 0 || !reg_addr)
|
||||
return SBI_ENODEV;
|
||||
|
||||
|
||||
litex_soc_base = (volatile u32 *)(unsigned long)reg_addr;
|
||||
|
||||
sbi_system_reset_add_device(&litex_reset);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const struct fdt_match litex_reset_match[] = {
|
||||
{ .compatible = "litex,soc-controller" },
|
||||
{ },
|
||||
};
|
||||
|
||||
const struct fdt_driver fdt_reset_litex = {
|
||||
.match_table = litex_reset_match,
|
||||
.init = litex_reset_init,
|
||||
};
|
||||
Reference in New Issue
Block a user