Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add cv181x reset support to SBI #78

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions opensbi/platform/generic/cvitek_cv181x.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* SPDX-License-Identifier: BSD-2-Clause
*
* Copyright (c) 2025 Thomas Makin.
*
* Authors:
* Thomas Makin <[email protected]>
*/

#include <platform_override.h>
#include <sbi/sbi_system.h>
#include <sbi/riscv_io.h>
#include <sbi_utils/fdt/fdt_helper.h>

static inline void cv_writel(u32 value, uintptr_t base, u32 reg) {
writel(value, (volatile void *)(base + reg));
}

static inline u32 cv_readl(uintptr_t base, u32 reg) {
return readl((volatile void *)(base + reg));
}

static int cv_system_reset_check(u32 type, u32 reason)
{
return 1;
}

#define REG_RTC_CTRL_BASE 0x05025000
#define RTC_CTRL0_UNLOCKKEY 0x4
#define RTC_CTRL0 0x8

#define REG_RTC_BASE 0x05026000
#define RTC_EN_WARM_RST_REQ 0xCC

static void cv_system_reset(u32 type, u32 reason)
{
u32 val;

cv_writel(0x01, REG_RTC_BASE, RTC_EN_WARM_RST_REQ);
while (cv_readl(REG_RTC_BASE, RTC_EN_WARM_RST_REQ) != 0x01);
cv_writel(0xAB18, REG_RTC_CTRL_BASE, RTC_CTRL0_UNLOCKKEY);
val = cv_readl(REG_RTC_CTRL_BASE, + RTC_CTRL0);
val |= (0xFFFF0800 | (0x1 << 4));
cv_writel(val, REG_RTC_CTRL_BASE, RTC_CTRL0);

while (1);
}

static struct sbi_system_reset_device cv_reset = {
.name = "cv_reset",
.system_reset_check = cv_system_reset_check,
.system_reset = cv_system_reset
};

static int cv_early_init(bool cold_boot, const struct fdt_match *match)
{
if (cold_boot)
sbi_system_reset_set_device(&cv_reset);

return 0;
}

static const struct fdt_match cvitek_cv181x_match[] = {
{ .compatible = "cvitek,cv181x" },
{ },
};

const struct platform_override cvitek_cv181x = {
.match_table = cvitek_cv181x_match,
.early_init = cv_early_init,
};
1 change: 1 addition & 0 deletions opensbi/platform/generic/objects.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@

platform-objs-y += platform.o
platform-objs-y += sifive_fu540.o
platform-objs-y += cvitek_cv181x.o
2 changes: 2 additions & 0 deletions opensbi/platform/generic/platform.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
#include <sbi_utils/reset/fdt_reset.h>

extern const struct platform_override sifive_fu540;
extern const struct platform_override cvitek_cv181x;

static const struct platform_override *special_platforms[] = {
&sifive_fu540,
&cvitek_cv181x,
};

static const struct platform_override *generic_plat = NULL;
Expand Down