Skip to contentSkip to conversation

lib: utils/reset: Add litex SoC reset driver

PATCH Applied Inochi Amaoto 2 participants 2 messages May 29 – Jun 15 Litex platform

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 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.

---
 lib/utils/reset/Kconfig            |  5 +++
 lib/utils/reset/fdt_reset_litex.c  | 66 ++++++++++++++++++++++++++++++
 lib/utils/reset/objects.mk         |  3 ++
 platform/generic/configs/defconfig |  1 +
 4 files changed, 75 insertions(+)
 create mode 100644 lib/utils/reset/fdt_reset_litex.c
lib/utils/reset/Kconfig +5 -0
index f98926e5..b2ac120e 100644
@@ -24,6 +24,11 @@ config FDT_RESET_HTIF
 	select SYS_HTIF
 	default n
 
+config FDT_RESET_LITEX
+	bool "LITEX SoC reset driver"
+	depends on FDT_GPIO
+	default n
+
 config FDT_RESET_RPMI
 	bool "RPMI FDT reset driver"
 	depends on FDT_MAILBOX && RPMI_MAILBOX
lib/utils/reset/fdt_reset_litex.c new file +66 -0

66 lines not on this page · raw message

lib/utils/reset/objects.mk +3 -0
index 3c681c27..38b4e306 100644
@@ -17,6 +17,9 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_GPIO) += reset/fdt_reset_gpio.o
 carray-fdt_early_drivers-$(CONFIG_FDT_RESET_HTIF) += fdt_reset_htif
 libsbiutils-objs-$(CONFIG_FDT_RESET_HTIF) += reset/fdt_reset_htif.o
 
+carray-fdt_early_drivers-$(CONFIG_FDT_RESET_LITEX) += fdt_reset_litex
+libsbiutils-objs-$(CONFIG_FDT_RESET_LITEX) += reset/fdt_reset_litex.o
+
 carray-fdt_early_drivers-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += fdt_reset_sg2042_mcu
 libsbiutils-objs-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += reset/fdt_reset_sg2042_hwmon_mcu.o
 
platform/generic/configs/defconfig +1 -0
index 818b71f4..969639e3 100644
@@ -49,6 +49,7 @@ CONFIG_FDT_REGMAP_SYSCON=y
 CONFIG_FDT_RESET=y
 CONFIG_FDT_RESET_ATCWDT200=y
 CONFIG_FDT_RESET_GPIO=y
+CONFIG_FDT_RESET_LITEX=y
 CONFIG_FDT_RESET_HTIF=y
 CONFIG_FDT_RESET_RPMI=y
 CONFIG_FDT_RESET_SG2042_HWMON_MCU=y

--
2.54.0

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi
Reviewed-by on v1 1/1 Applied
#1 lore raw
Quoted 6 lines · Inochi Amaoto

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.

LGTM.

Applied this patch to the riscv/opensbi repo.

Thanks,
Anup

Quoted 130 lines
---
 lib/utils/reset/Kconfig            |  5 +++
 lib/utils/reset/fdt_reset_litex.c  | 66 ++++++++++++++++++++++++++++++
 lib/utils/reset/objects.mk         |  3 ++
 platform/generic/configs/defconfig |  1 +
 4 files changed, 75 insertions(+)
 create mode 100644 lib/utils/reset/fdt_reset_litex.c
lib/utils/reset/Kconfig +5 -0
index f98926e5..b2ac120e 100644
@@ -24,6 +24,11 @@ config FDT_RESET_HTIF
        select SYS_HTIF
        default n
 
+config FDT_RESET_LITEX
+       bool "LITEX SoC reset driver"
+       depends on FDT_GPIO
+       default n
+
 config FDT_RESET_RPMI
        bool "RPMI FDT reset driver"
        depends on FDT_MAILBOX && RPMI_MAILBOX
lib/utils/reset/fdt_reset_litex.c new file +66 -0
new file mode 100644
index 00000000..287745f0
@@ -0,0 +1,66 @@
+/*
+ * SPDX-License-Identifier: BSD-2-Clause
+ *
+ * Copyright (c) 2026 Inochi Amaoto <[email protected]>
+ */
+
+#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, &reg_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,
+};
lib/utils/reset/objects.mk +3 -0
index 3c681c27..38b4e306 100644
@@ -17,6 +17,9 @@ libsbiutils-objs-$(CONFIG_FDT_RESET_GPIO) += reset/fdt_reset_gpio.o
 carray-fdt_early_drivers-$(CONFIG_FDT_RESET_HTIF) += fdt_reset_htif
 libsbiutils-objs-$(CONFIG_FDT_RESET_HTIF) += reset/fdt_reset_htif.o
 
+carray-fdt_early_drivers-$(CONFIG_FDT_RESET_LITEX) += fdt_reset_litex
+libsbiutils-objs-$(CONFIG_FDT_RESET_LITEX) += reset/fdt_reset_litex.o
+
 carray-fdt_early_drivers-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += fdt_reset_sg2042_mcu
 libsbiutils-objs-$(CONFIG_FDT_RESET_SG2042_HWMON_MCU) += reset/fdt_reset_sg2042_hwmon_mcu.o
 
platform/generic/configs/defconfig +1 -1
index 818b71f4..969639e3 100644
@@ -49,6 +49,7 @@ CONFIG_FDT_REGMAP_SYSCON=y
 CONFIG_FDT_RESET=y
 CONFIG_FDT_RESET_ATCWDT200=y
 CONFIG_FDT_RESET_GPIO=y
+CONFIG_FDT_RESET_LITEX=y
 CONFIG_FDT_RESET_HTIF=y
 CONFIG_FDT_RESET_RPMI=y
 CONFIG_FDT_RESET_SG2042_HWMON_MCU=y
--

2.54.0

--
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi

Signature · 3 lines
opensbi mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/opensbi