2 * Generic Syscon Reboot Driver
4 * Copyright (c) 2013, Applied Micro Circuits Corporation
5 * Author: Feng Kan <fkan@apm.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 #include <linux/delay.h>
19 #include <linux/notifier.h>
20 #include <linux/mfd/syscon.h>
21 #include <linux/of_address.h>
22 #include <linux/of_device.h>
23 #include <linux/platform_device.h>
24 #include <linux/reboot.h>
25 #include <linux/regmap.h>
27 struct syscon_reboot_context
{
31 struct notifier_block restart_handler
;
34 static int syscon_restart_handle(struct notifier_block
*this,
35 unsigned long mode
, void *cmd
)
37 struct syscon_reboot_context
*ctx
=
38 container_of(this, struct syscon_reboot_context
,
41 /* Issue the reboot */
42 regmap_write(ctx
->map
, ctx
->offset
, ctx
->mask
);
46 pr_emerg("Unable to restart system\n");
50 static int syscon_reboot_probe(struct platform_device
*pdev
)
52 struct syscon_reboot_context
*ctx
;
53 struct device
*dev
= &pdev
->dev
;
56 ctx
= devm_kzalloc(&pdev
->dev
, sizeof(*ctx
), GFP_KERNEL
);
60 ctx
->map
= syscon_regmap_lookup_by_phandle(dev
->of_node
, "regmap");
62 return PTR_ERR(ctx
->map
);
64 if (of_property_read_u32(pdev
->dev
.of_node
, "offset", &ctx
->offset
))
67 if (of_property_read_u32(pdev
->dev
.of_node
, "mask", &ctx
->mask
))
70 ctx
->restart_handler
.notifier_call
= syscon_restart_handle
;
71 ctx
->restart_handler
.priority
= 192;
72 err
= register_restart_handler(&ctx
->restart_handler
);
74 dev_err(dev
, "can't register restart notifier (err=%d)\n", err
);
79 static const struct of_device_id syscon_reboot_of_match
[] = {
80 { .compatible
= "syscon-reboot" },
84 static struct platform_driver syscon_reboot_driver
= {
85 .probe
= syscon_reboot_probe
,
87 .name
= "syscon-reboot",
88 .of_match_table
= syscon_reboot_of_match
,
91 builtin_platform_driver(syscon_reboot_driver
);