]> git.ipfire.org Git - thirdparty/linux.git/blame - drivers/power/reset/xgene-reboot.c
treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 156
[thirdparty/linux.git] / drivers / power / reset / xgene-reboot.c
CommitLineData
1a59d1b8 1// SPDX-License-Identifier: GPL-2.0-or-later
67778e0e
LH
2/*
3 * AppliedMicro X-Gene SoC Reboot Driver
4 *
5 * Copyright (c) 2013, Applied Micro Circuits Corporation
6 * Author: Feng Kan <fkan@apm.com>
7 * Author: Loc Ho <lho@apm.com>
8 *
67778e0e
LH
9 * This driver provides system reboot functionality for APM X-Gene SoC.
10 * For system shutdown, this is board specify. If a board designer
11 * implements GPIO shutdown, use the gpio-poweroff.c driver.
12 */
745e1976 13#include <linux/delay.h>
67778e0e 14#include <linux/io.h>
8f57f231 15#include <linux/notifier.h>
67778e0e
LH
16#include <linux/of_device.h>
17#include <linux/of_address.h>
18#include <linux/platform_device.h>
8f57f231 19#include <linux/reboot.h>
67778e0e
LH
20#include <linux/stat.h>
21#include <linux/slab.h>
67778e0e
LH
22
23struct xgene_reboot_context {
43160718 24 struct device *dev;
67778e0e
LH
25 void *csr;
26 u32 mask;
8f57f231 27 struct notifier_block restart_handler;
67778e0e
LH
28};
29
8f57f231
GR
30static int xgene_restart_handler(struct notifier_block *this,
31 unsigned long mode, void *cmd)
67778e0e 32{
8f57f231
GR
33 struct xgene_reboot_context *ctx =
34 container_of(this, struct xgene_reboot_context,
35 restart_handler);
67778e0e
LH
36
37 /* Issue the reboot */
8f57f231 38 writel(ctx->mask, ctx->csr);
67778e0e 39
745e1976 40 mdelay(1000);
67778e0e 41
43160718 42 dev_emerg(ctx->dev, "Unable to restart system\n");
8f57f231
GR
43
44 return NOTIFY_DONE;
67778e0e
LH
45}
46
47static int xgene_reboot_probe(struct platform_device *pdev)
48{
49 struct xgene_reboot_context *ctx;
43160718 50 struct device *dev = &pdev->dev;
8f57f231 51 int err;
67778e0e 52
43160718 53 ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
ef288f9f
GR
54 if (!ctx)
55 return -ENOMEM;
67778e0e 56
43160718 57 ctx->csr = of_iomap(dev->of_node, 0);
67778e0e 58 if (!ctx->csr) {
43160718 59 dev_err(dev, "can not map resource\n");
67778e0e
LH
60 return -ENODEV;
61 }
62
43160718 63 if (of_property_read_u32(dev->of_node, "mask", &ctx->mask))
67778e0e
LH
64 ctx->mask = 0xFFFFFFFF;
65
43160718 66 ctx->dev = dev;
8f57f231
GR
67 ctx->restart_handler.notifier_call = xgene_restart_handler;
68 ctx->restart_handler.priority = 128;
69 err = register_restart_handler(&ctx->restart_handler);
896af83e
AY
70 if (err) {
71 iounmap(ctx->csr);
8f57f231 72 dev_err(dev, "cannot register restart handler (err=%d)\n", err);
896af83e 73 }
67778e0e 74
8f57f231 75 return err;
67778e0e
LH
76}
77
8fb08855 78static const struct of_device_id xgene_reboot_of_match[] = {
67778e0e
LH
79 { .compatible = "apm,xgene-reboot" },
80 {}
81};
82
83static struct platform_driver xgene_reboot_driver = {
84 .probe = xgene_reboot_probe,
85 .driver = {
86 .name = "xgene-reboot",
87 .of_match_table = xgene_reboot_of_match,
88 },
89};
90
91static int __init xgene_reboot_init(void)
92{
93 return platform_driver_register(&xgene_reboot_driver);
94}
95device_initcall(xgene_reboot_init);