2 * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
10 #include <linux/init.h>
11 #include <linux/module.h>
12 #include <linux/kernel.h>
14 #include <linux/platform_device.h>
15 #include <linux/reboot.h>
16 #include <linux/regmap.h>
17 #include <linux/mfd/syscon.h>
18 #include "reboot-mode.h"
20 struct syscon_reboot_mode {
22 struct reboot_mode_driver reboot;
27 static int syscon_reboot_mode_write(struct reboot_mode_driver *reboot,
30 struct syscon_reboot_mode *syscon_rbm;
33 syscon_rbm = container_of(reboot, struct syscon_reboot_mode, reboot);
35 ret = regmap_update_bits(syscon_rbm->map, syscon_rbm->offset,
36 syscon_rbm->mask, magic);
38 dev_err(reboot->dev, "update reboot mode bits failed\n");
43 static int syscon_reboot_mode_probe(struct platform_device *pdev)
46 struct syscon_reboot_mode *syscon_rbm;
48 syscon_rbm = devm_kzalloc(&pdev->dev, sizeof(*syscon_rbm), GFP_KERNEL);
52 syscon_rbm->reboot.dev = &pdev->dev;
53 syscon_rbm->reboot.write = syscon_reboot_mode_write;
54 syscon_rbm->mask = 0xffffffff;
56 syscon_rbm->map = syscon_node_to_regmap(pdev->dev.parent->of_node);
57 if (IS_ERR(syscon_rbm->map))
58 return PTR_ERR(syscon_rbm->map);
60 if (of_property_read_u32(pdev->dev.of_node, "offset",
64 of_property_read_u32(pdev->dev.of_node, "mask", &syscon_rbm->mask);
66 ret = devm_reboot_mode_register(&pdev->dev, &syscon_rbm->reboot);
68 dev_err(&pdev->dev, "can't register reboot mode\n");
73 static const struct of_device_id syscon_reboot_mode_of_match[] = {
74 { .compatible = "syscon-reboot-mode" },
77 MODULE_DEVICE_TABLE(of, syscon_reboot_mode_of_match);
79 static struct platform_driver syscon_reboot_mode_driver = {
80 .probe = syscon_reboot_mode_probe,
82 .name = "syscon-reboot-mode",
83 .of_match_table = syscon_reboot_mode_of_match,
86 module_platform_driver(syscon_reboot_mode_driver);
89 MODULE_DESCRIPTION("SYSCON reboot mode driver");
90 MODULE_LICENSE("GPL v2");