1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Generic Syscon Poweroff Driver
5 * Copyright (c) 2015, National Instruments Corp.
6 * Author: Moritz Fischer <moritz.fischer@ettus.com>
9 #include <linux/delay.h>
11 #include <linux/notifier.h>
12 #include <linux/mfd/syscon.h>
14 #include <linux/platform_device.h>
16 #include <linux/regmap.h>
18 static struct regmap *map;
23 static void syscon_poweroff(void)
25 /* Issue the poweroff */
26 regmap_update_bits(map, offset, mask, value);
30 pr_emerg("Unable to poweroff system\n");
33 static int syscon_poweroff_probe(struct platform_device *pdev)
35 struct device *dev = &pdev->dev;
36 int mask_err, value_err;
38 map = syscon_regmap_lookup_by_phandle(dev->of_node, "regmap");
40 map = syscon_node_to_regmap(dev->parent->of_node);
42 dev_err(dev, "unable to get syscon");
47 if (of_property_read_u32(dev->of_node, "offset", &offset)) {
48 dev_err(dev, "unable to read 'offset'");
52 value_err = of_property_read_u32(dev->of_node, "value", &value);
53 mask_err = of_property_read_u32(dev->of_node, "mask", &mask);
54 if (value_err && mask_err) {
55 dev_err(dev, "unable to read 'value' and 'mask'");
60 /* support old binding */
63 } else if (mask_err) {
64 /* support value without mask*/
69 dev_err(dev, "pm_power_off already claimed for %ps",
74 pm_power_off = syscon_poweroff;
79 static int syscon_poweroff_remove(struct platform_device *pdev)
81 if (pm_power_off == syscon_poweroff)
87 static const struct of_device_id syscon_poweroff_of_match[] = {
88 { .compatible = "syscon-poweroff" },
92 static struct platform_driver syscon_poweroff_driver = {
93 .probe = syscon_poweroff_probe,
94 .remove = syscon_poweroff_remove,
96 .name = "syscon-poweroff",
97 .of_match_table = syscon_poweroff_of_match,
100 builtin_platform_driver(syscon_poweroff_driver);