1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2014 STMicroelectronics
5 * Power off Restart driver, used in STMicroelectronics devices.
7 * Author: Christophe Kerello <christophe.kerello@st.com>
10 #include <linux/module.h>
12 #include <linux/of_platform.h>
13 #include <linux/platform_device.h>
14 #include <linux/mfd/syscon.h>
15 #include <linux/reboot.h>
16 #include <linux/regmap.h>
19 struct regmap
*regmap
;
20 /* syscfg used for reset */
21 unsigned int offset_rst
;
22 unsigned int mask_rst
;
23 /* syscfg used for unmask the reset */
24 unsigned int offset_rst_msk
;
25 unsigned int mask_rst_msk
;
29 #define STIH407_SYSCFG_4000 0x0
30 #define STIH407_SYSCFG_4008 0x20
32 static struct reset_syscfg stih407_reset
= {
33 .offset_rst
= STIH407_SYSCFG_4000
,
35 .offset_rst_msk
= STIH407_SYSCFG_4008
,
36 .mask_rst_msk
= BIT(0)
40 static struct reset_syscfg
*st_restart_syscfg
;
42 static int st_restart(struct notifier_block
*this, unsigned long mode
,
45 /* reset syscfg updated */
46 regmap_update_bits(st_restart_syscfg
->regmap
,
47 st_restart_syscfg
->offset_rst
,
48 st_restart_syscfg
->mask_rst
,
51 /* unmask the reset */
52 regmap_update_bits(st_restart_syscfg
->regmap
,
53 st_restart_syscfg
->offset_rst_msk
,
54 st_restart_syscfg
->mask_rst_msk
,
60 static struct notifier_block st_restart_nb
= {
61 .notifier_call
= st_restart
,
65 static const struct of_device_id st_reset_of_match
[] = {
67 .compatible
= "st,stih407-restart",
68 .data
= (void *)&stih407_reset
,
73 static int st_reset_probe(struct platform_device
*pdev
)
75 struct device_node
*np
= pdev
->dev
.of_node
;
76 const struct of_device_id
*match
;
77 struct device
*dev
= &pdev
->dev
;
79 match
= of_match_device(st_reset_of_match
, dev
);
83 st_restart_syscfg
= (struct reset_syscfg
*)match
->data
;
85 st_restart_syscfg
->regmap
=
86 syscon_regmap_lookup_by_phandle(np
, "st,syscfg");
87 if (IS_ERR(st_restart_syscfg
->regmap
)) {
88 dev_err(dev
, "No syscfg phandle specified\n");
89 return PTR_ERR(st_restart_syscfg
->regmap
);
92 return register_restart_handler(&st_restart_nb
);
95 static struct platform_driver st_reset_driver
= {
96 .probe
= st_reset_probe
,
99 .of_match_table
= st_reset_of_match
,
103 static int __init
st_reset_init(void)
105 return platform_driver_register(&st_reset_driver
);
108 device_initcall(st_reset_init
);
110 MODULE_AUTHOR("Christophe Kerello <christophe.kerello@st.com>");
111 MODULE_DESCRIPTION("STMicroelectronics Power off Restart driver");
112 MODULE_LICENSE("GPL v2");