From: Geert Uytterhoeven <geert@linux-m68k.org>
To: Karol Gugala <kgugala@antmicro.com>,
Mateusz Holenko <mholenko@antmicro.com>
Cc: Gabriel Somlo <gsomlo@gmail.com>,
Stafford Horne <shorne@gmail.com>,
linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org,
Geert Uytterhoeven <geert@linux-m68k.org>
Subject: [PATCH v2] drivers/soc/litex: Add restart handler
Date: Mon, 4 Jan 2021 17:45:00 +0100 [thread overview]
Message-ID: <20210104164500.1311091-1-geert@linux-m68k.org> (raw)
Let the LiteX SoC Controller a register a restart handler, which resets
the LiteX SoC by writing 1 to CSR_CTRL_RESET_ADDR.
Signed-off-by: Geert Uytterhoeven <geert@linux-m68k.org>
---
Tested with linux-on-litex-vexriscv.
This patch is based on upstream, i.e. not on top of Gabriel Somlo's
"[PATCH v5 0/4] drivers/soc/litex: support 32-bit subregisters, 64-bit
CPUs"
(https://lore.kernel.org/lkml/20201227161320.2194830-1-gsomlo@gmail.com/)
v2:
- Rebase on top of v5.11-rc1,
- Change reset handler priority to recommended default value of 128
(was 192).
(v1 was not sent to a mailing list)
---
drivers/soc/litex/litex_soc_ctrl.c | 33 +++++++++++++++++++++++++++---
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git a/drivers/soc/litex/litex_soc_ctrl.c b/drivers/soc/litex/litex_soc_ctrl.c
index 1217cafdfd4d1d2b..d729ad50d4ffca5e 100644
--- a/drivers/soc/litex/litex_soc_ctrl.c
+++ b/drivers/soc/litex/litex_soc_ctrl.c
@@ -15,6 +15,11 @@
#include <linux/module.h>
#include <linux/errno.h>
#include <linux/io.h>
+#include <linux/reboot.h>
+
+/* reset register located at the base address */
+#define RESET_REG_OFF 0x00
+#define RESET_REG_VALUE 0x00000001
/*
* LiteX SoC Generator, depending on the configuration, can split a single
@@ -136,8 +141,20 @@ static int litex_check_csr_access(void __iomem *reg_addr)
return 0;
}
-struct litex_soc_ctrl_device {
+static struct litex_soc_ctrl_device {
void __iomem *base;
+} *soc_ctrl_dev;
+
+static int litex_reset_handler(struct notifier_block *this, unsigned long mode,
+ void *cmd)
+{
+ litex_write32(soc_ctrl_dev->base + RESET_REG_OFF, RESET_REG_VALUE);
+ return NOTIFY_DONE;
+}
+
+static struct notifier_block litex_reset_nb = {
+ .notifier_call = litex_reset_handler,
+ .priority = 128,
};
static const struct of_device_id litex_soc_ctrl_of_match[] = {
@@ -149,7 +166,7 @@ MODULE_DEVICE_TABLE(of, litex_soc_ctrl_of_match);
static int litex_soc_ctrl_probe(struct platform_device *pdev)
{
- struct litex_soc_ctrl_device *soc_ctrl_dev;
+ int error;
soc_ctrl_dev = devm_kzalloc(&pdev->dev, sizeof(*soc_ctrl_dev), GFP_KERNEL);
if (!soc_ctrl_dev)
@@ -159,7 +176,17 @@ static int litex_soc_ctrl_probe(struct platform_device *pdev)
if (IS_ERR(soc_ctrl_dev->base))
return PTR_ERR(soc_ctrl_dev->base);
- return litex_check_csr_access(soc_ctrl_dev->base);
+ error = litex_check_csr_access(soc_ctrl_dev->base);
+ if (error)
+ return error;
+
+ error = register_restart_handler(&litex_reset_nb);
+ if (error) {
+ dev_warn(&pdev->dev, "cannot register restart handler: %d\n",
+ error);
+ }
+
+ return 0;
}
static struct platform_driver litex_soc_ctrl_driver = {
--
2.25.1
next reply other threads:[~2021-01-04 16:46 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-04 16:45 Geert Uytterhoeven [this message]
2021-01-04 16:49 ` Geert Uytterhoeven
2021-01-14 2:03 ` Stafford Horne
2021-01-14 13:48 ` Geert Uytterhoeven
2021-01-18 11:43 ` Stafford Horne
2021-01-18 12:27 ` Geert Uytterhoeven
2021-01-18 21:15 ` Stafford Horne
2021-01-19 7:59 ` Geert Uytterhoeven
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210104164500.1311091-1-geert@linux-m68k.org \
--to=geert@linux-m68k.org \
--cc=gsomlo@gmail.com \
--cc=kgugala@antmicro.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-riscv@lists.infradead.org \
--cc=mholenko@antmicro.com \
--cc=shorne@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®