treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / power / reset / zx-reboot.c
blob457950833dba61a65eade2383b8783fd29f70517
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3 * ZTE zx296702 SoC reset code
5 * Copyright (c) 2015 Linaro Ltd.
7 * Author: Jun Nie <jun.nie@linaro.org>
8 */
10 #include <linux/delay.h>
11 #include <linux/io.h>
12 #include <linux/module.h>
13 #include <linux/notifier.h>
14 #include <linux/of_address.h>
15 #include <linux/platform_device.h>
16 #include <linux/reboot.h>
18 static void __iomem *base;
19 static void __iomem *pcu_base;
21 static int zx_restart_handler(struct notifier_block *this,
22 unsigned long mode, void *cmd)
24 writel_relaxed(1, base + 0xb0);
25 writel_relaxed(1, pcu_base + 0x34);
27 mdelay(50);
28 pr_emerg("Unable to restart system\n");
30 return NOTIFY_DONE;
33 static struct notifier_block zx_restart_nb = {
34 .notifier_call = zx_restart_handler,
35 .priority = 128,
38 static int zx_reboot_probe(struct platform_device *pdev)
40 struct device_node *np = pdev->dev.of_node;
41 int err;
43 base = of_iomap(np, 0);
44 if (!base) {
45 WARN(1, "failed to map base address");
46 return -ENODEV;
49 np = of_find_compatible_node(NULL, NULL, "zte,zx296702-pcu");
50 pcu_base = of_iomap(np, 0);
51 of_node_put(np);
52 if (!pcu_base) {
53 iounmap(base);
54 WARN(1, "failed to map pcu_base address");
55 return -ENODEV;
58 err = register_restart_handler(&zx_restart_nb);
59 if (err) {
60 iounmap(base);
61 iounmap(pcu_base);
62 dev_err(&pdev->dev, "Register restart handler failed(err=%d)\n",
63 err);
66 return err;
69 static const struct of_device_id zx_reboot_of_match[] = {
70 { .compatible = "zte,sysctrl" },
73 MODULE_DEVICE_TABLE(of, zx_reboot_of_match);
75 static struct platform_driver zx_reboot_driver = {
76 .probe = zx_reboot_probe,
77 .driver = {
78 .name = "zx-reboot",
79 .of_match_table = zx_reboot_of_match,
82 module_platform_driver(zx_reboot_driver);
84 MODULE_DESCRIPTION("ZTE SoCs reset driver");
85 MODULE_AUTHOR("Jun Nie <jun.nie@linaro.org>");
86 MODULE_LICENSE("GPL v2");