2 * Generic Syscon Poweroff Driver
4 * Copyright (c) 2015, National Instruments Corp.
5 * Author: Moritz Fischer <moritz.fischer@ettus.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.
18 #include <linux/kallsyms.h>
19 #include <linux/delay.h>
21 #include <linux/notifier.h>
22 #include <linux/mfd/syscon.h>
23 #include <linux/of_address.h>
24 #include <linux/of_device.h>
25 #include <linux/platform_device.h>
27 #include <linux/regmap.h>
29 static struct regmap *map;
33 void syscon_poweroff(void)
35 /* Issue the poweroff */
36 regmap_write(map, offset, mask);
40 pr_emerg("Unable to poweroff system\n");
43 static int syscon_poweroff_probe(struct platform_device *pdev)
45 char symname[KSYM_NAME_LEN];
47 map = syscon_regmap_lookup_by_phandle(pdev->dev.of_node, "regmap");
49 dev_err(&pdev->dev, "unable to get syscon");
53 if (of_property_read_u32(pdev->dev.of_node, "offset", &offset)) {
54 dev_err(&pdev->dev, "unable to read 'offset'");
58 if (of_property_read_u32(pdev->dev.of_node, "mask", &mask)) {
59 dev_err(&pdev->dev, "unable to read 'mask'");
64 lookup_symbol_name((ulong)pm_power_off, symname);
66 "pm_power_off already claimed %p %s",
67 pm_power_off, symname);
71 pm_power_off = syscon_poweroff;
76 static int syscon_poweroff_remove(struct platform_device *pdev)
78 if (pm_power_off == syscon_poweroff)
84 static const struct of_device_id syscon_poweroff_of_match[] = {
85 { .compatible = "syscon-poweroff" },
89 static struct platform_driver syscon_poweroff_driver = {
90 .probe = syscon_poweroff_probe,
91 .remove = syscon_poweroff_remove,
93 .name = "syscon-poweroff",
94 .of_match_table = syscon_poweroff_of_match,
98 static int __init syscon_poweroff_register(void)
100 return platform_driver_register(&syscon_poweroff_driver);
102 device_initcall(syscon_poweroff_register);