Commit 3706f9f7 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Stafford Horne

drivers/soc/litex: Add restart handler

Let the LiteX SoC Controller register a restart handler, which resets
the LiteX SoC by writing 1 to CSR_CTRL_RESET_ADDR.
Signed-off-by: default avatarGeert Uytterhoeven <geert@linux-m68k.org>
Reviewed-by: default avatarJoel Stanley <joel@jms.id.au>
Signed-off-by: default avatarStafford Horne <shorne@gmail.com>
parent 803c72c8
...@@ -15,6 +15,11 @@ ...@@ -15,6 +15,11 @@
#include <linux/module.h> #include <linux/module.h>
#include <linux/errno.h> #include <linux/errno.h>
#include <linux/io.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
#define SCRATCH_REG_OFF 0x04 #define SCRATCH_REG_OFF 0x04
#define SCRATCH_REG_VALUE 0x12345678 #define SCRATCH_REG_VALUE 0x12345678
...@@ -66,8 +71,19 @@ static int litex_check_csr_access(void __iomem *reg_addr) ...@@ -66,8 +71,19 @@ static int litex_check_csr_access(void __iomem *reg_addr)
struct litex_soc_ctrl_device { struct litex_soc_ctrl_device {
void __iomem *base; void __iomem *base;
struct notifier_block reset_nb;
}; };
static int litex_reset_handler(struct notifier_block *this, unsigned long mode,
void *cmd)
{
struct litex_soc_ctrl_device *soc_ctrl_dev =
container_of(this, struct litex_soc_ctrl_device, reset_nb);
litex_write32(soc_ctrl_dev->base + RESET_REG_OFF, RESET_REG_VALUE);
return NOTIFY_DONE;
}
static const struct of_device_id litex_soc_ctrl_of_match[] = { static const struct of_device_id litex_soc_ctrl_of_match[] = {
{.compatible = "litex,soc-controller"}, {.compatible = "litex,soc-controller"},
{}, {},
...@@ -78,6 +94,7 @@ MODULE_DEVICE_TABLE(of, litex_soc_ctrl_of_match); ...@@ -78,6 +94,7 @@ MODULE_DEVICE_TABLE(of, litex_soc_ctrl_of_match);
static int litex_soc_ctrl_probe(struct platform_device *pdev) static int litex_soc_ctrl_probe(struct platform_device *pdev)
{ {
struct litex_soc_ctrl_device *soc_ctrl_dev; struct litex_soc_ctrl_device *soc_ctrl_dev;
int error;
soc_ctrl_dev = devm_kzalloc(&pdev->dev, sizeof(*soc_ctrl_dev), GFP_KERNEL); soc_ctrl_dev = devm_kzalloc(&pdev->dev, sizeof(*soc_ctrl_dev), GFP_KERNEL);
if (!soc_ctrl_dev) if (!soc_ctrl_dev)
...@@ -87,7 +104,29 @@ static int litex_soc_ctrl_probe(struct platform_device *pdev) ...@@ -87,7 +104,29 @@ static int litex_soc_ctrl_probe(struct platform_device *pdev)
if (IS_ERR(soc_ctrl_dev->base)) if (IS_ERR(soc_ctrl_dev->base))
return PTR_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;
platform_set_drvdata(pdev, soc_ctrl_dev);
soc_ctrl_dev->reset_nb.notifier_call = litex_reset_handler;
soc_ctrl_dev->reset_nb.priority = 128;
error = register_restart_handler(&soc_ctrl_dev->reset_nb);
if (error) {
dev_warn(&pdev->dev, "cannot register restart handler: %d\n",
error);
}
return 0;
}
static int litex_soc_ctrl_remove(struct platform_device *pdev)
{
struct litex_soc_ctrl_device *soc_ctrl_dev = platform_get_drvdata(pdev);
unregister_restart_handler(&soc_ctrl_dev->reset_nb);
return 0;
} }
static struct platform_driver litex_soc_ctrl_driver = { static struct platform_driver litex_soc_ctrl_driver = {
...@@ -96,6 +135,7 @@ static struct platform_driver litex_soc_ctrl_driver = { ...@@ -96,6 +135,7 @@ static struct platform_driver litex_soc_ctrl_driver = {
.of_match_table = of_match_ptr(litex_soc_ctrl_of_match) .of_match_table = of_match_ptr(litex_soc_ctrl_of_match)
}, },
.probe = litex_soc_ctrl_probe, .probe = litex_soc_ctrl_probe,
.remove = litex_soc_ctrl_remove,
}; };
module_platform_driver(litex_soc_ctrl_driver); module_platform_driver(litex_soc_ctrl_driver);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment