1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 2016, Fuzhou Rockchip Electronics Co., Ltd
6 #include <linux/init.h>
7 #include <linux/module.h>
8 #include <linux/kernel.h>
10 #include <linux/platform_device.h>
11 #include <linux/reboot.h>
12 #include <linux/regmap.h>
13 #include <linux/mfd/syscon.h>
14 #include <linux/reboot-mode.h>
16 struct syscon_reboot_mode
{
18 struct reboot_mode_driver reboot
;
23 static int syscon_reboot_mode_write(struct reboot_mode_driver
*reboot
,
26 struct syscon_reboot_mode
*syscon_rbm
;
29 syscon_rbm
= container_of(reboot
, struct syscon_reboot_mode
, reboot
);
31 ret
= regmap_update_bits(syscon_rbm
->map
, syscon_rbm
->offset
,
32 syscon_rbm
->mask
, magic
);
34 dev_err(reboot
->dev
, "update reboot mode bits failed\n");
39 static int syscon_reboot_mode_probe(struct platform_device
*pdev
)
42 struct syscon_reboot_mode
*syscon_rbm
;
44 syscon_rbm
= devm_kzalloc(&pdev
->dev
, sizeof(*syscon_rbm
), GFP_KERNEL
);
48 syscon_rbm
->reboot
.dev
= &pdev
->dev
;
49 syscon_rbm
->reboot
.write
= syscon_reboot_mode_write
;
50 syscon_rbm
->mask
= 0xffffffff;
52 syscon_rbm
->map
= syscon_node_to_regmap(pdev
->dev
.parent
->of_node
);
53 if (IS_ERR(syscon_rbm
->map
))
54 return PTR_ERR(syscon_rbm
->map
);
56 if (of_property_read_u32(pdev
->dev
.of_node
, "offset",
60 of_property_read_u32(pdev
->dev
.of_node
, "mask", &syscon_rbm
->mask
);
62 ret
= devm_reboot_mode_register(&pdev
->dev
, &syscon_rbm
->reboot
);
64 dev_err(&pdev
->dev
, "can't register reboot mode\n");
69 static const struct of_device_id syscon_reboot_mode_of_match
[] = {
70 { .compatible
= "syscon-reboot-mode" },
73 MODULE_DEVICE_TABLE(of
, syscon_reboot_mode_of_match
);
75 static struct platform_driver syscon_reboot_mode_driver
= {
76 .probe
= syscon_reboot_mode_probe
,
78 .name
= "syscon-reboot-mode",
79 .of_match_table
= syscon_reboot_mode_of_match
,
82 module_platform_driver(syscon_reboot_mode_driver
);
84 MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com");
85 MODULE_DESCRIPTION("SYSCON reboot mode driver");
86 MODULE_LICENSE("GPL v2");