-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opensbi: generic: add cv181x reset support
This allows certain secondary program loaders and other payloads to utilize SBI reboot ecalls.
- Loading branch information
1 parent
c4bd8d0
commit a85a57f
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ | |
|
||
platform-objs-y += platform.o | ||
platform-objs-y += sifive_fu540.o | ||
platform-objs-y += cvitek_cv181x.o |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters